From patchwork Wed Jan 20 17:36:53 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: 1429360 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=ZrPFpgn3; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=gEd8X4P9; 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=QsSOQh6c; 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 4DLXst5Ywlz9sCD for ; Thu, 21 Jan 2021 04:42:42 +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=gMSED7hpcOQob1JrCgAZ0LjJ1mjzX7jM89QCHR1y3NQ=; b=ZrPFpgn30Wp0IpdY9Xv3lVILS vZ032Z3CzP5jsuH5fGRMbs5fDCw2WgNW7CUQrXE8/Jqf+TDf8guSZmvX9PmKhJs1wcrIkThx0mjuh oor9Tf3aYJmLqTWtKOSu4iFg09AJ/t4mue5IrsML/zDMgi8MDw7sZoF4rQurCW9OrH1hVNrEebCLb f/lOQeH5Vg+gS4e8RJ1TGkTkYbomcz9zLQq414K2LvZYh5Gzy+GyZRrWz54ugYfdzg3ONtF9c7kme /O96Qm9DQbZW9hzz/W1BYYnyeDFPN97f50gG8AmxDJy+CF++UH0hCPGQgRnJsogXibixFbJNCrhGM 5sDqbxqyA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HT2-0003nN-5P; Wed, 20 Jan 2021 17:40:28 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HQP-0002VP-Uz for openwrt-devel@merlin.infradead.org; Wed, 20 Jan 2021 17:37:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description; bh=z3TSxfl5C01jmSaI+DkZsZpxyI/bSwdUPp+UIC7F3c8=; b=gEd8X4P9/ALoqlevQjzuFqMwhz AVkR3S2DiREYRRdSMKJhQcsLEpNxE1bihJzdfSSHcvNP1kK6IahqisW0ZWiXbFMsI2DdL7JrvIn9M U16EUXIgFcYDWbEdS1he5jVwjj7h2XC2YyIl/XNokfnLFirfc8AJODp+2sq2JtddYB3QXrM2ajiug nNxzRp7BQYZEfLii5KSx/Tj0wNckrOF2PJ4r9jEWC2U7H2Yurf8r68xmd+GMFniiRHQoreL9mtMu9 yS8nYvYGpM4e2dUVGR2FpiqVYTKzJfdOpIOXWHQE1KuHUGHxsBiGwVK0fvbW8kSVRYsFS4PUHHGku IWSQ4CMw==; Received: from canardo.mork.no ([2001:4641::1]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1l2HPt-00FztS-9I for openwrt-devel@lists.openwrt.org; Wed, 20 Jan 2021 17:37:30 +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 10KHb6MV028954 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 18:37:06 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1611164226; bh=z3TSxfl5C01jmSaI+DkZsZpxyI/bSwdUPp+UIC7F3c8=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=QsSOQh6cCbDlV/JC4JCQnu5yxWbhKMpS3RYgJpHDLphQTn+EujGr6OJQV9EOKalIP 8cgE1vGu1GqVJ14VqzZJuoEFgHc6wS2F3/qMuMORJjqrURaQmEUpu6ogaBWhqAajQ8 pdE65zAxWJI62VC8857VwsCVtKzR0iRK0Jf3SYQE= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10KHb6IE028947; Wed, 20 Jan 2021 18:37:06 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH v4 10/10] kernel: mtdsplit_uimage: replace "edimax, uimage" parser Date: Wed, 20 Jan 2021 18:36:53 +0100 Message-Id: <20210120173653.28784-11-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_173730_344956_44078947 X-CRM114-Status: GOOD ( 21.30 ) X-Spam-Note: SpamAssassin invocation failed 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 The "edimax,uimage"" parser can be replaced by the generic parser using device specific openwrt,partition-magic and openwrt,offset properties. Signed-off-by: Bjørn Mork --- .../drivers/mtd/mtdsplit/mtdsplit_uimage.c | 129 ++++-------------- .../dt-bindings/mtd/partitions/uimage.h | 2 + .../dts/mt7620a_edimax_br-6478ac-v2.dts | 5 +- .../ramips/dts/mt7620a_edimax_ew-7478apc.dts | 5 +- .../ramips/dts/mt7620a_edimax_ew-747x.dtsi | 5 +- .../linux/ramips/dts/mt7621_edimax_re23s.dts | 5 +- .../ramips/dts/rt3050_edimax_3g-6200n.dts | 5 +- .../ramips/dts/rt3050_edimax_3g-6200nl.dts | 5 +- .../ramips/dts/rt3662_edimax_br-6475nd.dts | 5 +- 9 files changed, 60 insertions(+), 106 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 7a8ccdf8f59a..a3e55fb1fe38 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c @@ -23,12 +23,6 @@ #include "mtdsplit.h" -/* - * uimage_header itself is only 64B, but it may be prepended with another data. - * Currently the biggest size is for Fon(Foxconn) devices: 64B + 32B - */ -#define MAX_HEADER_LEN 96 - /* * Legacy format image header, * all data in network byte order (aka natural aka bigendian). @@ -90,6 +84,32 @@ static void uimage_parse_dt(struct mtd_info *master, int *extralen, pr_debug("got openwrt,partition-magic=%08x from device-tree\n", *part_magic); } +static ssize_t uimage_verify_default(u_char *buf, u32 ih_magic, u32 ih_type) +{ + struct uimage_header *header = (struct uimage_header *)buf; + + /* default sanity checks */ + if (be32_to_cpu(header->ih_magic) != ih_magic) { + pr_debug("invalid uImage magic: %08x != %08x\n", + be32_to_cpu(header->ih_magic), ih_magic); + return -EINVAL; + } + + if (header->ih_os != IH_OS_LINUX) { + pr_debug("invalid uImage OS: %08x != %08x\n", + be32_to_cpu(header->ih_os), IH_OS_LINUX); + return -EINVAL; + } + + if (header->ih_type != ih_type) { + pr_debug("invalid uImage type: %08x != %08x\n", + be32_to_cpu(header->ih_type), ih_type); + return -EINVAL; + } + + return 0; +} + /** * __mtdsplit_parse_uimage - scan partition and create kernel + rootfs parts * @@ -98,8 +118,7 @@ static void uimage_parse_dt(struct mtd_info *master, int *extralen, */ 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, u32 ih_type)) + struct mtd_part_parser_data *data) { struct mtd_partition *parts; u_char *buf; @@ -125,7 +144,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, return -ENOMEM; uimage_parse_dt(master, &extralen, &ih_magic, &ih_type, &header_offset, &part_magic); - buflen = MAX_HEADER_LEN; + buflen = sizeof(struct uimage_header) + header_offset; buf = vmalloc(buflen); if (!buf) { ret = -ENOMEM; @@ -146,16 +165,13 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, if (header_offset && part_magic && (be32_to_cpu(*(u32 *)buf) != part_magic)) continue; - ret = find_header(buf + header_offset, buflen, ih_magic, ih_type); + ret = uimage_verify_default(buf + header_offset, 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); continue; } - /* let uimage_find_edimax override the offset */ - if (ret > 0) - header_offset = ret; header = (struct uimage_header *)(buf + header_offset); uimage_size = sizeof(*header) + @@ -238,41 +254,6 @@ err_free_parts: return ret; } -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; - - /* default sanity checks */ - if (be32_to_cpu(header->ih_magic) != ih_magic) { - pr_debug("invalid uImage magic: %08x != %08x\n", - be32_to_cpu(header->ih_magic), ih_magic); - return -EINVAL; - } - - if (header->ih_os != IH_OS_LINUX) { - pr_debug("invalid uImage OS: %08x != %08x\n", - be32_to_cpu(header->ih_os), IH_OS_LINUX); - return -EINVAL; - } - - if (header->ih_type != ih_type) { - pr_debug("invalid uImage type: %08x != %08x\n", - be32_to_cpu(header->ih_type), ih_type); - return -EINVAL; - } - - return 0; -} - -static int -mtdsplit_uimage_parse_generic(struct mtd_info *master, - const struct mtd_partition **pparts, - struct mtd_part_parser_data *data) -{ - return __mtdsplit_parse_uimage(master, pparts, data, - uimage_verify_default); -} - static const struct of_device_id mtdsplit_uimage_of_match_table[] = { { .compatible = "denx,uimage" }, { .compatible = "openwrt,uimage" }, @@ -283,59 +264,10 @@ static struct mtd_part_parser uimage_generic_parser = { .owner = THIS_MODULE, .name = "uimage-fw", .of_match_table = mtdsplit_uimage_of_match_table, - .parse_fn = mtdsplit_uimage_parse_generic, + .parse_fn = __mtdsplit_parse_uimage, .type = MTD_PARSER_TYPE_FIRMWARE, }; -/************************************************** - * Edimax - **************************************************/ - -#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, u32 ih_type) -{ - u32 *magic; - - if (len < FW_EDIMAX_OFFSET + sizeof(struct uimage_header)) { - pr_err("Buffer too small for checking Edimax header\n"); - return -ENOSPC; - } - - magic = (u32 *)buf; - if (be32_to_cpu(*magic) != FW_MAGIC_EDIMAX) - return -EINVAL; - - if (!uimage_verify_default(buf + FW_EDIMAX_OFFSET, len, ih_magic, ih_type)) - return FW_EDIMAX_OFFSET; - - return -EINVAL; -} - -static int -mtdsplit_uimage_parse_edimax(struct mtd_info *master, - const struct mtd_partition **pparts, - struct mtd_part_parser_data *data) -{ - return __mtdsplit_parse_uimage(master, pparts, data, - uimage_find_edimax); -} - -static const struct of_device_id mtdsplit_uimage_edimax_of_match_table[] = { - { .compatible = "edimax,uimage" }, - {}, -}; - -static struct mtd_part_parser uimage_edimax_parser = { - .owner = THIS_MODULE, - .name = "edimax-fw", - .of_match_table = mtdsplit_uimage_edimax_of_match_table, - .parse_fn = mtdsplit_uimage_parse_edimax, - .type = MTD_PARSER_TYPE_FIRMWARE, -}; - - /************************************************** * Init **************************************************/ @@ -343,7 +275,6 @@ static struct mtd_part_parser uimage_edimax_parser = { static int __init mtdsplit_uimage_init(void) { register_mtd_parser(&uimage_generic_parser); - register_mtd_parser(&uimage_edimax_parser); return 0; } diff --git a/target/linux/generic/files/include/dt-bindings/mtd/partitions/uimage.h b/target/linux/generic/files/include/dt-bindings/mtd/partitions/uimage.h index 407e46ce2c46..43d5f7b5da87 100644 --- a/target/linux/generic/files/include/dt-bindings/mtd/partitions/uimage.h +++ b/target/linux/generic/files/include/dt-bindings/mtd/partitions/uimage.h @@ -192,5 +192,7 @@ * Magic values specific to "openwrt,uimage" partitions */ #define IH_MAGIC_OKLI 0x4f4b4c49 /* 'OKLI' */ +#define FW_EDIMAX_OFFSET 20 /* Edimax Firmware Offset */ +#define FW_MAGIC_EDIMAX 0x43535953 /* Edimax Firmware Magic Number */ #endif /* __UIMAGE_H__ */ diff --git a/target/linux/ramips/dts/mt7620a_edimax_br-6478ac-v2.dts b/target/linux/ramips/dts/mt7620a_edimax_br-6478ac-v2.dts index 0b991611b223..773db22c743e 100644 --- a/target/linux/ramips/dts/mt7620a_edimax_br-6478ac-v2.dts +++ b/target/linux/ramips/dts/mt7620a_edimax_br-6478ac-v2.dts @@ -15,6 +15,7 @@ #include #include +#include / { compatible = "edimax,br-6478ac-v2", "ralink,mt7620a-soc"; @@ -116,7 +117,9 @@ }; partition@70000 { - compatible = "edimax,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,offset = ; + openwrt,partition-magic = ; label = "firmware"; reg = <0x00070000 0x00790000>; }; diff --git a/target/linux/ramips/dts/mt7620a_edimax_ew-7478apc.dts b/target/linux/ramips/dts/mt7620a_edimax_ew-7478apc.dts index 1e1b2830f02b..77d214e888c1 100644 --- a/target/linux/ramips/dts/mt7620a_edimax_ew-7478apc.dts +++ b/target/linux/ramips/dts/mt7620a_edimax_ew-7478apc.dts @@ -4,6 +4,7 @@ #include #include +#include / { compatible = "edimax,ew-7478apc", "ralink,mt7620a-soc"; @@ -102,7 +103,9 @@ }; partition@70000 { - compatible = "edimax,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,offset = ; + openwrt,partition-magic = ; label = "firmware"; reg = <0x00070000 0x00790000>; }; diff --git a/target/linux/ramips/dts/mt7620a_edimax_ew-747x.dtsi b/target/linux/ramips/dts/mt7620a_edimax_ew-747x.dtsi index 78b481bd2a64..d17cc090c2d2 100644 --- a/target/linux/ramips/dts/mt7620a_edimax_ew-747x.dtsi +++ b/target/linux/ramips/dts/mt7620a_edimax_ew-747x.dtsi @@ -4,6 +4,7 @@ #include #include +#include / { compatible = "ralink,mt7620a-soc"; @@ -122,7 +123,9 @@ }; partition@70000 { - compatible = "edimax,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,offset = ; + openwrt,partition-magic = ; label = "firmware"; reg = <0x00070000 0x00790000>; }; diff --git a/target/linux/ramips/dts/mt7621_edimax_re23s.dts b/target/linux/ramips/dts/mt7621_edimax_re23s.dts index cf44746e8f61..9b9657344601 100644 --- a/target/linux/ramips/dts/mt7621_edimax_re23s.dts +++ b/target/linux/ramips/dts/mt7621_edimax_re23s.dts @@ -4,6 +4,7 @@ #include #include +#include / { compatible = "edimax,re23s", "mediatek,mt7621-soc"; @@ -97,7 +98,9 @@ }; partition@70000 { - compatible = "edimax,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,offset = ; + openwrt,partition-magic = ; label = "firmware"; reg = <0x70000 0xf50000>; }; diff --git a/target/linux/ramips/dts/rt3050_edimax_3g-6200n.dts b/target/linux/ramips/dts/rt3050_edimax_3g-6200n.dts index a185e5d5bb8d..07ff8bc9bc46 100644 --- a/target/linux/ramips/dts/rt3050_edimax_3g-6200n.dts +++ b/target/linux/ramips/dts/rt3050_edimax_3g-6200n.dts @@ -2,6 +2,7 @@ #include #include +#include / { compatible = "edimax,3g-6200n", "ralink,rt3050-soc"; @@ -50,7 +51,9 @@ }; partition@50000 { - compatible = "edimax,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,offset = ; + openwrt,partition-magic = ; label = "firmware"; reg = <0x50000 0x390000>; }; diff --git a/target/linux/ramips/dts/rt3050_edimax_3g-6200nl.dts b/target/linux/ramips/dts/rt3050_edimax_3g-6200nl.dts index 41768078f5fc..f339b7ebe8bd 100644 --- a/target/linux/ramips/dts/rt3050_edimax_3g-6200nl.dts +++ b/target/linux/ramips/dts/rt3050_edimax_3g-6200nl.dts @@ -2,6 +2,7 @@ #include #include +#include / { compatible = "edimax,3g-6200nl", "ralink,rt3050-soc"; @@ -50,7 +51,9 @@ }; partition@50000 { - compatible = "edimax,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,offset = ; + openwrt,partition-magic = ; label = "firmware"; reg = <0x50000 0x390000>; }; diff --git a/target/linux/ramips/dts/rt3662_edimax_br-6475nd.dts b/target/linux/ramips/dts/rt3662_edimax_br-6475nd.dts index a1e7c837d1a6..56d9dc08948d 100644 --- a/target/linux/ramips/dts/rt3662_edimax_br-6475nd.dts +++ b/target/linux/ramips/dts/rt3662_edimax_br-6475nd.dts @@ -2,6 +2,7 @@ #include #include +#include / { compatible = "edimax,br-6475nd", "ralink,rt3662-soc", "ralink,rt3883-soc"; @@ -86,7 +87,9 @@ }; partition@70000 { - compatible = "edimax,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,offset = ; + openwrt,partition-magic = ; reg = <0x00070000 0x00790000>; label = "firmware"; };