Lines Matching refs:config
374 static UINTN entry_lookup_key(Config *config, UINTN start, CHAR16 key) { in entry_lookup_key() argument
375 assert(config); in entry_lookup_key()
383 if (i > config->entry_count) in entry_lookup_key()
384 i = config->entry_count; in entry_lookup_key()
389 for (UINTN i = start; i < config->entry_count; i++) in entry_lookup_key()
390 if (config->entries[i]->key == key) in entry_lookup_key()
394 if (config->entries[i]->key == key) in entry_lookup_key()
467 static void print_status(Config *config, CHAR16 *loaded_image_path) { in print_status() argument
473 assert(config); in print_status()
501 switch (config->timeout_sec_config) { in print_status()
509 Print(L" timeout (config): %u s\n", config->timeout_sec_config); in print_status()
512 switch (config->timeout_sec_efivar) { in print_status()
520 Print(L" timeout (EFI var): %u s\n", config->timeout_sec_efivar); in print_status()
523 ps_string(L" default (config): %s\n", config->entry_default_config); in print_status()
524 ps_string(L" default (EFI var): %s\n", config->entry_default_efivar); in print_status()
525 ps_string(L" default (one-shot): %s\n", config->entry_oneshot); in print_status()
526 ps_string(L" saved entry: %s\n", config->entry_saved); in print_status()
527 ps_bool(L" editor: %s\n", config->editor); in print_status()
528 ps_bool(L" auto-entries: %s\n", config->auto_entries); in print_status()
529 ps_bool(L" auto-firmware: %s\n", config->auto_firmware); in print_status()
530 ps_bool(L" beep: %s\n", config->beep); in print_status()
531 ps_bool(L" reboot-for-bitlocker: %s\n", config->reboot_for_bitlocker); in print_status()
532 … ps_string(L" random-seed-mode: %s\n", random_seed_modes_table[config->random_seed_mode]); in print_status()
534 switch (config->console_mode) { in print_status()
542 Print(L" console-mode (config): %ld\n", config->console_mode); break; in print_status()
546 if (config->console_mode_efivar != CONSOLE_MODE_KEEP) in print_status()
547 Print(L"console-mode (EFI var): %ld\n", config->console_mode_efivar); in print_status()
552 for (UINTN i = 0; i < config->entry_count; i++) { in print_status()
553 ConfigEntry *entry = config->entries[i]; in print_status()
555 Print(L" config entry: %" PRIuN L"/%" PRIuN L"\n", i + 1, config->entry_count); in print_status()
600 Config *config, in menu_run() argument
604 assert(config); in menu_run()
610 UINTN idx_highlight = config->idx_default; in menu_run()
619 UINT32 timeout_efivar_saved = config->timeout_sec_efivar; in menu_run()
620 UINT32 timeout_remain = config->timeout_sec == TIMEOUT_MENU_FORCE ? 0 : config->timeout_sec; in menu_run()
622 …INT64 console_mode_initial = ST->ConOut->Mode->Mode, console_mode_efivar_saved = config->console_m… in menu_run()
623 UINTN default_efivar_saved = config->idx_default_efivar; in menu_run()
632 err = console_set_mode(config->console_mode_efivar != CONSOLE_MODE_KEEP ? in menu_run()
633 config->console_mode_efivar : config->console_mode); in menu_run()
653 if (config->entry_count <= visible_max || idx_highlight <= visible_max / 2) in menu_run()
655 else if (idx_highlight >= config->entry_count - (visible_max / 2)) in menu_run()
656 idx_first = config->entry_count - visible_max; in menu_run()
663 for (UINTN i = 0; i < config->entry_count; i++) in menu_run()
664 … line_width = MAX(line_width, StrLen(config->entries[i]->title_show)); in menu_run()
669 if (config->entry_count < visible_max) in menu_run()
670 y_start = ((visible_max - config->entry_count) / 2) + 1; in menu_run()
675 … y_status = MIN(y_start + MIN(visible_max, config->entry_count) + 1, y_max - 1); in menu_run()
682 lines = xnew(CHAR16*, config->entry_count + 1); in menu_run()
684 for (UINTN i = 0; i < config->entry_count; i++) { in menu_run()
688 … padding = (line_width - MIN(StrLen(config->entries[i]->title_show), line_width)) / 2; in menu_run()
693 … for (UINTN k = 0; config->entries[i]->title_show[k] != '\0' && j < line_width; j++, k++) in menu_run()
694 lines[i][j] = config->entries[i]->title_show[k]; in menu_run()
700 lines[config->entry_count] = NULL; in menu_run()
722 for (UINTN i = idx_first; i <= idx_last && i < config->entry_count; i++) { in menu_run()
726 if (i == config->idx_default_efivar) in menu_run()
735 if (idx_highlight_prev == config->idx_default_efivar) in menu_run()
737 if (idx_highlight == config->idx_default_efivar) in menu_run()
768 if (config->beep) in menu_run()
817 if (idx_highlight < config->entry_count-1) in menu_run()
831 if (idx_highlight < config->entry_count-1) { in menu_run()
833 idx_highlight = config->entry_count-1; in menu_run()
846 if (idx_highlight > config->entry_count-1) in menu_run()
847 idx_highlight = config->entry_count-1; in menu_run()
873 if (config->idx_default_efivar != idx_highlight) { in menu_run()
874 FreePool(config->entry_default_efivar); in menu_run()
875 … config->entry_default_efivar = xstrdup(config->entries[idx_highlight]->id); in menu_run()
876 config->idx_default_efivar = idx_highlight; in menu_run()
879 config->entry_default_efivar = mfree(config->entry_default_efivar); in menu_run()
880 config->idx_default_efivar = IDX_INVALID; in menu_run()
883 config->use_saved_entry_efivar = FALSE; in menu_run()
889 status = update_timeout_efivar(&config->timeout_sec_efivar, FALSE); in menu_run()
894 status = update_timeout_efivar(&config->timeout_sec_efivar, TRUE); in menu_run()
900 if (!config->editor || !IN_SET(config->entries[idx_highlight]->type, in menu_run()
907 if (config->entries[idx_highlight]->type == LOADER_UNIFIED_LINUX && in menu_run()
909 config->entries[idx_highlight]->options) in menu_run()
918 …exit = line_edit(config->entries[idx_highlight]->options, &config->options_edit, x_max - 2, y_stat… in menu_run()
935 print_status(config, loaded_image_path); in menu_run()
949 config->console_mode_efivar = ST->ConOut->Mode->Mode; in menu_run()
950 … status = xpool_print(L"Console mode changed to %ld.", config->console_mode_efivar); in menu_run()
956 config->console_mode_efivar = CONSOLE_MODE_KEEP; in menu_run()
957 err = console_set_mode(config->console_mode == CONSOLE_MODE_KEEP ? in menu_run()
958 console_mode_initial : config->console_mode); in menu_run()
963 … config->console_mode == CONSOLE_MODE_KEEP ? L"firmware" : L"configuration file"); in menu_run()
983 idx = entry_lookup_key(config, idx_highlight+1, KEYCHAR(key)); in menu_run()
1004 *chosen_entry = config->entries[idx_highlight]; in menu_run()
1008 if (default_efivar_saved != config->idx_default_efivar) in menu_run()
1009 …efivar_set(LOADER_GUID, L"LoaderEntryDefault", config->entry_default_efivar, EFI_VARIABLE_NON_VOLA… in menu_run()
1011 if (console_mode_efivar_saved != config->console_mode_efivar) { in menu_run()
1012 if (config->console_mode_efivar == CONSOLE_MODE_KEEP) in menu_run()
1016 … config->console_mode_efivar, EFI_VARIABLE_NON_VOLATILE); in menu_run()
1019 if (timeout_efivar_saved != config->timeout_sec_efivar) { in menu_run()
1020 if (config->timeout_sec_efivar == TIMEOUT_UNSET) in menu_run()
1024 … config->timeout_sec_efivar, EFI_VARIABLE_NON_VOLATILE); in menu_run()
1031 static void config_add_entry(Config *config, ConfigEntry *entry) { in config_add_entry() argument
1032 assert(config); in config_add_entry()
1036 assert(config->entry_count < IDX_MAX); in config_add_entry()
1038 if ((config->entry_count & 15) == 0) { in config_add_entry()
1039 UINTN i = config->entry_count + 16; in config_add_entry()
1040 config->entries = xreallocate_pool( in config_add_entry()
1041 config->entries, in config_add_entry()
1042 sizeof(void *) * config->entry_count, in config_add_entry()
1045 config->entries[config->entry_count++] = entry; in config_add_entry()
1145 static void config_defaults_load_from_file(Config *config, CHAR8 *content) { in config_defaults_load_from_file() argument
1151 assert(config); in config_defaults_load_from_file()
1157 config->timeout_sec_config = TIMEOUT_MENU_FORCE; in config_defaults_load_from_file()
1159 config->timeout_sec_config = TIMEOUT_MENU_HIDDEN; in config_defaults_load_from_file()
1164 config->timeout_sec_config = MIN(Atoi(s), TIMEOUT_TYPE_MAX); in config_defaults_load_from_file()
1166 config->timeout_sec = config->timeout_sec_config; in config_defaults_load_from_file()
1175 FreePool(config->entry_default_config); in config_defaults_load_from_file()
1176 config->entry_default_config = xstra_to_str(value); in config_defaults_load_from_file()
1181 err = parse_boolean(value, &config->editor); in config_defaults_load_from_file()
1188 err = parse_boolean(value, &config->auto_entries); in config_defaults_load_from_file()
1195 err = parse_boolean(value, &config->auto_firmware); in config_defaults_load_from_file()
1202 err = parse_boolean(value, &config->beep); in config_defaults_load_from_file()
1209 err = parse_boolean(value, &config->reboot_for_bitlocker); in config_defaults_load_from_file()
1217 config->console_mode = CONSOLE_MODE_AUTO; in config_defaults_load_from_file()
1219 config->console_mode = CONSOLE_MODE_FIRMWARE_MAX; in config_defaults_load_from_file()
1221 config->console_mode = CONSOLE_MODE_KEEP; in config_defaults_load_from_file()
1226 config->console_mode = MIN(Atoi(s), (UINTN)CONSOLE_MODE_RANGE_MAX); in config_defaults_load_from_file()
1233 config->random_seed_mode = RANDOM_SEED_OFF; in config_defaults_load_from_file()
1235 config->random_seed_mode = RANDOM_SEED_WITH_SYSTEM_TOKEN; in config_defaults_load_from_file()
1237 config->random_seed_mode = RANDOM_SEED_ALWAYS; in config_defaults_load_from_file()
1247 … config->random_seed_mode = on ? RANDOM_SEED_ALWAYS : RANDOM_SEED_OFF; in config_defaults_load_from_file()
1423 Config *config, in config_entry_add_from_file() argument
1438 assert(config); in config_entry_add_from_file()
1570 config_add_entry(config, entry); in config_entry_add_from_file()
1576 static void config_load_defaults(Config *config, EFI_FILE *root_dir) { in config_load_defaults() argument
1583 *config = (Config) { in config_load_defaults()
1598 config_defaults_load_from_file(config, content); in config_load_defaults()
1602 config->timeout_sec_efivar = MIN(value, TIMEOUT_TYPE_MAX); in config_load_defaults()
1603 config->timeout_sec = config->timeout_sec_efivar; in config_load_defaults()
1611 config->timeout_sec = MIN(value, TIMEOUT_TYPE_MAX); in config_load_defaults()
1612 config->force_menu = TRUE; /* force the menu when this is set */ in config_load_defaults()
1617 config->console_mode_efivar = value; in config_load_defaults()
1619 err = efivar_get(LOADER_GUID, L"LoaderEntryOneShot", &config->entry_oneshot); in config_load_defaults()
1624 (void) efivar_get(LOADER_GUID, L"LoaderEntryDefault", &config->entry_default_efivar); in config_load_defaults()
1626 config->use_saved_entry = streq_ptr(config->entry_default_config, L"@saved"); in config_load_defaults()
1627 config->use_saved_entry_efivar = streq_ptr(config->entry_default_efivar, L"@saved"); in config_load_defaults()
1628 if (config->use_saved_entry || config->use_saved_entry_efivar) in config_load_defaults()
1629 (void) efivar_get(LOADER_GUID, L"LoaderEntryLastBooted", &config->entry_saved); in config_load_defaults()
1633 Config *config, in config_load_entries() argument
1643 assert(config); in config_load_entries()
1672 …config_entry_add_from_file(config, device, root_dir, L"\\loader\\entries", f->FileName, content, l… in config_load_entries()
1730 static UINTN config_entry_find(Config *config, const CHAR16 *needle) { in config_entry_find() argument
1731 assert(config); in config_entry_find()
1736 for (UINTN i = 0; i < config->entry_count; i++) in config_entry_find()
1737 if (MetaiMatch(config->entries[i]->id, (CHAR16*) needle)) in config_entry_find()
1743 static void config_default_entry_select(Config *config) { in config_default_entry_select() argument
1746 assert(config); in config_default_entry_select()
1748 i = config_entry_find(config, config->entry_oneshot); in config_default_entry_select()
1750 config->idx_default = i; in config_default_entry_select()
1754 …i = config_entry_find(config, config->use_saved_entry_efivar ? config->entry_saved : config->entry… in config_default_entry_select()
1756 config->idx_default = i; in config_default_entry_select()
1757 config->idx_default_efivar = i; in config_default_entry_select()
1761 if (config->use_saved_entry) in config_default_entry_select()
1763 … i = config->use_saved_entry_efivar ? IDX_INVALID : config_entry_find(config, config->entry_saved); in config_default_entry_select()
1765 i = config_entry_find(config, config->entry_default_config); in config_default_entry_select()
1767 config->idx_default = i; in config_default_entry_select()
1772 for (i = 0; i < config->entry_count; i++) { in config_default_entry_select()
1773 if (config->entries[i]->type == LOADER_AUTO || config->entries[i]->call) in config_default_entry_select()
1775 config->idx_default = i; in config_default_entry_select()
1780 config->idx_default = 0; in config_default_entry_select()
1781 if (config->timeout_sec == 0) in config_default_entry_select()
1782 config->timeout_sec = 10; in config_default_entry_select()
1803 static void config_title_generate(Config *config) { in config_title_generate() argument
1804 assert(config); in config_title_generate()
1806 BOOLEAN unique[config->entry_count]; in config_title_generate()
1809 for (UINTN i = 0; i < config->entry_count; i++) { in config_title_generate()
1810 assert(!config->entries[i]->title_show); in config_title_generate()
1812 … config->entries[i]->title_show = xstrdup(config->entries[i]->title ?: config->entries[i]->id); in config_title_generate()
1815 if (entries_unique(config->entries, unique, config->entry_count)) in config_title_generate()
1819 for (UINTN i = 0; i < config->entry_count; i++) { in config_title_generate()
1825 if (!config->entries[i]->version) in config_title_generate()
1828 _cleanup_freepool_ CHAR16 *t = config->entries[i]->title_show; in config_title_generate()
1829 … config->entries[i]->title_show = xpool_print(L"%s (%s)", t, config->entries[i]->version); in config_title_generate()
1832 if (entries_unique(config->entries, unique, config->entry_count)) in config_title_generate()
1836 for (UINTN i = 0; i < config->entry_count; i++) { in config_title_generate()
1842 if (!config->entries[i]->machine_id) in config_title_generate()
1845 _cleanup_freepool_ CHAR16 *t = config->entries[i]->title_show; in config_title_generate()
1846 config->entries[i]->title_show = xpool_print( in config_title_generate()
1849 StrnLen(config->entries[i]->machine_id, 8), in config_title_generate()
1850 config->entries[i]->machine_id); in config_title_generate()
1853 if (entries_unique(config->entries, unique, config->entry_count)) in config_title_generate()
1857 for (UINTN i = 0; i < config->entry_count; i++) { in config_title_generate()
1861 _cleanup_freepool_ CHAR16 *t = config->entries[i]->title_show; in config_title_generate()
1862 config->entries[i]->title_show = xpool_print(L"%s (%s)", t, config->entries[i]->id); in config_title_generate()
1867 Config *config, in config_entry_add_call() argument
1874 assert(config); in config_entry_add_call()
1888 config_add_entry(config, entry); in config_entry_add_call()
1893 Config *config, in config_entry_add_loader() argument
1905 assert(config); in config_entry_add_loader()
1927 config_add_entry(config, entry); in config_entry_add_loader()
1955 Config *config, in config_entry_add_loader_auto() argument
1964 assert(config); in config_entry_add_loader_auto()
1971 if (!config->auto_entries) in config_entry_add_loader_auto()
1994 … return config_entry_add_loader(config, device, LOADER_AUTO, id, key, title, loader, NULL, NULL); in config_entry_add_loader_auto()
1997 static void config_entry_add_osx(Config *config) { in config_entry_add_osx() argument
2002 assert(config); in config_entry_add_osx()
2004 if (!config->auto_entries) in config_entry_add_osx()
2017 config, in config_entry_add_osx()
2109 static void config_entry_add_windows(Config *config, EFI_HANDLE *device, EFI_FILE *root_dir) { in config_entry_add_windows() argument
2116 assert(config); in config_entry_add_windows()
2120 if (!config->auto_entries) in config_entry_add_windows()
2128 ConfigEntry *e = config_entry_add_loader_auto(config, device, root_dir, NULL, in config_entry_add_windows()
2132 if (config->reboot_for_bitlocker) in config_entry_add_windows()
2138 Config *config, in config_entry_add_linux() argument
2150 assert(config); in config_entry_add_linux()
2271 config, in config_entry_add_linux()
2301 Config *config, in config_load_xbootldr() argument
2308 assert(config); in config_load_xbootldr()
2315 config_entry_add_linux(config, new_device, root_dir); in config_load_xbootldr()
2316 config_load_entries(config, new_device, root_dir, NULL); in config_load_xbootldr()
2321 const Config *config, in image_start() argument
2330 assert(config); in image_start()
2355 if (config->options_edit) in image_start()
2356 options = config->options_edit; in image_start()
2384 static void config_free(Config *config) { in config_free() argument
2385 assert(config); in config_free()
2386 for (UINTN i = 0; i < config->entry_count; i++) in config_free()
2387 config_entry_free(config->entries[i]); in config_free()
2388 FreePool(config->entries); in config_free()
2389 FreePool(config->entry_default_config); in config_free()
2390 FreePool(config->options_edit); in config_free()
2391 FreePool(config->entry_oneshot); in config_free()
2394 static void config_write_entries_to_variable(Config *config) { in config_write_entries_to_variable() argument
2399 assert(config); in config_write_entries_to_variable()
2401 for (UINTN i = 0; i < config->entry_count; i++) in config_write_entries_to_variable()
2402 sz += StrSize(config->entries[i]->id); in config_write_entries_to_variable()
2406 for (UINTN i = 0; i < config->entry_count; i++) { in config_write_entries_to_variable()
2409 l = StrSize(config->entries[i]->id); in config_write_entries_to_variable()
2410 CopyMem(p, config->entries[i]->id, l); in config_write_entries_to_variable()
2421 static void save_selected_entry(const Config *config, const ConfigEntry *entry) { in save_selected_entry() argument
2422 assert(config); in save_selected_entry()
2430 if (streq_ptr(config->entry_oneshot, entry->id)) in save_selected_entry()
2433 …if (config->use_saved_entry_efivar || (!config->entry_default_efivar && config->use_saved_entry)) { in save_selected_entry()
2435 if (streq_ptr(config->entry_saved, entry->id)) in save_selected_entry()
2486 Config *config, in config_load_all_entries() argument
2491 assert(config); in config_load_all_entries()
2496 config_load_defaults(config, root_dir); in config_load_all_entries()
2499 config_entry_add_linux(config, loaded_image->DeviceHandle, root_dir); in config_load_all_entries()
2502 config_load_entries(config, loaded_image->DeviceHandle, root_dir, loaded_image_path); in config_load_all_entries()
2505 config_load_xbootldr(config, loaded_image->DeviceHandle); in config_load_all_entries()
2508 …sort_pointer_array((void **) config->entries, config->entry_count, (compare_pointer_func_t) config… in config_load_all_entries()
2511 config_entry_add_osx(config); in config_load_all_entries()
2512 config_entry_add_windows(config, loaded_image->DeviceHandle, root_dir); in config_load_all_entries()
2513 config_entry_add_loader_auto(config, loaded_image->DeviceHandle, root_dir, NULL, in config_load_all_entries()
2515 … config_entry_add_loader_auto(config, loaded_image->DeviceHandle, root_dir, loaded_image_path, in config_load_all_entries()
2518 …if (config->auto_firmware && FLAGS_SET(get_os_indications_supported(), EFI_OS_INDICATIONS_BOOT_TO_… in config_load_all_entries()
2519 config_entry_add_call(config, in config_load_all_entries()
2524 if (config->entry_count == 0) in config_load_all_entries()
2527 config_write_entries_to_variable(config); in config_load_all_entries()
2529 config_title_generate(config); in config_load_all_entries()
2532 config_default_entry_select(config); in config_load_all_entries()
2538 _cleanup_(config_free) Config config = {}; in efi_main()
2577 config_load_all_entries(&config, loaded_image, loaded_image_path, root_dir); in efi_main()
2579 if (config.entry_count == 0) { in efi_main()
2585 if (config.force_menu || config.timeout_sec > 0) in efi_main()
2594 UINTN idx = entry_lookup_key(&config, config.idx_default, KEYCHAR(key)); in efi_main()
2596 config.idx_default = idx; in efi_main()
2605 entry = config.entries[config.idx_default]; in efi_main()
2608 if (!menu_run(&config, &entry, loaded_image_path)) in efi_main()
2620 save_selected_entry(&config, entry); in efi_main()
2623 (void) process_random_seed(root_dir, config.random_seed_mode); in efi_main()
2625 err = image_start(image, &config, entry); in efi_main()
2633 config.timeout_sec = 0; in efi_main()