[boot] More initrd format changes

CDB seemed to be too simple for the needs of init, and squashfs is too
laden with design choices to work around Linux's APIs. This commit adds
creation of an initrd image of a new format I've called `j6romfs`.

Note that this commit currently does not work! The initrd-reading code
still needs to be added.
This commit is contained in:
Justin C. Miller
2023-01-29 19:10:12 -08:00
parent 1f15d2ef49
commit 6f7dd7fc05
9 changed files with 276 additions and 79 deletions

View File

@@ -4,11 +4,6 @@ class Manifest:
from collections import namedtuple
Entry = namedtuple("Entry", ("module", "target", "output", "flags"))
formats = {
"none": 0x00,
"zstd": 0x01,
}
flags = {
"graphical": 0x01,
"symbols": 0x80,
@@ -45,11 +40,10 @@ class Manifest:
self.flags = config.get("flags", tuple())
initrd = config.get("initrd", dict())
self.initrd = initrd.get("name", "initrd.dat")
self.initrd_format = initrd.get("format", "none")
if not self.initrd_format in Manifest.formats:
raise BonnibelError(f"Manifest specifies unknown initrd format '{self.initrd_format}'")
self.initrd = {
"name": initrd.get("name", "initrd.dat"),
"format": initrd.get("format", "zstd"),
}
self.data = []
for d in config.get("data", tuple()):
@@ -89,15 +83,12 @@ class Manifest:
with open(path, 'wb') as outfile:
magic = "jsixboot".encode("utf-8") # magic string
version = 1
reserved = 0
initrd_format = Manifest.formats.get(self.initrd_format, 0)
bootflags = sum([Manifest.boot_flags.get(s, 0) for s in self.flags])
outfile.write(struct.pack("<8s BBH HH",
outfile.write(struct.pack("<8s BBH",
magic,
version, reserved, len(self.panics),
initrd_format, bootflags))
version, len(self.panics), bootflags))
def write_str(s):
data = s.encode("utf-16le")
@@ -118,7 +109,7 @@ class Manifest:
write_ent(self.kernel)
write_ent(self.init)
write_path(self.initrd)
write_path(self.initrd["name"])
for p in self.panics:
write_ent(p)

View File

@@ -64,20 +64,25 @@ class Project:
outputs = ["all-headers"],
inputs = ["${build_root}/.all_headers"])
from .manifest import Manifest
manifest = Manifest(manifest_file, modules)
debugroot = output / ".debug"
debugroot.mkdir(exist_ok=True)
fatroot = output / "fatroot"
fatroot.mkdir(exist_ok=True)
(fatroot / manifest.location).mkdir(exist_ok=True)
initrdroot = output / "initrd_root"
initrdroot.mkdir(exist_ok=True)
fatroot_content = []
initrd_content = []
from .manifest import Manifest
manifest = Manifest(manifest_file, modules)
def add_fatroot(source, entry):
output = join(manifest.location, entry.output)
def add_fatroot(source, name):
output = join(manifest.location, name)
fatroot_output = f"${{build_root}}/fatroot/{output}"
build.build(
@@ -85,7 +90,7 @@ class Project:
outputs = [fatroot_output],
inputs = [source],
variables = {
"name": f"Installing {output}",
"description": f"Installing {output}",
})
fatroot_content.append(fatroot_output)
@@ -105,9 +110,24 @@ class Project:
"debug": f"${{build_root}}/.debug/{entry.output}.debug",
})
add_fatroot(intermediary, entry)
add_fatroot(intermediary, entry.output)
def add_initrd_exe(entry):
def add_initrd_content(root, name):
output = join(root, name)
initrd_output = f"${{build_root}}/initrd_root/{output}"
build.build(
rule = "cp",
outputs = [initrd_output],
inputs = [f"${{build_root}}/{name}"],
variables = {
"description": f"Installing {name}",
})
initrd_content.append(initrd_output)
build.newline()
def add_initrd_stripped(root, entry):
input_path = f"${{build_root}}/{entry.target}/{entry.output}"
intermediary = f"${{build_root}}/{entry.output}"
@@ -121,13 +141,18 @@ class Project:
"debug": f"${{build_root}}/.debug/{entry.output}.debug",
})
initrd_content.append(intermediary)
add_initrd_content(root, entry.output)
add_fatroot_exe(manifest.kernel)
add_fatroot_exe(manifest.init)
for program in manifest.panics: add_fatroot_exe(program)
for program in manifest.services: add_initrd_exe(program)
for program in manifest.drivers: add_initrd_exe(program)
for program in manifest.panics:
add_fatroot_exe(program)
for program in manifest.services:
add_initrd_stripped("jsix/services", program)
for program in manifest.drivers:
add_initrd_stripped("jsix/drivers", program)
syms = manifest.add_data("symbol_table.dat",
"Symbol table", ("symbols",))
@@ -136,9 +161,9 @@ class Project:
build.build(
rule = "makest",
outputs = [sym_out],
inputs = [f"${{build_root}}/{modules['kernel'].output}"],
inputs = [f"${{build_root}}/kernel/{modules['kernel'].output}"],
)
initrd_content.append(sym_out)
add_initrd_content("jsix/data", "symbol_table.dat")
bootloader = "${build_root}/fatroot/efi/boot/bootx64.efi"
build.build(
@@ -146,23 +171,23 @@ class Project:
outputs = [bootloader],
inputs = ["${build_root}/boot/boot.efi"],
variables = {
"name": "Installing bootloader",
"description": "Installing bootloader",
})
build.newline()
boot_config = str(fatroot / "jsix_boot.dat")
init_config = str(output / "init.manifest")
boot_config = join(fatroot, "jsix", "boot.conf")
manifest.write_boot_config(boot_config)
manifest.write_init_config(init_config, modules)
initrd_content.append(init_config)
initrd = join(fatroot, manifest.location, "initrd.dat")
initrd = str(fatroot / manifest.location / manifest.initrd["name"])
build.build(
rule = "mkinitrd",
rule = "makeinitrd",
outputs = [initrd],
inputs = initrd_content,
)
inputs = [str(initrdroot)],
implicit = initrd_content + ["${source_root}/scripts/mkj6romfs.py"],
variables = {"format": manifest.initrd["format"]},
)
build.newline()
fatroot_content.append(initrd)
build.build(