Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup and improve rpm generation #536

Merged
merged 7 commits into from
May 19, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 44 additions & 49 deletions docs/tools/firmware.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -117,74 +117,69 @@ create_rpm () {
mkdir -p $HOME/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

# Extract firmware
python3 "$0" /usr/share/firmware $HOME/rpmbuild/firmware.tar
python3 "$0" /usr/share/firmware $HOME/rpmbuild/SOURCES/firmware.tar
cd $HOME/rpmbuild/BUILD
tar -xf $HOME/rpmbuild/firmware.tar ${verbose}
cd - >/dev/null
rm ${verbose} $HOME/rpmbuild/firmware.tar

if [[ (${identifier} = iMac19,1) || (${identifier} = iMac19,2) || (${identifier} = iMacPro1,1) ]]
then
nvramfile=$(ioreg -l | grep RequestedFiles | cut -d "/" -f 5 | rev | cut -c 4- | rev)
txcapblob=$(ioreg -l | grep RequestedFiles | cut -d "/" -f 3 | cut -d "\"" -f 1)
cp ${verbose} /usr/share/firmware/wifi/C-4364__s-B2/${nvramfile} "$HOME/rpmbuild/BUILD/brcmfmac4364b2-pcie.txt"
cp ${verbose} /usr/share/firmware/wifi/C-4364__s-B2/${txcapblob} "$HOME/rpmbuild/BUILD/brcmfmac4364b2-pcie.txcap_blob"
cp ${verbose} /usr/share/firmware/wifi/C-4364__s-B2/${nvramfile} brcmfmac4364b2-pcie.txt
cp ${verbose} /usr/share/firmware/wifi/C-4364__s-B2/${txcapblob} brcmfmac4364b2-pcie.txcap_blob
tar --append ${verbose} -f $HOME/rpmbuild/SOURCES/firmware.tar brcmfmac4364b2-pcie.txt
tar --append ${verbose} -f $HOME/rpmbuild/SOURCES/firmware.tar brcmfmac4364b2-pcie.txcap_blob
rm brcmfmac4364b2-pcie.txcap_blob brcmfmac4364b2-pcie.txt
fi

# Create the spec file
echo "Name: apple-firmware" > $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "Version: ${ver}" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "Release: 1" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "Summary: Wi-Fi and Bluetooth firmware for T2 Macs" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "License: Proprietary" >> $HOME/rpmbuild/SPECS/apple-firmware.spec

echo -e "\n%description" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "Wi-Fi and Bluetooth firmware for T2 Macs" >> $HOME/rpmbuild/SPECS/apple-firmware.spec

echo -e "\n%install" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "mkdir -p %{buildroot}/usr/lib/firmware/brcm" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "install -m 644 * %{buildroot}/usr/lib/firmware/brcm" >> $HOME/rpmbuild/SPECS/apple-firmware.spec

echo -e "\n%post" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "modprobe -r brcmfmac_wcc || true" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "modprobe -r brcmfmac || true" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "modprobe brcmfmac || true" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "modprobe -r hci_bcm4377 || true" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "modprobe hci_bcm4377 || true" >> $HOME/rpmbuild/SPECS/apple-firmware.spec

echo -e "\n%files" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "/usr/lib/firmware/brcm/*" >> $HOME/rpmbuild/SPECS/apple-firmware.spec

# Set OS to Linux
if [ -f "$HOME/.rpmrc" ]
then
echo -e "\nBacking up existing .rpmrc"
cp ${verbose} $HOME/.rpmrc $HOME/.rpmrc_orj
fi
echo "buildostranslate: Darwin: Linux" > $HOME/.rpmrc
cat <<- EOF > $HOME/rpmbuild/SPECS/apple-firmware.spec
Name: apple-firmware
Version: ${ver}
Release: 1
Summary: Wi-Fi and Bluetooth firmware for T2 Macs
License: Proprietary
BuildArch: noarch
AdityaGarg8 marked this conversation as resolved.
Show resolved Hide resolved

Source1: firmware.tar

%description
Wi-Fi and Bluetooth firmware for T2 Macs

%prep
tar -xf %{SOURCE1}

%build

%install
mkdir -p %{buildroot}/usr/lib/firmware/brcm
install -m 644 * %{buildroot}/usr/lib/firmware/brcm

%posttrans
modprobe -r brcmfmac_wcc || true
modprobe -r brcmfmac || true
modprobe brcmfmac || true
modprobe -r hci_bcm4377 || true
modprobe hci_bcm4377 || true

%files
/usr/lib/firmware/brcm/*
EOF

# Build
# For some reason bash doesn't like rpmbuild. Use zsh.
if [[ ${verbose} = -v ]]
then
/bin/zsh -c "rpmbuild -bb $HOME/rpmbuild/SPECS/apple-firmware.spec"
rpmbuild -bb --define '_target_os linux' $HOME/rpmbuild/SPECS/apple-firmware.spec
else
/bin/zsh -c "rpmbuild -bb $HOME/rpmbuild/SPECS/apple-firmware.spec >/dev/null 2&>/dev/null || echo \"Failed to make rpm package. Run the script with -v to get logs.\""
rpmbuild -bb --define '_target_os linux' $HOME/rpmbuild/SPECS/apple-firmware.spec >/dev/null 2>&1 || echo "Failed to make rpm package. Run the script with -v to get logs."
fi

# Copy and Cleanup
cp ${verbose} $HOME/rpmbuild/RPMS/x86_64/apple-firmware-${ver}-1.x86_64.rpm $HOME/Downloads
cp ${verbose} $HOME/rpmbuild/RPMS/noarch/apple-firmware-${ver}-1.noarch.rpm $HOME/Downloads
echo -e "\nCleaning up"
sudo rm -r ${verbose} $HOME/rpmbuild
sudo rm $HOME/.rpmrc
if [ -f $HOME/.rpmrc_orj ]
then
echo -e "\nRestoring backed up .rpmrc"
mv $HOME/.rpmrc_orj $HOME/.rpmrc
fi
rm -r ${verbose} $HOME/rpmbuild

echo -e "\nRpm package apple-firmware-${ver}-1.x86_64.rpm has been saved to Downloads!"
echo "Copy it to Linux and install using rpm."
echo -e "\nRpm package apple-firmware-${ver}-1.noarch.rpm has been saved to Downloads!"
echo "Copy it to Linux and install it with \`sudo dnf install --disablerepo=* /path/to/apple-firmware-${ver}-1.noarch.rpm\`"
sharpenedblade marked this conversation as resolved.
Show resolved Hide resolved
}

create_arch_pkg () {
Expand Down