2
0
Fork 0

Add linux-boot and render-init apps

This commit is contained in:
Ehmry - 2020-01-19 16:02:39 +01:00
parent 40df18a963
commit 70cafac9d7
7 changed files with 120 additions and 30 deletions

View File

@ -1,8 +1,16 @@
# SPDX-License-Identifier: CC0-1.0 # SPDX-License-Identifier: CC0-1.0
{ nixpkgs, packages, dhallApps }: { nixpkgs, dhallApps, packages }:
rec { rec {
linux-boot =
let drv = import ./linux-boot { inherit nixpkgs dhallApps packages; };
in {
type = "app";
program = "${drv}/bin/linux-boot";
};
nova-image = let nova-image = let
drv = import ./nova-image { drv = import ./nova-image {
stdenv = packages.stdenv; stdenv = packages.stdenv;
@ -11,16 +19,29 @@ rec {
in { in {
type = "app"; type = "app";
program = "${drv}/bin/nova-image"; program = "${drv}/bin/nova-image";
function = attrs: bootDesc:
nixpkgs.runCommand "nova-iso" (attrs // { inherit bootDesc; })
"${drv}/bin/nova-image $out $bootDesc";
}; };
nova-iso = let nova-iso = let
drv = import ./nova-iso { drv = import ./nova-iso {
stdenv = packages.stdenv; stdenv = packages.stdenv;
inherit nixpkgs dhallApps packages nova-image; inherit nixpkgs packages nova-image;
}; };
in { in {
type = "app"; type = "app";
program = "${drv}/bin/nova-iso"; program = "${drv}/bin/nova-iso";
function = attrs: bootDesc:
nixpkgs.runCommand "nova.iso" attrs
''${drv}/bin/nova-iso $out "${bootDesc}"'';
}; };
render-init =
let drv = import ./render-init { inherit nixpkgs dhallApps packages; };
in {
type = "app";
program = "${drv}/bin/render-init";
};
} }

View File

@ -0,0 +1,18 @@
# SPDX-License-Identifier: CC0-1.0
{ nixpkgs, dhallApps, packages }:
nixpkgs.writeScriptBin "linux-boot" (with nixpkgs.buildPackages; ''
#!${runtimeShell}
set -eu
if [ -z "$@" ]; then
echo "Error: a boot description 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}
export BASE_LINUX_MANIFEST=''${BASE_LINUX_MANIFEST:-${packages.genode.base-linux.manifest}}
export OS_MANIFEST=''${OS_MANIFEST:-${packages.genode.os.manifest}}
${dhallApps.dhall.program} text <<< "${./script.dhall} ($@)" > boot.sh
source boot.sh
'')

View File

@ -0,0 +1,30 @@
-- SPDX-License-Identifier: CC0-1.0
let Genode = env:DHALL_GENODE
let Prelude = Genode.Prelude
let Args =
{ config : Genode.Init.Type, rom : Genode.Prelude.Map.Type Text Text }
: Type
in λ(args : Args)
→ let addLink =
λ(e : Prelude.Map.Entry Text Text)
→ λ(script : Text)
→ script ++ "ln -s ${Text/show e.mapValue} ${Text/show e.mapKey}\n"
let links =
Prelude.List.fold
(Prelude.Map.Entry Text Text)
args.rom
Text
addLink
""
in ''
#!/bin/sh
${links}
echo ${Text/show (Genode.Init.render args.config)} > config
exec ./core-linux
''

View File

@ -10,19 +10,27 @@ in nixpkgs.writeScriptBin "nova-image" (with nixpkgs.buildPackages;
#!${runtimeShell} #!${runtimeShell}
set -eu set -eu
out="$1"
shift
if [ -e "$out" ]; then
echo "refusing to overwrite $out as output" > /dev/stderr
exit 1
fi
CC="${cc}/bin/${cc.targetPrefix}cc" CC="${cc}/bin/${cc.targetPrefix}cc"
LD="${buildPackages.binutils}/bin/${buildPackages.binutils.targetPrefix}ld" 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" CORE_NOVA="${base-nova}/lib/core-nova.o"
TMPDIR="$(${coreutils}/bin/mktemp -d)"
trap "rm -rf $TMPDIR" err exit
export DHALL_PRELUDE=${packages.dhallPrelude}/package.dhall export DHALL_PRELUDE=${packages.dhallPrelude}/package.dhall
export DHALL_GENODE=${packages.dhallGenode}/package.dhall export DHALL_GENODE=${packages.dhallGenode}/package.dhall
${dhallApps.dhall.program} text <<< "(${ ${dhallApps.dhall.program} text <<< "${
../nova-modules.as.dhall ./nova-modules.as.dhall
}) ($@)" > "$TMPDIR/modules.as" } ($@)" > "$TMPDIR/modules.as"
# compile the boot modules into one object file # compile the boot modules into one object file
$CC -c -x assembler -o "$TMPDIR/boot_modules.o" "$TMPDIR/modules.as" $CC -c -x assembler -o "$TMPDIR/boot_modules.o" "$TMPDIR/modules.as"
@ -34,5 +42,5 @@ in nixpkgs.writeScriptBin "nova-image" (with nixpkgs.buildPackages;
-z max-page-size=0x1000 \ -z max-page-size=0x1000 \
-Ttext=0x100000 -gc-sections \ -Ttext=0x100000 -gc-sections \
"$CORE_NOVA" "$TMPDIR/boot_modules.o" \ "$CORE_NOVA" "$TMPDIR/boot_modules.o" \
-o "image.elf" -o "$out"
'') '')

View File

@ -1,6 +1,6 @@
# SPDX-License-Identifier: CC0-1.0 # SPDX-License-Identifier: CC0-1.0
{ stdenv, nixpkgs, dhallApps, packages, nova-image }: { stdenv, nixpkgs, packages, nova-image }:
nixpkgs.writeScriptBin "nova-iso" (with nixpkgs.buildPackages; nixpkgs.writeScriptBin "nova-iso" (with nixpkgs.buildPackages;
let inherit (stdenv) cc; let inherit (stdenv) cc;
@ -9,20 +9,25 @@ nixpkgs.writeScriptBin "nova-iso" (with nixpkgs.buildPackages;
#!${runtimeShell} #!${runtimeShell}
set -eu set -eu
CC="${cc}/bin/${cc.targetPrefix}cc" out="$1"
LD="${buildPackages.binutils}/bin/${buildPackages.binutils.targetPrefix}ld" shift
if [ -e "$out" ]; then
echo "refusing to overwrite $out as output" > /dev/stderr
exit 1
fi
SYSLINUX="${syslinux}/share/syslinux" SYSLINUX="${syslinux}/share/syslinux"
TMPDIR="$(${coreutils}/bin/mktemp -p /tmp -d nova-iso.XXXX)" TMPDIR="$(${coreutils}/bin/mktemp -d)"
mkdir -p "$TMPDIR/boot/syslinux"
trap "rm -rf $TMPDIR" err exit trap "rm -rf $TMPDIR" err exit
${nova-image.program} $@ mkdir -p "$TMPDIR/boot/syslinux"
mv image.elf "$TMPDIR/boot" ${nova-image.program} "$TMPDIR/boot/image.elf" $@
pushd "$TMPDIR" pushd "$TMPDIR"
# build ISO image # build ISO layout
cp ${packages.NOVA}/hypervisor* boot/hypervisor cp ${packages.NOVA}/hypervisor* boot/hypervisor
cp ${./isolinux.cfg} boot/syslinux/isolinux.cfg cp ${./isolinux.cfg} boot/syslinux/isolinux.cfg
cp \ cp \
@ -33,22 +38,13 @@ nixpkgs.writeScriptBin "nova-iso" (with nixpkgs.buildPackages;
boot/syslinux boot/syslinux
chmod +w boot/syslinux/isolinux.bin chmod +w boot/syslinux/isolinux.bin
ISO_FILE="''${DIRSTACK[1]}/nova.iso" # create ISO image
${cdrkit}/bin/mkisofs -o "$out" \
${cdrkit}/bin/mkisofs -o "$ISO_FILE" \
-b syslinux/isolinux.bin -c syslinux/boot.cat \ -b syslinux/isolinux.bin -c syslinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \ -no-emul-boot -boot-load-size 4 -boot-info-table \
-iso-level 2 \ -iso-level 2 \
boot boot
popd ${syslinux}/bin/isohybrid "$out"
echo ISO is at $out
# build test script
QEMU_SCRIPT=boot-qemu.sh
cat > "$QEMU_SCRIPT" << EOF
#!/bin/sh
qemu-system-x86_64 -cdrom nova.iso -machine q35 -serial mon:stdio \$@
EOF
chmod +x "$QEMU_SCRIPT"
'') '')

View File

@ -0,0 +1,17 @@
# SPDX-License-Identifier: CC0-1.0
{ nixpkgs, dhallApps, packages }:
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 -
'')