Skip to content

Build new Kernel on EdgeKit

Saber Kaygusuz edited this page Jul 18, 2023 · 7 revisions

General

Sometimes we need kernel modules that are missing for development and later use. For the development or customization phase of your use case, we recommend this tutorial to build the customized kernel image flexibly on EdgeKit itself. An example is if you need the Wireguard module.

Step 1: Prepare environment on the EdgeKit

This procedure needs some space left on the EdgeKit so make sure you have at least 20GB free. First of all we're creating a new folder in the home directory:

mkdir /home/edgekit/kernel && cd /home/edgekit/kernel

Also we're installing some dependencies for further steps:

sudo apt-get install build-essential bc libncurses5-dev libssl-dev

Now we have to download the kernel source files directly from NVIDIA, for that please check which Release you've installed on your EdgeKit with

cat /etc/nv_tegra_release

sample Output:

# R35 (release), REVISION: 3.1, GCID: 32827747, BOARD: t186ref, EABI: aarch64, DATE: Sun Mar 19 15:19:21 UTC 2023

The release (R35) and the revision (3.1) is necessary for downloading the correct source files with the following structure:

wget https://developer.nvidia.com/downloads/embedded/l4t/rXX_release_vYYY/sources/public_sources.tbz2/ -O public_sources.tar.gz

XX = release e.g. 35

YYY = revision with dot as seperation e.g. 3.1

So in this example we would have following command:

wget https://developer.nvidia.com/downloads/embedded/l4t/r35_release_v3.1/sources/public_sources.tbz2/ -O public_sources.tar.gz

After downloading the sources, we extract them and enter the correct directory:

tar -xvf public_sources.tar.gz 
cd Linux_for_Tegra/source/public/ 
tar -xvjf kernel_src.tbz2 
cd kernel/kernel-5.10 

Step 2: Configuring the kernel modules

First of all we are changing to root and set the environment variables for the make commands:

sudo su -
cd /home/edgekit/kernel/Linux_for_Tegra/source/public/kernel/kernel-5.10
export LOCALVERSION="-tegra"

Then we're taking the default kernel configuration as a basis with the following command:

make tegra_defconfig

Now we're changing some kernel configurations:

make menuconfig

Here we're gonna activate the module we want to have within the kernel (in this example: Wireguard):

Device Drivers  --->
    [*] Network device support  --->
        [*] Network core driver support
        <*>   WireGuard secure network tunnel

Make sure the module is marked with a star (*) so it will be included in the kernel. Creating a external module (M) is not covered in this tutorial.

Step 3: Building the kernel modules

Now we're gonna to build the kernel modules, this takes a while.

make -j 16 Image

When our kernel is build we have a new Image file, which we need to use on our EdgeKit. Herefore we copy the new file into the /boot/ directory:

cp arch/arm64/boot/Image /boot/Image_custom

Step 4: Make the custom kernel usable

When testing a custom kernel, it's recommended to have a boot entry to boot from the original kernel. Otherwise we have to reflash the system, which takes a long time and deletes all changes you made so far. For this we take a look to the following file: /boot/extlinux/extlinux.conf

This file is responsible for booting the correct kernel with the chosen device-tree file.

You need to edit the file, the following way:

  1. Copy the block "LABEL primary" and rename it to "LABEL backup"
  2. In the block "Label primary" change the LINUX parameter from /boot/Image to /boot/Image_custom

The content of /boot/extlinux/extlinux.conf should look like this:

root@edgekit-desktop:/home/edgekit# cat /boot/extlinux/extlinux.conf
TIMEOUT 30
DEFAULT primary

MENU TITLE L4T boot options

LABEL primary
      MENU LABEL primary kernel
      LINUX /boot/Image_custom
      FDT /boot/dtb/kernel_tegra234-p3767-0000-p3509-a02.dtb
      INITRD /boot/initrd
      APPEND ${cbootargs} root=PARTUUID=8bc8ac27-14c8-4863-959a-b364831c47b6 rw rootwait rootfstype=ext4 mminit_loglevel=4 console=ttyTCU0,115200 console=ttyAMA0,115200 firmware_class.path=/etc/firmware fbcon=map:0 net.ifnames=0 

# When testing a custom kernel, it is recommended that you create a backup of
# the original kernel and add a new entry to this file so that the device can
# fallback to the original kernel. To do this:
#
# 1, Make a backup of the original kernel
#      sudo cp /boot/Image /boot/Image.backup
#
# 2, Copy your custom kernel into /boot/Image
#
# 3, Uncomment below menu setting lines for the original kernel
#
# 4, Reboot

LABEL backup
      MENU LABEL backup kernel
      LINUX /boot/Image
      FDT /boot/dtb/kernel_tegra234-p3767-0000-p3509-a02.dtb
      INITRD /boot/initrd
      APPEND ${cbootargs} root=PARTUUID=8bc8ac27-14c8-4863-959a-b364831c47b6 rw rootwait rootfstype=ext4 mminit_loglevel=4 console=ttyTCU0,115200 console=ttyAMA0,115200 firmware_class.path=/etc/firmware fbcon=map:0 net.ifnames=0 

With this configuration we have two kernels we can boot from.

Now it's time to reboot the system. After rebooting the system you should have all the kernel modules build in. No data from your user-space will be lost.

Clone this wiki locally