2022-07-11 01:15:56 +03:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2022-07-13 08:40:53 +03:00
|
|
|
#include <stdnoreturn.h>
|
2022-07-11 01:15:56 +03:00
|
|
|
#include <protos/chainload_next.h>
|
|
|
|
#include <protos/chainload.h>
|
2022-08-27 00:44:47 +03:00
|
|
|
#include <lib/misc.h>
|
2022-07-11 01:15:56 +03:00
|
|
|
#include <lib/print.h>
|
|
|
|
#include <lib/part.h>
|
|
|
|
|
2022-09-02 03:29:12 +03:00
|
|
|
#if defined (BIOS)
|
2022-07-11 01:27:22 +03:00
|
|
|
static void try(char *config, struct volume *v) {
|
|
|
|
(void)config;
|
2022-07-11 01:15:56 +03:00
|
|
|
bios_chainload_volume(v);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-09-02 03:29:12 +03:00
|
|
|
#if defined (UEFI)
|
2022-07-11 01:27:22 +03:00
|
|
|
static void try(char *config, struct volume *v) {
|
2022-07-11 01:53:33 +03:00
|
|
|
for (int i = 0; i <= v->max_partition + 1; i++) {
|
2022-07-11 01:15:56 +03:00
|
|
|
struct file_handle *image;
|
2022-07-11 01:53:33 +03:00
|
|
|
struct volume *p = volume_get_by_coord(v->is_optical, v->index, i);
|
2022-07-11 01:15:56 +03:00
|
|
|
|
2022-09-01 15:02:53 +03:00
|
|
|
bool old_cif = case_insensitive_fopen;
|
|
|
|
case_insensitive_fopen = true;
|
|
|
|
if ((image = fopen(p, "/EFI/BOOT/BOOTX64.EFI")) == NULL) {
|
|
|
|
case_insensitive_fopen = old_cif;
|
2022-07-11 01:15:56 +03:00
|
|
|
continue;
|
|
|
|
}
|
2022-09-01 15:02:53 +03:00
|
|
|
case_insensitive_fopen = old_cif;
|
2022-07-11 01:15:56 +03:00
|
|
|
|
2022-07-11 01:27:22 +03:00
|
|
|
efi_chainload_file(config, image);
|
2022-07-11 01:15:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-07-13 08:40:53 +03:00
|
|
|
noreturn void chainload_next(char *config) {
|
2022-07-11 01:15:56 +03:00
|
|
|
bool wrap = false;
|
|
|
|
for (int i = boot_volume->is_optical ? 0 : (wrap = true, boot_volume->index + 1);
|
|
|
|
boot_volume->is_optical ? true : i != boot_volume->index; i++) {
|
|
|
|
struct volume *v = volume_get_by_coord(false, i, 0);
|
|
|
|
if (v == NULL) {
|
|
|
|
if (wrap) {
|
|
|
|
i = 0;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 01:27:22 +03:00
|
|
|
try(config, v);
|
2022-07-11 01:15:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
wrap = false;
|
|
|
|
for (int i = boot_volume->is_optical ? (wrap = true, boot_volume->index + 1) : 0;
|
|
|
|
boot_volume->is_optical ? i != boot_volume->index : true; i++) {
|
|
|
|
struct volume *v = volume_get_by_coord(true, i, 0);
|
|
|
|
if (v == NULL) {
|
|
|
|
if (wrap) {
|
|
|
|
i = 0;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 01:27:22 +03:00
|
|
|
try(config, v);
|
2022-07-11 01:15:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
panic(true, "chainload_next: No other bootable device");
|
|
|
|
}
|