From patchwork Sat Aug 12 00:06:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Edwards X-Patchwork-Id: 1820445 X-Patchwork-Delegate: dario.binacchi@amarulasolutions.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=fO4zdgvD; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RN1D76fXrz1yf2 for ; Sat, 12 Aug 2023 10:06:31 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C7B418693C; Sat, 12 Aug 2023 02:06:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fO4zdgvD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0A2728693F; Sat, 12 Aug 2023 02:06:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 72D8286948 for ; Sat, 12 Aug 2023 02:06:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=cfsworks@gmail.com Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-686ba29ccb1so1774547b3a.1 for ; Fri, 11 Aug 2023 17:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691798777; x=1692403577; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qXaevzcu7JO5/+jDgIIKpfyz5H7WrySjZ2+ye1D1FA0=; b=fO4zdgvD7ri+ijvJds52N/XuD9K38CfKAYQApUfA1MnZUpApR9QRk880WMHcUbirrJ MmT0MQpeayb31RpTTtFTv/DRRa9eUqZ3YVyKkLtfDdwTEzyFVSlymSgFrjPEx/XvIh0d QotYiXgLoH5GplcHNgu6Z9TFNtHVusKJSqFTIFLQ317SAFYXinkYO8ZFgOPMiA1KoCl5 dKOg1MAQufeROcXzPMKORoZG3I/U2Jm1VCpliy3/hgVueAtbn10/3vosgGEt9l4cUS/c wLZ9+0vfXjzbVqMBBt31hGDsqdmZJYeZCp4rTyv1c4vUXQ22XZIgEdppOIP/Zr/pLLXj vUHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691798777; x=1692403577; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qXaevzcu7JO5/+jDgIIKpfyz5H7WrySjZ2+ye1D1FA0=; b=WD4GwYTz15zyQdNuPOXyihJ9r9sDCHvmW8dzI0o0ZPNlBtnb74FCJSXyV4+nxaA1Rp UWw7bLI71QQWcCE1KcEL3Anq7axN+JTt/OPGb/V4Ii94Avfw7TmZYYLvuO3FvDy+5gKg jY1bGmdq4FqnXgSgisBOEQ1xY9+OFn82id6knAhvhpRlO0YkUrkkdhXSh6ciaLmB8Puw HIRJvXm5r0oYA5ulSPMr/OggybD5FwffqZpGCBbJKyZ6uDLv4ZvEjimZzXA2NXyabvKo 6CuEGQCfg8/lael3YuU+BYQmmIUWTDbDyyHGSsCdxNfmyRkHtyPXIhYiSXdiEGr04ey3 Qyjg== X-Gm-Message-State: AOJu0YxzVdOm9a3bOga3+bKZJfkfpJaI+xFEYynArHaqwOj7w5F6SkgZ K+W8559N008MN6RAWc4K9QU= X-Google-Smtp-Source: AGHT+IE8+W4w8No01mJs4b+pQQ3Mq6QigCxa4IFDKL/4L38YMlfOvQgRMafztAAg3zpu81+FiDxGyA== X-Received: by 2002:a05:6a00:1c86:b0:687:2cba:67ad with SMTP id y6-20020a056a001c8600b006872cba67admr8302485pfw.2.1691798776702; Fri, 11 Aug 2023 17:06:16 -0700 (PDT) Received: from celestia.nettie.lan (static-198-54-134-172.cust.tzulo.com. [198.54.134.172]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b00686bef8e55csm3848834pfm.39.2023.08.11.17.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 17:06:16 -0700 (PDT) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Heiko Schocher , Kyungmin Park Cc: u-boot@lists.denx.de, Sam Edwards Subject: [RFC PATCH 1/4] mtd: ubi: register UBI attachments as DM devices Date: Fri, 11 Aug 2023 18:06:03 -0600 Message-ID: <20230812000606.72319-2-CFSworks@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230812000606.72319-1-CFSworks@gmail.com> References: <20230812000606.72319-1-CFSworks@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This is in preparation for exposing static UBI volumes as block devices. A UBI uclass and driver are introduced, and a "ubi0" virtual device with the proper driver is created below whichever MTD device is attached as the active UBI partition. This virtual device will soon be the parent for the BLK devices that represent the static volumes. Signed-off-by: Sam Edwards --- cmd/ubi.c | 11 ++++++ drivers/mtd/ubi/Makefile | 1 + drivers/mtd/ubi/ubi-uclass.c | 74 ++++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/ubi_uboot.h | 5 +++ 5 files changed, 92 insertions(+) create mode 100644 drivers/mtd/ubi/ubi-uclass.c diff --git a/cmd/ubi.c b/cmd/ubi.c index b61ae1efea..ab336d30f1 100644 --- a/cmd/ubi.c +++ b/cmd/ubi.c @@ -560,6 +560,13 @@ static int ubi_detach(void) cmd_ubifs_umount(); #endif +#ifdef CONFIG_DM_MTD + /* + * Clean up any UBI devices in DM + */ + ubi_dm_unbind_all(); +#endif + /* * Call ubi_exit() before re-initializing the UBI subsystem */ @@ -598,6 +605,10 @@ int ubi_part(char *part_name, const char *vid_header_offset) return err; } +#ifdef CONFIG_DM_MTD + ubi_dm_bind(0); +#endif + ubi = ubi_devices[0]; return 0; diff --git a/drivers/mtd/ubi/Makefile b/drivers/mtd/ubi/Makefile index 30d00fbdfe..375075f75e 100644 --- a/drivers/mtd/ubi/Makefile +++ b/drivers/mtd/ubi/Makefile @@ -7,3 +7,4 @@ obj-y += attach.o build.o vtbl.o vmt.o upd.o kapi.o eba.o io.o wl.o crc32.o obj-$(CONFIG_MTD_UBI_FASTMAP) += fastmap.o obj-y += misc.o obj-y += debug.o +obj-$(CONFIG_DM_MTD) += ubi-uclass.o diff --git a/drivers/mtd/ubi/ubi-uclass.c b/drivers/mtd/ubi/ubi-uclass.c new file mode 100644 index 0000000000..f8971e793e --- /dev/null +++ b/drivers/mtd/ubi/ubi-uclass.c @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0 +/** + * ubi-uclass.c - UBI partition and volume block device uclass driver + * + * Copyright (C) 2023 Sam Edwards + */ + +#define LOG_CATEGORY UCLASS_UBI + +#include +#include +#include +#include + +int ubi_dm_bind(unsigned int index) +{ + struct udevice *dev; + int ret; + char name[16]; + const char *name_dup; + struct ubi_device *ubi = ubi_devices[index]; + const struct mtd_info *mtd = ubi->mtd; + + /* MTD partitions are not in DM; navigate to the real MTD device */ + if (mtd->parent) + mtd = mtd->parent; + + snprintf(name, sizeof(name), "ubi%u", index); + name_dup = strdup(name); + ret = device_bind(mtd->dev, DM_DRIVER_GET(ubi), name_dup, ubi, + ofnode_null(), &dev); + if (ret) { + free((void *)name_dup); + return ret; + } + + device_set_name_alloced(dev); + + return 0; +} + +int ubi_dm_unbind_all(void) +{ + int ret; + struct uclass *uc; + struct udevice *dev; + struct udevice *next; + + ret = uclass_get(UCLASS_UBI, &uc); + if (ret) + return ret; + + uclass_foreach_dev_safe(dev, next, uc) { + ret = device_remove(dev, DM_REMOVE_NORMAL); + if (ret) + return ret; + + ret = device_unbind(dev); + if (ret) + return ret; + } + + return 0; +} + +U_BOOT_DRIVER(ubi) = { + .id = UCLASS_UBI, + .name = "ubi_dev", +}; + +UCLASS_DRIVER(ubi) = { + .id = UCLASS_UBI, + .name = "ubi", +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 307ad6931c..407166d080 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -133,6 +133,7 @@ enum uclass_id { UCLASS_THERMAL, /* Thermal sensor */ UCLASS_TIMER, /* Timer device */ UCLASS_TPM, /* Trusted Platform Module TIS interface */ + UCLASS_UBI, /* Unsorted Block Images MTD partition */ UCLASS_UFS, /* Universal Flash Storage */ UCLASS_USB, /* USB bus */ UCLASS_USB_DEV_GENERIC, /* USB generic device */ diff --git a/include/ubi_uboot.h b/include/ubi_uboot.h index 6da348eb62..9d37848f03 100644 --- a/include/ubi_uboot.h +++ b/include/ubi_uboot.h @@ -52,6 +52,11 @@ extern int ubi_part(char *part_name, const char *vid_header_offset); extern int ubi_volume_write(char *volume, void *buf, size_t size); extern int ubi_volume_read(char *volume, char *buf, size_t size); +#ifdef CONFIG_DM_MTD +extern int ubi_dm_bind(unsigned int); +extern int ubi_dm_unbind_all(void); +#endif + extern struct ubi_device *ubi_devices[]; int cmd_ubifs_mount(char *vol_name); int cmd_ubifs_umount(void); From patchwork Sat Aug 12 00:06:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Edwards X-Patchwork-Id: 1820446 X-Patchwork-Delegate: dario.binacchi@amarulasolutions.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=ko/+bAOh; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RN1DL1HK3z1yf2 for ; Sat, 12 Aug 2023 10:06:42 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1584586961; Sat, 12 Aug 2023 02:06:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ko/+bAOh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C72988693A; Sat, 12 Aug 2023 02:06:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9D2D38693A for ; Sat, 12 Aug 2023 02:06:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=cfsworks@gmail.com Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6873a30d02eso1899186b3a.3 for ; Fri, 11 Aug 2023 17:06:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691798778; x=1692403578; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZbbsDIf4C6pfkATnl2uZzdgV8NsTXUdrdyGi5hFKqaw=; b=ko/+bAOhIXGU2QhaiIArdh7mw/9jv36VO45vivh5a16KJ+Xt5pLNu4kPQq8PUGgMBv DHd3QXto70zU25HOhbGNGhrFuFBwzh9cyuW7B9wV9FPSjaPZ4cMV8tG+kF3ZEekhuFWl CLmsfJURUL2cyOUpvTRwTAJizZbXhKY7J2mgc3OfQWvv/qMXHrb+wdZZF8AuGZ04hd5G Jex0eGUXj7qb5ye//xSLhNh8cm0HcsMZAr5X3U2CtEgqcOUgdp6NVHPjCaoxMotrEeL1 7dLKF/7neW10UM8JmsHn0ZhcFv/MrIr5H6HUfcv4OSL1NN74KeaitSxA/4pu81+b3B/h 3Zzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691798778; x=1692403578; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZbbsDIf4C6pfkATnl2uZzdgV8NsTXUdrdyGi5hFKqaw=; b=HgQdNFqfqF1ufA9SJCjsAl98jsgQH+udhxb4rmXdkJNzLhrb9Mlwvhozse3J7JCsrm 7mm/XKvZW901ycetTNENxxvlV68IO0Skzse5gp3EzUWlxq/A7DXNoZUGn76YLPD2thc5 EdnjlPWUQ3zCYvixt7j243kVSY6koAsEEFxrntAi+PNyxgAMtXwYnMHY0kaZT68tcbk/ u/JfKBoL0ArTB9xe1YxDOR5EUUQu9R+illERFQ2YWarhcxUOzoS7yJ9kqxqAB5xo6iBx CWcnhyU5RO10psDrq64jR5I7H6NKsffcF4Cc5vko3AdRvFk1d6CW27FppFqQe4D7ecc5 +7XA== X-Gm-Message-State: AOJu0YyflhAl4R60Km2NDE7lW44T97knKXxIb8iS36DzvG3KJ6b1FXBn bm3frt/KCKhrICX1jmB0NBk= X-Google-Smtp-Source: AGHT+IGUFXxAhltzhc0ZCEJ67gUnLWkzmkGyidV0gLrMk+nMbJOZV8Qfv3dbyTHY/M+0TYEVIUvcXQ== X-Received: by 2002:a05:6a00:1703:b0:668:83b7:fd02 with SMTP id h3-20020a056a00170300b0066883b7fd02mr4151944pfc.31.1691798777814; Fri, 11 Aug 2023 17:06:17 -0700 (PDT) Received: from celestia.nettie.lan (static-198-54-134-172.cust.tzulo.com. [198.54.134.172]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b00686bef8e55csm3848834pfm.39.2023.08.11.17.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 17:06:17 -0700 (PDT) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Heiko Schocher , Kyungmin Park Cc: u-boot@lists.denx.de, Sam Edwards Subject: [RFC PATCH 2/4] mtd: ubi: bind block device driver for static volumes Date: Fri, 11 Aug 2023 18:06:04 -0600 Message-ID: <20230812000606.72319-3-CFSworks@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230812000606.72319-1-CFSworks@gmail.com> References: <20230812000606.72319-1-CFSworks@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This makes static UBI volumes readable as block devices, however no mechanism for selecting these volume devices yet exists. Signed-off-by: Sam Edwards --- drivers/mtd/ubi/ubi-uclass.c | 110 +++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/drivers/mtd/ubi/ubi-uclass.c b/drivers/mtd/ubi/ubi-uclass.c index f8971e793e..231d6d90c7 100644 --- a/drivers/mtd/ubi/ubi-uclass.c +++ b/drivers/mtd/ubi/ubi-uclass.c @@ -8,10 +8,119 @@ #define LOG_CATEGORY UCLASS_UBI #include +#include #include #include #include +static ulong ubi_bread(struct udevice *dev, lbaint_t lba, lbaint_t blkcnt, + void *dst) +{ + int err, lnum; + struct blk_desc *blk = dev_get_uclass_plat(dev); + struct ubi_device *ubi = dev_get_plat(dev->parent); + struct ubi_volume *vol = ubi->volumes[blk->devnum]; + lbaint_t lba_per_peb = vol->usable_leb_size / blk->blksz; + lbaint_t lba_off, lba_len, total = 0; + + while (blkcnt) { + lnum = lba / lba_per_peb; + lba_off = lba % lba_per_peb; + lba_len = lba_per_peb - lba_off; + if (lba_len > blkcnt) + lba_len = blkcnt; + + err = ubi_eba_read_leb(ubi, vol, lnum, dst, + lba_off << blk->log2blksz, + lba_len << blk->log2blksz, 0); + if (err) { + pr_err("UBI read error %x\n", err); + break; + } + + lba += lba_len; + blkcnt -= lba_len; + dst += lba_len << blk->log2blksz; + total += lba_len; + } + + return total; +} + +static const struct blk_ops ubi_block_ops = { + .read = ubi_bread, +}; + +U_BOOT_DRIVER(ubi_block) = { + .name = "ubi_block", + .id = UCLASS_BLK, + .ops = &ubi_block_ops, +}; + +static bool is_power_of_two(unsigned int x) +{ + return (x & -x) == x; +} + +static unsigned int choose_blksz_for_volume(const struct ubi_volume *vol) +{ + /* + * U-Boot assumes a power-of-two blksz; however, UBI LEBs are + * very often not suitably sized. To solve this, we divide the + * LEBs into a whole number of LBAs per LEB, such that each LBA + * addresses a power-of-two-sized block. To choose the blksz, + * we either: + * 1) Use the volume alignment, if it's a non-unity power of + * two. The LEB size is a multiple of this alignment, and it + * allows the user to force a particular blksz if needed for + * their use case. + * 2) Otherwise, find the greatest power-of-two factor of the + * LEB size. + */ + if (vol->alignment > 1 && is_power_of_two(vol->alignment)) + return vol->alignment; + + unsigned int blksz = 1; + while ((vol->usable_leb_size & blksz) == 0) + blksz <<= 1; + return blksz; +} + +static int ubi_post_bind(struct udevice *dev) +{ + int i; + int ret; + unsigned int blksz; + lbaint_t lba; + struct ubi_device *ubi = dev_get_plat(dev); + + for (i = 0; i < ubi->vtbl_slots; i++) { + struct ubi_volume *vol = ubi->volumes[i]; + if (!vol || vol->vol_id >= UBI_INTERNAL_VOL_START || + vol->vol_type != UBI_STATIC_VOLUME) + continue; + + if (vol->updating || vol->upd_marker) { + pr_err("** UBI volume %d (\"%s\") midupdate; ignored\n", + vol->vol_id, vol->name); + continue; + } + + blksz = choose_blksz_for_volume(vol); + lba = DIV_ROUND_UP((unsigned long long)vol->used_bytes, blksz); + + pr_debug("UBI volume %d (\"%s\"): %lu blocks, %d bytes each\n", + vol->vol_id, vol->name, lba, blksz); + + ret = blk_create_device(dev, "ubi_block", vol->name, UCLASS_UBI, + vol->vol_id, blksz, lba, NULL); + if (ret) + return ret; + } + + return 0; +} + int ubi_dm_bind(unsigned int index) { struct udevice *dev; @@ -71,4 +180,5 @@ U_BOOT_DRIVER(ubi) = { UCLASS_DRIVER(ubi) = { .id = UCLASS_UBI, .name = "ubi", + .post_bind = ubi_post_bind, }; From patchwork Sat Aug 12 00:06:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Edwards X-Patchwork-Id: 1820447 X-Patchwork-Delegate: dario.binacchi@amarulasolutions.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=Ilzchboc; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RN1DX5Cy0z1yf2 for ; Sat, 12 Aug 2023 10:06:52 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5701886954; Sat, 12 Aug 2023 02:06:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Ilzchboc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AE73C86959; Sat, 12 Aug 2023 02:06:23 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8D7CD86915 for ; Sat, 12 Aug 2023 02:06:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=cfsworks@gmail.com Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6873a30d02eso1899192b3a.3 for ; Fri, 11 Aug 2023 17:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691798780; x=1692403580; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v2zmJKnSfR4C/ixDOEZa5+Scmj0+LOzHh0gJlz+aL10=; b=IlzchbocLT/9rwMdIce0qHF/zSswpGzzxCdAv3S3UM3WNRJa3mVyitornO5hlNBYsv V8q5WADW+UJSZIG5mCSNdrvAAerurbpEML4BTrFv58DL0OdhG8PDUTjKlFtAoU1M9RaM HQJhuKJ5Vj5icKi++O5ZGC9GwykAyfOkiFOIVkjOX+5OKaza9qFi67kFkN33gK6Hrv0s CdE6/QOClARLcTpmK+4ryk4aJikF7vZ57WEElF1zn1qqaqvZG86YOCr2OVp5a4sJD0qZ f7qpCvAOz52V+y6PRr3LP7pEAEGfyP7BKBb3HgYeTliDcPlPfxMCcL1j8/37l1r/7czJ E4hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691798780; x=1692403580; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v2zmJKnSfR4C/ixDOEZa5+Scmj0+LOzHh0gJlz+aL10=; b=E2Fs1JQjqOlVw+ms1mAAEZD1AuO/PyCAu36Qdggx1szvT9fJ8GNsnDvCgXu6qSdHua nx3DiOUAICHL4ngBn9YspnnK0Rk/rTqbYyNPNAF1gqJ73ultG+bJRp2wEeczizG5Dlmb ZGnH7BozyJhozZNETHOnb2JqRQnnlCwKUy0LwUeqUNjEscIY0x5yu9rh2PAM+pMRFyCz D/4q9USryh1gj1etL9HcWhkIgr853WSMsiPHqWN16EVSj4+vkW6Pk4Uj2VnlJUxf5+PS omoyqYodN3we3wR8CXDALupkAR7b7MCU8Nk4l9xn8IqeSglnRX2cwNw0s+HcxvHEe2V/ Jmug== X-Gm-Message-State: AOJu0Yy6elJ8nWceeSIZGuKZggGtyeBJqP9aMBrTI+EMpcXrtSwyp4Q4 uoKCGoJutHXZdtYA3nP2MSlreYJARGs= X-Google-Smtp-Source: AGHT+IEEQZdDFY4Mw4EWhlyZ/jIOG+Njvx/zk+g5JuL15CcXoiaCPZ9j+NQKdKeshKYZOqWWheN+jw== X-Received: by 2002:a05:6a20:9683:b0:137:a9d7:de12 with SMTP id hp3-20020a056a20968300b00137a9d7de12mr2697699pzc.59.1691798779836; Fri, 11 Aug 2023 17:06:19 -0700 (PDT) Received: from celestia.nettie.lan (static-198-54-134-172.cust.tzulo.com. [198.54.134.172]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b00686bef8e55csm3848834pfm.39.2023.08.11.17.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 17:06:18 -0700 (PDT) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Heiko Schocher , Kyungmin Park Cc: u-boot@lists.denx.de, Sam Edwards Subject: [RFC PATCH 3/4] disk: part: fall-through if "ubi" requested but ubifs not mounted Date: Fri, 11 Aug 2023 18:06:05 -0600 Message-ID: <20230812000606.72319-4-CFSworks@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230812000606.72319-1-CFSworks@gmail.com> References: <20230812000606.72319-1-CFSworks@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Since we're adding the ability to access static UBI volumes as block devices, it is no longer an error to use the "ubi" ifname with UBIFS unmounted. Ideally, the access to UBIFS should instead be called "ubifs" but it would break backwards compatibility to change this. Instead, use the UBIFS mount status to disambiguate what the user means by "ubi" There is no change in functionality in this patch: UBIFS access works the same and an error still occurs when using "ubi" without UBIFS mounted. The only difference is that now, the error message is a plain "Bad device specification" and does not suggest using ubifsmount. Signed-off-by: Sam Edwards --- disk/part.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/disk/part.c b/disk/part.c index 0a03b8213d..1ad8277b65 100644 --- a/disk/part.c +++ b/disk/part.c @@ -492,15 +492,13 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, #if IS_ENABLED(CONFIG_CMD_UBIFS) && !IS_ENABLED(CONFIG_SPL_BUILD) /* - * Special-case ubi, ubi goes through a mtd, rather than through - * a regular block device. + * Special-case ubifs, which does not go through the block device layer + * and also must be mounted ahead of time. U-Boot has historically + * called this "ubi" too, even though *static* UBI volumes are + * accessible as block devices. For backward compatibility, assume that + * when UBIFS is mounted, the user intends "ubi" to mean "ubifs." */ - if (!strcmp(ifname, "ubi")) { - if (!ubifs_is_mounted()) { - printf("UBIFS not mounted, use ubifsmount to mount volume first!\n"); - return -EINVAL; - } - + if (ubifs_is_mounted() && !strcmp(ifname, "ubi")) { strcpy((char *)info->type, BOOT_PART_TYPE); strcpy((char *)info->name, "UBI"); return 0; From patchwork Sat Aug 12 00:06:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Edwards X-Patchwork-Id: 1820448 X-Patchwork-Delegate: dario.binacchi@amarulasolutions.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=mmYTOYOR; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RN1Dm4Ngxz1yf2 for ; Sat, 12 Aug 2023 10:07:04 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9AFDE86958; Sat, 12 Aug 2023 02:06:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mmYTOYOR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BEB518696C; Sat, 12 Aug 2023 02:06:24 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A4F478694A for ; Sat, 12 Aug 2023 02:06:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=cfsworks@gmail.com Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6874d1c8610so1974727b3a.0 for ; Fri, 11 Aug 2023 17:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691798781; x=1692403581; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B1cPWvDUSrchITPUFqDJKG/h7PP+aMoFZka7Erfphvg=; b=mmYTOYORjuqYxkSIWl/Oqn+XwZY5Tx2ljfIcYKITBslPrGOW4Mc24SgBP451f6a0Jv n9Bwf8SWjRcGWqp4lfHlm6+E4bIvTHDkl02TbrAXWoJtUV2FsV7l+CAj9yKEWKkTEEWY KOgGsBliArDOA44G8v1yRbs4R5Rd5XSITR/UT8ynIjuSSO7O5sFD0ic5RMZewzH6DhiH Ik1kkbIum7CBDAT1F2wPGsRyGfxsFK+oPwEzOD2sWqQuXD7sJoCq0fctXsyoKwow9gGH ATtJfb2PrDLZ26x6uQ0SUb66UVwofWu47WCYOa8ElpnBAuryyl1xjV3F1qjANbLgjqD4 IUWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691798781; x=1692403581; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B1cPWvDUSrchITPUFqDJKG/h7PP+aMoFZka7Erfphvg=; b=cL+Be7UK13DHT7KMGPL0F4lWOJYHuO5H/Bb11cWsdCWJVzjz1PzB5az+QGoJZ191uK AIMetpsAJ8ATYEPbsBjPcR9LryDmm2WFm+cBh9ukQ49Goruw+nvaoT622m+78kgaz5rv rwRUZMJarjB0tMD3qyz8jJKciFpMXhqDCKVRqxjI7/R4xEpyMNnuAE/0MH+06AQe43Z/ l1/GtARYvofBtoqQ05g48H9+RpOfVAmpo9vDs9DBcon0Acr586XgMBa7PpSIAw0q24B0 5rursW4/lBHDWvZezKTd6XOx3LjTQ4utduKCYfoo/jWftmGNbnelXamxOaJ/QBe/FT2y aaig== X-Gm-Message-State: AOJu0Yy87kghh0NBMjkQQieG78q96dHzfoVzgw2F1nUyZ+XBGysHhuho 2S6+T6iZ5uiDp4xrLSfK4tw= X-Google-Smtp-Source: AGHT+IEutgawaGmRcB/4/PZs919nb5bHGbeyMa2+uJI/MH+kEKeBREtp0SAT2rkGkV6pNYGP3D8Hyw== X-Received: by 2002:a05:6a21:2790:b0:13f:cd07:2b3c with SMTP id rn16-20020a056a21279000b0013fcd072b3cmr3159949pzb.36.1691798781058; Fri, 11 Aug 2023 17:06:21 -0700 (PDT) Received: from celestia.nettie.lan (static-198-54-134-172.cust.tzulo.com. [198.54.134.172]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b00686bef8e55csm3848834pfm.39.2023.08.11.17.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 17:06:20 -0700 (PDT) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Heiko Schocher , Kyungmin Park Cc: u-boot@lists.denx.de, Sam Edwards Subject: [RFC PATCH 4/4] HACK: enable access to `ubi 0:volname` block devices Date: Fri, 11 Aug 2023 18:06:06 -0600 Message-ID: <20230812000606.72319-5-CFSworks@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230812000606.72319-1-CFSworks@gmail.com> References: <20230812000606.72319-1-CFSworks@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean --- disk/part.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/disk/part.c b/disk/part.c index 1ad8277b65..85eb51429a 100644 --- a/disk/part.c +++ b/disk/part.c @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include #undef PART_DEBUG @@ -505,6 +508,59 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, } #endif +#if IS_ENABLED(CONFIG_CMD_UBI) && !IS_ENABLED(CONFIG_SPL_BUILD) + /* + * Also special-case UBI, which may use names to find the specific + * volumes, so this deviates a bit from the typical devnum:partnum + * syntax. + */ + if (!strcmp(ifname, "ubi")) { + dev = hextoul(dev_part_str, &ep); + if (*ep == ':') { + struct udevice *ubi_dev = NULL; + struct udevice *vol_dev = NULL; + part_str = &ep[1]; + + ret = uclass_find_device(UCLASS_UBI, dev, &ubi_dev); + if (!ubi_dev || ret) { + printf("** Cannot find UBI %x\n", dev); + return -EINVAL; + } + + part = hextoul(part_str, &ep); + if (!*ep) { + struct udevice *tmp_dev; + device_foreach_child(tmp_dev, ubi_dev) { + struct blk_desc *desc = dev_get_uclass_plat(tmp_dev); + if (desc->devnum == part) { + vol_dev = tmp_dev; + break; + } + } + } + + if (!vol_dev) + ret = device_find_child_by_name(ubi_dev, part_str, &vol_dev); + + if (!vol_dev || ret) { + printf("** UBI volume %s not found\n", part_str); + return -EINVAL; + } + + ret = device_probe(vol_dev); + if (ret) + return ret; + + *dev_desc = dev_get_uclass_plat(vol_dev); + part_get_info_whole_disk(*dev_desc, info); + return 0; + } + + printf("UBIFS not mounted, use ubifsmount to mount volume first!\n"); + return -EINVAL; + } +#endif + /* If no dev_part_str, use bootdevice environment variable */ if (!dev_part_str || !strlen(dev_part_str) || !strcmp(dev_part_str, "-"))