What's the first code to run when booting from TF/UDISK?

hi community,

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?

many thanks.

i belive the very first code to run is aml_autoscript, though i’ve got no proof…

and what’s the format of kernel.img?

and, where do the commands setenv/run/fatload/bootm/etc are defined?

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.

one step ahead. thanks.

what’s the format of kernel.img? KERNEL seems to be a squashfs image (i’m not with a linux box so i cannot verify it)

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

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.