Init starfive visionfive 2

This commit is contained in:
Jakob Leifhelm 2023-04-16 22:43:32 +02:00
parent 3006d2860a
commit 0cc1214203
No known key found for this signature in database
GPG key ID: 6817AA0238100822
11 changed files with 270 additions and 0 deletions

View file

@ -156,6 +156,7 @@
kobol-helios4 = import ./kobol/helios4;
samsung-np900x3c = import ./samsung/np900x3c;
starfive-visionfive-v1 = import ./starfive/visionfive/v1;
starfive-visionfive-2 = import ./starfive/visionfive/v2;
supermicro = import ./supermicro;
supermicro-a1sri-2758f = import ./supermicro/a1sri-2758f;
supermicro-m11sdv-8c-ln4f = import ./supermicro/m11sdv-8c-ln4f;

View file

@ -0,0 +1,5 @@
# Creating SD-Image
``` nix
```

View file

@ -0,0 +1,25 @@
{ config, lib, pkgs, ... }: {
boot = {
# Force no ZFS (from nixos/modules/profiles/base.nix) until updated to kernel 6.0
supportedFilesystems =
lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs" "ntfs" "cifs" ];
consoleLogLevel = lib.mkDefault 7;
kernelPackages =
lib.mkDefault (pkgs.callPackage ./linux_6_3.nix { inherit (config.boot) kernelPatches; });
kernelParams =
lib.mkDefault [ "console=tty0" "console=ttyS0,115200n8" "earlycon=sbi" ];
initrd.availableKernelModules = [
"dw_mmc_starfive"
];
loader = {
grub.enable = lib.mkDefault false;
generic-extlinux-compatible.enable = lib.mkDefault true;
};
hardware.deviceTree.name =
lib.mkDefault "starfive/jh7110-starfive-visionfive-2-v1.3b.dtb";
};
}

View file

@ -0,0 +1,56 @@
{ callPackage, runCommand, writeText, stdenv, dtc }:
let
uboot = callPackage ./uboot.nix { };
opensbi = callPackage ./opensbi.nix {
withPayload = "${uboot}/u-boot.bin";
withFDT = "${uboot}/starfive_visionfive2.dtb";
};
spl-tool = callPackage ./spl-tool.nix { };
its-file = writeText "visionfive2-uboot-fit-image.its" ''
/dts-v1/;
/ {
description = "U-boot-spl FIT image for JH7110 VisionFive2";
#address-cells = <2>;
images {
firmware {
description = "u-boot";
data = /incbin/("${opensbi}/share/opensbi/lp64/generic/firmware/fw_payload.bin");
type = "firmware";
arch = "riscv";
os = "u-boot";
load = <0x0 0x40000000>;
entry = <0x0 0x40000000>;
compression = "none";
};
};
configurations {
default = "config-1";
config-1 {
description = "U-boot-spl FIT config for JH7110 VisionFive2";
firmware = "firmware";
};
};
};
'';
in {
inherit opensbi uboot;
spl = runCommand "starfive-visionfive2-spl" { } ''
mkdir -p $out/share/starfive-visionfive2/
ln -s ${uboot}/u-boot-spl.bin .
${spl-tool}/bin/spl_tool -c -f ./u-boot-spl.bin
cp u-boot-spl.bin.normal.out $out/share/starfive-visionfive2/spl.bin
'';
uboot-fit-image = stdenv.mkDerivation {
name = "starfive-visionfive2-uboot-fit-image";
nativeBuildInputs = [ dtc ];
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out/share/starfive-visionfive2/
${uboot}/mkimage -f ${its-file} -A riscv -O u-boot -T firmware $out/share/starfive-visionfive2/visionfive2_fw_payload.img
'';
};
}

View file

@ -0,0 +1,13 @@
diff --git a/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi b/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
index 752bb0b6fd00..93670da6cabd 100644
--- a/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi
@@ -30,7 +30,7 @@ cpus {
memory@40000000 {
device_type = "memory";
- reg = <0x0 0x40000000 0x1 0x0>;
+ reg = <0x0 0x40000000 0x2 0x0>;
};
thermal-zones {

View file

@ -0,0 +1,28 @@
{ lib, callPackage, linuxPackagesFor, kernelPatches, fetchpatch, ... }:
let
modDirVersion = "6.3.0-rc3";
linuxPkg = { lib, fetchFromGitHub, buildLinux, ... }@args:
buildLinux (args // {
version = "${modDirVersion}-starfive-visionfive2";
src = fetchFromGitHub {
owner = "starfive-tech";
repo = "linux";
rev = "2a6909fb414dfc72ae391791ec6edc3eedd13e6f";
sha256 = "sha256-FeY6N+hk0PTpuIuA1hkcS+B+ozn6iHV6YaRVx1kuYHc=";
};
inherit modDirVersion;
kernelPatches = [{ patch = ./fix-memory-size.patch; }] ++ kernelPatches;
structuredExtraConfig = with lib.kernel; {
PL330_DMA = no;
PINCTRL_STARFIVE_JH7110_SYS = yes;
SERIAL_8250_DW = yes;
};
extraMeta.branch = "JH7110_VisionFive2_upstream";
} // (args.argsOverride or { }));
in lib.recurseIntoAttrs (linuxPackagesFor (callPackage linuxPkg { }))

View file

@ -0,0 +1,42 @@
{ lib
, stdenv
, fetchFromGitHub
, python3
, withPlatform ? "generic"
, withPayload ? null
, withFDT ? null
}:
stdenv.mkDerivation rec {
pname = "opensbi";
version = "1.3-git-2868f26";
src = fetchFromGitHub {
owner = "riscv-software-src";
repo = "opensbi";
rev = "2868f26131308ff345382084681ea89c5b0159f1";
sha256 = "sha256-E+nVFLSpH6lQ2nVmMlVRTr7qYRVY0ULW7gUvAyTr90I=";
};
postPatch = ''
patchShebangs ./scripts
'';
nativeBuildInputs = [ python3 ];
installFlags = [
"I=$(out)"
];
makeFlags = [
"PLATFORM=${withPlatform}"
"FW_TEXT_START=0x40000000"
] ++ lib.optionals (withPayload != null) [
"FW_PAYLOAD_PATH=${withPayload}"
] ++ lib.optionals (withFDT != null) [
"FW_FDT_PATH=${withFDT}"
];
dontStrip = true;
dontPatchELF = true;
}

View file

@ -0,0 +1,11 @@
{ modulesPath, ... }:
{
imports = [
"${modulesPath}/profiles/installation-device.nix"
./sd-image.nix
];
# The installation media is also the installation target,
# so we don't want to provide the installation configuration.nix.
installer.cloneConfig = false;
}

View file

@ -0,0 +1,51 @@
{ config, pkgs, lib, modulesPath, ... }:
let
firmware = pkgs.callPackage ./firmware.nix { };
in {
imports = [
"${modulesPath}/profiles/base.nix"
"${modulesPath}/installer/sd-card/sd-image.nix"
./default.nix
];
sdImage = {
imageName =
"${config.sdImage.imageBaseName}-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}-starfive-visionfive2.img";
# Overridden by postBuildCommands
populateFirmwareCommands = "";
firmwarePartitionOffset = 4;
firmwareSize = 4;
postBuildCommands = ''
# preserve root partition
eval $(partx $img -o START,SECTORS --nr 2 --pairs)
# increase image size for gpt backup header
truncate -s '+2M' $img
sfdisk $img <<EOF
label: gpt
unit: sectors
sector-size: 512
start=4096, size=4096, type=2E54B353-1271-4842-806F-E436D6AF6985
start=8192, size=8192, type=5B193300-FC78-40CD-8002-E86C45580B47
start=$START, size=$SECTORS, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, attrs="LegacyBIOSBootable"
EOF
eval $(partx $img -o START,SECTORS --nr 1 --pairs)
dd conv=notrunc if=${firmware.spl}/share/starfive-visionfive2/spl.bin of=$img seek=$START count=$SECTORS
eval $(partx $img -o START,SECTORS --nr 2 --pairs)
dd conv=notrunc if=${firmware.uboot-fit-image}/share/starfive-visionfive2/visionfive2_fw_payload.img of=$img seek=$START count=$SECTORS
'';
populateRootCommands = ''
mkdir -p ./files/boot
${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
'';
};
}

View file

@ -0,0 +1,18 @@
{ stdenv, fetchFromGitHub }:
stdenv.mkDerivation rec{
pname = "spi_tool";
version = "0x01010101";
src = fetchFromGitHub {
owner = "starfive-tech";
repo = "soft_3rdpart";
rev = "cd7b50cd9f9eca66c23ebd19f06a172ce0be591f";
sha256 = "sha256-hRmP74gz0Y9KnSwXCjxEiArJE+FonI9rGghZTK54qGs=";
sparseCheckout = [ "spl_tool" ];
};
sourceRoot = "source/spl_tool";
installPhase = ''
mkdir -p $out/bin
cp spl_tool $out/bin
'';
}

View file

@ -0,0 +1,20 @@
{ fetchFromGitHub, buildUBoot }:
buildUBoot {
version = "2021.10";
src = fetchFromGitHub {
owner = "starfive-tech";
repo = "u-boot";
rev = "688befadf1d337dee3593e6cc0fe1c737cc150bd";
sha256 = "sha256-RGADEJRZyuzjblxowdHnhj78eMJBIWnvkwEcpSen5Oo=";
};
defconfig = "starfive_visionfive2_defconfig";
filesToInstall = [
"u-boot.bin"
"arch/riscv/dts/starfive_visionfive2.dtb"
"spl/u-boot-spl.bin"
"tools/mkimage"
];
}