Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-kernel/linux-firmware/
Date: Sat, 18 Mar 2023 14:58:26
Message-Id: 1679151433.624ae2809186f915f6cd343daf719ab382141e51.mpagano@gentoo
1 commit: 624ae2809186f915f6cd343daf719ab382141e51
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Sat Mar 18 14:57:13 2023 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Sat Mar 18 14:57:13 2023 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=624ae280
7
8 sys-kernel/linux-firmware: fix kernel config checking
9
10 Remove the ! linux_config_exists check because the function will
11 always fail when /proc/config.gz support is not enabled because
12 KV_OUT_DIR needed by linux_config_src_exists is not populated yet
13
14 die if USE=compress-zstd is set with an unsupported kernel
15 Thanks to xxc3nsoredxx
16
17 Closes: https://bugs.gentoo.org/899958
18 Closes: https://github.com/gentoo/gentoo/pull/30148
19
20 Author: xxc2ensoredxx
21 Signed-off-by: Mike Pagano <mpagano <AT> gentoo.org>
22
23 .../linux-firmware-20230310-r2.ebuild | 403 +++++++++++++++++++++
24 1 file changed, 403 insertions(+)
25
26 diff --git a/sys-kernel/linux-firmware/linux-firmware-20230310-r2.ebuild b/sys-kernel/linux-firmware/linux-firmware-20230310-r2.ebuild
27 new file mode 100644
28 index 000000000000..feed015c3e3e
29 --- /dev/null
30 +++ b/sys-kernel/linux-firmware/linux-firmware-20230310-r2.ebuild
31 @@ -0,0 +1,403 @@
32 +# Copyright 1999-2023 Gentoo Authors
33 +# Distributed under the terms of the GNU General Public License v2
34 +
35 +EAPI=7
36 +inherit linux-info mount-boot savedconfig multiprocessing
37 +
38 +# In case this is a real snapshot, fill in commit below.
39 +# For normal, tagged releases, leave blank
40 +MY_COMMIT=""
41 +
42 +if [[ ${PV} == 99999999* ]]; then
43 + inherit git-r3
44 + EGIT_REPO_URI="https://git.kernel.org/pub/scm/linux/kernel/git/firmware/${PN}.git"
45 +else
46 + if [[ -n "${MY_COMMIT}" ]]; then
47 + SRC_URI="https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/snapshot/${MY_COMMIT}.tar.gz -> ${P}.tar.gz"
48 + S="${WORKDIR}/${MY_COMMIT}"
49 + else
50 + SRC_URI="https://mirrors.edge.kernel.org/pub/linux/kernel/firmware/${P}.tar.xz"
51 + fi
52 +
53 + KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
54 +fi
55 +
56 +DESCRIPTION="Linux firmware files"
57 +HOMEPAGE="https://git.kernel.org/?p=linux/kernel/git/firmware/linux-firmware.git"
58 +
59 +LICENSE="GPL-2 GPL-2+ GPL-3 BSD MIT || ( MPL-1.1 GPL-2 )
60 + redistributable? ( linux-fw-redistributable BSD-2 BSD BSD-4 ISC MIT )
61 + unknown-license? ( all-rights-reserved )"
62 +SLOT="0"
63 +IUSE="compress-xz compress-zstd initramfs +redistributable savedconfig unknown-license"
64 +REQUIRED_USE="initramfs? ( redistributable )
65 + ?? ( compress-xz compress-zstd )"
66 +
67 +RESTRICT="binchecks strip test
68 + unknown-license? ( bindist )"
69 +
70 +BDEPEND="initramfs? ( app-arch/cpio )
71 + compress-xz? ( app-arch/xz-utils )
72 + compress-zstd? ( app-arch/zstd )"
73 +
74 +#add anything else that collides to this
75 +RDEPEND="!savedconfig? (
76 + redistributable? (
77 + !sys-firmware/alsa-firmware[alsa_cards_ca0132]
78 + !sys-block/qla-fc-firmware
79 + !sys-firmware/iwl1000-ucode
80 + !sys-firmware/iwl6005-ucode
81 + !sys-firmware/iwl6030-ucode
82 + !sys-firmware/iwl3160-ucode
83 + !sys-firmware/iwl7260-ucode
84 + !sys-firmware/iwl3160-7260-bt-ucode
85 + !sys-firmware/raspberrypi-wifi-ucode
86 + )
87 + unknown-license? (
88 + !sys-firmware/alsa-firmware[alsa_cards_korg1212]
89 + !sys-firmware/alsa-firmware[alsa_cards_maestro3]
90 + !sys-firmware/alsa-firmware[alsa_cards_sb16]
91 + !sys-firmware/alsa-firmware[alsa_cards_ymfpci]
92 + )
93 + )"
94 +
95 +QA_PREBUILT="*"
96 +
97 +pkg_setup() {
98 + if use compress-xz || use compress-zstd ; then
99 + local CONFIG_CHECK
100 +
101 + if kernel_is -ge 5 19; then
102 + use compress-xz && CONFIG_CHECK="~FW_LOADER_COMPRESS_XZ"
103 + use compress-zstd && CONFIG_CHECK="~FW_LOADER_COMPRESS_ZSTD"
104 + else
105 + use compress-xz && CONFIG_CHECK="~FW_LOADER_COMPRESS"
106 + if use compress-zstd; then
107 + eerror "Kernels <5.19 do not support ZSTD-compressed firmware files"
108 + fi
109 + fi
110 + linux-info_pkg_setup
111 + fi
112 +}
113 +
114 +pkg_pretend() {
115 + use initramfs && mount-boot_pkg_pretend
116 +}
117 +
118 +src_unpack() {
119 + if [[ ${PV} == 99999999* ]]; then
120 + git-r3_src_unpack
121 + else
122 + default
123 + # rename directory from git snapshot tarball
124 + if [[ ${#GIT_COMMIT} -gt 8 ]]; then
125 + mv ${PN}-*/ ${P} || die
126 + fi
127 + fi
128 +}
129 +
130 +src_prepare() {
131 + default
132 +
133 + find . -type f -not -perm 0644 -print0 \
134 + | xargs --null --no-run-if-empty chmod 0644 \
135 + || die
136 +
137 + chmod +x copy-firmware.sh || die
138 +
139 + if use initramfs; then
140 + if [[ -d "${S}/amd-ucode" ]]; then
141 + local UCODETMP="${T}/ucode_tmp"
142 + local UCODEDIR="${UCODETMP}/kernel/x86/microcode"
143 + mkdir -p "${UCODEDIR}" || die
144 + echo 1 > "${UCODETMP}/early_cpio"
145 +
146 + local amd_ucode_file="${UCODEDIR}/AuthenticAMD.bin"
147 + cat "${S}"/amd-ucode/*.bin > "${amd_ucode_file}" || die "Failed to concat amd cpu ucode"
148 +
149 + if [[ ! -s "${amd_ucode_file}" ]]; then
150 + die "Sanity check failed: '${amd_ucode_file}' is empty!"
151 + fi
152 +
153 + pushd "${UCODETMP}" &>/dev/null || die
154 + find . -print0 | cpio --quiet --null -o -H newc -R 0:0 > "${S}"/amd-uc.img
155 + popd &>/dev/null || die
156 + if [[ ! -s "${S}/amd-uc.img" ]]; then
157 + die "Failed to create '${S}/amd-uc.img'!"
158 + fi
159 + else
160 + # If this will ever happen something has changed which
161 + # must be reviewed
162 + die "'${S}/amd-ucode' not found!"
163 + fi
164 + fi
165 +
166 + # whitelist of misc files
167 + local misc_files=(
168 + copy-firmware.sh
169 + WHENCE
170 + README
171 + )
172 +
173 + # whitelist of images with a free software license
174 + local free_software=(
175 + # keyspan_pda (GPL-2+)
176 + keyspan_pda/keyspan_pda.fw
177 + keyspan_pda/xircom_pgs.fw
178 + # dsp56k (GPL-2+)
179 + dsp56k/bootstrap.bin
180 + # ath9k_htc (BSD GPL-2+ MIT)
181 + ath9k_htc/htc_7010-1.4.0.fw
182 + ath9k_htc/htc_9271-1.4.0.fw
183 + # pcnet_cs, 3c589_cs, 3c574_cs, serial_cs (dual GPL-2/MPL-1.1)
184 + cis/LA-PCM.cis
185 + cis/PCMLM28.cis
186 + cis/DP83903.cis
187 + cis/NE2K.cis
188 + cis/tamarack.cis
189 + cis/PE-200.cis
190 + cis/PE520.cis
191 + cis/3CXEM556.cis
192 + cis/3CCFEM556.cis
193 + cis/MT5634ZLX.cis
194 + cis/RS-COM-2P.cis
195 + cis/COMpad2.cis
196 + cis/COMpad4.cis
197 + # serial_cs (GPL-3)
198 + cis/SW_555_SER.cis
199 + cis/SW_7xx_SER.cis
200 + cis/SW_8xx_SER.cis
201 + # dvb-ttpci (GPL-2+)
202 + av7110/bootcode.bin
203 + # usbdux, usbduxfast, usbduxsigma (GPL-2+)
204 + usbdux_firmware.bin
205 + usbduxfast_firmware.bin
206 + usbduxsigma_firmware.bin
207 + # brcmfmac (GPL-2+)
208 + brcm/brcmfmac4330-sdio.Prowise-PT301.txt
209 + brcm/brcmfmac43340-sdio.meegopad-t08.txt
210 + brcm/brcmfmac43362-sdio.cubietech,cubietruck.txt
211 + brcm/brcmfmac43362-sdio.lemaker,bananapro.txt
212 + brcm/brcmfmac43430a0-sdio.jumper-ezpad-mini3.txt
213 + "brcm/brcmfmac43430a0-sdio.ONDA-V80 PLUS.txt"
214 + brcm/brcmfmac43430-sdio.AP6212.txt
215 + brcm/brcmfmac43430-sdio.Hampoo-D2D3_Vi8A1.txt
216 + brcm/brcmfmac43430-sdio.MUR1DX.txt
217 + brcm/brcmfmac43430-sdio.raspberrypi,3-model-b.txt
218 + brcm/brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
219 + brcm/brcmfmac4356-pcie.gpd-win-pocket.txt
220 + # isci (GPL-2)
221 + isci/isci_firmware.bin
222 + # carl9170 (GPL-2+)
223 + carl9170-1.fw
224 + # atusb (GPL-2+)
225 + atusb/atusb-0.2.dfu
226 + atusb/atusb-0.3.dfu
227 + atusb/rzusb-0.3.bin
228 + # mlxsw_spectrum (dual BSD/GPL-2)
229 + mellanox/mlxsw_spectrum-13.1420.122.mfa2
230 + mellanox/mlxsw_spectrum-13.1530.152.mfa2
231 + mellanox/mlxsw_spectrum-13.1620.192.mfa2
232 + mellanox/mlxsw_spectrum-13.1702.6.mfa2
233 + mellanox/mlxsw_spectrum-13.1703.4.mfa2
234 + mellanox/mlxsw_spectrum-13.1910.622.mfa2
235 + mellanox/mlxsw_spectrum-13.2000.1122.mfa2
236 + )
237 +
238 + # blacklist of images with unknown license
239 + local unknown_license=(
240 + korg/k1212.dsp
241 + ess/maestro3_assp_kernel.fw
242 + ess/maestro3_assp_minisrc.fw
243 + yamaha/ds1_ctrl.fw
244 + yamaha/ds1_dsp.fw
245 + yamaha/ds1e_ctrl.fw
246 + ttusb-budget/dspbootcode.bin
247 + emi62/bitstream.fw
248 + emi62/loader.fw
249 + emi62/midi.fw
250 + emi62/spdif.fw
251 + ti_3410.fw
252 + ti_5052.fw
253 + mts_mt9234mu.fw
254 + mts_mt9234zba.fw
255 + whiteheat.fw
256 + whiteheat_loader.fw
257 + cpia2/stv0672_vp4.bin
258 + vicam/firmware.fw
259 + edgeport/boot.fw
260 + edgeport/boot2.fw
261 + edgeport/down.fw
262 + edgeport/down2.fw
263 + edgeport/down3.bin
264 + sb16/mulaw_main.csp
265 + sb16/alaw_main.csp
266 + sb16/ima_adpcm_init.csp
267 + sb16/ima_adpcm_playback.csp
268 + sb16/ima_adpcm_capture.csp
269 + sun/cassini.bin
270 + acenic/tg1.bin
271 + acenic/tg2.bin
272 + adaptec/starfire_rx.bin
273 + adaptec/starfire_tx.bin
274 + yam/1200.bin
275 + yam/9600.bin
276 + ositech/Xilinx7OD.bin
277 + qlogic/isp1000.bin
278 + myricom/lanai.bin
279 + yamaha/yss225_registers.bin
280 + lgs8g75.fw
281 + )
282 +
283 + if use !unknown-license; then
284 + einfo "Removing files with unknown license ..."
285 + rm -v "${unknown_license[@]}" || die
286 + fi
287 +
288 + if use !redistributable; then
289 + # remove files _not_ in the free_software or unknown_license lists
290 + # everything else is confirmed (or assumed) to be redistributable
291 + # based on upstream acceptance policy
292 + einfo "Removing non-redistributable files ..."
293 + local OLDIFS="${IFS}"
294 + local IFS=$'\n'
295 + set -o pipefail
296 + find ! -type d -printf "%P\n" \
297 + | grep -Fvx -e "${misc_files[*]}" -e "${free_software[*]}" -e "${unknown_license[*]}" \
298 + | xargs -d '\n' --no-run-if-empty rm -v
299 +
300 + [[ ${?} -ne 0 ]] && die "Failed to remove non-redistributable files"
301 +
302 + IFS="${OLDIFS}"
303 + fi
304 +
305 + restore_config ${PN}.conf
306 +}
307 +
308 +src_install() {
309 + ./copy-firmware.sh -v "${ED}/lib/firmware" || die
310 +
311 + pushd "${ED}/lib/firmware" &>/dev/null || die
312 +
313 + # especially use !redistributable will cause some broken symlinks
314 + einfo "Removing broken symlinks ..."
315 + find * -xtype l -print -delete || die
316 +
317 + if use savedconfig; then
318 + if [[ -s "${S}/${PN}.conf" ]]; then
319 + local files_to_keep="${T}/files_to_keep.lst"
320 + grep -v '^#' "${S}/${PN}.conf" 2>/dev/null > "${files_to_keep}" || die
321 + [[ -s "${files_to_keep}" ]] || die "grep failed, empty config file?"
322 +
323 + einfo "Applying USE=savedconfig; Removing all files not listed in config ..."
324 + find ! -type d -printf "%P\n" \
325 + | grep -Fvx -f "${files_to_keep}" \
326 + | xargs -d '\n' --no-run-if-empty rm -v
327 +
328 + if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
329 + die "Find failed to print installed files"
330 + elif [[ ${PIPESTATUS[1]} -eq 2 ]]; then
331 + # grep returns exit status 1 if no lines were selected
332 + # which is the case when we want to keep all files
333 + die "Grep failed to select files to keep"
334 + elif [[ ${PIPESTATUS[2]} -ne 0 ]]; then
335 + die "Failed to remove files not listed in config"
336 + fi
337 + fi
338 + fi
339 +
340 + # remove empty directories, bug #396073
341 + find -type d -empty -delete || die
342 +
343 + # sanity check
344 + if ! ( shopt -s failglob; : * ) 2>/dev/null; then
345 + eerror "No files to install. Check your USE flag settings"
346 + eerror "and the list of files in your saved configuration."
347 + die "Refusing to install an empty package"
348 + fi
349 +
350 + # create config file
351 + echo "# Remove files that shall not be installed from this list." > "${S}"/${PN}.conf || die
352 + find * ! -type d >> "${S}"/${PN}.conf || die
353 + save_config "${S}"/${PN}.conf
354 +
355 + if use compress-xz || use compress-zstd; then
356 + einfo "Compressing firmware ..."
357 + local target
358 + local ext
359 + local compressor
360 +
361 + if use compress-xz; then
362 + ext=xz
363 + compressor="xz -T1 -C crc32"
364 + elif use compress-zstd; then
365 + ext=zst
366 + compressor="zstd -15 -T1 -C -q --rm"
367 + fi
368 +
369 + # rename symlinks
370 + while IFS= read -r -d '' f; do
371 + # skip symlinks pointing to directories
372 + [[ -d ${f} ]] && continue
373 +
374 + target=$(readlink "${f}")
375 + [[ $? -eq 0 ]] || die
376 + ln -sf "${target}".${ext} "${f}" || die
377 + mv -T "${f}" "${f}".${ext} || die
378 + done < <(find . -type l -print0) || die
379 +
380 + find . -type f ! -path "./amd-ucode/*" -print0 | \
381 + xargs -0 -P $(makeopts_jobs) -I'{}' ${compressor} '{}' || die
382 +
383 + fi
384 +
385 + popd &>/dev/null || die
386 +
387 + if use initramfs ; then
388 + insinto /boot
389 + doins "${S}"/amd-uc.img
390 + fi
391 +}
392 +
393 +pkg_preinst() {
394 + if use savedconfig; then
395 + ewarn "USE=savedconfig is active. You must handle file collisions manually."
396 + fi
397 +
398 + # Fix 'symlink is blocked by a directory' Bug #871315
399 + if has_version "<${CATEGORY}/${PN}-20220913-r2" ; then
400 + rm -rf "${EROOT}"/lib/firmware/qcom/LENOVO/21BX
401 + fi
402 +
403 + # Make sure /boot is available if needed.
404 + use initramfs && mount-boot_pkg_preinst
405 +}
406 +
407 +pkg_postinst() {
408 + elog "If you are only interested in particular firmware files, edit the saved"
409 + elog "configfile and remove those that you do not want."
410 +
411 + local ver
412 + for ver in ${REPLACING_VERSIONS}; do
413 + if ver_test ${ver} -lt 20190514; then
414 + elog
415 + elog 'Starting with version 20190514, installation of many firmware'
416 + elog 'files is controlled by USE flags. Please review your USE flag'
417 + elog 'and package.license settings if you are missing some files.'
418 + break
419 + fi
420 + done
421 +
422 + # Don't forget to umount /boot if it was previously mounted by us.
423 + use initramfs && mount-boot_pkg_postinst
424 +}
425 +
426 +pkg_prerm() {
427 + # Make sure /boot is mounted so that we can remove /boot/amd-uc.img!
428 + use initramfs && mount-boot_pkg_prerm
429 +}
430 +
431 +pkg_postrm() {
432 + # Don't forget to umount /boot if it was previously mounted by us.
433 + use initramfs && mount-boot_pkg_postrm
434 +}