--- elwix/tools/mktplinkfw/mktplinkfw.c 2014/01/14 22:25:57 1.1.2.1 +++ elwix/tools/mktplinkfw/mktplinkfw.c 2014/06/15 15:07:23 1.1.2.2 @@ -43,6 +43,7 @@ #endif #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_WA901ND_V1 0x09010001 @@ -134,6 +135,19 @@ char md5salt_boot[MD5SUM_LEN] = { static struct board_info boards[] = { { + .id = "TL-MR3020v1", + .hw_id = HWID_TL_MR3020_V1, + .hw_rev = 1, + /* + * Actual size of firmware is 3.8MB but for now, allow larger + * sizes until we work out a plan for this unit + * .fw_max_len = 0x3c0000, + */ + .fw_max_len = 0x640000, + .kernel_la = 0x80060000, + .kernel_ep = 0x80060000, + .rootfs_ofs = 0x100000, + }, { .id = "TL-MR3220v1", .hw_id = HWID_TL_MR3220_V1, .hw_rev = 1, @@ -278,7 +292,7 @@ static struct board_info boards[] = { #define ERRS(fmt, ...) do { \ int save = errno; \ fflush(0); \ - fprintf(stderr, "[%s] *** error: " fmt " %s\n", \ + fprintf(stderr, "[%s] *** error: " fmt " error:%s\n", \ progname, ## __VA_ARGS__, strerror(save)); \ } while (0) @@ -343,15 +357,13 @@ static void usage(int status) exit(status); } -static int get_md5(char *data, int size, char *md5) +static void get_md5(char *data, int size, uint8_t *md5) { MD5_CTX ctx; MD5_Init(&ctx); MD5_Update(&ctx, data, size); - MD5_Final((u_char*) md5, &ctx); - - return 0; + MD5_Final(md5, &ctx); } static int get_file_stat(struct file_info *fdata) @@ -442,13 +454,15 @@ static int check_options(void) if (combined) { if (kernel_info.file_size > board->fw_max_len - sizeof(struct fw_header)) { - ERR("kernel image is too big"); + ERR("Combined kernel image is too big. Max[%lu] kernel img [%d]", + board->fw_max_len - sizeof(struct fw_header), kernel_info.file_size); return -1; } } else { if (kernel_info.file_size > - rootfs_ofs - sizeof(struct fw_header)) { - ERR("kernel image is too big"); + (rootfs_ofs - sizeof(struct fw_header))) { + ERR("kernel image is too big. Max[%lu] kernel img [%d]", + rootfs_ofs - sizeof(struct fw_header), kernel_info.file_size); return -1; } if (rootfs_info.file_name == NULL) { @@ -462,7 +476,8 @@ static int check_options(void) if (rootfs_info.file_size > (board->fw_max_len - rootfs_ofs)) { - ERR("rootfs image is too big"); + ERR("rootfs image is too big. Max[%d] fs img [%d]", + board->fw_max_len - rootfs_ofs, rootfs_info.file_size); return -1; } } @@ -502,7 +517,7 @@ static void fill_header(char *buf, int len) hdr->rootfs_len = HOST_TO_BE32(rootfs_info.file_size); } - get_md5(buf, len, (char*) hdr->md5sum1); + get_md5(buf, len, hdr->md5sum1); } static int write_fw(char *data, int len) @@ -519,7 +534,7 @@ static int write_fw(char *data, int len) errno = 0; fwrite(data, len, 1, f); if (errno) { - ERRS("unable to write output file"); + ERRS("unable to write output file \"%s\"", ofname); goto out_flush; } @@ -688,7 +703,7 @@ static int inspect_fw(void) memcpy(hdr->md5sum1, md5salt_normal, sizeof(md5sum)); else memcpy(hdr->md5sum1, md5salt_boot, sizeof(md5sum)); - get_md5(buf, inspect_info.file_size, (char*) hdr->md5sum1); + get_md5(buf, inspect_info.file_size, hdr->md5sum1); if (memcmp(md5sum, hdr->md5sum1, sizeof(md5sum))) { inspect_fw_pmd5sum("Header MD5Sum1", md5sum, "(*ERROR*)");