[中文]使用 QEMU 模擬 iPod Touch 1G 和 iPhoneOS 1.0(第二部分)
在我之前的博客文章中,我描述了如何使用QEMU模擬器啟動并運行iPod Touch 1G。在這篇后續(xù)文章中,我將概述在本地環(huán)境中啟動和運行模擬器的必要步驟。
注意:到目前為止,以下說明僅在MacOS上進行了測試。
建設(shè)QEMU
模擬器建立在 QEMU 之上,我們應(yīng)該首先構(gòu)建它。首先克隆我的 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 庫的編譯,該庫用于與模擬器交互(例如,捕獲鍵盤和鼠標(biāo)事件)。此外,我們僅配置和構(gòu)建 ARM 模擬器。我們還鏈接到OpenSSL,因為AES / SHA1引擎使用庫的一些加密函數(shù)。請記住更新 OpenSSL 庫的包含/庫路徑,以防它們位于其他位置。您可以通過傳遞帶有標(biāo)志的可用 CPU 內(nèi)核數(shù)量來加快命令速度,例如,用于使用六個 CPU 內(nèi)核進行編譯。編譯過程應(yīng)在目錄中生成二進制文件。make
-j
make -j6
qemu-system-arm
build/arm-softmmu
下載系統(tǒng)文件
我們需要幾個文件才能成功將iPod Touch模擬器啟動到主屏幕,為了方便起見,我將其發(fā)布為GitHub版本。您可以從此處下載所有這些文件,它們包括以下內(nèi)容:
S5L8900 bootrom 二進制文件,因為 iBoot 和內(nèi)核調(diào)用 bootrom 邏輯中的一些過程。
iBoot 引導(dǎo)加載程序二進制文件。此文件通常以加密格式包含在 IPSW 固件中,但為了方便起見,我提取了原始二進制文件并將其包含在 GitHub 存儲庫中。
包含引導(dǎo)加載程序使用的各種輔助文件的 NOR 映像。我將在本文后面提供一些有關(guān)手動生成此NOR圖像的說明。
包含根文件系統(tǒng)的 NAND 映像。我將在本文后面提供一些有關(guān)手動生成此 NAND 映像的說明。
下載所有必需的文件并將它們保存到方便的位置。您應(yīng)該解壓縮該文件,其中包含一個名為 的目錄。nand_n45ap.zip
nand
運行模擬器
現(xiàn)在,我們可以使用以下命令從目錄中運行模擬器: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>
請記住修復(fù)標(biāo)志,以便它們正確指向下載的系統(tǒng)文件。運行上述命令應(yīng)該會啟動模擬器,并且您應(yīng)該會在控制臺中看到一些日志記錄輸出:
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 映像進行更改,例如替換引導(dǎo)徽標(biāo)、修改設(shè)備樹或更改內(nèi)核引導(dǎo)參數(shù),您可以按照以下說明進行操作。我創(chuàng)建了一個單獨的工具工具來生成 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 文件的細節(jié)。例如,可以在此處修改內(nèi)核引導(dǎo)參數(shù)。該目錄包含將嵌入在 NOR 映像中的各種 IMG2 映像,包括設(shè)備樹和啟動徽標(biāo)。生成 NOR 映像可以通過運行二進制文件來完成:generate_nor.c
data
generate_nor
./generate_nor
這將生成一個文件。nor.bin
手動生成 NAND 映像
NAND映像是基于IPSW固件文件中包含的根文件系統(tǒng)生成的,盡管經(jīng)過大量修改以繞過各種檢查。必要的代碼可以在此存儲庫中找到并克隆,如下所示:
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
創(chuàng)建文件系統(tǒng)映像
作為起點,我將一個可寫的根文件系統(tǒng)上傳到GitHub。此DMG文件基于N45AP固件,并包含用于仿真目的的各種修改。在 Mac 上,您可以掛載此文件并對其進行更改。完成后,卸載文件并使用該工具將可寫 DMG 轉(zhuǎn)換為只讀 DMG(在 Mac 上可用):hdiutil
hdiutil convert -format UDRO -o filesystem-readonly.dmg ?filesystem-writable.dmg
然后,您應(yīng)該從DMG文件中提取文件系統(tǒng)分區(qū)。為此,我使用了該工具,可以從此處下載(構(gòu)建說明也可以在此存儲庫中找到)。您可以使用以下命令查看 DMG 文件包含哪些分區(qū):dmg2img
./dmg2img -l filesystem-readonly.dmg
輸出如下內(nèi)容:
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 格式提取分區(qū),即分區(qū) 3。使用以下命令提取此分區(qū):
./dmg2img -p 3 filesystem-readonly.dmg
這將生成一個 ,您應(yīng)該將其復(fù)制到包含二進制文件的目錄中。最后一步,按如下方式生成目錄:filesystem-readonly.img
generate_nand
nand
./generate_nand