From patchwork Tue Nov 8 23:02:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 17265 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp25959wru; Tue, 8 Nov 2022 15:09:19 -0800 (PST) X-Google-Smtp-Source: AMsMyM7RACpDImdTMn4DhljBMsN6oBMDCDXlZ1HX+hc3c5iAd8aLGuMhN2gm/F1X9TC6kai0cgxF X-Received: by 2002:a17:90b:254c:b0:20a:8a92:ea5b with SMTP id nw12-20020a17090b254c00b0020a8a92ea5bmr58981983pjb.81.1667948958843; Tue, 08 Nov 2022 15:09:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667948958; cv=none; d=google.com; s=arc-20160816; b=ngGARfWP5RYRlqZMq8b5DWJxtMgUnGJbAnYXRCLBN+5o7BEg/E5uQzXhlPVOeoFMCv 7KVVanA2gyGVJ766sKVFeaBRCC5TfTBFusO5a5gha+3/BfduwX6+rq6z25jpkG9bGtHs ejMxzo2BhJmiEGfWPWWEQgvkbZcG7jHrIvjtMKlR/GpvTLTiIkH+yt3E2lrH9IwOdTTe PfVyLAgmOzonXw/GCmeP92HiKzsBFpsmZR+p42t815pUFV+0uBKuVrejz5s6+5TUuB/f VDjP/wlXclz0s7JzS09/Er+SDk3UtqRHNzFonk9VN9yAJ9pu1Ic6602axCRqlrACnxZ3 tRjQ== 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=QL8a0deLAuhj1IQrO+ZAK2NOnJRVmLLYuYU2Bz1xQ2g=; b=T97LHs/zP71fF8ZqDUs9r8fOVncYVCARTKe0wwhtriMRe8CECbtinJVN0u3JYKOOkP Ppv7WiRM9bCvs48T/6QqaVNH+/WUHkx79nVOzT06rL6ByaZu7FOGWsU42sHOTPgwY9T5 GJnRrcXvxnGmayhwESc/iS/UggeIEGbb8B0v/iF489rLzkGbsQcL4OmLVKWqfl0+oTMs RmDVDKRrEzy9+yOqTlXqj0wVi9//IEgW4w6G2V3CLc0cs3hLjDWAfhAh6p4sDTMPJJq7 2hG+BDcYax83+F3IensrwwwroTlVdahp1BdmUMDYsWpv+Cr8k0Oc2icZCk6ILsO5NPsG KaPw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j1-20020a63e741000000b0042bc2bd5797si15527418pgk.278.2022.11.08.15.09.05; Tue, 08 Nov 2022 15:09:18 -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 S229907AbiKHXE2 (ORCPT + 99 others); Tue, 8 Nov 2022 18:04:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiKHXE1 (ORCPT ); Tue, 8 Nov 2022 18:04:27 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1C4C6314B; Tue, 8 Nov 2022 15:04:26 -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 1osXde-0005td-94; Wed, 09 Nov 2022 00:04:14 +0100 Date: Tue, 8 Nov 2022 23:02:49 +0000 From: Daniel Golle To: Jens Axboe , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Davidlohr Bueso , Matthew Wilcox , "Martin K. Petersen" , Chaitanya Kulkarni , Daniel Golle , Ming Lei , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-efi@vger.kernel.org Subject: [PATCH v4 1/5] block: add new flag to add partitions read-only Message-ID: MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748971247628511388?= X-GMAIL-MSGID: =?utf-8?q?1748971247628511388?= Add flag ADDPART_FLAG_READONLY to allow partition parsers marking a partition to be set read-only. This is needed for the uImage.FIT partition parser added by a follow-up commit: we need to be sure the contents of uImage.FIT sub-images remain unaltered they are validated using a hash within the uImage.FIT structure which also serves as partition table. Signed-off-by: Daniel Golle --- block/blk.h | 1 + block/partitions/core.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/block/blk.h b/block/blk.h index e85703ae81dd..05ac426350b2 100644 --- a/block/blk.h +++ b/block/blk.h @@ -414,6 +414,7 @@ void blk_free_ext_minor(unsigned int minor); #define ADDPART_FLAG_NONE 0 #define ADDPART_FLAG_RAID 1 #define ADDPART_FLAG_WHOLEDISK 2 +#define ADDPART_FLAG_READONLY 4 int bdev_add_partition(struct gendisk *disk, int partno, sector_t start, sector_t length); int bdev_del_partition(struct gendisk *disk, int partno); diff --git a/block/partitions/core.c b/block/partitions/core.c index b8112f52d388..355646b0707d 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -398,6 +398,9 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, goto out_del; } + if (flags & ADDPART_FLAG_READONLY) + bdev->bd_read_only = true; + /* everything is up and running, commence */ err = xa_insert(&disk->part_tbl, partno, bdev, GFP_KERNEL); if (err) From patchwork Tue Nov 8 23:03:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 17266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp25969wru; Tue, 8 Nov 2022 15:09:20 -0800 (PST) X-Google-Smtp-Source: AMsMyM4hi/+LmQELBirUuOvOKt+qR73uNWBqotcr5xAxo74H6GtfxuWBzwpHkN1MEx5D4K+GSmeO X-Received: by 2002:a05:6a00:4c93:b0:56e:55de:986e with SMTP id eb19-20020a056a004c9300b0056e55de986emr30322581pfb.42.1667948960142; Tue, 08 Nov 2022 15:09:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667948960; cv=none; d=google.com; s=arc-20160816; b=DZCwYISoj48MNL5TW77ryhSpMZhgZ8VLEt8WTi3IuwxiELWU55LWouoMmPm8qMwwqv N4kzS2KIF0tqe+FQumn/c7/2EhlddPFo+Jpkfj9/mks86k0kRwwCDMvI93rzlPZpVlym VVrSQGfj5aXGSAHhJxBXTblBdX/TaNNRb6kUgskUOIbXhenKzoW1yScd+aLWrjB7fhhc fCJeE6MC0pbXoJney+gZOZ9xG3MDlNvKmrRy0dwfVNywkWpzT5jg0Uui2n8okcElQzxh lBwrmfFn48ltlpQPxG1D6wiEG1mAkBBpL/zeg14Pl7LNS6w1H0rU0Jt4N741upKs5qHt AVKw== 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=GoWufAQF8qzdLfDlxF0NiG/priXjtzSuj6M+DV80dig=; b=DupIMdEhITm+6M4z0k5lQ7BbAypty8EKCK8z/EG5HGRVNmZ8vklT1oawK6Y1FnqfMv vib8dwAEwObIXHQJCYdw0GDxe1owquP3+al1wjdbdj9frc96lzotFT2bZV95sMuHvxHK 756o7nyaRMo2ohzGcue4Ig9LSK3QMBaH5LoLKzYzfKRPOELcHBXbJjm+5WO2B8701FAH EhY1RQ3cME8pMM6qtM54zUobwEZtleNbAGXEa5/gxHF0emoU8Z/66LHAVAe6Ys6IE9ZY o850lyISq+Oglscd1S32FU1MuLBX4/xtGNosfThqO0L+C95jhSTGPRe1utJ5oHeya6He bM/A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb12-20020a17090b35cc00b0021320088071si15190796pjb.175.2022.11.08.15.09.06; Tue, 08 Nov 2022 15:09:20 -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 S229997AbiKHXEz (ORCPT + 99 others); Tue, 8 Nov 2022 18:04:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230015AbiKHXEy (ORCPT ); Tue, 8 Nov 2022 18:04:54 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98B3B63140; Tue, 8 Nov 2022 15:04:52 -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 1osXe2-0005uE-O8; Wed, 09 Nov 2022 00:04:38 +0100 Date: Tue, 8 Nov 2022 23:03:16 +0000 From: Daniel Golle To: Jens Axboe , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Davidlohr Bueso , Matthew Wilcox , "Martin K. Petersen" , Chaitanya Kulkarni , Daniel Golle , Ming Lei , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-efi@vger.kernel.org Subject: [PATCH v4 2/5] block: add partition parser for U-Boot uImage.FIT Message-ID: MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748971248467718613?= X-GMAIL-MSGID: =?utf-8?q?1748971248467718613?= Introduce a new partition parser for U-Boot's Flattened-Image-Tree (FIT) in order to allow Linux to mount the filesystem part of a uImage.FIT. uImage.FIT needs to be created with external data and aligned to the system's memory page size. e.g. mkimage -E -B 0x1000 -p 0x1000 ... Signed-off-by: Daniel Golle --- MAINTAINERS | 6 + block/partitions/Kconfig | 15 ++ block/partitions/Makefile | 1 + block/partitions/check.h | 4 + block/partitions/core.c | 3 + block/partitions/fit.c | 353 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 382 insertions(+) create mode 100644 block/partitions/fit.c diff --git a/MAINTAINERS b/MAINTAINERS index f6108373680e..556183a9d112 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8044,6 +8044,12 @@ F: Documentation/firmware_class/ F: drivers/base/firmware_loader/ F: include/linux/firmware.h +FIT PARTITION TABLE (uImage.FIT) +M: Daniel Golle +L: linux-block@vger.kernel.org +S: Maintained +F: block/partitions/fit.c + FLEXTIMER FTM-QUADDEC DRIVER M: Patrick Havelange L: linux-iio@vger.kernel.org diff --git a/block/partitions/Kconfig b/block/partitions/Kconfig index 7aff4eb81c60..77dc85d3797d 100644 --- a/block/partitions/Kconfig +++ b/block/partitions/Kconfig @@ -103,6 +103,21 @@ config ATARI_PARTITION Say Y here if you would like to use hard disks under Linux which were partitioned under the Atari OS. +config FIT_PARTITION + bool "Flattened-Image-Tree (FIT) partition support" if PARTITION_ADVANCED + default n + select LIBFDT + help + Say Y here if your system needs to mount the filesystem part of + a Flattened-Image-Tree (FIT) image commonly used with Das U-Boot. + + uImage.FIT needs to be created with external data and aligned to + the systems memory page size. e.g. + mkimage -E -B 0x1000 -p 0x1000 ... + + If your system doesn't use U-Boot or you don't need to mount uImage.FIT + filesystem sub-images in Linux, say N. + config IBM_PARTITION bool "IBM disk label and partition support" depends on PARTITION_ADVANCED && S390 diff --git a/block/partitions/Makefile b/block/partitions/Makefile index a7f05cdb02a8..d319eb1deba9 100644 --- a/block/partitions/Makefile +++ b/block/partitions/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_ACORN_PARTITION) += acorn.o obj-$(CONFIG_AMIGA_PARTITION) += amiga.o obj-$(CONFIG_ATARI_PARTITION) += atari.o obj-$(CONFIG_AIX_PARTITION) += aix.o +obj-$(CONFIG_FIT_PARTITION) += fit.o obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o obj-$(CONFIG_MAC_PARTITION) += mac.o obj-$(CONFIG_LDM_PARTITION) += ldm.o diff --git a/block/partitions/check.h b/block/partitions/check.h index 8d70a880c372..76b006d3cb27 100644 --- a/block/partitions/check.h +++ b/block/partitions/check.h @@ -57,6 +57,7 @@ int amiga_partition(struct parsed_partitions *state); int atari_partition(struct parsed_partitions *state); int cmdline_partition(struct parsed_partitions *state); int efi_partition(struct parsed_partitions *state); +int fit_partition(struct parsed_partitions *state); int ibm_partition(struct parsed_partitions *); int karma_partition(struct parsed_partitions *state); int ldm_partition(struct parsed_partitions *state); @@ -67,3 +68,6 @@ int sgi_partition(struct parsed_partitions *state); int sun_partition(struct parsed_partitions *state); int sysv68_partition(struct parsed_partitions *state); int ultrix_partition(struct parsed_partitions *state); + +int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector, + u64 sectors, int *slot, int max_slot, bool add_remain); diff --git a/block/partitions/core.c b/block/partitions/core.c index 355646b0707d..9d4bb8f48d35 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -43,6 +43,9 @@ static int (*check_part[])(struct parsed_partitions *) = { #ifdef CONFIG_CMDLINE_PARTITION cmdline_partition, #endif +#ifdef CONFIG_FIT_PARTITION + fit_partition, +#endif #ifdef CONFIG_EFI_PARTITION efi_partition, /* this must come before msdos */ #endif diff --git a/block/partitions/fit.c b/block/partitions/fit.c new file mode 100644 index 000000000000..095faa5fa69a --- /dev/null +++ b/block/partitions/fit.c @@ -0,0 +1,353 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * fs/partitions/fit.c + * Copyright (C) 2021 Daniel Golle + * + * headers extracted from U-Boot mkimage sources + * (C) Copyright 2008 Semihalf + * (C) Copyright 2000-2005 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * based on existing partition parsers + * Copyright (C) 1991-1998 Linus Torvalds + * Re-organised Feb 1998 Russell King + */ + +#include +#include +#include +#include +#include + +#include "check.h" + +#define FIT_IMAGES_PATH "/images" +#define FIT_CONFS_PATH "/configurations" + +/* hash/signature/key node */ +#define FIT_HASH_NODENAME "hash" +#define FIT_ALGO_PROP "algo" +#define FIT_VALUE_PROP "value" +#define FIT_IGNORE_PROP "uboot-ignore" +#define FIT_SIG_NODENAME "signature" +#define FIT_KEY_REQUIRED "required" +#define FIT_KEY_HINT "key-name-hint" + +/* cipher node */ +#define FIT_CIPHER_NODENAME "cipher" +#define FIT_ALGO_PROP "algo" + +/* image node */ +#define FIT_DATA_PROP "data" +#define FIT_DATA_POSITION_PROP "data-position" +#define FIT_DATA_OFFSET_PROP "data-offset" +#define FIT_DATA_SIZE_PROP "data-size" +#define FIT_TIMESTAMP_PROP "timestamp" +#define FIT_DESC_PROP "description" +#define FIT_ARCH_PROP "arch" +#define FIT_TYPE_PROP "type" +#define FIT_OS_PROP "os" +#define FIT_COMP_PROP "compression" +#define FIT_ENTRY_PROP "entry" +#define FIT_LOAD_PROP "load" + +/* configuration node */ +#define FIT_KERNEL_PROP "kernel" +#define FIT_FILESYSTEM_PROP "filesystem" +#define FIT_RAMDISK_PROP "ramdisk" +#define FIT_FDT_PROP "fdt" +#define FIT_LOADABLE_PROP "loadables" +#define FIT_DEFAULT_PROP "default" +#define FIT_SETUP_PROP "setup" +#define FIT_FPGA_PROP "fpga" +#define FIT_FIRMWARE_PROP "firmware" +#define FIT_STANDALONE_PROP "standalone" + +#define MIN_FREE_SECT 16 +#define REMAIN_VOLNAME "rootfs_data" +#define MAX_FIT_LOADABLES 16 + +/** + * parse_fit_partitions - map uImage.FIT filesystem sub-images into sub-partitions + * @state: pointer to partition parser state + * @fit_start_sector: start sector of the FIT structure on disk + * @sectors: number of sectors of the uImage.FIT partition or 0 if whole device + * @slot: pointer to the current partition slot number + * @add_remain: map unused sectors into additional partition + * + * To be called by other partition parsers on physical block devices or using + * wrapper function int fit_partition(struct parsed_partitions *state) for the + * whole disk, relevant typically for ubiblock or mtdblock devices. + */ +int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector, + u64 sectors, int *slot, int max_slot, bool add_remain) +{ + struct block_device *bdev = state->disk->part0; + struct address_space *mapping = bdev->bd_inode->i_mapping; + struct page *page; + void *fit, *init_fit; + struct partition_meta_info *info; + char tmp[sizeof(info->volname)]; + u64 dsize, dsectors, imgmaxsect = 0; + u32 size, image_pos, image_len; + const __be32 *image_offset_be, *image_len_be, *image_pos_be; + int ret = 1, node, images, config; + const char *image_name, *image_type, *image_description, + *config_default, *config_description, *config_loadables; + u32 image_name_len, image_type_len, image_description_len, + config_default_len, config_description_len, + config_loadables_len; + sector_t start_sect, nr_sects; + size_t label_min; + struct device_node *np = NULL; + const char *bootconf; + const char *loadable; + bool found; + int loadables_rem_len, loadable_len; + u16 loadcnt; + + /* uImage.FIT should be aligned to page boundaries */ + if (fit_start_sector % (1 << (PAGE_SHIFT - SECTOR_SHIFT))) + return 0; + + /* map first page */ + page = read_mapping_page( + mapping, fit_start_sector >> (PAGE_SHIFT - SECTOR_SHIFT), NULL); + + if (IS_ERR(page)) + return -EFAULT; + + if (PageError(page)) + return -EFAULT; + + init_fit = page_address(page); + + if (!init_fit) { + put_page(page); + return -EFAULT; + } + + /* uImage.FIT is based on flattened device tree structure */ + if (fdt_check_header(init_fit)) { + put_page(page); + return 0; + } + + /* acquire disk or partition size */ + dsectors = get_capacity(bdev->bd_disk); + if (sectors) + dsectors = min_t(u64, sectors, dsectors); + + dsize = dsectors << SECTOR_SHIFT; + size = fdt_totalsize(init_fit); + + /* silently skip non-external-data legacy uImage.FIT */ + if (size > PAGE_SIZE) { + put_page(page); + return 0; + } + + /* abort if FIT structure is larger than disk or partition size */ + if (size >= dsize) { + state->access_beyond_eod = 1; + put_page(page); + return -EFBIG; + } + + /* + * copy FIT structure for further processing + * this is necessary for libfdt to work + */ + fit = kmemdup(init_fit, size, GFP_KERNEL); + put_page(page); + if (!fit) + return -ENOMEM; + + /* set boot config node name U-Boot may have added to the device tree */ + np = of_find_node_by_path("/chosen"); + if (np) + bootconf = of_get_property(np, "u-boot,bootconf", NULL); + else + bootconf = NULL; + + /* find configuration path in uImage.FIT */ + config = fdt_path_offset(fit, FIT_CONFS_PATH); + if (config < 0) { + pr_err("FIT: Cannot find %s node: %d\n", + FIT_CONFS_PATH, config); + ret = -ENOENT; + goto ret_out; + } + + /* get default configuration node name */ + config_default = + fdt_getprop(fit, config, FIT_DEFAULT_PROP, &config_default_len); + + /* make sure we got either default or selected boot config node name */ + if (!config_default && !bootconf) { + pr_err("FIT: Cannot find default configuration\n"); + ret = -ENOENT; + goto ret_out; + } + + /* find selected boot config node, fallback on default config node */ + node = fdt_subnode_offset(fit, config, bootconf ?: config_default); + if (node < 0) { + pr_err("FIT: Cannot find %s node: %d\n", + bootconf ?: config_default, node); + ret = -ENOENT; + goto ret_out; + } + + /* get selected configuration data */ + config_description = + fdt_getprop(fit, node, FIT_DESC_PROP, &config_description_len); + config_loadables = fdt_getprop(fit, node, FIT_LOADABLE_PROP, + &config_loadables_len); + + pr_info("FIT: %s configuration: \"%s\"%s%s%s\n", + bootconf ? "Selected" : "Default", bootconf ?: config_default, + config_description ? " (" : "", config_description ?: "", + config_description ? ")" : ""); + + if (!config_loadables || !config_loadables_len) { + pr_err("FIT: No loadables configured in \"%s\"\n", + bootconf ?: config_default); + ret = -ENOENT; + goto ret_out; + } + + /* get images path in uImage.FIT */ + images = fdt_path_offset(fit, FIT_IMAGES_PATH); + if (images < 0) { + pr_err("FIT: Cannot find %s node: %d\n", FIT_IMAGES_PATH, images); + ret = -EINVAL; + goto ret_out; + } + + /* allocate one slot for mapping remaing space */ + if (add_remain) + --max_slot; + + /* iterate over images in uImage.FIT */ + fdt_for_each_subnode(node, fit, images) { + image_name = fdt_get_name(fit, node, &image_name_len); + image_type = fdt_getprop(fit, node, FIT_TYPE_PROP, &image_type_len); + image_offset_be = fdt_getprop(fit, node, FIT_DATA_OFFSET_PROP, NULL); + image_pos_be = fdt_getprop(fit, node, FIT_DATA_POSITION_PROP, NULL); + image_len_be = fdt_getprop(fit, node, FIT_DATA_SIZE_PROP, NULL); + + if (!image_name || !image_type || !image_len_be) + continue; + + image_len = be32_to_cpu(*image_len_be); + if (!image_len) + continue; + + if (image_offset_be) + image_pos = be32_to_cpu(*image_offset_be) + size; + else if (image_pos_be) + image_pos = be32_to_cpu(*image_pos_be); + else + continue; + + image_description = fdt_getprop(fit, node, FIT_DESC_PROP, + &image_description_len); + + pr_info("FIT: %16s sub-image 0x%08x..0x%08x \"%.*s\"%s%.*s%s\n", + image_type, image_pos, image_pos + image_len - 1, + image_name_len, image_name, image_description ? " (" : "", + image_description ? image_description_len : 0, + image_description ?: "", image_description ? ") " : ""); + + /* only 'filesystem' images should be mapped as partitions */ + if (strncmp(image_type, FIT_FILESYSTEM_PROP, image_type_len)) + continue; + + /* check if sub-image is part of configured loadables */ + found = false; + loadable = config_loadables; + loadables_rem_len = config_loadables_len; + for (loadcnt = 0; loadables_rem_len > 1 && + loadcnt < MAX_FIT_LOADABLES; ++loadcnt) { + loadable_len = + strnlen(loadable, loadables_rem_len - 1) + 1; + loadables_rem_len -= loadable_len; + if (!strncmp(image_name, loadable, loadable_len)) { + found = true; + break; + } + loadable += loadable_len; + } + if (!found) + continue; + + if (image_pos % (1 << PAGE_SHIFT)) { + pr_err("FIT: image %.*s start not aligned to page boundaries, skipping\n", + image_name_len, image_name); + continue; + } + + if (image_len % (1 << PAGE_SHIFT)) { + pr_err("FIT: sub-image %.*s end not aligned to page boundaries, skipping\n", + image_name_len, image_name); + continue; + } + + start_sect = image_pos >> SECTOR_SHIFT; + nr_sects = image_len >> SECTOR_SHIFT; + imgmaxsect = (imgmaxsect < (start_sect + nr_sects)) ? + (start_sect + nr_sects) : + imgmaxsect; + + if (start_sect + nr_sects > dsectors) { + state->access_beyond_eod = 1; + continue; + } + + put_partition(state, *slot, fit_start_sector + start_sect, + nr_sects); + state->parts[*slot].flags = ADDPART_FLAG_READONLY; + state->parts[*slot].has_info = true; + info = &state->parts[*slot].info; + + label_min = min_t(int, sizeof(info->volname) - 1, image_name_len); + strncpy(info->volname, image_name, label_min); + info->volname[label_min] = '\0'; + + snprintf(tmp, sizeof(tmp), "(%s)", info->volname); + strlcat(state->pp_buf, tmp, PAGE_SIZE); + + if (++(*slot) > max_slot) + break; + } + + /* in case uImage.FIT is stored in a partition, map the remaining space */ + if (add_remain && (imgmaxsect + MIN_FREE_SECT) < dsectors) { + put_partition(state, *slot, fit_start_sector + imgmaxsect, + dsectors - imgmaxsect); + state->parts[*slot].flags = 0; + info = &state->parts[*slot].info; + strcpy(info->volname, REMAIN_VOLNAME); + snprintf(tmp, sizeof(tmp), "(%s)", REMAIN_VOLNAME); + strlcat(state->pp_buf, tmp, PAGE_SIZE); + ++(*slot); + } +ret_out: + kfree(fit); + return ret; +} + +/** + * fit_partition - map uImage.FIT filesystem sub-images into partitions + * @state: pointer to partition parser state + * + * Used to parse uImage.FIT structure for images directly stored on + * the whole block device (typically ubiblock or mtdblock). + */ +int fit_partition(struct parsed_partitions *state) +{ + int slot = 1; + + return parse_fit_partitions(state, 0, 0, &slot, MAX_FIT_LOADABLES, false); +} From patchwork Tue Nov 8 23:03:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 17264 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp25455wru; Tue, 8 Nov 2022 15:08:05 -0800 (PST) X-Google-Smtp-Source: AMsMyM7oGQ/Pc5BaQAxDxlHf/GrGnm+Ina/fbYU/rtpaLCRUhh9nOpoAjQLvvxiBIG/XEMXSN0K+ X-Received: by 2002:a05:6402:50c:b0:461:bc01:1828 with SMTP id m12-20020a056402050c00b00461bc011828mr58568506edv.64.1667948885060; Tue, 08 Nov 2022 15:08:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667948885; cv=none; d=google.com; s=arc-20160816; b=WvRIwEh51xDYHsQDEB9Jg66YXDvDj/1V2eifryCosaE1NjxtrDeGhTRoR9w1bybhjK aj9wSxysTGZ4q8E36iDF9C+eOCxGwuq6txFcqc8rxFeu6n+QDUmVfwtIkktqqSKydIUn LwF4hoZmNB6sW65Ie21ZXTNwfO7uxfjaoMc40rOd9yQrZMgyERSIf9SzAZaRdALpX1pA Qjvdw3RmUnf1olF4DfR/vHbdHmLvAXzWkB0t5wJVVJqPGocO6q0Zbx8l8m2MIPKUc5Sj qYj78i1yM8leeINOES47r6CFMmfQnaV3azWtgwIlNRDwCo2u0ivvf0Ebj5XuP/xlulbK glKA== 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=q+mEapDl3A3nGTAE8boQEVA1WENIGE3CNZVC9sJwYRk=; b=dwr6Yh8zFC8dG1azZ84oZzpAgkRFE7LuFUSMVe8f81adA5tQPbwFl5vP8xZvmXV4xi D6n/LyHFVZceG3FfpZwmU+JUV45ykV1x5YZDdOYxe83gxxbgqK1D6iU6OOom2yjE0hiI VxuD0TJHAgYNjHL1srEeHSatM0LCrGZ070QPENVYwIwShNjA/L5/nZQJ6dhb4YFOBBf+ xNiIgZwN3N7pLbzBDug3aBAuMYjRFwa2dDMN66X4m2rW/h0aJvClwwBZeXLRqD3rggaV ihVbeAMJIUc6aNLWmRr6AvV9Jt2n5K1of7t9xmQUZGW2EUIwXOv8BjkY17qYvNWhM5Io 5Bpg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la26-20020a170907781a00b00780488c11bbsi10403377ejc.388.2022.11.08.15.07.40; Tue, 08 Nov 2022 15:08:05 -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 S229992AbiKHXF2 (ORCPT + 99 others); Tue, 8 Nov 2022 18:05:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbiKHXFY (ORCPT ); Tue, 8 Nov 2022 18:05:24 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CD3E63147; Tue, 8 Nov 2022 15:05:23 -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 1osXeZ-0005vA-Rm; Wed, 09 Nov 2022 00:05:12 +0100 Date: Tue, 8 Nov 2022 23:03:48 +0000 From: Daniel Golle To: Jens Axboe , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Davidlohr Bueso , Matthew Wilcox , "Martin K. Petersen" , Chaitanya Kulkarni , Daniel Golle , Ming Lei , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-efi@vger.kernel.org Subject: [PATCH v4 3/5] partitions/efi: add support for uImage.FIT sub-partitions Message-ID: MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748971170188114944?= X-GMAIL-MSGID: =?utf-8?q?1748971170188114944?= Add new GUID allowing to parse uImage.FIT stored in a GPT partition and map filesystem sub-image as sub-partitions. Signed-off-by: Daniel Golle --- block/partitions/efi.c | 9 +++++++++ block/partitions/efi.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/block/partitions/efi.c b/block/partitions/efi.c index 5e9be13a56a8..bf87893eabe4 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -716,6 +716,9 @@ int efi_partition(struct parsed_partitions *state) gpt_entry *ptes = NULL; u32 i; unsigned ssz = queue_logical_block_size(state->disk->queue) / 512; +#ifdef CONFIG_FIT_PARTITION + u32 extra_slot = 65; +#endif if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) { kfree(gpt); @@ -749,6 +752,12 @@ int efi_partition(struct parsed_partitions *state) ARRAY_SIZE(ptes[i].partition_name)); utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname); state->parts[i + 1].has_info = true; + /* If this is a U-Boot FIT volume it may have subpartitions */ +#ifdef CONFIG_FIT_PARTITION + if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_FIT_GUID)) + (void) parse_fit_partitions(state, start * ssz, size * ssz, + &extra_slot, 127, 1); +#endif } kfree(ptes); kfree(gpt); diff --git a/block/partitions/efi.h b/block/partitions/efi.h index 84b9f36b9e47..06c11f6ae398 100644 --- a/block/partitions/efi.h +++ b/block/partitions/efi.h @@ -51,6 +51,9 @@ #define PARTITION_LINUX_LVM_GUID \ EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \ 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28) +#define PARTITION_LINUX_FIT_GUID \ + EFI_GUID( 0xcae9be83, 0xb15f, 0x49cc, \ + 0x86, 0x3f, 0x08, 0x1b, 0x74, 0x4a, 0x2d, 0x93) typedef struct _gpt_header { __le64 signature; From patchwork Tue Nov 8 23:04:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 17267 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp26165wru; Tue, 8 Nov 2022 15:09:49 -0800 (PST) X-Google-Smtp-Source: AMsMyM7HREIe8dRXp+rxC4rqVrpSzGGKuKZ3BPbguE3aHvz2th2HdPss/RleFqJDsdj/wdDDqbgg X-Received: by 2002:a17:90a:2d8b:b0:213:b314:4652 with SMTP id p11-20020a17090a2d8b00b00213b3144652mr58172927pjd.96.1667948989319; Tue, 08 Nov 2022 15:09:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667948989; cv=none; d=google.com; s=arc-20160816; b=jnw/vukVYwdk4d12xYbCHhURv+dcgYnGMVTVa6wd5wWu0Eo76bUWFDg+/X840TdFiN HK1V6uArk7d8p/dfzTg9YRlcv54VTf5hiN9PZcp31BFs6Cfb1mBHoUkTMn+QdqaZ/LFm 83X6jXMbppkKgvDU9j6fbiOahTZMmd6nD8vndm78guO4XKhZBY6JA/54MhLoGp++vrtg tlbaxzgM4Nl8p8tLNhPGVd8U3NyBpm1aUt+uwRq7YlcupKpSaMzoTIEGgT62KSYXQQ0f eoWHV8UWYrJ6hLrurCFmj6w4ESO6JsyNlfzoG2SqYH/WSpNubOtkb5/seMjiGLMQd2VB aqcA== 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=ulczSCiKyYKYeEYWVUdvnRHWt1pChHSadOU6tR5w8FA=; b=kpvD3lreSZjI5O1EbJL5i5Vjyq/IIEWzF8bb5f6ayK/TC6oV4nLiT4yXpfU345encQ a7K5KoGcxtA3V/60en4AK8ch5cIOOyap7DvVlc/BAFCCiPqHW0o5N0D/wA6IfNmq+7AS nMkE0y2G6Ar4dbFEi079QCC8ptxV3RriKWyqtMJgXYs7sJ+6yUbu3/w0GrA3iQB28Skx J5iiF10U7l0WHN8swEgO0HvToIewk9QPugz/kstLECP2AbzKhKaAtuCTPnTDj6YVBmNU f6BcbrhzfjwdGuCLY3UaRmnF1khXeHVs4333uZW03Wp3gIMjSQRDftrHYgwzMKVquxsD TqGA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a29-20020a631a1d000000b0046b041e1408si15334681pga.744.2022.11.08.15.09.36; Tue, 08 Nov 2022 15:09:49 -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 S229626AbiKHXF6 (ORCPT + 99 others); Tue, 8 Nov 2022 18:05:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbiKHXFs (ORCPT ); Tue, 8 Nov 2022 18:05:48 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 558CF657D9; Tue, 8 Nov 2022 15:05:47 -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 1osXex-0005vp-Nv; Wed, 09 Nov 2022 00:05:35 +0100 Date: Tue, 8 Nov 2022 23:04:13 +0000 From: Daniel Golle To: Jens Axboe , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Davidlohr Bueso , Matthew Wilcox , "Martin K. Petersen" , Chaitanya Kulkarni , Daniel Golle , Ming Lei , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-efi@vger.kernel.org Subject: [PATCH v4 4/5] mtd_blkdevs: add option to enable scanning for partitions Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748971279199838646?= X-GMAIL-MSGID: =?utf-8?q?1748971279199838646?= Add Kconfig boolean CONFIG_MTD_BLOCK_PARTITIONS and enable block partition parsers on non-NAND mtdblock devices in case it is selected. Signed-off-by: Daniel Golle Acked-by: Miquel Raynal --- drivers/mtd/Kconfig | 11 +++++++++++ drivers/mtd/mtd_blkdevs.c | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 796a2eccbef0..12874dec1569 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -69,6 +69,17 @@ config MTD_BLOCK_RO You do not need this option for use with the DiskOnChip devices. For those, enable NFTL support (CONFIG_NFTL) instead. +config MTD_BLOCK_PARTITIONS + bool "Scan for partitions on MTD block devices" + depends on MTD_BLOCK || MTD_BLOCK_RO + default y if FIT_PARTITION + help + Scan MTD block devices for partitions (ie. MBR, GPT, uImage.FIT, ...). + (NAND devices are omitted, ubiblock should be used instead when) + + Unless your MTD partitions contain sub-partitions mapped using a + partition table, say no. + comment "Note that in some cases UBI block is preferred. See MTD_UBI_BLOCK." depends on MTD_BLOCK || MTD_BLOCK_RO diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 60b222799871..e6f2e0888246 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -359,7 +359,9 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) } else { snprintf(gd->disk_name, sizeof(gd->disk_name), "%s%d", tr->name, new->devnum); - gd->flags |= GENHD_FL_NO_PART; + + if (!IS_ENABLED(CONFIG_MTD_BLOCK_PARTITIONS) || mtd_type_is_nand(new->mtd)) + gd->flags |= GENHD_FL_NO_PART; } set_capacity(gd, ((u64)new->size * tr->blksize) >> 9); From patchwork Tue Nov 8 23:04:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 17268 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp26211wru; Tue, 8 Nov 2022 15:09:57 -0800 (PST) X-Google-Smtp-Source: AMsMyM5k2P6++dGSLxAOd8NvK+sy/PX13tsCWBBJh4pNnVGkJQH5CuaOeYleBoKJW6beTUqfmTKs X-Received: by 2002:a17:90a:c56:b0:213:d200:e958 with SMTP id u22-20020a17090a0c5600b00213d200e958mr53431308pje.6.1667948996833; Tue, 08 Nov 2022 15:09:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667948996; cv=none; d=google.com; s=arc-20160816; b=cOLoOfx/ato7y2MB/X36gQm1rDKWLgtTbwq1wbFh4Bq0wss1VfRWcaHEeIUe9bPBK3 3nu+0oQ8xYSLlgpe1Kijq/roBR4apM89fit/e3vMQLxwl/i5T/HnUm6AHH3btWo4mIu0 vE7WTn0TIZFK66L0cXph9Bw6DAP4Ug4pPfmfh9005rI5o3Kq5fPhuaS6wrGty/SEp3HJ SfeujD/ZHIENwawvEkrRsk1KPeCSKEbueLcVpO7/FTDfRiDS0uj5D8aG+4aPKWVOkAQn 5vTixhzIjJwK/w2nXh/i6lTgFquanNxLXHMspBfJ9lfP5Qf9vQm0ImjS1lX/Vqa0B5EC MjCQ== 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=JMh8J/oFNoRdEnWHwUoV5ShUmqG5pbux0mW3rqhQ82s=; b=GwgK/qanyJqhevYNnaGCB51BnpZuXjaVD0FZO7tJAFnW0ZSlXwwLPVvv13HoIYxrlF Jj8C3Iox1ETSNffSlt/xh0NTVQIiyA82zzfq6alKTZRyzs7ZzbX8+Fm5tc8SWu/y/J5x WtALdNpOTlnwlXdwalNLGqaE5c7Z8BJEP50z7HM4cdqNA8QcVbs2q8bQwZNY6wDb09jG 3pr5B5009VYWAQ3M1Gm/78eXF7JVIruhVWYPI+vgaSpAx4XGiyoQhvq34fCzoIDVP6yL ZuzftQ043JQ0KtV700/xnrDZspKYlrb15ZrHY9YoUxsQ63CZmyLKv/heYjaG1pmSbMD2 UxfA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020a170902da8800b0017680ae3a9csi18449858plx.534.2022.11.08.15.09.42; Tue, 08 Nov 2022 15:09:56 -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 S229751AbiKHXGL (ORCPT + 99 others); Tue, 8 Nov 2022 18:06:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbiKHXGK (ORCPT ); Tue, 8 Nov 2022 18:06:10 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 952E463159; Tue, 8 Nov 2022 15:06:09 -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 1osXfK-0005wb-6u; Wed, 09 Nov 2022 00:05:58 +0100 Date: Tue, 8 Nov 2022 23:04:35 +0000 From: Daniel Golle To: Jens Axboe , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Davidlohr Bueso , Matthew Wilcox , "Martin K. Petersen" , Chaitanya Kulkarni , Daniel Golle , Ming Lei , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-efi@vger.kernel.org Subject: [PATCH v4 5/5] mtd: ubi: block: add option to enable scanning for partitions Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748971287470924814?= X-GMAIL-MSGID: =?utf-8?q?1748971287470924814?= Add Kconfig option CONFIG_MTD_UBI_BLOCK_PARTITIONS and enable block partition parsers on ubiblock devices in case it is selected. Signed-off-by: Daniel Golle --- drivers/mtd/ubi/Kconfig | 10 ++++++++++ drivers/mtd/ubi/block.c | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig index 2ed77b7b3fcb..491330e42ab2 100644 --- a/drivers/mtd/ubi/Kconfig +++ b/drivers/mtd/ubi/Kconfig @@ -104,4 +104,14 @@ config MTD_UBI_BLOCK If in doubt, say "N". +config MTD_UBI_BLOCK_PARTITIONS + bool "Scan UBI block devices for partitions" + default y if FIT_PARTITION + depends on MTD_UBI_BLOCK + help + Scan UBI block devices for partitions (ie. MBR, GPT, uImage.FIT, ...). + + Unless your UBI volumes contain sub-partitions mapped using a partition + table, say no. + endif # MTD_UBI diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c index 75eaecc8639f..d9baa99ca093 100644 --- a/drivers/mtd/ubi/block.c +++ b/drivers/mtd/ubi/block.c @@ -430,7 +430,10 @@ int ubiblock_create(struct ubi_volume_info *vi) ret = -ENODEV; goto out_cleanup_disk; } - gd->flags |= GENHD_FL_NO_PART; + + if (!IS_ENABLED(CONFIG_MTD_UBI_BLOCK_PARTITIONS)) + gd->flags |= GENHD_FL_NO_PART; + gd->private_data = dev; sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id); set_capacity(gd, disk_capacity);