2023-12-25 21:14:17 +01:00
|
|
|
{ config, pkgs, modulesPath, ... }:
|
2023-04-16 22:43:32 +02:00
|
|
|
|
2023-06-08 20:24:13 +02:00
|
|
|
let firmware = pkgs.callPackage ./firmware.nix { };
|
2023-04-16 22:43:32 +02:00
|
|
|
in {
|
|
|
|
imports = [
|
|
|
|
"${modulesPath}/profiles/base.nix"
|
|
|
|
"${modulesPath}/installer/sd-card/sd-image.nix"
|
|
|
|
./default.nix
|
|
|
|
];
|
|
|
|
|
|
|
|
sdImage = {
|
|
|
|
imageName =
|
|
|
|
"${config.sdImage.imageBaseName}-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}-starfive-visionfive2.img";
|
|
|
|
|
|
|
|
# Overridden by postBuildCommands
|
|
|
|
populateFirmwareCommands = "";
|
|
|
|
|
|
|
|
firmwarePartitionOffset = 4;
|
|
|
|
firmwareSize = 4;
|
|
|
|
|
|
|
|
postBuildCommands = ''
|
|
|
|
# preserve root partition
|
|
|
|
eval $(partx $img -o START,SECTORS --nr 2 --pairs)
|
|
|
|
|
|
|
|
# increase image size for gpt backup header
|
|
|
|
truncate -s '+2M' $img
|
|
|
|
|
|
|
|
sfdisk $img <<EOF
|
|
|
|
label: gpt
|
|
|
|
unit: sectors
|
|
|
|
sector-size: 512
|
|
|
|
|
|
|
|
start=4096, size=4096, type=2E54B353-1271-4842-806F-E436D6AF6985
|
|
|
|
start=8192, size=8192, type=5B193300-FC78-40CD-8002-E86C45580B47
|
|
|
|
start=$START, size=$SECTORS, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, attrs="LegacyBIOSBootable"
|
|
|
|
EOF
|
|
|
|
|
|
|
|
eval $(partx $img -o START,SECTORS --nr 1 --pairs)
|
2024-01-01 04:50:15 +01:00
|
|
|
dd conv=notrunc if=${firmware.uboot}/u-boot-spl.bin.normal.out of=$img seek=$START count=$SECTORS
|
2023-04-16 22:43:32 +02:00
|
|
|
|
|
|
|
eval $(partx $img -o START,SECTORS --nr 2 --pairs)
|
2024-01-01 04:50:15 +01:00
|
|
|
dd conv=notrunc if=${firmware.uboot}/u-boot.itb of=$img seek=$START count=$SECTORS
|
2023-04-16 22:43:32 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
populateRootCommands = ''
|
|
|
|
mkdir -p ./files/boot
|
|
|
|
${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
|
|
|
|
'';
|
|
|
|
};
|
2023-06-08 20:24:13 +02:00
|
|
|
|
|
|
|
environment.systemPackages = [ firmware.updater-flash ];
|
2023-04-16 22:43:32 +02:00
|
|
|
}
|