1 // SPDX-License-Identifier: GPL-2.0+
3 * Menu-driven UEFI Variable maintenance
5 * Copyright (c) 2022 Masahisa Kojima, Linaro Limited
11 #include <efi_loader.h>
12 #include <efi_load_initrd.h>
13 #include <efi_config.h>
14 #include <efi_variable.h>
20 #include <asm/unaligned.h>
21 #include <linux/delay.h>
23 static struct efi_simple_text_input_protocol *cin;
25 #define EFICONFIG_DESCRIPTION_MAX 32
26 #define EFICONFIG_OPTIONAL_DATA_MAX 64
29 * struct eficonfig_filepath_info - structure to be used to store file path
31 * @name: file or directory name
32 * @list: list structure
34 struct eficonfig_filepath_info {
36 struct list_head list;
40 * struct eficonfig_boot_option - structure to be used for updating UEFI boot option
42 * @file_info: user selected file info
43 * @initrd_info: user selected initrd file info
44 * @boot_index: index of the boot option
45 * @description: pointer to the description string
46 * @optional_data: pointer to the optional_data
47 * @edit_completed: flag indicates edit complete
49 struct eficonfig_boot_option {
50 struct eficonfig_select_file_info file_info;
51 struct eficonfig_select_file_info initrd_info;
52 unsigned int boot_index;
59 * struct eficonfig_volume_entry_data - structure to be used to store volume info
61 * @file_info: pointer to file info structure
62 * @v: pointer to the protocol interface
63 * @dp: pointer to the device path
65 struct eficonfig_volume_entry_data {
66 struct eficonfig_select_file_info *file_info;
67 struct efi_simple_file_system_protocol *v;
68 struct efi_device_path *dp;
72 * struct eficonfig_file_entry_data - structure to be used to store file info
74 * @file_info: pointer to file info structure
75 * @is_directory: flag to identify the directory or file
76 * @file_name: name of directory or file
78 struct eficonfig_file_entry_data {
79 struct eficonfig_select_file_info *file_info;
85 * struct eficonfig_boot_selection_data - structure to be used to select the boot option entry
87 * @boot_index: index of the boot option
88 * @selected: pointer to store the selected index in the BootOrder variable
90 struct eficonfig_boot_selection_data {
96 * eficonfig_print_msg() - print message
98 * display the message to the user, user proceeds the screen
101 * @items: pointer to the structure of each menu entry
102 * @count: the number of menu entry
103 * @menu_header: pointer to the menu header string
104 * Return: status code
106 void eficonfig_print_msg(char *msg)
112 printf(ANSI_CURSOR_HIDE
115 "%s\n\n Press any key to continue", 3, 4, msg);
121 * eficonfig_print_entry() - print each menu entry
123 * @data: pointer to the data associated with each menu entry
125 static void eficonfig_print_entry(void *data)
127 struct eficonfig_entry *entry = data;
128 int reverse = (entry->efi_menu->active == entry->num);
130 /* TODO: support scroll or page for many entries */
133 * Move cursor to line where the entry will be drawn (entry->num)
134 * First 3 lines(menu header) + 1 empty line
136 printf(ANSI_CURSOR_POSITION, entry->num + 4, 7);
139 puts(ANSI_COLOR_REVERSE);
141 printf("%s", entry->title);
144 puts(ANSI_COLOR_RESET);
148 * eficonfig_display_statusline() - print status line
150 * @m: pointer to the menu structure
152 static void eficonfig_display_statusline(struct menu *m)
154 struct eficonfig_entry *entry;
156 if (menu_default_choice(m, (void *)&entry) < 0)
159 printf(ANSI_CURSOR_POSITION
161 ANSI_CURSOR_POSITION ANSI_CLEAR_LINE ANSI_CURSOR_POSITION
162 " Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit"
163 ANSI_CLEAR_LINE_TO_END ANSI_CURSOR_POSITION ANSI_CLEAR_LINE,
164 1, 1, entry->efi_menu->menu_header, entry->efi_menu->count + 5, 1,
165 entry->efi_menu->count + 6, 1, entry->efi_menu->count + 7, 1);
169 * eficonfig_choice_entry() - user key input handler
171 * @data: pointer to the efimenu structure
172 * Return: key string to identify the selected entry
174 static char *eficonfig_choice_entry(void *data)
177 struct list_head *pos, *n;
178 struct eficonfig_entry *entry;
179 enum bootmenu_key key = KEY_NONE;
180 struct efimenu *efi_menu = data;
183 bootmenu_loop((struct bootmenu_data *)efi_menu, &key, &esc);
187 if (efi_menu->active > 0)
189 /* no menu key selected, regenerate menu */
192 if (efi_menu->active < efi_menu->count - 1)
194 /* no menu key selected, regenerate menu */
197 list_for_each_safe(pos, n, &efi_menu->list) {
198 entry = list_entry(pos, struct eficonfig_entry, list);
199 if (entry->num == efi_menu->active)
204 /* Quit by choosing the last entry */
205 entry = list_last_entry(&efi_menu->list, struct eficonfig_entry, list);
208 /* Pressed key is not valid, no need to regenerate the menu */
215 * eficonfig_destroy() - destroy efimenu
217 * @efi_menu: pointer to the efimenu structure
219 void eficonfig_destroy(struct efimenu *efi_menu)
221 struct list_head *pos, *n;
222 struct eficonfig_entry *entry;
227 list_for_each_safe(pos, n, &efi_menu->list) {
228 entry = list_entry(pos, struct eficonfig_entry, list);
230 list_del(&entry->list);
233 free(efi_menu->menu_header);
238 * eficonfig_process_quit() - callback function for "Quit" entry
240 * @data: pointer to the data
241 * Return: status code
243 efi_status_t eficonfig_process_quit(void *data)
249 * append_entry() - append menu item
251 * @efi_menu: pointer to the efimenu structure
252 * @title: pointer to the entry title
253 * @func: callback of each entry
254 * @data: pointer to the data to be passed to each entry callback
255 * Return: status code
257 static efi_status_t append_entry(struct efimenu *efi_menu,
258 char *title, eficonfig_entry_func func, void *data)
260 struct eficonfig_entry *entry;
262 if (efi_menu->count >= EFICONFIG_ENTRY_NUM_MAX)
263 return EFI_OUT_OF_RESOURCES;
265 entry = calloc(1, sizeof(struct eficonfig_entry));
267 return EFI_OUT_OF_RESOURCES;
269 entry->title = title;
270 sprintf(entry->key, "%d", efi_menu->count);
271 entry->efi_menu = efi_menu;
274 entry->num = efi_menu->count++;
275 list_add_tail(&entry->list, &efi_menu->list);
281 * append_quit_entry() - append quit entry
283 * @efi_menu: pointer to the efimenu structure
284 * Return: status code
286 static efi_status_t append_quit_entry(struct efimenu *efi_menu)
291 title = strdup("Quit");
293 return EFI_OUT_OF_RESOURCES;
295 ret = append_entry(efi_menu, title, eficonfig_process_quit, NULL);
296 if (ret != EFI_SUCCESS)
303 * eficonfig_create_fixed_menu() - create fixed entry menu structure
305 * @items: pointer to the menu entry item
306 * @count: the number of menu entry
307 * Return: pointer to the efimenu structure
309 void *eficonfig_create_fixed_menu(const struct eficonfig_item *items, int count)
314 struct efimenu *efi_menu;
315 const struct eficonfig_item *iter = items;
317 efi_menu = calloc(1, sizeof(struct efimenu));
321 INIT_LIST_HEAD(&efi_menu->list);
322 for (i = 0; i < count; i++, iter++) {
323 title = strdup(iter->title);
327 ret = append_entry(efi_menu, title, iter->func, iter->data);
328 if (ret != EFI_SUCCESS) {
336 eficonfig_destroy(efi_menu);
342 * eficonfig_process_common() - main handler for UEFI menu
344 * Construct the structures required to show the menu, then handle
345 * the user input interacting with u-boot menu functions.
347 * @efi_menu: pointer to the efimenu structure
348 * @menu_header: pointer to the menu header string
349 * Return: status code
351 efi_status_t eficonfig_process_common(struct efimenu *efi_menu, char *menu_header)
355 struct list_head *pos, *n;
356 struct eficonfig_entry *entry;
357 efi_status_t ret = EFI_SUCCESS;
359 if (efi_menu->count > EFICONFIG_ENTRY_NUM_MAX)
360 return EFI_OUT_OF_RESOURCES;
362 efi_menu->delay = -1;
363 efi_menu->active = 0;
366 efi_menu->menu_header = strdup(menu_header);
367 if (!efi_menu->menu_header)
368 return EFI_OUT_OF_RESOURCES;
371 menu = menu_create(NULL, 0, 1, eficonfig_display_statusline,
372 eficonfig_print_entry, eficonfig_choice_entry,
375 return EFI_INVALID_PARAMETER;
377 list_for_each_safe(pos, n, &efi_menu->list) {
378 entry = list_entry(pos, struct eficonfig_entry, list);
379 if (!menu_item_add(menu, entry->key, entry)) {
380 ret = EFI_INVALID_PARAMETER;
385 entry = list_first_entry_or_null(&efi_menu->list, struct eficonfig_entry, list);
387 menu_default_set(menu, entry->key);
389 printf(ANSI_CURSOR_HIDE
391 ANSI_CURSOR_POSITION, 1, 1);
393 if (menu_get_choice(menu, &choice)) {
396 ret = entry->func(entry->data);
401 printf(ANSI_CLEAR_CONSOLE
403 ANSI_CURSOR_SHOW, 1, 1);
409 * eficonfig_volume_selected() - handler of volume selection
411 * @data: pointer to the data of selected entry
412 * Return: status code
414 static efi_status_t eficonfig_volume_selected(void *data)
416 struct eficonfig_volume_entry_data *info = data;
419 info->file_info->current_volume = info->v;
420 info->file_info->dp_volume = info->dp;
427 * create_selected_device_path() - create device path
429 * @file_info: pointer to the selected file information
431 * device path or NULL. Caller must free the returned value
434 struct efi_device_path *create_selected_device_path(struct eficonfig_select_file_info *file_info)
439 struct efi_device_path *dp;
440 struct efi_device_path_file_path *fp;
442 fp_size = sizeof(struct efi_device_path) +
443 ((u16_strlen(file_info->current_path) + 1) * sizeof(u16));
444 buf = calloc(1, fp_size + sizeof(END));
449 fp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE,
450 fp->dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH,
451 fp->dp.length = (u16)fp_size;
452 u16_strcpy(fp->str, file_info->current_path);
456 *((struct efi_device_path *)p) = END;
458 dp = efi_dp_append(file_info->dp_volume, (struct efi_device_path *)buf);
465 * eficonfig_file_selected() - handler of file selection
467 * @data: pointer to the data of selected entry
468 * Return: status code
470 static efi_status_t eficonfig_file_selected(void *data)
473 struct eficonfig_file_entry_data *info = data;
476 return EFI_INVALID_PARAMETER;
478 if (!strcmp(info->file_name, "..")) {
479 struct eficonfig_filepath_info *iter;
480 struct list_head *pos, *n;
483 tmp = info->file_info->current_path;
485 memset(info->file_info->current_path, 0, EFICONFIG_FILE_PATH_BUF_SIZE);
486 filepath = calloc(1, EFICONFIG_FILE_PATH_MAX);
488 return EFI_OUT_OF_RESOURCES;
490 list_for_each_safe(pos, n, &info->file_info->filepath_list) {
491 iter = list_entry(pos, struct eficonfig_filepath_info, list);
493 is_last = list_is_last(&iter->list, &info->file_info->filepath_list);
495 list_del(&iter->list);
500 strlcat(filepath, iter->name, EFICONFIG_FILE_PATH_MAX);
502 utf8_utf16_strcpy(&tmp, filepath);
505 struct eficonfig_filepath_info *filepath_info;
507 new_len = u16_strlen(info->file_info->current_path) +
508 strlen(info->file_name);
509 if (new_len >= EFICONFIG_FILE_PATH_MAX) {
510 eficonfig_print_msg("File path is too long!");
511 return EFI_INVALID_PARAMETER;
513 tmp = &info->file_info->current_path[u16_strlen(info->file_info->current_path)];
514 utf8_utf16_strcpy(&tmp, info->file_name);
516 filepath_info = calloc(1, sizeof(struct eficonfig_filepath_info));
518 return EFI_OUT_OF_RESOURCES;
520 filepath_info->name = strdup(info->file_name);
521 if (!filepath_info->name) {
523 return EFI_OUT_OF_RESOURCES;
525 list_add_tail(&filepath_info->list, &info->file_info->filepath_list);
527 if (!info->is_directory)
528 info->file_info->file_selected = true;
535 * eficonfig_select_volume() - construct the volume selection menu
537 * @file_info: pointer to the file selection structure
538 * Return: status code
540 static efi_status_t eficonfig_select_volume(struct eficonfig_select_file_info *file_info)
545 struct efimenu *efi_menu;
546 struct list_head *pos, *n;
547 struct efi_handler *handler;
548 struct eficonfig_entry *entry;
549 struct efi_device_path *device_path;
550 efi_handle_t *volume_handles = NULL;
551 struct efi_simple_file_system_protocol *v;
553 ret = efi_locate_handle_buffer_int(BY_PROTOCOL, &efi_simple_file_system_protocol_guid,
554 NULL, &count, (efi_handle_t **)&volume_handles);
555 if (ret != EFI_SUCCESS) {
556 eficonfig_print_msg("No block device found!");
560 efi_menu = calloc(1, sizeof(struct efimenu));
562 return EFI_OUT_OF_RESOURCES;
564 INIT_LIST_HEAD(&efi_menu->list);
565 for (i = 0; i < count; i++) {
567 struct efi_block_io *block_io;
568 struct eficonfig_volume_entry_data *info;
570 if (efi_menu->count >= EFICONFIG_ENTRY_NUM_MAX - 1)
573 ret = efi_search_protocol(volume_handles[i],
574 &efi_simple_file_system_protocol_guid, &handler);
575 if (ret != EFI_SUCCESS)
577 ret = efi_protocol_open(handler, (void **)&v, efi_root, NULL,
578 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
579 if (ret != EFI_SUCCESS)
582 ret = efi_search_protocol(volume_handles[i], &efi_guid_device_path, &handler);
583 if (ret != EFI_SUCCESS)
585 ret = efi_protocol_open(handler, (void **)&device_path,
586 efi_root, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
587 if (ret != EFI_SUCCESS)
590 ret = efi_search_protocol(volume_handles[i], &efi_block_io_guid, &handler);
591 if (ret != EFI_SUCCESS)
593 ret = efi_protocol_open(handler, (void **)&block_io,
594 efi_root, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
595 if (ret != EFI_SUCCESS)
598 info = calloc(1, sizeof(struct eficonfig_volume_entry_data));
600 ret = EFI_OUT_OF_RESOURCES;
604 devname = calloc(1, BOOTMENU_DEVICE_NAME_MAX);
607 ret = EFI_OUT_OF_RESOURCES;
610 ret = efi_disk_get_device_name(volume_handles[i], devname,
611 BOOTMENU_DEVICE_NAME_MAX);
612 if (ret != EFI_SUCCESS) {
618 info->dp = device_path;
619 info->file_info = file_info;
620 ret = append_entry(efi_menu, devname, eficonfig_volume_selected, info);
621 if (ret != EFI_SUCCESS) {
627 ret = append_quit_entry(efi_menu);
628 if (ret != EFI_SUCCESS)
631 ret = eficonfig_process_common(efi_menu, " ** Select Volume **");
633 efi_free_pool(volume_handles);
634 list_for_each_safe(pos, n, &efi_menu->list) {
635 entry = list_entry(pos, struct eficonfig_entry, list);
638 eficonfig_destroy(efi_menu);
644 * sort_file() - sort the file name in ascii order
646 * @data1: pointer to the file entry data
647 * @data2: pointer to the file entry data
648 * Return: -1 if the data1 file name is less than data2 file name,
649 * 0 if both file name match,
650 * 1 if the data1 file name is greater thant data2 file name.
652 static int sort_file(const void *arg1, const void *arg2)
654 const struct eficonfig_file_entry_data *data1, *data2;
656 data1 = *((const struct eficonfig_file_entry_data **)arg1);
657 data2 = *((const struct eficonfig_file_entry_data **)arg2);
659 return strcasecmp(data1->file_name, data2->file_name);
663 * eficonfig_create_file_entry() - construct the file menu entry
665 * @efi_menu: pointer to the efimenu structure
666 * @count: number of the directory and file
667 * @tmp_infos: pointer to the entry data array
668 * @f: pointer to the file handle
669 * @buf: pointer to the buffer to store the directory information
670 * @file_info: pointer to the file selection structure
671 * Return: status code
674 eficonfig_create_file_entry(struct efimenu *efi_menu, u32 count,
675 struct eficonfig_file_entry_data **tmp_infos,
676 struct efi_file_handle *f, struct efi_file_info *buf,
677 struct eficonfig_select_file_info *file_info)
682 u32 i, entry_num = 0;
683 struct eficonfig_file_entry_data *info;
685 efi_file_setpos_int(f, 0);
686 /* Read directory and construct menu structure */
687 for (i = 0; i < count; i++) {
688 if (entry_num >= EFICONFIG_ENTRY_NUM_MAX - 1)
691 len = sizeof(struct efi_file_info) + EFICONFIG_FILE_PATH_BUF_SIZE;
692 ret = efi_file_read_int(f, &len, buf);
693 if (ret != EFI_SUCCESS || len == 0)
696 info = calloc(1, sizeof(struct eficonfig_file_entry_data));
698 ret = EFI_OUT_OF_RESOURCES;
702 /* append '\\' at the end of directory name */
703 name = calloc(1, utf16_utf8_strlen(buf->file_name) + 2);
705 ret = EFI_OUT_OF_RESOURCES;
710 utf16_utf8_strcpy(&p, buf->file_name);
711 if (buf->attribute & EFI_FILE_DIRECTORY) {
712 /* filter out u'.' */
713 if (!u16_strcmp(buf->file_name, u".")) {
718 name[u16_strlen(buf->file_name)] = '\\';
719 info->is_directory = true;
722 info->file_name = name;
723 info->file_info = file_info;
724 tmp_infos[entry_num++] = info;
727 qsort(tmp_infos, entry_num, sizeof(*tmp_infos),
728 (int (*)(const void *, const void *))sort_file);
730 for (i = 0; i < entry_num; i++) {
731 ret = append_entry(efi_menu, tmp_infos[i]->file_name,
732 eficonfig_file_selected, tmp_infos[i]);
733 if (ret != EFI_SUCCESS)
742 * eficonfig_select_file() - construct the file selection menu
744 * @file_info: pointer to the file selection structure
745 * @root: pointer to the file handle
746 * Return: status code
748 static efi_status_t eficonfig_select_file(struct eficonfig_select_file_info *file_info,
749 struct efi_file_handle *root)
754 struct efimenu *efi_menu;
755 struct efi_file_handle *f;
756 struct efi_file_info *buf;
757 struct eficonfig_file_entry_data **tmp_infos;
759 buf = calloc(1, sizeof(struct efi_file_info) + EFICONFIG_FILE_PATH_BUF_SIZE);
761 return EFI_OUT_OF_RESOURCES;
763 while (!file_info->file_selected) {
764 efi_menu = calloc(1, sizeof(struct efimenu));
766 ret = EFI_OUT_OF_RESOURCES;
769 INIT_LIST_HEAD(&efi_menu->list);
771 ret = efi_file_open_int(root, &f, file_info->current_path, EFI_FILE_MODE_READ, 0);
772 if (ret != EFI_SUCCESS) {
773 eficonfig_print_msg("Reading volume failed!");
779 /* Count the number of directory entries */
781 len = sizeof(struct efi_file_info) + EFICONFIG_FILE_PATH_BUF_SIZE;
782 ret = efi_file_read_int(f, &len, buf);
783 if (ret != EFI_SUCCESS || len == 0)
789 /* allocate array to sort the entry */
790 tmp_infos = calloc(count, sizeof(*tmp_infos));
792 ret = EFI_OUT_OF_RESOURCES;
796 ret = eficonfig_create_file_entry(efi_menu, count, tmp_infos,
798 if (ret != EFI_SUCCESS)
801 ret = append_quit_entry(efi_menu);
802 if (ret != EFI_SUCCESS)
805 ret = eficonfig_process_common(efi_menu, " ** Select File **");
807 efi_file_close_int(f);
808 eficonfig_destroy(efi_menu);
811 for (i = 0; i < count; i++)
817 if (ret != EFI_SUCCESS)
828 * handle_user_input() - handle user input
830 * @buf: pointer to the buffer
831 * @buf_size: size of the buffer
832 * @cursor_col: cursor column for user input
833 * @msg: pointer to the string to display
834 * Return: status code
836 static efi_status_t handle_user_input(u16 *buf, int buf_size,
837 int cursor_col, char *msg)
842 printf(ANSI_CLEAR_CONSOLE
846 " Press ENTER to complete, ESC/CTRL+C to quit",
849 /* tmp is used to accept user cancel */
850 tmp = calloc(1, buf_size * sizeof(u16));
852 return EFI_OUT_OF_RESOURCES;
854 ret = efi_console_get_u16_string(cin, tmp, buf_size, NULL, 4, cursor_col);
855 if (ret == EFI_SUCCESS)
856 u16_strcpy(buf, tmp);
860 /* to stay the parent menu */
861 ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret;
867 * eficonfig_boot_add_enter_description() - handle user input for description
869 * @data: pointer to the internal boot option structure
870 * Return: status code
872 static efi_status_t eficonfig_boot_add_enter_description(void *data)
874 struct eficonfig_boot_option *bo = data;
876 return handle_user_input(bo->description, EFICONFIG_DESCRIPTION_MAX, 22,
877 "\n ** Edit Description **\n"
879 " enter description: ");
883 * eficonfig_boot_add_optional_data() - handle user input for optional data
885 * @data: pointer to the internal boot option structure
886 * Return: status code
888 static efi_status_t eficonfig_boot_add_optional_data(void *data)
890 struct eficonfig_boot_option *bo = data;
892 return handle_user_input(bo->optional_data, EFICONFIG_OPTIONAL_DATA_MAX, 24,
893 "\n ** Edit Optional Data **\n"
895 " enter optional data:");
899 * eficonfig_boot_edit_save() - handler to save the boot option
901 * @data: pointer to the internal boot option structure
902 * Return: status code
904 static efi_status_t eficonfig_boot_edit_save(void *data)
906 struct eficonfig_boot_option *bo = data;
908 if (u16_strlen(bo->description) == 0) {
909 eficonfig_print_msg("Boot Description is empty!");
910 bo->edit_completed = false;
911 return EFI_NOT_READY;
913 if (u16_strlen(bo->file_info.current_path) == 0) {
914 eficonfig_print_msg("File is not selected!");
915 bo->edit_completed = false;
916 return EFI_NOT_READY;
919 bo->edit_completed = true;
925 * eficonfig_process_select_file() - callback function for "Select File" entry
927 * @data: pointer to the data
928 * Return: status code
930 efi_status_t eficonfig_process_select_file(void *data)
936 * eficonfig_process_clear_file_selection() - callback function for "Clear" entry
938 * @data: pointer to the data
939 * Return: status code
941 efi_status_t eficonfig_process_clear_file_selection(void *data)
943 struct eficonfig_select_file_info *file_info = data;
945 /* clear the existing file information */
946 file_info->current_volume = NULL;
947 file_info->current_path[0] = u'\0';
948 file_info->dp_volume = NULL;
953 static struct eficonfig_item select_file_menu_items[] = {
954 {"Select File", eficonfig_process_select_file},
955 {"Clear", eficonfig_process_clear_file_selection},
956 {"Quit", eficonfig_process_quit},
961 * eficonfig_display_select_file_option() - display select file option
963 * @file_info: pointer to the file information structure
964 * Return: status code
966 efi_status_t eficonfig_display_select_file_option(struct eficonfig_select_file_info *file_info)
969 struct efimenu *efi_menu;
971 select_file_menu_items[1].data = file_info;
972 efi_menu = eficonfig_create_fixed_menu(select_file_menu_items,
973 ARRAY_SIZE(select_file_menu_items));
975 return EFI_OUT_OF_RESOURCES;
977 ret = eficonfig_process_common(efi_menu, " ** Update File **");
978 if (ret != EFI_SUCCESS) /* User selects "Clear" or "Quit" */
981 eficonfig_destroy(efi_menu);
987 * eficonfig_select_file_handler() - handle user file selection
989 * @data: pointer to the data
990 * Return: status code
992 efi_status_t eficonfig_select_file_handler(void *data)
996 struct list_head *pos, *n;
997 struct efi_file_handle *root;
998 struct eficonfig_filepath_info *item;
999 struct eficonfig_select_file_info *tmp = NULL;
1000 struct eficonfig_select_file_info *file_info = data;
1002 ret = eficonfig_display_select_file_option(file_info);
1003 if (ret != EFI_SUCCESS)
1006 tmp = calloc(1, sizeof(struct eficonfig_select_file_info));
1008 return EFI_OUT_OF_RESOURCES;
1010 tmp->current_path = calloc(1, EFICONFIG_FILE_PATH_BUF_SIZE);
1011 if (!tmp->current_path) {
1013 return EFI_OUT_OF_RESOURCES;
1015 INIT_LIST_HEAD(&tmp->filepath_list);
1017 while (!tmp->file_selected) {
1018 tmp->current_volume = NULL;
1019 memset(tmp->current_path, 0, EFICONFIG_FILE_PATH_BUF_SIZE);
1021 ret = eficonfig_select_volume(tmp);
1022 if (ret != EFI_SUCCESS)
1025 if (!tmp->current_volume)
1026 return EFI_INVALID_PARAMETER;
1028 ret = efi_open_volume_int(tmp->current_volume, &root);
1029 if (ret != EFI_SUCCESS)
1032 ret = eficonfig_select_file(tmp, root);
1033 if (ret == EFI_ABORTED)
1035 if (ret != EFI_SUCCESS)
1040 if (ret == EFI_SUCCESS) {
1041 len = u16_strlen(tmp->current_path);
1042 len = (len >= EFICONFIG_FILE_PATH_MAX) ? (EFICONFIG_FILE_PATH_MAX - 1) : len;
1043 memcpy(file_info->current_path, tmp->current_path, len * sizeof(u16));
1044 file_info->current_path[len] = u'\0';
1045 file_info->current_volume = tmp->current_volume;
1046 file_info->dp_volume = tmp->dp_volume;
1049 list_for_each_safe(pos, n, &tmp->filepath_list) {
1050 item = list_entry(pos, struct eficonfig_filepath_info, list);
1051 list_del(&item->list);
1055 free(tmp->current_path);
1058 /* to stay the parent menu */
1059 ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret;
1065 * eficonfig_get_unused_bootoption() - get unused "Boot####" index
1067 * @buf: pointer to the buffer to store boot option variable name
1068 * @buf_size: buffer size
1069 * @index: pointer to store the index in the BootOrder variable
1070 * Return: status code
1072 efi_status_t eficonfig_get_unused_bootoption(u16 *buf, efi_uintn_t buf_size,
1073 unsigned int *index)
1079 if (buf_size < u16_strsize(u"Boot####"))
1080 return EFI_BUFFER_TOO_SMALL;
1082 for (i = 0; i <= 0xFFFF; i++) {
1084 efi_create_indexed_name(buf, buf_size, "Boot", i);
1085 ret = efi_get_variable_int(buf, &efi_global_variable_guid,
1086 NULL, &size, NULL, NULL);
1087 if (ret == EFI_BUFFER_TOO_SMALL)
1094 return EFI_OUT_OF_RESOURCES;
1102 * eficonfig_set_boot_option() - set boot option
1104 * @varname: pointer to variable name
1105 * @dp: pointer to device path
1106 * @label: pointer to label string
1107 * @optional_data: pointer to optional data
1108 * Return: status code
1110 static efi_status_t eficonfig_set_boot_option(u16 *varname, struct efi_device_path *dp,
1111 efi_uintn_t dp_size, u16 *label, char *optional_data)
1116 struct efi_load_option lo;
1119 lo.file_path_length = dp_size;
1120 lo.attributes = LOAD_OPTION_ACTIVE;
1121 lo.optional_data = optional_data;
1124 size = efi_serialize_load_option(&lo, (u8 **)&p);
1126 return EFI_INVALID_PARAMETER;
1128 ret = efi_set_variable_int(varname, &efi_global_variable_guid,
1129 EFI_VARIABLE_NON_VOLATILE |
1130 EFI_VARIABLE_BOOTSERVICE_ACCESS |
1131 EFI_VARIABLE_RUNTIME_ACCESS,
1139 * eficonfig_append_bootorder() - append new boot option in BootOrder variable
1141 * @index: "Boot####" index to append to BootOrder variable
1142 * Return: status code
1144 efi_status_t eficonfig_append_bootorder(u16 index)
1148 u16 *new_bootorder = NULL;
1149 efi_uintn_t last, size, new_size;
1151 /* append new boot option */
1152 bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size);
1153 last = size / sizeof(u16);
1154 new_size = size + sizeof(u16);
1155 new_bootorder = calloc(1, new_size);
1156 if (!new_bootorder) {
1157 ret = EFI_OUT_OF_RESOURCES;
1160 memcpy(new_bootorder, bootorder, size);
1161 new_bootorder[last] = index;
1163 ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid,
1164 EFI_VARIABLE_NON_VOLATILE |
1165 EFI_VARIABLE_BOOTSERVICE_ACCESS |
1166 EFI_VARIABLE_RUNTIME_ACCESS,
1167 new_size, new_bootorder, false);
1168 if (ret != EFI_SUCCESS)
1173 free(new_bootorder);
1179 * create_boot_option_entry() - create boot option entry
1181 * @efi_menu: pointer to the efimenu structure
1182 * @title: pointer to the entry title
1183 * @val: pointer to boot option label
1184 * @func: callback of each entry
1185 * @data: pointer to the data to be passed to each entry callback
1186 * Return: status code
1188 static efi_status_t create_boot_option_entry(struct efimenu *efi_menu, char *title, u16 *val,
1189 eficonfig_entry_func func, void *data)
1194 len = strlen(title) + 1;
1196 len += utf16_utf8_strlen(val);
1197 buf = calloc(1, len);
1199 return EFI_OUT_OF_RESOURCES;
1203 p = buf + strlen(title);
1204 utf16_utf8_strcpy(&p, val);
1207 return append_entry(efi_menu, buf, func, data);
1211 * prepare_file_selection_entry() - prepare file selection entry
1213 * @efi_menu: pointer to the efimenu structure
1214 * @title: pointer to the title string
1215 * @file_info: pointer to the file info
1216 * Return: status code
1218 static efi_status_t prepare_file_selection_entry(struct efimenu *efi_menu, char *title,
1219 struct eficonfig_select_file_info *file_info)
1223 u16 *file_name = NULL, *p;
1224 efi_handle_t handle;
1227 devname = calloc(1, EFICONFIG_VOLUME_PATH_MAX + 1);
1229 return EFI_OUT_OF_RESOURCES;
1231 /* get the device name only when the user already selected the file path */
1232 handle = efi_dp_find_obj(file_info->dp_volume, NULL, NULL);
1234 ret = efi_disk_get_device_name(handle, devname, EFICONFIG_VOLUME_PATH_MAX);
1235 if (ret != EFI_SUCCESS)
1240 * If the preconfigured volume does not exist in the system, display the text
1241 * converted volume device path instead of U-Boot friendly name(e.g. "usb 0:1").
1243 if (!handle && file_info->dp_volume) {
1247 dp_str = efi_dp_str(file_info->dp_volume);
1249 utf16_utf8_strncpy(&q, dp_str, EFICONFIG_VOLUME_PATH_MAX);
1251 efi_free_pool(dp_str);
1254 /* append u'/' to devname, it is just for display purpose. */
1255 if (file_info->current_path[0] != u'\0' && file_info->current_path[0] != u'/')
1256 strlcat(devname, "/", EFICONFIG_VOLUME_PATH_MAX + 1);
1258 len = strlen(devname);
1259 len += utf16_utf8_strlen(file_info->current_path) + 1;
1260 file_name = calloc(1, len * sizeof(u16));
1262 ret = EFI_OUT_OF_RESOURCES;
1267 utf8_utf16_strcpy(&p, devname);
1268 u16_strlcat(file_name, file_info->current_path, len);
1269 ret = create_boot_option_entry(efi_menu, title, file_name,
1270 eficonfig_select_file_handler, file_info);
1279 * eficonfig_show_boot_option() - prepare menu entry for editing boot option
1281 * Construct the structures to create edit boot option menu
1283 * @bo: pointer to the boot option
1284 * @header_str: pointer to the header string
1285 * Return: status code
1287 static efi_status_t eficonfig_show_boot_option(struct eficonfig_boot_option *bo,
1291 struct efimenu *efi_menu;
1293 efi_menu = calloc(1, sizeof(struct efimenu));
1295 return EFI_OUT_OF_RESOURCES;
1297 INIT_LIST_HEAD(&efi_menu->list);
1299 ret = create_boot_option_entry(efi_menu, "Description: ", bo->description,
1300 eficonfig_boot_add_enter_description, bo);
1301 if (ret != EFI_SUCCESS)
1304 ret = prepare_file_selection_entry(efi_menu, "File: ", &bo->file_info);
1305 if (ret != EFI_SUCCESS)
1308 ret = prepare_file_selection_entry(efi_menu, "Initrd File: ", &bo->initrd_info);
1309 if (ret != EFI_SUCCESS)
1312 ret = create_boot_option_entry(efi_menu, "Optional Data: ", bo->optional_data,
1313 eficonfig_boot_add_optional_data, bo);
1314 if (ret != EFI_SUCCESS)
1317 ret = create_boot_option_entry(efi_menu, "Save", NULL,
1318 eficonfig_boot_edit_save, bo);
1319 if (ret != EFI_SUCCESS)
1322 ret = create_boot_option_entry(efi_menu, "Quit", NULL,
1323 eficonfig_process_quit, NULL);
1324 if (ret != EFI_SUCCESS)
1327 ret = eficonfig_process_common(efi_menu, header_str);
1329 eficonfig_destroy(efi_menu);
1335 * fill_file_info() - fill the file info from efi_device_path structure
1337 * @dp: pointer to the device path
1338 * @file_info: pointer to the file info structure
1339 * @device_dp: pointer to the volume device path
1341 static void fill_file_info(struct efi_device_path *dp,
1342 struct eficonfig_select_file_info *file_info,
1343 struct efi_device_path *device_dp)
1346 struct efi_device_path *file_dp = NULL;
1348 efi_dp_split_file_path(dp, &device_dp, &file_dp);
1349 file_info->dp_volume = device_dp;
1352 file_str = efi_dp_str(file_dp);
1354 * efi_convert_device_path_to_text() automatically adds u'/' at the
1355 * beginning of file name, remove u'/' before copying to current_path
1361 u16_strcpy(file_info->current_path, p);
1362 efi_free_pool(file_dp);
1363 efi_free_pool(file_str);
1368 * eficonfig_edit_boot_option() - prepare boot option structure for editing
1370 * Construct the boot option structure and copy the existing value
1372 * @varname: pointer to the UEFI variable name
1373 * @bo: pointer to the boot option
1374 * @load_option: pointer to the load option
1375 * @load_option_size: size of the load option
1376 * @header_str: pointer to the header string
1377 * Return : status code
1379 static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_boot_option *bo,
1380 void *load_option, efi_uintn_t load_option_size,
1385 char *tmp = NULL, *p;
1386 struct efi_load_option lo = {0};
1387 efi_uintn_t final_dp_size;
1388 struct efi_device_path *dp = NULL;
1389 efi_uintn_t size = load_option_size;
1390 struct efi_device_path *final_dp = NULL;
1391 struct efi_device_path *device_dp = NULL;
1392 struct efi_device_path *initrd_dp = NULL;
1393 struct efi_device_path *initrd_device_dp = NULL;
1395 const struct efi_initrd_dp id_dp = {
1398 DEVICE_PATH_TYPE_MEDIA_DEVICE,
1399 DEVICE_PATH_SUB_TYPE_VENDOR_PATH,
1400 sizeof(id_dp.vendor),
1402 EFI_INITRD_MEDIA_GUID,
1405 DEVICE_PATH_TYPE_END,
1406 DEVICE_PATH_SUB_TYPE_END,
1411 bo->file_info.current_path = calloc(1, EFICONFIG_FILE_PATH_BUF_SIZE);
1412 if (!bo->file_info.current_path) {
1413 ret = EFI_OUT_OF_RESOURCES;
1417 bo->initrd_info.current_path = calloc(1, EFICONFIG_FILE_PATH_BUF_SIZE);
1418 if (!bo->file_info.current_path) {
1419 ret = EFI_OUT_OF_RESOURCES;
1423 bo->description = calloc(1, EFICONFIG_DESCRIPTION_MAX * sizeof(u16));
1424 if (!bo->description) {
1425 ret = EFI_OUT_OF_RESOURCES;
1429 bo->optional_data = calloc(1, EFICONFIG_OPTIONAL_DATA_MAX * sizeof(u16));
1430 if (!bo->optional_data) {
1431 ret = EFI_OUT_OF_RESOURCES;
1435 /* copy the preset value */
1437 ret = efi_deserialize_load_option(&lo, load_option, &size);
1438 if (ret != EFI_SUCCESS)
1442 ret = EFI_INVALID_PARAMETER;
1445 /* truncate the long label string */
1446 if (u16_strlen(lo.label) >= EFICONFIG_DESCRIPTION_MAX)
1447 lo.label[EFICONFIG_DESCRIPTION_MAX - 1] = u'\0';
1449 u16_strcpy(bo->description, lo.label);
1451 /* EFI image file path is a first instance */
1453 fill_file_info(lo.file_path, &bo->file_info, device_dp);
1455 /* Initrd file path(optional) is placed at second instance. */
1456 initrd_dp = efi_dp_from_lo(&lo, &efi_lf2_initrd_guid);
1458 fill_file_info(initrd_dp, &bo->initrd_info, initrd_device_dp);
1459 efi_free_pool(initrd_dp);
1463 memcpy(bo->optional_data, lo.optional_data, size);
1467 ret = eficonfig_show_boot_option(bo, header_str);
1468 if (ret == EFI_SUCCESS && bo->edit_completed)
1470 if (ret == EFI_NOT_READY)
1472 if (ret != EFI_SUCCESS)
1476 if (bo->initrd_info.dp_volume) {
1477 dp = create_selected_device_path(&bo->initrd_info);
1479 ret = EFI_OUT_OF_RESOURCES;
1482 initrd_dp = efi_dp_append((const struct efi_device_path *)&id_dp, dp);
1486 dp = create_selected_device_path(&bo->file_info);
1488 ret = EFI_OUT_OF_RESOURCES;
1491 final_dp_size = efi_dp_size(dp) + sizeof(END);
1493 final_dp = efi_dp_concat(dp, initrd_dp);
1494 final_dp_size += efi_dp_size(initrd_dp) + sizeof(END);
1496 final_dp = efi_dp_dup(dp);
1503 if (utf16_utf8_strlen(bo->optional_data)) {
1504 len = utf16_utf8_strlen(bo->optional_data) + 1;
1505 tmp = calloc(1, len);
1509 utf16_utf8_strncpy(&p, bo->optional_data, u16_strlen(bo->optional_data));
1512 ret = eficonfig_set_boot_option(varname, final_dp, final_dp_size, bo->description, tmp);
1513 if (ret != EFI_SUCCESS)
1517 free(bo->optional_data);
1518 free(bo->description);
1519 free(bo->file_info.current_path);
1520 free(bo->initrd_info.current_path);
1521 efi_free_pool(device_dp);
1522 efi_free_pool(initrd_device_dp);
1523 efi_free_pool(initrd_dp);
1524 efi_free_pool(final_dp);
1530 * eficonfig_process_add_boot_option() - handler to add boot option
1532 * @data: pointer to the data for each entry
1533 * Return: status code
1535 static efi_status_t eficonfig_process_add_boot_option(void *data)
1539 struct eficonfig_boot_option *bo = NULL;
1541 bo = calloc(1, sizeof(struct eficonfig_boot_option));
1543 return EFI_OUT_OF_RESOURCES;
1545 ret = eficonfig_get_unused_bootoption(varname, sizeof(varname), &bo->boot_index);
1546 if (ret != EFI_SUCCESS)
1549 ret = eficonfig_edit_boot_option(varname, bo, NULL, 0, " ** Add Boot Option ** ");
1550 if (ret != EFI_SUCCESS)
1553 ret = eficonfig_append_bootorder((u16)bo->boot_index);
1554 if (ret != EFI_SUCCESS)
1560 /* to stay the parent menu */
1561 ret = (ret == EFI_ABORTED) ? EFI_SUCCESS : ret;
1567 * eficonfig_process_boot_selected() - handler to select boot option entry
1569 * @data: pointer to the data for each entry
1570 * Return: status code
1572 static efi_status_t eficonfig_process_boot_selected(void *data)
1574 struct eficonfig_boot_selection_data *info = data;
1577 *info->selected = info->boot_index;
1583 * search_bootorder() - search the boot option index in BootOrder
1585 * @bootorder: pointer to the BootOrder variable
1586 * @num: number of BootOrder entry
1587 * @target: target boot option index to search
1588 * @index: pointer to store the index of BootOrder variable
1589 * Return: true if exists, false otherwise
1591 static bool search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index)
1595 for (i = 0; i < num; i++) {
1596 if (target == bootorder[i]) {
1608 * eficonfig_add_boot_selection_entry() - add boot option menu entry
1610 * @efi_menu: pointer to store the efimenu structure
1611 * @boot_index: boot option index to be added
1612 * @selected: pointer to store the selected boot option index
1613 * Return: status code
1615 static efi_status_t eficonfig_add_boot_selection_entry(struct efimenu *efi_menu,
1616 unsigned int boot_index,
1617 unsigned int *selected)
1623 struct efi_load_option lo;
1624 u16 varname[] = u"Boot####";
1625 struct eficonfig_boot_selection_data *info;
1627 efi_create_indexed_name(varname, sizeof(varname), "Boot", boot_index);
1628 load_option = efi_get_var(varname, &efi_global_variable_guid, &size);
1632 ret = efi_deserialize_load_option(&lo, load_option, &size);
1633 if (ret != EFI_SUCCESS) {
1634 log_warning("Invalid load option for %ls\n", varname);
1639 if (size >= sizeof(efi_guid_t) &&
1640 !guidcmp(lo.optional_data, &efi_guid_bootmenu_auto_generated)) {
1642 * auto generated entry has GUID in optional_data,
1643 * skip auto generated entry because it will be generated
1644 * again even if it is edited or deleted.
1650 info = calloc(1, sizeof(struct eficonfig_boot_selection_data));
1653 return EFI_OUT_OF_RESOURCES;
1656 buf = calloc(1, utf16_utf8_strlen(lo.label) + 1);
1660 return EFI_OUT_OF_RESOURCES;
1663 utf16_utf8_strcpy(&p, lo.label);
1664 info->boot_index = boot_index;
1665 info->selected = selected;
1666 ret = append_entry(efi_menu, buf, eficonfig_process_boot_selected, info);
1667 if (ret != EFI_SUCCESS) {
1678 * eficonfig_show_boot_selection() - construct boot option menu entry
1680 * @selected: pointer to store the selected boot option index
1681 * Return: status code
1683 static efi_status_t eficonfig_show_boot_selection(unsigned int *selected)
1688 efi_uintn_t num, size;
1689 struct efimenu *efi_menu;
1690 struct list_head *pos, *n;
1691 struct eficonfig_entry *entry;
1693 efi_menu = calloc(1, sizeof(struct efimenu));
1695 return EFI_OUT_OF_RESOURCES;
1697 bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size);
1699 INIT_LIST_HEAD(&efi_menu->list);
1700 num = size / sizeof(u16);
1701 /* list the load option in the order of BootOrder variable */
1702 for (i = 0; i < num; i++) {
1703 ret = eficonfig_add_boot_selection_entry(efi_menu, bootorder[i], selected);
1704 if (ret != EFI_SUCCESS)
1707 if (efi_menu->count >= EFICONFIG_ENTRY_NUM_MAX - 1)
1711 /* list the remaining load option not included in the BootOrder */
1712 for (i = 0; i <= 0xFFFF; i++) {
1713 /* If the index is included in the BootOrder, skip it */
1714 if (search_bootorder(bootorder, num, i, NULL))
1717 ret = eficonfig_add_boot_selection_entry(efi_menu, i, selected);
1718 if (ret != EFI_SUCCESS)
1721 if (efi_menu->count >= EFICONFIG_ENTRY_NUM_MAX - 1)
1725 ret = append_quit_entry(efi_menu);
1726 if (ret != EFI_SUCCESS)
1729 ret = eficonfig_process_common(efi_menu, " ** Select Boot Option **");
1731 list_for_each_safe(pos, n, &efi_menu->list) {
1732 entry = list_entry(pos, struct eficonfig_entry, list);
1735 eficonfig_destroy(efi_menu);
1741 * eficonfig_process_edit_boot_option() - handler to edit boot option
1743 * @data: pointer to the data for each entry
1744 * Return: status code
1746 static efi_status_t eficonfig_process_edit_boot_option(void *data)
1750 struct eficonfig_boot_option *bo = NULL;
1753 unsigned int selected;
1755 u16 varname[] = u"Boot####";
1757 ret = eficonfig_show_boot_selection(&selected);
1758 if (ret != EFI_SUCCESS)
1761 bo = calloc(1, sizeof(struct eficonfig_boot_option));
1763 ret = EFI_OUT_OF_RESOURCES;
1767 bo->boot_index = selected;
1768 efi_create_indexed_name(varname, sizeof(varname), "Boot", selected);
1769 load_option = efi_get_var(varname, &efi_global_variable_guid, &size);
1772 ret = EFI_NOT_FOUND;
1776 ret = eficonfig_edit_boot_option(varname, bo, load_option, size,
1777 " ** Edit Boot Option ** ");
1781 if (ret != EFI_SUCCESS && ret != EFI_ABORTED)
1785 /* to stay the parent menu */
1786 ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret;
1792 * delete_boot_option() - delete selected boot option
1794 * @boot_index: boot option index to delete
1795 * Return: status code
1797 static efi_status_t delete_boot_option(u16 boot_index)
1803 efi_uintn_t num, size;
1805 efi_create_indexed_name(varname, sizeof(varname),
1806 "Boot", boot_index);
1807 ret = efi_set_variable_int(varname, &efi_global_variable_guid,
1809 if (ret != EFI_SUCCESS) {
1810 log_err("delete boot option(%ls) failed\n", varname);
1814 /* update BootOrder if necessary */
1815 bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size);
1819 num = size / sizeof(u16);
1820 if (!search_bootorder(bootorder, num, boot_index, &index))
1823 memmove(&bootorder[index], &bootorder[index + 1],
1824 (num - index - 1) * sizeof(u16));
1825 size -= sizeof(u16);
1826 ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid,
1827 EFI_VARIABLE_NON_VOLATILE |
1828 EFI_VARIABLE_BOOTSERVICE_ACCESS |
1829 EFI_VARIABLE_RUNTIME_ACCESS,
1830 size, bootorder, false);
1836 * eficonfig_process_delete_boot_option() - handler to delete boot option
1838 * @data: pointer to the data for each entry
1839 * Return: status code
1841 static efi_status_t eficonfig_process_delete_boot_option(void *data)
1844 unsigned int selected;
1847 ret = eficonfig_show_boot_selection(&selected);
1848 if (ret == EFI_SUCCESS)
1849 ret = delete_boot_option(selected);
1851 if (ret != EFI_SUCCESS)
1855 /* to stay the parent menu */
1856 ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret;
1862 * eficonfig_init() - do required initialization for eficonfig command
1864 * Return: status code
1866 static efi_status_t eficonfig_init(void)
1868 efi_status_t ret = EFI_SUCCESS;
1870 struct efi_handler *handler;
1873 ret = efi_search_protocol(efi_root, &efi_guid_text_input_protocol, &handler);
1874 if (ret != EFI_SUCCESS)
1877 ret = efi_protocol_open(handler, (void **)&cin, efi_root, NULL,
1878 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
1879 if (ret != EFI_SUCCESS)
1888 static const struct eficonfig_item maintenance_menu_items[] = {
1889 {"Add Boot Option", eficonfig_process_add_boot_option},
1890 {"Edit Boot Option", eficonfig_process_edit_boot_option},
1891 {"Delete Boot Option", eficonfig_process_delete_boot_option},
1892 {"Quit", eficonfig_process_quit},
1896 * do_eficonfig() - execute `eficonfig` command
1898 * @cmdtp: table entry describing command
1899 * @flag: bitmap indicating how the command was invoked
1900 * @argc: number of arguments
1901 * @argv: command line arguments
1902 * Return: status code
1904 static int do_eficonfig(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
1907 struct efimenu *efi_menu;
1910 return CMD_RET_USAGE;
1912 ret = efi_init_obj_list();
1913 if (ret != EFI_SUCCESS) {
1914 log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n",
1915 ret & ~EFI_ERROR_MASK);
1917 return CMD_RET_FAILURE;
1920 ret = eficonfig_init();
1921 if (ret != EFI_SUCCESS)
1922 return CMD_RET_FAILURE;
1925 efi_menu = eficonfig_create_fixed_menu(maintenance_menu_items,
1926 ARRAY_SIZE(maintenance_menu_items));
1928 return CMD_RET_FAILURE;
1930 ret = eficonfig_process_common(efi_menu, " ** UEFI Maintenance Menu **");
1931 eficonfig_destroy(efi_menu);
1933 if (ret == EFI_ABORTED)
1937 return CMD_RET_SUCCESS;
1941 eficonfig, 1, 0, do_eficonfig,
1942 "provide menu-driven UEFI variable maintenance interface",