2
0
Fork 0
genodepkgs/apps/hw-image/default.nix

47 lines
1.5 KiB
Nix

# SPDX-License-Identifier: CC0-1.0
{ stdenv, nixpkgs, dhallApps, packages }:
let inherit (packages) base-hw-pc;
in nixpkgs.writeScriptBin "hw-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 -d)"
trap "rm -rf $TMPDIR" err exit
export DHALL_PRELUDE=${packages.dhallPrelude}/package.dhall
export DHALL_GENODE=${packages.dhallGenode}/package.dhall
build_core() {
local lib="$1"
local modules="$2"
local link_address="$3"
${dhallApps.dhall.program} text <<< \
"(${../modules.as.dhall}).to64bitImage ($modules)" \
> "$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 \
--strip-all \
-T${base-hw-pc.src}/repos/base/src/ld/genode.ld \
-z max-page-size=0x1000 \
-Ttext=$link_address -gc-sections \
"$lib" "$TMPDIR/boot_modules.o"
cat a.out
}
set -v
${dhallApps.dhall.program} <<< "${../render-rom.dhall} ($@)" > "$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
'')