[Concept,08/18] efi: Move a few helper functions into the common efi/ dir
Commit Message
From: Simon Glass <sjg@chromium.org>
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>
---
lib/efi/Makefile | 1 +
lib/efi/helper.c | 42 +++++++++++++++++++++++++++++++++++++
lib/efi_loader/efi_helper.c | 33 -----------------------------
3 files changed, 43 insertions(+), 33 deletions(-)
create mode 100644 lib/efi/helper.c
@@ -5,5 +5,6 @@
obj-y += basename.o
obj-y += device_path.o
+obj-y += helper.o
obj-y += memory.o
obj-y += run.o
new file mode 100644
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2020, Linaro Limited
+ */
+
+#define LOG_CATEGORY LOGC_EFI
+
+#include <string.h>
+#include <linux/types.h>
+
+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;
+}
@@ -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
*