0. Preamble
Why compile the kernel?
For the support of some peripherals, it is necessary to update the kernel implementation after adding peripheral drivers.
PC operating system: Ubuntu 20.04
Kernel version: linux-3.10.tar.gz
Cross tool chain: gcc-4.9.3-64-gnu.tar.gz
1. Compile the Godson Pie kernel
-
Loongson Pie Kernel Download
Download URL: http://ftp.loongnix.cn/embedd/ls2k/
The selected kernel is: linux-3.10.tar.gz
Decompress the Kernel code compression package on the host computer, in the ~ directory
mkdir -p loongson cd loongson tar -zxvf 压缩包名 -C ~/loongson
Copy the kernel configuration file of Loongson Pi to the current directory (note that it is ".config", remember to enter the dot at the beginning)
sudo cp arch/mips/configs/loongson2k1000_defconfig .config
-
Introduce the downloaded cross-compilation toolchain
Download URL: http://ftp.loongnix.cn/embedd/ls3a/toolchain/
The model I chose is: gcc-4.9.3-64-gnu.tar.gz
Unzip the package folder:
tar -xvf gcc-4.9.3-64-gnu.tar.gz
Then enter the unzipped directory:
cd ./opt/gcc-4.9.3-64-gnu/bin pwd ls
You can use ls to check which files are in this folder, and how they are named.
Copy the "path" generated by pwd, and replace the path of the following command to add environment variables.
export PATH=路径:$PATH export PATH=/home/caistrong/loongson/opt/gcc-4.9.3-64-gnu/bin:$PATH
-
Open GUI
First switch to the folder where the kernel is downloaded, and then enter the following command
cd ~/loongson/linux-3.10 sudo apt-get install libncurses5-dev make menuconfig ARCH=mips
-
Parameter adjustment
For the specific adjustment method, please refer to P122 of "Using the Core Detection Core Loongson Pie to Develop Practical Combat"Or https://www.bilibili.com/video/BV1DJ411e7Se?spm_id_from=333.880.my_history.page.click&vd_source=427133ec405e7923eb9d5bbc83d58d1e
If there are too many parameters, it seems that the compilation will fail. -
start compiling
method one:
Enter the following commands in sequence on the command line:
make vmlinuz CROSS_COMPILE=mips64el-linux- ARCH=mips DEBUG=-g mips64el-linux-strip vmlinuz
The first line: The parameter of the file in CROSS_COMPILE is the prefix of the file in the /home/caistrong/loongson/opt/gcc-4.9.3-64-gnu/bin folder.
The second line: mips64el-linux-strip is a tool of the cross-compilation toolchain, let it compile vmlinuz again
Method Two:
Create a script file to compile
touch cmd.sh vim cmd.sh
Contents of cmd.sh
#!/bin/bash export PATH=/home/caistrong/loongson/opt/gcc-4.9.3-64-gnu/bin:$PATH make vmlinuz CROSS_COMPILE=mips64el-linux- ARCH=mips DEBUG=-g -j4 mips64el-linux-strip vmlinuz
run script
chmod 777 cmd.sh sudo ./cmd.sh
-
Copy the generated vmlinuz file to the U disk
sudo cp vmlinuz /media/caistrong/382E-C0A8/
The path behind is where my U disk is mounted
-
After inserting the U disk
into the Loongson Pi, the serial port failed to open, and I couldn’t understand the commands. I tried to do it, but it still failed.
reference link
Loongson TechLive Phase 3: Compiling and updating the Linux kernel for Loongson Pie