commit d2a52f6d6bd0925d91340102f488cc001dcc5a6d
parent 3fcbb48a3c3597a43e42c39f57de350ecf368f49
Author: Nikolay Korotkiy <sikmir@gmail.com>
Date: Fri, 6 Aug 2021 18:55:54 +0300
embox: enable x86 build
Diffstat:
3 files changed, 68 insertions(+), 31 deletions(-)
diff --git a/pkgs/default.nix b/pkgs/default.nix
@@ -138,7 +138,11 @@ lib.makeScope newScope (
### EMBOX
- embox = callPackage ./embox { };
+ embox-aarch64 = callPackage ./embox { arch = "aarch64"; };
+ embox-arm = callPackage ./embox { arch = "arm"; };
+ embox-ppc = callPackage ./embox { arch = "ppc"; };
+ embox-riscv64 = callPackage ./embox { arch = "riscv64"; };
+ embox-x86 = callPackage ./embox { };
### GARMIN
diff --git a/pkgs/embox/default.nix b/pkgs/embox/default.nix
@@ -1,34 +1,27 @@
{ lib
-, stdenv
+, multiStdenv
, fetchFromGitHub
, fetchurl
-, writers
+, makeWrapper
+, pkgsCross
, cpio
, gcc-arm-embedded
, python
, qemu
, unzip
, which
-, template ? "arm/qemu"
+, arch ? "x86"
}:
-let
- cjson = fetchurl {
- url = "mirror://sourceforge/cjson/cJSONFiles.zip";
- hash = "sha256-DWI67XuLdgpv+u26Isvrgs6HAvn0yknTyPKdTLDTDac=";
- };
- runScript = writers.writeBash "run-embox" ''
- ${qemu}/bin/qemu-system-arm \
- -M integratorcp \
- -kernel @out@/share/embox/images/embox.img \
- -m 256 \
- -net nic,netdev=n0,model=smc91c111,macaddr=AA:BB:CC:DD:EE:02 \
- -netdev tap,script=@out@/share/embox/scripts/qemu_start,downscript=@out@/share/embox/scripts/qemu_stop,id=n0 \
- -nographic
- '';
+assert lib.assertOneOf "arch" arch [ "aarch64" "arm" "ppc" "riscv64" "x86" ];
+
+let
+ third-party = lib.mapAttrs
+ (name: spec: fetchurl spec)
+ (builtins.fromJSON (builtins.readFile ./third-party.json));
in
-stdenv.mkDerivation rec {
- pname = "embox";
+multiStdenv.mkDerivation rec {
+ pname = "embox-${arch}-qemu";
version = "0.5.3";
src = fetchFromGitHub {
@@ -40,31 +33,61 @@ stdenv.mkDerivation rec {
patches = [ ./0001-fix-build.patch ];
+ postPatch = ''
+ substituteInPlace templates/aarch64/qemu/build.conf \
+ --replace "aarch64-elf" "aarch64-none-elf"
+ substituteInPlace templates/ppc/qemu/build.conf \
+ --replace "powerpc-elf" "powerpc-none-eabi"
+ substituteInPlace templates/riscv64/qemu/build.conf \
+ --replace "riscv64-unknown-elf" "riscv64-none-elf"
+ '';
+
nativeBuildInputs = [
cpio
- gcc-arm-embedded
python
unzip
which
- ];
+ makeWrapper
+ ] ++ lib.optional (arch != "x86" && arch != "arm") pkgsCross."${arch}-embedded".stdenv.cc
+ ++ lib.optional (arch == "arm") gcc-arm-embedded;
- postPatch = ''
+ configurePhase = "make confload-${arch}/qemu";
+
+ preBuild = ''
patchShebangs ./mk
mkdir -p ./download
- ln -s ${cjson} ./download/cjson.zip
+ ln -s ${third-party.cjson} ./download/cjson.zip
+ ln -s ${third-party.acpica-unix} ./download/acpica-unix-20210331.tar.gz
'';
- configurePhase = "make confload-${template}";
-
- installPhase = ''
+ installPhase = let
+ platform_args = {
+ aarch64 = "-M virt -cpu cortex-a53 -m 1024";
+ arm = "-M integratorcp -m 256";
+ ppc = "-M virtex-ml507 -m 64";
+ riscv64 = "-M virt -m 512";
+ x86 = "-enable-kvm -device pci-ohci,id=ohci -m 256";
+ }.${arch};
+ net_args = {
+ aarch64 = "model=e1000";
+ arm = "model=smc91c111";
+ x86 = "model=virtio";
+ };
+ withNetwork = lib.hasAttr arch net_args;
+ in ''
mkdir -p $out/bin
- substitute ${runScript} $out/bin/run-embox --subst-var out
- chmod +x $out/bin/run-embox
+
+ makeWrapper ${qemu}/bin/qemu-system-${if arch == "x86" then "i386" else arch} $out/bin/embox \
+ --add-flags "${platform_args}" \
+ --add-flags "-kernel $out/share/embox/images/embox.img" \
+ --add-flags "${lib.optionalString withNetwork "-net nic,netdev=n0,${net_args.${arch}},macaddr=AA:BB:CC:DD:EE:02"}" \
+ --add-flags "${lib.optionalString withNetwork "-netdev tap,script=$out/share/embox/scripts/start_script,downscript=$out/share/embox/scripts/stop_script,id=n0"}" \
+ --add-flags "-nographic"
install -Dm644 build/base/bin/embox $out/share/embox/images/embox.img
install -Dm644 conf/*.conf* -t $out/share/embox/conf
- install -Dm755 scripts/qemu/start_script $out/share/embox/scripts/qemu_start
- install -Dm755 scripts/qemu/stop_script $out/share/embox/scripts/qemu_stop
+ '' + lib.optionalString withNetwork ''
+ install -Dm755 scripts/qemu/{start,stop}_script -t $out/share/embox/scripts
'';
meta = with lib; {
diff --git a/pkgs/embox/third-party.json b/pkgs/embox/third-party.json
@@ -0,0 +1,10 @@
+{
+ "acpica-unix": {
+ "url": "http://acpica.org/sites/acpica/files/acpica-unix-20210331.tar.gz",
+ "hash": "sha256-tJI3osPfWLVzEGEuw6br7mnhpSW17+7HFS+vMqA7cGg="
+ },
+ "cjson": {
+ "url": "mirror://sourceforge/cjson/cJSONFiles.zip",
+ "hash": "sha256-DWI67XuLdgpv+u26Isvrgs6HAvn0yknTyPKdTLDTDac="
+ }
+}