[LEDE-DEV] [PATCH] firmware-utils: mktplinkfw2: update firmware header

Rafał Miłecki zajec5 at gmail.com
Sun Jul 2 04:29:26 PDT 2017


From: Rafał Miłecki <rafal at milecki.pl>

1) Be consistent and use tabs
2) Drop FIXME from boot comments - some images use these fields normally
3) Add V3 specific fields (signatures)
4) Add V3.0.0.3 region field

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 tools/firmware-utils/src/mktplinkfw2.c | 75 ++++++++++++++++++++++------------
 1 file changed, 48 insertions(+), 27 deletions(-)

diff --git a/tools/firmware-utils/src/mktplinkfw2.c b/tools/firmware-utils/src/mktplinkfw2.c
index 3ab5c52ec2..cfedf81d3b 100644
--- a/tools/firmware-utils/src/mktplinkfw2.c
+++ b/tools/firmware-utils/src/mktplinkfw2.c
@@ -39,33 +39,54 @@ struct file_info {
 };
 
 struct fw_header {
-	uint32_t	version;	/* 0x00: header version */
-	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 */
-	uint8_t		md5sum1[MD5SUM_LEN]; /* 0x40 */
-	uint32_t	unk2;		/* 0x50: 0x00000000 */
-	uint8_t		md5sum2[MD5SUM_LEN]; /* 0x54 */
-	uint32_t	unk3;		/* 0x64: 0xffffffff */
-
-	uint32_t	kernel_la;	/* 0x68: kernel load address */
-	uint32_t	kernel_ep;	/* 0x6c: kernel entry point */
-	uint32_t	fw_length;	/* 0x70: total length of the image */
-	uint32_t	kernel_ofs;	/* 0x74: kernel data offset */
-	uint32_t	kernel_len;	/* 0x78: kernel data length */
-	uint32_t	rootfs_ofs;	/* 0x7c: rootfs data offset */
-	uint32_t	rootfs_len;	/* 0x80: rootfs data length */
-	uint32_t	boot_ofs;	/* 0x84: FIXME: seems to be unused */
-	uint32_t	boot_len;	/* 0x88: FIXME: seems to be unused */
-	uint16_t	unk4;		/* 0x8c: 0x55aa */
-	uint8_t		sver_hi;	/* 0x8e */
-	uint8_t		sver_lo;	/* 0x8f */
-	uint8_t		unk5;		/* 0x90: magic: 0xa5 */
-	uint8_t		ver_hi;         /* 0x91 */
-	uint8_t		ver_mid;        /* 0x92 */
-	uint8_t		ver_lo;         /* 0x93 */
-	uint8_t		pad[364];
+	uint32_t	version;			/* 0x00: header version */
+	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 */
+	uint8_t		md5sum1[MD5SUM_LEN];		/* 0x40 */
+	uint32_t	unk2;				/* 0x50: 0x00000000 */
+	uint8_t		md5sum2[MD5SUM_LEN];		/* 0x54 */
+	uint32_t	unk3;				/* 0x64: 0xffffffff */
+
+	uint32_t	kernel_la;			/* 0x68: kernel load address */
+	uint32_t	kernel_ep;			/* 0x6c: kernel entry point */
+	uint32_t	fw_length;			/* 0x70: total length of the image */
+	uint32_t	kernel_ofs;			/* 0x74: kernel data offset */
+	uint32_t	kernel_len;			/* 0x78: kernel data length */
+	uint32_t	rootfs_ofs;			/* 0x7c: rootfs data offset */
+	uint32_t	rootfs_len;			/* 0x80: rootfs data length */
+	uint32_t	boot_ofs;			/* 0x84: bootloader offset */
+	uint32_t	boot_len;			/* 0x88: bootloader length */
+	uint16_t	unk4;				/* 0x8c: 0x55aa */
+	uint8_t		sver_hi;			/* 0x8e */
+	uint8_t		sver_lo;			/* 0x8f */
+	uint8_t		unk5;				/* 0x90: magic: 0xa5 */
+	uint8_t		ver_hi;				/* 0x91 */
+	uint8_t		ver_mid;			/* 0x92 */
+	uint8_t		ver_lo;				/* 0x93 */
+	union {
+		struct {
+			uint8_t		pad[364];
+		} v2 __attribute__ ((packed));
+
+		struct {
+			uint32_t	unk6;		/* 0x94: FIXME: changing value */
+			uint8_t		pad1[56];
+			uint8_t		sig1[128];	/* 0xd0: signature (boot)+kernel+rootfs */
+			uint8_t		sig2[128];	/* 0x150: unused: 0x00 */
+			uint8_t		pad2[48];
+		} v3 __attribute__ ((packed));
+
+		struct {
+			uint32_t	unk6;		/* 0x94: FIXME: changing value */
+			char		region[4];	/* 0x98: region (e.g. "DE\0\0" or "US\0\0") */
+			uint8_t		pad1[52];
+			uint8_t		sig1[128];	/* 0xd0: signature (boot)+kernel+rootfs */
+			uint8_t		sig2[128];	/* 0x150: unused: 0x00 */
+			uint8_t		pad2[48];
+		} v3_0_0_3 __attribute__ ((packed));
+	} __attribute__ ((packed));
 } __attribute__ ((packed));
 
 struct flash_layout {
-- 
2.11.0




More information about the Lede-dev mailing list