Nix: Add nova-image app
This commit is contained in:
parent
18c0e21996
commit
292bd3f579
|
@ -0,0 +1,33 @@
|
||||||
|
{ stdenv, nixpkgs, dhallApps, NOVA, base-nova }:
|
||||||
|
|
||||||
|
nixpkgs.writeScriptBin "nova-image" (with nixpkgs.buildPackages;
|
||||||
|
let inherit (stdenv) cc;
|
||||||
|
|
||||||
|
in ''
|
||||||
|
#!${runtimeShell}
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
CC="${cc}/bin/${cc.targetPrefix}cc"
|
||||||
|
LD="${buildPackages.binutils}/bin/${buildPackages.binutils.targetPrefix}ld"
|
||||||
|
|
||||||
|
TMPDIR="$(${coreutils}/bin/mktemp -p /tmp -d nova-iso.XXXX)"
|
||||||
|
# trap "rm -rf $TMPDIR" err exit
|
||||||
|
|
||||||
|
CORE_NOVA="${base-nova}/lib/core-nova.o"
|
||||||
|
|
||||||
|
${dhallApps.dhall.program} text <<< "(${
|
||||||
|
./modules.as.dhall
|
||||||
|
}) ($@)" > "$TMPDIR/modules.as"
|
||||||
|
|
||||||
|
# compile the boot modules into one object file
|
||||||
|
$CC -c -x assembler -o "$TMPDIR/boot_modules.o" "$TMPDIR/modules.as"
|
||||||
|
|
||||||
|
# link final image
|
||||||
|
$LD -nostdlib \
|
||||||
|
-T${../../repos/base/src/ld/genode.ld} \
|
||||||
|
-T${../../repos/base-nova/src/core/core-bss.ld} \
|
||||||
|
-z max-page-size=0x1000 \
|
||||||
|
-Ttext=0x100000 -gc-sections \
|
||||||
|
"$CORE_NOVA" "$TMPDIR/boot_modules.o" \
|
||||||
|
-o "image.elf"
|
||||||
|
'')
|
|
@ -0,0 +1,119 @@
|
||||||
|
let Genode =
|
||||||
|
env:DHALL_GENODE
|
||||||
|
? https://git.sr.ht/~ehmry/dhall-genode/blob/v11.0.0/package.dhall sha256:4336da47b739fe6b9e117436404ca56af0cfec15805abb0baf6f5ba366c7e5ce
|
||||||
|
|
||||||
|
let Prelude = Genode.Prelude
|
||||||
|
|
||||||
|
let Configuration =
|
||||||
|
{ arch : < x86_32 | x86_64 >
|
||||||
|
, config : Genode.Init.Type
|
||||||
|
, rom : Prelude.Map.Type Text Text
|
||||||
|
}
|
||||||
|
: Type
|
||||||
|
|
||||||
|
in λ ( boot
|
||||||
|
: Configuration
|
||||||
|
)
|
||||||
|
→ let NaturalIndex =
|
||||||
|
{ index : Natural, value : Text }
|
||||||
|
|
||||||
|
let TextIndex = { index : Text, value : Text }
|
||||||
|
|
||||||
|
let moduleKeys =
|
||||||
|
let keys = Prelude.Map.keys Text Text boot.rom
|
||||||
|
|
||||||
|
in [ "config" ] # keys
|
||||||
|
|
||||||
|
let moduleValues =
|
||||||
|
let values = Prelude.Map.values Text Text boot.rom
|
||||||
|
|
||||||
|
let incbin =
|
||||||
|
Prelude.List.map
|
||||||
|
Text
|
||||||
|
Text
|
||||||
|
(λ(path : Text) → ".incbin ${Text/show path}")
|
||||||
|
values
|
||||||
|
|
||||||
|
in [ ".ascii ${Text/show (Genode.Init.render boot.config)}" ]
|
||||||
|
# incbin
|
||||||
|
|
||||||
|
let map =
|
||||||
|
λ(list : List Text)
|
||||||
|
→ λ(f : TextIndex → Text)
|
||||||
|
→ let indexedNatural = Prelude.List.indexed Text list
|
||||||
|
|
||||||
|
let indexed =
|
||||||
|
Prelude.List.map
|
||||||
|
NaturalIndex
|
||||||
|
TextIndex
|
||||||
|
( λ(x : NaturalIndex)
|
||||||
|
→ { index = Prelude.Natural.show (x.index + 1)
|
||||||
|
, value = x.value
|
||||||
|
}
|
||||||
|
)
|
||||||
|
indexedNatural
|
||||||
|
|
||||||
|
let texts = Prelude.List.map TextIndex Text f indexed
|
||||||
|
|
||||||
|
in Prelude.Text.concatSep "\n" texts
|
||||||
|
|
||||||
|
let mapNames = map moduleKeys
|
||||||
|
|
||||||
|
let mapValues = map moduleValues
|
||||||
|
|
||||||
|
let addressType = merge { x86_32 = ".long", x86_64 = ".quad" } boot.arch
|
||||||
|
|
||||||
|
in ''
|
||||||
|
.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
|
||||||
|
( λ ( m
|
||||||
|
: TextIndex
|
||||||
|
)
|
||||||
|
→ ''
|
||||||
|
${addressType} _boot_module_${m.index}_name
|
||||||
|
${addressType} _boot_module_${m.index}_begin
|
||||||
|
${addressType} _boot_module_${m.index}_end - _boot_module_${m.index}_begin
|
||||||
|
''
|
||||||
|
)
|
||||||
|
++ ''
|
||||||
|
.global _boot_modules_headers_end
|
||||||
|
_boot_modules_headers_end:
|
||||||
|
|
||||||
|
''
|
||||||
|
++ mapNames
|
||||||
|
( λ(m : TextIndex)
|
||||||
|
→ ''
|
||||||
|
.p2align DATA_ACCESS_ALIGNM_LOG2
|
||||||
|
_boot_module_${m.index}_name:
|
||||||
|
.string "${m.value}"
|
||||||
|
.byte 0
|
||||||
|
''
|
||||||
|
)
|
||||||
|
++ ''
|
||||||
|
.section .data.boot_modules_binaries
|
||||||
|
|
||||||
|
.global _boot_modules_binaries_begin
|
||||||
|
_boot_modules_binaries_begin:
|
||||||
|
|
||||||
|
''
|
||||||
|
++ mapValues
|
||||||
|
( λ(m : TextIndex)
|
||||||
|
→ ''
|
||||||
|
.p2align MIN_PAGE_SIZE_LOG2
|
||||||
|
_boot_module_${m.index}_begin:
|
||||||
|
${m.value}
|
||||||
|
_boot_module_${m.index}_end:
|
||||||
|
''
|
||||||
|
)
|
||||||
|
++ ''
|
||||||
|
.p2align MIN_PAGE_SIZE_LOG2
|
||||||
|
.global _boot_modules_binaries_end
|
||||||
|
_boot_modules_binaries_end:
|
||||||
|
''
|
10
default.nix
10
default.nix
|
@ -336,6 +336,12 @@ in rec {
|
||||||
|
|
||||||
inherit stdenvGcc stdenvLlvm tupConfigGcc tupConfigLlvm;
|
inherit stdenvGcc stdenvLlvm tupConfigGcc tupConfigLlvm;
|
||||||
|
|
||||||
|
nova-image = import ./apps/nova-image {
|
||||||
|
stdenv = stdenvLlvm;
|
||||||
|
inherit nixpkgs NOVA base-nova;
|
||||||
|
dhallApps = dhall-haskell.apps.${localSystem};
|
||||||
|
};
|
||||||
|
|
||||||
nova-iso = import ./apps/nova-iso {
|
nova-iso = import ./apps/nova-iso {
|
||||||
stdenv = stdenvLlvm;
|
stdenv = stdenvLlvm;
|
||||||
inherit nixpkgs NOVA base-nova;
|
inherit nixpkgs NOVA base-nova;
|
||||||
|
@ -348,6 +354,10 @@ in rec {
|
||||||
type = "app";
|
type = "app";
|
||||||
program = "${packages.base-linux}/bin/core-linux";
|
program = "${packages.base-linux}/bin/core-linux";
|
||||||
};
|
};
|
||||||
|
nova-image = {
|
||||||
|
type = "app";
|
||||||
|
program = "${packages.nova-image}/bin/nova-image";
|
||||||
|
};
|
||||||
nova-iso = {
|
nova-iso = {
|
||||||
type = "app";
|
type = "app";
|
||||||
program = "${packages.nova-iso}/bin/nova-iso";
|
program = "${packages.nova-iso}/bin/nova-iso";
|
||||||
|
|
Loading…
Reference in New Issue