]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - cmd/bootefi.c
Merge CONFIG_BOOTCOUNT and CONFIG_BOOTCOUNT_LIMIT
[people/ms/u-boot.git] / cmd / bootefi.c
index b894403ff6777132327bcb3230cece53c0093fc8..2106ed9c8c8b9af778d814d4921c5d2266acc9bb 100644 (file)
@@ -32,6 +32,9 @@ static void efi_init_obj_list(void)
 {
        efi_obj_list_initalized = 1;
 
+       /* Initialize EFI driver uclass */
+       efi_driver_init();
+
        efi_console_register();
 #ifdef CONFIG_PARTITIONS
        efi_disk_register();
@@ -103,11 +106,11 @@ static void *copy_fdt(void *fdt)
 
        /* Safe fdt location is at 128MB */
        new_fdt_addr = fdt_ram_start + (128 * 1024 * 1024) + fdt_size;
-       if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages,
+       if (efi_allocate_pages(1, EFI_RUNTIME_SERVICES_DATA, fdt_pages,
                               &new_fdt_addr) != EFI_SUCCESS) {
                /* If we can't put it there, put it somewhere */
                new_fdt_addr = (ulong)memalign(EFI_PAGE_SIZE, fdt_size);
-               if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages,
+               if (efi_allocate_pages(1, EFI_RUNTIME_SERVICES_DATA, fdt_pages,
                                       &new_fdt_addr) != EFI_SUCCESS) {
                        printf("ERROR: Failed to reserve space for FDT\n");
                        return NULL;
@@ -122,9 +125,10 @@ static void *copy_fdt(void *fdt)
 }
 
 static efi_status_t efi_do_enter(
-                       void *image_handle, struct efi_system_table *st,
-                       asmlinkage ulong (*entry)(void *image_handle,
-                                                 struct efi_system_table *st))
+                       efi_handle_t image_handle, struct efi_system_table *st,
+                       EFIAPI efi_status_t (*entry)(
+                               efi_handle_t image_handle,
+                               struct efi_system_table *st))
 {
        efi_status_t ret = EFI_LOAD_ERROR;
 
@@ -135,9 +139,9 @@ static efi_status_t efi_do_enter(
 }
 
 #ifdef CONFIG_ARM64
-static efi_status_t efi_run_in_el2(asmlinkage ulong (*entry)(
-                       void *image_handle, struct efi_system_table *st),
-                       void *image_handle, struct efi_system_table *st)
+static efi_status_t efi_run_in_el2(EFIAPI efi_status_t (*entry)(
+                       efi_handle_t image_handle, struct efi_system_table *st),
+                       efi_handle_t image_handle, struct efi_system_table *st)
 {
        /* Enable caches again */
        dcache_enable();
@@ -159,8 +163,8 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,
        struct efi_device_path *memdp = NULL;
        ulong ret;
 
-       ulong (*entry)(void *image_handle, struct efi_system_table *st)
-               asmlinkage;
+       EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,
+                                    struct efi_system_table *st);
        ulong fdt_pages, fdt_size, fdt_start, fdt_end;
        const efi_guid_t fdt_guid = EFI_FDT_GUID;
        bootm_headers_t img = { 0 };
@@ -218,6 +222,8 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,
                efi_install_configuration_table(&fdt_guid, NULL);
        }
 
+       /* Transfer environment variable bootargs as load options */
+       set_load_options(&loaded_image_info, "bootargs");
        /* Load the EFI payload */
        entry = efi_load_pe(efi, &loaded_image_info);
        if (!entry) {
@@ -252,7 +258,8 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,
                dcache_disable();       /* flush cache before switch to EL2 */
 
                /* Move into EL2 and keep running there */
-               armv8_switch_to_el2((ulong)entry, (ulong)&loaded_image_info,
+               armv8_switch_to_el2((ulong)entry,
+                                   (ulong)&loaded_image_info_obj.handle,
                                    (ulong)&systab, 0, (ulong)efi_run_in_el2,
                                    ES_TO_AARCH64);
 
@@ -261,7 +268,7 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,
        }
 #endif
 
-       ret = efi_do_enter(&loaded_image_info, &systab, entry);
+       ret = efi_do_enter(loaded_image_info_obj.handle, &systab, entry);
 
 exit:
        /* image has returned, loaded-image obj goes *poof*: */
@@ -348,9 +355,11 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                /* Transfer environment variable efi_selftest as load options */
                set_load_options(&loaded_image_info, "efi_selftest");
                /* Execute the test */
-               r = efi_selftest(&loaded_image_info, &systab);
+               r = efi_selftest(loaded_image_info_obj.handle, &systab);
+               efi_restore_gd();
                free(loaded_image_info.load_options);
-               return r;
+               list_del(&loaded_image_info_obj.link);
+               return r != EFI_SUCCESS;
        } else
 #endif
        if (!strcmp(argv[1], "bootmgr")) {
@@ -364,6 +373,9 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                saddr = argv[1];
 
                addr = simple_strtoul(saddr, NULL, 16);
+               /* Check that a numeric value was passed */
+               if (!addr && *saddr != '0')
+                       return CMD_RET_USAGE;
 
                if (argc > 2) {
                        sfdt = argv[2];
@@ -399,7 +411,7 @@ static char bootefi_help_text[] =
        "    Use environment variable efi_selftest to select a single test.\n"
        "    Use 'setenv efi_selftest list' to enumerate all tests.\n"
 #endif
-       "bootmgr [fdt addr]\n"
+       "bootefi bootmgr [fdt addr]\n"
        "  - load and boot EFI payload based on BootOrder/BootXXXX variables.\n"
        "\n"
        "    If specified, the device tree located at <fdt address> gets\n"
@@ -432,6 +444,8 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path)
                int part;
 
                desc = blk_get_dev(dev, simple_strtol(devnr, NULL, 10));
+               if (!desc)
+                       return;
                part = parse_partnum(devnr);
 
                bootefi_device_path = efi_dp_from_part(desc, part);