Proses boot iPhone. Bagian 1: Boot ROM

Halo rekan-rekan.





Saya merasa menarik untuk berbagi informasi tentang struktur internal teknologi Apple dengan komunitas, karena hanya ada sedikit artikel tentang topik ini. Saya memutuskan untuk mulai dengan iPhone. Oleh karena itu, saya menyarankan Anda, bersama saya, mencoba memahami cara kerja perangkat misterius ini.





Saya akan mencoba menargetkan model terbaru. Saya akan senang jika komentar Anda menunjukkan kesalahan dan membantu kita semua untuk lebih memahami cara kerja perangkat di sekitar kita.





pengantar

Saya tidak tahu apakah ini akan mengejutkan siapa pun atau tidak, tetapi meluncurkan iPhone tidak jauh berbeda dengan proses meluncurkan komputer yang kompatibel dengan IBM-PC dalam bentuk unit sistem di bawah tabel, yang sudah banyak dilakukan. telah ditulis. Mungkin inilah alasan mengapa hanya ada sedikit artikel tentang topik ini yang terkait dengan perangkat seluler.





Jika Anda melihat proses peluncuran iPhone, secara keseluruhan, maka itu adalah rantai transisi kepercayaan dari satu tahap unduhan ke tahap lain, yang disebut "Rantai kepercayaan" . Secara umum, ada 3 program independen yang terlibat dalam proses ini: Boot ROM , iBoot, dan kernel XNU (dalam urutan eksekusi). Pengalihan kendali dari satu pihak ke pihak lain terjadi setelah identitas orang yang kepadanya kendali harus dialihkan diverifikasi. Masing-masing memiliki tanda kriptografi Apple . Sebuah pertanyaan yang masuk akal muncul: bagaimana keaslian langkah pertama diverifikasi? Jawaban: tidak mungkin .





Yang pertama mengontrol Boot ROM. Ini adalah komponen sistem yang tidak dapat diubah, dijahit di pabrik dan tidak berubah lagi. Itu tidak dapat diperbarui (tidak seperti BIOS dan UEFI). Oleh karena itu, tidak ada gunanya memverifikasi keasliannya. Oleh karena itu, statusnya sesuai: "Akar kepercayaan perangkat keras" . Kunci publik Apple Root certificate authority (CA) tertanam di Boot ROM , yang digunakan untuk memverifikasi keaslian iBoot. Pada gilirannya, iBoot memverifikasi keaslian inti XNU dengan kuncinya. Rantai pemeriksaan ini memungkinkan Anda untuk menjalankan hanya perangkat lunak tepercaya.





Rantai kepercayaan
Rantai kepercayaan

  ,   Boot ROM.        ,   Jailbreak (  ). Boot ROM     .  ,   . 150 .  ,     .   Boot ROM  iBoot   . . (AES, ANC, USB), ( , ), (env, libc, image),   (  SoC, MMU, NAND). , . iBoot ,  ,  ..





.

























1. Boot ROM













BIOS, UEFI, coreboot





SRAM





2. iBoot













GNU GRUB, Windows Bootmgr, efibootmgr





SDRAM





3. XNU













Linux, NT kernel, GNU Hurd





SDRAM





4. iOS













Ubuntu, Windows, Android





SDRAM





  . (     ,   ,   ,     ).   (PMIC β€” Power Management Integrated Circuit).   PMIC  , , Lightning, ( ).     . .   ,       .





  PMIC   Power-On. :     ( ).  β€” .





, . ,   - .  ,     . ,     ,        .     , , .    PMIC Side-Button ,   , , :   (  ).    ,  PMIC   PMIC.   D-   .     CLR .   ,   RC-, .





Perkiraan pengoperasian tombol samping

  ,    CTLx -.   .    CLR ,   CLK ,   CTLx , PMIC   .





SoC CPU

     .     ,   ,  ,   ,   . -     .   (System on a Crystal β€” SoC)  Apple     β€” TSMC (Taiwan Semiconductor Manufacturing Corporation). Apple ,   ,   . ,   -   . ,   Apple.





SoC   . , , , , , -,  .   .   SoC .      . (Power-on reset / PoR generator).   : ,   . PoR   , .





Prosedur penyetelan ulang daya
Power-on reset

      ,   , RC-  .     ( ), PoR ,     .





  . , . PoR   - ( ).   (Program Counter/PC register)   . (Reset vector).   ,    0Γ—100000000



.       (    ,   ).      .





, ,   . ,   ,   (primary core),   .     .





    (Read only memory β€” ROM). SoC. ( )    ( ).   .   , Boot ROM.   .





Boot ROM

, Boot ROM β€” , SoC.       -.    Apple.   C  , - .     Boot ROM,     , -,   β€” _start



. ,   ,   arm64.   :





  1. (L2 cache) ( 2 MiB). 





  2. , . , .





  3. main



    ( C) LR. ret



    main



    .





  4. . , , .





  5. .





  6. , main



    .





Tata letak RAM untuk Boot ROM
Boot ROM

, ,   C.





main



CPU.

, , Exception Levels (EL): EL0, EL1, EL2, EL3.   .  β€” .    (    ).   . ,   , .

  CPU   .





  1. (Secure Configuration Register - SCR): (FIQ IRQ). 









  2. (System Control Register: SCTLR): , (Memory Management Unit - MMU, CPU), , ( Execute Never / XN β€” NX- x86 ), . 









  main



,   .





  :





  1. .





  2. (DVFS - Dynamic voltage and frequency scaling).





  3. , BootROM.





  4. BootROM.





  5. (PLL - Phase Lock loop).





  6. (SEP - Secure Enclave processor).





(sepOS),      .      .





(  -).   (Static Random Access Memory β€” SRAM).     ,   . (Dynamic Random Access Memory β€” DRAM).  , SRAM  ,   DRAM  .      .   ,     .   ,   . SRAM   ( , ),  DRAM   ( , ).  SoC GPIO (General Purpose Input/Output)   .   , , ,  DFU (Device Firmware Upgrade mode β€” ). ,   .





/ (BIOS), Boot ROM : ( )   (heap).    .   ,    Boot ROM.





: , SoC. iPhone :









  1.  













  2. GPIO





,   .  DFU .     ,  ,         DFU , ,   .





  ,     . DFU ,     USB,   - (  NAND ).





if (dfu_enabled) 
  boot_fallback_step = -1;

while (1) {
  if (!get_boot_device(&device, &options))
    break;

  process_boot(device, options);

  if (boot_fallback_step < 0)
    continue;

  boot_fallback_step++;
}

reset();
      
      



  , ( ). ,    USB. ,   «».





Apple  β€” IMG4 ( ).    DER ASN.1.





sequence [
   0: string "IMG4"
   1: payload   - IMG4 Payload, IM4P
   2: [0] (constructed) [
          manifest   - IMG4 Manifest, IM4M
      ]
]
      
      



sequence [
    0: string "IM4P"
    1: string type    - ibot, rdsk, sepi, ...
    2: string description    - 'iBoot-6723.102.4'
    3: octetstring    - the encrypted/raw data
    4: octetstring    - containing DER encoded KBAG values (optional)
        sequence [
            sequence [
                0: int: 01
                1: octetstring: iv
                2: octetstring: key
            ]
            sequence [
                0: int: 02
                1: octetstring: iv
                2: octetstring: key
            ]
        ]
]
      
      



(UtilDM β€” Utility Device Manager), ANC (Abstract NAND Chip)   . NAND   ,   iBoot.   IMG4.

,      .   ,     .   .    β€” (environment)     . , , ,   Boot ROM (Apple Root CA public key).





,   Boot ROM. -,   iBoot.     ,     , - , , ,  ..

iBoot   ,     .





  .     iPhone β€” iBoot.





.






:





Apple: Boot process for iOS and iPad devices

Apple: Hardware security overview

Design & Reuse: Method for Booting ARM Based Multi-Core SoCs

Maxim integrated: Power-on reset and related supervisory functions

The iPhone wiki

ARM: Documentation

Jonathan Levin: MacOS and *OS internals

Wikipedia

: iBoot address space

Harry Moulton: Inside XNU Series

Ilhan Raja: checkra1n

Texas Instruments: Push-Button Circuit

iFixit: iPhone 12 and 12 Pro Teardown

SecureROM iBoot, 2018








All Articles