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);