diff --git a/lib/default.nix b/lib/default.nix index 8a6a318..4894cae 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -7,18 +7,21 @@ let inherit (nixpkgs) buildPackages; testPkgs = thisSystem genodepkgs.packages; + dhallCachePrelude = '' + export XDG_CACHE_HOME=$NIX_BUILD_TOP + export DHALL_GENODE="${testPkgs.dhallGenode}/binary.dhall"; + ${buildPackages.xorg.lndir}/bin/lndir -silent \ + ${testPkgs.dhallGenode}/.cache \ + $XDG_CACHE_HOME + ''; + in rec { runDhallCommand = name: env: script: nixpkgs.runCommand name ({ nativeBuildInputs = [ buildPackages.dhall ]; } // env) '' - export XDG_CACHE_HOME=$NIX_BUILD_TOP - export DHALL_GENODE="${testPkgs.dhallGenode}/binary.dhall"; - ${buildPackages.xorg.lndir}/bin/lndir -silent \ - ${testPkgs.dhallGenode}/.cache \ - $XDG_CACHE_HOME - - ${script} + ${dhallCachePrelude} + ${script} ''; linuxScript = name: env: bootDhall: @@ -31,16 +34,72 @@ in rec { runDhallCommand name env '' dhall to-directory-tree --output $out \ <<< "${./compile-boot.dhall} (${bootDhall}) \"$out\"" + dhall <<< "(${bootDhall}).config" \ + | dhall encode \ + > $out/config.dhall.bin ''; - novaImage = name: env: boot: - let inherit (nixpkgs.stdenv) cc; - in nixpkgs.stdenv.mkDerivation { + hwImage = name: env: boot: + nixpkgs.stdenv.mkDerivation { name = name + ".image.elf"; - # buildInputs = with buildPackages; [ stdenv.cc ]; build = compileBoot name env boot; + nativeBuildInputs = [ buildPackages.dhall ]; + buildCommand = let + bootstrapDhall = + # snippet used to nest core.elf into image.elf + builtins.toFile "boostrap.dall" '' + let Genode = env:DHALL_GENODE - # CC="${cc}/bin/${cc.targetPrefix}cc" + in { config = Genode.Init.default + , rom = + Genode.BootModules.toRomPaths + [ { mapKey = "core.elf", mapValue = "./core.elf" } ] + } + ''; + in '' + ${dhallCachePrelude} + + build_core() { + local lib="$1" + local modules="$2" + local link_address="$3" + local out="$4" + + # compile the boot modules into one object file + $CC -c -x assembler -o "boot_modules.o" "$modules" + + # link final image + LD="${buildPackages.binutils}/bin/${buildPackages.binutils.targetPrefix}ld" + $LD \ + --strip-all \ + -T${testPkgs.genodeSources}/repos/base/src/ld/genode.ld \ + -z max-page-size=0x1000 \ + -Ttext=$link_address -gc-sections \ + "$lib" "boot_modules.o" \ + -o $out + } + + build_core \ + "${testPkgs.base-hw-pc.coreObj}" \ + "$build/modules_asm" \ + 0xffffffc000000000 \ + core.elf + + dhall to-directory-tree --output bootstrap \ + <<< "${./compile-boot.dhall} ${bootstrapDhall} \"bootstrap\"" + + build_core \ + "${testPkgs.base-hw-pc.bootstrapObj}" \ + bootstrap/modules_asm \ + 0x00200000 \ + $out + ''; + }; + + novaImage = name: env: boot: + nixpkgs.stdenv.mkDerivation { + name = name + ".image.elf"; + build = compileBoot name env boot; buildCommand = '' # compile the boot modules into one object file diff --git a/tests/boot-ram.dhall b/tests/boot-ram.dhall deleted file mode 100644 index 1a20451..0000000 --- a/tests/boot-ram.dhall +++ /dev/null @@ -1,9 +0,0 @@ --- SPDX-License-Identifier: CC0-1.0 - -let Genode = env:DHALL_GENODE - -let sumRam = - λ(boot : Genode.Boot.Type) - → let sum = Genode.Init.resources boot.config in sum.ram - -in sumRam diff --git a/tests/driver-hw.nix b/tests/driver-hw.nix index 8596203..ac6ad85 100644 --- a/tests/driver-hw.nix +++ b/tests/driver-hw.nix @@ -48,7 +48,7 @@ let XDG_CACHE_HOME = "/tmp"; } // testEnv; - image = apps.hw-image.function testEnv' testConfig'; + image = lib.hwImage name testEnv' testConfig'; baseSetup = '' ## @@ -114,13 +114,13 @@ let mkdir -p $out/bin echo "$testScript" > $out/test-script echo "$baseSetup" > $out/base-setup - eval $(${apps.dhall-to-bash.program} --declare "TEST_RAM" \ - <<< "${./boot-ram.dhall} (${testConfig'})") + source ${image.build}/stats + ln -s ${testDriver}/bin/genode-test-driver $out/bin/ wrapProgram $out/bin/genode-test-driver \ --set testScript "$testScript" \ --set baseSetup "$baseSetup" \ - --set TEST_RAM $TEST_RAM \ + --set TEST_RAM $RAM \ ''; passMeta = drv: diff --git a/tests/driver-nova.nix b/tests/driver-nova.nix index b94f003..2af38ca 100644 --- a/tests/driver-nova.nix +++ b/tests/driver-nova.nix @@ -116,7 +116,7 @@ let mkdir -p $out/bin echo "$testScript" > $out/test-script echo "$baseSetup" > $out/base-setup - source ${build}/stats + source ${image.build}/stats ln -s ${testDriver}/bin/genode-test-driver $out/bin/ wrapProgram $out/bin/genode-test-driver \ @@ -132,7 +132,8 @@ let test = passMeta (runTests driver); in test // { - inherit build driver image test manifest; + inherit driver image test manifest; + inherit (image) build; config = buildPackages.runCommand (name + ".dhall") testEnv' '' ${apps.dhall.program} <<< "${testConfig'}" > $out