%global _firmware_path /lib/firmware
%global _systemd_path /lib/systemd/system
%define url_version 2021.04.29-138a1

%global debug_package %{nil}

Name:           raspberrypi-eeprom
Version:        2021.04.29
Release:        1
Summary:        Raspberry Pi 4 boot EEPROM firmware
License:        BSD-3-Clause and custom
URL:            https://github.com/raspberrypi/rpi-eeprom
Source0:        https://github.com/raspberrypi/rpi-eeprom/archive/v%{url_version}/rpi-eeprom-%{version}.tar.gz
Source1:        rpi-eeprom-update.service

Patch0000:      python3_env.patch

AutoReq: no
AutoProv: yes

Provides:       rpi-eeprom
Requires:       raspberrypi-firmware libraspberrypi-bin python3 binutils pciutils
Provides:       rpi-eeprom-config = %{version}
Obsoletes:      rpi-eeprom-config < %{version}
ExclusiveArch: aarch64
ExclusiveOS: Linux

%description
Installation scripts and binaries for the closed sourced Raspberry Pi 4 EEPROMs.

%prep
%setup -q -n %{name}-%{version} -c
mv rpi-eeprom-%{url_version} %{name}-%{version}
cd %{name}-%{version}
%patch0000 -p1

%build

%install
mkdir -p %{buildroot}%{_systemd_path}
install -p -m 644 %{SOURCE1} %{buildroot}%{_systemd_path}/
cd %{name}-%{version}
mkdir -p %{buildroot}%{_bindir}
install -m 0755 rpi-eeprom-config %{buildroot}%{_bindir}
install -m 0755 rpi-eeprom-update %{buildroot}%{_bindir}
mkdir -p %{buildroot}/etc/default
install -m 644 rpi-eeprom-update-default %{buildroot}/etc/default/rpi-eeprom-update
mkdir -p %{buildroot}%{_firmware_path}/raspberrypi/bootloader
install -m 644 releases.md %{buildroot}%{_firmware_path}/raspberrypi/bootloader/
cp -a firmware/beta %{buildroot}%{_firmware_path}/raspberrypi/bootloader
cp -a firmware/critical %{buildroot}%{_firmware_path}/raspberrypi/bootloader
cp -a firmware/stable %{buildroot}%{_firmware_path}/raspberrypi/bootloader
cd %{buildroot}%{_firmware_path}/raspberrypi/bootloader
ln -s stable latest
ln -s critical default
cd -

%files
%license %{name}-%{version}/LICENSE
%{_bindir}/rpi-eeprom-config
%{_bindir}/rpi-eeprom-update
%config /etc/default/rpi-eeprom-update
%{_firmware_path}/raspberrypi
%{_systemd_path}/*.service

%changelog
* Sat Sep 25 2021 Yafen Fang <yafen@iscas.ac.cn> - 2021.04.29-1
- init package