blob: 27a4905ac63e4772e5a913bb69a392cd1c2234f2 [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
Brad Bishop316dfdd2018-06-25 12:45:53 -04009FILES_${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
36do_configure_append() {
37 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
58do_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
69do_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
79do_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
86 ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name.$dtb_ext
87 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 -050088 for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do
Brad Bishopd7bf8c12018-02-25 22:55:05 -050089 if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080090 cat ${D}/${KERNEL_IMAGEDEST}/$type \
Brad Bishop64c979e2019-11-04 13:55:29 -050091 $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \
92 > $deployDir/$type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080093 ln -sf $type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin \
Brad Bishop64c979e2019-11-04 13:55:29 -050094 $deployDir/$type-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext.bin
Brad Bishopd7bf8c12018-02-25 22:55:05 -050095 if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then
96 cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \
Brad Bishop64c979e2019-11-04 13:55:29 -050097 $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \
98 > $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080099 ln -sf ${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin \
Brad Bishop64c979e2019-11-04 13:55:29 -0500100 $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext.bin
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500101 fi
102 fi
103 done
104 done
105}