efi_loader: utility function to check the variable name is "Boot####"
Some commands need to enumerate the existing UEFI load option variable("Boot####"). This commit transfers some code from cmd/efidebug.c to lib/efi_loder/, then exposes efi_varname_is_load_option() function to check whether the UEFI variable name is "Boot####". Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
This commit is contained in:

committed by
Heinrich Schuchardt

parent
78b1ccc430
commit
3ac026ae46
@@ -190,3 +190,36 @@ 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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user