* [PATCH 01/18] cdev: make cdev_find_child_by_gpt_typeuuid external
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
@ 2025-04-14 6:31 ` 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
` (18 subsequent siblings)
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
From: Ahmad Fatoum <a.fatoum@barebox.org>
The function is already used from two places and long enough that we
probably don't want to duplicate it more than once in the final binary.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/devfs-core.c | 16 ++++++++++++++++
include/driver.h | 17 ++---------------
2 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 2617eeea0706..f67c86b2267e 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -126,6 +126,22 @@ struct cdev *cdev_by_diskuuid(const char *diskuuid)
return NULL;
}
+struct cdev *
+cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, guid_t *typeuuid)
+{
+ struct cdev *partcdev;
+
+ if (!cdev_is_gpt_partitioned(cdev))
+ return ERR_PTR(-EINVAL);
+
+ for_each_cdev_partition(partcdev, cdev) {
+ if (guid_equal(&partcdev->typeuuid, typeuuid))
+ return partcdev;
+ }
+
+ return ERR_PTR(-ENOENT);
+}
+
/**
* device_find_partition - find a partition belonging to a physical device
*
diff --git a/include/driver.h b/include/driver.h
index 094347d4577e..d01d026b687b 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -608,21 +608,8 @@ static inline bool cdev_is_gpt_partitioned(const struct cdev *master)
return master && (master->flags & DEVFS_IS_GPT_PARTITIONED);
}
-static inline struct cdev *
-cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, guid_t *typeuuid)
-{
- struct cdev *partcdev;
-
- if (!cdev_is_gpt_partitioned(cdev))
- return ERR_PTR(-EINVAL);
-
- for_each_cdev_partition(partcdev, cdev) {
- if (guid_equal(&partcdev->typeuuid, typeuuid))
- return partcdev;
- }
-
- return ERR_PTR(-ENOENT);
-}
+struct cdev *
+cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, guid_t *typeuuid);
#ifdef CONFIG_FS_AUTOMOUNT
void cdev_create_default_automount(struct cdev *cdev);
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 02/18] cdev: constify cdev_find_child_by_gpt_typeuuid's guid_t pointer argument
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 ` Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 03/18] partition: efi: respect DPS_TYPE_FLAG_NO_AUTO flag Ahmad Fatoum
` (17 subsequent siblings)
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
From: Ahmad Fatoum <a.fatoum@barebox.org>
The UUID is only used for comparison and never written.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/devfs-core.c | 2 +-
include/driver.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index f67c86b2267e..f84b34ea53ab 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -127,7 +127,7 @@ struct cdev *cdev_by_diskuuid(const char *diskuuid)
}
struct cdev *
-cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, guid_t *typeuuid)
+cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, const guid_t *typeuuid)
{
struct cdev *partcdev;
diff --git a/include/driver.h b/include/driver.h
index d01d026b687b..3f2c681c0e80 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -609,7 +609,7 @@ static inline bool cdev_is_gpt_partitioned(const struct cdev *master)
}
struct cdev *
-cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, guid_t *typeuuid);
+cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, const guid_t *typeuuid);
#ifdef CONFIG_FS_AUTOMOUNT
void cdev_create_default_automount(struct cdev *cdev);
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 03/18] partition: efi: respect DPS_TYPE_FLAG_NO_AUTO flag
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 ` 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
` (16 subsequent siblings)
19 siblings, 1 reply; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
From: Ahmad Fatoum <a.fatoum@barebox.org>
The DPS_TYPE_FLAG_NO_AUTO flag indicates that a partition should not be
automatically discovered by type UUID if not directly referenced.
We do auto discovery for barebox env and sate using
cdev_find_child_by_gpt_typeuuid, so teach it to respect that flag.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/blspec.c | 4 ++--
common/bootscan.c | 11 +++++++++--
fs/devfs-core.c | 11 +++++++++--
include/bootscan.h | 5 ++++-
4 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/common/blspec.c b/common/blspec.c
index 5223ac30f8a5..59fa40c9ff50 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -511,7 +511,7 @@ static int blspec_scan_disk(struct bootscanner *scanner,
* should be used as $BOOT
*/
if (cdev_is_mbr_partitioned(cdev) && partcdev->dos_partition_type == 0xea) {
- ret = boot_scan_cdev(scanner, bootentries, partcdev);
+ ret = boot_scan_cdev(scanner, bootentries, partcdev, true);
if (ret == 0)
ret = -ENOENT;
@@ -560,7 +560,7 @@ static int blspec_scan_device(struct bootscanner *scanner,
* by the bootblspec spec).
*/
list_for_each_entry(cdev, &dev->cdevs, devices_list) {
- ret = boot_scan_cdev(scanner, bootentries, cdev);
+ ret = boot_scan_cdev(scanner, bootentries, cdev, true);
if (ret > 0)
found += ret;
}
diff --git a/common/bootscan.c b/common/bootscan.c
index 222498c609a4..813d6d242a08 100644
--- a/common/bootscan.c
+++ b/common/bootscan.c
@@ -8,6 +8,7 @@
#include <linux/stat.h>
#include <linux/err.h>
#include <mtd/ubi-user.h>
+#include <uapi/spec/dps.h>
#include <bootscan.h>
@@ -80,7 +81,8 @@ static int boot_scan_ubi(struct bootscanner *scanner,
* error occurred.
*/
int boot_scan_cdev(struct bootscanner *scanner,
- struct bootentries *bootentries, struct cdev *cdev)
+ struct bootentries *bootentries, struct cdev *cdev,
+ bool autodiscover)
{
int ret, found = 0;
void *buf = xzalloc(512);
@@ -89,6 +91,11 @@ int boot_scan_cdev(struct bootscanner *scanner,
pr_debug("%s(%s): %s\n", __func__, scanner->name, cdev->name);
+ if (autodiscover && (cdev->typeflags & DPS_TYPE_FLAG_NO_AUTO)) {
+ pr_debug("auto discovery skipped\n");
+ return 0;
+ }
+
ret = cdev_read(cdev, buf, 512, 0, 0);
if (ret < 0) {
free(buf);
@@ -144,7 +151,7 @@ static int boot_scan_devicename(struct bootscanner *scanner,
cdev = cdev_by_name(devname);
if (cdev) {
- int ret = boot_scan_cdev(scanner, bootentries, cdev);
+ int ret = boot_scan_cdev(scanner, bootentries, cdev, false);
if (ret > 0)
return ret;
}
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index f84b34ea53ab..c69c38d6506e 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -27,6 +27,7 @@
#include <unistd.h>
#include <range.h>
#include <fs.h>
+#include <spec/dps.h>
LIST_HEAD(cdev_list);
@@ -135,8 +136,14 @@ cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, const guid_t *typeuuid)
return ERR_PTR(-EINVAL);
for_each_cdev_partition(partcdev, cdev) {
- if (guid_equal(&partcdev->typeuuid, typeuuid))
- return partcdev;
+ if (!guid_equal(&partcdev->typeuuid, typeuuid))
+ continue;
+ if (cdev->typeflags & DPS_TYPE_FLAG_NO_AUTO) {
+ dev_dbg(cdev->dev, "auto discovery skipped\n");
+ continue;
+ }
+
+ return partcdev;
}
return ERR_PTR(-ENOENT);
diff --git a/include/bootscan.h b/include/bootscan.h
index 99094dc09320..ffc67c4a90ab 100644
--- a/include/bootscan.h
+++ b/include/bootscan.h
@@ -2,6 +2,8 @@
#ifndef __BOOTSCAN_H
#define __BOOTSCAN_H
+#include <linux/types.h>
+
struct bootentries;
struct device;
struct cdev;
@@ -25,7 +27,8 @@ struct bootscanner {
};
int boot_scan_cdev(struct bootscanner *scanner,
- struct bootentries *bootentries, struct cdev *cdev);
+ struct bootentries *bootentries, struct cdev *cdev,
+ bool autodiscover);
int bootentry_scan_generate(struct bootscanner *scanner,
struct bootentries *bootentries,
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 03/18] partition: efi: respect DPS_TYPE_FLAG_NO_AUTO flag
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
0 siblings, 0 replies; 33+ messages in thread
From: Sascha Hauer @ 2025-04-14 11:38 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Apr 14, 2025 at 08:31:37AM +0200, Ahmad Fatoum wrote:
> From: Ahmad Fatoum <a.fatoum@barebox.org>
>
> The DPS_TYPE_FLAG_NO_AUTO flag indicates that a partition should not be
> automatically discovered by type UUID if not directly referenced.
>
> We do auto discovery for barebox env and sate using
In case you have to resend for other reasons:
s/sate/state/
> cdev_find_child_by_gpt_typeuuid, so teach it to respect that flag.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> common/blspec.c | 4 ++--
> common/bootscan.c | 11 +++++++++--
> fs/devfs-core.c | 11 +++++++++--
> include/bootscan.h | 5 ++++-
> 4 files changed, 24 insertions(+), 7 deletions(-)
>
> diff --git a/common/blspec.c b/common/blspec.c
> index 5223ac30f8a5..59fa40c9ff50 100644
> --- a/common/blspec.c
> +++ b/common/blspec.c
> @@ -511,7 +511,7 @@ static int blspec_scan_disk(struct bootscanner *scanner,
> * should be used as $BOOT
> */
> if (cdev_is_mbr_partitioned(cdev) && partcdev->dos_partition_type == 0xea) {
> - ret = boot_scan_cdev(scanner, bootentries, partcdev);
> + ret = boot_scan_cdev(scanner, bootentries, partcdev, true);
> if (ret == 0)
> ret = -ENOENT;
>
> @@ -560,7 +560,7 @@ static int blspec_scan_device(struct bootscanner *scanner,
> * by the bootblspec spec).
> */
> list_for_each_entry(cdev, &dev->cdevs, devices_list) {
> - ret = boot_scan_cdev(scanner, bootentries, cdev);
> + ret = boot_scan_cdev(scanner, bootentries, cdev, true);
> if (ret > 0)
> found += ret;
> }
> diff --git a/common/bootscan.c b/common/bootscan.c
> index 222498c609a4..813d6d242a08 100644
> --- a/common/bootscan.c
> +++ b/common/bootscan.c
> @@ -8,6 +8,7 @@
> #include <linux/stat.h>
> #include <linux/err.h>
> #include <mtd/ubi-user.h>
> +#include <uapi/spec/dps.h>
>
> #include <bootscan.h>
>
> @@ -80,7 +81,8 @@ static int boot_scan_ubi(struct bootscanner *scanner,
> * error occurred.
> */
> int boot_scan_cdev(struct bootscanner *scanner,
> - struct bootentries *bootentries, struct cdev *cdev)
> + struct bootentries *bootentries, struct cdev *cdev,
> + bool autodiscover)
> {
> int ret, found = 0;
> void *buf = xzalloc(512);
> @@ -89,6 +91,11 @@ int boot_scan_cdev(struct bootscanner *scanner,
>
> pr_debug("%s(%s): %s\n", __func__, scanner->name, cdev->name);
>
> + if (autodiscover && (cdev->typeflags & DPS_TYPE_FLAG_NO_AUTO)) {
> + pr_debug("auto discovery skipped\n");
> + return 0;
> + }
> +
> ret = cdev_read(cdev, buf, 512, 0, 0);
> if (ret < 0) {
> free(buf);
> @@ -144,7 +151,7 @@ static int boot_scan_devicename(struct bootscanner *scanner,
>
> cdev = cdev_by_name(devname);
> if (cdev) {
> - int ret = boot_scan_cdev(scanner, bootentries, cdev);
> + int ret = boot_scan_cdev(scanner, bootentries, cdev, false);
> if (ret > 0)
> return ret;
> }
> diff --git a/fs/devfs-core.c b/fs/devfs-core.c
> index f84b34ea53ab..c69c38d6506e 100644
> --- a/fs/devfs-core.c
> +++ b/fs/devfs-core.c
> @@ -27,6 +27,7 @@
> #include <unistd.h>
> #include <range.h>
> #include <fs.h>
> +#include <spec/dps.h>
>
> LIST_HEAD(cdev_list);
>
> @@ -135,8 +136,14 @@ cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, const guid_t *typeuuid)
> return ERR_PTR(-EINVAL);
>
> for_each_cdev_partition(partcdev, cdev) {
> - if (guid_equal(&partcdev->typeuuid, typeuuid))
> - return partcdev;
> + if (!guid_equal(&partcdev->typeuuid, typeuuid))
> + continue;
> + if (cdev->typeflags & DPS_TYPE_FLAG_NO_AUTO) {
> + dev_dbg(cdev->dev, "auto discovery skipped\n");
> + continue;
> + }
> +
> + return partcdev;
> }
>
> return ERR_PTR(-ENOENT);
> diff --git a/include/bootscan.h b/include/bootscan.h
> index 99094dc09320..ffc67c4a90ab 100644
> --- a/include/bootscan.h
> +++ b/include/bootscan.h
> @@ -2,6 +2,8 @@
> #ifndef __BOOTSCAN_H
> #define __BOOTSCAN_H
>
> +#include <linux/types.h>
> +
> struct bootentries;
> struct device;
> struct cdev;
> @@ -25,7 +27,8 @@ struct bootscanner {
> };
>
> int boot_scan_cdev(struct bootscanner *scanner,
> - struct bootentries *bootentries, struct cdev *cdev);
> + struct bootentries *bootentries, struct cdev *cdev,
> + bool autodiscover);
>
> int bootentry_scan_generate(struct bootscanner *scanner,
> struct bootentries *bootentries,
> --
> 2.39.5
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 04/18] blspec: iterate over all XBOOTLDR partitions
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (2 preceding siblings ...)
2025-04-14 6:31 ` [PATCH 03/18] partition: efi: respect DPS_TYPE_FLAG_NO_AUTO flag Ahmad Fatoum
@ 2025-04-14 6:31 ` Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 05/18] blspec: support GPT XBOOTLDR partition Ahmad Fatoum
` (15 subsequent siblings)
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We currently stop at the first XBOOTLDR partition when collecting
entries, but there might be more than one XBOOTLDR partition, so we
should really iterate over all of them.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/blspec.c | 40 ++++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/common/blspec.c b/common/blspec.c
index 59fa40c9ff50..cf9f973acd21 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -502,33 +502,41 @@ static int blspec_scan_disk(struct bootscanner *scanner,
struct bootentries *bootentries, struct cdev *cdev)
{
struct cdev *partcdev;
- int ret;
+ int ret, err = 0, found = 0;
for_each_cdev_partition(partcdev, cdev) {
+ struct cdev *match = NULL;
+
/*
* If the OS is installed on a disk with MBR disk label, and a
* partition with the MBR type id of 0xEA already exists it
* should be used as $BOOT
*/
- if (cdev_is_mbr_partitioned(cdev) && partcdev->dos_partition_type == 0xea) {
- ret = boot_scan_cdev(scanner, bootentries, partcdev, true);
- if (ret == 0)
- ret = -ENOENT;
-
- return ret;
+ if (cdev_is_mbr_partitioned(cdev)) {
+ if (partcdev->dos_partition_type == 0xea)
+ match = partcdev;
+ } else {
+ /*
+ * If the OS is installed on a disk with GPT disk label, and a
+ * partition with the GPT type GUID of
+ * bc13c2ff-59e6-4262-a352-b275fd6f7172 already exists, it
+ * should be used as $BOOT.
+ *
+ * Not yet implemented
+ */
}
- /*
- * If the OS is installed on a disk with GPT disk label, and a
- * partition with the GPT type GUID of
- * bc13c2ff-59e6-4262-a352-b275fd6f7172 already exists, it
- * should be used as $BOOT.
- *
- * Not yet implemented
- */
+ if (!match)
+ continue;
+
+ ret = boot_scan_cdev(scanner, bootentries, partcdev, true);
+ if (ret > 0)
+ found += ret;
+ else
+ err = ret ?: -ENOENT;
}
- return 0;
+ return found ?: err;
}
/*
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 05/18] blspec: support GPT XBOOTLDR partition
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (3 preceding siblings ...)
2025-04-14 6:31 ` [PATCH 04/18] blspec: iterate over all XBOOTLDR partitions Ahmad Fatoum
@ 2025-04-14 6:31 ` Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 06/18] blspec: collect bootloader spec entries from ESP Ahmad Fatoum
` (14 subsequent siblings)
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
So far we matched the XBOOTLDR partition only on MBR-partitioned media.
Let's do the same for GPT too.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/blspec.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/common/blspec.c b/common/blspec.c
index cf9f973acd21..adc3fb2e2ea2 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -16,6 +16,7 @@
#include <linux/stat.h>
#include <linux/list.h>
#include <linux/err.h>
+#include <uapi/spec/dps.h>
#include <boot.h>
#include <bootscan.h>
@@ -508,22 +509,22 @@ static int blspec_scan_disk(struct bootscanner *scanner,
struct cdev *match = NULL;
/*
- * If the OS is installed on a disk with MBR disk label, and a
- * partition with the MBR type id of 0xEA already exists it
- * should be used as $BOOT
+ * If the OS is installed on a disk with:
+ *
+ * - MBR disk label, and a partition with the MBR type id of 0xEA
+ * already exists
+ *
+ * - GPT disk label, and a partition with the GPT type GUID of
+ * bc13c2ff-59e6-4262-a352-b275fd6f7172 already exists
+ *
+ * it should be used as $BOOT
*/
if (cdev_is_mbr_partitioned(cdev)) {
if (partcdev->dos_partition_type == 0xea)
match = partcdev;
- } else {
- /*
- * If the OS is installed on a disk with GPT disk label, and a
- * partition with the GPT type GUID of
- * bc13c2ff-59e6-4262-a352-b275fd6f7172 already exists, it
- * should be used as $BOOT.
- *
- * Not yet implemented
- */
+ } else if (cdev_is_gpt_partitioned(cdev)) {
+ if (guid_equal(&partcdev->typeuuid, &SD_GPT_XBOOTLDR))
+ match = partcdev;
}
if (!match)
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 06/18] blspec: collect bootloader spec entries from ESP
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (4 preceding siblings ...)
2025-04-14 6:31 ` [PATCH 05/18] blspec: support GPT XBOOTLDR partition Ahmad Fatoum
@ 2025-04-14 6:31 ` Ahmad Fatoum
2025-04-14 10:14 ` Marco Felsch
2025-04-14 6:31 ` [PATCH 07/18] cdev: alias: add support for partition links Ahmad Fatoum
` (13 subsequent siblings)
19 siblings, 1 reply; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The spec points out that spec entries should be collected from ESP, even
when XBOOTLDR partitions exist, but at a lower priority.
Implement this logic in barebox. As barebox as EFI payload systems have
an ESP, but may have the bootloader spec files in a separate partition,
we can't skip the walk through all partitions when we have an ESP like
we do for XBOOTLDR partitions.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/blspec.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/common/blspec.c b/common/blspec.c
index adc3fb2e2ea2..dd3bb1c167d7 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -504,6 +504,7 @@ static int blspec_scan_disk(struct bootscanner *scanner,
{
struct cdev *partcdev;
int ret, err = 0, found = 0;
+ bool have_esp = false;
for_each_cdev_partition(partcdev, cdev) {
struct cdev *match = NULL;
@@ -517,9 +518,13 @@ static int blspec_scan_disk(struct bootscanner *scanner,
* - GPT disk label, and a partition with the GPT type GUID of
* bc13c2ff-59e6-4262-a352-b275fd6f7172 already exists
*
+ * - an EFI System Partition and none of the above
+ *
* it should be used as $BOOT
*/
- if (cdev_is_mbr_partitioned(cdev)) {
+ if (partcdev->flags & DEVFS_PARTITION_BOOTABLE_ESP)
+ have_esp = true;
+ else if (cdev_is_mbr_partitioned(cdev)) {
if (partcdev->dos_partition_type == 0xea)
match = partcdev;
} else if (cdev_is_gpt_partitioned(cdev)) {
@@ -537,6 +542,25 @@ static int blspec_scan_disk(struct bootscanner *scanner,
err = ret ?: -ENOENT;
}
+ if (!have_esp)
+ goto out;
+
+ for_each_cdev_partition(partcdev, cdev) {
+ if (!(partcdev->flags & DEVFS_PARTITION_BOOTABLE_ESP))
+ continue;
+
+ /*
+ * ESP is only a fallback. If we have an ESP, but no bootloader spec
+ * files inside, this is not an error.
+ */
+ ret = boot_scan_cdev(scanner, bootentries, partcdev, true);
+ if (ret >= 0)
+ found += ret;
+ else
+ err = ret;
+ }
+
+out:
return found ?: err;
}
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 06/18] blspec: collect bootloader spec entries from ESP
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
0 siblings, 1 reply; 33+ messages in thread
From: Marco Felsch @ 2025-04-14 10:14 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On 25-04-14, Ahmad Fatoum wrote:
> The spec points out that spec entries should be collected from ESP, even
> when XBOOTLDR partitions exist, but at a lower priority.
>
> Implement this logic in barebox. As barebox as EFI payload systems have
> an ESP, but may have the bootloader spec files in a separate partition,
> we can't skip the walk through all partitions when we have an ESP like
> we do for XBOOTLDR partitions.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> common/blspec.c | 26 +++++++++++++++++++++++++-
> 1 file changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/common/blspec.c b/common/blspec.c
> index adc3fb2e2ea2..dd3bb1c167d7 100644
> --- a/common/blspec.c
> +++ b/common/blspec.c
> @@ -504,6 +504,7 @@ static int blspec_scan_disk(struct bootscanner *scanner,
> {
> struct cdev *partcdev;
> int ret, err = 0, found = 0;
> + bool have_esp = false;
>
> for_each_cdev_partition(partcdev, cdev) {
> struct cdev *match = NULL;
> @@ -517,9 +518,13 @@ static int blspec_scan_disk(struct bootscanner *scanner,
> * - GPT disk label, and a partition with the GPT type GUID of
> * bc13c2ff-59e6-4262-a352-b275fd6f7172 already exists
> *
> + * - an EFI System Partition and none of the above
> + *
> * it should be used as $BOOT
> */
> - if (cdev_is_mbr_partitioned(cdev)) {
> + if (partcdev->flags & DEVFS_PARTITION_BOOTABLE_ESP)
> + have_esp = true;
> + else if (cdev_is_mbr_partitioned(cdev)) {
> if (partcdev->dos_partition_type == 0xea)
> match = partcdev;
> } else if (cdev_is_gpt_partitioned(cdev)) {
> @@ -537,6 +542,25 @@ static int blspec_scan_disk(struct bootscanner *scanner,
> err = ret ?: -ENOENT;
> }
>
> + if (!have_esp)
> + goto out;
> +
> + for_each_cdev_partition(partcdev, cdev) {
> + if (!(partcdev->flags & DEVFS_PARTITION_BOOTABLE_ESP))
> + continue;
> +
> + /*
> + * ESP is only a fallback. If we have an ESP, but no bootloader spec
> + * files inside, this is not an error.
> + */
> + ret = boot_scan_cdev(scanner, bootentries, partcdev, true);
> + if (ret >= 0)
> + found += ret;
> + else
> + err = ret;
> + }
Is it allowed to have multiple ESP partitions? If not we could save us
the additional loop and just store the ESP directly and make use of it.
Regards,
Marco
> +
> +out:
> return found ?: err;
> }
>
> --
> 2.39.5
>
>
>
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 06/18] blspec: collect bootloader spec entries from ESP
2025-04-14 10:14 ` Marco Felsch
@ 2025-04-14 10:19 ` Ahmad Fatoum
2025-04-14 10:41 ` Marco Felsch
0 siblings, 1 reply; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 10:19 UTC (permalink / raw)
To: Marco Felsch; +Cc: barebox
Hello Marco,
On 4/14/25 12:14, Marco Felsch wrote:
> On 25-04-14, Ahmad Fatoum wrote:
>> + if (!have_esp)
>> + goto out;
>> +
>> + for_each_cdev_partition(partcdev, cdev) {
>> + if (!(partcdev->flags & DEVFS_PARTITION_BOOTABLE_ESP))
>> + continue;
>> +
>> + /*
>> + * ESP is only a fallback. If we have an ESP, but no bootloader spec
>> + * files inside, this is not an error.
>> + */
>> + ret = boot_scan_cdev(scanner, bootentries, partcdev, true);
>> + if (ret >= 0)
>> + found += ret;
>> + else
>> + err = ret;
>> + }
>
> Is it allowed to have multiple ESP partitions? If not we could save us
> the additional loop and just store the ESP directly and make use of it.
It may make sense to have multiple ESPs on the same medium, as long as
some of them set DPS_TYPE_FLAG_NO_AUTO in the upper bits of the Type
UUID. I didn't want to preclude such a configuration, hence the loop.
Thanks,
Ahmad
>
> Regards,
> Marco
>
>
>> +
>> +out:
>> return found ?: err;
>> }
>>
>> --
>> 2.39.5
>>
>>
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 06/18] blspec: collect bootloader spec entries from ESP
2025-04-14 10:19 ` Ahmad Fatoum
@ 2025-04-14 10:41 ` Marco Felsch
0 siblings, 0 replies; 33+ messages in thread
From: Marco Felsch @ 2025-04-14 10:41 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On 25-04-14, Ahmad Fatoum wrote:
> Hello Marco,
>
> On 4/14/25 12:14, Marco Felsch wrote:
> > On 25-04-14, Ahmad Fatoum wrote:
> >> + if (!have_esp)
> >> + goto out;
> >> +
> >> + for_each_cdev_partition(partcdev, cdev) {
> >> + if (!(partcdev->flags & DEVFS_PARTITION_BOOTABLE_ESP))
> >> + continue;
> >> +
> >> + /*
> >> + * ESP is only a fallback. If we have an ESP, but no bootloader spec
> >> + * files inside, this is not an error.
> >> + */
> >> + ret = boot_scan_cdev(scanner, bootentries, partcdev, true);
> >> + if (ret >= 0)
> >> + found += ret;
> >> + else
> >> + err = ret;
> >> + }
> >
> > Is it allowed to have multiple ESP partitions? If not we could save us
> > the additional loop and just store the ESP directly and make use of it.
>
> It may make sense to have multiple ESPs on the same medium, as long as
> some of them set DPS_TYPE_FLAG_NO_AUTO in the upper bits of the Type
> UUID. I didn't want to preclude such a configuration, hence the loop.
Make sense.
Regards,
Marco
>
> Thanks,
> Ahmad
>
> >
> > Regards,
> > Marco
> >
> >
> >> +
> >> +out:
> >> return found ?: err;
> >> }
> >>
> >> --
> >> 2.39.5
> >>
> >>
> >>
> >
>
> --
> Pengutronix e.K. | |
> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
>
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 07/18] cdev: alias: add support for partition links
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (5 preceding siblings ...)
2025-04-14 6:31 ` [PATCH 06/18] blspec: collect bootloader spec entries from ESP Ahmad Fatoum
@ 2025-04-14 6:31 ` Ahmad Fatoum
2025-04-14 10:17 ` Marco Felsch
2025-04-14 6:31 ` [PATCH 08/18] cdev: do not dereference partname for non-partitions Ahmad Fatoum
` (12 subsequent siblings)
19 siblings, 1 reply; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We currently support bootsource.2, but not bootsource.root-A.
Fix this and while at it, factor out the logic for general reuse.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/cdev-alias.c | 22 +++-------------------
fs/devfs-core.c | 29 +++++++++++++++++++++++++++++
include/driver.h | 1 +
3 files changed, 33 insertions(+), 19 deletions(-)
diff --git a/common/cdev-alias.c b/common/cdev-alias.c
index 5c37c2e58bf3..09e6770f5dea 100644
--- a/common/cdev-alias.c
+++ b/common/cdev-alias.c
@@ -17,22 +17,6 @@ struct cdev_alias {
cdev_alias_processor_t fn, void *data);
};
-static struct cdev *resolve_partition(struct cdev *cdev,
- const char *partname)
-{
- struct cdev *partcdev;
-
- if (!partname)
- return cdev;
-
- for_each_cdev_partition(partcdev, cdev) {
- if (streq_ptr(partcdev->partname, partname))
- return partcdev;
- }
-
- return ERR_PTR(-ENODEV);
-}
-
static int cdev_alias_resolve_bootsource(struct cdev_alias *cdev_alias,
const char *partname,
cdev_alias_processor_t fn,
@@ -44,9 +28,9 @@ static int cdev_alias_resolve_bootsource(struct cdev_alias *cdev_alias,
if (!cdev)
return -ENODEV;
- cdev = resolve_partition(cdev, partname);
- if (IS_ERR(cdev))
- return PTR_ERR(cdev);
+ cdev = cdev_find_partition(cdev, partname);
+ if (!cdev)
+ return -ENODEV;
return fn(cdev, data);
}
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index c69c38d6506e..e32bce9e307e 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -21,6 +21,7 @@
#include <malloc.h>
#include <ioctl.h>
#include <nand.h>
+#include <string.h>
#include <linux/err.h>
#include <linux/fs.h>
#include <linux/mtd/mtd.h>
@@ -149,6 +150,34 @@ cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, const guid_t *typeuuid)
return ERR_PTR(-ENOENT);
}
+/**
+ * cdev_find_partition - find a partition belonging to a physical device
+ *
+ * @cdev: the cdev which should be searched for partitions
+ * @name: the partition name
+ */
+struct cdev *cdev_find_partition(struct cdev *cdevm, const char *name)
+{
+ struct cdev *partcdev;
+
+ if (!name)
+ return cdevm;
+
+ for_each_cdev_partition(partcdev, cdevm) {
+ struct cdev *cdevl;
+
+ if (streq_ptr(partcdev->partname, name))
+ return partcdev;
+
+ list_for_each_entry(cdevl, &partcdev->links, link_entry) {
+ if (streq_ptr(cdevl->partname, name))
+ return cdevl;
+ }
+ }
+
+ return NULL;
+}
+
/**
* device_find_partition - find a partition belonging to a physical device
*
diff --git a/include/driver.h b/include/driver.h
index 3f2c681c0e80..ca002c5164c2 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -503,6 +503,7 @@ int devfs_create(struct cdev *);
int devfs_create_link(struct cdev *, const char *name);
int devfs_remove(struct cdev *);
int cdev_find_free_index(const char *);
+struct cdev *cdev_find_partition(struct cdev *cdevm, const char *name);
struct cdev *device_find_partition(struct device *dev, const char *name);
struct cdev *lcdev_by_name(const char *filename);
struct cdev *cdev_readlink(struct cdev *cdev);
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 07/18] cdev: alias: add support for partition links
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
0 siblings, 1 reply; 33+ messages in thread
From: Marco Felsch @ 2025-04-14 10:17 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On 25-04-14, Ahmad Fatoum wrote:
> We currently support bootsource.2, but not bootsource.root-A.
> Fix this and while at it, factor out the logic for general reuse.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> common/cdev-alias.c | 22 +++-------------------
> fs/devfs-core.c | 29 +++++++++++++++++++++++++++++
> include/driver.h | 1 +
> 3 files changed, 33 insertions(+), 19 deletions(-)
>
> diff --git a/common/cdev-alias.c b/common/cdev-alias.c
> index 5c37c2e58bf3..09e6770f5dea 100644
> --- a/common/cdev-alias.c
> +++ b/common/cdev-alias.c
> @@ -17,22 +17,6 @@ struct cdev_alias {
> cdev_alias_processor_t fn, void *data);
> };
>
> -static struct cdev *resolve_partition(struct cdev *cdev,
> - const char *partname)
> -{
> - struct cdev *partcdev;
> -
> - if (!partname)
> - return cdev;
> -
> - for_each_cdev_partition(partcdev, cdev) {
> - if (streq_ptr(partcdev->partname, partname))
> - return partcdev;
> - }
> -
> - return ERR_PTR(-ENODEV);
> -}
> -
> static int cdev_alias_resolve_bootsource(struct cdev_alias *cdev_alias,
> const char *partname,
> cdev_alias_processor_t fn,
> @@ -44,9 +28,9 @@ static int cdev_alias_resolve_bootsource(struct cdev_alias *cdev_alias,
> if (!cdev)
> return -ENODEV;
>
> - cdev = resolve_partition(cdev, partname);
> - if (IS_ERR(cdev))
> - return PTR_ERR(cdev);
> + cdev = cdev_find_partition(cdev, partname);
> + if (!cdev)
> + return -ENODEV;
>
> return fn(cdev, data);
> }
> diff --git a/fs/devfs-core.c b/fs/devfs-core.c
> index c69c38d6506e..e32bce9e307e 100644
> --- a/fs/devfs-core.c
> +++ b/fs/devfs-core.c
> @@ -21,6 +21,7 @@
> #include <malloc.h>
> #include <ioctl.h>
> #include <nand.h>
> +#include <string.h>
> #include <linux/err.h>
> #include <linux/fs.h>
> #include <linux/mtd/mtd.h>
> @@ -149,6 +150,34 @@ cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, const guid_t *typeuuid)
> return ERR_PTR(-ENOENT);
> }
>
> +/**
> + * cdev_find_partition - find a partition belonging to a physical device
> + *
> + * @cdev: the cdev which should be searched for partitions
> + * @name: the partition name
> + */
> +struct cdev *cdev_find_partition(struct cdev *cdevm, const char *name)
> +{
> + struct cdev *partcdev;
> +
> + if (!name)
> + return cdevm;
return ERR_PTR(-EINVAL) ?
Regards,
Marco
> +
> + for_each_cdev_partition(partcdev, cdevm) {
> + struct cdev *cdevl;
> +
> + if (streq_ptr(partcdev->partname, name))
> + return partcdev;
> +
> + list_for_each_entry(cdevl, &partcdev->links, link_entry) {
> + if (streq_ptr(cdevl->partname, name))
> + return cdevl;
> + }
> + }
> +
> + return NULL;
> +}
> +
> /**
> * device_find_partition - find a partition belonging to a physical device
> *
> diff --git a/include/driver.h b/include/driver.h
> index 3f2c681c0e80..ca002c5164c2 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -503,6 +503,7 @@ int devfs_create(struct cdev *);
> int devfs_create_link(struct cdev *, const char *name);
> int devfs_remove(struct cdev *);
> int cdev_find_free_index(const char *);
> +struct cdev *cdev_find_partition(struct cdev *cdevm, const char *name);
> struct cdev *device_find_partition(struct device *dev, const char *name);
> struct cdev *lcdev_by_name(const char *filename);
> struct cdev *cdev_readlink(struct cdev *cdev);
> --
> 2.39.5
>
>
>
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 07/18] cdev: alias: add support for partition links
2025-04-14 10:17 ` Marco Felsch
@ 2025-04-14 10:20 ` Ahmad Fatoum
2025-04-14 10:49 ` Marco Felsch
0 siblings, 1 reply; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 10:20 UTC (permalink / raw)
To: Marco Felsch; +Cc: barebox
Hello Marco,
On 4/14/25 12:17, Marco Felsch wrote:
> On 25-04-14, Ahmad Fatoum wrote:
>> We currently support bootsource.2, but not bootsource.root-A.
>> Fix this and while at it, factor out the logic for general reuse.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
[snip]
>> -static struct cdev *resolve_partition(struct cdev *cdev,
>> - const char *partname)
>> -{
>> - struct cdev *partcdev;
>> -
>> - if (!partname)
>> - return cdev;
>> -
>> - for_each_cdev_partition(partcdev, cdev) {
>> - if (streq_ptr(partcdev->partname, partname))
>> - return partcdev;
>> - }
>> -
>> - return ERR_PTR(-ENODEV);
>> -}
>> -
[snip]
>> +/**
>> + * cdev_find_partition - find a partition belonging to a physical device
>> + *
>> + * @cdev: the cdev which should be searched for partitions
>> + * @name: the partition name
>> + */
>> +struct cdev *cdev_find_partition(struct cdev *cdevm, const char *name)
>> +{
>> + struct cdev *partcdev;
>> +
>> + if (!name)
>> + return cdevm;
No, I want a NULL name to expand to the parent device. This makes is a
drop-in replacement for resolve_partition() removed in this same patch.
Thanks,
Ahmad
>
> return ERR_PTR(-EINVAL) ?
>
> Regards,
> Marco
>
>> +
>> + for_each_cdev_partition(partcdev, cdevm) {
>> + struct cdev *cdevl;
>> +
>> + if (streq_ptr(partcdev->partname, name))
>> + return partcdev;
>> +
>> + list_for_each_entry(cdevl, &partcdev->links, link_entry) {
>> + if (streq_ptr(cdevl->partname, name))
>> + return cdevl;
>> + }
>> + }
>> +
>> + return NULL;
>> +}
>> +
>> /**
>> * device_find_partition - find a partition belonging to a physical device
>> *
>> diff --git a/include/driver.h b/include/driver.h
>> index 3f2c681c0e80..ca002c5164c2 100644
>> --- a/include/driver.h
>> +++ b/include/driver.h
>> @@ -503,6 +503,7 @@ int devfs_create(struct cdev *);
>> int devfs_create_link(struct cdev *, const char *name);
>> int devfs_remove(struct cdev *);
>> int cdev_find_free_index(const char *);
>> +struct cdev *cdev_find_partition(struct cdev *cdevm, const char *name);
>> struct cdev *device_find_partition(struct device *dev, const char *name);
>> struct cdev *lcdev_by_name(const char *filename);
>> struct cdev *cdev_readlink(struct cdev *cdev);
>> --
>> 2.39.5
>>
>>
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 07/18] cdev: alias: add support for partition links
2025-04-14 10:20 ` Ahmad Fatoum
@ 2025-04-14 10:49 ` Marco Felsch
2025-04-14 13:28 ` Sascha Hauer
0 siblings, 1 reply; 33+ messages in thread
From: Marco Felsch @ 2025-04-14 10:49 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On 25-04-14, Ahmad Fatoum wrote:
> Hello Marco,
>
> On 4/14/25 12:17, Marco Felsch wrote:
> > On 25-04-14, Ahmad Fatoum wrote:
> >> We currently support bootsource.2, but not bootsource.root-A.
> >> Fix this and while at it, factor out the logic for general reuse.
> >>
> >> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> >> ---
>
> [snip]
>
> >> -static struct cdev *resolve_partition(struct cdev *cdev,
> >> - const char *partname)
> >> -{
> >> - struct cdev *partcdev;
> >> -
> >> - if (!partname)
> >> - return cdev;
> >> -
> >> - for_each_cdev_partition(partcdev, cdev) {
> >> - if (streq_ptr(partcdev->partname, partname))
> >> - return partcdev;
> >> - }
> >> -
> >> - return ERR_PTR(-ENODEV);
> >> -}
> >> -
>
> [snip]
>
> >> +/**
> >> + * cdev_find_partition - find a partition belonging to a physical device
> >> + *
> >> + * @cdev: the cdev which should be searched for partitions
> >> + * @name: the partition name
> >> + */
> >> +struct cdev *cdev_find_partition(struct cdev *cdevm, const char *name)
> >> +{
> >> + struct cdev *partcdev;
> >> +
> >> + if (!name)
> >> + return cdevm;
>
> No, I want a NULL name to expand to the parent device. This makes is a
> drop-in replacement for resolve_partition() removed in this same patch.
I have seen that :-) but in the end it was a local function so changes
shouldn't be hard to adapt.
With making the function public avaiable I don't see why
cdev_find_partition() should return the parent device if NULL is
provided. IMHO this is wrong input from the user. What use-case do you
see with returning the parent device?
Regards,
Marco
> Thanks,
> Ahmad
>
> >
> > return ERR_PTR(-EINVAL) ?
> >
> > Regards,
> > Marco
> >
> >> +
> >> + for_each_cdev_partition(partcdev, cdevm) {
> >> + struct cdev *cdevl;
> >> +
> >> + if (streq_ptr(partcdev->partname, name))
> >> + return partcdev;
> >> +
> >> + list_for_each_entry(cdevl, &partcdev->links, link_entry) {
> >> + if (streq_ptr(cdevl->partname, name))
> >> + return cdevl;
> >> + }
> >> + }
> >> +
> >> + return NULL;
> >> +}
> >> +
> >> /**
> >> * device_find_partition - find a partition belonging to a physical device
> >> *
> >> diff --git a/include/driver.h b/include/driver.h
> >> index 3f2c681c0e80..ca002c5164c2 100644
> >> --- a/include/driver.h
> >> +++ b/include/driver.h
> >> @@ -503,6 +503,7 @@ int devfs_create(struct cdev *);
> >> int devfs_create_link(struct cdev *, const char *name);
> >> int devfs_remove(struct cdev *);
> >> int cdev_find_free_index(const char *);
> >> +struct cdev *cdev_find_partition(struct cdev *cdevm, const char *name);
> >> struct cdev *device_find_partition(struct device *dev, const char *name);
> >> struct cdev *lcdev_by_name(const char *filename);
> >> struct cdev *cdev_readlink(struct cdev *cdev);
> >> --
> >> 2.39.5
> >>
> >>
> >>
> >
>
> --
> Pengutronix e.K. | |
> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
>
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 07/18] cdev: alias: add support for partition links
2025-04-14 10:49 ` Marco Felsch
@ 2025-04-14 13:28 ` Sascha Hauer
0 siblings, 0 replies; 33+ messages in thread
From: Sascha Hauer @ 2025-04-14 13:28 UTC (permalink / raw)
To: Marco Felsch; +Cc: Ahmad Fatoum, barebox
On Mon, Apr 14, 2025 at 12:49:14PM +0200, Marco Felsch wrote:
> On 25-04-14, Ahmad Fatoum wrote:
> > Hello Marco,
> >
> > On 4/14/25 12:17, Marco Felsch wrote:
> > > On 25-04-14, Ahmad Fatoum wrote:
> > >> We currently support bootsource.2, but not bootsource.root-A.
> > >> Fix this and while at it, factor out the logic for general reuse.
> > >>
> > >> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> > >> ---
> >
> > [snip]
> >
> > >> -static struct cdev *resolve_partition(struct cdev *cdev,
> > >> - const char *partname)
> > >> -{
> > >> - struct cdev *partcdev;
> > >> -
> > >> - if (!partname)
> > >> - return cdev;
> > >> -
> > >> - for_each_cdev_partition(partcdev, cdev) {
> > >> - if (streq_ptr(partcdev->partname, partname))
> > >> - return partcdev;
> > >> - }
> > >> -
> > >> - return ERR_PTR(-ENODEV);
> > >> -}
> > >> -
> >
> > [snip]
> >
> > >> +/**
> > >> + * cdev_find_partition - find a partition belonging to a physical device
> > >> + *
> > >> + * @cdev: the cdev which should be searched for partitions
> > >> + * @name: the partition name
> > >> + */
> > >> +struct cdev *cdev_find_partition(struct cdev *cdevm, const char *name)
> > >> +{
> > >> + struct cdev *partcdev;
> > >> +
> > >> + if (!name)
> > >> + return cdevm;
> >
> > No, I want a NULL name to expand to the parent device. This makes is a
> > drop-in replacement for resolve_partition() removed in this same patch.
>
> I have seen that :-) but in the end it was a local function so changes
> shouldn't be hard to adapt.
>
> With making the function public avaiable I don't see why
> cdev_find_partition() should return the parent device if NULL is
> provided. IMHO this is wrong input from the user. What use-case do you
> see with returning the parent device?
I can follow this argument and changed the caller to:
if (partname) {
cdev = cdev_find_partition(cdev, partname);
if (!cdev)
return -ENODEV;
}
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 08/18] cdev: do not dereference partname for non-partitions
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (6 preceding siblings ...)
2025-04-14 6:31 ` [PATCH 07/18] cdev: alias: add support for partition links Ahmad Fatoum
@ 2025-04-14 6:31 ` Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 09/18] cdev: use common cdev_free helper internally Ahmad Fatoum
` (11 subsequent siblings)
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Except for this one place, the rest of the code can deal with cdev links
to non-partitions. Switch the function over to use streq_ptr, so we can
use cdev master links without risking a NULL pointer dereference.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/devfs-core.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index e32bce9e307e..04bf866a67e0 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -192,13 +192,11 @@ struct cdev *device_find_partition(struct device *dev, const char *name)
list_for_each_entry(cdev, &dev->cdevs, devices_list) {
struct cdev *cdevl;
- if (!cdev->partname)
- continue;
- if (!strcmp(cdev->partname, name))
+ if (streq_ptr(cdev->partname, name))
return cdev;
list_for_each_entry(cdevl, &cdev->links, link_entry) {
- if (!strcmp(cdevl->partname, name))
+ if (streq_ptr(cdevl->partname, name))
return cdev_readlink(cdevl);
}
}
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 09/18] cdev: use common cdev_free helper internally
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (7 preceding siblings ...)
2025-04-14 6:31 ` [PATCH 08/18] cdev: do not dereference partname for non-partitions Ahmad Fatoum
@ 2025-04-14 6:31 ` Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 10/18] cdev: implement devfs_create_link in terms of devfs_create Ahmad Fatoum
` (10 subsequent siblings)
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We duplicate the same three lines at three places and a fourth is
incoming, so create a helper function.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/devfs-core.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 04bf866a67e0..4c5445b17aaf 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -397,6 +397,13 @@ static struct cdev *cdev_alloc(const char *name)
return new;
}
+static void cdev_free(struct cdev *cdev)
+{
+ free(cdev->name);
+ free(cdev->partname);
+ free(cdev);
+}
+
int devfs_create(struct cdev *new)
{
struct cdev *cdev;
@@ -476,11 +483,8 @@ int devfs_remove(struct cdev *cdev)
if (cdev_is_partition(cdev))
list_del(&cdev->partition_entry);
- if (cdev->link) {
- free(cdev->name);
- free(cdev->partname);
- free(cdev);
- }
+ if (cdev->link)
+ cdev_free(cdev);
return 0;
}
@@ -669,9 +673,7 @@ int cdevfs_del_partition(struct cdev *cdev)
if (ret)
return ret;
- free(cdev->name);
- free(cdev->partname);
- free(cdev);
+ cdev_free(cdev);
return 0;
}
@@ -797,8 +799,7 @@ void cdev_remove_loop(struct cdev *cdev)
devfs_remove(cdev);
close(priv->fd);
free(priv);
- free(cdev->name);
- free(cdev);
+ cdev_free(cdev);
}
ssize_t mem_copy(struct device *dev, void *dst, const void *src,
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 10/18] cdev: implement devfs_create_link in terms of devfs_create
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (8 preceding siblings ...)
2025-04-14 6:31 ` [PATCH 09/18] cdev: use common cdev_free helper internally Ahmad Fatoum
@ 2025-04-14 6:31 ` Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 11/18] misc: storage-by-uuid: consider only first diskuuid match Ahmad Fatoum
` (9 subsequent siblings)
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
devfs_create_link and devfs_create do much of the same things, so have
them share the code.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/devfs-core.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 4c5445b17aaf..eb6691b5252b 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -422,15 +422,16 @@ int devfs_create(struct cdev *new)
new->device_node = new->dev->of_node;
}
+ if (new->link)
+ list_add_tail(&new->link_entry, &new->link->links);
+
return 0;
}
int devfs_create_link(struct cdev *cdev, const char *name)
{
struct cdev *new;
-
- if (cdev_by_name(name))
- return -EEXIST;
+ int ret;
/*
* Create a link to the real cdev instead of creating
@@ -441,6 +442,12 @@ int devfs_create_link(struct cdev *cdev, const char *name)
new = cdev_alloc(name);
new->link = cdev;
+ ret = devfs_create(new);
+ if (ret) {
+ cdev_free(new);
+ return ret;
+ }
+
if (cdev->partname) {
size_t partnameoff = 0;
@@ -454,11 +461,6 @@ int devfs_create_link(struct cdev *cdev, const char *name)
new->partname = xstrdup(name + partnameoff);
}
- INIT_LIST_HEAD(&new->links);
- INIT_LIST_HEAD(&new->partitions);
- list_add_tail(&new->list, &cdev_list);
- list_add_tail(&new->link_entry, &cdev->links);
-
return 0;
}
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 11/18] misc: storage-by-uuid: consider only first diskuuid match
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (9 preceding siblings ...)
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 ` Ahmad Fatoum
2025-04-14 10:24 ` Marco Felsch
2025-04-14 6:31 ` [PATCH 12/18] misc: storage-by-uuid: prepare for generalizing to different aliases Ahmad Fatoum
` (8 subsequent siblings)
19 siblings, 1 reply; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Multiple devices with the same disk UUID shouldn't happen and if it
does, the existing code is not equipped to handle that.
Change it, so only the first _disk_ is considered. diskuuid is in a
union with partuuid and that could lead to cdev partition being taken as
backend storage instead.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/misc/storage-by-uuid.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/misc/storage-by-uuid.c b/drivers/misc/storage-by-uuid.c
index 8b8fd901685e..7bb987dffbec 100644
--- a/drivers/misc/storage-by-uuid.c
+++ b/drivers/misc/storage-by-uuid.c
@@ -143,10 +143,14 @@ static void check_exist(struct sbu *sbu)
struct cdev *cdev;
for_each_cdev(cdev) {
- if (!strcmp(cdev->diskuuid, sbu->uuid)) {
- dev_dbg(sbu->dev, "Found %s %s\n", cdev->name, cdev->diskuuid);
- storage_by_uuid_add_partitions(sbu, cdev);
- }
+ if (cdev_is_partition(cdev))
+ continue;
+ if (strcmp(cdev->diskuuid, sbu->uuid))
+ continue;
+
+ dev_dbg(sbu->dev, "Found %s %s\n", cdev->name, cdev->diskuuid);
+ storage_by_uuid_add_partitions(sbu, cdev);
+ return;
}
}
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 11/18] misc: storage-by-uuid: consider only first diskuuid match
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
0 siblings, 1 reply; 33+ messages in thread
From: Marco Felsch @ 2025-04-14 10:24 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On 25-04-14, Ahmad Fatoum wrote:
> Multiple devices with the same disk UUID shouldn't happen and if it
Do we need to print a warning to inform the user that two disks share
the same disk-UUID?
Regards,
Marco
> does, the existing code is not equipped to handle that.
>
> Change it, so only the first _disk_ is considered. diskuuid is in a
> union with partuuid and that could lead to cdev partition being taken as
> backend storage instead.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/misc/storage-by-uuid.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/misc/storage-by-uuid.c b/drivers/misc/storage-by-uuid.c
> index 8b8fd901685e..7bb987dffbec 100644
> --- a/drivers/misc/storage-by-uuid.c
> +++ b/drivers/misc/storage-by-uuid.c
> @@ -143,10 +143,14 @@ static void check_exist(struct sbu *sbu)
> struct cdev *cdev;
>
> for_each_cdev(cdev) {
> - if (!strcmp(cdev->diskuuid, sbu->uuid)) {
> - dev_dbg(sbu->dev, "Found %s %s\n", cdev->name, cdev->diskuuid);
> - storage_by_uuid_add_partitions(sbu, cdev);
> - }
> + if (cdev_is_partition(cdev))
> + continue;
> + if (strcmp(cdev->diskuuid, sbu->uuid))
> + continue;
> +
> + dev_dbg(sbu->dev, "Found %s %s\n", cdev->name, cdev->diskuuid);
> + storage_by_uuid_add_partitions(sbu, cdev);
> + return;
> }
> }
>
> --
> 2.39.5
>
>
>
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 11/18] misc: storage-by-uuid: consider only first diskuuid match
2025-04-14 10:24 ` Marco Felsch
@ 2025-04-14 10:31 ` Ahmad Fatoum
0 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 10:31 UTC (permalink / raw)
To: Marco Felsch; +Cc: barebox
Hello Marco,
On 4/14/25 12:24, Marco Felsch wrote:
> On 25-04-14, Ahmad Fatoum wrote:
>> Multiple devices with the same disk UUID shouldn't happen and if it
>
> Do we need to print a warning to inform the user that two disks share
> the same disk-UUID?
If we do, we should do it a generic place like when disks are registered
the first time with a duplicate UUID and not at consumers like here.
Cheers,
Ahmad
>
> Regards,
> Marco
>
>> does, the existing code is not equipped to handle that.
>>
>> Change it, so only the first _disk_ is considered. diskuuid is in a
>> union with partuuid and that could lead to cdev partition being taken as
>> backend storage instead.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> drivers/misc/storage-by-uuid.c | 12 ++++++++----
>> 1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/misc/storage-by-uuid.c b/drivers/misc/storage-by-uuid.c
>> index 8b8fd901685e..7bb987dffbec 100644
>> --- a/drivers/misc/storage-by-uuid.c
>> +++ b/drivers/misc/storage-by-uuid.c
>> @@ -143,10 +143,14 @@ static void check_exist(struct sbu *sbu)
>> struct cdev *cdev;
>>
>> for_each_cdev(cdev) {
>> - if (!strcmp(cdev->diskuuid, sbu->uuid)) {
>> - dev_dbg(sbu->dev, "Found %s %s\n", cdev->name, cdev->diskuuid);
>> - storage_by_uuid_add_partitions(sbu, cdev);
>> - }
>> + if (cdev_is_partition(cdev))
>> + continue;
>> + if (strcmp(cdev->diskuuid, sbu->uuid))
>> + continue;
>> +
>> + dev_dbg(sbu->dev, "Found %s %s\n", cdev->name, cdev->diskuuid);
>> + storage_by_uuid_add_partitions(sbu, cdev);
>> + return;
>> }
>> }
>>
>> --
>> 2.39.5
>>
>>
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 12/18] misc: storage-by-uuid: prepare for generalizing to different aliases
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (10 preceding siblings ...)
2025-04-14 6:31 ` [PATCH 11/18] misc: storage-by-uuid: consider only first diskuuid match Ahmad Fatoum
@ 2025-04-14 6:31 ` Ahmad Fatoum
2025-04-14 10:31 ` Marco Felsch
2025-04-14 6:31 ` [PATCH 13/18] misc: storage-by-uuid: rename to storage-by-alias Ahmad Fatoum
` (7 subsequent siblings)
19 siblings, 1 reply; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Besides the probe function and the check_exist function, there is
nothing UUID specific about the code. As preparation for making it
reusable for arbitrary cdev aliases, rename it to storage-by-alias
instead as I couldn't figure out a proper backronym for sbu.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/misc/storage-by-uuid.c | 204 ++++++++++++++++++---------------
1 file changed, 114 insertions(+), 90 deletions(-)
diff --git a/drivers/misc/storage-by-uuid.c b/drivers/misc/storage-by-uuid.c
index 7bb987dffbec..2795ff93c07c 100644
--- a/drivers/misc/storage-by-uuid.c
+++ b/drivers/misc/storage-by-uuid.c
@@ -1,4 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * cdev aliases for existing block devices. In future, this should
+ * likely be replaced by a more generic device mapper support.
+ *
+ * Currently supported targets:
+ * - barebox,storage-by-uuid
+ * Useful for referencing existing EFI disks and their partition
+ * from device tree by offset
+ */
#include <common.h>
#include <init.h>
#include <io.h>
@@ -7,200 +16,215 @@
#include <envfs.h>
#include <fs.h>
-static LIST_HEAD(sbu_list);
+static LIST_HEAD(sba_list);
-struct sbu {
- char *uuid;
+struct sba {
+ char *alias;
struct device *dev;
struct cdev *rcdev;
struct cdev cdev;
struct list_head list;
};
-void storage_by_uuid_check_exist(struct cdev *cdev);
-
-static ssize_t sbu_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
+static ssize_t sba_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
{
- struct sbu *sbu = cdev->priv;
+ struct sba *sba = cdev->priv;
- return cdev_read(sbu->rcdev, buf, count, offset, flags);
+ return cdev_read(sba->rcdev, buf, count, offset, flags);
}
-static ssize_t sbu_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags)
+static ssize_t sba_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags)
{
- struct sbu *sbu = cdev->priv;
+ struct sba *sba = cdev->priv;
- return cdev_write(sbu->rcdev, buf, count, offset, flags);
+ return cdev_write(sba->rcdev, buf, count, offset, flags);
}
-static int sbu_ioctl(struct cdev *cdev, unsigned int request, void *buf)
+static int sba_ioctl(struct cdev *cdev, unsigned int request, void *buf)
{
- struct sbu *sbu = cdev->priv;
+ struct sba *sba = cdev->priv;
- return cdev_ioctl(sbu->rcdev, request, buf);
+ return cdev_ioctl(sba->rcdev, request, buf);
}
-static int sbu_open(struct cdev *cdev, unsigned long flags)
+static int sba_open(struct cdev *cdev, unsigned long flags)
{
- struct sbu *sbu = cdev->priv;
+ struct sba *sba = cdev->priv;
- return cdev_open(sbu->rcdev, flags);
+ return cdev_open(sba->rcdev, flags);
}
-static int sbu_close(struct cdev *cdev)
+static int sba_close(struct cdev *cdev)
{
- struct sbu *sbu = cdev->priv;
+ struct sba *sba = cdev->priv;
- cdev_close(sbu->rcdev);
+ cdev_close(sba->rcdev);
return 0;
}
-static int sbu_flush(struct cdev *cdev)
+static int sba_flush(struct cdev *cdev)
{
- struct sbu *sbu = cdev->priv;
+ struct sba *sba = cdev->priv;
- return cdev_flush(sbu->rcdev);
+ return cdev_flush(sba->rcdev);
}
-static int sbu_erase(struct cdev *cdev, loff_t count, loff_t offset)
+static int sba_erase(struct cdev *cdev, loff_t count, loff_t offset)
{
- struct sbu *sbu = cdev->priv;
+ struct sba *sba = cdev->priv;
- return cdev_erase(sbu->rcdev, count, offset);
+ return cdev_erase(sba->rcdev, count, offset);
}
-static int sbu_protect(struct cdev *cdev, size_t count, loff_t offset, int prot)
+static int sba_protect(struct cdev *cdev, size_t count, loff_t offset, int prot)
{
- struct sbu *sbu = cdev->priv;
+ struct sba *sba = cdev->priv;
- return cdev_protect(sbu->rcdev, count, offset, prot);
+ return cdev_protect(sba->rcdev, count, offset, prot);
}
-static int sbu_discard_range(struct cdev *cdev, loff_t count, loff_t offset)
+static int sba_discard_range(struct cdev *cdev, loff_t count, loff_t offset)
{
- struct sbu *sbu = cdev->priv;
+ struct sba *sba = cdev->priv;
- return cdev_discard_range(sbu->rcdev, count, offset);
+ return cdev_discard_range(sba->rcdev, count, offset);
}
-static int sbu_memmap(struct cdev *cdev, void **map, int flags)
+static int sba_memmap(struct cdev *cdev, void **map, int flags)
{
- struct sbu *sbu = cdev->priv;
+ struct sba *sba = cdev->priv;
- return cdev_memmap(sbu->rcdev, map, flags);
+ return cdev_memmap(sba->rcdev, map, flags);
}
-static int sbu_truncate(struct cdev *cdev, size_t size)
+static int sba_truncate(struct cdev *cdev, size_t size)
{
- struct sbu *sbu = cdev->priv;
+ struct sba *sba = cdev->priv;
- return cdev_truncate(sbu->rcdev, size);
+ return cdev_truncate(sba->rcdev, size);
}
-static struct cdev_operations sbu_ops = {
- .read = sbu_read,
- .write = sbu_write,
- .ioctl = sbu_ioctl,
- .open = sbu_open,
- .close = sbu_close,
- .flush = sbu_flush,
- .erase = sbu_erase,
- .protect = sbu_protect,
- .discard_range = sbu_discard_range,
- .memmap = sbu_memmap,
- .truncate = sbu_truncate,
+static struct cdev_operations sba_ops = {
+ .read = sba_read,
+ .write = sba_write,
+ .ioctl = sba_ioctl,
+ .open = sba_open,
+ .close = sba_close,
+ .flush = sba_flush,
+ .erase = sba_erase,
+ .protect = sba_protect,
+ .discard_range = sba_discard_range,
+ .memmap = sba_memmap,
+ .truncate = sba_truncate,
};
-static void storage_by_uuid_add_partitions(struct sbu *sbu, struct cdev *rcdev)
+static void sba_add_partitions(struct sba *sba, struct cdev *rcdev)
{
int ret;
- if (sbu->rcdev)
+ if (sba->rcdev)
return;
- sbu->rcdev = rcdev;
- sbu->cdev.name = sbu->uuid;
- sbu->cdev.size = rcdev->size;
- sbu->cdev.ops = &sbu_ops;
- sbu->cdev.dev = sbu->dev;
- sbu->cdev.priv = sbu;
+ sba->rcdev = rcdev;
+ sba->cdev.name = sba->alias;
+ sba->cdev.size = rcdev->size;
+ sba->cdev.ops = &sba_ops;
+ sba->cdev.dev = sba->dev;
+ sba->cdev.priv = sba;
if (rcdev->flags & DEVFS_WRITE_AUTOERASE)
- sbu->cdev.flags |= DEVFS_WRITE_AUTOERASE;
+ sba->cdev.flags |= DEVFS_WRITE_AUTOERASE;
- ret = devfs_create(&sbu->cdev);
+ ret = devfs_create(&sba->cdev);
if (ret) {
- dev_err(sbu->dev, "Failed to create cdev: %s\n", strerror(-ret));
+ dev_err(sba->dev, "Failed to create cdev: %s\n", strerror(-ret));
return;
}
- of_parse_partitions(&sbu->cdev, sbu->dev->of_node);
+ of_parse_partitions(&sba->cdev, sba->dev->of_node);
}
-static void check_exist(struct sbu *sbu)
+static void check_exist(struct sba *sba)
{
struct cdev *cdev;
for_each_cdev(cdev) {
if (cdev_is_partition(cdev))
continue;
- if (strcmp(cdev->diskuuid, sbu->uuid))
+ if (strcmp(cdev->diskuuid, sba->alias))
continue;
- dev_dbg(sbu->dev, "Found %s %s\n", cdev->name, cdev->diskuuid);
- storage_by_uuid_add_partitions(sbu, cdev);
+ dev_dbg(sba->dev, "Found %s %s\n", cdev->name, cdev->diskuuid);
+ sba_add_partitions(sba, cdev);
return;
}
}
-static int sbu_detect(struct device *dev)
+static int sba_detect(struct device *dev)
{
- struct sbu *sbu = dev->priv;
+ struct sba *sba = dev->priv;
dev_dbg(dev, "%s\n", __func__);
- check_exist(sbu);
+ check_exist(sba);
return 0;
}
-static int storage_by_uuid_probe(struct device *dev)
+static int storage_by_uuid_init(struct sba *sba)
{
- struct sbu *sbu;
- int ret;
const char *uuid;
+ int ret;
- sbu = xzalloc(sizeof(*sbu));
-
- ret = of_property_read_string(dev->of_node, "uuid", &uuid);
+ ret = of_property_read_string(sba->dev->of_node, "uuid", &uuid);
if (ret)
return ret;
- sbu->dev = dev;
- sbu->uuid = xstrdup(uuid);
-
- list_add_tail(&sbu->list, &sbu_list);
-
- check_exist(sbu);
- dev->priv = sbu;
- dev->detect = sbu_detect;
+ sba->alias = xstrdup(uuid);
return 0;
}
-static struct of_device_id storage_by_uuid_dt_ids[] = {
+static int sba_probe(struct device *dev)
+{
+ int (*init)(struct sba *);
+ struct sba *sba;
+ int ret;
+
+ sba = xzalloc(sizeof(*sba));
+ sba->dev = dev;
+
+ init = device_get_match_data(dev);
+ if (!init)
+ return -ENODEV;
+
+ ret = init(sba);
+ if (ret)
+ return ret;
+
+ list_add_tail(&sba->list, &sba_list);
+
+ check_exist(sba);
+ dev->priv = sba;
+ dev->detect = sba_detect;
+
+ return 0;
+}
+
+static struct of_device_id sba_dt_ids[] = {
{
.compatible = "barebox,storage-by-uuid",
+ .data = storage_by_uuid_init
}, {
/* sentinel */
}
};
-MODULE_DEVICE_TABLE(of, storage_by_uuid_dt_ids);
+MODULE_DEVICE_TABLE(of, sba_dt_ids);
-static struct driver storage_by_uuid_driver = {
- .name = "storage-by-uuid",
- .probe = storage_by_uuid_probe,
- .of_compatible = storage_by_uuid_dt_ids,
+static struct driver sba_driver = {
+ .name = "storage-by-alias",
+ .probe = sba_probe,
+ .of_compatible = sba_dt_ids,
};
-device_platform_driver(storage_by_uuid_driver);
+device_platform_driver(sba_driver);
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 12/18] misc: storage-by-uuid: prepare for generalizing to different aliases
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
0 siblings, 1 reply; 33+ messages in thread
From: Marco Felsch @ 2025-04-14 10:31 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On 25-04-14, Ahmad Fatoum wrote:
> Besides the probe function and the check_exist function, there is
> nothing UUID specific about the code. As preparation for making it
> reusable for arbitrary cdev aliases, rename it to storage-by-alias
> instead as I couldn't figure out a proper backronym for sbu.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/misc/storage-by-uuid.c | 204 ++++++++++++++++++---------------
> 1 file changed, 114 insertions(+), 90 deletions(-)
>
> diff --git a/drivers/misc/storage-by-uuid.c b/drivers/misc/storage-by-uuid.c
> index 7bb987dffbec..2795ff93c07c 100644
> --- a/drivers/misc/storage-by-uuid.c
> +++ b/drivers/misc/storage-by-uuid.c
> @@ -1,4 +1,13 @@
> // SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * cdev aliases for existing block devices. In future, this should
> + * likely be replaced by a more generic device mapper support.
> + *
> + * Currently supported targets:
> + * - barebox,storage-by-uuid
> + * Useful for referencing existing EFI disks and their partition
> + * from device tree by offset
> + */
> #include <common.h>
> #include <init.h>
> #include <io.h>
> @@ -7,200 +16,215 @@
> #include <envfs.h>
> #include <fs.h>
>
> -static LIST_HEAD(sbu_list);
> +static LIST_HEAD(sba_list);
>
> -struct sbu {
> - char *uuid;
> +struct sba {
> + char *alias;
> struct device *dev;
> struct cdev *rcdev;
> struct cdev cdev;
> struct list_head list;
> };
>
> -void storage_by_uuid_check_exist(struct cdev *cdev);
> -
> -static ssize_t sbu_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
> +static ssize_t sba_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
> {
> - struct sbu *sbu = cdev->priv;
> + struct sba *sba = cdev->priv;
>
> - return cdev_read(sbu->rcdev, buf, count, offset, flags);
> + return cdev_read(sba->rcdev, buf, count, offset, flags);
> }
>
> -static ssize_t sbu_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags)
> +static ssize_t sba_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags)
> {
> - struct sbu *sbu = cdev->priv;
> + struct sba *sba = cdev->priv;
>
> - return cdev_write(sbu->rcdev, buf, count, offset, flags);
> + return cdev_write(sba->rcdev, buf, count, offset, flags);
> }
>
> -static int sbu_ioctl(struct cdev *cdev, unsigned int request, void *buf)
> +static int sba_ioctl(struct cdev *cdev, unsigned int request, void *buf)
> {
> - struct sbu *sbu = cdev->priv;
> + struct sba *sba = cdev->priv;
>
> - return cdev_ioctl(sbu->rcdev, request, buf);
> + return cdev_ioctl(sba->rcdev, request, buf);
> }
>
> -static int sbu_open(struct cdev *cdev, unsigned long flags)
> +static int sba_open(struct cdev *cdev, unsigned long flags)
> {
> - struct sbu *sbu = cdev->priv;
> + struct sba *sba = cdev->priv;
>
> - return cdev_open(sbu->rcdev, flags);
> + return cdev_open(sba->rcdev, flags);
> }
>
> -static int sbu_close(struct cdev *cdev)
> +static int sba_close(struct cdev *cdev)
> {
> - struct sbu *sbu = cdev->priv;
> + struct sba *sba = cdev->priv;
>
> - cdev_close(sbu->rcdev);
> + cdev_close(sba->rcdev);
>
> return 0;
> }
>
> -static int sbu_flush(struct cdev *cdev)
> +static int sba_flush(struct cdev *cdev)
> {
> - struct sbu *sbu = cdev->priv;
> + struct sba *sba = cdev->priv;
>
> - return cdev_flush(sbu->rcdev);
> + return cdev_flush(sba->rcdev);
> }
>
> -static int sbu_erase(struct cdev *cdev, loff_t count, loff_t offset)
> +static int sba_erase(struct cdev *cdev, loff_t count, loff_t offset)
> {
> - struct sbu *sbu = cdev->priv;
> + struct sba *sba = cdev->priv;
>
> - return cdev_erase(sbu->rcdev, count, offset);
> + return cdev_erase(sba->rcdev, count, offset);
> }
>
> -static int sbu_protect(struct cdev *cdev, size_t count, loff_t offset, int prot)
> +static int sba_protect(struct cdev *cdev, size_t count, loff_t offset, int prot)
> {
> - struct sbu *sbu = cdev->priv;
> + struct sba *sba = cdev->priv;
>
> - return cdev_protect(sbu->rcdev, count, offset, prot);
> + return cdev_protect(sba->rcdev, count, offset, prot);
> }
>
> -static int sbu_discard_range(struct cdev *cdev, loff_t count, loff_t offset)
> +static int sba_discard_range(struct cdev *cdev, loff_t count, loff_t offset)
> {
> - struct sbu *sbu = cdev->priv;
> + struct sba *sba = cdev->priv;
>
> - return cdev_discard_range(sbu->rcdev, count, offset);
> + return cdev_discard_range(sba->rcdev, count, offset);
> }
>
> -static int sbu_memmap(struct cdev *cdev, void **map, int flags)
> +static int sba_memmap(struct cdev *cdev, void **map, int flags)
> {
> - struct sbu *sbu = cdev->priv;
> + struct sba *sba = cdev->priv;
>
> - return cdev_memmap(sbu->rcdev, map, flags);
> + return cdev_memmap(sba->rcdev, map, flags);
> }
>
> -static int sbu_truncate(struct cdev *cdev, size_t size)
> +static int sba_truncate(struct cdev *cdev, size_t size)
> {
> - struct sbu *sbu = cdev->priv;
> + struct sba *sba = cdev->priv;
>
> - return cdev_truncate(sbu->rcdev, size);
> + return cdev_truncate(sba->rcdev, size);
> }
>
> -static struct cdev_operations sbu_ops = {
> - .read = sbu_read,
> - .write = sbu_write,
> - .ioctl = sbu_ioctl,
> - .open = sbu_open,
> - .close = sbu_close,
> - .flush = sbu_flush,
> - .erase = sbu_erase,
> - .protect = sbu_protect,
> - .discard_range = sbu_discard_range,
> - .memmap = sbu_memmap,
> - .truncate = sbu_truncate,
> +static struct cdev_operations sba_ops = {
> + .read = sba_read,
> + .write = sba_write,
> + .ioctl = sba_ioctl,
> + .open = sba_open,
> + .close = sba_close,
> + .flush = sba_flush,
> + .erase = sba_erase,
> + .protect = sba_protect,
> + .discard_range = sba_discard_range,
> + .memmap = sba_memmap,
> + .truncate = sba_truncate,
> };
>
> -static void storage_by_uuid_add_partitions(struct sbu *sbu, struct cdev *rcdev)
> +static void sba_add_partitions(struct sba *sba, struct cdev *rcdev)
> {
> int ret;
>
> - if (sbu->rcdev)
> + if (sba->rcdev)
> return;
>
> - sbu->rcdev = rcdev;
> - sbu->cdev.name = sbu->uuid;
> - sbu->cdev.size = rcdev->size;
> - sbu->cdev.ops = &sbu_ops;
> - sbu->cdev.dev = sbu->dev;
> - sbu->cdev.priv = sbu;
> + sba->rcdev = rcdev;
> + sba->cdev.name = sba->alias;
> + sba->cdev.size = rcdev->size;
> + sba->cdev.ops = &sba_ops;
> + sba->cdev.dev = sba->dev;
> + sba->cdev.priv = sba;
>
> if (rcdev->flags & DEVFS_WRITE_AUTOERASE)
> - sbu->cdev.flags |= DEVFS_WRITE_AUTOERASE;
> + sba->cdev.flags |= DEVFS_WRITE_AUTOERASE;
>
> - ret = devfs_create(&sbu->cdev);
> + ret = devfs_create(&sba->cdev);
> if (ret) {
> - dev_err(sbu->dev, "Failed to create cdev: %s\n", strerror(-ret));
> + dev_err(sba->dev, "Failed to create cdev: %s\n", strerror(-ret));
> return;
> }
>
> - of_parse_partitions(&sbu->cdev, sbu->dev->of_node);
> + of_parse_partitions(&sba->cdev, sba->dev->of_node);
> }
>
> -static void check_exist(struct sbu *sbu)
> +static void check_exist(struct sba *sba)
> {
> struct cdev *cdev;
>
> for_each_cdev(cdev) {
> if (cdev_is_partition(cdev))
> continue;
> - if (strcmp(cdev->diskuuid, sbu->uuid))
> + if (strcmp(cdev->diskuuid, sba->alias))
> continue;
>
> - dev_dbg(sbu->dev, "Found %s %s\n", cdev->name, cdev->diskuuid);
> - storage_by_uuid_add_partitions(sbu, cdev);
> + dev_dbg(sba->dev, "Found %s %s\n", cdev->name, cdev->diskuuid);
> + sba_add_partitions(sba, cdev);
> return;
> }
> }
>
> -static int sbu_detect(struct device *dev)
> +static int sba_detect(struct device *dev)
> {
> - struct sbu *sbu = dev->priv;
> + struct sba *sba = dev->priv;
>
> dev_dbg(dev, "%s\n", __func__);
>
> - check_exist(sbu);
> + check_exist(sba);
>
> return 0;
> }
>
> -static int storage_by_uuid_probe(struct device *dev)
> +static int storage_by_uuid_init(struct sba *sba)
> {
> - struct sbu *sbu;
> - int ret;
> const char *uuid;
> + int ret;
>
> - sbu = xzalloc(sizeof(*sbu));
> -
> - ret = of_property_read_string(dev->of_node, "uuid", &uuid);
> + ret = of_property_read_string(sba->dev->of_node, "uuid", &uuid);
> if (ret)
> return ret;
>
> - sbu->dev = dev;
> - sbu->uuid = xstrdup(uuid);
> -
> - list_add_tail(&sbu->list, &sbu_list);
> -
> - check_exist(sbu);
> - dev->priv = sbu;
> - dev->detect = sbu_detect;
> + sba->alias = xstrdup(uuid);
>
> return 0;
> }
>
> -static struct of_device_id storage_by_uuid_dt_ids[] = {
> +static int sba_probe(struct device *dev)
> +{
> + int (*init)(struct sba *);
This does the job but a proper driver_data struct would be the more
aligned to all other drivers.
Regards,
Marco
> + struct sba *sba;
> + int ret;
> +
> + sba = xzalloc(sizeof(*sba));
> + sba->dev = dev;
> +
> + init = device_get_match_data(dev);
> + if (!init)
> + return -ENODEV;
> +
> + ret = init(sba);
> + if (ret)
> + return ret;
> +
> + list_add_tail(&sba->list, &sba_list);
> +
> + check_exist(sba);
> + dev->priv = sba;
> + dev->detect = sba_detect;
> +
> + return 0;
> +}
> +
> +static struct of_device_id sba_dt_ids[] = {
> {
> .compatible = "barebox,storage-by-uuid",
> + .data = storage_by_uuid_init
> }, {
> /* sentinel */
> }
> };
> -MODULE_DEVICE_TABLE(of, storage_by_uuid_dt_ids);
> +MODULE_DEVICE_TABLE(of, sba_dt_ids);
>
> -static struct driver storage_by_uuid_driver = {
> - .name = "storage-by-uuid",
> - .probe = storage_by_uuid_probe,
> - .of_compatible = storage_by_uuid_dt_ids,
> +static struct driver sba_driver = {
> + .name = "storage-by-alias",
> + .probe = sba_probe,
> + .of_compatible = sba_dt_ids,
> };
> -device_platform_driver(storage_by_uuid_driver);
> +device_platform_driver(sba_driver);
> --
> 2.39.5
>
>
>
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 12/18] misc: storage-by-uuid: prepare for generalizing to different aliases
2025-04-14 10:31 ` Marco Felsch
@ 2025-04-14 10:35 ` Ahmad Fatoum
0 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 10:35 UTC (permalink / raw)
To: Marco Felsch; +Cc: barebox
Hello Marco,
On 4/14/25 12:31, Marco Felsch wrote:
> On 25-04-14, Ahmad Fatoum wrote:
>> -static struct of_device_id storage_by_uuid_dt_ids[] = {
>> +static int sba_probe(struct device *dev)
>> +{
>> + int (*init)(struct sba *);
>
> This does the job but a proper driver_data struct would be the more
> aligned to all other drivers.
IMO if we ever need more than one member in driver_data, it should
probably be a separate driver and not a storage-by-alias.
Cheers,
Ahmad
>
> Regards,
> Marco
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 13/18] misc: storage-by-uuid: rename to storage-by-alias
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (11 preceding siblings ...)
2025-04-14 6:31 ` [PATCH 12/18] misc: storage-by-uuid: prepare for generalizing to different aliases Ahmad Fatoum
@ 2025-04-14 6:31 ` Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 14/18] misc: storage-by-alias: switch over to using cdev aliases Ahmad Fatoum
` (6 subsequent siblings)
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Now that the symbols in the file have been renamed, rename the file
itself too. This was split off as not to confuse git rename detection.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/misc/Kconfig | 16 +++++++++++-----
drivers/misc/Makefile | 2 +-
.../{storage-by-uuid.c => storage-by-alias.c} | 0
3 files changed, 12 insertions(+), 6 deletions(-)
rename drivers/misc/{storage-by-uuid.c => storage-by-alias.c} (100%)
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 40482f8b88a7..73814f36bf9c 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -51,13 +51,19 @@ config STARFIVE_PWRSEQ
be accessed over /dev/mem or used from kernels which still depend
on bootloader for initialization.
-config STORAGE_BY_UUID
- bool "storage by UUID"
+config STORAGE_BY_ALIAS
+ bool "storage by alias"
depends on OFDEVICE
help
- This adds a driver which matches to a "barebox,storage-by-uuid"
- compatible node. The driver looks for a storage device matching the
- given UUID and when found registers a new cdev for the device.
+ This adds a driver which matches device tree nodes corresponding
+ to a barebox cdev aliases.
+
+ Following compatibles are supported:
+
+ - "barebox,storage-by-uuid"
+
+ Look for a storage device matching the given DISKUUID and when found
+ registers a new cdev for the device.
This driver solved a very specific problem. On EFI the storage devices
are not connected to any device tree node. barebox-state however expects
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 871af85d5920..c4b61de7b8b5 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -10,4 +10,4 @@ obj-$(CONFIG_DEV_MEM) += mem.o
obj-$(CONFIG_DEV_PORT) += port.o
obj-$(CONFIG_UBOOTVAR) += ubootvar.o
obj-$(CONFIG_STARFIVE_PWRSEQ) += starfive-pwrseq.o
-obj-$(CONFIG_STORAGE_BY_UUID) += storage-by-uuid.o
+obj-$(CONFIG_STORAGE_BY_ALIAS) += storage-by-alias.o
diff --git a/drivers/misc/storage-by-uuid.c b/drivers/misc/storage-by-alias.c
similarity index 100%
rename from drivers/misc/storage-by-uuid.c
rename to drivers/misc/storage-by-alias.c
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 14/18] misc: storage-by-alias: switch over to using cdev aliases
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (12 preceding siblings ...)
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
2025-04-14 6:31 ` [PATCH 15/18] misc: storage-by-alias: add support barebox,bootsource Ahmad Fatoum
` (5 subsequent siblings)
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 15/18] misc: storage-by-alias: add support barebox,bootsource
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (13 preceding siblings ...)
2025-04-14 6:31 ` [PATCH 14/18] misc: storage-by-alias: switch over to using cdev aliases Ahmad Fatoum
@ 2025-04-14 6:31 ` Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 16/18] misc: storage-by-alias: register as link to main cdev Ahmad Fatoum
` (4 subsequent siblings)
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
This is useful as state backend that need not hardcode a specific device
at compile time and instead uses the bootsource device at runtime.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/misc/Kconfig | 5 +++++
drivers/misc/storage-by-alias.c | 12 ++++++++++++
2 files changed, 17 insertions(+)
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 73814f36bf9c..e235646ee551 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -60,6 +60,11 @@ config STORAGE_BY_ALIAS
Following compatibles are supported:
+ - "barebox,bootsource"
+
+ Alias the device barebox was booted from. This is useful to have
+ barebox-state come from the same device as barebox itself.
+
- "barebox,storage-by-uuid"
Look for a storage device matching the given DISKUUID and when found
diff --git a/drivers/misc/storage-by-alias.c b/drivers/misc/storage-by-alias.c
index 0bf0059ad41c..ece5929d60ce 100644
--- a/drivers/misc/storage-by-alias.c
+++ b/drivers/misc/storage-by-alias.c
@@ -7,6 +7,9 @@
* - barebox,storage-by-uuid
* Useful for referencing existing EFI disks and their partition
* from device tree by offset
+ * - barebox,bootsource
+ * Reference the boot medium indicated by barebox $bootsource
+ * and $bootsource_instance variable
*/
#include <common.h>
#include <init.h>
@@ -179,6 +182,12 @@ static int storage_by_uuid_init(struct sba *sba)
return 0;
}
+static int storage_by_bootsource_init(struct sba *sba)
+{
+ sba->alias = xasprintf("bootsource");
+ return 0;
+}
+
static int sba_probe(struct device *dev)
{
int (*init)(struct sba *);
@@ -209,6 +218,9 @@ static struct of_device_id sba_dt_ids[] = {
{
.compatible = "barebox,storage-by-uuid",
.data = storage_by_uuid_init
+ }, {
+ .compatible = "barebox,bootsource",
+ .data = storage_by_bootsource_init
}, {
/* sentinel */
}
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 16/18] misc: storage-by-alias: register as link to main cdev
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (14 preceding siblings ...)
2025-04-14 6:31 ` [PATCH 15/18] misc: storage-by-alias: add support barebox,bootsource Ahmad Fatoum
@ 2025-04-14 6:31 ` Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 17/18] cdev: constify cdev_readlink argument Ahmad Fatoum
` (3 subsequent siblings)
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
By establishing the link, we ensure that the storage-by-alias device is
freed alongside the original device and also that resolving the parent
device will automatically point at the original device.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/misc/storage-by-alias.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/misc/storage-by-alias.c b/drivers/misc/storage-by-alias.c
index ece5929d60ce..4a0513236743 100644
--- a/drivers/misc/storage-by-alias.c
+++ b/drivers/misc/storage-by-alias.c
@@ -133,6 +133,7 @@ static int sba_add_partitions(struct cdev *rcdev, void *data)
return 0;
sba->rcdev = rcdev;
+ sba->cdev.link = rcdev;
sba->cdev.name = sba->alias;
sba->cdev.size = rcdev->size;
sba->cdev.ops = &sba_ops;
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 17/18] cdev: constify cdev_readlink argument
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (15 preceding siblings ...)
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 ` Ahmad Fatoum
2025-04-14 6:31 ` [PATCH 18/18] cdev: follow links in cdev_find_child_by_gpt_typeuuid Ahmad Fatoum
` (2 subsequent siblings)
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
For use in functions that accept a const cdev, have cdev_readlink take a
const cdev as well.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/devfs-core.c | 4 ++--
include/driver.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index eb6691b5252b..d1e4e1f0f6b5 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -50,7 +50,7 @@ int devfs_partition_complete(struct string_list *sl, char *instr)
}
#endif
-struct cdev *cdev_readlink(struct cdev *cdev)
+struct cdev *cdev_readlink(const struct cdev *cdev)
{
if (!cdev)
return NULL;
@@ -61,7 +61,7 @@ struct cdev *cdev_readlink(struct cdev *cdev)
/* links to links are not allowed */
BUG_ON(cdev->link);
- return cdev;
+ return (void *)cdev;
}
struct cdev *lcdev_by_name(const char *filename)
diff --git a/include/driver.h b/include/driver.h
index ca002c5164c2..d73c33a42a81 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -506,7 +506,7 @@ int cdev_find_free_index(const char *);
struct cdev *cdev_find_partition(struct cdev *cdevm, const char *name);
struct cdev *device_find_partition(struct device *dev, const char *name);
struct cdev *lcdev_by_name(const char *filename);
-struct cdev *cdev_readlink(struct cdev *cdev);
+struct cdev *cdev_readlink(const struct cdev *cdev);
struct cdev *cdev_by_device_node(struct device_node *node);
struct cdev *cdev_by_partuuid(const char *partuuid);
struct cdev *cdev_by_diskuuid(const char *partuuid);
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 18/18] cdev: follow links in cdev_find_child_by_gpt_typeuuid
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (16 preceding siblings ...)
2025-04-14 6:31 ` [PATCH 17/18] cdev: constify cdev_readlink argument Ahmad Fatoum
@ 2025-04-14 6:31 ` 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
19 siblings, 0 replies; 33+ messages in thread
From: Ahmad Fatoum @ 2025-04-14 6:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Now that we can have a link pointing from the parent, follow it to make
cdev_find_child_by_gpt_typeuuid resolves to the correct partition.
This doesn't affect state-by-alias, because __of_cdev_find already calls
cdev_readlink, but that's an implementation detail that we shouldn't
depend on in cdev_find_child_by_gpt_typeuuid.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/devfs-core.c | 3 +++
include/block.h | 1 +
2 files changed, 4 insertions(+)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index d1e4e1f0f6b5..8f504abdfd8d 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -133,6 +133,9 @@ cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, const guid_t *typeuuid)
{
struct cdev *partcdev;
+ /* Follow links to support storage-by-alias */
+ cdev = cdev_readlink(cdev);
+
if (!cdev_is_gpt_partitioned(cdev))
return ERR_PTR(-EINVAL);
diff --git a/include/block.h b/include/block.h
index 0ca6c6aff6e9..5ce3eb7d7838 100644
--- a/include/block.h
+++ b/include/block.h
@@ -112,6 +112,7 @@ static inline bool cdev_is_block_partition(const struct cdev *cdev)
static inline bool cdev_is_block_disk(const struct cdev *cdev)
{
+ cdev = cdev_readlink(cdev);
return cdev_is_block_device(cdev) && !cdev_is_partition(cdev);
}
--
2.39.5
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 00/18] boot: improve cdev alias and blspec support
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (17 preceding siblings ...)
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 ` Marco Felsch
2025-04-14 13:25 ` Sascha Hauer
19 siblings, 0 replies; 33+ messages in thread
From: Marco Felsch @ 2025-04-14 10:51 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
Hi Ahmad,
On 25-04-14, Ahmad Fatoum wrote:
> Building on past top of past bootscan and cdev alias infrastructure in
> next, enable the following:
>
> - Favoring entries in GPT XBOOTLDR partition and EFI system
> partitions, like we already do for MBR XBOOTLDR partition
>
> - Allow state backend and other DT bindings to point at a
> barebox,bootsource node to allow same state DT description
> to work across different boot media
thanks for your work :) The series LGTM with minor nits.
Reviewed-by: Marco Felsch <m.felsch@pengutronix.de>
Regards,
Marco
>
> Ahmad Fatoum (18):
> cdev: make cdev_find_child_by_gpt_typeuuid external
> cdev: constify cdev_find_child_by_gpt_typeuuid's guid_t pointer
> argument
> partition: efi: respect DPS_TYPE_FLAG_NO_AUTO flag
> blspec: iterate over all XBOOTLDR partitions
> blspec: support GPT XBOOTLDR partition
> blspec: collect bootloader spec entries from ESP
> cdev: alias: add support for partition links
> cdev: do not dereference partname for non-partitions
> cdev: use common cdev_free helper internally
> cdev: implement devfs_create_link in terms of devfs_create
> misc: storage-by-uuid: consider only first diskuuid match
> misc: storage-by-uuid: prepare for generalizing to different aliases
> misc: storage-by-uuid: rename to storage-by-alias
> misc: storage-by-alias: switch over to using cdev aliases
> misc: storage-by-alias: add support barebox,bootsource
> misc: storage-by-alias: register as link to main cdev
> cdev: constify cdev_readlink argument
> cdev: follow links in cdev_find_child_by_gpt_typeuuid
>
> commands/boot.c | 1 +
> common/blspec.c | 75 +++++++---
> common/bootscan.c | 11 +-
> common/cdev-alias.c | 53 ++++---
> drivers/misc/Kconfig | 21 ++-
> drivers/misc/Makefile | 2 +-
> drivers/misc/storage-by-alias.c | 236 ++++++++++++++++++++++++++++++++
> drivers/misc/storage-by-uuid.c | 202 ---------------------------
> fs/devfs-core.c | 104 ++++++++++----
> include/block.h | 1 +
> include/bootscan.h | 5 +-
> include/driver.h | 20 +--
> 12 files changed, 440 insertions(+), 291 deletions(-)
> create mode 100644 drivers/misc/storage-by-alias.c
> delete mode 100644 drivers/misc/storage-by-uuid.c
>
> --
> 2.39.5
>
>
>
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 00/18] boot: improve cdev alias and blspec support
2025-04-14 6:31 [PATCH 00/18] boot: improve cdev alias and blspec support Ahmad Fatoum
` (18 preceding siblings ...)
2025-04-14 10:51 ` [PATCH 00/18] boot: improve cdev alias and blspec support Marco Felsch
@ 2025-04-14 13:25 ` Sascha Hauer
19 siblings, 0 replies; 33+ messages in thread
From: Sascha Hauer @ 2025-04-14 13:25 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Mon, 14 Apr 2025 08:31:34 +0200, Ahmad Fatoum wrote:
> Building on past top of past bootscan and cdev alias infrastructure in
> next, enable the following:
>
> - Favoring entries in GPT XBOOTLDR partition and EFI system
> partitions, like we already do for MBR XBOOTLDR partition
>
> - Allow state backend and other DT bindings to point at a
> barebox,bootsource node to allow same state DT description
> to work across different boot media
>
> [...]
Applied, thanks!
[01/18] cdev: make cdev_find_child_by_gpt_typeuuid external
https://git.pengutronix.de/cgit/barebox/commit/?id=a007ea23536f (link may not be stable)
[02/18] cdev: constify cdev_find_child_by_gpt_typeuuid's guid_t pointer argument
https://git.pengutronix.de/cgit/barebox/commit/?id=3135334dcf4b (link may not be stable)
[03/18] partition: efi: respect DPS_TYPE_FLAG_NO_AUTO flag
https://git.pengutronix.de/cgit/barebox/commit/?id=37bc13eddaea (link may not be stable)
[04/18] blspec: iterate over all XBOOTLDR partitions
https://git.pengutronix.de/cgit/barebox/commit/?id=06adbb825081 (link may not be stable)
[05/18] blspec: support GPT XBOOTLDR partition
https://git.pengutronix.de/cgit/barebox/commit/?id=396f3e6b4119 (link may not be stable)
[06/18] blspec: collect bootloader spec entries from ESP
https://git.pengutronix.de/cgit/barebox/commit/?id=6d5595a6a3c5 (link may not be stable)
[07/18] cdev: alias: add support for partition links
https://git.pengutronix.de/cgit/barebox/commit/?id=7936038edadc (link may not be stable)
[08/18] cdev: do not dereference partname for non-partitions
https://git.pengutronix.de/cgit/barebox/commit/?id=1bbc03a7faa1 (link may not be stable)
[09/18] cdev: use common cdev_free helper internally
https://git.pengutronix.de/cgit/barebox/commit/?id=cf3f7e562d18 (link may not be stable)
[10/18] cdev: implement devfs_create_link in terms of devfs_create
https://git.pengutronix.de/cgit/barebox/commit/?id=db79238d94b8 (link may not be stable)
[11/18] misc: storage-by-uuid: consider only first diskuuid match
https://git.pengutronix.de/cgit/barebox/commit/?id=838211091e0b (link may not be stable)
[12/18] misc: storage-by-uuid: prepare for generalizing to different aliases
https://git.pengutronix.de/cgit/barebox/commit/?id=b82ba2a5d097 (link may not be stable)
[13/18] misc: storage-by-uuid: rename to storage-by-alias
https://git.pengutronix.de/cgit/barebox/commit/?id=e957f8c82f7e (link may not be stable)
[14/18] misc: storage-by-alias: switch over to using cdev aliases
https://git.pengutronix.de/cgit/barebox/commit/?id=b6d3b15b25db (link may not be stable)
[15/18] misc: storage-by-alias: add support barebox,bootsource
https://git.pengutronix.de/cgit/barebox/commit/?id=f22f557b8334 (link may not be stable)
[16/18] misc: storage-by-alias: register as link to main cdev
https://git.pengutronix.de/cgit/barebox/commit/?id=4c496eb9bc2c (link may not be stable)
[17/18] cdev: constify cdev_readlink argument
https://git.pengutronix.de/cgit/barebox/commit/?id=f5e1996adc0c (link may not be stable)
[18/18] cdev: follow links in cdev_find_child_by_gpt_typeuuid
https://git.pengutronix.de/cgit/barebox/commit/?id=f2a44cdffc32 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 33+ messages in thread