From patchwork Mon May 2 16:24:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Richard via openwrt-devel X-Patchwork-Id: 1625203 X-Patchwork-Delegate: sander@svanheule.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=ZHt/y4Ah; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KsTBx4pc7z9sFs for ; Tue, 3 May 2022 02:32:08 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type:List-Help: Reply-To:List-Archive:List-Unsubscribe:List-Subscribe:From:List-Post:List-Id: Message-ID:MIME-Version:Date:Subject:To:Cc:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=BOrZ+m42e4JyER9Ctd1pIp80wWWiCZYkNY1D3/KiZAw=; b=ZHt/y4AhixchvkhFCzCYSdE70y 63jTclVXzNM/d1Rm3v7IIvkoyMMEDB1fAb9W6cMw3TkQulF7fStz+DIYVGkA5CFIcTK+4pKwfJylU 8kPyhX0s0FHW8bsTBemEAI0q1ByazTu8BvvX0SU7K3J+TBJP5BHh22tMRhGqr4C7df6NHwybeoG5b ECEagYUA99zUKCpYx/mnoarA6cCZ1QHMWwKQASUMy+61Wc49zBUlXDPopjy5XE458zpOEQyw0RY1d RR46RK1tUExqKDzl2s89r/z46NHPzcoYA37qnWPFK3WuVo8h0talW0+P7YMfiTw3ed/kMLy1k6Pst /tMoxiFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nlYqz-001has-I5; Mon, 02 May 2022 16:24:54 +0000 To: openwrt-devel@lists.openwrt.org Subject: [PATCH] tplink-safeloader: Patch to handle partitions with alternate names. Date: Mon, 2 May 2022 18:24:24 +0200 MIME-Version: 1.0 Message-ID: List-Id: OpenWrt Development List List-Post: X-Patchwork-Original-From: Ole Kristian Lona via openwrt-devel From: Thomas Richard via openwrt-devel Precedence: list X-Mailman-Version: 2.1.34 X-BeenThere: openwrt-devel@lists.openwrt.org List-Subscribe: , List-Unsubscribe: , List-Archive: Reply-To: oklo@oklona.net List-Help: Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The sender domain has a DMARC Reject/Quarantine policy which disallows sending mailing list messages using the original "From" header. To mitigate this problem, the original message has been wrapped automatically by the mailing list software. From: Ole Kristian Lona Some devices, specifically Deco M4R-v3 / M5. These devices have fallback partitions which will be used in case the device determines that the primary partition set is unbootable. Signed-off-by: Ole Kristian Lona --- src/tplink-safeloader.c | 67 +++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/src/tplink-safeloader.c b/src/tplink-safeloader.c index fc46124..0ddbc02 100644 --- a/src/tplink-safeloader.c +++ b/src/tplink-safeloader.c @@ -53,6 +53,15 @@ struct flash_partition_entry { uint32_t size; }; +/** Flash partition names table entry */ +struct factory_partition_names { + const char *partition_table; + const char *soft_ver; + const char *os_image; + const char *file_system; + const char *extra_para; +}; + /** Partition trailing padding definitions * Values 0x00 to 0xff are reserved to indicate the padding value * Values from 0x100 are reserved to indicate other behaviour */ @@ -89,6 +98,7 @@ struct device_info { struct flash_partition_entry partitions[MAX_PARTITIONS+1]; const char *first_sysupgrade_partition; const char *last_sysupgrade_partition; + struct factory_partition_names partition_names; }; #define SOFT_VER_TEXT(_t) {.type = SOFT_VER_TYPE_TEXT, .text = _t} @@ -2982,8 +2992,10 @@ static void set_source_date_epoch() { } /** Generates the partition-table partition */ -static struct image_partition_entry make_partition_table(const struct flash_partition_entry *p) { - struct image_partition_entry entry = alloc_image_partition("partition-table", 0x800); +static struct image_partition_entry make_partition_table(const char *name, + const struct flash_partition_entry *p) +{ + struct image_partition_entry entry = alloc_image_partition(name, 0x800); char *s = (char *)entry.data, *end = (char *)(s+entry.size); @@ -3018,14 +3030,14 @@ static inline uint8_t bcd(uint8_t v) { /** Generates the soft-version partition */ -static struct image_partition_entry make_soft_version( +static struct image_partition_entry make_soft_version(const char *name, const struct device_info *info, uint32_t rev) { /** If an info string is provided, use this instead of * the structured data, and include the null-termination */ if (info->soft_ver.type == SOFT_VER_TYPE_TEXT) { uint32_t len = strlen(info->soft_ver.text) + 1; - return init_meta_partition_entry("soft-version", + return init_meta_partition_entry(name, info->soft_ver.text, len, info->part_trail); } @@ -3055,11 +3067,11 @@ static struct image_partition_entry make_soft_version( }; if (info->soft_ver_compat_level == 0) - return init_meta_partition_entry("soft-version", &s, + return init_meta_partition_entry(name, &s, (uint8_t *)(&s.compat_level) - (uint8_t *)(&s), info->part_trail); else - return init_meta_partition_entry("soft-version", &s, + return init_meta_partition_entry(name, &s, sizeof(s), info->part_trail); } @@ -3306,6 +3318,8 @@ static void build_image(const char *output, struct flash_partition_entry *os_image_partition = NULL; struct flash_partition_entry *file_system_partition = NULL; size_t firmware_partition_index = 0; + char fs_name[32]; + char os_name[32]; for (i = 0; info->partitions[i].name; i++) { if (!strcmp(info->partitions[i].name, "firmware")) @@ -3330,7 +3344,13 @@ static void build_image(const char *output, for (i = MAX_PARTITIONS-1; i >= firmware_partition_index + 1; i--) info->partitions[i+1] = info->partitions[i]; - file_system_partition->name = "file-system"; + if (info->partition_names.file_system == NULL) + file_system_partition->name = "file-system"; + else { + strcpy(fs_name, info->partition_names.file_system); + file_system_partition->name = fs_name; + } + file_system_partition->base = firmware_partition->base + kernel.st_size; /* Align partition start to erase blocks for factory images only */ @@ -3339,15 +3359,38 @@ static void build_image(const char *output, file_system_partition->size = firmware_partition->size - file_system_partition->base; - os_image_partition->name = "os-image"; + if (info->partition_names.os_image == NULL) + os_image_partition->name = "os-image"; + else { + strcpy(os_name, info->partition_names.os_image); + os_image_partition->name = os_name; + } + os_image_partition->size = kernel.st_size; } - parts[0] = make_partition_table(info->partitions); - parts[1] = make_soft_version(info, rev); + if (info->partition_names.partition_table == NULL) + parts[0] = make_partition_table("partition-table", info->partitions); + else + parts[0] = make_partition_table(info->partition_names.partition_table, info->partitions); + + if (info->partition_names.soft_ver == NULL) + parts[1] = make_soft_version("soft-version", info, rev); + else + parts[1] = make_soft_version(info->partition_names.soft_ver, info, rev); + parts[2] = make_support_list(info); - parts[3] = read_file("os-image", kernel_image, false, NULL); - parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof, file_system_partition); + + if (info->partition_names.os_image == NULL) + parts[3] = read_file("os-image", kernel_image, false, NULL); + else + parts[3] = read_file(info->partition_names.os_image, kernel_image, false, NULL); + + if (info->partition_names.file_system == NULL) + parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof, file_system_partition); + else + parts[4] = read_file(info->partition_names.file_system, rootfs_image, add_jffs2_eof, file_system_partition); + /* Some devices need the extra-para partition to accept the firmware */ if (strcasecmp(info->id, "ARCHER-A6-V3") == 0 ||