@@ -990,31 +990,67 @@ noreturn void _menu(bool first_run) {
990990
991991 size_t selected_entry = 0 ;
992992
993- char * default_entry = config_get_value (NULL , 0 , "DEFAULT_ENTRY" );
994- if (default_entry != NULL ) {
995- selected_entry = strtoui (default_entry , NULL , 10 );
996- if (selected_entry )
997- selected_entry -- ;
993+ bool has_entry = false;
994+
995+ #if defined (UEFI )
996+ {
997+ char path [256 ];
998+ if (bli_get_oneshot_entry (path , 256 )) {
999+ // Find the entry with this path, expand directories, and get its index.
1000+ struct menu_entry * found_entry = NULL ;
1001+ size_t found_index = 0 ;
1002+ find_entry_by_path (path , menu_tree , 0 , & found_entry , & found_index , true);
1003+ if (found_entry != NULL ) {
1004+ selected_entry = found_index ;
1005+ has_entry = true;
1006+ }
1007+ }
1008+ }
1009+ #endif
1010+
1011+ if (!has_entry ) {
1012+ char * default_entry = config_get_value (NULL , 0 , "DEFAULT_ENTRY" );
1013+ if (default_entry != NULL ) {
1014+ selected_entry = strtoui (default_entry , NULL , 10 );
1015+ if (selected_entry )
1016+ selected_entry -- ;
1017+ }
9981018 }
9991019
10001020#if defined (UEFI )
1001- char * remember_last = config_get_value (NULL , 0 , "REMEMBER_LAST_ENTRY" );
1002- if (remember_last != NULL && strcasecmp (remember_last , "yes" ) == 0 ) {
1003- char last_entry_path [256 ];
1004- UINTN getvar_size = sizeof (last_entry_path );
1005- if (gRT -> GetVariable (L"LimineLastBootedEntry" ,
1006- & limine_efi_vendor_guid ,
1007- NULL ,
1008- & getvar_size ,
1009- last_entry_path ) == 0 && getvar_size > 0 ) {
1010- // Ensure NUL termination
1011- last_entry_path [getvar_size < sizeof (last_entry_path ) ? getvar_size : sizeof (last_entry_path ) - 1 ] = '\0' ;
1021+ if (!has_entry ) {
1022+ char * remember_last = config_get_value (NULL , 0 , "REMEMBER_LAST_ENTRY" );
1023+ if (remember_last != NULL && strcasecmp (remember_last , "yes" ) == 0 ) {
1024+ char last_entry_path [256 ];
1025+ UINTN getvar_size = sizeof (last_entry_path );
1026+ if (gRT -> GetVariable (L"LimineLastBootedEntry" ,
1027+ & limine_efi_vendor_guid ,
1028+ NULL ,
1029+ & getvar_size ,
1030+ last_entry_path ) == 0 && getvar_size > 0 ) {
1031+ // Ensure NUL termination
1032+ last_entry_path [getvar_size < sizeof (last_entry_path ) ? getvar_size : sizeof (last_entry_path ) - 1 ] = '\0' ;
1033+ // Find the entry with this path, expand directories, and get its index.
1034+ struct menu_entry * found_entry = NULL ;
1035+ size_t found_index = 0 ;
1036+ find_entry_by_path (last_entry_path , menu_tree , 0 , & found_entry , & found_index , true);
1037+ if (found_entry != NULL ) {
1038+ selected_entry = found_index ;
1039+ has_entry = true;
1040+ }
1041+ }
1042+ }
1043+ }
1044+ if (!has_entry ) {
1045+ char path [256 ];
1046+ if (bli_get_default_entry (path , 256 )) {
10121047 // Find the entry with this path, expand directories, and get its index.
10131048 struct menu_entry * found_entry = NULL ;
10141049 size_t found_index = 0 ;
1015- find_entry_by_path (last_entry_path , menu_tree , 0 , & found_entry , & found_index , true);
1050+ find_entry_by_path (path , menu_tree , 0 , & found_entry , & found_index , true);
10161051 if (found_entry != NULL ) {
10171052 selected_entry = found_index ;
1053+ has_entry = true;
10181054 }
10191055 }
10201056 }
@@ -1309,6 +1345,7 @@ noreturn void _menu(bool first_run) {
13091345 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS ,
13101346 strlen (entry_path ) + 1 ,
13111347 entry_path );
1348+ bli_set_selected_entry (entry_path );
13121349#endif
13131350
13141351 boot (selected_menu_entry -> body );
0 commit comments