]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
Merge tag 'v2024.01-rc5' into next
authorTom Rini <trini@konsulko.com>
Mon, 18 Dec 2023 13:31:50 +0000 (08:31 -0500)
committerTom Rini <trini@konsulko.com>
Mon, 18 Dec 2023 14:55:32 +0000 (09:55 -0500)
Prepare v2024.01-rc5

20 files changed:
1  2 
MAINTAINERS
Makefile
arch/arm/dts/Makefile
arch/arm/dts/imx7d-pico-pi-u-boot.dtsi
arch/arm/mach-imx/imx8m/clock_imx8mm.c
arch/sandbox/dts/test.dts
arch/sandbox/include/asm/clk.h
board/emulation/qemu-riscv/Kconfig
board/toradex/colibri_imx7/colibri_imx7.c
boot/bootmeth_efi.c
common/spl/Kconfig
configs/imx8mm_data_modul_edm_sbc_defconfig
configs/imx8mp_data_modul_edm_sbc_defconfig
configs/imx8mp_dhcom_pdk2_defconfig
configs/imx8mp_dhcom_pdk3_defconfig
configs/imx8mp_evk_defconfig
lib/Kconfig
lib/efi_loader/Makefile
lib/efi_loader/efi_bootmgr.c
lib/efi_loader/efi_boottime.c

diff --combined MAINTAINERS
index d77b9ffc9b667392fe911db3f9be9c99e83571ff,969514468cbc11e32d5254e1259a6ddcff5ea376..25f2bb80deb985cfce5109fab3861f9a920363e4
@@@ -117,7 -117,7 +117,7 @@@ F: drivers/mmc/snps_dw_mmc.
  APPLE M1 SOC SUPPORT
  M:    Mark Kettenis <kettenis@openbsd.org>
  S:    Maintained
- F:    arch/arm/include/asm/arch-m1/
+ F:    arch/arm/include/asm/arch-apple/
  F:    arch/arm/mach-apple/
  F:    configs/apple_m1_defconfig
  F:    drivers/iommu/apple_dart.c
@@@ -979,7 -979,7 +979,7 @@@ EFI AP
  M:    Simon Glass <sjg@chromium.org>
  M:    Heinrich Schuchardt <xypron.glpk@gmx.de>
  S:    Maintained
 -W:    https://u-boot.readthedocs.io/en/latest/develop/uefi/u-boot_on_efi.html
 +W:    https://docs.u-boot.org/en/latest/develop/uefi/u-boot_on_efi.html
  F:    board/efi/efi-x86_app
  F:    configs/efi-x86_app*
  F:    doc/develop/uefi/u-boot_on_efi.rst
@@@ -1528,7 -1528,6 +1528,6 @@@ F:      cmd/stackprot_test.
  F:    test/py/tests/test_stackprotector.py
  
  TARGET_BCMNS3
- M:    Bharat Gooty <bharat.gooty@broadcom.com>
  M:    Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
  S:    Maintained
  F:    board/broadcom/bcmns3/
@@@ -1551,11 -1550,6 +1550,11 @@@ M:    Liviu Dudau <liviu.dudau@foss.arm.co
  S:    Maintained
  F:    drivers/video/tda19988.c
  
 +TI LP5562 LED DRIVER
 +M:    Rasmus Villemoes <rasmus.villemoes@prevas.dk>
 +S:    Supported
 +F:    drivers/led/led_lp5562.c
 +
  TI SYSTEM SECURITY
  M:    Andrew F. Davis <afd@ti.com>
  S:    Supported
diff --combined Makefile
index 243494f46411cf82d1c3b7e66764a412ebb17ac0,220411a293f49c527287ed5d8d6bfd46105aeaaa..60805f54a69fdbc1d5cbbb7720b5b4cd137abac7
+++ b/Makefile
@@@ -3,7 -3,7 +3,7 @@@
  VERSION = 2024
  PATCHLEVEL = 01
  SUBLEVEL =
- EXTRAVERSION = -rc4
+ EXTRAVERSION = -rc5
  NAME =
  
  # *DOCUMENTATION*
@@@ -750,7 -750,6 +750,7 @@@ endi
  
  ifeq ($(CONFIG_STACKPROTECTOR),y)
  KBUILD_CFLAGS += $(call cc-option,-fstack-protector-strong)
 +KBUILD_CFLAGS += $(call cc-option,-mstack-protector-guard=global)
  CFLAGS_EFI += $(call cc-option,-fno-stack-protector)
  else
  KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
@@@ -852,7 -851,7 +852,7 @@@ HAVE_VENDOR_COMMON_LIB = $(if $(wildcar
  libs-$(CONFIG_API) += api/
  libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
  libs-y += boot/
 -libs-y += cmd/
 +libs-$(CONFIG_CMDLINE) += cmd/
  libs-y += common/
  libs-$(CONFIG_OF_EMBED) += dts/
  libs-y += env/
@@@ -1154,6 -1153,7 +1154,6 @@@ endi
        @# is enable to tell 'deprecated' that one of these symbols exists
        $(call deprecated,CONFIG_TIMER,Timer drivers,v2023.01,$(if $(strip $(CFG_SYS_TIMER_RATE)$(CFG_SYS_TIMER_COUNTER)),x))
        $(call deprecated,CONFIG_DM_SERIAL,Serial drivers,v2023.04,$(CONFIG_SERIAL))
 -      $(call deprecated,CONFIG_DM_SCSI,SCSI drivers,v2023.04,$(CONFIG_SCSI))
        @# Check that this build does not override OF_HAS_PRIOR_STAGE by
        @# disabling OF_BOARD.
        $(call cmd,ofcheck,$(KCONFIG_CONFIG))
@@@ -1349,7 -1349,6 +1349,7 @@@ cmd_binman = $(srctree)/tools/binman/bi
                $(foreach f,$(BINMAN_INDIRS),-I $(f)) \
                -a atf-bl31-path=${BL31} \
                -a tee-os-path=${TEE} \
 +              -a ti-dm-path=${TI_DM} \
                -a opensbi-path=${OPENSBI} \
                -a default-dt=$(default_dt) \
                -a scp-path=$(SCP) \
diff --combined arch/arm/dts/Makefile
index ef0e705f3d77370b6ba962b0522736afb7e051e6,9d28a485bec6d4e8dbe8967c4d3d9fed271117cf..e9e58c5478dfe0e2e683bf12f86416b870be86b6
@@@ -835,6 -835,7 +835,7 @@@ dtb-$(CONFIG_MACH_SUN50I_H6) += 
        sun50i-h6-tanix-tx6-mini.dtb
  dtb-$(CONFIG_MACH_SUN50I_H616) += \
        sun50i-h616-orangepi-zero2.dtb \
+       sun50i-h618-orangepi-zero3.dtb \
        sun50i-h616-x96-mate.dtb
  dtb-$(CONFIG_MACH_SUN50I) += \
        sun50i-a64-amarula-relic.dtb \
@@@ -1074,7 -1075,6 +1075,7 @@@ dtb-$(CONFIG_ARCH_IMX8M) += 
        imx8mm-kontron-bl-osm-s.dtb \
        imx8mm-mx8menlo.dtb \
        imx8mm-phg.dtb \
 +      imx8mm-phyboard-polis-rdk.dtb \
        imx8mm-venice.dtb \
        imx8mm-venice-gw71xx-0x.dtb \
        imx8mm-venice-gw72xx-0x.dtb \
        imx8mm-venice-gw7904.dtb \
        imx8mm-venice-gw7905-0x.dtb \
        imx8mm-verdin-wifi-dev.dtb \
 -      phycore-imx8mm.dtb \
        imx8mn-bsh-smm-s2.dtb \
        imx8mn-bsh-smm-s2pro.dtb \
        imx8mn-ddr4-evk.dtb \
        imx8mp-dhcom-som-overlay-eth1xfast.dtbo \
        imx8mp-dhcom-som-overlay-eth2xfast.dtbo \
        imx8mp-dhcom-pdk-overlay-eth2xfast.dtbo \
 +      imx8mp-debix-model-a.dtb \
        imx8mp-dhcom-pdk2.dtb \
        imx8mp-dhcom-pdk3.dtb \
        imx8mp-dhcom-pdk3-overlay-rev100.dtbo \
@@@ -1382,9 -1382,6 +1383,9 @@@ dtb-$(CONFIG_STM32MP15x) += 
        stm32mp15xx-dhcor-drc-compact.dtb \
        stm32mp15xx-dhcor-testbench.dtb
  
 +dtb-$(CONFIG_STM32MP25X) += \
 +      stm32mp257f-ev1.dtb
 +
  dtb-$(CONFIG_SOC_K3_AM654) += \
        k3-am654-base-board.dtb \
        k3-am654-r5-base-board.dtb \
@@@ -1401,10 -1398,7 +1402,10 @@@ dtb-$(CONFIG_SOC_K3_J721E) += k3-j721e-
                              k3-j7200-common-proc-board.dtb \
                              k3-j7200-r5-common-proc-board.dtb \
                              k3-j721e-sk.dtb \
 -                            k3-j721e-r5-sk.dtb
 +                            k3-j721e-r5-sk.dtb \
 +                            k3-j721e-beagleboneai64.dtb \
 +                            k3-j721e-r5-beagleboneai64.dtb
 +
  dtb-$(CONFIG_SOC_K3_J721S2) += k3-am68-sk-base-board.dtb\
                               k3-am68-sk-r5-base-board.dtb\
                               k3-j721s2-common-proc-board.dtb\
@@@ -1516,6 -1510,8 +1517,8 @@@ targets += $(dtb-y
  # Add any required device tree compiler flags here
  DTC_FLAGS += -a 0x8
  
+ DTC_FLAGS_imx8mp-dhcom-pdk3-overlay-rev100 += -Wno-avoid_default_addr_size -Wno-reg_format
  PHONY += dtbs
  dtbs: $(addprefix $(obj)/, $(dtb-y))
        @:
index 3dd01e36a4afffe46cddb1e34d45d29e609b5934,c6856823c64d2d14e352d3b4264539d374653b4e..3b5f14ecb044bca5d478b6f922cdd1aa1a77627a
@@@ -1,12 -1,17 +1,18 @@@
  #include "imx7s-u-boot.dtsi"
  
  /{
 -    aliases {
 -        mmc0 = &usdhc3;
 -        usb0 = &usbotg1;
 -        display0 = &lcdif;
 -    };
 +      aliases {
 +              mmc0 = &usdhc3;
 +              mmc1 = &usdhc1;
 +              usb0 = &usbotg1;
 +              display0 = &lcdif;
 +      };
+       wdt-reboot {
+               compatible = "wdt-reboot";
+               wdt = <&wdog1>;
+               bootph-pre-ram;
+       };
  };
  
  &usbotg1 {
        };
  };
  
+ &wdog1 {
+       bootph-pre-ram;
+ };
  &iomuxc {
        pinctrl_backlight: backlight {
                fsl,pins = <
index 5cf97a5ea952430df11cd9b1c1f298b941c21cb5,a24eb7446015abf6d1f65900ac948e4195e75414..47219957b58c028ba46f438cd3fa966832636544
@@@ -56,6 -56,7 +56,7 @@@ int enable_i2c_clk(unsigned char enable
  static struct imx_int_pll_rate_table imx8mm_fracpll_tbl[] = {
        PLL_1443X_RATE(1000000000U, 250, 3, 1, 0),
        PLL_1443X_RATE(933000000U, 311, 4, 1, 0),
+       PLL_1443X_RATE(900000000U, 300, 8, 0, 0),
        PLL_1443X_RATE(800000000U, 300, 9, 0, 0),
        PLL_1443X_RATE(750000000U, 250, 8, 0, 0),
        PLL_1443X_RATE(650000000U, 325, 3, 2, 0),
@@@ -904,13 -905,6 +905,13 @@@ static int imx8mp_fec_interface_init(st
  
        return 0;
  }
 +#else
 +static int imx8mp_fec_interface_init(struct udevice *dev,
 +                                   phy_interface_t interface_type,
 +                                   bool mx8mp)
 +{
 +      return 0;
 +}
  #endif
  
  int board_interface_eth_init(struct udevice *dev, phy_interface_t interface_type)
index 9131eda970b03fe07dffec775c2ce8bcc8c3c982,a3a865d65ca5e343da85f06d58a849cf58f40f5b..4fe72664c4b31555b63a7bced51d0da6d8ad669c
                clocks = <&clk_fixed>,
                         <&clk_sandbox 1>,
                         <&clk_sandbox 0>,
+                        <&ccf 11>,
                         <&clk_sandbox 3>,
                         <&clk_sandbox 2>;
-               clock-names = "fixed", "i2c", "spi", "uart2", "uart1";
+               clock-names = "fixed", "i2c", "spi", "i2c_root", "uart2", "uart1";
        };
  
        clk-test2 {
  
        ccf: clk-ccf {
                compatible = "sandbox,clk-ccf";
+               #clock-cells = <1>;
        };
  
        efi-media {
                                compatible = "sandbox,arm-ffa";
                };
        };
 +
 +      nand-controller {
 +              #address-cells = <1>;
 +              #size-cells = <0>;
 +              compatible = "sandbox,nand";
 +
 +              nand@0 {
 +                      reg = <0>;
 +                      nand-ecc-mode = "soft";
 +                      sandbox,id = [00 e3];
 +                      sandbox,erasesize = <(8 * 1024)>;
 +                      sandbox,oobsize = <16>;
 +                      sandbox,pagesize = <512>;
 +                      sandbox,pages = <0x2000>;
 +                      sandbox,err-count = <1>;
 +                      sandbox,err-step-size = <512>;
 +              };
 +
 +              /* MT29F64G08AKABA */
 +              nand@1 {
 +                      reg = <1>;
 +                      nand-ecc-mode = "soft_bch";
 +                      sandbox,id = [2C 48 00 26 89 00 00 00];
 +                      sandbox,onfi = [
 +                              4f 4e 46 49 0e 00 5a 00
 +                              ff 01 00 00 00 00 03 00
 +                              00 00 00 00 00 00 00 00
 +                              00 00 00 00 00 00 00 00
 +                              4d 49 43 52 4f 4e 20 20
 +                              20 20 20 20 4d 54 32 39
 +                              46 36 34 47 30 38 41 4b
 +                              41 42 41 43 35 20 20 20
 +                              2c 00 00 00 00 00 00 00
 +                              00 00 00 00 00 00 00 00
 +                              00 10 00 00 e0 00 00 02
 +                              00 00 1c 00 80 00 00 00
 +                              00 10 00 00 02 23 01 50
 +                              00 01 05 01 00 00 04 00
 +                              04 01 1e 00 00 00 00 00
 +                              00 00 00 00 00 00 00 00
 +                              0e 1f 00 1f 00 f4 01 ac
 +                              0d 19 00 c8 00 00 00 00
 +                              00 00 00 00 00 00 0a 07
 +                              19 00 00 00 00 00 00 00
 +                              00 00 00 00 01 00 01 00
 +                              00 00 04 10 01 81 04 02
 +                              02 01 1e 90 00 00 00 00
 +                              00 00 00 00 00 00 00 00
 +                              00 00 00 00 00 00 00 00
 +                              00 00 00 00 00 00 00 00
 +                              00 00 00 00 00 00 00 00
 +                              00 00 00 00 00 00 00 00
 +                              00 00 00 00 00 00 00 00
 +                              00 00 00 00 00 00 00 00
 +                              00 00 00 00 00 00 00 00
 +                              00 00 00 00 00 03 20 7d
 +                      ];
 +                      sandbox,erasesize = <(512 * 1024)>;
 +                      sandbox,oobsize = <224>;
 +                      sandbox,pagesize = <4096>;
 +                      sandbox,pages = <0x200000>;
 +                      sandbox,err-count = <3>;
 +                      sandbox,err-step-size = <512>;
 +              };
 +      };
  };
  
  #include "sandbox_pmic.dtsi"
index 2b7dbca8f75511af5c67f5f58ab478e96f9d1e06,1daf2e7ac79ad252f178a3de9d9287b975b43861..d4e04ad148612c867944bccdf34c4419930f482b
@@@ -6,6 -6,7 +6,6 @@@
  #ifndef __SANDBOX_CLK_H
  #define __SANDBOX_CLK_H
  
 -#include <common.h>
  #include <clk.h>
  #include <dt-structs.h>
  #include <linux/clk-provider.h>
@@@ -38,6 -39,7 +38,7 @@@ enum sandbox_clk_test_id 
        SANDBOX_CLK_TEST_ID_FIXED,
        SANDBOX_CLK_TEST_ID_SPI,
        SANDBOX_CLK_TEST_ID_I2C,
+       SANDBOX_CLK_TEST_ID_I2C_ROOT,
        SANDBOX_CLK_TEST_ID_DEVM1,
        SANDBOX_CLK_TEST_ID_DEVM2,
        SANDBOX_CLK_TEST_ID_DEVM_NULL,
index 2709c9ca1eb3af36da0e06cad6892258fd45b7a0,c490dcfeab8304debadfe31ef7d8af063fc221d6..cdd0d0d95f612588b2a763c2d649696229cae09c
@@@ -54,11 -54,12 +54,11 @@@ config BOARD_SPECIFIC_OPTIONS # dumm
        imply SCSI_AHCI
        imply AHCI_PCI
        imply E1000
-       imply NVME
        imply PCI
+       imply NVME_PCI
        imply PCIE_ECAM_GENERIC
        imply DM_RNG
        imply SCSI
 -      imply DM_SCSI
        imply SYS_NS16550
        imply SIFIVE_SERIAL
        imply HTIF_CONSOLE if 64BIT
@@@ -81,7 -82,5 +81,7 @@@
        imply USB_XHCI_PCI
        imply USB_KEYBOARD
        imply CMD_USB
 +      imply UFS
 +      imply UFS_PCI
  
  endif
index e23f9af20da0b47bcdf5e875bca47ffb8cced473,3e7c5d64c30478971bf279ac15eb0c6928b17490..7a59a786d98d6816034aa2f662a8767f7f1643b6
@@@ -66,7 -66,7 +66,7 @@@ int dram_init(void
  }
  
  static iomux_v3_cfg_t const flash_detection_pads[] = {
-       MX7D_PAD_SD3_RESET_B__GPIO6_IO11 | MUX_PAD_CTRL(FLASH_DETECTION_CTRL),
+       MX7D_PAD_SD3_RESET_B__GPIO6_IO11 | MUX_PAD_CTRL(FLASH_DETECTION_CTRL) | MUX_MODE_SION,
  };
  
  static iomux_v3_cfg_t const uart1_pads[] = {
@@@ -193,9 -193,9 +193,9 @@@ int board_init(void
        gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  
        /*
-        * Enable GPIO on NAND_WE_B/eMMC_RST with 100k pull-down. eMMC_RST
+        * Enable GPIO SION on NAND_WE_B/eMMC_RST with 100k pull-down. eMMC_RST
         * is pulled high with 4.7k for eMMC devices. This allows to reliably
-        * detect eMMC/NAND flash
+        * detect eMMC vs NAND flash.
         */
        imx_iomux_v3_setup_multiple_pads(flash_detection_pads, ARRAY_SIZE(flash_detection_pads));
        gpio_request(FLASH_DET_GPIO, "flash-detection-gpio");
@@@ -279,7 -279,7 +279,7 @@@ int checkboard(void
        printf("Model: Toradex Colibri iMX7%c\n",
               is_cpu_type(MXC_CPU_MX7D) ? 'D' : 'S');
  
 -      return 0;
 +      return tdx_checkboard();
  }
  
  #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
@@@ -360,17 -360,13 +360,17 @@@ int board_late_init(void
        setup_lcd();
  #endif
  
 -#if defined(CONFIG_CMD_USB_SDP)
 -      if (is_boot_from_usb()) {
 -              printf("Serial Downloader recovery mode, using sdp command\n");
 +      if (IS_ENABLED(CONFIG_USB) && is_boot_from_usb()) {
                env_set("bootdelay", "0");
 -              env_set("bootcmd", "sdp 0");
 +              if (IS_ENABLED(CONFIG_CMD_USB_SDP)) {
 +                      printf("Serial Downloader recovery mode, using sdp command\n");
 +                      env_set("bootcmd", "sdp 0");
 +              } else if (IS_ENABLED(CONFIG_CMD_FASTBOOT)) {
 +                      printf("Fastboot recovery mode, using fastboot command\n");
 +                      env_set("bootcmd", "fastboot usb 0");
 +              }
        }
 -#endif
 +
        if (is_emmc)
                env_set("variant", "-emmc");
        else
diff --combined boot/bootmeth_efi.c
index d46bff51d8a7a6ec0fbcbf1d960c08e709673ccc,446cb73140eea22c3a12b3046be16a020e3c06c7..00060f7d25a571c91848b7b5073dfb2cd6434ea6
@@@ -160,7 -160,6 +160,6 @@@ static int efiload_read_file(struct boo
        if (ret)
                return log_msg_ret("read", ret);
        bflow->buf = map_sysmem(addr, bflow->size);
-       bflow->flags |= BOOTFLOWF_STATIC_BUF;
  
        set_efi_bootdev(desc, bflow);
  
@@@ -313,6 -312,7 +312,7 @@@ static int distro_efi_try_bootflow_file
                 */
        } else {
                log_debug("No device tree available\n");
+               bflow->flags |= BOOTFLOWF_USE_BUILTIN_FDT;
        }
  
        return 0;
@@@ -323,7 -323,7 +323,7 @@@ static int distro_efi_read_bootflow_net
        char file_addr[17], fname[256];
        char *tftp_argv[] = {"tftp", file_addr, fname, NULL};
        struct cmd_tbl cmdtp = {};      /* dummy */
-       const char *addr_str, *fdt_addr_str;
+       const char *addr_str, *fdt_addr_str, *bootfile_name;
        int ret, arch, size;
        ulong addr, fdt_addr;
        char str[36];
        ret = env_set("bootp_vci", str);
        if (ret)
                return log_msg_ret("vcs", ret);
-       ret = env_set_ulong("bootp_arch", arch);
+       ret = env_set_hex("bootp_arch", arch);
        if (ret)
                return log_msg_ret("ars", ret);
  
                return log_msg_ret("sz", -EINVAL);
        bflow->size = size;
  
+     /* bootfile should be setup by dhcp*/
+       bootfile_name = env_get("bootfile");
+       if (!bootfile_name)
+               return log_msg_ret("bootfile_name", ret);
+       bflow->fname = strdup(bootfile_name);
        /* do the hideous EFI hack */
        efi_set_bootdev("Net", "", bflow->fname, map_sysmem(addr, 0),
                        bflow->size);
                bflow->fdt_addr = fdt_addr;
        } else {
                log_debug("No device tree available\n");
+               bflow->flags |= BOOTFLOWF_USE_BUILTIN_FDT;
        }
  
        bflow->state = BOOTFLOWST_READY;
@@@ -396,6 -403,12 +403,12 @@@ static int distro_efi_read_bootflow(str
  {
        int ret;
  
+       /*
+        * bootmeth_efi doesn't allocate any buffer neither for blk nor net device
+        * set flag to avoid freeing static buffer.
+        */
+       bflow->flags |= BOOTFLOWF_STATIC_BUF;
        if (bootmeth_uses_network(bflow)) {
                /* we only support reading from one device, so ignore 'dev' */
                ret = distro_efi_read_bootflow_net(bflow);
  static int distro_efi_boot(struct udevice *dev, struct bootflow *bflow)
  {
        ulong kernel, fdt;
 -      char cmd[50];
        int ret;
  
        kernel = env_get_hex("kernel_addr_r", 0);
                        return log_msg_ret("read", ret);
  
                /*
-                * use the provided device tree if available, else fall back to
-                * the control FDT
+                * use the provided device tree if not using the built-in fdt
                 */
-               if (bflow->fdt_fname)
+               if (bflow->flags & ~BOOTFLOWF_USE_BUILTIN_FDT)
                        fdt = bflow->fdt_addr;
-               else
-                       fdt = (ulong)map_to_sysmem(gd->fdt_blob);
        } else {
                /*
                 * This doesn't actually work for network devices:
                fdt = env_get_hex("fdt_addr_r", 0);
        }
  
-       if (efi_binary_run(map_sysmem(kernel, 0), 0, map_sysmem(fdt, 0)))
-               return log_msg_ret("run", -EINVAL);
 -      /*
 -       * At some point we can add a real interface to bootefi so we can call
 -       * this directly. For now, go through the CLI, like distro boot.
 -       */
+       if (bflow->flags & BOOTFLOWF_USE_BUILTIN_FDT) {
+               log_debug("Booting with built-in fdt\n");
 -              snprintf(cmd, sizeof(cmd), "bootefi %lx", kernel);
++              if (efi_binary_run(map_sysmem(kernel, 0), 0,
++                                 EFI_FDT_USE_INTERNAL))
++                      return log_msg_ret("run", -EINVAL);
+       } else {
+               log_debug("Booting with external fdt\n");
 -              snprintf(cmd, sizeof(cmd), "bootefi %lx %lx", kernel, fdt);
++              if (efi_binary_run(map_sysmem(kernel, 0), 0,
++                                 map_sysmem(fdt, 0)))
++                      return log_msg_ret("run", -EINVAL);
+       }
  
 -      if (run_command(cmd, 0))
 -              return log_msg_ret("run", -EINVAL);
 -
        return 0;
  }
  
diff --combined common/spl/Kconfig
index fc284a5bffce275c545138a7c8243ae0923aafef,c521b02f4a34c1407e5abd071ce43f64b6e1e180..cf7ffc9b1126014b98baf8005989c3c001b9cb9a
@@@ -183,7 -183,6 +183,7 @@@ config SPL_SYS_REPORT_STACK_F_USAG
  
  config SPL_SHOW_ERRORS
        bool "Show more information when something goes wrong"
 +      depends on SPL_LIBCOMMON_SUPPORT
        help
          This enabled more verbose error messages and checking when something
          goes wrong in SPL. For example, it shows the error code when U-Boot
@@@ -280,15 -279,8 +280,15 @@@ config SPL_BOARD_INI
          spl_board_init() from board_init_r(). This function should be
          provided by the board.
  
 +config SPL_LOAD_BLOCK
 +      bool
 +      help
 +        Support loading images from block devices. This adds a bl_len member
 +        to struct spl_load_info.
 +
  config SPL_BOOTROM_SUPPORT
        bool "Support returning to the BOOTROM"
 +      select SPL_LOAD_BLOCK if MACH_IMX
        help
          Some platforms (e.g. the Rockchip RK3368) provide support in their
          ROM for loading the next boot-stage after performing basic setup
@@@ -378,7 -370,7 +378,7 @@@ config SPL_STAC
        default 0x93ffb8 if ARCH_MX6 && MX6_OCRAM_256KB
        default 0x91ffb8 if ARCH_MX6 && !MX6_OCRAM_256KB
        default 0x118000 if MACH_SUN50I_H6
-       default 0x58000 if MACH_SUN50I_H616
+       default 0x52a00 if MACH_SUN50I_H616
        default 0x40000 if MACH_SUN8I_R528
        default 0x54000 if MACH_SUN50I || MACH_SUN50I_H5
        default 0x18000 if MACH_SUN9I
@@@ -481,11 -473,6 +481,11 @@@ config SPL_DISPLAY_PRIN
          banner ("U-Boot SPL ..."). This function should be provided by
          the board.
  
 +config SPL_SYS_MMCSD_RAW_MODE
 +      bool
 +      help
 +        Support booting from an MMC without a filesystem.
 +
  config SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
        bool "MMC raw mode: by sector"
        default y if ARCH_SUNXI || ARCH_DAVINCI || ARCH_UNIPHIER || \
                     ARCH_AT91 || ARCH_ZYNQ || ARCH_KEYSTONE || OMAP34XX || \
                     OMAP44XX || OMAP54XX || AM33XX || AM43XX || \
                     TARGET_SIFIVE_UNLEASHED || TARGET_SIFIVE_UNMATCHED
 +      select SPL_LOAD_BLOCK if SPL_MMC
 +      select SPL_SYS_MMCSD_RAW_MODE if SPL_MMC
        help
          Use sector number for specifying U-Boot location on MMC/SD in
          raw mode.
@@@ -532,8 -517,6 +532,8 @@@ config SYS_MMCSD_RAW_MODE_U_BOOT_DATA_P
  
  config SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
        bool "MMC Raw mode: by partition"
 +      select SPL_LOAD_BLOCK if SPL_MMC
 +      select SPL_SYS_MMCSD_RAW_MODE if SPL_MMC
        help
          Use a partition for loading U-Boot when using MMC/SD in raw mode.
  
@@@ -700,22 -683,6 +700,22 @@@ config SPL_FS_FA
          filesystem from within SPL. Support for the underlying block
          device (e.g. MMC or USB) must be enabled separately.
  
 +config SPL_FS_FAT_DMA_ALIGN
 +      bool "Use DMA-aligned buffers with FAT"
 +      depends on SPL_FS_FAT
 +      select SPL_LOAD_BLOCK
 +      default y if SPL_LOAD_FIT
 +      help
 +        The FAT filesystem driver tries to ensure that the reads it issues to
 +        the block subsystem use DMA-aligned buffers. If the supplied buffer is
 +        not DMA-aligned, the FAT driver will use a bounce-buffer and read
 +        block-by-block. This is separate from the bounce-buffer used by the
 +        block subsystem (CONFIG_BOUNCE_BUFFER).
 +
 +        Enable this config to align buffers passed to the FAT filesystem
 +        driver. This will speed up reads, but will increase the size of U-Boot
 +        by around 60 bytes.
 +
  config SPL_FS_LOAD_PAYLOAD_NAME
        string "File to load for U-Boot from the filesystem"
        depends on SPL_FS_EXT4 || SPL_FS_FAT || SPL_FS_SQUASHFS || SPL_SEMIHOSTING
@@@ -890,7 -857,7 +890,7 @@@ config SPL_MPC8XXX_INIT_DD
          allows DRAM to be set up before loading U-Boot into that DRAM,
          where it can run.
  
 -config SPL_MTD_SUPPORT
 +config SPL_MTD
        bool "Support MTD drivers"
        help
          Enable support for MTD (Memory Technology Device) within SPL. MTD
@@@ -909,7 -876,6 +909,7 @@@ config SPL_MUSB_NE
  
  config SPL_NAND_SUPPORT
        bool "Support NAND flash"
 +      select SPL_LOAD_BLOCK
        help
          Enable support for NAND (Negative AND) flash in SPL. NAND flash
          can be used to allow SPL to load U-Boot from supported devices.
@@@ -1135,8 -1101,6 +1135,8 @@@ config SYS_OS_BAS
  config SPL_FALCON_BOOT_MMCSD
        bool "Enable Falcon boot from MMC or SD media"
        depends on SPL_OS_BOOT && SPL_MMC
 +      select SPL_LOAD_BLOCK
 +      select SPL_SYS_MMCSD_RAW_MODE
        help
          Select this if the Falcon mode OS image mode is on MMC or SD media.
  
@@@ -1295,6 -1259,7 +1295,6 @@@ config SPL_SATA_RAW_U_BOOT_SECTO
  config SPL_NVME
        bool "NVM Express device support"
        depends on BLK
 -      select HAVE_BLOCK_DEVICE
        select FS_LOADER
        select SPL_BLK_FS
        help
index 20a38a38280127d39d18ae87ea72b3fa29288e4f,06e10869bc13c64a7aecfd05b78af6b4f35efe6a..6a4244e3084508e9aaf17c15ef5b1d0c68ad426d
@@@ -108,9 -108,6 +108,9 @@@ CONFIG_CMD_USB=
  CONFIG_CMD_USB_SDP=y
  CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_DHCP=y
 +CONFIG_CMD_DHCP6=y
 +CONFIG_CMD_TFTPPUT=y
 +CONFIG_CMD_WGET=y
  CONFIG_CMD_MII=y
  CONFIG_CMD_PING=y
  CONFIG_CMD_PXE=y
@@@ -151,8 -148,6 +151,8 @@@ CONFIG_NET_RANDOM_ETHADDR=
  CONFIG_NETCONSOLE=y
  CONFIG_IP_DEFRAG=y
  CONFIG_TFTP_TSIZE=y
 +CONFIG_PROT_TCP_SACK=y
 +CONFIG_IPV6=y
  CONFIG_SPL_DM=y
  CONFIG_REGMAP=y
  CONFIG_SYSCON=y
@@@ -162,6 -157,7 +162,7 @@@ CONFIG_SPL_CLK_COMPOSITE_CCF=
  CONFIG_CLK_COMPOSITE_CCF=y
  CONFIG_SPL_CLK_IMX8MM=y
  CONFIG_CLK_IMX8MM=y
+ CONFIG_FSL_CAAM=y
  CONFIG_DFU_TFTP=y
  CONFIG_DFU_TIMEOUT=y
  CONFIG_DFU_MMC=y
index 7ee454076c6038c611ddcaf58085b89e33b9d7ca,3974e376b85bf98f0e17f914334df52e82e88cd3..f5914ac2a802c4b8ef7180c7c1bb11ac4ef53766
@@@ -114,9 -114,6 +114,9 @@@ CONFIG_CMD_USB=
  CONFIG_CMD_USB_SDP=y
  CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_DHCP=y
 +CONFIG_CMD_DHCP6=y
 +CONFIG_CMD_TFTPPUT=y
 +CONFIG_CMD_WGET=y
  CONFIG_CMD_MII=y
  CONFIG_CMD_PING=y
  CONFIG_CMD_PXE=y
@@@ -158,8 -155,6 +158,8 @@@ CONFIG_NET_RANDOM_ETHADDR=
  CONFIG_NETCONSOLE=y
  CONFIG_IP_DEFRAG=y
  CONFIG_TFTP_TSIZE=y
 +CONFIG_PROT_TCP_SACK=y
 +CONFIG_IPV6=y
  CONFIG_SPL_DM=y
  CONFIG_REGMAP=y
  CONFIG_SYSCON=y
@@@ -169,6 -164,8 +169,8 @@@ CONFIG_SPL_CLK_COMPOSITE_CCF=
  CONFIG_CLK_COMPOSITE_CCF=y
  CONFIG_SPL_CLK_IMX8MP=y
  CONFIG_CLK_IMX8MP=y
+ CONFIG_FSL_CAAM=y
+ CONFIG_IMX8M_DRAM_INLINE_ECC=y
  CONFIG_DFU_TFTP=y
  CONFIG_DFU_TIMEOUT=y
  CONFIG_DFU_MMC=y
index 54c02dfd7abab5a0b08a2a046beaefe58dce53db,09481343bc6ce429ca50b3dbc7ad8f14417299c6..3f9b0e3733cc9ba74345681fba0cc0e3f13980f1
@@@ -109,9 -109,6 +109,9 @@@ CONFIG_CMD_USB=
  CONFIG_CMD_USB_SDP=y
  CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_DHCP=y
 +CONFIG_CMD_DHCP6=y
 +CONFIG_CMD_TFTPPUT=y
 +CONFIG_CMD_WGET=y
  CONFIG_CMD_MII=y
  CONFIG_CMD_PING=y
  CONFIG_CMD_PXE=y
@@@ -154,8 -151,6 +154,8 @@@ CONFIG_NET_RANDOM_ETHADDR=
  CONFIG_NETCONSOLE=y
  CONFIG_IP_DEFRAG=y
  CONFIG_TFTP_TSIZE=y
 +CONFIG_PROT_TCP_SACK=y
 +CONFIG_IPV6=y
  CONFIG_SPL_DM=y
  CONFIG_REGMAP=y
  CONFIG_SYSCON=y
@@@ -165,6 -160,7 +165,7 @@@ CONFIG_SPL_CLK_COMPOSITE_CCF=
  CONFIG_CLK_COMPOSITE_CCF=y
  CONFIG_SPL_CLK_IMX8MP=y
  CONFIG_CLK_IMX8MP=y
+ CONFIG_FSL_CAAM=y
  CONFIG_DFU_TFTP=y
  CONFIG_DFU_TIMEOUT=y
  CONFIG_DFU_MMC=y
index 6799f0c8b73e1b538d551f90bac222cf20d0f916,86121c7d9a4b366f3ba4742ddb796fa05b665907..50c21d51b8d5cd11af09936b2780b22a5e89219e
@@@ -111,9 -111,6 +111,9 @@@ CONFIG_CMD_USB=
  CONFIG_CMD_USB_SDP=y
  CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_DHCP=y
 +CONFIG_CMD_DHCP6=y
 +CONFIG_CMD_TFTPPUT=y
 +CONFIG_CMD_WGET=y
  CONFIG_CMD_MII=y
  CONFIG_CMD_PING=y
  CONFIG_CMD_PXE=y
@@@ -156,8 -153,6 +156,8 @@@ CONFIG_NET_RANDOM_ETHADDR=
  CONFIG_NETCONSOLE=y
  CONFIG_IP_DEFRAG=y
  CONFIG_TFTP_TSIZE=y
 +CONFIG_PROT_TCP_SACK=y
 +CONFIG_IPV6=y
  CONFIG_SPL_DM=y
  CONFIG_REGMAP=y
  CONFIG_SYSCON=y
@@@ -167,6 -162,7 +167,7 @@@ CONFIG_SPL_CLK_COMPOSITE_CCF=
  CONFIG_CLK_COMPOSITE_CCF=y
  CONFIG_SPL_CLK_IMX8MP=y
  CONFIG_CLK_IMX8MP=y
+ CONFIG_FSL_CAAM=y
  CONFIG_DFU_TFTP=y
  CONFIG_DFU_TIMEOUT=y
  CONFIG_DFU_MMC=y
index 0b59971723cc667d8a8192656a1595a90faa3ca0,08998a63e756aff4c8fce08ec61d47ec462291bd..683053b42f6dbb67bfd608cdf76b7eb826288614
@@@ -7,6 -7,9 +7,6 @@@ CONFIG_SPL_LIBCOMMON_SUPPORT=
  CONFIG_SPL_LIBGENERIC_SUPPORT=y
  CONFIG_ENV_SIZE=0x1000
  CONFIG_ENV_OFFSET=0x400000
 -CONFIG_SYS_I2C_MXC_I2C1=y
 -CONFIG_SYS_I2C_MXC_I2C2=y
 -CONFIG_SYS_I2C_MXC_I2C3=y
  CONFIG_DM_GPIO=y
  CONFIG_DEFAULT_DEVICE_TREE="imx8mp-evk"
  CONFIG_SPL_TEXT_BASE=0x920000
@@@ -71,6 -74,7 +71,7 @@@ CONFIG_SYS_MMC_ENV_DEV=
  CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
  CONFIG_USE_ETHPRIME=y
  CONFIG_ETHPRIME="eth1"
+ CONFIG_NET_RANDOM_ETHADDR=y
  CONFIG_SPL_DM=y
  CONFIG_CLK_COMPOSITE_CCF=y
  CONFIG_CLK_IMX8MP=y
@@@ -85,6 -89,8 +86,6 @@@ CONFIG_FASTBOOT_MMC_USER_SUPPORT=
  CONFIG_MXC_GPIO=y
  CONFIG_DM_PCA953X=y
  CONFIG_DM_I2C=y
 -# CONFIG_SPL_DM_I2C is not set
 -CONFIG_SPL_SYS_I2C_LEGACY=y
  CONFIG_LED=y
  CONFIG_LED_GPIO=y
  CONFIG_SUPPORT_EMMC_BOOT=y
@@@ -105,16 -111,15 +106,16 @@@ CONFIG_PHY_IMX8MQ_USB=
  CONFIG_PINCTRL=y
  CONFIG_SPL_PINCTRL=y
  CONFIG_PINCTRL_IMX8M=y
 -CONFIG_SPL_POWER_LEGACY=y
  CONFIG_POWER_DOMAIN=y
  CONFIG_IMX8M_POWER_DOMAIN=y
  CONFIG_IMX8MP_HSIOMIX_BLKCTRL=y
 -CONFIG_POWER_PCA9450=y
 +CONFIG_DM_PMIC=y
 +CONFIG_DM_PMIC_PCA9450=y
 +CONFIG_SPL_DM_PMIC_PCA9450=y
  CONFIG_DM_REGULATOR=y
 +CONFIG_DM_REGULATOR_PCA9450=y
  CONFIG_DM_REGULATOR_FIXED=y
  CONFIG_DM_REGULATOR_GPIO=y
 -CONFIG_SPL_POWER_I2C=y
  CONFIG_DM_SERIAL=y
  CONFIG_MXC_UART=y
  CONFIG_SYSRESET=y
diff --combined lib/Kconfig
index 9ae846ea5f75d1891f211242457e09a8ade67125,d47df6bb1cfae2349ec7015e32f9d157002f08c5..37ac14f7bab7c11ea7a6026502618654e606e974
@@@ -74,13 -74,6 +74,13 @@@ config HAVE_PRIVATE_LIBGC
  config LIB_UUID
        bool
  
 +config RANDOM_UUID
 +      bool "GPT Random UUID generation"
 +      select LIB_UUID
 +      help
 +        Enable the generation of partitions with random UUIDs if none
 +        are provided.
 +
  config SPL_LIB_UUID
        depends on SPL
        bool
@@@ -100,7 -93,7 +100,7 @@@ config SEMIHOSTIN
  
  config SEMIHOSTING_FALLBACK
        bool "Recover gracefully when semihosting fails"
 -      depends on SEMIHOSTING && (ARM64 || RISCV)
 +      depends on SEMIHOSTING
        default y
        help
          Normally, if U-Boot makes a semihosting call and no debugger is
@@@ -123,7 -116,7 +123,7 @@@ config SPL_SEMIHOSTIN
  
  config SPL_SEMIHOSTING_FALLBACK
        bool "Recover gracefully when semihosting fails in SPL"
 -      depends on SPL_SEMIHOSTING && (ARM64 || RISCV)
 +      depends on SPL_SEMIHOSTING
        select ARMV8_SPL_EXCEPTION_VECTORS if ARM64
        default y
        help
@@@ -1002,7 -995,7 +1002,7 @@@ config GENERATE_SMBIOS_TABL
  
          Check http://www.dmtf.org/standards/smbios for details.
  
-         See also SMBIOS_SYSINFO which allows SMBIOS values to be provided in
+         See also SYSINFO_SMBIOS which allows SMBIOS values to be provided in
          the devicetree.
  
  endmenu
diff --combined lib/efi_loader/Makefile
index 0a2cb6e3c4766df2c4e660ecfab99e9c25964dc7,d476df112b85876a57fd80bf189081a360feae2b..24d33d5409995d989082fbf7c69d761619afbc7a
@@@ -42,7 -42,7 +42,7 @@@ targets += initrddump.
  endif
  
  obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
 -obj-$(CONFIG_CMD_BOOTEFI_BOOTMGR) += efi_bootmgr.o
 +obj-$(CONFIG_BOOTEFI_BOOTMGR) += efi_bootmgr.o
  obj-y += efi_boottime.o
  obj-y += efi_helper.o
  obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o
@@@ -51,9 -51,7 +51,7 @@@ obj-y += efi_console.
  obj-y += efi_device_path.o
  obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_device_path_to_text.o
  obj-$(CONFIG_EFI_DEVICE_PATH_UTIL) += efi_device_path_utilities.o
- ifeq ($(CONFIG_GENERATE_ACPI_TABLE),)
  obj-y += efi_dt_fixup.o
- endif
  obj-y += efi_file.o
  obj-$(CONFIG_EFI_LOADER_HII) += efi_hii.o
  obj-y += efi_image_loader.o
index 56d97f23827bb6a7ac15c10bd5e3ac3a0e037c2b,a40762c74c8380540170c6a8c447ce4a72d1288e..e815fa06c8bd3ff5fc182feb624342ccefa6bebc
@@@ -3,56 -3,22 +3,56 @@@
   *  EFI boot manager
   *
   *  Copyright (c) 2017 Rob Clark
 + *  For the code moved from cmd/bootefi.c
 + *  Copyright (c) 2016 Alexander Graf
   */
  
  #define LOG_CATEGORY LOGC_EFI
  
 +#include <blk.h>
 +#include <blkmap.h>
  #include <common.h>
  #include <charset.h>
 +#include <dm.h>
  #include <log.h>
  #include <malloc.h>
 +#include <net.h>
  #include <efi_default_filename.h>
  #include <efi_loader.h>
  #include <efi_variable.h>
  #include <asm/unaligned.h>
  
 +/* TODO: temporarily added here; clean up later */
 +#include <bootm.h>
 +#include <efi_selftest.h>
 +#include <env.h>
 +#include <mapmem.h>
 +#include <asm/global_data.h>
 +#include <linux/libfdt.h>
 +#include <linux/libfdt_env.h>
 +
 +DECLARE_GLOBAL_DATA_PTR;
 +
  static const struct efi_boot_services *bs;
  static const struct efi_runtime_services *rs;
  
 +/**
 + * struct uridp_context - uri device path resource
 + *
 + * @image_size:               image size
 + * @image_addr:               image address
 + * @loaded_dp:                pointer to loaded device path
 + * @ramdisk_blk_dev:  pointer to the ramdisk blk device
 + * @mem_handle:               efi_handle to the loaded PE-COFF image
 + */
 +struct uridp_context {
 +      ulong image_size;
 +      ulong image_addr;
 +      struct efi_device_path *loaded_dp;
 +      struct udevice *ramdisk_blk_dev;
 +      efi_handle_t mem_handle;
 +};
 +
  const efi_guid_t efi_guid_bootmenu_auto_generated =
                EFICONFIG_AUTO_GENERATED_ENTRY_GUID;
  
@@@ -202,364 -168,6 +202,364 @@@ out
        return ret;
  }
  
 +/**
 + * mount_image() - mount the image with blkmap
 + *
 + * @lo_label: u16 label string of load option
 + * @addr:     image address
 + * @size:     image size
 + * Return:    pointer to the UCLASS_BLK udevice, NULL if failed
 + */
 +static struct udevice *mount_image(u16 *lo_label, ulong addr, ulong size)
 +{
 +      int err;
 +      struct blkmap *bm;
 +      struct udevice *bm_dev;
 +      char *label = NULL, *p;
 +
 +      label = efi_alloc(utf16_utf8_strlen(lo_label) + 1);
 +      if (!label)
 +              return NULL;
 +
 +      p = label;
 +      utf16_utf8_strcpy(&p, lo_label);
 +      err = blkmap_create_ramdisk(label, addr, size, &bm_dev);
 +      if (err) {
 +              efi_free_pool(label);
 +              return NULL;
 +      }
 +      bm = dev_get_plat(bm_dev);
 +
 +      efi_free_pool(label);
 +
 +      return bm->blk;
 +}
 +
 +/**
 + * search_default_file() - search default file
 + *
 + * @dev:      pointer to the UCLASS_BLK or UCLASS_PARTITION udevice
 + * @loaded_dp:        pointer to default file device path
 + * Return:    status code
 + */
 +static efi_status_t search_default_file(struct udevice *dev,
 +                                      struct efi_device_path **loaded_dp)
 +{
 +      efi_status_t ret;
 +      efi_handle_t handle;
 +      u16 *default_file_name = NULL;
 +      struct efi_file_handle *root, *f;
 +      struct efi_device_path *dp = NULL, *fp = NULL;
 +      struct efi_simple_file_system_protocol *file_system;
 +      struct efi_device_path *device_path, *full_path = NULL;
 +
 +      if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle)) {
 +              log_warning("DM_TAG_EFI not found\n");
 +              return EFI_INVALID_PARAMETER;
 +      }
 +
 +      ret = EFI_CALL(bs->open_protocol(handle, &efi_guid_device_path,
 +                                       (void **)&device_path, efi_root, NULL,
 +                                       EFI_OPEN_PROTOCOL_GET_PROTOCOL));
 +      if (ret != EFI_SUCCESS)
 +              return ret;
 +
 +      ret = EFI_CALL(bs->open_protocol(handle, &efi_simple_file_system_protocol_guid,
 +                                       (void **)&file_system, efi_root, NULL,
 +                                       EFI_OPEN_PROTOCOL_GET_PROTOCOL));
 +      if (ret != EFI_SUCCESS)
 +              return ret;
 +
 +      ret = EFI_CALL(file_system->open_volume(file_system, &root));
 +      if (ret != EFI_SUCCESS)
 +              return ret;
 +
 +      full_path = expand_media_path(device_path);
 +      ret = efi_dp_split_file_path(full_path, &dp, &fp);
 +      if (ret != EFI_SUCCESS)
 +              goto err;
 +
 +      default_file_name = efi_dp_str(fp);
 +      efi_free_pool(dp);
 +      efi_free_pool(fp);
 +      if (!default_file_name) {
 +              ret = EFI_OUT_OF_RESOURCES;
 +              goto err;
 +      }
 +
 +      ret = EFI_CALL(root->open(root, &f, default_file_name,
 +                                EFI_FILE_MODE_READ, 0));
 +      efi_free_pool(default_file_name);
 +      if (ret != EFI_SUCCESS)
 +              goto err;
 +
 +      EFI_CALL(f->close(f));
 +      EFI_CALL(root->close(root));
 +
 +      *loaded_dp = full_path;
 +
 +      return EFI_SUCCESS;
 +
 +err:
 +      EFI_CALL(root->close(root));
 +      efi_free_pool(full_path);
 +
 +      return ret;
 +}
 +
 +/**
 + * check_disk_has_default_file() - load the default file
 + *
 + * @blk:      pointer to the UCLASS_BLK udevice
 + * @dp:               pointer to default file device path
 + * Return:    status code
 + */
 +static efi_status_t check_disk_has_default_file(struct udevice *blk,
 +                                              struct efi_device_path **dp)
 +{
 +      efi_status_t ret;
 +      struct udevice *partition;
 +
 +      /* image that has no partition table but a file system */
 +      ret = search_default_file(blk, dp);
 +      if (ret == EFI_SUCCESS)
 +              return ret;
 +
 +      /* try the partitions */
 +      device_foreach_child(partition, blk) {
 +              enum uclass_id id;
 +
 +              id = device_get_uclass_id(partition);
 +              if (id != UCLASS_PARTITION)
 +                      continue;
 +
 +              ret = search_default_file(partition, dp);
 +              if (ret == EFI_SUCCESS)
 +                      return ret;
 +      }
 +
 +      return EFI_NOT_FOUND;
 +}
 +
 +/**
 + * prepare_loaded_image() - prepare ramdisk for downloaded image
 + *
 + * @label:    label of load option
 + * @addr:     image address
 + * @size:     image size
 + * @dp:               pointer to default file device path
 + * @blk:      pointer to created blk udevice
 + * Return:    status code
 + */
 +static efi_status_t prepare_loaded_image(u16 *label, ulong addr, ulong size,
 +                                       struct efi_device_path **dp,
 +                                       struct udevice **blk)
 +{
 +      efi_status_t ret;
 +      struct udevice *ramdisk_blk;
 +
 +      ramdisk_blk = mount_image(label, addr, size);
 +      if (!ramdisk_blk)
 +              return EFI_LOAD_ERROR;
 +
 +      ret = check_disk_has_default_file(ramdisk_blk, dp);
 +      if (ret != EFI_SUCCESS) {
 +              log_info("Cannot boot from downloaded image\n");
 +              goto err;
 +      }
 +
 +      /*
 +       * TODO: expose the ramdisk to OS.
 +       * Need to pass the ramdisk information by the architecture-specific
 +       * methods such as 'pmem' device-tree node.
 +       */
 +      ret = efi_add_memory_map(addr, size, EFI_RESERVED_MEMORY_TYPE);
 +      if (ret != EFI_SUCCESS) {
 +              log_err("Memory reservation failed\n");
 +              goto err;
 +      }
 +
 +      *blk = ramdisk_blk;
 +
 +      return EFI_SUCCESS;
 +
 +err:
 +      if (blkmap_destroy(ramdisk_blk->parent))
 +              log_err("Destroying blkmap failed\n");
 +
 +      return ret;
 +}
 +
 +/**
 + * efi_bootmgr_release_uridp_resource() - cleanup uri device path resource
 + *
 + * @ctx:      event context
 + * Return:    status code
 + */
 +efi_status_t efi_bootmgr_release_uridp_resource(struct uridp_context *ctx)
 +{
 +      efi_status_t ret = EFI_SUCCESS;
 +
 +      if (!ctx)
 +              return ret;
 +
 +      /* cleanup for iso or img image */
 +      if (ctx->ramdisk_blk_dev) {
 +              ret = efi_add_memory_map(ctx->image_addr, ctx->image_size,
 +                                       EFI_CONVENTIONAL_MEMORY);
 +              if (ret != EFI_SUCCESS)
 +                      log_err("Reclaiming memory failed\n");
 +
 +              if (blkmap_destroy(ctx->ramdisk_blk_dev->parent)) {
 +                      log_err("Destroying blkmap failed\n");
 +                      ret = EFI_DEVICE_ERROR;
 +              }
 +      }
 +
 +      /* cleanup for PE-COFF image */
 +      if (ctx->mem_handle) {
 +              ret = efi_uninstall_multiple_protocol_interfaces(
 +                      ctx->mem_handle, &efi_guid_device_path, ctx->loaded_dp,
 +                      NULL);
 +              if (ret != EFI_SUCCESS)
 +                      log_err("Uninstall device_path protocol failed\n");
 +      }
 +
 +      efi_free_pool(ctx->loaded_dp);
 +      free(ctx);
 +
 +      return ret;
 +}
 +
 +/**
 + * efi_bootmgr_image_return_notify() - return to efibootmgr callback
 + *
 + * @event:    the event for which this notification function is registered
 + * @context:  event context
 + */
 +static void EFIAPI efi_bootmgr_image_return_notify(struct efi_event *event,
 +                                                 void *context)
 +{
 +      efi_status_t ret;
 +
 +      EFI_ENTRY("%p, %p", event, context);
 +      ret = efi_bootmgr_release_uridp_resource(context);
 +      EFI_EXIT(ret);
 +}
 +
 +/**
 + * try_load_from_uri_path() - Handle the URI device path
 + *
 + * @uridp:    uri device path
 + * @lo_label: label of load option
 + * @handle:   pointer to handle for newly installed image
 + * Return:    status code
 + */
 +static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp,
 +                                         u16 *lo_label,
 +                                         efi_handle_t *handle)
 +{
 +      char *s;
 +      int err;
 +      int uri_len;
 +      efi_status_t ret;
 +      void *source_buffer;
 +      efi_uintn_t source_size;
 +      struct uridp_context *ctx;
 +      struct udevice *blk = NULL;
 +      struct efi_event *event = NULL;
 +      efi_handle_t mem_handle = NULL;
 +      struct efi_device_path *loaded_dp;
 +      static ulong image_size, image_addr;
 +
 +      ctx = calloc(1, sizeof(struct uridp_context));
 +      if (!ctx)
 +              return EFI_OUT_OF_RESOURCES;
 +
 +      s = env_get("loadaddr");
 +      if (!s) {
 +              log_err("Error: loadaddr is not set\n");
 +              ret = EFI_INVALID_PARAMETER;
 +              goto err;
 +      }
 +
 +      image_addr = hextoul(s, NULL);
 +      err = wget_with_dns(image_addr, uridp->uri);
 +      if (err < 0) {
 +              ret = EFI_INVALID_PARAMETER;
 +              goto err;
 +      }
 +
 +      image_size = env_get_hex("filesize", 0);
 +      if (!image_size) {
 +              ret = EFI_INVALID_PARAMETER;
 +              goto err;
 +      }
 +
 +      /*
 +       * If the file extension is ".iso" or ".img", mount it and try to load
 +       * the default file.
 +       * If the file is PE-COFF image, load the downloaded file.
 +       */
 +      uri_len = strlen(uridp->uri);
 +      if (!strncmp(&uridp->uri[uri_len - 4], ".iso", 4) ||
 +          !strncmp(&uridp->uri[uri_len - 4], ".img", 4)) {
 +              ret = prepare_loaded_image(lo_label, image_addr, image_size,
 +                                         &loaded_dp, &blk);
 +              if (ret != EFI_SUCCESS)
 +                      goto err;
 +
 +              source_buffer = NULL;
 +              source_size = 0;
 +      } else if (efi_check_pe((void *)image_addr, image_size, NULL) == EFI_SUCCESS) {
 +              /*
 +               * loaded_dp must exist until efi application returns,
 +               * will be freed in return_to_efibootmgr event callback.
 +               */
 +              loaded_dp = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE,
 +                                          (uintptr_t)image_addr, image_size);
 +              ret = efi_install_multiple_protocol_interfaces(
 +                      &mem_handle, &efi_guid_device_path, loaded_dp, NULL);
 +              if (ret != EFI_SUCCESS)
 +                      goto err;
 +
 +              source_buffer = (void *)image_addr;
 +              source_size = image_size;
 +      } else {
 +              log_err("Error: file type is not supported\n");
 +              ret = EFI_UNSUPPORTED;
 +              goto err;
 +      }
 +
 +      ctx->image_size = image_size;
 +      ctx->image_addr = image_addr;
 +      ctx->loaded_dp = loaded_dp;
 +      ctx->ramdisk_blk_dev = blk;
 +      ctx->mem_handle = mem_handle;
 +
 +      ret = EFI_CALL(efi_load_image(false, efi_root, loaded_dp, source_buffer,
 +                                    source_size, handle));
 +      if (ret != EFI_SUCCESS)
 +              goto err;
 +
 +      /* create event for cleanup when the image returns or error occurs */
 +      ret = efi_create_event(EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
 +                             efi_bootmgr_image_return_notify, ctx,
 +                             &efi_guid_event_group_return_to_efibootmgr,
 +                             &event);
 +      if (ret != EFI_SUCCESS) {
 +              log_err("Creating event failed\n");
 +              goto err;
 +      }
 +
 +      return ret;
 +
 +err:
 +      efi_bootmgr_release_uridp_resource(ctx);
 +
 +      return ret;
 +}
 +
  /**
   * try_load_entry() - try to load image for boot option
   *
@@@ -603,13 -211,6 +603,13 @@@ static efi_status_t try_load_entry(u16 
                if (EFI_DP_TYPE(lo.file_path, MEDIA_DEVICE, FILE_PATH)) {
                        /* file_path doesn't contain a device path */
                        ret = try_load_from_short_path(lo.file_path, handle);
 +              } else if (EFI_DP_TYPE(lo.file_path, MESSAGING_DEVICE, MSG_URI)) {
 +                      if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT))
 +                              ret = try_load_from_uri_path(
 +                                      (struct efi_device_path_uri *)lo.file_path,
 +                                      lo.label, handle);
 +                      else
 +                              ret = EFI_LOAD_ERROR;
                } else {
                        file_path = expand_media_path(lo.file_path);
                        ret = EFI_CALL(efi_load_image(true, efi_root, file_path,
                return EFI_SUCCESS;
        return ret;
  }
- #if !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)
 +
 +static struct efi_device_path *bootefi_image_path;
 +static struct efi_device_path *bootefi_device_path;
 +static void *image_addr;
 +static size_t image_size;
 +
 +/**
 + * efi_get_image_parameters() - return image parameters
 + *
 + * @img_addr:         address of loaded image in memory
 + * @img_size:         size of loaded image
 + */
 +void efi_get_image_parameters(void **img_addr, size_t *img_size)
 +{
 +      *img_addr = image_addr;
 +      *img_size = image_size;
 +}
 +
 +/**
 + * efi_clear_bootdev() - clear boot device
 + */
 +void efi_clear_bootdev(void)
 +{
 +      efi_free_pool(bootefi_device_path);
 +      efi_free_pool(bootefi_image_path);
 +      bootefi_device_path = NULL;
 +      bootefi_image_path = NULL;
 +      image_addr = NULL;
 +      image_size = 0;
 +}
 +
 +/**
 + * efi_set_bootdev() - set boot device
 + *
 + * This function is called when a file is loaded, e.g. via the 'load' command.
 + * We use the path to this file to inform the UEFI binary about the boot device.
 + *
 + * @dev:              device, e.g. "MMC"
 + * @devnr:            number of the device, e.g. "1:2"
 + * @path:             path to file loaded
 + * @buffer:           buffer with file loaded
 + * @buffer_size:      size of file loaded
 + */
 +void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
 +                   void *buffer, size_t buffer_size)
 +{
 +      struct efi_device_path *device, *image;
 +      efi_status_t ret;
 +
 +      log_debug("dev=%s, devnr=%s, path=%s, buffer=%p, size=%zx\n", dev,
 +                devnr, path, buffer, buffer_size);
 +
 +      /* Forget overwritten image */
 +      if (buffer + buffer_size >= image_addr &&
 +          image_addr + image_size >= buffer)
 +              efi_clear_bootdev();
 +
 +      /* Remember only PE-COFF and FIT images */
 +      if (efi_check_pe(buffer, buffer_size, NULL) != EFI_SUCCESS) {
 +              if (IS_ENABLED(CONFIG_FIT) &&
 +                  !fit_check_format(buffer, IMAGE_SIZE_INVAL)) {
 +                      /*
 +                       * FIT images of type EFI_OS are started via command
 +                       * bootm. We should not use their boot device with the
 +                       * bootefi command.
 +                       */
 +                      buffer = 0;
 +                      buffer_size = 0;
 +              } else {
 +                      log_debug("- not remembering image\n");
 +                      return;
 +              }
 +      }
 +
 +      /* efi_set_bootdev() is typically called repeatedly, recover memory */
 +      efi_clear_bootdev();
 +
 +      image_addr = buffer;
 +      image_size = buffer_size;
 +
 +      ret = efi_dp_from_name(dev, devnr, path, &device, &image);
 +      if (ret == EFI_SUCCESS) {
 +              bootefi_device_path = device;
 +              if (image) {
 +                      /* FIXME: image should not contain device */
 +                      struct efi_device_path *image_tmp = image;
 +
 +                      efi_dp_split_file_path(image, &device, &image);
 +                      efi_free_pool(image_tmp);
 +              }
 +              bootefi_image_path = image;
 +              log_debug("- boot device %pD\n", device);
 +              if (image)
 +                      log_debug("- image %pD\n", image);
 +      } else {
 +              log_debug("- efi_dp_from_name() failed, err=%lx\n", ret);
 +              efi_clear_bootdev();
 +      }
 +}
 +
 +/**
 + * efi_env_set_load_options() - set load options from environment variable
 + *
 + * @handle:           the image handle
 + * @env_var:          name of the environment variable
 + * @load_options:     pointer to load options (output)
 + * Return:            status code
 + */
 +efi_status_t efi_env_set_load_options(efi_handle_t handle,
 +                                    const char *env_var,
 +                                    u16 **load_options)
 +{
 +      const char *env = env_get(env_var);
 +      size_t size;
 +      u16 *pos;
 +      efi_status_t ret;
 +
 +      *load_options = NULL;
 +      if (!env)
 +              return EFI_SUCCESS;
 +      size = sizeof(u16) * (utf8_utf16_strlen(env) + 1);
 +      pos = calloc(size, 1);
 +      if (!pos)
 +              return EFI_OUT_OF_RESOURCES;
 +      *load_options = pos;
 +      utf8_utf16_strcpy(&pos, env);
 +      ret = efi_set_load_options(handle, size, *load_options);
 +      if (ret != EFI_SUCCESS) {
 +              free(*load_options);
 +              *load_options = NULL;
 +      }
 +      return ret;
 +}
 +
- #endif /* !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) */
 +/**
 + * copy_fdt() - Copy the device tree to a new location available to EFI
 + *
 + * The FDT is copied to a suitable location within the EFI memory map.
 + * Additional 12 KiB are added to the space in case the device tree needs to be
 + * expanded later with fdt_open_into().
 + *
 + * @fdtp:     On entry a pointer to the flattened device tree.
 + *            On exit a pointer to the copy of the flattened device tree.
 + *            FDT start
 + * Return:    status code
 + */
 +static efi_status_t copy_fdt(void **fdtp)
 +{
 +      unsigned long fdt_ram_start = -1L, fdt_pages;
 +      efi_status_t ret = 0;
 +      void *fdt, *new_fdt;
 +      u64 new_fdt_addr;
 +      uint fdt_size;
 +      int i;
 +
 +      for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
 +              u64 ram_start = gd->bd->bi_dram[i].start;
 +              u64 ram_size = gd->bd->bi_dram[i].size;
 +
 +              if (!ram_size)
 +                      continue;
 +
 +              if (ram_start < fdt_ram_start)
 +                      fdt_ram_start = ram_start;
 +      }
 +
 +      /*
 +       * Give us at least 12 KiB of breathing room in case the device tree
 +       * needs to be expanded later.
 +       */
 +      fdt = *fdtp;
 +      fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) + 0x3000);
 +      fdt_size = fdt_pages << EFI_PAGE_SHIFT;
 +
 +      ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
 +                               EFI_ACPI_RECLAIM_MEMORY, fdt_pages,
 +                               &new_fdt_addr);
 +      if (ret != EFI_SUCCESS) {
 +              log_err("ERROR: Failed to reserve space for FDT\n");
 +              goto done;
 +      }
 +      new_fdt = (void *)(uintptr_t)new_fdt_addr;
 +      memcpy(new_fdt, fdt, fdt_totalsize(fdt));
 +      fdt_set_totalsize(new_fdt, fdt_size);
 +
 +      *fdtp = (void *)(uintptr_t)new_fdt_addr;
 +done:
 +      return ret;
 +}
 +
 +/**
 + * get_config_table() - get configuration table
 + *
 + * @guid:     GUID of the configuration table
 + * Return:    pointer to configuration table or NULL
 + */
 +static void *get_config_table(const efi_guid_t *guid)
 +{
 +      size_t i;
 +
 +      for (i = 0; i < systab.nr_tables; i++) {
 +              if (!guidcmp(guid, &systab.tables[i].guid))
 +                      return systab.tables[i].table;
 +      }
 +      return NULL;
 +}
 +
- #if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)
-       if (fdt) {
 +/**
 + * efi_install_fdt() - install device tree
 + *
 + * If fdt is not EFI_FDT_USE_INTERNAL, the device tree located at that memory
 + * address will be installed as configuration table, otherwise the device
 + * tree located at the address indicated by environment variable fdt_addr or as
 + * fallback fdtcontroladdr will be used.
 + *
 + * On architectures using ACPI tables device trees shall not be installed as
 + * configuration table.
 + *
 + * @fdt:      address of device tree or EFI_FDT_USE_INTERNAL to use
 + *            the hardware device tree as indicated by environment variable
 + *            fdt_addr or as fallback the internal device tree as indicated by
 + *            the environment variable fdtcontroladdr
 + * Return:    status code
 + */
 +efi_status_t efi_install_fdt(void *fdt)
 +{
++      struct bootm_headers img = { 0 };
++      efi_status_t ret;
++
 +      /*
 +       * The EBBR spec requires that we have either an FDT or an ACPI table
 +       * but not both.
 +       */
-               return EFI_SUCCESS;
-       }
- #else
-       struct bootm_headers img = { 0 };
-       efi_status_t ret;
++      if (CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) && fdt)
 +              log_warning("WARNING: Can't have ACPI table and device tree - ignoring DT.\n");
-       /* Create memory reservations as indicated by the device tree */
-       efi_carve_out_dt_rsv(fdt);
 +
 +      if (fdt == EFI_FDT_USE_INTERNAL) {
 +              const char *fdt_opt;
 +              uintptr_t fdt_addr;
 +
 +              /* Look for device tree that is already installed */
 +              if (get_config_table(&efi_guid_fdt))
 +                      return EFI_SUCCESS;
 +              /* Check if there is a hardware device tree */
 +              fdt_opt = env_get("fdt_addr");
 +              /* Use our own device tree as fallback */
 +              if (!fdt_opt) {
 +                      fdt_opt = env_get("fdtcontroladdr");
 +                      if (!fdt_opt) {
 +                              log_err("ERROR: need device tree\n");
 +                              return EFI_NOT_FOUND;
 +                      }
 +              }
 +              fdt_addr = hextoul(fdt_opt, NULL);
 +              if (!fdt_addr) {
 +                      log_err("ERROR: invalid $fdt_addr or $fdtcontroladdr\n");
 +                      return EFI_LOAD_ERROR;
 +              }
 +              fdt = map_sysmem(fdt_addr, 0);
 +      }
 +
 +      /* Install device tree */
 +      if (fdt_check_header(fdt)) {
 +              log_err("ERROR: invalid device tree\n");
 +              return EFI_LOAD_ERROR;
 +      }
 +
++      /* Create memory reservations as indicated by the device tree */
++      efi_carve_out_dt_rsv(fdt);
++
++      if (CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE))
++              return EFI_SUCCESS;
++
 +      /* Prepare device tree for payload */
 +      ret = copy_fdt(&fdt);
 +      if (ret) {
 +              log_err("ERROR: out of memory\n");
 +              return EFI_OUT_OF_RESOURCES;
 +      }
 +
 +      if (image_setup_libfdt(&img, fdt, NULL)) {
 +              log_err("ERROR: failed to process device tree\n");
 +              return EFI_LOAD_ERROR;
 +      }
 +
- #endif /* GENERATE_ACPI_TABLE */
 +      efi_try_purge_kaslr_seed(fdt);
 +
 +      if (CONFIG_IS_ENABLED(EFI_TCG2_PROTOCOL_MEASURE_DTB)) {
 +              ret = efi_tcg2_measure_dtb(fdt);
 +              if (ret == EFI_SECURITY_VIOLATION) {
 +                      log_err("ERROR: failed to measure DTB\n");
 +                      return ret;
 +              }
 +      }
 +
 +      /* Install device tree as UEFI table */
 +      ret = efi_install_configuration_table(&efi_guid_fdt, fdt);
 +      if (ret != EFI_SUCCESS) {
 +              log_err("ERROR: failed to install device tree\n");
 +              return ret;
 +      }
 +
 +      return EFI_SUCCESS;
 +}
 +
 +/**
 + * do_bootefi_exec() - execute EFI binary
 + *
 + * The image indicated by @handle is started. When it returns the allocated
 + * memory for the @load_options is freed.
 + *
 + * @handle:           handle of loaded image
 + * @load_options:     load options
 + * Return:            status code
 + *
 + * Load the EFI binary into a newly assigned memory unwinding the relocation
 + * information, install the loaded image protocol, and call the binary.
 + */
 +static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options)
 +{
 +      efi_status_t ret;
 +      efi_uintn_t exit_data_size = 0;
 +      u16 *exit_data = NULL;
 +      struct efi_event *evt;
 +
 +      /* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */
 +      switch_to_non_secure_mode();
 +
 +      /*
 +       * The UEFI standard requires that the watchdog timer is set to five
 +       * minutes when invoking an EFI boot option.
 +       *
 +       * Unified Extensible Firmware Interface (UEFI), version 2.7 Errata A
 +       * 7.5. Miscellaneous Boot Services - EFI_BOOT_SERVICES.SetWatchdogTimer
 +       */
 +      ret = efi_set_watchdog(300);
 +      if (ret != EFI_SUCCESS) {
 +              log_err("ERROR: Failed to set watchdog timer\n");
 +              goto out;
 +      }
 +
 +      /* Call our payload! */
 +      ret = EFI_CALL(efi_start_image(handle, &exit_data_size, &exit_data));
 +      if (ret != EFI_SUCCESS) {
 +              log_err("## Application failed, r = %lu\n",
 +                      ret & ~EFI_ERROR_MASK);
 +              if (exit_data) {
 +                      log_err("## %ls\n", exit_data);
 +                      efi_free_pool(exit_data);
 +              }
 +      }
 +
 +      efi_restore_gd();
 +
 +out:
 +      free(load_options);
 +
 +      if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) {
 +              if (efi_initrd_deregister() != EFI_SUCCESS)
 +                      log_err("Failed to remove loadfile2 for initrd\n");
 +      }
 +
 +      /* Notify EFI_EVENT_GROUP_RETURN_TO_EFIBOOTMGR event group. */
 +      list_for_each_entry(evt, &efi_events, link) {
 +              if (evt->group &&
 +                  !guidcmp(evt->group,
 +                           &efi_guid_event_group_return_to_efibootmgr)) {
 +                      efi_signal_event(evt);
 +                      EFI_CALL(systab.boottime->close_event(evt));
 +                      break;
 +              }
 +      }
 +
 +      /* Control is returned to U-Boot, disable EFI watchdog */
 +      efi_set_watchdog(0);
 +
 +      return ret;
 +}
 +
 +/**
 + * efi_bootmgr_run() - execute EFI boot manager
 + * @fdt:      Flat device tree
 + *
 + * Invoke EFI boot manager and execute a binary depending on
 + * boot options. If @fdt is not NULL, it will be passed to
 + * the executed binary.
 + *
 + * Return:    status code
 + */
 +efi_status_t efi_bootmgr_run(void *fdt)
 +{
 +      efi_handle_t handle;
 +      void *load_options;
 +      efi_status_t ret;
 +
 +      /* Initialize EFI drivers */
 +      ret = efi_init_obj_list();
 +      if (ret != EFI_SUCCESS) {
 +              log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n",
 +                      ret & ~EFI_ERROR_MASK);
 +              return CMD_RET_FAILURE;
 +      }
 +
 +      ret = efi_install_fdt(fdt);
 +      if (ret != EFI_SUCCESS)
 +              return ret;
 +
 +      ret = efi_bootmgr_load(&handle, &load_options);
 +      if (ret != EFI_SUCCESS) {
 +              log_notice("EFI boot manager: Cannot load any image\n");
 +              return ret;
 +      }
 +
 +      return do_bootefi_exec(handle, load_options);
 +}
 +
 +/**
 + * efi_run_image() - run loaded UEFI image
 + *
 + * @source_buffer:    memory address of the UEFI image
 + * @source_size:      size of the UEFI image
 + * Return:            status code
 + */
 +efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size)
 +{
 +      efi_handle_t mem_handle = NULL, handle;
 +      struct efi_device_path *file_path = NULL;
 +      struct efi_device_path *msg_path;
 +      efi_status_t ret, ret2;
 +      u16 *load_options;
 +
 +      if (!bootefi_device_path || !bootefi_image_path) {
 +              log_debug("Not loaded from disk\n");
 +              /*
 +               * Special case for efi payload not loaded from disk,
 +               * such as 'bootefi hello' or for example payload
 +               * loaded directly into memory via JTAG, etc:
 +               */
 +              file_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE,
 +                                          (uintptr_t)source_buffer,
 +                                          source_size);
 +              /*
 +               * Make sure that device for device_path exist
 +               * in load_image(). Otherwise, shell and grub will fail.
 +               */
 +              ret = efi_install_multiple_protocol_interfaces(&mem_handle,
 +                                                             &efi_guid_device_path,
 +                                                             file_path, NULL);
 +              if (ret != EFI_SUCCESS)
 +                      goto out;
 +              msg_path = file_path;
 +      } else {
 +              file_path = efi_dp_append(bootefi_device_path,
 +                                        bootefi_image_path);
 +              msg_path = bootefi_image_path;
 +              log_debug("Loaded from disk\n");
 +      }
 +
 +      log_info("Booting %pD\n", msg_path);
 +
 +      ret = EFI_CALL(efi_load_image(false, efi_root, file_path, source_buffer,
 +                                    source_size, &handle));
 +      if (ret != EFI_SUCCESS) {
 +              log_err("Loading image failed\n");
 +              goto out;
 +      }
 +
 +      /* Transfer environment variable as load options */
 +      ret = efi_env_set_load_options(handle, "bootargs", &load_options);
 +      if (ret != EFI_SUCCESS)
 +              goto out;
 +
 +      ret = do_bootefi_exec(handle, load_options);
 +
 +out:
 +      ret2 = efi_uninstall_multiple_protocol_interfaces(mem_handle,
 +                                                        &efi_guid_device_path,
 +                                                        file_path, NULL);
 +      efi_free_pool(file_path);
 +      return (ret != EFI_SUCCESS) ? ret : ret2;
 +}
 +
 +/**
 + * efi_binary_run() - run loaded UEFI image
 + *
 + * @image:    memory address of the UEFI image
 + * @size:     size of the UEFI image
 + * @fdt:      device-tree
 + *
 + * Execute an EFI binary image loaded at @image.
 + * @size may be zero if the binary is loaded with U-Boot load command.
 + *
 + * Return:    status code
 + */
 +efi_status_t efi_binary_run(void *image, size_t size, void *fdt)
 +{
 +      efi_status_t ret;
 +
 +      /* Initialize EFI drivers */
 +      ret = efi_init_obj_list();
 +      if (ret != EFI_SUCCESS) {
 +              log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n",
 +                      ret & ~EFI_ERROR_MASK);
 +              return -1;
 +      }
 +
 +      ret = efi_install_fdt(fdt);
 +      if (ret != EFI_SUCCESS)
 +              return ret;
 +
 +      return efi_run_image(image, size);
 +}
index 3767fa2db429a5cf3f53ebc74511ed7980e50b5b,fad0476a88184005f7009f3f6fe3ca49c8cc8170..644bebee6b77f244d8458f9b7b6af93679f96be9
@@@ -90,9 -90,6 +90,9 @@@ const efi_guid_t efi_guid_event_group_r
  /* event group ResetSystem() invoked (before ExitBootServices) */
  const efi_guid_t efi_guid_event_group_reset_system =
                        EFI_EVENT_GROUP_RESET_SYSTEM;
 +/* event group return to efibootmgr */
 +const efi_guid_t efi_guid_event_group_return_to_efibootmgr =
 +                      EFI_EVENT_GROUP_RETURN_TO_EFIBOOTMGR;
  /* GUIDs of the Load File and Load File2 protocols */
  const efi_guid_t efi_guid_load_file_protocol = EFI_LOAD_FILE_PROTOCOL_GUID;
  const efi_guid_t efi_guid_load_file2_protocol = EFI_LOAD_FILE2_PROTOCOL_GUID;
@@@ -715,7 -712,7 +715,7 @@@ efi_status_t efi_create_event(uint32_t 
                              void (EFIAPI *notify_function) (
                                        struct efi_event *event,
                                        void *context),
 -                            void *notify_context, efi_guid_t *group,
 +                            void *notify_context, const efi_guid_t *group,
                              struct efi_event **event)
  {
        struct efi_event *evt;
@@@ -793,7 -790,7 +793,7 @@@ efi_status_t EFIAPI efi_create_event_ex
                                                        struct efi_event *event,
                                                        void *context),
                                        void *notify_context,
 -                                      efi_guid_t *event_group,
 +                                      const efi_guid_t *event_group,
                                        struct efi_event **event)
  {
        efi_status_t ret;
@@@ -1342,7 -1339,7 +1342,7 @@@ static efi_status_t efi_disconnect_all_
                                 const efi_guid_t *protocol,
                                 efi_handle_t child_handle)
  {
-       efi_uintn_t number_of_drivers, tmp;
+       efi_uintn_t number_of_drivers;
        efi_handle_t *driver_handle_buffer;
        efi_status_t r, ret;
  
        if (!number_of_drivers)
                return EFI_SUCCESS;
  
-       tmp = number_of_drivers;
        while (number_of_drivers) {
-               ret = EFI_CALL(efi_disconnect_controller(
+               r = EFI_CALL(efi_disconnect_controller(
                                handle,
                                driver_handle_buffer[--number_of_drivers],
                                child_handle));
-               if (ret != EFI_SUCCESS)
-                       goto reconnect;
-       }
-       free(driver_handle_buffer);
-       return ret;
- reconnect:
-       /* Reconnect all disconnected drivers */
-       for (; number_of_drivers < tmp; number_of_drivers++) {
-               r = EFI_CALL(efi_connect_controller(handle,
-                                                   &driver_handle_buffer[number_of_drivers],
-                                                   NULL, true));
                if (r != EFI_SUCCESS)
-                       EFI_PRINT("Failed to reconnect controller\n");
+                       ret = r;
        }
  
        free(driver_handle_buffer);
@@@ -1412,6 -1395,13 +1398,13 @@@ static efi_status_t efi_uninstall_proto
        r = efi_disconnect_all_drivers(handle, protocol, NULL);
        if (r != EFI_SUCCESS) {
                r = EFI_ACCESS_DENIED;
+               /*
+                * This will reconnect all controllers of the handle, even ones
+                * that were not connected before. This can be done better
+                * but we are following the EDKII implementation on this for
+                * now
+                */
+               EFI_CALL(efi_connect_controller(handle, NULL, NULL, true));
                goto out;
        }
        /* Close protocol */