From patchwork Wed Jan 20 14:35:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Bj=C3=B8rn_Mork?= X-Patchwork-Id: 1429217 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=NJ8ZgUve; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=mork.no header.i=@mork.no header.a=rsa-sha256 header.s=b header.b=nRSVjFgK; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DLSmf1sDQz9sB4 for ; Thu, 21 Jan 2021 01:37:54 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yoBP0gUmJ3OsDTIIhIWjVYqh95zFeAEwg31RwZKAcsk=; b=NJ8ZgUveoJ2NMiJUAzoFl7HIp Xg2NBl2xnEbfoNRh9UBNcE8ahsqixFaZurqKFIaiuorqnR1On+w1MnFpi3fe4lK2fUlfX5VfTOdoC fGOSNSZ/kAYZRGMzOIPykrf2iDCJUCz/+BbmBlqwTcBGD+KyC5TaHk7++LhElUCHJNO24n+0YQ8cS dWzMmBSAAG+l+SJdnWog+iqp9IEMhV1KC0cZkwLnY5Zka+feq+NzLgGty5V2bwnnfamL358HIRyRl Ma/B3Zs7KHa1PvUTOGX2ONa5CzyODb2SiFvaTYuyRvdWfm1vnYaDkEJnsQKrEBUplsZxcYbqDgWQh xQnH2uCJA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2Eac-0005w7-RG; Wed, 20 Jan 2021 14:36:06 +0000 Received: from canardo.mork.no ([2001:4641::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2EaE-0005lB-3F for openwrt-devel@lists.openwrt.org; Wed, 20 Jan 2021 14:35:48 +0000 Received: from canardo.mork.no (ip6-localhost [IPv6:0:0:0:0:0:0:0:1]) by canardo.mork.no (8.15.2/8.15.2) with ESMTPS id 10KEZZl7014554 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 15:35:35 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1611153335; bh=5zUuCMOzdLc1hnulnhateq1fvBlpEy6hw/Iwp/BxiI0=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=nRSVjFgK1cH5lVnYiUV+NtRWP/Pjrd43EYmVnItX0mIhgALZoUTDJy2pcsm1b/rzT TSL2Kv+unHo8GSeUy4chtlrAgdxzIMNMC4lAnWuEMwfRIxbcXsV5aaUZyUwjAQ+TqI If80PdhlH91Whl5SALqT9msOV9bNDCGfc0/PE4qw= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10KEZZMs014547; Wed, 20 Jan 2021 15:35:35 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH v3 07/10] kernel: mtdsplit_uimage: add "openwrt, ih-type" device-tree property Date: Wed, 20 Jan 2021 15:35:24 +0100 Message-Id: <20210120143527.14434-8-bjorn@mork.no> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210120143527.14434-1-bjorn@mork.no> References: <20210120143527.14434-1-bjorn@mork.no> MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on canardo.mork.no X-Virus-Scanned: clamav-milter 0.102.4 at canardo X-Virus-Status: Clean X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210120_093542_701904_0EB1287C X-CRM114-Status: GOOD ( 14.07 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2001:4641:0:0:0:0:0:1 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Bj=C3=B8rn_Mork?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Some devices use uimage headers with a non-default ih_type. Add support for overriding this in device tree. Signed-off-by: Bjørn Mork --- .../drivers/mtd/mtdsplit/mtdsplit_uimage.c | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c index 55eaca9946a0..ef2d857abb04 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c @@ -69,7 +69,8 @@ read_uimage_header(struct mtd_info *mtd, size_t offset, u_char *buf, return 0; } -static void uimage_parse_dt(struct mtd_info *master, int *extralen, u32 *ih_magic) +static void uimage_parse_dt(struct mtd_info *master, int *extralen, + u32 *ih_magic, u32 *ih_type) { struct device_node *np = mtd_get_of_node(master); @@ -80,6 +81,8 @@ static void uimage_parse_dt(struct mtd_info *master, int *extralen, u32 *ih_magi pr_debug("got openwrt,padding=%d from device-tree\n", *extralen); if (!of_property_read_u32(np, "openwrt,ih-magic", ih_magic)) pr_debug("got openwrt,ih-magic=%08x from device-tree\n", *ih_magic); + if (!of_property_read_u32(np, "openwrt,ih-type", ih_type)) + pr_debug("got openwrt,ih-type=%08x from device-tree\n", *ih_type); } /** @@ -91,7 +94,7 @@ static void uimage_parse_dt(struct mtd_info *master, int *extralen, u32 *ih_magi static int __mtdsplit_parse_uimage(struct mtd_info *master, const struct mtd_partition **pparts, struct mtd_part_parser_data *data, - ssize_t (*find_header)(u_char *buf, size_t len, u32 ih_magic)) + ssize_t (*find_header)(u_char *buf, size_t len, u32 ih_magic, u32 ih_type)) { struct mtd_partition *parts; u_char *buf; @@ -105,6 +108,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, int ret; int extralen = 0; u32 ih_magic = IH_MAGIC; + u32 ih_type = IH_TYPE_KERNEL; enum mtdsplit_part_type type; nr_parts = 2; @@ -118,7 +122,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, goto err_free_parts; } - uimage_parse_dt(master, &extralen, &ih_magic); + uimage_parse_dt(master, &extralen, &ih_magic, &ih_type); /* find uImage on erase block boundaries */ for (offset = 0; offset < master->size; offset += master->erasesize) { @@ -130,7 +134,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, if (ret) continue; - ret = find_header(buf, MAX_HEADER_LEN, ih_magic); + ret = find_header(buf, MAX_HEADER_LEN, ih_magic, ih_type); if (ret < 0) { pr_debug("no valid uImage found in \"%s\" at offset %llx\n", master->name, (unsigned long long) offset); @@ -218,7 +222,7 @@ err_free_parts: return ret; } -static ssize_t uimage_verify_default(u_char *buf, size_t len, u32 ih_magic) +static ssize_t uimage_verify_default(u_char *buf, size_t len, u32 ih_magic, u32 ih_type) { struct uimage_header *header = (struct uimage_header *)buf; @@ -235,9 +239,9 @@ static ssize_t uimage_verify_default(u_char *buf, size_t len, u32 ih_magic) return -EINVAL; } - if (header->ih_type != IH_TYPE_KERNEL) { + if (header->ih_type != ih_type) { pr_debug("invalid uImage type: %08x != %08x\n", - be32_to_cpu(header->ih_type), IH_TYPE_KERNEL); + be32_to_cpu(header->ih_type), ih_type); return -EINVAL; } @@ -279,7 +283,7 @@ static struct mtd_part_parser uimage_generic_parser = { #define FW_MAGIC_WNDR3700V2 0x33373031 #define FW_MAGIC_WPN824N 0x31313030 -static ssize_t uimage_verify_wndr3700(u_char *buf, size_t len, u32 ih_magic) +static ssize_t uimage_verify_wndr3700(u_char *buf, size_t len, u32 ih_magic, u32 ih_type) { struct uimage_header *header = (struct uimage_header *)buf; uint8_t expected_type = IH_TYPE_FILESYSTEM; @@ -340,7 +344,7 @@ static struct mtd_part_parser uimage_netgear_parser = { #define FW_EDIMAX_OFFSET 20 #define FW_MAGIC_EDIMAX 0x43535953 -static ssize_t uimage_find_edimax(u_char *buf, size_t len, u32 ih_magic) +static ssize_t uimage_find_edimax(u_char *buf, size_t len, u32 ih_magic, u32 ih_type) { u32 *magic; @@ -353,7 +357,7 @@ static ssize_t uimage_find_edimax(u_char *buf, size_t len, u32 ih_magic) if (be32_to_cpu(*magic) != FW_MAGIC_EDIMAX) return -EINVAL; - if (!uimage_verify_default(buf + FW_EDIMAX_OFFSET, len, ih_magic)) + if (!uimage_verify_default(buf + FW_EDIMAX_OFFSET, len, ih_magic, ih_type)) return FW_EDIMAX_OFFSET; return -EINVAL;