From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 14/18] misc: storage-by-alias: switch over to using cdev aliases
Date: Mon, 14 Apr 2025 08:31:48 +0200 [thread overview]
Message-ID: <20250414063152.2736649-15-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250414063152.2736649-1-a.fatoum@pengutronix.de>
This makes it easy to support referencing further cdev aliases
from the device tree.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/boot.c | 1 +
common/cdev-alias.c | 31 +++++++++++++++++++++++++++++++
drivers/misc/storage-by-alias.c | 25 +++++++++----------------
3 files changed, 41 insertions(+), 16 deletions(-)
diff --git a/commands/boot.c b/commands/boot.c
index 502ad19e5e75..97c574b4a0a3 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -184,6 +184,7 @@ BAREBOX_CMD_HELP_TEXT("- \"bootchooser\": boot with barebox bootchooser")
#endif
#ifdef CONFIG_BOOT_DEFAULTS
BAREBOX_CMD_HELP_TEXT("- \"bootsource\": boot from the device barebox has been started from")
+BAREBOX_CMD_HELP_TEXT("- \"diskuuid.*\": boot from disk with specified diskuuid")
#endif
BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("Multiple bootsources may be given which are probed in order until")
diff --git a/common/cdev-alias.c b/common/cdev-alias.c
index 09e6770f5dea..4ce79d0ba4a7 100644
--- a/common/cdev-alias.c
+++ b/common/cdev-alias.c
@@ -35,8 +35,39 @@ static int cdev_alias_resolve_bootsource(struct cdev_alias *cdev_alias,
return fn(cdev, data);
}
+static int cdev_alias_resolve_diskuuid(struct cdev_alias *cdev_alias,
+ const char *uuid,
+ cdev_alias_processor_t fn,
+ void *data)
+{
+ struct cdev *cdev;
+ char *arg;
+
+ arg = xstrdup(uuid);
+ uuid = strsep(&arg, ".");
+ if (!uuid || !*uuid)
+ return -EINVAL;
+
+ for_each_cdev(cdev) {
+ if (cdev_is_partition(cdev))
+ continue;
+
+ if (strcasecmp(cdev->diskuuid, uuid))
+ continue;
+
+ cdev = cdev_find_partition(cdev, arg);
+ if (!cdev)
+ return -ENODEV;
+
+ return fn(cdev, data);
+ }
+
+ return 0;
+}
+
static struct cdev_alias cdev_alias_aliases[] = {
{ "bootsource", cdev_alias_resolve_bootsource },
+ { "diskuuid", cdev_alias_resolve_diskuuid },
{ /* sentinel */}
};
diff --git a/drivers/misc/storage-by-alias.c b/drivers/misc/storage-by-alias.c
index 2795ff93c07c..0bf0059ad41c 100644
--- a/drivers/misc/storage-by-alias.c
+++ b/drivers/misc/storage-by-alias.c
@@ -119,12 +119,15 @@ static struct cdev_operations sba_ops = {
.truncate = sba_truncate,
};
-static void sba_add_partitions(struct sba *sba, struct cdev *rcdev)
+static int sba_add_partitions(struct cdev *rcdev, void *data)
{
+ struct sba *sba = data;
int ret;
+ dev_dbg(sba->dev, "Adding %s -> %s\n", sba->alias, rcdev->name);
+
if (sba->rcdev)
- return;
+ return 0;
sba->rcdev = rcdev;
sba->cdev.name = sba->alias;
@@ -139,26 +142,16 @@ static void sba_add_partitions(struct sba *sba, struct cdev *rcdev)
ret = devfs_create(&sba->cdev);
if (ret) {
dev_err(sba->dev, "Failed to create cdev: %s\n", strerror(-ret));
- return;
+ return 0;
}
of_parse_partitions(&sba->cdev, sba->dev->of_node);
+ return 0;
}
static void check_exist(struct sba *sba)
{
- struct cdev *cdev;
-
- for_each_cdev(cdev) {
- if (cdev_is_partition(cdev))
- continue;
- if (strcmp(cdev->diskuuid, sba->alias))
- continue;
-
- dev_dbg(sba->dev, "Found %s %s\n", cdev->name, cdev->diskuuid);
- sba_add_partitions(sba, cdev);
- return;
- }
+ cdev_alias_resolve_for_each(sba->alias, sba_add_partitions, sba);
}
static int sba_detect(struct device *dev)
@@ -181,7 +174,7 @@ static int storage_by_uuid_init(struct sba *sba)
if (ret)
return ret;
- sba->alias = xstrdup(uuid);
+ sba->alias = xasprintf("diskuuid.%s", uuid);
return 0;
}
--
2.39.5
next prev parent reply other threads:[~2025-04-14 6:36 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 01/18] cdev: make cdev_find_child_by_gpt_typeuuid external Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 02/18] cdev: constify cdev_find_child_by_gpt_typeuuid's guid_t pointer argument Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 03/18] partition: efi: respect DPS_TYPE_FLAG_NO_AUTO flag Ahmad Fatoum
2025-04-14 11:38 ` Sascha Hauer
2025-04-14 6:31 ` [PATCH 04/18] blspec: iterate over all XBOOTLDR partitions Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 05/18] blspec: support GPT XBOOTLDR partition Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 06/18] blspec: collect bootloader spec entries from ESP Ahmad Fatoum
2025-04-14 10:14 ` Marco Felsch
2025-04-14 10:19 ` Ahmad Fatoum
2025-04-14 10:41 ` Marco Felsch
2025-04-14 6:31 ` [PATCH 07/18] cdev: alias: add support for partition links Ahmad Fatoum
2025-04-14 10:17 ` Marco Felsch
2025-04-14 10:20 ` Ahmad Fatoum
2025-04-14 10:49 ` Marco Felsch
2025-04-14 13:28 ` Sascha Hauer
2025-04-14 6:31 ` [PATCH 08/18] cdev: do not dereference partname for non-partitions Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 09/18] cdev: use common cdev_free helper internally Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 10/18] cdev: implement devfs_create_link in terms of devfs_create Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 11/18] misc: storage-by-uuid: consider only first diskuuid match Ahmad Fatoum
2025-04-14 10:24 ` Marco Felsch
2025-04-14 10:31 ` Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 12/18] misc: storage-by-uuid: prepare for generalizing to different aliases Ahmad Fatoum
2025-04-14 10:31 ` Marco Felsch
2025-04-14 10:35 ` Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 13/18] misc: storage-by-uuid: rename to storage-by-alias Ahmad Fatoum
2025-04-14 6:31 ` Ahmad Fatoum [this message]
2025-04-14 6:31 ` [PATCH 15/18] misc: storage-by-alias: add support barebox,bootsource Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 16/18] misc: storage-by-alias: register as link to main cdev Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 17/18] cdev: constify cdev_readlink argument Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 18/18] cdev: follow links in cdev_find_child_by_gpt_typeuuid Ahmad Fatoum
2025-04-14 10:51 ` [PATCH 00/18] boot: improve cdev alias and blspec support Marco Felsch
2025-04-14 13:25 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250414063152.2736649-15-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox