From patchwork Wed Jan 20 17:36:45 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: 1429349 X-Patchwork-Delegate: ynezz@true.cz 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=dw9RK+NL; 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=bXnqBGYK; 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 4DLXqd4yCsz9sCD for ; Thu, 21 Jan 2021 04:40:45 +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=Ngr0OgDHR3BejL0GuJ81oG67+2pWRFTSTs1Av5Snj9M=; b=dw9RK+NLjudSeZqNF7zOlcDVQ IDN8R+bIxY/Jev+ITE7BwESsCthB5iT/4vE2sQ0MmhaseZwdsuRS2d2lykOsrXVRmyx3sOXoCCmyL iIY/ZBFh+oGM8yL2lwDgA8exH4c7kEQ/epgBNaAPRzOxYG0aRuFEP+AuRuPbuLOqHQOuRT32A1Bi5 33V4hvfr61vJZChUahCFOtRpbiKnfI0XKApSQYf2ZhaA3sjb1PgPaQ7yJniySxjGWQqjyrw3Gt3Fg B3XFfDhk+qGnLSi0eG9WO/2NZHHhO18e6XUg3R6xXgMnViBef/42rBVQfzph9ZD5QU1Zo+hlt65T8 wZIwrm7mQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HQc-0002da-Vg; Wed, 20 Jan 2021 17:37:59 +0000 Received: from canardo.mork.no ([2001:4641::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HPj-0002EO-Mm for openwrt-devel@lists.openwrt.org; Wed, 20 Jan 2021 17:37:20 +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 10KHb1xP028854 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 18:37:02 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1611164222; bh=osEmHBePd8yqxldVNVFBZ1sM4aHivHMNUuy4NnnsZ9Y=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=bXnqBGYKIE3HvMINloBl/wjTiFtlJh0ypWZXcPiS5uLzef9YZ6tydlWQR+XdcD0eZ yto7umiytQxkM27Vay9pkzE8ZqF+zWQN7ahDtTzbbozPWDLr8Qy481IfwaTM9jdmeW HZa5jeSRBIiALSMMEiuQyYMYk51II5SGKYHahLfc= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10KHb1Nm028847; Wed, 20 Jan 2021 18:37:01 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH v4 02/10] kernel: mtdsplit_uimage: read extralen from device tree Date: Wed, 20 Jan 2021 18:36:45 +0100 Message-Id: <20210120173653.28784-3-bjorn@mork.no> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210120173653.28784-1-bjorn@mork.no> References: <20210120173653.28784-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_123704_210285_5F063639 X-CRM114-Status: GOOD ( 14.09 ) 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 An "openwrt,padding" property in device tree can replace two device specific parsers. 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 57d8b9f420d7..f9544ec382e3 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "mtdsplit.h" @@ -28,14 +29,6 @@ */ #define MAX_HEADER_LEN 96 -#define IH_MAGIC 0x27051956 /* Image Magic Number */ -#define IH_NMLEN 32 /* Image Name Length */ - -#define IH_OS_LINUX 5 /* Linux */ - -#define IH_TYPE_KERNEL 2 /* OS Kernel Image */ -#define IH_TYPE_FILESYSTEM 7 /* Filesystem Image */ - /* * Legacy format image header, * all data in network byte order (aka natural aka bigendian). @@ -76,6 +69,15 @@ 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) +{ + struct device_node *np = mtd_get_of_node(master); + + if (!np || !of_device_is_compatible(np, "openwrt,uimage")) + return; + of_property_read_u32(np, "openwrt,padding", extralen); +} + /** * __mtdsplit_parse_uimage - scan partition and create kernel + rootfs parts * @@ -97,7 +99,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, size_t rootfs_size = 0; int uimage_part, rf_part; int ret; - int extralen; + int extralen = 0; enum mtdsplit_part_type type; nr_parts = 2; @@ -111,6 +113,8 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, goto err_free_parts; } + uimage_parse_dt(master, &extralen); + /* find uImage on erase block boundaries */ for (offset = 0; offset < master->size; offset += master->erasesize) { struct uimage_header *header; @@ -121,7 +125,6 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, if (ret) continue; - extralen = 0; ret = find_header(buf, MAX_HEADER_LEN, &extralen); if (ret < 0) { pr_debug("no valid uImage found in \"%s\" at offset %llx\n", @@ -247,6 +250,7 @@ mtdsplit_uimage_parse_generic(struct mtd_info *master, static const struct of_device_id mtdsplit_uimage_of_match_table[] = { { .compatible = "denx,uimage" }, + { .compatible = "openwrt,uimage" }, {}, };