commit: 58b118816d567fdffaaaf589c49f33268d12cae4 Author: Alexander Tsoy <alexander <AT> tsoy <DOT> me> AuthorDate: Wed Jun 19 07:50:43 2024 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Sun Jun 30 17:25:04 2024 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=58b11881
sys-kernel/linux-firmware: compress firmwares via copy-firmware.sh Currently we only skip compression for AMD microcode, but we should skip it for all files labeled as RawFile in WHENCE. copy-firmware.sh gained support for compressing firmware files at some point and it does it right. A notable consequence of this change is that saved config now contains file names with compression extension. Closes: https://bugs.gentoo.org/934537 Signed-off-by: Alexander Tsoy <alexander <AT> tsoy.me> Closes: https://github.com/gentoo/gentoo/pull/37213 Signed-off-by: Sam James <sam <AT> gentoo.org> ...99.ebuild => linux-firmware-20240610-r2.ebuild} | 112 ++++++++------------- .../linux-firmware/linux-firmware-99999999.ebuild | 44 +++----- 2 files changed, 55 insertions(+), 101 deletions(-) diff --git a/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild b/sys-kernel/linux-firmware/linux-firmware-20240610-r2.ebuild similarity index 85% copy from sys-kernel/linux-firmware/linux-firmware-99999999.ebuild copy to sys-kernel/linux-firmware/linux-firmware-20240610-r2.ebuild index cbf74c22e3a1..2b7db9344104 100644 --- a/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild +++ b/sys-kernel/linux-firmware/linux-firmware-20240610-r2.ebuild @@ -2,7 +2,7 @@ # Distributed under the terms of the GNU General Public License v2 EAPI=8 -inherit dist-kernel-utils linux-info mount-boot savedconfig multiprocessing +inherit dist-kernel-utils linux-info mount-boot savedconfig # In case this is a real snapshot, fill in commit below. # For normal, tagged releases, leave blank @@ -19,7 +19,7 @@ else SRC_URI="https://mirrors.edge.kernel.org/pub/linux/kernel/firmware/${P}.tar.xz" fi - KEYWORDS="~amd64" + KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86" fi DESCRIPTION="Linux firmware files" @@ -29,12 +29,13 @@ LICENSE="GPL-2 GPL-2+ GPL-3 BSD MIT || ( MPL-1.1 GPL-2 ) redistributable? ( linux-fw-redistributable BSD-2 BSD BSD-4 ISC MIT ) unknown-license? ( all-rights-reserved )" SLOT="0" -IUSE="compress-xz compress-zstd deduplicate dist-kernel +initramfs +redistributable savedconfig unknown-license" +IUSE="bindist compress-xz compress-zstd deduplicate dist-kernel +initramfs +redistributable savedconfig unknown-license" REQUIRED_USE="initramfs? ( redistributable ) ?? ( compress-xz compress-zstd ) savedconfig? ( !deduplicate )" RESTRICT="binchecks strip test + !bindist? ( bindist ) unknown-license? ( bindist )" BDEPEND="initramfs? ( app-alternatives/cpio ) @@ -65,6 +66,19 @@ IDEPEND=" " QA_PREBUILT="*" +PATCHES=( "${FILESDIR}"/${PN}-copy-firmware-r4.patch ) + +pkg_pretend() { + if use initramfs; then + if [[ -z ${ROOT} ]] && use dist-kernel; then + # Check, but don't die because we can fix the problem and then + # emerge --config ... to re-run installation. + nonfatal mount-boot_check_status + else + mount-boot_pkg_pretend + fi + fi +} pkg_setup() { if use compress-xz || use compress-zstd ; then @@ -83,18 +97,6 @@ pkg_setup() { linux-info_pkg_setup } -pkg_pretend() { - if use initramfs; then - if [[ -z ${ROOT} ]] && use dist-kernel; then - # Check, but don't die because we can fix the problem and then - # emerge --config ... to re-run installation. - nonfatal mount-boot_check_status - else - mount-boot_pkg_pretend - fi - fi -} - src_unpack() { if [[ ${PV} == 99999999* ]]; then git-r3_src_unpack @@ -120,7 +122,7 @@ src_prepare() { if use initramfs && ! use dist-kernel; then if [[ -d "${S}/amd-ucode" ]]; then - ."/${T}/make-amd-ucode-img" "${S}/amd-ucode" "${S}/amd-ucode.img" || die + "${T}/make-amd-ucode-img" "${S}" "${S}/amd-ucode" || die else # If this will ever happen something has changed which # must be reviewed @@ -131,8 +133,9 @@ src_prepare() { # whitelist of misc files local misc_files=( copy-firmware.sh + README.md WHENCE - README + LICEN[CS]E.* ) # whitelist of images with a free software license @@ -271,37 +274,34 @@ src_prepare() { } src_install() { - ./copy-firmware.sh $(usex deduplicate '' '--ignore-duplicates') -v "${ED}/lib/firmware" || die - pushd "${ED}/lib/firmware" &>/dev/null || die - - # especially use !redistributable will cause some broken symlinks - einfo "Removing broken symlinks ..." - find * -xtype l -print -delete || die + local FW_OPTIONS=( "-v" ) + local files_to_keep= if use savedconfig; then if [[ -s "${S}/${PN}.conf" ]]; then - local files_to_keep="${T}/files_to_keep.lst" + files_to_keep="${T}/files_to_keep.lst" grep -v '^#' "${S}/${PN}.conf" 2>/dev/null > "${files_to_keep}" || die [[ -s "${files_to_keep}" ]] || die "grep failed, empty config file?" - - einfo "Applying USE=savedconfig; Removing all files not listed in config ..." - find ! -type d -printf "%P\n" \ - | grep -Fvx -f "${files_to_keep}" \ - | xargs -d '\n' --no-run-if-empty rm -v - - if [[ ${PIPESTATUS[0]} -ne 0 ]]; then - die "Find failed to print installed files" - elif [[ ${PIPESTATUS[1]} -eq 2 ]]; then - # grep returns exit status 1 if no lines were selected - # which is the case when we want to keep all files - die "Grep failed to select files to keep" - elif [[ ${PIPESTATUS[2]} -ne 0 ]]; then - die "Failed to remove files not listed in config" - fi + FW_OPTIONS+=( "--firmware-list" "${files_to_keep}" ) fi fi + if use compress-xz; then + FW_OPTIONS+=( "--xz" ) + elif use compress-zstd; then + FW_OPTIONS+=( "--zstd" ) + fi + ! use deduplicate && FW_OPTIONS+=( "--ignore-duplicates" ) + FW_OPTIONS+=( "${ED}/lib/firmware" ) + ./copy-firmware.sh "${FW_OPTIONS[@]}" || die + + pushd "${ED}/lib/firmware" &>/dev/null || die + + # especially use !redistributable will cause some broken symlinks + einfo "Removing broken symlinks ..." + find * -xtype l -print -delete || die + # remove empty directories, bug #396073 find -type d -empty -delete || die @@ -317,36 +317,6 @@ src_install() { find * ! -type d >> "${S}"/${PN}.conf || die save_config "${S}"/${PN}.conf - if use compress-xz || use compress-zstd; then - einfo "Compressing firmware ..." - local target - local ext - local compressor - - if use compress-xz; then - ext=xz - compressor="xz -T1 -C crc32" - elif use compress-zstd; then - ext=zst - compressor="zstd -15 -T1 -C -q --rm" - fi - - # rename symlinks - while IFS= read -r -d '' f; do - # skip symlinks pointing to directories - [[ -d ${f} ]] && continue - - target=$(readlink "${f}") - [[ $? -eq 0 ]] || die - ln -sf "${target}".${ext} "${f}" || die - mv -T "${f}" "${f}".${ext} || die - done < <(find . -type l -print0) || die - - find . -type f ! -path "./amd-ucode/*" -print0 | \ - xargs -0 -P $(makeopts_jobs) -I'{}' ${compressor} '{}' || die - - fi - popd &>/dev/null || die # Instruct Dracut on whether or not we want the microcode in initramfs @@ -370,6 +340,10 @@ src_install() { insinto /boot doins "${S}"/amd-uc.img fi + + dodoc README.md + # some licenses require copyright and permission notice to be included + use bindist && dodoc WHENCE LICEN[CS]E.* } pkg_preinst() { diff --git a/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild b/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild index cbf74c22e3a1..144bba36cba3 100644 --- a/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild +++ b/sys-kernel/linux-firmware/linux-firmware-99999999.ebuild @@ -2,7 +2,7 @@ # Distributed under the terms of the GNU General Public License v2 EAPI=8 -inherit dist-kernel-utils linux-info mount-boot savedconfig multiprocessing +inherit dist-kernel-utils linux-info mount-boot savedconfig # In case this is a real snapshot, fill in commit below. # For normal, tagged releases, leave blank @@ -271,7 +271,17 @@ src_prepare() { } src_install() { - ./copy-firmware.sh $(usex deduplicate '' '--ignore-duplicates') -v "${ED}/lib/firmware" || die + + local FW_OPTIONS=( "-v" ) + + if use compress-xz; then + FW_OPTIONS+=( "--xz" ) + elif use compress-zstd; then + FW_OPTIONS+=( "--zstd" ) + fi + ! use deduplicate && FW_OPTIONS+=( "--ignore-duplicates" ) + FW_OPTIONS+=( "${ED}/lib/firmware" ) + ./copy-firmware.sh "${FW_OPTIONS[@]}" || die pushd "${ED}/lib/firmware" &>/dev/null || die @@ -317,36 +327,6 @@ src_install() { find * ! -type d >> "${S}"/${PN}.conf || die save_config "${S}"/${PN}.conf - if use compress-xz || use compress-zstd; then - einfo "Compressing firmware ..." - local target - local ext - local compressor - - if use compress-xz; then - ext=xz - compressor="xz -T1 -C crc32" - elif use compress-zstd; then - ext=zst - compressor="zstd -15 -T1 -C -q --rm" - fi - - # rename symlinks - while IFS= read -r -d '' f; do - # skip symlinks pointing to directories - [[ -d ${f} ]] && continue - - target=$(readlink "${f}") - [[ $? -eq 0 ]] || die - ln -sf "${target}".${ext} "${f}" || die - mv -T "${f}" "${f}".${ext} || die - done < <(find . -type l -print0) || die - - find . -type f ! -path "./amd-ucode/*" -print0 | \ - xargs -0 -P $(makeopts_jobs) -I'{}' ${compressor} '{}' || die - - fi - popd &>/dev/null || die # Instruct Dracut on whether or not we want the microcode in initramfs
