Reference https://linux.do/t/topic/779944
该文章分为用Mac刷机和用Linux刷机两个部分 均使用libimobiledevice 属予作文以记之
我觉得idevicerestore应该换个思路,只刷recovery系统,剩下的交给Recovery去联网恢复,工作量又小又不容易出问题
低版本Mac给M4 Macbookair 刷机(DFU模式)
成功了
- 在用主机 MacbookPro 2013 MacOSX 10.15.7 Catalina (USB 2.0接口)
- 目标主机 MacbookAir M4 无系统(USB Type C接口)
- 使用iPad带的USB TypeC to C的线和一个TypeC转USB2.0的转接头,注意iPad带的这根线有正反面,插反了虽然能插进去,但是在电脑中看不到DFU设备
- 选择UniversalMac_15.3.2_24D2082_Restore.ipsw刷机 (为 保险起见参考了 这个issue 选择了旧版本)
软件准备
首先按 https://github.com/libimobiledevice/idevicerestore/tree/master?tab=readme-ov-file#macos 下载一键编译脚本,修改内容如下:
- 把
INSTALL_SUDO="sudo"注释掉 我们下文使用自定义安装路径不用sudo - 第一遍运行
PREFIX=/my-install-dir ./limd-build-macos.sh该脚本将自动下载源码等, 随后将会在编译libirecovery时失败,此时我们参考该issue https://github.com/libimobiledevice/libirecovery/issues/149 修改libirecovery/udev/Makefile.am中的-r改为-E - 第二遍运行
PREFIX=/my-install-dir NO_CLONE=false ./limd-build-macos.sh此时跳过git更新代码,将会重新执行我们修改后的Makefile 此后便可编译成功
开始刷机
在安装目录运行sudo ./idevicerestore -d -e /my/path/of/UniversalMac_15.3.2_24D2082_Restore.ipsw
(需要管理员权限)
随后便可静等进度条走完,目标主机启动成功。
Linux刷机
环境
Linux宿主机 RHEL 9.6
Linux虚拟机 RHEL 10.1 (Coughlan) Linux 6.12.0-124.20.1.el10_1.x86_64
虚拟机内Podman
警告
以下podman不成功,经分析应该是usbmuxd没有接收到目标mac重启信号,从而导致idevicerestore认为失败。
若只有Linux版本,推荐修改idevicerestore源码后自行编译,将等待usbmux报告callback的部分return 注释掉 改为getchar 手动确认状态。
如何确定目标主机已经加载成功 参考后文 使用lsusb确认。。
在RHEL宿主机 配置USB透传到Linux Guest
我的CPU可以直接透传整个USB root hub (独立的PCIE)先确定
先确定哪个USB RootHub是我们想要的, 得到输出如下$ lsusb -t /: Bus 001.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/2p, 480M |__ Port 001: Dev 006, If 0, Class=Application Specific Interface, Driver=[none], 1.5M $ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 006: ID 05ac:f014 Apple, Inc. Apple Device (Port DFU Mode) $ cat /sys/bus/usb/devices/usb1/*/idVendor 05ac(vendorID 0x05ac 是Apple)确定我们需要透传Bus 001 Device 001,然后检查该设备是否
查询该设备是否有独立的IOMMU Group
for g in /sys/kernel/iommu_groups/*; do
echo "IOMMU Group ${g##*/}:"
lspci -nns $(basename -a $g/devices/*)
done查询该设备对应的PCIE device 后使用virsh edit添加如下内容到<devices>下
下文以我的举例:我的宿主机USB RootHUB 所在的PCIE地址为 0000:44:00.3,映射到GUEST的0000:06:00.0上
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x44' slot='0x00' function='0x3'/>
</source>
<address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
</hostdev>- 在Linux Guest机
sudo podman load -i ./idevicerestore-docker.tar - 在Linux Guest机运行如下命令进入container
sudo podman run -it --privileged -v /dev/bus/usb:/dev/bus/usb -v /mnt/tfable/:/mnt/tfable/ --net=host idevicerestore-docker bash 在container内部运行
idevicerestore --latest
将显示如下内容:root@fable:/tmp# usbmuxd root@fable:/tmp# idevicerestore.sh --latest idevicerestore 1.0.0-268-g74e3bd9 (libirecovery 1.3.1, libtatsu 1.0.5-3-g60a39f3) Found device in Recovery mode ECID: XXXXXXXXX..... Identified device as j715ap, Mac16,13 Device Product Version: N/A Device Product Build: N/A The following firmwares are currently being signed for Mac16,13: [1] 26.2 (build 25C56) [2] 26.1 (build 25B78) [3] 26.0.1 (build 25A362) [4] 26.0 (build 25A354) [5] 15.6.1 (build 24G90) [6] 15.6 (build 24G84) [7] 15.5 (build 24F74) [8] 15.4.1 (build 24E263) [9] 15.4 (build 24E248) [10] 15.3.2 (build 24D2082) Select the firmware you want to restore:
表明正常检测到设备,继续运行以下命令以从文件恢复idevicerestore.sh -e /mnt/fabledata/UniversalMac_15.6.1_24G90_Restore.ipsw
注意使用.sh的脚本启动,其内部运行了usbmuxd,但在我这usbmuxd并没管用,不知为何。。
idevic在恢复过程的几个阶段
- 关机状态下 按Ctrl+Opt+RShift+Power 10秒后 只保留Power按钮继续按,等待大约8秒左右将进入DFU(电源灯为绿色呼吸灯)
lsusb: ID 05ac:f014 Apple, Inc. Apple Device (Port DFU Mode)- idevicerestore: Found device in DFU mode
- idevicerestore: Creating Ace3Binary, dfu_send_buffer_with_options
- 若此时没有等到usbmuxd反馈重连 则提示
Device did not disconnect. Port DFU failed.后退出, 但系统已经进入下一阶段 lsusb: ID 05ac:1881 Apple, Inc. Debug USB- idevicerestore: Found device in DFU mode
- idevicerestore: Sending iBSS
- 若此时没有等到usbmuxd反馈重连 则提示
Device did not disconnect. Possibly invalid iBSS. Reset device and try again. Unable to place device into recovery mode from DFU mode后退出, 但系统已经进入下一阶段 lsusb: ID 05ac:1281 Apple, Inc. Apple Mobile Device [Recovery Mode]- idevicerestore: Personalizing IMG4 component Ap,LocalPolicy...
lsusb: ID 05ac:1905 Apple Inc. Mac- idevicerestore: 执行若干命令包括Extracting XXX, Sending XXX now, Restoring image 在这个过程中目标主机屏幕亮起 显示白色苹果开机Logo 下方显示进度条
- 成功恢复 正常进入系统