Skip to content

Instantly share code, notes, and snippets.

@rgov
Created January 17, 2022 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgov/0628785685ab858a99c5bfca626c1d8f to your computer and use it in GitHub Desktop.
Save rgov/0628785685ab858a99c5bfca626c1d8f to your computer and use it in GitHub Desktop.
# As of Linux version 3.7, we must provide a device tree blob on boot so that
# the kernel understands our hardware configuration.
#
# However, the version of U-Boot currently in use predates the use of device
# trees, and provides no way of specifying the DTB to load. Therefore, there
# exists a configuration option CONFIG_ARM_APPENDED_DTB=y which instructs the
# kernel to find the DTB immediate following the kernel image itself.
#
# To produce a uImage file with the combined kernel + DTB, we just concatenate
# the two before running mkimage. (Note, the uImage file header includes a
# data size field and a checksum field, so one should not append to the
# uImage after the fact, as meta-ti's bundle-devicetree.inc does.)
#
# Poky's kernel-devicetree.bbclass appears to provide a way to do this with the
# KERNEL_DEVICETREE_BUNDLE variable but it caused build errors as of the
# Honister release.
#
# Therefore, we modify the behavior of Poky's do_uboot_mkimage task to append
# the DTB file ourselves.
inherit kernel-uimage
python __anonymous () {
# The KERNEL_IMAGETYPE must be uImage, not zImage etc.
if "uImage" not in d.getVar("KERNEL_IMAGETYPES"):
bb.fatal("Set KERNEL_IMAGETYPE = \"uImage\".")
# We only append one .dtb file
if len(d.getVar("KERNEL_DEVICETREE").split()) != 1:
bb.fatal("Set KERNEL_DEVICETREE to exactly one DTB file.")
# The KERNEL_DEVICETREE_BUNDLE behavior defined in kernel-devicetree.bbclass
# does not seem to work.
if d.getVar("KERNEL_DEVICETREE_BUNDLE") != "0":
bb.fatal("Do not use KERNEL_DEVICETREE_BUNDLE. "
"See comment in kernel-uimage+dtb.bbclass.")
# We must disable the KEEPUIMAGE option to trigger the execution of the
# do_uboot_mkimage task in kernel-uimage.bbclass.
if d.getVar("KEEPUIMAGE") == "yes":
bb.fatal("Set KEEPUIMAGE = \"no\" to build a uImage with appended DTB.")
}
do_configure:append() {
if ! grep -q "CONFIG_ARM_APPENDED_DTB=y" "${B}/.config"; then
bbwarn "CONFIG_ARM_APPENDED_DTB is NOT enabled in the kernel!"
fi
}
# Append the DTB file to the linux.bin file, prior to building the uImage in
# do_uboot_mkimage().
uboot_prep_kimage:append () {
# This function is defined in kernel-devicetree.class
dtb_file=`get_real_dtb_path_in_kernel "${KERNEL_DEVICETREE}"`
mv linux.bin linux-orig.bin
cat linux-orig.bin "${dtb_file}" > linux+dtb.bin
ln -s linux+dtb.bin linux.bin
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment