Table of Contents

Introduction to Embedded Linux kernel development

In this session we will walk-through the essential software components that make the Board Suppport Package (BSP) for a hardware platform. We will demonstrate our work by booting PICO-IMX8M evaluation Kit.

In order to boot a hardware platform and runs applications on Linux we need the following software components:

The virtual machine provided by NXP should have all the software already downloaded including all the prerequisites. In this lab we will use a prebuild uboot and rootfs image.

Presentation

Practical lab

You can use virtual machine setup or native Linux setup.

To connect to the Linux running inside the virtual machine you can use:

ssh -p 3022 student@localhost

1. Explore the development environment

Your work directory should look like this.

$ tree -L 2 /home/student/work/
├── nss-linux                  # Linux kernel source code
├── images                     # prebuild binaries
│   ├── flash.bin
│   ├── Image
│   ├── imx8mq-pico-pi.dtb
│   └── rootfs.ext2
└── scripts                    # several scripts to help with compilation and booting
    ├── modules_install.sh
    ├── setenv.sh
    ├── uuu
    └── uuu_script

2. Compile the Linux kernel

$ source ~/work/scripts/setenv.sh
$ cd ~/work/nss-linux
$ make tn_imx8_defconfig
$ make -j8

Successful compilation will create the following binaries:

We also have prebuild binaries for Image and imx8mq-pico-pi.dtb found under ~/work/images/ directory to be used as a backup.

3. Boot the board

Connect the PICO-PI-IMX8M to your laptop using the two USB cables provided as described on Technexion webpage.

pico-pi-imx8m-mini-cables.jpg

  1. Yellow box: debug console cable
  2. Red box: power cable (USB Type C)
  3. Magent box: boot configuration jumper location.

Make sure the board is in Serial Download Mode. Jumper location should be set as follows:

.

Now, we are ready to boot the board. Open two consoles:

Console #1

$ minicom -D /dev/ttyUSB0

Console #2

# sudo ~/work/scripts/uuu ~/work/scripts/uuu_script

And then hit Reset button on the board.

During the booting of the board you will need to tell Virtualbox which USB devices to passthrough the Guest Linux.

The final consoles should look like this. Notice Console #1 has Linux kernel booting log:

Use user root and password root to login on Linux running on the board

4. Make a change in the Linux kernel

Go to the Linux kernel source root tree and modify a file.

$ cd ~/work/nss-linux
 
$ vim ~/work/arch/arm64/kernel/setup.c

Add a simple print like in the following patch

--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -90,6 +90,8 @@ void __init smp_setup_processor_id(void)
 
        pr_info("Booting Linux on physical CPU 0x%010lx [0x%08x]\n",
                (unsigned long)mpidr, read_cpuid_id());
+
+       pr_info("Hello from Embedded Linux Summer School\n");
 }

Now recompile the kernel. You can go back and read 2. Compile the Linux kernel. Sequence for recompiling the kernel is as simple as:

$ cd ~/work/nss-linux
$ source ~/work/scripts/setenv.sh
$ make -j8

Boot script ~/work/scripts/uuu_script will use your newly compiled Linux kernel image. So there is no need to change anything after your recompiled the kernel. Just follow again the steps in section 3. Boot the board !

Now, with the new boot image notice the new logs on the console:

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[    0.000000] Hello from Embedded Linux Summer School
[    0.000000] Linux version 6.1.55-ga5f70b9823b6-dirty (student@nss)
[    0.000000] Machine model: TechNexion PICO-IMX8MQ and PI baseboard

5. Make a change in the rootfs

rootfs (or the root file system) is the filesystem that is mounted at / (root of the hierarchy) and contains all the files necessary for the operating system to boot and run.

# ls /
bin         home        lost+found  proc        srv         var
boot        lib         media       root        sys
dev         lib64       mnt         run         tmp
etc         linuxrc     opt         sbin        usr

In our setup, the rootfs used to boot the board can be found in ~/work/images/rootfs.ext2. Use the following instructions that add one of your own files into the root filesystem.

$ cd ~/work/images
# make a backup of the initial root filesystem
$ cp rootfs.ext2 rootfs.ext2.back
$ sudo mkdir /mnt/my_root
$ sudo mount -o loop rootfs.ext2 /mnt/my_root
 
# explore the contents of /mnt/my_root directory and notice that these are the exact files that you can find on the board
 
# create your own file 
$ sudo touch /mnt/my_root/root/my_file
 
# unmount the filesystem
 
$ sudo umount /mnt/my_root

Now boot the board and notice that the file you created exists on the board! Follow the steps in section 3. Boot the board !

5. Explore the board

After booting the board and getting the prompt explore the hardware board capabilities.

Check the current Linux kernel version:

$ cat /proc/version

Check the command line arguments used to start the Linux kernel:

$ cat /proc/cmdline

List all the cpus in the system:

$ cat /proc/cpuinfo

List all available free and used physical memory in the system.

$ free -h

List the physical memory map for the system:

$ cat /proc/iomem

Notice the address range for System RAM and for the rest of devices.

Check the current list of filesystems supported by the kernel:

$ cat /proc/filesystems

Check the current list of modules loaded in the system:

$ cat /proc/modules

Finally check the kernel log:

$ dmesg