[U-Boot] [PATCH v3 1/7] env: save UEFI non-volatile variables in dedicated storage

Ilias Apalodimas ilias.apalodimas at linaro.org
Tue Jun 11 10:59:52 UTC 2019


Hi Akashi-san

Thanks for doing this!

[...]
> +	return 0;
> +}
> +
> +int env_efi_save(void)
> +{
> +#ifdef CONFIG_ENV_IS_NOWHERE
One of the 'features' we discussed is the ability to have CONFIG_ENV_IS_NOWHERE
set (not allowing users to change the U-Boot ENV) and still be able to store 
UEFI variables. Doesn't this ifdef prevent that from happening?
> +	return 0;
> +#else
> +	struct env_driver *drv = NULL;
> +	int ret;
> +
> +	if (!efi_nv_var_htab.table)
> +		return 0;
> +
> +	if (gd->env_efi_prio == -1) {
> +		pr_warn("No UEFI non-volatile variable storage\n");
> +		return -1;
> +	}
> +
> +	drv = _env_driver_lookup(env_get_location(ENVOP_EFI, gd->env_efi_prio));
> +	if (!drv) {
> +		pr_warn("No UEFI non-volatile variable storage\n");
> +		return -1;
> +	}
> +
> +	ret = drv->efi_save();
> +	if (ret)
> +		pr_err("Saving UEFI non-volatile variable failed\n");
> +
> +	return ret;
> +#endif
> +}
> +
> +/* This function should be called only once at init */
> +int env_efi_load(void)
> +{
> +#ifndef CONFIG_ENV_IS_NOWHERE
ditto
> +	struct env_driver *drv;
> +	int prio;
> +	enum env_location loc;
> +#endif
> +	int ret;
> +
> +	/* volatile variables */
> +	if (!efi_var_htab.table) {
> +		ret = himport_r(&efi_var_htab, NULL, 0, '\0', 0, 0, 0, NULL);
> +		if (!ret) {
> +			pr_err("Creating UEFI volatile variables failed\n");
> +			return -1;
> +		}
> +	}
> +
> +#ifndef CONFIG_ENV_IS_NOWHERE
ditto
> +	gd->env_efi_prio = -1;
> +
> +	/* non-volatile variables */
> +	if (efi_nv_var_htab.table)
> +		return 0;
> +
> +	for (drv = NULL, prio = 0; prio < ARRAY_SIZE(env_locations); prio++) {
> +		loc = env_get_location(ENVOP_EFI, prio);
> +		drv = _env_driver_lookup(loc);
> +		if (!drv)
> +			continue;
> +
> +		if (drv->efi_load && drv->efi_save)
> +			break;
> +	}
> +	if (!drv || prio == ARRAY_SIZE(env_locations)) {
> +		pr_warn("No UEFI non-volatile variable storage\n");
> +		goto skip_load;
> +	}
> +
> +	gd->env_efi_prio = prio;
> +
> +	ret = drv->efi_load();
> +	if (ret) {
> +		pr_err("Loading UEFI non-volatile variables failed\n");
> +		return -1;
> +	}
> +skip_load:
> +#endif /* CONFIG_ENV_IS_NOWHERE */
[...]

Thanks
/Ilias


More information about the U-Boot mailing list