mtd: add option for TRX magic to fixtrx
[openwrt/openwrt.git] / package / system / mtd / src / mtd.c
index 9baed3fd5e9938792320320d45e9c4976d00dc47..fc7071d940833d2595b1cf57bc14e6671f8d5dc1 100644 (file)
@@ -94,6 +94,7 @@ int mtdsize = 0;
 int erasesize = 0;
 int jffs2_skip_bytes=0;
 int mtdtype = 0;
+uint32_t opt_trxmagic = TRX_MAGIC;
 
 int mtd_open(const char *mtd, bool block)
 {
@@ -205,7 +206,7 @@ image_check(int imagefd, const char *mtd)
 
        magic = ((uint32_t *)buf)[0];
 
-       if (be32_to_cpu(magic) == TRX_MAGIC)
+       if (be32_to_cpu(magic) == opt_trxmagic)
                imageformat = MTD_IMAGE_FORMAT_TRX;
        else if (be32_to_cpu(magic) == SEAMA_MAGIC)
                imageformat = MTD_IMAGE_FORMAT_SEAMA;
@@ -810,6 +811,7 @@ static void usage(void)
        "        -l <length>             the length of data that we want to dump\n");
        if (mtd_fixtrx) {
            fprintf(stderr,
+       "        -M <magic>              magic number of the image header in the partition (for fixtrx)\n"
        "        -o offset               offset of the image header in the partition(for fixtrx)\n");
        }
        if (mtd_fixtrx || mtd_fixseama || mtd_fixwrg || mtd_fixwrgg) {
@@ -877,7 +879,7 @@ int main (int argc, char **argv)
 #ifdef FIS_SUPPORT
                        "F:"
 #endif
-                       "frnqe:d:s:j:p:o:c:t:l:")) != -1)
+                       "frnqe:d:s:j:p:o:c:t:l:M:")) != -1)
                switch (ch) {
                        case 'f':
                                force = 1;
@@ -929,6 +931,14 @@ int main (int argc, char **argv)
                                        usage();
                                }
                                break;
+                       case 'M':
+                               errno = 0;
+                               opt_trxmagic = strtoul(optarg, 0, 0);
+                               if (errno) {
+                                       fprintf(stderr, "-M: illegal numeric string\n");
+                                       usage();
+                               }
+                               break;
                        case 'o':
                                errno = 0;
                                offset = strtoul(optarg, 0, 0);