73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 1) # Linux kernel for StarFive's JH7100 RISC-V SoC
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 2)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 3) ## What is this?
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 4)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 5) The [JH7100][soc] is a Linux-capable dual-core 64bit RISC-V SoC and this tree
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 6) is meant to collect all the in-development patches for running Linux on boards
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 7) using this. So far there are two such boards and both are supported by this tree:
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 8)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 9) 1) [StarFive VisionFive][visionfive]
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 10) 2) [BeagleV Starlight Beta][starlight]
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 11)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 12) The VisionFive boards aren't quite shipping yet, but you can already
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 13) [register interest][interest] and ask questions on the [forum][].
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 14)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 15) About 300 BeagleV Starlight Beta boards were sent out to developers in
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 16) April 2021 in preparation for an eventual BeagleV branded board using the
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 17) updated JH7110 chip. The BeagleBoard organization has since [cancelled that
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 18) project][beaglev] though.
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 19)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 20)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 21) [visionfive]: https://github.com/starfive-tech/VisionFive
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 22) [interest]: http://starfive.mikecrm.com/doQXj99
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 23) [forum]: https://forum.rvspace.org/c/visionfive/6
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 24) [starlight]: https://github.com/beagleboard/beaglev-starlight
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 25) [soc]: https://github.com/starfive-tech/JH7100_Docs
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 26) [beaglev]: https://beaglev.org/blog/2021-07-30-the-future-of-beaglev-community
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 27)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 28) ## Cross-compiling
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 29)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 30) Cross-compiling the Linux kernel is surprisingly easy since it doesn't depend
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 31) on any (target) libraries and most distributions already have packages with a
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 32) working cross-compiler. We'll also need a few other tools to build everything:
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 33) ```shell
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 34) # Debian/Ubuntu
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 35) sudo apt-get install libncurses-dev libssl-dev bc flex bison make gcc gcc-riscv64-linux-gnu
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 36) # Fedora
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 37) sudo dnf install ncurses-devel openssl openssl-devel bc flex bison make gcc gcc-riscv64-linux-gnu
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 38) # Archlinux
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 39) sudo pacman -S --needed ncurses openssl bc flex bison make gcc riscv64-linux-gnu-gcc
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 40) ```
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 41)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 42) The build system needs to know that we want to cross-compile a kernel for
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 43) RISC-V by setting `ARCH=riscv`. It also needs to know the prefix of our
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 44) cross-compiler using `CROSS_COMPILE=riscv64-linux-gnu-`. Also let's assume
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 45) we're building on an 8-core machine so compilation can be greatly sped up by
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 46) telling make to use all 8 cores with `-j8`.
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 47)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 48) First we need to configure the kernel though. Linux has a *very* extensive
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 49) configuration system, but you can get a good baseline configuration for the
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 50) boards using:
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 51) ```shell
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 52) make -j8 ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- visionfive_defconfig
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 53) ```
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 54)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 55) There is nothing magic about this configuration other than it has all the
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 56) drivers enabled that are working for the hardware on the boards. In fact it has
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 57) very little extra features enabled which is great for compile times, but you
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 58) are very much encouraged to add additional drivers and configure your kernel
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 59) further using
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 60) ```shell
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 61) make -j8 ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- nconfig
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 62) ```
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 63)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 64) Now compile the whole thing with
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 65) ```
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 66) make -j8 ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 67) ```
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 68)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 69)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 70) ## Installing
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 71)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 72) Once the build has finished the resulting kernel can be found at
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 73) ```shell
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 74) arch/riscv/boot/Image
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 75) ```
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 76) You'll also need the matching device tree at
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 77) ```shell
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 78) arch/riscv/boot/dts/starfive/jh7100-starfive-visionfive-v1.dtb
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 79) ```
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 80) (If you have a Starlight board you should instead be using `jh7100-beaglev-starlight.dtb`.)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 81)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 82) These two files should be copied to the boot partition on the SD card. In the
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 83) default [Fedora image][fedora] this is `/dev/mmcblk0p3` and is mounted at `/boot`.
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 84)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 85) Now add the following entry to the `grub.cfg` file:
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 86) ```
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 87) menuentry 'My New Kernel' {
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 88) linux /Image earlycon console=ttyS0,115200n8 stmmac.chain_mode=1 root=/dev/mmcblk0p4 rootwait
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 89) devicetree /jh7100-starfive-visionfive-v1.dtb
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 90) }
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 91) ```
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 92)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 93) This assumes your root file system is at `/dev/mmcblk0p4` which it is in the
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 94) default [Fedora image][fedora].
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 95)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 96) The `visionfive_defconfig` doesn't enable modules, but if you enabled them in
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 97) your build you'll also need to install them in `/lib/modules/` on the root file
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 98) system. How to do that best is out of scope for this README though.
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 99)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 100) [fedora]: https://github.com/starfive-tech/Fedora_on_StarFive/
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 101)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 102) ## Status
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 103)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 104) #### SoC
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 105)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 106) - [x] Clock tree
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 107) - [x] Resets
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 108) - [x] Pinctrl/Pinmux
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 109) - [x] GPIO
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 110) - [x] Serial port
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 111) - [x] I2C
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 112) - [x] SPI
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 113) - [x] MMC / SDIO / SD card
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 114) - [x] Random number generator
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 115) - [x] Temperature sensor
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 116) - [x] Ethernet, though `stmmac.chain_mode=1` needed on the cmdline
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 117) - [x] USB, USB 3.0 is broken with `CONFIG_PM=y`
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 118) - [x] DRM driver
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 119) - [x] NVDLA
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 120) - [x] Watchdog
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 121) - [x] PWM DAC for sound through the minijack, only 16kHz samplerate for now
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 122) - [ ] I2S [WIP]
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 123) - [ ] TDM [WIP]
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 124) - [ ] MIPI-DSI [WIP]
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 125) - [ ] MIPI-CSI [WIP]
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 126) - [ ] ISP [WIP]
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 127) - [ ] Video Decode [WIP]
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 128) - [ ] Video Encode [WIP]
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 129) - [ ] QSPI
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 130) - [ ] Security Engine
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 131) - [ ] NNE50
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 132) - [ ] Vision DSP
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 133)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 134) #### Board
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 135)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 136) - [x] LED
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 137) - [x] PMIC / Reboot
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 138) - [x] Ethernet PHY
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 139) - [x] HDMI
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 140) - [x] AP6236 Wifi
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 141) - [x] AP6236 Bluetooth, with a [userspace tool][patchram]
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 142) - [x] I2C EEPROM (VisionFive only)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 143) - [ ] GD25LQ128DWIG (VisionFive) / GD25LQ256D (Starlight) flash
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 144)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 145) [patchram]: https://github.com/AsteroidOS/brcm-patchram-plus
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 146)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 147) ## Contributing
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 148)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 149) If you're working on cleaning up or upstreaming some of this or adding support
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 150) for more of the SoC I'd very much like to incorporate it into this tree. Either
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 151) send a pull request, mail or contact Esmil on IRC/Slack.
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 152)
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 153) Also think of this tree mostly as a collection of patches that will hopefully
73e3caed13cf0 (Emil Renner Berthing 2021-05-05 20:03:04 +0200 154) mature enough to be submitted upstream eventually. So expect regular rebases.