[lowrisc-dev] lowRISC kernel changes rebased over stock 4.19

Gabriel L. Somlo gsomlo at gmail.com
Tue Oct 30 19:02:47 GMT 2018

Hi Jonathan,

First off, thank you and all other lowRISC developers for v0.6 (and also
for your earlier hard work making this system available)!

I am working on a project where I need to get pretty deep under the hood,
and actually understand how everything hangs together. For that kind of
effort, I think it would be a huge help to distill changes from standard,
upstream projects to a concise, minimally invasive patch set rebased
over latest upstream versions, in a way that can be easily kept distinct
and up-to-date as the upstream projects evolve.

I've managed to successfully use https://github.com/riscv/riscv-gnu-toolchain
directly to build every other component of lowRISC v0.6 (specifically
busybox, the kernel, and bbl). That makes it possible to ignore any current
differences between the toolchain fork included in rocket-chip/riscv-tools
and "upstream" :)

Next, I looked at the kernel, and tried to figure out how I can ignore
everything that is *not* lowRISC, and focus only on the specific bits that
*are*! So I came up with the following set of six patches on top of the
latest (4.19) upstream kernel:


This is exactly six commits added to stock upstream:

    1/6: keyboard driver (uart and ps2-over-usb)
    2/6: vga console driver
    3/6: xilinx/nexys4ddr ethernet driver
    4/6: microSD card reader
    5/6: GPIO driver (inserted on top of microSD driver .c file)
    6/6: lowRISC-specific defconfig (separate from default RISC-V defconfig)

I specifically avoided cleaning up indentation and running anything
through checkpatch, to give you a chance to ensure these are roughly the
same files as what's currently present in lowrisc's own v0.6 fork of the
linux source tree (okay, I removed some trailing whitespaces, but
managed to contain my OCD from making further changes *beyond* that :)

With the following patch against riscv-pk's lowrisc.dts:

diff --git a/machine/lowrisc.dts b/machine/lowrisc.dts
index 6e3c4c2..13a79e5 100644
--- a/machine/lowrisc.dts
+++ b/machine/lowrisc.dts
@@ -14,6 +14,7 @@
 	cpus {
 		#address-cells = <1>;
 		#size-cells = <0>;
+		timebase-frequency = <500000>;
 		cpu at 0 {
 			clock-frequency = <0>;
 			compatible = "sifive,rocket0", "riscv";
@@ -33,7 +34,6 @@
 			reg = <0>;
 			riscv,isa = "rv64imafdc";
 			status = "okay";
-			timebase-frequency = <500000>;
 			L3: interrupt-controller {
 				#interrupt-cells = <1>;

...it is possible to avoid touching arch/riscv/kernel/time.c and/or
drivers/clocksource/riscv_timer.c altogether, and use the unmodified
upstream clock initialization code path.

I've built and tested this successfully on the nexys4ddr (with only
busybox for now), using the latest 4.19 kernel and standard

  make ARCH=riscv lowrisc_defconfig
  cp ../initramfs.cpio .
  make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu-

... then built the bbl (boot.bin) file after applying the above
mentioned patch to the device tree source file.

I'd like to run the newly introduced .[ch] files through
scripts/checkpatch.pl and generally bring them up to kernel coding
standards, but wanted to get your overall opinion, thoughs, and
feedback before I started doing anything like that :)

Please let me know what you think.


More information about the lowrisc-dev mailing list