Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7556091rwb; Tue, 15 Nov 2022 14:15:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf57dqXMEj1XGSlV85kBhKjX77m46DFFeZ3nDEcjlaLlFaSCw/eFhGHWMZlNTYsVURFJN5Te X-Received: by 2002:a63:5850:0:b0:434:aa27:d8e8 with SMTP id i16-20020a635850000000b00434aa27d8e8mr18270384pgm.275.1668550540421; Tue, 15 Nov 2022 14:15:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668550540; cv=none; d=google.com; s=arc-20160816; b=x20wiSICAnUayfRpDYqIQ8PL0m1vbiW0m1xwFm8Y9UTIGfLVz8nHqhHAIzce7tQL7u dyIuZKLWDPLjIBlE5bYL43vVvLnNwca8qmykjjRArFax2EDyPfJpgotILvxXX4CyTBrl sfkVk90kFecUU5abwBsvr/cJSrHJECGdxQ2qIJQ5wV5JzBML+ADoXl3tGLKiH4i+2zPs wOaSe5W+Psa9JLzl7gH4xQL623JFD2JWT3jI0ex/6AuBkKylnOerLW+sWmCmDoHDaqSv 1LZUg8pJM8ZzpUUvsQuEEZwd2Dg23GC1twPqfSPizJiO9/IoPLk28mv84vuVzn091NtR B32A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date; bh=jIB+drL//9xdhL4Y7mFRVUyT3AZOZ8Mg/P5PwADhKwo=; b=LG2dQM4zoZIreDnTX5WlGLF8QCLEgLK7UDqsGEeLwrHm1ROTu7KfPqBj0E9gFSqFt3 I7smy3CzUKE2+lxqNPP0TLhuUtm3ZU2zpCfRB6HVrkPBTP0+bZgwbrrnEaKMjud/xMzQ qZoKijiNMYxEUIjYNrsjIeZ1+JLL3gJILODVU2Ko7fisHmWX8rVDtzJVkDQ0ARr6B5op 18OuaholnF5Cc5PCTWJUcQlBrvXQovH9/2B7+VZR1ERLhh8XRFBcc/hgNX1tzJsYkmcV Roj4iHsVpdJ5Y1VWWx2hrh8+Yt+ZtHaUipO9QB4FF3So0OX4ov5EccaY8WBWXO2HtzPk TInA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s18-20020a170902ea1200b0017f75654a27si14496217plg.510.2022.11.15.14.15.29; Tue, 15 Nov 2022 14:15:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230403AbiKOVrP (ORCPT + 90 others); Tue, 15 Nov 2022 16:47:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230399AbiKOVqz (ORCPT ); Tue, 15 Nov 2022 16:46:55 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1AD2AE7A; Tue, 15 Nov 2022 13:46:54 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.94.2) (envelope-from ) id 1ov3lH-0005HO-0k; Tue, 15 Nov 2022 22:46:31 +0100 Date: Tue, 15 Nov 2022 21:45:05 +0000 From: Daniel Golle To: Jens Axboe , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Matthew Wilcox , Daniel Golle , "Martin K. Petersen" , Chaitanya Kulkarni , Michal Orzel , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH v5 0/4] partition parser for U-Boot's uImage.FIT Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_00,PDS_OTHER_BAD_TLD, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add uImage.FIT partition parser and wire it up to allow mounting filesystem sub-images from uImage.FIT in GPT partitions as well as mtdblock and ubiblock devices within Linux (e.g. as root filesystem). Using uImage.FIT to store the root filesystem besides kernel and dtb has several obvious advantages which are hard to obtain in any other way: * single image accross different storage types * dynamically sized partitions for kernel and rootfs * hash also for rootfs checked by U-Boot before launching kernel * images may include additional filesystems e.g. for localization or branding For this to work, the image has to be created with external data and sub-images aligned to the system's memory page boundaries, ie. mkimage -E -B 0x1000 -p 0x1000 ... Booting such images has been supported by U-Boot since v2018.01. A previous version of this partition parser is in production use on some OpenWrt devices, eg. the BananaPi R64 where using the FIT parser allows booting the very same image from eMMC, SD Card or SPI-NAND/UBI and also using it as a firmware-upgrade image at the same time. The Ubiquiti UniFi 6 LR access point served as a reference board with SPI-NOR flash and use of the partition parser on top of a mtdblock device. As U-Boot by now also passes down the selected configuration node name via device tree this allows the partition parser (or userspace process via sysfs) to identify the selected image configuration. Device Tree schema for that: https://github.com/devicetree-org/dt-schema/commit/a24d97d43491e55d4def006213213a6c4045b646 In most cases this partition parser can be used without relying on the bootloader to pass-down the configuration node name. The default configuration node is used then. Changes since v4: * use folio instead of page (requested by Matthew Wilcox) * remove unneeded checks (requested by Matthew Wilcox) * use strscpy instead of strlcpy (strlcpy is deprecated) * fix off-by-one string size limit label_min (discovered during tests) * use only a single config symbol MTD_BLOCK_PARTITION affecting both ubiblock and mtdblock (requested by Richard Weinberger) Changes since v3: * use min_t(size_t, ...) Changes since v2: * use returned length to limit all strings read from fit/dt * use __be32 type for 32-bit values read from fit/dt Reported-by: kernel test robot * Kconfig: select LIBFDT for FIT_PARTITION Reported-by: kernel test robot Changes since v1: * Use again #ifdef's in partitions/efi to only build against FIT parser symbols if it is actually selected. Otherwise the efi/gpt would unconditionally depend on the FTT parser to be present. Changes since RFC: * fixed wrong variable used in error path * introduced dedicated Kconfig options to enable partition parsers on mtdblock and ubiblock * drop #ifdef'ery, use IS_ENABLED(...) where needed Daniel Golle (4): block: add new flag to add partitions read-only block: add partition parser for U-Boot uImage.FIT partitions/efi: add support for uImage.FIT sub-partitions mtd: add option to enable scanning for partitions MAINTAINERS | 6 + block/blk.h | 1 + block/partitions/Kconfig | 15 ++ block/partitions/Makefile | 1 + block/partitions/check.h | 4 + block/partitions/core.c | 6 + block/partitions/efi.c | 9 + block/partitions/efi.h | 3 + block/partitions/fit.c | 346 ++++++++++++++++++++++++++++++++++++++ drivers/mtd/Kconfig | 11 ++ drivers/mtd/mtd_blkdevs.c | 4 +- drivers/mtd/ubi/block.c | 5 +- 12 files changed, 409 insertions(+), 2 deletions(-) create mode 100644 block/partitions/fit.c -- 2.38.1