Ejemplo n.º 1
0
static int efi_execute_image(const char *file)
{
	efi_handle_t handle;
	efi_loaded_image_t *loaded_image;
	efi_status_t efiret;
	struct linux_kernel_header *image_header;
	const char *options;
	int ret;

	ret = efi_load_image(file, &loaded_image, &handle);
	if (ret)
		return ret;

	image_header = (struct linux_kernel_header *)loaded_image->image_base;
	if (image_header->boot_flag == 0xAA55 &&
	    image_header->header == 0x53726448) {
		pr_debug("Linux kernel detected. Adding bootargs.");
		options = linux_bootargs_get();
		pr_err("add linux options '%s'\n", options);
		loaded_image->load_options = xstrdup_char_to_wchar(options);
		loaded_image->load_options_size =
			(strlen(options) + 1) * sizeof(wchar_t);
	}

	efiret = BS->start_image(handle, NULL, NULL);
	if (EFI_ERROR(efiret))
		pr_err("failed to StartImage: %s\n", efi_strerror(efiret));

	BS->unload_image(handle);

	efi_connect_all();
	efi_register_devices();

	return -efi_errno(efiret);
}
Ejemplo n.º 2
0
static int efi_execute_image(const char *file)
{
	void *exe;
	size_t size;
	efi_handle_t handle;
	efi_status_t efiret;
	const char *options;
	efi_loaded_image_t *loaded_image;

	exe = read_file(file, &size);
	if (!exe)
		return -EINVAL;

	efiret = BS->load_image(false, efi_parent_image, efi_device_path, exe, size,
			&handle);
	if (EFI_ERROR(efiret)) {
		pr_err("failed to LoadImage: %s\n", efi_strerror(efiret));
		return -efi_errno(efiret);;
	};

	efiret = BS->open_protocol(handle, &efi_loaded_image_protocol_guid,
			(void **)&loaded_image,
			efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
	if (EFI_ERROR(efiret))
		return -efi_errno(efiret);

	options = linux_bootargs_get();
	loaded_image->load_options = strdup_char_to_wchar(options);
	loaded_image->load_options_size = (strlen(options) + 1) * sizeof(wchar_t);

	efiret = BS->start_image(handle, NULL, NULL);

	efi_connect_all();
	efi_register_devices();

	return 0;
}