191 lines
6.0 KiB
Markdown
191 lines
6.0 KiB
Markdown
# Build Kernel
|
|
|
|
ODROID Linux kernel cross compile
|
|
|
|
## Package requirement
|
|
In order to build Linux kernel, you need to install developement packages required.
|
|
|
|
```Bash
|
|
sudo apt install git build-essential bc flex bison libssl-dev libncurses-dev
|
|
```
|
|
|
|
## Get compiler
|
|
For build kernel, you must get cross-compiler, and set some environment values.
|
|
|
|
| Board | Branch | Cross-compiler |
|
|
|--------------------------|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| ODROID-C4/HC4/N2/N2L/N2+ | odroidg12-4.9.y | [](https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz) |
|
|
| ODROID-M1 | odroidm1-4.19.y | [](https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz) |
|
|
| ODROID-M1S/M2 | odroidm1-5.10.y | [](https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz) |
|
|
|
|
```Bash
|
|
tar Jxvf gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz
|
|
|
|
export ARCH=arm64
|
|
export CROSS_COMPILE=aarch64-linux-gnu-
|
|
export PATH=/toolchain/path/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/:$PATH
|
|
```
|
|
|
|
## Connect odroid and mount
|
|
ODROID, which uses an external eMMC, connects to a PC using an [eMMC Writer](https://www.hardkernel.com/shop/usb3-0-emmc-module-writer-2/).
|
|
|
|
For embedded eMMC like M1S/M2, there are two ways to connect to a PC.
|
|
|
|
### Use sd card
|
|
First, burn below image to sd card.
|
|
|
|
| Board | Image |
|
|
|-------|-------------------------------------------------------------------------------|
|
|
| M1S | [](https://dn.odroid.com/RK3566/ODROID-M1S/Installer/ODROID-M1S_EMMC2UMS.img) |
|
|
| M2 | [](https://dn.odroid.com/RK3588S2/ODROID-M2/Installer/ODROID-M2_EMMC2UMS.img) |
|
|
|
|
|
|
And boot ODROID, (If M2, set boot switch to Micro SD before boot ODROID), Then connect odroid to your PC using a USB cable.
|
|
|
|
### Use usb to uart board
|
|
Connect [USB-UART Module](https://www.hardkernel.com/shop/usb-uart-2-module-kit-copy/) to pc and ODROID.
|
|
|
|
Then, connect to ODROID serial using a terminal emulator such as minicom.
|
|
|
|
| Board | Baud rate |
|
|
|------------------|-------------|
|
|
| M1/M1S/M2 | 1500000 8N1 |
|
|
| Except M1/M1S/M2 | 115200 8N1 |
|
|
|
|
After booting the board, quickly press Ctrl+C to stop booting on u-boot.
|
|
|
|
```Plain text
|
|
...
|
|
...
|
|
aclk_perimid 300000 KHz
|
|
hclk_perimid 150000 KHz
|
|
pclk_pmu 100000 KHz
|
|
Net: No ethernet found.
|
|
Hit key to stop autoboot('CTRL+C'): 0
|
|
=> <INTERRUPT>
|
|
=> <INTERRUPT>
|
|
=> <INTERRUPT>
|
|
=>
|
|
```
|
|
|
|
Use `ums` command, you can connect ODROID's eMMC as storage.
|
|
|
|
```Plain Text
|
|
=> ums mmc 0
|
|
UMS: LUN 0, dev 0, hwpart 0, sector 0x0, count 0x747c000
|
|
/
|
|
```
|
|
|
|
If you want stop, just press Ctrl+C, and enter reset for reboot board.
|
|
```Plain Text
|
|
=> ums mmc 0
|
|
UMS: LUN 0, dev 0, hwpart 0, sector 0x0, count 0x747c000
|
|
CTRL+C - Operation aborted
|
|
=> reset
|
|
... Reboot start ...
|
|
```
|
|
|
|
|
|
## Set kernel config
|
|
One way is to copy the config file from the ODROID board.
|
|
|
|
```Bash
|
|
# In linux kernel source
|
|
cp /path/to/mounted/boot/partion/config-{kernel version}-odroid-arm64 .config
|
|
```
|
|
|
|
|
|
## Get source
|
|
|
|
You can get kernel source code from Hardkernel's github
|
|
|
|
[https://github.com/hardkernel/linux](https://github.com/hardkernel/linux)
|
|
|
|
In ODROID, you can get branch name use below command:
|
|
```Bash
|
|
uname -r | awk -F'.' '{print "odroid-" $1 "." $2 ".y"}'
|
|
```
|
|
|
|
| Board | Branch |
|
|
|--------------------------|-----------------|
|
|
| ODROID-C4/HC4/N2/N2L/N2+ | odroidg12-4.9.y |
|
|
| ODROID-M1 | odroidm1-4.19.y |
|
|
| ODROID-M1S/M2 | odroidm1-5.10.y |
|
|
|
|
|
|
Clone kernel source from github
|
|
```Bash
|
|
git clone --depth 1 https://github.com/tobetter/linux -b {branch_name}
|
|
```
|
|
|
|
|
|
## Build kernel
|
|
You have to tweak a couple of things once in order to let the package `flash-kernel` install your custom kernel properly.
|
|
```Bash
|
|
cp /boot/config-$(uname -r) .config
|
|
sed -i "s/.*CONFIG_LOCALVERSION_AUTO.*/CONFIG_LOCALVERSION_AUTO=y/g" .config
|
|
echo "-odroid-arm64" > .scmversion
|
|
```
|
|
|
|
Then. start build kernel
|
|
```Bash
|
|
make oldconfig
|
|
make
|
|
```
|
|
Kernel builds take a lot of time.
|
|
Use `-j` option in `make` command, Make `make` use multicore.
|
|
|
|
|
|
|
|
|
|
## Install kernel binary
|
|
After the build, three main results are generated:
|
|
- Kernel image
|
|
- Kernel modules
|
|
- Device tree binary(dtb), overlay files
|
|
|
|
In ODROID storage has multiple partitions.
|
|
There are usually uboot, boot, and rootfs partitions.
|
|
|
|
The Kernel image and dtb files are stored in ODROID's boot partition,
|
|
and The kernel modules are stored in /usr/lib/modules directory in root partition.
|
|
|
|
First, you must mount boot and root partitions.
|
|
If you use ubuntu-desktop, it will usually be mounted automatically.
|
|
|
|
For install kernel, you must set some environment variables.
|
|
```Bash
|
|
export ARCH=arm64
|
|
export INSTALL_PATH=/mounted/BOOT/partition/path
|
|
export INSTALL_MOD_PATH=/mounted/root/partition/path
|
|
```
|
|
|
|
Maybe you need sudo permission, use `sudo -E`, you can keep environment variable values.
|
|
|
|
```Bash
|
|
# kernel install
|
|
sudo -E make install
|
|
|
|
# dtbs install
|
|
sudo -E make dtbs_install
|
|
|
|
# modules install
|
|
sudo -E make modules_install
|
|
```
|
|
|
|
|
|
### Change kernel
|
|
You can see installed kernel list, use command `linux-version list`.
|
|
|
|
If you want change kernel version, use `flash-kernel`.
|
|
```Bash
|
|
sudo flash-kernel --force 5.9.0-odroid-arm64
|
|
```
|
|
|
|
<seealso>
|
|
<category ref="external">
|
|
<a href="https://github.com/hardkernel/linux">Official kernel source</a>
|
|
<a href="https://github.com/tobetter/linux">Tobetter's kernel source</a>
|
|
<a href="https://docs.linuxfactory.or.kr/guides/compile_kernel.html">Build odroid kernel</a>
|
|
</category>
|
|
</seealso> |