[PATCH] firmware-utils: tplink-safeloader: Add alternative partition table offset

Andreas Böhler dev at aboehler.at
Sun Jan 22 13:36:59 PST 2023


Some newer OEM firmware files, even for existing devices, have the
fwup-ptn at offset 0x1050 instead of 0x1014. If the fwup-ptn header is not
found at 0x1014, the alternative offset at 0x1050 is tried.

Signed-off-by: Andreas Böhler <dev at aboehler.at>
---
 src/tplink-safeloader.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/tplink-safeloader.c b/src/tplink-safeloader.c
index ddb5dff..5bf62f3 100644
--- a/src/tplink-safeloader.c
+++ b/src/tplink-safeloader.c
@@ -3987,6 +3987,7 @@ static void convert_firmware(const char *input, const char *output)
 	struct flash_partition_entry *flash_os_image = NULL, *flash_file_system = NULL;
 	struct flash_partition_entry *fwup_partition_table = NULL;
 	size_t firmware_offset = 0x1014;
+	size_t firmware_offset_alt = 0x1050;
 	FILE *input_file, *output_file;
 
 	struct stat statbuf;
@@ -4005,7 +4006,12 @@ static void convert_firmware(const char *input, const char *output)
 		error(1, 0, "Can not open output firmware %s", output);
 
 	if (read_partition_table(input_file, firmware_offset, fwup, MAX_PARTITIONS, 0) != 0) {
-		error(1, 0, "Error can not read the partition table (fwup-ptn)");
+		fprintf(stderr, "DEBUG: can not find partition table at 0x%lx, trying alternative location at 0x%lx\n",
+				firmware_offset, firmware_offset_alt);
+		firmware_offset = firmware_offset_alt;
+		if (read_partition_table(input_file, firmware_offset, fwup, MAX_PARTITIONS, 0) != 0) {
+			error(1, 0, "Error can not read the partition table (fwup-ptn)");
+		}
 	}
 
 	fwup_os_image = find_partition(fwup, MAX_PARTITIONS,
-- 
2.38.1




More information about the openwrt-devel mailing list