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 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 12 | # dtc flags passed via DTC_FLAGS env variable |
| 13 | KERNEL_DTC_FLAGS ?= "" |
| 14 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 15 | normalize_dtb () { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 16 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 20 | fi |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 21 | echo "$dtb" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | get_real_dtb_path_in_kernel () { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 25 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 29 | fi |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 30 | echo "$dtb_path" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | do_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 | |
| 55 | do_compile_append() { |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 56 | if [ -n "${KERNEL_DTC_FLAGS}" ]; then |
| 57 | export DTC_FLAGS="${KERNEL_DTC_FLAGS}" |
| 58 | fi |
| 59 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 60 | for dtbf in ${KERNEL_DEVICETREE}; do |
| 61 | dtb=`normalize_dtb "$dtbf"` |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 62 | 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] | 63 | done |
| 64 | } |
| 65 | |
| 66 | do_install_append() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 67 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 73 | done |
| 74 | } |
| 75 | |
| 76 | do_deploy_append() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 77 | for dtbf in ${KERNEL_DEVICETREE}; do |
| 78 | dtb=`normalize_dtb "$dtbf"` |
| 79 | dtb_ext=${dtb##*.} |
| 80 | dtb_base_name=`basename $dtb .$dtb_ext` |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 81 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 85 | for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 86 | if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 87 | cat ${D}/${KERNEL_IMAGEDEST}/$type \ |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 88 | $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \ |
| 89 | > $deployDir/$type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 90 | ln -sf $type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin \ |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 91 | $deployDir/$type-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext.bin |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 92 | if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then |
| 93 | cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \ |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 94 | $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \ |
| 95 | > $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] | 96 | 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] | 97 | $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] | 98 | fi |
| 99 | fi |
| 100 | done |
| 101 | done |
| 102 | } |