tools/firmware-utils: add version 3 header support for mktplinkfw2
Signed-off-by: Felix Fietkau <nbd@openwrt.org> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@43897 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
2d5407a0c6
commit
d19b95492f
1 changed files with 42 additions and 9 deletions
|
@ -20,6 +20,8 @@
|
||||||
#include <getopt.h> /* for getopt() */
|
#include <getopt.h> /* for getopt() */
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <endian.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
@ -29,10 +31,6 @@
|
||||||
|
|
||||||
#define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
|
#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
|
#define MD5SUM_LEN 16
|
||||||
|
|
||||||
struct file_info {
|
struct file_info {
|
||||||
|
@ -83,6 +81,8 @@ struct board_info {
|
||||||
uint32_t hw_id;
|
uint32_t hw_id;
|
||||||
uint32_t hw_rev;
|
uint32_t hw_rev;
|
||||||
char *layout_id;
|
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 *version = "ver. 1.0";
|
||||||
static char *fw_ver = "0.0.0";
|
static char *fw_ver = "0.0.0";
|
||||||
static char *sver = "1.0";
|
static char *sver = "1.0";
|
||||||
|
static uint32_t hdr_ver = 2;
|
||||||
|
|
||||||
static char *board_id;
|
static char *board_id;
|
||||||
static struct board_info *board;
|
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 struct file_info inspect_info;
|
||||||
static int extract = 0;
|
static int extract = 0;
|
||||||
|
static bool endian_swap = false;
|
||||||
|
|
||||||
char md5salt_normal[MD5SUM_LEN] = {
|
char md5salt_normal[MD5SUM_LEN] = {
|
||||||
0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb,
|
0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb,
|
||||||
|
@ -141,6 +143,12 @@ static struct flash_layout layouts[] = {
|
||||||
.kernel_la = 0x80002000,
|
.kernel_la = 0x80002000,
|
||||||
.kernel_ep = 0x80002000,
|
.kernel_ep = 0x80002000,
|
||||||
.rootfs_ofs = 0x140000,
|
.rootfs_ofs = 0x140000,
|
||||||
|
}, {
|
||||||
|
.id = "8Mmtk",
|
||||||
|
.fw_max_len = 0x7a0000,
|
||||||
|
.kernel_la = 0x80000000,
|
||||||
|
.kernel_ep = 0x80000000,
|
||||||
|
.rootfs_ofs = 0x140000,
|
||||||
}, {
|
}, {
|
||||||
/* terminating entry */
|
/* terminating entry */
|
||||||
}
|
}
|
||||||
|
@ -149,9 +157,16 @@ static struct flash_layout layouts[] = {
|
||||||
static struct board_info boards[] = {
|
static struct board_info boards[] = {
|
||||||
{
|
{
|
||||||
.id = "TD-W8970v1",
|
.id = "TD-W8970v1",
|
||||||
.hw_id = HWID_TD_W8970_V1,
|
.hw_id = 0x89700001,
|
||||||
.hw_rev = 1,
|
.hw_rev = 1,
|
||||||
.layout_id = "8Mltq",
|
.layout_id = "8Mltq",
|
||||||
|
}, {
|
||||||
|
.id = "ArcherC20i",
|
||||||
|
.hw_id = 0xc2000001,
|
||||||
|
.hw_rev = 58,
|
||||||
|
.layout_id = "8Mmtk",
|
||||||
|
.hdr_ver = 3,
|
||||||
|
.endian_swap = true,
|
||||||
}, {
|
}, {
|
||||||
/* terminating entry */
|
/* terminating entry */
|
||||||
}
|
}
|
||||||
|
@ -339,6 +354,9 @@ static int check_options(void)
|
||||||
|
|
||||||
hw_id = board->hw_id;
|
hw_id = board->hw_id;
|
||||||
hw_rev = board->hw_rev;
|
hw_rev = board->hw_rev;
|
||||||
|
if (board->hdr_ver)
|
||||||
|
hdr_ver = board->hdr_ver;
|
||||||
|
endian_swap = board->endian_swap;
|
||||||
} else {
|
} else {
|
||||||
if (layout_id == NULL) {
|
if (layout_id == NULL) {
|
||||||
ERR("flash layout is not specified");
|
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));
|
memset(hdr, '\xff', sizeof(struct fw_header));
|
||||||
|
|
||||||
hdr->version = htonl(HEADER_VERSION_V2);
|
hdr->version = htonl(bswap_32(hdr_ver));
|
||||||
ver_len = strlen(version);
|
ver_len = strlen(version);
|
||||||
if (ver_len > (sizeof(hdr->fw_version) - 1))
|
if (ver_len > (sizeof(hdr->fw_version) - 1))
|
||||||
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_mid = fw_ver_mid;
|
||||||
hdr->ver_lo = fw_ver_lo;
|
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);
|
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_pstr("File name", inspect_info.file_name);
|
||||||
inspect_fw_phexdec("File size", inspect_info.file_size);
|
inspect_fw_phexdec("File size", inspect_info.file_size);
|
||||||
|
|
||||||
if (ntohl(hdr->version) != HEADER_VERSION_V2) {
|
switch(bswap_32(ntohl(hdr->version))) {
|
||||||
ERR("file does not seem to have V2 header!\n");
|
case 2:
|
||||||
|
case 3:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ERR("file does not seem to have V2/V3 header!\n");
|
||||||
goto out_free_buf;
|
goto out_free_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -855,7 +882,7 @@ int main(int argc, char *argv[])
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
int c;
|
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)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -920,6 +947,12 @@ int main(int argc, char *argv[])
|
||||||
case 'x':
|
case 'x':
|
||||||
extract = 1;
|
extract = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'T':
|
||||||
|
hdr_ver = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
endian_swap = true;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(EXIT_SUCCESS);
|
usage(EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue