2024-04-07 13:42:03 -04:00
|
|
|
{ buildPackages
|
2024-03-30 20:45:46 -04:00
|
|
|
, fetchFromGitHub
|
|
|
|
, fetchpatch
|
|
|
|
, linux-firmware
|
2024-04-07 13:42:03 -04:00
|
|
|
, buildGoModule
|
2024-03-30 20:45:46 -04:00
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
|
|
|
|
# Based on
|
|
|
|
# https://github.com/sophgo/bootloader-riscv/blob/e0839852d571df106db622611f4786ae17e8df0f/scripts/envsetup.sh#L809-L819
|
2024-04-07 13:42:03 -04:00
|
|
|
let
|
|
|
|
u-root = buildPackages.buildGoModule rec {
|
|
|
|
pname = "u-root";
|
|
|
|
version = "0.14.0";
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "u-root";
|
|
|
|
repo = "u-root";
|
|
|
|
rev = "v${version}";
|
|
|
|
hash = "sha256-8zA3pHf45MdUcq/MA/mf0KCTxB1viHieU/oigYwIPgo=";
|
|
|
|
};
|
|
|
|
vendorHash = null;
|
|
|
|
patches = [
|
|
|
|
(fetchpatch {
|
2024-03-30 20:45:46 -04:00
|
|
|
url = "https://github.com/sophgo/bootloader-riscv/commit/322c3305763872a9b88a1c85d79bca63b8fbe7a6.patch";
|
|
|
|
hash = "sha256-l5r3DbcMqRYD5FhRBqtEIEscZAdDvjmQJE4BIAtWYWE=";
|
|
|
|
stripLen = 1;
|
2024-04-07 13:42:03 -04:00
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
cp -r . $out/src
|
|
|
|
'';
|
|
|
|
|
|
|
|
# We only build the u-root binary in the build phase and the initrd in the
|
|
|
|
# postBuild hook.
|
|
|
|
subPackages = [ "." ];
|
2024-03-30 20:45:46 -04:00
|
|
|
|
2024-04-07 13:42:03 -04:00
|
|
|
# Tests time out after 10min for native riscv64 builds on the pioneer.
|
|
|
|
doCheck = false;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
buildGoModule {
|
|
|
|
name = "linuxboot-initrd";
|
|
|
|
src = null;
|
|
|
|
vendorHash = null;
|
|
|
|
dontUnpack = true;
|
|
|
|
nativeBuildInputs = [ u-root ];
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
pushd ${u-root}/src
|
|
|
|
mkdir -p $out
|
|
|
|
GOROOT="$(go env GOROOT)" u-root \
|
2024-03-30 20:45:46 -04:00
|
|
|
-build bb \
|
|
|
|
-uinitcmd=boot \
|
|
|
|
-files "${linux-firmware}/lib/firmware/amdgpu/:lib/firmware/amdgpu/" \
|
|
|
|
-files "${linux-firmware}/lib/firmware/radeon/:lib/firmware/radeon/" \
|
2024-04-07 13:42:03 -04:00
|
|
|
-o $out/initramfs.cpio \
|
2024-03-30 20:45:46 -04:00
|
|
|
core boot
|
2024-04-07 13:42:03 -04:00
|
|
|
popd
|
2024-03-30 20:45:46 -04:00
|
|
|
|
|
|
|
# The vendor does not compress the initrd. We do since we include more
|
|
|
|
# firmware files. CRC32 is required by the kernel's decompressor.
|
2024-04-07 13:42:03 -04:00
|
|
|
xz --check=crc32 $out/initramfs.cpio
|
|
|
|
runHook postBuild
|
2024-03-30 20:45:46 -04:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
2024-04-07 13:42:03 -04:00
|
|
|
runHook preInstall
|
|
|
|
mv $out/initramfs.cpio.xz $out/initrd.img
|
|
|
|
runHook postInstall
|
2024-03-30 20:45:46 -04:00
|
|
|
'';
|
|
|
|
}
|