kernel: Stop using update-alternatives
PATCH v6 1/3 kernel: Stop using update-alternatives
The update-alternatives where using relative links so not being really in use since December 2016 (see OE-Core:c7bc46b9 "kernel: Fix symlinks") so instead we now generate the relative symlinks during the do_install task and drop the update-alternatives use at all.
---
Changes in v6: None
Changes in v5: None
Changes in v4:
- Fix symlink on deploy directory
Changes in v3: None
Changes in v2: None
meta/classes/kernel.bbclass | 16 +++------------ meta/recipes-kernel/linux/linux-dtb.inc | 36 +++++---------------------------- 2 files changed, 8 insertions(+), 44 deletions(-)
meta/classes/kernel.bbclass +3 -13
@@ -2,7 +2,7 @@ inherit linux-kernel-base kernel-module-split PROVIDES += "virtual/kernel" DEPENDS += "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}gcc kmod-native bc-native lzop-native" -PACKAGE_WRITE_DEPS += "depmodwrapper-cross virtual/update-alternatives-native" +PACKAGE_WRITE_DEPS += "depmodwrapper-cross" do_deploy[depends] += "depmodwrapper-cross:do_populate_sysroot"
@@ -57,7 +57,7 @@ python __anonymous () { d.appendVar('PACKAGES', ' ' + 'kernel-image-' + typelower) - d.setVar('FILES_kernel-image-' + typelower, '/' + imagedest + '/' + type + '-${KERNEL_VERSION_NAME}') + d.setVar('FILES_kernel-image-' + typelower, '/' + imagedest + '/' + type + '-${KERNEL_VERSION_NAME}' + ' /' + imagedest + '/' + type) d.appendVar('RDEPENDS_kernel-image', ' ' + 'kernel-image-' + typelower)
@@ -65,13 +65,6 @@ python __anonymous () { d.setVar('ALLOW_EMPTY_kernel-image-' + typelower, '1') - priority = d.getVar('KERNEL_PRIORITY') - postinst = '#!/bin/sh\n' + 'update-alternatives --install /' + imagedest + '/' + type + ' ' + type + ' ' + type + '-${KERNEL_VERSION_NAME} ' + priority + ' || true' + '\n' - d.setVar('pkg_postinst_kernel-image-' + typelower, postinst) - - postrm = '#!/bin/sh\n' + 'update-alternatives --remove' + ' ' + type + ' ' + type + '-${KERNEL_VERSION_NAME} || true' + '\n' - d.setVar('pkg_postrm_kernel-image-' + typelower, postrm) - image = d.getVar('INITRAMFS_IMAGE') if image: d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
@@ -137,10 +130,6 @@ export CROSS_COMPILE = "${TARGET_PREFIX}" export KBUILD_BUILD_USER = "oe-user" export KBUILD_BUILD_HOST = "oe-host" -KERNEL_PRIORITY ?= "${@int(d.getVar('PV').split('-')[0].split('+')[0].split('.')[0]) * 10000 + \ - int(d.getVar('PV').split('-')[0].split('+')[0].split('.')[1]) * 100 + \ - int(d.getVar('PV').split('-')[0].split('+')[0].split('.')[-1])}" - KERNEL_RELEASE ?= "${KERNEL_VERSION}" # The directory where built kernel lies in the kernel tree
@@ -350,6 +339,7 @@ kernel_do_install() { install -d ${D}/boot for type in ${KERNEL_IMAGETYPES} ; do install -m 0644 ${KERNEL_OUTPUT_DIR}/${type} ${D}/${KERNEL_IMAGEDEST}/${type}-${KERNEL_VERSION} + ln -sf ${type}-${KERNEL_VERSION} ${D}/${KERNEL_IMAGEDEST}/${type} done install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION} install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION}
meta/recipes-kernel/linux/linux-dtb.inc +5 -31
@@ -1,7 +1,5 @@ # Support for device tree generation -FILES_kernel-devicetree = "/${KERNEL_IMAGEDEST}/devicetree*" - -PACKAGE_WRITE_DEPS += "virtual/update-alternatives-native" +FILES_kernel-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo" python __anonymous () { d.appendVar("PACKAGES", " kernel-devicetree")
@@ -36,12 +34,13 @@ do_install_append() { for DTB in ${KERNEL_DEVICETREE}; do DTB=`normalize_dtb "${DTB}"` DTB_EXT=${DTB##*.} + DTB_PATH=`get_real_dtb_path_in_kernel "${DTB}"` DTB_BASE_NAME=`basename ${DTB} ."${DTB_EXT}"` + install -m 0644 ${DTB_PATH} ${D}/${KERNEL_IMAGEDEST}/${DTB_BASE_NAME}.${DTB_EXT} for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do symlink_name=${type}"-"${KERNEL_IMAGE_SYMLINK_NAME} DTB_SYMLINK_NAME=`echo ${symlink_name} | sed "s/${MACHINE}/${DTB_BASE_NAME}/g"` - DTB_PATH=`get_real_dtb_path_in_kernel "${DTB}"` - install -m 0644 ${DTB_PATH} ${D}/${KERNEL_IMAGEDEST}/devicetree-${DTB_SYMLINK_NAME}.${DTB_EXT} + ln -sf ${DTB_BASE_NAME}.${DTB_EXT} ${D}/${KERNEL_IMAGEDEST}/devicetree-${DTB_SYMLINK_NAME}.${DTB_EXT} done done }
@@ -60,32 +59,7 @@ do_deploy_append() { install -d ${DEPLOYDIR} install -m 0644 ${DTB_PATH} ${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT} ln -sf ${DTB_NAME}.${DTB_EXT} ${DEPLOYDIR}/${DTB_SYMLINK_NAME}.${DTB_EXT} - done - done -} - -pkg_postinst_kernel-devicetree () { - cd /${KERNEL_IMAGEDEST} - for DTB in ${KERNEL_DEVICETREE}; do - for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do - symlink_name=${type}"-"${KERNEL_IMAGE_SYMLINK_NAME} - DTB_EXT=${DTB##*.} - DTB_BASE_NAME=`basename ${DTB} ."${DTB_EXT}"` - DTB_SYMLINK_NAME=`echo ${symlink_name} | sed "s/${MACHINE}/${DTB_BASE_NAME}/g"` - update-alternatives --install /${KERNEL_IMAGEDEST}/${DTB_BASE_NAME}.${DTB_EXT} ${DTB_BASE_NAME}.${DTB_EXT} devicetree-${DTB_SYMLINK_NAME}.${DTB_EXT} ${KERNEL_PRIORITY} || true - done - done -} - -pkg_postrm_kernel-devicetree () { - cd /${KERNEL_IMAGEDEST} - for DTB in ${KERNEL_DEVICETREE}; do - for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do - symlink_name=${type}"-"${KERNEL_IMAGE_SYMLINK_NAME} - DTB_EXT=${DTB##*.} - DTB_BASE_NAME=`basename ${DTB} ."${DTB_EXT}"` - DTB_SYMLINK_NAME=`echo ${symlink_name} | sed "s/${MACHINE}/${DTB_BASE_NAME}/g"` - update-alternatives --remove ${DTB_BASE_NAME}.${DTB_EXT} devicetree-${DTB_SYMLINK_NAME}.${DTB_EXT} ${KERNEL_PRIORITY} || true + ln -sf ${DTB_NAME}.${DTB_EXT} ${DEPLOYDIR}/${DTB_BASE_NAME}.${DTB_EXT} done done }
Signature · 1 line
2.14.1
PATCH v6 2/3 kernel: Move Device Tree support to kernel.bbclass
The Device Tree is commonly used but it is still kept as a .inc file instead of a proper class. Instead now we move the Device Tree code to a kernel-devicetree class and automatically enable it when the KERNEL_DEVICETREE variable is set.
While converting to the class, we reworked the compile and install in tasks as well as run the build of the Device Tree files in parallel, if possible.
To avoid breakage in existing layers, we kept a linux-dtb.inc file which raises a warning telling the user about the change so in next release this can be removed.
---
Changes in v6:
- Remove linux-dtb.inc from linux-yocto recipes
- Always inherit kernel-devicetree class
Changes in v5: None
Changes in v4:
- Rebase on top of 1/3
Changes in v3:
- rework compile and install to tasks
- improve commit log
Changes in v2:
- Wrong version as the changes were not staged. Sorry!
meta/classes/kernel-devicetree.bbclass | 68 +++++++++++++++++++++++++++++++ meta/classes/kernel.bbclass | 3 ++ meta/recipes-kernel/linux/linux-dtb.inc | 66 +----------------------------- meta/recipes-kernel/linux/linux-yocto.inc | 1 - 4 files changed, 73 insertions(+), 65 deletions(-) create mode 100644 meta/classes/kernel-devicetree.bbclass
meta/classes/kernel-devicetree.bbclass new file +68 -0
@@ -0,0 +1,68 @@ +# Support for device tree generation +PACKAGES_append = " kernel-devicetree" +FILES_kernel-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo" + +normalize_dtb () { + DTB="$1" + if echo ${DTB} | grep -q '/dts/'; then + bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used." + DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'` + fi + echo "${DTB}" +} + +get_real_dtb_path_in_kernel () { + DTB="$1" + DTB_PATH="${B}/arch/${ARCH}/boot/dts/${DTB}" + if [ ! -e "${DTB_PATH}" ]; then + DTB_PATH="${B}/arch/${ARCH}/boot/${DTB}" + fi + echo "${DTB_PATH}" +} + +do_compile_devicetree() { + DTBS="" + for dtb in ${KERNEL_DEVICETREE}; do + dtb=`normalize_dtb "${dtb}"` + DTBS="$DTBS $dtb" + done + oe_runmake -C ${B} ${PARALLEL_MAKE} ${DTBS} +} +addtask compile_devicetree after do_compile before do_install + +do_install_devicetree[dirs] = "${B}" +do_install_devicetree[umask] = "022" +fakeroot do_install_devicetree() { + for DTB in ${KERNEL_DEVICETREE}; do + DTB=`normalize_dtb "${DTB}"` + DTB_EXT=${DTB##*.} + DTB_PATH=`get_real_dtb_path_in_kernel "${DTB}"` + DTB_BASE_NAME=`basename ${DTB} ."${DTB_EXT}"` + install -m 0644 ${DTB_PATH} ${D}/${KERNEL_IMAGEDEST}/${DTB_BASE_NAME}.${DTB_EXT} + for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do + symlink_name=${type}"-"${KERNEL_IMAGE_SYMLINK_NAME} + DTB_SYMLINK_NAME=`echo ${symlink_name} | sed "s/${MACHINE}/${DTB_BASE_NAME}/g"` + ln -sf ${DTB_BASE_NAME}.${DTB_EXT} ${D}/${KERNEL_IMAGEDEST}/devicetree-${DTB_SYMLINK_NAME}.${DTB_EXT} + done + done +} +addtask install_devicetree after do_install before do_deploy + +do_deploy_append() { + for DTB in ${KERNEL_DEVICETREE}; do + DTB=`normalize_dtb "${DTB}"` + DTB_EXT=${DTB##*.} + DTB_BASE_NAME=`basename ${DTB} ."${DTB_EXT}"` + for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do + base_name=${type}"-"${KERNEL_IMAGE_BASE_NAME} + symlink_name=${type}"-"${KERNEL_IMAGE_SYMLINK_NAME} + DTB_NAME=`echo ${base_name} | sed "s/${MACHINE}/${DTB_BASE_NAME}/g"` + DTB_SYMLINK_NAME=`echo ${symlink_name} | sed "s/${MACHINE}/${DTB_BASE_NAME}/g"` + DTB_PATH=`get_real_dtb_path_in_kernel "${DTB}"` + install -d ${DEPLOYDIR} + install -m 0644 ${DTB_PATH} ${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT} + ln -sf ${DTB_NAME}.${DTB_EXT} ${DEPLOYDIR}/${DTB_SYMLINK_NAME}.${DTB_EXT} + ln -sf ${DTB_NAME}.${DTB_EXT} ${DEPLOYDIR}/${DTB_BASE_NAME}.${DTB_EXT} + done + done +}
meta/classes/kernel.bbclass +3 -0
@@ -662,3 +662,6 @@ do_deploy[prefuncs] += "package_get_auto_pr" addtask deploy after do_populate_sysroot do_packagedata EXPORT_FUNCTIONS do_deploy + +# Add using Device Tree support +inherit kernel-devicetree
meta/recipes-kernel/linux/linux-dtb.inc +2 -64
67 lines not on this page · raw message
meta/recipes-kernel/linux/linux-yocto.inc +0 -1
@@ -54,7 +54,6 @@ LINUX_VERSION_EXTENSION ?= "-yocto-${LINUX_KERNEL_TYPE}" # Pick up shared functions inherit kernel inherit kernel-yocto -require linux-dtb.inc B = "${WORKDIR}/linux-${PACKAGE_ARCH}-${LINUX_KERNEL_TYPE}-build"
Signature · 1 line
2.14.1
PATCH v6 3/3 kernel-devicetree.bbclass: Add support to generate append to kernel
In reply to Otavio SalvadorThe are use cases where the Device Tree appended to the kernel is convinient, so we generate the bundle concatenating the kernel (and potentionally the initramfs) and the Device Tree binaries.
To enable it, set KERNEL_DEVICETREE_BUNDLE variable to '1'
---
Changes in v6: None
Changes in v5:
- add support for initramfs bundle
Changes in v4:
- new patch
Changes in v3: None
Changes in v2: None
meta/classes/kernel-devicetree.bbclass | 49 +++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-)
meta/classes/kernel-devicetree.bbclass +48 -1
@@ -1,6 +1,13 @@ # Support for device tree generation -PACKAGES_append = " kernel-devicetree" +PACKAGES_append = " \ + kernel-devicetree \ + ${@['kernel-image-zimage-bundle', ''][d.getVar('KERNEL_DEVICETREE_BUNDLE') != '1']} \ +" FILES_kernel-devicetree = "/${KERNEL_IMAGEDEST}/*.dtb /${KERNEL_IMAGEDEST}/*.dtbo" +FILES_kernel-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bundle" + +# Generate kernel+devicetree bundle +KERNEL_DEVICETREE_BUNDLE ?= "0" normalize_dtb () { DTB="$1"
@@ -20,6 +27,24 @@ get_real_dtb_path_in_kernel () { echo "${DTB_PATH}" } + +do_configure_devicetree() { + if [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then + if echo ${KERNEL_IMAGETYPE_FOR_MAKE} | grep -q 'zImage'; then + config="${B}/.config" + if ! grep -q 'CONFIG_ARM_APPENDED_DTB=y' $config; then + bbwarn 'CONFIG_ARM_APPENDED_DTB is NOT enabled in the kernel. Enabling it to allow the kernel to boot with the Device Tree appended!' + sed -i "/CONFIG_ARM_APPENDED_DTB[ =]/d" $config + echo "CONFIG_ARM_APPENDED_DTB=y" >> $config + echo "# CONFIG_ARM_ATAG_DTB_COMPAT is not set" >> $config + fi + else + bberror 'The KERNEL_DEVICETREE_BUNDLE requires the KERNEL_IMAGETYPE to contain zImage.' + fi + fi +} +addtask configure_devicetree after do_configure before do_compile + do_compile_devicetree() { DTBS="" for dtb in ${KERNEL_DEVICETREE}; do
@@ -43,6 +68,12 @@ fakeroot do_install_devicetree() { symlink_name=${type}"-"${KERNEL_IMAGE_SYMLINK_NAME} DTB_SYMLINK_NAME=`echo ${symlink_name} | sed "s/${MACHINE}/${DTB_BASE_NAME}/g"` ln -sf ${DTB_BASE_NAME}.${DTB_EXT} ${D}/${KERNEL_IMAGEDEST}/devicetree-${DTB_SYMLINK_NAME}.${DTB_EXT} + + if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then + cat ${D}/${KERNEL_IMAGEDEST}/$type \ + ${D}/${KERNEL_IMAGEDEST}/${DTB_BASE_NAME}.${DTB_EXT} \ + > ${D}/${KERNEL_IMAGEDEST}/$type-${DTB_BASE_NAME}.${DTB_EXT}.bundle + fi done done }
@@ -63,6 +94,22 @@ do_deploy_append() { install -m 0644 ${DTB_PATH} ${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT} ln -sf ${DTB_NAME}.${DTB_EXT} ${DEPLOYDIR}/${DTB_SYMLINK_NAME}.${DTB_EXT} ln -sf ${DTB_NAME}.${DTB_EXT} ${DEPLOYDIR}/${DTB_BASE_NAME}.${DTB_EXT} + + if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then + cat ${DEPLOYDIR}/$type \ + ${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT} \ + > ${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT}.bundle + ln -sf ${DTB_NAME}.${DTB_EXT}.bundle ${DEPLOYDIR}/$type-${DTB_BASE_NAME}.${DTB_EXT}.bundle + + if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then + initramfs_base_name=${type}-${INITRAMFS_BASE_NAME}-${DTB_BASE_NAME}.${DTB_EXT} + initramfs_symlink_name=${type}-initramfs-${DTB_BASE_NAME}.${DTB_EXT}-${MACHINE} + cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \ + ${DEPLOYDIR}/${DTB_NAME}.${DTB_EXT} \ + > ${DEPLOYDIR}/${initramfs_base_name}.bin + ln -sf ${initramfs_base_name}.bin ${DEPLOYDIR}/${initramfs_symlink_name}.bin + fi + fi done done }
Signature · 1 line
2.14.1