sudo apt install libncurses5-dev flex bison # for menuconfig tool.
sudo apt install subversion libssl-dev
sudo apt-get install qemu-system
sudo apt-get install device-tree-compiler
- Download/Choose Kernel.
- Understand kernel versioning system [stable-mainline-long-term-support]
- Understand kernel source code tree.
- Understand Device tree.
- Understand menuconfig/kconfig/kbuild.
- Compiling Kernel for raspi3/4
- Identify Kernel size.
- Compiling device tree.
- Booting kernel on Qemu.
- Choose Kernel Version.
- Downloading Source code.
- Understand Kernel config.
- Identify Kernel Version.
- Compiling kernel for specific target.
- Build artifcats [Targets]:
- VMLinux: elf version.
- zImage: compressed version (u-boot understand it through
bootzcommand) - uImage: for uBoot.
a. from vendor
source: https://www.raspberrypi.com/documentation/computers/linux_kernel.html\
git clone --depth=1 -b rpi-4.19.y https://github.com/raspberrypi/linux.git # raspberrypi linux version.
[Kernel.org](https://www.kernel.org/) # Main branches [Kernel Archives]
b. from kernel main branch.
1. [Kernel.org](https://www.kernel.org/) # Main branches [Kernel Archives]
2. wget <version link from kernel.org>
3. tar xf <compressed filename>
- menuconfig ---> read KConfig ---> output .config
make ARCH=<target> menuconfig
# choose configs
make ARCH=<target> <filename>
-
Kbuild ---> read .config ---> add parameters inside code as Macros.
-
build :)
make ARCH=<target> kernelrelease
- Most Important Targets:
a. VMLinux b. zImage c. uImage. d. distclean
- Most Used make targets.
a. distclean
make ARCH=<target> distclean
b. vmLinux: elf
make -j 4 ARCH=<target> CROSS_COMPILE=`prefix`
# output
> main directory for Linux.
c. zImage: compressed.
make -j4 ARCH=<target> CROSS_COMPILE=`prefix` Image
# output
<linux_directory>/arch/<target>/boot
d. uImage: zImage + uBoot header.
make -j4 ARCH=<target> CROSS_COMPILE=`prefix` LOADADDR=0x80008000 uImage
# output
<linux_directory>/arch/<target>/boot
a. Find device tree for target. Device tree for Raspi3
b. compile device tree.
dtc <name>.dts -o <name>.dtb # convert it into binary.
qemu-system-aarch64 \
-M raspi3b \
-cpu cortex-a72 \
-append "rw earlyprintk loglevel=8 console=ttyAMA0,115200" \
-kernel <Image> \
-dtb <dtb>.dtb \
-m 1G -smp 4 \
-serial stdio \
-usb -device usb-mouse -device usb-kbd \
-device usb-net,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::5555-:22
