nixos-riscv/lagarto-ox.nix

239 lines
7.1 KiB
Nix
Raw Normal View History

2024-06-25 11:11:05 +02:00
{ config, lib, pkgs, modulesPath, ... }:
{
imports = [
"${modulesPath}/installer/sd-card/sd-image.nix"
];
2024-06-27 11:29:15 +02:00
#nixpkgs.crossSystem = {
# system = "riscv64-linux";
# gcc.arch = "rv64imafd";
2024-07-01 10:14:39 +02:00
# gcc.tune = "generic";
2024-06-27 11:29:15 +02:00
#};
2024-07-01 10:14:39 +02:00
boot.kernelPackages = pkgs.linuxPackages_latest;
2024-06-25 11:11:05 +02:00
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
''
2024-07-01 10:14:39 +02:00
# No vector extensions
+ ''
RISCV_ISA_V n
CONFIG_RISCV_ISA_V_DEFAULT_ENABLE n
''
# Debugging
+ ''
DEBUG_WX y
MAGIC_SYSRQ y
''
2024-06-25 11:11:05 +02:00
;
}
];
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;
};
};
# No network
services.openssh.enable = false;
# Run getty on /dev/console and restartt until it works
systemd.services."serial-getty@console" = {
enable = true;
wantedBy = [ "getty.target" ]; # to start at boot
serviceConfig.Restart = "always";
};
# Disable hvc0 as it is racing for the same console
systemd.services."serial-getty@hvc0" = {
enable = lib.mkForce false;
wantedBy = lib.mkForce [ ];
};
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-07-01 10:14:39 +02:00
# FIXME: Fails on start
busybox = (prev.busybox.override {
Make busybox static Now the problem is inside the busybox binary: [ 43.028000] Run /init as init process [ 43.033300] with arguments: [ 43.037260] /init [ 43.040000] with environment: [ 43.044180] HOME=/ [ 43.047600] TERM=linux [ 43.078020] init[1]: unhandled signal 4 code 0x1 at 0x0000000000010660 in busybox[10000+22d000] [ 43.090080] CPU: 0 PID: 1 Comm: init Not tainted 6.1.62 #1-NixOS [ 43.097580] Hardware name: Barcelona Supercomputing Center - Lagarto Ox (NixOS) (DT) [ 43.106480] epc : 0000000000010660 ra : 0000000000000000 sp : 0000003fd5489db0 [ 43.114780] gp : ffffffff8197ea48 tp : 0000000000000000 t0 : 0000000000000000 [ 43.123080] t1 : 0000000000000000 t2 : 0000000000000000 s0 : 0000000000000000 [ 43.131340] s1 : 0000000000000000 a0 : 0000000000000000 a1 : 0000000000000000 [ 43.139620] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000 [ 43.147900] a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000000000 [ 43.156180] s2 : 0000000000000000 s3 : 0000000000000000 s4 : 0000000000000000 [ 43.164860] s5 : 0000000000000000 s6 : 0000000000000000 s7 : 0000000000000000 [ 43.173140] s8 : 0000000000000000 s9 : 0000000000000000 s10: 0000000000000000 [ 43.181420] s11: 0000000000000000 t3 : 0000000000000000 t4 : 0000000000000000 [ 43.189680] t5 : 0000000000000000 t6 : 0000000000000000 [ 43.196040] status: 0000000200004020 badaddr: 00000000034000ef cause: 0000000000000002 [ 43.208240] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004 [ 43.216340] CPU: 0 PID: 1 Comm: init Not tainted 6.1.62 #1-NixOS [ 43.222940] Hardware name: Barcelona Supercomputing Center - Lagarto Ox (NixOS) (DT) [ 43.231100] Call Trace: [ 43.234000] [<ffffffff800070c4>] dump_backtrace+0x38/0x48 [ 43.240140] [<ffffffff809f063c>] show_stack+0x50/0x68 [ 43.245900] [<ffffffff809fd1f8>] dump_stack_lvl+0x60/0x84 [ 43.252000] [<ffffffff809fd23c>] dump_stack+0x20/0x30 [ 43.257740] [<ffffffff809f0918>] panic+0x160/0x390 [ 43.263200] [<ffffffff80020184>] do_exit+0xa70/0xa78 [ 43.268820] [<ffffffff800203a4>] do_group_exit+0x44/0xb0 [ 43.274780] [<ffffffff80031eec>] get_signal+0x9b4/0xa00 [ 43.280700] [<ffffffff80005ca0>] do_work_pending+0x18c/0x610 [ 43.287020] [<ffffffff80003880>] resume_userspace_slow+0x10/0x14 [ 43.293960] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004 ]---
2024-06-28 15:08:53 +02:00
enableStatic = true;
2024-07-01 10:14:39 +02:00
}).overrideAttrs (old: {
#env.NIX_CFLAGS_COMPILE = "-mtune=generic";
#env.NIX_DEBUG = 5;
});
2024-07-01 11:30:12 +02:00
linuxPackages_latest = prev.linuxPackages_latest;
#linuxPackages_latest = prev.linuxPackages_latest.extend (lib.const (ksuper: {
# kernel = ksuper.kernel.override {
# stdenv = prev.gcc8Stdenv;
# };
#}));
2024-07-01 10:14:39 +02:00
ox-dtb = prev.runCommand "ox.dtb" {
dtsFile = ./ox-plic.dts;
#dtsFile = ./xavi.dts;
nativeBuildInputs = [ prev.buildPackages.dtc ];
} "dtc -O dtb -o $out $dtsFile";
2024-06-25 11:11:05 +02:00
uboot = prev.ubootQemuRiscv64Smode.override {
filesToInstall = [ "u-boot.bin" "u-boot-nodtb.bin" ];
version = "2023.07.02-print-cpu-probe";
src = builtins.fetchGit {
url = "file:///home/Computational/rarias/riscv/u-boot";
2024-06-28 10:39:10 +02:00
rev = "f80a22a480f0e4157647bacf90e663be457c72c4";
};
#patches = [ ./u-boot-debug.patch ];
#
# CONFIG_SERIAL_PRESENT=n
# CONFIG_SYS_NS16550=n
2024-06-25 11:11:05 +02:00
extraConfig = ''
CONFIG_RISCV_ISA_C=n
CONFIG_REQUIRE_SERIAL_CONSOLE=n
CONFIG_SERIAL=y
CONFIG_SERIAL_PUTS=y
CONFIG_SHOW_BOOT_PROGRESS=y
CONFIG_SHOW_REGS=y
CONFIG_LIBCOMMON_SUPPORT=y
CONFIG_SERIAL_SEARCH_ALL=n
CONFIG_SERIAL_PROBE_ALL=n
2024-06-25 11:11:05 +02:00
CONFIG_OF_CONTROL=y
CONFIG_OF_EMBED=y
2024-06-25 11:11:05 +02:00
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
CONFIG_SMP=n
CONFIG_TRACE_EARLY=y
CONFIG_LOG=y
CONFIG_LOGLEVEL=9
CONFIG_LOG_MAX_LEVEL=9
CONFIG_LOG_DEFAULT_LEVEL=9
2024-06-25 11:11:05 +02:00
'';
extraMakeFlags = [
"KCPPFLAGS=-DLOG_DEBUG"
#"EXT_DTB=${final.ox-dtb}"
];
2024-06-25 11:11:05 +02: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 of 3 GiB [0x140000000, 0x200000000)
fdt mknode / pmem@0x140000000
fdt set /pmem@0x140000000 compatible "pmem-region"
fdt set /pmem@0x140000000 reg <0x1 0x40000000 0x0 0xc0000000>
# Reduce memory to 3 GiB [0x80000000, 0x140000000)
fdt set /memory@80000000 reg <0x0 0x80000000 0x0 0xc0000000>
# 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-06-27 11:29:15 +02:00
# Lagarto OX doesn't work with newer versions of OpenSBI (1.3, 1.4), not
# sure why.
opensbi = prev.opensbi.overrideAttrs (old: rec {
version = "1.2"; # ok
#version = "1.3"; # bad
#version = "1.4"; # bad
src = prev.fetchFromGitHub {
owner = "riscv-software-src";
repo = "opensbi";
rev = "v${version}";
hash = "sha256-Zcl+SE2nySMycV/ozsl4AvGipRsMblA5mt3oVZ81Z44="; #1.2
#hash = "sha256-Dr16fVUGLYGnGYHkjAyqpJxt8p95F0CJIU9ESGWKGWo="; #1.3
#hash = "sha256-T8ZeAzjM9aeTXitjE7s+m+jjGGtDo2jK1qO5EuKiVLU="; #1.4
};
#NIX_DEBUG=5;
makeFlags = [
"PLATFORM=fpga/ox_alveo"
#"CONFIG_SBI_ECALL_RFENCE=n"
#"PLATFORM_RISCV_ISA=rv64imafd" # No compressed instructions
#"PLATFORM_RISCV_ISA=rv64g" # No compressed instructions
#"PLATFORM_RISCV_ABI=lp64d"
"FW_PAYLOAD_PATH=${final.uboot}/u-boot.bin"
"FW_FDT_PATH=${final.ox-dtb}"
2024-06-25 11:11:05 +02:00
];
2024-06-27 11:29:15 +02:00
patches = [ ./ox-alveo-platform-plic.patch ];
2024-06-25 11:11:05 +02:00
});
2024-06-27 11:29:15 +02:00
# opensbi = prev.opensbi.overrideAttrs (old: {
# #NIX_DEBUG=5;
# # Compile dts to dtb form
# #nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ prev.buildPackages.dtc ];
# #preBuild = ''
# # dtc -O dtb -o ox.dtb ${./ox.dts}
# #'';
# makeFlags = old.makeFlags ++ [
# "PLATFORM=fpga/sargantana_alveo"
# #"PLATFORM_RISCV_ISA=rv64imafd" # No compressed instructions
# "PLATFORM_RISCV_ISA=rv64g" # No compressed instructions
# #"PLATFORM_RISCV_ABI=lp64d"
# "FW_PAYLOAD_PATH=${final.uboot}/u-boot-nodtb.bin"
# #"FW_FDT_PATH=ox.dtb"
# ];
# patches = [ ./alveo-uart-sbi-hack.patch ];
# });
# opensbi = prev.opensbi.overrideAttrs (old: {
# makeFlags = old.makeFlags ++ [
# "PLATFORM=fpga/openpiton"
# "FW_PAYLOAD_PATH=${final.uboot}/u-boot-nodtb.bin"
# ];
# patches = [ ./opensbi-lagarto-hun.patch ];
# });
2024-06-25 11:11:05 +02:00
}) ];
}