blob: 867b776aa7f342db36dc673831cbce842768306e [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
12normalize_dtb () {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080013 dtb="$1"
14 if echo $dtb | grep -q '/dts/'; then
15 bbwarn "$dtb contains the full path to the the dts file, but only the dtb name should be used."
16 dtb=`basename $dtb | sed 's,\.dts$,.dtb,g'`
Brad Bishopd7bf8c12018-02-25 22:55:05 -050017 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080018 echo "$dtb"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050019}
20
21get_real_dtb_path_in_kernel () {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080022 dtb="$1"
23 dtb_path="${B}/arch/${ARCH}/boot/dts/$dtb"
24 if [ ! -e "$dtb_path" ]; then
25 dtb_path="${B}/arch/${ARCH}/boot/$dtb"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050026 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080027 echo "$dtb_path"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050028}
29
30do_configure_append() {
31 if [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
32 if echo ${KERNEL_IMAGETYPE_FOR_MAKE} | grep -q 'zImage'; then
33 case "${ARCH}" in
34 "arm")
35 config="${B}/.config"
36 if ! grep -q 'CONFIG_ARM_APPENDED_DTB=y' $config; then
37 bbwarn 'CONFIG_ARM_APPENDED_DTB is NOT enabled in the kernel. Enabling it to allow the kernel to boot with the Device Tree appended!'
38 sed -i "/CONFIG_ARM_APPENDED_DTB[ =]/d" $config
39 echo "CONFIG_ARM_APPENDED_DTB=y" >> $config
40 echo "# CONFIG_ARM_ATAG_DTB_COMPAT is not set" >> $config
41 fi
42 ;;
43 *)
44 bberror "KERNEL_DEVICETREE_BUNDLE is not supported for ${ARCH}. Currently it is only supported for 'ARM'."
45 esac
46 else
47 bberror 'The KERNEL_DEVICETREE_BUNDLE requires the KERNEL_IMAGETYPE to contain zImage.'
48 fi
49 fi
50}
51
52do_compile_append() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080053 for dtbf in ${KERNEL_DEVICETREE}; do
54 dtb=`normalize_dtb "$dtbf"`
55 oe_runmake $dtb
Brad Bishopd7bf8c12018-02-25 22:55:05 -050056 done
57}
58
59do_install_append() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080060 for dtbf in ${KERNEL_DEVICETREE}; do
61 dtb=`normalize_dtb "$dtbf"`
62 dtb_ext=${dtb##*.}
63 dtb_base_name=`basename $dtb .$dtb_ext`
64 dtb_path=`get_real_dtb_path_in_kernel "$dtb"`
65 install -m 0644 $dtb_path ${D}/${KERNEL_IMAGEDEST}/$dtb_base_name.$dtb_ext
Brad Bishopd7bf8c12018-02-25 22:55:05 -050066 done
67}
68
69do_deploy_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 install -d ${DEPLOYDIR}
75 install -m 0644 ${D}/${KERNEL_IMAGEDEST}/$dtb_base_name.$dtb_ext ${DEPLOYDIR}/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext
76 ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext ${DEPLOYDIR}/$dtb_base_name.$dtb_ext
77 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 -050078 for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do
Brad Bishopd7bf8c12018-02-25 22:55:05 -050079 if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080080 cat ${D}/${KERNEL_IMAGEDEST}/$type \
81 ${DEPLOYDIR}/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \
82 > ${DEPLOYDIR}/$type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin
83 ln -sf $type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin \
84 ${DEPLOYDIR}/$type-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext.bin
Brad Bishopd7bf8c12018-02-25 22:55:05 -050085 if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then
86 cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080087 ${DEPLOYDIR}/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext
88 > ${DEPLOYDIR}/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin
89 ln -sf ${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin \
90 ${DEPLOYDIR}/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext.bin
Brad Bishopd7bf8c12018-02-25 22:55:05 -050091 fi
92 fi
93 done
94 done
95}