diff options
author | Waldemar Brodkorb <wbx@openadk.org> | 2015-08-03 13:45:08 +0200 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2015-08-03 14:13:17 +0200 |
commit | c6a72670b54e13d3ab3a6056d7c4f4c503cf0d78 (patch) | |
tree | 51c776165e7abb4f1336a93edc519461786496fe /scripts | |
parent | 6debfdc194f5192706120783d133fbb99271eccc (diff) |
rework kernel module infrastructure
Instead of maintaining mk/modules.mk which defines compilations of
related kernel modules to pack together into a single package, follow an
automatic approach: For every kernel module found in the modules
installation directory, create a single package.
There are a few caveats to cover:
=== Module Loading Order ===
Upon bootup, module loading is ordered based on the number-prefixed
files in /etc/modules.d/. The correct number was previously managed in
mk/modules.mk on a per-collection basis. The new approach is to have
levels which modules are to be assigned to. Level 0 contains modules
with no dependencies at all. Level 1 contains modules which have only
level 0 dependencies, and so on. This information is determined at
compile-time by make-module-ipkgs.sh.
=== Module Installation to Target RootFS ===
Since module packages are created automatically from the modules the
script finds, ADK build system has no knowledge about the connection
between what the user has selected in menuconfig and the actual module
packages. Therefore the earlier approach to install selected packages
into rootfs does not hold anymore. Instead, use wildcards to find all
packages in firmware directory prefixed by 'kmod-' and install them all
(hopefully doing the right thing).
=== Kernel Version ===
KERNEL_VERSION now contains KERNEL_RELEASE already
By creating a localversion file, make KERNEL_RELEASE part of the
kernel's version number (so KERNEL_VERSION is correct in most
situations)
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/make-module-ipkgs.sh | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/scripts/make-module-ipkgs.sh b/scripts/make-module-ipkgs.sh new file mode 100644 index 000000000..3ab0dc787 --- /dev/null +++ b/scripts/make-module-ipkgs.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash +# +# make-module-ipkgs.sh - scan through modules directory and create a package +# for each of them automatically. +# +# Copyright (C) 2015 - Phil Sutter <phil@nwl.cc> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# +# Usage: +# $0 <ARCH> <KERNEL_VERSION> <LINUX_BUILD_DIR> <pkg-build-cmd> <PACKAGE_DIR> + +ARCH="$1" +VER="$2" +BUILD_DIR="$3" +PKG_BUILD="$4" +PACKAGE_DIR="$5" + +declare -A modpaths moddeps modlevels + +# recursively find a level for given module which is high enough so all +# dependencies are in a lower level +find_modlevel() { # (modname) + local level=0 + for dep in ${moddeps[$1]}; do + [[ -n "${modlevels[$dep]}" ]] || find_modlevel $dep + [[ ${modlevels[$dep]} -lt $level ]] || level=$((modlevels[$dep] + 1)) + done + modlevels[$1]=$level +} + +# sanitize modname, ipkg does not allow uppercase or underscores +pkgname() { # (modname) + tr 'A-Z_' 'a-z-' <<< "kmod-$1" +} + +for modpath in $(find ${BUILD_DIR}/modules -name \*.ko | xargs); do + modname="$(basename $modpath .ko)" + moddep="$(modinfo $modpath | awk '/^depends:/{print $2}' | sed 's/,/ /g')" + modpaths[$modname]="$modpath" + moddeps[$modname]="$moddep" +done + +#echo "modpaths:" +#for modname in ${!modpaths[@]}; do +# echo "$modname: ${modpaths[$modname]}" +#done +#echo +#echo "moddeps:" +#for modname in ${!moddeps[@]}; do +# echo "$modname: ${moddeps[$modname]}" +#done +#echo + +for modname in ${!modpaths[@]}; do + find_modlevel $modname + + ctrlfile=${BUILD_DIR}/kmod-control/kmod-${modname}.control + ipkgdir=${BUILD_DIR}/linux-modules/ipkg/$modname + + cat >$ctrlfile <<-EOF + Package: $(pkgname $modname) + Priority: optional + Section: sys + Description: kernel module $modname + EOF + sh $(dirname $0)/make-ipkg-dir.sh $ipkgdir $ctrlfile $VER $ARCH + + moddep="$(modinfo $modpath | awk '/^depends:/{print $2}' | sed 's/,/ /g')" + depline="kernel ($VER)" + for m in ${moddeps[$modname]}; do + depline+=", $(pkgname ${m})" + done + echo "Depends: $depline" >>${ipkgdir}/CONTROL/control + mkdir -p ${ipkgdir}/lib/modules/${VER} + cp ${modpaths[$modname]} ${ipkgdir}/lib/modules/${VER} + cat >${ipkgdir}/CONTROL/postinst <<EOF +#!/bin/sh +if [ -z \${IPKG_INSTROOT} ]; then + . /etc/functions.sh + load_modules /etc/modules.d/${modlevels[$modname]}-$modname +fi +EOF + chmod 0755 ${ipkgdir}/CONTROL/postinst + mkdir -p ${ipkgdir}/etc/modules.d + echo $modname >${ipkgdir}/etc/modules.d/${modlevels[$modname]}-$modname + env ${PKG_BUILD} ${ipkgdir} ${PACKAGE_DIR} || exit 1 +done |