generic: rtl8366: rename vlanmc and vlan4k related structures an functions
[openwrt.git] / package / mtd / src / fis.c
index 3108c5a..559ca95 100644 (file)
@@ -77,7 +77,7 @@ fis_open(void)
                goto error;
 
        fis_erasesize = erasesize;
                goto error;
 
        fis_erasesize = erasesize;
-       desc = mmap(NULL, erasesize, PROT_READ|PROT_WRITE, MAP_SHARED, fis_fd, 0);
+       desc = mmap(NULL, erasesize, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, fis_fd, 0);
        if (desc == MAP_FAILED)
                goto error;
 
        if (desc == MAP_FAILED)
                goto error;
 
@@ -146,7 +146,7 @@ fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new)
        struct fis_image_desc *desc;
        struct fis_part *part;
        uint32_t offset = 0, size = 0;
        struct fis_image_desc *desc;
        struct fis_part *part;
        uint32_t offset = 0, size = 0;
-       char *end, *tmp;
+       char *start, *end, *tmp;
        int i;
 
        desc = fis_open();
        int i;
 
        desc = fis_open();
@@ -156,6 +156,7 @@ fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new)
        if (!quiet)
                fprintf(stderr, "Updating FIS table... \n");
 
        if (!quiet)
                fprintf(stderr, "Updating FIS table... \n");
 
+       start = (char *) desc;
        end = (char *) desc + fis_erasesize;
        while ((char *) desc < end) {
                if (!desc->hdr.name[0] || (desc->hdr.name[0] == 0xff))
        end = (char *) desc + fis_erasesize;
        while ((char *) desc < end) {
                if (!desc->hdr.name[0] || (desc->hdr.name[0] == 0xff))
@@ -167,9 +168,12 @@ fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new)
                if (!strcmp((char *) desc->hdr.name, "RedBoot"))
                        redboot = desc;
 
                if (!strcmp((char *) desc->hdr.name, "RedBoot"))
                        redboot = desc;
 
+               /* update max offset */
+               if (offset < desc->hdr.flash_base)
+                       offset = desc->hdr.flash_base;
+
                for (i = 0; i < n_old; i++) {
                        if (!strncmp((char *) desc->hdr.name, (char *) old[i].name, sizeof(desc->hdr.name))) {
                for (i = 0; i < n_old; i++) {
                        if (!strncmp((char *) desc->hdr.name, (char *) old[i].name, sizeof(desc->hdr.name))) {
-                               size += desc->hdr.size;
                                last = desc;
                                if (!first)
                                        first = desc;
                                last = desc;
                                if (!first)
                                        first = desc;
@@ -180,13 +184,21 @@ fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new)
        }
        desc--;
 
        }
        desc--;
 
-       if (desc == last) {
-               desc = fisdir;
+       /* determine size of available space */
+       desc = (struct fis_image_desc *) start;
+       while ((char *) desc < end) {
+               if (!desc->hdr.name[0] || (desc->hdr.name[0] == 0xff))
+                       break;
+
+               if (desc->hdr.flash_base > last->hdr.flash_base &&
+                   desc->hdr.flash_base < offset)
+                       offset = desc->hdr.flash_base;
+
+               desc++;
        }
        }
+       desc--;
 
 
-       /* size fixup */
-       if (desc && (last->hdr.flash_base < desc->hdr.flash_base - last->hdr.size))
-                       size += (desc->hdr.flash_base - last->hdr.flash_base) - last->hdr.size;
+       size = offset - first->hdr.flash_base;
 
 #ifdef notyet
        desc = first - 1;
 
 #ifdef notyet
        desc = first - 1;
This page took 0.03515 seconds and 4 git commands to generate.