From patchwork Sun Jan 22 21:36:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_B=C3=B6hler?= X-Patchwork-Id: 1730200 X-Patchwork-Delegate: sander@svanheule.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=To61h/NX; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=aboehler.at header.i=@aboehler.at header.a=rsa-sha256 header.s=default header.b=IoyHlXm4; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P0RVZ6JxBz23hB for ; Mon, 23 Jan 2023 08:40:37 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=lT8UtZRc366aYCycJa0E07O2Q8m1Ycs2Aw59qWc6jS4=; b=To61h/NXRAGOxI BIZL6TZyuqMwilQ10C+O321Bu2hv4/c6VL3gI2qsUI5JdQyucKyJp3nP+e0zlYt7tbLJjOOlRrIaT Ls3Fe7JtaEhMIkGbtPKgbW7T4Gzla3g03CCK1t0nLOzaQNlUlj+E19adxPiBvxU6RpWa3MV4TyN1b GTwTTTWgD2JEjP7BqkCL4iW+jMFPkA/dfwQKeK5NWFFtEQn9u53+1ZKAy9eOhyb8y6EnxZMUnKA9h VdPVAEFD1Y1OseAyNoXO/BqxVzJN32A1PYW0nxX+LxY8LkVfDtYB1H5V161NCl2YUYQMA70bE/j2G HrRZfK86c+aKkVt69TpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJi1p-00Fo73-Ud; Sun, 22 Jan 2023 21:37:30 +0000 Received: from mail.aboehler.at ([2a01:4f8:121:5012::2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJi1l-00Fo5R-5t for openwrt-devel@lists.openwrt.org; Sun, 22 Jan 2023 21:37:27 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.aboehler.at (Postfix) with ESMTP id D3A1F3CC029C for ; Sun, 22 Jan 2023 22:37:17 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aboehler.at Received: from mail.aboehler.at ([127.0.0.1]) by localhost (aboehler.at [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vP75Z7n6B7WE; Sun, 22 Jan 2023 22:37:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aboehler.at; s=default; t=1674423437; bh=LBgNmmkYtHUgZB3uANZDMJGgM+yzf2szPY1wn9//GT4=; h=From:To:Cc:Subject:Date:From; b=IoyHlXm4PYHBM6jPEYZNDNLYCFzDYT5TtRamyqdsm90sn4AyaMvBXIs5W2PoALIT5 +hH2CC8MBVMTaLMVSwbN4I4Jzbyl1p7bxa5olM1Oo28MX6nTg1H6GVtigYP8HVQXuS Y/SYbXJgKr5qXiIqwlhCA+Qiz15IVzfKeRYcImgg= Received: from x390y.lan (213-240-119-125.adsl.highway.telekom.at [213.240.119.125]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: andreas@aboehler.at) by mail.aboehler.at (Postfix) with ESMTPSA id 194EE3CC029A; Sun, 22 Jan 2023 22:37:17 +0100 (CET) From: =?utf-8?q?Andreas_B=C3=B6hler?= To: openwrt-devel@lists.openwrt.org Cc: =?utf-8?q?Andreas_B=C3=B6hler?= Subject: [PATCH] firmware-utils: tplink-safeloader: Add alternative partition table offset Date: Sun, 22 Jan 2023 22:36:59 +0100 Message-Id: <20230122213659.55793-1-dev@aboehler.at> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230122_133725_728294_C81487B6 X-CRM114-Status: UNSURE ( 9.75 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org 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 --- 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,