Custom Linux Kernel and Device Tree
This section describes how to customize and build the Linux kernel and device tree blobs (DTBs) for the R-Car V4H SH by using the rcar-utils repository.
Customizing and Building the Linux Kernel
Use the build script provided in the rcar-utils repository to build the Linux kernel for the R-Car V4H SH.
Change to the build script directory:
cd ~/rcarv4h_workspace/rcar-utils/local-build-scripts
Modify the kernel source as needed by editing the files in the linux-sh directory.
Build the Linux kernel image and the device tree blobs (DTBs):
./main_build.sh kernel all
The following kernel sub-commands are available:
Sub-command |
Description |
|---|---|
|
Configure the kernel, then build the kernel image and every device tree. |
|
Configure the kernel, then build the kernel image only. |
|
Configure the kernel, then build the device trees only. |
|
Run |
|
Run |
|
Regenerate |
|
Open the kernel configuration editor. The |
|
Clean the kernel build outputs. |
Every build sub-command configures the kernel before compiling. “Configure” does not always mean
“regenerate”: a .config that has been customized is kept, as described in
Customizing and Building the Kernel Configuration.
Note
The all target does not build the kernel modules, and none of the kernel
sub-commands produce a fitImage:
./main_build.sh kernel modules-installbuilds the kernel image, the device trees and the modules, and installs the modules toKERNEL_MODULES_OUTPUT_DIR../main_build.sh fitimage allbuilds the kernel image, the device trees and the modules, then the BL31 blob and the initramfs, and packages them intofitImage. Internally it runskernel modules, notkernel modules-install, so it leavesKERNEL_MODULES_OUTPUT_DIRuntouched. Run./main_build.sh kernel modules-installas well whenever the modules also have to be deployed. See Building the FIT Image.
The board boots from fitImage, so a change to the kernel or the device tree only takes
effect once that file has been rebuilt and copied to the board. Deploying a .dtb or
.dtbo on its own has no effect.
Customizing and Building the Kernel Configuration
Customize the kernel configuration to enable a driver or feature that the default configuration leaves out, such as the driver for a camera sensor you want to attach. See the Linux Kernel Configuration Guide for the mechanics of kconfig itself.
The kernel configuration is not produced by a plain make sparrow_hawk_defconfig. The build
script concatenates two files and lets kconfig fill in the defaults for everything else, which is
what a Yocto kernel build does:
File |
Purpose |
|---|---|
|
Base configuration for the target platform. |
|
Configuration fragment merged on top of the base configuration. |
The fragment is applied last, so an option set there overrides the same option in the defconfig.
To change the configuration, add your options to the fragment
linux-sh/arch/arm64/configs/sparrow_hawk.config, then rebuild and repackage the FIT image:
./main_build.sh fitimage all
To browse the available options, or to try a setting out without editing the fragment, use the kernel configuration editor:
./main_build.sh kernel menuconfig
./main_build.sh kernel defconfig is the only sub-command that discards a customized
.config and starts again from the defconfig and the fragment. It builds nothing, which also
makes it a quick way to check that an edited fragment produces the configuration you expect.
Warning
A .config kept this way is not tracked by git, and ./main_build.sh kernel distclean
removes it along with the stamp file. Copy the options you want to keep into
sparrow_hawk.config.
Note
CONFIG_LOCALVERSION and CONFIG_LOCALVERSION_AUTO are appended by the build script from
the KERNEL_LOCALVERSION setting in config.ini, after both files. Whatever the defconfig
and the fragment set for these two symbols is therefore overridden; change
KERNEL_LOCALVERSION instead. When KERNEL_VARIANT is set, its fragment is appended
after these two lines and can set CONFIG_LOCALVERSION again, which is what gives the
variant its own uname -r and its own /usr/lib/modules/<release>.
Tip
To check the specific configuration options that are enabled in the default configuration, you can run the following command on the target board:
zcat /proc/config.gz | grep "CONFIG_<option_name>"
Customizing and Building the Device Tree
Use the device tree sources in the linux-sh repository to modify hardware-related settings such as enabled peripherals, pin control, buses, and attached devices.
For the R-Car V4H SH, the main device tree source file is located at
linux-sh/arch/arm64/boot/dts/renesas/r8a779g3-sparrow-hawk.dts.
The device tree overlay source files are located at
linux-sh/arch/arm64/boot/dts/renesas/r8a779g3-sparrow-hawk-<overlay_name>.dtso.
Refer to the Device Tree Usage Guide for detailed information on how to modify device tree blobs (DTBs) and overlays (DTBOs).
After making changes to the device tree source files, rebuild and repackage the FIT image:
./main_build.sh fitimage all
This single command rebuilds the device tree blobs and packages them into fitImage, so there is
no need to run ./main_build.sh kernel dtbs beforehand. That target only writes the .dtb and
.dtbo files on the build host, which the board never reads directly.
Adding a New Device Tree Overlay
A new overlay is not picked up automatically. After creating the .dtso source file, register it
in two places:
Add the
.dtbotarget tolinux-sh/arch/arm64/boot/dts/renesas/Makefileso that the kernel build produces it.Add the overlay to
rcar-utils/local-build-scripts/build_fitimage.shso that it is packaged into the FIT image, by appending an entry to both arrays:FIT_OVERLAY_IMAGES=( ... "fdt-my-overlay|${BOARD_DTB}-my-overlay.dtbo" ) FIT_OVERLAY_CONFIGS=( ... "my-overlay|fdt-my-overlay|" )
The first array declares the image node that carries the overlay data. The second declares the FIT configuration name that selects it at boot time, which is the name appended to the boot address as
#my-overlay.
If a .dtbo listed in FIT_OVERLAY_IMAGES has not been built, the FIT image build stops with
an overlay not built error.