From b5941e800b8f2575eadd2024038bde4c3a9c09f9 Mon Sep 17 00:00:00 2001 From: Diogo Costa Date: Sat, 25 May 2024 17:01:42 +0100 Subject: [PATCH 01/12] feat(atf.nix): add support to build either GICv2 or GICv3 QEMU driver Signed-off-by: Diogo Costa --- pkgs/firmware/atf/atf.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/firmware/atf/atf.nix b/pkgs/firmware/atf/atf.nix index 8620b61..4933883 100644 --- a/pkgs/firmware/atf/atf.nix +++ b/pkgs/firmware/atf/atf.nix @@ -7,6 +7,7 @@ , u-boot , openssl , platform +, gic-version ? "QEMU_GICV3" }: stdenv.mkDerivation rec { @@ -25,7 +26,7 @@ stdenv.mkDerivation rec { buildPhase = '' export CROSS_COMPILE=aarch64-none-elf- make PLAT=qemu bl1 fip BL33=${u-boot}/bin/u-boot.bin\ - QEMU_USE_GIC_DRIVER=QEMU_GICV3 + QEMU_USE_GIC_DRIVER=${gic-version} ''; installPhase = '' From 749800410d2fc87bf8804b7feb9e2a65222ca4bc Mon Sep 17 00:00:00 2001 From: Diogo Costa Date: Sat, 25 May 2024 17:24:01 +0100 Subject: [PATCH 02/12] feat(qemu-aarch64.nix): add support to build GICv2 or GICv3 platform Signed-off-by: Diogo Costa --- pkgs/firmware/qemu-aarch64-virt.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/firmware/qemu-aarch64-virt.nix b/pkgs/firmware/qemu-aarch64-virt.nix index da362a2..fa09db7 100644 --- a/pkgs/firmware/qemu-aarch64-virt.nix +++ b/pkgs/firmware/qemu-aarch64-virt.nix @@ -5,6 +5,7 @@ , fetchFromGitHub , toolchain , platform +, IRQC ? "QEMU_GICV3" }: let u-boot = pkgs.callPackage ./u-boot/u-boot.nix @@ -16,6 +17,7 @@ let inherit toolchain; inherit u-boot; inherit platform; + gic-version = IRQC; }; in stdenv.mkDerivation rec { From 09581e7a1cdf995142c6dc021afab98cdf07ff66 Mon Sep 17 00:00:00 2001 From: Diogo Costa Date: Mon, 27 May 2024 17:26:26 +0100 Subject: [PATCH 03/12] update(bao): update bao version and recipe naming Signed-off-by: Diogo Costa --- pkgs/bao/bao.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkgs/bao/bao.nix b/pkgs/bao/bao.nix index 1bf901d..5207d27 100644 --- a/pkgs/bao/bao.nix +++ b/pkgs/bao/bao.nix @@ -11,20 +11,21 @@ , bao_cfg , setup-cfg , guests +, irq_controller }: stdenv.mkDerivation rec { # Derivation to build bao to run the bao test framework (as a guest) # MUT: bao-hypervisor - pname = "bao-local"; + pname = "bao"; version = "1.0.0"; srcs = if bao_srcs_path == " " || bao_srcs_path == null then fetchFromGitHub { owner = "bao-project"; repo = "bao-hypervisor"; - rev = "0575782359132465128491ab2fa44c16e76b57f8"; # branch: demo - sha256 = "sha256-pCsVpSOuCCQ86HbLbyGpi6nHi5dxa7hbQIuoemE/fSA="; + rev = "692fab8ccfcdb9cffb52f8793e798a0220e7d550"; + sha256 = "sha256-LOrTZvAAA8ABnw/R+kqKBq8X6mXLTVsz/XfAJTQP2NA="; } else bao_srcs_path; From 1e44732defca548fff30ee29782454b87c5bd075 Mon Sep 17 00:00:00 2001 From: Diogo Costa Date: Mon, 27 May 2024 17:27:07 +0100 Subject: [PATCH 04/12] feat(irq_controller): add support to select interrupt controller Signed-off-by: Diogo Costa --- pkgs/bao/bao.nix | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pkgs/bao/bao.nix b/pkgs/bao/bao.nix index 5207d27..6bcfd56 100644 --- a/pkgs/bao/bao.nix +++ b/pkgs/bao/bao.nix @@ -56,12 +56,22 @@ stdenv.mkDerivation rec { export ARCH=${setup-cfg.arch} export CROSS_COMPILE=${setup-cfg.toolchain_name}- - # Build Bao - make PLATFORM=${setup-cfg.platform_name} \ - CONFIG_REPO=$out/configs\ - CONFIG=$bao_build_cfg\ - CPPFLAGS=-DBAO_WRKDIR_IMGS=$out/guests + if [ "$ARCH" = "aarch64" ]; then + make PLATFORM=${setup-cfg.platform_name} \ + CONFIG_REPO=$out/configs \ + CONFIG=$bao_build_cfg \ + CPPFLAGS=-DBAO_WRKDIR_IMGS=$out/guests \ + GIC_VERSION=${irq_controller} + + elif [ "$ARCH" = "riscv64" ]; then + IFS=' ' read -r IRQC_IRQC IRQC_IPIC <<< "${irq_controller}" + make PLATFORM=${setup-cfg.platform_name} \ + CONFIG_REPO=$out/configs \ + CONFIG=$bao_build_cfg \ + CPPFLAGS=-DBAO_WRKDIR_IMGS=$out/guests \ + IRQC=$IRQC_IRQC IPIC=IPIC_SBI + fi ''; installPhase = '' From a520f91f329bc110b0c3053168a808c6c0b207de Mon Sep 17 00:00:00 2001 From: Diogo Costa Date: Mon, 27 May 2024 17:27:43 +0100 Subject: [PATCH 05/12] fix(atf): include support to build different GIC versions Signed-off-by: Diogo Costa --- pkgs/firmware/atf/atf.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/firmware/atf/atf.nix b/pkgs/firmware/atf/atf.nix index 4933883..917b178 100644 --- a/pkgs/firmware/atf/atf.nix +++ b/pkgs/firmware/atf/atf.nix @@ -26,7 +26,7 @@ stdenv.mkDerivation rec { buildPhase = '' export CROSS_COMPILE=aarch64-none-elf- make PLAT=qemu bl1 fip BL33=${u-boot}/bin/u-boot.bin\ - QEMU_USE_GIC_DRIVER=${gic-version} + QEMU_USE_GIC_DRIVER=QEMU_${gic-version} ''; installPhase = '' From 8f5aa3d48fbfda56e37c761652e9094aff98aea5 Mon Sep 17 00:00:00 2001 From: Diogo Costa Date: Fri, 31 May 2024 12:10:26 +0100 Subject: [PATCH 06/12] feat(baremetal): add support for building with different GIC versions Signed-off-by: Diogo Costa --- pkgs/guest/baremetal.nix | 8 +++++++- pkgs/guest/tf/baremetal.nix | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pkgs/guest/baremetal.nix b/pkgs/guest/baremetal.nix index 077476f..ffe464b 100644 --- a/pkgs/guest/baremetal.nix +++ b/pkgs/guest/baremetal.nix @@ -10,6 +10,7 @@ , setup-cfg , guest_name ? "baremetal" , baremetal_srcs_path ? " " +, irq_controller ? " " }: stdenv.mkDerivation rec { @@ -40,7 +41,12 @@ stdenv.mkDerivation rec { buildPhase = '' export ARCH=${setup-cfg.arch} export CROSS_COMPILE=${setup-cfg.toolchain_name}- - make -C $out PLATFORM=${setup-cfg.platform_name} + if [ ARCH == "aarch64" ]; then + make -C $out PLATFORM=${setup-cfg.platform_name} \ + GIC_VERSION=${irq_controller} + else + make -C $out PLATFORM=${setup-cfg.platform_name} + fi ''; installPhase = '' diff --git a/pkgs/guest/tf/baremetal.nix b/pkgs/guest/tf/baremetal.nix index d6585b5..8c2cfe9 100644 --- a/pkgs/guest/tf/baremetal.nix +++ b/pkgs/guest/tf/baremetal.nix @@ -14,6 +14,7 @@ , list_tests ? " " , list_suites ? " " , log_level ? "2" +, irq_controller ? " " }: stdenv.mkDerivation rec { @@ -62,7 +63,16 @@ stdenv.mkDerivation rec { export CROSS_COMPILE=${setup-cfg.toolchain_name}- export TESTF_TESTS_DIR=$out/tests/src export TESTF_REPO_DIR=$out/tests/bao-tests - make -C $out PLATFORM=${setup-cfg.platform_name} BAO_TEST=1 SUITES=${list_suites} TESTS=${list_tests} TESTF_LOG_LEVEL=${log_level} + if [ ARCH == "aarch64" ]; then + make -C $out PLATFORM=${setup-cfg.platform_name} \ + BAO_TEST=1 SUITES=${list_suites} TESTS=${list_tests} \ + TESTF_LOG_LEVEL=${log_level} \ + GIC_VERSION=${irq_controller} + else + make -C $out PLATFORM=${setup-cfg.platform_name} \ + BAO_TEST=1 SUITES=${list_suites} TESTS=${list_tests} \ + TESTF_LOG_LEVEL=${log_level} + fi ''; installPhase = '' From f0ad5ec4ca8951731550319524108d799e6d7f9a Mon Sep 17 00:00:00 2001 From: Miguel Silva Date: Fri, 31 May 2024 14:27:45 +0100 Subject: [PATCH 07/12] feat(setup-cfg): Add make flags for IRQ controller to the cfg This commit adds a irq_flags variable as an output of the setup-cfg. These flags are filled according to the platform arch. Signed-off-by: Miguel Silva --- pkgs/setup-cfg/setup-cfg.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/setup-cfg/setup-cfg.nix b/pkgs/setup-cfg/setup-cfg.nix index e3a72bb..0760d25 100644 --- a/pkgs/setup-cfg/setup-cfg.nix +++ b/pkgs/setup-cfg/setup-cfg.nix @@ -7,6 +7,9 @@ , bao-tests ? " " , tests_srcs ? " " , baremetal_patch ? " " + , GIC_VERSION ? " " + , IRQC ? " " + , IPIC ? " " }: let platforms-arch = { @@ -43,4 +46,8 @@ in { bao-tests = bao-tests; tests_srcs = tests_srcs; baremetal_patch = baremetal_patch; + + irq_flags = if platforms-arch.${platform} == "riscv64" then + "IRQC=${IRQC} IPIC=${IPIC}" + else "GIC_VERSION=${GIC_VERSION}"; } \ No newline at end of file From 9084453e27cc1c0de88c7c76c86fdaad68950a0a Mon Sep 17 00:00:00 2001 From: Diogo Costa Date: Sat, 1 Jun 2024 10:32:59 +0100 Subject: [PATCH 08/12] fix(bao): update bao recipe to use irq flags Signed-off-by: Diogo Costa --- pkgs/bao/bao.nix | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/pkgs/bao/bao.nix b/pkgs/bao/bao.nix index 6bcfd56..a95e1d7 100644 --- a/pkgs/bao/bao.nix +++ b/pkgs/bao/bao.nix @@ -11,7 +11,6 @@ , bao_cfg , setup-cfg , guests -, irq_controller }: stdenv.mkDerivation rec { @@ -55,23 +54,12 @@ stdenv.mkDerivation rec { cd $out/srcs export ARCH=${setup-cfg.arch} export CROSS_COMPILE=${setup-cfg.toolchain_name}- - # Build Bao - if [ "$ARCH" = "aarch64" ]; then - make PLATFORM=${setup-cfg.platform_name} \ - CONFIG_REPO=$out/configs \ - CONFIG=$bao_build_cfg \ - CPPFLAGS=-DBAO_WRKDIR_IMGS=$out/guests \ - GIC_VERSION=${irq_controller} - - elif [ "$ARCH" = "riscv64" ]; then - IFS=' ' read -r IRQC_IRQC IRQC_IPIC <<< "${irq_controller}" - make PLATFORM=${setup-cfg.platform_name} \ + make PLATFORM=${setup-cfg.platform_name} \ CONFIG_REPO=$out/configs \ CONFIG=$bao_build_cfg \ CPPFLAGS=-DBAO_WRKDIR_IMGS=$out/guests \ - IRQC=$IRQC_IRQC IPIC=IPIC_SBI - fi + ${setup-cfg.irq_flags} ''; installPhase = '' From 8702eb24f548e432a2fa16155c2d9a4fe4b7f6ee Mon Sep 17 00:00:00 2001 From: Diogo Costa Date: Sat, 1 Jun 2024 10:34:01 +0100 Subject: [PATCH 09/12] fix(qemu-aarch64): update qemu recipe to use irq flags Signed-off-by: Diogo Costa --- pkgs/firmware/qemu-aarch64-virt.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/firmware/qemu-aarch64-virt.nix b/pkgs/firmware/qemu-aarch64-virt.nix index fa09db7..6c821e3 100644 --- a/pkgs/firmware/qemu-aarch64-virt.nix +++ b/pkgs/firmware/qemu-aarch64-virt.nix @@ -5,7 +5,7 @@ , fetchFromGitHub , toolchain , platform -, IRQC ? "QEMU_GICV3" +, gic-version ? "QEMU_GICV3" }: let u-boot = pkgs.callPackage ./u-boot/u-boot.nix @@ -17,7 +17,7 @@ let inherit toolchain; inherit u-boot; inherit platform; - gic-version = IRQC; + inherit gic-version; }; in stdenv.mkDerivation rec { From 7eaed7adb1ee6c2c5fd9310253a188d0f714e8de Mon Sep 17 00:00:00 2001 From: Diogo Costa Date: Sat, 1 Jun 2024 10:34:39 +0100 Subject: [PATCH 10/12] fix(baremetal): update baremetal recipe to use irq flags Signed-off-by: Diogo Costa --- pkgs/guest/baremetal.nix | 3 +-- pkgs/guest/tf/baremetal.nix | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pkgs/guest/baremetal.nix b/pkgs/guest/baremetal.nix index ffe464b..fb48ea8 100644 --- a/pkgs/guest/baremetal.nix +++ b/pkgs/guest/baremetal.nix @@ -10,7 +10,6 @@ , setup-cfg , guest_name ? "baremetal" , baremetal_srcs_path ? " " -, irq_controller ? " " }: stdenv.mkDerivation rec { @@ -43,7 +42,7 @@ stdenv.mkDerivation rec { export CROSS_COMPILE=${setup-cfg.toolchain_name}- if [ ARCH == "aarch64" ]; then make -C $out PLATFORM=${setup-cfg.platform_name} \ - GIC_VERSION=${irq_controller} + ${setup-cfg.irq_flags} else make -C $out PLATFORM=${setup-cfg.platform_name} fi diff --git a/pkgs/guest/tf/baremetal.nix b/pkgs/guest/tf/baremetal.nix index 8c2cfe9..4acd934 100644 --- a/pkgs/guest/tf/baremetal.nix +++ b/pkgs/guest/tf/baremetal.nix @@ -14,7 +14,6 @@ , list_tests ? " " , list_suites ? " " , log_level ? "2" -, irq_controller ? " " }: stdenv.mkDerivation rec { @@ -67,7 +66,7 @@ stdenv.mkDerivation rec { make -C $out PLATFORM=${setup-cfg.platform_name} \ BAO_TEST=1 SUITES=${list_suites} TESTS=${list_tests} \ TESTF_LOG_LEVEL=${log_level} \ - GIC_VERSION=${irq_controller} + ${setup-cfg.irq_flags} else make -C $out PLATFORM=${setup-cfg.platform_name} \ BAO_TEST=1 SUITES=${list_suites} TESTS=${list_tests} \ From 33b3c752b3b7226bb6184698d29e5171a278fbab Mon Sep 17 00:00:00 2001 From: Diogo Costa Date: Tue, 4 Jun 2024 09:27:33 +0100 Subject: [PATCH 11/12] fix(aarch64_firmware): add setup-cfg as derivation input Signed-off-by: Diogo Costa --- pkgs/firmware/atf/atf.nix | 5 +++-- pkgs/firmware/qemu-aarch64-virt.nix | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkgs/firmware/atf/atf.nix b/pkgs/firmware/atf/atf.nix index 917b178..d3e7612 100644 --- a/pkgs/firmware/atf/atf.nix +++ b/pkgs/firmware/atf/atf.nix @@ -7,7 +7,7 @@ , u-boot , openssl , platform -, gic-version ? "QEMU_GICV3" +, setup-cfg }: stdenv.mkDerivation rec { @@ -25,8 +25,9 @@ stdenv.mkDerivation rec { buildPhase = '' export CROSS_COMPILE=aarch64-none-elf- + gic_version=$(echo "${setup-cfg.irq_flags}" | grep -oP '(?<=GIC_VERSION=)[^ ]+') make PLAT=qemu bl1 fip BL33=${u-boot}/bin/u-boot.bin\ - QEMU_USE_GIC_DRIVER=QEMU_${gic-version} + QEMU_USE_GIC_DRIVER=QEMU_$gic_version ''; installPhase = '' diff --git a/pkgs/firmware/qemu-aarch64-virt.nix b/pkgs/firmware/qemu-aarch64-virt.nix index 6c821e3..7501bd5 100644 --- a/pkgs/firmware/qemu-aarch64-virt.nix +++ b/pkgs/firmware/qemu-aarch64-virt.nix @@ -5,7 +5,7 @@ , fetchFromGitHub , toolchain , platform -, gic-version ? "QEMU_GICV3" +, setup-cfg }: let u-boot = pkgs.callPackage ./u-boot/u-boot.nix @@ -17,7 +17,7 @@ let inherit toolchain; inherit u-boot; inherit platform; - inherit gic-version; + inherit setup-cfg; }; in stdenv.mkDerivation rec { From 3839949df6d53fbf4b01458d1b7233eb9cf1c010 Mon Sep 17 00:00:00 2001 From: Diogo Costa Date: Tue, 4 Jun 2024 13:07:33 +0100 Subject: [PATCH 12/12] fix(riscv64_firmware): add setup-cfg as derivation input Signed-off-by: Diogo Costa --- pkgs/firmware/qemu-riscv64-virt.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/firmware/qemu-riscv64-virt.nix b/pkgs/firmware/qemu-riscv64-virt.nix index 1e88367..8d80512 100644 --- a/pkgs/firmware/qemu-riscv64-virt.nix +++ b/pkgs/firmware/qemu-riscv64-virt.nix @@ -5,6 +5,7 @@ , fetchFromGitHub , toolchain , platform +, setup-cfg }: let sbi = pkgs.callPackage ./openSBI/openSBI.nix {