Skip to main content

Miscellaneous

Build Linux kernel from source code

You can build the Linux kernel outside of Yocto by following the instructions in this section. Please note that it is recommended that the kernel is built by Yocto when you are generating your final distribution images since there can be dependencies between the root file system and the kernel.

The instructions in this section assume that you have built and installed the toolchain as described in meta-toolchain section.

Setup the environment variables for the toolchain. We are using the same installation path as described in the meta-toolchain section. If you have installed the toolchain in a different path use that path in the instructions below.

source /opt/rz-vlp/5.0.8/environment-setup-cortexa55-poky-linux

Get the source code from the Embedded Artists GitHub repository. In this example we are checking out branch ea-6.1.

git clone https://github.com/embeddedartists/linux-rz.git
cd linux-rz
git checkout ea-6.1

Use Embedded Artists kernel configurations.

make defconfig

(Optional) If you want to change kernel configurations you can at this point run the menuconfig tool.

make menuconfig

Build the kernel.

make

When the build process has finished the kernel will be available here: arch/arm64/boot/Image. Device tree files are available in the following directory: arch/arm64/boot/dts/renesas. A compiled device tree file has the file extension dtb.

Update the device

Kernel images and dtb (device tree) files are available in the /boot/ folder in Linux. The instructions below will show how to update the kernel image and dtb files (or add new dtb files) using a USB memory stick.

  1. Copy the files (Image and/or dtb files) to a USB memory stick
  2. Boot into Linux and insert the USB memory stick into any of the USB Host Connectors on the SOM Carrier Board. You will see output in the console as below.
usb 2-1: new high-speed USB device number 2 using ehci-platform
usb-storage 2-1:1.0: USB Mass Storage device detected
scsi host0: usb-storage 2-1:1.0
scsi 0:0:0:0: Direct-Access USB Flash Disk 1100 PQ: 0 ANSI: 0 CCS
sd 0:0:0:0: [sda] 3915776 512-byte logical blocks: (2.00 GB/1.87 GiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] No Caching mode page found
sd 0:0:0:0: [sda] Assuming drive cache: write through
sda: sda1
sd 0:0:0:0: [sda] Attached SCSI disk
  1. Mount the USB memory stick. The USB memory stick has in this example the device name sda1 as can be seen in the output in step 2 above.
mkdir /mnt/usb
mount /dev/sda1 /mnt/usb
  1. Copy the Image file and / or dtb file(s) from the USB memory stick to the boot partition.
cp /mnt/usb/Image /boot
cp /mnt/usb/*.dtb /boot
  1. Un-mount devices.
unmount /mnt/usb
  1. Reboot to start using the updated files.
reboot
  1. In case you updated the Linux kernel (i.e. the Image file) it is highly likely that you will be missing some drivers and will get strange errors in the boot log. This is because the new kernel has a different id compared to the old one. To verify that this is the issue type these two commands in the terminal:
root@rzg3e-ea-som:~# uname -r
6.1.107-cip28-yocto-dirty

root@rzg3e-ea-som:~# ls -la /lib/modules/
drwxr-xr-x 3 root root 4096 Nov 24 13:04 .
drwxr-xr-x 58 root root 36864 Nov 24 13:05 ..
drwxr-xr-x 4 root root 4096 Nov 24 13:04 6.1.107-cip28-yocto-standard

In the example above /lib/modules/ expect the id to be 6.1.107-cip28-yocto-standard but the kernel that is being used is 6.1.107-cip28-yocto-dirty. To align the two run:

cd /lib/modules
ln -s 6.1.107-cip28-yocto-standard $(uname -r)

That will create a symbolic link (like an alias). It will now look like this:

root@rzg3e-ea-som:/lib/modules# ls -la
drwxr-xr-x 3 root root 4096 Nov 25 08:08 .
drwxr-xr-x 58 root root 36864 Nov 24 13:05 ..
lrwxrwxrwx 1 root root 29 Nov 25 08:08 6.1.107-cip28-yocto-dirty -> 6.1.107-cip28-yocto-standard/
drwxr-xr-x 4 root root 4096 Nov 24 13:04 6.1.107-cip28-yocto-standard
  1. Reboot to apply the changes
reboot

If you have added a new dtb file that you want to use, see How do select which device tree file to use?.

Build U-Boot from source code

You can build U-Boot outside of Yocto by following the instructions in this section.

info

Building the U-Boot outside of Yocto can be done but the output file cannot be directly flashed as it has to be converted into a fip-rzg3e-ea-som.srec before it can be used. This is one of the things that yocto does automatically. So the main point of compiling outside of yocto is to smoke out build errors while you are developing changes in the U-Boot.

The instructions in this section assume that you have built and installed the toolchain as described in meta-toolchain section.

Setup the environment variables for the toolchain. We are using the same installation path as described in the meta-toolchain section. If you have installed the toolchain in a different path use that path in the instructions below.

source /opt/rz-vlp/5.0.8/environment-setup-cortexa55-poky-linux

Get the source code from the Embedded Artists GitHub repository. In this example we are checking out branch ea_v2024.07.

git clone https://github.com/embeddedartists/uboot-rz.git
cd uboot-rz
git checkout ea_v2024.07

Use the Embedded Artists configuration for the SOM board you are using. In the example below the configuration for the RZ/G3E.

make rzg3e-ea-som_defconfig‎

Build the bootloader

make

When the build process has finished the U-Boot image will be available directly in the uboot-rz directory.

Update the device

Not applicable.

Use devtool to build Linux / U-Boot

The Build Linux from source code and the Build U-Boot from source code sections describe how to build Linux and U-Boot from source code outside of Yocto. This is in general a fast way to work with Linux / U-Boot development compared to re-building inside of Yocto. There is however another alternative that will let you build within Yocto, but with your own Linux / U-Boot repositories. This can be suitable when you for example want to test modifications, but make sure to keep the kernel in sync with the root file system. For U-Boot the benefits of using devtool is that you get a fip-rzg3e-ea-som.srec which can actually be flashed.

Run the commands below within your Yocto build directory.

Linux kernel:

devtool modify linux-ea

If your build folder is ea-bsp/build_dir/ then the Linux kernel will be checked out and ready to be modified in ea-bsp/build_dir/workspace/sources/linux-ea.

For U-Boot:

devtool modify u-boot-ea

If your build folder is ea-bsp/build_dir/ then the U-Boot will be checked out and ready to be modified in ea-bsp/build_dir/workspace/sources/u-boot-ea.

Once you have modified the repository you can build a new Yocto image, for example, ea-image-base.

bitbake ea-image-base

If you want to switch back to using the default repositories you can use devtool reset as shown below.

devtool reset linux-ea
devtool reset u-boot-ea

State and download cache in Yocto

If you regularly build Yocto images you can significantly reduce build times by using state and download caches. The download cache will contain downloaded packages so they don’t have to be downloaded multiple times for new build directories. The state cache will contain built packages so you these don’t have to be re-built between build directories given that the state hasn’t changed.

You can enable the caches by adding the lines below to your local.conf file (<build dir>/conf/local.conf).

Download cache (change the directory name below to a directory on your computer): DL_DIR="~/downloads"

State cache (change the directory name below to a directory on your computer): SSTATE_DIR="~/shared-sstate-cache"

You could also create a file called site.conf that you copy to your conf directory each time you create a new build directory. Below is an example of how such a file could look like.

SSTATE_DIR = "/opt/yocto-cache/shared-sstate-cache"
DL_DIR = "/opt/yocto-cache/downloads"
SSTATE_MIRRORS = " file://.* file:///opt/yocto-cache/shared-sstatecachePATH "