'Yocto Space Profiling Using KSize

I have a Yocto build that I am trying to shrink. I have removed a lot of unnecessary code by building core-image-full-cmdline. The Yocto mega manual mentions that to strip the size of your kernel you can use the ksize.py script in the project build directory. When I run this script I get an output of all 0s. This cannot be correct as I have a working SD card image with a booting kernel.



Solution 1:[1]

As I remember, you need to execute the script in the kernel folder. The script scan the current folder.

cd /path/to/kernel
python /path/to/ksize.py

(use python2 or 3 depending the current Yocto branch)

Solution 2:[2]

@PierreOlivier is right, you need to run this specifically from the kernel build directory (not the kernel source directory), in my case it is:

$ cd tmp/work/qemuarm64-poky-linux/linux-yocto/5.15.14+gitAUTOINC+72e4eafb6b_f77b2ba7d5-r0/linux-qemuarm64-standard-build
$ ../../../../../../../scripts/tiny/ksize.py
Linux Kernel                          total |       text       data        bss                   
--------------------------------------------------------------------------------                 
vmlinux                            20936031 |   15461191    4784912     689928                   
--------------------------------------------------------------------------------                 
fs/built-in.a                       4548119 |    3862922     640608      44589                   
drivers/built-in.a                  3991696 |    3591409     339384      60903    
kernel/built-in.a                   3104792 |    2078218     834883     191691  
net/built-in.a                      3083322 |    2731018     305491      46813

Additionally I recommend you try setting either:

DISTRO="poky-tiny"

or

PREFERRED_PROVIDER_linux-yocto = "linux-yocto-tiny"

Which would build a smaller kernel and/or rootfs as reference (assuming you are using linux-yocto and poky), you may set this on your local.conf

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PierreOlivier
Solution 2 aehs29