nixos-riscv/overlay.nix
Rodrigo Arias Mallo 3707e5708e Disable EFI in the kernel and use normal stdenv
In order to build the kernel without compressed instructions we need to
disable EFI support. We also need to leave the kernel to figure the
proper -march and -mabi flags, as otherwise it fails to build. Using the
option "CONFIG_RISCV_ISA_C n" disables the use of compressed
instructions.
2024-01-22 13:37:00 +01:00

93 lines
2.9 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

final: prev:
# Changes to packages from nixpkgs
{
opensbi = prev.opensbi.overrideAttrs (old: {
makeFlags = old.makeFlags ++ [
# Build OpenSBI without compressed instructions
"PLATFORM_RISCV_ISA=rv64gv"
# Check with: riscv64-unknown-elf-objdump -d -M no-aliases rotate
];
});
# Fix GCC 13 format-overflow warning/error:
# ../src/shared/install.c:444:64: error: %s directive argument is null [-Werror=format-overflow=]
# 444 | err = log_error_errno(changes[i].type, "Failed to %s unit, unit %s does not exist.",
# | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
systemd = prev.systemd.overrideAttrs (old: {
CFLAGS = "-Wno-error=format-overflow";
});
qemu = prev.qemu.override { rutabagaSupport = false; };
uboot-custom = prev.ubootQemuRiscv64Smode.override {
# Override preboot to set 'bootcmd' directly to the kernel address in RAM
extraConfig = ''
CONFIG_PREBOOT="setenv fdt_addr ''${fdtcontroladdr}; fdt addr ''${fdtcontroladdr}; setenv bootcmd booti ''${kernel_addr_r} - ''${fdtcontroladdr};"
CONFIG_RISCV_ISA_C=n
'';
# Also include debug u-boot
filesToInstall = ["u-boot.bin" "u-boot"];
};
# To cross compile for riscv64, we need to populate this env variable, not
# NIX_CFLAGS_COMPILE, otherwise we affect the packages for x86.
stdenv = if prev.stdenv.buildPlatform != prev.stdenv.hostPlatform
then
prev.stdenvAdapters.addAttrsToDerivation {
NIX_CFLAGS_COMPILE_riscv64_unknown_linux_gnu = "-march=rv64g";
} prev.stdenv
else
prev.stdenv;
opensbi-uboot = prev.opensbi.overrideAttrs (old: {
makeFlags = old.makeFlags ++ [
# Build OpenSBI without compressed instructions
"PLATFORM_RISCV_ISA=rv64gv"
# Check with: riscv64-unknown-elf-objdump -d -M no-aliases rotate
"FW_PAYLOAD_PATH=${final.uboot-custom}/u-boot.bin"
];
});
linuxPackagesCustom = prev.linuxPackagesFor (prev.linux.override {
# Don't use a compiler without compressed instructions, let the kernel
# configure the -march and -mabi arguments.
stdenv = prev.stdenv;
structuredExtraConfig = with prev.lib.kernel; {
KEXEC = yes;
SERIAL_8250_DW = yes;
PINCTRL_STARFIVE = yes;
# Doesn't build as a module
DW_AXI_DMAC_STARFIVE = yes;
# stmmac hangs when built as a module
#PTP_1588_CLOCK = yes;
#STMMAC_ETH = yes;
#STMMAC_PCI = yes;
# For qemu
BLOCK = yes;
BLK_DEV = yes;
DEVTMPFS = yes;
VIRTIO_MENU = yes;
VIRTIO_BLK = yes;
# For 9P: https://wiki.qemu.org/Documentation/9psetup
NET_9P = yes;
NET_9P_VIRTIO = yes;
NET_9P_DEBUG = yes;
"9P_FS" = yes;
"9P_FS_POSIX_ACL" = yes;
PCI = yes;
VIRTIO_PCI = yes;
PCI_HOST_GENERIC = yes;
RISCV_ISA_C = no;
NONPORTABLE = yes;
EFI = no;
};
});
}