nixos-riscv/lagarto-hun.nix

116 lines
3.2 KiB
Nix
Raw Normal View History

2024-03-01 18:33:30 +01:00
{ config, lib, pkgs, modulesPath, ... }:
2024-03-07 12:04:40 +01:00
{
imports = [
"${modulesPath}/installer/sd-card/sd-image.nix"
];
#boot.kernelPackages = pkgs.linuxPackages_latest;
boot = {
kernelPatches = [
{
name = assert false; "sbi-early-console";
patch = null;
extraConfig =
# Early console via SBI
''
RISCV_SBI y
RISCV_SBI_V01 y
SERIAL_EARLYCON y
SERIAL_EARLYCON_RISCV_SBI y
HVC_DRIVER y
HVC_RISCV_SBI y
''
# Allows regions of persistent memory to be described in the device-tree.
+ ''
OF_PMEM y
''
# Allow you to use a contiguous range of reserved memory as one or more
# persistent block devices (/dev/pmem0)
+ ''
LIBNVDIMM y
BLK_DEV_PMEM y
''
;
}
];
initrd = {
# Avoid zstd as we don't have the tools in "cucu" machine
compressor = "gzip";
kernelModules = [ ];
};
loader = {
grub.enable = false;
generic-extlinux-compatible.enable = true;
};
};
sdImage = {
# The image will be loaded as-is in memory, so no compression
compressImage = false;
imageName = "rootfs.img";
# Not needed for now
expandOnBoot = false;
populateFirmwareCommands = "";
populateRootCommands = ''
mkdir -p ./files/boot
${config.boot.loader.generic-extlinux-compatible.populateCmd} \
-c ${config.system.build.toplevel} \
-d ./files/boot
'';
};
nixpkgs.overlays = [ (final: prev: {
2024-03-01 18:33:30 +01:00
uboot = prev.ubootQemuRiscv64Smode.override {
filesToInstall = [ "u-boot.bin" "u-boot-nodtb.bin" ];
extraConfig = ''
CONFIG_RISCV_ISA_C=n
CONFIG_REQUIRE_SERIAL_CONSOLE=n
CONFIG_SERIAL_SEARCH_ALL=y
CONFIG_OF_CONTROL=y
CONFIG_OF_BOARD=y
CONFIG_OF_HAS_PRIOR_STAGE=y
CONFIG_BLKMAP=y
CONFIG_CMD_BLKMAP=y
CONFIG_SBI_V01=y
CONFIG_DEBUG_UART=y
CONFIG_DEBUG_UART_ANNOUNCE=y
CONFIG_DEBUG_SBI_CONSOLE=y
'';
};
2024-03-07 16:49:48 +01:00
uboot-env = let
init = "${config.system.build.toplevel}/init";
initrd = "${config.system.build.initialRamdisk}/initrd";
in prev.runCommand "uboot.txt" {} ''
cat > $out <<EOF
# Create pmem
fdt mknode / pmem@0x180000000
fdt set /pmem@0x180000000 compatible "pmem-region"
fdt set /pmem@0x180000000 reg <0x1 0x80000000 0x0 0x80000000>
# Reduce memory
fdt set /memory@80000000 reg <0x00000000 0x80000000 0x00000001 0x00000000>
# Set kernel options
setenv bootargs "root=/dev/ram0 loglevel=7 debug rw earlycon=sbi boot.trace console=hvc0 init=${init}"
EOF
# Populate the bood commands from the initrd size
echo "# Boot system" >> $out
echo "setenv ramdisk_size $(stat --format %s $(readlink -f ${initrd}))" >> $out
echo 'booti ''${kernel_addr_r} ''${ramdisk_addr_r}:''${ramdisk_size} ''${fdtcontroladdr}' >> $out
'';
2024-03-01 18:33:30 +01:00
opensbi = prev.opensbi.overrideAttrs (old: {
makeFlags = old.makeFlags ++ [
2024-03-07 12:04:40 +01:00
"PLATFORM=fpga/openpiton"
"FW_PAYLOAD_PATH=${final.uboot}/u-boot-nodtb.bin"
2024-03-01 18:33:30 +01:00
];
});
2024-03-07 12:04:40 +01:00
}) ];
2024-03-01 18:33:30 +01:00
}