From f0d02fc483a1e9e46be8d8b4ed13f0d0f46bf918 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 16 Feb 2023 11:37:41 +0100 Subject: [PATCH 1/6] configuration.nix: Add boot.shell_on_fail --- configuration.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configuration.nix b/configuration.nix index 388200d..b4b42b1 100644 --- a/configuration.nix +++ b/configuration.nix @@ -17,6 +17,8 @@ networking.hostName = "visionfive-nix"; + boot.kernelParams = [ "boot.shell_on_fail" ]; + # Enable ssh on boot services.openssh.enable = true; From 4b417999a31315d48c51da189e6e1f90bd6e1a92 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 16 Feb 2023 11:57:52 +0100 Subject: [PATCH 2/6] Add VisionFive 2 inputs --- flake.lock | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 22 +++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/flake.lock b/flake.lock index d8d0b02..bfa06b0 100644 --- a/flake.lock +++ b/flake.lock @@ -36,6 +36,59 @@ "url": "https://github.com/starfive-tech/JH7100_secondBoot/releases/download/bootloader-211102_VisionFive_JH7100/bootloader-JH7100-211102.bin.out" } }, + "jh7110-kernel": { + "flake": false, + "locked": { + "lastModified": 1673450975, + "narHash": "sha256-o1k1UDUXUsRb4200zZ5ozVL15g7wsheet8O5UhX2HWY=", + "owner": "starfive-tech", + "repo": "linux", + "rev": "59cf9af678dbfa3d73f6cb86ed1ae7219da9f5c9", + "type": "github" + }, + "original": { + "owner": "starfive-tech", + "ref": "JH7110_VisionFive2_devel", + "repo": "linux", + "type": "github" + } + }, + "jh7110_recovery_binary": { + "flake": false, + "locked": { + "narHash": "sha256-WL2ltlIJoWQFrRxEQNYQdzBBj0qv9FnMWLHVZVzWzBQ=", + "type": "file", + "url": "https://github.com/starfive-tech/Tools/blob/bc6dc7e33e0c2466db0476b5043f0f77842f98f0/recovery/jh7110-recovery-20221205.bin?raw=true" + }, + "original": { + "type": "file", + "url": "https://github.com/starfive-tech/Tools/blob/bc6dc7e33e0c2466db0476b5043f0f77842f98f0/recovery/jh7110-recovery-20221205.bin?raw=true" + } + }, + "jh7110_u-boot-bin": { + "flake": false, + "locked": { + "narHash": "sha256-DfB8HpWv+/i+fdGvF6oGVVgc+A+LV5NA8PZ1JSOSuys=", + "type": "file", + "url": "https://github.com/starfive-tech/VisionFive2/releases/download/VF2_v2.8.0/visionfive2_fw_payload.img" + }, + "original": { + "type": "file", + "url": "https://github.com/starfive-tech/VisionFive2/releases/download/VF2_v2.8.0/visionfive2_fw_payload.img" + } + }, + "jh7110_u-boot-spl-bin": { + "flake": false, + "locked": { + "narHash": "sha256-Mgw6YUn69MNvgZFd1WvamF0N1ZjF35km76i1AknaAT8=", + "type": "file", + "url": "https://github.com/starfive-tech/VisionFive2/releases/download/VF2_v2.8.0/u-boot-spl.bin.normal.out" + }, + "original": { + "type": "file", + "url": "https://github.com/starfive-tech/VisionFive2/releases/download/VF2_v2.8.0/u-boot-spl.bin.normal.out" + } + }, "jh71xx-tools": { "flake": false, "locked": { @@ -73,6 +126,10 @@ "jh7100_ddrinit": "jh7100_ddrinit", "jh7100_recovery_binary": "jh7100_recovery_binary", "jh7100_secondBoot": "jh7100_secondBoot", + "jh7110-kernel": "jh7110-kernel", + "jh7110_recovery_binary": "jh7110_recovery_binary", + "jh7110_u-boot-bin": "jh7110_u-boot-bin", + "jh7110_u-boot-spl-bin": "jh7110_u-boot-spl-bin", "jh71xx-tools": "jh71xx-tools", "nixpkgs": "nixpkgs", "vendor-kernel": "vendor-kernel" diff --git a/flake.nix b/flake.nix index 0ec759b..5508bd3 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,8 @@ { inputs = { nixpkgs.url = "github:matthewcroughan/nixpkgs/mc/riscv-testing"; + + # VisionFive ("v1") vendor-kernel = { url = "github:starfive-tech/linux"; flake = false; @@ -21,6 +23,26 @@ url = "github:xypron/jh71xx-tools"; flake = false; }; + + # VisionFive 2 + jh7110-kernel = { + # url = "github:starfive-tech/linux/50a831018ed997c9fb3b603574176b221a28aa12"; # JH7110_VisionFive2_devel via VisionFive2 project submodule about two revisions back. + url = "github:starfive-tech/linux/JH7110_VisionFive2_devel"; + flake = false; + }; + jh7110_recovery_binary = { + url = "https://github.com/starfive-tech/Tools/blob/bc6dc7e33e0c2466db0476b5043f0f77842f98f0/recovery/jh7110-recovery-20221205.bin?raw=true"; + flake = false; + }; + # Should be possible to build from https://github.com/starfive-tech/VisionFive2 + jh7110_u-boot-spl-bin = { + url = https://github.com/starfive-tech/VisionFive2/releases/download/VF2_v2.8.0/u-boot-spl.bin.normal.out; + flake = false; + }; + jh7110_u-boot-bin = { + url = https://github.com/starfive-tech/VisionFive2/releases/download/VF2_v2.8.0/visionfive2_fw_payload.img; + flake = false; + }; }; outputs = { self, nixpkgs, jh71xx-tools, jh7100_recovery_binary, jh7100_secondBoot, jh7100_ddrinit, vendor-kernel }: let From f85cae4a4814b90ece85bbb7fdb48ffbc5d559af Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 16 Feb 2023 12:49:58 +0100 Subject: [PATCH 3/6] Add visionfive2 images --- flake.nix | 41 ++- visionfive2/kernel/nixos-module.nix | 37 ++ visionfive2/kernel/package/default.nix | 3 + visionfive2/kernel/package/package.nix | 319 ++++++++++++++++++ .../visionfive-2-duplicate-init-module.patch | 62 ++++ .../kernel/package/visionfive-2-gpu.patch | 13 + .../visionfive-2-pl330-name-collision.patch | 40 +++ visionfive2/sd-image.nix | 48 +++ 8 files changed, 561 insertions(+), 2 deletions(-) create mode 100644 visionfive2/kernel/nixos-module.nix create mode 100644 visionfive2/kernel/package/default.nix create mode 100644 visionfive2/kernel/package/package.nix create mode 100644 visionfive2/kernel/package/visionfive-2-duplicate-init-module.patch create mode 100644 visionfive2/kernel/package/visionfive-2-gpu.patch create mode 100644 visionfive2/kernel/package/visionfive-2-pl330-name-collision.patch create mode 100644 visionfive2/sd-image.nix diff --git a/flake.nix b/flake.nix index 5508bd3..91a8582 100644 --- a/flake.nix +++ b/flake.nix @@ -44,8 +44,9 @@ flake = false; }; }; - outputs = { self, nixpkgs, jh71xx-tools, jh7100_recovery_binary, jh7100_secondBoot, jh7100_ddrinit, vendor-kernel }: + outputs = inputs@{ self, nixpkgs, jh71xx-tools, jh7100_recovery_binary, jh7100_secondBoot, jh7100_ddrinit, vendor-kernel, ... }: let + inherit (nixpkgs) lib; system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; overlays = [ self.overlay ]; }; modules = [ @@ -54,6 +55,12 @@ ./base.nix ./configuration.nix ]; + + # Pass arguments to a module inside a function inside a file, while preserving + # the file name behavior of the module system. + importApply = + modulePath: staticArgs: + lib.setDefaultModuleLocation modulePath (import modulePath staticArgs); in { overlay = final: prev: { @@ -131,8 +138,23 @@ images = { visionfive-cross = self.nixosConfigurations.visionfive-cross.config.system.build.sdImage; visionfive-native = self.nixosConfigurations.visionfive-native.config.system.build.sdImage; + + visionfive2-cross = self.nixosConfigurations.visionfive2-cross.config.system.build.sdImage; + visionfive2-native = self.nixosConfigurations.visionfive2-native.config.system.build.sdImage; }; - nixosConfigurations = { + nixosModules = { + visionfive2-sd-image = importApply ./visionfive2/sd-image.nix { inherit inputs importApply; }; + visionfive2-kernel = importApply ./visionfive2/kernel/nixos-module.nix { inherit inputs importApply; }; + }; + nixosConfigurations = + let + visionfive2-example-modules = [ + ./base.nix + ./configuration.nix + self.nixosModules.visionfive2-sd-image + ]; + in + { visionfive-cross = nixpkgs.lib.nixosSystem { system = "${system}"; modules = modules ++ [ @@ -147,6 +169,21 @@ system = "riscv64-linux"; modules = modules; }; + + visionfive2-cross = nixpkgs.lib.nixosSystem { + system = "${system}"; + modules = visionfive2-example-modules ++ [ + { + nixpkgs.crossSystem = { + system = "riscv64-linux"; + }; + } + ]; + }; + visionfive2-native = nixpkgs.lib.nixosSystem { + system = "riscv64-linux"; + modules = visionfive2-example-modules; + }; }; }; } diff --git a/visionfive2/kernel/nixos-module.nix b/visionfive2/kernel/nixos-module.nix new file mode 100644 index 0000000..0fad48a --- /dev/null +++ b/visionfive2/kernel/nixos-module.nix @@ -0,0 +1,37 @@ +{ inputs, ... }: +{ lib, pkgs, ... }: +{ + disabledModules = [ + "profiles/all-hardware.nix" # references virtio_pci kernel module, which we don't have + ]; + + config = { + boot = { + kernelPackages = pkgs.linuxPackagesFor (import ./package/default.nix { inherit pkgs inputs; }); + + kernelParams = [ + "console=tty0" + "console=ttyS0,115200n8" + "earlycon=sbi" + ]; + + blacklistedKernelModules = [ + # Last thing to log before crash... + "axp15060-regulator" + # Also sus + "at24" + # Also also sus + "jh7110-vin" + # Maybe?? + "starfive-jh7110-regulator" + + # This one stopped the crashing + "starfivecamss" + ]; + }; + + # Example: hardware.deviceTree.name = "starfive/jh7110-visionfive-v2-A11.dtb"; + hardware.deviceTree.name = lib.mkDefault "starfive/jh7110-visionfive-v2.dtb"; + + }; +} diff --git a/visionfive2/kernel/package/default.nix b/visionfive2/kernel/package/default.nix new file mode 100644 index 0000000..12ad586 --- /dev/null +++ b/visionfive2/kernel/package/default.nix @@ -0,0 +1,3 @@ +{ pkgs, inputs }: + +pkgs.callPackage ./package.nix { src = inputs.jh7110-kernel; } \ No newline at end of file diff --git a/visionfive2/kernel/package/package.nix b/visionfive2/kernel/package/package.nix new file mode 100644 index 0000000..d7ab39e --- /dev/null +++ b/visionfive2/kernel/package/package.nix @@ -0,0 +1,319 @@ +{ lib +, fetchFromGitHub +, fetchpatch +, buildLinux +, src +, ... } @ args: + +let + kernelVersion = rec { + # Fully constructed string, example: "5.10.0-rc5". + string = "${version + "." + patchlevel + "." + sublevel + (lib.optionalString (extraversion != "") extraversion)}"; + file = "${src}/Makefile"; + version = toString (builtins.match ".+VERSION = ([0-9]+).+" (builtins.readFile file)); + patchlevel = toString (builtins.match ".+PATCHLEVEL = ([0-9]+).+" (builtins.readFile file)); + sublevel = toString (builtins.match ".+SUBLEVEL = ([0-9]+).+" (builtins.readFile file)); + # rc, next, etc. + extraversion = toString (builtins.match ".+EXTRAVERSION = ([a-z0-9-]+).+" (builtins.readFile file)); + }; + modDirVersion = "${kernelVersion.string}"; +in buildLinux (args // { + inherit modDirVersion; + version = "${modDirVersion}-visionfive2"; + + inherit src; + + kernelPatches = [ + { patch = fetchpatch { + url = "https://github.com/torvalds/linux/commit/215bebc8c6ac438c382a6a56bd2764a2d4e1da72.diff"; + hash = "sha256-1ZqmVOkgcDBRkHvVRPH8I5G1STIS1R/l/63PzQQ0z0I="; + includes = ["security/keys/dh.c"]; + }; + } + { patch = ./visionfive-2-duplicate-init-module.patch; } + { patch = ./visionfive-2-pl330-name-collision.patch; } + { patch = ./visionfive-2-gpu.patch; } + ]; + + defconfig = "starfive_visionfive2_defconfig"; + + structuredExtraConfig = with lib.kernel; { + + # USB Wifi + RT2800USB_RT53XX = yes; + RT2800USB = module; + RT2800USB_RT3573 = yes; + + KEXEC = yes; + SERIAL_8250_DW = yes; + + SOC_STARFIVE = yes; + + # CLK_STARFIVE_JH7110_SYS = yes; + RESET_STARFIVE_JH7110 = yes; + PINCTRL_STARFIVE_JH7110 = yes; + + # MMC_DW_STARFIVE = yes; + + # # Doesn't build as a module + # DW_AXI_DMAC_STARFIVE = yes; + + # # stmmac hangs when built as a module (at least on VisionFive v1, apparently) + PTP_1588_CLOCK = yes; + STMMAC_ETH = yes; + STMMAC_PCI = yes; + + # Fix build error + # RIPE-MD and other algos appears to have been removed, correlating with https://github.com/starfive-tech/linux/commit/d210ee3fdfe8584f84f8fdd0ac4a9895d023325b + # defconfig out of date? + CRYPTO_RMD128 = no; + CRYPTO_RMD160 = yes; + CRYPTO_RMD256 = no; + CRYPTO_RMD320 = no; + CRYPTO_TGR192 = no; + CRYPTO_SALSA20 = no; + + # sm4 lacks a symbol + CRYPTO_DEV_CCREE = no; + CRYPTO_SM4 = no; + + # Can't be built as modules + SPI_PL022 = yes; + SPI_PL022_STARFIVE = yes; + RTC_DRV_STARFIVE = yes; + + # Compile errors + STARFIVE_DSI = no; + VIDEO_HDPVR = no; + VIDEO_PVRUSB2_DVB = no; + DRM_IMG = no; # gpu module doesn't compile at this time + DRM_IMG_ROGUE = no; + DRM_VERISILICON = no; + # DRM_LEGACY = no; + DRM_PANEL_JADARD_JD9365DA_H3 = no; + VERISILICON_DW_MIPI_DSI = no; + VGA_ARB = no; + + # brute force disable drm + CEC_CORE = no; + CEC_NOTIFIER = no; + DRM = no; + DRM_MIPI_DBI = no; + DRM_MIPI_DSI = no; + DRM_DP_AUX_BUS = no; + DRM_DP_AUX_CHARDEV = lib.mkForce no; + DRM_KMS_HELPER = no; + DRM_FBDEV_EMULATION = no; + DRM_LOAD_EDID_FIRMWARE = lib.mkForce no; + DRM_TTM = no; + DRM_VRAM_HELPER = no; + DRM_TTM_HELPER = no; + DRM_GEM_CMA_HELPER = no; + DRM_KMS_CMA_HELPER = no; + DRM_GEM_SHMEM_HELPER = no; + DRM_SCHED = no; + DRM_I2C_CH7006 = no; + DRM_I2C_SIL164 = no; + DRM_I2C_NXP_TDA998X = no; + DRM_I2C_NXP_TDA9950 = no; + DRM_KOMEDA = no; + DRM_RADEON = no; + DRM_AMDGPU = no; + DRM_AMDGPU_SI = lib.mkForce no; + DRM_AMDGPU_CIK = lib.mkForce no; + DRM_AMDGPU_USERPTR = lib.mkForce no; + DRM_AMD_DC = no; + DRM_AMD_DC_HDCP = lib.mkForce no; + DRM_AMD_DC_SI = lib.mkForce no; + DRM_NOUVEAU = no; + NOUVEAU_LEGACY_CTX_SUPPORT = no; + DRM_NOUVEAU_BACKLIGHT = no; + DRM_VGEM = no; + DRM_VKMS = no; + DRM_UDL = no; + DRM_AST = no; + DRM_MGAG200 = no; + DRM_RCAR_DW_HDMI = no; + DRM_QXL = no; + DRM_VIRTIO_GPU = no; + DRM_PANEL = no; + DRM_PANEL_ABT_Y030XX067A = no; + DRM_PANEL_ARM_VERSATILE = no; + DRM_PANEL_ASUS_Z00T_TM5P5_NT35596 = no; + DRM_PANEL_BOE_HIMAX8279D = no; + DRM_PANEL_BOE_TV101WUM_NL6 = no; + DRM_PANEL_DSI_CM = no; + DRM_PANEL_LVDS = no; + DRM_PANEL_SIMPLE = no; + DRM_PANEL_ELIDA_KD35T133 = no; + DRM_PANEL_FEIXIN_K101_IM2BA02 = no; + DRM_PANEL_FEIYANG_FY07024DI26A30D = no; + DRM_PANEL_ILITEK_IL9322 = no; + DRM_PANEL_ILITEK_ILI9341 = no; + DRM_PANEL_ILITEK_ILI9881C = no; + DRM_PANEL_INNOLUX_EJ030NA = no; + DRM_PANEL_INNOLUX_P079ZCA = no; + DRM_PANEL_JDI_LT070ME05000 = no; + DRM_PANEL_KHADAS_TS050 = no; + DRM_PANEL_KINGDISPLAY_KD097D04 = no; + DRM_PANEL_LEADTEK_LTK050H3146W = no; + DRM_PANEL_LEADTEK_LTK500HD1829 = no; + DRM_PANEL_SAMSUNG_LD9040 = no; + DRM_PANEL_LG_LB035Q02 = no; + DRM_PANEL_LG_LG4573 = no; + DRM_PANEL_NEC_NL8048HL11 = no; + DRM_PANEL_NOVATEK_NT35510 = no; + DRM_PANEL_NOVATEK_NT36672A = no; + DRM_PANEL_NOVATEK_NT39016 = no; + DRM_PANEL_MANTIX_MLAF057WE51 = no; + DRM_PANEL_OLIMEX_LCD_OLINUXINO = no; + DRM_PANEL_ORISETECH_OTM8009A = no; + DRM_PANEL_OSD_OSD101T2587_53TS = no; + DRM_PANEL_PANASONIC_VVX10F034N00 = no; + DRM_PANEL_RASPBERRYPI_TOUCHSCREEN = no; + DRM_PANEL_RAYDIUM_RM67191 = no; + DRM_PANEL_RAYDIUM_RM68200 = no; + DRM_PANEL_RONBO_RB070D30 = no; + DRM_PANEL_SAMSUNG_ATNA33XC20 = no; + DRM_PANEL_SAMSUNG_DB7430 = no; + DRM_PANEL_SAMSUNG_S6D16D0 = no; + DRM_PANEL_SAMSUNG_S6E3HA2 = no; + DRM_PANEL_SAMSUNG_S6E63J0X03 = no; + DRM_PANEL_SAMSUNG_S6E63M0 = no; + DRM_PANEL_SAMSUNG_S6E63M0_SPI = no; + DRM_PANEL_SAMSUNG_S6E63M0_DSI = no; + DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01 = no; + DRM_PANEL_SAMSUNG_S6E8AA0 = no; + DRM_PANEL_SAMSUNG_SOFEF00 = no; + DRM_PANEL_SEIKO_43WVF1G = no; + DRM_PANEL_SHARP_LQ101R1SX01 = no; + DRM_PANEL_SHARP_LS037V7DW01 = no; + DRM_PANEL_SHARP_LS043T1LE01 = no; + DRM_PANEL_SITRONIX_ST7701 = no; + DRM_PANEL_SITRONIX_ST7703 = no; + DRM_PANEL_SITRONIX_ST7789V = no; + DRM_PANEL_SONY_ACX565AKM = no; + DRM_PANEL_TDO_TL070WSH30 = no; + DRM_PANEL_TPO_TD028TTEC1 = no; + DRM_PANEL_TPO_TD043MTEA1 = no; + DRM_PANEL_TPO_TPG110 = no; + DRM_PANEL_TRULY_NT35597_WQXGA = no; + DRM_PANEL_VISIONOX_RM69299 = no; + DRM_PANEL_WIDECHIPS_WS2401 = no; + DRM_PANEL_XINPENG_XPP055C272 = no; + DRM_BRIDGE = no; + DRM_PANEL_BRIDGE = no; + DRM_CDNS_DSI = no; + DRM_CHIPONE_ICN6211 = no; + DRM_CHRONTEL_CH7033 = no; + DRM_DISPLAY_CONNECTOR = no; + DRM_LONTIUM_LT8912B = no; + DRM_LONTIUM_LT9611 = no; + DRM_LONTIUM_LT9611UXC = no; + DRM_ITE_IT66121 = no; + DRM_LVDS_CODEC = no; + DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW = no; + DRM_NWL_MIPI_DSI = no; + DRM_NXP_PTN3460 = no; + DRM_PARADE_PS8622 = no; + DRM_PARADE_PS8640 = no; + DRM_SIL_SII8620 = no; + DRM_SII902X = no; + DRM_SII9234 = no; + DRM_SIMPLE_BRIDGE = no; + DRM_THINE_THC63LVD1024 = no; + DRM_TOSHIBA_TC358762 = no; + DRM_TOSHIBA_TC358764 = no; + DRM_TOSHIBA_TC358767 = no; + DRM_TOSHIBA_TC358768 = no; + DRM_TOSHIBA_TC358775 = no; + DRM_TI_TFP410 = no; + DRM_TI_SN65DSI83 = no; + DRM_TI_SN65DSI86 = no; + DRM_TI_TPD12S015 = no; + DRM_ANALOGIX_ANX6345 = no; + DRM_ANALOGIX_ANX78XX = no; + DRM_ANALOGIX_DP = no; + DRM_ANALOGIX_ANX7625 = no; + DRM_I2C_ADV7511 = no; + DRM_I2C_ADV7511_CEC = no; + DRM_CDNS_MHDP8546 = no; + DRM_DW_HDMI = no; + DRM_DW_HDMI_AHB_AUDIO = no; + DRM_DW_HDMI_I2S_AUDIO = no; + DRM_DW_HDMI_CEC = no; + DRM_ETNAVIV = no; + DRM_ETNAVIV_THERMAL = no; + DRM_MXS = no; + DRM_MXSFB = no; + DRM_ARCPGU = no; + DRM_BOCHS = no; + DRM_CIRRUS_QEMU = no; + DRM_GM12U320 = no; + TINYDRM_HX8357D = no; + TINYDRM_ILI9225 = no; + TINYDRM_ILI9341 = no; + TINYDRM_ILI9486 = no; + TINYDRM_MI0283QT = no; + TINYDRM_REPAPER = no; + TINYDRM_ST7586 = no; + TINYDRM_ST7735R = no; + DRM_GUD = no; + DRM_LEGACY = no; + DRM_TDFX = no; + DRM_R128 = no; + DRM_MGA = no; + DRM_VIA = no; + DRM_SAVAGE = no; + VIDEOMODE_HELPERS = no; + SND_PCM_ELD = no; + SND_PCM_IEC958 = no; + SND_HDA_COMPONENT = no; + SND_SOC_HDMI_CODEC = no; + VIRTIO_DMA_SHARED_BUFFER = no; + + #end + + USB_WIFI_ECR6600U = no; + VIN_SENSOR_IMX219 = no; + VIDEO_IMX219 = no; + + VIN_SENSOR_OV5640 = no; + VIDEO_OV5640 = no; + + # missing MODULE_LICENSE() + SND_SOC_WM8960 = no; + + # # Wonky config generation? Its dependency and dependent are enabled as module, + # # but VIRTIO_PCI itself was not listed in the .config + # # Error was: modprobe: FATAL: Module virtio_pci not found in directory + # VIRTIO = no; + # VIRTIO_PCI = module; + # VIRTIO_PCI_LIB = no; + # # VIRTIO_VSOCKETS = no; + # # BT_VIRTIO = no; + # # NET_9P_VIRTIO = no; + # # VIRTIO_BLK = no; + # # SCSI_VIRTIO = no; + # # VIRTIO_NET = no; + # # VIRTIO_CONSOLE = no; + # # HW_RANDOM_VIRTIO = no; + # # I2C_VIRTIO = no; + # # GPIO_VIRTIO = no; + # # SND_VIRTIO = no; + # # VIRTIO_MENU = no; + # # RPMSG_VIRTIO = no; + # # VIRTIO_FS = no; + # # CRYPTO_DEV_VIRTIO = no; + + # SND_SOC_STARFIVE_PWMDAC = yes; + # SND_SOC_STARFIVE = yes; + # SND = no; + }; + + extraMeta = { + description = "Linux kernel for StarFive's JH7110 RISC-V SoC (VisionFive 2)"; + platforms = [ "riscv64-linux" ]; + hydraPlatforms = [ "riscv64-linux" ]; + }; +} // (args.argsOverride or { })) diff --git a/visionfive2/kernel/package/visionfive-2-duplicate-init-module.patch b/visionfive2/kernel/package/visionfive-2-duplicate-init-module.patch new file mode 100644 index 0000000..c0e17a4 --- /dev/null +++ b/visionfive2/kernel/package/visionfive-2-duplicate-init-module.patch @@ -0,0 +1,62 @@ +diff --git a/sound/soc/starfive/pwmdac.h b/sound/soc/starfive/pwmdac.h +index d4742f99a51b..4b1f4586e901 100644 +--- a/sound/soc/starfive/pwmdac.h ++++ b/sound/soc/starfive/pwmdac.h +@@ -154,6 +154,9 @@ int sf_pwmdac_pcm_register(struct platform_device *pdev) + { + return -EINVAL; + } ++void pwmdac_dit_driver_init(void); ++void pwmdac_dit_driver_exit(void); ++ + #endif + + #endif +diff --git a/sound/soc/starfive/starfive_pwmdac.c b/sound/soc/starfive/starfive_pwmdac.c +index fba58e22d7ef..20cbf7083e10 100644 +--- a/sound/soc/starfive/starfive_pwmdac.c ++++ b/sound/soc/starfive/starfive_pwmdac.c +@@ -968,14 +968,15 @@ static struct platform_driver sf_pwmdac_driver = { + }, + }; + +- + static int __init pwmdac_driver_init(void) + { ++ pwmdac_dit_driver_init(); + return platform_driver_register(&sf_pwmdac_driver); + } + + static void pwmdac_driver_exit(void) + { ++ pwmdac_dit_driver_exit(); + platform_driver_unregister(&sf_pwmdac_driver); + } + +diff --git a/sound/soc/starfive/starfive_pwmdac_transmitter.c b/sound/soc/starfive/starfive_pwmdac_transmitter.c +index 6d58fcfd5592..0c50c82c4c20 100755 +--- a/sound/soc/starfive/starfive_pwmdac_transmitter.c ++++ b/sound/soc/starfive/starfive_pwmdac_transmitter.c +@@ -90,20 +90,16 @@ static struct platform_driver pwmdac_dit_driver = { + }, + }; + +-static int __init pwmdac_dit_driver_init(void) ++int __init pwmdac_dit_driver_init(void) + { + return platform_driver_register(&pwmdac_dit_driver); + } + +-static void pwmdac_dit_driver_exit(void) ++void pwmdac_dit_driver_exit(void) + { + platform_driver_unregister(&pwmdac_dit_driver); + } + +-late_initcall(pwmdac_dit_driver_init); +-module_exit(pwmdac_dit_driver_exit); +- +- + MODULE_AUTHOR("curry.zhang "); + MODULE_DESCRIPTION("pwmdac dummy codec driver"); + MODULE_LICENSE("GPL v2"); diff --git a/visionfive2/kernel/package/visionfive-2-gpu.patch b/visionfive2/kernel/package/visionfive-2-gpu.patch new file mode 100644 index 0000000..beea1d9 --- /dev/null +++ b/visionfive2/kernel/package/visionfive-2-gpu.patch @@ -0,0 +1,13 @@ +diff --git a/drivers/gpu/drm/i2c/tda998x_pin.c b/drivers/gpu/drm/i2c/tda998x_pin.c +index 995efc8e55ed..48a616a7e851 100644 +--- a/drivers/gpu/drm/i2c/tda998x_pin.c ++++ b/drivers/gpu/drm/i2c/tda998x_pin.c +@@ -30,7 +30,7 @@ static const struct of_device_id tda998x_rgb_dt_ids[] = { + { .compatible = "starfive,tda998x_rgb_pin", }, + { /* sentinel */ }, + }; +-MODULE_DEVICE_TABLE(of, starfive_drm_dt_ids); ++MODULE_DEVICE_TABLE(of, tda998x_rgb_dt_ids); + + static struct platform_driver starfive_drm_platform_driver = { + .probe = starfive_drm_platform_probe, diff --git a/visionfive2/kernel/package/visionfive-2-pl330-name-collision.patch b/visionfive2/kernel/package/visionfive-2-pl330-name-collision.patch new file mode 100644 index 0000000..255f7be --- /dev/null +++ b/visionfive2/kernel/package/visionfive-2-pl330-name-collision.patch @@ -0,0 +1,40 @@ +diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c +index 110de8a60058..0a01256ef9e4 100644 +--- a/drivers/dma/pl330.c ++++ b/drivers/dma/pl330.c +@@ -1050,7 +1050,7 @@ static bool _trigger(struct pl330_thread *thrd) + return true; + } + +-static bool _start(struct pl330_thread *thrd) ++static bool _dma_start(struct pl330_thread *thrd) + { + switch (_state(thrd)) { + case PL330_STATE_FAULT_COMPLETING: +@@ -1702,7 +1702,7 @@ static int pl330_update(struct pl330_dmac *pl330) + thrd->req_running = -1; + + /* Get going again ASAP */ +- _start(thrd); ++ _dma_start(thrd); + + /* For now, just make a list of callbacks to be done */ + list_add_tail(&descdone->rqd, &pl330->req_done); +@@ -2089,7 +2089,7 @@ static void pl330_tasklet(struct tasklet_struct *t) + } else { + /* Make sure the PL330 Channel thread is active */ + spin_lock(&pch->thread->dmac->lock); +- _start(pch->thread); ++ _dma_start(pch->thread); + spin_unlock(&pch->thread->dmac->lock); + } + +@@ -2107,7 +2107,7 @@ static void pl330_tasklet(struct tasklet_struct *t) + if (power_down) { + pch->active = true; + spin_lock(&pch->thread->dmac->lock); +- _start(pch->thread); ++ _dma_start(pch->thread); + spin_unlock(&pch->thread->dmac->lock); + power_down = false; + } diff --git a/visionfive2/sd-image.nix b/visionfive2/sd-image.nix new file mode 100644 index 0000000..2470d06 --- /dev/null +++ b/visionfive2/sd-image.nix @@ -0,0 +1,48 @@ +{ inputs, importApply, ... }: +{ config, lib, pkgs, modulesPath, ... }: +{ + imports = [ + (modulesPath + "/profiles/base.nix") + (modulesPath + "/installer/sd-card/sd-image.nix") + (importApply ./kernel/nixos-module.nix { inherit inputs; }) + ]; + + environment.systemPackages = with pkgs; [ mtdutils ]; + + boot = { + consoleLogLevel = lib.mkDefault 7; + + initrd.kernelModules = [ + # "dw-axi-dmac-platform" + ]; + initrd.includeDefaultModules = false; + initrd.availableKernelModules = [ + "dw_mmc-pltfm" + "dw_mmc-starfive" + "spi-dw-mmio" + "mmc_block" + "nvme" + "sdhci" #? + "sdhci-pci" #? + "sdhci-of-dwcmshc" + ]; + + loader = { + grub.enable = false; + generic-extlinux-compatible.enable = true; + }; + + }; + + sdImage = { + imageName = "${config.sdImage.imageBaseName}-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}-visionfive-2.img"; + + populateFirmwareCommands = '' + ''; + + populateRootCommands = '' + mkdir -p ./files/boot + ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot + ''; + }; +} \ No newline at end of file From ee4b3c9e3374977ad13f89f681762ebcbb0de9c8 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 16 Feb 2023 13:21:01 +0100 Subject: [PATCH 4/6] Add nix run visionFive2_* commands --- flake.nix | 2 +- visionfive2/README.md | 61 ++++++++++++++++++++++ visionfive2/commands.nix | 107 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 visionfive2/README.md create mode 100644 visionfive2/commands.nix diff --git a/flake.nix b/flake.nix index 91a8582..2a7d644 100644 --- a/flake.nix +++ b/flake.nix @@ -131,7 +131,7 @@ type = "app"; program = "${program}"; }; - }; + } // import ./visionfive2/commands.nix { inherit inputs pkgs; }; packages.${system} = { jh7100-recover = pkgs.writeCBin "jh7100-recover" (builtins.readFile "${jh71xx-tools}/jh7100-recover.c"); }; diff --git a/visionfive2/README.md b/visionfive2/README.md new file mode 100644 index 0000000..a86f83d --- /dev/null +++ b/visionfive2/README.md @@ -0,0 +1,61 @@ + +# VisionFive 2 + +As of writing, VisionFive 2 support is quite experimental. + +## Flash the bootloader via serial connection + +This step may be optional. + +Make the serial connection according to the section "Recovering the Bootloader" in . +Flip the tiny switches towards the H (as opposed to L) marking on the PCB (towards edge of the board) as described that section (Step 2). +Power up, and assuming your serial device is `/dev/ttyUSB0`, run: + +```shellSession +nix run .#visionFive2_bootloader_recover /dev/ttyUSB0 +``` + +## Write a bootable SD card + +```shellSession +$ nix build .#images.visionfive2-cross +``` + +Insert an SD card of which all contents will be replaced. + +These instructions assume your SD card reader is `/dev/mmcblk0`. + +Make sure no partitions are mounted. + +```shellSession +$ echo /dev/mmcblk0p* +$ sudo umount /dev/mmcblk0p1 +$ sudo umount /dev/mmcblk0p2 +... repeat for all partitions +``` + +`pv` provides a rough progress indicator based on the compressed size. +If you don't have `pv`, run in `nix shell nixpkgs#pv` or use `cat` instead. + +```shellSession +$ sudo sh -c 'pv &2 NOTE: If your board appears to hang, RX/TX may be flipped, + echo >&2 _depending on boot setting_!!! + echo "$0" + ${expectScript} "$@" + echo >&2 "Launching new session. Hint enter to display help." + ${visionFive2_recovery_resume.program} "$@" + ''; + in { type = "app"; program = "${wrapSudo program}"; }; + + visionFive2_recovery_resume = + let + program = pkgs.writeScript "recoverBootloader_resume" '' + #!${pkgs.runtimeShell} + set -eu + ${pkgs.picocom}/bin/picocom $1 -b 115200 -s "${pkgs.lrzsz}/bin/sz -X" + ''; + in { type = "app"; program = "${wrapSudo program}"; }; + + visionFive2_bootloader_recover = + let + expectScript = pkgs.writeScript "expect-visionfive-recover-bootLoader" '' + #!${pkgs.expect}/bin/expect -f + set timeout -1 + spawn ${pkgs.picocom}/bin/picocom [lindex $argv 0] -b 115200 -s "${pkgs.lrzsz}/bin/sz -X" + expect "CC" + send "\x01\x13" + expect "*** file:" + send "${inputs.jh7110_recovery_binary}" + send "\r" + expect "Transfer complete" + + # Wait for menu and install SPL + expect "0: update 2ndboot/SPL in flash" + send "0\r" + + expect "CC" + send "\x01\x13" + expect "*** file:" + send "${inputs.jh7110_u-boot-spl-bin}" + send "\r" + expect "Transfer complete" + + # Wait for menu and install u-boot + expect "2: update fw_verif/uboot in flash" + send "2\r" + expect "CC" + send "\x01\x13" + expect "*** file:" + send "${inputs.jh7110_u-boot-bin}" + send "\r" + expect "Transfer complete" + ''; + program = pkgs.writeShellScript "flash-visionfive.sh" '' + cat >&2 <&2 < Date: Thu, 16 Feb 2023 13:23:11 +0100 Subject: [PATCH 5/6] README.md: Reference visionfive2 --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b844bc..73a1738 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -# Flashing the Bootloader +# VisionFive-Nix + +This repository contains primarily instructions for the VisionFive 1 board. + +For experimental support for VisionFive 2, see [visionfive2/README.md](visionfive2/README.md). + +# Flashing the Bootloader (VisionFive 1) 1. Do not apply power to the board 2. Attach the board via serial to your system, ensuring power is still not applied From 1a9dee930fb6aae6639b9dd333f0a6b60bd355bf Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 16 Feb 2023 13:30:40 +0100 Subject: [PATCH 6/6] visionfive2: Explain kernel situation --- visionfive2/README.md | 2 +- visionfive2/kernel/README.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 visionfive2/kernel/README.md diff --git a/visionfive2/README.md b/visionfive2/README.md index a86f83d..151061b 100644 --- a/visionfive2/README.md +++ b/visionfive2/README.md @@ -1,7 +1,7 @@ # VisionFive 2 -As of writing, VisionFive 2 support is quite experimental. +As of writing, VisionFive 2 support is quite experimental; see [kernel/README.md](kernel/README.md). ## Flash the bootloader via serial connection diff --git a/visionfive2/kernel/README.md b/visionfive2/kernel/README.md new file mode 100644 index 0000000..018bb74 --- /dev/null +++ b/visionfive2/kernel/README.md @@ -0,0 +1,4 @@ + +# VisionFive 2 kernel + +The VisionFive 2 kernel is still under development. Most of the contents of this directory only exist in order to work around build errors and a crash or two. As such, the settings described here are by no means final, or even good.