Differences

This shows you the differences between two versions of the page.

Link to this comparison view

lkd:laboratoare:01 [2024/07/07 11:47]
daniel.baluta
lkd:laboratoare:01 [2024/07/08 15:18] (current)
daniel.baluta
Line 1: Line 1:
-=====Introduction to Embedded Linux kernel development =====+===== 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 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.
Line 13: Line 13:
 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. ​ 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 ===+==== Presentation ​====
  
-  * follow slides at [[session ​1]+  * follow slides at  ​{{:​lkd:​laboratoare:​lkd_01.pdf| Session 1}} 
 + 
 +==== Practical lab ==== 
 + 
 +You can use [[https://​ocw.cs.pub.ro/​courses/​lkd/​res/​masini-virtuale | virtual machine]] setup or [[https://​ocw.cs.pub.ro/​courses/​lkd/​res/​linux | native Linux setup]]. 
 + 
 +To connect to the Linux running inside the virtual machine you can use: 
 + 
 +<code bash> 
 +ssh -p 3022 student@localhost 
 +</​code>​ 
 +=== 1. Explore the development environment === 
 +Your work directory should look like this.  
 + 
 +<​code>​ 
 +$ 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 
 +</​code>​ 
 + 
 +=== 2. Compile the Linux kernel === 
 + 
 +<code bash> 
 + 
 +$ source ~/​work/​scripts/​setenv.sh 
 +$ cd ~/​work/​nss-linux 
 +$ make tn_imx8_defconfig 
 +$ make -j8 
 + 
 +</​code>​ 
 + 
 +Successful compilation will create the following binaries: 
 + 
 +  * ''​arch/​arm64/​boot/​Image''​ - this is the resulting Linux kernel image 
 +  * ''​arch/​arm64/​boot/​dts/​freescale/​imx8mq-pico-pi.dtb''​ - device tree blob files 
 +  * a set of Linux kernel modules (''​*.ko''​) scattered around the Linux kernel working tree. 
 + 
 +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 [[https://​developer.technexion.com/​docs/​recover-to-factory-settings-pico-imx8m-mini | Technexion ]] webpage.  
 + 
 +{{:​lkd:​laboratoare:​pico-pi-imx8m-mini-cables.jpg}} 
 + 
 +  - Yellow box: debug console cable 
 +  - Red box: power cable (USB Type C) 
 +  - Magent box: boot configuration jumper location.  
 + 
 + 
 +Make sure the board is in ''​Serial Download Mode''​. Jumper location should be set as follows: 
 + 
 +{{:​lkd:​laboratoare:​pico-imx8m-pi-serial-download-mode.png}}. 
 + 
 +Now, we are ready to boot the board. Open two consoles: 
 + 
 + 
 +Console #1 
 + 
 +<code bash> 
 + 
 +$ minicom -D /​dev/​ttyUSB0 
 +</​code>​ 
 + 
 +Console #2 
 + 
 +<code bash> 
 +# sudo ~/​work/​scripts/​uuu ~/​work/​scripts/​uuu_script 
 + 
 +</​code>​ 
 + 
 +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.  
 + 
 +{{:​lkd:​laboratoare:​usb_filter.png}} 
 + 
 +The final consoles should look like this. Notice Console #1 has Linux kernel booting log: 
 + 
 +{{:​lkd:​laboratoare:​boot_run.png?​736x356}} 
 + 
 +<note important>​Use user ''​root''​ and password ''​root''​ to login on Linux running on the board </​note>​ 
 +=== 4. Make a change in the Linux kernel === 
 + 
 +Go to the Linux kernel source root tree and modify a file. 
 + 
 +<code bash> 
 +$ cd ~/​work/​nss-linux 
 + 
 +$ vim ~/​work/​arch/​arm64/​kernel/​setup.c 
 + 
 +</​code>​ 
 + 
 +Add a simple print like in the following patch 
 + 
 +<code c> 
 +--- 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"​);​ 
 + } 
 + 
 +</​code>​ 
 + 
 +Now recompile the kernel. You can go back and read [[#​compile_the_linux_kernel | 2. Compile the Linux kernel]]. Sequence for recompiling the kernel is as simple as: 
 + 
 +<code bash> 
 + 
 +$ cd ~/​work/​nss-linux 
 +$ source ~/​work/​scripts/​setenv.sh 
 +$ make -j8 
 + 
 +</​code>​ 
 + 
 +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 ​ [[#​boot_the_board |3. Boot the board ]]! 
 + 
 +Now, with the new boot image notice the new logs on the console: 
 + 
 +<code bash> 
 + 
 +[    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 
 + 
 +</​code>​ 
 + 
 +=== 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.  
 + 
 +<code bash> 
 +# ls / 
 +bin         ​home ​       lost+found ​ proc        srv         var 
 +boot        lib         ​media ​      ​root ​       sys 
 +dev         ​lib64 ​      ​mnt ​        ​run ​        tmp 
 +etc         ​linuxrc ​    ​opt ​        ​sbin ​       usr 
 +</​code>​ 
 + 
 +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. 
 + 
 +<code bash> 
 +$ 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 
 +</​code>​ 
 + 
 +Now boot the board and notice that the file you created exists on the board! Follow the steps in section ​ [[#​boot_the_board |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: 
 +<code bash> 
 +$ cat /​proc/​version 
 +</​code>​ 
 + 
 +Check the command line arguments used to start the Linux kernel: 
 +<code bash> 
 + 
 +$ cat /​proc/​cmdline 
 + 
 +</​code>​ 
 + 
 +List all the cpus in the system: 
 +<code bash> 
 + 
 +$ cat /​proc/​cpuinfo 
 +</​code>​ 
 + 
 +List all available free and used physical memory in the system. 
 + 
 +<code bash> 
 +$ free -h 
 + 
 +</​code>​ 
 + 
 +List the physical memory map for the system: 
 + 
 +<code bash> 
 + 
 +$ cat /​proc/​iomem 
 +</​code>​ 
 + 
 +Notice the address range for ''​System RAM''​ and for the rest of devices. 
 + 
 +Check the current list of filesystems supported by the kernel: 
 + 
 +<code bash> 
 + 
 +$ cat /​proc/​filesystems 
 + 
 +</​code>​ 
 + 
 +Check the current list of modules loaded in the system: 
 + 
 +<code bash> 
 + 
 +$ cat /​proc/​modules 
 + 
 +</​code>​ 
 + 
 +Finally check the kernel log: 
 + 
 +<code bash> 
 + 
 +$ dmesg 
 + 
 +</​code>​
  
-=== Practical lab === 
  
  
lkd/laboratoare/01.1720342071.txt.gz · Last modified: 2024/07/07 11:47 by daniel.baluta
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0