mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 19:11:53 +00:00
efi_loader: Enable run-time variable support for tee based variables
We recently added functions for storing/restoring variables from a file to a memory backed buffer marked as __efi_runtime_data commitf1f990a8c9
("efi_loader: memory buffer for variables") commit5f7dcf079d
("efi_loader: UEFI variable persistence") Using the same idea we now can support GetVariable() and GetNextVariable() on the OP-TEE based variables as well. So let's re-arrange the code a bit and move the commmon code for accessing variables out of efi_variable.c. Create common functions for reading variables from memory that both implementations can use on run-time. Then just use those functions in the run-time variants of the OP-TEE based EFI variable implementation and initialize the memory buffer on ExitBootServices() Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
This commit is contained in:
parent
db94dfbd52
commit
e01aed47d6
7 changed files with 222 additions and 154 deletions
|
@ -282,68 +282,14 @@ efi_get_variable_int(u16 *variable_name, const efi_guid_t *vendor,
|
|||
u32 *attributes, efi_uintn_t *data_size, void *data,
|
||||
u64 *timep)
|
||||
{
|
||||
efi_uintn_t old_size;
|
||||
struct efi_var_entry *var;
|
||||
u16 *pdata;
|
||||
|
||||
if (!variable_name || !vendor || !data_size)
|
||||
return EFI_INVALID_PARAMETER;
|
||||
var = efi_var_mem_find(vendor, variable_name, NULL);
|
||||
if (!var)
|
||||
return EFI_NOT_FOUND;
|
||||
|
||||
if (attributes)
|
||||
*attributes = var->attr;
|
||||
if (timep)
|
||||
*timep = var->time;
|
||||
|
||||
old_size = *data_size;
|
||||
*data_size = var->length;
|
||||
if (old_size < var->length)
|
||||
return EFI_BUFFER_TOO_SMALL;
|
||||
|
||||
if (!data)
|
||||
return EFI_INVALID_PARAMETER;
|
||||
|
||||
for (pdata = var->name; *pdata; ++pdata)
|
||||
;
|
||||
++pdata;
|
||||
|
||||
efi_memcpy_runtime(data, pdata, var->length);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
return efi_get_variable_mem(variable_name, vendor, attributes, data_size, data, timep);
|
||||
}
|
||||
|
||||
efi_status_t __efi_runtime
|
||||
efi_get_next_variable_name_int(efi_uintn_t *variable_name_size,
|
||||
u16 *variable_name, efi_guid_t *vendor)
|
||||
{
|
||||
struct efi_var_entry *var;
|
||||
efi_uintn_t old_size;
|
||||
u16 *pdata;
|
||||
|
||||
if (!variable_name_size || !variable_name || !vendor)
|
||||
return EFI_INVALID_PARAMETER;
|
||||
|
||||
efi_var_mem_find(vendor, variable_name, &var);
|
||||
|
||||
if (!var)
|
||||
return EFI_NOT_FOUND;
|
||||
|
||||
for (pdata = var->name; *pdata; ++pdata)
|
||||
;
|
||||
++pdata;
|
||||
|
||||
old_size = *variable_name_size;
|
||||
*variable_name_size = (uintptr_t)pdata - (uintptr_t)var->name;
|
||||
|
||||
if (old_size < *variable_name_size)
|
||||
return EFI_BUFFER_TOO_SMALL;
|
||||
|
||||
efi_memcpy_runtime(variable_name, var->name, *variable_name_size);
|
||||
efi_memcpy_runtime(vendor, &var->guid, sizeof(efi_guid_t));
|
||||
|
||||
return EFI_SUCCESS;
|
||||
return efi_get_next_variable_name_mem(variable_name_size, variable_name, vendor);
|
||||
}
|
||||
|
||||
efi_status_t efi_set_variable_int(u16 *variable_name, const efi_guid_t *vendor,
|
||||
|
@ -504,49 +450,6 @@ efi_status_t __efi_runtime EFIAPI efi_query_variable_info_runtime(
|
|||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* efi_get_variable_runtime() - runtime implementation of GetVariable()
|
||||
*
|
||||
* @variable_name: name of the variable
|
||||
* @vendor: vendor GUID
|
||||
* @attributes: attributes of the variable
|
||||
* @data_size: size of the buffer to which the variable value is copied
|
||||
* @data: buffer to which the variable value is copied
|
||||
* Return: status code
|
||||
*/
|
||||
static efi_status_t __efi_runtime EFIAPI
|
||||
efi_get_variable_runtime(u16 *variable_name, const efi_guid_t *vendor,
|
||||
u32 *attributes, efi_uintn_t *data_size, void *data)
|
||||
{
|
||||
efi_status_t ret;
|
||||
|
||||
ret = efi_get_variable_int(variable_name, vendor, attributes,
|
||||
data_size, data, NULL);
|
||||
|
||||
/* Remove EFI_VARIABLE_READ_ONLY flag */
|
||||
if (attributes)
|
||||
*attributes &= EFI_VARIABLE_MASK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* efi_get_next_variable_name_runtime() - runtime implementation of
|
||||
* GetNextVariable()
|
||||
*
|
||||
* @variable_name_size: size of variable_name buffer in byte
|
||||
* @variable_name: name of uefi variable's name in u16
|
||||
* @vendor: vendor's guid
|
||||
* Return: status code
|
||||
*/
|
||||
static efi_status_t __efi_runtime EFIAPI
|
||||
efi_get_next_variable_name_runtime(efi_uintn_t *variable_name_size,
|
||||
u16 *variable_name, efi_guid_t *vendor)
|
||||
{
|
||||
return efi_get_next_variable_name_int(variable_name_size, variable_name,
|
||||
vendor);
|
||||
}
|
||||
|
||||
/**
|
||||
* efi_set_variable_runtime() - runtime implementation of SetVariable()
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue