summaryrefslogtreecommitdiffstats
path: root/helper/kernel.inc
diff options
context:
space:
mode:
Diffstat (limited to 'helper/kernel.inc')
-rw-r--r--helper/kernel.inc178
1 files changed, 0 insertions, 178 deletions
diff --git a/helper/kernel.inc b/helper/kernel.inc
deleted file mode 100644
index 61fa3efd..00000000
--- a/helper/kernel.inc
+++ /dev/null
@@ -1,178 +0,0 @@
-#
-# Common functions to copy kernel related files
-#
-############################################################
-#
-#
-# copies kernel modules as given in the module config file
-# * depends on 'depmod'
-# * requires REQUIRED_KERNEL_MODULES to be set.
-# (entries must be a relative path to /lib/modules/<KERNEL_CURRENT_VERSION>)
-#
-# ex: for /lib/modules/3.2.0/kernel/fs/nfs/nfs.ko
-# must be given as kernel/fs/nfs/nfs.ko
-#
-
-# this code depends on KERNEL_CURRENT_VERSION, this file needs to be sourced after helper/system.inc!
-# (TODO: maybe source system.inc if KERNEL_CURRENT_VERSION
-if [ -z "${KERNEL_CURRENT_VERSION}" ]; then
- . ${ROOT_DIR}/helper/system.inc
- [ -z "${KERNEL_CURRENT_VERSION}" ] && perror "KERNEL_CURRENT_VERSION still not set after sourcing, something is very wrong..."
-fi
-
-# set global KERNEL_TARGET_NAME
-KERNEL_TARGET_NAME="kernel"
-
-check_kernel_build_dir() {
- [ -d "${MODULES_DIR}/kernel/build" ] && KERNEL_BUILD_DIR="${MODULES_DIR}/kernel/build" \
- || perror "No build directory set for the kernel. Was is built?"
- # hack to get the real path of the installed modules
- KERNEL_NEW_VERSION=$(ls ${KERNEL_BUILD_DIR}/lib/modules)
-}
-
-copy_kernel_modules() {
- pinfo "Copying kernel modules for kernel ${KERNEL_CURRENT_VERSION}..."
- [ -z "${REQUIRED_KERNEL_MODULES}" ] && perror "REQUIRED_KERNEL_MODULES is empty. Check your config file."
- check_kernel_build_dir
- #
- # process modules list
- #
- # search for modules in KERNEL_BUILD_DIR
- cd "${KERNEL_BUILD_DIR}" || perror "Could not cd to ${KERNEL_BUILD_DIR}"
-
- local KERNEL_MODULES_DIR="lib/modules/${KERNEL_NEW_VERSION}"
- local KERNEL_MODULES_LIST=""
- local REQUIRED_KERNEL_MODULES_EXPANDED=""
- local KERNEL_MODULE=""
- local KERNEL_MODULE_PATH=""
- local ELEM=""
-
- # Do some fancy stuff to allow wildcards etc. in required kernel modules.
- cd "${KERNEL_MODULES_DIR}"
- for KERNEL_MODULE in ${REQUIRED_KERNEL_MODULES}; do
- for ELEM in $KERNEL_MODULE; do
- echo $ELEM | grep '\*' && pwarning "Could not expand '$ELEM'." && continue
- REQUIRED_KERNEL_MODULES_EXPANDED+=" $ELEM"
- done
- done
- cd -
- pinfo "Expanded the list of $(echo "$REQUIRED_KERNEL_MODULES" | wc -w) required kernel modules to $(echo "$REQUIRED_KERNEL_MODULES_EXPANDED" | wc -w)"
-
- for KERNEL_MODULE in ${REQUIRED_KERNEL_MODULES_EXPANDED}; do
- local KERNEL_MODULE_PATH="${KERNEL_MODULES_DIR}/${KERNEL_MODULE}"
- if grep "^${KERNEL_MODULE}$" "${KERNEL_BUILD_DIR}/${KERNEL_MODULES_DIR}/modules.builtin" >/dev/null; then
- pdebug "Already built-in ${KERNEL_MODULE}."
- elif [ -e "${KERNEL_MODULE_PATH}" ]; then
- pdebug "Copying '${KERNEL_MODULE_PATH}'"
- KERNEL_MODULES_LIST+=" ${KERNEL_MODULE_PATH}"
- else
- pwarning "Module ${KERNEL_MODULE} not found. Skipping. (might cause problems on certain clients!)"
- continue
- fi
-
- # check for dependencies
- local DEPS=$(grep "${KERNEL_MODULE}:" "${KERNEL_BUILD_DIR}/${KERNEL_MODULES_DIR}/modules.dep" | cut -d ":" -f2-)
- if [ ! -z "$DEPS" ]; then
- for DEP in $DEPS; do
- pdebug "Adding dep: ${KERNEL_MODULES_DIR}/$DEP"
- KERNEL_MODULES_LIST+=" ${KERNEL_MODULES_DIR}/$DEP"
- done
- else
- pdebug "${KERNEL_MODULE} has no dependencies."
- fi
- done
-
- if [ ! -z "${KERNEL_MODULES_LIST}" ]; then
- local COUNT=$(echo "${KERNEL_MODULES_LIST}" | wc -w)
- pinfo "Copying $COUNT modules to target directory."
- tarcopy "${KERNEL_MODULES_LIST}" "${TARGET_BUILD_DIR}"
- fi
-
- #
- # generate modules map files
- #
- # first strip modules.order of all the modules we don't use
- cat "${KERNEL_MODULES_DIR}/modules.order" | grep -E $(echo ${REQUIRED_KERNEL_MODULES} | tr '\ ' '|') \
- >> "${TARGET_BUILD_DIR}/${KERNEL_MODULES_DIR}/modules.order"
- # copy list of builtin kernel modules
- cp "${KERNEL_MODULES_DIR}/modules.builtin" "${TARGET_BUILD_DIR}/${KERNEL_MODULES_DIR}"
- # with modules.order and modules.builtin, we can run depmod for the rest of the files
- depmod -b "${TARGET_BUILD_DIR}" -a "${KERNEL_NEW_VERSION}"
-
- cd - >/dev/null
-}
-
-copy_firmware() {
-
- pinfo "Copying firmware for kernel ${KERNEL_CURRENT_VERSION}..."
- [ -z "${REQUIRED_FIRMWARE}" ] && perror "REQUIRED_FIRMWARE is empty. Check your config file."
- local OLD_DIR=$(pwd)
- check_kernel_build_dir
- #
- # process firmware list
- #
- cd "${KERNEL_BUILD_DIR}" || perror "Could not cd!"
- local FIRMWARE_DIR="lib/firmware"
- local FIRMWARE_LIST=""
- for FIRMWARE in ${REQUIRED_FIRMWARE}; do
- local FOUND=0
- # check for firmware in the build directory of the kernel
- for CANDIDATE in "${FIRMWARE_DIR}/${FIRMWARE}" "${FIRMWARE_DIR}/${KERNEL_NEW_VERSION}/${FIRMWARE}"; do
- if [ -e "${CANDIDATE}" ]; then
- pdebug "Copying from kernel build dir: '${CANDIDATE}'"
- FIRMWARE_LIST+=" ${CANDIDATE}"
- FOUND=1
- fi
- done
-
- # if we didn't found it in the kernel build directory, check for firmware in the system firmware directory
- if [ $FOUND -ne 1 ]; then
- for CANDIDATE in "/${FIRMWARE_DIR}/${FIRMWARE}" "/${FIRMWARE_DIR}/${KERNEL_CURRENT_VERSION}/${FIRMWARE}"; do
- if [ -e "${CANDIDATE}" ]; then
- if [ $(echo "${CANDIDATE}" | grep -c "${KERNEL_CURRENT_VERSION}") -eq 0 ]; then
- pdebug "Copying from system: '${CANDIDATE}'"
- FIRMWARE_LIST+=" ${CANDIDATE}"
- else
- pdebug "Copying from system: '${CANDIDATE}' to ${FIRMWARE_DIR}/${KERNEL_NEW_VERSION}/${FIRMWARE}"
- FIRMWARE_LIST+=" /${FIRMWARE_DIR}/${KERNEL_CURRENT_VERSION}/${FIRMWARE}"
- fi
- FOUND=1
- fi
- done
- fi
-
- [ $FOUND -ne 1 ] && pwarning "Neither '${FIRMWARE_DIR}/${FIRMWARE}' nor '${FIRMWARE_DIR}/${KERNEL_NEW_VERSION}/${FIRMWARE}' "\
- " was found on the system. Skipping. (might cause problems on certain clients!)"
- done
-
- if [ ! -z "${FIRMWARE_LIST}" ]; then
- local COUNT=$(echo "${FIRMWARE_LIST}" | wc -w)
- pinfo "Copying $COUNT firmware to target directory."
- tarcopy "${FIRMWARE_LIST}" "${TARGET_BUILD_DIR}"
- fi
-
- # post-process to fix the path of the firmwares found on the system unter /lib/firmware/$(uname -r)
- # which have to be copied to /lib/firmware/${KERNEL_NEW_VERSION}
- if [ -d "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_CURRENT_VERSION}" ]; then
- mkdir -p "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_NEW_VERSION}/"
- cd "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_CURRENT_VERSION}" || perror "old kernel but no old kernel"
- tarcopy "$(ls)" "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_NEW_VERSION}/"
- cd -
- rm -r "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_CURRENT_VERSION}" || perror "something went very wrong..."
- else
- pdebug "No ${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_CURRENT_VERSION} directory, skipping the merge."
- fi
-
- cd "$OLD_DIR"
-}
-
-copy_kernel() {
- check_kernel_build_dir
-
- local TOOL_STR="$TOOL_STR copy_kernel:"
- local KERNEL_DIR="${MODE_DIR}/builds/kernel"
- pinfo "Copying '${KERNEL_TARGET_NAME}' to '${KERNEL_DIR}'."
- [ -d "${KERNEL_DIR}" ] || mkdir -p "${KERNEL_DIR}"
- cp "${KERNEL_BUILD_DIR}/${KERNEL_TARGET_NAME}" "${KERNEL_DIR}" || perror "Could not copy kernel!"
- pinfo "You may want to update your systems firmware/modules to match the current kernel."
-}