misc: Clean up the boot device detection system
This commit is contained in:
parent
0cd183faf4
commit
53332d7056
@ -23,11 +23,7 @@
|
||||
|
||||
extern uint64_t stage3_build_id;
|
||||
|
||||
int boot_drive;
|
||||
int boot_partition = -1;
|
||||
|
||||
bool booted_from_pxe = false;
|
||||
bool booted_from_cd = false;
|
||||
struct volume *boot_volume;
|
||||
|
||||
#if defined (bios)
|
||||
|
||||
@ -63,13 +59,14 @@ static bool stage3_init(struct volume *part) {
|
||||
return true;
|
||||
}
|
||||
|
||||
enum {
|
||||
BOOTED_FROM_HDD,
|
||||
BOOTED_FROM_PXE,
|
||||
BOOTED_FROM_CD
|
||||
};
|
||||
|
||||
__attribute__((noreturn))
|
||||
void entry(uint8_t _boot_drive, int boot_from) {
|
||||
boot_drive = _boot_drive;
|
||||
|
||||
booted_from_pxe = (boot_from == BOOT_FROM_PXE);
|
||||
booted_from_cd = (boot_from == BOOT_FROM_CD);
|
||||
|
||||
void entry(uint8_t boot_drive, int boot_from) {
|
||||
term_textmode();
|
||||
|
||||
print("Limine " LIMINE_VERSION "\n\n");
|
||||
@ -82,7 +79,9 @@ void entry(uint8_t _boot_drive, int boot_from) {
|
||||
|
||||
disk_create_index();
|
||||
|
||||
struct volume *boot_volume = volume_get_by_coord(boot_drive, -1);
|
||||
if (boot_from == BOOTED_FROM_HDD || boot_from == BOOTED_FROM_CD) {
|
||||
boot_volume = volume_get_by_coord(boot_drive, -1);
|
||||
}
|
||||
|
||||
volume_iterate_parts(boot_volume,
|
||||
if (stage3_init(_PART)) {
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <pxe/tftp.h>
|
||||
#include <drivers/disk.h>
|
||||
|
||||
void stage3_common(struct volume *boot_volume);
|
||||
void stage3_common(void);
|
||||
|
||||
#if defined (uefi)
|
||||
EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
|
||||
@ -55,12 +55,12 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
|
||||
uefi_call_wrapper(gBS->HandleProtocol, 3, ImageHandle, &loaded_img_prot_guid,
|
||||
&loaded_image);
|
||||
|
||||
struct volume *boot_volume = disk_volume_from_efi_handle(loaded_image->DeviceHandle);
|
||||
boot_volume = disk_volume_from_efi_handle(loaded_image->DeviceHandle);
|
||||
if (boot_volume == NULL) {
|
||||
panic("Can't determine boot disk");
|
||||
}
|
||||
|
||||
stage3_common(boot_volume);
|
||||
stage3_common();
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -68,25 +68,15 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
|
||||
__attribute__((section(".stage3_build_id")))
|
||||
uint64_t stage3_build_id = BUILD_ID;
|
||||
|
||||
__attribute__((noreturn))
|
||||
__attribute__((section(".stage3_entry")))
|
||||
void stage3_entry(int boot_from) {
|
||||
(void)boot_from;
|
||||
|
||||
struct volume *boot_volume = volume_get_by_coord(boot_drive, -1);
|
||||
|
||||
stage3_common(boot_volume);
|
||||
}
|
||||
#endif
|
||||
|
||||
__attribute__((noreturn))
|
||||
void stage3_common(struct volume *boot_volume) {
|
||||
void stage3_common(void) {
|
||||
bool got_config = false;
|
||||
volume_iterate_parts(boot_volume,
|
||||
if (!init_config_disk(_PART)) {
|
||||
print("Config file found and loaded.\n");
|
||||
boot_partition = _PARTNO;
|
||||
boot_drive = _PART->drive;
|
||||
boot_volume = _PART;
|
||||
got_config = true;
|
||||
break;
|
||||
}
|
||||
@ -95,8 +85,8 @@ void stage3_common(struct volume *boot_volume) {
|
||||
if (!got_config)
|
||||
panic("Config file not found.");
|
||||
|
||||
print("Boot drive: %x\n", boot_drive);
|
||||
print("Boot partition: %d\n", boot_partition);
|
||||
print("Boot drive: %x\n", boot_volume->drive);
|
||||
print("Boot partition: %d\n", boot_volume->partition);
|
||||
|
||||
mtrr_save();
|
||||
|
||||
@ -113,7 +103,7 @@ void stage3_common(struct volume *boot_volume) {
|
||||
} else if (!strcmp(proto, "stivale")) {
|
||||
stivale_load(config, cmdline);
|
||||
} else if (!strcmp(proto, "stivale2")) {
|
||||
stivale2_load(config, cmdline, booted_from_pxe);
|
||||
stivale2_load(config, cmdline, false /*booted_from_pxe*/);
|
||||
#if defined (bios)
|
||||
} else if (!strcmp(proto, "linux")) {
|
||||
linux_load(config, cmdline);
|
||||
|
@ -20,12 +20,11 @@ extern bool efi_boot_services_exited;
|
||||
bool efi_exit_boot_services(void);
|
||||
#endif
|
||||
|
||||
extern int boot_drive;
|
||||
extern int boot_partition;
|
||||
extern struct volume *boot_volume;
|
||||
|
||||
extern bool booted_from_pxe;
|
||||
extern bool booted_from_cd;
|
||||
#if defined (bios)
|
||||
extern bool stage3_loaded;
|
||||
#endif
|
||||
|
||||
bool parse_resolution(int *width, int *height, int *bpp, const char *buf);
|
||||
|
||||
@ -60,12 +59,6 @@ uint64_t strtoui(const char *s, const char **end, int base);
|
||||
|
||||
typedef char symbol[];
|
||||
|
||||
enum {
|
||||
BOOT_FROM_HDD,
|
||||
BOOT_FROM_PXE,
|
||||
BOOT_FROM_CD
|
||||
};
|
||||
|
||||
#if defined (uefi)
|
||||
__attribute__((noreturn)) void do_32(void *fnptr, int args, ...);
|
||||
#endif
|
||||
|
@ -67,7 +67,7 @@ static bool parse_bios_partition(char *loc, uint8_t *drive, uint8_t *partition)
|
||||
if (loc[i] == ':') {
|
||||
loc[i] = 0;
|
||||
if (*loc == 0) {
|
||||
*drive = boot_drive;
|
||||
*drive = boot_volume->drive;
|
||||
} else {
|
||||
val = strtoui(loc, NULL, 10);
|
||||
if (val < 1 || val > 16) {
|
||||
@ -157,7 +157,7 @@ static bool uri_tftp_dispatch(struct file_handle *fd, char *root, char *path) {
|
||||
|
||||
static bool uri_boot_dispatch(struct file_handle *fd, char *s_part, char *path) {
|
||||
#if defined (bios)
|
||||
if (booted_from_pxe)
|
||||
if (false /*booted_from_pxe*/)
|
||||
return uri_tftp_dispatch(fd, s_part, path);
|
||||
#endif
|
||||
|
||||
@ -169,13 +169,11 @@ static bool uri_boot_dispatch(struct file_handle *fd, char *s_part, char *path)
|
||||
panic("Partition number outside range 1-256");
|
||||
}
|
||||
partition = val - 1;
|
||||
} else if (booted_from_cd || boot_partition != -1) {
|
||||
partition = boot_partition;
|
||||
} else {
|
||||
panic("Boot partition information is unavailable.");
|
||||
partition = boot_volume->partition;
|
||||
}
|
||||
|
||||
struct volume *volume = volume_get_by_coord(boot_drive, partition);
|
||||
struct volume *volume = volume_get_by_coord(boot_volume->drive, partition);
|
||||
if (volume == NULL)
|
||||
return false;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user