|
| 1 | +# SpacemiT K3 Pico-ITX |
| 2 | + |
| 3 | +NixOS support for the [SpacemiT K3 Pico-ITX](https://www.spacemit.com/community/document/info?nodepath=hardware%2Feco%2Fk3_pico%2Fpico_user_guide.md&lang=en) single-board |
| 4 | +computer, built around the SpacemiT K3 SoC (RVA23 RISC-V). |
| 5 | + |
| 6 | +## Hardware |
| 7 | + |
| 8 | +| Component | Detail | |
| 9 | +| --------- | ------ | |
| 10 | +| SoC | SpacemiT K3 (RVA23, 64-bit RISC-V) | |
| 11 | +| CPU | 16 cores: 8× X100 @ 2.4 GHz + 8× A100 @ 2.0 GHz | |
| 12 | +| Memory | LPDDR5, up to 32 GB | |
| 13 | +| Storage | PCIe Gen3 ×4 (NVMe), internal UFS, microSD | |
| 14 | +| Network | RTL8211F 1GbE (`end0`), RTL8127 10GbE (PCIe), RTL8852BE Wi-Fi 6 (PCIe) | |
| 15 | +| Firmware | EDK2 UEFI + U-Boot + OpenSBI | |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +Add the module to your configuration: |
| 20 | + |
| 21 | +```nix |
| 22 | +{ |
| 23 | + imports = [ |
| 24 | + "${nixos-hardware}/spacemit/k3-pico-itx" |
| 25 | + ]; |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +This gives you the base setup with the vendor `linux-6.18` kernel and |
| 30 | +EDK2/U-Boot/OpenSBI. I plan to move to the mainline kernel. |
| 31 | + |
| 32 | +### Building an SD-image |
| 33 | + |
| 34 | +```nix |
| 35 | +{ |
| 36 | + imports = [ |
| 37 | + "${nixos-hardware}/spacemit/k3-pico-itx/sd-image.nix" |
| 38 | + ]; |
| 39 | +
|
| 40 | + # Set a password or add an SSH key so you can log in |
| 41 | + # users.users.nixos.password = "changeme"; |
| 42 | + # users.users.nixos.openssh.authorizedKeys.keys = [ "ssh-ed25519 ..." ]; |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +```sh |
| 47 | +nix build .#sd-image |
| 48 | +``` |
| 49 | + |
| 50 | +## Cache |
| 51 | + |
| 52 | +To install and update your system I set up a binary cache: |
| 53 | +`build05.ynh.ovh` |
| 54 | +This saves you from compiling everything locally. |
| 55 | +Here is how to add it to your configuration: |
| 56 | + |
| 57 | +```nix |
| 58 | +nix.settings = { |
| 59 | + substituters = [ "https://build05.ynh.ovh" ]; |
| 60 | + trusted-public-keys = [ |
| 61 | + "build05.ynh.ovh:bLxWKPjbKYOFxqrjOxv+cdwS3kFLuHEf1k6j8fAxbzM=" |
| 62 | + ]; |
| 63 | +}; |
| 64 | +``` |
| 65 | + |
| 66 | +Here is how to use it without adding it to your configuration: |
| 67 | + |
| 68 | +```sh |
| 69 | +nix build \ |
| 70 | + --substituters https://build05.ynh.ovh \ |
| 71 | + --trusted-public-keys "build05.ynh.ovh:bLxWKPjbKYOFxqrjOxv+cdwS3kFLuHEf1k6j8fAxbzM=" |
| 72 | +``` |
| 73 | + |
| 74 | +PS: This is a cache maintained on a voluntary basis for the K3 and riscv64 |
| 75 | +hardware. I can't guarantee its availability, nor that everything is already |
| 76 | +built on it. The Hydra infrastructure is still being deployed, so please be |
| 77 | +lenient in that regard. |
| 78 | + |
| 79 | +## HMP configuration |
| 80 | + |
| 81 | +The X100 and A100 clusters have different vector widths (`VLENB=32` vs `VLENB=128`). |
| 82 | + |
| 83 | +You can configure HMP at runtime: |
| 84 | + |
| 85 | +`echo strict > /sys/kernel/spacemit_hmp/mode` (default) |
| 86 | + |
| 87 | +or |
| 88 | + |
| 89 | +`echo permissive > /sys/kernel/spacemit_hmp/mode` |
| 90 | + |
| 91 | +Permissive mode lets you use the 8 A100 cores in addition to the X100 cores. |
| 92 | +However, I deliberately apply a segmentation between the two clusters because of a |
| 93 | +VLEN issue. |
| 94 | + |
| 95 | +If you force tasks across both clusters anyway (e.g. via `taskset`), it will cause |
| 96 | +crypto corruption. |
| 97 | + |
| 98 | +I also made a small module for this: |
| 99 | + |
| 100 | +```nix |
| 101 | +hardware.spacemit.hmp = { |
| 102 | + enable = true; |
| 103 | + mode = "permissive"; # or "strict" |
| 104 | +}; |
| 105 | +``` |
| 106 | + |
| 107 | +- **`strict`** (default): uses the X100 cores only. |
| 108 | +- **`permissive`**: uses both the X100 and A100 cores, but with a segmentation |
| 109 | + between the clusters. |
| 110 | + |
| 111 | +An alternative is still available to use all 16 cores without segmentation, with |
| 112 | +this: |
| 113 | + |
| 114 | +```nix |
| 115 | +environment.variables.OPENSSL_riscvcap = "RV64GC"; |
| 116 | +``` |
| 117 | + |
| 118 | +## UEFI |
| 119 | + |
| 120 | +To get UEFI I made a small script, to be run from Bianbu: |
| 121 | + |
| 122 | +https://github.com/liberodark/k3-uefi-flash |
| 123 | + |
| 124 | +## Status |
| 125 | + |
| 126 | +Working: |
| 127 | + |
| 128 | +- Boot to NixOS, SSH reachable |
| 129 | +- NVMe root (PCIe Gen3 ×4), 1GbE (`end0`) |
| 130 | +- All 16 cores usable (see HMP notes above) |
| 131 | + |
| 132 | +Known issues: |
| 133 | + |
| 134 | +- I noticed a reboot issue, so I force it with `reboot -ff`. |
| 135 | + |
| 136 | +## Upstream status |
| 137 | + |
| 138 | +- [Kernel](https://github.com/spacemit-com/linux/wiki) |
| 139 | +- [OpenSBI](https://github.com/spacemit-com/opensbi-upstream/wiki) |
| 140 | +- [U-Boot](https://github.com/spacemit-com/u-boot/wiki) |
| 141 | +- [LLVM/GCC](https://github.com/spacemit-com/.github/blob/main/upstream-status/toolchain.md) |
| 142 | +- [llama.cpp](https://github.com/spacemit-com/llama.cpp/wiki) |
0 commit comments