projects
/
openwrt
/
staging
/
mkresin.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
firmware-utils: mkfwimage: fix firmware_max_length for XM layout
[openwrt/staging/mkresin.git]
/
tools
/
firmware-utils
/
src
/
mktplinkfw.c
diff --git
a/tools/firmware-utils/src/mktplinkfw.c
b/tools/firmware-utils/src/mktplinkfw.c
index 09536c64271406573601bc0a0f5c20bacf0333fa..9fd5e3830a4b1ec059d492d22c5877edd8ffdbdc 100644
(file)
--- a/
tools/firmware-utils/src/mktplinkfw.c
+++ b/
tools/firmware-utils/src/mktplinkfw.c
@@
-30,9
+30,12
@@
#define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
#define HEADER_VERSION_V1 0x01000000
#define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
#define HEADER_VERSION_V1 0x01000000
-#define HWID_ANTMINER_S1 0x04440001
+#define HEADER_VERSION_V2 0x02000000
+#define HWID_ANTMINER_S1 0x04440101
+#define HWID_ANTMINER_S3 0x04440301
#define HWID_GL_INET_V1 0x08000001
#define HWID_GS_OOLITE_V1 0x3C000101
#define HWID_GL_INET_V1 0x08000001
#define HWID_GS_OOLITE_V1 0x3C000101
+#define HWID_ONION_OMEGA 0x04700001
#define HWID_TL_MR10U_V1 0x00100101
#define HWID_TL_MR13U_V1 0x00130101
#define HWID_TL_MR3020_V1 0x30200001
#define HWID_TL_MR10U_V1 0x00100101
#define HWID_TL_MR13U_V1 0x00130101
#define HWID_TL_MR3020_V1 0x30200001
@@
-48,6
+51,7
@@
#define HWID_TL_WA830RE_V1 0x08300010
#define HWID_TL_WA830RE_V2 0x08300002
#define HWID_TL_WA801ND_V2 0x08010002
#define HWID_TL_WA830RE_V1 0x08300010
#define HWID_TL_WA830RE_V2 0x08300002
#define HWID_TL_WA801ND_V2 0x08010002
+#define HWID_TL_WA801ND_V3 0x08010003
#define HWID_TL_WA901ND_V1 0x09010001
#define HWID_TL_WA901ND_V2 0x09010002
#define HWID_TL_WDR4300_V1_IL 0x43008001
#define HWID_TL_WA901ND_V1 0x09010001
#define HWID_TL_WA901ND_V2 0x09010002
#define HWID_TL_WDR4300_V1_IL 0x43008001
@@
-128,6
+132,7
@@
static char *progname;
static char *vendor = "TP-LINK Technologies";
static char *version = "ver. 1.0";
static char *fw_ver = "0.0.0";
static char *vendor = "TP-LINK Technologies";
static char *version = "ver. 1.0";
static char *fw_ver = "0.0.0";
+static uint32_t hdr_ver = HEADER_VERSION_V1;
static char *board_id;
static struct board_info *board;
static char *board_id;
static struct board_info *board;
@@
-137,6
+142,7
@@
static char *opt_hw_id;
static uint32_t hw_id;
static char *opt_hw_rev;
static uint32_t hw_rev;
static uint32_t hw_id;
static char *opt_hw_rev;
static uint32_t hw_rev;
+static uint32_t opt_hdr_ver = 1;
static int fw_ver_lo;
static int fw_ver_mid;
static int fw_ver_hi;
static int fw_ver_lo;
static int fw_ver_mid;
static int fw_ver_hi;
@@
-293,6
+299,11
@@
static struct board_info boards[] = {
.hw_id = HWID_TL_WA801ND_V2,
.hw_rev = 1,
.layout_id = "4Mlzma",
.hw_id = HWID_TL_WA801ND_V2,
.hw_rev = 1,
.layout_id = "4Mlzma",
+ },{
+ .id = "TL-WA801NDv3",
+ .hw_id = HWID_TL_WA801ND_V3,
+ .hw_rev = 1,
+ .layout_id = "4Mlzma",
}, {
.id = "TL-WA901NDv1",
.hw_id = HWID_TL_WA901ND_V1,
}, {
.id = "TL-WA901NDv1",
.hw_id = HWID_TL_WA901ND_V1,
@@
-418,11
+429,21
@@
static struct board_info boards[] = {
.hw_id = HWID_GS_OOLITE_V1,
.hw_rev = 1,
.layout_id = "16Mlzma",
.hw_id = HWID_GS_OOLITE_V1,
.hw_rev = 1,
.layout_id = "16Mlzma",
+ }, {
+ .id = "ONION-OMEGA",
+ .hw_id = HWID_ONION_OMEGA,
+ .hw_rev = 1,
+ .layout_id = "16Mlzma",
}, {
.id = "ANTMINER-S1",
.hw_id = HWID_ANTMINER_S1,
.hw_rev = 1,
.layout_id = "8Mlzma",
}, {
.id = "ANTMINER-S1",
.hw_id = HWID_ANTMINER_S1,
.hw_rev = 1,
.layout_id = "8Mlzma",
+ }, {
+ .id = "ANTMINER-S3",
+ .hw_id = HWID_ANTMINER_S3,
+ .hw_rev = 1,
+ .layout_id = "8Mlzma",
}, {
/* terminating entry */
}
}, {
/* terminating entry */
}
@@
-440,7
+461,7
@@
static struct board_info boards[] = {
#define ERRS(fmt, ...) do { \
int save = errno; \
fflush(0); \
#define ERRS(fmt, ...) do { \
int save = errno; \
fflush(0); \
- fprintf(stderr, "[%s] *** error: " fmt "\n", \
+ fprintf(stderr, "[%s] *** error: " fmt "
: %s
\n", \
progname, ## __VA_ARGS__, strerror(save)); \
} while (0)
progname, ## __VA_ARGS__, strerror(save)); \
} while (0)
@@
-519,6
+540,7
@@
static void usage(int status)
" -N <vendor> set image vendor to <vendor>\n"
" -V <version> set image version to <version>\n"
" -v <version> set firmware version to <version>\n"
" -N <vendor> set image vendor to <vendor>\n"
" -V <version> set image version to <version>\n"
" -v <version> set firmware version to <version>\n"
+" -m <version> set header version to <version>\n"
" -i <file> inspect given firmware file <file>\n"
" -x extract kernel and rootfs while inspecting (requires -i)\n"
" -X <size> reserve <size> bytes in the firmware image (hexval prefixed with 0x)\n"
" -i <file> inspect given firmware file <file>\n"
" -x extract kernel and rootfs while inspecting (requires -i)\n"
" -X <size> reserve <size> bytes in the firmware image (hexval prefixed with 0x)\n"
@@
-584,6
+606,7
@@
static int read_to_buf(struct file_info *fdata, char *buf)
static int check_options(void)
{
int ret;
static int check_options(void)
{
int ret;
+ int exceed_bytes;
if (inspect_info.file_name) {
ret = get_file_stat(&inspect_info);
if (inspect_info.file_name) {
ret = get_file_stat(&inspect_info);
@@
-657,10
+680,10
@@
static int check_options(void)
kernel_len = kernel_info.file_size;
if (combined) {
kernel_len = kernel_info.file_size;
if (combined) {
- if (kernel_info.file_size >
-
fw_max_len - sizeof(struct fw_header)
) {
+ exceed_bytes = kernel_info.file_size - (fw_max_len - sizeof(struct fw_header));
+
if (exceed_bytes > 0
) {
if (!ignore_size) {
if (!ignore_size) {
- ERR("kernel image is too big
"
);
+ ERR("kernel image is too big
by %i bytes", exceed_bytes
);
return -1;
}
layout->fw_max_len = sizeof(struct fw_header) +
return -1;
}
layout->fw_max_len = sizeof(struct fw_header) +
@@
-684,21
+707,21
@@
static int check_options(void)
DBG("kernel length aligned to %u", kernel_len);
DBG("kernel length aligned to %u", kernel_len);
- if (kernel_len + rootfs_info.file_size >
-
fw_max_len - sizeof(struct fw_header)
) {
- ERR("images are too big
"
);
+ exceed_bytes = kernel_len + rootfs_info.file_size - (fw_max_len - sizeof(struct fw_header));
+
if (exceed_bytes > 0
) {
+ ERR("images are too big
by %i bytes", exceed_bytes
);
return -1;
}
} else {
return -1;
}
} else {
- if (kernel_info.file_size >
-
rootfs_ofs - sizeof(struct fw_header)
) {
- ERR("kernel image is too big
"
);
+ exceed_bytes = kernel_info.file_size - (rootfs_ofs - sizeof(struct fw_header));
+
if (exceed_bytes > 0
) {
+ ERR("kernel image is too big
by %i bytes", exceed_bytes
);
return -1;
}
return -1;
}
- if (rootfs_info.file_size >
-
(fw_max_len - rootfs_ofs)
) {
- ERR("rootfs image is too big
"
);
+ exceed_bytes = rootfs_info.file_size - (fw_max_len - rootfs_ofs);
+
if (exceed_bytes > 0
) {
+ ERR("rootfs image is too big
by %i bytes", exceed_bytes
);
return -1;
}
}
return -1;
}
}
@@
-715,6
+738,15
@@
static int check_options(void)
return -1;
}
return -1;
}
+ if (opt_hdr_ver == 1) {
+ hdr_ver = HEADER_VERSION_V1;
+ } else if (opt_hdr_ver == 2) {
+ hdr_ver = HEADER_VERSION_V2;
+ } else {
+ ERR("invalid header version '%u'", opt_hdr_ver);
+ return -1;
+ }
+
return 0;
}
return 0;
}
@@
-724,7
+756,7
@@
static void fill_header(char *buf, int len)
memset(hdr, 0, sizeof(struct fw_header));
memset(hdr, 0, sizeof(struct fw_header));
- hdr->version = htonl(
HEADER_VERSION_V1
);
+ hdr->version = htonl(
hdr_ver
);
strncpy(hdr->vendor_name, vendor, sizeof(hdr->vendor_name));
strncpy(hdr->fw_version, version, sizeof(hdr->fw_version));
hdr->hw_id = htonl(hw_id);
strncpy(hdr->vendor_name, vendor, sizeof(hdr->vendor_name));
strncpy(hdr->fw_version, version, sizeof(hdr->fw_version));
hdr->hw_id = htonl(hw_id);
@@
-964,8
+996,9
@@
static int inspect_fw(void)
inspect_fw_pstr("File name", inspect_info.file_name);
inspect_fw_phexdec("File size", inspect_info.file_size);
inspect_fw_pstr("File name", inspect_info.file_name);
inspect_fw_phexdec("File size", inspect_info.file_size);
- if (ntohl(hdr->version) != HEADER_VERSION_V1) {
- ERR("file does not seem to have V1 header!\n");
+ if ((ntohl(hdr->version) != HEADER_VERSION_V1) &&
+ (ntohl(hdr->version) != HEADER_VERSION_V2)) {
+ ERR("file does not seem to have V1/V2 header!\n");
goto out_free_buf;
}
goto out_free_buf;
}
@@
-1100,7
+1133,7
@@
int main(int argc, char *argv[])
while ( 1 ) {
int c;
while ( 1 ) {
int c;
- c = getopt(argc, argv, "a:B:H:E:F:L:V:N:W:ci:k:r:R:o:xX:hsSjv:");
+ c = getopt(argc, argv, "a:B:H:E:F:L:
m:
V:N:W:ci:k:r:R:o:xX:hsSjv:");
if (c == -1)
break;
if (c == -1)
break;
@@
-1126,6
+1159,9
@@
int main(int argc, char *argv[])
case 'L':
sscanf(optarg, "0x%x", &kernel_la);
break;
case 'L':
sscanf(optarg, "0x%x", &kernel_la);
break;
+ case 'm':
+ sscanf(optarg, "%u", &opt_hdr_ver);
+ break;
case 'V':
version = optarg;
break;
case 'V':
version = optarg;
break;
@@
-1189,4
+1225,3
@@
int main(int argc, char *argv[])
out:
return ret;
}
out:
return ret;
}
-