summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMasahisa Kojima <masahisa.kojima@linaro.org>2022-09-12 11:33:50 +0300
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2022-09-14 09:43:31 +0300
commit87d791423ac69affec43dfb834965adcb0aa02e6 (patch)
tree82576a5bf3f39e7963c7931407542342deaeb9a7 /lib
parentc2238fcf0c4567bbd581882e5952047e71406f58 (diff)
downloadu-boot-87d791423ac69affec43dfb834965adcb0aa02e6.tar.xz
eficonfig: menu-driven addition of UEFI boot option
This commit add the "eficonfig" command. The "eficonfig" command implements the menu-driven UEFI boot option maintenance feature. This commit implements the addition of new boot option. User can select the block device volume having efi_simple_file_system_protocol and select the file corresponding to the Boot#### variable. User can also enter the description and optional_data of the BOOT#### variable in utf8. This commit adds "include/efi_config.h", it contains the common definition to be used from other menus such as UEFI Secure Boot key management. Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/efi_loader/efi_bootmgr.c3
-rw-r--r--lib/efi_loader/efi_boottime.c52
-rw-r--r--lib/efi_loader/efi_console.c70
-rw-r--r--lib/efi_loader/efi_disk.c50
-rw-r--r--lib/efi_loader/efi_file.c75
5 files changed, 203 insertions, 47 deletions
diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 234073ecb7..ede9116b3c 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -19,6 +19,9 @@
static const struct efi_boot_services *bs;
static const struct efi_runtime_services *rs;
+const efi_guid_t efi_guid_bootmenu_auto_generated =
+ EFICONFIG_AUTO_GENERATED_ENTRY_GUID;
+
/*
* bootmgr implements the logic of trying to find a payload to boot
* based on the BootOrder + BootXXXX variables, and then loading it.
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 4da64b5d29..1233418e77 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -2453,6 +2453,35 @@ static efi_status_t EFIAPI efi_protocols_per_handle(
return EFI_EXIT(EFI_SUCCESS);
}
+efi_status_t efi_locate_handle_buffer_int(enum efi_locate_search_type search_type,
+ const efi_guid_t *protocol, void *search_key,
+ efi_uintn_t *no_handles, efi_handle_t **buffer)
+{
+ efi_status_t r;
+ efi_uintn_t buffer_size = 0;
+
+ if (!no_handles || !buffer) {
+ r = EFI_INVALID_PARAMETER;
+ goto out;
+ }
+ *no_handles = 0;
+ *buffer = NULL;
+ r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
+ *buffer);
+ if (r != EFI_BUFFER_TOO_SMALL)
+ goto out;
+ r = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, buffer_size,
+ (void **)buffer);
+ if (r != EFI_SUCCESS)
+ goto out;
+ r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
+ *buffer);
+ if (r == EFI_SUCCESS)
+ *no_handles = buffer_size / sizeof(efi_handle_t);
+out:
+ return r;
+}
+
/**
* efi_locate_handle_buffer() - locate handles implementing a protocol
* @search_type: selection criterion
@@ -2474,30 +2503,13 @@ efi_status_t EFIAPI efi_locate_handle_buffer(
efi_uintn_t *no_handles, efi_handle_t **buffer)
{
efi_status_t r;
- efi_uintn_t buffer_size = 0;
EFI_ENTRY("%d, %pUs, %p, %p, %p", search_type, protocol, search_key,
no_handles, buffer);
- if (!no_handles || !buffer) {
- r = EFI_INVALID_PARAMETER;
- goto out;
- }
- *no_handles = 0;
- *buffer = NULL;
- r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
- *buffer);
- if (r != EFI_BUFFER_TOO_SMALL)
- goto out;
- r = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, buffer_size,
- (void **)buffer);
- if (r != EFI_SUCCESS)
- goto out;
- r = efi_locate_handle(search_type, protocol, search_key, &buffer_size,
- *buffer);
- if (r == EFI_SUCCESS)
- *no_handles = buffer_size / sizeof(efi_handle_t);
-out:
+ r = efi_locate_handle_buffer_int(search_type, protocol, search_key,
+ no_handles, buffer);
+
return EFI_EXIT(r);
}
diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c
index 3164fd484e..5be509f0d6 100644
--- a/lib/efi_loader/efi_console.c
+++ b/lib/efi_loader/efi_console.c
@@ -7,6 +7,7 @@
#define LOG_CATEGORY LOGC_EFI
+#include <ansi.h>
#include <common.h>
#include <charset.h>
#include <malloc.h>
@@ -1318,3 +1319,72 @@ out_of_memory:
printf("ERROR: Out of memory\n");
return r;
}
+
+/**
+ * efi_console_get_u16_string() - get user input string
+ *
+ * @cin: protocol interface to EFI_SIMPLE_TEXT_INPUT_PROTOCOL
+ * @buf: buffer to store user input string in UTF16
+ * @count: number of u16 string including NULL terminator that buf has
+ * @filter_func: callback to filter user input
+ * @row: row number to locate user input form
+ * @col: column number to locate user input form
+ * Return: status code
+ */
+efi_status_t efi_console_get_u16_string(struct efi_simple_text_input_protocol *cin,
+ u16 *buf, efi_uintn_t count,
+ efi_console_filter_func filter_func,
+ int row, int col)
+{
+ efi_status_t ret;
+ efi_uintn_t len = 0;
+ struct efi_input_key key;
+
+ printf(ANSI_CURSOR_POSITION
+ ANSI_CLEAR_LINE_TO_END
+ ANSI_CURSOR_SHOW, row, col);
+
+ ret = EFI_CALL(cin->reset(cin, false));
+ if (ret != EFI_SUCCESS)
+ return ret;
+
+ for (;;) {
+ do {
+ ret = EFI_CALL(cin->read_key_stroke(cin, &key));
+ mdelay(10);
+ } while (ret == EFI_NOT_READY);
+
+ if (key.unicode_char == u'\b') {
+ if (len > 0)
+ buf[--len] = u'\0';
+
+ printf(ANSI_CURSOR_POSITION
+ "%ls"
+ ANSI_CLEAR_LINE_TO_END, row, col, buf);
+ continue;
+ } else if (key.unicode_char == u'\r') {
+ buf[len] = u'\0';
+ return EFI_SUCCESS;
+ } else if (key.unicode_char == 0x3 || key.scan_code == 23) {
+ return EFI_ABORTED;
+ } else if (key.unicode_char < 0x20) {
+ /* ignore control codes other than Ctrl+C, '\r' and '\b' */
+ continue;
+ } else if (key.scan_code != 0) {
+ /* only accept single ESC press for cancel */
+ continue;
+ }
+
+ if (filter_func) {
+ if (filter_func(&key) != EFI_SUCCESS)
+ continue;
+ }
+
+ if (len >= (count - 1))
+ continue;
+
+ buf[len] = key.unicode_char;
+ len++;
+ printf(ANSI_CURSOR_POSITION "%ls", row, col, buf);
+ }
+}
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index f269abf135..a34ca46a11 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -760,3 +760,53 @@ efi_status_t efi_disk_init(void)
return EFI_SUCCESS;
}
+
+/**
+ * efi_disk_get_device_name() - get U-Boot device name associated with EFI handle
+ *
+ * @handle: pointer to the EFI handle
+ * @buf: pointer to the buffer to store the string
+ * @size: size of buffer
+ * Return: status code
+ */
+efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int size)
+{
+ int count;
+ int diskid;
+ enum uclass_id id;
+ unsigned int part;
+ struct udevice *dev;
+ struct blk_desc *desc;
+ const char *if_typename;
+ bool is_partition = false;
+ struct disk_part *part_data;
+
+ if (!handle || !buf || !size)
+ return EFI_INVALID_PARAMETER;
+
+ dev = handle->dev;
+ id = device_get_uclass_id(dev);
+ if (id == UCLASS_BLK) {
+ desc = dev_get_uclass_plat(dev);
+ } else if (id == UCLASS_PARTITION) {
+ desc = dev_get_uclass_plat(dev_get_parent(dev));
+ is_partition = true;
+ } else {
+ return EFI_INVALID_PARAMETER;
+ }
+ if_typename = blk_get_if_type_name(desc->if_type);
+ diskid = desc->devnum;
+
+ if (is_partition) {
+ part_data = dev_get_uclass_plat(dev);
+ part = part_data->partnum;
+ count = snprintf(buf, size, "%s %d:%d", if_typename, diskid, part);
+ } else {
+ count = snprintf(buf, size, "%s %d", if_typename, diskid);
+ }
+
+ if (count < 0 || (count + 1) > size)
+ return EFI_INVALID_PARAMETER;
+
+ return EFI_SUCCESS;
+}
diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
index 7a7077e6d0..c96a7f7ca3 100644
--- a/lib/efi_loader/efi_file.c
+++ b/lib/efi_loader/efi_file.c
@@ -246,10 +246,10 @@ error:
return NULL;
}
-static efi_status_t efi_file_open_int(struct efi_file_handle *this,
- struct efi_file_handle **new_handle,
- u16 *file_name, u64 open_mode,
- u64 attributes)
+efi_status_t efi_file_open_int(struct efi_file_handle *this,
+ struct efi_file_handle **new_handle,
+ u16 *file_name, u64 open_mode,
+ u64 attributes)
{
struct file_handle *fh = to_fh(this);
efi_status_t ret;
@@ -369,11 +369,17 @@ static efi_status_t file_close(struct file_handle *fh)
return EFI_SUCCESS;
}
-static efi_status_t EFIAPI efi_file_close(struct efi_file_handle *file)
+efi_status_t efi_file_close_int(struct efi_file_handle *file)
{
struct file_handle *fh = to_fh(file);
+
+ return file_close(fh);
+}
+
+static efi_status_t EFIAPI efi_file_close(struct efi_file_handle *file)
+{
EFI_ENTRY("%p", file);
- return EFI_EXIT(file_close(fh));
+ return EFI_EXIT(efi_file_close_int(file));
}
static efi_status_t EFIAPI efi_file_delete(struct efi_file_handle *file)
@@ -562,8 +568,8 @@ static efi_status_t dir_read(struct file_handle *fh, u64 *buffer_size,
return EFI_SUCCESS;
}
-static efi_status_t efi_file_read_int(struct efi_file_handle *this,
- efi_uintn_t *buffer_size, void *buffer)
+efi_status_t efi_file_read_int(struct efi_file_handle *this,
+ efi_uintn_t *buffer_size, void *buffer)
{
struct file_handle *fh = to_fh(this);
efi_status_t ret = EFI_SUCCESS;
@@ -773,24 +779,11 @@ out:
return EFI_EXIT(ret);
}
-/**
- * efi_file_setpos() - set current position in file
- *
- * This function implements the SetPosition service of the EFI file protocol.
- * See the UEFI spec for details.
- *
- * @file: file handle
- * @pos: new file position
- * Return: status code
- */
-static efi_status_t EFIAPI efi_file_setpos(struct efi_file_handle *file,
- u64 pos)
+efi_status_t efi_file_setpos_int(struct efi_file_handle *file, u64 pos)
{
struct file_handle *fh = to_fh(file);
efi_status_t ret = EFI_SUCCESS;
- EFI_ENTRY("%p, %llu", file, pos);
-
if (fh->isdir) {
if (pos != 0) {
ret = EFI_UNSUPPORTED;
@@ -812,6 +805,28 @@ static efi_status_t EFIAPI efi_file_setpos(struct efi_file_handle *file,
fh->offset = pos;
error:
+ return ret;
+}
+
+/**
+ * efi_file_setpos() - set current position in file
+ *
+ * This function implements the SetPosition service of the EFI file protocol.
+ * See the UEFI spec for details.
+ *
+ * @file: file handle
+ * @pos: new file position
+ * Return: status code
+ */
+static efi_status_t EFIAPI efi_file_setpos(struct efi_file_handle *file,
+ u64 pos)
+{
+ efi_status_t ret = EFI_SUCCESS;
+
+ EFI_ENTRY("%p, %llu", file, pos);
+
+ ret = efi_file_setpos_int(file, pos);
+
return EFI_EXIT(ret);
}
@@ -1138,17 +1153,23 @@ struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp)
return f;
}
+efi_status_t efi_open_volume_int(struct efi_simple_file_system_protocol *this,
+ struct efi_file_handle **root)
+{
+ struct file_system *fs = to_fs(this);
+
+ *root = file_open(fs, NULL, NULL, 0, 0);
+
+ return EFI_SUCCESS;
+}
+
static efi_status_t EFIAPI
efi_open_volume(struct efi_simple_file_system_protocol *this,
struct efi_file_handle **root)
{
- struct file_system *fs = to_fs(this);
-
EFI_ENTRY("%p, %p", this, root);
- *root = file_open(fs, NULL, NULL, 0, 0);
-
- return EFI_EXIT(EFI_SUCCESS);
+ return EFI_EXIT(efi_open_volume_int(this, root));
}
struct efi_simple_file_system_protocol *