U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mattijs Korpershoek <mkorpershoek@kernel.org>
To: Simon Glass <sjg@chromium.org>, u-boot@lists.denx.de
Cc: Simon Glass <sjg@chromium.org>,
	Jaehoon Chung <jh80.chung@samsung.com>,
	Marek Vasut <marex@denx.de>, Peng Fan <peng.fan@nxp.com>,
	Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH v2 10/11] sandbox: Find disk images in the persistent-data directory
Date: Mon, 08 Jun 2026 10:41:46 +0200	[thread overview]
Message-ID: <87ldcpxw39.fsf@kernel.org> (raw)
In-Reply-To: <20260523085455.750591-11-sjg@chromium.org>

Hi Simon,

Thank you for the patch.

On Sat, May 23, 2026 at 02:54, Simon Glass <sjg@chromium.org> wrote:

> The sandbox mmc, scsi and usb-flash drivers open their backing files
> from plat->pathname as given. Test images are about to move out of
> the source tree into the persistent-data directory, so the drivers
> need to find them there.
>
> Try the persistent-data directory first via os_persistent_file() and
> fall back to the original pathname when the lookup fails, so absolute
> paths and files already in the current directory keep working.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> (no changes since v1)
>
>  drivers/mmc/sandbox_mmc.c        | 13 +++++++++++--
>  drivers/scsi/sandbox_scsi.c      | 15 ++++++++++++---
>  drivers/usb/emul/sandbox_flash.c | 14 +++++++++++---
>  3 files changed, 34 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/mmc/sandbox_mmc.c b/drivers/mmc/sandbox_mmc.c
> index a24520f2e78..42a80c7499c 100644
> --- a/drivers/mmc/sandbox_mmc.c
> +++ b/drivers/mmc/sandbox_mmc.c
> @@ -170,11 +170,20 @@ static int sandbox_mmc_probe(struct udevice *dev)
>  	int ret;
>  
>  	if (plat->fname) {
> -		ret = os_map_file(plat->fname, OS_O_RDWR | OS_O_CREAT,
> +		const char *fname = plat->fname;
> +		char buf[256];

Why 256? Can't we use a define/constant for this?
I see that fname ends up coming from ofnode_read_string() but it's
unclear to me if there is a build-time constant size we could use instead.

> +
> +		/*
> +		 * Try persistent data directory first, then fall back to the
> +		 * filename as given (for absolute paths or current directory)
> +		 */
> +		if (!os_persistent_file(buf, sizeof(buf), plat->fname))
> +			fname = buf;
> +		ret = os_map_file(fname, OS_O_RDWR | OS_O_CREAT,
>  				  (void **)&priv->buf, &priv->size);
>  		if (ret) {
>  			log_err("%s: Unable to map file '%s'\n", dev->name,
> -				plat->fname);
> +				fname);
>  			return ret;
>  		}
>  		priv->csize = priv->size / SIZE_MULTIPLE - 1;
> diff --git a/drivers/scsi/sandbox_scsi.c b/drivers/scsi/sandbox_scsi.c
> index 544a0247083..97afeddc2e9 100644
> --- a/drivers/scsi/sandbox_scsi.c
> +++ b/drivers/scsi/sandbox_scsi.c
> @@ -104,9 +104,18 @@ static int sandbox_scsi_probe(struct udevice *dev)
>  	info->block_size = SANDBOX_SCSI_BLOCK_LEN;
>  
>  	if (priv->pathname) {
> -		priv->fd = os_open(priv->pathname, OS_O_RDONLY);
> -		if (priv->fd != -1) {
> -			ret = os_get_filesize(priv->pathname, &info->file_size);
> +		const char *pathname = priv->pathname;
> +		char buf[256];
> +
> +		/*
> +		 * Try persistent data directory first, then fall back to the
> +		 * pathname as given (for absolute paths or current directory)
> +		 */
> +		if (!os_persistent_file(buf, sizeof(buf), priv->pathname))
> +			pathname = buf;
> +		priv->fd = os_open(pathname, OS_O_RDONLY);
> +		if (priv->fd >= 0) {

I've noticed that the error handling gets updated here (from != -1 to >=
0).
Any reason for doing that? If so, can you please mention it in
the commit message?

os_open()'s docstring seems to mention:

 * Return:	file descriptor, or -1 on error

> +			ret = os_get_filesize(pathname, &info->file_size);
>  			if (ret)
>  				return log_msg_ret("sz", ret);
>  		}
> diff --git a/drivers/usb/emul/sandbox_flash.c b/drivers/usb/emul/sandbox_flash.c
> index b5176bb30ce..82aa7062865 100644
> --- a/drivers/usb/emul/sandbox_flash.c
> +++ b/drivers/usb/emul/sandbox_flash.c
> @@ -339,11 +339,19 @@ static int sandbox_flash_probe(struct udevice *dev)
>  	struct sandbox_flash_plat *plat = dev_get_plat(dev);
>  	struct sandbox_flash_priv *priv = dev_get_priv(dev);
>  	struct scsi_emul_info *info = &priv->eminfo;
> +	const char *pathname = plat->pathname;
> +	char buf[256];
>  	int ret;
>  
> -	priv->fd = os_open(plat->pathname, OS_O_RDWR);
> -	if (priv->fd != -1) {
> -		ret = os_get_filesize(plat->pathname, &info->file_size);
> +	/*
> +	 * Try persistent data directory first, then fall back to the
> +	 * pathname as given (for absolute paths or current directory)
> +	 */
> +	if (!os_persistent_file(buf, sizeof(buf), plat->pathname))
> +		pathname = buf;
> +	priv->fd = os_open(pathname, OS_O_RDWR);
> +	if (priv->fd >= 0) {

Same here.

> +		ret = os_get_filesize(pathname, &info->file_size);
>  		if (ret)
>  			return log_msg_ret("sz", ret);
>  	}
> -- 
> 2.43.0

  reply	other threads:[~2026-06-08  8:41 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-23  8:54 [PATCH v2 00/11] Move test/py image creation into separate modules Simon Glass
2026-05-23  8:54 ` [PATCH v2 01/11] test: Create a common file for image utilities Simon Glass
2026-06-08  8:04   ` Mattijs Korpershoek
2026-05-23  8:54 ` [PATCH v2 02/11] test: Move extlinux image-creation to its own file Simon Glass
2026-06-08  8:17   ` Mattijs Korpershoek
2026-05-23  8:54 ` [PATCH v2 03/11] test: Move script " Simon Glass
2026-06-08  8:13   ` Mattijs Korpershoek
2026-05-23  8:54 ` [PATCH v2 04/11] test: Move ChromeOS " Simon Glass
2026-06-08  8:19   ` Mattijs Korpershoek
2026-05-23  8:54 ` [PATCH v2 05/11] test: Move Android " Simon Glass
2026-06-08  8:21   ` Mattijs Korpershoek
2026-05-23  8:54 ` [PATCH v2 06/11] test: Move EFI " Simon Glass
2026-06-08  8:22   ` Mattijs Korpershoek
2026-05-23  8:54 ` [PATCH v2 07/11] test: Move the configuration-editor setup " Simon Glass
2026-06-08  8:23   ` Mattijs Korpershoek
2026-05-23  8:54 ` [PATCH v2 08/11] test: Add Args docstrings to img setup functions Simon Glass
2026-06-08  8:24   ` Mattijs Korpershoek
2026-05-23  8:54 ` [PATCH v2 09/11] test: Reformat line wraps in " Simon Glass
2026-06-08  8:27   ` Mattijs Korpershoek
2026-05-23  8:54 ` [PATCH v2 10/11] sandbox: Find disk images in the persistent-data directory Simon Glass
2026-06-08  8:41   ` Mattijs Korpershoek [this message]
2026-05-23  8:54 ` [PATCH v2 11/11] test: Move disk images to " Simon Glass
2026-06-08  8:49   ` Mattijs Korpershoek
2026-06-08  7:53 ` [PATCH v2 00/11] Move test/py image creation into separate modules Mattijs Korpershoek

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=87ldcpxw39.fsf@kernel.org \
    --to=mkorpershoek@kernel.org \
    --cc=jh80.chung@samsung.com \
    --cc=marex@denx.de \
    --cc=peng.fan@nxp.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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