3.1. Android Kernel

3.1.1. Downloading sources

Fetch the code using repo:

$ mkdir ${YOUR_PATH}/ti-kernel-aosp/ && cd $_
$ repo init -u https://git.ti.com/git/android/manifest.git -b android15-release -m releases/RLS_10_01_Kernel-6.6.xml
$ repo sync

Tip

To save some disk space, pass the --depth=1 option to repo init:

$ repo init -u https://git.ti.com/git/android/manifest.git -b android15-release -m releases/RLS_10_01_Kernel-6.6.xml --depth=1

3.1.2. Build Instructions

3.1.2.1. Building everything from scratch

$ cd ${YOUR_PATH}/ti-kernel-aosp/
$ export TARGET_KERNEL_USE="6.6"
$ export DIST_DIR=${YOUR_PATH}/ti-aosp-15/device/ti/am62x-kernel/kernel/${TARGET_KERNEL_USE}
$ tools/bazel run //common:ti_dist -- --dist_dir=$DIST_DIR

Android uses Kleaf, a Bazel-based build system to build the kernel. AOSP documentation can be found here and Kleaf documentation here

Attention

Kernel builds hangs when using the btrfs file system. This is a known issue according to the kleaf documentation Make sure to pass the --workaround_btrfs_b292212788 flag to bazel when using btrfs.

3.1.2.2. Rebuilding faster

$ cd ${YOUR_PATH}/ti-kernel-aosp/
$ export TARGET_KERNEL_USE="6.6"
$ export DIST_DIR=${YOUR_PATH}/ti-aosp-15/device/ti/am62x-kernel/kernel/${TARGET_KERNEL_USE}
$ tools/bazel run --config=fast //common:ti_dist -- --dist_dir=$DIST_DIR

3.1.2.3. Defconfig/menuconfig changes

The usual (make menuconfig) is done via bazel command :

$ cd ${YOUR_PATH}/ti-kernel-aosp/
$ tools/bazel run //common:ti_config -- menuconfig

Note

Users must have built the android kernel image prior to building the Android file system. Otherwise pre-built kernel images present in device/ti/am62x-kernel will be used to create boot.img

3.1.2.4. Rebuild Android images

We should re-generate the Android images to include the newly build kernel. Follow the Android Build Instructions to do so.

3.1.3. Flashing instructions

In order to flash a new kernel, several images should be flashed:

$ adb reboot fastboot
< Wait for fastbootd reboot >

$ cd <PATH/TO/IMAGES>
$ fastboot flash boot boot.img
$ fastboot flash vendor_boot vendor_boot.img
$ fastboot flash vendor_dlkm vendor_dlkm.img
$ fastboot reboot

The board should boot with the new kernel.

3.1.4. Enabling new drivers

Since the kernel is based on the Generic Kernel Image, new drivers should always be added as modules.

To enable new modules:

  1. Run menuconfig as documented previously, Select =m for the driver.

  2. Edit $YOUR_PATH/ti-kernel-aosp/BUILD.bazel to add your new module. Look for the following section:

    _TI_MODULE_OUTS = [
        # keep sorted
        "crypto/af_alg.ko",
        "crypto/algif_hash.ko",
    
  3. In the _TI_MODULE_OUTS array, add the path to your new kernel module.

  4. Rebuild the kernel as documented in Build Instructions.

  5. If the driver module needs to be loaded early (in the ramdisk), edit $YOUR_PATH/ti-aosp-15/device/ti/am62x/BoardConfig-common.mk and add the path to your module:

    BOARD_VENDOR_RAMDISK_KERNEL_MODULES += \
            device/ti/am62x-kernel/kernel/$(TARGET_KERNEL_USE)/your_module.ko
    
  6. Finally, rebuild the Android images.

3.1.5. Device tree overlays

3.1.5.1. Mapping adtbo_idx with filenames

Device tree overlays can be used to configure additional hardware peripherals. These overlays are stored in the dtbo.img. This image is generated when building the Android kernel as documented in Build Instructions.

As listed in Device Tree Overlay Support, we can configure an overlay to be applied from U-Boot by setting the adtbo_idx variable.

To view how the adtbo_idx maps with the dtbo file, we can inspect the BUILD.bazel from the kernel source code. Looking at the kernel_images() macro, we can see:

kernel_images(
 name = "ti_images",
 build_dtbo = True,
 build_initramfs = True,
 dtbo_srcs = [
     ":ti/k3-am62x-sk-hdmi-audio.dtbo",
     ":ti/k3-am62x-sk-csi2-ov5640.dtbo",
     ":ti/k3-am62x-sk-csi2-tevi-ov5640.dtbo",
     ":ti/k3-am625-sk-microtips-mf101hie-panel.dtbo",
     ":ti/k3-am62x-sk-lpm-wkup-sources.dtbo",
     ":ti/k3-am62-lp-sk-microtips-mf101hie-panel.dtbo",
     ":ti/k3-am625-beagleplay-csi2-ov5640.dtbo",
     ":ti/k3-am625-beagleplay-csi2-tevi-ov5640.dtbo",
     ":ti/k3-am625-beagleplay-lincolntech-lcd185-panel.dtbo",
     ":ti/k3-am62p5-sk-mcan.dtbo",
     ":ti/k3-am62p5-sk-microtips-mf101hie-panel.dtbo",
     ":ti/k3-am625-sk-m2-cc3301.dtbo",
     ":ti/k3-am62p5-sk-m2-cc3301.dtbo",
     ":ti/k3-am625-sk-wl1837.dtbo",

The dtbo_srcs array order dicates the index. For example:

filename

index

ti/k3-am62x-sk-hdmi-audio.dtbo

0

ti/k3-am62x-sk-csi2-ov5640.dtbo

1

3.1.5.2. Adding more .dtbo files to the dtbo.img

In this section, we will see how to add more .dtbo files to the dtbo.img. Let’s see how to add ti/k3-am62p5-sk-dsi-rpi-7inch-panel.dtbo for example:

  1. Edit $YOUR_PATH/ti-kernel-aosp/BUILD.bazel. Look for the following section:

    kernel_build(
        name = "ti",
        outs = [
            "Image",
            "System.map",
            "k3-am62-lp-sk.dtb",
            "k3-am62-lp-sk-microtips-mf101hie-panel.dtbo",
    
  2. In the kernel_build() section, add k3-am62p5-sk-dsi-rpi-7inch-panel.dtbo to the outs array.

  3. Still in kernel_build(), look for the make_goals array and add ti/k3-am62p5-sk-dsi-rpi-7inch-panel.dtbo.

  4. Now look for the following section:

    kernel_images(
        name = "ti_images",
        build_dtbo = True,
        build_initramfs = True,
        dtbo_srcs = [
            ":ti/k3-am62x-sk-hdmi-audio.dtbo",
            ":ti/k3-am62x-sk-csi2-ov5640.dtbo",
            ":ti/k3-am62x-sk-csi2-tevi-ov5640.dtbo",
    
  5. In the kernel_images(), add :ti/k3-am62p5-sk-dsi-rpi-7inch-panel.dtbo at the end of the array.

    Important

    Make sure to add the it at the end of the array. The order in dtbo_srcs will determine the adtbo_idx to be used.

  6. Rebuild the kernel as documented in Build Instructions.