Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | # Support for device tree generation |
| 8 | python () { |
| 9 | if not bb.data.inherits_class('nopackages', d): |
| 10 | d.appendVar("PACKAGES", " ${KERNEL_PACKAGE_NAME}-devicetree") |
| 11 | if d.getVar('KERNEL_DEVICETREE_BUNDLE') == '1': |
| 12 | d.appendVar("PACKAGES", " ${KERNEL_PACKAGE_NAME}-image-zimage-bundle") |
| 13 | } |
| 14 | |
Patrick Williams | e760df8 | 2023-05-26 11:10:49 -0500 | [diff] [blame] | 15 | # recursivly search for devicetree files |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 16 | FILES:${KERNEL_PACKAGE_NAME}-devicetree = " \ |
Patrick Williams | e760df8 | 2023-05-26 11:10:49 -0500 | [diff] [blame] | 17 | /${KERNEL_DTBDEST}/**/*.dtb \ |
| 18 | /${KERNEL_DTBDEST}/**/*.dtbo \ |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 19 | " |
Patrick Williams | e760df8 | 2023-05-26 11:10:49 -0500 | [diff] [blame] | 20 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 21 | FILES:${KERNEL_PACKAGE_NAME}-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin" |
| 22 | |
| 23 | # Generate kernel+devicetree bundle |
| 24 | KERNEL_DEVICETREE_BUNDLE ?= "0" |
| 25 | |
| 26 | # dtc flags passed via DTC_FLAGS env variable |
| 27 | KERNEL_DTC_FLAGS ?= "" |
| 28 | |
| 29 | normalize_dtb () { |
| 30 | dtb="$1" |
| 31 | if echo $dtb | grep -q '/dts/'; then |
| 32 | bbwarn "$dtb contains the full path to the the dts file, but only the dtb name should be used." |
| 33 | dtb=`basename $dtb | sed 's,\.dts$,.dtb,g'` |
| 34 | fi |
| 35 | echo "$dtb" |
| 36 | } |
| 37 | |
| 38 | get_real_dtb_path_in_kernel () { |
| 39 | dtb="$1" |
| 40 | dtb_path="${B}/arch/${ARCH}/boot/dts/$dtb" |
| 41 | if [ ! -e "$dtb_path" ]; then |
| 42 | dtb_path="${B}/arch/${ARCH}/boot/$dtb" |
| 43 | fi |
| 44 | echo "$dtb_path" |
| 45 | } |
| 46 | |
| 47 | do_configure:append() { |
| 48 | if [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then |
| 49 | if echo ${KERNEL_IMAGETYPE_FOR_MAKE} | grep -q 'zImage'; then |
| 50 | case "${ARCH}" in |
| 51 | "arm") |
| 52 | config="${B}/.config" |
| 53 | if ! grep -q 'CONFIG_ARM_APPENDED_DTB=y' $config; then |
| 54 | bbwarn 'CONFIG_ARM_APPENDED_DTB is NOT enabled in the kernel. Enabling it to allow the kernel to boot with the Device Tree appended!' |
| 55 | sed -i "/CONFIG_ARM_APPENDED_DTB[ =]/d" $config |
| 56 | echo "CONFIG_ARM_APPENDED_DTB=y" >> $config |
| 57 | echo "# CONFIG_ARM_ATAG_DTB_COMPAT is not set" >> $config |
| 58 | fi |
| 59 | ;; |
| 60 | *) |
| 61 | bberror "KERNEL_DEVICETREE_BUNDLE is not supported for ${ARCH}. Currently it is only supported for 'ARM'." |
| 62 | esac |
| 63 | else |
| 64 | bberror 'The KERNEL_DEVICETREE_BUNDLE requires the KERNEL_IMAGETYPE to contain zImage.' |
| 65 | fi |
| 66 | fi |
| 67 | } |
| 68 | |
| 69 | do_compile:append() { |
| 70 | if [ -n "${KERNEL_DTC_FLAGS}" ]; then |
| 71 | export DTC_FLAGS="${KERNEL_DTC_FLAGS}" |
| 72 | fi |
| 73 | |
| 74 | for dtbf in ${KERNEL_DEVICETREE}; do |
| 75 | dtb=`normalize_dtb "$dtbf"` |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 76 | oe_runmake $dtb CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" OBJCOPY="${KERNEL_OBJCOPY}" ${KERNEL_EXTRA_ARGS} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 77 | done |
| 78 | } |
| 79 | |
| 80 | do_install:append() { |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 81 | install -d ${D}/${KERNEL_DTBDEST} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 82 | for dtbf in ${KERNEL_DEVICETREE}; do |
| 83 | dtb=`normalize_dtb "$dtbf"` |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 84 | dtb_path=`get_real_dtb_path_in_kernel "$dtb"` |
Patrick Williams | e760df8 | 2023-05-26 11:10:49 -0500 | [diff] [blame] | 85 | if "${@'false' if oe.types.boolean(d.getVar('KERNEL_DTBVENDORED')) else 'true'}"; then |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 86 | dtb_ext=${dtb##*.} |
| 87 | dtb_base_name=`basename $dtb .$dtb_ext` |
| 88 | dtb=$dtb_base_name.$dtb_ext |
| 89 | fi |
| 90 | install -Dm 0644 $dtb_path ${D}/${KERNEL_DTBDEST}/$dtb |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 91 | done |
| 92 | } |
| 93 | |
| 94 | do_deploy:append() { |
| 95 | for dtbf in ${KERNEL_DEVICETREE}; do |
| 96 | dtb=`normalize_dtb "$dtbf"` |
| 97 | dtb_ext=${dtb##*.} |
| 98 | dtb_base_name=`basename $dtb .$dtb_ext` |
| 99 | install -d $deployDir |
Patrick Williams | e760df8 | 2023-05-26 11:10:49 -0500 | [diff] [blame] | 100 | if "${@'false' if oe.types.boolean(d.getVar('KERNEL_DTBVENDORED')) else 'true'}"; then |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 101 | dtb=$dtb_base_name.$dtb_ext |
| 102 | fi |
| 103 | install -m 0644 ${D}/${KERNEL_DTBDEST}/$dtb $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 104 | if [ "${KERNEL_IMAGETYPE_SYMLINK}" = "1" ] ; then |
| 105 | ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name.$dtb_ext |
| 106 | fi |
| 107 | if [ -n "${KERNEL_DTB_LINK_NAME}" ] ; then |
| 108 | ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext |
| 109 | fi |
| 110 | for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do |
| 111 | if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then |
| 112 | cat ${D}/${KERNEL_IMAGEDEST}/$type \ |
| 113 | $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \ |
| 114 | > $deployDir/$type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} |
| 115 | if [ -n "${KERNEL_DTB_LINK_NAME}" ]; then |
| 116 | ln -sf $type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} \ |
| 117 | $deployDir/$type-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} |
| 118 | fi |
| 119 | if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then |
| 120 | cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \ |
| 121 | $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \ |
| 122 | > $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} |
| 123 | if [ -n "${KERNEL_DTB_LINK_NAME}" ]; then |
| 124 | ln -sf ${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} \ |
| 125 | $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} |
| 126 | fi |
| 127 | fi |
| 128 | fi |
| 129 | done |
| 130 | done |
| 131 | } |