From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6950929522725224448 X-Received: by 2002:a05:6512:3618:: with SMTP id f24mr26242961lfs.34.1618389394272; Wed, 14 Apr 2021 01:36:34 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a19:48c6:: with SMTP id v189ls1439470lfa.0.gmail; Wed, 14 Apr 2021 01:36:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwg+dpMuDGr7a8pGXaDkYmqVJsJWXTVR6B305Ru+Tte9MdLXbzH5y977hBRRcSXCJTZkI9F X-Received: by 2002:ac2:44c8:: with SMTP id d8mr3532610lfm.67.1618389393257; Wed, 14 Apr 2021 01:36:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618389393; cv=none; d=google.com; s=arc-20160816; b=ALL1t4KPCfLE1lSxq0LN0evh9ICeoSq/Y2jq2S3eTg8PCRtykCjjlf0k7tV6gXVkkr y30s3WW6aFBLpJ0z3yPxcW+IBvhk2JvW0dJ2shS53l0lAClU8+acCVmLfjFcrR1yd96p ekQuDRmEG+RiIJbvqPbzuTEKQ4TNSf0WBi1K1NvRBv+Bs+xL+3O1Ic4CeL0W4WyKPnqA gWOJgmiBM+wIpu3cBtgUqoDAo+8/pPcalGGKJNToEuaYrmYJq6Pn6IE4AtO9WeYGc6vi T0yWi08ipi6IOrAtCLhw2pokf5tsXpoZUORHhlAHESaDmqAxYc6TsBZ1KLpBU8gl1Crr Vt8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=7wNcfZtHsYbHT6t6ub6NIFBV55FtUT6MVdNYheHCAEg=; b=iv8m/3iADWtQqfzUOj2IcOavSeuk0A/pJDKBuL102hkQfZ79ti4rHpbQ7hj0wl3J69 MggRELLLh53swbI1GPqCfkcwbRQAtQpJxaCyR1o6GMUQtt+CARcBq8kSr6njC6lxD6o7 BqqXNWHH3at49lsR/i04VjdpQ6T5OR5pXoX56u3/M3MPzrNANxE8xrPg9GqlMcuMQtoM JjyDozGtaoZmIh/Kew4knur0SuwauBzUfI6umddHJc24tIkjb3k9qC0Qmf3BzpLzbcRN tLjzaZezZihC744TvAySZY8n8NQGAcIaDUPPmN5Bm5vqof15kKGakm0D/heQ8zTLTPee TB/g== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of felix.moessbauer@siemens.com designates 194.138.37.40 as permitted sender) smtp.mailfrom=felix.moessbauer@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Return-Path: Received: from gecko.sbs.de (gecko.sbs.de. [194.138.37.40]) by gmr-mx.google.com with ESMTPS id a10si1040558lfs.11.2021.04.14.01.36.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Apr 2021 01:36:33 -0700 (PDT) Received-SPF: pass (google.com: domain of felix.moessbauer@siemens.com designates 194.138.37.40 as permitted sender) client-ip=194.138.37.40; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of felix.moessbauer@siemens.com designates 194.138.37.40 as permitted sender) smtp.mailfrom=felix.moessbauer@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from mail1.sbs.de (mail1.sbs.de [192.129.41.35]) by gecko.sbs.de (8.15.2/8.15.2) with ESMTPS id 13E8aWJM015525 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 14 Apr 2021 10:36:32 +0200 Received: from MD1T0KAC-VM.ad001.siemens.net (md1t0kac.ad001.siemens.net [139.25.0.7]) by mail1.sbs.de (8.15.2/8.15.2) with ESMTP id 13E8aPej023005; Wed, 14 Apr 2021 10:36:32 +0200 From: Felix Moessbauer To: isar-users@googlegroups.com Cc: henning.schild@siemens.com, jan.kiszka@siemens.com, Felix Moessbauer Subject: [PATCH 1/1] Add support to build binary version of DKMS kernel modules Date: Wed, 14 Apr 2021 10:36:17 +0200 Message-Id: <20210414083617.20940-2-felix.moessbauer@siemens.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210414083617.20940-1-felix.moessbauer@siemens.com> References: <20210414083617.20940-1-felix.moessbauer@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: gt6kEGPBO/62 This patch adds support to build and install a kernel module that is available via a debian DKMS package. As it is hard to directly build and install the package we create and distribute a meta package that is independent of the kernel version. In that package, we depend on the versioned prebuild kernel module package. To build the dkms module, we add two tasks and directly use dkms to build the debian package containing the binary module Then we just copy the binary-module debian package to the workdir, Signed-off-by: Felix Moessbauer --- .../example-dkms-module/igb-uio_20.11.bb | 14 ++++ meta/classes/dkms-module.bbclass | 68 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 meta-isar/recipes-kernel/example-dkms-module/igb-uio_20.11.bb create mode 100644 meta/classes/dkms-module.bbclass diff --git a/meta-isar/recipes-kernel/example-dkms-module/igb-uio_20.11.bb b/meta-isar/recipes-kernel/example-dkms-module/igb-uio_20.11.bb new file mode 100644 index 0000000..abb9922 --- /dev/null +++ b/meta-isar/recipes-kernel/example-dkms-module/igb-uio_20.11.bb @@ -0,0 +1,14 @@ +# Example recipe for building the binary version of a DKMS module +# +# This software is a part of ISAR. +# Copyright (c) Siemens AG, 2018 +# +# SPDX-License-Identifier: MIT + +inherit dkms-module + +PN .= "-${KERNEL_NAME}" + +#package name (without -dkms. E.g "dpdk-kmods" for package "dpdk-kmods-dkms") +DKMS_PACKAGE_NAME = "dpdk-kmods" +AUTOLOAD += "igb_uio" diff --git a/meta/classes/dkms-module.bbclass b/meta/classes/dkms-module.bbclass new file mode 100644 index 0000000..d1dbba9 --- /dev/null +++ b/meta/classes/dkms-module.bbclass @@ -0,0 +1,68 @@ +# This software is a part of ISAR. +# Copyright (C) 2021 Siemens AG +# +# SPDX-License-Identifier: MIT + +inherit dpkg-raw + +# Build and install a kernel module that is available via a debian DKMS package. +# As it is hard to directly build and install the package we create and distribute +# a meta package that is independent of the kernel version. +# In that package, we depend on the versioned prebuild kernel module package. +# +# To build the dkms module, we add two tasks and directly +# use dkms to build the debian package containing the binary module +# Then we just copy the binary-module debian package to the workdir, +# so ISAR's do_deploy_deb picks it up. + +#package name (without -dkms. E.g "dpdk-kmods" for package "dpdk-kmods-dkms") +DKMS_PACKAGE_NAME ?= "" +AUTOLOAD ?= "" + +DESCRIPTION ?= "Kernel module from DKMS package for ${PN}" +DEPENDS += "linux-headers-${KERNEL_NAME}" +DEBIAN_DEPENDS += "${DKMS_PACKAGE_NAME}-modules," +DEBIAN_BUILD_DEPENDS += "linux-headers-${KERNEL_NAME}, ${DKMS_PACKAGE_NAME}-dkms," + +# install configuration to auto-load the modules in ${AUTOLOAD} +do_install() { + # auto load the module + install -v -d ${D}/etc/modules-load.d + for module in "${AUTOLOAD}"; do + echo $module > ${D}/etc/modules-load.d/${PN}.conf + done +} + +# build the binary kernel module and package as debian package (versioned) +do_module_build() { + # we have to find out the module version, e.g. dpdk-kmods/0~20201113+git -k 5.10.0-3-rt-amd64/x86_64 + REVISION=$(find ${BUILDCHROOT_DIR}/usr/src/${DKMS_PACKAGE_NAME}-* -type d -exec basename {} + | sed 's/${DKMS_PACKAGE_NAME}-//g') + if ! dpkg -s --root=${BUILDCHROOT_DIR} linux-headers-${KERNEL_NAME} | grep "Depends:.*linux-headers"; then + # custom kernels directly place their files in linux-image-KERNEL-NAME, instead + # of using a meta package + a versioned package with the resources + # The prebuild DKMS binary package depends on the versioned kernel package, + # but that is not available on custom kernels. Hence, we just remove the dependency. + bbnote "Building ${DKMS_PACKAGE_NAME} for custom kernel ${KERNEL_NAME}" + cp ${BUILDCHROOT_DIR}/etc/dkms/template-dkms-mkbmdeb/debian/control ${WORKDIR}/control.dkms.orig + sudo sed -i 's/, linux-image-KERNEL_VERSION//' ${BUILDCHROOT_DIR}/etc/dkms/template-dkms-mkbmdeb/debian/control + fi + # build the module for all installed kernels (should be just one) + sudo -E chroot ${BUILDCHROOT_DIR} dkms mkbmdeb ${DKMS_PACKAGE_NAME}/${REVISION} --all + DKMS_PACKAGE_VERSIONED=$(find ${BUILDCHROOT_DIR}/var/lib/dkms/${DKMS_PACKAGE_NAME}/ -name "${DKMS_PACKAGE_NAME}-modules*.deb" -exec dpkg -I {} + | grep "Package:" | awk '{print $2}') + if [ -z "$DKMS_PACKAGE_VERSIONED" ]; then + bberror "No prebuild dkms module found" + exit 1 + fi + # restore dkms template (if any) + cp ${WORKDIR}/control.dkms.orig ${BUILDCHROOT_DIR}/etc/dkms/template-dkms-mkbmdeb/debian/control || true +} + +# simply copy our module from the build tree to the expected output location +# of this recipe. Then, do_deploy_dep finds it and adds it to the +# debian isar repo +do_module_deploy() { + cp ${BUILDCHROOT_DIR}/var/lib/dkms/${DKMS_PACKAGE_NAME}/*/bmdeb/*.deb ${S}/../ +} + +addtask module_build after do_install_builddeps before do_dpkg_build +addtask module_deploy after do_module_build before do_deploy_deb -- 2.20.1