summaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2015-01-09 15:40:39 +0000
committerFelix Fietkau <nbd@openwrt.org>2015-01-09 15:40:39 +0000
commit265174ef489db9c4ddfb5ae3a3212bbb368fd079 (patch)
tree3e7d7a4d5ee28ca3e9af12f6dabdfa5076b6b102 /tools/firmware-utils
parent5cda3e9f7f2ca63853314f1b170889211a4900ae (diff)
downloadmaster-31e0f0ae-265174ef489db9c4ddfb5ae3a3212bbb368fd079.tar.gz
master-31e0f0ae-265174ef489db9c4ddfb5ae3a3212bbb368fd079.tar.bz2
master-31e0f0ae-265174ef489db9c4ddfb5ae3a3212bbb368fd079.zip
tools/firmware-utils: add version 3 header support for mktplinkfw2
Signed-off-by: Felix Fietkau <nbd@openwrt.org> SVN-Revision: 43897
Diffstat (limited to 'tools/firmware-utils')
-rw-r--r--tools/firmware-utils/src/mktplinkfw2.c51
1 files changed, 42 insertions, 9 deletions
diff --git a/tools/firmware-utils/src/mktplinkfw2.c b/tools/firmware-utils/src/mktplinkfw2.c
index df64ac3a86..34c4b14064 100644
--- a/tools/firmware-utils/src/mktplinkfw2.c
+++ b/tools/firmware-utils/src/mktplinkfw2.c
@@ -20,6 +20,8 @@
#include <getopt.h> /* for getopt() */
#include <stdarg.h>
#include <errno.h>
+#include <stdbool.h>
+#include <endian.h>
#include <sys/stat.h>
#include <arpa/inet.h>
@@ -29,10 +31,6 @@
#define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
-#define HEADER_VERSION_V2 0x02000000
-
-#define HWID_TD_W8970_V1 0x89700001
-
#define MD5SUM_LEN 16
struct file_info {
@@ -83,6 +81,8 @@ struct board_info {
uint32_t hw_id;
uint32_t hw_rev;
char *layout_id;
+ uint32_t hdr_ver;
+ bool endian_swap;
};
/*
@@ -94,6 +94,7 @@ static char *vendor = "TP-LINK Technologies";
static char *version = "ver. 1.0";
static char *fw_ver = "0.0.0";
static char *sver = "1.0";
+static uint32_t hdr_ver = 2;
static char *board_id;
static struct board_info *board;
@@ -123,6 +124,7 @@ static unsigned char jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde};
static struct file_info inspect_info;
static int extract = 0;
+static bool endian_swap = false;
char md5salt_normal[MD5SUM_LEN] = {
0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb,
@@ -142,6 +144,12 @@ static struct flash_layout layouts[] = {
.kernel_ep = 0x80002000,
.rootfs_ofs = 0x140000,
}, {
+ .id = "8Mmtk",
+ .fw_max_len = 0x7a0000,
+ .kernel_la = 0x80000000,
+ .kernel_ep = 0x80000000,
+ .rootfs_ofs = 0x140000,
+ }, {
/* terminating entry */
}
};
@@ -149,10 +157,17 @@ static struct flash_layout layouts[] = {
static struct board_info boards[] = {
{
.id = "TD-W8970v1",
- .hw_id = HWID_TD_W8970_V1,
+ .hw_id = 0x89700001,
.hw_rev = 1,
.layout_id = "8Mltq",
}, {
+ .id = "ArcherC20i",
+ .hw_id = 0xc2000001,
+ .hw_rev = 58,
+ .layout_id = "8Mmtk",
+ .hdr_ver = 3,
+ .endian_swap = true,
+ }, {
/* terminating entry */
}
};
@@ -339,6 +354,9 @@ static int check_options(void)
hw_id = board->hw_id;
hw_rev = board->hw_rev;
+ if (board->hdr_ver)
+ hdr_ver = board->hdr_ver;
+ endian_swap = board->endian_swap;
} else {
if (layout_id == NULL) {
ERR("flash layout is not specified");
@@ -446,7 +464,7 @@ static void fill_header(char *buf, int len)
memset(hdr, '\xff', sizeof(struct fw_header));
- hdr->version = htonl(HEADER_VERSION_V2);
+ hdr->version = htonl(bswap_32(hdr_ver));
ver_len = strlen(version);
if (ver_len > (sizeof(hdr->fw_version) - 1))
ver_len = sizeof(hdr->fw_version) - 1;
@@ -493,6 +511,11 @@ static void fill_header(char *buf, int len)
hdr->ver_mid = fw_ver_mid;
hdr->ver_lo = fw_ver_lo;
+ if (endian_swap) {
+ hdr->kernel_la = bswap_32(hdr->kernel_la);
+ hdr->kernel_ep = bswap_32(hdr->kernel_ep);
+ }
+
get_md5(buf, len, hdr->md5sum1);
}
@@ -708,8 +731,12 @@ 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_V2) {
- ERR("file does not seem to have V2 header!\n");
+ switch(bswap_32(ntohl(hdr->version))) {
+ case 2:
+ case 3:
+ break;
+ default:
+ ERR("file does not seem to have V2/V3 header!\n");
goto out_free_buf;
}
@@ -855,7 +882,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:");
+ c = getopt(argc, argv, "a:B:H:E:F:L:V:N:W:ci:k:r:R:o:xhsjv:y:T:e");
if (c == -1)
break;
@@ -920,6 +947,12 @@ int main(int argc, char *argv[])
case 'x':
extract = 1;
break;
+ case 'T':
+ hdr_ver = atoi(optarg);
+ break;
+ case 'e':
+ endian_swap = true;
+ break;
case 'h':
usage(EXIT_SUCCESS);
break;