* [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse
@ 2022-08-15 11:48 Ahmad Fatoum
2022-08-15 11:48 ` [PATCH 2/2] common: bootm: reuse cdev_get_linux_rootarg() Ahmad Fatoum
2022-08-16 8:26 ` [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-08-15 11:48 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We've the root=PARTUUID=%s generation at two places: Once to populate
fsdev->linux_rootarg and once to handle struct bootm_data::root_dev.
In preparation for dropping the duplicate out-of-sync code in the bootm
code, export the originl fs/fs.c code as cdev_get_linux_rootarg().
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 50 +++++++++++++++++++++++++++++++++++---------------
include/fs.h | 1 +
2 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index bd6f144742ac..620cd6597a63 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2876,12 +2876,23 @@ int popd(char *oldcwd)
return ret;
}
-static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
+static bool cdev_partname_equal(const struct cdev *a,
+ const struct cdev *b)
{
- struct cdev *cdevm, *cdev;
+ return a->partname && b->partname &&
+ !strcmp(a->partname, b->partname);
+}
+
+static char *get_linux_mmcblkdev(const struct cdev *root_cdev)
+{
+ struct cdev *cdevm = root_cdev->master, *cdev;
int id, partnum;
- cdevm = fsdev->cdev->master;
+ if (!IS_ENABLED(CONFIG_MMCBLKDEV_ROOTARG))
+ return NULL;
+ if (!cdevm || !cdev_is_mci_main_part_dev(cdevm))
+ return NULL;
+
id = of_alias_get_id(cdevm->device_node, "mmc");
if (id < 0)
return NULL;
@@ -2894,8 +2905,7 @@ static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
* in the partitions list so we need to count it instead of
* skipping it.
*/
- if (cdev->partname &&
- !strcmp(cdev->partname, fsdev->cdev->partname))
+ if (cdev_partname_equal(root_cdev, cdev))
return basprintf("root=/dev/mmcblk%dp%d", id, partnum);
partnum++;
}
@@ -2903,6 +2913,23 @@ static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
return NULL;
}
+char *cdev_get_linux_rootarg(const struct cdev *cdev)
+{
+ char *str;
+
+ if (!cdev)
+ return NULL;
+
+ str = get_linux_mmcblkdev(cdev);
+ if (str)
+ return str;
+
+ if (cdev->uuid[0] != 0)
+ return basprintf("root=PARTUUID=%s", cdev->uuid);
+
+ return NULL;
+}
+
/*
* Mount a device to a directory.
* We do this by registering a new device on which the filesystem
@@ -2991,17 +3018,10 @@ int mount(const char *device, const char *fsname, const char *pathname,
fsdev->vfsmount.mnt_root = fsdev->sb.s_root;
- if (!fsdev->linux_rootarg && fsdev->cdev) {
- char *str = NULL;
-
- if (IS_ENABLED(CONFIG_MMCBLKDEV_ROOTARG) &&
- fsdev->cdev->master &&
- cdev_is_mci_main_part_dev(fsdev->cdev->master))
- str = get_linux_mmcblkdev(fsdev);
-
- if (!str && fsdev->cdev->uuid[0] != 0)
- str = basprintf("root=PARTUUID=%s", fsdev->cdev->uuid);
+ if (!fsdev->linux_rootarg) {
+ char *str;
+ str = cdev_get_linux_rootarg(fsdev->cdev);
if (str)
fsdev_set_linux_rootarg(fsdev, str);
}
diff --git a/include/fs.h b/include/fs.h
index cd5eb571e08e..894cae3e4c2f 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -168,6 +168,7 @@ void mount_all(void);
void fsdev_set_linux_rootarg(struct fs_device_d *fsdev, const char *str);
char *path_get_linux_rootarg(const char *path);
+char *cdev_get_linux_rootarg(const struct cdev *cdev);
static inline const char *devpath_to_name(const char *devpath)
{
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] common: bootm: reuse cdev_get_linux_rootarg()
2022-08-15 11:48 [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse Ahmad Fatoum
@ 2022-08-15 11:48 ` Ahmad Fatoum
2022-08-16 8:26 ` [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-08-15 11:48 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
CONFIG_MMCBLKDEV_ROOTARG=y so far had no effect on the root= option
generated by $global.bootm.root_dev. Have the bootm code reuse
cdev_get_linux_rootarg(), so it behaves the same as with boot from
file system.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/bootm.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/common/bootm.c b/common/bootm.c
index c0f7bca6ce86..2f02c156e56f 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -710,9 +710,8 @@ int bootm_boot(struct bootm_data *bootm_data)
const char *root_dev_name = devpath_to_name(bootm_data->root_dev);
const struct cdev *root_cdev = cdev_by_name(root_dev_name);
- if (root_cdev && root_cdev->uuid[0] != 0) {
- rootarg = basprintf("root=PARTUUID=%s", root_cdev->uuid);
- } else {
+ rootarg = cdev_get_linux_rootarg(root_cdev);
+ if (!rootarg) {
rootarg = ERR_PTR(-EINVAL);
if (!root_cdev)
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse
2022-08-15 11:48 [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse Ahmad Fatoum
2022-08-15 11:48 ` [PATCH 2/2] common: bootm: reuse cdev_get_linux_rootarg() Ahmad Fatoum
@ 2022-08-16 8:26 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2022-08-16 8:26 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Aug 15, 2022 at 01:48:34PM +0200, Ahmad Fatoum wrote:
> We've the root=PARTUUID=%s generation at two places: Once to populate
> fsdev->linux_rootarg and once to handle struct bootm_data::root_dev.
>
> In preparation for dropping the duplicate out-of-sync code in the bootm
> code, export the originl fs/fs.c code as cdev_get_linux_rootarg().
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> fs/fs.c | 50 +++++++++++++++++++++++++++++++++++---------------
> include/fs.h | 1 +
> 2 files changed, 36 insertions(+), 15 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/fs/fs.c b/fs/fs.c
> index bd6f144742ac..620cd6597a63 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -2876,12 +2876,23 @@ int popd(char *oldcwd)
> return ret;
> }
>
> -static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
> +static bool cdev_partname_equal(const struct cdev *a,
> + const struct cdev *b)
> {
> - struct cdev *cdevm, *cdev;
> + return a->partname && b->partname &&
> + !strcmp(a->partname, b->partname);
> +}
> +
> +static char *get_linux_mmcblkdev(const struct cdev *root_cdev)
> +{
> + struct cdev *cdevm = root_cdev->master, *cdev;
> int id, partnum;
>
> - cdevm = fsdev->cdev->master;
> + if (!IS_ENABLED(CONFIG_MMCBLKDEV_ROOTARG))
> + return NULL;
> + if (!cdevm || !cdev_is_mci_main_part_dev(cdevm))
> + return NULL;
> +
> id = of_alias_get_id(cdevm->device_node, "mmc");
> if (id < 0)
> return NULL;
> @@ -2894,8 +2905,7 @@ static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
> * in the partitions list so we need to count it instead of
> * skipping it.
> */
> - if (cdev->partname &&
> - !strcmp(cdev->partname, fsdev->cdev->partname))
> + if (cdev_partname_equal(root_cdev, cdev))
> return basprintf("root=/dev/mmcblk%dp%d", id, partnum);
> partnum++;
> }
> @@ -2903,6 +2913,23 @@ static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
> return NULL;
> }
>
> +char *cdev_get_linux_rootarg(const struct cdev *cdev)
> +{
> + char *str;
> +
> + if (!cdev)
> + return NULL;
> +
> + str = get_linux_mmcblkdev(cdev);
> + if (str)
> + return str;
> +
> + if (cdev->uuid[0] != 0)
> + return basprintf("root=PARTUUID=%s", cdev->uuid);
> +
> + return NULL;
> +}
> +
> /*
> * Mount a device to a directory.
> * We do this by registering a new device on which the filesystem
> @@ -2991,17 +3018,10 @@ int mount(const char *device, const char *fsname, const char *pathname,
>
> fsdev->vfsmount.mnt_root = fsdev->sb.s_root;
>
> - if (!fsdev->linux_rootarg && fsdev->cdev) {
> - char *str = NULL;
> -
> - if (IS_ENABLED(CONFIG_MMCBLKDEV_ROOTARG) &&
> - fsdev->cdev->master &&
> - cdev_is_mci_main_part_dev(fsdev->cdev->master))
> - str = get_linux_mmcblkdev(fsdev);
> -
> - if (!str && fsdev->cdev->uuid[0] != 0)
> - str = basprintf("root=PARTUUID=%s", fsdev->cdev->uuid);
> + if (!fsdev->linux_rootarg) {
> + char *str;
>
> + str = cdev_get_linux_rootarg(fsdev->cdev);
> if (str)
> fsdev_set_linux_rootarg(fsdev, str);
> }
> diff --git a/include/fs.h b/include/fs.h
> index cd5eb571e08e..894cae3e4c2f 100644
> --- a/include/fs.h
> +++ b/include/fs.h
> @@ -168,6 +168,7 @@ void mount_all(void);
>
> void fsdev_set_linux_rootarg(struct fs_device_d *fsdev, const char *str);
> char *path_get_linux_rootarg(const char *path);
> +char *cdev_get_linux_rootarg(const struct cdev *cdev);
>
> static inline const char *devpath_to_name(const char *devpath)
> {
> --
> 2.30.2
>
>
>
--
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] 3+ messages in thread
end of thread, other threads:[~2022-08-16 8:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15 11:48 [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse Ahmad Fatoum
2022-08-15 11:48 ` [PATCH 2/2] common: bootm: reuse cdev_get_linux_rootarg() Ahmad Fatoum
2022-08-16 8:26 ` [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox