[PATCH firmware-utils v1 10/10] tplink-safeloader: add Cloud image detection

Sander Vanheule sander at svanheule.net
Fri Feb 3 14:03:24 PST 2023


The vendor info in the safeloader header for some images (e.g. Archer
C60 v3) starts with "fw-type:Cloud" instead of a big endian data length.

Only detection is implemented at this moment, as the full header format
is not yet understood.

Signed-off-by: Sander Vanheule <sander at svanheule.net>
---
 src/tplink-safeloader.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/tplink-safeloader.c b/src/tplink-safeloader.c
index 71dfe7910dbb..f39e7fe15f2a 100644
--- a/src/tplink-safeloader.c
+++ b/src/tplink-safeloader.c
@@ -143,6 +143,11 @@ struct __attribute__((__packed__)) soft_version {
  *   UINT32 size, followed by that number of bytes containing (text) data.
  *   Padded with 0xFF. Payload starts at offset 0x1014.
  *
+ * SAFELOADER_TYPE_CLOUD
+ *   Standard preamble with size including preamble length, and checksum.
+ *   Followed by the 'fw-type:Cloud' string and some (unknown) data.
+ *   Payload starts at offset 0x1014.
+ *
  * SAFELOADER_TYPE_QNEW
  *   Reversed order preamble, with (apparent) md5 checksum before the image
  *   size. The size does not include the preamble length.
@@ -153,6 +158,7 @@ struct __attribute__((__packed__)) soft_version {
 enum safeloader_image_type {
 	SAFELOADER_TYPE_DEFAULT,
 	SAFELOADER_TYPE_VENDOR,
+	SAFELOADER_TYPE_CLOUD,
 	SAFELOADER_TYPE_QNEW,
 };
 
@@ -3858,6 +3864,7 @@ static void safeloader_read_partition(FILE *input_file, size_t payload_offset,
 
 static void safeloader_parse_image(FILE *input_file, struct safeloader_image_info *image)
 {
+	static const char *HEADER_ID_CLOUD = "fw-type:Cloud";
 	static const char *HEADER_ID_QNEW = "?NEW";
 
 	char buf[64];
@@ -3872,6 +3879,8 @@ static void safeloader_parse_image(FILE *input_file, struct safeloader_image_inf
 
 	if (memcmp(HEADER_ID_QNEW, &buf[0], strlen(HEADER_ID_QNEW)) == 0)
 		image->type = SAFELOADER_TYPE_QNEW;
+	else if (memcmp(HEADER_ID_CLOUD, &buf[0], strlen(HEADER_ID_CLOUD)) == 0)
+		image->type = SAFELOADER_TYPE_CLOUD;
 	else if (ntohl(*((uint32_t *) &buf[0])) <= SAFELOADER_HEADER_SIZE)
 		image->type = SAFELOADER_TYPE_VENDOR;
 	else
@@ -3880,6 +3889,7 @@ static void safeloader_parse_image(FILE *input_file, struct safeloader_image_inf
 	switch (image->type) {
 	case SAFELOADER_TYPE_DEFAULT:
 	case SAFELOADER_TYPE_VENDOR:
+	case SAFELOADER_TYPE_CLOUD:
 		image->payload_offset = SAFELOADER_PAYLOAD_OFFSET;
 		break;
 	case SAFELOADER_TYPE_QNEW:
-- 
2.39.0




More information about the openwrt-devel mailing list