Refer to program and library ROMs by store path

Retrieve ROMs in the common case by full store path. This reduces
the need for route policies for driving relative requests into
absolute package paths.

Making library requests by absolute path required libraries to be
stored in the core image as such, and it follows that program
binaries should be handled in the same way. This makes requests
to core and to a file-system store more consistent, and makes
dependency detection more robust.
This commit is contained in:
Emery Hemingway 2021-02-03 20:39:25 +01:00
parent f463b467ce
commit 8379dccf12
17 changed files with 111 additions and 227 deletions

View File

@ -143,10 +143,10 @@ in {
localPackages.runCommand "${drv.name}.dhall" { inherit drv; } ''
set -eu
echo -n '[' >> $out
find $drv/ -type f -printf ',{mapKey= "%f",mapValue="%p"}' >> $out
find $drv/ -type f -printf ',{mapKey= "%p",mapValue="%p"}' >> $out
${if builtins.elem "lib" drv.outputs then
''
find ${drv.lib}/ -type f -printf ',{mapKey= "%f",mapValue="%p"}' >> $out''
find ${drv.lib}/ -type f -printf ',{mapKey= "%p",mapValue="%p"}' >> $out''
else
""}
echo -n ']' >> $out
@ -176,6 +176,8 @@ in {
paths = value.inputs;
}) config.genode.init.children);
tarball =
"${config.system.build.tarball}/tarball/${config.system.build.tarball.fileName}.tar";
in {
assertions = [{
@ -189,17 +191,29 @@ in {
lib.optional (config.genode.boot.storeBackend != "memory")
pkgs.genodePackages.part_block;
genode.boot.romModules = let
getBin = name: "${builtins.getAttr name pkgs.genodePackages}/bin/${name}";
in {
cached_fs_rom = getBin "cached_fs_rom";
init = "${pkgs.genodePackages.init}/bin/init";
jitter_sponge = "${pkgs.genodePackages.jitter_sponge}/bin/jitter_sponge";
report_rom = "${pkgs.genodePackages.report_rom}/bin/report_rom";
rtc_drv = "${pkgs.genodePackages.rtc_drv}/bin/rtc_drv";
vfs = "${pkgs.genodePackages.vfs}/bin/vfs";
"vfs.lib.so" = "${pkgs.genodePackages.vfs.lib}/lib/vfs.lib.so";
};
genode.core.children =
# Component to steer the main fs to a specific partition
(if config.genode.boot.storeBackend != "memory" then {
part_block.configFile = builtins.toFile "part_block.dhall" ''
part_block.configFile = pkgs.writeText "part_block.dhall" ''
let Genode = env:DHALL_GENODE
let Init = Genode.Init
in Init.Child.flat
Init.Child.Attributes::{
, binary = "part_block"
, binary = "${pkgs.genodePackages.part_block}/bin/part_block"
, resources = Init.Resources::{ ram = Genode.units.MiB 8 }
, config = Init.Config::{
, attributes = toMap { ignore_mbr = "yes" }
@ -223,11 +237,24 @@ in {
{ }) // {
fs.configFile = let
vfsConfig = if config.genode.boot.storeBackend == "memory" then ''
VFS.vfs [ VFS.leafAttrs "tar" (toMap { name = "${config.system.build.tarball.fileName}.tar" }) ]
VFS.vfs
[ VFS.leafAttrs
"tar"
(toMap { name = "${tarball}" })
]
'' else
let
rumpExt2 = ''
VFS.vfs [ VFS.leafAttrs "rump" (toMap { fs = "ext2fs", ram="12M" }) ]
VFS.vfs
[ VFS.leafAttrs
"plugin"
( toMap
{ load = "${pkgs.genodePackages.rump}/lib/vfs_rump.lib.so"
, fs = "ext2fs"
, ram = "12M"
}
)
]
'';
in {
ahci = rumpExt2;
@ -262,7 +289,7 @@ in {
}
'') (builtins.attrNames config.genode.init.children);
in builtins.toFile "fs.dhall" ''
in pkgs.writeText "fs.dhall" ''
let Genode = env:DHALL_GENODE
let Init = Genode.Init
@ -297,8 +324,6 @@ in {
};
genode.boot.configFile = let
tarball =
"${config.system.build.tarball}/tarball/${config.system.build.tarball.fileName}.tar";
storeBackendInputs = {
fs = [ pkgs.genodePackages.rump ];
@ -315,8 +340,7 @@ in {
pkgs.writeText "manifest.dhall" (mergeManifests (map addManifest
(with pkgs.genodePackages;
config.genode.core.basePackages ++ storeBackendInputs
++ [ init cached_fs_rom jitter_sponge report_rom vfs ]
++ coreInputs))
++ [ cached_fs_rom jitter_sponge report_rom vfs ] ++ coreInputs))
+ lib.optionalString (config.genode.boot.romModules != { }) ''
# [ { mapKey = "romModules", mapValue = [ ${
toString (mapAttrsToList

View File

@ -27,7 +27,7 @@ in λ(params : { fontFile : Text }) →
{ gui_fb =
Child.flat
Child.Attributes::{
, binary = "gui_fb"
, binary = "${pkgs.genodePackages.gui_fb}/bin/gui_fb"
, exitPropagate = True
, resources = Resources::{ ram = Genode.units.MiB 8 }
, config = Init.Config::{
@ -53,7 +53,7 @@ in λ(params : { fontFile : Text }) →
, terminal =
Child.flat
Child.Attributes::{
, binary = "terminal"
, binary = "${pkgs.genodePackages.terminal}/bin/terminal"
, exitPropagate = True
, resources = Resources::{
, caps = 256
@ -131,7 +131,8 @@ in λ(params : { fontFile : Text }) →
, terminal_log =
Child.flat
Child.Attributes::{
, binary = "terminal_log"
, binary =
"${pkgs.genodePackages.terminal_log}/bin/terminal_log"
, config = Init.Config::{
, policies =
[ Init.Config.Policy::{
@ -148,13 +149,13 @@ in λ(params : { fontFile : Text }) →
, core =
Child.flat
Child.Attributes::{
, binary = "log_core"
, binary = "${pkgs.genodePackages.log_core}/bin/log_core"
, routes = [ routeLogRom "core_log" ]
}
, kernel =
Child.flat
Child.Attributes::{
, binary = "log_core"
, binary = "${pkgs.genodePackages.log_core}/bin/log_core"
, routes = [ routeLogRom "kernel_log" ]
}
}

View File

@ -7,7 +7,7 @@ let Init = Genode.Init
in λ(params : { policies : List Init.Config.Policy.Type }) →
Init.Child.flat
Init.Child.Attributes::{
, binary = "nitpicker"
, binary = "${pkgs.genodePackages.nitpicker}/bin/nitpicker"
, resources = Init.Resources::{ ram = Genode.units.MiB 4 }
, config = Init.Config::{
, attributes = toMap

View File

@ -33,7 +33,7 @@ with lib;
in Init.Child.flat
Init.Child.Attributes::{
, binary = "ahci_drv"
, binary = "${pkgs.genodePackages.ahci_drv}/bin/ahci_drv"
, resources = Init.Resources::{
, caps = 400
, ram = Genode.units.MiB 10

View File

@ -32,7 +32,7 @@ with lib;
in Init.Child.flat
Init.Child.Attributes::{
, binary = "acpi_drv"
, binary = "${pkgs.genodePackages.acpi_drv}/bin/acpi_drv"
, resources = Init.Resources::{
, caps = 400
, ram = Genode.units.MiB 4
@ -60,7 +60,7 @@ with lib;
in Init.Child.flat
Init.Child.Attributes::{
, binary = "platform_drv"
, binary = "${pkgs.genodePackages.platform_drv}/bin/platform_drv"
, resources = Init.Resources::{
, caps = 800
, ram = Genode.units.MiB 4

View File

@ -13,18 +13,20 @@ with lib;
config = {
genode.core.children.fb_drv =
mkIf config.hardware.genode.framebuffer.enable {
inputs = with pkgs.genodePackages;
genode.core.children.fb_drv = mkIf config.hardware.genode.framebuffer.enable
(let
binary = with pkgs.genodePackages;
{
"boot" = [ boot_fb_drv ];
"vesa" = [ vesa_drv ];
boot = boot_fb_drv;
vesa = vesa_drv;
}.${config.hardware.genode.framebuffer.driver};
in {
inputs = [ binary ];
configFile = let
binary = with pkgs.genodePackages;
{
"boot" = "boot_fb_drv";
"vesa" = "vesa_fb_drv";
boot = "${boot_fb_drv}/bin/boot_fb_drv";
vesa = "${vesa_drv}/bin/vesa_fb_drv";
}.${config.hardware.genode.framebuffer.driver};
in builtins.toFile "fb_drv.dhall" ''
let Genode = env:DHALL_GENODE
@ -43,7 +45,7 @@ with lib;
]
}
'';
};
});
};

View File

@ -103,7 +103,7 @@ with lib;
in Init.Child.flat
Init.Child.Attributes::{
, binary = "${binary.pname}"
, binary = "${binary}/bin/${binary.pname}"
, provides = [ "Nic" ]
, resources = Init.Resources::{ caps = 128, ram = Genode.units.MiB 4 }
, routes = [ Init.ServiceRoute.parent "IO_MEM" ]
@ -120,31 +120,36 @@ with lib;
genode.init.children = let
sockets = mapAttrs' (name: interface:
let name' = name + ".sockets";
let
name' = name + ".sockets";
vfsPlugin = with pkgs.genodePackages;
{
lwip = vfs_lwip;
lxip = vfs_lxip;
}.${interface.genode.stack};
in {
name = name';
value = if interface.genode.stack == null then
null
else {
inputs = with pkgs.genodePackages;
{
lwip = [ vfs_lwip ];
lxip = [ vfs_lxip ];
}.${interface.genode.stack};
inputs = [ vfsPlugin ];
routeToNics = [ name ];
configFile = let
binary = "${pkgs.genodePackages.vfs}/bin/vfs";
ram = {
lwip = 16;
lxip = 32;
}.${interface.genode.stack};
settings = with builtins;
[{
name = "label";
value = name;
}] ++ lib.optionals (interface.ipv4.addresses != [ ])
[
{
name = "label";
value = name;
}
{
name = "load";
value = "${vfsPlugin}/lib/${vfsPlugin.pname}.lib.so";
}
] ++ lib.optionals (interface.ipv4.addresses != [ ])
(let addr = head interface.ipv4.addresses;
in [
{
@ -177,7 +182,7 @@ with lib;
in Init.Child.flat
Init.Child.Attributes::{
, binary = "${binary}"
, binary = "${pkgs.genodePackages.vfs}/bin/vfs"
, provides = [ "File_system" ]
, resources = Init.Resources::{
, caps = 128
@ -196,7 +201,7 @@ with lib;
in [ VFS.vfs
[ VFS.leafAttrs
"${interface.genode.stack}"
"plugin"
([ ${settingsMap} ] : Genode.Prelude.Map.Type Text Text)
]
]

View File

@ -46,7 +46,7 @@ with lib;
in Init.Child.flat
Init.Child.Attributes::{
, binary = "usb_drv"
, binary = "${pkgs.genodePackages.usb_drv}/bin/usb_drv"
, resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 12 }
, romReports = let local = "devices" in [ { local, route = local } ]
, routes = [ Init.ServiceRoute.parent "IO_MEM" ]
@ -97,7 +97,7 @@ with lib;
in Init.Child.flat
Init.Child.Attributes::{
, binary = "usb_block_drv"
, binary = "${pkgs.genodePackages.usb_block_drv}/bin/usb_block_drv"
, resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 4 }
, config = Init.Config::{
, attributes = toMap { writeable = "yes" }

View File

@ -22,12 +22,14 @@ in {
genode.core = {
prefix = "nova-";
supportedSystems = [ "x86_64-genode" ];
basePackages = with pkgs.genodePackages; [ base-nova rtc_drv ];
};
genode.boot = {
image =
utils.novaImage config.system.name { } config.genode.boot.configFile;
genode.boot.image =
utils.novaImage config.system.name { } config.genode.boot.configFile;
genode.boot.romModules = {
"ld.lib.so" = "${pkgs.genodePackages.base-nova}/lib/ld.lib.so";
timer_drv = "${pkgs.genodePackages.base-nova}/bin/timer_drv";
};
genode.boot.storePaths =

View File

@ -8,33 +8,12 @@
};
genode.boot.storeBackend = "fs";
genode.init.children.hello = {
inputs = [ pkgs.hello pkgs.genodePackages.vfs.lib ];
configFile = pkgs.writeText "ahci-hello.child.dhall" ''
let Genode = env:DHALL_GENODE
let Init = Genode.Init
let Child = Init.Child
let Libc = Genode.Libc
in Child.flat
Child.Attributes::{
, binary = "hello"
, exitPropagate = True
, resources = Genode.Init.Resources::{
, caps = 500
, ram = Genode.units.MiB 10
}
, config =
Libc.toConfig
Libc::{ args = [ "hello", "-g", "Hello from AHCI test" ] }
}
'';
configFile = ./hello.dhall;
inputs = [ pkgs.hello ];
};
};
testScript = ''
start_all()
machine.wait_until_serial_output("Hello from AHCI test")
machine.wait_until_serial_output("child \"init\" exited with exit value 0")
'';
}

View File

@ -15,7 +15,6 @@ let
./hello.nix
./log.nix
./vmm_x86.nix
./x86.nix
];
core = builtins.filter (core:

View File

@ -1,6 +1,4 @@
let Genode =
env:DHALL_GENODE
? https://git.sr.ht/~ehmry/dhall-genode/blob/master/package.dhall
let Genode = env:DHALL_GENODE
let Init = Genode.Init
@ -16,5 +14,5 @@ in Child.flat
, caps = 500
, ram = Genode.units.MiB 10
}
, config = Libc.toConfig Libc.default
, config = Libc.toConfig Libc::{ args = [ "hello" ] }
}

View File

@ -1,27 +1,11 @@
{
name = "hello";
machine = { pkgs, ... }:
let
hello = pkgs.stdenv.mkDerivation {
name = "hello";
dontUnpack = true;
buildPhase = ''
cat > hello.c << EOF
#include <stdio.h>
int main(int argc, char **argv) { printf("hello world!\n"); return 0; }
EOF
$CC hello.c -o hello
'';
installPhase = "install -Dt $out/bin hello";
};
in {
genode.init.children.hello = {
configFile = ./hello.dhall;
inputs = [ hello pkgs.genodePackages.vfs.lib ];
# TODO: libc.lib.so has only relative linking to vfs.lib.so
};
machine = { pkgs, ... }: {
genode.init.children.hello = {
configFile = ./hello.dhall;
inputs = [ pkgs.hello ];
};
};
testScript = ''
start_all()
machine.wait_until_serial_output("child \"init\" exited with exit value 0")

View File

@ -1,15 +0,0 @@
let Genode =
env:DHALL_GENODE
? https://git.sr.ht/~ehmry/dhall-genode/blob/master/package.dhall
let Child = Genode.Init.Child
in Child.flat
Child.Attributes::{
, binary = "test-log"
, exitPropagate = True
, resources = Genode.Init.Resources::{
, caps = 500
, ram = Genode.units.MiB 10
}
}

View File

@ -2,8 +2,23 @@
name = "log";
machine = { pkgs, ... }: {
genode.init.children.log = {
configFile = ./log.dhall;
inputs = [ pkgs.genodePackages.test-log ];
configFile = pkgs.writeText "test-log.dhall" ''
let Genode =
env:DHALL_GENODE
? https://git.sr.ht/~ehmry/dhall-genode/blob/master/package.dhall
let Child = Genode.Init.Child
in Child.flat
Child.Attributes::{
, binary = "${pkgs.genodePackages.test-log}/bin/test-log"
, exitPropagate = True
, resources = Genode.Init.Resources::{
, caps = 500
, ram = Genode.units.MiB 10
}
}
'';
};
};
testScript = ''

View File

@ -1,88 +0,0 @@
let Genode = env:DHALL_GENODE
let XML = Genode.Prelude.XML
let Init = Genode.Init
let Child = Init.Child
let Resources = Init.Resources
let ServiceRoute = Init.ServiceRoute
let label = λ(_ : Text) → { local = _, route = _ } : Child.Attributes.Label
let pciInit =
Init::{
, verbose = True
, routes = [ ServiceRoute.parent "Timer", ServiceRoute.parent "Rtc" ]
, children = toMap
{ signal =
Child.flat
Child.Attributes::{
, binary = "test-signal"
, exitPropagate = True
, priority = 5
, resources = Init.Resources::{
, caps = 500
, ram = Genode.units.MiB 10
}
}
, rtc = Child.flat Child.Attributes::{ binary = "test-rtc" }
, test-pci =
Child.flat
Child.Attributes::{
, binary = "test-pci"
, resources = Resources::{ ram = Genode.units.MiB 3 }
}
, acpi_drv =
Child.flat
Child.Attributes::{
, binary = "acpi_drv"
, resources = Resources::{
, caps = 400
, ram = Genode.units.MiB 4
, constrainPhys = True
}
, romReports = [ label "acpi", label "smbios_table" ]
, routes =
[ ServiceRoute.parent "IRQ"
, ServiceRoute.parent "IO_MEM"
, ServiceRoute.parent "IO_PORT"
]
}
, platform_drv =
Child.flat
Child.Attributes::{
, binary = "platform_drv"
, resources = Resources::{
, caps = 800
, ram = Genode.units.MiB 4
, constrainPhys = True
}
, reportRoms = [ label "acpi" ]
, provides = [ "Platform" ]
, routes =
[ ServiceRoute.parent "IRQ"
, ServiceRoute.parent "IO_MEM"
, ServiceRoute.parent "IO_PORT"
]
, config = Init.Config::{
, policies =
[ Init.Config.Policy::{
, service = "Platform"
, label = Init.LabelSelector.prefix "test-pci"
, content =
[ XML.leaf
{ name = "pci"
, attributes = toMap { class = "ALL" }
}
]
}
]
}
}
}
}
in pciInit

View File

@ -1,22 +0,0 @@
{
name = "x86";
constraints = builtins.any (spec: spec == "x86");
machine = { pkgs, ... }: {
genode.init.subinits.test = {
configFile = ./x86.dhall;
coreROMs = [ "platform_info" ];
inputs = with pkgs.genodePackages; [
acpi_drv
platform_drv
report_rom
test-signal
test-pci
test-rtc
];
};
};
testScript = ''
start_all()
machine.wait_until_serial_output("child \"test\" exited with exit value 0")
'';
}