44#include <stdnoreturn.h>
55#include <config.h>
66#include <menu.h>
7+ #include <lib/bli.h>
78#include <lib/print.h>
89#include <lib/misc.h>
910#include <lib/libc.h>
@@ -1167,56 +1168,92 @@ noreturn void _menu(bool first_run) {
11671168
11681169 size_t selected_entry = 0 ;
11691170
1170- char * default_entry = config_get_value (NULL , 0 , "DEFAULT_ENTRY" );
1171- if (default_entry != NULL ) {
1172- bool is_index = true;
1173- for (const char * p = default_entry ; * p != '\0' ; p ++ ) {
1174- if (* p < '0' || * p > '9' ) {
1175- is_index = false;
1176- break ;
1177- }
1178- }
1179- if (is_index ) {
1180- selected_entry = strtoui (default_entry , NULL , 10 );
1181- if (selected_entry )
1182- selected_entry -- ;
1183- } else {
1184- // Copy the path since find_entry_by_path calls config_get_value
1185- // internally (via should_skip_entry), which clobbers the static buffer.
1186- char default_entry_path [256 ];
1187- size_t len = strlen (default_entry );
1188- if (len >= sizeof (default_entry_path )) {
1189- len = sizeof (default_entry_path ) - 1 ;
1190- }
1191- memcpy (default_entry_path , default_entry , len );
1192- default_entry_path [len ] = '\0' ;
1171+ bool has_entry = false;
1172+
1173+ #if defined (UEFI )
1174+ {
1175+ char path [256 ];
1176+ if (bli_get_oneshot_entry (path , 256 )) {
1177+ // Find the entry with this path, expand directories, and get its index.
11931178 struct menu_entry * found_entry = NULL ;
11941179 size_t found_index = 0 ;
1195- find_entry_by_path (default_entry_path , menu_tree , 0 , & found_entry , & found_index , true);
1180+ find_entry_by_path (path , menu_tree , 0 , & found_entry , & found_index , true);
11961181 if (found_entry != NULL ) {
11971182 selected_entry = found_index ;
1183+ has_entry = true;
1184+ }
1185+ }
1186+ }
1187+ #endif
1188+
1189+ if (!has_entry ) {
1190+ char * default_entry = config_get_value (NULL , 0 , "DEFAULT_ENTRY" );
1191+ if (default_entry != NULL ) {
1192+ bool is_index = true;
1193+ for (const char * p = default_entry ; * p != '\0' ; p ++ ) {
1194+ if (* p < '0' || * p > '9' ) {
1195+ is_index = false;
1196+ break ;
1197+ }
1198+ }
1199+ if (is_index ) {
1200+ selected_entry = strtoui (default_entry , NULL , 10 );
1201+ if (selected_entry )
1202+ selected_entry -- ;
1203+ } else {
1204+ // Copy the path since find_entry_by_path calls config_get_value
1205+ // internally (via should_skip_entry), which clobbers the static buffer.
1206+ char default_entry_path [256 ];
1207+ size_t len = strlen (default_entry );
1208+ if (len >= sizeof (default_entry_path )) {
1209+ len = sizeof (default_entry_path ) - 1 ;
1210+ }
1211+ memcpy (default_entry_path , default_entry , len );
1212+ default_entry_path [len ] = '\0' ;
1213+ struct menu_entry * found_entry = NULL ;
1214+ size_t found_index = 0 ;
1215+ find_entry_by_path (default_entry_path , menu_tree , 0 , & found_entry , & found_index , true);
1216+ if (found_entry != NULL ) {
1217+ selected_entry = found_index ;
1218+ }
11981219 }
11991220 }
12001221 }
12011222
12021223#if defined (UEFI )
1203- char * remember_last = config_get_value (NULL , 0 , "REMEMBER_LAST_ENTRY" );
1204- if (remember_last != NULL && strcasecmp (remember_last , "yes" ) == 0 ) {
1205- char last_entry_path [256 ];
1206- UINTN getvar_size = sizeof (last_entry_path );
1207- if (gRT -> GetVariable (L"LimineLastBootedEntry" ,
1208- & limine_efi_vendor_guid ,
1209- NULL ,
1210- & getvar_size ,
1211- last_entry_path ) == 0 && getvar_size > 0 ) {
1212- // Ensure NUL termination
1213- last_entry_path [getvar_size < sizeof (last_entry_path ) ? getvar_size : sizeof (last_entry_path ) - 1 ] = '\0' ;
1224+ if (!has_entry ) {
1225+ char * remember_last = config_get_value (NULL , 0 , "REMEMBER_LAST_ENTRY" );
1226+ if (remember_last != NULL && strcasecmp (remember_last , "yes" ) == 0 ) {
1227+ char last_entry_path [256 ];
1228+ UINTN getvar_size = sizeof (last_entry_path );
1229+ if (gRT -> GetVariable (L"LimineLastBootedEntry" ,
1230+ & limine_efi_vendor_guid ,
1231+ NULL ,
1232+ & getvar_size ,
1233+ last_entry_path ) == 0 && getvar_size > 0 ) {
1234+ // Ensure NUL termination
1235+ last_entry_path [getvar_size < sizeof (last_entry_path ) ? getvar_size : sizeof (last_entry_path ) - 1 ] = '\0' ;
1236+ // Find the entry with this path, expand directories, and get its index.
1237+ struct menu_entry * found_entry = NULL ;
1238+ size_t found_index = 0 ;
1239+ find_entry_by_path (last_entry_path , menu_tree , 0 , & found_entry , & found_index , true);
1240+ if (found_entry != NULL ) {
1241+ selected_entry = found_index ;
1242+ has_entry = true;
1243+ }
1244+ }
1245+ }
1246+ }
1247+ if (!has_entry ) {
1248+ char path [256 ];
1249+ if (bli_get_default_entry (path , 256 )) {
12141250 // Find the entry with this path, expand directories, and get its index.
12151251 struct menu_entry * found_entry = NULL ;
12161252 size_t found_index = 0 ;
1217- find_entry_by_path (last_entry_path , menu_tree , 0 , & found_entry , & found_index , true);
1253+ find_entry_by_path (path , menu_tree , 0 , & found_entry , & found_index , true);
12181254 if (found_entry != NULL ) {
12191255 selected_entry = found_index ;
1256+ has_entry = true;
12201257 }
12211258 }
12221259 }
@@ -1230,14 +1267,30 @@ noreturn void _menu(bool first_run) {
12301267 }
12311268
12321269 size_t timeout = 5 ;
1233- char * timeout_config = config_get_value (NULL , 0 , "TIMEOUT" );
1234- if (timeout_config != NULL ) {
1235- if (!strcmp (timeout_config , "no" ))
1236- skip_timeout = true;
1237- else
1238- timeout = strtoui (timeout_config , NULL , 10 );
1270+
1271+ bool has_timeout = false;
1272+
1273+ #if defined (UEFI )
1274+ has_timeout = bli_update_oneshot_timeout (& timeout , & skip_timeout );
1275+ #endif
1276+
1277+ if (!has_timeout ) {
1278+ char * timeout_config = config_get_value (NULL , 0 , "TIMEOUT" );
1279+ if (timeout_config != NULL ) {
1280+ has_timeout = true;
1281+ if (!strcmp (timeout_config , "no" ))
1282+ skip_timeout = true;
1283+ else
1284+ timeout = strtoui (timeout_config , NULL , 10 );
1285+ }
12391286 }
12401287
1288+ #if defined (UEFI )
1289+ if (!has_timeout ) {
1290+ has_timeout = bli_update_timeout (& timeout , & skip_timeout );
1291+ }
1292+ #endif
1293+
12411294#if defined(UEFI )
12421295 bool reboot_to_firmware_supported = reboot_to_fw_ui_supported ();
12431296#endif
@@ -1508,6 +1561,7 @@ noreturn void _menu(bool first_run) {
15081561 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS ,
15091562 strlen (entry_path ) + 1 ,
15101563 entry_path );
1564+ bli_set_selected_entry (entry_path );
15111565#endif
15121566
15131567 boot (selected_menu_entry -> body );
0 commit comments