|
| 1 | +# Parameterized OP-TEE OS builder for i.MX platforms |
| 2 | +# This builder is used across i.MX93, i.MX8MP, i.MX8MQ and similar platforms |
| 3 | +{ |
| 4 | + lib, |
| 5 | + pkgs, |
| 6 | + # Platform-specific parameters |
| 7 | + pname, |
| 8 | + version, |
| 9 | + platformFlavor, |
| 10 | + src, |
| 11 | + # Optional parameters |
| 12 | + meta ? { }, |
| 13 | +}: |
| 14 | +let |
| 15 | + inherit (pkgs.buildPackages) python3; |
| 16 | + toolchain = pkgs.gccStdenv.cc; |
| 17 | + binutils = pkgs.gccStdenv.cc.bintools.bintools_bin; |
| 18 | + cpp = pkgs.gcc; |
| 19 | + |
| 20 | + # Determine PLATFORM and PLATFORM_FLAVOR from platformFlavor |
| 21 | + # Format can be either "imx-mx93evk" (full platform string) or "mx8mpevk" (just flavor, platform is "imx") |
| 22 | + # Check if it starts with "imx-" to determine if it's a full platform string or just a flavor |
| 23 | + hasFullPlatform = lib.hasPrefix "imx-" platformFlavor; |
| 24 | + platform = if hasFullPlatform then platformFlavor else "imx"; |
| 25 | + flavor = if hasFullPlatform then null else platformFlavor; |
| 26 | +in |
| 27 | +pkgs.stdenv.mkDerivation { |
| 28 | + inherit pname version src; |
| 29 | + |
| 30 | + nativeBuildInputs = [ |
| 31 | + python3 |
| 32 | + ]; |
| 33 | + |
| 34 | + enableParallelBuilding = true; |
| 35 | + |
| 36 | + propagatedBuildInputs = with python3.pkgs; [ |
| 37 | + pycryptodomex |
| 38 | + pyelftools |
| 39 | + cryptography |
| 40 | + ]; |
| 41 | + |
| 42 | + # Common postPatch for all i.MX platforms |
| 43 | + # This is the major source of code duplication - ~60 lines of identical substitutions |
| 44 | + postPatch = '' |
| 45 | + # Patch all script shebangs automatically |
| 46 | + patchShebangs scripts/ |
| 47 | + patchShebangs ta/ |
| 48 | +
|
| 49 | + # Patch toolchain paths in mk/gcc.mk |
| 50 | + substituteInPlace mk/gcc.mk \ |
| 51 | + --replace "\$(CROSS_COMPILE_\$(sm))objcopy" ${binutils}/bin/${toolchain.targetPrefix}objcopy |
| 52 | + substituteInPlace mk/gcc.mk \ |
| 53 | + --replace "\$(CROSS_COMPILE_\$(sm))objdump" ${binutils}/bin/${toolchain.targetPrefix}objdump |
| 54 | + substituteInPlace mk/gcc.mk \ |
| 55 | + --replace "\$(CROSS_COMPILE_\$(sm))nm" ${binutils}/bin/${toolchain.targetPrefix}nm |
| 56 | + substituteInPlace mk/gcc.mk \ |
| 57 | + --replace "\$(CROSS_COMPILE_\$(sm))readelf" ${binutils}/bin/${toolchain.targetPrefix}readelf |
| 58 | + substituteInPlace mk/gcc.mk \ |
| 59 | + --replace "\$(CROSS_COMPILE_\$(sm))ar" ${binutils}/bin/${toolchain.targetPrefix}ar |
| 60 | + substituteInPlace mk/gcc.mk \ |
| 61 | + --replace "\$(CROSS_COMPILE_\$(sm))cpp" ${cpp}/bin/cpp |
| 62 | + ''; |
| 63 | + |
| 64 | + makeFlags = |
| 65 | + [ |
| 66 | + "PLATFORM=${platform}" |
| 67 | + ] |
| 68 | + ++ lib.optionals (!hasFullPlatform) [ |
| 69 | + "PLATFORM_FLAVOR=${flavor}" |
| 70 | + ] |
| 71 | + ++ [ |
| 72 | + "CFG_ARM64_core=y" |
| 73 | + "CFG_TEE_TA_LOG_LEVEL=0" |
| 74 | + "CFG_TEE_CORE_LOG_LEVEL=0" |
| 75 | + "CROSS_COMPILE=${toolchain}/bin/${toolchain.targetPrefix}" |
| 76 | + "CROSS_COMPILE64=${toolchain}/bin/${toolchain.targetPrefix}" |
| 77 | + ]; |
| 78 | + |
| 79 | + installPhase = '' |
| 80 | + mkdir -p $out |
| 81 | + cp ./out/arm-plat-imx/core/tee-raw.bin $out/tee.bin |
| 82 | + ''; |
| 83 | + |
| 84 | + meta = { |
| 85 | + homepage = "https://github.com/nxp-imx/imx-optee-os"; |
| 86 | + license = [ lib.licenses.bsd2 ]; |
| 87 | + platforms = [ "aarch64-linux" ]; |
| 88 | + } // meta; |
| 89 | +} |
0 commit comments