blob: d4f8864200d7ffb13839165e0c40a0182620c5e4 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001# Support for device tree generation
2PACKAGES_append = " \
Brad Bishop316dfdd2018-06-25 12:45:53 -04003 ${KERNEL_PACKAGE_NAME}-devicetree \
4 ${@[d.getVar('KERNEL_PACKAGE_NAME') + '-image-zimage-bundle', ''][d.getVar('KERNEL_DEVICETREE_BUNDLE') != '1']} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005"
Brad Bishop316dfdd2018-06-25 12:45:53 -04006FILES_${KERNEL_PACKAGE_NAME}-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo"
7FILES_${KERNEL_PACKAGE_NAME}-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008
9# Generate kernel+devicetree bundle
10KERNEL_DEVICETREE_BUNDLE ?= "0"
11
Andrew Geisslerd1e89492021-02-12 15:35:20 -060012# dtc flags passed via DTC_FLAGS env variable
13KERNEL_DTC_FLAGS ?= ""
14
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015normalize_dtb () {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080016 dtb="$1"
17 if echo $dtb | grep -q '/dts/'; then
18 bbwarn "$dtb contains the full path to the the dts file, but only the dtb name should be used."
19 dtb=`basename $dtb | sed 's,\.dts$,.dtb,g'`
Brad Bishopd7bf8c12018-02-25 22:55:05 -050020 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080021 echo "$dtb"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050022}
23
24get_real_dtb_path_in_kernel () {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080025 dtb="$1"
26 dtb_path="${B}/arch/${ARCH}/boot/dts/$dtb"
27 if [ ! -e "$dtb_path" ]; then
28 dtb_path="${B}/arch/${ARCH}/boot/$dtb"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050029 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080030 echo "$dtb_path"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050031}
32
33do_configure_append() {
34 if [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
35 if echo ${KERNEL_IMAGETYPE_FOR_MAKE} | grep -q 'zImage'; then
36 case "${ARCH}" in
37 "arm")
38 config="${B}/.config"
39 if ! grep -q 'CONFIG_ARM_APPENDED_DTB=y' $config; then
40 bbwarn 'CONFIG_ARM_APPENDED_DTB is NOT enabled in the kernel. Enabling it to allow the kernel to boot with the Device Tree appended!'
41 sed -i "/CONFIG_ARM_APPENDED_DTB[ =]/d" $config
42 echo "CONFIG_ARM_APPENDED_DTB=y" >> $config
43 echo "# CONFIG_ARM_ATAG_DTB_COMPAT is not set" >> $config
44 fi
45 ;;
46 *)
47 bberror "KERNEL_DEVICETREE_BUNDLE is not supported for ${ARCH}. Currently it is only supported for 'ARM'."
48 esac
49 else
50 bberror 'The KERNEL_DEVICETREE_BUNDLE requires the KERNEL_IMAGETYPE to contain zImage.'
51 fi
52 fi
53}
54
55do_compile_append() {
Andrew Geisslerd1e89492021-02-12 15:35:20 -060056 if [ -n "${KERNEL_DTC_FLAGS}" ]; then
57 export DTC_FLAGS="${KERNEL_DTC_FLAGS}"
58 fi
59
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080060 for dtbf in ${KERNEL_DEVICETREE}; do
61 dtb=`normalize_dtb "$dtbf"`
Andrew Geissler635e0e42020-08-21 15:58:33 -050062 oe_runmake $dtb CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS}
Brad Bishopd7bf8c12018-02-25 22:55:05 -050063 done
64}
65
66do_install_append() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080067 for dtbf in ${KERNEL_DEVICETREE}; do
68 dtb=`normalize_dtb "$dtbf"`
69 dtb_ext=${dtb##*.}
70 dtb_base_name=`basename $dtb .$dtb_ext`
71 dtb_path=`get_real_dtb_path_in_kernel "$dtb"`
72 install -m 0644 $dtb_path ${D}/${KERNEL_IMAGEDEST}/$dtb_base_name.$dtb_ext
Brad Bishopd7bf8c12018-02-25 22:55:05 -050073 done
74}
75
76do_deploy_append() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080077 for dtbf in ${KERNEL_DEVICETREE}; do
78 dtb=`normalize_dtb "$dtbf"`
79 dtb_ext=${dtb##*.}
80 dtb_base_name=`basename $dtb .$dtb_ext`
Brad Bishop64c979e2019-11-04 13:55:29 -050081 install -d $deployDir
82 install -m 0644 ${D}/${KERNEL_IMAGEDEST}/$dtb_base_name.$dtb_ext $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext
83 ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name.$dtb_ext
84 ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext
Brad Bishopd7bf8c12018-02-25 22:55:05 -050085 for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do
Brad Bishopd7bf8c12018-02-25 22:55:05 -050086 if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080087 cat ${D}/${KERNEL_IMAGEDEST}/$type \
Brad Bishop64c979e2019-11-04 13:55:29 -050088 $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \
89 > $deployDir/$type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080090 ln -sf $type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin \
Brad Bishop64c979e2019-11-04 13:55:29 -050091 $deployDir/$type-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext.bin
Brad Bishopd7bf8c12018-02-25 22:55:05 -050092 if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then
93 cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \
Brad Bishop64c979e2019-11-04 13:55:29 -050094 $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \
95 > $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080096 ln -sf ${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin \
Brad Bishop64c979e2019-11-04 13:55:29 -050097 $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext.bin
Brad Bishopd7bf8c12018-02-25 22:55:05 -050098 fi
99 fi
100 done
101 done
102}