Browse Source

firmware-utils: mktplinkfw2: support additional hardware version

As it turned out, some of new MediaTek based TP-Link devices use value
from field at 0x3c offset in version 3 of TP-Link header to specify
"Additional Hardware Version".

Value from this field is validated during regular (GUI) firmware upgrade
on devices like TL-WR840N v4 or TL-WR841N v13. If it's zero (based on
some tests, it seems that firmware will accept anything != 0), errors
like below are printed on console and upgrade fails:

[ rsl_sys_updateFirmware ] 2137:  Firmware Additional HardwareVersion
check failed

[ rdp_updateFirmware ] 345:  perror:4506

Signed-off-by: Piotr Dymacz <[email protected]>
Piotr Dymacz 8 years ago
parent
commit
4b35e174ca
1 changed files with 20 additions and 6 deletions
  1. 20 6
      tools/firmware-utils/src/mktplinkfw2.c

+ 20 - 6
tools/firmware-utils/src/mktplinkfw2.c

@@ -43,7 +43,7 @@ struct fw_header {
 	char		fw_version[48]; /* 0x04: fw version string */
 	uint32_t	hw_id;		/* 0x34: hardware id */
 	uint32_t	hw_rev;		/* 0x38: FIXME: hardware revision? */
-	uint32_t	unk1;	        /* 0x3c: 0x00000000 */
+	uint32_t	hw_ver_add;	/* 0x3c: additional hardware version */
 	uint8_t		md5sum1[MD5SUM_LEN]; /* 0x40 */
 	uint32_t	unk2;		/* 0x50: 0x00000000 */
 	uint8_t		md5sum2[MD5SUM_LEN]; /* 0x54 */
@@ -80,6 +80,7 @@ struct board_info {
 	char		*id;
 	uint32_t	hw_id;
 	uint32_t	hw_rev;
+	uint32_t	hw_ver_add;
 	char		*layout_id;
 	uint32_t	hdr_ver;
 	bool		endian_swap;
@@ -104,6 +105,8 @@ static char *opt_hw_id;
 static uint32_t hw_id;
 static char *opt_hw_rev;
 static uint32_t hw_rev;
+static char *opt_hw_ver_add;
+static uint32_t hw_ver_add;
 static int fw_ver_lo;
 static int fw_ver_mid;
 static int fw_ver_hi;
@@ -288,6 +291,7 @@ static void usage(int status)
 "  -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"
+"  -w <hwveradd>   use additional hardware version specified with <hwveradd>\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"
@@ -391,6 +395,7 @@ static int check_options(void)
 
 		hw_id = board->hw_id;
 		hw_rev = board->hw_rev;
+		hw_ver_add = board->hw_ver_add;
 		if (board->hdr_ver)
 			hdr_ver = board->hdr_ver;
 		endian_swap = board->endian_swap;
@@ -405,6 +410,11 @@ static int check_options(void)
 			hw_rev = strtoul(opt_hw_rev, NULL, 0);
 		else
 			hw_rev = 1;
+
+		if (opt_hw_ver_add)
+			hw_ver_add = strtoul(opt_hw_rev, NULL, 0);
+		else
+			hw_ver_add = 0;
 	}
 
 	layout = find_layout(layout_id);
@@ -511,6 +521,7 @@ static void fill_header(char *buf, int len)
 
 	hdr->hw_id = htonl(hw_id);
 	hdr->hw_rev = htonl(hw_rev);
+	hdr->hw_ver_add = htonl(hw_ver_add);
 
 	if (boot_info.file_size == 0) {
 		memcpy(hdr->md5sum1, md5salt_normal, sizeof(hdr->md5sum1));
@@ -535,7 +546,6 @@ static void fill_header(char *buf, int len)
 	hdr->boot_ofs = htonl(0);
 	hdr->boot_len = htonl(boot_info.file_size);
 
-	hdr->unk1 = htonl(0);
 	hdr->unk2 = htonl(0);
 	hdr->unk3 = htonl(0xffffffff);
 	hdr->unk4 = htons(0x55aa);
@@ -779,9 +789,6 @@ static int inspect_fw(void)
 
 	inspect_fw_phexdec("Version 2 Header size", sizeof(struct fw_header));
 
-	if (ntohl(hdr->unk1) != 0)
-		inspect_fw_phexdec("Unknown value 1", hdr->unk1);
-
 	memcpy(md5sum, hdr->md5sum1, sizeof(md5sum));
 	if (ntohl(hdr->boot_len) == 0)
 		memcpy(hdr->md5sum1, md5salt_normal, sizeof(md5sum));
@@ -820,11 +827,15 @@ static int inspect_fw(void)
 		                    ntohl(hdr->hw_id), board->id);
 		inspect_fw_phexexp("Hardware Revision",
 		                   ntohl(hdr->hw_rev), board->hw_rev);
+		inspect_fw_phexexp("Additional HW Version",
+		                   ntohl(hdr->hw_ver_add), board->hw_ver_add);
 	} else {
 		inspect_fw_phexpost("Hardware ID",
 		                    ntohl(hdr->hw_id), "unknown");
 		inspect_fw_phex("Hardware Revision",
 		                ntohl(hdr->hw_rev));
+		inspect_fw_phex("Additional HW Version",
+		                ntohl(hdr->hw_ver_add));
 	}
 
 	printf("%-23s: %d.%d.%d-%d.%d\n", "Software version",
@@ -919,7 +930,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:y:T:e");
+		c = getopt(argc, argv, "a:B:H:E:F:L:V:N:W:w:ci:k:r:R:o:xhsjv:y:T:e");
 		if (c == -1)
 			break;
 
@@ -942,6 +953,9 @@ int main(int argc, char *argv[])
 		case 'W':
 			opt_hw_rev = optarg;
 			break;
+		case 'w':
+			opt_hw_ver_add = optarg;
+			break;
 		case 'L':
 			sscanf(optarg, "0x%x", &kernel_la);
 			break;