From patchwork Wed Jan 20 17:36:44 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: 1429351 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=rOIr7Sdt; 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=VJPPfagX; 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 4DLXqg3SfZz9sCD for ; Thu, 21 Jan 2021 04:40:47 +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=LsHwmn8ZP7WwF1AKjAO933EDXsy39FLCZCgKvHi58BU=; b=rOIr7SdtpgjdiZqiUGZqnhH4g s19AALkv/sw6mIulefZAkD4xzNaTlgpYjxCzmbfemg80MSpoBt+XLhd0vPTyYw3QY6OTHbjMCA1jn 2J0wenDwVDbHawMUfoFCp8A24DQ5hNsoMBVnlgMtlRYDumafy1yjgDYiIjwGXbne7GgduSWINl2Np TSa0SXxUV9OCI6UHm0NpO3nGma9SAFyTgbOeCik0Tih+F6d6XU56imCicWmuidJA4Ox7ZHdX9nxE3 dcfEuGDsAPoGFaiYEh+TE1xv87/EaUuOefz8JMaiimutr5AXGYJ3vlYe+W6e6GrmFaWwZhdOmG7Md xHkv4a3Aw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HQq-0002k3-59; Wed, 20 Jan 2021 17:38:12 +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-0002EG-LZ for openwrt-devel@lists.openwrt.org; Wed, 20 Jan 2021 17:37:21 +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 10KHb1pW028836 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 18:37:01 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1611164221; bh=TMrSF97sjtWSLlweyCSltlApo5Oywll5bCxIgjzap+M=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=VJPPfagXFihfaow7tTSNfvY9jB8LMDgDLMpoOUJqvmquxKQv2PEZEzr0O9fWCvkOm 6vK6DXBuu+rK7erA3FnfI1D16dpz+qB8x8LxKbSPGO4qXcEZV1pX/U6Lx1HtOsvSOR 9k4Zama7qAU9uRd6dRLdapVqfx91wvbvCr3IUia0= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10KHb17p028835; 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 01/10] dt-bindings: mtd: partitions: add OpenWrt defined U-Boot Image Date: Wed, 20 Jan 2021 18:36:44 +0100 Message-Id: <20210120173653.28784-2-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_104332_326960CC X-CRM114-Status: GOOD ( 25.04 ) 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 Add devicetree bindings for vendor specific variants of U-Boot Images, as defined by OpenWrt. Signed-off-by: Bjørn Mork --- .../mtd/partitions/openwrt,uimage.yaml | 91 +++++++++ .../dt-bindings/mtd/partitions/uimage.h | 191 ++++++++++++++++++ 2 files changed, 282 insertions(+) create mode 100644 target/linux/generic/files/Documentation/devicetree/bindings/mtd/partitions/openwrt,uimage.yaml create mode 100644 target/linux/generic/files/include/dt-bindings/mtd/partitions/uimage.h diff --git a/target/linux/generic/files/Documentation/devicetree/bindings/mtd/partitions/openwrt,uimage.yaml b/target/linux/generic/files/Documentation/devicetree/bindings/mtd/partitions/openwrt,uimage.yaml new file mode 100644 index 000000000000..d052ab1fc981 --- /dev/null +++ b/target/linux/generic/files/Documentation/devicetree/bindings/mtd/partitions/openwrt,uimage.yaml @@ -0,0 +1,91 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mtd/partitions/openwrt,uimage.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: OpenWrt variations of U-Boot Image partitions + +maintainers: + - Bjørn Mork + +description: | + The image format defined by the boot loader "Das U-Boot" is often + modified or extended by device vendors. This defines a few optional + properties which can be used to describe such modifications. + +# partition.txt defines common properties, but has not yet been +# converted to YAML +#allOf: +# - $ref: ../partition.yaml# + +properties: + compatible: + items: + - enum: + - openwrt,uimage + - const: denx,uimage + + openwrt,padding: + description: Number of padding bytes between header and data + $ref: /schemas/types.yaml#/definitions/uint32 + default: 0 + + openwrt,ih-magic: + description: U-Boot Image Header magic number. + $ref: /schemas/types.yaml#/definitions/uint32 + default: 0x27051956 # IH_MAGIC + + openwrt,ih-type: + description: U-Boot Image type + $ref: /schemas/types.yaml#/definitions/uint32 + default: 2 # IH_TYPE_KERNEL + + openwrt,offset: + description: + Offset between partition start and U-Boot Image in bytes + $ref: /schemas/types.yaml#/definitions/uint32 + default: 0 + + openwrt,partition-magic: + description: + Magic number found at the start of the partition. Will only be + validated if both this property and openwrt,offset is non-zero + $ref: /schemas/types.yaml#/definitions/uint32 + default: 0 + +required: + - compatible + - reg + +#unevaluatedProperties: false +additionalProperties: false + +examples: + - | + // device with non-default magic + partition@300000 { + compatible = "openwrt,uimage", "denx,uimage"; + reg = <0x00300000 0xe80000>; + label = "firmware"; + openwrt,ih-magic = <0x4e474520>; + }; + - | + // device with U-Boot Image at an offset, with a partition magic value + partition@70000 { + compatible = "openwrt,uimage", "denx,uimage"; + reg = <0x00070000 0x00790000>; + label = "firmware"; + openwrt,offset = <20>; + openwrt,partition-magic = <0x43535953>; + }; + - | + // device using a non-default image type + #include "dt-bindings/mtd/partitions/uimage.h" + partition@6c0000 { + compatible = "openwrt,uimage", "denx,uimage"; + reg = <0x6c0000 0x1900000>; + label = "firmware"; + openwrt,ih-magic = <0x33373033>; + openwrt,ih-type = ; + }; 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 new file mode 100644 index 000000000000..29eec38dd282 --- /dev/null +++ b/target/linux/generic/files/include/dt-bindings/mtd/partitions/uimage.h @@ -0,0 +1,191 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * *** IMPORTANT *** + * This file is not only included from C-code but also from devicetree source + * files. As such this file MUST only contain comments and defines. + * + * Based on image.h from U-Boot which is + * (C) Copyright 2008 Semihalf + * (C) Copyright 2000-2005 Wolfgang Denk, DENX Software Engineering, wd@denx.de. + */ + +#ifndef __UIMAGE_H__ +#define __UIMAGE_H__ + +/* + * Operating System Codes + * + * The following are exposed to uImage header. + * New IDs *MUST* be appended at the end of the list and *NEVER* + * inserted for backward compatibility. + */ +#define IH_OS_INVALID 0 /* Invalid OS */ +#define IH_OS_OPENBSD 1 /* OpenBSD */ +#define IH_OS_NETBSD 2 /* NetBSD */ +#define IH_OS_FREEBSD 3 /* FreeBSD */ +#define IH_OS_4_4BSD 4 /* 4.4BSD */ +#define IH_OS_LINUX 5 /* Linux */ +#define IH_OS_SVR4 6 /* SVR4 */ +#define IH_OS_ESIX 7 /* Esix */ +#define IH_OS_SOLARIS 8 /* Solaris */ +#define IH_OS_IRIX 9 /* Irix */ +#define IH_OS_SCO 10 /* SCO */ +#define IH_OS_DELL 11 /* Dell */ +#define IH_OS_NCR 12 /* NCR */ +#define IH_OS_LYNXOS 13 /* LynxOS */ +#define IH_OS_VXWORKS 14 /* VxWorks */ +#define IH_OS_PSOS 15 /* pSOS */ +#define IH_OS_QNX 16 /* QNX */ +#define IH_OS_U_BOOT 17 /* Firmware */ +#define IH_OS_RTEMS 18 /* RTEMS */ +#define IH_OS_ARTOS 19 /* ARTOS */ +#define IH_OS_UNITY 20 /* Unity OS */ +#define IH_OS_INTEGRITY 21 /* INTEGRITY */ +#define IH_OS_OSE 22 /* OSE */ +#define IH_OS_PLAN9 23 /* Plan 9 */ +#define IH_OS_OPENRTOS 24 /* OpenRTOS */ +#define IH_OS_ARM_TRUSTED_FIRMWARE 25 /* ARM Trusted Firmware */ +#define IH_OS_TEE 26 /* Trusted Execution Environment */ +#define IH_OS_OPENSBI 27 /* RISC-V OpenSBI */ +#define IH_OS_EFI 28 /* EFI Firmware (e.g. GRUB2) */ + +/* + * CPU Architecture Codes (supported by Linux) + * + * The following are exposed to uImage header. + * New IDs *MUST* be appended at the end of the list and *NEVER* + * inserted for backward compatibility. + */ +#define IH_ARCH_INVALID 0 /* Invalid CPU */ +#define IH_ARCH_ALPHA 1 /* Alpha */ +#define IH_ARCH_ARM 2 /* ARM */ +#define IH_ARCH_I386 3 /* Intel x86 */ +#define IH_ARCH_IA64 4 /* IA64 */ +#define IH_ARCH_MIPS 5 /* MIPS */ +#define IH_ARCH_MIPS64 6 /* MIPS 64 Bit */ +#define IH_ARCH_PPC 7 /* PowerPC */ +#define IH_ARCH_S390 8 /* IBM S390 */ +#define IH_ARCH_SH 9 /* SuperH */ +#define IH_ARCH_SPARC 10 /* Sparc */ +#define IH_ARCH_SPARC64 11 /* Sparc 64 Bit */ +#define IH_ARCH_M68K 12 /* M68K */ +#define IH_ARCH_NIOS 13 /* Nios-32 */ +#define IH_ARCH_MICROBLAZE 14 /* MicroBlaze */ +#define IH_ARCH_NIOS2 15 /* Nios-II */ +#define IH_ARCH_BLACKFIN 16 /* Blackfin */ +#define IH_ARCH_AVR32 17 /* AVR32 */ +#define IH_ARCH_ST200 18 /* STMicroelectronics ST200 */ +#define IH_ARCH_SANDBOX 19 /* Sandbox architecture (test only) */ +#define IH_ARCH_NDS32 20 /* ANDES Technology - NDS32 */ +#define IH_ARCH_OPENRISC 21 /* OpenRISC 1000 */ +#define IH_ARCH_ARM64 22 /* ARM64 */ +#define IH_ARCH_ARC 23 /* Synopsys DesignWare ARC */ +#define IH_ARCH_X86_64 24 /* AMD x86_64, Intel and Via */ +#define IH_ARCH_XTENSA 25 /* Xtensa */ +#define IH_ARCH_RISCV 26 /* RISC-V */ + +/* + * Image Types + * + * "Standalone Programs" are directly runnable in the environment + * provided by U-Boot; it is expected that (if they behave + * well) you can continue to work in U-Boot after return from + * the Standalone Program. + * "OS Kernel Images" are usually images of some Embedded OS which + * will take over control completely. Usually these programs + * will install their own set of exception handlers, device + * drivers, set up the MMU, etc. - this means, that you cannot + * expect to re-enter U-Boot except by resetting the CPU. + * "RAMDisk Images" are more or less just data blocks, and their + * parameters (address, size) are passed to an OS kernel that is + * being started. + * "Multi-File Images" contain several images, typically an OS + * (Linux) kernel image and one or more data images like + * RAMDisks. This construct is useful for instance when you want + * to boot over the network using BOOTP etc., where the boot + * server provides just a single image file, but you want to get + * for instance an OS kernel and a RAMDisk image. + * + * "Multi-File Images" start with a list of image sizes, each + * image size (in bytes) specified by an "uint32_t" in network + * byte order. This list is terminated by an "(uint32_t)0". + * Immediately after the terminating 0 follow the images, one by + * one, all aligned on "uint32_t" boundaries (size rounded up to + * a multiple of 4 bytes - except for the last file). + * + * "Firmware Images" are binary images containing firmware (like + * U-Boot or FPGA images) which usually will be programmed to + * flash memory. + * + * "Script files" are command sequences that will be executed by + * U-Boot's command interpreter; this feature is especially + * useful when you configure U-Boot to use a real shell (hush) + * as command interpreter (=> Shell Scripts). + * + * The following are exposed to uImage header. + * New IDs *MUST* be appended at the end of the list and *NEVER* + * inserted for backward compatibility. + */ +#define IH_TYPE_INVALID 0 /* Invalid Image */ +#define IH_TYPE_STANDALONE 1 /* Standalone Program */ +#define IH_TYPE_KERNEL 2 /* OS Kernel Image */ +#define IH_TYPE_RAMDISK 3 /* RAMDisk Image */ +#define IH_TYPE_MULTI 4 /* Multi-File Image */ +#define IH_TYPE_FIRMWARE 5 /* Firmware Image */ +#define IH_TYPE_SCRIPT 6 /* Script file */ +#define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */ +#define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */ +#define IH_TYPE_KWBIMAGE 9 /* Kirkwood Boot Image */ +#define IH_TYPE_IMXIMAGE 10 /* Freescale IMXBoot Image */ +#define IH_TYPE_UBLIMAGE 11 /* Davinci UBL Image */ +#define IH_TYPE_OMAPIMAGE 12 /* TI OMAP Config Header Image */ +#define IH_TYPE_AISIMAGE 13 /* TI Davinci AIS Image */ + /* OS Kernel Image, can run from any load address */ +#define IH_TYPE_KERNEL_NOLOAD 14 +#define IH_TYPE_PBLIMAGE 15 /* Freescale PBL Boot Image */ +#define IH_TYPE_MXSIMAGE 16 /* Freescale MXSBoot Image */ +#define IH_TYPE_GPIMAGE 17 /* TI Keystone GPHeader Image */ +#define IH_TYPE_ATMELIMAGE 18 /* ATMEL ROM bootable Image */ +#define IH_TYPE_SOCFPGAIMAGE 19 /* Altera SOCFPGA CV/AV Preloader */ +#define IH_TYPE_X86_SETUP 20 /* x86 setup.bin Image */ +#define IH_TYPE_LPC32XXIMAGE 21 /* x86 setup.bin Image */ +#define IH_TYPE_LOADABLE 22 /* A list of typeless images */ +#define IH_TYPE_RKIMAGE 23 /* Rockchip Boot Image */ +#define IH_TYPE_RKSD 24 /* Rockchip SD card */ +#define IH_TYPE_RKSPI 25 /* Rockchip SPI image */ +#define IH_TYPE_ZYNQIMAGE 26 /* Xilinx Zynq Boot Image */ +#define IH_TYPE_ZYNQMPIMAGE 27 /* Xilinx ZynqMP Boot Image */ +#define IH_TYPE_ZYNQMPBIF 28 /* Xilinx ZynqMP Boot Image (bif) */ +#define IH_TYPE_FPGA 29 /* FPGA Image */ +#define IH_TYPE_VYBRIDIMAGE 30 /* VYBRID .vyb Image */ +#define IH_TYPE_TEE 31 /* Trusted Execution Environment OS Image */ +#define IH_TYPE_FIRMWARE_IVT 32 /* Firmware Image with HABv4 IVT */ +#define IH_TYPE_PMMC 33 /* TI Power Management Micro-Controller Firmware */ +#define IH_TYPE_STM32IMAGE 34 /* STMicroelectronics STM32 Image */ +#define IH_TYPE_SOCFPGAIMAGE_V1 35 /* Altera SOCFPGA A10 Preloader */ +#define IH_TYPE_MTKIMAGE 36 /* MediaTek BootROM loadable Image */ +#define IH_TYPE_IMX8MIMAGE 37 /* Freescale IMX8MBoot Image */ +#define IH_TYPE_IMX8IMAGE 38 /* Freescale IMX8Boot Image */ +#define IH_TYPE_COPRO 39 /* Coprocessor Image for remoteproc*/ + + +/* + * Compression Types + * + * The following are exposed to uImage header. + * New IDs *MUST* be appended at the end of the list and *NEVER* + * inserted for backward compatibility. + */ +#define IH_COMP_NONE 0 /* No Compression Used */ +#define IH_COMP_GZIP 1 /* gzip Compression Used */ +#define IH_COMP_BZIP2 2 /* bzip2 Compression Used */ +#define IH_COMP_LZMA 3 /* lzma Compression Used */ +#define IH_COMP_LZO 4 /* lzo Compression Used */ +#define IH_COMP_LZ4 5 /* lz4 Compression Used */ + + +#define LZ4F_MAGIC 0x184D2204 /* LZ4 Magic Number */ +#define IH_MAGIC 0x27051956 /* Image Magic Number */ +#define IH_NMLEN 32 /* Image Name Length */ + +#endif /* __UIMAGE_H__ */ 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" }, {}, }; From patchwork Wed Jan 20 17:36:46 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: 1429355 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=0L4Rx1vD; 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=NC0xfAm5; 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 4DLXrR75YJz9sCD for ; Thu, 21 Jan 2021 04:41:27 +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=ZavrUlcHKlVrH9WuFOWAJZToZHXsHEflSZQPIDPAPCs=; b=0L4Rx1vDdWLQhgz4gsAtR1t0W nPnC10u3Jo6BvmAj9RZN4fm/8aTIO4S7nEFXHR3bSiK2F1XBW8t04PI50yc2I8GKQ0LTYEI/zsu4W csiNt7XjaoQkL2wB1EIxdsyuRTmq20zkG6tl45Ujp6EXuzhLtTl071bx6n2jbw3eASNaq7dHBEHGb Q8qFOzmBkWgSsKlZQHX50Z6o1HBDLgmtPIrrXnyxJFLCyQINep6VXcfSFZ818y45XlycqeH7tVUbf fcUNjmW9toThc6/Sihd0XyeJIY86Flb4/hgYT2S4fZi0LHirJ5+uMI9jlYfeyDPb8Efrdyn6TR45D Z7tcdhiaA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HSM-0003Sr-Ip; Wed, 20 Jan 2021 17:39:46 +0000 Received: from canardo.mork.no ([2001:4641::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HPk-0002EQ-BK for openwrt-devel@lists.openwrt.org; Wed, 20 Jan 2021 17:37:27 +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 10KHb2p5028864 (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=0AlsmjAJc+g6ZlZWCsREtutNEyf2xfA/RD2eyH99vDg=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=NC0xfAm5djbVpGNnUasNPN8jtg1LPtIIFaLGhzUCd/6NRodj/HNb/iRrf4l9O3Ma2 Ch4zZ++12zJ7zklUJNLE0BJVj8XrRWDpsOVlqz6Ec7LOY8oEk8qBNeKazH2UVywTYF rf4aAx3DvpzJ47LLq1lan/bOQcVVcfv0pMtaY7xM= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10KHb2Nd028857; Wed, 20 Jan 2021 18:37:02 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH v4 03/10] kernel: mtdsplit_uimage: replace "fonfxc" and "sge" parsers Date: Wed, 20 Jan 2021 18:36:46 +0100 Message-Id: <20210120173653.28784-4-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_742217_9500A3DC X-CRM114-Status: GOOD ( 14.34 ) 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 Convert users of the "fonfxc" and "sge" parsers to the generic "openwrt,uimage", using device specific "openwrt,padding" properties. Signed-off-by: Bjørn Mork Tested-by: Stijn Segers --- .../drivers/mtd/mtdsplit/mtdsplit_uimage.c | 93 ++----------------- .../linux/ramips/dts/mt7620a_fon_fon2601.dts | 3 +- .../ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi | 3 +- .../ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi | 6 +- 4 files changed, 16 insertions(+), 89 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 f9544ec382e3..f5e48c661e8f 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c @@ -87,7 +87,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, int *extralen)) + ssize_t (*find_header)(u_char *buf, size_t len)) { struct mtd_partition *parts; u_char *buf; @@ -125,7 +125,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, if (ret) continue; - ret = find_header(buf, MAX_HEADER_LEN, &extralen); + ret = find_header(buf, MAX_HEADER_LEN); if (ret < 0) { pr_debug("no valid uImage found in \"%s\" at offset %llx\n", master->name, (unsigned long long) offset); @@ -213,7 +213,7 @@ err_free_parts: return ret; } -static ssize_t uimage_verify_default(u_char *buf, size_t len, int *extralen) +static ssize_t uimage_verify_default(u_char *buf, size_t len) { struct uimage_header *header = (struct uimage_header *)buf; @@ -274,7 +274,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, int *extralen) +static ssize_t uimage_verify_wndr3700(u_char *buf, size_t len) { struct uimage_header *header = (struct uimage_header *)buf; uint8_t expected_type = IH_TYPE_FILESYSTEM; @@ -336,7 +336,7 @@ static struct mtd_part_parser uimage_netgear_parser = { #define FW_MAGIC_SG8208M 0x00000006 #define FW_MAGIC_SG8310PM 0x83000006 -static ssize_t uimage_verify_allnet(u_char *buf, size_t len, int *extralen) +static ssize_t uimage_verify_allnet(u_char *buf, size_t len) { struct uimage_header *header = (struct uimage_header *)buf; @@ -383,7 +383,7 @@ static struct mtd_part_parser uimage_allnet_parser = { #define FW_EDIMAX_OFFSET 20 #define FW_MAGIC_EDIMAX 0x43535953 -static ssize_t uimage_find_edimax(u_char *buf, size_t len, int *extralen) +static ssize_t uimage_find_edimax(u_char *buf, size_t len) { u32 *magic; @@ -396,7 +396,7 @@ static ssize_t uimage_find_edimax(u_char *buf, size_t len, int *extralen) if (be32_to_cpu(*magic) != FW_MAGIC_EDIMAX) return -EINVAL; - if (!uimage_verify_default(buf + FW_EDIMAX_OFFSET, len, extralen)) + if (!uimage_verify_default(buf + FW_EDIMAX_OFFSET, len)) return FW_EDIMAX_OFFSET; return -EINVAL; @@ -424,88 +424,13 @@ static struct mtd_part_parser uimage_edimax_parser = { .type = MTD_PARSER_TYPE_FIRMWARE, }; - -/************************************************** - * Fon(Foxconn) - **************************************************/ - -#define FONFXC_PAD_LEN 32 - -static ssize_t uimage_find_fonfxc(u_char *buf, size_t len, int *extralen) -{ - if (uimage_verify_default(buf, len, extralen) < 0) - return -EINVAL; - - *extralen = FONFXC_PAD_LEN; - - return 0; -} - -static int -mtdsplit_uimage_parse_fonfxc(struct mtd_info *master, - const struct mtd_partition **pparts, - struct mtd_part_parser_data *data) -{ - return __mtdsplit_parse_uimage(master, pparts, data, - uimage_find_fonfxc); -} - -static const struct of_device_id mtdsplit_uimage_fonfxc_of_match_table[] = { - { .compatible = "fonfxc,uimage" }, - {}, -}; - -static struct mtd_part_parser uimage_fonfxc_parser = { - .owner = THIS_MODULE, - .name = "fonfxc-fw", - .of_match_table = mtdsplit_uimage_fonfxc_of_match_table, - .parse_fn = mtdsplit_uimage_parse_fonfxc, -}; - -/************************************************** - * SGE (T&W) Shenzhen Gongjin Electronics - **************************************************/ - -#define SGE_PAD_LEN 96 - -static ssize_t uimage_find_sge(u_char *buf, size_t len, int *extralen) -{ - if (uimage_verify_default(buf, len, extralen) < 0) - return -EINVAL; - - *extralen = SGE_PAD_LEN; - - return 0; -} - -static int -mtdsplit_uimage_parse_sge(struct mtd_info *master, - const struct mtd_partition **pparts, - struct mtd_part_parser_data *data) -{ - return __mtdsplit_parse_uimage(master, pparts, data, - uimage_find_sge); -} - -static const struct of_device_id mtdsplit_uimage_sge_of_match_table[] = { - { .compatible = "sge,uimage" }, - {}, -}; - -static struct mtd_part_parser uimage_sge_parser = { - .owner = THIS_MODULE, - .name = "sge-fw", - .of_match_table = mtdsplit_uimage_sge_of_match_table, - .parse_fn = mtdsplit_uimage_parse_sge, -}; - /************************************************** * OKLI (OpenWrt Kernel Loader Image) **************************************************/ #define IH_MAGIC_OKLI 0x4f4b4c49 -static ssize_t uimage_verify_okli(u_char *buf, size_t len, int *extralen) +static ssize_t uimage_verify_okli(u_char *buf, size_t len) { struct uimage_header *header = (struct uimage_header *)buf; @@ -562,8 +487,6 @@ static int __init mtdsplit_uimage_init(void) register_mtd_parser(&uimage_netgear_parser); register_mtd_parser(&uimage_allnet_parser); register_mtd_parser(&uimage_edimax_parser); - register_mtd_parser(&uimage_fonfxc_parser); - register_mtd_parser(&uimage_sge_parser); register_mtd_parser(&uimage_okli_parser); return 0; diff --git a/target/linux/ramips/dts/mt7620a_fon_fon2601.dts b/target/linux/ramips/dts/mt7620a_fon_fon2601.dts index 4dc0e28c9f61..ee61c6e59e99 100644 --- a/target/linux/ramips/dts/mt7620a_fon_fon2601.dts +++ b/target/linux/ramips/dts/mt7620a_fon_fon2601.dts @@ -83,7 +83,8 @@ }; partition@50000 { - compatible = "fonfxc,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,padding = <32>; label = "firmware"; reg = <0x50000 0xf90000>; }; diff --git a/target/linux/ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi b/target/linux/ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi index c43cc49aa16f..95ef0afcd9d5 100644 --- a/target/linux/ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi +++ b/target/linux/ramips/dts/mt7621_dlink_dir-8xx-a1.dtsi @@ -34,7 +34,8 @@ }; partition@60000 { - compatible = "sge,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,padding = <96>; label = "firmware"; reg = <0x60000 0xfa0000>; }; diff --git a/target/linux/ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi b/target/linux/ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi index 96c69211243b..a54b2be4f061 100644 --- a/target/linux/ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi +++ b/target/linux/ramips/dts/mt7621_dlink_dir-xx60-a1.dtsi @@ -89,7 +89,8 @@ partition@180000 { label = "firmware"; - compatible = "sge,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,padding = <96>; reg = <0x180000 0x2800000>; }; @@ -101,7 +102,8 @@ partition@4980000 { label = "firmware2"; - compatible = "sge,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,padding = <96>; reg = <0x4980000 0x2800000>; }; From patchwork Wed Jan 20 17:36:47 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: 1429352 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=1KnzIDud; 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=ccdGMrkf; 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 4DLXqn02chz9sCD for ; Thu, 21 Jan 2021 04:40:53 +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=PVGwJr5Ud1s0PXu/n3AeuQHp2chQBCY9D1LIEKyeSSg=; b=1KnzIDudyqAbUmH8IYN1dsoAx NPs2EDTFDgtdzJm0ARp9vTQdSlaoD25imTtE/VlGB9cQyGutdXg1KGvUtwNr2iV8fOLlysjieC9mM v7iquGwTfZ51dT+FKjpacbqBnjOw8GpS3HKJdFCI42o4X/1tLufEEieLAJ7gsoLICQ2KI9KruOeNV OKb0kpseIzpJ71BdX+DYSKWIvqzcF1ips5k02+KcqqVsaPJegKeDTRqwiBHyQm+vINW7QgCLgqVAt ZRMu3TbfFpIR6TjwmJjQOCU0P2F/eVI4BKYF5IlX4bbpaHnPmkoZmz9fEw98EVNLZsLGsDMHU2izB aM6yrljJg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HRi-0003AI-L1; Wed, 20 Jan 2021 17:39: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 1l2HPk-0002EW-SY for openwrt-devel@lists.openwrt.org; Wed, 20 Jan 2021 17:37:26 +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 10KHb2XO028874 (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=1611164223; bh=huCrk7EwuZNbH0cfIffb1h2jbMc7YQDZOytSUcB+Kb0=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=ccdGMrkfFSkJAuA7vVSp73watirK/aRHN2f5dpICAB7TXcXN5KoP5WgQzE05RJaLX drHf48HMaTxTs+h5x9Dv2TgIUv2ruEXBj/BJvmrsLfo9GObUcp/EVbLgaoORqEihwJ PIjVn7OnMIGfMOTLGbzJkF3DrrkhbJRM/+wnNRZs= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10KHb2sg028867; Wed, 20 Jan 2021 18:37:02 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH v4 04/10] kernel: mtdsplit_uimage: add "openwrt, ih-magic" device-tree property Date: Wed, 20 Jan 2021 18:36:47 +0100 Message-Id: <20210120173653.28784-5-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_123705_243248_242A46DC X-CRM114-Status: GOOD ( 14.97 ) 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 Many devices use uimages with non-standard magic values. Let device tree override the default magic. Signed-off-by: Bjørn Mork --- .../drivers/mtd/mtdsplit/mtdsplit_uimage.c | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 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 f5e48c661e8f..58c40e9ec70b 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c @@ -69,13 +69,17 @@ 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) +static void uimage_parse_dt(struct mtd_info *master, int *extralen, u32 *ih_magic) { 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); + + if (!of_property_read_u32(np, "openwrt,padding", extralen)) + 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); } /** @@ -87,7 +91,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)) + ssize_t (*find_header)(u_char *buf, size_t len, u32 ih_magic)) { struct mtd_partition *parts; u_char *buf; @@ -100,6 +104,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, int uimage_part, rf_part; int ret; int extralen = 0; + u32 ih_magic = IH_MAGIC; enum mtdsplit_part_type type; nr_parts = 2; @@ -113,7 +118,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, goto err_free_parts; } - uimage_parse_dt(master, &extralen); + uimage_parse_dt(master, &extralen, &ih_magic); /* find uImage on erase block boundaries */ for (offset = 0; offset < master->size; offset += master->erasesize) { @@ -125,7 +130,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, if (ret) continue; - ret = find_header(buf, MAX_HEADER_LEN); + ret = find_header(buf, MAX_HEADER_LEN, ih_magic); if (ret < 0) { pr_debug("no valid uImage found in \"%s\" at offset %llx\n", master->name, (unsigned long long) offset); @@ -213,26 +218,26 @@ err_free_parts: return ret; } -static ssize_t uimage_verify_default(u_char *buf, size_t len) +static ssize_t uimage_verify_default(u_char *buf, size_t len, u32 ih_magic) { 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\n", - be32_to_cpu(header->ih_magic)); + 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\n", - be32_to_cpu(header->ih_os)); + 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_KERNEL) { - pr_debug("invalid uImage type: %08x\n", - be32_to_cpu(header->ih_type)); + pr_debug("invalid uImage type: %08x != %08x\n", + be32_to_cpu(header->ih_type), IH_TYPE_KERNEL); return -EINVAL; } @@ -274,7 +279,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) +static ssize_t uimage_verify_wndr3700(u_char *buf, size_t len, u32 ih_magic) { struct uimage_header *header = (struct uimage_header *)buf; uint8_t expected_type = IH_TYPE_FILESYSTEM; @@ -336,7 +341,7 @@ static struct mtd_part_parser uimage_netgear_parser = { #define FW_MAGIC_SG8208M 0x00000006 #define FW_MAGIC_SG8310PM 0x83000006 -static ssize_t uimage_verify_allnet(u_char *buf, size_t len) +static ssize_t uimage_verify_allnet(u_char *buf, size_t len, u32 ih_magic) { struct uimage_header *header = (struct uimage_header *)buf; @@ -383,7 +388,7 @@ static struct mtd_part_parser uimage_allnet_parser = { #define FW_EDIMAX_OFFSET 20 #define FW_MAGIC_EDIMAX 0x43535953 -static ssize_t uimage_find_edimax(u_char *buf, size_t len) +static ssize_t uimage_find_edimax(u_char *buf, size_t len, u32 ih_magic) { u32 *magic; @@ -396,7 +401,7 @@ static ssize_t uimage_find_edimax(u_char *buf, size_t len) if (be32_to_cpu(*magic) != FW_MAGIC_EDIMAX) return -EINVAL; - if (!uimage_verify_default(buf + FW_EDIMAX_OFFSET, len)) + if (!uimage_verify_default(buf + FW_EDIMAX_OFFSET, len, ih_magic)) return FW_EDIMAX_OFFSET; return -EINVAL; @@ -430,7 +435,7 @@ static struct mtd_part_parser uimage_edimax_parser = { #define IH_MAGIC_OKLI 0x4f4b4c49 -static ssize_t uimage_verify_okli(u_char *buf, size_t len) +static ssize_t uimage_verify_okli(u_char *buf, size_t len, u32 ih_magic) { struct uimage_header *header = (struct uimage_header *)buf; From patchwork Wed Jan 20 17:36:48 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: 1429358 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=M/dnXRoC; 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=PdWqneAU; 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 4DLXsL2mH9z9sRR for ; Thu, 21 Jan 2021 04:42:14 +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=Pcfo6pNxGsaXchQjQj6bgKFRAuEynzWc+9NOjUAlXpw=; b=M/dnXRoCYV4rktBXXYivv4rVV eIsVRZXtKw6By9OIlE1qEEoiXRLSg2Dqao3NM4DR9qJRPmtyZKFae2sTPACjtEgudckC1FDtz6sAD 31UqOV41q/ut12yCeYQx06nQXN9pVpKvUJV1aa3kJG+tlTB8rr/vFIGKn23D49/KYmfm3nY/zNAfd VSZPSsy8IK36Sk/i/DPLXjaUS9rL/o5G4CGA36wqQYvEUu4yDtlWFEGJyGupSq4ylwBzv46k3ycDM PqQFzJGT6ikV3iWi4YTmvjvMmd76ApZBpXSw3Zm2N/0MUNpEjbKofeWYCQZqs8BxEkXNXtoXaEn8j w5gxQCzhw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HSs-0003hv-H4; Wed, 20 Jan 2021 17:40:18 +0000 Received: from canardo.mork.no ([2001:4641::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HPl-0002FL-H9 for openwrt-devel@lists.openwrt.org; Wed, 20 Jan 2021 17:37:33 +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 10KHb3km028895 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 18:37:03 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1611164223; bh=2ltxfYcx7CaAFZE7qigUDZyHq/otpprc8vX9lenm480=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=PdWqneAUf/z+SIAUILNL1Eo9Hecth8D4Y3lClbGxrGI9ZIvW/BFC0+XAgwavBM4lk +MzAsPreHkT/LFPZvZ4l2BdSgTp6KfcB0dWLQYY1iZT2W2qj0gvtb+Eug8cDtd3FJ7 rwywtSJ+DmPch6zP0RVgrP+r6KLZnIcxxrNzdCi0= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10KHb3Rv028888; Wed, 20 Jan 2021 18:37:03 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH v4 05/10] kernel: mtdsplit_uimage: replace "openwrt, okli" parser Date: Wed, 20 Jan 2021 18:36:48 +0100 Message-Id: <20210120173653.28784-6-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_123706_176981_832BDA67 X-CRM114-Status: GOOD ( 16.23 ) 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: Michael Pratt , =?utf-8?q?Bj=C3=B8rn_Mork?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The only difference between the "openwrt,okli" and the generic parser is the magic. Set this in device tree for all affected devices and remove the "openwrt,okli" parser. Tested-by: Michael Pratt # EAP300 v2, ENS202EXT and ENH202 Signed-off-by: Bjørn Mork --- .../ath79/dts/ar7240_engenius_enh202-v1.dts | 4 +- .../ath79/dts/ar7242_engenius_eap350-v1.dts | 4 +- .../ath79/dts/ar7242_engenius_ecb350-v1.dts | 4 +- .../ath79/dts/ar9341_engenius_eap300-v2.dts | 4 +- .../dts/ar9341_engenius_ens202ext-v1.dts | 4 +- .../linux/ath79/dts/ar9341_pisen_wmb001n.dts | 4 +- .../ath79/dts/ar9344_engenius_exx600.dtsi | 4 +- .../dts/qca9557_engenius_enstationac-v1.dts | 4 +- .../ath79/dts/qca9558_belkin_f9x-v2.dtsi | 4 +- .../drivers/mtd/mtdsplit/mtdsplit_uimage.c | 53 ------------------- .../dt-bindings/mtd/partitions/uimage.h | 5 ++ .../ramips/dts/mt7620n_sunvalley_filehub.dtsi | 4 +- 12 files changed, 35 insertions(+), 63 deletions(-) diff --git a/target/linux/ath79/dts/ar7240_engenius_enh202-v1.dts b/target/linux/ath79/dts/ar7240_engenius_enh202-v1.dts index 1d26a9765b53..7c819e88e796 100644 --- a/target/linux/ath79/dts/ar7240_engenius_enh202-v1.dts +++ b/target/linux/ath79/dts/ar7240_engenius_enh202-v1.dts @@ -4,6 +4,7 @@ #include #include +#include / { compatible = "engenius,enh202-v1", "qca,ar7240"; @@ -80,7 +81,8 @@ #size-cells = <1>; partition@0 { - compatible = "openwrt,okli"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = ; label = "firmware"; reg = <0x0 0x0>; }; diff --git a/target/linux/ath79/dts/ar7242_engenius_eap350-v1.dts b/target/linux/ath79/dts/ar7242_engenius_eap350-v1.dts index 4001897adf4d..39a8a7f25f8c 100644 --- a/target/linux/ath79/dts/ar7242_engenius_eap350-v1.dts +++ b/target/linux/ath79/dts/ar7242_engenius_eap350-v1.dts @@ -4,6 +4,7 @@ #include #include +#include / { compatible = "engenius,eap350-v1", "qca,ar7242"; @@ -59,7 +60,8 @@ #size-cells = <1>; partition@0 { - compatible = "openwrt,okli"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = ; label = "firmware"; reg = <0x0 0x0>; }; diff --git a/target/linux/ath79/dts/ar7242_engenius_ecb350-v1.dts b/target/linux/ath79/dts/ar7242_engenius_ecb350-v1.dts index e73082267c88..0e06ee0128fb 100644 --- a/target/linux/ath79/dts/ar7242_engenius_ecb350-v1.dts +++ b/target/linux/ath79/dts/ar7242_engenius_ecb350-v1.dts @@ -4,6 +4,7 @@ #include #include +#include / { compatible = "engenius,ecb350-v1", "qca,ar7242"; @@ -59,7 +60,8 @@ #size-cells = <1>; partition@0 { - compatible = "openwrt,okli"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = ; label = "firmware"; reg = <0x0 0x0>; }; diff --git a/target/linux/ath79/dts/ar9341_engenius_eap300-v2.dts b/target/linux/ath79/dts/ar9341_engenius_eap300-v2.dts index 3121ec0e0180..7aa89a4cce5c 100644 --- a/target/linux/ath79/dts/ar9341_engenius_eap300-v2.dts +++ b/target/linux/ath79/dts/ar9341_engenius_eap300-v2.dts @@ -4,6 +4,7 @@ #include #include +#include / { model = "Engenius EAP300 v2"; @@ -60,7 +61,8 @@ #size-cells = <1>; partition@0 { - compatible = "openwrt,okli"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = ; label = "firmware"; reg = <0x0 0x0>; }; diff --git a/target/linux/ath79/dts/ar9341_engenius_ens202ext-v1.dts b/target/linux/ath79/dts/ar9341_engenius_ens202ext-v1.dts index 6e296ab49681..38e9b381c0d8 100644 --- a/target/linux/ath79/dts/ar9341_engenius_ens202ext-v1.dts +++ b/target/linux/ath79/dts/ar9341_engenius_ens202ext-v1.dts @@ -4,6 +4,7 @@ #include #include +#include / { model = "Engenius ENS202EXT v1"; @@ -70,7 +71,8 @@ #size-cells = <1>; partition@0 { - compatible = "openwrt,okli"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = ; label = "firmware"; reg = <0x0 0x0>; }; diff --git a/target/linux/ath79/dts/ar9341_pisen_wmb001n.dts b/target/linux/ath79/dts/ar9341_pisen_wmb001n.dts index aaa4d1576bd2..98236d44a683 100644 --- a/target/linux/ath79/dts/ar9341_pisen_wmb001n.dts +++ b/target/linux/ath79/dts/ar9341_pisen_wmb001n.dts @@ -4,6 +4,7 @@ #include #include +#include / { model = "PISEN WMB001N"; @@ -106,7 +107,8 @@ partition@0 { reg = <0x0 0x0>; label = "firmware"; - compatible = "openwrt,okli"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = ; }; }; }; diff --git a/target/linux/ath79/dts/ar9344_engenius_exx600.dtsi b/target/linux/ath79/dts/ar9344_engenius_exx600.dtsi index 5ae2ea66efac..340357b8deb2 100644 --- a/target/linux/ath79/dts/ar9344_engenius_exx600.dtsi +++ b/target/linux/ath79/dts/ar9344_engenius_exx600.dtsi @@ -4,6 +4,7 @@ #include #include +#include / { aliases { @@ -47,7 +48,8 @@ #size-cells = <1>; partition@0 { - compatible = "openwrt,okli"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = ; label = "firmware"; reg = <0x0 0x0>; }; diff --git a/target/linux/ath79/dts/qca9557_engenius_enstationac-v1.dts b/target/linux/ath79/dts/qca9557_engenius_enstationac-v1.dts index f9801693c57f..2cf800cddc4c 100644 --- a/target/linux/ath79/dts/qca9557_engenius_enstationac-v1.dts +++ b/target/linux/ath79/dts/qca9557_engenius_enstationac-v1.dts @@ -4,6 +4,7 @@ #include #include +#include / { compatible = "engenius,enstationac-v1", "qca,qca9557"; @@ -70,7 +71,8 @@ #size-cells = <1>; partition@0 { - compatible = "openwrt,okli"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = ; label = "firmware"; reg = <0x0 0x0>; }; diff --git a/target/linux/ath79/dts/qca9558_belkin_f9x-v2.dtsi b/target/linux/ath79/dts/qca9558_belkin_f9x-v2.dtsi index af22f6681ac2..624e20096f20 100644 --- a/target/linux/ath79/dts/qca9558_belkin_f9x-v2.dtsi +++ b/target/linux/ath79/dts/qca9558_belkin_f9x-v2.dtsi @@ -4,6 +4,7 @@ #include #include +#include / { aliases { @@ -85,7 +86,8 @@ #size-cells = <1>; partition@0 { - compatible = "openwrt,okli"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = ; label = "firmware"; reg = <0x0 0x0>; }; 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 58c40e9ec70b..32c027d3e979 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c @@ -429,58 +429,6 @@ static struct mtd_part_parser uimage_edimax_parser = { .type = MTD_PARSER_TYPE_FIRMWARE, }; -/************************************************** - * OKLI (OpenWrt Kernel Loader Image) - **************************************************/ - -#define IH_MAGIC_OKLI 0x4f4b4c49 - -static ssize_t uimage_verify_okli(u_char *buf, size_t len, u32 ih_magic) -{ - struct uimage_header *header = (struct uimage_header *)buf; - - /* default sanity checks */ - if (be32_to_cpu(header->ih_magic) != IH_MAGIC_OKLI) { - pr_debug("invalid uImage magic: %08x\n", - be32_to_cpu(header->ih_magic)); - return -EINVAL; - } - - if (header->ih_os != IH_OS_LINUX) { - pr_debug("invalid uImage OS: %08x\n", - be32_to_cpu(header->ih_os)); - return -EINVAL; - } - - if (header->ih_type != IH_TYPE_KERNEL) { - pr_debug("invalid uImage type: %08x\n", - be32_to_cpu(header->ih_type)); - return -EINVAL; - } - - return 0; -} - -static int -mtdsplit_uimage_parse_okli(struct mtd_info *master, - const struct mtd_partition **pparts, - struct mtd_part_parser_data *data) -{ - return __mtdsplit_parse_uimage(master, pparts, data, - uimage_verify_okli); -} - -static const struct of_device_id mtdsplit_uimage_okli_of_match_table[] = { - { .compatible = "openwrt,okli" }, - {}, -}; - -static struct mtd_part_parser uimage_okli_parser = { - .owner = THIS_MODULE, - .name = "okli-fw", - .of_match_table = mtdsplit_uimage_okli_of_match_table, - .parse_fn = mtdsplit_uimage_parse_okli, -}; /************************************************** * Init @@ -492,7 +440,6 @@ static int __init mtdsplit_uimage_init(void) register_mtd_parser(&uimage_netgear_parser); register_mtd_parser(&uimage_allnet_parser); register_mtd_parser(&uimage_edimax_parser); - register_mtd_parser(&uimage_okli_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 29eec38dd282..407e46ce2c46 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 @@ -188,4 +188,9 @@ #define IH_MAGIC 0x27051956 /* Image Magic Number */ #define IH_NMLEN 32 /* Image Name Length */ +/* + * Magic values specific to "openwrt,uimage" partitions + */ +#define IH_MAGIC_OKLI 0x4f4b4c49 /* 'OKLI' */ + #endif /* __UIMAGE_H__ */ diff --git a/target/linux/ramips/dts/mt7620n_sunvalley_filehub.dtsi b/target/linux/ramips/dts/mt7620n_sunvalley_filehub.dtsi index beca2954dc8f..20ff2dbd1c3d 100644 --- a/target/linux/ramips/dts/mt7620n_sunvalley_filehub.dtsi +++ b/target/linux/ramips/dts/mt7620n_sunvalley_filehub.dtsi @@ -4,6 +4,7 @@ #include #include +#include / { aliases { @@ -31,7 +32,8 @@ #size-cells = <1>; partition@0 { - compatible = "openwrt,okli"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = ; label = "firmware"; reg = <0x0 0x0>; }; From patchwork Wed Jan 20 17:36:49 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: 1429356 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=QnbmVdky; 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=m/cE0XkR; 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 4DLXrZ4c8fz9sCD for ; Thu, 21 Jan 2021 04:41:34 +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=RwivgTRkwaNouLjxchzt7bFMF5PlxkvtDKt6of+adXY=; b=QnbmVdky11/6dlPdDRhGxBxpg kh8ipRml/kCJdLkY4B/rV8szZIHCe6utMQF1Ivyu/jnPAlltLM2wlL3zwm+DJomeKxYtl0RoDCovB u8bZ2PSQtANvk9R/ROKKQl1tvtfyt3Cy9F3uHivv7BEu8737rtkDVHOnwAsbW5YbkJMWSuJdUlxBy rGnTBj+K9m0EzQJZo8yDlCsh5mFQ0k2ixTzjdalg+Jat6e1qWb3+gbwWOC6UZziNtTkBOZK5PYqJw XrS4+wVNb/kzbvtUBHdc8Rp9p9xqQOGUW+1z2cwBXbvJ9OZOwIBonkUwWraxECPqJNq5bvX0OF5tW sPeY4hl/g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HSl-0003ch-L5; Wed, 20 Jan 2021 17:40:11 +0000 Received: from canardo.mork.no ([2001:4641::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HPm-0002FY-72 for openwrt-devel@lists.openwrt.org; Wed, 20 Jan 2021 17:37:31 +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 10KHb4dI028905 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 18:37:04 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1611164224; bh=Wobof2gp1ijSPUhr+bfRSBDVbYsolGVMcqpM+kWG8kw=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=m/cE0XkRwdLKghSuijMlKk62YqsoFvzlt7Psk2s1UKr9bZgzGowMTOaV5dhSnRmFX fWg894UPfEhDG2ijItG1JSjyCjG0LtJAs7JDrGYfXRCvu15tH7B1UJGVoTx5vPQmpm U0jRXaEKJQKZuQPff2HULiH+Sm3xGoZeqr9Ql0Ls= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10KHb4Cn028898; Wed, 20 Jan 2021 18:37:04 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH v4 06/10] kernel: mtdsplit_uimage: replace "allnet, uimage" parser Date: Wed, 20 Jan 2021 18:36:49 +0100 Message-Id: <20210120173653.28784-7-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_123706_973160_91894E2D X-CRM114-Status: GOOD ( 13.28 ) 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 Convert users to the generic "openwrt,uimage" using device specific "openwrt,ih-magic" properties, and remove "allnet,uimage". Signed-off-by: Bjørn Mork --- .../drivers/mtd/mtdsplit/mtdsplit_uimage.c | 49 ------------------- .../dts/rtl8382_allnet_all-sg8208m.dts | 3 +- 2 files changed, 2 insertions(+), 50 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 32c027d3e979..55eaca9946a0 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c @@ -333,54 +333,6 @@ static struct mtd_part_parser uimage_netgear_parser = { }; - -/************************************************** - * ALLNET - **************************************************/ - -#define FW_MAGIC_SG8208M 0x00000006 -#define FW_MAGIC_SG8310PM 0x83000006 - -static ssize_t uimage_verify_allnet(u_char *buf, size_t len, u32 ih_magic) -{ - struct uimage_header *header = (struct uimage_header *)buf; - - switch (be32_to_cpu(header->ih_magic)) { - case FW_MAGIC_SG8208M: - case FW_MAGIC_SG8310PM: - break; - default: - return -EINVAL; - } - - if (header->ih_os != IH_OS_LINUX) - return -EINVAL; - - return 0; -} - -static int -mtdsplit_uimage_parse_allnet(struct mtd_info *master, - const struct mtd_partition **pparts, - struct mtd_part_parser_data *data) -{ - return __mtdsplit_parse_uimage(master, pparts, data, - uimage_verify_allnet); -} - -static const struct of_device_id mtdsplit_uimage_allnet_of_match_table[] = { - { .compatible = "allnet,uimage" }, - {}, -}; - -static struct mtd_part_parser uimage_allnet_parser = { - .owner = THIS_MODULE, - .name = "allnet-fw", - .of_match_table = mtdsplit_uimage_allnet_of_match_table, - .parse_fn = mtdsplit_uimage_parse_allnet, -}; - - /************************************************** * Edimax **************************************************/ @@ -438,7 +390,6 @@ static int __init mtdsplit_uimage_init(void) { register_mtd_parser(&uimage_generic_parser); register_mtd_parser(&uimage_netgear_parser); - register_mtd_parser(&uimage_allnet_parser); register_mtd_parser(&uimage_edimax_parser); return 0; diff --git a/target/linux/realtek/dts/rtl8382_allnet_all-sg8208m.dts b/target/linux/realtek/dts/rtl8382_allnet_all-sg8208m.dts index 28c4fd2970ba..681d699e8a32 100644 --- a/target/linux/realtek/dts/rtl8382_allnet_all-sg8208m.dts +++ b/target/linux/realtek/dts/rtl8382_allnet_all-sg8208m.dts @@ -95,7 +95,8 @@ partition@2a0000 { label = "firmware"; reg = <0x2a0000 0xd60000>; - compatible = "allnet,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x00000006>; }; }; }; From patchwork Wed Jan 20 17:36:50 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: 1429361 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=UltdYo6D; 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=efdtKWri; 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=QI50XIa+; 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 4DLXsw4k4bz9sRR for ; Thu, 21 Jan 2021 04:42:44 +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=UltdYo6D5AuM1jN4pBAPhbMlE bu9GiNgQAHHpSB4aHNRc3AILGr8xN4vc/a4JwrpYmus42a5hlEc9ZADWFafu+1HBRSOqSBOG8DZpY EXgqGu3cJ2VYBHVDbedK+xB2WAcbq8GR2pV9Xwkf4KWcFzguoILy9V/ZOtHVnXMXryaebW9MfPQa1 2ubo67izq6iE18DqJiT1mLP7vC560LE5yQRwSCOcso2H2FpKgBf9wng5OEUyMOMOmALsDEXvEVE1z qkGgStDvAfr+MCWFDkMHzSSoCm3A3PT09v81df/fYPzOFX/aYfCtZmRMpN32SsVzj7ePHHc005FJz ZR+fiouKA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HT6-0003rO-JD; Wed, 20 Jan 2021 17:40:32 +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 1l2HQQ-0002W8-Sm 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=5zUuCMOzdLc1hnulnhateq1fvBlpEy6hw/Iwp/BxiI0=; b=efdtKWritxELbOPTRC5W9mnNE+ 9iAKoT4pEL/aHPlMNz9BP6TvXw+oLzn5UnHufoaFLJHCTo2FhRZfk2tcj/tMG22Y4M4hCDly2oHyS kUVXRJoBoNRhhjTkQwithBq8OYAHK/Gq5fATNhjCqINHnPuGkXcgNSZYEzpgLC2vG3j0JjaVm7THX ZoZOB2E3gpA/8V6WMNP78OPDEvUQDwq0xPW0QaklST0ocmLKVN4lnB5KEcb/Kx4XGPCar6qJC/qza hbmU6RsLkWvekMOgMb+AVuvL22DTR2DfuPxKMAA3uUwDsAKBj8cMiqm6A1kZ+uveLLC6+ZF4Pd8Yu xnEyFCKA==; Received: from canardo.mork.no ([2001:4641::1]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1l2HQ1-00FztR-HN for openwrt-devel@lists.openwrt.org; Wed, 20 Jan 2021 17:37:32 +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 10KHb4Zs028915 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 18:37:04 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1611164224; bh=5zUuCMOzdLc1hnulnhateq1fvBlpEy6hw/Iwp/BxiI0=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=QI50XIa+bSe8IsLjrMMmanEoGvmBU8IW2eSn/rGsZyy6OfVYSVZCZE8MTIgUbIPFX sWOIfsyNdYQo+o0sPQrAdocFgxf0uMf06FKkaamPzD6m9YStpbLeA5YByW9CaWfLGO oPFLdLJRPCyWMNc4HzhiT211S3nuIbUle3SAFuw4= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10KHb4TS028909; Wed, 20 Jan 2021 18:37:04 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH v4 07/10] kernel: mtdsplit_uimage: add "openwrt, ih-type" device-tree property Date: Wed, 20 Jan 2021 18:36:50 +0100 Message-Id: <20210120173653.28784-8-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_173732_300382_20A5A51A X-CRM114-Status: GOOD ( 12.78 ) 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 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; From patchwork Wed Jan 20 17:36:51 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: 1429363 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=eKF1TelZ; 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=HJvKo0iH; 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=UhwbK1AP; 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 4DLXt32HTQz9sVr for ; Thu, 21 Jan 2021 04:42:51 +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=/hcx4iMQFmNdn9oekN8hy61o6k3XukbE1ZQV6ebdTMk=; b=eKF1TelZB/uD2FVXzgx8pHwF7 1LZr9KwxBwfudu9kexaYdx7kC8ItoAti3FSTNGapbyUMmZKbsQLcTJle9f73WyTOzidUrA64WaEQH HDsRHfBRSxSLCs+BpZFjPHBXRsK1+ikGj+k240N5lb2AAMF7v6rQGvta4rduDi9rXd5hKn8ZhGcRe fplc6E5IjDSWmCdsRtWjeWdVLhS2sMFQ3Dxo11uOsEZ4pAC0FKqAdz3cSmgxWX+OfKN7tMx5piCOD PGJTJnS/HfrT/NK7YbI1eobnUT5aHlGHhtcSe2x0e4Z58HEhv2tOfxuyyMcAzPZoM2Ad5APh/yJlp dGID7G/nQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2HTC-0003uW-6L; Wed, 20 Jan 2021 17:40:38 +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 1l2HQS-0002Wr-4f for openwrt-devel@merlin.infradead.org; Wed, 20 Jan 2021 17:37:48 +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=dpZqy4FZyRiWxoITAvZerJ2VaUhX9zMsWGrBFpAPPlA=; b=HJvKo0iHMVXsAg7vFmRJz29g7r Bb+nAoQK9luXrBFdli8oi48QqGmIE4ywn9cKVTA2MJXrCfNB084Sw3LqzEEngnKXkh3ShhoAnLsx7 wEt2irqls/yHG2FSoIWhIMIGCq3yn3llhEc85AqdmaUcpV1V/jF9/1KWbhePEFxk4Ns/Om5RBfNHs GGoeiz++AxD44w+rMaqSm8kMJXeT+19oyPdM9Fc65QIMKyXaZCkLbSK86ofmfZjeC1Pw1cJXlXLxS k8o2RhLTuCXw6r+6oRMkEWZvCnmt3/JU7AhNlztoDG62CRIoBdnnhPE9MvS/8wnaDV+9UZvUBK0Ha QhHtlVFQ==; Received: from canardo.mork.no ([2001:4641::1]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1l2HQ9-00FztT-V4 for openwrt-devel@lists.openwrt.org; Wed, 20 Jan 2021 17:37:36 +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 10KHb5Zv028934 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 18:37:05 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1611164225; bh=dpZqy4FZyRiWxoITAvZerJ2VaUhX9zMsWGrBFpAPPlA=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=UhwbK1AP/UAiN+qbTYattWFUDSR9MmY666sKils2N140UiLQtz9iLikOt/wa0TsiN d+rG+gS7OS0txXx4bd15k/x+P2LWK0+nohtgU9UCKPcvW9MqRvFntZrITlUym/HNZV Gl0dsX8yKV8Ut8NSQVDVodWrqwu/bGFT6kKLZJZ4= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10KHb4tf028928; Wed, 20 Jan 2021 18:37:04 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH v4 08/10] kernel: mtdsplit_uimage: replace "netgear, uimage" parser Date: Wed, 20 Jan 2021 18:36:51 +0100 Message-Id: <20210120173653.28784-9-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_173736_044680_A5FDB2D7 X-CRM114-Status: GOOD ( 12.88 ) 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: Sander Vanheule , Stijn Segers , =?utf-8?q?Bj=C3=B8rn_Mork?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The "netgear,uimage" parser can be replaced by the generic parser using device specific openwrt,ih-magic and openwrt,ih-type properties. Device tree properties for the following devices have not been set, as they have been dropped from OpenWrt with the removal of the ar71xx target: FW_MAGIC_WNR2000V1 0x32303031 FW_MAGIC_WNR2000V4 0x32303034 FW_MAGIC_WNR1000V2_VC 0x31303030 FW_MAGIC_WPN824N 0x31313030 Tested-by: Sander Vanheule # WNDR3700v2 Tested-by: Stijn Segers # WNDR3700v1 Signed-off-by: Bjørn Mork --- .../linux/ath79/dts/ar7161_netgear_wndr.dtsi | 1 + .../ath79/dts/ar7161_netgear_wndr3700-v2.dts | 4 +- .../ath79/dts/ar7161_netgear_wndr3700.dts | 4 +- .../ath79/dts/ar7161_netgear_wndr3800.dts | 4 +- .../ath79/dts/ar7161_netgear_wndr3800ch.dts | 4 +- .../ath79/dts/ar7161_netgear_wndrmac-v1.dts | 4 +- .../ath79/dts/ar7161_netgear_wndrmac-v2.dts | 4 +- .../ath79/dts/ar7240_netgear_wnr1000-v2.dts | 5 +- .../ath79/dts/ar7240_netgear_wnr612-v2.dtsi | 5 +- .../ath79/dts/ar7241_netgear_wnr2000-v3.dts | 5 +- .../ath79/dts/ar7241_netgear_wnr2200-16m.dts | 4 +- .../ath79/dts/ar7241_netgear_wnr2200-8m.dts | 4 +- .../ath79/dts/ar7241_netgear_wnr2200.dtsi | 1 + .../linux/ath79/dts/ar9344_netgear_wndr.dtsi | 5 +- .../drivers/mtd/mtdsplit/mtdsplit_uimage.c | 67 ------------------- .../dts/rtl8380_netgear_gs110tpp-v1.dts | 3 +- 16 files changed, 44 insertions(+), 80 deletions(-) diff --git a/target/linux/ath79/dts/ar7161_netgear_wndr.dtsi b/target/linux/ath79/dts/ar7161_netgear_wndr.dtsi index 61097f967955..217128546f91 100644 --- a/target/linux/ath79/dts/ar7161_netgear_wndr.dtsi +++ b/target/linux/ath79/dts/ar7161_netgear_wndr.dtsi @@ -4,6 +4,7 @@ #include #include +#include / { aliases { diff --git a/target/linux/ath79/dts/ar7161_netgear_wndr3700-v2.dts b/target/linux/ath79/dts/ar7161_netgear_wndr3700-v2.dts index 0543c471130c..6d78c019dac1 100644 --- a/target/linux/ath79/dts/ar7161_netgear_wndr3700-v2.dts +++ b/target/linux/ath79/dts/ar7161_netgear_wndr3700-v2.dts @@ -22,7 +22,9 @@ partition@70000 { label = "firmware"; reg = <0x070000 0xf80000>; - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x33373031>; + openwrt,ih-type = ; }; art: partition@ff0000 { diff --git a/target/linux/ath79/dts/ar7161_netgear_wndr3700.dts b/target/linux/ath79/dts/ar7161_netgear_wndr3700.dts index 955dd2edf0f1..ad29d256f6d8 100644 --- a/target/linux/ath79/dts/ar7161_netgear_wndr3700.dts +++ b/target/linux/ath79/dts/ar7161_netgear_wndr3700.dts @@ -22,7 +22,9 @@ partition@70000 { label = "firmware"; reg = <0x070000 0x780000>; - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x33373030>; + openwrt,ih-type = ; }; art: partition@7f0000 { diff --git a/target/linux/ath79/dts/ar7161_netgear_wndr3800.dts b/target/linux/ath79/dts/ar7161_netgear_wndr3800.dts index 41fe401ddb01..80b25492b1b7 100644 --- a/target/linux/ath79/dts/ar7161_netgear_wndr3800.dts +++ b/target/linux/ath79/dts/ar7161_netgear_wndr3800.dts @@ -23,7 +23,9 @@ partition@70000 { label = "firmware"; reg = <0x070000 0xf80000>; - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x33373031>; + openwrt,ih-type = ; }; art: partition@ff0000 { diff --git a/target/linux/ath79/dts/ar7161_netgear_wndr3800ch.dts b/target/linux/ath79/dts/ar7161_netgear_wndr3800ch.dts index 79569adba87f..cc51aca8b636 100644 --- a/target/linux/ath79/dts/ar7161_netgear_wndr3800ch.dts +++ b/target/linux/ath79/dts/ar7161_netgear_wndr3800ch.dts @@ -23,7 +23,9 @@ partition@70000 { label = "firmware"; reg = <0x070000 0xf80000>; - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x33373031>; + openwrt,ih-type = ; }; art: partition@ff0000 { diff --git a/target/linux/ath79/dts/ar7161_netgear_wndrmac-v1.dts b/target/linux/ath79/dts/ar7161_netgear_wndrmac-v1.dts index 65d2393c67a3..8604414d1998 100644 --- a/target/linux/ath79/dts/ar7161_netgear_wndrmac-v1.dts +++ b/target/linux/ath79/dts/ar7161_netgear_wndrmac-v1.dts @@ -22,7 +22,9 @@ partition@70000 { label = "firmware"; reg = <0x070000 0xf80000>; - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x33373031>; + openwrt,ih-type = ; }; art: partition@ff0000 { diff --git a/target/linux/ath79/dts/ar7161_netgear_wndrmac-v2.dts b/target/linux/ath79/dts/ar7161_netgear_wndrmac-v2.dts index f7641203cf01..bebd96c72f09 100644 --- a/target/linux/ath79/dts/ar7161_netgear_wndrmac-v2.dts +++ b/target/linux/ath79/dts/ar7161_netgear_wndrmac-v2.dts @@ -23,7 +23,9 @@ partition@70000 { label = "firmware"; reg = <0x070000 0xf80000>; - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x33373031>; + openwrt,ih-type = ; }; art: partition@ff0000 { diff --git a/target/linux/ath79/dts/ar7240_netgear_wnr1000-v2.dts b/target/linux/ath79/dts/ar7240_netgear_wnr1000-v2.dts index d700ea73fa62..0c94c9028487 100644 --- a/target/linux/ath79/dts/ar7240_netgear_wnr1000-v2.dts +++ b/target/linux/ath79/dts/ar7240_netgear_wnr1000-v2.dts @@ -4,6 +4,7 @@ #include #include +#include / { compatible = "netgear,wnr1000-v2", "qca,ar7240"; @@ -158,7 +159,9 @@ partition@50000 { label = "firmware"; reg = <0x50000 0x3a0000>; - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x31303031>; + openwrt,ih-type = ; }; art: partition@3f0000 { diff --git a/target/linux/ath79/dts/ar7240_netgear_wnr612-v2.dtsi b/target/linux/ath79/dts/ar7240_netgear_wnr612-v2.dtsi index 382529b32d00..036041259840 100644 --- a/target/linux/ath79/dts/ar7240_netgear_wnr612-v2.dtsi +++ b/target/linux/ath79/dts/ar7240_netgear_wnr612-v2.dtsi @@ -4,6 +4,7 @@ #include #include +#include / { aliases { @@ -89,7 +90,9 @@ }; partition@50000 { - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x32303631>; + openwrt,ih-type = ; reg = <0x50000 0x3a0000>; label = "firmware"; }; diff --git a/target/linux/ath79/dts/ar7241_netgear_wnr2000-v3.dts b/target/linux/ath79/dts/ar7241_netgear_wnr2000-v3.dts index 2e7ea746dff6..831f3e9c2501 100644 --- a/target/linux/ath79/dts/ar7241_netgear_wnr2000-v3.dts +++ b/target/linux/ath79/dts/ar7241_netgear_wnr2000-v3.dts @@ -4,6 +4,7 @@ #include #include +#include / { compatible = "netgear,wnr2000-v3", "qca,ar7241"; @@ -161,7 +162,9 @@ partition@50000 { label = "firmware"; reg = <0x50000 0x3a0000>; - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x32303033>; + openwrt,ih-type = ; }; art: partition@3f0000 { diff --git a/target/linux/ath79/dts/ar7241_netgear_wnr2200-16m.dts b/target/linux/ath79/dts/ar7241_netgear_wnr2200-16m.dts index 2c7443654788..3842238e540e 100644 --- a/target/linux/ath79/dts/ar7241_netgear_wnr2200-16m.dts +++ b/target/linux/ath79/dts/ar7241_netgear_wnr2200-16m.dts @@ -22,7 +22,9 @@ partition@50000 { label = "firmware"; reg = <0x50000 0xfa0000>; - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x32323030>; + openwrt,ih-type = ; }; art: partition@ff0000 { diff --git a/target/linux/ath79/dts/ar7241_netgear_wnr2200-8m.dts b/target/linux/ath79/dts/ar7241_netgear_wnr2200-8m.dts index c23cb6e00250..4eb15e23136f 100644 --- a/target/linux/ath79/dts/ar7241_netgear_wnr2200-8m.dts +++ b/target/linux/ath79/dts/ar7241_netgear_wnr2200-8m.dts @@ -22,7 +22,9 @@ partition@50000 { label = "firmware"; reg = <0x50000 0x7a0000>; - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x32323030>; + openwrt,ih-type = ; }; art: partition@7f0000 { diff --git a/target/linux/ath79/dts/ar7241_netgear_wnr2200.dtsi b/target/linux/ath79/dts/ar7241_netgear_wnr2200.dtsi index c61e188e3284..625f4b068473 100644 --- a/target/linux/ath79/dts/ar7241_netgear_wnr2200.dtsi +++ b/target/linux/ath79/dts/ar7241_netgear_wnr2200.dtsi @@ -4,6 +4,7 @@ #include #include +#include / { chosen { diff --git a/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi b/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi index 26f9db5924fc..ac012eafb437 100644 --- a/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi +++ b/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi @@ -4,6 +4,7 @@ #include #include +#include / { chosen { @@ -161,7 +162,9 @@ partition@6c0000 { label = "firmware"; reg = <0x6c0000 0x1900000>; - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x33373033>; + openwrt,ih-type = ; }; partition@1fc0000 { 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 ef2d857abb04..c29eb6234bc2 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c @@ -271,72 +271,6 @@ static struct mtd_part_parser uimage_generic_parser = { .type = MTD_PARSER_TYPE_FIRMWARE, }; -#define FW_MAGIC_GS110TPPV1 0x4e474520 -#define FW_MAGIC_WNR2000V1 0x32303031 -#define FW_MAGIC_WNR2000V3 0x32303033 -#define FW_MAGIC_WNR2000V4 0x32303034 -#define FW_MAGIC_WNR2200 0x32323030 -#define FW_MAGIC_WNR612V2 0x32303631 -#define FW_MAGIC_WNR1000V2 0x31303031 -#define FW_MAGIC_WNR1000V2_VC 0x31303030 -#define FW_MAGIC_WNDR3700 0x33373030 -#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, u32 ih_type) -{ - struct uimage_header *header = (struct uimage_header *)buf; - uint8_t expected_type = IH_TYPE_FILESYSTEM; - - switch (be32_to_cpu(header->ih_magic)) { - case FW_MAGIC_GS110TPPV1: - case FW_MAGIC_WNR2000V4: - expected_type = IH_TYPE_KERNEL; - break; - case FW_MAGIC_WNR612V2: - case FW_MAGIC_WNR1000V2: - case FW_MAGIC_WNR1000V2_VC: - case FW_MAGIC_WNR2000V1: - case FW_MAGIC_WNR2000V3: - case FW_MAGIC_WNR2200: - case FW_MAGIC_WNDR3700: - case FW_MAGIC_WNDR3700V2: - case FW_MAGIC_WPN824N: - break; - default: - return -EINVAL; - } - - if (header->ih_os != IH_OS_LINUX || - header->ih_type != expected_type) - return -EINVAL; - - return 0; -} - -static int -mtdsplit_uimage_parse_netgear(struct mtd_info *master, - const struct mtd_partition **pparts, - struct mtd_part_parser_data *data) -{ - return __mtdsplit_parse_uimage(master, pparts, data, - uimage_verify_wndr3700); -} - -static const struct of_device_id mtdsplit_uimage_netgear_of_match_table[] = { - { .compatible = "netgear,uimage" }, - {}, -}; - -static struct mtd_part_parser uimage_netgear_parser = { - .owner = THIS_MODULE, - .name = "netgear-fw", - .of_match_table = mtdsplit_uimage_netgear_of_match_table, - .parse_fn = mtdsplit_uimage_parse_netgear, - .type = MTD_PARSER_TYPE_FIRMWARE, - -}; - /************************************************** * Edimax **************************************************/ @@ -393,7 +327,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_netgear_parser); register_mtd_parser(&uimage_edimax_parser); return 0; diff --git a/target/linux/realtek/dts/rtl8380_netgear_gs110tpp-v1.dts b/target/linux/realtek/dts/rtl8380_netgear_gs110tpp-v1.dts index 251585a8dafb..cd9342f3f13b 100644 --- a/target/linux/realtek/dts/rtl8380_netgear_gs110tpp-v1.dts +++ b/target/linux/realtek/dts/rtl8380_netgear_gs110tpp-v1.dts @@ -70,7 +70,8 @@ }; partition@300000{ label = "firmware"; - compatible = "netgear,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x4e474520>; reg = <0x0300000 0x1d00000>; }; }; From patchwork Wed Jan 20 17:36:52 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: 1429376 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=u7Gj0xhr; 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=i0Q0cKr5; 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 4DLY5Y0cL6z9sRR for ; Thu, 21 Jan 2021 04:52:49 +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=I+QVAnjJ6lpo+ynLmdkfSGQ+Ur13jl8JQODOQrJfEwU=; b=u7Gj0xhr+PNeN/WWjcB7Amuz5 B4yfn16e6cWakRGRvAhR4inZV+o7kuTM3PF/cfKHzSfUHahv6zQBjqCAYOvA8K3AcCYTNoCkwMm5w cxCgF0jYe/vWgYcI1zeZLBW0AYVQDwrQyaQMdoRuj3qImyepHl5BerUJ4xXyV5RpZ/OhK3YTTwZlj sW1DqkW/F6TQfEKP4/P4bXwcIiEERsAXghpYiQFNXW6vrrk0Yb6o+GTb/bqcybihN9BncAxgIARGW 6H4RnXhTKf05Uuudvaew7DygDoxz8Hk0Xp0i4KugDks/OBQJnIOfv5n59AXiamhooID8tZ8BSje+e IlORRfnnA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2Hd9-00012N-UH; Wed, 20 Jan 2021 17:50:56 +0000 Received: from canardo.mork.no ([2001:4641::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2Hd5-0000zf-Mw for openwrt-devel@lists.openwrt.org; Wed, 20 Jan 2021 17:50:53 +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 10KHb57I028944 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 18:37:05 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1611164225; bh=xPEIR9ZREDdsw4/DYjsni00fMKrcyvgxTi7EypUXuBk=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=i0Q0cKr58rP/+uCyEO87fqVawrqKzG2xnWDjtz24niUVr35TTQUXl/H0kr+YSsbdV ZtuMWUG1UqLb9PI87mOWYK6SSmuJMjsdWs88tpWYFA6dhCJyzCB5rQXao7XBK2mJJ7 GhbeE0RKrnhSl1TJLpZMdb0qpXsjjUTGQlUgXE1k= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10KHb5D3028937; Wed, 20 Jan 2021 18:37:05 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH v4 09/10] kernel: mtdsplit_uimage: add "openwrt, offset" and "openwrt, partition-magic" Date: Wed, 20 Jan 2021 18:36:52 +0100 Message-Id: <20210120173653.28784-10-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_125052_060111_D41DADC4 X-CRM114-Status: GOOD ( 15.21 ) 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 prepend a standard U-Boot Image with a vendor specific header, having its own magic. Adding two new properties will support validation of such images, including the additional magic. Signed-off-by: Bjørn Mork --- .../drivers/mtd/mtdsplit/mtdsplit_uimage.c | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 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 c29eb6234bc2..7a8ccdf8f59a 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c @@ -70,7 +70,8 @@ read_uimage_header(struct mtd_info *mtd, size_t offset, u_char *buf, } static void uimage_parse_dt(struct mtd_info *master, int *extralen, - u32 *ih_magic, u32 *ih_type) + u32 *ih_magic, u32 *ih_type, + u32 *header_offset, u32 *part_magic) { struct device_node *np = mtd_get_of_node(master); @@ -83,6 +84,10 @@ static void uimage_parse_dt(struct mtd_info *master, int *extralen, 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); + if (!of_property_read_u32(np, "openwrt,offset", header_offset)) + pr_debug("got ih-start=%u from device-tree\n", *header_offset); + if (!of_property_read_u32(np, "openwrt,partition-magic", part_magic)) + pr_debug("got openwrt,partition-magic=%08x from device-tree\n", *part_magic); } /** @@ -92,9 +97,9 @@ static void uimage_parse_dt(struct mtd_info *master, int *extralen, * and tail padding length of a valid uImage header if found */ 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)) + 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_partition *parts; u_char *buf; @@ -104,11 +109,14 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, size_t uimage_size = 0; size_t rootfs_offset; size_t rootfs_size = 0; + size_t buflen; int uimage_part, rf_part; int ret; int extralen = 0; u32 ih_magic = IH_MAGIC; u32 ih_type = IH_TYPE_KERNEL; + u32 header_offset = 0; + u32 part_magic = 0; enum mtdsplit_part_type type; nr_parts = 2; @@ -116,34 +124,42 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, if (!parts) return -ENOMEM; - buf = vmalloc(MAX_HEADER_LEN); + uimage_parse_dt(master, &extralen, &ih_magic, &ih_type, &header_offset, &part_magic); + buflen = MAX_HEADER_LEN; + buf = vmalloc(buflen); if (!buf) { ret = -ENOMEM; goto err_free_parts; } - uimage_parse_dt(master, &extralen, &ih_magic, &ih_type); - /* find uImage on erase block boundaries */ for (offset = 0; offset < master->size; offset += master->erasesize) { struct uimage_header *header; uimage_size = 0; - ret = read_uimage_header(master, offset, buf, MAX_HEADER_LEN); + ret = read_uimage_header(master, offset, buf, buflen); if (ret) continue; - ret = find_header(buf, MAX_HEADER_LEN, ih_magic, ih_type); + /* verify optional partition magic before uimage header */ + if (header_offset && part_magic && (be32_to_cpu(*(u32 *)buf) != part_magic)) + continue; + + ret = find_header(buf + header_offset, buflen, 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; } - header = (struct uimage_header *)(buf + ret); + + /* let uimage_find_edimax override the offset */ + if (ret > 0) + header_offset = ret; + header = (struct uimage_header *)(buf + header_offset); uimage_size = sizeof(*header) + - be32_to_cpu(header->ih_size) + ret + extralen; + be32_to_cpu(header->ih_size) + header_offset + extralen; if ((offset + uimage_size) > master->size) { pr_debug("uImage exceeds MTD device \"%s\"\n", @@ -254,7 +270,7 @@ mtdsplit_uimage_parse_generic(struct mtd_info *master, struct mtd_part_parser_data *data) { return __mtdsplit_parse_uimage(master, pparts, data, - uimage_verify_default); + uimage_verify_default); } static const struct of_device_id mtdsplit_uimage_of_match_table[] = { 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"; };