Kernel Boot Loader

The Kernel Boot Loader is (likely) the third stage bootloader of the PS Vita system. It is  in the Boot Partition. It initializes ARM TrustZone (ARM Secure kernel) through SKBL and ARM Non-secure kernel through NSKBL.

= Structure =

Kernel Boot Loader ELF consists of 4 segments: SKBL reset vector, SKBL segment 0, SKBL segment 1, NSKBL.

SKBL reset vector
SKBL Reset vector is copied ?by SKBL Segment 0 or by second_loader? from file to physical address.

SKBL Segment 0
This is SKBL executable code followed by Tzs modules.

SKBL Segment 1
This seems to be SKBL data segment.

It contains at least:
 * two corelock contexts
 * initial SKBL stack cookie
 * some pointers to SKBL area
 * device register base
 * zeroed data

NSKBL
See NSKBL.

= Boot steps =

ARM Kernel BootLoader
It is speculated that the first stage of the secure boot process is the Boot ROM in CMeP which decrypts kernel_boot_loader.self into DRAM and resets the ARM CPU. The stage at this point would have set up DRAM and the eMMC driver. There is no Virtual Memory Addressing at this point. A couple of things are loaded into memory. from the SLB2 eMMC partition is located at  (as-is/encrypted). Similarly  is located at. The VBAR is likely set to, where most handlers point to unhandled exception error code. The SKBL segments are loaded to  (where the reset vector points to) and are in three main parts. The first part is the SKBL code which includes stripped down versions of SceSysmem, SceKernelModulemgr, and initialization code (reset vector points to code in this range). The second part is the TrustZone stored as a series of either plaintext ELFs or ARZL compressed ELF. On FW 1.69, only SceSysmem is ARZL compressed whilst the other TrustZone modules are plaintext ELFs. Additionally, some initialization data is passed in,  , and.

Secure Kernel BootLoader - reset
The reset function cleans the cache and resets many CP15 registers. Next it does some more device initialization and prints out the debug string. Core 0 then creates some initialization data from parameters passed in from the previous stage as well as with params hard coded. This includes the VMA for the VBAR, MVBAR, TTBR0, TTBR1, and other configurations. It then turns on virtual memory and maps the defined regions for everything defined above. Other cores wait for this to complete and then just use the initialization data created by core 0. The L2 cache is also setup at this point. After this point, the low-level system is finished initializing.

Secure Kernel BootLoader - TrustZone loading
Next the ARM Secure Kernel is loaded with the stripped down module manager (equivalent to SceKernelModulemgr) inside the kernel boot loader. First SceSysmem, which on newer FWs is ARZL compressed, is decompressed to scratch space at. Then the ELF loader loads it and the system memory manager's initialization function is called which setups the memory in TrustZone. This also setups KBL Param in TrustZone. Data from physical address  is copied to the buffer allocated at offset 0x6C0 (?KBL Param?) (in FW 1.69 this is 0x46C0). The other ELFs are not compressed and just loaded as-is by the module manager. SceExcpmgr is loaded next and its initialization function replaces the vectors pointed to by VBAR and MVBAR. The MVBAR determines how SMC calls are handled and is the entry point to TrustZone. Other modules' initialization functions invoke SceExcpmgr functions to register SMC handlers. When SceSblSmsched is initialized, it initialized the security processor with  and   found in memory. After this point is likely when signature revocation would take effect. The other TrustZone modules are loaded, then the TrustZone DRAM region (0x40000000-0x40300000 on FW 1.69, 0x40200000 on later firmwares ?which?) are set up in hardware, and after that, the TrustZone is completely loaded.

Non-Secure Kernel BootLoader
The NSKBL is stored as an ARZL compressed binary at physical address. The NSKBL is uncompressed to physical address. The reset vector for NSKBL is also found at. The initialization data initially found at  is copied to   (  before FW 3.50) so that non-secure world can access it. SKBL then switches to non-secure world by writing NS to SCR and does a return-from-exception to the non-secure reset vector. The NSKBL has to setup everything (including VMA) again in the non-secure world. The initialization of the non-secure KBL is almost exactly the same as the secure KBL one.

Non-secure Kernel
TODO: Talk about  loading and stuff.