Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | # Support for device tree generation |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 2 | python () { |
| 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 Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame^] | 9 | FILES:${KERNEL_PACKAGE_NAME}-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo" |
| 10 | FILES:${KERNEL_PACKAGE_NAME}-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 11 | |
| 12 | # Generate kernel+devicetree bundle |
| 13 | KERNEL_DEVICETREE_BUNDLE ?= "0" |
| 14 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 15 | # dtc flags passed via DTC_FLAGS env variable |
| 16 | KERNEL_DTC_FLAGS ?= "" |
| 17 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 18 | normalize_dtb () { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 19 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 23 | fi |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 24 | echo "$dtb" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | get_real_dtb_path_in_kernel () { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 28 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 32 | fi |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 33 | echo "$dtb_path" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 34 | } |
| 35 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame^] | 36 | do_configure:append() { |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 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 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame^] | 58 | do_compile:append() { |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 59 | if [ -n "${KERNEL_DTC_FLAGS}" ]; then |
| 60 | export DTC_FLAGS="${KERNEL_DTC_FLAGS}" |
| 61 | fi |
| 62 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 63 | for dtbf in ${KERNEL_DEVICETREE}; do |
| 64 | dtb=`normalize_dtb "$dtbf"` |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 65 | 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] | 66 | done |
| 67 | } |
| 68 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame^] | 69 | do_install: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` |
| 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 76 | done |
| 77 | } |
| 78 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame^] | 79 | do_deploy:append() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 80 | for dtbf in ${KERNEL_DEVICETREE}; do |
| 81 | dtb=`normalize_dtb "$dtbf"` |
| 82 | dtb_ext=${dtb##*.} |
| 83 | dtb_base_name=`basename $dtb .$dtb_ext` |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 84 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 88 | for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 89 | if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 90 | cat ${D}/${KERNEL_IMAGEDEST}/$type \ |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 91 | $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \ |
| 92 | > $deployDir/$type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 93 | ln -sf $type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext.bin \ |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 94 | $deployDir/$type-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext.bin |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 95 | if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then |
| 96 | cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \ |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 97 | $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \ |
| 98 | > $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] | 99 | 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] | 100 | $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] | 101 | fi |
| 102 | fi |
| 103 | done |
| 104 | done |
| 105 | } |