poky/meta/classes-recipe/kernel-devicetree.bbclass
Martin Jansa fbace41114 kernel-devicetree: install dtb files without -${KERNEL_DTB_NAME} suffix
* we were installing them with -${KERNEL_DTB_NAME} suffix
  and then adding a symlink without this suffix if
  KERNEL_IMAGETYPE_SYMLINK is set:
  if [ "${KERNEL_IMAGETYPE_SYMLINK}" = "1" ] ; then
    ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name.$dtb_ext
  fi

  and another one when KERNEL_DTB_LINK_NAME is set:
  if [ -n "${KERNEL_DTB_LINK_NAME}" ] ; then
    ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext
  fi

  but KERNEL_DEVICETREE variable doesn't include this
  -${KERNEL_DTB_NAME} suffix, so everything which uses KERNEL_DEVICETREE
  either needs to add it as well or depend on KERNEL_IMAGETYPE_SYMLINK
  being set, e.g. IMAGE_BOOT_FILES variable used by do_image_wic is
  generated by make_dtb_boot_files function here:
  2ad4dd667a/conf/machine/include/rpi-base.inc (L118)
  and do_image_wic fails without KERNEL_IMAGETYPE_SYMLINK:
  | WARNING: bootloader config not specified, using defaults
  |
  | ERROR: _exec_cmd: install -m 0644 -D deploy/images/raspberrypi4-64/bcm2711-rpi-4-b.dtb image/1.0-r1/tmp-wic/boot.1/bcm2711-rpi-4-b.dtb returned '1' instead of 0
  | output: install: cannot stat 'deploy/images/raspberrypi4-64/bcm2711-rpi-4-b.dtb': No such file or directory

  we can fix the function to append -${KERNEL_DTB_NAME} or we can
  change this to install without suffix and then add ${KERNEL_DTB_NAME}
  link only when KERNEL_DTB_NAME is set (${MACHINE} by default)

* now it looks strange to have both KERNEL_DTB_LINK_NAME and KERNEL_DTB_NAME
  symlinks, but keep it for backwards compatibility and it will make
  more sense again together with the rest of [YOCTO #12937] where version
  specific *_LINK_NAME links are created as hardlinks in separate do_deploy_links
  task.

[YOCTO #12937]

(From OE-Core rev: 3d04a8405b0fffef7df0760bd4551bd8767a1954)

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2023-06-29 11:28:32 +01:00

140 lines
4.8 KiB
Plaintext

#
# Copyright OpenEmbedded Contributors
#
# SPDX-License-Identifier: MIT
#
# Support for device tree generation
python () {
if not bb.data.inherits_class('nopackages', d):
d.appendVar("PACKAGES", " ${KERNEL_PACKAGE_NAME}-devicetree")
if d.getVar('KERNEL_DEVICETREE_BUNDLE') == '1':
d.appendVar("PACKAGES", " ${KERNEL_PACKAGE_NAME}-image-zimage-bundle")
}
# recursivly search for devicetree files
FILES:${KERNEL_PACKAGE_NAME}-devicetree = " \
/${KERNEL_DTBDEST}/**/*.dtb \
/${KERNEL_DTBDEST}/**/*.dtbo \
"
FILES:${KERNEL_PACKAGE_NAME}-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin"
# Generate kernel+devicetree bundle
KERNEL_DEVICETREE_BUNDLE ?= "0"
# dtc flags passed via DTC_FLAGS env variable
KERNEL_DTC_FLAGS ?= ""
normalize_dtb () {
dtb="$1"
if echo $dtb | grep -q '/dts/'; then
bbwarn "$dtb contains the full path to the the dts file, but only the dtb name should be used."
dtb=`basename $dtb | sed 's,\.dts$,.dtb,g'`
fi
echo "$dtb"
}
get_real_dtb_path_in_kernel () {
dtb="$1"
dtb_path="${B}/arch/${ARCH}/boot/dts/$dtb"
if [ ! -e "$dtb_path" ]; then
dtb_path="${B}/arch/${ARCH}/boot/$dtb"
fi
echo "$dtb_path"
}
do_configure:append() {
if [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
if echo ${KERNEL_IMAGETYPE_FOR_MAKE} | grep -q 'zImage'; then
case "${ARCH}" in
"arm")
config="${B}/.config"
if ! grep -q 'CONFIG_ARM_APPENDED_DTB=y' $config; then
bbwarn 'CONFIG_ARM_APPENDED_DTB is NOT enabled in the kernel. Enabling it to allow the kernel to boot with the Device Tree appended!'
sed -i "/CONFIG_ARM_APPENDED_DTB[ =]/d" $config
echo "CONFIG_ARM_APPENDED_DTB=y" >> $config
echo "# CONFIG_ARM_ATAG_DTB_COMPAT is not set" >> $config
fi
;;
*)
bberror "KERNEL_DEVICETREE_BUNDLE is not supported for ${ARCH}. Currently it is only supported for 'ARM'."
esac
else
bberror 'The KERNEL_DEVICETREE_BUNDLE requires the KERNEL_IMAGETYPE to contain zImage.'
fi
fi
}
do_compile:append() {
if [ -n "${KERNEL_DTC_FLAGS}" ]; then
export DTC_FLAGS="${KERNEL_DTC_FLAGS}"
fi
for dtbf in ${KERNEL_DEVICETREE}; do
dtb=`normalize_dtb "$dtbf"`
oe_runmake $dtb CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" OBJCOPY="${KERNEL_OBJCOPY}" STRIP="${KERNEL_STRIP}" ${KERNEL_EXTRA_ARGS}
done
}
do_install:append() {
install -d ${D}/${KERNEL_DTBDEST}
for dtbf in ${KERNEL_DEVICETREE}; do
dtb=`normalize_dtb "$dtbf"`
dtb_path=`get_real_dtb_path_in_kernel "$dtb"`
if "${@'false' if oe.types.boolean(d.getVar('KERNEL_DTBVENDORED')) else 'true'}"; then
dtb_ext=${dtb##*.}
dtb_base_name=`basename $dtb .$dtb_ext`
dtb=$dtb_base_name.$dtb_ext
fi
install -Dm 0644 $dtb_path ${D}/${KERNEL_DTBDEST}/$dtb
done
}
do_deploy:append() {
for dtbf in ${KERNEL_DEVICETREE}; do
dtb=`normalize_dtb "$dtbf"`
dtb_ext=${dtb##*.}
dtb_base_name=`basename $dtb .$dtb_ext`
install -d $deployDir
if "${@'false' if oe.types.boolean(d.getVar('KERNEL_DTBVENDORED')) else 'true'}"; then
dtb=$dtb_base_name.$dtb_ext
fi
install -m 0644 ${D}/${KERNEL_DTBDEST}/$dtb $deployDir/$dtb_base_name.$dtb_ext
if [ -n "${KERNEL_DTB_NAME}" ] ; then
ln -sf $dtb_base_name.$dtb_ext $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext
fi
if [ -n "${KERNEL_DTB_LINK_NAME}" ] ; then
ln -sf $dtb_base_name.$dtb_ext $deployDir/$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext
fi
for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do
if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
cat ${D}/${KERNEL_IMAGEDEST}/$type \
$deployDir/$dtb_base_name.$dtb_ext \
> $deployDir/$type-$dtb_base_name.$dtb_ext${KERNEL_DTB_BIN_EXT}
if [ -n "${KERNEL_DTB_NAME}" ]; then
ln -sf $type-$dtb_base_name.$dtb_ext${KERNEL_DTB_BIN_EXT} \
$deployDir/$type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
fi
if [ -n "${KERNEL_DTB_LINK_NAME}" ]; then
ln -sf $type-$dtb_base_name.$dtb_ext${KERNEL_DTB_BIN_EXT} \
$deployDir/$type-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
fi
if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then
cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \
$deployDir/$dtb_base_name.$dtb_ext \
> $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name.$dtb_ext${KERNEL_DTB_BIN_EXT}
if [ -n "${KERNEL_DTB_NAME}" ]; then
ln -sf ${type}-${INITRAMFS_NAME}-$dtb_base_name.$dtb_ext${KERNEL_DTB_BIN_EXT} \
$deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
fi
if [ -n "${KERNEL_DTB_LINK_NAME}" ]; then
ln -sf ${type}-${INITRAMFS_NAME}-$dtb_base_name.$dtb_ext${KERNEL_DTB_BIN_EXT} \
$deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
fi
fi
fi
done
done
}