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 |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 86 | if [ "${KERNEL_IMAGETYPE_SYMLINK}" = "1" ] ; then |
| 87 | ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name.$dtb_ext |
| 88 | fi |
| 89 | if [ -n "${KERNEL_DTB_LINK_NAME}" ] ; then |
| 90 | ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext |
| 91 | fi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 92 | for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 93 | if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 94 | cat ${D}/${KERNEL_IMAGEDEST}/$type \ |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 95 | $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 96 | > $deployDir/$type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} |
| 97 | if [ -n "${KERNEL_DTB_LINK_NAME}" ]; then |
| 98 | ln -sf $type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} \ |
| 99 | $deployDir/$type-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} |
| 100 | fi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 101 | if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then |
| 102 | cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \ |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 103 | $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 104 | > $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} |
| 105 | if [ -n "${KERNEL_DTB_LINK_NAME}" ]; then |
| 106 | ln -sf ${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} \ |
| 107 | $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} |
| 108 | fi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 109 | fi |
| 110 | fi |
| 111 | done |
| 112 | done |
| 113 | } |