X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/9f5f35abdaa8bab4a6ae424413bbd9e9e64a3c41..33b476daa3525c5f83bf29fa96506f06c13eb0f3:/tools/firmware-utils/src/mktplinkfw.c diff --git a/tools/firmware-utils/src/mktplinkfw.c b/tools/firmware-utils/src/mktplinkfw.c index 174df957f..f8fa2f14b 100644 --- a/tools/firmware-utils/src/mktplinkfw.c +++ b/tools/firmware-utils/src/mktplinkfw.c @@ -30,8 +30,10 @@ #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); }) #define HEADER_VERSION_V1 0x01000000 +#define HWID_TL_MR3020_V1 0x30200001 #define HWID_TL_MR3220_V1 0x32200001 #define HWID_TL_MR3420_V1 0x34200001 +#define HWID_TL_WA701N_V1 0x07010001 #define HWID_TL_WA901ND_V1 0x09010001 #define HWID_TL_WA901ND_V2 0x09010002 #define HWID_TL_WR703N_V1 0x07030101 @@ -47,6 +49,7 @@ #define HWID_TL_WR941ND_V2 0x09410002 #define HWID_TL_WR941ND_V4 0x09410004 #define HWID_TL_WR1043ND_V1 0x10430001 +#define HWID_TL_WR2543N_V1 0x25430001 #define MD5SUM_LEN 16 @@ -119,6 +122,8 @@ static uint32_t rootfs_align; static struct file_info boot_info; static int combined; static int strip_padding; +static int add_jffs2_eof; +static unsigned char jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde}; static struct file_info inspect_info; static int extract = 0; @@ -152,6 +157,12 @@ static struct flash_layout layouts[] = { .kernel_la = 0x80060000, .kernel_ep = 0x80060000, .rootfs_ofs = 0x140000, + }, { + .id = "8Mlzma", + .fw_max_len = 0x7c0000, + .kernel_la = 0x80060000, + .kernel_ep = 0x80060000, + .rootfs_ofs = 0x100000, }, { /* terminating entry */ } @@ -159,6 +170,11 @@ static struct flash_layout layouts[] = { static struct board_info boards[] = { { + .id = "TL-MR3020v1", + .hw_id = HWID_TL_MR3020_V1, + .hw_rev = 1, + .layout_id = "4Mlzma", + }, { .id = "TL-MR3220v1", .hw_id = HWID_TL_MR3220_V1, .hw_rev = 1, @@ -168,6 +184,11 @@ static struct board_info boards[] = { .hw_id = HWID_TL_MR3420_V1, .hw_rev = 1, .layout_id = "4M", + }, { + .id = "TL-WA701Nv1", + .hw_id = HWID_TL_WA701N_V1, + .hw_rev = 1, + .layout_id = "4M", }, { .id = "TL-WA901NDv1", .hw_id = HWID_TL_WA901ND_V1, @@ -238,6 +259,11 @@ static struct board_info boards[] = { .hw_id = HWID_TL_WR1043ND_V1, .hw_rev = 1, .layout_id = "8M", + }, { + .id = "TL-WR2543Nv1", + .hw_id = HWID_TL_WR2543N_V1, + .hw_rev = 1, + .layout_id = "8Mlzma", }, { .id = "TL-WR703Nv1", .hw_id = HWID_TL_WR703N_V1, @@ -333,6 +359,7 @@ 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" +" -j add jffs2 end-of-filesystem markers\n" " -N set image vendor to \n" " -V set image version to \n" " -i inspect given firmware file \n" @@ -545,6 +572,40 @@ static void fill_header(char *buf, int len) get_md5(buf, len, hdr->md5sum1); } +static int pad_jffs2(char *buf, int currlen) +{ + int len; + uint32_t pad_mask; + + len = currlen; + pad_mask = (64 * 1024); + while ((len < layout->fw_max_len) && (pad_mask != 0)) { + uint32_t mask; + int i; + + for (i = 10; i < 32; i++) { + mask = 1 << i; + if (pad_mask & mask) + break; + } + + len = ALIGN(len, mask); + + for (i = 10; i < 32; i++) { + mask = 1 << i; + if ((len & (mask - 1)) == 0) + pad_mask &= ~mask; + } + + for (i = 0; i < sizeof(jffs2_eof_mark); i++) + buf[len + i] = jffs2_eof_mark[i]; + + len += sizeof(jffs2_eof_mark); + } + + return len; +} + static int write_fw(char *data, int len) { FILE *f; @@ -606,6 +667,7 @@ static int build_fw(void) p = buf + writelen; else p = buf + rootfs_ofs; + ret = read_to_buf(&rootfs_info, p); if (ret) goto out_free_buf; @@ -614,6 +676,9 @@ static int build_fw(void) writelen += rootfs_info.file_size; else writelen = rootfs_ofs + rootfs_info.file_size; + + if (add_jffs2_eof) + writelen = pad_jffs2(buf, writelen); } if (!strip_padding) @@ -855,7 +920,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:xhs"); + c = getopt(argc, argv, "a:B:H:E:F:L:V:N:W:ci:k:r:R:o:xhsj"); if (c == -1) break; @@ -908,6 +973,9 @@ int main(int argc, char *argv[]) case 'i': inspect_info.file_name = optarg; break; + case 'j': + add_jffs2_eof = 1; + break; case 'x': extract = 1; break;