mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] fs: export cdev_get_linux_rootarg() for reuse
Date: Tue, 16 Aug 2022 10:26:42 +0200	[thread overview]
Message-ID: <20220816082642.GJ17485@pengutronix.de> (raw)
In-Reply-To: <20220815114835.2277946-1-a.fatoum@pengutronix.de>

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 |



      parent reply	other threads:[~2022-08-16  8:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220816082642.GJ17485@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox