Skip to content

Commit

Permalink
Rename firmware on macos & don't mess with mounts
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpenedblade committed Feb 15, 2024
1 parent 69bc2e8 commit dbc4725
Showing 1 changed file with 24 additions and 65 deletions.
89 changes: 24 additions & 65 deletions docs/tools/firmware.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ case "$os" in
EFILABEL=$(diskutil info disk0s1 | grep "Volume Name" | cut -d ":" -f 2 | xargs)
sudo diskutil mount disk0s1
echo "Getting Wi-Fi and Bluetooth firmware"
cd /usr/share/firmware
if [[ ${1-default} = -v ]]
then
tar czvf "/Volumes/${EFILABEL}/firmware.tar.gz" *
python3 $0 /usr/share/firmware "/Volumes/${EFILABEL}/firmware.tar"
gzip --best "/Volumes/${EFILABEL}/firmware.tar"
else
tar czf "/Volumes/${EFILABEL}/firmware.tar.gz" *
python3 $0 /usr/share/firmware "/Volumes/${EFILABEL}/firmware.tar" &> /dev/null
gzip --best "/Volumes/${EFILABEL}/firmware.tar"
fi
if [[ (${identifier} = iMac19,1) || (${identifier} = iMac19,2) || (${identifier} = iMacPro1,1) ]]
then
Expand All @@ -43,54 +44,29 @@ case "$os" in
cp /usr/share/firmware/wifi/C-4364__s-B2/${txcapblob} "/Volumes/${EFILABEL}/brcmfmac4364b2-pcie.txcap_blob"
fi
fi
echo "Copying this script to EFI"
cd - >/dev/null
cp "$0" "/Volumes/${EFILABEL}/firmware.sh"|| (echo -e "\nFailed to copy script.\nPlease copy the script manually to the EFI partition using Finder\nMake sure the name of the script is firmware.sh in the EFI partition\n" && echo && read -p "Press enter after you have copied" && echo)
echo "Copying this script to the ESP"
cp "$0" "/Volumes/${EFILABEL}/firmware.sh"|| (echo -e "\nFailed to copy script.\nPlease copy the script manually to the EFI partition using Finder\n" && echo && read -p "Press enter after you have copied" && echo)
echo "Unmounting the EFI partition"
sudo diskutil unmount disk0s1
sudo diskutil unmount "/Volumes/${EFILABEL}/"
echo
echo -e "Run the following commands or run this script itself in Linux now to set up Wi-Fi :-\n\nsudo umount /dev/nvme0n1p1\nsudo mkdir -p /tmp/apple-wifi-efi\nsudo mount /dev/nvme0n1p1 /tmp/apple-wifi-efi\nbash /tmp/apple-wifi-efi/firmware.sh\n"
echo -e "Run the following commands or run this script itself in Linux now to set up Wi-Fi:\n\n sudo mkdir -p /tmp/apple-wifi-efi\n sudo mount /dev/nvme0n1p1 /tmp/apple-wifi-efi\n /tmp/apple-wifi-efi/firmware.sh\n"
;;
(Linux)
echo "Detected Linux"
echo "Re-mounting the EFI partition"
mountpoint=$(mktemp -d)
echo "Installing Wi-Fi and Bluetooth firmware"
if [[ ${1-default} = -v ]]
then
sudo umount -v /dev/nvme0n1p1 || true
sudo mkdir -p -v /tmp/apple-wifi-efi || true
sudo mount -v /dev/nvme0n1p1 /tmp/apple-wifi-efi || true
sudo mount -v /dev/nvme0n1p1 $mountpoint
sudo tar --warning=no-unknown-keyword -xvC /lib/firmware -f $mountpoint/firmware.tar.gz
else
sudo umount /dev/nvme0n1p1 2>/dev/null || true
sudo mkdir -p /tmp/apple-wifi-efi 2>/dev/null || true
sudo mount /dev/nvme0n1p1 /tmp/apple-wifi-efi 2>/dev/null || true
sudo mount /dev/nvme0n1p1 $mountpoint
sudo tar --warning=no-unknown-keyword -xC /lib/firmware -f $mountpoint/firmware.tar.gz
fi
mountpoint=$(findmnt -n -o TARGET /dev/nvme0n1p1)
echo "Getting Wi-Fi and Bluetooth firmware"
sudo mkdir -p /tmp/apple-wifi-fw
cd /tmp/apple-wifi-fw
if [[ ${1-default} = -v ]]
then
sudo tar xvf $mountpoint/firmware.tar.gz
else
sudo tar xf $mountpoint/firmware.tar.gz 2>/dev/null
fi
echo "Setting up Wi-Fi and Bluetooth"
if [[ ${1-default} = -v ]]
then
sudo python3 $mountpoint/firmware.sh /tmp/apple-wifi-fw
else
sudo python3 $mountpoint/firmware.sh /tmp/apple-wifi-fw >/dev/null
fi
cd /lib/firmware
if [[ ${1-default} = -v ]]
then
sudo tar xvf /tmp/apple-wifi-fw/firmware.tar
else
sudo tar xf /tmp/apple-wifi-fw/firmware.tar
fi

echo "Installing extra firmware"
for file in "$mountpoint/brcmfmac4364b2-pcie.txt" \
"$mountpoint/brcmfmac4364b2-pcie.txcap_blob"
"$mountpoint/brcmfmac4364b2-pcie.txcap_blob"
do
if [ -f "$file" ]
then
Expand All @@ -102,30 +78,13 @@ case "$os" in
fi
fi
done
sudo modprobe -r brcmfmac || true
sudo modprobe brcmfmac || true
sudo modprobe -r hci_bcm4377 || true
sudo modprobe hci_bcm4377 || true
echo "Cleaning up"
sudo rm -r /tmp/apple-wifi-fw
echo "Keeping a copy of the firmware and the script in the EFI partition shall allow you to set up Wi-Fi again in the future by running this script or the commands told in the macOS step in Linux only, without the macOS step. Do you want to keep a copy? (y/N)"
read input
if [[ ($input != y) && ($input != Y) ]]
then
echo "Removing the copy from the EFI partition"
for file in "$mountpoint/brcmfmac4364b2-pcie.txt" \
"$mountpoint/brcmfmac4364b2-pcie.txcap_blob" \
"$mountpoint/firmware.tar.gz" \
"$mountpoint/firmware.sh"
do
if [ -f "$file" ]
then
sudo rm $file
fi
done
fi
echo "Running post-installation scripts"
exec sudo sh -c "umount /dev/nvme0n1p1 && mount -a && rmdir /tmp/apple-wifi-efi && echo Done!"
sudo umount $mountpoint; sudo rmdir $mountpoint
echo "Reloading Wi-Fi drivers"
sudo modprobe -r brcmfmac
sudo modprobe brcmfmac
sudo modprobe -r hci_bcm4377
sudo modprobe hci_bcm4377
echo "Done!"
;;
(*)
echo "Error: unsupported platform"
Expand Down Expand Up @@ -454,7 +413,7 @@ class FWPackage(object):
pkg = FWPackage("firmware.tar")
pkg = FWPackage(sys.argv[2])
col = WiFiFWCollection(sys.argv[1]+"/wifi")
pkg.add_files(sorted(col.files()))
col = BluetoothFWCollection(sys.argv[1]+"/bluetooth")
Expand Down

0 comments on commit dbc4725

Please sign in to comment.