2024-03-20 01:58:35 +01:00
|
|
|
{ lib, stdenv, fetchFromGitHub, fetchFromGitLab, openssl, pkgsCross, buildPackages
|
2022-02-08 10:44:21 +01:00
|
|
|
|
2022-05-26 08:49:22 +02:00
|
|
|
# Warning: this blob (hdcp.bin) runs on the main CPU (not the GPU) at
|
|
|
|
# privilege level EL3, which is above both the kernel and the
|
|
|
|
# hypervisor.
|
|
|
|
#
|
|
|
|
# This parameter applies only to platforms which are believed to use
|
|
|
|
# hdcp.bin. On all other platforms, or if unfreeIncludeHDCPBlob=false,
|
|
|
|
# hdcp.bin will be deleted before building.
|
2022-02-08 10:44:21 +01:00
|
|
|
, unfreeIncludeHDCPBlob ? true
|
|
|
|
}:
|
2018-02-24 03:46:39 +01:00
|
|
|
|
|
|
|
let
|
2018-03-20 01:31:31 +01:00
|
|
|
buildArmTrustedFirmware = { filesToInstall
|
2018-02-24 03:46:39 +01:00
|
|
|
, installDir ? "$out"
|
2019-12-05 22:16:06 +01:00
|
|
|
, platform ? null
|
2022-05-26 08:49:22 +02:00
|
|
|
, platformCanUseHDCPBlob ? false # set this to true if the platform is able to use hdcp.bin
|
2018-02-24 03:46:39 +01:00
|
|
|
, extraMakeFlags ? []
|
|
|
|
, extraMeta ? {}
|
|
|
|
, ... } @ args:
|
2022-05-26 08:49:22 +02:00
|
|
|
|
|
|
|
# delete hdcp.bin if either: the platform is thought to
|
|
|
|
# not need it or unfreeIncludeHDCPBlob is false
|
|
|
|
let deleteHDCPBlobBeforeBuild = !platformCanUseHDCPBlob || !unfreeIncludeHDCPBlob; in
|
|
|
|
|
2022-08-03 13:27:36 +02:00
|
|
|
stdenv.mkDerivation (rec {
|
2018-02-24 03:46:39 +01:00
|
|
|
|
2022-01-23 13:39:52 +01:00
|
|
|
pname = "arm-trusted-firmware${lib.optionalString (platform != null) "-${platform}"}";
|
2023-11-25 09:15:10 +01:00
|
|
|
version = "2.10.0";
|
2018-02-24 03:46:39 +01:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "ARM-software";
|
|
|
|
repo = "arm-trusted-firmware";
|
2020-04-22 11:00:10 +02:00
|
|
|
rev = "v${version}";
|
2023-11-25 09:15:10 +01:00
|
|
|
hash = "sha256-CAuftVST9Fje/DWaaoX0K2SfWwlGMaUFG4huuwsTOSU=";
|
2018-02-24 03:46:39 +01:00
|
|
|
};
|
|
|
|
|
2022-05-26 08:49:22 +02:00
|
|
|
patches = lib.optionals deleteHDCPBlobBeforeBuild [
|
2022-02-08 10:44:21 +01:00
|
|
|
# this is a rebased version of https://gitlab.com/vicencb/kevinboot/-/blob/master/atf.patch
|
|
|
|
./remove-hdcp-blob.patch
|
|
|
|
];
|
2022-02-06 01:38:42 +01:00
|
|
|
|
2022-05-26 08:49:22 +02:00
|
|
|
postPatch = lib.optionalString deleteHDCPBlobBeforeBuild ''
|
|
|
|
rm plat/rockchip/rk3399/drivers/dp/hdcp.bin
|
|
|
|
'';
|
|
|
|
|
2018-02-24 03:46:39 +01:00
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
|
|
|
|
2018-12-30 23:39:29 +01:00
|
|
|
# For Cortex-M0 firmware in RK3399
|
|
|
|
nativeBuildInputs = [ pkgsCross.arm-embedded.stdenv.cc ];
|
|
|
|
|
2019-12-05 22:16:06 +01:00
|
|
|
buildInputs = [ openssl ];
|
|
|
|
|
2018-02-24 03:46:39 +01:00
|
|
|
makeFlags = [
|
2023-08-08 01:39:07 +02:00
|
|
|
"HOSTCC=$(CC_FOR_BUILD)"
|
2023-08-08 01:40:16 +02:00
|
|
|
"M0_CROSS_COMPILE=${pkgsCross.arm-embedded.stdenv.cc.targetPrefix}"
|
2018-02-24 03:46:39 +01:00
|
|
|
"CROSS_COMPILE=${stdenv.cc.targetPrefix}"
|
2022-10-09 21:41:22 +02:00
|
|
|
# binutils 2.39 regression
|
|
|
|
# `warning: /build/source/build/rk3399/release/bl31/bl31.elf has a LOAD segment with RWX permissions`
|
|
|
|
# See also: https://developer.trustedfirmware.org/T996
|
|
|
|
"LDFLAGS=-no-warn-rwx-segments"
|
2019-12-05 22:16:06 +01:00
|
|
|
] ++ (lib.optional (platform != null) "PLAT=${platform}")
|
|
|
|
++ extraMakeFlags;
|
2018-02-24 03:46:39 +01:00
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mkdir -p ${installDir}
|
2019-12-05 22:16:06 +01:00
|
|
|
cp ${lib.concatStringsSep " " filesToInstall} ${installDir}
|
2018-02-24 03:46:39 +01:00
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
hardeningDisable = [ "all" ];
|
|
|
|
dontStrip = true;
|
|
|
|
|
2018-03-23 18:03:26 +01:00
|
|
|
# Fatal error: can't create build/sun50iw1p1/release/bl31/sunxi_clocks.o: No such file or directory
|
|
|
|
enableParallelBuilding = false;
|
2018-02-24 03:46:39 +01:00
|
|
|
|
2019-12-05 22:16:06 +01:00
|
|
|
meta = with lib; {
|
2020-04-01 03:11:51 +02:00
|
|
|
homepage = "https://github.com/ARM-software/arm-trusted-firmware";
|
2018-02-24 03:46:39 +01:00
|
|
|
description = "Reference implementation of secure world software for ARMv8-A";
|
2022-05-26 08:49:22 +02:00
|
|
|
license = [ licenses.bsd3 ] ++ lib.optionals (!deleteHDCPBlobBeforeBuild) [ licenses.unfreeRedistributable ];
|
2020-04-22 11:00:10 +02:00
|
|
|
maintainers = with maintainers; [ lopsided98 ];
|
2018-02-24 03:46:39 +01:00
|
|
|
} // extraMeta;
|
|
|
|
} // builtins.removeAttrs args [ "extraMeta" ]);
|
|
|
|
|
2019-08-13 23:52:01 +02:00
|
|
|
in {
|
2018-02-24 03:46:39 +01:00
|
|
|
inherit buildArmTrustedFirmware;
|
|
|
|
|
2019-12-05 22:16:06 +01:00
|
|
|
armTrustedFirmwareTools = buildArmTrustedFirmware rec {
|
2023-08-09 14:20:15 +02:00
|
|
|
# Normally, arm-trusted-firmware builds the build tools for buildPlatform
|
|
|
|
# using CC_FOR_BUILD (or as it calls it HOSTCC). Since want to build them
|
|
|
|
# for the hostPlatform here, we trick it by overriding the HOSTCC setting
|
|
|
|
# and, to be safe, remove CC_FOR_BUILD from the environment.
|
|
|
|
depsBuildBuild = [ ];
|
2019-12-05 22:16:06 +01:00
|
|
|
extraMakeFlags = [
|
|
|
|
"HOSTCC=${stdenv.cc.targetPrefix}gcc"
|
2022-12-04 21:29:06 +01:00
|
|
|
"fiptool" "certtool"
|
2019-12-05 22:16:06 +01:00
|
|
|
];
|
|
|
|
filesToInstall = [
|
|
|
|
"tools/fiptool/fiptool"
|
|
|
|
"tools/cert_create/cert_create"
|
|
|
|
];
|
|
|
|
postInstall = ''
|
|
|
|
mkdir -p "$out/bin"
|
|
|
|
find "$out" -type f -executable -exec mv -t "$out/bin" {} +
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-12-11 02:54:11 +01:00
|
|
|
armTrustedFirmwareAllwinner = buildArmTrustedFirmware rec {
|
2019-05-18 19:40:16 +02:00
|
|
|
platform = "sun50i_a64";
|
2018-03-20 01:31:31 +01:00
|
|
|
extraMeta.platforms = ["aarch64-linux"];
|
2017-12-11 02:54:11 +01:00
|
|
|
filesToInstall = ["build/${platform}/release/bl31.bin"];
|
2021-06-05 01:20:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
armTrustedFirmwareAllwinnerH616 = buildArmTrustedFirmware rec {
|
|
|
|
platform = "sun50i_h616";
|
|
|
|
extraMeta.platforms = ["aarch64-linux"];
|
|
|
|
filesToInstall = ["build/${platform}/release/bl31.bin"];
|
2017-12-11 02:54:11 +01:00
|
|
|
};
|
|
|
|
|
2023-04-05 22:41:15 +02:00
|
|
|
armTrustedFirmwareAllwinnerH6 = buildArmTrustedFirmware rec {
|
|
|
|
platform = "sun50i_h6";
|
|
|
|
extraMeta.platforms = ["aarch64-linux"];
|
|
|
|
filesToInstall = ["build/${platform}/release/bl31.bin"];
|
|
|
|
};
|
|
|
|
|
2017-12-11 02:54:11 +01:00
|
|
|
armTrustedFirmwareQemu = buildArmTrustedFirmware rec {
|
|
|
|
platform = "qemu";
|
2018-03-20 01:31:31 +01:00
|
|
|
extraMeta.platforms = ["aarch64-linux"];
|
2017-12-11 02:54:11 +01:00
|
|
|
filesToInstall = [
|
|
|
|
"build/${platform}/release/bl1.bin"
|
|
|
|
"build/${platform}/release/bl2.bin"
|
|
|
|
"build/${platform}/release/bl31.bin"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2018-02-24 03:46:39 +01:00
|
|
|
armTrustedFirmwareRK3328 = buildArmTrustedFirmware rec {
|
|
|
|
extraMakeFlags = [ "bl31" ];
|
|
|
|
platform = "rk3328";
|
2018-03-20 01:31:31 +01:00
|
|
|
extraMeta.platforms = ["aarch64-linux"];
|
2018-02-24 03:46:39 +01:00
|
|
|
filesToInstall = [ "build/${platform}/release/bl31/bl31.elf"];
|
|
|
|
};
|
2018-12-30 23:39:29 +01:00
|
|
|
|
|
|
|
armTrustedFirmwareRK3399 = buildArmTrustedFirmware rec {
|
|
|
|
extraMakeFlags = [ "bl31" ];
|
|
|
|
platform = "rk3399";
|
|
|
|
extraMeta.platforms = ["aarch64-linux"];
|
|
|
|
filesToInstall = [ "build/${platform}/release/bl31/bl31.elf"];
|
2022-05-26 08:49:22 +02:00
|
|
|
platformCanUseHDCPBlob = true;
|
2018-12-30 23:39:29 +01:00
|
|
|
};
|
2019-12-05 22:17:36 +01:00
|
|
|
|
2024-03-20 01:58:35 +01:00
|
|
|
armTrustedFirmwareRK3588 = buildArmTrustedFirmware rec {
|
|
|
|
extraMakeFlags = [ "bl31" ];
|
|
|
|
platform = "rk3588";
|
|
|
|
extraMeta.platforms = ["aarch64-linux"];
|
|
|
|
filesToInstall = [ "build/${platform}/release/bl31/bl31.elf"];
|
|
|
|
|
|
|
|
# TODO: remove this once the following get merged:
|
|
|
|
# 1: https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/21840
|
|
|
|
# 2: https://review.trustedfirmware.org/c/ci/tf-a-ci-scripts/+/21833
|
|
|
|
src = fetchFromGitLab {
|
|
|
|
domain = "gitlab.collabora.com";
|
|
|
|
owner = "hardware-enablement/rockchip-3588";
|
|
|
|
repo = "trusted-firmware-a";
|
|
|
|
rev = "002d8e85ce5f4f06ebc2c2c52b4923a514bfa701";
|
|
|
|
hash = "sha256-1XOG7ILIgWa3uXUmAh9WTfSGLD/76OsmWrUhIxm/zTg=";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-12-05 22:17:36 +01:00
|
|
|
armTrustedFirmwareS905 = buildArmTrustedFirmware rec {
|
|
|
|
extraMakeFlags = [ "bl31" ];
|
|
|
|
platform = "gxbb";
|
|
|
|
extraMeta.platforms = ["aarch64-linux"];
|
|
|
|
filesToInstall = [ "build/${platform}/release/bl31.bin"];
|
|
|
|
};
|
2018-02-24 03:46:39 +01:00
|
|
|
}
|