[boot] Build, load, and pass initrd from boot to init
The initrd image is now created by the build system, loaded by the bootloader, and passed to srv.init, which loads it (but doesn't do anything with it yet, so this is actually a functional regression). This simplifies a lot of the modules code between boot and init as well: Gone are the many subclasses of module and all the data being inline with the module structs, except for any loaded files. Now the only modules loaded and passed will be the initrd, and any devices only the bootloader has knowledge of, like the UEFI framebuffer.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
|
||||
#include <j6/cap_flags.h>
|
||||
#include <j6/errors.h>
|
||||
@@ -10,11 +11,11 @@
|
||||
|
||||
#include "loader.h"
|
||||
#include "modules.h"
|
||||
#include "ramdisk.h"
|
||||
#include "service_locator.h"
|
||||
|
||||
using bootproto::module;
|
||||
using bootproto::module_type;
|
||||
using bootproto::module_program;
|
||||
|
||||
extern "C" {
|
||||
int main(int, const char **);
|
||||
@@ -61,19 +62,38 @@ main(int argc, const char **argv)
|
||||
|
||||
modules mods = modules::load_modules(_arg_modules_phys, sys, __handle_self);
|
||||
|
||||
for (auto &mod : mods.of_type(module_type::program)) {
|
||||
auto &prog = static_cast<const module_program&>(mod);
|
||||
module const *initrd_module;
|
||||
std::vector<module const*> devices;
|
||||
|
||||
char message[100];
|
||||
sprintf(message, " loading program module '%s' at %lx", prog.filename, prog.base_address);
|
||||
j6_log(message);
|
||||
for (auto &mod : mods) {
|
||||
switch (mod.type) {
|
||||
case module_type::initrd:
|
||||
initrd_module = &mod;
|
||||
break;
|
||||
|
||||
if (!load_program(prog, sys_child, slp_mb_child, message)) {
|
||||
j6_log(message);
|
||||
return 2;
|
||||
case module_type::device:
|
||||
devices.push_back(&mod);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Unknown module??
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!initrd_module)
|
||||
return 1;
|
||||
|
||||
j6_handle_t initrd_vma =
|
||||
map_phys(sys, initrd_module->data.pointer, initrd_module->data.count);
|
||||
if (initrd_vma == j6_handle_invalid) {
|
||||
j6_log(" ** error loading ramdisk: mapping physical vma");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ramdisk initrd {initrd_module->data};
|
||||
util::buffer manifest = initrd.load_file("init.manifest");
|
||||
|
||||
service_locator_start(slp_mb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user