blob: 6901c4b40b34b43cdfaa91e1909ad963bea60f7c (
plain) (
tree)
|
|
#
# 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_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_VERSION, this file needs to be sourced after helper/system.inc!
# (TODO: maybe source system.inc if KERNEL_VERSION is empty.
if [ -z "${KERNEL_VERSION}" ]; then
. ${ROOT_DIR}/helper/system.inc
[ -z "${KERNEL_VERSION}" ] && perror "KERNEL_VERSION still not set after sourcing, something is very wrong..."
fi
# set global KERNEL_TARGET_NAME
KERNEL_TARGET_NAME="vmlinuz-${KERNEL_VERSION}-openslx"
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() {
[ -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() {
[ -z "${REQUIRED_FIRMWARE}" ] && perror "REQUIRED_FIRMWARE is empty. Check your config file."
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
for CANDIDATE in "${FIRMWARE_DIR}/${FIRMWARE}" "${FIRMWARE_DIR}/${KERNEL_NEW_VERSION}/${FIRMWARE}"; do
if [ -e "${CANDIDATE}" ]; then
pdebug "Copying '${CANDIDATE}'"
FIRMWARE_LIST+=" ${CANDIDATE}"
FOUND=1
fi
done
[ $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
cd - >/dev/null
}
copy_kernel() {
local TOOL_STR="$TOOL_STR copy_kernel:"
check_kernel_build_dir
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."
}
|