diff options
author | Dmitry Baranov <reagentoo@gmail.com> | 2022-06-01 20:21:18 +0300 |
---|---|---|
committer | Sam James <sam@gentoo.org> | 2023-08-30 07:18:18 +0100 |
commit | 08b4f191c9fb064f8564d888e3969a02b0384a32 (patch) | |
tree | b267a76b8c6a1f8d2f0eaa622670297c2cc0d0ae /gen_initramfs.sh | |
parent | Changed firmware and modules requirements to warnings. (diff) | |
download | genkernel-08b4f191c9fb064f8564d888e3969a02b0384a32.tar.gz genkernel-08b4f191c9fb064f8564d888e3969a02b0384a32.tar.bz2 genkernel-08b4f191c9fb064f8564d888e3969a02b0384a32.zip |
firmware: copy only the necessary firmware(s) into initramfs
FIRMWARE=yes behavior is changed:
Only the minimum number of firmware files will be copied.
The list is generated using the `modinfo -F firmware [modules]...` command.
The ability to copy all firmware(s) is also available with a new
ALLFIRMWARE setting (see the modified genkernel.conf for more details).
As for changes in the source code:
gen_moddeps.sh: Significantly redesigned module list generation.
To get a list of modules, use the `mod_dep_list()` function instead
of `gen_dep_list()`. Modules that are not in the kernel (=n or invalid)
will be filtered out. Aliases will be replaced with real names
(including dependencies).
Signed-off-by: Dmitry Baranov <reagentoo@gmail.com>
Closes: https://github.com/gentoo/genkernel/pull/40
Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'gen_initramfs.sh')
-rwxr-xr-x | gen_initramfs.sh | 91 |
1 files changed, 58 insertions, 33 deletions
diff --git a/gen_initramfs.sh b/gen_initramfs.sh index ad61faa..2cfa0fd 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -1762,15 +1762,42 @@ append_firmware() { mkdir -p "${TDIR}"/lib/firmware || gen_die "Failed to create '${TDIR}/lib/firmware'!" - if [ ${#FIRMWARE_FILES[@]} -gt 0 ] + local -a fwlist=() + + if isTrue "${ALLFIRMWARE}" then - pushd "${FIRMWARE_DIR}" &>/dev/null || gen_die "Failed to chdir to '${FIRMWARE_DIR}'!" - cp -rL --parents --target-directory="${TDIR}/lib/firmware" "${FIRMWARE_FILES[@]}" 2>/dev/null \ - || gen_die "Failed to copy firmware files (${FIRMWARE_FILES}) to '${TDIR}/lib/firmware'!" - popd &>/dev/null || gen_die "Failed to chdir!" - else cp -a "${FIRMWARE_DIR}"/* "${TDIR}"/lib/firmware/ 2>/dev/null \ || gen_die "Failed to copy firmware files to '${TDIR}/lib/firmware'!" + elif [ ${#FIRMWARE_FILES[@]} -gt 0 ] + then + fwlist=( "${FIRMWARE_FILES[@]}" ) + else + local myfw= + while IFS= read -r -u 3 myfw + do + if [ -z "${myfw}" ] + then + gen_die "modinfo error!" + fi + + if [ ! -f "${FIRMWARE_DIR}/${myfw}" ] + then + print_warning 3 "$(get_indent 3) - ${myfw} is missing; Ignoring ..." + continue + fi + + fwlist+=( "${myfw}" ) + done 3< <( ( + modinfo -b "${KERNEL_MODULES_PREFIX%/}" -k "${KV}" -F firmware $(mod_dep_list) 2>/dev/null || echo + ) | sort | uniq ) + fi + + if [ ${#fwlist[@]} -gt 0 ] + then + pushd "${FIRMWARE_DIR}" &>/dev/null || gen_die "Failed to chdir to '${FIRMWARE_DIR}'!" + cp -rL --parents --target-directory="${TDIR}/lib/firmware" "${fwlist[@]}" 2>/dev/null \ + || gen_die "Failed to copy firmware files to '${TDIR}/lib/firmware'!" + popd &>/dev/null || gen_die "Failed to chdir!" fi cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!" @@ -1864,34 +1891,42 @@ append_modules() { gen_die "${error_message}" fi - determine_KEXT - cd "${modules_srcdir}" || gen_die "Failed to chdir to '${modules_srcdir}'!" - print_info 2 "$(get_indent 2)modules: >> Copying modules from '${modules_srcdir}' to initramfs ..." + print_info 2 "$(get_indent 2)modules: >> Searching modules in '${modules_srcdir}' ..." - local i= mymod= - local n_copied_modules=0 - for i in $(gen_dep_list) + local mymod= + local -a modlist=() + while IFS= read -r -u 3 mymod do - mymod=$(find . -name "${i}${KEXT}" 2>/dev/null | head -n 1) if [ -z "${mymod}" ] then - print_warning 3 "$(get_indent 3) - ${i}${KEXT} not found; Skipping ..." - continue; + gen_die "modinfo error!" fi - print_info 3 "$(get_indent 3) - Copying ${i}${KEXT} ..." - cp -ax --parents --target-directory "${modules_dstdir}" "${mymod}" 2>/dev/null \ - || gen_die "Failed to copy '${modules_srcdir}/${mymod}' to '${modules_dstdir}'!" - n_copied_modules=$[$n_copied_modules+1] - done + if [ "${mymod}" = '(builtin)' ] + then + continue + fi - if [ ${n_copied_modules} -eq 0 ] + if [ ! -f "${mymod}" ] + then + gen_die "Module '${i}${KEXT}' is missing!" + fi + + modlist+=( "${mymod/#${modules_srcdir}\//}" ) + done 3< <( ( + modinfo -b "${KERNEL_MODULES_PREFIX%/}" -k "${KV}" -F filename $(mod_dep_list) 2>/dev/null || echo + ) | sort | uniq ) + + if [ ${#modlist[@]} -gt 0 ] then - print_warning 1 "$(get_indent 2)modules: ${n_copied_modules} modules copied. Is that correct?" + print_info 2 "$(get_indent 2)modules: >> Copying modules from '${modules_srcdir}' to initramfs ..." + cp -ax --parents --target-directory "${modules_dstdir}" "${modlist[@]}" 2>/dev/null \ + || gen_die "Failed to copy modules!" + print_info 2 "$(get_indent 2)modules: ${#modlist[@]} modules copied!" else - print_info 2 "$(get_indent 2)modules: ${n_copied_modules} modules copied!" + print_warning 1 "$(get_indent 2)modules: 0 modules copied. Is that correct?" fi cp -ax --parents --target-directory "${modules_dstdir}" modules* 2>/dev/null \ @@ -2108,16 +2143,6 @@ append_data() { create_initramfs() { print_info 1 "initramfs: >> Initializing ..." - if ! isTrue "${BUILD_KERNEL}" - then - # Check early for suitable kmod - determine_KEXT - if ! isTrue "$(is_kext_supported_by_kmod "${KEXT}")" - then - gen_die "${KMOD_CMD} does not support chosen module compression algorithm. Please re-emerge sys-apps/kmod with USE=$(get_kext_kmod_use_flag "${KEXT}") enabled or adjust CONFIG_MODULE_COMPRESS_* kernel option!" - fi - fi - # Create empty cpio CPIO_ARCHIVE="${TMPDIR}/${GK_FILENAME_TEMP_INITRAMFS}" append_data 'devices' # WARNING, must be first! |