diff options
author | Jonathan Bauer | 2014-03-24 13:43:42 +0100 |
---|---|---|
committer | Jonathan Bauer | 2014-03-24 13:43:42 +0100 |
commit | 901d911c9837a83b75b452e85c52f8c0c5ec0f06 (patch) | |
tree | fb26cff59fc214451bf7326d1f0f9650c720b45d /remote | |
parent | Merge branch 'master' of git://git.openslx.org/openslx-ng/tm-scripts (diff) | |
download | tm-scripts-901d911c9837a83b75b452e85c52f8c0c5ec0f06.tar.gz tm-scripts-901d911c9837a83b75b452e85c52f8c0c5ec0f06.tar.xz tm-scripts-901d911c9837a83b75b452e85c52f8c0c5ec0f06.zip |
[kernel.inc] major rework to support system kernel
changed how we determine the path of headers and kernel modules to support
the "kernel-system" module
Diffstat (limited to 'remote')
-rw-r--r-- | remote/includes/kernel.inc | 97 |
1 files changed, 64 insertions, 33 deletions
diff --git a/remote/includes/kernel.inc b/remote/includes/kernel.inc index 4eef36e5..e92eed3c 100644 --- a/remote/includes/kernel.inc +++ b/remote/includes/kernel.inc @@ -16,36 +16,54 @@ # set global KERNEL_TARGET_NAME KERNEL_TARGET_NAME="kernel" +# set global KERNEL_BASE_DIR as in the directory containing lib/modules and lib/firmware +# for system kernel, that is "/" and for an openslx kernel KERNEL_BUILD_DIR +KERNEL_BASE_DIR="" + get_kernel_version () { # determine kernel version currently running on this machine - KERNEL_CURRENT_VERSION=$(uname -r) + [ -z "$KERNEL_CURRENT_VERSION" ] && declare -rg KERNEL_CURRENT_VERSION="$(uname -r)" [ -z "$KERNEL_CURRENT_VERSION" ] && pwarning "Could not determine kernel version." - # determine kernel version that will be running in the generated system - if [ -e "$MODULES_DIR/kernel/ksrc/include/generated/utsrelease.h" ]; then - SYS_UTS_RELEASE=$(grep 'UTS_RELEASE' "$MODULES_DIR/kernel/ksrc/include/generated/utsrelease.h" | awk -F '"' '{print $2}') - SYS_KERNEL=$(echo "$SYS_UTS_RELEASE" | grep -o -E '^[0-9\.]+') - else - SYS_UTS_RELEASE="(unknown-not-compiled-yet)" - SYS_KERNEL="$SYS_UTS_RELEASE" - fi + pinfo "$KERNEL_CURRENT_VERSION" + # set empty SYS_UTS_RELEASE and SYS_KERNEL + SYS_UTS_RELEASE="(unknown)" + SYS_KERNEL="$(echo "$SYS_UTS_RELEASE" | grep -o -E '^[0-9\.]+')" } -check_kernel_build_dir() { +check_kernel_base_dir() { + + # check if KERNEL_BASE_DIR was set, if not we don't know + # whether kernel-openslx or kernel-system has been built + # and therefore not were to look for kernel modules, + # firmware and the kernel itself + + if [ -z "${KERNEL_BASE_DIR}" ]; then + # this is bad, abort + perror "KERNEL_BASE_DIR is not set. The kernel module did not run properly" + fi + # all good, keep going + + # old deprecated KERNEL_BUILD_DIR variable, here for compat reasons for now. TODO: delete [ -d "${MODULES_DIR}/kernel/build" ] && KERNEL_BUILD_DIR="${MODULES_DIR}/kernel/build" \ - || perror "No build directory set for the kernel. Was is built?" + || 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) + #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 + [ -z "${KERNEL_HEADERS_PATH}" ] && perror "KERNEL_HEADERS_PATH is empty. Kernel headers appears to be missing." + + + check_kernel_base_dir + # # process modules list # - # search for modules in KERNEL_BUILD_DIR - cd "${KERNEL_BUILD_DIR}" || perror "Could not cd to ${KERNEL_BUILD_DIR}" + # search for modules in KERNEL_BASE_DIR + cd "${KERNEL_BASE_DIR}" || perror "Could not cd to ${KERNEL_BASE_DIR}" local KERNEL_MODULES_DIR="lib/modules/${KERNEL_NEW_VERSION}" local KERNEL_MODULES_LIST="" @@ -62,12 +80,12 @@ copy_kernel_modules() { REQUIRED_KERNEL_MODULES_EXPANDED+=" $ELEM" done done - cd - + cd - 2>/dev/null 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 + if grep "^${KERNEL_MODULE}$" "${KERNEL_BASE_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}'" @@ -78,7 +96,7 @@ copy_kernel_modules() { fi # check for dependencies - local DEPS=$(grep "${KERNEL_MODULE}:" "${KERNEL_BUILD_DIR}/${KERNEL_MODULES_DIR}/modules.dep" | cut -d ":" -f2-) + local DEPS=$(grep "${KERNEL_MODULE}:" "${KERNEL_BASE_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" @@ -114,11 +132,13 @@ 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 + + check_kernel_base_dir + # # process firmware list # - cd "${KERNEL_BUILD_DIR}" || perror "Could not cd!" + cd "${KERNEL_BASE_DIR}" || perror "Could not cd to ${KERNEL_BASE_DIR}" local FIRMWARE_DIR="lib/firmware" local FIRMWARE_LIST="" for FIRMWARE in ${REQUIRED_FIRMWARE}; do @@ -126,14 +146,21 @@ copy_firmware() { # 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}'" + pdebug "Copying from kernel base dir ('$KERNEL_BASE_DIR'): '${CANDIDATE}'" FIRMWARE_LIST+=" ${CANDIDATE}" FOUND=1 fi done - + + # dont look under / if KERNEL_BASE_DIR is already / + if [ "x${KERNEL_BASE_DIR}" == "x/" ]; then + [ $FOUND -ne 1 ] && pwarning "Neither '${FIRMWARE_DIR}/${FIRMWARE}' nor '${FIRMWARE_DIR}/${KERNEL_NEW_VERSION}/${FIRMWARE}' found on the system" + continue + fi + # if we didn't found it in the kernel build directory, check for firmware in the system firmware directory if [ $FOUND -ne 1 ]; then + pwarning "Did not found '$FIRMWARE' in kernel base dir. Searching system..." 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 @@ -153,33 +180,37 @@ copy_firmware() { done if [ ! -z "${FIRMWARE_LIST}" ]; then + echo "$FIRMWARE_LIST" > /fwlist local COUNT=$(echo "${FIRMWARE_LIST}" | wc -w) pinfo "Copying $COUNT firmware to target directory." tarcopy "${FIRMWARE_LIST}" "${TARGET_BUILD_DIR}" fi + # only for kernel-openslx # 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." + if [ "x${KERNEL_BASE_DIR}" != "x/" ]; then + 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 fi - + cd "$OLD_DIR" } copy_kernel() { - check_kernel_build_dir + check_kernel_base_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!" + cp "${KERNEL_BASE_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." } |