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.
This commit is contained in:
Jörg Thalheim
2025-10-29 16:03:39 +01:00
parent 8b405e9c6d
commit 688ee555de
14 changed files with 398 additions and 598 deletions

View File

@@ -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 ];
};
}

View File

@@ -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
'';
}

View File

@@ -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";
}