[中文]使用 QEMU 模拟 iPod Touch 1G 和 iPhoneOS 1.0(第二部分)
在我之前的博客文章中,我描述了如何使用QEMU模拟器启动并运行iPod Touch 1G。在这篇后续文章中,我将概述在本地环境中启动和运行模拟器的必要步骤。
注意:到目前为止,以下说明仅在MacOS上进行了测试。
建设QEMU
模拟器建立在 QEMU 之上,我们应该首先构建它。首先克隆我的 QEMU 分支并签出到分支:ipod_touch_1g
git clone https://github.com/devos50/qemu
cd qemu
git checkout ipod_touch_1g
通过运行以下命令编译 QEMU:
mkdir build
cd build
../configure --enable-sdl --disable-cocoa --target-list=arm-softmmu --disable-capstone --disable-pie --disable-slirp --extra-cflags=-I/usr/local/opt/openssl@3/include --extra-ldflags='-L/usr/local/opt/openssl@3/lib -lcrypto'
make
请注意,我们显式启用 SDL 库的编译,该库用于与模拟器交互(例如,捕获键盘和鼠标事件)。此外,我们仅配置和构建 ARM 模拟器。我们还链接到OpenSSL,因为AES / SHA1引擎使用库的一些加密函数。请记住更新 OpenSSL 库的包含/库路径,以防它们位于其他位置。您可以通过传递带有标志的可用 CPU 内核数量来加快命令速度,例如,用于使用六个 CPU 内核进行编译。编译过程应在目录中生成二进制文件。make
-j
make -j6
qemu-system-arm
build/arm-softmmu
下载系统文件
我们需要几个文件才能成功将iPod Touch模拟器启动到主屏幕,为了方便起见,我将其发布为GitHub版本。您可以从此处下载所有这些文件,它们包括以下内容:
S5L8900 bootrom 二进制文件,因为 iBoot 和内核调用 bootrom 逻辑中的一些过程。
iBoot 引导加载程序二进制文件。此文件通常以加密格式包含在 IPSW 固件中,但为了方便起见,我提取了原始二进制文件并将其包含在 GitHub 存储库中。
包含引导加载程序使用的各种辅助文件的 NOR 映像。我将在本文后面提供一些有关手动生成此NOR图像的说明。
包含根文件系统的 NAND 映像。我将在本文后面提供一些有关手动生成此 NAND 映像的说明。
下载所有必需的文件并将它们保存到方便的位置。您应该解压缩该文件,其中包含一个名为 的目录。nand_n45ap.zip
nand
运行模拟器
现在,我们可以使用以下命令从目录中运行模拟器:build
./arm-softmmu/qemu-system-arm -M iPod-Touch,bootrom=<path to bootrom image>,iboot=<path to iboot image>,nand=<path to nand directory> -serial mon:stdio -cpu max -m 1G -d unimp -pflash <path to NOR image>
请记住修复标志,以便它们正确指向下载的系统文件。运行上述命令应该会启动模拟器,并且您应该会在控制台中看到一些日志记录输出:
martijndevos@iMac-van-Martijn build % ./arm-softmmu/qemu-system-arm -M iPod-Touch,bootrom=/Users/martijndevos/Documents/ipod_touch_emulation/bootrom_s5l8900,iboot=/Users/martijndevos/Documents/ipod_touch_emulation/iboot.bin,nand=/Users/martijndevos/Documents/generate_nand/nand -serial mon:stdio -cpu max -m 1G -d unimp -pflash /Users/martijndevos/Documents/generate_nor/nor.bin
WARNING: Image format was not specified for '/Users/martijndevos/Documents/generate_nor/nor.bin' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
Reading PMU register 118
Reading PMU register 75
Reading PMU register 87
Reading PMU register 103
iis_init()
spi_init()
Reading PMU register 75
power supply type batt
battery voltage Reading PMU register 87
error
SysCfg: version 0x00010001 with 4 entries using 200 of 8192 bytes
BDEV: protecting 0x2000-0x8000
image 0x1802bd20: bdev 0x1802b6a8 type dtre offset 0x10800 len 0x7d28
image 0x1802c170: bdev 0x1802b6a8 type batC offset 0x18d40 len 0x101e1
image 0x1802c5c0: bdev 0x1802b6a8 type logo offset 0x29a80 len 0x1c3a
image 0x1802ca10: bdev 0x1802b6a8 type nsrv offset 0x2bfc0 len 0x4695
image 0x1802ce60: bdev 0x1802b6a8 type batl offset 0x30d00 len 0xc829
image 0x1802d2b0: bdev 0x1802b6a8 type batL offset 0x3e240 len 0xe9d2
image 0x1802e888: bdev 0x1802b6a8 type recm offset 0x4d780 len 0xb594
display_init: displayEnabled: 0
otf clock divisor 5
fps set to: 59.977
SFN: 0x600, Addr: 0xfe00000, Size: 0x14001e0, hspan: 0x500, QLEN: 0x140
merlot_init() -- Universal code version 08-29-07
Merlot Panel ID (0x71c200):
Build: PVT1
Type: TMD
Project/Driver: M68/NSC-Merlot
ClcdInstallGammaTable: No Gamma table found for display_id: 0x0071c200
Reading PMU register 75
power supply type batt
battery voltage Reading PMU register 87
error
Reading PMU register 23
Reading PMU register 42
Reading PMU register 40
Reading PMU register 41
Reading PMU register 75
power supply type batt
battery voltage Reading PMU register 87
error
Reading PMU register 23
Reading PMU register 42
Reading PMU register 40
Reading PMU register 41
usb_menu_init()
vrom_late_init: unknown image crc: 0x66a3fbbf
=======================================
::
:: iBoot, Copyright 2007, Apple Inc.
::
:: BUILD_TAG: iBoot-204
::
:: BUILD_STYLE: RELEASE
::
=======================================
Reading PMU register 87
[FTL:MSG] Apple NAND Driver (AND) 0x43303032
...
如果运行上述命令时有任何问题,请通过评论这篇文章或在 GitHub 上提出问题来告诉我。
手动生成 NOR 映像
如果您希望对 NOR 映像进行更改,例如替换引导徽标、修改设备树或更改内核引导参数,您可以按照以下说明进行操作。我创建了一个单独的工具工具来生成 NOR 图像。您可以使用以下命令克隆和编译此工具:
git clone https://github.com/devos50/generate-ipod-touch-1g-nor
cd generate-ipod-touch-1g-nor
gcc generate_nor.c aes.c -o generate_nor -I/usr/local/Cellar/openssl@1.1/1.1.1l/include -L/usr/local/Cellar/openssl@1.1/1.1.1l/lib -lssl -lcrypto
请记住替换包含和库路径以指向您的 OpenSSL 安装。
您可以通过更改文件来修改生成的 NOR 文件的细节。例如,可以在此处修改内核引导参数。该目录包含将嵌入在 NOR 映像中的各种 IMG2 映像,包括设备树和启动徽标。生成 NOR 映像可以通过运行二进制文件来完成:generate_nor.c
data
generate_nor
./generate_nor
这将生成一个文件。nor.bin
手动生成 NAND 映像
NAND映像是基于IPSW固件文件中包含的根文件系统生成的,尽管经过大量修改以绕过各种检查。必要的代码可以在此存储库中找到并克隆,如下所示:
git clone https://github.com/devos50/generate-ipod-touch-1g-nand
cd generate-ipod-touch-1g-nand
gcc generate_nand.c -o generate_nand
这会在存储库的根目录中生成二进制文件。它需要文件,该文件可以使用以下说明生成。generate_nand
filesystem-readonly.img
创建文件系统映像
作为起点,我将一个可写的根文件系统上传到GitHub。此DMG文件基于N45AP固件,并包含用于仿真目的的各种修改。在 Mac 上,您可以挂载此文件并对其进行更改。完成后,卸载文件并使用该工具将可写 DMG 转换为只读 DMG(在 Mac 上可用):hdiutil
hdiutil convert -format UDRO -o filesystem-readonly.dmg filesystem-writable.dmg
然后,您应该从DMG文件中提取文件系统分区。为此,我使用了该工具,可以从此处下载(构建说明也可以在此存储库中找到)。您可以使用以下命令查看 DMG 文件包含哪些分区:dmg2img
./dmg2img -l filesystem-readonly.dmg
输出如下内容:
dmg2img v1.6.5 (c) vu1tur (to@vu1tur.eu.org)
filesystem-readonly.dmg --> (partition list)
partition 0: Driver Descriptor Map (DDM: 0)
partition 1: Apple (Apple_partition_map: 1)
partition 2: Macintosh (Apple_Driver_ATAPI: 2)
partition 3: Mac_OS_X (Apple_HFSX: 3)
partition 4: (Apple_Free: 4)
我们需要以 HFS 格式提取分区,即分区 3。使用以下命令提取此分区:
./dmg2img -p 3 filesystem-readonly.dmg
这将生成一个 ,您应该将其复制到包含二进制文件的目录中。最后一步,按如下方式生成目录:filesystem-readonly.img
generate_nand
nand
./generate_nand