i’d like to study the boot prcess of CE after bootloader, i.e., from the img released on github.
so my first question is, what’s the first code to run in the FAT32 partition labelled with COREELEC, and who decides to boot this code instead of others?
aml_autoscript does only setup the boot environment of the Amlogic u-boot.
Then we use cfgload script for generic or boot.ini SBC device where we deliver CE u-boot as well.
So cfgload or boot.ini loads the kernel.img from storage to memory and boot the kernel.
The kernel.img is in Android boot image format v0, it’s a combination of kernel and initramfs. Its specifications is listed on Android doc: Boot Image Header | Android Open Source Project. Note that many features supported by this format do not exist in CoreELEC’s kernel.img as they are not needed, e.g. second stage ramdisk, cmdline.
Reason for Android to use this is to store kernel, initramfs, second stage ramdisk, cmdline, etc in the same partition (mostly boot or recovery) to ease the pain of maintenance, and Amlogic’s u-boot then naturally supports this format as they were designed to work as Android TV boxes. So it is the first choice if you want to side-load your kernel on Amlogic devices.
Only a few devices do not support this format due to the decision of vendors. An example for this is an unsupported device “Phicomm N1” which only supports plain kernel image and standalone initramfs file, and therefore cannot boot official CoreELEC/EmuELEC images.
You can check the script mkbootimg under the bootloader subfolder under the project/device. The last command combines kernel and initcpio into a single kernel.img.
About initramfs, you can get understanding of why it’s used for Linux from Arch Wiki: Arch boot process - ArchWiki. In fact I suggest you build an Arch PC from ground up to get a good understanding of how Linux works before dive into the bootup mechanism of Linux on ARM platforms