efi: Move a few helper functions into the common efi/ dir
Checking if a variable is a load option is useful for the app, so move efi_varname_is_load_option() and u16_tohex() into a new helper.c file. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -241,39 +241,6 @@ int efi_unlink_dev(efi_handle_t handle)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int u16_tohex(u16 c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return c - '0';
|
||||
if (c >= 'A' && c <= 'F')
|
||||
return c - 'A' + 10;
|
||||
|
||||
/* not hexadecimal */
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool efi_varname_is_load_option(u16 *var_name16, int *index)
|
||||
{
|
||||
int id, i, digit;
|
||||
|
||||
if (memcmp(var_name16, u"Boot", 8))
|
||||
return false;
|
||||
|
||||
for (id = 0, i = 0; i < 4; i++) {
|
||||
digit = u16_tohex(var_name16[4 + i]);
|
||||
if (digit < 0)
|
||||
break;
|
||||
id = (id << 4) + digit;
|
||||
}
|
||||
if (i == 4 && !var_name16[8]) {
|
||||
if (index)
|
||||
*index = id;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* efi_next_variable_name() - get next variable name
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user