Kernel Size Reduced, but Boot Time Remains Unchanged

Hi @rania !


I would like to kindly ask you to avoid using several threads to bring up the same topic. For example, I see you commented about your fastboot requirement on other 2 threads (Yocto Kernel Build Fails: No Rule to Make Target 'Image.zst and Falcon mode for imx8quad max). Doing this makes us a bit confused regarding where should we proceed with your case, since we have different pieces of the same context scattered across different topics.


Checking internally, I found a work done by one of our Domain Experts around making boot go faster. From that, I managed to get some pointers based on the optimization done for that specific case.

Disclaimer: this was done for Verdin iMX8M Mini and BSP 6.4.0, therefore the translation for your use case most probably won’t be 1:1. Nevertheless, this is certainly helpful.

Here is what we have:

Kernel configuration

Here is an example of defconfig for the kernel that made it go from 12 MB to 6.7 MB
kernel_config_dsi_in_reduction4 (147.6 KB)

Partial result:

root@verdin-imx8mm-14700070:~# systemd-analyze 
Startup finished in 742ms (kernel) + 3.783s (userspace) = 4.525s 
graphical.target reached after 2.912s in userspace

Starting the application as soon as possible

Not relying on systemd to start the application can make it start earlier:

root@verdin-imx8mm-14700070:~# cat /proc/cmdline 
root=PARTUUID=37ff9e95-02 ro rootwait console=ttymxc0,115200 consoleblank=0 quiet init=/home/root/preinit.sh
root@verdin-imx8mm-14700070:~# cat preinit.sh 
#!/bin/busybox sh
echo "-> Start Application..."
#Initialize your time-critical application here !
/home/root/guidemo &
echo "-> Application started !"
# start real init (systemd/SysVinit)

Be aware that starting the application this way, systemd is not monitoring its behavior and is not capable of restarting it if it crashes, or taking other corrective measures if needed. This is a thread of that you need to deal with for your case.

I think this was possible because the application what prepared for this (although I am not sure). So I don’t know how much this relates to your case.

Boot loader optimization

Disable boot delay in U-Boot:

setenv bootdelay -2

Bypass distroboot:

setenv bargs 'root=PARTUUID=37ff9e95-02 ro rootwait console=ttymxc0,115200 consoleblank=0 quiet init=/home/root/preinit.sh'
bootcmd=setenv bootargs $bargs;fatload mmc 0:1 $ramdisk_addr_r imx8mm.itb;bootm $ramdisk_addr_r

In this case, the boot was done with a FIT image:

cat kernel_fit_image.its
/dts-v1/;
/ {
        description = "Verdin iMX8MM FIT Image";
        #address-cells = <1>;
        images {
                kernel {
                        description = "Kernel";
                        data = /incbin/("Image.gz");
                        type = "kernel";
                        arch = "arm64";
                        os = "linux";
                        compression = "gzip";
                        load = <0x48200000>;
                        entry = <0x48200000>;
                        hash {
                                algo = "sha1";
                        };
                };
                fdt {
                        description = "DTB";
                        data = /incbin/("imx8mm-verdin-nonwifi-dev.dtb");
                        type = "flat_dt";
                        arch = "arm64";
                        compression = "none";
                        load = <0x43000000>;
                        entry = <0x43000000>;
                        hash {
                                algo = "sha1";
                        };
                };
/*
                initrd {
                        description = "Initrd";
                        data = /incbin/("core-image-minimal-nitrogen8m.ext2.gz");
                        type = "ramdisk";
                        arch = "arm64";
                        os = "linux";
                        compression = "none";
                        hash {
                                algo = "sha1";
                        };
                };
*/
        };
        configurations {
                default = "standard";
                standard {
                        description = "Standard Boot";
                        kernel = "kernel";
                        fdt = "fdt";
 /*                       ramdisk = "initrd";*/
                        hash {
                                algo = "sha1";
                        };
                };
        };
};
mkimage -f kernel_fit_image.its imx8mm.itb

Result

Here is the result that was measured with theses steps:

grabserial -d /dev/ttyverdin -t -m "U-Boot SPL" -e 10 -o boot.log
cat boot.log 
[0.000001 0.000001] 
[0.080000 0.079998] U-Boot SPL 2022.04-6.4.0+git.dc27426aa417 (Sep 25 2023 - 13:34:50 +0000)
[0.018048 0.018048] DDRINFO: start DRAM init
[0.031917 0.013869] DDRINFO: DRAM rate 3000MTS
[0.303697 0.271779] DDRINFO:ddrphy calibration done
[0.306362 0.002665] DDRINFO: ddrmix config done
[0.351683 0.045322] WDT:   Started watchdog@30280000 with servicing (60s timeout)
[0.354373 0.002689] Trying to boot from MMC1
[0.479635 0.125262] NOTICE:  BL31: v2.6(release):lf_v2.6-g3c1583ba0a
[0.482295 0.002660] NOTICE:  BL31: Built : 11:00:38, Nov 21 2022
[0.911635 0.429341] 
[0.911798 0.000162] 
[0.911884 0.000086] U-Boot 2022.04-6.4.0+git.dc27426aa417 (Sep 25 2023 - 13:34:50 +0000)
[0.930079 0.018195] 
[0.943611 0.013533] CPU:   i.MX8MMDL rev1.0 1600 MHz (running at 1200 MHz)
[0.960896 0.017285] CPU:   Industrial temperature grade (-40C to 105C) at 37C
[1.088169 0.127273] Reset cause: POR
[1.089197 0.001027] DRAM:  1 GiB
[1.183609 0.094412] Core:  114 devices, 21 uclasses, devicetree: separate
[1.185198 0.001589] WDT:   Started watchdog@30280000 with servicing (60s timeout)
[1.201462 0.016264] MMC:   FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2
[1.216694 0.015232] Loading Environment from MMC... OK
[1.263708 0.047014] In:    serial
[1.279810 0.016102] Out:   serial
[1.280106 0.000296] Err:   serial
[1.280344 0.000238] Model: Toradex 0060 Verdin iMX8M Mini DualLite 1GB WB IT V1.1C
[1.281466 0.001122] Serial#: 14700070
[1.281780 0.000314] Carrier: Toradex Verdin Development Board V1.1B, Serial# 10866136
[1.296568 0.014788] flash target is MMC:0
[1.327649 0.031081] Net:   eth0: ethernet@30be0000
[1.568681 0.241032] Fastboot: Normal
[1.569323 0.000642] Normal Boot
[1.615556 0.046233] 7050012 bytes read in 45 ms (149.4 MiB/s)
[1.616799 0.001243] ## Loading kernel from FIT Image at 50300000 ...
[1.632854 0.016055]    Using 'standard' configuration
[1.634097 0.001243]    Trying 'kernel' kernel subimage
[1.635712 0.001615]      Description:  Kernel
[1.636983 0.001271]      Type:         Kernel Image
[1.638300 0.001317]      Compression:  gzip compressed
[1.648668 0.010368]      Data Start:   0x503000bc
[1.650068 0.001400]      Data Size:    6989415 Bytes = 6.7 MiB
[1.651927 0.001859]      Architecture: AArch64
[1.652382 0.000456]      OS:           Linux
[1.652844 0.000462]      Load Address: 0x48200000
[1.663579 0.010735]      Entry Point:  0x48200000
[1.664612 0.001032]      Hash algo:    sha1
[1.665762 0.001150]      Hash value:   3107b42d7d571e776b8f34a2f0dd0f77f82ebc52
[1.668446 0.002684]    Verifying Hash Integrity ... sha1+ OK
[1.759918 0.091473] ## Loading fdt from FIT Image at 50300000 ...
[1.762120 0.002202]    Using 'standard' configuration
[1.763731 0.001610]    Trying 'fdt' fdt subimage
[1.765150 0.001419]      Description:  DTB
[1.776192 0.011042]      Type:         Flat Device Tree
[1.777885 0.001693]      Compression:  uncompressed
[1.779510 0.001625]      Data Start:   0x509aa800
[1.780288 0.000778]      Data Size:    58805 Bytes = 57.4 KiB
[1.781178 0.000890]      Architecture: AArch64
[1.791815 0.010637]      Load Address: 0x43000000
[1.793392 0.001577]      Hash algo:    sha1
[1.794559 0.001167]      Hash value:   c5bdfe992262c157d64a3cbe6f8dd088a2cadb37
[1.797231 0.002671]    Verifying Hash Integrity ... sha1+ OK
[1.798730 0.001499]    Loading fdt from 0x509aa800 to 0x43000000
[1.808334 0.009604]    Booting using the fdt blob at 0x43000000
[1.810000 0.001667]    Uncompressing Kernel Image
[2.079628 0.269627]    Loading Device Tree to 000000007defd000, end 000000007df0e5b4 ... OK
[2.081290 0.001662] Warning: /thermal-zones/cpu-thermal/cooling-maps/map0, cooling-device count 6
[2.097816 0.016526] Update node /thermal-zones/cpu-thermal/cooling-maps/map0, cooling-device prop
[2.100515 0.002699] 
[2.100581 0.000067] Starting kernel ...
[2.101026 0.000445] 
[2.671596 0.570570] [    0.485991] rtc-ds1307 0-0032: hctosys: unable to read the hardware clock
[2.688383 0.016787] [    0.505191] [drm:drm_bridge_attach] *ERROR* failed to attach bridge /soc@0/bus@32c00000/mipi_dsi@32e10000 to encoder DSI-34: -517
[2.708472 0.020090] [    0.516922] imx_sec_dsim_drv 32e10000.mipi_dsi: Failed to attach bridge: 32e10000.mipi_dsi
[2.720184 0.011711] [    0.525200] imx_sec_dsim_drv 32e10000.mipi_dsi: failed to bind sec dsim bridge: -517
[2.879507 0.159323] -> Start Application...
[2.880566 0.001060] -> Application started !
[2.895512 0.014946] drm: drm_find_connector:222 35 LVDS
[2.897013 0.001501] 
[2.897077 0.000064] drm: drm_find_connector:230
[2.898190 0.001113] 
[2.898247 0.000056] drm: drm: connector 35: connected
[2.899559 0.001312] drm: drm_find_connector:241
[2.912351 0.012792] 
[2.912417 0.000066] drm: conn_id: 35
[2.913119 0.000702] drm: enc0 enc_id 34 conn enc_id 34
[2.914434 0.001315] drm: enc_id: 34
[2.915053 0.000618] drm: crtc_id: 33
[2.915704 0.000652] drm: crtc_idx: 0
[2.916356 0.000651] drm: drm: found planes 1
[2.917320 0.000964] drm: found plane 31
[2.918084 0.000764] drm: Found plane_id: 31 connector_id: 35 crtc_id: 33
[2.929305 0.011220] drm: 1280x800 (217mm X 136mm) pixel format RG16
[2.931113 0.001809] size 2048000 pitch 2560 offset 4096000
[2.932342 0.001229] size 2048000 pitch 2560 offset 6144000
[2.933313 0.000971] DRM subsystem and buffer mapped successfully
[2.944656 0.011343] drm drv: 0
[2.945111 0.000454] lv_example_get_started_1:35 0xaaaadd902290
[2.959459 0.014349] [    0.770761] systemd[1]: Failed to find module 'autofs4'
[2.961694 0.002235] drm: Flush done
[4.511469 1.549775] [    2.318978] atmel_mxt_ts 3-004a: __mxt_read_reg: i2c transfer failed (-6)
[4.527349 0.015880] [    2.337402] atmel_mxt_ts 3-004a: mxt_bootloader_read: i2c recv failed (-6)
[4.639380 0.112031] [    2.452137] atmel_mxt_ts 3-004a: mxt_bootloader_read: i2c recv failed (-6)
[7.743234 3.103855] 
[7.743375 0.000141] TDX Wayland with XWayland 6.4.0+build.8 (kirkstone) verdin-imx8mm-14700070 -
[7.746255 0.002879] Verdin-iMX8MM_Reference-Multimedia-Image
[7.747768 0.001513] 
[7.747820 0.000052] verdin-imx8mm-14700070 login:

From the grabserial’s log above, we can see that the “Start Application…”/“Application started” happened before the 3 seconds mark.

Conclusion

With this reference, I hope you got some possible ideas to make your system boot faster. And please note that the a different kernel compression was not needed. Also no falcon mode.

Best regards,