Note that mainstream Linux support is not yet complete, this documentation will also be updated accordingly as support improves.
1.1. Preface#
The Linux mainline included some patches in v6.5-rc1 to provide support for the Lichee Pi 4A board. This article introduces the process of building and running Linux v6.5-rc1 for the LicheePi 4A development board, achieving the effect of: the kernel can successfully start and enter the initramfs command line interface.
1.2. Software Versions#
Software Version
Linux 6.5-rc1
U-Boot 2020.01
OpenSBI 0.9
Buildroot 2023.02.2
1.3. Build U-Boot、OpenSBI#
U-Boot and OpenSBI mainly use the official versions provided by Sipeed, see the relevant sections on building U-Boot and OpenSBI in the RevyOS documentation.
1.4. Build dtb#
When trying to boot with the device tree included in Linux v6.5-rc1, the system will error during PLIC initialization:
Since it was not possible to verify if there were bugs in the device tree, the device tree compiled with the official Sipeed SDK was used instead. According to the RevyOS documentation, after building the kernel, the device tree files are: arch/riscv/boot/dts/thead/light-lpi4a.dtb (for 8GB RAM core board); arch/riscv/boot/dts/thead/light-lpi4a-16gb.dtb (for 16GB RAM core board).
1.5. Build initramfs#
It is relatively simple to build initramfs using Buildroot, just need some basic configuration and it can automatically compile and generate it.
1.5.1. Configure processor architecture#
Filesystem images --->
[*] cpio the root file system(for use as an initial RAM filesystem)
1.5.3. Configure kernel#
Once initramfs is built, you need to enable initramfs in the kernel configuration and specify the location of the generated CPIO file.
General Setup --->
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
() Initramfs source file(s)
1.6. Build Kernel#
The process of building the Linux v6.5-rc1 kernel is similar to RevyOS documentation in the process of building the kernel, It is only necessary to change the kernel configuration to use defconfig under RISC-V architecture:
make CROSS_COMPILE=riscv64-unknown-linux-gnu- ARCH=riscv defconfig
1.6.1. Serial port fails to work#
When trying to start on the development board using the directly compiled Linux v6.5-rc1 kernel, the serial port output will jam and will not continue to display, the related log is as follows:
Assistant
[ 0.876673] Warning: unable to open an initial console.
[ 0.884088] Freeing unused kernel image (initmem) memory: 3744K
[ 0.895429] Run /init as init process
The following will introduce the solution of the problem and the solution.
1.6.2. Troubleshooting#
The following steps consider the possible causes of the problem from the root file system, kernel startup parameters, device tree, and kernel driver, and then check them in turn.
root file system#
The most common reason for this problem is that the console file is missing from the root file system, so you need to enter the following command in the /dev directory of the root file system to create it:
mknod -m 660 console c 5 1
mknod -m 660 null c 1 3
Opening the /dev directory and finding that the console file is not missing does not solve the problem, and when running the built kernel file and initramfs on the QEMU emulator, the QEMU emulator can start up and enter the command line interface of initramfs, so we can infer that the built initramfs can be used.
kernel startup parameters#
When the kernel starts, it needs to be passed some command line parameters by the Bootloader.The console parameter specifies the output port used after the kernel starts, which is usually set to console=ttyS0,115200.If the development board serial port provides a baud rate other than 115200, it needs to be changed.
When using U-Boot as the Bootloader, you can enter the U-Boot command line interface by pressing the Enter key at the start countdown, and enter the printenv command to see the kernel boot parameters bootargs, and you can change the parameter by entering the setenv command.
The boot parameters are also printed in the kernel's boot log, such as:
Then we considered whether there was a problem with the device tree, but the device tree used was provided by the development board manufacturer Sipeed, and it could successfully start the RevyOS provided by the manufacturer (based on Linux v5.10.113). Therefore, it was inferred that the device tree could be used normally.
kernel driver#
Other factors have been almost excluded, and only the kernel-related factors may have problems.However, the built kernel can be successfully started by using QEMU, so the problem is basically locked in the factors related to the development board.We mainly suspect that there may be a problem with the correspondence between the kernel driver and the device tree, and the most suspicious is the serial port driver.
After re-analyzing the boot log, we found the following output:
Basically declared the real cause of the problem: the loading of the serial device failed.
The Linux kernel driver uses the platform device driver model, where the driver and device are loaded into the kernel separately and then matched. Therefore, it is possible that the driver is successfully loaded, but the serial port fails to load. The reason for deferred probe pending may be that the driver that the device depends on has not been properly loaded by the kernel. Then analyze the serial port-related part in the device tree file:
Find out if there is a missing driver in the kernel by searching for the value of the compatible attribute in the code repository.
The serial port uses the driver: "snps, dw-apb-uart"
The serial port dependent interrupt controller intc uses the driver: "riscv, PLIC0"
The serial port dependent clock clk uses the driver: "thead, light-fm-ree-clk"
Through the search found that the serial port dependent clock clk uses the driver "thead, light-fm-ree-clk" missing. After the relevant drivers were transplanted from the kernel provided by Sipeed to Linux v6.5-rc1, it finally started normally.
Solution#
Find the drivers/clk/thead folder in the kernel provided by Sipeed and add it to the drivers/clk folder of Linux v6.5-rc1
Modify the Kconfig file in the thead folder: replace all SOC_THEAD with ARCH_THEAD
Modify the Kconfig and Makefile files under drivers/clk to include the thead folder
Find the include/dt-bindings/clock folder in the kernel provided by Sipeed and add the following header files to the same folder of Linux v6.5-rc1: - light-dspsys.h
light-fm-ap-clock.h
light-mpw-clock.h
light-visys.h
light-vosys.h
light-vpsys.h
Modify the Linux v6.5-rc1 arch/riscv/configs/defconfig file to add
CONFIG_THEAD_CLK=y
CONFIG_CLK_LIGHT_FM=y
After the driver transplantation is completed, the kernel can be recompiled and burned to the development board for normal startup.
2. Reference#
Build Linux v6.5-rc1 for LicheePi 4A
How to troubleshoot deferred probe issues in Linux
[PATCH v3 0/8] Add Sipeed Lichee Pi 4A RISC-V board support
Burn image t@job:lsDesktopDownloadsPicturesriscv−gnu−toolchainoldTemplatesVideosDocumentsMusicPublicsnapu−boott@job: cd ..
t@job:/homecd..t@job:/ ls
bin dev lib libx32 mnt root snap sys var
boot etc lib32 lost+found opt run srv tmp
cdrom home lib64 media proc sbin swapfile usr
t@job:/cdhome/t@job:/home git clone https://github.com/Lichee-Pi/linux.git
fatal: could not create work tree dir 'linux': Permission denied
t@job:/homecdt/t@job: git clone https://github.com/Lichee-Pi/linux.git
Cloning into 'linux'...
remote: Enumerating objects: 6883668, done.
remote: Total 6883668 (delta 0), reused 0 (delta 0), pack-reused 6883668 (from 1)
Receiving objects: 100% (6883668/6883668), 2.57 GiB | 2.12 MiB/s, done.
Resolving deltas: 100% (5678603/5678603), done.
Updating files: 100% (57986/57986), done.
t@job:cdlinuxt@job:/linux ls arch/riscv/configs | grep lichee
ls: cannot access 'arch/riscv/configs': No such file or directory
t@job:~/linux cd ..~m
bash: cd: ..m: No such file or directory
t@job:/linuxcd..t@job: rm -rf linux
t@job:gitclone−−depth=1−blicheerv645 git branch -a
fatal: not a git repository (or any of the parent directories): .git
t@job:lsDesktopD git clone --depth=1 -b lichee4a https://github.com/Lichee-Pi/linux-5.5.git
Cloning into 'linux-5.5'...
Username for 'https://github.com':
Password for 'https://github.com':
remote: Repository not found.
fatal: Authentication failed for 'https://github.com/Lichee-Pi/linux-5.5.git/'
t@job:t@job:
t@job: git clone --depth=1 -b lichee_rv64_5.4_dev https://github.com/Lichee-Pi/linux
Cloning into 'linux'...
warning: Could not find remote branch lichee_rv64_5.4_dev to clone.
fatal: Remote branch lichee_rv64_5.4_dev not found in upstream origin
t@job:[[200ителем.Выполнивзадание,нажмитекнопку"Напроверку".Соблюдайтесроки.Послеоплатызаданиявысможетеоставиителем.: ^C
t@job:lsDesktopD git clone https://github.com/sipeed/LicheeRV-Linux.git
Cloning into 'LicheeRV-Linux'...
Username for 'https://github.com': ^C
t@job:~
It looks like you're trying to build the Linux kernel for the Lichee Pi 4A but are encountering some issues with cloning the correct repository and building the kernel. Let's address each of the issues you've encountered step by step.
Issue 1: Permission Denied when Cloning the Repository
Error Message:
fatal: could not create work tree dir 'linux': Permission denied
Solution:
This error occurs because you're trying to clone the repository into a directory where you don't have write permissions (e.g., /home).
Steps to Fix:
Clone into Your Home Directory:
Make sure you're in your home directory (/home/t or ~) before cloning:
cd ~
git clone https://github.com/Lichee-Pi/linux.git
Issue 2: Missing arch/riscv Directory After Cloning
Error Message:
ls: cannot access 'arch/riscv/configs': No such file or directory
Explanation:
The repository you're cloning (https://github.com/Lichee-Pi/linux.git) might not contain the RISC-V architecture support or is outdated.
Solution:
Instead of cloning the Lichee-Pi/linux.git repository, you should clone the mainline Linux kernel or the specific repository that contains support for the Lichee Pi 4A.
Recommended Steps to Build the Kernel for Lichee Pi 4A
1. Clone the Mainline Linux Kernel
Since support for the Lichee Pi 4A was included in Linux v6.5-rc1, you can clone the mainline Linux kernel and checkout the appropriate version.
Clone the Mainline Kernel:
cd ~
git clone https://github.com/torvalds/linux.git
cd linux
Checkout Version 6.5-rc1:
git checkout v6.5-rc1
2. Verify the arch/riscv Directory Exists
ls arch/riscv
You should see directories like configs, boot, kernel, etc.
3. Check for Lichee Pi 4A Configuration
Check if there's a default configuration for the Lichee Pi 4A:
ls arch/riscv/configs | grep lichee
As of Linux v6.5-rc1, there might not be a default config named licheepi4a_defconfig. If not, you'll need to configure the kernel manually.
4. Configure the Kernel
Load the Default RISC-V Configuration:
make ARCH=riscv defconfig
Customize Kernel Configuration:
make ARCH=riscv menuconfig
In menuconfig, navigate to:
System Type -> Enable options specific to the Lichee Pi 4A if available.
Ensure the required drivers are enabled:
Serial Drivers: Enable snps,dw-apb-uart
Clock Drivers: Since you need thead,light-fm-ree-clk, you may need to enable it or add it manually.
Interrupt Controllers: Enable riscv,plic0
5. Addressing Missing Drivers
From your previous steps, it's clear that the thead,light-fm-ree-clk driver is missing from the mainline kernel.
Solution:
Since the driver isn't in the mainline kernel, you need to manually add it.
Steps:
Obtain the Driver Source:
Unfortunately, the repositories you tried to clone from Sipeed (e.g., https://github.com/sipeed/LicheeRV-Linux.git) are private or no longer available.
You can try accessing the drivers from a different fork or ask the manufacturer for the driver source code.
Add the Driver to the Kernel Source:
Once you have the driver source files (from drivers/clk/thead in Sipeed's kernel):
Copy the thead directory into drivers/clk/ in your mainline kernel source.
Copy the necessary header files into include/dt-bindings/clock/.
Modify Kernel Configuration Files:
Update drivers/clk/Kconfig and drivers/clk/Makefile to include the thead directory and driver.
Replace all instances of SOC_THEAD with ARCH_THEAD in the Kconfig files if needed.
Now that you've added the necessary drivers and configured the kernel, you can build it.
make -j$(nproc) ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu-
7. Build and Include initramfs
As per your initial steps, make sure your initramfs is correctly built and the kernel is configured to include it.
8. Booting the Kernel
After building the kernel, follow the standard steps to copy it to your boot medium (e.g., SD card) and attempt to boot your Lichee Pi 4A.
Additional Tips
Check for Updated Repositories:
Search for any updated repositories or official sources from Sipeed or Lichee Pi that might have the necessary files.
Community Assistance:
Visit forums or community pages related to the Lichee Pi 4A to see if others have shared the necessary drivers or have alternative solutions.
Contact Support:
If possible, contact Sipeed or the maintainers of the Lichee Pi 4A for access to the required source code or for any available patches.
Understanding the Errors in Your Attempt
Cloning Non-Existent Branches:
Error:
fatal: Remote branch lichee_rv64_5.4_dev not found in upstream origin
This error indicates that the branch lichee_rv64_5.4_dev does not exist in the repository you're trying to clone.
Cloning Private Repositories:
Prompt:
Username for 'https://github.com':
If Git prompts for a username, it often means the repository is private, and you need proper authentication to access it. If you don't have access, you won't be able to clone it.
Summary
Clone the mainline Linux kernel and checkout version v6.5-rc1.
Manually add any missing drivers required by the Lichee Pi 4A.
Configure the kernel to include the necessary drivers.
Build the kernel and attempt to boot.
I hope this helps you resolve the issues you're facing. Let me know if you have any questions or need further assistance!