This commit is contained in:
Rodrigo Arias 2024-05-28 18:12:14 +02:00
parent f69e04ccbe
commit f554a154b7
10 changed files with 341 additions and 38 deletions

View File

@ -6,14 +6,19 @@
#"${modulesPath}/profiles/minimal.nix" #"${modulesPath}/profiles/minimal.nix"
]; ];
nixpkgs.crossSystem = { nixpkgs = {
crossSystem = {
system = "riscv64-linux"; system = "riscv64-linux";
}; };
nixpkgs.overlays = [ overlays = [
self.inputs.bscpkgs.bscOverlay self.inputs.bscpkgs.bscOverlay
(import ./overlay.nix)
]; ];
config.allowUnsupportedSystem = true;
};
networking.hostName = "nixos-riscv"; networking.hostName = "nixos-riscv";
system.stateVersion = "24.05"; system.stateVersion = "24.05";
@ -31,4 +36,5 @@
}; };
#environment.systemPackages = with pkgs; [ vim gdb neofetch gcc bintools ]; #environment.systemPackages = with pkgs; [ vim gdb neofetch gcc bintools ];
environment.systemPackages = with pkgs; [ rvb unalignedCheck ];
} }

View File

@ -5,10 +5,10 @@
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
}, },
"locked": { "locked": {
"dirtyRev": "e605f7dfad67a6bf15c1f1ff83e0c8a1c9ee42b9-dirty", "dirtyRev": "15c8a61d1787d52f904755bee9b1840ce8823525-dirty",
"dirtyShortRev": "e605f7d-dirty", "dirtyShortRev": "15c8a61-dirty",
"lastModified": 1715179381, "lastModified": 1715619485,
"narHash": "sha256-487pg/odvGPcEVpCBDS3gVmK/4o3Yv7S/uvI2HYECGM=", "narHash": "sha256-zgwnjGVBXTvItXIYtaMIdf2acHiNQOJ6Fba4OFZRYT4=",
"type": "git", "type": "git",
"url": "file:///home/Computational/rarias/bscpkgs" "url": "file:///home/Computational/rarias/bscpkgs"
}, },
@ -32,17 +32,17 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1706092046, "lastModified": 1700390070,
"narHash": "sha256-Cbethl95Cu+WVIWfaAnRRBZiz5PmXxQvg4vXNqIZQUg=", "narHash": "sha256-de9KYi8rSJpqvBfNwscWdalIJXPo8NjdIZcEJum1mH0=",
"owner": "rodarima", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "57e7c8fa4fdc414a936ce83afd0c70fb0a3a31d5", "rev": "e4ad989506ec7d71f7302cc3067abd82730a4beb",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "rodarima", "owner": "NixOS",
"ref": "fix-pkgs-static-gcc-march",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "e4ad989506ec7d71f7302cc3067abd82730a4beb",
"type": "github" "type": "github"
} }
}, },

View File

@ -1,19 +1,33 @@
{ {
inputs.nixpkgs.url = "github:rodarima/nixpkgs/fix-pkgs-static-gcc-march"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/e4ad989506ec7d71f7302cc3067abd82730a4beb";
#inputs.bscpkgs.url = "path:/home/Computational/rarias/bscpkgs"; #inputs.bscpkgs.url = "path:/home/Computational/rarias/bscpkgs";
inputs.bscpkgs.url = "/home/Computational/rarias/bscpkgs"; inputs.bscpkgs.url = "/home/Computational/rarias/bscpkgs";
outputs = { self, nixpkgs, bscpkgs, ... }: outputs = {self,...}@inputs:
let let
system = "x86_64-linux"; system = "x86_64-linux";
#overlay = import ./overlay.nix; remoteNixpkgsPatches = [
#pkgs = import nixpkgs { inherit system; }; {
meta.description = "sha256-ZCDQ7SpGhH8JvAwWzdcyrc68RFEWHxxAj0M2+AvEzIg=";
url = "https://github.com/NixOS/nixpkgs/pull/283460.diff";
sha256 = "sha256-g6o4rqkOOYZ6OJTzv9kTPq9Zsu5Z1QXZmPLC3Q7Sq6w=";
}
];
originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
nixpkgs = originPkgs.applyPatches {
name = "nixpkgs-patched";
src = inputs.nixpkgs;
patches = map originPkgs.fetchpatch remoteNixpkgsPatches;
};
nixosSystem = import (nixpkgs + "/nixos/lib/eval-config.nix");
in { in {
#overlay = import ./overlay.nix; #overlay = import ./overlay.nix;
nixosConfigurations = { nixosConfigurations = {
# The qemu configuration defines a system that runs in the RISC-V # The qemu configuration defines a system that runs in the RISC-V
# architecture, but is build from an x86 host machine. # architecture, but is build from an x86 host machine.
qemu = nixpkgs.lib.nixosSystem { qemu = nixosSystem {
specialArgs = { inherit self; }; specialArgs = { inherit self; };
system = "${system}"; system = "${system}";
modules = [ modules = [
@ -23,7 +37,7 @@
}; };
# Same, but disable compressed instructions # Same, but disable compressed instructions
qemu-nc = nixpkgs.lib.nixosSystem { qemu-nc = nixosSystem {
specialArgs = { inherit self; }; specialArgs = { inherit self; };
system = "${system}"; system = "${system}";
modules = [ modules = [
@ -34,7 +48,7 @@
}; };
# FPGA Lagarto Hun CPU # FPGA Lagarto Hun CPU
lagarto-hun = nixpkgs.lib.nixosSystem { lagarto-hun = nixosSystem {
specialArgs = { inherit self; }; specialArgs = { inherit self; };
system = "${system}"; system = "${system}";
modules = [ modules = [
@ -54,7 +68,7 @@
toplevel = nixosconf.config.system.build.toplevel; toplevel = nixosconf.config.system.build.toplevel;
in syspkgs.mkShell { in syspkgs.mkShell {
pname = "qemu-shell"; pname = "qemu-shell";
buildInputs = with syspkgs; [ qemu e2fsprogs ]; nativeBuildInputs = with syspkgs; [ qemu e2fsprogs ];
# Here we tell the run script where to find the system # Here we tell the run script where to find the system
NIXOS_SYSTEM_TOPLEVEL = toplevel; NIXOS_SYSTEM_TOPLEVEL = toplevel;
OPENSBI = syspkgs.opensbi-uboot; OPENSBI = syspkgs.opensbi-uboot;

View File

@ -273,7 +273,7 @@ verbose=
bootloader_addr=0x80000000 bootloader_addr=0x80000000
kernel_addr=0x84000000 kernel_addr=0x84000000
initrd_addr=0x8c300000 initrd_addr=0x8c300000
rootfs_addr=0x180000000 rootfs_addr=0x140000000
function usage() function usage()
{ {

View File

@ -5,6 +5,10 @@ set -x
dst=femu:nixos/ dst=femu:nixos/
if [ "$1" != "" ]; then
dst="$1"
fi
rsync -a fpga/fpgactl "$dst" rsync -a fpga/fpgactl "$dst"
rsync -a fpga/boot.sh "$dst" rsync -a fpga/boot.sh "$dst"
rsync -a fpga/env.sh "$dst" rsync -a fpga/env.sh "$dst"

View File

@ -102,13 +102,13 @@
initrd = "${config.system.build.initialRamdisk}/initrd"; initrd = "${config.system.build.initialRamdisk}/initrd";
in prev.runCommand "uboot.txt" {} '' in prev.runCommand "uboot.txt" {} ''
cat > $out <<EOF cat > $out <<EOF
# Create pmem # Create pmem of 3 GiB [0x140000000, 0x200000000)
fdt mknode / pmem@0x180000000 fdt mknode / pmem@0x140000000
fdt set /pmem@0x180000000 compatible "pmem-region" fdt set /pmem@0x140000000 compatible "pmem-region"
fdt set /pmem@0x180000000 reg <0x1 0x80000000 0x0 0x80000000> fdt set /pmem@0x140000000 reg <0x1 0x40000000 0x0 0xc0000000>
# Reduce memory # Reduce memory to 3 GiB [0x80000000, 0x140000000)
fdt set /memory@80000000 reg <0x00000000 0x80000000 0x00000001 0x00000000> fdt set /memory@80000000 reg <0x0 0x80000000 0x0 0xc0000000>
# Set kernel options # Set kernel options
setenv bootargs "root=/dev/ram0 loglevel=7 debug rw earlycon=sbi boot.trace console=hvc0 init=${init}" setenv bootargs "root=/dev/ram0 loglevel=7 debug rw earlycon=sbi boot.trace console=hvc0 init=${init}"

View File

@ -1,9 +1,9 @@
--- a/platform/fpga/openpiton/platform.c 2024-03-12 16:27:13.886525365 +0100 --- a/platform/fpga/openpiton/platform.c 2024-03-12 16:27:13.886525365 +0100
+++ b/platform/fpga/openpiton/platform.c 2024-03-12 16:28:40.598403778 +0100 +++ b/platform/fpga/openpiton/platform.c 2024-05-27 11:42:47.748244398 +0200
@@ -26,8 +26,8 @@ @@ -24,8 +24,8 @@
#define OPENPITON_DEFAULT_UART_REG_WIDTH 1
#define OPENPITON_DEFAULT_UART_REG_OFFSET 0
#define OPENPITON_DEFAULT_PLIC_ADDR 0xfff1100000 #define OPENPITON_DEFAULT_PLIC_ADDR 0xfff1100000
#define OPENPITON_DEFAULT_PLIC_SIZE (0x200000 + \
(OPENPITON_DEFAULT_HART_COUNT * 0x1000))
-#define OPENPITON_DEFAULT_PLIC_NUM_SOURCES 2 -#define OPENPITON_DEFAULT_PLIC_NUM_SOURCES 2
-#define OPENPITON_DEFAULT_HART_COUNT 3 -#define OPENPITON_DEFAULT_HART_COUNT 3
+#define OPENPITON_DEFAULT_PLIC_NUM_SOURCES 3 +#define OPENPITON_DEFAULT_PLIC_NUM_SOURCES 3

View File

@ -3,5 +3,37 @@ final: prev:
# Changes to packages from nixpkgs # Changes to packages from nixpkgs
{ {
blis = ((prev.blis.override {
blas64 = true;
withArchitecture = "generic";
}).overrideAttrs (old: {
nativeBuildInputs = (old.nativeBuildInputs or []) ++ [
prev.buildPackages.gfortran
];
})).overrideDerivation (old : {
configureFlags = [
"--enable-cblas"
"--blas-int-size=64"
"--enable-threading=openmp"
#"--build=x86_64-unknown-linux-gnu"
#"--host=riscv64-unknown-linux-gnu"
"generic"
];
});
unalignedCheck = prev.stdenv.mkDerivation {
name = "unaligned-check";
src = ./unalign.c;
unpackPhase = ''
cp ${./unalign.c} unalign.c
'';
dontConfigure = true;
buildPhase = ''
$CC unalign.c -o unalign_check
'';
installPhase = ''
mkdir -p $out/bin
cp unalign_check $out/bin/
'';
};
} }

239
unalign.c Normal file
View File

@ -0,0 +1,239 @@
/*
* unalign_check - check the CPU behaviour on different alignments
* Copyright (C) 2021 Matteo Croce <mcroce@linux.microsoft.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <time.h>
#include <sys/mman.h>
#define ACT_READ 0
#define ACT_WRITE 1
#define ACT_XOR 2
#define ACT_COPY 3
#define READ(SIZE) \
case SIZE / 8: { \
volatile uint##SIZE##_t *buf2 = (uint##SIZE##_t *)buf; \
int i; \
for (i = 0; i < count; i++) \
(void)buf2[i]; \
break; \
}
#define WRITE(SIZE) \
case SIZE / 8: { \
volatile uint##SIZE##_t *buf2 = (uint##SIZE##_t *)buf; \
int i; \
for (i = 0; i < count; i++) \
buf2[i] = (uint##SIZE##_t)0xaabbccdd11223344; \
break; \
}
#define XOR(SIZE) \
case SIZE / 8: { \
volatile uint##SIZE##_t *buf2 = (uint##SIZE##_t *)buf; \
int i; \
for (i = 0; i < count; i++) \
buf2[i] = ~buf2[i]; \
break; \
}
#define COPY(SIZE) \
case SIZE / 8: { \
volatile uint##SIZE##_t *buf2 = (uint##SIZE##_t *)buf; \
int i; \
for (i = 0; i < count / 2; i++) \
buf2[i] = buf2[i + count / 2]; \
for (i = count / 2; i < count; i++) \
buf2[i] = buf2[i - count / 2]; \
break; \
}
static void do_read(void *buf, size_t count, int size)
{
switch (size) {
READ(8);
READ(16);
READ(32);
READ(64);
}
}
static void do_write(void *buf, size_t count, int size)
{
switch (size) {
WRITE(8);
WRITE(16);
WRITE(32);
WRITE(64);
}
}
static void do_xor(void *buf, size_t count, int size)
{
switch (size) {
XOR(8);
XOR(16);
XOR(32);
XOR(64);
}
}
static void do_copy(void *buf, size_t count, int size)
{
switch (size) {
COPY(8);
COPY(16);
COPY(32);
COPY(64);
}
}
static uint64_t time_sub(struct timespec *since, struct timespec *to)
{
if (to->tv_sec == since->tv_sec)
return to->tv_nsec - since->tv_nsec;
return (to->tv_sec - since->tv_sec) * 1000000000 + to->tv_nsec - since->tv_nsec;
}
static void __attribute__ ((noreturn)) usage(char *argv0, int ret)
{
fprintf(ret ? stderr : stdout,
"usage: %s [-rwxc1234h] [-l length] [-u unalignment]\n"
"\n"
"Options:\n"
" -r read memory (default)\n"
" -w write memory\n"
" -x xor memory\n"
" -c copy memory\n"
" -l SIZE use SIZE Mb for the test (default 100)\n"
" -u BYTE unalign buffer by BYTE bytes (default 0)\n"
" -1 read 1 byte at time\n"
" -2 read 2 bytes at time\n"
" -4 read 4 bytes at time (default)\n"
" -8 read 8 bytes at time\n"
" -h this help\n",
argv0);
exit(ret);
}
static const char *actions[] = {
"read",
"write",
"xor",
"copy",
};
int main(int argc, char *argv[])
{
struct timespec before, after;
uint64_t elapsed;
int action = ACT_READ;
size_t len = 100 * 1024 * 1024;
int shift = 0;
int size = sizeof(long);
char *buf;
int c;
while((c = getopt(argc, argv, "hrwxc1248l:u:")) != -1) {
switch (c) {
case 'r':
action = ACT_READ;
break;
case 'w':
action = ACT_WRITE;
break;
case 'x':
action = ACT_XOR;
break;
case 'c':
action = ACT_COPY;
break;
case 'l':
len = atol(optarg) * 1024 * 1024;
if (len <= 0) {
fprintf(stderr, "Invalid size %s\n", optarg);
return 1;
}
break;
case 'u':
shift = atoi(optarg);
break;
case '1':
case '2':
case '4':
case '8':
size = c - '0';
break;
case 'h':
default:
usage(argv[0], c != 'h');
}
}
shift %= size;
if (optind != argc)
usage(argv[0], 1);
buf = malloc(len);
if (!buf) {
perror("malloc");
return 1;
}
if (mlock(buf, len)) {
perror("mlock");
return 1;
}
clock_gettime(CLOCK_MONOTONIC, &before);
switch (action) {
case ACT_READ:
do_read(buf + shift, (len - shift) / size, size);
break;
case ACT_WRITE:
do_write(buf + shift, (len - shift) / size, size);
break;
case ACT_XOR:
do_xor(buf + shift, (len - shift) / size, size);
break;
case ACT_COPY:
do_copy(buf + shift, (len - shift) / size, size);
break;
}
clock_gettime(CLOCK_MONOTONIC, &after);
elapsed = time_sub(&before, &after);
printf( "size: %lu Mb\n"
"%s size: %d bit\n"
"unalignment: %d byte\n"
"elapsed time: %.2f sec\n"
"throughput: %.2f Mb/s\n",
len / 1024 / 1024,
actions[action], size * 8,
shift,
elapsed / 1E9,
(len / 1024 / 1024) / (elapsed / 1E9));
return 0;
}

14
vm.nix
View File

@ -47,8 +47,8 @@
INET y INET y
NETWORK_FILESYSTEMS y NETWORK_FILESYSTEMS y
OVERLAY_FS y OVERLAY_FS y
"9P_FS" y #"9P_FS" y
"9P_FS_POSIX_ACL" y #"9P_FS_POSIX_ACL" y
PCI y PCI y
VIRTIO_PCI y VIRTIO_PCI y
PCI_HOST_GENERIC y PCI_HOST_GENERIC y
@ -63,7 +63,15 @@
nixpkgs.overlays = [ nixpkgs.overlays = [
(final: prev: { (final: prev: {
qemu = prev.qemu.override { rutabagaSupport = false; }; qemu = prev.qemu.override {
pulseSupport = false;
pipewireSupport = false;
sdlSupport = false;
jackSupport = false;
gtkSupport = false;
vncSupport = false;
smartcardSupport = false;
};
uboot-custom = prev.ubootQemuRiscv64Smode.override { uboot-custom = prev.ubootQemuRiscv64Smode.override {
# Override preboot to set 'bootcmd' directly to the kernel address in RAM # Override preboot to set 'bootcmd' directly to the kernel address in RAM