From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cristian Ciocaltea Date: Sun, 29 Dec 2019 18:53:55 +0200 Subject: [PATCH v4 2/5] bootm: Add a bootm command for type IH_OS_EFI In-Reply-To: <2eb0b9b9-18d3-c875-f32b-194bca24782e@gmx.de> References: <53b0cb4503c807651fc677934324cfa5f59552e6.1577202178.git.cristian.ciocaltea@gmail.com> <2eb0b9b9-18d3-c875-f32b-194bca24782e@gmx.de> Message-ID: <20191229165355.GA26594@BV030612LT> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Sun, Dec 29, 2019 at 11:34:09AM +0100, Heinrich Schuchardt wrote: > On 12/24/19 5:05 PM, Cristian Ciocaltea wrote: > > Add support for booting EFI binaries contained in FIT images. > > A typical usage scenario is chain-loading GRUB2 in a verified > > boot environment. > > > > Signed-off-by: Cristian Ciocaltea > > Reviewed-by: Heinrich Schuchardt > > --- > > cmd/Kconfig | 7 ++++++ > > common/bootm_os.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 63 insertions(+) > > > > diff --git a/cmd/Kconfig b/cmd/Kconfig > > index 1e4cf146c5..87f2335a3c 100644 > > --- a/cmd/Kconfig > > +++ b/cmd/Kconfig > > @@ -263,6 +263,13 @@ config CMD_BOOTI > > help > > Boot an AArch64 Linux Kernel image from memory. > > > > +config BOOTM_EFI > > + bool "Support booting EFI OS images" > > Shouldn't this be "Support booting UEFI FIT images"? Done. > > + depends on CMD_BOOTEFI > > depends on BOOTM > > is missing here. Right, thanks. Added 'CMD_BOOTEFI && CMD_BOOTM'. > > + default y > > + help > > + Support booting EFI images via the bootm command. > > Should we say: > > Support booting UEFI FIT images via the bootm command. Done. > Best regards > > Heinrich > > > + > > config BOOTM_LINUX > > bool "Support booting Linux OS images" > > depends on CMD_BOOTM || CMD_BOOTZ || CMD_BOOTI > > diff --git a/common/bootm_os.c b/common/bootm_os.c > > index d89ddc32b0..1d58462509 100644 > > --- a/common/bootm_os.c > > +++ b/common/bootm_os.c > > @@ -7,10 +7,12 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > #include > > +#include > > #include > > #include > > > > @@ -498,6 +500,57 @@ static int do_bootm_tee(int flag, int argc, char * const argv[], > > } > > #endif > > > > +#ifdef CONFIG_BOOTM_EFI > > +static int do_bootm_efi(int flag, int argc, char * const argv[], > > + bootm_headers_t *images) > > +{ > > + int ret; > > + efi_status_t efi_ret; > > + void *image_buf; > > + > > + if (flag != BOOTM_STATE_OS_GO) > > + return 0; > > + > > + /* Locate FDT, if provided */ > > + ret = bootm_find_images(flag, argc, argv); > > + if (ret) > > + return ret; > > + > > + /* Initialize EFI drivers */ > > + efi_ret = efi_init_obj_list(); > > + if (efi_ret != EFI_SUCCESS) { > > + printf("## Failed to initialize UEFI sub-system: r = %lu\n", > > + efi_ret & ~EFI_ERROR_MASK); > > + return 1; > > + } > > + > > + /* Install device tree */ > > + efi_ret = efi_install_fdt(images->ft_len > > + ? images->ft_addr : EFI_FDT_USE_INTERNAL); > > + if (efi_ret != EFI_SUCCESS) { > > + printf("## Failed to install device tree: r = %lu\n", > > + efi_ret & ~EFI_ERROR_MASK); > > + return 1; > > + } > > + > > + /* Run EFI image */ > > + printf("## Transferring control to EFI (at address %08lx) ...\n", > > + images->ep); > > + bootstage_mark(BOOTSTAGE_ID_RUN_OS); > > + > > + image_buf = map_sysmem(images->ep, images->os.image_len); > > + > > + efi_ret = efi_run_image(image_buf, images->os.image_len); > > + if (efi_ret != EFI_SUCCESS) { > > + printf("## Failed to run EFI image: r = %lu\n", > > + efi_ret & ~EFI_ERROR_MASK); > > + return 1; > > + } > > + > > + return 0; > > +} > > +#endif > > + > > static boot_os_fn *boot_os[] = { > > [IH_OS_U_BOOT] = do_bootm_standalone, > > #ifdef CONFIG_BOOTM_LINUX > > @@ -534,6 +587,9 @@ static boot_os_fn *boot_os[] = { > > #ifdef CONFIG_BOOTM_OPTEE > > [IH_OS_TEE] = do_bootm_tee, > > #endif > > +#ifdef CONFIG_BOOTM_EFI > > + [IH_OS_EFI] = do_bootm_efi, > > +#endif > > }; > > > > /* Allow for arch specific config before we boot */ > > >