[PATCH 1/2] Boot var automatic management for removable medias

Ilias Apalodimas ilias.apalodimas at linaro.org
Mon Apr 3 12:34:07 CEST 2023


Hi Raymond,


[...]

> +			}
> +		}
> +	}
> +
> +out:
> +	if (opt) {
> +		for (i = 0; i < count; i++) {
> +			if (opt[i].lo)
> +				free(opt[i].lo);
> +		}
> +		free(opt);
> +	}
> +	efi_free_pool(volume_handles);
> +
> +	return ret;
> +}
> diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
> index d2256713a8..1309e28134 100644
> --- a/lib/efi_loader/efi_disk.c
> +++ b/lib/efi_loader/efi_disk.c
> @@ -687,6 +687,13 @@ int efi_disk_probe(void *ctx, struct event *event)
>  			return -1;
>  	}
>
> +	/* only do the boot option management when UEFI sub-system is initialized */
> +	if (efi_obj_list_initialized == EFI_SUCCESS) {
> +		ret = efi_bootmgr_update_media_device_boot_option();

I am not sure if this is the problem, but with these patches applied and no
media attached QEMU fails to initialize the EFI sub-system.  IOW running
qemu-system-aarch64  -bios u-boot.bin -machine virt,secure=off -cpu cortex-a53 -m 2G  -nographic -no-acpi

=> efidebug boot dump
No EFI system partition
Error: Cannot initialize UEFI sub-system, r = 14

We should always start EFI, even if scanning for boot options fails.

> +		if (ret)
> +			return -1;
> +	}
> +
>  	return 0;
>  }
>
> diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c
> index 1f4ab2b419..cdfd16ea77 100644
> --- a/lib/efi_loader/efi_helper.c
> +++ b/lib/efi_loader/efi_helper.c
> @@ -257,3 +257,28 @@ efi_status_t efi_next_variable_name(efi_uintn_t *size, u16 **buf, efi_guid_t *gu
>
>  	return ret;
>  }
> +
> +/**
> + * efi_search_bootorder() - search the boot option index in BootOrder
> + *
> + * @bootorder:	pointer to the BootOrder variable
> + * @num:	number of BootOrder entry
> + * @target:	target boot option index to search
> + * @index:	pointer to store the index of BootOrder variable
> + * Return:	true if exists, false otherwise
> + */
> +bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index)
> +{
> +	u32 i;
> +
> +	for (i = 0; i < num; i++) {
> +		if (target == bootorder[i]) {
> +			if (index)
> +				*index = i;
> +
> +			return true;
> +		}
> +	}
> +
> +	return false;
> +}
> diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
> index be95ed44e6..2f251553e1 100644
> --- a/lib/efi_loader/efi_variable.c
> +++ b/lib/efi_loader/efi_variable.c
> @@ -476,6 +476,10 @@ efi_status_t efi_init_variables(void)
>  			log_err("Invalid EFI variable seed\n");
>  	}
>
> +	ret = efi_init_secure_state();
> +	if (ret != EFI_SUCCESS)
> +		return ret;
>
> -	return efi_init_secure_state();
> +	/* update boot option management after variable service initialized */
> +	return efi_bootmgr_update_media_device_boot_option();
>  }
> diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c
> index dfef18435d..a48d313ef0 100644
> --- a/lib/efi_loader/efi_variable_tee.c
> +++ b/lib/efi_loader/efi_variable_tee.c
> @@ -748,5 +748,6 @@ efi_status_t efi_init_variables(void)
>  	if (ret != EFI_SUCCESS)
>  		return ret;
>
> -	return EFI_SUCCESS;
> +	/* update boot option management after variable service initialized */
> +	return efi_bootmgr_update_media_device_boot_option();
>  }
> --
> 2.25.1
>

Regards
/Ilias


More information about the U-Boot mailing list