# Yocto Kernel Build Note
## do_prepare_recipe_sysroot
*meta/classes/staging.bbclass*
Copy the files into thw individual recipe work directories.
建立 `recipe-sysroot` 以及 `recipe-sysroot-native` directories,做`do_populate_sysroot`時會與這邊的檔案有相依性
## do_symlink_kernsrc
*meta/classes/kernel.bbclass*
有些old style kernel`${S} = ${WORKDIR}/git`,須將這裡的資料移至`${STAGING_KERNEL_DIR}`
Check if `${S}` not equal to `${STAGING_KERNEL_DIR}`, then move `${S}` files to `${STAGING_KERNEL_DIR}`
Aspeed case:
`${S} == ${STAGING_KERNEL_DIR} == build/tmp/work-shared/witherspoon/kernel-source`
## do_kernel_checkout
*meta/classes/kernel-yocto.bbclass*
Go to `${S}` and do git_init (如果.git存在也要再做一次,wierd),取得所有remote branch name,並checkout `${machine_branch}`
# Create a working tree copy of the kernel by checking out a branch
machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
``` python
def get_machine_branch(d, default):
fetch = bb.fetch2.Fetch([], d)
for url in fetch.urls:
urldata = fetch.ud[url]
parm = urldata.parm
if "branch" in parm:
branches = urldata.parm.get("branch").split(',')
btype = urldata.parm.get("type")
if btype != "kmeta":
return branches[0]
return default
```
In Aspeed case: `${S} = build/tmp/work-shared/witherspoon/kernel-source`
## do_validate_branches
*meta/classes/kernel-yocto.bbclass*
1. Ensure that the branch is on the locations specified by SRCREV value.
2. Add new branch `$current_branch-orig` and hard reset it for following patching stage.
Aspeed case:
`${SRCREV_machine}` is empty, `${SRCREV}` is defined in meta-aspeed/recipes-kernel/linux/linux-aspeed_git.bb
## do_kernel_metadata
Find kernel metadata **.scc** (Series Configuration Control) configuration fragments, and patches.
Aspeed case:
.scc and the associated cfg path: `meta-phosphor/aspeed-layer/recipes-kernel/linux/linux-aspeed`
For example, phosphor-gpio-keys.scc:
```
define KFEATURE_DESCRIPTION "Enable gpio-keys"
kconf non-hardware phosphor-gpio-keys.cfg
```
`KFEATURE_DESCRIPTION`: Description of the fragment
`kconf [hardware|non-hardware] CFG_FILE`: Queue a configuration fragment for merging into the final Linux .config file.
## do_patch
*meta/classes/kernel-yocto.bbclass*
Apply patches from `.kernel-meta/patch.queue`
In Aspeed case:
No patch exists (No .kernel-meta/series path)
## do_kernel_version_sanity_check
meta/classes/kernel.bbclass
Check kernel version.
If the package version `${PV}` matches the kernel being built `${vers}`, then success.
Aspeed case:
`${PV} = 5.4.39+gitAUTOINC+30079d65ac`, `${vers} = 5.4.39`, `${reg} = ^5\.4\.39`
## do_kernel_configme
*meta/classes/kernel-yocto.bbclass*
Search `.kernel-meta/config.queue` and merge to kernel .config
Aspeed case:
merge log: `build/tmp/work-shared/witherspoon/kernel-source/.kernel-meta/cfg/merge_config_build.log`
## do_populate_lic
*meta/classes/license.bbclass*
Write license information for the recipe that is collected later when the image is constructed.
## do_configure
*meta/classes/kernel.bbclass*
execute following command:
```
KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} CC="${KERNEL_CC}" LD="${KERNEL_LD}" O=${B} olddefconfig"
```
where
`oe_runmake_call` = `make`
`CC` = `arm-openbmc-linux-gnueabi-gcc`
`LD` = `arm-openbmc-linux-gnueabi-ld.bfd`
## do_kernel_configcheck
*meta/classes/kernel-yocto.bbclass*
驗證requested config是否出現在final .config中
Check three paths:
* ${S}/.meta/cfg/mismatch.txt
* specified values did not make it into the kernel's final configuration
* ${S}/.meta/cfg/invalid.cfg
* This BSP sets config options that are not offered anywhere within this kernel
* ${S}/.meta/cfg/redefinition.txt
* This BSP has configuration options defined in more than one config, with differing values
Aspeed case:
invalid.cfg exists --> CONFIG_INPUT_MOUSDEV
## do_compile
*meta/classes/kernel.bbclass*
```
for typeformake in zImage ; do
oe_runmake ${typeformake} CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}"
done
```
where
`$typeformake ` = `zImage`
## do_shared_workdir
編譯kernel結束到編譯lernel module之前,將kernel module的必要檔案移至shared work directory
Aspeed case:
shared work directory = `kerneldir` = `build/tmp/work-shared/witherspoon/kernel-build-artifacts`
## do_kernel_link_images
Do some symbolic link for vmlinux and vmlinuz
## do_assemble_fitimage
meta/class/kernel-fitimage.bbclass
Assemble the fit image
1. Prepare a kernel image section
2. Prepare a DTB image section
3. Prepare a configurations section
## do_compile_kernelmodules
*meta/classes/kernel.bbclass*
Search `CONFIG_MODULES=y` in .config, then make modules
Note:` CONFIG_MODULES` == Enable loadable module support
In Aspeed case:
no modules to compile
## do_strip
*meta/classes/kernel.bbclass*
if `KERNEL_IMAGE_STRIP_EXTRA_SECTIONS` is defined, emove nonessential sections such as .comment sections.
In Aspeed case:
No action
## do_sizecheck
*meta/classes/kernel.bbclass*
If `KERNEL_IMAGE_MAXSIZE` is defined, check kernel size. If size greater than `KERNEL_IMAGE_MAXSIZE`, it will show warning message
In Aspeed case:
`KERNEL_IMAGE_MAXSIZE` not defined
## do_install
*meta/classes/kernel.bbclass/kerneldoinstall()*
Copy kernel modules and fitimage to holding area `${D}`, do_package phase will use this holding directory.
Aspeed case:
No `CONFIG_MODULES=y`, so no modules to install
`${D} = build/tmp/work/witherspoon-openbmc-linux-gnueabi/linux-aspeed/5.4.39+gitAUTOINC+30079d65ac-r0/image`
`${KERNEL_IMAGEDEST} = boot`
## do_package
*meta/classes/package.bbclass*
## do_populate_sysroot
*meta/classes/staging.bbclass*
Copy a subset of the files installed by the do_install task into apporiate sysroot.
execute sysroot_stage_all --> sysroot_strip
## do_packagedata
*meta/classes/package.bbclass*
Saves package metadata generated by the do_package task in `$PKGDATA_DIR` to make it available globally
## do_package_write_rpm
Creates RPM packages (*.rpm) and places them in the `${DEPLOY_DIR_RPM}` directory
Aspeed case:
`${DEPLOY_DIR_RPM}` = `build/tmp/deploy/rpm`
## do_package_qa
*meta/classes/insane.bbclass*
Run QA checks on packaged files.
## do_bundle_initramfs
Combine an initial RAM disk (initramfs) image and kernel together to form a single image
## do_assemble_fitimage_initramfs
Aspeed case:
`$INITRAMFS_IMAGE` is empty, no action.
## do_deploy
Writes output files that are to be deployed to `${DEPLOY_DIR_IMAGE}`
## do_build
The default task for all recipes.
# OpenBMC Image

* aspeed-ast2600a1-evb--5.1.3+git0+3be8a38861-r0-evb-ast2600-20200602032717.dtb
--> kernel dtb file
* aspeed-image-initramfs-evb-ast2600-20200527072154.rootfs.cpio.xz
--> initramfs
* fitImage-aspeed-image-initramfs-evb-ast2600--5.1.3+git0+3be8a38861-r0-evb-ast2600-20200602032717.bin
--> Kernel FIT image (kernel + dtb + initramfs)