# Compiling Linux Kernel 5.15 LTS

<abstract>
This article illustrates how to generate a bootable Linux Kernel for Acme Systems SOM
from scratch
</abstract>

## Prerequisite

* Install the ARM toolchain: @article='arm9_toolchain'
* It is advisable to have a Debug Port Interface like [DPI](/DPI) or [USB-3V-SER](/USB-3V-SER) 
to check the error messages during the kernel bootstrap

## Step-by-step procedure

### Kernel sources download

Open a terminal on your Linux PC and download the Linux Kernel sources from the main stream repository:

	wget https://github.com/linux4microchip/linux/archive/refs/heads/linux-5.15-mchp.zip
	unzip linux-5.15-mchp.zip
	mv linux-linux-5.15-mchp linux-5.15-mchp
	cd linux-5.15-mchp

Download and set the Kernel defconfig to use for your SOM:

[Roadrunner](/roadrunner)

	wget https://www.acmesystems.it/www/compile_kernel_5_15/acme-roadrunner_defconfig -O arch/arm/configs/acme-roadrunner_defconfig
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- acme-roadrunner_defconfig

[Acqua](/acqua)

	wget https://www.acmesystems.it/www/compile_kernel_5_15/acme-acqua_defconfig -O arch/arm/configs/acme-acqua_defconfig
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- acme-acqua_defconfig

[Aria](/aria)

	wget https://www.acmesystems.it/www/compile_kernel_5_15/acme-aria_defconfig -O arch/arm/configs/acme-aria_defconfig
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-aria_defconfig

[Arietta](/arietta)

	wget https://www.acmesystems.it/www/compile_kernel_5_15/acme-arietta_defconfig -O arch/arm/configs/acme-arietta_defconfig
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-arietta_defconfig

### Customize the default Linux Kernel configuration:

If you need to customize the Kernel configuration or you just want to take a look
around the Kernel setup type:

	make ARCH=arm menuconfig

and navigate inside the Kernel configuration using the arrow keys and 
following the help provided by the menuconfig interface.

### Generate the Device Tree Blob file (.dtb)

Download and compile the device tree file:

[Roadrunner](/roadrunner)

	wget https://www.acmesystems.it/www/compile_kernel_5_15/acme-roadrunner.dts -O arch/arm/boot/dts/acme-roadrunner.dts
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- acme-roadrunner.dtb

[Acqua](/acqua)

	wget https://www.acmesystems.it/www/compile_kernel_5_15/acme-acqua.dts -O arch/arm/boot/dts/acme-acqua.dts
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- acme-acqua.dtb

[Aria](/aria)

	wget https://www.acmesystems.it/www/compile_kernel_5_15/acme-aria.dts -O arch/arm/boot/dts/acme-aria.dts
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-aria.dtb

[Arietta](/arietta)

	wget https://www.acmesystems.it/www/compile_kernel_5_15/acme-arietta.dts -O arch/arm/boot/dts/acme-arietta.dts
	make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-arietta.dtb

### Compile the Kernel image

Compile the Linux Kernel sources and generate the binary compressed 
image file to save in the first partition of microSD card.

[Roadrunner](/roadrunner) and [Acqua](/roadrunner)

	make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage

[Aria](/aria) and [Arietta](/arietta)

	make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- zImage


### Compile the Kernel modules

The image generated contains the Linux Kernel and all the built-in 
device drivers (option <b>[*]</b> in menuconfig) compiled with it.

Al the drivers compiled as external modules (option <b>[M]</b> in menuconfig)
need to be compiled and saved in the rootfs <code>/lib</code> directory on the second 
partition of the microSD. We didn't use any [M] flag in our defconfig so this procedure 
is not requested but. in case you add something. these are the commands to use
to compile them:

[Roadrunner](/roadrunner) and [Acqua](/roadrunner)

	make modules -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

[Aria](/aria) and [Arietta](/arietta)

	make modules -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-

All SOMs:

	make modules_install INSTALL_MOD_PATH=./modules ARCH=arm

### Copy the boot files into the first microSD partition

Insert a [formatted microSD](/microsd_format) with the boot loader ([at91bootstrap](/at91bootstrap))
and the rootfs contents already created in your Linux PC and copy on it these files:

Write the Linux Kernel image and the device tree blob in the first microSD partition:
	
	sudo cp arch/arm/boot/zImage /media/$USER/boot

Write also the devicd tree blob file (selected one of these for your board):

	sudo cp arch/arm/boot/dts/acme-roadrunner.dtb /media/$USER/boot
	sudo cp arch/arm/boot/dts/acme-acqua.dtb /media/$USER/boot
	sudo cp arch/arm/boot/dts/acme-aria.dtb /media/$USER/boot
	sudo cp arch/arm/boot/dts/acme-arietta.dtb /media/$USER/boot

Copy also the Linux kernel command file cmdline.txt

[Roadrunner](/roadrunner)

	wget https://www.acmesystems.it/www/compile_kernel_5_15/acme-roadrunner_cmdline.txt
	sudo cp acme-roadrunner_cmdline.txt /media/$USER/boot/cmdline.txt

[Acqua](/acqua)

	wget https://www.acmesystems.it/www/compile_kernel_5_15/acme-acqua_cmdline.txt
	sudo cp acme-acqua_cmdline.txt /media/$USER/boot/cmdline.txt

[Aria](/aria)

	wget https://www.acmesystems.it/www/compile_kernel_5_15/acme-aria_cmdline.txt
	sudo cp acme-aria_cmdline.txt /media/$USER/boot/cmdline.txt

[Arietta](/arietta)

	wget https://www.acmesystems.it/www/compile_kernel_5_15/acme-arietta_cmdline.txt
	sudo cp acme-arietta_cmdline.txt /media/$USER/boot/cmdline.txt

Write the Linux Kernel modules inside the second microSD partition:
	
	sudo rsync -avc modules/lib/. /media/$USER/rootfs/lib/.

Insert the MicroSD in your Roadrunner board and check on the serial debug port the boot messages

### After the first boot

At the first access to the board command line update the module dependencies by typing this command:

	sudo depmod -a

## File used

[Roadrunner](/roadrunner)

* [Kernel config (acme-roadrunner_defconfig)](./acme-roadrunner_defconfig)
* [Device tree for Acqua (acme-roadrunner.dts)](./acme-roadrunner.dts)
* [cmdline.txt](./acme-roadrunner_cmdline.txt)

[Acqua](/acqua)

* [Kernel config (acme-acqua_defconfig)](./acme-acqua_defconfig)
* [Device tree for Acqua (acme-acqua.dts)](./acme-acqua.dts)
* [cmdline.txt](./acme-acqua_cmdline.txt)

[Aria](/aria)

* [Kernel config (acme-aria_defconfig)](./acme-aria_defconfig)
* [Device tree for Acqua (acme-aria.dts)](./acme-aria.dts)
* [cmdline.txt](./acme-aria_cmdline.txt)

[Arietta](/arietta)

* [Kernel config (acme-arietta_defconfig)](./acme-arietta_defconfig)
* [Device tree for Acqua (acme-arietta.dts)](./acme-arietta.dts)
* [cmdline.txt](./acme-arietta_cmdline.txt)

## Save your own Kernel configuration

In case of changes to the kernel configuration follow this steps to save it:

	make ARCH=arm savedefconfig

The file <code>defconfig</code> contains your configuration. You could rename and copy it in <code>arch/arm/configs/</code>

	cp defconfig arch/arm/configs/my_defconfig

