mtd: add fixwrg command
[openwrt/openwrt.git] / package / system / mtd / src / mtd.c
index e66e647c0135625bf57cbad69268063008642de3..55a3bdba8105dea7c6260b32e2f652c9225a1861 100644 (file)
@@ -54,6 +54,7 @@
 
 #define TRX_MAGIC              0x48445230      /* "HDR0" */
 #define SEAMA_MAGIC            0x5ea3a417
+#define WRG_MAGIC              0x20040220
 #define WRGG03_MAGIC           0x20080321
 
 #if !defined(__BYTE_ORDER)
@@ -76,6 +77,7 @@ enum mtd_image_format {
        MTD_IMAGE_FORMAT_UNKNOWN,
        MTD_IMAGE_FORMAT_TRX,
        MTD_IMAGE_FORMAT_SEAMA,
+       MTD_IMAGE_FORMAT_WRG,
        MTD_IMAGE_FORMAT_WRGG03,
 };
 
@@ -205,6 +207,8 @@ image_check(int imagefd, const char *mtd)
                imageformat = MTD_IMAGE_FORMAT_TRX;
        else if (be32_to_cpu(magic) == SEAMA_MAGIC)
                imageformat = MTD_IMAGE_FORMAT_SEAMA;
+       else if (le32_to_cpu(magic) == WRG_MAGIC)
+               imageformat = MTD_IMAGE_FORMAT_WRG;
        else if (le32_to_cpu(magic) == WRGG03_MAGIC)
                imageformat = MTD_IMAGE_FORMAT_WRGG03;
 
@@ -214,7 +218,7 @@ image_check(int imagefd, const char *mtd)
                        ret = trx_check(imagefd, mtd, buf, &buflen);
                break;
        case MTD_IMAGE_FORMAT_SEAMA:
-               break;
+       case MTD_IMAGE_FORMAT_WRG:
        case MTD_IMAGE_FORMAT_WRGG03:
                break;
        default:
@@ -685,6 +689,10 @@ resume:
                        if (mtd_fixseama)
                                mtd_fixseama(mtd, 0, 0);
                        break;
+               case MTD_IMAGE_FORMAT_WRG:
+                       if (mtd_fixwrg)
+                               mtd_fixwrg(mtd, 0, 0);
+                       break;
                case MTD_IMAGE_FORMAT_WRGG03:
                        if (mtd_fixwrgg)
                                mtd_fixwrgg(mtd, 0, 0);
@@ -734,6 +742,10 @@ static void usage(void)
            fprintf(stderr,
        "        fixseama                fix the checksum in a seama header on first boot\n");
        }
+       if (mtd_fixwrg) {
+           fprintf(stderr,
+       "        fixwrg                  fix the checksum in a wrg header on first boot\n");
+       }
        if (mtd_fixwrgg) {
            fprintf(stderr,
        "        fixwrgg                 fix the checksum in a wrgg header on first boot\n");
@@ -755,9 +767,9 @@ static void usage(void)
            fprintf(stderr,
        "        -o offset               offset of the image header in the partition(for fixtrx)\n");
        }
-       if (mtd_fixtrx || mtd_fixseama || mtd_fixwrgg) {
+       if (mtd_fixtrx || mtd_fixseama || mtd_fixwrg || mtd_fixwrgg) {
                fprintf(stderr,
-       "        -c datasize             amount of data to be used for checksum calculation (for fixtrx / fixseama / fixwrgg)\n");
+       "        -c datasize             amount of data to be used for checksum calculation (for fixtrx / fixseama / fixwrg / fixwrgg)\n");
        }
        fprintf(stderr,
 #ifdef FIS_SUPPORT
@@ -798,6 +810,7 @@ int main (int argc, char **argv)
                CMD_JFFS2WRITE,
                CMD_FIXTRX,
                CMD_FIXSEAMA,
+               CMD_FIXWRG,
                CMD_FIXWRGG,
                CMD_VERIFY,
                CMD_DUMP,
@@ -913,6 +926,9 @@ int main (int argc, char **argv)
        } else if (((strcmp(argv[0], "fixseama") == 0) && (argc == 2)) && mtd_fixseama) {
                cmd = CMD_FIXSEAMA;
                device = argv[1];
+       } else if (((strcmp(argv[0], "fixwrg") == 0) && (argc == 2)) && mtd_fixwrg) {
+               cmd = CMD_FIXWRG;
+               device = argv[1];
        } else if (((strcmp(argv[0], "fixwrgg") == 0) && (argc == 2)) && mtd_fixwrgg) {
                cmd = CMD_FIXWRGG;
                device = argv[1];
@@ -1012,6 +1028,10 @@ int main (int argc, char **argv)
                        if (mtd_fixseama)
                                mtd_fixseama(device, 0, data_size);
                        break;
+               case CMD_FIXWRG:
+                       if (mtd_fixwrg)
+                               mtd_fixwrg(device, 0, data_size);
+                       break;
                case CMD_FIXWRGG:
                        if (mtd_fixwrgg)
                                mtd_fixwrgg(device, 0, data_size);