Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Difference between revisions of "Rockpi4/dev/kernel-mainline"

< Rockpi4‎ | dev
(Build kernel)
 
(5 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
ROCK Pi 4 is officially supported in mainline kernel since v5.1 thanks to developer Akash Gajjar from Mentor. Below is how to build it on a X86 Linux host PC and run on ROCK Pi 4.
 
ROCK Pi 4 is officially supported in mainline kernel since v5.1 thanks to developer Akash Gajjar from Mentor. Below is how to build it on a X86 Linux host PC and run on ROCK Pi 4.
  
=== Get the mainline kernel source ===
+
== Please help to fix/enhance this page ==
  
    wget https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/snapshot/linux-5.2-rc6.tar.gz
+
=== Current status ===
    tar -xvzf linux-5.2-rc6.tar.gz
+
    cd linux-5.1.15/
+
  
=== Install toolchain from Linaro ===
+
As of 01/07/2020, these instructions are incomplete, incorrect and do not result in a working kernel. Please help to fix them.
  
    wget https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
+
Use [[https://forum.radxa.com/t/mainline-support-for-rockpi-4/131/91]] to discuss this page.
    sudo tar xvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz  -C /usr/local/
+
    export ARCH=arm64
+
    export CROSS_COMPILE=/usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
+
  
=== Build kernel===
+
Tested with
  
    make menuconfig
+
* RockPI 4 A with 2GByte
 +
* 16 GByte eMMC module (no uSD)
 +
* Current debian (5.5.0-rc5-00039-gae6088216ce4).
  
*In the menu-config TUI:
+
Without any overlays configured, the kernel starts to boot with working console output, but then it seems to hang after the following output:
*Navigate to Platform selection  ---> Rockchip Platforms
+
*Select Rockchip Platforms
+
  
    make -j6
+
  ...
 +
  [  14.670351] mmc_host mmc0: Bus speed (slot 0) = 200000Hz (slot req 200000Hz, actual 200000HZ div = 0)
 +
  [  14.674934] hctosys: unable to open rtc device (rtc0)
  
copy '''arch/arm64/boot/Image''' and '''arch/arm64/boot/dts/rk3399-rock-pi-4.dtb''' to your ROCK Pi 4.
+
=== ID of root file system ===
  
'''If you run on debian you should Install the latest u-boot and kernel before Install mainline kernel on ROCK Pi 4.'''
+
The instructions show a specific PARTUUID. It seems as if the instructions should explain that the PARTUUID needs to be changed according to the PARTUUID of the boot partition on the boot device - aka: The same PARTUUID used with the 'old' radxa 4.4 kernel ?!
  
== Install the latest u-boot and kernel==  
+
=== Use of overlays ===
    apt-get install rockpi4b-rk-u-boot-latest
+
  
Manually run the u-boot flash script
+
The instructions on this page do not describe if/how overlays can be used with mainline kernel:
    /usr/local/sbin/rockpi4b_upgrade_bootloader.sh
+
  
 +
The instructions do not explain if overlays need to be compiled for the new kernel or not.
  
Type '''YES''' to perform the uboot.img flashing.
+
The instructions do not explain why overlays may fail to work, for example because all or some of the overlays do not have according entry points in the mainline kernel ?
  
then install kernel 
+
The instructions do not explain if it is possible to configure u-boot so that there are different overlays enabled for different kernels - e.g.: all necessary overlays for the radxa 4.4 kernel and non (or others) for a mainline kernel. Is this even possible ?
    apt-get install linux-base
+
    apt-get install linux-4.4-latest
+
  
 +
Result: When attempting to use ANY overlays such as spi1-flash, the boot process fails to merge the overlays and reverts to boot the first (default) kernel instead.
  
After installation, check file '''/boot/extlinux/extlinux.conf'''. It lists all kernel version installed in ROCK Pi. The kernel corresponding to the first label is the newest version and the first boot option.
+
The console log for this looks as follows:
  
==== Install it on ROCK Pi 4.====
+
    ...
 +
    reading /rk3399-rock-pi-4.dtb
 +
    54207 bytes read in 13 ms (4 MiB/s)
 +
    fdt addr 0000000008300000
 +
    fdt magic number edfe0dd0
 +
    fdt size 1048576
 +
    merge_dts_overlay
 +
    Retrieving file: /overlays/spi1-flash.dtbo
 +
    reading /overlays/spi1-flash.dtbo
 +
    765 bytes read in 11 ms (67.4 KiB/s)
 +
    overlay dtb(0x0000000008200000) is valid
 +
    fdt_overlay_apply 0000000008300000 0000000008200000
 +
    fdt_overlay_apply(): FDT_ERR_NOTFOUND
 +
    Can't load dts overlay
 +
    Can not merge dts overlay
 +
    ERROR: Did not find a cmdline Flattened Device Tree
 +
    Could not find a valid device tree
 +
    ...
  
     rockpi4# cp Image rk3399-rock-pi-4.dtb /boot/
+
=== Loadable modules ===
     rockpi4#vi /boot/extlinux/extlinux.conf
+
 
 +
The kernel will need dynamically loaded modules. These need to be installed into /lib/modules/<kernel-name>.
 +
 
 +
It is unclear how to best do this when compiling on a separate PC (cross-compilation as explained).
 +
 
 +
When compiling locally on the Rock PI 4, this is easily achied by using "make modules_install".
 +
 
 +
=== Already fixed ===
 +
 
 +
01/07/2020 Added explanations how to add new kernel to existing boot file and choose from serial console during boot.
 +
 
 +
== Build kernel on linux PC ==
 +
 
 +
=== Requirement ===
 +
 
 +
    $ sudo apt-get install libncurses-dev flex bison libssl-dev git
 +
 
 +
=== Get the mainline kernel source ===
 +
 
 +
    $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
 +
    $ cd linux
 +
 
 +
=== Install toolchain from Linaro ===
 +
 
 +
    $ wget https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
 +
    $ sudo tar xvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz  -C /usr/local/
 +
    $ export ARCH=arm64
 +
    $ export CROSS_COMPILE=/usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
 +
 
 +
=== Build kernel===
 +
 
 +
    $ make defconfig
 +
    $ make -j6
 +
 
 +
Copy '''arch/arm64/boot/Image''' and '''arch/arm64/boot/dts/rockchip/rk3399-rock-pi-4.dtb''' to your ROCK Pi 4.
 +
 
 +
== Install it on ROCK Pi 4.==
 +
 
 +
=== Copy files ===
 +
 
 +
     $ sudo cp Image rk3399-rock-pi-4.dtb /boot/
 +
 
 +
=== Configure and Reboot ===
 +
 
 +
     $ sudo vim /boot/extlinux/extlinux.conf
 +
 
 +
Add an entry as follows:
  
*Change the contents to:
 
 
   label kernel-mainline
 
   label kernel-mainline
 
   kernel /Image
 
   kernel /Image
 
   fdt /rk3399-rock-pi-4.dtb
 
   fdt /rk3399-rock-pi-4.dtb
   append earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 coherent_pool=1m earlyprintk console=ttyS2,1500000n8 rw root=PARTUUID=b921b045-1d rootfstype=ext4 init=/sbin/init rootwaitt
+
   append earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 coherent_pool=1m earlyprintk console=ttyS2,1500000n8 rw root=PARTUUID=b921b045-1d rootfstype=ext4 init=/sbin/init rootwait
  
 
Reboot you will have the new kernel booting.
 
Reboot you will have the new kernel booting.
 +
 +
If you have a serial console connected to the Rock PI 4, you can also add this kernel as a second or further boot entry and then select it during the bootstrap process as follows:
 +
 +
  ...
 +
  Retrieving file: /extlinux/extlinux.conf
 +
  reading /extlinux/extlinux.conf
 +
  956 bytes read in 17 ms (54.7 KiB/s)
 +
  select kernel
 +
  1:      kernel-4.4.154-100-rockchip-gf7c3df9923c2
 +
  2:      kernel-mainline
 +
  Enter choice: 2
 +
  ...
 +
  ...
 +
  2:      kernel-mainline
 +
  Retrieving file: /Image
 +
  reading /Image
 +
 +
You need to be fast typing the desired number (2).
 +
 +
The benefit of this approach is that the bootstrap process will automatically revert booting the first (working radxa) kernel when the newly built kernel fails to boot - or that you can simply power cycle to boot the working kernel in case the newly built kernel does not work.

Latest revision as of 12:09, 18 September 2021

    ROCK Pi 4 >  Development >  Build mainline kernel(5.x)

ROCK Pi 4 is officially supported in mainline kernel since v5.1 thanks to developer Akash Gajjar from Mentor. Below is how to build it on a X86 Linux host PC and run on ROCK Pi 4.

Please help to fix/enhance this page

Current status

As of 01/07/2020, these instructions are incomplete, incorrect and do not result in a working kernel. Please help to fix them.

Use [[1]] to discuss this page.

Tested with

  • RockPI 4 A with 2GByte
  • 16 GByte eMMC module (no uSD)
  • Current debian (5.5.0-rc5-00039-gae6088216ce4).

Without any overlays configured, the kernel starts to boot with working console output, but then it seems to hang after the following output:

  ...
  [   14.670351] mmc_host mmc0: Bus speed (slot 0) = 200000Hz (slot req 200000Hz, actual 200000HZ div = 0)
  [   14.674934] hctosys: unable to open rtc device (rtc0)

ID of root file system

The instructions show a specific PARTUUID. It seems as if the instructions should explain that the PARTUUID needs to be changed according to the PARTUUID of the boot partition on the boot device - aka: The same PARTUUID used with the 'old' radxa 4.4 kernel ?!

Use of overlays

The instructions on this page do not describe if/how overlays can be used with mainline kernel:

The instructions do not explain if overlays need to be compiled for the new kernel or not.

The instructions do not explain why overlays may fail to work, for example because all or some of the overlays do not have according entry points in the mainline kernel ?

The instructions do not explain if it is possible to configure u-boot so that there are different overlays enabled for different kernels - e.g.: all necessary overlays for the radxa 4.4 kernel and non (or others) for a mainline kernel. Is this even possible ?

Result: When attempting to use ANY overlays such as spi1-flash, the boot process fails to merge the overlays and reverts to boot the first (default) kernel instead.

The console log for this looks as follows:

   ...
   reading /rk3399-rock-pi-4.dtb
   54207 bytes read in 13 ms (4 MiB/s)
   fdt addr 0000000008300000
   fdt magic number edfe0dd0
   fdt size 1048576
   merge_dts_overlay
   Retrieving file: /overlays/spi1-flash.dtbo
   reading /overlays/spi1-flash.dtbo
   765 bytes read in 11 ms (67.4 KiB/s)
   overlay dtb(0x0000000008200000) is valid
   fdt_overlay_apply 0000000008300000 0000000008200000
   fdt_overlay_apply(): FDT_ERR_NOTFOUND
   Can't load dts overlay
   Can not merge dts overlay
   ERROR: Did not find a cmdline Flattened Device Tree
   Could not find a valid device tree
   ...

Loadable modules

The kernel will need dynamically loaded modules. These need to be installed into /lib/modules/<kernel-name>.

It is unclear how to best do this when compiling on a separate PC (cross-compilation as explained).

When compiling locally on the Rock PI 4, this is easily achied by using "make modules_install".

Already fixed

01/07/2020 Added explanations how to add new kernel to existing boot file and choose from serial console during boot.

Build kernel on linux PC

Requirement

   $ sudo apt-get install libncurses-dev flex bison libssl-dev git

Get the mainline kernel source

   $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
   $ cd linux

Install toolchain from Linaro

   $ wget https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
   $ sudo tar xvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz  -C /usr/local/
   $ export ARCH=arm64
   $ export CROSS_COMPILE=/usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-

Build kernel

   $ make defconfig
   $ make -j6

Copy arch/arm64/boot/Image and arch/arm64/boot/dts/rockchip/rk3399-rock-pi-4.dtb to your ROCK Pi 4.

Install it on ROCK Pi 4.

Copy files

   $ sudo cp Image rk3399-rock-pi-4.dtb /boot/

Configure and Reboot

   $ sudo vim /boot/extlinux/extlinux.conf

Add an entry as follows:

  label kernel-mainline
  kernel /Image
  fdt /rk3399-rock-pi-4.dtb
  append earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 coherent_pool=1m earlyprintk console=ttyS2,1500000n8 rw root=PARTUUID=b921b045-1d rootfstype=ext4 init=/sbin/init rootwait

Reboot you will have the new kernel booting.

If you have a serial console connected to the Rock PI 4, you can also add this kernel as a second or further boot entry and then select it during the bootstrap process as follows:

  ...
  Retrieving file: /extlinux/extlinux.conf
  reading /extlinux/extlinux.conf
  956 bytes read in 17 ms (54.7 KiB/s)
  select kernel
  1:      kernel-4.4.154-100-rockchip-gf7c3df9923c2
  2:      kernel-mainline
  Enter choice: 2
  ...
  ...
  2:      kernel-mainline
  Retrieving file: /Image
  reading /Image

You need to be fast typing the desired number (2).

The benefit of this approach is that the bootstrap process will automatically revert booting the first (working radxa) kernel when the newly built kernel fails to boot - or that you can simply power cycle to boot the working kernel in case the newly built kernel does not work.