This shows you the differences between two versions of the page.
lkd:laboratoare:01 [2024/07/07 14:15] daniel.baluta [Practical lab] |
lkd:laboratoare:01 [2024/07/08 15:18] (current) daniel.baluta |
||
---|---|---|---|
Line 15: | Line 15: | ||
==== Presentation ==== | ==== Presentation ==== | ||
- | * follow slides at [[session 1]] | + | * follow slides at {{:lkd:laboratoare:lkd_01.pdf| Session 1}} |
==== Practical lab ==== | ==== Practical lab ==== | ||
Line 55: | Line 54: | ||
</code> | </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 ==== | === 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> | ||
+ | |||
+ | |||