[PATCH v8 5/8] sandbox: Report host default-filename in native mode
Ilias Apalodimas
ilias.apalodimas at linaro.org
Fri Oct 25 11:56:29 CEST 2024
Hi Simon,
On Tue, 22 Oct 2024 at 15:00, Simon Glass <sjg at chromium.org> wrote:
>
> When the --native flag is given, pretend to be running the host
> architecture rather than sandbox.
>
> Add an 'efidebug filename' command to report it.
Heinrich does this allow you to continue your testing in native archs?
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> Changes in v8:
> - Add new patch to report host default-filename in native mode
>
> boot/bootmeth_efi.c | 25 ++------------------
> boot/efi_fname.c | 57 +++++++++++++++++++++++++++++++++------------
> cmd/efidebug.c | 25 ++++++++++++++++++++
> include/efi.h | 25 ++++++++++++++++++++
> 4 files changed, 94 insertions(+), 38 deletions(-)
>
> diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c
> index 371b36d550b..f836aa655f5 100644
> --- a/boot/bootmeth_efi.c
> +++ b/boot/bootmeth_efi.c
> @@ -25,32 +25,11 @@
>
> #define EFI_DIRNAME "/EFI/BOOT/"
>
> -static int get_efi_pxe_arch(void)
> -{
> - /* http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml */
> - if (IS_ENABLED(CONFIG_ARM64))
> - return 0xb;
> - else if (IS_ENABLED(CONFIG_ARM))
> - return 0xa;
> - else if (IS_ENABLED(CONFIG_X86_64))
> - return 0x6;
> - else if (IS_ENABLED(CONFIG_X86))
> - return 0x7;
> - else if (IS_ENABLED(CONFIG_ARCH_RV32I))
> - return 0x19;
> - else if (IS_ENABLED(CONFIG_ARCH_RV64I))
> - return 0x1b;
> - else if (IS_ENABLED(CONFIG_SANDBOX))
> - return 0; /* not used */
> -
> - return -EINVAL;
> -}
> -
> static int get_efi_pxe_vci(char *str, int max_len)
> {
> int ret;
>
> - ret = get_efi_pxe_arch();
> + ret = efi_get_pxe_arch();
> if (ret < 0)
> return ret;
>
> @@ -239,7 +218,7 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)
> ret = get_efi_pxe_vci(str, sizeof(str));
> if (ret)
> return log_msg_ret("vci", ret);
> - ret = get_efi_pxe_arch();
> + ret = efi_get_pxe_arch();
> if (ret < 0)
> return log_msg_ret("arc", ret);
> arch = ret;
> diff --git a/boot/efi_fname.c b/boot/efi_fname.c
> index a6b11383bba..790f9e2fa36 100644
> --- a/boot/efi_fname.c
> +++ b/boot/efi_fname.c
> @@ -9,29 +9,34 @@
> */
>
> #include <efi.h>
> +#include <errno.h>
> #include <host_arch.h>
>
> -#ifdef CONFIG_SANDBOX
> -
> #if HOST_ARCH == HOST_ARCH_X86_64
> -#define BOOTEFI_NAME "BOOTX64.EFI"
> +#define HOST_BOOTEFI_NAME "BOOTX64.EFI"
> +#define HOST_PXE_ARCH 0x6
> #elif HOST_ARCH == HOST_ARCH_X86
> -#define BOOTEFI_NAME "BOOTIA32.EFI"
> +#define HOST_BOOTEFI_NAME "BOOTIA32.EFI"
> +#define HOST_PXE_ARCH 0x7
> #elif HOST_ARCH == HOST_ARCH_AARCH64
> -#define BOOTEFI_NAME "BOOTAA64.EFI"
> +#define HOST_BOOTEFI_NAME "BOOTAA64.EFI"
> +#define HOST_PXE_ARCH 0xb
> #elif HOST_ARCH == HOST_ARCH_ARM
> -#define BOOTEFI_NAME "BOOTARM.EFI"
> +#define HOST_BOOTEFI_NAME "BOOTARM.EFI"
> +#define HOST_PXE_ARCH 0xa
> #elif HOST_ARCH == HOST_ARCH_RISCV32
> -#define BOOTEFI_NAME "BOOTRISCV32.EFI"
> +#define HOST_BOOTEFI_NAME "BOOTRISCV32.EFI"
> +#define HOST_PXE_ARCH 0x19
> #elif HOST_ARCH == HOST_ARCH_RISCV64
> -#define BOOTEFI_NAME "BOOTRISCV64.EFI"
> +#define HOST_BOOTEFI_NAME "BOOTRISCV64.EFI"
> +#define HOST_PXE_ARCH 0x1b
> #else
> -#error Unsupported UEFI architecture
> +#error Unsupported Host architecture
> #endif
>
> -#else
> -
> -#if defined(CONFIG_ARM64)
> +#if defined(CONFIG_SANDBOX)
> +#define BOOTEFI_NAME "BOOTSBOX.EFI"
> +#elif defined(CONFIG_ARM64)
> #define BOOTEFI_NAME "BOOTAA64.EFI"
> #elif defined(CONFIG_ARM)
> #define BOOTEFI_NAME "BOOTARM.EFI"
> @@ -47,9 +52,31 @@
> #error Unsupported UEFI architecture
> #endif
>
> -#endif
> -
> const char *efi_get_basename(void)
> {
> - return BOOTEFI_NAME;
> + return efi_use_host_arch() ? HOST_BOOTEFI_NAME : BOOTEFI_NAME;
> +}
> +
> +int efi_get_pxe_arch(void)
> +{
> + if (efi_use_host_arch())
> + return HOST_PXE_ARCH;
> +
> + /* http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml */
> + if (IS_ENABLED(CONFIG_ARM64))
> + return 0xb;
> + else if (IS_ENABLED(CONFIG_ARM))
> + return 0xa;
> + else if (IS_ENABLED(CONFIG_X86_64))
> + return 0x6;
> + else if (IS_ENABLED(CONFIG_X86))
> + return 0x7;
> + else if (IS_ENABLED(CONFIG_ARCH_RV32I))
> + return 0x19;
> + else if (IS_ENABLED(CONFIG_ARCH_RV64I))
> + return 0x1b;
> + else if (IS_ENABLED(CONFIG_SANDBOX))
> + return 0; /* not used */
> +
> + return -EINVAL;
> }
> diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> index e040fe75fa1..02f1e080e88 100644
> --- a/cmd/efidebug.c
> +++ b/cmd/efidebug.c
> @@ -511,6 +511,27 @@ static int do_efi_show_images(struct cmd_tbl *cmdtp, int flag,
> return CMD_RET_SUCCESS;
> }
>
> +/**
> + * do_efi_show_defaults() - show UEFI default filename and PXE architecture
> + *
> + * @cmdtp: Command table
> + * @flag: Command flag
> + * @argc: Number of arguments
> + * @argv: Argument array
> + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
> + *
> + * Implement efidebug "defaults" sub-command.
> + * Shows the default EFI filename and PXE architecture
> + */
> +static int do_efi_show_defaults(struct cmd_tbl *cmdtp, int flag,
> + int argc, char *const argv[])
> +{
> + printf("Default boot path: EFI\\BOOT\\%s\n", efi_get_basename());
> + printf("PXE arch: 0x%02x\n", efi_get_pxe_arch());
> +
> + return CMD_RET_SUCCESS;
> +}
> +
> static const char * const efi_mem_type_string[] = {
> [EFI_RESERVED_MEMORY_TYPE] = "RESERVED",
> [EFI_LOADER_CODE] = "LOADER CODE",
> @@ -1561,6 +1582,8 @@ static struct cmd_tbl cmd_efidebug_sub[] = {
> "", ""),
> U_BOOT_CMD_MKENT(dh, CONFIG_SYS_MAXARGS, 1, do_efi_show_handles,
> "", ""),
> + U_BOOT_CMD_MKENT(defaults, CONFIG_SYS_MAXARGS, 1, do_efi_show_defaults,
> + "", ""),
> U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1, do_efi_show_images,
> "", ""),
> U_BOOT_CMD_MKENT(memmap, CONFIG_SYS_MAXARGS, 1, do_efi_show_memmap,
> @@ -1653,6 +1676,8 @@ U_BOOT_LONGHELP(efidebug,
> " - show UEFI drivers\n"
> "efidebug dh\n"
> " - show UEFI handles\n"
> + "efidebug defaults\n"
> + " - show default EFI filename and PXE architecture\n"
> "efidebug images\n"
> " - show loaded images\n"
> "efidebug memmap\n"
> diff --git a/include/efi.h b/include/efi.h
> index 1b8093bd4d3..70bb47e742f 100644
> --- a/include/efi.h
> +++ b/include/efi.h
> @@ -678,4 +678,29 @@ void efi_show_tables(struct efi_system_table *systab);
> */
> const char *efi_get_basename(void);
>
> +#ifdef CONFIG_SANDBOX
> +#include <asm/state.h>
> +#endif
> +
> +static inline bool efi_use_host_arch(void)
> +{
> +#ifdef CONFIG_SANDBOX
#if IS_ENABLED(CONFIG_SANDBOX) is preferred no ?
> + struct sandbox_state *state = state_get_current();
> +
> + return state->native;
> +#else
> + return false;
> +#endif
> +}
> +
> +/**
> + * efi_get_pxe_arch() - Get the architecture value for PXE
> + *
> + * See:
> + * http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml
> + *
> + * Return: Architecture value
> + */
> +int efi_get_pxe_arch(void);
> +
> #endif /* _LINUX_EFI_H */
> --
> 2.43.0
>
Thanks
/Ilias
More information about the U-Boot
mailing list