2024-07-03 13:58:18 +02:00
|
|
|
{ config, lib, pkgs, modulesPath, self, ... }:
|
2024-06-25 11:11:05 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
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
|
|
|
|
''
|
2024-07-03 14:01:40 +02:00
|
|
|
# Enable console driver
|
|
|
|
+''
|
|
|
|
SERIAL_8250 y
|
|
|
|
SERIAL_8250_CONSOLE y
|
|
|
|
SERIAL_OF_PLATFORM y
|
2024-07-04 11:39:35 +02:00
|
|
|
CONSOLE_POLL y
|
2024-07-03 14:01:40 +02:00
|
|
|
''
|
2024-06-25 11:11:05 +02:00
|
|
|
# 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
|
2024-07-01 18:00:54 +02:00
|
|
|
RISCV_ISA_V_DEFAULT_ENABLE n
|
2024-07-01 10:14:39 +02:00
|
|
|
''
|
|
|
|
# Debugging
|
|
|
|
+ ''
|
2024-07-01 18:00:54 +02:00
|
|
|
DEBUG_KERNEL y
|
|
|
|
DEBUG_MISC y
|
2024-07-01 10:14:39 +02:00
|
|
|
DEBUG_WX y
|
|
|
|
MAGIC_SYSRQ y
|
2024-07-01 18:00:54 +02:00
|
|
|
SYSRQ_SERIAL y
|
|
|
|
DEBUG_VM y
|
|
|
|
SOFTLOCKUP_DETECTOR y
|
|
|
|
SOFTLOCKUP_DETECTOR_INTR_STORM y
|
|
|
|
HARDLOCKUP_DETECTOR y
|
|
|
|
DETECT_HUNG_TASK y
|
|
|
|
WQ_WATCHDOG y
|
|
|
|
WQ_CPU_INTENSIVE_REPORT y
|
2024-07-03 19:35:23 +02:00
|
|
|
TRACING y
|
|
|
|
BOOTTIME_TRACING y
|
2024-07-04 12:45:41 +02:00
|
|
|
STRICT_DEVMEM n
|
2024-07-08 18:27:29 +02:00
|
|
|
BUG n
|
2024-07-01 10:14:39 +02:00
|
|
|
''
|
2024-07-03 19:31:30 +02:00
|
|
|
# Disable SMP so we don't have IPI
|
|
|
|
+ ''
|
|
|
|
SMP n
|
|
|
|
''
|
2024-06-25 11:11:05 +02:00
|
|
|
;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
initrd = {
|
|
|
|
# Avoid zstd as we don't have the tools in "cucu" machine
|
|
|
|
compressor = "gzip";
|
|
|
|
kernelModules = [ ];
|
2024-07-05 12:23:07 +02:00
|
|
|
|
2024-07-08 19:02:01 +02:00
|
|
|
# Add the csrtool to the initrd so we can change the
|
|
|
|
# in-order/out-of-order.
|
|
|
|
extraUtilsCommands = ''
|
|
|
|
cp -a ${pkgs.csrtool}/bin/csrtool $out/bin
|
|
|
|
'';
|
|
|
|
|
2024-07-05 12:23:07 +02:00
|
|
|
# Write a counter to the DMA region, so we can check the kernel is not
|
|
|
|
# dead. Monitor from the host with:
|
|
|
|
# while [ 1 ]; do xxd -s $((0x1bfff0000 - 0x60000000)) \
|
|
|
|
# -l 4 /dev/qdma34000-MM-1; sleep 0.2; done
|
|
|
|
preDeviceCommands = ''
|
|
|
|
echo "Creating a heartbeat counter at 0x1bfff0000"
|
2024-07-05 12:56:33 +02:00
|
|
|
sh -c 'hb=0; while [ 1 ]; do let hb=$hb+1; devmem 0x1bfff0000 32 $hb; done' &
|
2024-07-05 15:15:53 +02:00
|
|
|
''
|
|
|
|
+
|
2024-07-05 15:57:18 +02:00
|
|
|
# Disable proactive compaction. May be better to disable CONFIG_COMPACTION.
|
|
|
|
''
|
|
|
|
echo 0 > /proc/sys/vm/compaction_proactiveness
|
|
|
|
''
|
2024-07-08 08:55:50 +02:00
|
|
|
+
|
|
|
|
# Show stacktrace on calls to the hvc_remove function.
|
|
|
|
''
|
|
|
|
echo "Mount debugfs"
|
|
|
|
mkdir -p /sys/kernel/debug/
|
|
|
|
mount -t debugfs none /sys/kernel/debug/
|
|
|
|
td=/sys/kernel/debug/tracing
|
|
|
|
echo hvc_remove > $td/set_ftrace_filter
|
|
|
|
echo function > $td/current_tracer
|
|
|
|
echo 1 > $td/options/func_stack_trace
|
|
|
|
''
|
2024-07-05 16:23:09 +02:00
|
|
|
# FIXME: Disable sched_switch for now, as it still hangs the boot...
|
|
|
|
# +
|
|
|
|
# # Exclude the second pid, which is the kthread that will dump the trace to
|
|
|
|
# # the console, otherwise we live lock the kernel. Then enable the
|
|
|
|
# # sched_switch events.
|
|
|
|
# ''
|
|
|
|
# echo "Mount debugfs"
|
|
|
|
# mkdir -p /sys/kernel/debug/
|
|
|
|
# mount -t debugfs none /sys/kernel/debug/
|
|
|
|
# echo "Exclude pid 2 from sched"
|
|
|
|
# echo '(prev_pid != 2 && next_pid != 2)' > /sys/kernel/debug/tracing/events/sched/filter
|
|
|
|
# echo "Enable sched_switch events"
|
|
|
|
# echo 1 > /sys/kernel/debug/tracing/events/sched/sched_switch/enable
|
|
|
|
# ''
|
|
|
|
;
|
2024-06-25 11:11:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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-03 13:21:04 +02:00
|
|
|
#busybox = prev.busybox.overrideAttrs (old: {
|
|
|
|
# # Print some debug lines on switch_root to see where it hangs.
|
|
|
|
# patches = (old.patches or []) ++ [ ./busybox-debug.patch ];
|
|
|
|
#});
|
2024-07-01 10:14:39 +02:00
|
|
|
|
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
|
|
|
|
2024-06-27 16:08:30 +02:00
|
|
|
ox-dtb = prev.runCommand "ox.dtb" {
|
2024-06-27 17:58:21 +02:00
|
|
|
dtsFile = ./ox-plic.dts;
|
|
|
|
#dtsFile = ./xavi.dts;
|
2024-06-27 16:08:30 +02:00
|
|
|
nativeBuildInputs = [ prev.buildPackages.dtc ];
|
2024-06-27 17:58:21 +02:00
|
|
|
} "dtc -O dtb -o $out $dtsFile";
|
2024-06-27 16:08:30 +02:00
|
|
|
|
2024-07-08 13:48:20 +02:00
|
|
|
#bitstream = "${final.bitstreams}/lagarto-3-ox/gold.bit";
|
|
|
|
bitstream = "${final.bitstreams}/lagarto-3-ox/ox_u55c_a234c132_two_uarts.bit";
|
2024-07-08 13:32:29 +02:00
|
|
|
|
2024-07-08 17:37:46 +02:00
|
|
|
bootrom = "${final.bitstreams}/lagarto-3-ox/large_bootrom.bin";
|
|
|
|
|
2024-06-25 11:11:05 +02:00
|
|
|
uboot = prev.ubootQemuRiscv64Smode.override {
|
|
|
|
filesToInstall = [ "u-boot.bin" "u-boot-nodtb.bin" ];
|
2024-07-01 12:10:19 +02:00
|
|
|
#version = "2023.07.02-print-cpu-probe";
|
|
|
|
#src = builtins.fetchGit {
|
|
|
|
# url = "file:///home/Computational/rarias/riscv/u-boot";
|
|
|
|
# rev = "f80a22a480f0e4157647bacf90e663be457c72c4";
|
|
|
|
#};
|
2024-06-27 16:08:30 +02:00
|
|
|
#patches = [ ./u-boot-debug.patch ];
|
2024-06-27 17:58:21 +02:00
|
|
|
#
|
|
|
|
# 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
|
2024-06-27 16:08:30 +02:00
|
|
|
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
|
2024-06-27 16:08:30 +02:00
|
|
|
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
|
2024-06-27 16:08:30 +02:00
|
|
|
CONFIG_SMP=n
|
|
|
|
CONFIG_TRACE_EARLY=y
|
2024-07-01 12:10:19 +02:00
|
|
|
''
|
|
|
|
# # Enable debug logs
|
|
|
|
# +
|
|
|
|
# ''
|
|
|
|
# CONFIG_LOG=y
|
|
|
|
# CONFIG_LOGLEVEL=9
|
|
|
|
# CONFIG_LOG_MAX_LEVEL=9
|
|
|
|
# CONFIG_LOG_DEFAULT_LEVEL=9
|
|
|
|
# ''
|
|
|
|
;
|
2024-06-27 16:08:30 +02:00
|
|
|
extraMakeFlags = [
|
2024-07-01 12:10:19 +02:00
|
|
|
#"KCPPFLAGS=-DLOG_DEBUG"
|
2024-06-27 16:08:30 +02:00
|
|
|
#"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";
|
2024-07-03 13:58:18 +02:00
|
|
|
rev = if self ? rev then self.rev
|
|
|
|
else throw ("Refusing to build from a dirty Git tree!");
|
2024-06-25 11:11:05 +02:00
|
|
|
in prev.runCommand "uboot.txt" {} ''
|
|
|
|
cat > $out <<EOF
|
2024-07-03 13:58:18 +02:00
|
|
|
# Git commit: ${rev}
|
|
|
|
|
2024-06-25 11:11:05 +02:00
|
|
|
# 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
|
2024-07-05 15:09:59 +02:00
|
|
|
setenv debugargs "debug1 trace_options=sym-addr trace_event=initcall:* tp_printk trace_buf_size=1M"
|
|
|
|
setenv bootargs "root=/dev/ram0 loglevel=7 debug rw earlycon=sbi boot.trace console=hvc0 \''${debugargs} init=${init}"
|
2024-06-25 11:11:05 +02:00
|
|
|
|
|
|
|
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
|
|
|
opensbi = prev.opensbi.overrideAttrs (old: rec {
|
2024-07-08 10:03:48 +02:00
|
|
|
version = "1.4";
|
|
|
|
src = prev.fetchFromGitHub {
|
|
|
|
owner = "riscv-software-src";
|
|
|
|
repo = "opensbi";
|
|
|
|
rev = "v${version}";
|
|
|
|
hash = "sha256-T8ZeAzjM9aeTXitjE7s+m+jjGGtDo2jK1qO5EuKiVLU=";
|
|
|
|
};
|
2024-06-27 11:29:15 +02:00
|
|
|
#NIX_DEBUG=5;
|
|
|
|
makeFlags = [
|
2024-07-08 10:03:48 +02:00
|
|
|
"PLATFORM=fpga/ox_alveo"
|
2024-06-27 11:29:15 +02:00
|
|
|
#"CONFIG_SBI_ECALL_RFENCE=n"
|
|
|
|
#"PLATFORM_RISCV_ISA=rv64imafd" # No compressed instructions
|
|
|
|
#"PLATFORM_RISCV_ISA=rv64g" # No compressed instructions
|
|
|
|
#"PLATFORM_RISCV_ABI=lp64d"
|
2024-06-27 16:08:30 +02:00
|
|
|
"FW_PAYLOAD_PATH=${final.uboot}/u-boot.bin"
|
2024-06-27 17:58:21 +02:00
|
|
|
"FW_FDT_PATH=${final.ox-dtb}"
|
2024-06-25 11:11:05 +02:00
|
|
|
];
|
2024-07-08 10:03:48 +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
|
|
|
}) ];
|
|
|
|
}
|