firmware-utils/mktplinkfw: allow to reserve space in the generated images
[openwrt/svn-archive/archive.git] / tools / firmware-utils / src / mktplinkfw.c
index 2be63356dab78d923057ee4c748ae6eb8d56cee4..d15ca5bf45b41c0da141fb631aae6b100143740d 100644 (file)
 #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
 
 #define HEADER_VERSION_V1      0x01000000
+#define HWID_TL_MR10U_V1       0x00100101
+#define HWID_TL_MR13U_V1       0x00130101
 #define HWID_TL_MR3020_V1      0x30200001
 #define HWID_TL_MR3220_V1      0x32200001
+#define HWID_TL_MR3220_V2      0x32200002
 #define HWID_TL_MR3420_V1      0x34200001
+#define HWID_TL_MR3420_V2      0x34200002
 #define HWID_TL_WA701N_V1      0x07010001
 #define HWID_TL_WA7510N_V1     0x75100001
+#define HWID_TL_WA801ND_V1     0x08010001
+#define HWID_TL_WA830RE_V1     0x08300010
+#define HWID_TL_WA830RE_V2     0x08300002
+#define HWID_TL_WA801ND_V2     0x08010002
 #define HWID_TL_WA901ND_V1     0x09010001
 #define HWID_TL_WA901ND_V2     0x09010002
+#define HWID_TL_WDR4900_V1     0x49000001
 #define HWID_TL_WR703N_V1      0x07030101
+#define HWID_TL_WR720N_V3      0x07200103
 #define HWID_TL_WR741ND_V1     0x07410001
 #define HWID_TL_WR741ND_V4     0x07410004
 #define HWID_TL_WR740N_V1      0x07400001
 #define HWID_TL_WR740N_V3      0x07400003
 #define HWID_TL_WR743ND_V1     0x07430001
+#define HWID_TL_WR743ND_V2     0x07430002
 #define HWID_TL_WR841N_V1_5    0x08410002
 #define HWID_TL_WR841ND_V3     0x08410003
 #define HWID_TL_WR841ND_V5     0x08410005
@@ -50,6 +61,7 @@
 #define HWID_TL_WR941ND_V2     0x09410002
 #define HWID_TL_WR941ND_V4     0x09410004
 #define HWID_TL_WR1043ND_V1    0x10430001
+#define HWID_TL_WR1043ND_V2    0x10430002
 #define HWID_TL_WR1041N_V2     0x10410002
 #define HWID_TL_WR2543N_V1     0x25430001
 
@@ -133,6 +145,8 @@ static int combined;
 static int strip_padding;
 static int add_jffs2_eof;
 static unsigned char jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde};
+static uint32_t fw_max_len;
+static uint32_t reserved_space;
 
 static struct file_info inspect_info;
 static int extract = 0;
@@ -172,6 +186,12 @@ static struct flash_layout layouts[] = {
                .kernel_la      = 0x80060000,
                .kernel_ep      = 0x80060000,
                .rootfs_ofs     = 0x100000,
+       }, {
+               .id             = "16Mppc",
+               .fw_max_len     = 0xf80000,
+               .kernel_la      = 0x00000000,
+               .kernel_ep      = 0xc0000000,
+               .rootfs_ofs     = 0x2a0000,
        }, {
                /* terminating entry */
        }
@@ -179,6 +199,16 @@ static struct flash_layout layouts[] = {
 
 static struct board_info boards[] = {
        {
+               .id             = "TL-MR10Uv1",
+               .hw_id          = HWID_TL_MR10U_V1,
+               .hw_rev         = 1,
+               .layout_id      = "4Mlzma",
+       }, {
+               .id             = "TL-MR13Uv1",
+               .hw_id          = HWID_TL_MR13U_V1,
+               .hw_rev         = 1,
+               .layout_id      = "4Mlzma",
+       }, {
                .id             = "TL-MR3020v1",
                .hw_id          = HWID_TL_MR3020_V1,
                .hw_rev         = 1,
@@ -188,11 +218,21 @@ static struct board_info boards[] = {
                .hw_id          = HWID_TL_MR3220_V1,
                .hw_rev         = 1,
                .layout_id      = "4M",
+       }, {
+               .id             = "TL-MR3220v2",
+               .hw_id          = HWID_TL_MR3220_V2,
+               .hw_rev         = 1,
+               .layout_id      = "4Mlzma",
        }, {
                .id             = "TL-MR3420v1",
                .hw_id          = HWID_TL_MR3420_V1,
                .hw_rev         = 1,
                .layout_id      = "4M",
+       }, {
+               .id             = "TL-MR3420v2",
+               .hw_id          = HWID_TL_MR3420_V2,
+               .hw_rev         = 1,
+               .layout_id      = "4Mlzma",
        }, {
                .id             = "TL-WA701Nv1",
                .hw_id          = HWID_TL_WA701N_V1,
@@ -203,6 +243,26 @@ static struct board_info boards[] = {
                .hw_id          = HWID_TL_WA7510N_V1,
                .hw_rev         = 1,
                .layout_id      = "4M",
+       }, {
+               .id             = "TL-WA801NDv1",
+               .hw_id          = HWID_TL_WA801ND_V1,
+               .hw_rev         = 1,
+               .layout_id      = "4M",
+       }, {
+               .id             = "TL-WA830REv1",
+               .hw_id          = HWID_TL_WA830RE_V1,
+               .hw_rev         = 1,
+               .layout_id      = "4M",
+       }, {
+               .id             = "TL-WA830REv2",
+               .hw_id          = HWID_TL_WA830RE_V2,
+               .hw_rev         = 1,
+               .layout_id      = "4M",
+       }, {
+               .id             = "TL-WA801NDv2",
+               .hw_id          = HWID_TL_WA801ND_V2,
+               .hw_rev         = 1,
+               .layout_id      = "4Mlzma",
        }, {
                .id             = "TL-WA901NDv1",
                .hw_id          = HWID_TL_WA901ND_V1,
@@ -213,6 +273,11 @@ static struct board_info boards[] = {
                .hw_id          = HWID_TL_WA901ND_V2,
                .hw_rev         = 1,
                .layout_id      = "4M",
+       }, {
+               .id             = "TL-WDR4900v1",
+               .hw_id          = HWID_TL_WDR4900_V1,
+               .hw_rev         = 1,
+               .layout_id      = "16Mppc",
        }, {
                .id             = "TL-WR741NDv1",
                .hw_id          = HWID_TL_WR741ND_V1,
@@ -238,6 +303,11 @@ static struct board_info boards[] = {
                .hw_id          = HWID_TL_WR743ND_V1,
                .hw_rev         = 1,
                .layout_id      = "4M",
+       }, {
+               .id             = "TL-WR743NDv2",
+               .hw_id          = HWID_TL_WR743ND_V2,
+               .hw_rev         = 1,
+               .layout_id      = "4Mlzma",
        }, {
                .id             = "TL-WR841Nv1.5",
                .hw_id          = HWID_TL_WR841N_V1_5,
@@ -278,6 +348,11 @@ static struct board_info boards[] = {
                .hw_id          = HWID_TL_WR1043ND_V1,
                .hw_rev         = 1,
                .layout_id      = "8M",
+       }, {
+               .id             = "TL-WR1043NDv2",
+               .hw_id          = HWID_TL_WR1043ND_V2,
+               .hw_rev         = 1,
+               .layout_id      = "8Mlzma",
        }, {
                .id             = "TL-WR2543Nv1",
                .hw_id          = HWID_TL_WR2543N_V1,
@@ -288,6 +363,11 @@ static struct board_info boards[] = {
                .hw_id          = HWID_TL_WR703N_V1,
                .hw_rev         = 1,
                .layout_id      = "4Mlzma",
+       }, {
+               .id             = "TL-WR720Nv3",
+               .hw_id          = HWID_TL_WR720N_V3,
+               .hw_rev         = 1,
+               .layout_id      = "4Mlzma",
        }, {
                /* terminating entry */
        }
@@ -371,6 +451,7 @@ static void usage(int status)
 "  -E <ep>         overwrite kernel entry point with <ep> (hexval prefixed with 0x)\n"
 "  -L <la>         overwrite kernel load address with <la> (hexval prefixed with 0x)\n"
 "  -H <hwid>       use hardware id specified with <hwid>\n"
+"  -W <hwrev>      use hardware revision specified with <hwrev>\n"
 "  -F <id>         use flash layout specified with <id>\n"
 "  -k <file>       read kernel image from the file <file>\n"
 "  -r <file>       read rootfs image from the file <file>\n"
@@ -384,6 +465,7 @@ static void usage(int status)
 "  -v <version>    set firmware version to <version>\n"
 "  -i <file>       inspect given firmware file <file>\n"
 "  -x              extract kernel and rootfs while inspecting (requires -i)\n"
+"  -X <size>       reserve <size> bytes in the firmware image (hexval prefixed with 0x)\n"
 "  -h              show this screen\n"
        );
 
@@ -500,6 +582,13 @@ static int check_options(void)
        if (!rootfs_ofs)
                rootfs_ofs = layout->rootfs_ofs;
 
+       if (reserved_space > layout->fw_max_len) {
+               ERR("reserved space is not valid");
+               return -1;
+       }
+
+       fw_max_len = layout->fw_max_len - reserved_space;
+
        if (kernel_info.file_name == NULL) {
                ERR("no kernel image specified");
                return -1;
@@ -513,7 +602,7 @@ static int check_options(void)
 
        if (combined) {
                if (kernel_info.file_size >
-                   layout->fw_max_len - sizeof(struct fw_header)) {
+                   fw_max_len - sizeof(struct fw_header)) {
                        ERR("kernel image is too big");
                        return -1;
                }
@@ -535,7 +624,7 @@ static int check_options(void)
                        DBG("kernel length aligned to %u", kernel_len);
 
                        if (kernel_len + rootfs_info.file_size >
-                           layout->fw_max_len - sizeof(struct fw_header)) {
+                           fw_max_len - sizeof(struct fw_header)) {
                                ERR("images are too big");
                                return -1;
                        }
@@ -547,7 +636,7 @@ static int check_options(void)
                        }
 
                        if (rootfs_info.file_size >
-                           (layout->fw_max_len - rootfs_ofs)) {
+                           (fw_max_len - rootfs_ofs)) {
                                ERR("rootfs image is too big");
                                return -1;
                        }
@@ -950,7 +1039,7 @@ int main(int argc, char *argv[])
        while ( 1 ) {
                int c;
 
-               c = getopt(argc, argv, "a:B:H:E:F:L:V:N:W:ci:k:r:R:o:xhsjv:");
+               c = getopt(argc, argv, "a:B:H:E:F:L:V:N:W:ci:k:r:R:o:xX:hsjv:");
                if (c == -1)
                        break;
 
@@ -1015,6 +1104,9 @@ int main(int argc, char *argv[])
                case 'h':
                        usage(EXIT_SUCCESS);
                        break;
+               case 'X':
+                       sscanf(optarg, "0x%x", &reserved_space);
+                       break;
                default:
                        usage(EXIT_FAILURE);
                        break;