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 () { |
| 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'` |
| 17 | fi |
| 18 | echo "${DTB}" |
| 19 | } |
| 20 | |
| 21 | get_real_dtb_path_in_kernel () { |
| 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}" |
| 26 | fi |
| 27 | echo "${DTB_PATH}" |
| 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() { |
| 53 | for DTB in ${KERNEL_DEVICETREE}; do |
| 54 | DTB=`normalize_dtb "${DTB}"` |
| 55 | oe_runmake ${DTB} |
| 56 | done |
| 57 | } |
| 58 | |
| 59 | do_install_append() { |
| 60 | for DTB in ${KERNEL_DEVICETREE}; do |
| 61 | DTB=`normalize_dtb "${DTB}"` |
| 62 | DTB_EXT=${DTB##*.} |
| 63 | DTB_PATH=`get_real_dtb_path_in_kernel "${DTB}"` |
| 64 | DTB_BASE_NAME=`basename ${DTB} ."${DTB_EXT}"` |
| 65 | install -m 0644 ${DTB_PATH} ${D}/${KERNEL_IMAGEDEST}/${DTB_BASE_NAME}.${DTB_EXT} |
| 66 | for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do |
| 67 | symlink_name=${type}"-"${KERNEL_IMAGE_SYMLINK_NAME} |
| 68 | DTB_SYMLINK_NAME=`echo ${symlink_name} | sed "s/${MACHINE}/${DTB_BASE_NAME}/g"` |
| 69 | ln -sf ${DTB_BASE_NAME}.${DTB_EXT} ${D}/${KERNEL_IMAGEDEST}/devicetree-${DTB_SYMLINK_NAME}.${DTB_EXT} |
| 70 | |
| 71 | if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then |
| 72 | cat ${D}/${KERNEL_IMAGEDEST}/$type \ |
| 73 | ${D}/${KERNEL_IMAGEDEST}/${DTB_BASE_NAME}.${DTB_EXT} \ |
| 74 | > ${D}/${KERNEL_IMAGEDEST}/$type-${DTB_BASE_NAME}.${DTB_EXT}.bin |
| 75 | fi |
| 76 | done |
| 77 | done |
| 78 | } |
| 79 | |
| 80 | do_deploy_append() { |
| 81 | for DTB in ${KERNEL_DEVICETREE}; do |
| 82 | DTB=`normalize_dtb "${DTB}"` |
| 83 | DTB_EXT=${DTB##*.} |
| 84 | DTB_BASE_NAME=`basename ${DTB} ."${DTB_EXT}"` |
| 85 | for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do |
| 86 | base_name=${type}"-"${KERNEL_IMAGE_BASE_NAME} |
| 87 | symlink_name=${type}"-"${KERNEL_IMAGE_SYMLINK_NAME} |
| 88 | DTB_NAME=`echo ${base_name} | sed "s/${MACHINE}/${DTB_BASE_NAME}/g"` |
| 89 | DTB_SYMLINK_NAME=`echo ${symlink_name} | sed "s/${MACHINE}/${DTB_BASE_NAME}/g"` |
| 90 | DTB_PATH=`get_real_dtb_path_in_kernel "${DTB}"` |
| 91 | install -d ${DEPLOYDIR} |
| 92 | install -m 0644 ${DTB_PATH} ${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT} |
| 93 | ln -sf ${DTB_NAME}.${DTB_EXT} ${DEPLOYDIR}/${DTB_SYMLINK_NAME}.${DTB_EXT} |
| 94 | ln -sf ${DTB_NAME}.${DTB_EXT} ${DEPLOYDIR}/${DTB_BASE_NAME}.${DTB_EXT} |
| 95 | |
| 96 | if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then |
| 97 | cat ${DEPLOYDIR}/$type \ |
| 98 | ${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT} \ |
| 99 | > ${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT}.bin |
| 100 | ln -sf ${DTB_NAME}.${DTB_EXT}.bin ${DEPLOYDIR}/$type-${DTB_BASE_NAME}.${DTB_EXT}.bin |
| 101 | |
| 102 | if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then |
| 103 | cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \ |
| 104 | ${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT} \ |
| 105 | > ${DEPLOYDIR}/${type}-${INITRAMFS_BASE_NAME}-${DTB_BASE_NAME}.${DTB_EXT}.bin |
| 106 | ln -sf ${type}-${INITRAMFS_BASE_NAME}-${DTB_BASE_NAME}.${DTB_EXT}.bin \ |
| 107 | ${DEPLOYDIR}/${type}-initramfs-${DTB_BASE_NAME}.${DTB_EXT}-${MACHINE}.bin |
| 108 | fi |
| 109 | fi |
| 110 | done |
| 111 | done |
| 112 | } |