ar71xx: add support for TL-WA701ND v2
[openwrt/staging/chunkeey.git] / tools / firmware-utils / src / mktplinkfw.c
index 1c3f49dcffa9991961192f5b83e5e0490dc875ad..0a5e4c32825f3d3e2de0d35d2817d517342c347a 100644 (file)
@@ -30,6 +30,8 @@
 #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
 
 #define HEADER_VERSION_V1      0x01000000
+#define HWID_GL_INET_V1                0x08000001
+#define HWID_GS_OOLITE_V1      0x3C000101
 #define HWID_TL_MR10U_V1       0x00100101
 #define HWID_TL_MR13U_V1       0x00130101
 #define HWID_TL_MR3020_V1      0x30200001
@@ -38,6 +40,7 @@
 #define HWID_TL_MR3420_V1      0x34200001
 #define HWID_TL_MR3420_V2      0x34200002
 #define HWID_TL_WA701N_V1      0x07010001
+#define HWID_TL_WA701N_V2      0x07010002
 #define HWID_TL_WA7510N_V1     0x75100001
 #define HWID_TL_WA801ND_V1     0x08010001
 #define HWID_TL_WA830RE_V1     0x08300010
@@ -45,6 +48,7 @@
 #define HWID_TL_WA801ND_V2     0x08010002
 #define HWID_TL_WA901ND_V1     0x09010001
 #define HWID_TL_WA901ND_V2     0x09010002
+#define HWID_TL_WDR4300_V1_IL  0x43008001
 #define HWID_TL_WDR4900_V1     0x49000001
 #define HWID_TL_WR703N_V1      0x07030101
 #define HWID_TL_WR720N_V3      0x07200103
@@ -145,6 +149,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;
@@ -184,6 +190,18 @@ static struct flash_layout layouts[] = {
                .kernel_la      = 0x80060000,
                .kernel_ep      = 0x80060000,
                .rootfs_ofs     = 0x100000,
+       }, {
+               .id             = "16M",
+               .fw_max_len     = 0xf80000,
+               .kernel_la      = 0x80060000,
+               .kernel_ep      = 0x80060000,
+               .rootfs_ofs     = 0x140000,
+       }, {
+               .id             = "16Mlzma",
+               .fw_max_len     = 0xf80000,
+               .kernel_la      = 0x80060000,
+               .kernel_ep      = 0x80060000,
+               .rootfs_ofs     = 0x100000,
        }, {
                .id             = "16Mppc",
                .fw_max_len     = 0xf80000,
@@ -236,6 +254,11 @@ static struct board_info boards[] = {
                .hw_id          = HWID_TL_WA701N_V1,
                .hw_rev         = 1,
                .layout_id      = "4M",
+       }, {
+               .id             = "TL-WA701Nv2",
+               .hw_id          = HWID_TL_WA701N_V2,
+               .hw_rev         = 1,
+               .layout_id      = "4Mlzma",
        }, {
                .id             = "TL-WA7510N",
                .hw_id          = HWID_TL_WA7510N_V1,
@@ -271,6 +294,11 @@ static struct board_info boards[] = {
                .hw_id          = HWID_TL_WA901ND_V2,
                .hw_rev         = 1,
                .layout_id      = "4M",
+       }, {
+               .id             = "TL-WDR4300v1",
+               .hw_id          = HWID_TL_WDR4300_V1_IL,
+               .hw_rev         = 1,
+               .layout_id      = "8Mlzma",
        }, {
                .id             = "TL-WDR4900v1",
                .hw_id          = HWID_TL_WDR4900_V1,
@@ -366,6 +394,16 @@ static struct board_info boards[] = {
                .hw_id          = HWID_TL_WR720N_V3,
                .hw_rev         = 1,
                .layout_id      = "4Mlzma",
+       }, {
+               .id             = "GL-INETv1",
+               .hw_id          = HWID_GL_INET_V1,
+               .hw_rev         = 1,
+               .layout_id      = "8Mlzma",
+       }, {
+               .id             = "GS-OOLITEv1",
+               .hw_id          = HWID_GS_OOLITE_V1,
+               .hw_rev         = 1,
+               .layout_id      = "16Mlzma",
        }, {
                /* terminating entry */
        }
@@ -463,6 +501,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"
        );
 
@@ -579,6 +618,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;
@@ -592,7 +638,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;
                }
@@ -614,7 +660,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;
                        }
@@ -626,7 +672,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;
                        }
@@ -1029,7 +1075,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;
 
@@ -1094,6 +1140,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;