From 34b7229b9588772e6d92cc875ba4e5fefa6e4133 Mon Sep 17 00:00:00 2001 From: Govind Singh Date: Tue, 21 Oct 2025 09:28:17 +0400 Subject: [PATCH 1/3] Add support for i.MX93-EVK platform The i.MX93 EVK provides a platform for comprehensive evaluation of the i.MX93 application processors. This change adds support in NixOS hardware to provide a template for customized i.MX93-based platforms. Signed-off-by: Govind Singh --- flake.nix | 1 + nxp/README.md | 7 +- nxp/imx93-evk/bsp/imx93-atf.nix | 50 ++++++++++++++ nxp/imx93-evk/bsp/imx93-boot.nix | 85 ++++++++++++++++++++++++ nxp/imx93-evk/bsp/imx93-firmware.nix | 47 +++++++++++++ nxp/imx93-evk/bsp/imx93-linux.nix | 62 +++++++++++++++++ nxp/imx93-evk/bsp/imx93-optee-os.nix | 75 +++++++++++++++++++++ nxp/imx93-evk/bsp/imx93-uboot.nix | 99 ++++++++++++++++++++++++++++ nxp/imx93-evk/default.nix | 19 ++++++ nxp/imx93-evk/modules.nix | 17 +++++ nxp/imx93-evk/overlay.nix | 3 + 11 files changed, 462 insertions(+), 3 deletions(-) create mode 100644 nxp/imx93-evk/bsp/imx93-atf.nix create mode 100644 nxp/imx93-evk/bsp/imx93-boot.nix create mode 100644 nxp/imx93-evk/bsp/imx93-firmware.nix create mode 100644 nxp/imx93-evk/bsp/imx93-linux.nix create mode 100644 nxp/imx93-evk/bsp/imx93-optee-os.nix create mode 100644 nxp/imx93-evk/bsp/imx93-uboot.nix create mode 100644 nxp/imx93-evk/default.nix create mode 100644 nxp/imx93-evk/modules.nix create mode 100644 nxp/imx93-evk/overlay.nix diff --git a/flake.nix b/flake.nix index 32fb1e0..bc3a709 100644 --- a/flake.nix +++ b/flake.nix @@ -331,6 +331,7 @@ nxp-imx8mp-evk = import ./nxp/imx8mp-evk; nxp-imx8mq-evk = import ./nxp/imx8mq-evk; nxp-imx8qm-mek = import ./nxp/imx8qm-mek; + nxp-imx93-evk = import ./nxp/imx93-evk; hardkernel-odroid-hc4 = import ./hardkernel/odroid-hc4; hardkernel-odroid-h3 = import ./hardkernel/odroid-h3; hardkernel-odroid-h4 = import ./hardkernel/odroid-h4; diff --git a/nxp/README.md b/nxp/README.md index f8ccefa..cf1f5d2 100644 --- a/nxp/README.md +++ b/nxp/README.md @@ -21,17 +21,18 @@ Code snippet example that enables imx8qm configuration: } ``` -### 2.2 For imx8mq-evk/imx8mp-evk +### 2.2 For imx8mq-evk/imx8mp-evk/imx93-evk This NXP overlay is used for generating sdimage. -Current configuration uses uboot as a bootloader. It provides an options to use optee-os which is currently disabled. It can be enabled using `enable-tee` boolean argument avalable in `imx8m-boot.nix`, which is `false` by default. +Current configuration uses uboot as a bootloader. It provides an options to use optee-os which is currently disabled. It can be enabled using `enable-tee` boolean argument avalable in `imx8m-boot.nix`, which is `false` by default in imx8m platform. -Code snippet example that enables 'imx8mp-evk/emx8mq-evk' configuration: +Code snippet example that enables 'imx8mp-evk/imx8mq-evk/imx93-evk' configuration: ``` { nixos-hardware, }: { system = "aarch64-linux"; modules = [ nixos-hardware.nixosModules.imx8mp-evk #For imx8mp-evk + #nixos-hardware.nixosModules.imx93-evk #For imx93-evk #nixos-hardware.nixosModules.imx8mq-evk #For imx8mq-evk ]; } diff --git a/nxp/imx93-evk/bsp/imx93-atf.nix b/nxp/imx93-evk/bsp/imx93-atf.nix new file mode 100644 index 0000000..4180dde --- /dev/null +++ b/nxp/imx93-evk/bsp/imx93-atf.nix @@ -0,0 +1,50 @@ +{ lib, fetchgit, stdenv, buildPackages, pkgsCross, openssl }: + +let + target-board = "imx93"; +in stdenv.mkDerivation rec { + pname = "imx93-atf"; + version = "2.10.0"; + platform = target-board; + enableParallelBuilding = true; + + src = fetchgit { + url = "https://github.com/nxp-imx/imx-atf.git"; + rev = "28affcae957cb8194917b5246276630f9e6343e1"; + sha256 = "sha256-a8F+Lf8pwML+tCwawS0N/mrSXWPmFhlUeOg0MCRK3VE="; + }; + + # Compiler dependencies + depsBuildBuild = [ buildPackages.stdenv.cc ]; + nativeBuildInputs = [ pkgsCross.aarch64-embedded.stdenv.cc ]; + + buildInputs = [ openssl ]; + + makeFlags = [ + "HOSTCC=$(CC_FOR_BUILD)" + "CROSS_COMPILE=${pkgsCross.aarch64-embedded.stdenv.cc.targetPrefix}" + "PLAT=${platform}" + "SPD=opteed" + "bl31" + "LDFLAGS=-no-warn-rwx-segments" + ]; + + installPhase = '' + runHook preInstall + mkdir -p $out + cp build/${target-board}/release/bl31.bin $out + runHook postInstall + ''; + + hardeningDisable = [ "all" ]; + dontStrip = true; + + meta = with lib; { + homepage = "https://github.com/nxp-imx/imx-atf"; + description = "Reference implementation of secure world software for ARMv8-A"; + license = [ licenses.bsd3 ]; + maintainers = with maintainers; [ govindsi ]; + platforms = [ "aarch64-linux" ]; + }; +} + diff --git a/nxp/imx93-evk/bsp/imx93-boot.nix b/nxp/imx93-evk/bsp/imx93-boot.nix new file mode 100644 index 0000000..abc023e --- /dev/null +++ b/nxp/imx93-evk/bsp/imx93-boot.nix @@ -0,0 +1,85 @@ +{ + pkgs, +}: +with pkgs; +let + fw-ver = "202406"; + + imx93-atf = pkgs.callPackage ./imx93-atf.nix { }; + imx93-firmware = pkgs.callPackage ./imx93-firmware.nix { }; + imx93-uboot = pkgs.callPackage ./imx93-uboot.nix { }; + imx93-optee-os = pkgs.callPackage ./imx93-optee-os.nix { }; + src = pkgs.fetchgit { + url = "https://github.com/nxp-imx/imx-mkimage.git"; + #tag: lf-6.12.3 + rev = "4622115cbc037f79039c4522faeced4aabea986b"; + sha256 = "sha256-2gz0GxlB3jwy8PC6+cP3+MpyUzqE1vDTw8nuxK6vo3g="; + }; + shortRev = builtins.substring 0 8 src.rev; +in +{ + imx93-boot = pkgs.stdenv.mkDerivation rec { + inherit src; + name = "imx93-mkimage"; + version = "lf-6.12.3"; + + postPatch = '' + substituteInPlace Makefile \ + --replace 'git rev-parse --short=8 HEAD' 'echo ${shortRev}' + substituteInPlace Makefile \ + --replace 'CC = gcc' 'CC = clang' + substituteInPlace iMX93/soc.mak \ + --replace 'xxd' "${pkgs.vim.xxd}/bin/xxd" + substituteInPlace scripts/fspi_fcb_gen.sh \ + --replace 'xxd' "${pkgs.vim.xxd}/bin/xxd" + substituteInPlace scripts/fspi_packer.sh \ + --replace 'xxd' "${pkgs.vim.xxd}/bin/xxd" + patchShebangs scripts + ''; + + nativeBuildInputs = [ + clang + git + dtc + ]; + + buildInputs = [ + git + glibc.static + zlib + zlib.static + ]; + + buildPhase = '' + runHook preBuild + + make bin + # mkimage is common across imx8 and imx9 + make SOC=iMX8M mkimage_imx8 + + if [ -f ${imx93-uboot}/u-boot.bin ]; then + install -m 0644 ${imx93-uboot}/u-boot.bin ./iMX93/u-boot.bin + else + cat ${imx93-uboot}/u-boot-nodtb.bin ${imx93-uboot}/imx93-11x11-evk.dtb > ./iMX93/u-boot.bin + fi + install -m 0644 ${imx93-uboot}/u-boot-spl.bin ./iMX93/u-boot-spl.bin + install -m 0644 ${imx93-uboot}/u-boot-nodtb.bin ./iMX93/u-boot-nodtb.bin + install -m 0644 ${imx93-uboot}/imx93-11x11-evk.dtb ./iMX93/imx93-11x11-evk.dtb + install -m 0644 ${imx93-optee-os}/tee.bin ./iMX93/tee.bin + install -m 0644 ${imx93-atf}/bl31.bin ./iMX93/bl31.bin + install -m 0644 ${imx93-firmware}/ddr/lpddr4* ./iMX93/ + install -m 0644 ${imx93-firmware}/ahab/mx93a1-ahab-container.img ./iMX93/ + + make SOC=iMX9 flash_singleboot + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/image + install -m 0644 ./iMX93/flash.bin $out/image + runHook postInstall + ''; + }; +} diff --git a/nxp/imx93-evk/bsp/imx93-firmware.nix b/nxp/imx93-evk/bsp/imx93-firmware.nix new file mode 100644 index 0000000..b48e8a3 --- /dev/null +++ b/nxp/imx93-evk/bsp/imx93-firmware.nix @@ -0,0 +1,47 @@ +{ pkgs, ... }: + +with pkgs; +stdenv.mkDerivation rec { + pname = "nxp-firmware"; + version = "nxp-firmware-8.21-0.11"; + + # Fetch the two firmware installers from NXP + ddrFirmware = fetchurl { + url = "https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/firmware-imx-8.21.bin"; + sha256 = "sha256-w0R/D4E0FczqncLvEggMs6yLvAxnOSp0/H1ZIF61pnI="; + }; + + ahabFirmware = fetchurl { + url = "https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/firmware-sentinel-0.11.bin"; + sha256 = "sha256-JpSAQXqK6apMxBAauUcof8M0VakxAh29xNm621ISvOs="; + }; + + nativeBuildInputs = [ coreutils bash ]; + + dontUnpack = true; + dontStrip = true; + + installPhase = '' + mkdir -p $out + + echo "Extracting DDR firmware..." + cp ${ddrFirmware} ./firmware-imx-8.21.bin + chmod +x firmware-imx-8.21.bin + ./firmware-imx-8.21.bin --auto-accept + + echo "Extracting AHAB firmware..." + cp ${ahabFirmware} ./firmware-sentinel-0.11.bin + chmod +x firmware-sentinel-0.11.bin + ./firmware-sentinel-0.11.bin --auto-accept + + echo "Copying DDR .bin files..." + mkdir -p $out/ddr + cp firmware-imx-8.21/firmware/ddr/synopsys/lpddr4*.bin $out/ddr/ + + echo "Copying AHAB container image..." + mkdir -p $out/ahab + cp firmware-sentinel-0.11/mx93a1-ahab-container.img $out/ahab/ + + ''; +} + diff --git a/nxp/imx93-evk/bsp/imx93-linux.nix b/nxp/imx93-evk/bsp/imx93-linux.nix new file mode 100644 index 0000000..1eabbf4 --- /dev/null +++ b/nxp/imx93-evk/bsp/imx93-linux.nix @@ -0,0 +1,62 @@ +{ lib, pkgs, ... }@args: +with pkgs; +buildLinux ( + args + // rec { + version = "6.12.3"; + name = "imx93-linux"; + + # modDirVersion needs to be x.y.z, will automatically add .0 if needed + modDirVersion = version; + + defconfig = "imx_v8_defconfig"; + + # https://github.com/NixOS/nixpkgs/pull/366004 + # introduced a breaking change that if a module is declared but it is not being used it will faill. + ignoreConfigErrors = true; + + kernelPatches = [ + ]; + + autoModules = false; + + extraConfig = '' + CRYPTO_TLS m + TLS y + MD_RAID0 m + MD_RAID1 m + MD_RAID10 m + MD_RAID456 m + DM_VERITY m + LOGO y + FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER n + FB_EFI n + EFI_STUB y + EFI y + VIRTIO y + VIRTIO_PCI y + VIRTIO_BLK y + DRM_VIRTIO_GPU y + EXT4_FS y + USBIP_CORE m + USBIP_VHCI_HCD m + USBIP_HOST m + USBIP_VUDC m + ''; + + src = fetchFromGitHub { + owner = "nxp-imx"; + repo = "linux-imx"; + # tag: lf-6.12.3 + rev = "37d02f4dcbbe6677dc9f5fc17f386c05d6a7bd7a"; + sha256 = "sha256-1oJMbHR8Ho0zNritEJ+TMOAyYHCW0vwhPkDfLctrZa8="; + }; + meta = with lib; { + homepage = "https://github.com/nxp-imx/linux-imx"; + license = [ licenses.gpl2Only ]; + maintainers = with maintainers; [ govindsi ]; + platforms = [ "aarch64-linux" ]; + }; + } + // (args.argsOverride or { }) +) diff --git a/nxp/imx93-evk/bsp/imx93-optee-os.nix b/nxp/imx93-evk/bsp/imx93-optee-os.nix new file mode 100644 index 0000000..a7d82eb --- /dev/null +++ b/nxp/imx93-evk/bsp/imx93-optee-os.nix @@ -0,0 +1,75 @@ +{ + lib, + pkgs +}: +let + inherit (pkgs.buildPackages) python3; + toolchain = pkgs.gccStdenv.cc; + binutils = pkgs.gccStdenv.cc.bintools.bintools_bin; + cpp = pkgs.gcc; +in +pkgs.stdenv.mkDerivation rec { + pname = "imx93-optee-os"; + version = "lf-6.12.3_1.0.0"; + + nativeBuildInputs = [ + python3 + ]; + + enableParallelBuilding = true; + + propagatedBuildInputs = with python3.pkgs; [ + pycryptodomex + pyelftools + cryptography + ]; + + src = pkgs.fetchgit { + url = "https://github.com/nxp-imx/imx-optee-os.git"; + rev = "8dd180b6d149c1e1314b5869697179f665bd9ca3"; + sha256 = "sha256-PoolRscdyeGevrOa5YymPTQ36edVvReMM5WshRTz+uk="; + }; + meta = with lib; { + homepage = "https://github.com/nxp-imx/imx-optee-os"; + license = [ licenses.bsd2 ]; + maintainers = with maintainers; [ govindsi ]; + platforms = [ "aarch64-linux" ]; + }; + + postPatch = '' + substituteInPlace scripts/arm32_sysreg.py \ + --replace '/usr/bin/env python3' '${python3}/bin/python' + substituteInPlace scripts/gen_tee_bin.py \ + --replace '/usr/bin/env python3' '${python3}/bin/python' + substituteInPlace scripts/pem_to_pub_c.py \ + --replace '/usr/bin/env python3' '${python3}/bin/python' + substituteInPlace ta/pkcs11/scripts/verify-helpers.sh \ + --replace '/bin/bash' '${pkgs.bash}/bin/bash' + substituteInPlace mk/gcc.mk \ + --replace "\$(CROSS_COMPILE_\$(sm))objcopy" ${binutils}/bin/${toolchain.targetPrefix}objcopy + substituteInPlace mk/gcc.mk \ + --replace "\$(CROSS_COMPILE_\$(sm))objdump" ${binutils}/bin/${toolchain.targetPrefix}objdump + substituteInPlace mk/gcc.mk \ + --replace "\$(CROSS_COMPILE_\$(sm))nm" ${binutils}/bin/${toolchain.targetPrefix}nm + substituteInPlace mk/gcc.mk \ + --replace "\$(CROSS_COMPILE_\$(sm))readelf" ${binutils}/bin/${toolchain.targetPrefix}readelf + substituteInPlace mk/gcc.mk \ + --replace "\$(CROSS_COMPILE_\$(sm))ar" ${binutils}/bin/${toolchain.targetPrefix}ar + substituteInPlace mk/gcc.mk \ + --replace "\$(CROSS_COMPILE_\$(sm))cpp" ${cpp}/bin/cpp + ''; + + makeFlags = [ + "PLATFORM=imx-mx93evk" + "CFG_ARM64_core=y" + "CFG_TEE_TA_LOG_LEVEL=0" + "CFG_TEE_CORE_LOG_LEVEL=0" + "CROSS_COMPILE=${toolchain}/bin/${toolchain.targetPrefix}" + "CROSS_COMPILE64=${toolchain}/bin/${toolchain.targetPrefix}" + ]; + + installPhase = '' + mkdir -p $out + cp ./out/arm-plat-imx/core/tee-raw.bin $out/tee.bin + ''; +} diff --git a/nxp/imx93-evk/bsp/imx93-uboot.nix b/nxp/imx93-evk/bsp/imx93-uboot.nix new file mode 100644 index 0000000..f0bb626 --- /dev/null +++ b/nxp/imx93-evk/bsp/imx93-uboot.nix @@ -0,0 +1,99 @@ +{ + stdenv, + lib, + bison, + dtc, + fetchgit, + flex, + gnutls, + libuuid, + ncurses, + openssl, + which, + perl, + buildPackages, + efitools, +}: +let + ubsrc = fetchgit { + url = "https://github.com/nxp-imx/uboot-imx.git"; + #lf_v2024.04 + rev = "e3219a5a73445219df605d1492687918d488055c"; + sha256 = "sha256-6pXwgNzq4/XUUEmJ6sGC5pII4J5uMvlDPE9QJxjJJbQ="; + }; + meta = with lib; { + homepage = "https://github.com/nxp-imx/uboot-imx"; + license = [ licenses.gpl2Only ]; + maintainers = with maintainers; [ govindsi ]; + platforms = [ "aarch64-linux" ]; + }; +in +stdenv.mkDerivation { + pname = "imx93-uboot"; + version = "2024.04"; + src = ubsrc; + + postPatch = '' + patchShebangs tools + patchShebangs scripts + ''; + + nativeBuildInputs = [ + bison + flex + openssl + which + ncurses + libuuid + gnutls + openssl + perl + efitools + ]; + + depsBuildBuild = [ buildPackages.stdenv.cc ]; + hardeningDisable = [ "all" ]; + enableParallelBuilding = true; + + makeFlags = [ + "DTC=${lib.getExe buildPackages.dtc}" + "CROSS_COMPILE=${stdenv.cc.targetPrefix}" + ]; + + extraConfig = '' + CONFIG_USE_BOOTCOMMAND=y + CONFIG_BOOTCOMMAND="setenv ramdisk_addr_r 0x85000000; setenv fdt_addr_r 0x84000000; run distro_bootcmd; " + CONFIG_CMD_BOOTEFI_SELFTEST=y + CONFIG_CMD_BOOTEFI=y + CONFIG_EFI_LOADER=y + CONFIG_BLK=y + CONFIG_PARTITIONS=y + CONFIG_DM_DEVICE_REMOVE=n + CONFIG_CMD_CACHE=y + ''; + + passAsFile = [ "extraConfig" ]; + + configurePhase = '' + runHook preConfigure + + make imx93_11x11_evk_defconfig + cat $extraConfigPath >> .config + + runHook postConfigure + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out + cp ./u-boot-nodtb.bin $out + cp ./spl/u-boot-spl.bin $out + cp ./arch/arm/dts/imx93-11x11-evk.dtb $out + cp .config $out + + runHook postInstall + ''; + + dontStrip = true; +} diff --git a/nxp/imx93-evk/default.nix b/nxp/imx93-evk/default.nix new file mode 100644 index 0000000..892c6a6 --- /dev/null +++ b/nxp/imx93-evk/default.nix @@ -0,0 +1,19 @@ +{ pkgs, ... }: +{ + nixpkgs.overlays = [ + (import ./overlay.nix) + ]; + + imports = [ + ./modules.nix + ]; + + boot.loader.grub.extraFiles = { + "imx93-11x11-evk.dtb" = "${pkgs.callPackage ./bsp/imx93-linux.nix { }}/dtbs/freescale/imx93-11x11-evk.dtb"; + }; + + hardware.deviceTree = { + filter = "imx93-*.dtb"; + name = "imx93-11x11-evk.dtb"; + }; +} diff --git a/nxp/imx93-evk/modules.nix b/nxp/imx93-evk/modules.nix new file mode 100644 index 0000000..b893968 --- /dev/null +++ b/nxp/imx93-evk/modules.nix @@ -0,0 +1,17 @@ +{ + pkgs, + lib, + ... +}: +{ + nixpkgs.hostPlatform = "aarch64-linux"; + + boot = { + kernelPackages = pkgs.linuxPackagesFor (pkgs.callPackage ./bsp/imx93-linux.nix { }); + initrd.includeDefaultModules = lib.mkForce false; + }; + + disabledModules = [ "profiles/all-hardware.nix" ]; + + hardware.deviceTree.enable = true; +} diff --git a/nxp/imx93-evk/overlay.nix b/nxp/imx93-evk/overlay.nix new file mode 100644 index 0000000..420e974 --- /dev/null +++ b/nxp/imx93-evk/overlay.nix @@ -0,0 +1,3 @@ +final: _prev: { + inherit (final.callPackage ./bsp/imx93-boot.nix { pkgs = final; }) imx93-boot; +} From 8b405e9c6ddab8bbc7c6dcae7d20415bd8f5ad76 Mon Sep 17 00:00:00 2001 From: Govind Singh Date: Tue, 21 Oct 2025 16:00:55 +0400 Subject: [PATCH 2/3] chore(fmt): apply nix formatting Signed-off-by: Govind Singh --- nxp/imx93-evk/bsp/imx93-atf.nix | 13 ++++++++++--- nxp/imx93-evk/bsp/imx93-boot.nix | 1 - nxp/imx93-evk/bsp/imx93-firmware.nix | 7 ++++--- nxp/imx93-evk/bsp/imx93-linux.nix | 14 +++++++------- nxp/imx93-evk/bsp/imx93-optee-os.nix | 6 +++--- nxp/imx93-evk/bsp/imx93-uboot.nix | 6 ------ nxp/imx93-evk/default.nix | 4 +++- 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/nxp/imx93-evk/bsp/imx93-atf.nix b/nxp/imx93-evk/bsp/imx93-atf.nix index 4180dde..634cca1 100644 --- a/nxp/imx93-evk/bsp/imx93-atf.nix +++ b/nxp/imx93-evk/bsp/imx93-atf.nix @@ -1,8 +1,16 @@ -{ lib, fetchgit, stdenv, buildPackages, pkgsCross, openssl }: +{ + lib, + fetchgit, + stdenv, + buildPackages, + pkgsCross, + openssl, +}: let target-board = "imx93"; -in stdenv.mkDerivation rec { +in +stdenv.mkDerivation rec { pname = "imx93-atf"; version = "2.10.0"; platform = target-board; @@ -47,4 +55,3 @@ in stdenv.mkDerivation rec { platforms = [ "aarch64-linux" ]; }; } - diff --git a/nxp/imx93-evk/bsp/imx93-boot.nix b/nxp/imx93-evk/bsp/imx93-boot.nix index abc023e..c11f31d 100644 --- a/nxp/imx93-evk/bsp/imx93-boot.nix +++ b/nxp/imx93-evk/bsp/imx93-boot.nix @@ -3,7 +3,6 @@ }: with pkgs; let - fw-ver = "202406"; imx93-atf = pkgs.callPackage ./imx93-atf.nix { }; imx93-firmware = pkgs.callPackage ./imx93-firmware.nix { }; diff --git a/nxp/imx93-evk/bsp/imx93-firmware.nix b/nxp/imx93-evk/bsp/imx93-firmware.nix index b48e8a3..1caa239 100644 --- a/nxp/imx93-evk/bsp/imx93-firmware.nix +++ b/nxp/imx93-evk/bsp/imx93-firmware.nix @@ -5,7 +5,6 @@ stdenv.mkDerivation rec { pname = "nxp-firmware"; version = "nxp-firmware-8.21-0.11"; - # Fetch the two firmware installers from NXP ddrFirmware = fetchurl { url = "https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/firmware-imx-8.21.bin"; sha256 = "sha256-w0R/D4E0FczqncLvEggMs6yLvAxnOSp0/H1ZIF61pnI="; @@ -16,7 +15,10 @@ stdenv.mkDerivation rec { sha256 = "sha256-JpSAQXqK6apMxBAauUcof8M0VakxAh29xNm621ISvOs="; }; - nativeBuildInputs = [ coreutils bash ]; + nativeBuildInputs = [ + coreutils + bash + ]; dontUnpack = true; dontStrip = true; @@ -44,4 +46,3 @@ stdenv.mkDerivation rec { ''; } - diff --git a/nxp/imx93-evk/bsp/imx93-linux.nix b/nxp/imx93-evk/bsp/imx93-linux.nix index 1eabbf4..6e4cc21 100644 --- a/nxp/imx93-evk/bsp/imx93-linux.nix +++ b/nxp/imx93-evk/bsp/imx93-linux.nix @@ -51,12 +51,12 @@ buildLinux ( rev = "37d02f4dcbbe6677dc9f5fc17f386c05d6a7bd7a"; sha256 = "sha256-1oJMbHR8Ho0zNritEJ+TMOAyYHCW0vwhPkDfLctrZa8="; }; - meta = with lib; { - homepage = "https://github.com/nxp-imx/linux-imx"; - license = [ licenses.gpl2Only ]; - maintainers = with maintainers; [ govindsi ]; - platforms = [ "aarch64-linux" ]; - }; - } + meta = with lib; { + homepage = "https://github.com/nxp-imx/linux-imx"; + license = [ licenses.gpl2Only ]; + maintainers = with maintainers; [ govindsi ]; + platforms = [ "aarch64-linux" ]; + }; + } // (args.argsOverride or { }) ) diff --git a/nxp/imx93-evk/bsp/imx93-optee-os.nix b/nxp/imx93-evk/bsp/imx93-optee-os.nix index a7d82eb..75e3dde 100644 --- a/nxp/imx93-evk/bsp/imx93-optee-os.nix +++ b/nxp/imx93-evk/bsp/imx93-optee-os.nix @@ -1,6 +1,6 @@ -{ +{ lib, - pkgs + pkgs, }: let inherit (pkgs.buildPackages) python3; @@ -57,7 +57,7 @@ pkgs.stdenv.mkDerivation rec { --replace "\$(CROSS_COMPILE_\$(sm))ar" ${binutils}/bin/${toolchain.targetPrefix}ar substituteInPlace mk/gcc.mk \ --replace "\$(CROSS_COMPILE_\$(sm))cpp" ${cpp}/bin/cpp - ''; + ''; makeFlags = [ "PLATFORM=imx-mx93evk" diff --git a/nxp/imx93-evk/bsp/imx93-uboot.nix b/nxp/imx93-evk/bsp/imx93-uboot.nix index f0bb626..ce91838 100644 --- a/nxp/imx93-evk/bsp/imx93-uboot.nix +++ b/nxp/imx93-evk/bsp/imx93-uboot.nix @@ -21,12 +21,6 @@ let rev = "e3219a5a73445219df605d1492687918d488055c"; sha256 = "sha256-6pXwgNzq4/XUUEmJ6sGC5pII4J5uMvlDPE9QJxjJJbQ="; }; - meta = with lib; { - homepage = "https://github.com/nxp-imx/uboot-imx"; - license = [ licenses.gpl2Only ]; - maintainers = with maintainers; [ govindsi ]; - platforms = [ "aarch64-linux" ]; - }; in stdenv.mkDerivation { pname = "imx93-uboot"; diff --git a/nxp/imx93-evk/default.nix b/nxp/imx93-evk/default.nix index 892c6a6..fd375aa 100644 --- a/nxp/imx93-evk/default.nix +++ b/nxp/imx93-evk/default.nix @@ -9,7 +9,9 @@ ]; boot.loader.grub.extraFiles = { - "imx93-11x11-evk.dtb" = "${pkgs.callPackage ./bsp/imx93-linux.nix { }}/dtbs/freescale/imx93-11x11-evk.dtb"; + "imx93-11x11-evk.dtb" = "${ + pkgs.callPackage ./bsp/imx93-linux.nix { } + }/dtbs/freescale/imx93-11x11-evk.dtb"; }; hardware.deviceTree = { From 688ee555decae8a61301c572c0f69d93f50a94dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 29 Oct 2025 16:03:39 +0100 Subject: [PATCH 3/3] refactor(nxp): parameterize i.MX platform builders to reduce duplication This refactoring reduces code duplication across i.MX93, i.MX8MP, and i.MX8MQ platforms by extracting common build logic into parameterized shared builders. This makes it easier to maintain and add new i.MX platforms while ensuring consistency across all platforms. --- nxp/common/bsp/imx-linux-builder.nix | 56 +++++++++++++++ nxp/common/bsp/imx-optee-builder.nix | 89 +++++++++++++++++++++++ nxp/common/bsp/imx-uboot-builder.nix | 97 ++++++++++++++++++++++++++ nxp/common/lib/kernel-config.nix | 29 ++++++++ nxp/common/lib/uboot-config.nix | 33 +++++++++ nxp/imx8mp-evk/bsp/imx8mp-linux.nix | 68 +++++------------- nxp/imx8mp-evk/bsp/imx8mp-optee-os.nix | 60 +--------------- nxp/imx8mp-evk/bsp/imx8mp-uboot.nix | 96 +++---------------------- nxp/imx8mq-evk/bsp/imx8mq-linux.nix | 68 +++++------------- nxp/imx8mq-evk/bsp/imx8mq-optee-os.nix | 58 +-------------- nxp/imx8mq-evk/bsp/imx8mq-uboot.nix | 96 +++---------------------- nxp/imx93-evk/bsp/imx93-linux.nix | 78 ++++++--------------- nxp/imx93-evk/bsp/imx93-optee-os.nix | 72 ++----------------- nxp/imx93-evk/bsp/imx93-uboot.nix | 96 +++---------------------- 14 files changed, 398 insertions(+), 598 deletions(-) create mode 100644 nxp/common/bsp/imx-linux-builder.nix create mode 100644 nxp/common/bsp/imx-optee-builder.nix create mode 100644 nxp/common/bsp/imx-uboot-builder.nix create mode 100644 nxp/common/lib/kernel-config.nix create mode 100644 nxp/common/lib/uboot-config.nix diff --git a/nxp/common/bsp/imx-linux-builder.nix b/nxp/common/bsp/imx-linux-builder.nix new file mode 100644 index 0000000..cc8fb93 --- /dev/null +++ b/nxp/common/bsp/imx-linux-builder.nix @@ -0,0 +1,56 @@ +# Parameterized Linux kernel builder for i.MX platforms +# This builder is used across i.MX93, i.MX8MP, i.MX8MQ and similar platforms +{ lib, pkgs, ... }@args: +let + inherit (pkgs) buildLinux; + + # Import common kernel configuration + kernelConfig = import ../lib/kernel-config.nix; +in +# Platform-specific parameters +{ + pname, + version, + src, + defconfig ? "imx_v8_defconfig", + # Optional parameters + extraConfig ? "", + kernelPatches ? [ ], + autoModules ? false, + ignoreConfigErrors ? true, + extraMeta ? { }, +}: +let + # Combine common i.MX kernel config with platform-specific config + finalExtraConfig = kernelConfig.imxCommonKernelConfig + extraConfig; +in +buildLinux ( + args + // rec { + inherit + version + defconfig + kernelPatches + autoModules + ignoreConfigErrors + ; + name = pname; + + # modDirVersion needs to be x.y.z, will automatically add .0 if needed + modDirVersion = version; + + extraConfig = finalExtraConfig; + + inherit src; + + meta = + with lib; + { + homepage = "https://github.com/nxp-imx/linux-imx"; + license = [ licenses.gpl2Only ]; + platforms = [ "aarch64-linux" ]; + } + // extraMeta; + } + // (args.argsOverride or { }) +) diff --git a/nxp/common/bsp/imx-optee-builder.nix b/nxp/common/bsp/imx-optee-builder.nix new file mode 100644 index 0000000..c76024b --- /dev/null +++ b/nxp/common/bsp/imx-optee-builder.nix @@ -0,0 +1,89 @@ +# Parameterized OP-TEE OS builder for i.MX platforms +# This builder is used across i.MX93, i.MX8MP, i.MX8MQ and similar platforms +{ + lib, + pkgs, + # Platform-specific parameters + pname, + version, + platformFlavor, + src, + # Optional parameters + meta ? { }, +}: +let + inherit (pkgs.buildPackages) python3; + toolchain = pkgs.gccStdenv.cc; + binutils = pkgs.gccStdenv.cc.bintools.bintools_bin; + cpp = pkgs.gcc; + + # Determine PLATFORM and PLATFORM_FLAVOR from platformFlavor + # Format can be either "imx-mx93evk" (full platform string) or "mx8mpevk" (just flavor, platform is "imx") + # Check if it starts with "imx-" to determine if it's a full platform string or just a flavor + hasFullPlatform = lib.hasPrefix "imx-" platformFlavor; + platform = if hasFullPlatform then platformFlavor else "imx"; + flavor = if hasFullPlatform then null else platformFlavor; +in +pkgs.stdenv.mkDerivation { + inherit pname version src; + + nativeBuildInputs = [ + python3 + ]; + + enableParallelBuilding = true; + + propagatedBuildInputs = with python3.pkgs; [ + pycryptodomex + pyelftools + cryptography + ]; + + # Common postPatch for all i.MX platforms + # This is the major source of code duplication - ~60 lines of identical substitutions + postPatch = '' + # Patch all script shebangs automatically + patchShebangs scripts/ + patchShebangs ta/ + + # Patch toolchain paths in mk/gcc.mk + substituteInPlace mk/gcc.mk \ + --replace "\$(CROSS_COMPILE_\$(sm))objcopy" ${binutils}/bin/${toolchain.targetPrefix}objcopy + substituteInPlace mk/gcc.mk \ + --replace "\$(CROSS_COMPILE_\$(sm))objdump" ${binutils}/bin/${toolchain.targetPrefix}objdump + substituteInPlace mk/gcc.mk \ + --replace "\$(CROSS_COMPILE_\$(sm))nm" ${binutils}/bin/${toolchain.targetPrefix}nm + substituteInPlace mk/gcc.mk \ + --replace "\$(CROSS_COMPILE_\$(sm))readelf" ${binutils}/bin/${toolchain.targetPrefix}readelf + substituteInPlace mk/gcc.mk \ + --replace "\$(CROSS_COMPILE_\$(sm))ar" ${binutils}/bin/${toolchain.targetPrefix}ar + substituteInPlace mk/gcc.mk \ + --replace "\$(CROSS_COMPILE_\$(sm))cpp" ${cpp}/bin/cpp + ''; + + makeFlags = + [ + "PLATFORM=${platform}" + ] + ++ lib.optionals (!hasFullPlatform) [ + "PLATFORM_FLAVOR=${flavor}" + ] + ++ [ + "CFG_ARM64_core=y" + "CFG_TEE_TA_LOG_LEVEL=0" + "CFG_TEE_CORE_LOG_LEVEL=0" + "CROSS_COMPILE=${toolchain}/bin/${toolchain.targetPrefix}" + "CROSS_COMPILE64=${toolchain}/bin/${toolchain.targetPrefix}" + ]; + + installPhase = '' + mkdir -p $out + cp ./out/arm-plat-imx/core/tee-raw.bin $out/tee.bin + ''; + + meta = { + homepage = "https://github.com/nxp-imx/imx-optee-os"; + license = [ lib.licenses.bsd2 ]; + platforms = [ "aarch64-linux" ]; + } // meta; +} diff --git a/nxp/common/bsp/imx-uboot-builder.nix b/nxp/common/bsp/imx-uboot-builder.nix new file mode 100644 index 0000000..6d8a596 --- /dev/null +++ b/nxp/common/bsp/imx-uboot-builder.nix @@ -0,0 +1,97 @@ +# Parameterized U-Boot builder for i.MX platforms +# This builder is used across i.MX93, i.MX8MP, i.MX8MQ and similar platforms +{ + lib, + stdenv, + buildPackages, + # Required dependencies + bison, + dtc, + flex, + gnutls, + libuuid, + ncurses, + openssl, + perl, + efitools, + which, + # Platform-specific parameters + pname, + version, + src, + defconfig, + ramdiskAddr, + fdtAddr, + dtbPath, + # Optional parameters + extraConfig ? "", + extraNativeBuildInputs ? [ ], +}: +let + # Import common U-Boot configuration + ubootConfig = import ../lib/uboot-config.nix; + + # Generate the common config with platform-specific memory addresses + commonConfig = ubootConfig.imxCommonUbootConfig { + inherit ramdiskAddr fdtAddr; + }; + + # Combine common config with any platform-specific extra config + finalExtraConfig = commonConfig + extraConfig; +in +stdenv.mkDerivation { + inherit pname version src; + + postPatch = '' + patchShebangs tools + patchShebangs scripts + ''; + + nativeBuildInputs = [ + bison + flex + openssl + which + ncurses + libuuid + gnutls + perl + efitools + ] ++ extraNativeBuildInputs; + + depsBuildBuild = [ buildPackages.stdenv.cc ]; + hardeningDisable = [ "all" ]; + enableParallelBuilding = true; + + makeFlags = [ + "DTC=${lib.getExe buildPackages.dtc}" + "CROSS_COMPILE=${stdenv.cc.targetPrefix}" + ]; + + extraConfig = finalExtraConfig; + + passAsFile = [ "extraConfig" ]; + + configurePhase = '' + runHook preConfigure + + make ${defconfig} + cat $extraConfigPath >> .config + + runHook postConfigure + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out + cp ./u-boot-nodtb.bin $out + cp ./spl/u-boot-spl.bin $out + cp ${dtbPath} $out + cp .config $out + + runHook postInstall + ''; + + dontStrip = true; +} diff --git a/nxp/common/lib/kernel-config.nix b/nxp/common/lib/kernel-config.nix new file mode 100644 index 0000000..aca1e70 --- /dev/null +++ b/nxp/common/lib/kernel-config.nix @@ -0,0 +1,29 @@ +# Shared kernel configuration for i.MX platforms +# This configuration is used across i.MX93, i.MX8MP, i.MX8MQ and similar platforms +{ + # Common kernel extra configuration for i.MX platforms + # Includes: virtualization support, EFI boot, RAID, USB/IP, framebuffer settings + imxCommonKernelConfig = '' + CRYPTO_TLS m + TLS y + MD_RAID0 m + MD_RAID1 m + MD_RAID10 m + MD_RAID456 m + DM_VERITY m + LOGO y + FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER n + FB_EFI n + EFI_STUB y + EFI y + VIRTIO y + VIRTIO_PCI y + VIRTIO_BLK y + DRM_VIRTIO_GPU y + EXT4_FS y + USBIP_CORE m + USBIP_VHCI_HCD m + USBIP_HOST m + USBIP_VUDC m + ''; +} diff --git a/nxp/common/lib/uboot-config.nix b/nxp/common/lib/uboot-config.nix new file mode 100644 index 0000000..401e81c --- /dev/null +++ b/nxp/common/lib/uboot-config.nix @@ -0,0 +1,33 @@ +# Shared U-Boot configuration for i.MX platforms +# This configuration is used across i.MX93, i.MX8MP, i.MX8MQ and similar platforms +{ + # Generate common U-Boot extra configuration for i.MX platforms + # ramdiskAddr and fdtAddr are platform-specific memory addresses + imxCommonUbootConfig = + { ramdiskAddr, fdtAddr }: + '' + CONFIG_USE_BOOTCOMMAND=y + CONFIG_BOOTCOMMAND="setenv ramdisk_addr_r ${ramdiskAddr}; setenv fdt_addr_r ${fdtAddr}; run distro_bootcmd; " + CONFIG_CMD_BOOTEFI_SELFTEST=y + CONFIG_CMD_BOOTEFI=y + CONFIG_EFI_LOADER=y + CONFIG_BLK=y + CONFIG_PARTITIONS=y + CONFIG_DM_DEVICE_REMOVE=n + CONFIG_CMD_CACHE=y + ''; + + # Common U-Boot native build inputs for i.MX platforms + imxCommonUbootNativeBuildInputs = [ + "bison" + "flex" + "openssl" + "which" + "ncurses" + "libuuid" + "gnutls" + "openssl" + "perl" + "efitools" + ]; +} diff --git a/nxp/imx8mp-evk/bsp/imx8mp-linux.nix b/nxp/imx8mp-evk/bsp/imx8mp-linux.nix index 86025f2..5152237 100644 --- a/nxp/imx8mp-evk/bsp/imx8mp-linux.nix +++ b/nxp/imx8mp-evk/bsp/imx8mp-linux.nix @@ -1,56 +1,20 @@ { pkgs, ... }@args: -with pkgs; -buildLinux ( - args - // rec { - version = "6.12.20"; - name = "imx8mp-linux"; +(pkgs.callPackage ../../common/bsp/imx-linux-builder.nix args) { + pname = "imx8mp-linux"; + version = "6.12.20"; - # modDirVersion needs to be x.y.z, will automatically add .0 if needed - modDirVersion = version; + src = pkgs.fetchFromGitHub { + owner = "nxp-imx"; + repo = "linux-imx"; + # tag: lf-6.12.20-2.0.0 + rev = "dfaf2136deb2af2e60b994421281ba42f1c087e0"; + sha256 = "sha256-ITrmj3a5YfXh/PSRTi+Rlto5uEBIAWFWtkTsO1ATXIo="; + }; - defconfig = "imx_v8_defconfig"; + # Platform-specific configuration (if any) + extraConfig = ""; - # https://github.com/NixOS/nixpkgs/pull/366004 - # introduced a breaking change that if a module is declared but it is not being used it will faill. - ignoreConfigErrors = true; - - kernelPatches = [ - ]; - - autoModules = false; - - extraConfig = '' - CRYPTO_TLS m - TLS y - MD_RAID0 m - MD_RAID1 m - MD_RAID10 m - MD_RAID456 m - DM_VERITY m - LOGO y - FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER n - FB_EFI n - EFI_STUB y - EFI y - VIRTIO y - VIRTIO_PCI y - VIRTIO_BLK y - DRM_VIRTIO_GPU y - EXT4_FS y - USBIP_CORE m - USBIP_VHCI_HCD m - USBIP_HOST m - USBIP_VUDC m - ''; - - src = fetchFromGitHub { - owner = "nxp-imx"; - repo = "linux-imx"; - # tag: lf-6.12.20-2.0.0 - rev = "dfaf2136deb2af2e60b994421281ba42f1c087e0"; - sha256 = "sha256-ITrmj3a5YfXh/PSRTi+Rlto5uEBIAWFWtkTsO1ATXIo="; - }; - } - // (args.argsOverride or { }) -) + # https://github.com/NixOS/nixpkgs/pull/366004 + # introduced a breaking change that if a module is declared but it is not being used it will faill. + ignoreConfigErrors = true; +} diff --git a/nxp/imx8mp-evk/bsp/imx8mp-optee-os.nix b/nxp/imx8mp-evk/bsp/imx8mp-optee-os.nix index 4cdd5f5..c409e6c 100644 --- a/nxp/imx8mp-evk/bsp/imx8mp-optee-os.nix +++ b/nxp/imx8mp-evk/bsp/imx8mp-optee-os.nix @@ -1,69 +1,13 @@ { pkgs }: -let - inherit (pkgs.buildPackages) python3; - toolchain = pkgs.gccStdenv.cc; - binutils = pkgs.gccStdenv.cc.bintools.bintools_bin; - cpp = pkgs.gcc; -in -pkgs.stdenv.mkDerivation rec { +pkgs.callPackage ../../common/bsp/imx-optee-builder.nix { pname = "imx8mp-optee-os"; version = "lf-6.12.20-2.0.0"; - nativeBuildInputs = [ - python3 - ]; - - enableParallelBuilding = true; - - propagatedBuildInputs = with python3.pkgs; [ - pycryptodomex - pyelftools - cryptography - ]; - src = pkgs.fetchgit { url = "https://github.com/nxp-imx/imx-optee-os.git"; rev = "87964807d80baf1dcfd89cafc66de34a1cf16bf3"; sha256 = "sha256-AMZUMgmmyi5l3BMT84uubwjU0lwNObs9XW6ZCbqfhmc="; }; - postPatch = '' - substituteInPlace scripts/arm32_sysreg.py \ - --replace '/usr/bin/env python3' '${python3}/bin/python' - substituteInPlace scripts/gen_tee_bin.py \ - --replace '/usr/bin/env python3' '${python3}/bin/python' - substituteInPlace scripts/pem_to_pub_c.py \ - --replace '/usr/bin/env python3' '${python3}/bin/python' - substituteInPlace ta/pkcs11/scripts/verify-helpers.sh \ - --replace '/usr/bin/env bash' '${pkgs.bash}/bin/bash' - substituteInPlace ta/pkcs11/scripts/dump_ec_curve_params.sh \ - --replace '/usr/bin/env bash' '${pkgs.bash}/bin/bash' - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))objcopy" ${binutils}/bin/${toolchain.targetPrefix}objcopy - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))objdump" ${binutils}/bin/${toolchain.targetPrefix}objdump - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))nm" ${binutils}/bin/${toolchain.targetPrefix}nm - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))readelf" ${binutils}/bin/${toolchain.targetPrefix}readelf - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))ar" ${binutils}/bin/${toolchain.targetPrefix}ar - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))cpp" ${cpp}/bin/cpp - ''; - - makeFlags = [ - "PLATFORM=imx" - "PLATFORM_FLAVOR=mx8mpevk" - "CFG_ARM64_core=y" - "CFG_TEE_TA_LOG_LEVEL=0" - "CFG_TEE_CORE_LOG_LEVEL=0" - "CROSS_COMPILE=${toolchain}/bin/${toolchain.targetPrefix}" - "CROSS_COMPILE64=${toolchain}/bin/${toolchain.targetPrefix}" - ]; - - installPhase = '' - mkdir -p $out - cp ./out/arm-plat-imx/core/tee-raw.bin $out/tee.bin - ''; + platformFlavor = "mx8mpevk"; } diff --git a/nxp/imx8mp-evk/bsp/imx8mp-uboot.nix b/nxp/imx8mp-evk/bsp/imx8mp-uboot.nix index 582cb70..70b9992 100644 --- a/nxp/imx8mp-evk/bsp/imx8mp-uboot.nix +++ b/nxp/imx8mp-evk/bsp/imx8mp-uboot.nix @@ -1,93 +1,17 @@ -{ - stdenv, - lib, - bison, - dtc, - fetchgit, - flex, - gnutls, - libuuid, - ncurses, - openssl, - which, - perl, - buildPackages, - efitools, -}: -let - ubsrc = fetchgit { +{ pkgs, fetchgit }: +pkgs.callPackage ../../common/bsp/imx-uboot-builder.nix { + pname = "imx8mp-uboot"; + version = "2025.04"; + + src = fetchgit { url = "https://github.com/nxp-imx/uboot-imx.git"; # tag: lf-6.12.20-2.0.0 rev = "9383f8387dc76524524da69992db96c22195a57c"; sha256 = "sha256-httRSwN8NiKOdL7fZEvN/4AbypGQfegYtJgxKIea+Zg="; }; -in -stdenv.mkDerivation { - pname = "imx8mp-uboot"; - version = "2025.04"; - src = ubsrc; - postPatch = '' - patchShebangs tools - patchShebangs scripts - ''; - - nativeBuildInputs = [ - bison - flex - openssl - which - ncurses - libuuid - gnutls - openssl - perl - efitools - ]; - - depsBuildBuild = [ buildPackages.stdenv.cc ]; - hardeningDisable = [ "all" ]; - enableParallelBuilding = true; - - makeFlags = [ - "DTC=${lib.getExe buildPackages.dtc}" - "CROSS_COMPILE=${stdenv.cc.targetPrefix}" - ]; - - extraConfig = '' - CONFIG_USE_BOOTCOMMAND=y - CONFIG_BOOTCOMMAND="setenv ramdisk_addr_r 0x45000000; setenv fdt_addr_r 0x44000000; run distro_bootcmd; " - CONFIG_CMD_BOOTEFI_SELFTEST=y - CONFIG_CMD_BOOTEFI=y - CONFIG_EFI_LOADER=y - CONFIG_BLK=y - CONFIG_PARTITIONS=y - CONFIG_DM_DEVICE_REMOVE=n - CONFIG_CMD_CACHE=y - ''; - - passAsFile = [ "extraConfig" ]; - - configurePhase = '' - runHook preConfigure - - make imx8mp_evk_defconfig - cat $extraConfigPath >> .config - - runHook postConfigure - ''; - - installPhase = '' - runHook preInstall - - mkdir -p $out - cp ./u-boot-nodtb.bin $out - cp ./spl/u-boot-spl.bin $out - cp ./dts/upstream/src/arm64/freescale/imx8mp-evk.dtb $out - cp .config $out - - runHook postInstall - ''; - - dontStrip = true; + defconfig = "imx8mp_evk_defconfig"; + ramdiskAddr = "0x45000000"; + fdtAddr = "0x44000000"; + dtbPath = "./dts/upstream/src/arm64/freescale/imx8mp-evk.dtb"; } diff --git a/nxp/imx8mq-evk/bsp/imx8mq-linux.nix b/nxp/imx8mq-evk/bsp/imx8mq-linux.nix index 5c2fb53..68d5d97 100644 --- a/nxp/imx8mq-evk/bsp/imx8mq-linux.nix +++ b/nxp/imx8mq-evk/bsp/imx8mq-linux.nix @@ -1,56 +1,20 @@ { pkgs, ... }@args: -with pkgs; -buildLinux ( - args - // rec { - version = "6.1.55"; - name = "imx8mq-linux"; +(pkgs.callPackage ../../common/bsp/imx-linux-builder.nix args) { + pname = "imx8mq-linux"; + version = "6.1.55"; - # modDirVersion needs to be x.y.z, will automatically add .0 if needed - modDirVersion = version; + src = pkgs.fetchFromGitHub { + owner = "nxp-imx"; + repo = "linux-imx"; + # tag: lf-6.1.55-2.2.0 + rev = "770c5fe2c1d1529fae21b7043911cd50c6cf087e"; + sha256 = "sha256-tIWt75RUrjB6KmUuAYBVyAC1dmVGSUAgqV5ROJh3xU0="; + }; - defconfig = "imx_v8_defconfig"; + # Platform-specific configuration (if any) + extraConfig = ""; - # https://github.com/NixOS/nixpkgs/pull/366004 - # introduced a breaking change that if a module is declared but it is not being used it will faill. - ignoreConfigErrors = true; - - kernelPatches = [ - ]; - - autoModules = false; - - extraConfig = '' - CRYPTO_TLS m - TLS y - MD_RAID0 m - MD_RAID1 m - MD_RAID10 m - MD_RAID456 m - DM_VERITY m - LOGO y - FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER n - FB_EFI n - EFI_STUB y - EFI y - VIRTIO y - VIRTIO_PCI y - VIRTIO_BLK y - DRM_VIRTIO_GPU y - EXT4_FS y - USBIP_CORE m - USBIP_VHCI_HCD m - USBIP_HOST m - USBIP_VUDC m - ''; - - src = fetchFromGitHub { - owner = "nxp-imx"; - repo = "linux-imx"; - # tag: lf-6.1.55-2.2.0 - rev = "770c5fe2c1d1529fae21b7043911cd50c6cf087e"; - sha256 = "sha256-tIWt75RUrjB6KmUuAYBVyAC1dmVGSUAgqV5ROJh3xU0="; - }; - } - // (args.argsOverride or { }) -) + # https://github.com/NixOS/nixpkgs/pull/366004 + # introduced a breaking change that if a module is declared but it is not being used it will faill. + ignoreConfigErrors = true; +} diff --git a/nxp/imx8mq-evk/bsp/imx8mq-optee-os.nix b/nxp/imx8mq-evk/bsp/imx8mq-optee-os.nix index 73b60a3..3762887 100644 --- a/nxp/imx8mq-evk/bsp/imx8mq-optee-os.nix +++ b/nxp/imx8mq-evk/bsp/imx8mq-optee-os.nix @@ -1,67 +1,13 @@ { pkgs }: -let - python3 = pkgs.buildPackages.python3; - toolchain = pkgs.gcc9Stdenv.cc; - binutils = pkgs.gcc9Stdenv.cc.bintools.bintools_bin; - cpp = pkgs.gcc; -in -pkgs.stdenv.mkDerivation rec { +pkgs.callPackage ../../common/bsp/imx-optee-builder.nix { pname = "imx8mq-optee-os"; version = "lf-6.1.55-2.2.0"; - nativeBuildInputs = [ - python3 - ]; - - enableParallelBuilding = true; - - propagatedBuildInputs = with python3.pkgs; [ - pycryptodomex - pyelftools - cryptography - ]; - src = pkgs.fetchgit { url = "https://github.com/nxp-imx/imx-optee-os.git"; rev = "a303fc80f7c4bd713315687a1fa1d6ed136e78ee"; sha256 = "sha256-OpyG812DX0c06bRZPKWB2cNu6gtZCOvewDhsKgrGB+s="; }; - postPatch = '' - substituteInPlace scripts/arm32_sysreg.py \ - --replace '/usr/bin/env python3' '${python3}/bin/python' - substituteInPlace scripts/gen_tee_bin.py \ - --replace '/usr/bin/env python3' '${python3}/bin/python' - substituteInPlace scripts/pem_to_pub_c.py \ - --replace '/usr/bin/env python3' '${python3}/bin/python' - substituteInPlace ta/pkcs11/scripts/verify-helpers.sh \ - --replace '/bin/bash' '${pkgs.bash}/bin/bash' - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))objcopy" ${binutils}/bin/${toolchain.targetPrefix}objcopy - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))objdump" ${binutils}/bin/${toolchain.targetPrefix}objdump - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))nm" ${binutils}/bin/${toolchain.targetPrefix}nm - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))readelf" ${binutils}/bin/${toolchain.targetPrefix}readelf - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))ar" ${binutils}/bin/${toolchain.targetPrefix}ar - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))cpp" ${cpp}/bin/cpp - ''; - - makeFlags = [ - "PLATFORM=imx" - "PLATFORM_FLAVOR=mx8mqevk" - "CFG_ARM64_core=y" - "CFG_TEE_TA_LOG_LEVEL=0" - "CFG_TEE_CORE_LOG_LEVEL=0" - "CROSS_COMPILE=${toolchain}/bin/${toolchain.targetPrefix}" - "CROSS_COMPILE64=${toolchain}/bin/${toolchain.targetPrefix}" - ]; - - installPhase = '' - mkdir -p $out - cp ./out/arm-plat-imx/core/tee-raw.bin $out/tee.bin - ''; + platformFlavor = "mx8mqevk"; } diff --git a/nxp/imx8mq-evk/bsp/imx8mq-uboot.nix b/nxp/imx8mq-evk/bsp/imx8mq-uboot.nix index 7bb9c2d..9acc1ee 100644 --- a/nxp/imx8mq-evk/bsp/imx8mq-uboot.nix +++ b/nxp/imx8mq-evk/bsp/imx8mq-uboot.nix @@ -1,91 +1,17 @@ -{ - stdenv, - lib, - bison, - dtc, - fetchgit, - flex, - gnutls, - libuuid, - ncurses, - openssl, - which, - perl, - buildPackages, -}: -let - ubsrc = fetchgit { +{ pkgs, fetchgit }: +pkgs.callPackage ../../common/bsp/imx-uboot-builder.nix { + pname = "imx8mq-uboot"; + version = "2023.04"; + + src = fetchgit { url = "https://github.com/nxp-imx/uboot-imx.git"; # tag: "lf-6.1.55-2.2.0" rev = "49b102d98881fc28af6e0a8af5ea2186c1d90a5f"; sha256 = "sha256-1j6X82DqezEizeWoSS600XKPNwrQ4yT0vZuUImKAVVA="; }; -in -(stdenv.mkDerivation { - pname = "imx8mq-uboot"; - version = "2023.04"; - src = ubsrc; - postPatch = '' - patchShebangs tools - patchShebangs scripts - ''; - - nativeBuildInputs = [ - bison - flex - openssl - which - ncurses - libuuid - gnutls - openssl - perl - ]; - - depsBuildBuild = [ buildPackages.stdenv.cc ]; - hardeningDisable = [ "all" ]; - enableParallelBuilding = true; - - makeFlags = [ - "DTC=${lib.getExe buildPackages.dtc}" - "CROSS_COMPILE=${stdenv.cc.targetPrefix}" - ]; - - extraConfig = '' - CONFIG_USE_BOOTCOMMAND=y - CONFIG_BOOTCOMMAND="setenv ramdisk_addr_r 0x45000000; setenv fdt_addr_r 0x44000000; run distro_bootcmd; " - CONFIG_CMD_BOOTEFI_SELFTEST=y - CONFIG_CMD_BOOTEFI=y - CONFIG_EFI_LOADER=y - CONFIG_BLK=y - CONFIG_PARTITIONS=y - CONFIG_DM_DEVICE_REMOVE=n - CONFIG_CMD_CACHE=y - ''; - - passAsFile = [ "extraConfig" ]; - - configurePhase = '' - runHook preConfigure - - make imx8mq_evk_defconfig - cat $extraConfigPath >> .config - - runHook postConfigure - ''; - - installPhase = '' - runHook preInstall - - mkdir -p $out - cp ./u-boot-nodtb.bin $out - cp ./spl/u-boot-spl.bin $out - cp ./arch/arm/dts/imx8mq-evk.dtb $out - cp .config $out - - runHook postInstall - ''; - - dontStrip = true; -}) + defconfig = "imx8mq_evk_defconfig"; + ramdiskAddr = "0x45000000"; + fdtAddr = "0x44000000"; + dtbPath = "./arch/arm/dts/imx8mq-evk.dtb"; +} diff --git a/nxp/imx93-evk/bsp/imx93-linux.nix b/nxp/imx93-evk/bsp/imx93-linux.nix index 6e4cc21..1bdb833 100644 --- a/nxp/imx93-evk/bsp/imx93-linux.nix +++ b/nxp/imx93-evk/bsp/imx93-linux.nix @@ -1,62 +1,24 @@ -{ lib, pkgs, ... }@args: -with pkgs; -buildLinux ( - args - // rec { - version = "6.12.3"; - name = "imx93-linux"; +{ pkgs, ... }@args: +(pkgs.callPackage ../../common/bsp/imx-linux-builder.nix args) { + pname = "imx93-linux"; + version = "6.12.3"; - # modDirVersion needs to be x.y.z, will automatically add .0 if needed - modDirVersion = version; + src = pkgs.fetchFromGitHub { + owner = "nxp-imx"; + repo = "linux-imx"; + # tag: lf-6.12.3 + rev = "37d02f4dcbbe6677dc9f5fc17f386c05d6a7bd7a"; + sha256 = "sha256-1oJMbHR8Ho0zNritEJ+TMOAyYHCW0vwhPkDfLctrZa8="; + }; - defconfig = "imx_v8_defconfig"; + # Platform-specific configuration (if any) + extraConfig = ""; - # https://github.com/NixOS/nixpkgs/pull/366004 - # introduced a breaking change that if a module is declared but it is not being used it will faill. - ignoreConfigErrors = true; + # https://github.com/NixOS/nixpkgs/pull/366004 + # introduced a breaking change that if a module is declared but it is not being used it will faill. + ignoreConfigErrors = true; - kernelPatches = [ - ]; - - autoModules = false; - - extraConfig = '' - CRYPTO_TLS m - TLS y - MD_RAID0 m - MD_RAID1 m - MD_RAID10 m - MD_RAID456 m - DM_VERITY m - LOGO y - FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER n - FB_EFI n - EFI_STUB y - EFI y - VIRTIO y - VIRTIO_PCI y - VIRTIO_BLK y - DRM_VIRTIO_GPU y - EXT4_FS y - USBIP_CORE m - USBIP_VHCI_HCD m - USBIP_HOST m - USBIP_VUDC m - ''; - - src = fetchFromGitHub { - owner = "nxp-imx"; - repo = "linux-imx"; - # tag: lf-6.12.3 - rev = "37d02f4dcbbe6677dc9f5fc17f386c05d6a7bd7a"; - sha256 = "sha256-1oJMbHR8Ho0zNritEJ+TMOAyYHCW0vwhPkDfLctrZa8="; - }; - meta = with lib; { - homepage = "https://github.com/nxp-imx/linux-imx"; - license = [ licenses.gpl2Only ]; - maintainers = with maintainers; [ govindsi ]; - platforms = [ "aarch64-linux" ]; - }; - } - // (args.argsOverride or { }) -) + extraMeta = { + maintainers = with pkgs.lib.maintainers; [ govindsi ]; + }; +} diff --git a/nxp/imx93-evk/bsp/imx93-optee-os.nix b/nxp/imx93-evk/bsp/imx93-optee-os.nix index 75e3dde..a48a5be 100644 --- a/nxp/imx93-evk/bsp/imx93-optee-os.nix +++ b/nxp/imx93-evk/bsp/imx93-optee-os.nix @@ -1,75 +1,17 @@ -{ - lib, - pkgs, -}: -let - inherit (pkgs.buildPackages) python3; - toolchain = pkgs.gccStdenv.cc; - binutils = pkgs.gccStdenv.cc.bintools.bintools_bin; - cpp = pkgs.gcc; -in -pkgs.stdenv.mkDerivation rec { +{ pkgs }: +pkgs.callPackage ../../common/bsp/imx-optee-builder.nix { pname = "imx93-optee-os"; version = "lf-6.12.3_1.0.0"; - nativeBuildInputs = [ - python3 - ]; - - enableParallelBuilding = true; - - propagatedBuildInputs = with python3.pkgs; [ - pycryptodomex - pyelftools - cryptography - ]; - src = pkgs.fetchgit { url = "https://github.com/nxp-imx/imx-optee-os.git"; rev = "8dd180b6d149c1e1314b5869697179f665bd9ca3"; sha256 = "sha256-PoolRscdyeGevrOa5YymPTQ36edVvReMM5WshRTz+uk="; }; - meta = with lib; { - homepage = "https://github.com/nxp-imx/imx-optee-os"; - license = [ licenses.bsd2 ]; - maintainers = with maintainers; [ govindsi ]; - platforms = [ "aarch64-linux" ]; + + platformFlavor = "imx-mx93evk"; + + meta = { + maintainers = with pkgs.lib.maintainers; [ govindsi ]; }; - - postPatch = '' - substituteInPlace scripts/arm32_sysreg.py \ - --replace '/usr/bin/env python3' '${python3}/bin/python' - substituteInPlace scripts/gen_tee_bin.py \ - --replace '/usr/bin/env python3' '${python3}/bin/python' - substituteInPlace scripts/pem_to_pub_c.py \ - --replace '/usr/bin/env python3' '${python3}/bin/python' - substituteInPlace ta/pkcs11/scripts/verify-helpers.sh \ - --replace '/bin/bash' '${pkgs.bash}/bin/bash' - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))objcopy" ${binutils}/bin/${toolchain.targetPrefix}objcopy - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))objdump" ${binutils}/bin/${toolchain.targetPrefix}objdump - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))nm" ${binutils}/bin/${toolchain.targetPrefix}nm - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))readelf" ${binutils}/bin/${toolchain.targetPrefix}readelf - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))ar" ${binutils}/bin/${toolchain.targetPrefix}ar - substituteInPlace mk/gcc.mk \ - --replace "\$(CROSS_COMPILE_\$(sm))cpp" ${cpp}/bin/cpp - ''; - - makeFlags = [ - "PLATFORM=imx-mx93evk" - "CFG_ARM64_core=y" - "CFG_TEE_TA_LOG_LEVEL=0" - "CFG_TEE_CORE_LOG_LEVEL=0" - "CROSS_COMPILE=${toolchain}/bin/${toolchain.targetPrefix}" - "CROSS_COMPILE64=${toolchain}/bin/${toolchain.targetPrefix}" - ]; - - installPhase = '' - mkdir -p $out - cp ./out/arm-plat-imx/core/tee-raw.bin $out/tee.bin - ''; } diff --git a/nxp/imx93-evk/bsp/imx93-uboot.nix b/nxp/imx93-evk/bsp/imx93-uboot.nix index ce91838..9c6f6f9 100644 --- a/nxp/imx93-evk/bsp/imx93-uboot.nix +++ b/nxp/imx93-evk/bsp/imx93-uboot.nix @@ -1,93 +1,17 @@ -{ - stdenv, - lib, - bison, - dtc, - fetchgit, - flex, - gnutls, - libuuid, - ncurses, - openssl, - which, - perl, - buildPackages, - efitools, -}: -let - ubsrc = fetchgit { +{ pkgs, fetchgit }: +pkgs.callPackage ../../common/bsp/imx-uboot-builder.nix { + pname = "imx93-uboot"; + version = "2024.04"; + + src = fetchgit { url = "https://github.com/nxp-imx/uboot-imx.git"; #lf_v2024.04 rev = "e3219a5a73445219df605d1492687918d488055c"; sha256 = "sha256-6pXwgNzq4/XUUEmJ6sGC5pII4J5uMvlDPE9QJxjJJbQ="; }; -in -stdenv.mkDerivation { - pname = "imx93-uboot"; - version = "2024.04"; - src = ubsrc; - postPatch = '' - patchShebangs tools - patchShebangs scripts - ''; - - nativeBuildInputs = [ - bison - flex - openssl - which - ncurses - libuuid - gnutls - openssl - perl - efitools - ]; - - depsBuildBuild = [ buildPackages.stdenv.cc ]; - hardeningDisable = [ "all" ]; - enableParallelBuilding = true; - - makeFlags = [ - "DTC=${lib.getExe buildPackages.dtc}" - "CROSS_COMPILE=${stdenv.cc.targetPrefix}" - ]; - - extraConfig = '' - CONFIG_USE_BOOTCOMMAND=y - CONFIG_BOOTCOMMAND="setenv ramdisk_addr_r 0x85000000; setenv fdt_addr_r 0x84000000; run distro_bootcmd; " - CONFIG_CMD_BOOTEFI_SELFTEST=y - CONFIG_CMD_BOOTEFI=y - CONFIG_EFI_LOADER=y - CONFIG_BLK=y - CONFIG_PARTITIONS=y - CONFIG_DM_DEVICE_REMOVE=n - CONFIG_CMD_CACHE=y - ''; - - passAsFile = [ "extraConfig" ]; - - configurePhase = '' - runHook preConfigure - - make imx93_11x11_evk_defconfig - cat $extraConfigPath >> .config - - runHook postConfigure - ''; - - installPhase = '' - runHook preInstall - - mkdir -p $out - cp ./u-boot-nodtb.bin $out - cp ./spl/u-boot-spl.bin $out - cp ./arch/arm/dts/imx93-11x11-evk.dtb $out - cp .config $out - - runHook postInstall - ''; - - dontStrip = true; + defconfig = "imx93_11x11_evk_defconfig"; + ramdiskAddr = "0x85000000"; + fdtAddr = "0x84000000"; + dtbPath = "./arch/arm/dts/imx93-11x11-evk.dtb"; }