From patchwork Thu Oct 5 23:08:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Edwards X-Patchwork-Id: 1844180 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=20230601 header.b=LzpP/ccb; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S1nLw6WSZz1yqD for ; Fri, 6 Oct 2023 10:09:28 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1B1BD86C98; Fri, 6 Oct 2023 01:08:51 +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="LzpP/ccb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E76C286C0C; Fri, 6 Oct 2023 01:08:48 +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-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) (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 9F5B886BA0 for ; Fri, 6 Oct 2023 01:08:42 +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-il1-x12f.google.com with SMTP id e9e14a558f8ab-351208d0d6cso6256335ab.1 for ; Thu, 05 Oct 2023 16:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696547321; x=1697152121; darn=lists.denx.de; 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=SzttcXK/PKgI20uIB1bBvYt7CYS7s1sFWwjsGhMAXJU=; b=LzpP/ccbJW9flf2cJkWjqcDuVcMHdL6Shp6Foo7ZdW/3dM0u+ey2hDirMblbOt8wwy zVzbbiAGIl2bdUsd7kS0LTQqfy5hKYe5pzCxJ72jwxwq/BFeVcK/X56LhkFKXQPfzCRu FllQF3hbMyW5M7I3AfOG2g/+3l8jlFFgxqETU3j1bF2o9p72byxGTa1iRuWY0t5zveKb 96ubgsllDKTRMz4yIlTF+KUsGOp1+zeocHOOhS0XVxtrblfuPKncrSGpHbw20P2xUyPs Sx/oM53srMPAYenGN7dW032zp9NK5ixP0HFlgP8C4Lzs0Pv+V1OFVtCdbVevdovfbF8p Zbcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696547321; x=1697152121; 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=SzttcXK/PKgI20uIB1bBvYt7CYS7s1sFWwjsGhMAXJU=; b=kMqL+wEcRsP+6WOkxiDQEozkjmwts0c3oX5XgpzXQ77gt5Qnua4bKcje3eR3VBqO0O YxtazHCot5Fljp1g8+dgFe+gzKza6H6D+sJqhpaCaWz6SNOmq+QXQ1NR7WpdxroD3jAJ bKhLm2hVjBkgxM9sB+/rI9LRuodAIqZHnpfgBV3L12lV0bAJw7wNXhPgobJMzplAAmVr OKKMckFod0knjMrJD8FBdHdebIU/pJ7DNAf04HYExR21HTZlDTU3nTz98LIZp+dYWtpK OsVVVAZQAKYmccVffqr5zntzccgZ7rptnCRa+LNKZPtdAFgihvEPBIhMVuJPcJtx7eQ6 kRmQ== X-Gm-Message-State: AOJu0Yyu1X5zZwvaDjRPwnErRC9VQG/vIeZFMHfnpc90spaTrqCv+Vl+ 3fXaK+jiRSFbDcBjmeoM4xr6UkchVY2+wQ== X-Google-Smtp-Source: AGHT+IGA7eaOc9+KBcJZkyR2uxothx9yl6YSDx3b4+FsTJSWhKSsG3LqPacAlZe+46GnVCNVg0hqDw== X-Received: by 2002:a05:6e02:930:b0:349:851b:3e48 with SMTP id o16-20020a056e02093000b00349851b3e48mr5629076ilt.28.1696547321311; Thu, 05 Oct 2023 16:08:41 -0700 (PDT) Received: from celestia.nettie.lan ([2001:470:42c4:101:9b88:f219:40c8:60fc]) by smtp.gmail.com with ESMTPSA id l17-20020a922811000000b003513b7613f3sm709974ilf.3.2023.10.05.16.08.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 16:08:40 -0700 (PDT) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Heiko Schocher , Simon Glass Cc: Kyungmin Park , u-boot@lists.denx.de, Sam Edwards Subject: [RFC PATCH v2 1/4] mtd: ubi: register UBI attachments as DM devices Date: Thu, 5 Oct 2023 17:08:28 -0600 Message-ID: <20231005230831.4032070-2-CFSworks@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231005230831.4032070-1-CFSworks@gmail.com> References: <20231005230831.4032070-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 0a6a80bdd1..314c7f60f4 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 0432c95c9e..ee11fbb38d 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -140,6 +140,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 Thu Oct 5 23:08:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Edwards X-Patchwork-Id: 1844179 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=20230601 header.b=FxuIzusA; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S1nLZ6ykQz1yqD for ; Fri, 6 Oct 2023 10:09:10 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9F2A686BFA; Fri, 6 Oct 2023 01:08:50 +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="FxuIzusA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 99E4A86D28; Fri, 6 Oct 2023 01:08:48 +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-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) (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 C85D686C0C for ; Fri, 6 Oct 2023 01:08:43 +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-il1-x12f.google.com with SMTP id e9e14a558f8ab-351367c8fcdso6225385ab.3 for ; Thu, 05 Oct 2023 16:08:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696547322; x=1697152122; darn=lists.denx.de; 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=2z9xVsPdWH0H95bkDMT585tTHq2Ow72A8On4zXyiplM=; b=FxuIzusAJwUdwK9Zf7Ub8xCfb+h4Qqka1ucDaSAZC1As+60jPCFaA5zeaXXZM1mbyI ofJukHf7Du+VIlQ2GUuKsz+A4OnM8AzaBck96FtT+eNGsq1XNltk1Ut48tfAvo/XU4II yq77IHM5OgWo1DCAs0AzeOfBt5YCYF7ZkT5t/h/u+cW833EKDQnCxfe5tk5xWeoQA1tD THwZ0qCvPC8kmTVmkCjIFjXMINwXqoI/dQJDqZaoqvW3N8F3zUYRvHs9uZaH1wUHbSId KlWg5dOGVxOftSLY6vBvQ+69IRo+4U3ku6skEbqrM1LW10knfVMQ+1j3ACzZZSDYWVZI ALtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696547322; x=1697152122; 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=2z9xVsPdWH0H95bkDMT585tTHq2Ow72A8On4zXyiplM=; b=IwS9K7yaOf6M1RsMknxLorJfiooSChpWCM6uaN8ZN0qDaQn5JNMxz28iJmg3El6rSm V3Ursb4pz30Esri1w/X2WexF9tqJZSXkzXPCD8Q57VMx551jz7e77URtSYTWbquqi94d fZgqgox1wEaUxRg12ry7zwNh11g+FJ9oTx6Ode5WSEtihjzfEhxmu/CSBstErsyQ8/FL oLygKIFkCXfRTPgmIQyIq2ujvxqQl153AtOV9xlWewABs7opQ8w2nS19U+GeKqeEjxun tqSUOvF6MJT7awaOffi16exzW5cG+dNMyp5SxYPZVR02x2d4wIjwZIpfNeTjjBYM4Uc2 mxJw== X-Gm-Message-State: AOJu0YyZQ6pIhd53D58vKT7EcRCLKt5cwIK7GNrzlmcepw8VNry+4Zsu jYtwern9npKIZfxb35jjd7pNdZ4//ePcsA== X-Google-Smtp-Source: AGHT+IHJAHmthY0UxEI2MNapnkFsPLZQWbBXXAhuuA/t66dJMpckTSDGahHoBt5iMER0wpfMkmqnvQ== X-Received: by 2002:a05:6e02:1d11:b0:352:a306:9ad1 with SMTP id i17-20020a056e021d1100b00352a3069ad1mr8080547ila.0.1696547322427; Thu, 05 Oct 2023 16:08:42 -0700 (PDT) Received: from celestia.nettie.lan ([2001:470:42c4:101:9b88:f219:40c8:60fc]) by smtp.gmail.com with ESMTPSA id l17-20020a922811000000b003513b7613f3sm709974ilf.3.2023.10.05.16.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 16:08:41 -0700 (PDT) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Heiko Schocher , Simon Glass Cc: Kyungmin Park , u-boot@lists.denx.de, Sam Edwards Subject: [RFC PATCH v2 2/4] mtd: ubi: bind block device driver for static volumes Date: Thu, 5 Oct 2023 17:08:29 -0600 Message-ID: <20231005230831.4032070-3-CFSworks@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231005230831.4032070-1-CFSworks@gmail.com> References: <20231005230831.4032070-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 | 111 +++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/drivers/mtd/ubi/ubi-uclass.c b/drivers/mtd/ubi/ubi-uclass.c index f8971e793e..b2c47bfe0c 100644 --- a/drivers/mtd/ubi/ubi-uclass.c +++ b/drivers/mtd/ubi/ubi-uclass.c @@ -8,10 +8,120 @@ #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 udevice *blkdev; + 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, &blkdev); + if (ret) + return ret; + } + + return 0; +} + int ubi_dm_bind(unsigned int index) { struct udevice *dev; @@ -71,4 +181,5 @@ U_BOOT_DRIVER(ubi) = { UCLASS_DRIVER(ubi) = { .id = UCLASS_UBI, .name = "ubi", + .post_bind = ubi_post_bind, }; From patchwork Thu Oct 5 23:08:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Edwards X-Patchwork-Id: 1844181 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=20230601 header.b=HYOvqz5V; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S1nM71y4bz1yqD for ; Fri, 6 Oct 2023 10:09:39 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8596786D29; Fri, 6 Oct 2023 01:08:51 +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="HYOvqz5V"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6CCAE86C0C; Fri, 6 Oct 2023 01:08:49 +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-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) (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 99C3786C98 for ; Fri, 6 Oct 2023 01:08:44 +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-il1-x133.google.com with SMTP id e9e14a558f8ab-352a27ab1aeso6526765ab.3 for ; Thu, 05 Oct 2023 16:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696547323; x=1697152123; darn=lists.denx.de; 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=07Mlx/7I4oUZt5/A7bSwriKZgQwQdWy9fcTqVU/t/Do=; b=HYOvqz5Vw8oobWRp8fNq0lWmePDKsfHEYsqHQT0sum8UewIJ4r67fWTMc3tHQ5i8YS AgbAPvPmnxV3YXTT3RO9OiGq0295rfzOvfbZfud9Ci0DuUl+WeywSUhIS6xm2Yhr6YM9 +c7zR5VM+8R2sumAkrsfpYWssVhi7Wj4Lvgx9XIiMjd1cEvL8IE/pnGlXRfYnPWlUXaw wyHEYDDZ6+kQh5Td8i0dFpTNnHWlfz89rfQqC5eY+VebOgVJpucwKlSj4myE40w30ouz 21MhbBnYjJoHjxhFEgk3yBPMaSn4pMhPT7gZkQu2xKkKA37YdRLLRp/0EfQt8RQ947KW me2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696547323; x=1697152123; 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=07Mlx/7I4oUZt5/A7bSwriKZgQwQdWy9fcTqVU/t/Do=; b=fFtlvd+7ekKFdWAGxG6Jh9M+4ZwTiGIuYkT6AWy8a6iitWcCHOKQb0BZ8Tiw4I20HA P+ZhSdX9qBTZT9tvWW+rEFCF/IQM8kM1OLwafcrpvMuGxgM4dXafosJFwCDuESeyD1at e9tFAwAVWdeVqAkVCsmTx27UZek9lD1YAOC8r+ZhNM6h1pNiTgDPjwBEy/5nH6xHcmFa coVBA6l6kIiP0lnzI+ERS5aGzOB3lPCn0p+2691nqY7yZ2/w06vTiua3zS/86UEzm4ZH sXTbyNwhsa/JwSwdt9VpfQj2sp3l9rS/Ad5O0jZue5Magm5sPXZEFdLqwYjIQOX/Rz2S lGtw== X-Gm-Message-State: AOJu0Yw7CnPAaMiKIyr858lNCPDtnPfG3r+fZ0EMEs66x66MTVTfk7r1 x9gyZBMC0nH6ro7zfBqIOHE= X-Google-Smtp-Source: AGHT+IF+w0s4oXdQFHQ2SjKvcurnAY5mmG0Zp5AMyTqk68Q8ulZ4sNZIq8g3lbE8wTVHwkhcoL6LoQ== X-Received: by 2002:a05:6e02:2189:b0:34f:35e8:5098 with SMTP id j9-20020a056e02218900b0034f35e85098mr7824648ila.20.1696547323284; Thu, 05 Oct 2023 16:08:43 -0700 (PDT) Received: from celestia.nettie.lan ([2001:470:42c4:101:9b88:f219:40c8:60fc]) by smtp.gmail.com with ESMTPSA id l17-20020a922811000000b003513b7613f3sm709974ilf.3.2023.10.05.16.08.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 16:08:42 -0700 (PDT) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Heiko Schocher , Simon Glass Cc: Kyungmin Park , u-boot@lists.denx.de, Sam Edwards Subject: [RFC PATCH v2 3/4] disk: part: fall-through if "ubi" requested but ubifs not mounted Date: Thu, 5 Oct 2023 17:08:30 -0600 Message-ID: <20231005230831.4032070-4-CFSworks@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231005230831.4032070-1-CFSworks@gmail.com> References: <20231005230831.4032070-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 72241b7b23..a4b6d265da 100644 --- a/disk/part.c +++ b/disk/part.c @@ -511,15 +511,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 Thu Oct 5 23:08:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Edwards X-Patchwork-Id: 1844182 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=20230601 header.b=aX2OoT7c; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S1nMS5t66z1yqD for ; Fri, 6 Oct 2023 10:09:56 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0640886B18; Fri, 6 Oct 2023 01:08:54 +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="aX2OoT7c"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F0CA386AB3; Fri, 6 Oct 2023 01:08:50 +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=unavailable autolearn_force=no version=3.4.2 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) (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 C107C86C2F for ; Fri, 6 Oct 2023 01:08:45 +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-il1-x133.google.com with SMTP id e9e14a558f8ab-3529eafb3a9so6270115ab.2 for ; Thu, 05 Oct 2023 16:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696547324; x=1697152124; darn=lists.denx.de; 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=aB2O72bA4FINfbHMTGYiyRM5U044fF9JN3/NC490yG4=; b=aX2OoT7cNJItMqI6FE9mRud11dIg/w30CdH781AeC6UEWDukeBu0Q5HpqUpWsdjFEN jCFF9j/xuvtv0XYKQAqnbz/Ft6gQrfoyoN7R9O7ndf2+Jvl642J8UU2veO4YtBsFnb+T ihQanFZAHeRGKBSJAR0ZKhYKkBvRro9ZVQnnXE4aAq42pEEIN0cwgzfoPOtc4YVTLLKv rGrph2Mke74BBlJtu+7IWqJxsJN1Te8N+0swo4nMATMgDlMhAqmMTiNfuiFm2PGTOK24 LXnaRWdlP35QrgXiHE7MePup5rMa+Oy4lBx9q7LSh0uG9aHEuiuqCccygbKdWnmBvif1 Ej3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696547324; x=1697152124; 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=aB2O72bA4FINfbHMTGYiyRM5U044fF9JN3/NC490yG4=; b=veOWRBBMSW/HbY+u33Jk7NtzMX+4iWbGu4K9fH2+PWn9I1YWH+HViVP58KdmJ1snfs hMlzd5Eod1iHejzZWh3VBMMo+k6nI8Yjv9LH5zIAt25flmogFE5gmgpTGOG+DIdyh4Yq 4GuhnuqOR9MIylSq1/IdJwj4JUcVDwapaeOo/WWVN0MbL/x7JzEej2Od2uF6kICn0m5/ w/rsmP+GK8C6LwAE+V2EHOQ0/X7rVrBoDnAIwEk7A9iPBbV8u8ysXnLOGg65OK1YkW1v HztYmDNffLnE8hhdQfx+5UEHTFhpCTjSHWi2tIVNo2XzrfLeaPThmLKSjPmyWy+2d6vp v0dw== X-Gm-Message-State: AOJu0YzYjmSJMeCp/luN4/7hbwmWc0tLWG5Marex33Aa2yvfpqPY5GZ4 I9bc0l+JYIVDciSlTnjkoE54GdKzOe70ew== X-Google-Smtp-Source: AGHT+IHeqx6BxOwFOblOralPjhFpKAte6AYyM08J+kKaQ8m2wLLLeD/nghWBJkuxmEIeTM9U3TzY2g== X-Received: by 2002:a05:6e02:1061:b0:34f:d9db:66c4 with SMTP id q1-20020a056e02106100b0034fd9db66c4mr5983857ilj.30.1696547324061; Thu, 05 Oct 2023 16:08:44 -0700 (PDT) Received: from celestia.nettie.lan ([2001:470:42c4:101:9b88:f219:40c8:60fc]) by smtp.gmail.com with ESMTPSA id l17-20020a922811000000b003513b7613f3sm709974ilf.3.2023.10.05.16.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 16:08:43 -0700 (PDT) From: Sam Edwards X-Google-Original-From: Sam Edwards To: Heiko Schocher , Simon Glass Cc: Kyungmin Park , u-boot@lists.denx.de, Sam Edwards Subject: [RFC PATCH v2 4/4] HACK: enable access to `ubi 0:volname` block devices Date: Thu, 5 Oct 2023 17:08:31 -0600 Message-ID: <20231005230831.4032070-5-CFSworks@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231005230831.4032070-1-CFSworks@gmail.com> References: <20231005230831.4032070-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 | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/disk/part.c b/disk/part.c index a4b6d265da..7c995f583c 100644 --- a/disk/part.c +++ b/disk/part.c @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include #undef PART_DEBUG @@ -524,6 +527,58 @@ 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 = dectoul(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 = dectoul(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; + } + } + } else { + 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; + + *desc = dev_get_uclass_plat(vol_dev); + part_get_info_whole_disk(*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 (CONFIG_IS_ENABLED(ENV_SUPPORT)) { if (!dev_part_str || !strlen(dev_part_str) ||