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>
This commit is contained in:
Masahisa Kojima
2022-09-12 17:33:50 +09:00
committed by Heinrich Schuchardt
parent c2238fcf0c
commit 87d791423a
10 changed files with 1952 additions and 47 deletions

96
include/efi_config.h Normal file
View File

@@ -0,0 +1,96 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Menu-driven UEFI Variable maintenance
*
* Copyright (c) 2022 Masahisa Kojima, Linaro Limited
*/
#ifndef _EFI_CONFIG_H
#define _EFI_CONFIG_H
#include <efi_loader.h>
#define EFICONFIG_ENTRY_NUM_MAX 99
#define EFICONFIG_FILE_PATH_MAX 512
#define EFICONFIG_FILE_PATH_BUF_SIZE (EFICONFIG_FILE_PATH_MAX * sizeof(u16))
typedef efi_status_t (*eficonfig_entry_func)(void *data);
/**
* struct eficonfig_entry - menu entry structure
*
* @num: menu entry index
* @title: title of entry
* @key: unique key
* @efi_menu: pointer to the menu structure
* @func: callback function to be called when this entry is selected
* @data: data to be passed to the callback function, caller must free() this pointer
* @list: list structure
*/
struct eficonfig_entry {
u32 num;
char *title;
char key[3];
struct efimenu *efi_menu;
eficonfig_entry_func func;
void *data;
struct list_head list;
};
/**
* struct efimenu - efi menu structure
*
* @delay: delay for autoboot
* @active: active menu entry index
* @count: total count of menu entry
* @menu_header: menu header string
* @list: menu entry list structure
*/
struct efimenu {
int delay;
int active;
int count;
char *menu_header;
struct list_head list;
};
/**
* struct eficonfig_item - structure to construct eficonfig_entry
*
* @title: title of entry
* @func: callback function to be called when this entry is selected
* @data: data to be passed to the callback function
*/
struct eficonfig_item {
char *title;
eficonfig_entry_func func;
void *data;
};
/**
* struct eficonfig_select_file_info - structure to be used for file selection
*
* @current_volume: pointer to the efi_simple_file_system_protocol
* @dp_volume: pointer to device path of the selected device
* @current_path: pointer to the selected file path string
* @filepath_list: list_head structure for file path list
* @file_selectred: flag indicates file selecting status
*/
struct eficonfig_select_file_info {
struct efi_simple_file_system_protocol *current_volume;
struct efi_device_path *dp_volume;
u16 *current_path;
struct list_head filepath_list;
bool file_selected;
};
void eficonfig_print_msg(char *msg);
void eficonfig_destroy(struct efimenu *efi_menu);
efi_status_t eficonfig_process_quit(void *data);
efi_status_t eficonfig_process_common(struct efimenu *efi_menu, char *menu_header);
efi_status_t eficonfig_select_file_handler(void *data);
efi_status_t eficonfig_get_unused_bootoption(u16 *buf,
efi_uintn_t buf_size, u32 *index);
efi_status_t eficonfig_append_bootorder(u16 index);
#endif

View File

@@ -142,6 +142,11 @@ static inline efi_status_t efi_launch_capsules(void)
EFI_GUID(0x63293792, 0xadf5, 0x9325, \
0xb9, 0x9f, 0x4e, 0x0e, 0x45, 0x5c, 0x1b, 0x1e)
/* GUID for the auto generated boot menu entry */
#define EFICONFIG_AUTO_GENERATED_ENTRY_GUID \
EFI_GUID(0x38c1acc1, 0x9fc0, 0x41f0, \
0xb9, 0x01, 0xfa, 0x74, 0xd6, 0xd6, 0xe4, 0xde)
/* Use internal device tree when starting UEFI application */
#define EFI_FDT_USE_INTERNAL NULL
@@ -226,6 +231,9 @@ const char *__efi_nesting_dec(void);
#define EFI_CACHELINE_SIZE 128
#endif
/* max bootmenu title size for volume selection */
#define BOOTMENU_DEVICE_NAME_MAX 16
/* Key identifying current memory map */
extern efi_uintn_t efi_memory_map_key;
@@ -249,6 +257,9 @@ extern const struct efi_hii_string_protocol efi_hii_string;
uint16_t *efi_dp_str(struct efi_device_path *dp);
/* GUID for the auto generated boot menu entry */
extern const efi_guid_t efi_guid_bootmenu_auto_generated;
/* GUID of the U-Boot root node */
extern const efi_guid_t efi_u_boot_guid;
#ifdef CONFIG_SANDBOX
@@ -314,6 +325,8 @@ extern const efi_guid_t efi_guid_firmware_management_protocol;
extern const efi_guid_t efi_esrt_guid;
/* GUID of the SMBIOS table */
extern const efi_guid_t smbios_guid;
/*GUID of console */
extern const efi_guid_t efi_guid_text_input_protocol;
extern char __efi_runtime_start[], __efi_runtime_stop[];
extern char __efi_runtime_rel_start[], __efi_runtime_rel_stop[];
@@ -1064,4 +1077,28 @@ efi_status_t efi_esrt_populate(void);
efi_status_t efi_load_capsule_drivers(void);
efi_status_t platform_get_eventlog(struct udevice *dev, u64 *addr, u32 *sz);
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 efi_open_volume_int(struct efi_simple_file_system_protocol *this,
struct efi_file_handle **root);
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_close_int(struct efi_file_handle *file);
efi_status_t efi_file_read_int(struct efi_file_handle *this,
efi_uintn_t *buffer_size, void *buffer);
efi_status_t efi_file_setpos_int(struct efi_file_handle *file, u64 pos);
typedef efi_status_t (*efi_console_filter_func)(struct efi_input_key *key);
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 filer_func,
int row, int col);
efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int size);
#endif /* _EFI_LOADER_H */