[U-Boot] [PATCH 3/6] arm: efi: Add a hello world test program

Bin Meng bmeng.cn at gmail.com
Tue Aug 9 08:50:34 CEST 2016


Hi Simon,

On Sun, Aug 7, 2016 at 7:23 AM, Simon Glass <sjg at chromium.org> wrote:
> It is useful to have a basic sanity check for EFI loader support. Add a
> 'bootefi hello' command which loads HelloWord.efi and runs it under U-Boot.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
>  arch/arm/lib/HelloWorld32.efi  | Bin 0 -> 11712 bytes
>  arch/arm/lib/Makefile          |   6 ++++++
>  cmd/Kconfig                    |  10 ++++++++++
>  cmd/bootefi.c                  |  26 ++++++++++++++++++++------
>  include/asm-generic/sections.h |   2 ++
>  scripts/Makefile.lib           |  19 +++++++++++++++++++
>  6 files changed, 57 insertions(+), 6 deletions(-)
>  create mode 100644 arch/arm/lib/HelloWorld32.efi
>

[snip]

> diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
> index a8d1557..0f3ea0c 100644
> --- a/arch/arm/lib/Makefile
> +++ b/arch/arm/lib/Makefile
> @@ -29,6 +29,12 @@ obj-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
>  obj-$(CONFIG_CMD_BOOTM) += bootm.o
>  obj-$(CONFIG_CMD_BOOTM) += zimage.o
>  obj-$(CONFIG_SYS_L2_PL310) += cache-pl310.o
> +ifdef CONFIG_ARM64
> +# This option does not work for arm64, as there is no binary.

If so, can we just remove this for arm64?

> +obj-$(CONFIG_CMD_BOOTEFI_HELLO) += HelloWorld64.o
> +else
> +obj-$(CONFIG_CMD_BOOTEFI_HELLO) += HelloWorld32.o
> +endif
>  obj-$(CONFIG_USE_ARCH_MEMSET) += memset.o
>  obj-$(CONFIG_USE_ARCH_MEMCPY) += memcpy.o
>  else
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index d69b817..8df80b6 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -172,6 +172,16 @@ config CMD_BOOTEFI
>         help
>           Boot an EFI image from memory.
>
> +config CMD_BOOTEFI_HELLO
> +       bool "Allow booting a standard EFI hello word for testing"
> +       depends on CMD_BOOTEFI
> +       default y if CMD_BOOTEFI && !ARM64
> +       help
> +         This adds a standard EFI hello world application to U-Boot so that
> +         it can be used with the 'bootefi hello' command. This is useful
> +         for testing that EFI is woring at a basic level, and for brining

typo: working, bringing

> +         up EFI support on a new architecture.
> +
>  config CMD_ELF
>         bool "bootelf, bootvx"
>         default y
> diff --git a/cmd/bootefi.c b/cmd/bootefi.c
> index 0536b63..ecf9968 100644
> --- a/cmd/bootefi.c
> +++ b/cmd/bootefi.c
> @@ -229,13 +229,22 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>
>         if (argc < 2)
>                 return 1;
> -       saddr = argv[1];
> +#ifdef CONFIG_CMD_BOOTEFI_HELLO
> +       if (!strcmp(argv[1], "hello")) {
> +               addr = CONFIG_SYS_LOAD_ADDR;
> +               memcpy((char *)addr, __efi_hello_world_begin,
> +                      __efi_hello_world_end - __efi_hello_world_begin);
> +       } else
> +#endif
> +       {
> +               saddr = argv[1];
>
> -       addr = simple_strtoul(saddr, NULL, 16);
> +               addr = simple_strtoul(saddr, NULL, 16);
>
> -       if (argc > 2) {
> -               sfdt = argv[2];
> -               fdt_addr = simple_strtoul(sfdt, NULL, 16);
> +               if (argc > 2) {
> +                       sfdt = argv[2];
> +                       fdt_addr = simple_strtoul(sfdt, NULL, 16);
> +               }
>         }
>
>         printf("## Starting EFI application at 0x%08lx ...\n", addr);
> @@ -253,7 +262,12 @@ static char bootefi_help_text[] =
>         "<image address> [fdt address]\n"
>         "  - boot EFI payload stored at address <image address>.\n"
>         "    If specified, the device tree located at <fdt address> gets\n"
> -       "    exposed as EFI configuration table.\n";
> +       "    exposed as EFI configuration table.\n"
> +#ifdef CONFIG_CMD_BOOTEFI_HELLO
> +       "hello\n"
> +       "  - boot a sample Hello Word application stored within U-Boot"

typo: World

> +#endif
> +       ;
>  #endif
>
>  U_BOOT_CMD(
> diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
> index 328bc62..54ccac9 100644
> --- a/include/asm-generic/sections.h
> +++ b/include/asm-generic/sections.h
> @@ -22,6 +22,8 @@ extern char __kprobes_text_start[], __kprobes_text_end[];
>  extern char __entry_text_start[], __entry_text_end[];
>  extern char __initdata_begin[], __initdata_end[];
>  extern char __start_rodata[], __end_rodata[];
> +extern char __efi_hello_world_begin[];
> +extern char __efi_hello_world_end[];
>
>  /* Start and end of .ctors section - used for constructor calls. */
>  extern char __ctors_start[], __ctors_end[];
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index e720562..07469f0 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -321,6 +321,25 @@ cmd_S_ttf=                                         \
>  $(obj)/%.S: $(src)/%.ttf
>         $(call cmd,S_ttf)
>
> +# EFI Hello World application
> +# ---------------------------------------------------------------------------
> +
> +# Generate an assembly file to wrap the EFI app
> +cmd_S_efi=                                             \
> +(                                                      \
> +       echo '.section .rodata.efi.init,"a"';           \
> +       echo '.balign 16';                              \
> +       echo '.global __efi_hello_world_begin';         \
> +       echo '__efi_hello_world_begin:';                        \

nits: the ending \ is not aligned with other lines

> +       echo '.incbin "$<" ';                           \
> +       echo '__efi_hello_world_end:';                  \
> +       echo '.global __efi_hello_world_end';                   \

nits: the ending \ is not aligned with other lines

> +       echo '.balign 16';                              \
> +) > $@
> +
> +$(obj)/%.S: $(src)/%.efi
> +       $(call cmd,S_efi)
> +
>  # ACPI
>  # ---------------------------------------------------------------------------
>  quiet_cmd_acpi_c_asl= ASL     $<
> --

Regards,
Bin


More information about the U-Boot mailing list