%global debug_package %{nil}

%global _firmwarepath	/usr/lib/firmware
%define _binaries_in_noarch_packages_terminate_build 0

Name:		ti-linux-firmware
Version:	10.00.06
Release:	1%{?dist}
Summary:	Firmware files used by the Linux kernel for TI SoCs
License:	Redistributable, no modification permitted
URL:		https://git.ti.com/cgit/processor-firmware/ti-linux-firmware
BuildArch:	noarch

Requires:	linux-firmware-whence
Source0:	https://git.ti.com/cgit/processor-firmware/ti-linux-firmware/snapshot/ti-linux-firmware-%{version}.tar.xz

BuildRequires:	make
BuildRequires:	git-core
# Not required but de-dupes FW so reduces size
BuildRequires:	rdfind

Requires:	linux-firmware-whence
Provides:	ti-linux-firmware = %{version}
Obsoletes:	ti-linux-firmware < %{version}
Conflicts:	microcode_ctl < 2.1-0

%description
This package includes firmware files required for various component in
Texas Instruments SoCs to operate.

%prep
%autosetup -n ti-linux-firmware-%{version} -S git -p1

%build

%install
mkdir -p %{buildroot}/%{_firmwarepath}
mkdir -p %{buildroot}/%{_firmwarepath}/updates

%if 0%{?fedora} >= 34 || 0%{?rhel} >= 9
make DESTDIR=%{buildroot}/ FIRMWAREDIR=%{_firmwarepath} install-xz
%else
make DESTDIR=%{buildroot}/ FIRMWAREDIR=%{_firmwarepath} install
%endif

#Cleanup files we don't want to ship
pushd %{buildroot}/%{_firmwarepath}
# Remove firmware shipped in separate packages already
rm -rf	3com a300_p acenic adaptec advansys airoha amdgpu amd amdtee amd-ucode amlogic \
	amphion ar3k arm ath6k ath9k_htc ath10k ath11k ath12k atmel atusb \
	as102_data av7110 brcm bnx2 bnx2x cadence cavium cirrus cis cmmb cypress cxgb3 \
	cxgb4 dabusb dpaa2 dsp56k dvb e100 edgeport emi26 emi62 ene-ub6250 go7007 i915 \
	imx inside-secure intel isdbt iwlwifi keyspan nvidia \
	lgs8g75 libertas liquidio matrox meson mellanox mediatek microchip moxa mrvl \
	mt76 mwl8k mwlwifi netronome nxp ositech powervr qca qcom \
	qed qlogic r128 radeon rtl_bt rtl_nic rtlwifi rtw88 rtw89 rsi slicoss sms1xxx \
	sun sgx tehuti tdmb ti ti-img ti-connectivity tigon ttusb-budget ueagle-atm v4l-cx2 \
	vicam vxge wfx xe yam cpia2 isci ixp4xx kaweth keyspan_pda myricom rockchip sxg

rm -rf *.xz

rm -rf ess korg sb16 yamaha

# Remove firmware for Creative CA0132 HD as it's in alsa-firmware
rm -f ctefx.bin* ctspeq.bin*

# Remove source files we don't need to install
rm -rf carl9170fw
rm -rf cis/{src,Makefile}
rm -f atusb/ChangeLog
rm -f av7110/{Boot.S,Makefile}
rm -f dsp56k/{bootstrap.asm,concat-bootstrap.pl,Makefile}
rm -f iscis/{*.c,*.h,README,Makefile}
rm -f keyspan_pda/{keyspan_pda.S,xircom_pgs.S,Makefile}
rm -f usbdux/*dux */*.asm

# No need to install old firmware versions where we also provide newer versions
# which are preferred and support the same (or more) hardware
rm -f libertas/sd8686_v8*
rm -f libertas/usb8388_v5.bin*

# Remove superfluous infra files
rm -f check_whence.py configure Makefile README
popd

# Create file list but exclude firmwares that we place in subpackages
FILEDIR=`pwd`
pushd %{buildroot}/%{_firmwarepath}
find . \! -type d > $FILEDIR/ti-linux-firmware.files
find . -type d | sed -e '/^.$/d' > $FILEDIR/ti-linux-firmware.dirs
popd
sed -i -e 's:^./::' ti-linux-firmware.{files,dirs}
sed \
	-i -e '/^a300_p/d' \
	-i -e '/^amdgpu/d' \
	-i -e '/^amd/d' \
	-i -e '/^amdtee/d' \
	-i -e '/^amd-ucode/d' \
	-i -e '/^ar3k/d' \
	-i -e '/^ath6k/d' \
	-i -e '/^ath9k_htc/d' \
	-i -e '/^ath10k/d' \
	-i -e '/^ath11k/d' \
	-i -e '/^ath12k/d' \
	-i -e '/^as102_data/d' \
	-i -e '/^av7110/d' \
	-i -e '/^brcm/d' \
	-i -e '/^cirrus/d' \
	-i -e '/^cmmb/d' \
	-i -e '/^cnm/d' \
	-i -e '/^cypress/d' \
	-i -e '/^dvb/d' \
	-i -e '/^i915/d' \
	-i -e '/^intel\/avs/d' \
	-i -e '/^intel\/catpt/d' \
	-i -e '/^intel\/dsp_fw/d' \
	-i -e '/^intel\/fw_sst/d' \
	-i -e '/^intel\/ipu/d' \
	-i -e '/^intel\/ipu3/d' \
	-i -e '/^intel\/irci_irci/d' \
	-i -e '/^intel\/vsc/d' \
	-i -e '/^isdbt/d' \
	-i -e '/^iwlwifi/d' \
	-i -e '/^nvidia\/a/d' \
	-i -e '/^nvidia\/g/d' \
	-i -e '/^nvidia\/tu/d' \
	-i -e '/^lgs8g75/d' \
	-i -e '/^libertas/d' \
	-i -e '/^liquidio/d' \
	-i -e '/^mellanox/d' \
	-i -e '/^mediatek\/mt76/d' \
	-i -e '/^mediatek\/mt79/d' \
	-i -e '/^mediatek\/BT/d' \
	-i -e '/^mediatek\/WIFI/d' \
	-i -e '/^mrvl\/prestera/d' \
	-i -e '/^mrvl\/sd8787/d' \
	-i -e '/^mt76/d' \
	-i -e '/^netronome/d' \
	-i -e '/^nxp/d' \
	-i -e '/^qca/d' \
	-i -e '/^qcom/d' \
	-i -e '/^qed/d' \
	-i -e '/^radeon/d' \
	-i -e '/^rtl_bt/d' \
	-i -e '/^rtlwifi/d' \
	-i -e '/^rtw88/d' \
	-i -e '/^rtw89/d' \
	-i -e '/^sms1xxx/d' \
	-i -e '/^tdmb/d' \
	-i -e '/^ti-connectivity/d' \
	-i -e '/^v4l-cx2/d' \
	-i -e '/^ti-display-sharing/d' \
	-i -e '/^ti-dm/d' \
	-i -e '/^ti-eth/d' \
	-i -e '/^ti-evm/d' \
	-i -e '/^ti-ipc/d' \
	-i -e '/^ti-keystone/d' \
	-i -e '/^ti-pruss/d' \
	-i -e '/^ti-sysfw/d' \
	ti-linux-firmware.files
sed -i -e 's!^!/usr/lib/firmware/!' ti-linux-firmware.{files,dirs}
sed -i -e 's/^/"/;s/$/"/' ti-linux-firmware.files
sed -e 's/^/%%dir /' ti-linux-firmware.dirs >> ti-linux-firmware.files


%files -n ti-linux-firmware
%license LICENSE.ti LICENSE.ti-img LICENCE.cnm
%{_firmwarepath}/ti-display-sharing
%{_firmwarepath}/ti-dm
%{_firmwarepath}/ti-eth
%{_firmwarepath}/ti-evm
%{_firmwarepath}/ti-ipc
%{_firmwarepath}/ti-keystone
%{_firmwarepath}/ti-pruss
%{_firmwarepath}/ti-sysfw
%{_firmwarepath}/cnm

%changelog
* Tue Jul 23 2024 Enric Balletbo i Serra <eballetbo@redhat.com> - 10.00.06-1
- Update to upstream TI version 10.00.06
- Include Chips & Media wave521c firmware.

* Fri Jul 12 2024 Enric Balletbo i Serra <eballetbo@redhat.com> - 10.00.05-1
- Update to upstream TI version 10.00.05