2
0
Fork 0
Browse Source

Add 'lib' to flake top-level

20.02
Emery Hemingway 3 years ago
parent
commit
410a6522c5
  1. 4
      flake.nix
  2. 141
      lib/default.nix
  3. 0
      lib/genode.ld
  4. 0
      lib/nova-bss.ld
  5. 0
      lib/nova-isolinux.cfg
  6. 32
      tests/default.nix
  7. 10
      tests/driver-nova.nix

4
flake.nix

@ -18,6 +18,8 @@
in {
lib = import ./lib { genodepkgs = self; inherit nixpkgs dhall-haskell; };
packages = forAllSystems (system:
import ./packages.nix {
inherit system;
@ -26,7 +28,7 @@
checks = forAllSystems (system:
import ./tests {
inherit nixpkgs dhall-haskell;
inherit self nixpkgs dhall-haskell;
genodepkgs = builtins.getAttr system self.packages;
});
};

141
lib/default.nix

@ -0,0 +1,141 @@
{ genodepkgs, nixpkgs, dhall-haskell }:
let
hostPkgs = import nixpkgs {
system = "x86_64-linux";
overlays = [ (self: super: { inherit (dhall-haskell.packages) dhall; }) ];
};
depot = hostPkgs.callPackage ../depot { };
testPkgs = genodepkgs.packages.x86_64-genode;
in {
dhallText = name: source:
hostPkgs.runCommand name {
inherit name source;
preferLocalBuild = true;
buildInputs = [ hostPkgs.dhall ];
DHALL_PRELUDE = "${testPkgs.dhallPackages.prelude}/package.dhall";
DHALL_GENODE = "${testPkgs.dhallPackages.genode}/package.dhall";
} ''
export XDG_CACHE_HOME=$NIX_BUILD_TOP
dhall text < $source > $out
'';
renderDhallInit = path: args:
hostPkgs.runCommand "init.xml" {
preferLocalBuild = true;
buildInputs = [ hostPkgs.dhall ];
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 (Prelude.Init::{ children = toMap (env:initConfig env:initArgs) })' \
> $out
'';
x86_64-genode.buildNovaIso = { name, rom }:
let
inherit (hostPkgs) cdrkit syslinux;
coreNovaObj = "${testPkgs.genode-base-nova}/lib/core-nova.o";
addressType = ".quad"; # TODO: 32 or 64 bit?!
map' = with nixpkgs.lib;
l: f:
concatStrings (imap0 (i: v: (f (toString i) v)) l);
mapNames = map' (builtins.attrNames rom);
mapValues = map' (builtins.attrValues rom);
modulesAsm = ''
.set MIN_PAGE_SIZE_LOG2, 12
.set DATA_ACCESS_ALIGNM_LOG2, 3
.section .data
.p2align DATA_ACCESS_ALIGNM_LOG2
.global _boot_modules_headers_begin
_boot_modules_headers_begin:
'' + (mapNames (i: _: ''
${addressType} _boot_module_${i}_name
${addressType} _boot_module_${i}_begin
${addressType} _boot_module_${i}_end - _boot_module_${i}_begin
'')) + ''
.global _boot_modules_headers_end
_boot_modules_headers_end:
'' + (mapNames (i: name: ''
.p2align DATA_ACCESS_ALIGNM_LOG2
_boot_module_${i}_name:
.string "${name}"
.byte 0
'')) + ''
.section .data.boot_modules_binaries
.global _boot_modules_binaries_begin
_boot_modules_binaries_begin:
'' + (mapValues (i: path: ''
.p2align MIN_PAGE_SIZE_LOG2
_boot_module_${i}_begin:
.incbin "${path}"
_boot_module_${i}_end:
'')) + ''
.p2align MIN_PAGE_SIZE_LOG2
.global _boot_modules_binaries_end
_boot_modules_binaries_end:
'';
syslinuxDir = "${syslinux}/share/syslinux";
in hostPkgs.stdenv.mkDerivation {
name = name + ".iso";
preferLocalBuild = true;
buildInputs = [ testPkgs.stdenv.cc hostPkgs.cdrkit ];
dontUnpack = true;
dontConfigure = true;
dontBuild = true;
inherit modulesAsm;
installPhase = ''
mkdir -p boot/syslinux
# compile the boot modules into one object file
$CC -c -x assembler -o boot_modules.o - <<< $modulesAsm
# link final image
$LD -nostdlib \
-T${./genode.ld} \
-T${./nova-bss.ld} \
-z max-page-size=0x1000 \
-Ttext=0x100000 -gc-sections \
${coreNovaObj} boot_modules.o \
-o boot/image.elf
strip boot/image.elf
# build ISO image
cp ${testPkgs.nova}/hypervisor* boot/hypervisor
cp ${./nova-isolinux.cfg} boot/syslinux/isolinux.cfg
cp \
${syslinuxDir}/isolinux.bin \
${syslinuxDir}/ldlinux.c32 \
${syslinuxDir}/libcom32.c32 \
${syslinuxDir}/mboot.c32 \
boot/syslinux
chmod +w boot/syslinux/isolinux.bin
mkisofs -o $out \
-b syslinux/isolinux.bin -c syslinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-iso-level 2 \
boot
'';
};
}

0
tests/genode.ld → lib/genode.ld

0
tests/nova-bss.ld → lib/nova-bss.ld

0
tests/nova-isolinux.cfg → lib/nova-isolinux.cfg

32
tests/default.nix

@ -11,7 +11,7 @@ let
# solo5 = call ./solo5 { };
};
in { genodepkgs, nixpkgs, dhall-haskell }:
in { self, genodepkgs, nixpkgs, dhall-haskell }:
let
hostPkgs = import nixpkgs {
@ -21,35 +21,7 @@ let
depot = hostPkgs.callPackage ../depot { };
testPkgs = genodepkgs;
lib = hostPkgs.lib // {
dhallText = name: source:
hostPkgs.runCommand name {
inherit name source;
preferLocalBuild = true;
buildInputs = [ hostPkgs.dhall ];
DHALL_PRELUDE = "${testPkgs.dhallPackages.prelude}/package.dhall";
DHALL_GENODE = "${testPkgs.dhallPackages.genode}/package.dhall";
} ''
export XDG_CACHE_HOME=$NIX_BUILD_TOP
dhall text < $source > $out
'';
renderDhallInit = path: args:
hostPkgs.runCommand "init.xml" {
preferLocalBuild = true;
buildInputs = [ hostPkgs.dhall ];
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 (Prelude.Init::{ children = toMap (env:initConfig env:initArgs) })' \
> $out
'';
};
lib = hostPkgs.lib // self.lib;
linux = tests (import ./driver-linux.nix {
inherit testPkgs hostPkgs lib depot;

10
tests/driver-nova.nix

@ -36,11 +36,6 @@ let
'';
};
mkIso = import ./nova-iso.nix {
inherit hostPkgs testPkgs;
coreNovaObj = "${testPkgs.genode-base-nova}/lib/core-nova.o";
};
mkTest = { name ? "unamed", testScript, testConfig, bootModules, qemuMem ? 32
, ... }@t:
let
@ -53,7 +48,10 @@ let
timer = "${genode-base-nova}/bin/nova_timer_drv";
} // bootModules);
iso = mkIso bootModules';
iso = lib.x86_64-genode.buildNovaIso {
inherit name;
rom = bootModules';
};
baseSetup = ''
##

Loading…
Cancel
Save