Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | # Support for device tree generation |
| 2 | PACKAGES_append = " \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 3 | ${KERNEL_PACKAGE_NAME}-devicetree \ |
| 4 | ${@[d.getVar('KERNEL_PACKAGE_NAME') + '-image-zimage-bundle', ''][d.getVar('KERNEL_DEVICETREE_BUNDLE') != '1']} \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | " |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 6 | FILES_${KERNEL_PACKAGE_NAME}-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo" |
| 7 | FILES_${KERNEL_PACKAGE_NAME}-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8 | |
| 9 | # Generate kernel+devicetree bundle |
| 10 | KERNEL_DEVICETREE_BUNDLE ?= "0" |
| 11 | |
| 12 | normalize_dtb () { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 13 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 17 | fi |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 18 | echo "$dtb" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | get_real_dtb_path_in_kernel () { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 22 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 26 | fi |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 27 | echo "$dtb_path" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | do_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 | |
| 52 | do_compile_append() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 53 | for dtbf in ${KERNEL_DEVICETREE}; do |
| 54 | dtb=`normalize_dtb "$dtbf"` |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 55 | oe_runmake $dtb CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 56 | done |
| 57 | } |
| 58 | |
| 59 | do_install_append() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 60 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 66 | done |
| 67 | } |
| 68 | |
| 69 | do_deploy_append() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 70 | for dtbf in ${KERNEL_DEVICETREE}; do |
| 71 | dtb=`normalize_dtb "$dtbf"` |
| 72 | dtb_ext=${dtb##*.} |
| 73 | dtb_base_name=`basename $dtb .$dtb_ext` |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 78 | for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 79 | if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 80 | cat ${D}/${KERNEL_IMAGEDEST}/$type \ |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 81 | $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \ |
| 82 | > $deployDir/$type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 83 | ln -sf $type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin \ |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 84 | $deployDir/$type-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext.bin |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 85 | if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then |
| 86 | cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \ |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 87 | $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \ |
| 88 | > $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 89 | ln -sf ${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin \ |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 90 | $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext.bin |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 91 | fi |
| 92 | fi |
| 93 | done |
| 94 | done |
| 95 | } |