* 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)
+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;
- u16 *load_options;
-
- /* Transfer environment variable as load options */
- ret = efi_env_set_load_options(handle, "bootargs", &load_options);
- if (ret != EFI_SUCCESS)
- return ret;
/* Call our payload! */
ret = EFI_CALL(efi_start_image(handle, &exit_data_size, &exit_data));
{
efi_handle_t handle;
efi_status_t ret;
+ void *load_options;
- ret = efi_bootmgr_load(&handle);
+ ret = efi_bootmgr_load(&handle, &load_options);
if (ret != EFI_SUCCESS) {
log_notice("EFI boot manager: Cannot load any image\n");
return CMD_RET_FAILURE;
}
- ret = do_bootefi_exec(handle);
+ ret = do_bootefi_exec(handle, load_options);
if (ret != EFI_SUCCESS)
return CMD_RET_FAILURE;
if (ret != EFI_SUCCESS)
goto out;
- ret = do_bootefi_exec(handle);
+ u16 *load_options;
+
+ /* 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:
efi_delete_handle(mem_handle);
* if successful. This checks that the EFI_LOAD_OPTION is active (enabled)
* and that the specified file to boot exists.
*
- * @n: number of the boot option, e.g. 0x0a13 for Boot0A13
- * @handle: on return handle for the newly installed image
- * Return: status code
+ * @n: number of the boot option, e.g. 0x0a13 for Boot0A13
+ * @handle: on return handle for the newly installed image
+ * @load_options: load options set on the loaded image protocol
+ * Return: status code
*/
-static efi_status_t try_load_entry(u16 n, efi_handle_t *handle)
+static efi_status_t try_load_entry(u16 n, efi_handle_t *handle,
+ void **load_options)
{
struct efi_load_option lo;
u16 varname[] = L"Boot0000";
attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS;
- size = sizeof(n);
ret = efi_set_variable_int(L"BootCurrent",
&efi_global_variable_guid,
- attributes, size, &n, false);
+ attributes, sizeof(n), &n, false);
if (ret != EFI_SUCCESS) {
if (EFI_CALL(efi_unload_image(*handle))
!= EFI_SUCCESS)
ret = EFI_LOAD_ERROR;
}
+ /* Set load options */
+ if (size) {
+ *load_options = malloc(size);
+ if (!*load_options) {
+ ret = EFI_OUT_OF_RESOURCES;
+ goto error;
+ }
+ memcpy(*load_options, lo.optional_data, size);
+ ret = efi_set_load_options(*handle, size, *load_options);
+ } else {
+ load_options = NULL;
+ }
+
error:
free(load_option);
* EFI variable, the available load-options, finding and returning
* the first one that can be loaded successfully.
*
- * @handle: on return handle for the newly installed image
- * Return: status code
+ * @handle: on return handle for the newly installed image
+ * @load_options: load options set on the loaded image protocol
+ * Return: status code
*/
-efi_status_t efi_bootmgr_load(efi_handle_t *handle)
+efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options)
{
u16 bootnext, *bootorder;
efi_uintn_t size;
/* load BootNext */
if (ret == EFI_SUCCESS) {
if (size == sizeof(u16)) {
- ret = try_load_entry(bootnext, handle);
+ ret = try_load_entry(bootnext, handle,
+ load_options);
if (ret == EFI_SUCCESS)
return ret;
log_warning(
for (i = 0; i < num; i++) {
log_debug("%s trying to load Boot%04X\n", __func__,
bootorder[i]);
- ret = try_load_entry(bootorder[i], handle);
+ ret = try_load_entry(bootorder[i], handle, load_options);
if (ret == EFI_SUCCESS)
break;
}