bootefi.c 18.6 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0+
2 3 4 5 6 7
/*
 *  EFI application loader
 *
 *  Copyright (c) 2016 Alexander Graf
 */

8 9
#define LOG_CATEGORY LOGC_EFI

10
#include <common.h>
11
#include <bootm.h>
12
#include <charset.h>
13
#include <command.h>
14
#include <dm.h>
15
#include <efi_loader.h>
16
#include <efi_selftest.h>
S
Simon Glass 已提交
17
#include <env.h>
18
#include <errno.h>
19
#include <image.h>
20
#include <log.h>
21
#include <malloc.h>
22
#include <asm/global_data.h>
23 24
#include <linux/libfdt.h>
#include <linux/libfdt_env.h>
25
#include <mapmem.h>
26
#include <memalign.h>
S
Simon Glass 已提交
27 28
#include <asm-generic/sections.h>
#include <linux/linkage.h>
29 30

DECLARE_GLOBAL_DATA_PTR;
31

32 33
static struct efi_device_path *bootefi_image_path;
static struct efi_device_path *bootefi_device_path;
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
static void *image_addr;
static size_t image_size;

/**
 * efi_clear_bootdev() - clear boot device
 */
static 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;

68 69 70
	log_debug("dev=%s, devnr=%s, path=%s, buffer=%p, size=%zx\n", dev,
		  devnr, path, buffer, buffer_size);

71 72 73 74 75 76 77
	/* 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) {
78 79 80 81 82 83 84 85 86 87 88
		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");
89
			return;
90
		}
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
	}

	/* 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;
110 111 112
		log_debug("- recorded device %ls\n", efi_dp_str(device));
		if (image)
			log_debug("- and image %ls\n", efi_dp_str(image));
113
	} else {
114
		log_debug("- efi_dp_from_name() failed, err=%lx\n", ret);
115 116 117
		efi_clear_bootdev();
	}
}
118

119
/**
120
 * efi_env_set_load_options() - set load options from environment variable
121
 *
122 123 124 125
 * @handle:		the image handle
 * @env_var:		name of the environment variable
 * @load_options:	pointer to load options (output)
 * Return:		status code
126
 */
127 128 129
static efi_status_t efi_env_set_load_options(efi_handle_t handle,
					     const char *env_var,
					     u16 **load_options)
130 131
{
	const char *env = env_get(env_var);
132
	size_t size;
133
	u16 *pos;
134 135
	efi_status_t ret;

136
	*load_options = NULL;
137
	if (!env)
138 139 140 141
		return EFI_SUCCESS;
	size = sizeof(u16) * (utf8_utf16_strlen(env) + 1);
	pos = calloc(size, 1);
	if (!pos)
142
		return EFI_OUT_OF_RESOURCES;
143
	*load_options = pos;
144
	utf8_utf16_strcpy(&pos, env);
145 146 147 148 149 150
	ret = efi_set_load_options(handle, size, *load_options);
	if (ret != EFI_SUCCESS) {
		free(*load_options);
		*load_options = NULL;
	}
	return ret;
151 152
}

153 154
#if !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)

155 156 157
/**
 * copy_fdt() - Copy the device tree to a new location available to EFI
 *
158
 * The FDT is copied to a suitable location within the EFI memory map.
159
 * Additional 12 KiB are added to the space in case the device tree needs to be
160 161
 * expanded later with fdt_open_into().
 *
162 163
 * @fdtp:	On entry a pointer to the flattened device tree.
 *		On exit a pointer to the copy of the flattened device tree.
164 165
 *		FDT start
 * Return:	status code
166
 */
167
static efi_status_t copy_fdt(void **fdtp)
168
{
169
	unsigned long fdt_ram_start = -1L, fdt_pages;
170 171
	efi_status_t ret = 0;
	void *fdt, *new_fdt;
172
	u64 new_fdt_addr;
173
	uint fdt_size;
174
	int i;
175

176 177 178
	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;
179

180 181 182 183 184 185 186
		if (!ram_size)
			continue;

		if (ram_start < fdt_ram_start)
			fdt_ram_start = ram_start;
	}

187
	/*
188 189
	 * Give us at least 12 KiB of breathing room in case the device tree
	 * needs to be expanded later.
190
	 */
191
	fdt = *fdtp;
192 193
	fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) + 0x3000);
	fdt_size = fdt_pages << EFI_PAGE_SHIFT;
194

195 196 197 198 199 200
	/*
	 * Safe fdt location is at 127 MiB.
	 * On the sandbox convert from the sandbox address space.
	 */
	new_fdt_addr = (uintptr_t)map_sysmem(fdt_ram_start + 0x7f00000 +
					     fdt_size, 0);
201
	ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
202
				 EFI_ACPI_RECLAIM_MEMORY, fdt_pages,
203 204
				 &new_fdt_addr);
	if (ret != EFI_SUCCESS) {
205
		/* If we can't put it there, put it somewhere */
206
		new_fdt_addr = (ulong)memalign(EFI_PAGE_SIZE, fdt_size);
207
		ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
208
					 EFI_ACPI_RECLAIM_MEMORY, fdt_pages,
209 210
					 &new_fdt_addr);
		if (ret != EFI_SUCCESS) {
211
			log_err("ERROR: Failed to reserve space for FDT\n");
212
			goto done;
213
		}
214
	}
215
	new_fdt = (void *)(uintptr_t)new_fdt_addr;
216 217 218
	memcpy(new_fdt, fdt, fdt_totalsize(fdt));
	fdt_set_totalsize(new_fdt, fdt_size);

219
	*fdtp = (void *)(uintptr_t)new_fdt_addr;
220 221
done:
	return ret;
222 223
}

224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
/**
 * 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;
}

#endif /* !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) */

243
/**
244
 * efi_install_fdt() - install device tree
245
 *
246 247 248 249
 * If fdt is not EFI_FDT_USE_INTERNAL, the device tree located at that memory
 * address will 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.
250
 *
251 252
 * On architectures using ACPI tables device trees shall not be installed as
 * configuration table.
253
 *
254
 * @fdt:	address of device tree or EFI_FDT_USE_INTERNAL to use the
255 256 257
 *		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
258 259
 * Return:	status code
 */
260
efi_status_t efi_install_fdt(void *fdt)
261
{
262 263 264 265 266
	/*
	 * The EBBR spec requires that we have either an FDT or an ACPI table
	 * but not both.
	 */
#if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)
267
	if (fdt) {
268 269
		log_warning("WARNING: Can't have ACPI table and device tree - ignoring DT.\n");
		return EFI_SUCCESS;
270 271
	}
#else
272
	bootm_headers_t img = { 0 };
273 274
	efi_status_t ret;

275
	if (fdt == EFI_FDT_USE_INTERNAL) {
276
		const char *fdt_opt;
277
		uintptr_t fdt_addr;
278

279 280 281
		/* Look for device tree that is already installed */
		if (get_config_table(&efi_guid_fdt))
			return EFI_SUCCESS;
282 283 284
		/* Check if there is a hardware device tree */
		fdt_opt = env_get("fdt_addr");
		/* Use our own device tree as fallback */
285
		if (!fdt_opt) {
286 287
			fdt_opt = env_get("fdtcontroladdr");
			if (!fdt_opt) {
288
				log_err("ERROR: need device tree\n");
289 290
				return EFI_NOT_FOUND;
			}
291
		}
292
		fdt_addr = hextoul(fdt_opt, NULL);
293
		if (!fdt_addr) {
294
			log_err("ERROR: invalid $fdt_addr or $fdtcontroladdr\n");
295
			return EFI_LOAD_ERROR;
296
		}
297
		fdt = map_sysmem(fdt_addr, 0);
298
	}
299

300 301
	/* Install device tree */
	if (fdt_check_header(fdt)) {
302
		log_err("ERROR: invalid device tree\n");
303 304
		return EFI_LOAD_ERROR;
	}
305

306 307 308
	/* Prepare device tree for payload */
	ret = copy_fdt(&fdt);
	if (ret) {
309
		log_err("ERROR: out of memory\n");
310 311
		return EFI_OUT_OF_RESOURCES;
	}
312

313
	if (image_setup_libfdt(&img, fdt, 0, NULL)) {
314
		log_err("ERROR: failed to process device tree\n");
315 316 317
		return EFI_LOAD_ERROR;
	}

318 319 320
	/* Create memory reservations as indicated by the device tree */
	efi_carve_out_dt_rsv(fdt);

321 322
	efi_try_purge_kaslr_seed(fdt);

323 324 325
	/* Install device tree as UEFI table */
	ret = efi_install_configuration_table(&efi_guid_fdt, fdt);
	if (ret != EFI_SUCCESS) {
326
		log_err("ERROR: failed to install device tree\n");
327
		return ret;
328
	}
329
#endif /* GENERATE_ACPI_TABLE */
330 331 332 333

	return EFI_SUCCESS;
}

334 335 336
/**
 * do_bootefi_exec() - execute EFI binary
 *
337 338 339
 * The image indicated by @handle is started. When it returns the allocated
 * memory for the @load_options is freed.
 *
340
 * @handle:		handle of loaded image
341
 * @load_options:	load options
342 343 344 345
 * 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.
346
 */
347
static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options)
348
{
349
	efi_status_t ret;
350 351
	efi_uintn_t exit_data_size = 0;
	u16 *exit_data = NULL;
352

353 354 355
	/* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */
	switch_to_non_secure_mode();

356 357 358 359 360 361 362 363 364 365 366 367 368
	/*
	 * 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;
	}

369
	/* Call our payload! */
370
	ret = EFI_CALL(efi_start_image(handle, &exit_data_size, &exit_data));
371 372 373 374 375 376 377
	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);
		}
378
	}
379

380
	efi_restore_gd();
381

382
out:
383
	free(load_options);
384

385 386 387
	if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD))
		efi_initrd_deregister();

388 389 390
	/* Control is returned to U-Boot, disable EFI watchdog */
	efi_set_watchdog(0);

391
	return ret;
392 393
}

394
/**
395
 * do_efibootmgr() - execute EFI boot manager
396 397 398
 *
 * Return:	status code
 */
399
static int do_efibootmgr(void)
400
{
401
	efi_handle_t handle;
402
	efi_status_t ret;
403
	void *load_options;
404

405
	ret = efi_bootmgr_load(&handle, &load_options);
406
	if (ret != EFI_SUCCESS) {
407
		log_notice("EFI boot manager: Cannot load any image\n");
408 409
		return CMD_RET_FAILURE;
	}
410

411
	ret = do_bootefi_exec(handle, load_options);
412

413
	if (ret != EFI_SUCCESS)
414
		return CMD_RET_FAILURE;
415

416
	return CMD_RET_SUCCESS;
417 418
}

419
/**
420 421 422 423
 * do_bootefi_image() - execute EFI binary
 *
 * Set up memory image for the binary to be loaded, prepare device path, and
 * then call do_bootefi_exec() to execute it.
424
 *
425 426
 * @image_opt:	string with image start address
 * @size_opt:	string with image size or NULL
427 428
 * Return:	status code
 */
429
static int do_bootefi_image(const char *image_opt, const char *size_opt)
430
{
431 432
	void *image_buf;
	unsigned long addr, size;
433 434 435 436
	efi_status_t ret;

#ifdef CONFIG_CMD_BOOTEFI_HELLO
	if (!strcmp(image_opt, "hello")) {
437
		image_buf = __efi_helloworld_begin;
438
		size = __efi_helloworld_end - __efi_helloworld_begin;
439
		efi_clear_bootdev();
440 441 442
	} else
#endif
	{
443
		addr = strtoul(image_opt, NULL, 16);
444
		/* Check that a numeric value was passed */
445
		if (!addr)
446
			return CMD_RET_USAGE;
447 448
		image_buf = map_sysmem(addr, 0);

449 450 451 452 453 454 455 456 457 458 459 460
		if (size_opt) {
			size = strtoul(size_opt, NULL, 16);
			if (!size)
				return CMD_RET_USAGE;
			efi_clear_bootdev();
		} else {
			if (image_buf != image_addr) {
				log_err("No UEFI binary known at %s\n",
					image_opt);
				return CMD_RET_FAILURE;
			}
			size = image_size;
461
		}
462
	}
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
	ret = efi_run_image(image_buf, size);

	if (ret != EFI_SUCCESS)
		return CMD_RET_FAILURE;

	return CMD_RET_SUCCESS;
}

/**
 * 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;
482
	struct efi_device_path *msg_path;
483
	efi_status_t ret;
484
	u16 *load_options;
485

486
	if (!bootefi_device_path || !bootefi_image_path) {
487
		log_debug("Not loaded from disk\n");
488 489 490 491 492 493
		/*
		 * 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,
494 495
					    (uintptr_t)source_buffer,
					    source_size);
496 497 498 499 500 501 502 503 504 505 506 507
		/*
		 * Make sure that device for device_path exist
		 * in load_image(). Otherwise, shell and grub will fail.
		 */
		ret = efi_create_handle(&mem_handle);
		if (ret != EFI_SUCCESS)
			goto out;

		ret = efi_add_protocol(mem_handle, &efi_guid_device_path,
				       file_path);
		if (ret != EFI_SUCCESS)
			goto out;
508
		msg_path = file_path;
509
	} else {
510 511
		file_path = efi_dp_append(bootefi_device_path,
					  bootefi_image_path);
512
		msg_path = bootefi_image_path;
513
		log_debug("Loaded from disk\n");
514 515
	}

516 517
	log_info("Booting %pD\n", msg_path);

518 519
	ret = EFI_CALL(efi_load_image(false, efi_root, file_path, source_buffer,
				      source_size, &handle));
520 521
	if (ret != EFI_SUCCESS) {
		log_err("Loading image failed\n");
522
		goto out;
523
	}
524 525 526 527 528 529 530

	/* 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);
531 532

out:
533 534
	efi_delete_handle(mem_handle);
	efi_free_pool(file_path);
535
	return ret;
536 537
}

538
#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
539 540 541 542 543 544 545
static efi_status_t bootefi_run_prepare(const char *load_options_path,
		struct efi_device_path *device_path,
		struct efi_device_path *image_path,
		struct efi_loaded_image_obj **image_objp,
		struct efi_loaded_image **loaded_image_infop)
{
	efi_status_t ret;
546
	u16 *load_options;
547 548 549 550 551 552 553

	ret = efi_setup_loaded_image(device_path, image_path, image_objp,
				     loaded_image_infop);
	if (ret != EFI_SUCCESS)
		return ret;

	/* Transfer environment variable as load options */
554 555 556
	return efi_env_set_load_options((efi_handle_t)*image_objp,
					load_options_path,
					&load_options);
557 558
}

559 560 561
/**
 * bootefi_test_prepare() - prepare to run an EFI test
 *
562
 * Prepare to run a test as if it were provided by a loaded image.
563
 *
564 565 566 567 568 569 570
 * @image_objp:		pointer to be set to the loaded image handle
 * @loaded_image_infop:	pointer to be set to the loaded image protocol
 * @path:		dummy file path used to construct the device path
 *			set in the loaded image protocol
 * @load_options_path:	name of a U-Boot environment variable. Its value is
 *			set as load options in the loaded image protocol.
 * Return:		status code
571 572 573
 */
static efi_status_t bootefi_test_prepare
		(struct efi_loaded_image_obj **image_objp,
574 575
		 struct efi_loaded_image **loaded_image_infop, const char *path,
		 const char *load_options_path)
576
{
577 578
	efi_status_t ret;

579
	/* Construct a dummy device path */
580
	bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, 0, 0);
581 582
	if (!bootefi_device_path)
		return EFI_OUT_OF_RESOURCES;
583

584
	bootefi_image_path = efi_dp_from_file(NULL, 0, path);
585 586 587 588 589 590 591 592 593 594
	if (!bootefi_image_path) {
		ret = EFI_OUT_OF_RESOURCES;
		goto failure;
	}

	ret = bootefi_run_prepare(load_options_path, bootefi_device_path,
				  bootefi_image_path, image_objp,
				  loaded_image_infop);
	if (ret == EFI_SUCCESS)
		return ret;
595

596
failure:
597
	efi_clear_bootdev();
598
	return ret;
599 600
}

601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
/**
 * bootefi_run_finish() - finish up after running an EFI test
 *
 * @loaded_image_info: Pointer to a struct which holds the loaded image info
 * @image_obj: Pointer to a struct which holds the loaded image object
 */
static void bootefi_run_finish(struct efi_loaded_image_obj *image_obj,
			       struct efi_loaded_image *loaded_image_info)
{
	efi_restore_gd();
	free(loaded_image_info->load_options);
	efi_delete_handle(&image_obj->header);
}

/**
616
 * do_efi_selftest() - execute EFI selftest
617 618 619
 *
 * Return:	status code
 */
620
static int do_efi_selftest(void)
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
{
	struct efi_loaded_image_obj *image_obj;
	struct efi_loaded_image *loaded_image_info;
	efi_status_t ret;

	ret = bootefi_test_prepare(&image_obj, &loaded_image_info,
				   "\\selftest", "efi_selftest");
	if (ret != EFI_SUCCESS)
		return CMD_RET_FAILURE;

	/* Execute the test */
	ret = EFI_CALL(efi_selftest(&image_obj->header, &systab));
	bootefi_run_finish(image_obj, loaded_image_info);

	return ret != EFI_SUCCESS;
}
637 638
#endif /* CONFIG_CMD_BOOTEFI_SELFTEST */

639 640 641 642 643 644 645 646 647
/**
 * do_bootefi() - execute `bootefi` command
 *
 * @cmdtp:	table entry describing command
 * @flag:	bitmap indicating how the command was invoked
 * @argc:	number of arguments
 * @argv:	command line arguments
 * Return:	status code
 */
648 649
static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc,
		      char *const argv[])
650
{
651
	efi_status_t ret;
652
	char *img_addr, *img_size, *str_copy, *pos;
653
	void *fdt;
654

655 656
	if (argc < 2)
		return CMD_RET_USAGE;
657

658 659 660
	/* Initialize EFI drivers */
	ret = efi_init_obj_list();
	if (ret != EFI_SUCCESS) {
661 662
		log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n",
			ret & ~EFI_ERROR_MASK);
663 664 665
		return CMD_RET_FAILURE;
	}

666
	if (argc > 2) {
667 668
		uintptr_t fdt_addr;

669
		fdt_addr = hextoul(argv[2], NULL);
670 671 672 673 674
		fdt = map_sysmem(fdt_addr, 0);
	} else {
		fdt = EFI_FDT_USE_INTERNAL;
	}
	ret = efi_install_fdt(fdt);
675 676 677 678 679
	if (ret == EFI_INVALID_PARAMETER)
		return CMD_RET_USAGE;
	else if (ret != EFI_SUCCESS)
		return CMD_RET_FAILURE;

680 681 682 683
	if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) {
		if (!strcmp(argv[1], "bootmgr"))
			return do_efibootmgr();
	}
684
#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
685
	if (!strcmp(argv[1], "selftest"))
686
		return do_efi_selftest();
687
#endif
688 689 690 691 692 693 694 695 696 697
	str_copy = strdup(argv[1]);
	if (!str_copy) {
		log_err("Out of memory\n");
		return CMD_RET_FAILURE;
	}
	pos = str_copy;
	img_addr = strsep(&pos, ":");
	img_size = strsep(&pos, ":");
	ret = do_bootefi_image(img_addr, img_size);
	free(str_copy);
698

699
	return ret;
700 701 702 703
}

#ifdef CONFIG_SYS_LONGHELP
static char bootefi_help_text[] =
704 705
	"<image address>[:<image size>] [<fdt address>]\n"
	"  - boot EFI payload\n"
706
#ifdef CONFIG_CMD_BOOTEFI_HELLO
707 708 709 710
	"bootefi hello\n"
	"  - boot a sample Hello World application stored within U-Boot\n"
#endif
#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
711
	"bootefi selftest [fdt address]\n"
712
	"  - boot an EFI selftest application stored within U-Boot\n"
713 714
	"    Use environment variable efi_selftest to select a single test.\n"
	"    Use 'setenv efi_selftest list' to enumerate all tests.\n"
715
#endif
716
#ifdef CONFIG_CMD_BOOTEFI_BOOTMGR
717
	"bootefi bootmgr [fdt address]\n"
R
Rob Clark 已提交
718 719 720
	"  - load and boot EFI payload based on BootOrder/BootXXXX variables.\n"
	"\n"
	"    If specified, the device tree located at <fdt address> gets\n"
721 722 723
	"    exposed as EFI configuration table.\n"
#endif
	;
724 725 726
#endif

U_BOOT_CMD(
727
	bootefi, 4, 0, do_bootefi,
S
Sergey Kubushyn 已提交
728
	"Boots an EFI payload from memory",
729 730
	bootefi_help_text
);