X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fopenwrt.git;a=blobdiff_plain;f=tools%2Ffirmware-utils%2Fsrc%2Fmktplinkfw.c;h=085eb4c39d7ca6438029a8f0c1e6d541fa126931;hp=f8f162002b769fd839917a245d0cacce019f9c09;hb=0231d4135284dec47ec6597cf938698c6117ef1a;hpb=cbeb862b959c551fcac497457899952a5737a912 diff --git a/tools/firmware-utils/src/mktplinkfw.c b/tools/firmware-utils/src/mktplinkfw.c index f8f162002b..085eb4c39d 100644 --- a/tools/firmware-utils/src/mktplinkfw.c +++ b/tools/firmware-utils/src/mktplinkfw.c @@ -30,16 +30,34 @@ #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); }) #define HEADER_VERSION_V1 0x01000000 +#define HEADER_VERSION_V2 0x02000000 +#define HWID_ANTMINER_S1 0x04440101 +#define HWID_ANTMINER_S3 0x04440301 +#define HWID_GL_INET_V1 0x08000001 +#define HWID_GS_OOLITE_V1 0x3C000101 +#define HWID_ONION_OMEGA 0x04700001 +#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_WA701N_V2 0x07010002 +#define HWID_TL_WA7210N_V2 0x72100002 #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_WDR4300_V1_IL 0x43008001 +#define HWID_TL_WDR4900_V1 0x49000001 #define HWID_TL_WR703N_V1 0x07030101 +#define HWID_TL_WR720N_V3 0x07200103 +#define HWID_TL_WR720N_V4 0x07200104 #define HWID_TL_WR741ND_V1 0x07410001 #define HWID_TL_WR741ND_V4 0x07410004 #define HWID_TL_WR740N_V1 0x07400001 @@ -53,6 +71,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 @@ -112,6 +131,7 @@ static char *progname; static char *vendor = "TP-LINK Technologies"; static char *version = "ver. 1.0"; static char *fw_ver = "0.0.0"; +static uint32_t hdr_ver = HEADER_VERSION_V1; static char *board_id; static struct board_info *board; @@ -121,6 +141,7 @@ static char *opt_hw_id; static uint32_t hw_id; static char *opt_hw_rev; static uint32_t hw_rev; +static uint32_t opt_hdr_ver = 1; static int fw_ver_lo; static int fw_ver_mid; static int fw_ver_hi; @@ -134,8 +155,11 @@ static uint32_t rootfs_align; static struct file_info boot_info; static int combined; static int strip_padding; +static int ignore_size; 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; @@ -175,6 +199,24 @@ 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, + .kernel_la = 0x00000000, + .kernel_ep = 0xc0000000, + .rootfs_ofs = 0x2a0000, }, { /* terminating entry */ } @@ -182,6 +224,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, @@ -201,11 +253,26 @@ static struct board_info boards[] = { .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, .hw_rev = 1, .layout_id = "4M", + }, { + .id = "TL-WA701Nv2", + .hw_id = HWID_TL_WA701N_V2, + .hw_rev = 1, + .layout_id = "4Mlzma", + }, { + .id = "TL-WA7210N", + .hw_id = HWID_TL_WA7210N_V2, + .hw_rev = 2, + .layout_id = "4Mlzma", }, { .id = "TL-WA7510N", .hw_id = HWID_TL_WA7510N_V1, @@ -216,6 +283,21 @@ static struct board_info boards[] = { .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, @@ -226,6 +308,16 @@ 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, + .hw_rev = 1, + .layout_id = "16Mppc", }, { .id = "TL-WR741NDv1", .hw_id = HWID_TL_WR741ND_V1, @@ -296,6 +388,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, @@ -306,6 +403,41 @@ 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", + }, { + .id = "TL-WR720Nv4", + .hw_id = HWID_TL_WR720N_V4, + .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", + }, { + .id = "ONION-OMEGA", + .hw_id = HWID_ONION_OMEGA, + .hw_rev = 1, + .layout_id = "16Mlzma", + }, { + .id = "ANTMINER-S1", + .hw_id = HWID_ANTMINER_S1, + .hw_rev = 1, + .layout_id = "8Mlzma", + }, { + .id = "ANTMINER-S3", + .hw_id = HWID_ANTMINER_S3, + .hw_rev = 1, + .layout_id = "8Mlzma", }, { /* terminating entry */ } @@ -323,7 +455,7 @@ static struct board_info boards[] = { #define ERRS(fmt, ...) do { \ int save = errno; \ fflush(0); \ - fprintf(stderr, "[%s] *** error: " fmt "\n", \ + fprintf(stderr, "[%s] *** error: " fmt ": %s\n", \ progname, ## __VA_ARGS__, strerror(save)); \ } while (0) @@ -389,6 +521,7 @@ static void usage(int status) " -E overwrite kernel entry point with (hexval prefixed with 0x)\n" " -L overwrite kernel load address with (hexval prefixed with 0x)\n" " -H use hardware id specified with \n" +" -W use hardware revision specified with \n" " -F use flash layout specified with \n" " -k read kernel image from the file \n" " -r read rootfs image from the file \n" @@ -396,12 +529,15 @@ static void usage(int status) " -R overwrite rootfs offset with (hexval prefixed with 0x)\n" " -o write output to the file \n" " -s strip padding from the end of the image\n" +" -S ignore firmware size limit (only for combined images)\n" " -j add jffs2 end-of-filesystem markers\n" " -N set image vendor to \n" " -V set image version to \n" " -v set firmware version to \n" +" -m set header version to \n" " -i inspect given firmware file \n" " -x extract kernel and rootfs while inspecting (requires -i)\n" +" -X reserve bytes in the firmware image (hexval prefixed with 0x)\n" " -h show this screen\n" ); @@ -464,6 +600,7 @@ static int read_to_buf(struct file_info *fdata, char *buf) static int check_options(void) { int ret; + int exceed_bytes; if (inspect_info.file_name) { ret = get_file_stat(&inspect_info); @@ -518,6 +655,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; @@ -530,10 +674,15 @@ static int check_options(void) kernel_len = kernel_info.file_size; if (combined) { - if (kernel_info.file_size > - layout->fw_max_len - sizeof(struct fw_header)) { - ERR("kernel image is too big"); - return -1; + exceed_bytes = kernel_info.file_size - (fw_max_len - sizeof(struct fw_header)); + if (exceed_bytes > 0) { + if (!ignore_size) { + ERR("kernel image is too big by %i bytes", exceed_bytes); + return -1; + } + layout->fw_max_len = sizeof(struct fw_header) + + kernel_info.file_size + + reserved_space; } } else { if (rootfs_info.file_name == NULL) { @@ -552,21 +701,21 @@ 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)) { - ERR("images are too big"); + exceed_bytes = kernel_len + rootfs_info.file_size - (fw_max_len - sizeof(struct fw_header)); + if (exceed_bytes > 0) { + ERR("images are too big by %i bytes", exceed_bytes); return -1; } } else { - if (kernel_info.file_size > - rootfs_ofs - sizeof(struct fw_header)) { - ERR("kernel image is too big"); + exceed_bytes = kernel_info.file_size - (rootfs_ofs - sizeof(struct fw_header)); + if (exceed_bytes > 0) { + ERR("kernel image is too big by %i bytes", exceed_bytes); return -1; } - if (rootfs_info.file_size > - (layout->fw_max_len - rootfs_ofs)) { - ERR("rootfs image is too big"); + exceed_bytes = rootfs_info.file_size - (fw_max_len - rootfs_ofs); + if (exceed_bytes > 0) { + ERR("rootfs image is too big by %i bytes", exceed_bytes); return -1; } } @@ -583,6 +732,15 @@ static int check_options(void) return -1; } + if (opt_hdr_ver == 1) { + hdr_ver = HEADER_VERSION_V1; + } else if (opt_hdr_ver == 2) { + hdr_ver = HEADER_VERSION_V2; + } else { + ERR("invalid header version '%u'", opt_hdr_ver); + return -1; + } + return 0; } @@ -592,7 +750,7 @@ static void fill_header(char *buf, int len) memset(hdr, 0, sizeof(struct fw_header)); - hdr->version = htonl(HEADER_VERSION_V1); + hdr->version = htonl(hdr_ver); strncpy(hdr->vendor_name, vendor, sizeof(hdr->vendor_name)); strncpy(hdr->fw_version, version, sizeof(hdr->fw_version)); hdr->hw_id = htonl(hw_id); @@ -832,8 +990,9 @@ static int inspect_fw(void) inspect_fw_pstr("File name", inspect_info.file_name); inspect_fw_phexdec("File size", inspect_info.file_size); - if (ntohl(hdr->version) != HEADER_VERSION_V1) { - ERR("file does not seem to have V1 header!\n"); + if ((ntohl(hdr->version) != HEADER_VERSION_V1) && + (ntohl(hdr->version) != HEADER_VERSION_V2)) { + ERR("file does not seem to have V1/V2 header!\n"); goto out_free_buf; } @@ -968,7 +1127,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:m:V:N:W:ci:k:r:R:o:xX:hsSjv:"); if (c == -1) break; @@ -994,6 +1153,9 @@ int main(int argc, char *argv[]) case 'L': sscanf(optarg, "0x%x", &kernel_la); break; + case 'm': + sscanf(optarg, "%u", &opt_hdr_ver); + break; case 'V': version = optarg; break; @@ -1021,6 +1183,9 @@ int main(int argc, char *argv[]) case 's': strip_padding = 1; break; + case 'S': + ignore_size = 1; + break; case 'i': inspect_info.file_name = optarg; break; @@ -1033,6 +1198,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;