@@ -1125,56 +1125,92 @@ noreturn void _menu(bool first_run) {
11251125
11261126 size_t selected_entry = 0 ;
11271127
1128- char * default_entry = config_get_value (NULL , 0 , "DEFAULT_ENTRY" );
1129- if (default_entry != NULL ) {
1130- bool is_index = true;
1131- for (const char * p = default_entry ; * p != '\0' ; p ++ ) {
1132- if (* p < '0' || * p > '9' ) {
1133- is_index = false;
1134- break ;
1135- }
1136- }
1137- if (is_index ) {
1138- selected_entry = strtoui (default_entry , NULL , 10 );
1139- if (selected_entry )
1140- selected_entry -- ;
1141- } else {
1142- // Copy the path since find_entry_by_path calls config_get_value
1143- // internally (via should_skip_entry), which clobbers the static buffer.
1144- char default_entry_path [256 ];
1145- size_t len = strlen (default_entry );
1146- if (len >= sizeof (default_entry_path )) {
1147- len = sizeof (default_entry_path ) - 1 ;
1148- }
1149- memcpy (default_entry_path , default_entry , len );
1150- default_entry_path [len ] = '\0' ;
1128+ bool has_entry = false;
1129+
1130+ #if defined (UEFI )
1131+ {
1132+ char path [256 ];
1133+ if (bli_get_oneshot_entry (path , 256 )) {
1134+ // Find the entry with this path, expand directories, and get its index.
11511135 struct menu_entry * found_entry = NULL ;
11521136 size_t found_index = 0 ;
1153- find_entry_by_path (default_entry_path , menu_tree , 0 , & found_entry , & found_index , true);
1137+ find_entry_by_path (path , menu_tree , 0 , & found_entry , & found_index , true);
11541138 if (found_entry != NULL ) {
11551139 selected_entry = found_index ;
1140+ has_entry = true;
1141+ }
1142+ }
1143+ }
1144+ #endif
1145+
1146+ if (!has_entry ) {
1147+ char * default_entry = config_get_value (NULL , 0 , "DEFAULT_ENTRY" );
1148+ if (default_entry != NULL ) {
1149+ bool is_index = true;
1150+ for (const char * p = default_entry ; * p != '\0' ; p ++ ) {
1151+ if (* p < '0' || * p > '9' ) {
1152+ is_index = false;
1153+ break ;
1154+ }
1155+ }
1156+ if (is_index ) {
1157+ selected_entry = strtoui (default_entry , NULL , 10 );
1158+ if (selected_entry )
1159+ selected_entry -- ;
1160+ } else {
1161+ // Copy the path since find_entry_by_path calls config_get_value
1162+ // internally (via should_skip_entry), which clobbers the static buffer.
1163+ char default_entry_path [256 ];
1164+ size_t len = strlen (default_entry );
1165+ if (len >= sizeof (default_entry_path )) {
1166+ len = sizeof (default_entry_path ) - 1 ;
1167+ }
1168+ memcpy (default_entry_path , default_entry , len );
1169+ default_entry_path [len ] = '\0' ;
1170+ struct menu_entry * found_entry = NULL ;
1171+ size_t found_index = 0 ;
1172+ find_entry_by_path (default_entry_path , menu_tree , 0 , & found_entry , & found_index , true);
1173+ if (found_entry != NULL ) {
1174+ selected_entry = found_index ;
1175+ }
11561176 }
11571177 }
11581178 }
11591179
11601180#if defined (UEFI )
1161- char * remember_last = config_get_value (NULL , 0 , "REMEMBER_LAST_ENTRY" );
1162- if (remember_last != NULL && strcasecmp (remember_last , "yes" ) == 0 ) {
1163- char last_entry_path [256 ];
1164- UINTN getvar_size = sizeof (last_entry_path );
1165- if (gRT -> GetVariable (L"LimineLastBootedEntry" ,
1166- & limine_efi_vendor_guid ,
1167- NULL ,
1168- & getvar_size ,
1169- last_entry_path ) == 0 && getvar_size > 0 ) {
1170- // Ensure NUL termination
1171- last_entry_path [getvar_size < sizeof (last_entry_path ) ? getvar_size : sizeof (last_entry_path ) - 1 ] = '\0' ;
1181+ if (!has_entry ) {
1182+ char * remember_last = config_get_value (NULL , 0 , "REMEMBER_LAST_ENTRY" );
1183+ if (remember_last != NULL && strcasecmp (remember_last , "yes" ) == 0 ) {
1184+ char last_entry_path [256 ];
1185+ UINTN getvar_size = sizeof (last_entry_path );
1186+ if (gRT -> GetVariable (L"LimineLastBootedEntry" ,
1187+ & limine_efi_vendor_guid ,
1188+ NULL ,
1189+ & getvar_size ,
1190+ last_entry_path ) == 0 && getvar_size > 0 ) {
1191+ // Ensure NUL termination
1192+ last_entry_path [getvar_size < sizeof (last_entry_path ) ? getvar_size : sizeof (last_entry_path ) - 1 ] = '\0' ;
1193+ // Find the entry with this path, expand directories, and get its index.
1194+ struct menu_entry * found_entry = NULL ;
1195+ size_t found_index = 0 ;
1196+ find_entry_by_path (last_entry_path , menu_tree , 0 , & found_entry , & found_index , true);
1197+ if (found_entry != NULL ) {
1198+ selected_entry = found_index ;
1199+ has_entry = true;
1200+ }
1201+ }
1202+ }
1203+ }
1204+ if (!has_entry ) {
1205+ char path [256 ];
1206+ if (bli_get_default_entry (path , 256 )) {
11721207 // Find the entry with this path, expand directories, and get its index.
11731208 struct menu_entry * found_entry = NULL ;
11741209 size_t found_index = 0 ;
1175- find_entry_by_path (last_entry_path , menu_tree , 0 , & found_entry , & found_index , true);
1210+ find_entry_by_path (path , menu_tree , 0 , & found_entry , & found_index , true);
11761211 if (found_entry != NULL ) {
11771212 selected_entry = found_index ;
1213+ has_entry = true;
11781214 }
11791215 }
11801216 }
@@ -1469,6 +1505,7 @@ noreturn void _menu(bool first_run) {
14691505 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS ,
14701506 strlen (entry_path ) + 1 ,
14711507 entry_path );
1508+ bli_set_selected_entry (entry_path );
14721509#endif
14731510
14741511 boot (selected_menu_entry -> body );
0 commit comments