Change how config works a bit

This commit is contained in:
mintsuki 2020-05-06 16:38:45 +02:00
parent 23ba6bdb6c
commit 389b687985
7 changed files with 99 additions and 45 deletions

View File

@ -23,20 +23,26 @@ Some *local assignments* are shared between entries using any *protocol*, while
* `TIMEOUT` - Specifies the timeout in seconds before the first *entry* is automatically booted. * `TIMEOUT` - Specifies the timeout in seconds before the first *entry* is automatically booted.
*Locally assignable (non protocol specific)* keys are: *Locally assignable (non protocol specific)* keys are:
* `KERNEL_DRIVE` - The BIOS drive (in decimal) where the kernel resides (if unspecified, boot drive is assumed). * `PROTOCOL` - The boot protocol that will be used to boot the kernel. Valid protocols are: `linux`, `stivale`.
* `KERNEL_PARTITION` - The index (in decimal) of the partition containing the kernel. * `KERNEL_PROTO` - Alias of `PROTOCOL`.
* `KERNEL_PATH` - The path of the kernel in said partition, forward slashes to delimit directories. * `CMDLINE` - The command line string to be passed to the kernel. Can be omitted.
* `KERNEL_PROTO` - The boot protocol that will be used to boot the kernel. Valid protocols are: `linux`, `stivale`. * `KERNEL_CMDLINE` - Alias of `CMDLINE`.
* `KERNEL_CMDLINE` - The command line string to be passed to the kernel.
*Locally assignable (protocol specific)* keys are: *Locally assignable (protocol specific)* keys are:
* Linux protocol: * Linux protocol:
* `KERNEL_DRIVE` - The BIOS drive (in decimal) where the kernel resides (if unspecified, boot drive is assumed).
* `KERNEL_PARTITION` - The index (in decimal) of the partition containing the kernel.
* `KERNEL_PATH` - The path of the kernel in said partition, forward slashes to delimit directories.
* `INITRD_PARTITION` - Partition index of the initial ramdisk. * `INITRD_PARTITION` - Partition index of the initial ramdisk.
* `INITRD_PATH` - The path to the initial ramdisk. * `INITRD_PATH` - The path to the initial ramdisk.
* stivale protocol: * stivale protocol:
* `KERNEL_DRIVE` - The BIOS drive (in decimal) where the kernel resides (if unspecified, boot drive is assumed).
* `KERNEL_PARTITION` - The index (in decimal) of the partition containing the kernel.
* `KERNEL_PATH` - The path of the kernel in said partition, forward slashes to delimit directories.
* `MODULE_PARTITION` - Partition index of a module. * `MODULE_PARTITION` - Partition index of a module.
* `MODULE_PATH` - The path to a module. * `MODULE_PATH` - The path to a module.
* `MODULE_STRING` - A string to be passed to a module. * `MODULE_STRING` - A string to be passed to a module.
Note that one can define these 3 variable multiple times to specify multiple modules. Note that one can define these 3 variable multiple times to specify multiple modules.
The entries will be matched in order. E.g.: the 1st partition entry will be matched The entries will be matched in order. E.g.: the 1st partition entry will be matched
to the 1st path and the 1st string entry that appear, and so on. to the 1st path and the 1st string entry that appear, and so on.

View File

@ -71,7 +71,9 @@ refresh:
config_set_entry(selected_entry); config_set_entry(selected_entry);
text_enable_cursor(); text_enable_cursor();
if (!config_get_value(cmdline, 0, CMDLINE_MAX, "KERNEL_CMDLINE")) { if (!config_get_value(cmdline, 0, CMDLINE_MAX, "KERNEL_CMDLINE")) {
cmdline[0] = '\0'; if (!config_get_value(cmdline, 0, CMDLINE_MAX, "CMDLINE")) {
cmdline[0] = '\0';
}
} }
text_clear(); text_clear();
return; return;
@ -79,7 +81,9 @@ refresh:
config_set_entry(selected_entry); config_set_entry(selected_entry);
text_enable_cursor(); text_enable_cursor();
if (!config_get_value(cmdline, 0, CMDLINE_MAX, "KERNEL_CMDLINE")) { if (!config_get_value(cmdline, 0, CMDLINE_MAX, "KERNEL_CMDLINE")) {
cmdline[0] = '\0'; if (!config_get_value(cmdline, 0, CMDLINE_MAX, "CMDLINE")) {
cmdline[0] = '\0';
}
} }
print("\n\n> "); print("\n\n> ");
gets(cmdline, cmdline, CMDLINE_MAX); gets(cmdline, cmdline, CMDLINE_MAX);
@ -90,8 +94,6 @@ refresh:
} }
void main(int boot_drive) { void main(int boot_drive) {
struct file_handle f;
// Initial prompt. // Initial prompt.
init_vga_textmode(); init_vga_textmode();
@ -121,14 +123,13 @@ void main(int boot_drive) {
} }
} }
int drive, part; int timeout; {
char path[128], proto[64], buf[32]; char buf[32];
if (!config_get_value(buf, 0, 32, "TIMEOUT")) {
int timeout; timeout = 5;
if (!config_get_value(buf, 0, 64, "TIMEOUT")) { } else {
timeout = 5; timeout = (int)strtoui(buf);
} else { }
timeout = (int)strtoui(buf);
} }
print("\n"); print("\n");
@ -152,30 +153,17 @@ void main(int boot_drive) {
got_entry: got_entry:
init_e820(); init_e820();
if (!config_get_value(buf, 0, 32, "KERNEL_DRIVE")) { char proto[32];
drive = boot_drive; if (!config_get_value(proto, 0, 32, "KERNEL_PROTO")) {
} else { if (!config_get_value(proto, 0, 32, "PROTOCOL")) {
drive = (int)strtoui(buf); panic("PROTOCOL not specified");
} }
if (!config_get_value(buf, 0, 32, "KERNEL_PARTITION")) {
panic("KERNEL_PARTITION not specified");
}
part = (int)strtoui(buf);
if (!config_get_value(path, 0, 128, "KERNEL_PATH")) {
panic("KERNEL_PATH not specified");
}
if (!config_get_value(proto, 0, 64, "KERNEL_PROTO")) {
panic("KERNEL_PROTO not specified");
}
if (fopen(&f, drive, part, path)) {
panic("Could not open kernel file");
} }
if (!strcmp(proto, "stivale")) { if (!strcmp(proto, "stivale")) {
stivale_load(&f, cmdline); stivale_load(cmdline, boot_drive);
} else if (!strcmp(proto, "linux")) { } else if (!strcmp(proto, "linux")) {
linux_load(&f, cmdline); linux_load(cmdline, boot_drive);
} else { } else {
panic("Invalid protocol specified"); panic("Invalid protocol specified");
} }

View File

@ -10,7 +10,35 @@
#define KERNEL_LOAD_ADDR ((size_t)0x100000) #define KERNEL_LOAD_ADDR ((size_t)0x100000)
#define INITRD_LOAD_ADDR ((size_t)0x1000000) #define INITRD_LOAD_ADDR ((size_t)0x1000000)
void linux_load(struct file_handle *fd, char *cmdline) { void linux_load(char *cmdline, int boot_drive) {
int kernel_drive; {
char buf[32];
if (!config_get_value(buf, 0, 32, "KERNEL_DRIVE")) {
kernel_drive = boot_drive;
} else {
kernel_drive = (int)strtoui(buf);
}
}
int kernel_part; {
char buf[32];
if (!config_get_value(buf, 0, 32, "KERNEL_PARTITION")) {
panic("KERNEL_PARTITION not specified");
} else {
kernel_part = (int)strtoui(buf);
}
}
char *kernel_path = balloc(128);
if (!config_get_value(kernel_path, 0, 128, "KERNEL_PATH")) {
panic("KERNEL_PATH not specified");
}
struct file_handle *fd = balloc(sizeof(struct file_handle));
if (fopen(fd, kernel_drive, kernel_part, kernel_path)) {
panic("Could not open kernel file");
}
uint32_t signature; uint32_t signature;
fread(fd, &signature, 0x202, sizeof(uint32_t)); fread(fd, &signature, 0x202, sizeof(uint32_t));
@ -82,8 +110,11 @@ void linux_load(struct file_handle *fd, char *cmdline) {
int initrd_part; { int initrd_part; {
char buf[32]; char buf[32];
config_get_value(buf, 0, 32, "INITRD_PARTITION"); if (!config_get_value(buf, 0, 32, "INITRD_PARTITION")) {
initrd_part = (int)strtoui(buf); initrd_part = fd->partition;
} else {
initrd_part = (int)strtoui(buf);
}
} }
struct file_handle initrd; struct file_handle initrd;

View File

@ -3,6 +3,6 @@
#include <fs/file.h> #include <fs/file.h>
void linux_load(struct file_handle *fd, char *cmdline); void linux_load(char *cmdline, int boot_drive);
#endif #endif

View File

@ -46,7 +46,35 @@ struct stivale_struct {
struct stivale_struct stivale_struct = {0}; struct stivale_struct stivale_struct = {0};
void stivale_load(struct file_handle *fd, char *cmdline) { void stivale_load(char *cmdline, int boot_drive) {
int kernel_drive; {
char buf[32];
if (!config_get_value(buf, 0, 32, "KERNEL_DRIVE")) {
kernel_drive = boot_drive;
} else {
kernel_drive = (int)strtoui(buf);
}
}
int kernel_part; {
char buf[32];
if (!config_get_value(buf, 0, 32, "KERNEL_PARTITION")) {
panic("KERNEL_PARTITION not specified");
} else {
kernel_part = (int)strtoui(buf);
}
}
char *kernel_path = balloc(128);
if (!config_get_value(kernel_path, 0, 128, "KERNEL_PATH")) {
panic("KERNEL_PATH not specified");
}
struct file_handle *fd = balloc(sizeof(struct file_handle));
if (fopen(fd, kernel_drive, kernel_part, kernel_path)) {
panic("Could not open kernel file");
}
struct stivale_header stivale_hdr; struct stivale_header stivale_hdr;
int bits = elf_bits(fd); int bits = elf_bits(fd);

View File

@ -3,6 +3,6 @@
#include <fs/file.h> #include <fs/file.h>
void stivale_load(struct file_handle *fd, char *cmdline); void stivale_load(char *cmdline, int boot_drive);
#endif #endif

View File

@ -2,10 +2,11 @@ TIMEOUT=3
:Test kernel :Test kernel
PROTOCOL=stivale
KERNEL_PARTITION=1 KERNEL_PARTITION=1
KERNEL_PATH=/boot/test.elf KERNEL_PATH=/boot/test.elf
KERNEL_PROTO=stivale KERNEL_CMDLINE=something
KERNEL_CMDLINE=none
MODULE_PARTITION=1 MODULE_PARTITION=1
MODULE_PATH=qloader2.cfg MODULE_PATH=qloader2.cfg