bootboot: Further address some of the issues raise in #124
This commit is contained in:
parent
45552b23fb
commit
2829666bfd
@ -103,7 +103,7 @@ void bootboot_load(char *config) {
|
||||
/// Kernel loading code ///
|
||||
uint8_t *kernel;
|
||||
|
||||
if (known_initrd_format(bootboot_initrd_file)) {
|
||||
if (initrd_format(bootboot_initrd_file) != INITRD_FORMAT_UNKNOWN) {
|
||||
const char *corefile = config_get_value((char *)env, 0, "kernel");
|
||||
if (corefile == NULL) {
|
||||
corefile = "sys/core";
|
||||
|
@ -20,20 +20,20 @@ struct initrd_file bruteforce_kernel(struct initrd_file file) {
|
||||
return (struct initrd_file){0};
|
||||
}
|
||||
|
||||
bool known_initrd_format(struct initrd_file file) {
|
||||
enum initrd_format initrd_format(struct initrd_file file) {
|
||||
if (file.size >= 5 && file.data[4] == 0xbf) {
|
||||
return true;
|
||||
return INITRD_FORMAT_JAMESM;
|
||||
}
|
||||
|
||||
if (file.size >= 5 && memcmp("07070", file.data, 5) == 0) {
|
||||
return true;
|
||||
return INITRD_FORMAT_CPIO;
|
||||
}
|
||||
|
||||
if (file.size >= 262 && memcmp("ustar", file.data + 257, 5) == 0) {
|
||||
return true;
|
||||
return INITRD_FORMAT_USTAR;
|
||||
}
|
||||
|
||||
return false;
|
||||
return INITRD_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
INITRD_HANDLER(jamesm);
|
||||
@ -41,17 +41,14 @@ INITRD_HANDLER(ustar);
|
||||
INITRD_HANDLER(cpio);
|
||||
|
||||
INITRD_HANDLER(auto) {
|
||||
if (file.size >= 5 && file.data[4] == 0xbf) {
|
||||
return initrd_open_jamesm(file, path);
|
||||
switch (initrd_format(file)) {
|
||||
case INITRD_FORMAT_JAMESM:
|
||||
return initrd_open_jamesm(file, path);
|
||||
case INITRD_FORMAT_CPIO:
|
||||
return initrd_open_cpio(file, path);
|
||||
case INITRD_FORMAT_USTAR:
|
||||
return initrd_open_ustar(file, path);
|
||||
default:
|
||||
return (struct initrd_file){0};
|
||||
}
|
||||
|
||||
if (file.size >= 5 && memcmp("07070", file.data, 5) == 0) {
|
||||
return initrd_open_cpio(file, path);
|
||||
}
|
||||
|
||||
if (file.size >= 262 && memcmp("ustar", file.data + 257, 5) == 0) {
|
||||
return initrd_open_ustar(file, path);
|
||||
}
|
||||
|
||||
return (struct initrd_file){0};
|
||||
}
|
||||
|
@ -9,8 +9,15 @@ struct initrd_file {
|
||||
uint8_t *data;
|
||||
};
|
||||
|
||||
enum initrd_format {
|
||||
INITRD_FORMAT_UNKNOWN,
|
||||
INITRD_FORMAT_JAMESM,
|
||||
INITRD_FORMAT_CPIO,
|
||||
INITRD_FORMAT_USTAR
|
||||
};
|
||||
|
||||
struct initrd_file bruteforce_kernel(struct initrd_file file);
|
||||
bool known_initrd_format(struct initrd_file file);
|
||||
enum initrd_format initrd_format(struct initrd_file file);
|
||||
|
||||
#define INITRD_HANDLER(name) struct initrd_file initrd_open_##name(struct initrd_file file, const char *path)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user