U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: Simon Glass <sjg@chromium.org>,
	U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Michal Simek <michal.simek@amd.com>,
	Lean Sheng Tan <sheng.tan@9elements.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH v2 03/21] test: Move some SPL-loading test-code into sandbox common
Date: Thu, 18 Jul 2024 10:11:30 -0400	[thread overview]
Message-ID: <cd57edbe-bf5a-0545-9cbb-f39babdbe776@gmail.com> (raw)
In-Reply-To: <20240713070055.2172883-4-sjg@chromium.org>

On 7/13/24 03:00, Simon Glass wrote:
> This code is useful for loading an image in sandbox_spl so move it into
> a place where it can be called as needed.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
> (no changes since v1)
> 
>   arch/sandbox/cpu/spl.c         | 67 ++++++++++++++++++++++++++++++++++
>   arch/sandbox/include/asm/spl.h | 14 +++++++
>   test/image/spl_load_os.c       | 53 +--------------------------
>   3 files changed, 82 insertions(+), 52 deletions(-)
> 
> diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
> index 9ad9da686c6..caa8e0b3b01 100644
> --- a/arch/sandbox/cpu/spl.c
> +++ b/arch/sandbox/cpu/spl.c
> @@ -6,6 +6,7 @@
>   #include <dm.h>
>   #include <hang.h>
>   #include <handoff.h>
> +#include <image.h>
>   #include <init.h>
>   #include <log.h>
>   #include <os.h>
> @@ -179,3 +180,69 @@ int handoff_arch_save(struct spl_handoff *ho)
>   
>   	return 0;
>   }
> +
> +/* Context used to hold file descriptor */
> +struct load_ctx {
> +	int fd;
> +};
> +
> +static ulong read_fit_image(struct spl_load_info *load, ulong offset,
> +			    ulong size, void *buf)
> +{
> +	struct load_ctx *load_ctx = load->priv;
> +	off_t ret;
> +	ssize_t res;
> +
> +	ret = os_lseek(load_ctx->fd, offset, OS_SEEK_SET);
> +	if (ret < 0) {
> +		printf("Failed to seek to %zx, got %zx (errno=%d)\n", offset,
> +		       ret, errno);
> +		return log_msg_ret("lse", ret);
> +	}
> +
> +	res = os_read(load_ctx->fd, buf, size);
> +	if (res < 0) {
> +		printf("Failed to read %lx bytes, got %ld (errno=%d)\n",
> +		       size, res, errno);
> +		return log_msg_ret("osr", res);
> +	}
> +
> +	return size;
> +}
> +
> +int sandbox_spl_load_fit(char *fname, int maxlen, struct spl_image_info *image)
> +{
> +	struct legacy_img_hdr *header;
> +	struct load_ctx load_ctx;
> +	struct spl_load_info load;
> +	int ret;
> +	int fd;
> +
> +	memset(&load, '\0', sizeof(load));
> +	spl_set_bl_len(&load, 512);
> +	load.read = read_fit_image;
> +
> +	ret = sandbox_find_next_phase(fname, maxlen, true);
> +	if (ret) {
> +		printf("%s not found, error %d\n", fname, ret);
> +		return log_msg_ret("nph", ret);
> +	}
> +
> +	header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
> +
> +	log_debug("reading from %s\n", fname);
> +	fd = os_open(fname, OS_O_RDONLY);
> +	if (fd < 0)
> +		return log_msg_ret("ope", -ENOENT);

should return errno

and I think longer messages won't hurt (this is sandbox after all).

> +	if (os_read(fd, header, 512) != 512)

Actually, this should probably be sizeof(*header) and not 512

> +		return log_msg_ret("rea", -EIO);

ditto errno/message

> +	load_ctx.fd = fd;
> +
> +	load.priv = &load_ctx;
> +
> +	ret = spl_load_simple_fit(image, &load, 0, header);
> +	if (ret)
> +		return log_msg_ret("slf", ret);
> +
> +	return 0;
> +}
> diff --git a/arch/sandbox/include/asm/spl.h b/arch/sandbox/include/asm/spl.h
> index 4fab24cd156..d50d9ad6b48 100644
> --- a/arch/sandbox/include/asm/spl.h
> +++ b/arch/sandbox/include/asm/spl.h
> @@ -6,6 +6,8 @@
>   #ifndef __asm_spl_h
>   #define __asm_spl_h
>   
> +struct spl_image_info;
> +
>   enum {
>   	BOOT_DEVICE_MMC1,
>   	BOOT_DEVICE_MMC2,
> @@ -31,4 +33,16 @@ enum {
>    */
>   int sandbox_find_next_phase(char *fname, int maxlen, bool use_img);
>   
> +/**
> + * sandbox_spl_load_fit() - Load the next phase from a FIT
> + *
> + * Loads a FIT containing the next phase and sets it up for booting
> + *
> + * @fname: Returns filename loaded
> + * @maxlen: Maximum length for @fname including \0
> + * @image: Place to put SPL-image information
> + * Return: 0 if OK, -ve on error
> + */
> +int sandbox_spl_load_fit(char *fname, int maxlen, struct spl_image_info *image);
> +
>   #endif
> diff --git a/test/image/spl_load_os.c b/test/image/spl_load_os.c
> index 7d5fb9b07e0..56105a59236 100644
> --- a/test/image/spl_load_os.c
> +++ b/test/image/spl_load_os.c
> @@ -10,63 +10,12 @@
>   #include <test/spl.h>
>   #include <test/ut.h>
>   
> -/* Context used for this test */
> -struct text_ctx {
> -	int fd;
> -};
> -
> -static ulong read_fit_image(struct spl_load_info *load, ulong offset,
> -			    ulong size, void *buf)
> -{
> -	struct text_ctx *text_ctx = load->priv;
> -	off_t ret;
> -	ssize_t res;
> -
> -	ret = os_lseek(text_ctx->fd, offset, OS_SEEK_SET);
> -	if (ret != offset) {
> -		printf("Failed to seek to %zx, got %zx (errno=%d)\n", offset,
> -		       ret, errno);
> -		return 0;
> -	}
> -
> -	res = os_read(text_ctx->fd, buf, size);
> -	if (res == -1) {
> -		printf("Failed to read %lx bytes, got %ld (errno=%d)\n",
> -		       size, res, errno);
> -		return 0;
> -	}
> -
> -	return size;
> -}
> -
>   static int spl_test_load(struct unit_test_state *uts)
>   {
>   	struct spl_image_info image;
> -	struct legacy_img_hdr *header;
> -	struct text_ctx text_ctx;
> -	struct spl_load_info load;
>   	char fname[256];
> -	int ret;
> -	int fd;
> -
> -	memset(&load, '\0', sizeof(load));
> -	spl_set_bl_len(&load, 512);
> -	load.read = read_fit_image;
> -
> -	ret = sandbox_find_next_phase(fname, sizeof(fname), true);
> -	if (ret)
> -		ut_assertf(0, "%s not found, error %d\n", fname, ret);
> -
> -	header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
> -
> -	fd = os_open(fname, OS_O_RDONLY);
> -	ut_assert(fd >= 0);
> -	ut_asserteq(512, os_read(fd, header, 512));
> -	text_ctx.fd = fd;
> -
> -	load.priv = &text_ctx;
>   
> -	ut_assertok(spl_load_simple_fit(&image, &load, 0, header));
> +	ut_assertok(sandbox_spl_load_fit(fname, sizeof(fname), &image));
>   
>   	return 0;
>   }


  reply	other threads:[~2024-07-18 14:11 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-13  7:00 [PATCH v2 00/21] Universal Payload initial series Simon Glass
2024-07-13  7:00 ` [PATCH v2 01/21] sandbox: Use const in os_jump_to_file() Simon Glass
2024-07-18  8:02   ` Mattijs Korpershoek
2024-07-13  7:00 ` [PATCH v2 02/21] sandbox: Fix a comment in os_find_u_boot() Simon Glass
2024-07-18  8:02   ` Mattijs Korpershoek
2024-07-13  7:00 ` [PATCH v2 03/21] test: Move some SPL-loading test-code into sandbox common Simon Glass
2024-07-18 14:11   ` Sean Anderson [this message]
2024-07-13  7:00 ` [PATCH v2 04/21] sandbox: Enable SPL_LOAD_BLOCK Simon Glass
2024-07-18 13:28   ` Sean Anderson
2024-07-18 23:58     ` Sean Anderson
2024-07-13  7:00 ` [PATCH v2 05/21] fdt: Don't overwrite bloblist devicetree Simon Glass
2024-07-13  7:00 ` [PATCH v2 06/21] sandbox: fdt: Avoid overwriting an existing fdt Simon Glass
2024-07-13  7:00 ` [PATCH v2 07/21] sandbox: Return error code from read/write/seek Simon Glass
2024-07-13  7:00 ` [PATCH v2 08/21] sandbox: Add ELF file to VPL u-boot.img Simon Glass
2024-07-13  7:00 ` [PATCH v2 09/21] sandbox: Set up global_data earlier Simon Glass
2024-07-13  7:00 ` [PATCH v2 10/21] upl: Add support for reading a upl handoff Simon Glass
2024-07-18 14:41   ` Heinrich Schuchardt
2024-07-20 12:36     ` Simon Glass
2024-07-13  7:00 ` [PATCH v2 11/21] upl: Add support for writing " Simon Glass
2024-07-13  7:00 ` [PATCH v2 12/21] upl: Add basic tests Simon Glass
2024-07-13  7:00 ` [PATCH v2 13/21] upl: Add a command Simon Glass
2024-07-13  7:00 ` [PATCH v2 14/21] upl: Add support for Universal Payload in SPL Simon Glass
2024-07-13  7:00 ` [PATCH v2 15/21] spl: Plumb in the Universal Payload handoff Simon Glass
2024-07-18 13:54   ` Sean Anderson
2024-07-20 12:36     ` Simon Glass
2024-07-20 14:44       ` Sean Anderson
2024-07-21 10:08         ` Simon Glass
2024-07-13  7:00 ` [PATCH v2 16/21] upl: Plumb in universal payload to the init process Simon Glass
2024-07-13  7:00 ` [PATCH v2 17/21] sandbox_vpl: Enable Universal Payload Simon Glass
2024-07-13  7:00 ` [PATCH v2 18/21] upl: Add initial documentation Simon Glass
2024-07-13  7:00 ` [PATCH v2 19/21] sandbox: Add a flag to enable UPL Simon Glass
2024-07-13  7:00 ` [PATCH v2 20/21] sandbox: Add an SPL loader for UPL Simon Glass
2024-07-18 14:12   ` Sean Anderson
2024-07-20 12:36     ` Simon Glass
2024-07-13  7:00 ` [PATCH v2 21/21] upl: Add an end-to-end test Simon Glass
2024-07-13  8:12 ` [PATCH v2 00/21] Universal Payload initial series Mark Kettenis
2024-07-13 19:40   ` Heinrich Schuchardt
2024-07-16 19:08     ` Tom Rini
2024-07-18  8:23       ` Heinrich Schuchardt
2024-07-18 14:15         ` Tom Rini
2024-08-07 14:36   ` Simon Glass

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=cd57edbe-bf5a-0545-9cbb-f39babdbe776@gmail.com \
    --to=seanga2@gmail.com \
    --cc=michal.simek@amd.com \
    --cc=sheng.tan@9elements.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.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