Browse Source

Write boot image configuration to file during compilation

Sometimes ld chokes on complex XML renderings.
llvm-10
Emery Hemingway 2 years ago
parent
commit
2aab55dc38
  1. 18
      apps/hw-image/default.nix
  2. 9
      apps/insert-config-rom.dhall
  3. 14
      apps/nova-image/default.nix
  4. 12
      apps/render-init/default.nix
  5. 16
      lib/default.nix
  6. 12
      packages/default.nix
  7. 54
      packages/genodelabs/init.xsd.patch
  8. 10
      packages/genodelabs/sources.nix
  9. 2
      tests/driver-hw.nix
  10. 2
      tests/driver-linux.nix
  11. 2
      tests/driver-nova.nix
  12. 4
      tests/pci.dhall

18
apps/hw-image/default.nix

@ -39,8 +39,20 @@ in nixpkgs.writeScriptBin "hw-image" (with nixpkgs.buildPackages;
"$lib" "$TMPDIR/boot_modules.o"
cat a.out
}
set -v
${dhallApps.dhall.program} <<< "${../render-rom.dhall} ($@)" > "$TMPDIR/modules.dhall"
${dhallApps.dhall.program} text \
<<< "(env:DHALL_GENODE).Init.render ($@).config" \
| ${nixpkgs.buildPackages.libxml2}/bin/xmllint \
-schema ${packages.genode-sources}/repos/os/src/init/config.xsd - \
| sed 's/&gt;/>/g' \
> $TMPDIR/config
${dhallApps.dhall.program} \
<<< "${../insert-config-rom.dhall} \"$TMPDIR/config\" ($@).rom" \
> "$TMPDIR/modules.dhall"
build_core "''${CORE_OBJ:-${base-hw-pc}/lib/core-hw-pc.o}" "$TMPDIR/modules.dhall" 0xffffffc000000000 > core.elf
build_core "''${BOOTSTRAP_OBJ:-${base-hw-pc}/lib/bootstrap-hw-pc.o}" "${../to-rom.dhall} \"core.elf\" \"./core.elf\"" 0x00200000
build_core "''${BOOTSTRAP_OBJ:-${base-hw-pc}/lib/bootstrap-hw-pc.o}" "${
../to-rom.dhall
} \"core.elf\" \"./core.elf\"" 0x00200000
'')

9
apps/insert-config-rom.dhall

@ -0,0 +1,9 @@
-- SPDX-License-Identifier: CC0-1.0
let Genode = env:DHALL_GENODE
let BootModules = Genode.BootModules
in λ(configPath : Text)
→ λ(rom : Genode.BootModules.Type)
→ BootModules.toRomPaths (toMap { config = configPath }) # rom

14
apps/nova-image/default.nix

@ -18,8 +18,18 @@ in nixpkgs.writeScriptBin "nova-image" (with nixpkgs.buildPackages;
export DHALL_PRELUDE=${packages.dhallPrelude}/package.dhall
export DHALL_GENODE=${packages.dhallGenode}/package.dhall
${dhallApps.dhall.program} text <<< \
"(${../modules.as.dhall}).to64bitImage (${../render-rom.dhall} ($@))" \
${dhallApps.dhall.program} text \
<<< "(env:DHALL_GENODE).Init.render ($@).config" \
| ${nixpkgs.buildPackages.libxml2}/bin/xmllint \
-schema ${packages.genode-sources}/repos/os/src/init/config.xsd - \
| sed 's/&gt;/>/g' \
> $TMPDIR/config
${dhallApps.dhall.program} text \
<<< "(${../modules.as.dhall}).to64bitImage (${
../insert-config-rom.dhall
} \"$TMPDIR/config\" ($@).rom)" \
> "$TMPDIR/modules.as"
# compile the boot modules into one object file

12
apps/render-init/default.nix

@ -5,13 +5,13 @@
nixpkgs.writeScriptBin "render-init" (with nixpkgs.buildPackages; ''
#!${runtimeShell}
set -eu
if [ -z "$@" ]; then
echo "Error: a Dhall init configuration file must be passed as an argument - $0" > /dev/stderr
exit 1
fi
export DHALL_PRELUDE=''${DHALL_PRELUDE:-${packages.dhallPrelude}/package.dhall}
export DHALL_GENODE=''${DHALL_GENODE:-${packages.dhallGenode}/package.dhall}
${dhallApps.dhall.program} text \
<<< "(env:DHALL_GENODE).Init.render ($@)" \
| ${nixpkgs.buildPackages.libxml2}/bin/xmllint -format -
<<< "(env:DHALL_GENODE).Init.render ($(cat))" \
| ${nixpkgs.buildPackages.libxml2}/bin/xmllint \
-format \
-schema ${packages.genode-sources}/repos/os/src/init/config.xsd \
- \
| sed 's/&gt;/>/g'
'')

16
lib/default.nix

@ -29,22 +29,6 @@ in {
dhall text < $source > $out
'';
renderDhallInit = path: args:
hostPkgs.runCommand "init.xml" {
preferLocalBuild = true;
buildInputs = with hostPkgs; [ dhall libxml2 ];
initConfig = path;
initArgs = args;
DHALL_PRELUDE = "${testPkgs.dhallPrelude}/package.dhall";
DHALL_GENODE = "${testPkgs.dhallGenode}/package.dhall";
} ''
export XDG_CACHE_HOME=$NIX_BUILD_TOP
dhall text \
<<< 'let Prelude = env:DHALL_GENODE in Prelude.Init.render (env:initConfig env:initArgs)' \
> $out
xmllint --noout $out
'';
mergeManifests = inputs:
nixpkgs.legacyPackages.${localSystem}.writeTextFile {
name = "manifest.dhall";

12
packages/default.nix

@ -17,16 +17,15 @@ let
callPackage' = path: attrs:
addManifest (legacyPackages.callPackages path attrs);
buildUpstream = let
f = import ./genodelabs {
nixpkgs = legacyPackages;
};
buildUpstream = let f = import ./genodelabs { nixpkgs = legacyPackages; };
in args: addManifest (f args);
in rec {
inherit (legacyPackages) stdenv;
genode-sources = legacyPackages.callPackage ./genodelabs/sources.nix { };
base-hw-pc = buildUpstream {
name = "base-hw-pc";
KERNEL = "hw";
@ -61,10 +60,7 @@ in rec {
'';
};
driversPc = let
directoryBlacklist = [
"repos/dde_zircon"
];
driversPc = let directoryBlacklist = [ "repos/dde_zircon" ];
in buildUpstream {
name = "drivers";
BOARD = "pc";

54
packages/genodelabs/init.xsd.patch

@ -0,0 +1,54 @@
commit c0a6db17001fb088d3289613a02660d8725bbde8
Author: Emery Hemingway <ehmry@posteo.net>
Date: Sat Feb 22 15:40:56 2020 +0100
Update Init config schema
- Add <exit propagate="…"/> to the Init schema
- Use a relative path for base_types.xsd
- Allow empty <provides/> nodes
- Allow "label" attributes within <parent-provides/>
diff --git a/repos/os/src/init/config.xsd b/repos/os/src/init/config.xsd
index 938dcdb8fb..e7bfb5dfc5 100644
--- a/repos/os/src/init/config.xsd
+++ b/repos/os/src/init/config.xsd
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
- <xs:include schemaLocation="base_types.xsd"/>
+ <xs:include schemaLocation="../../../base/xsd/base_types.xsd"/>
<xs:complexType name="template_service">
<xs:choice minOccurs="1" maxOccurs="3">
@@ -90,6 +90,7 @@
<xs:element name="service" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
+ <xs:attribute name="label" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
@@ -160,6 +161,12 @@
</xs:complexType>
</xs:element> <!-- "resource" -->
+ <xs:element name="exit">
+ <xs:complexType>
+ <xs:attribute name="propagate" type="Boolean" />
+ </xs:complexType>
+ </xs:element> <!-- "exit" -->
+
<xs:element name="configfile">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
@@ -168,7 +175,7 @@
<xs:element name="provides">
<xs:complexType>
- <xs:choice maxOccurs="unbounded">
+ <xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element name="service">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />

10
packages/genodelabs/sources.nix

@ -0,0 +1,10 @@
{ stdenv, genodeHeaders }:
stdenv.mkDerivation {
pname = "genode-sources";
inherit (genodeHeaders) version src;
patches = [ ./init.xsd.patch ./svn-trust-server-cert.patch ];
dontConfigure = true;
dontBuild = true;
installPhase = "cp -a . $out";
}

2
tests/driver-hw.nix

@ -143,7 +143,7 @@ let
iso = apps.hw-iso.function testEnv' testConfig';
xml = hostPkgs.runCommand (name + ".config") testEnv' ''
${apps.render-init.program} "(${testConfig'}).config" > $out'';
${apps.render-init.program} <<< "(${testConfig'}).config" > $out'';
sotest = hostPkgs.runCommand "hw-${name}-sotest" testEnv' ''
cp "${testPkgs.bender}" bender

2
tests/driver-linux.nix

@ -104,7 +104,7 @@ let
${apps.dhall.program} <<< "(${testConfig'}).config" > $out
'';
xml = hostPkgs.runCommand (name + ".config") env' ''
${apps.render-init.program} "(${testConfig'}).config" > $out
${apps.render-init.program} <<< "(${testConfig'}).config" > $out
'';
image = hostPkgs.runCommand (name + ".image.elf") env' ''
mkdir -p $out

2
tests/driver-nova.nix

@ -144,7 +144,7 @@ let
iso = apps.nova-iso.function testEnv' "${testConfig'}";
xml = hostPkgs.runCommand (name + ".config") testEnv' ''
${apps.render-init.program} "(${testConfig'}).config" > $out'';
${apps.render-init.program} <<< "(${testConfig'}).config" > $out'';
sotest = hostPkgs.runCommand "nova-${name}-sotest" testEnv' ''
cp "${testPkgs.bender}" bender

4
tests/pci.dhall

@ -38,7 +38,7 @@ in { config =
, constrainPhys = True
}
, provides = [ "Platform", "Acpi" ]
, romReports = [ label "acpi" ]
, romReports = [ label "acpi", label "smbios_table" ]
, routes =
[ ServiceRoute.parent "IRQ"
, ServiceRoute.parent "IO_MEM"
@ -77,7 +77,7 @@ in { config =
}
, rom =
let manifest = env:MANIFEST
in Genode.Boot.toRomPaths
[ manifest.drivers.bin.acpi_drv
, manifest.drivers.bin.platform_drv

Loading…
Cancel
Save