aboutsummaryrefslogtreecommitdiffstats
path: root/package/utils/bcm4908img
diff options
context:
space:
mode:
authorRafał Miłecki <rafal@milecki.pl>2021-09-10 16:34:48 +0200
committerRafał Miłecki <rafal@milecki.pl>2021-12-13 14:33:06 +0100
commit2c1f27bf4bb2b2a90a326c2ae75ac5bdc6b47074 (patch)
tree0f2b96097bfc59ea324f9c76daee033f92f6cea4 /package/utils/bcm4908img
parent1d1c695273880d8da7f56be459b406ff550eb0ea (diff)
downloadupstream-2c1f27bf4bb2b2a90a326c2ae75ac5bdc6b47074.tar.gz
upstream-2c1f27bf4bb2b2a90a326c2ae75ac5bdc6b47074.tar.bz2
upstream-2c1f27bf4bb2b2a90a326c2ae75ac5bdc6b47074.zip
bcm4908img: detect Linksys images
Linksys uses an extra 0x100 bytes long tail for BCM4908 images. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> (cherry picked from commit c4d5e60f6115b9a97318774533ea764bf938c2a9)
Diffstat (limited to 'package/utils/bcm4908img')
-rw-r--r--package/utils/bcm4908img/Makefile2
-rw-r--r--package/utils/bcm4908img/src/bcm4908img.c22
2 files changed, 23 insertions, 1 deletions
diff --git a/package/utils/bcm4908img/Makefile b/package/utils/bcm4908img/Makefile
index ff504a8078..fbb91fba73 100644
--- a/package/utils/bcm4908img/Makefile
+++ b/package/utils/bcm4908img/Makefile
@@ -3,7 +3,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=bcm4908img
-PKG_RELEASE:=2
+PKG_RELEASE:=3
PKG_FLAGS:=nonshared
diff --git a/package/utils/bcm4908img/src/bcm4908img.c b/package/utils/bcm4908img/src/bcm4908img.c
index f2023ced9f..240fe895d9 100644
--- a/package/utils/bcm4908img/src/bcm4908img.c
+++ b/package/utils/bcm4908img/src/bcm4908img.c
@@ -77,6 +77,7 @@ struct bcm4908img_tail {
* 4. padding ├─ firmware
* 5. rootfs ─┘
* 6. BCM4908 tail
+ * 7. (Optional) vendor tail
*/
struct bcm4908img_info {
size_t cferom_offset;
@@ -249,6 +250,16 @@ struct chk_header {
char board_id[0];
};
+struct linksys_tail {
+ char magic[9];
+ uint8_t version[8];
+ char model[15];
+ uint32_t crc32;
+ uint8_t padding[9];
+ uint8_t signature[16];
+ uint8_t reserved[192];
+};
+
static bool bcm4908img_is_all_ff(const void *buf, size_t length)
{
const uint8_t *in = buf;
@@ -264,6 +275,7 @@ static bool bcm4908img_is_all_ff(const void *buf, size_t length)
static int bcm4908img_parse(FILE *fp, struct bcm4908img_info *info) {
struct bcm4908img_tail *tail = &info->tail;
+ struct linksys_tail *linksys;
struct chk_header *chk;
struct stat st;
uint8_t buf[1024];
@@ -297,6 +309,16 @@ static int bcm4908img_parse(FILE *fp, struct bcm4908img_info *info) {
if (be32_to_cpu(chk->magic) == 0x2a23245e)
info->cferom_offset = be32_to_cpu(chk->header_len);
+ fseek(fp, -sizeof(buf), SEEK_END);
+ if (fread(buf, 1, sizeof(buf), fp) != sizeof(buf)) {
+ fprintf(stderr, "Failed to read file header\n");
+ return -EIO;
+ }
+ linksys = (void *)(buf + sizeof(buf) - sizeof(*linksys));
+ if (!memcmp(linksys->magic, ".LINKSYS.", sizeof(linksys->magic))) {
+ info->tail_offset -= sizeof(*linksys);
+ }
+
/* Offsets */
for (info->bootfs_offset = info->cferom_offset;