1b9939336SAlexander Graf /* 2b9939336SAlexander Graf * EFI application loader 3b9939336SAlexander Graf * 4b9939336SAlexander Graf * Copyright (c) 2016 Alexander Graf 5b9939336SAlexander Graf * 6b9939336SAlexander Graf * SPDX-License-Identifier: GPL-2.0+ 7b9939336SAlexander Graf */ 8b9939336SAlexander Graf 9b9939336SAlexander Graf #include <common.h> 10b9939336SAlexander Graf #include <command.h> 119d922450SSimon Glass #include <dm.h> 12b9939336SAlexander Graf #include <efi_loader.h> 13b9939336SAlexander Graf #include <errno.h> 14b9939336SAlexander Graf #include <libfdt.h> 15b9939336SAlexander Graf #include <libfdt_env.h> 16ad0c1a3dSAlexander Graf #include <memalign.h> 170d9d501fSAlexander Graf #include <asm/global_data.h> 18e275458cSSimon Glass #include <asm-generic/sections.h> 19e275458cSSimon Glass #include <linux/linkage.h> 200d9d501fSAlexander Graf 210d9d501fSAlexander Graf DECLARE_GLOBAL_DATA_PTR; 22b9939336SAlexander Graf 23*7cbc1241SHeinrich Schuchardt static uint8_t efi_obj_list_initalized; 24*7cbc1241SHeinrich Schuchardt 25b9939336SAlexander Graf /* 26b9939336SAlexander Graf * When booting using the "bootefi" command, we don't know which 27b9939336SAlexander Graf * physical device the file came from. So we create a pseudo-device 28b9939336SAlexander Graf * called "bootefi" with the device path /bootefi. 29b9939336SAlexander Graf * 30b9939336SAlexander Graf * In addition to the originating device we also declare the file path 31b9939336SAlexander Graf * of "bootefi" based loads to be /bootefi. 32b9939336SAlexander Graf */ 330f4060ebSAlexander Graf static struct efi_device_path_file_path bootefi_image_path[] = { 34b9939336SAlexander Graf { 35b9939336SAlexander Graf .dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE, 36b9939336SAlexander Graf .dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH, 370f4060ebSAlexander Graf .dp.length = sizeof(bootefi_image_path[0]), 38b9939336SAlexander Graf .str = { 'b','o','o','t','e','f','i' }, 39b9939336SAlexander Graf }, { 40b9939336SAlexander Graf .dp.type = DEVICE_PATH_TYPE_END, 41b9939336SAlexander Graf .dp.sub_type = DEVICE_PATH_SUB_TYPE_END, 420f4060ebSAlexander Graf .dp.length = sizeof(bootefi_image_path[0]), 43b9939336SAlexander Graf } 44b9939336SAlexander Graf }; 45b9939336SAlexander Graf 46c07ad7c0SAlexander Graf static struct efi_device_path_file_path bootefi_device_path[] = { 47c07ad7c0SAlexander Graf { 48c07ad7c0SAlexander Graf .dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE, 49c07ad7c0SAlexander Graf .dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH, 50c07ad7c0SAlexander Graf .dp.length = sizeof(bootefi_image_path[0]), 51c07ad7c0SAlexander Graf .str = { 'b','o','o','t','e','f','i' }, 52c07ad7c0SAlexander Graf }, { 53c07ad7c0SAlexander Graf .dp.type = DEVICE_PATH_TYPE_END, 54c07ad7c0SAlexander Graf .dp.sub_type = DEVICE_PATH_SUB_TYPE_END, 55c07ad7c0SAlexander Graf .dp.length = sizeof(bootefi_image_path[0]), 56c07ad7c0SAlexander Graf } 57c07ad7c0SAlexander Graf }; 58c07ad7c0SAlexander Graf 59b9939336SAlexander Graf /* The EFI loaded_image interface for the image executed via "bootefi" */ 60b9939336SAlexander Graf static struct efi_loaded_image loaded_image_info = { 61c07ad7c0SAlexander Graf .device_handle = bootefi_device_path, 620f4060ebSAlexander Graf .file_path = bootefi_image_path, 63b9939336SAlexander Graf }; 64b9939336SAlexander Graf 65b9939336SAlexander Graf /* The EFI object struct for the image executed via "bootefi" */ 66b9939336SAlexander Graf static struct efi_object loaded_image_info_obj = { 67b9939336SAlexander Graf .handle = &loaded_image_info, 68b9939336SAlexander Graf .protocols = { 69b9939336SAlexander Graf { 70b9939336SAlexander Graf /* 71b9939336SAlexander Graf * When asking for the loaded_image interface, just 72b9939336SAlexander Graf * return handle which points to loaded_image_info 73b9939336SAlexander Graf */ 74b9939336SAlexander Graf .guid = &efi_guid_loaded_image, 75b5349f74Sxypron.glpk@gmx.de .protocol_interface = &loaded_image_info, 76b9939336SAlexander Graf }, 77b9939336SAlexander Graf { 78b9939336SAlexander Graf /* 79b9939336SAlexander Graf * When asking for the device path interface, return 80c07ad7c0SAlexander Graf * bootefi_device_path 81b9939336SAlexander Graf */ 82b9939336SAlexander Graf .guid = &efi_guid_device_path, 83b5349f74Sxypron.glpk@gmx.de .protocol_interface = bootefi_device_path, 84b9939336SAlexander Graf }, 8588adae5eSxypron.glpk@gmx.de { 8688adae5eSxypron.glpk@gmx.de .guid = &efi_guid_console_control, 8788adae5eSxypron.glpk@gmx.de .protocol_interface = (void *) &efi_console_control 8888adae5eSxypron.glpk@gmx.de }, 89cc5b7081Sxypron.glpk@gmx.de { 90cc5b7081Sxypron.glpk@gmx.de .guid = &efi_guid_device_path_to_text_protocol, 91cc5b7081Sxypron.glpk@gmx.de .protocol_interface = (void *) &efi_device_path_to_text 92cc5b7081Sxypron.glpk@gmx.de }, 93b9939336SAlexander Graf }, 94b9939336SAlexander Graf }; 95b9939336SAlexander Graf 96b9939336SAlexander Graf /* The EFI object struct for the device the "bootefi" image was loaded from */ 97b9939336SAlexander Graf static struct efi_object bootefi_device_obj = { 98c07ad7c0SAlexander Graf .handle = bootefi_device_path, 99b9939336SAlexander Graf .protocols = { 100b9939336SAlexander Graf { 101b9939336SAlexander Graf /* When asking for the device path interface, return 102c07ad7c0SAlexander Graf * bootefi_device_path */ 103b9939336SAlexander Graf .guid = &efi_guid_device_path, 104b5349f74Sxypron.glpk@gmx.de .protocol_interface = bootefi_device_path 105b9939336SAlexander Graf } 106b9939336SAlexander Graf }, 107b9939336SAlexander Graf }; 108b9939336SAlexander Graf 109*7cbc1241SHeinrich Schuchardt /* Initialize and populate EFI object list */ 110*7cbc1241SHeinrich Schuchardt static void efi_init_obj_list(void) 111*7cbc1241SHeinrich Schuchardt { 112*7cbc1241SHeinrich Schuchardt efi_obj_list_initalized = 1; 113*7cbc1241SHeinrich Schuchardt 114*7cbc1241SHeinrich Schuchardt list_add_tail(&loaded_image_info_obj.link, &efi_obj_list); 115*7cbc1241SHeinrich Schuchardt list_add_tail(&bootefi_device_obj.link, &efi_obj_list); 116*7cbc1241SHeinrich Schuchardt efi_console_register(); 117*7cbc1241SHeinrich Schuchardt #ifdef CONFIG_PARTITIONS 118*7cbc1241SHeinrich Schuchardt efi_disk_register(); 119*7cbc1241SHeinrich Schuchardt #endif 120*7cbc1241SHeinrich Schuchardt #if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO) 121*7cbc1241SHeinrich Schuchardt efi_gop_register(); 122*7cbc1241SHeinrich Schuchardt #endif 123*7cbc1241SHeinrich Schuchardt #ifdef CONFIG_NET 124*7cbc1241SHeinrich Schuchardt void *nethandle = loaded_image_info.device_handle; 125*7cbc1241SHeinrich Schuchardt efi_net_register(&nethandle); 126*7cbc1241SHeinrich Schuchardt 127*7cbc1241SHeinrich Schuchardt if (!memcmp(bootefi_device_path[0].str, "N\0e\0t", 6)) 128*7cbc1241SHeinrich Schuchardt loaded_image_info.device_handle = nethandle; 129*7cbc1241SHeinrich Schuchardt else 130*7cbc1241SHeinrich Schuchardt loaded_image_info.device_handle = bootefi_device_path; 131*7cbc1241SHeinrich Schuchardt #endif 132*7cbc1241SHeinrich Schuchardt #ifdef CONFIG_GENERATE_SMBIOS_TABLE 133*7cbc1241SHeinrich Schuchardt efi_smbios_register(); 134*7cbc1241SHeinrich Schuchardt #endif 135*7cbc1241SHeinrich Schuchardt 136*7cbc1241SHeinrich Schuchardt /* Initialize EFI runtime services */ 137*7cbc1241SHeinrich Schuchardt efi_reset_system_init(); 138*7cbc1241SHeinrich Schuchardt efi_get_time_init(); 139*7cbc1241SHeinrich Schuchardt } 140*7cbc1241SHeinrich Schuchardt 1410d9d501fSAlexander Graf static void *copy_fdt(void *fdt) 1420d9d501fSAlexander Graf { 1430d9d501fSAlexander Graf u64 fdt_size = fdt_totalsize(fdt); 144ad0c1a3dSAlexander Graf unsigned long fdt_ram_start = -1L, fdt_pages; 145ad0c1a3dSAlexander Graf u64 new_fdt_addr; 1460d9d501fSAlexander Graf void *new_fdt; 147ad0c1a3dSAlexander Graf int i; 1480d9d501fSAlexander Graf 149ad0c1a3dSAlexander Graf for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { 150ad0c1a3dSAlexander Graf u64 ram_start = gd->bd->bi_dram[i].start; 151ad0c1a3dSAlexander Graf u64 ram_size = gd->bd->bi_dram[i].size; 1520d9d501fSAlexander Graf 153ad0c1a3dSAlexander Graf if (!ram_size) 154ad0c1a3dSAlexander Graf continue; 155ad0c1a3dSAlexander Graf 156ad0c1a3dSAlexander Graf if (ram_start < fdt_ram_start) 157ad0c1a3dSAlexander Graf fdt_ram_start = ram_start; 158ad0c1a3dSAlexander Graf } 159ad0c1a3dSAlexander Graf 160ad0c1a3dSAlexander Graf /* Give us at least 4kb breathing room */ 161ad0c1a3dSAlexander Graf fdt_size = ALIGN(fdt_size + 4096, 4096); 162ad0c1a3dSAlexander Graf fdt_pages = fdt_size >> EFI_PAGE_SHIFT; 163ad0c1a3dSAlexander Graf 164ad0c1a3dSAlexander Graf /* Safe fdt location is at 128MB */ 165ad0c1a3dSAlexander Graf new_fdt_addr = fdt_ram_start + (128 * 1024 * 1024) + fdt_size; 166ad0c1a3dSAlexander Graf if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages, 167ad0c1a3dSAlexander Graf &new_fdt_addr) != EFI_SUCCESS) { 168ad0c1a3dSAlexander Graf /* If we can't put it there, put it somewhere */ 169ad0c1a3dSAlexander Graf new_fdt_addr = (ulong)memalign(4096, fdt_size); 17085a6e9b3SAlexander Graf if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages, 17185a6e9b3SAlexander Graf &new_fdt_addr) != EFI_SUCCESS) { 17285a6e9b3SAlexander Graf printf("ERROR: Failed to reserve space for FDT\n"); 17385a6e9b3SAlexander Graf return NULL; 174ad0c1a3dSAlexander Graf } 17585a6e9b3SAlexander Graf } 17685a6e9b3SAlexander Graf 177ad0c1a3dSAlexander Graf new_fdt = (void*)(ulong)new_fdt_addr; 1780d9d501fSAlexander Graf memcpy(new_fdt, fdt, fdt_totalsize(fdt)); 1790d9d501fSAlexander Graf fdt_set_totalsize(new_fdt, fdt_size); 1800d9d501fSAlexander Graf 1810d9d501fSAlexander Graf return new_fdt; 1820d9d501fSAlexander Graf } 1830d9d501fSAlexander Graf 184b06d8ac3Sxypron.glpk@gmx.de static ulong efi_do_enter(void *image_handle, 185b06d8ac3Sxypron.glpk@gmx.de struct efi_system_table *st, 186b06d8ac3Sxypron.glpk@gmx.de asmlinkage ulong (*entry)(void *image_handle, 187b06d8ac3Sxypron.glpk@gmx.de struct efi_system_table *st)) 188b06d8ac3Sxypron.glpk@gmx.de { 189b06d8ac3Sxypron.glpk@gmx.de efi_status_t ret = EFI_LOAD_ERROR; 190b06d8ac3Sxypron.glpk@gmx.de 191b06d8ac3Sxypron.glpk@gmx.de if (entry) 192b06d8ac3Sxypron.glpk@gmx.de ret = entry(image_handle, st); 193b06d8ac3Sxypron.glpk@gmx.de st->boottime->exit(image_handle, ret, 0, NULL); 194b06d8ac3Sxypron.glpk@gmx.de return ret; 195b06d8ac3Sxypron.glpk@gmx.de } 196b06d8ac3Sxypron.glpk@gmx.de 197ec6617c3SAlison Wang #ifdef CONFIG_ARM64 198b06d8ac3Sxypron.glpk@gmx.de static unsigned long efi_run_in_el2(asmlinkage ulong (*entry)( 199b06d8ac3Sxypron.glpk@gmx.de void *image_handle, struct efi_system_table *st), 200b06d8ac3Sxypron.glpk@gmx.de void *image_handle, struct efi_system_table *st) 201ec6617c3SAlison Wang { 202ec6617c3SAlison Wang /* Enable caches again */ 203ec6617c3SAlison Wang dcache_enable(); 204ec6617c3SAlison Wang 205b06d8ac3Sxypron.glpk@gmx.de return efi_do_enter(image_handle, st, entry); 206ec6617c3SAlison Wang } 207ec6617c3SAlison Wang #endif 208ec6617c3SAlison Wang 209b9939336SAlexander Graf /* 210b9939336SAlexander Graf * Load an EFI payload into a newly allocated piece of memory, register all 211b9939336SAlexander Graf * EFI objects it would want to access and jump to it. 212b9939336SAlexander Graf */ 2131c39809bSAlexander Graf static unsigned long do_bootefi_exec(void *efi, void *fdt) 214b9939336SAlexander Graf { 215e275458cSSimon Glass ulong (*entry)(void *image_handle, struct efi_system_table *st) 216e275458cSSimon Glass asmlinkage; 217b9939336SAlexander Graf ulong fdt_pages, fdt_size, fdt_start, fdt_end; 218dea2174dSAlexander Graf bootm_headers_t img = { 0 }; 219b9939336SAlexander Graf 220b9939336SAlexander Graf /* 221b9939336SAlexander Graf * gd lives in a fixed register which may get clobbered while we execute 222b9939336SAlexander Graf * the payload. So save it here and restore it on every callback entry 223b9939336SAlexander Graf */ 224b9939336SAlexander Graf efi_save_gd(); 225b9939336SAlexander Graf 2261c39809bSAlexander Graf if (fdt && !fdt_check_header(fdt)) { 227dea2174dSAlexander Graf /* Prepare fdt for payload */ 2280d9d501fSAlexander Graf fdt = copy_fdt(fdt); 2290d9d501fSAlexander Graf 2300d9d501fSAlexander Graf if (image_setup_libfdt(&img, fdt, 0, NULL)) { 231dea2174dSAlexander Graf printf("ERROR: Failed to process device tree\n"); 232dea2174dSAlexander Graf return -EINVAL; 233dea2174dSAlexander Graf } 234dea2174dSAlexander Graf 235dea2174dSAlexander Graf /* Link to it in the efi tables */ 236b9939336SAlexander Graf systab.tables[0].guid = EFI_FDT_GUID; 2370d9d501fSAlexander Graf systab.tables[0].table = fdt; 238b9939336SAlexander Graf systab.nr_tables = 1; 239b9939336SAlexander Graf 240b9939336SAlexander Graf /* And reserve the space in the memory map */ 2410d9d501fSAlexander Graf fdt_start = ((ulong)fdt) & ~EFI_PAGE_MASK; 2420d9d501fSAlexander Graf fdt_end = ((ulong)fdt) + fdt_totalsize(fdt); 243b9939336SAlexander Graf fdt_size = (fdt_end - fdt_start) + EFI_PAGE_MASK; 244b9939336SAlexander Graf fdt_pages = fdt_size >> EFI_PAGE_SHIFT; 245b9939336SAlexander Graf /* Give a bootloader the chance to modify the device tree */ 246b9939336SAlexander Graf fdt_pages += 2; 247b9939336SAlexander Graf efi_add_memory_map(fdt_start, fdt_pages, 248b9939336SAlexander Graf EFI_BOOT_SERVICES_DATA, true); 249b9939336SAlexander Graf } else { 2501c39809bSAlexander Graf printf("WARNING: Invalid device tree, expect boot to fail\n"); 251b9939336SAlexander Graf systab.nr_tables = 0; 252b9939336SAlexander Graf } 253b9939336SAlexander Graf 254b9939336SAlexander Graf /* Load the EFI payload */ 255b9939336SAlexander Graf entry = efi_load_pe(efi, &loaded_image_info); 256b9939336SAlexander Graf if (!entry) 257b9939336SAlexander Graf return -ENOENT; 258b9939336SAlexander Graf 259b9939336SAlexander Graf /* Initialize and populate EFI object list */ 260*7cbc1241SHeinrich Schuchardt if (!efi_obj_list_initalized) 261*7cbc1241SHeinrich Schuchardt efi_init_obj_list(); 26280a4800eSAlexander Graf 263b9939336SAlexander Graf /* Call our payload! */ 264edcef3baSAlexander Graf debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry); 265a86aeaf2SAlexander Graf 266a86aeaf2SAlexander Graf if (setjmp(&loaded_image_info.exit_jmp)) { 2671da1bac4Sxypron.glpk@gmx.de return loaded_image_info.exit_status; 268a86aeaf2SAlexander Graf } 269a86aeaf2SAlexander Graf 27069bd459dSAlexander Graf #ifdef CONFIG_ARM64 27169bd459dSAlexander Graf /* On AArch64 we need to make sure we call our payload in < EL3 */ 27269bd459dSAlexander Graf if (current_el() == 3) { 27369bd459dSAlexander Graf smp_kick_all_cpus(); 27469bd459dSAlexander Graf dcache_disable(); /* flush cache before switch to EL2 */ 275ec6617c3SAlison Wang 276ec6617c3SAlison Wang /* Move into EL2 and keep running there */ 277ec6617c3SAlison Wang armv8_switch_to_el2((ulong)entry, (ulong)&loaded_image_info, 2787c5e1febSAlison Wang (ulong)&systab, 0, (ulong)efi_run_in_el2, 279ec6617c3SAlison Wang ES_TO_AARCH64); 280ec6617c3SAlison Wang 281ec6617c3SAlison Wang /* Should never reach here, efi exits with longjmp */ 282ec6617c3SAlison Wang while (1) { } 28369bd459dSAlexander Graf } 28469bd459dSAlexander Graf #endif 28569bd459dSAlexander Graf 286b06d8ac3Sxypron.glpk@gmx.de return efi_do_enter(&loaded_image_info, &systab, entry); 287b9939336SAlexander Graf } 288b9939336SAlexander Graf 289b9939336SAlexander Graf 290b9939336SAlexander Graf /* Interpreter command to boot an arbitrary EFI image from memory */ 291b9939336SAlexander Graf static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 292b9939336SAlexander Graf { 2931c39809bSAlexander Graf char *saddr, *sfdt; 2941c39809bSAlexander Graf unsigned long addr, fdt_addr = 0; 2951da1bac4Sxypron.glpk@gmx.de unsigned long r; 296b9939336SAlexander Graf 297b9939336SAlexander Graf if (argc < 2) 2983c1dcef6SBin Meng return CMD_RET_USAGE; 299c7ae3dfdSSimon Glass #ifdef CONFIG_CMD_BOOTEFI_HELLO 300c7ae3dfdSSimon Glass if (!strcmp(argv[1], "hello")) { 301c7ae3dfdSSimon Glass ulong size = __efi_hello_world_end - __efi_hello_world_begin; 302c7ae3dfdSSimon Glass 303c7ae3dfdSSimon Glass addr = CONFIG_SYS_LOAD_ADDR; 304c7ae3dfdSSimon Glass memcpy((char *)addr, __efi_hello_world_begin, size); 305c7ae3dfdSSimon Glass } else 306c7ae3dfdSSimon Glass #endif 307c7ae3dfdSSimon Glass { 308b9939336SAlexander Graf saddr = argv[1]; 309b9939336SAlexander Graf 310b9939336SAlexander Graf addr = simple_strtoul(saddr, NULL, 16); 311b9939336SAlexander Graf 3121c39809bSAlexander Graf if (argc > 2) { 3131c39809bSAlexander Graf sfdt = argv[2]; 3141c39809bSAlexander Graf fdt_addr = simple_strtoul(sfdt, NULL, 16); 3151c39809bSAlexander Graf } 316c7ae3dfdSSimon Glass } 3171c39809bSAlexander Graf 3185ee31bafSSimon Glass printf("## Starting EFI application at %08lx ...\n", addr); 3191c39809bSAlexander Graf r = do_bootefi_exec((void *)addr, (void*)fdt_addr); 3201da1bac4Sxypron.glpk@gmx.de printf("## Application terminated, r = %lu\n", 3211da1bac4Sxypron.glpk@gmx.de r & ~EFI_ERROR_MASK); 322b9939336SAlexander Graf 3231da1bac4Sxypron.glpk@gmx.de if (r != EFI_SUCCESS) 3241da1bac4Sxypron.glpk@gmx.de return 1; 3251da1bac4Sxypron.glpk@gmx.de else 3261da1bac4Sxypron.glpk@gmx.de return 0; 327b9939336SAlexander Graf } 328b9939336SAlexander Graf 329b9939336SAlexander Graf #ifdef CONFIG_SYS_LONGHELP 330b9939336SAlexander Graf static char bootefi_help_text[] = 3311c39809bSAlexander Graf "<image address> [fdt address]\n" 3321c39809bSAlexander Graf " - boot EFI payload stored at address <image address>.\n" 3331c39809bSAlexander Graf " If specified, the device tree located at <fdt address> gets\n" 334c7ae3dfdSSimon Glass " exposed as EFI configuration table.\n" 335c7ae3dfdSSimon Glass #ifdef CONFIG_CMD_BOOTEFI_HELLO 336c7ae3dfdSSimon Glass "hello\n" 337c7ae3dfdSSimon Glass " - boot a sample Hello World application stored within U-Boot" 338c7ae3dfdSSimon Glass #endif 339c7ae3dfdSSimon Glass ; 340b9939336SAlexander Graf #endif 341b9939336SAlexander Graf 342b9939336SAlexander Graf U_BOOT_CMD( 3431c39809bSAlexander Graf bootefi, 3, 0, do_bootefi, 34492dfd922SSergey Kubushyn "Boots an EFI payload from memory", 345b9939336SAlexander Graf bootefi_help_text 346b9939336SAlexander Graf ); 3470f4060ebSAlexander Graf 348c07ad7c0SAlexander Graf void efi_set_bootdev(const char *dev, const char *devnr, const char *path) 3490f4060ebSAlexander Graf { 3508c3df0bfSAlexander Graf __maybe_unused struct blk_desc *desc; 351ecbe1a07SAlexander Graf char devname[32] = { 0 }; /* dp->str is u16[32] long */ 3523e433e96SRob Clark char *colon, *s; 3530f4060ebSAlexander Graf 3541acc0087SPatrick Delaunay #if defined(CONFIG_BLK) || CONFIG_IS_ENABLED(ISO_PARTITION) 355f9d334bdSAlexander Graf desc = blk_get_dev(dev, simple_strtol(devnr, NULL, 10)); 356f9d334bdSAlexander Graf #endif 357f9d334bdSAlexander Graf 358f9d334bdSAlexander Graf #ifdef CONFIG_BLK 359f9d334bdSAlexander Graf if (desc) { 360f9d334bdSAlexander Graf snprintf(devname, sizeof(devname), "%s", desc->bdev->name); 361f9d334bdSAlexander Graf } else 362f9d334bdSAlexander Graf #endif 363f9d334bdSAlexander Graf 364f9d334bdSAlexander Graf { 3650f4060ebSAlexander Graf /* Assemble the condensed device name we use in efi_disk.c */ 3660f4060ebSAlexander Graf snprintf(devname, sizeof(devname), "%s%s", dev, devnr); 367f9d334bdSAlexander Graf } 368f9d334bdSAlexander Graf 3690f4060ebSAlexander Graf colon = strchr(devname, ':'); 3708c3df0bfSAlexander Graf 3711acc0087SPatrick Delaunay #if CONFIG_IS_ENABLED(ISO_PARTITION) 3728c3df0bfSAlexander Graf /* For ISOs we create partition block devices */ 3738c3df0bfSAlexander Graf if (desc && (desc->type != DEV_TYPE_UNKNOWN) && 3748c3df0bfSAlexander Graf (desc->part_type == PART_TYPE_ISO)) { 3758c3df0bfSAlexander Graf if (!colon) 376f9d334bdSAlexander Graf snprintf(devname, sizeof(devname), "%s:1", devname); 377f9d334bdSAlexander Graf 3788c3df0bfSAlexander Graf colon = NULL; 3798c3df0bfSAlexander Graf } 3808c3df0bfSAlexander Graf #endif 3818c3df0bfSAlexander Graf 3820f4060ebSAlexander Graf if (colon) 3830f4060ebSAlexander Graf *colon = '\0'; 3840f4060ebSAlexander Graf 385c07ad7c0SAlexander Graf /* Patch bootefi_device_path to the target device */ 386c07ad7c0SAlexander Graf memset(bootefi_device_path[0].str, 0, sizeof(bootefi_device_path[0].str)); 387c07ad7c0SAlexander Graf ascii2unicode(bootefi_device_path[0].str, devname); 388c07ad7c0SAlexander Graf 389c07ad7c0SAlexander Graf /* Patch bootefi_image_path to the target file path */ 3900f4060ebSAlexander Graf memset(bootefi_image_path[0].str, 0, sizeof(bootefi_image_path[0].str)); 39149271666SAlexander Graf if (strcmp(dev, "Net")) { 39249271666SAlexander Graf /* Add leading / to fs paths, because they're absolute */ 39349271666SAlexander Graf snprintf(devname, sizeof(devname), "/%s", path); 39449271666SAlexander Graf } else { 395c07ad7c0SAlexander Graf snprintf(devname, sizeof(devname), "%s", path); 39649271666SAlexander Graf } 3973e433e96SRob Clark /* DOS style file path: */ 3983e433e96SRob Clark s = devname; 3993e433e96SRob Clark while ((s = strchr(s, '/'))) 4003e433e96SRob Clark *s++ = '\\'; 4010f4060ebSAlexander Graf ascii2unicode(bootefi_image_path[0].str, devname); 4020f4060ebSAlexander Graf } 403