blob: b4338da1b138522995e6c7610b71439da99e5c44 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001# Support for device tree generation
Andrew Geissler5f350902021-07-23 13:09:54 -04002python () {
3 if not bb.data.inherits_class('nopackages', d):
4 d.appendVar("PACKAGES", " ${KERNEL_PACKAGE_NAME}-devicetree")
5 if d.getVar('KERNEL_DEVICETREE_BUNDLE') == '1':
6 d.appendVar("PACKAGES", " ${KERNEL_PACKAGE_NAME}-image-zimage-bundle")
7}
8
Patrick Williams213cb262021-08-07 19:21:33 -05009FILES:${KERNEL_PACKAGE_NAME}-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo"
10FILES:${KERNEL_PACKAGE_NAME}-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011
12# Generate kernel+devicetree bundle
13KERNEL_DEVICETREE_BUNDLE ?= "0"
14
Andrew Geisslerd1e89492021-02-12 15:35:20 -060015# dtc flags passed via DTC_FLAGS env variable
16KERNEL_DTC_FLAGS ?= ""
17
Brad Bishopd7bf8c12018-02-25 22:55:05 -050018normalize_dtb () {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080019 dtb="$1"
20 if echo $dtb | grep -q '/dts/'; then
21 bbwarn "$dtb contains the full path to the the dts file, but only the dtb name should be used."
22 dtb=`basename $dtb | sed 's,\.dts$,.dtb,g'`
Brad Bishopd7bf8c12018-02-25 22:55:05 -050023 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080024 echo "$dtb"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050025}
26
27get_real_dtb_path_in_kernel () {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080028 dtb="$1"
29 dtb_path="${B}/arch/${ARCH}/boot/dts/$dtb"
30 if [ ! -e "$dtb_path" ]; then
31 dtb_path="${B}/arch/${ARCH}/boot/$dtb"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080033 echo "$dtb_path"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050034}
35
Patrick Williams213cb262021-08-07 19:21:33 -050036do_configure:append() {
Brad Bishopd7bf8c12018-02-25 22:55:05 -050037 if [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
38 if echo ${KERNEL_IMAGETYPE_FOR_MAKE} | grep -q 'zImage'; then
39 case "${ARCH}" in
40 "arm")
41 config="${B}/.config"
42 if ! grep -q 'CONFIG_ARM_APPENDED_DTB=y' $config; then
43 bbwarn 'CONFIG_ARM_APPENDED_DTB is NOT enabled in the kernel. Enabling it to allow the kernel to boot with the Device Tree appended!'
44 sed -i "/CONFIG_ARM_APPENDED_DTB[ =]/d" $config
45 echo "CONFIG_ARM_APPENDED_DTB=y" >> $config
46 echo "# CONFIG_ARM_ATAG_DTB_COMPAT is not set" >> $config
47 fi
48 ;;
49 *)
50 bberror "KERNEL_DEVICETREE_BUNDLE is not supported for ${ARCH}. Currently it is only supported for 'ARM'."
51 esac
52 else
53 bberror 'The KERNEL_DEVICETREE_BUNDLE requires the KERNEL_IMAGETYPE to contain zImage.'
54 fi
55 fi
56}
57
Patrick Williams213cb262021-08-07 19:21:33 -050058do_compile:append() {
Andrew Geisslerd1e89492021-02-12 15:35:20 -060059 if [ -n "${KERNEL_DTC_FLAGS}" ]; then
60 export DTC_FLAGS="${KERNEL_DTC_FLAGS}"
61 fi
62
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080063 for dtbf in ${KERNEL_DEVICETREE}; do
64 dtb=`normalize_dtb "$dtbf"`
Andrew Geissler635e0e42020-08-21 15:58:33 -050065 oe_runmake $dtb CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS}
Brad Bishopd7bf8c12018-02-25 22:55:05 -050066 done
67}
68
Patrick Williams213cb262021-08-07 19:21:33 -050069do_install:append() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080070 for dtbf in ${KERNEL_DEVICETREE}; do
71 dtb=`normalize_dtb "$dtbf"`
72 dtb_ext=${dtb##*.}
73 dtb_base_name=`basename $dtb .$dtb_ext`
74 dtb_path=`get_real_dtb_path_in_kernel "$dtb"`
75 install -m 0644 $dtb_path ${D}/${KERNEL_IMAGEDEST}/$dtb_base_name.$dtb_ext
Brad Bishopd7bf8c12018-02-25 22:55:05 -050076 done
77}
78
Patrick Williams213cb262021-08-07 19:21:33 -050079do_deploy:append() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080080 for dtbf in ${KERNEL_DEVICETREE}; do
81 dtb=`normalize_dtb "$dtbf"`
82 dtb_ext=${dtb##*.}
83 dtb_base_name=`basename $dtb .$dtb_ext`
Brad Bishop64c979e2019-11-04 13:55:29 -050084 install -d $deployDir
85 install -m 0644 ${D}/${KERNEL_IMAGEDEST}/$dtb_base_name.$dtb_ext $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext
Andrew Geissler595f6302022-01-24 19:11:47 +000086 if [ "${KERNEL_IMAGETYPE_SYMLINK}" = "1" ] ; then
87 ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name.$dtb_ext
88 fi
89 if [ -n "${KERNEL_DTB_LINK_NAME}" ] ; then
90 ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext
91 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -050092 for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do
Brad Bishopd7bf8c12018-02-25 22:55:05 -050093 if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080094 cat ${D}/${KERNEL_IMAGEDEST}/$type \
Brad Bishop64c979e2019-11-04 13:55:29 -050095 $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \
Andrew Geissler595f6302022-01-24 19:11:47 +000096 > $deployDir/$type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
97 if [ -n "${KERNEL_DTB_LINK_NAME}" ]; then
98 ln -sf $type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} \
99 $deployDir/$type-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
100 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500101 if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then
102 cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \
Brad Bishop64c979e2019-11-04 13:55:29 -0500103 $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \
Andrew Geissler595f6302022-01-24 19:11:47 +0000104 > $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
105 if [ -n "${KERNEL_DTB_LINK_NAME}" ]; then
106 ln -sf ${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} \
107 $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
108 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500109 fi
110 fi
111 done
112 done
113}