blob: eff052b402963ab1c21f4aeb60d2fc3fc7e4b92b [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7# Support for device tree generation
8python () {
9 if not bb.data.inherits_class('nopackages', d):
10 d.appendVar("PACKAGES", " ${KERNEL_PACKAGE_NAME}-devicetree")
11 if d.getVar('KERNEL_DEVICETREE_BUNDLE') == '1':
12 d.appendVar("PACKAGES", " ${KERNEL_PACKAGE_NAME}-image-zimage-bundle")
13}
14
Patrick Williamse760df82023-05-26 11:10:49 -050015# recursivly search for devicetree files
Andrew Geissler028142b2023-05-05 11:29:21 -050016FILES:${KERNEL_PACKAGE_NAME}-devicetree = " \
Patrick Williamse760df82023-05-26 11:10:49 -050017 /${KERNEL_DTBDEST}/**/*.dtb \
18 /${KERNEL_DTBDEST}/**/*.dtbo \
Andrew Geissler028142b2023-05-05 11:29:21 -050019"
Patrick Williamse760df82023-05-26 11:10:49 -050020
Patrick Williams92b42cb2022-09-03 06:53:57 -050021FILES:${KERNEL_PACKAGE_NAME}-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin"
22
23# Generate kernel+devicetree bundle
24KERNEL_DEVICETREE_BUNDLE ?= "0"
25
26# dtc flags passed via DTC_FLAGS env variable
27KERNEL_DTC_FLAGS ?= ""
28
29normalize_dtb () {
30 dtb="$1"
31 if echo $dtb | grep -q '/dts/'; then
32 bbwarn "$dtb contains the full path to the the dts file, but only the dtb name should be used."
33 dtb=`basename $dtb | sed 's,\.dts$,.dtb,g'`
34 fi
35 echo "$dtb"
36}
37
38get_real_dtb_path_in_kernel () {
39 dtb="$1"
40 dtb_path="${B}/arch/${ARCH}/boot/dts/$dtb"
41 if [ ! -e "$dtb_path" ]; then
42 dtb_path="${B}/arch/${ARCH}/boot/$dtb"
43 fi
44 echo "$dtb_path"
45}
46
47do_configure:append() {
48 if [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
49 if echo ${KERNEL_IMAGETYPE_FOR_MAKE} | grep -q 'zImage'; then
50 case "${ARCH}" in
51 "arm")
52 config="${B}/.config"
53 if ! grep -q 'CONFIG_ARM_APPENDED_DTB=y' $config; then
54 bbwarn 'CONFIG_ARM_APPENDED_DTB is NOT enabled in the kernel. Enabling it to allow the kernel to boot with the Device Tree appended!'
55 sed -i "/CONFIG_ARM_APPENDED_DTB[ =]/d" $config
56 echo "CONFIG_ARM_APPENDED_DTB=y" >> $config
57 echo "# CONFIG_ARM_ATAG_DTB_COMPAT is not set" >> $config
58 fi
59 ;;
60 *)
61 bberror "KERNEL_DEVICETREE_BUNDLE is not supported for ${ARCH}. Currently it is only supported for 'ARM'."
62 esac
63 else
64 bberror 'The KERNEL_DEVICETREE_BUNDLE requires the KERNEL_IMAGETYPE to contain zImage.'
65 fi
66 fi
67}
68
69do_compile:append() {
70 if [ -n "${KERNEL_DTC_FLAGS}" ]; then
71 export DTC_FLAGS="${KERNEL_DTC_FLAGS}"
72 fi
73
74 for dtbf in ${KERNEL_DEVICETREE}; do
75 dtb=`normalize_dtb "$dtbf"`
Patrick Williams520786c2023-06-25 16:20:36 -050076 oe_runmake $dtb CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" OBJCOPY="${KERNEL_OBJCOPY}" STRIP="${KERNEL_STRIP}" ${KERNEL_EXTRA_ARGS}
Patrick Williams92b42cb2022-09-03 06:53:57 -050077 done
78}
79
80do_install:append() {
Andrew Geissler028142b2023-05-05 11:29:21 -050081 install -d ${D}/${KERNEL_DTBDEST}
Patrick Williams92b42cb2022-09-03 06:53:57 -050082 for dtbf in ${KERNEL_DEVICETREE}; do
83 dtb=`normalize_dtb "$dtbf"`
Patrick Williams92b42cb2022-09-03 06:53:57 -050084 dtb_path=`get_real_dtb_path_in_kernel "$dtb"`
Patrick Williamse760df82023-05-26 11:10:49 -050085 if "${@'false' if oe.types.boolean(d.getVar('KERNEL_DTBVENDORED')) else 'true'}"; then
Andrew Geissler028142b2023-05-05 11:29:21 -050086 dtb_ext=${dtb##*.}
87 dtb_base_name=`basename $dtb .$dtb_ext`
88 dtb=$dtb_base_name.$dtb_ext
89 fi
90 install -Dm 0644 $dtb_path ${D}/${KERNEL_DTBDEST}/$dtb
Patrick Williams92b42cb2022-09-03 06:53:57 -050091 done
92}
93
94do_deploy:append() {
95 for dtbf in ${KERNEL_DEVICETREE}; do
96 dtb=`normalize_dtb "$dtbf"`
97 dtb_ext=${dtb##*.}
98 dtb_base_name=`basename $dtb .$dtb_ext`
99 install -d $deployDir
Patrick Williamse760df82023-05-26 11:10:49 -0500100 if "${@'false' if oe.types.boolean(d.getVar('KERNEL_DTBVENDORED')) else 'true'}"; then
Andrew Geissler028142b2023-05-05 11:29:21 -0500101 dtb=$dtb_base_name.$dtb_ext
102 fi
Andrew Geissler8f840682023-07-21 09:09:43 -0500103 install -m 0644 ${D}/${KERNEL_DTBDEST}/$dtb $deployDir/$dtb_base_name.$dtb_ext
104 if [ -n "${KERNEL_DTB_NAME}" ] ; then
105 ln -sf $dtb_base_name.$dtb_ext $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext
Patrick Williams92b42cb2022-09-03 06:53:57 -0500106 fi
107 if [ -n "${KERNEL_DTB_LINK_NAME}" ] ; then
Andrew Geissler8f840682023-07-21 09:09:43 -0500108 ln -sf $dtb_base_name.$dtb_ext $deployDir/$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext
Patrick Williams92b42cb2022-09-03 06:53:57 -0500109 fi
110 for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do
111 if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
112 cat ${D}/${KERNEL_IMAGEDEST}/$type \
Andrew Geissler8f840682023-07-21 09:09:43 -0500113 $deployDir/$dtb_base_name.$dtb_ext \
114 > $deployDir/$type-$dtb_base_name.$dtb_ext${KERNEL_DTB_BIN_EXT}
115 if [ -n "${KERNEL_DTB_NAME}" ]; then
116 ln -sf $type-$dtb_base_name.$dtb_ext${KERNEL_DTB_BIN_EXT} \
117 $deployDir/$type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
118 fi
Patrick Williams92b42cb2022-09-03 06:53:57 -0500119 if [ -n "${KERNEL_DTB_LINK_NAME}" ]; then
Andrew Geissler8f840682023-07-21 09:09:43 -0500120 ln -sf $type-$dtb_base_name.$dtb_ext${KERNEL_DTB_BIN_EXT} \
Patrick Williams92b42cb2022-09-03 06:53:57 -0500121 $deployDir/$type-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
122 fi
123 if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then
124 cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \
Andrew Geissler8f840682023-07-21 09:09:43 -0500125 $deployDir/$dtb_base_name.$dtb_ext \
126 > $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name.$dtb_ext${KERNEL_DTB_BIN_EXT}
127 if [ -n "${KERNEL_DTB_NAME}" ]; then
128 ln -sf ${type}-${INITRAMFS_NAME}-$dtb_base_name.$dtb_ext${KERNEL_DTB_BIN_EXT} \
129 $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
130 fi
Patrick Williams92b42cb2022-09-03 06:53:57 -0500131 if [ -n "${KERNEL_DTB_LINK_NAME}" ]; then
Andrew Geissler8f840682023-07-21 09:09:43 -0500132 ln -sf ${type}-${INITRAMFS_NAME}-$dtb_base_name.$dtb_ext${KERNEL_DTB_BIN_EXT} \
Patrick Williams92b42cb2022-09-03 06:53:57 -0500133 $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
134 fi
135 fi
136 fi
137 done
138 done
139}