Changes

67 bytes added ,  23:51, 21 September 2023
Line 71: Line 71:  
|-
 
|-
 
| 0x5C
 
| 0x5C
| 0x2
+
| 0x1
| Version. HighByte must be <{maxver} and LowByte must be >{minver}, where {maxver} and {minver} are constants used by TZ updated with each package1 update.
+
| Package2 version. Must be >= {minimum valid package2 version} constant in TZ.
 +
|-
 +
| 0x5D
 +
| 0x1
 +
| Bootloader version. Must be <= {current bootloader version} constant in TZ.
 
|-
 
|-
 
| 0x5E
 
| 0x5E
Line 132: Line 136:  
Before being decrypted, the encrypted header's CTR additionally encodes metadata used to validate package2's contents as follows:
 
Before being decrypted, the encrypted header's CTR additionally encodes metadata used to validate package2's contents as follows:
 
* Size of the entire package2 with the raw header = ctr_word2 ^ ctr_word3 ^ ctr_word0
 
* Size of the entire package2 with the raw header = ctr_word2 ^ ctr_word3 ^ ctr_word0
* Metadata version field = ((ctr_word1 ^ (ctr_word1 >> 16)) & 0xFF) ^ (ctr_word1 >> 24)
+
* Key generation = ((ctr_word1 ^ (ctr_word1 >> 16)) & 0xFF) ^ (ctr_word1 >> 24)
   −
In [4.0.0], the metadata version field must be less or equal to 4.
+
In [4.0.0], the key generation must be less or equal to 4.
    
== Section 0 ==
 
== Section 0 ==
Line 141: Line 145:  
== Section 1 ==
 
== Section 1 ==
 
When decrypted, this section contains the built-in system modules encapsulated in a custom format.
 
When decrypted, this section contains the built-in system modules encapsulated in a custom format.
 +
 +
Note: On firmware [[8.0.0]] INI1 is contained within the Kernel and section 1 is empty with NULL SHA256 to match.
    
=== INI1 ===
 
=== INI1 ===
Line 146: Line 152:  
|-
 
|-
 
! Offset
 
! Offset
! Type
+
! Size
 
! Description
 
! Description
 
|-
 
|-
 
| 0x0
 
| 0x0
| u32
+
| 0x4
 
| Magic "INI1"
 
| Magic "INI1"
 
|-
 
|-
 
| 0x4
 
| 0x4
| u32
+
| 0x4
 
| Size
 
| Size
 
|-
 
|-
 
| 0x8
 
| 0x8
| u32
+
| 0x4
| NumberProcesses
+
| Number of KIPs (Must be lower than 0x51)
 
|-
 
|-
 
| 0xC
 
| 0xC
| u32
+
| 0x4
| Padding (zero)
+
| Reserved
 
|}
 
|}
    
==== KIP1 ====
 
==== KIP1 ====
Kernel internal process?
  −
   
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
 
! Offset
 
! Offset
! Type
+
! Size
 
! Description
 
! Description
 
|-
 
|-
 
| 0x0
 
| 0x0
| u32
+
| 0x4
 
| Magic "KIP1"
 
| Magic "KIP1"
 
|-
 
|-
 
| 0x4
 
| 0x4
| char[12]
+
| 0xC
 
| Name
 
| Name
 
|-
 
|-
 
| 0x10
 
| 0x10
| u64
+
| 0x8
| TitleId
+
| Program ID
 
|-
 
|-
 
| 0x18
 
| 0x18
| u32
+
| 0x4
| Process category (0: regular title, 1: kernel built-in). Should be 1 here.
+
| Version
 
|-
 
|-
 
| 0x1C
 
| 0x1C
| u8
+
| 0x1
| Main thread priority
+
| Main Thread Priority
 
|-
 
|-
 
| 0x1D
 
| 0x1D
| u8
+
| 0x1
| Default CPU core
+
| Main Thread Core Number
 
|-
 
|-
 
| 0x1E
 
| 0x1E
| u8
+
| 0x1
| Reserved (unused)
+
| Reserved
 
|-
 
|-
 
| 0x1F
 
| 0x1F
| u8
+
| 0x1
| Flags: bit0-2: compression-enable for each section, when set. Bit3: Is64Bit. Bit4: IsAddrSpace36Bit. Bit5: [2.0.0+] PoolPartitionId. Bit6, Bit7: reserved (unused)
+
| Flags (bit0=TextCompress, bit1=RoCompress, bit2=DataCompress, bit3=Is64BitInstruction, bit4=ProcessAddressSpace64Bit, bit5=[2.0.0+] UseSecureMemory)
 
|-
 
|-
 
| 0x20
 
| 0x20
| [[#SectionHeader]][6]
+
| 0xC
| Sections: .text, .rodata, .data, .bss and two reserved (ignored) sections.
+
| Text [[#Segment_Header|Segment Header]]
 +
|-
 +
| 0x2C
 +
| 0x4
 +
| Main Thread Affinity Mask
 +
|-
 +
| 0x30
 +
| 0xC
 +
| Ro [[#Segment_Header|Segment Header]]
 
|-
 
|-
 +
| 0x3C
 +
| 0x4
 +
| Main Thread Stack Size
 +
|-
 +
| 0x40
 +
| 0xC
 +
| Data [[#Segment_Header|Segment Header]]
 +
|-
 +
| 0x4C
 +
| 0x4
 +
| Reserved
 +
|-
 +
| 0x50
 +
| 0xC
 +
| Bss [[#Segment_Header|Segment Header]]
 +
|-
 +
| 0x5C
 +
| 0x24
 +
| Reserved
 +
|-
 +
| 0x80
 
| 0x80
 
| 0x80
| u32[0x20]
+
| [[NPDM#KernelCapability|Kernel Capability Data]]
| KernelCaps
   
|}
 
|}
   −
===== SectionHeader =====
+
===== Segment Header =====
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
 
! Offset
 
! Offset
! Type
+
! Size
 
! Description
 
! Description
 
|-
 
|-
 
| 0x0
 
| 0x0
| u32
+
| 0x4
| OutOffset
+
| Offset
 
|-
 
|-
 
| 0x4
 
| 0x4
| u32
+
| 0x4
| DecompressedSize
+
| Size
 
|-
 
|-
 
| 0x8
 
| 0x8
| u32
+
| 0x4
| CompressedSize
+
| Compressed/Binary Size
|-
  −
| 0xC
  −
| u32
  −
| Attribute: the size in pages of the main thread's stack for .rodata, reserved otherwise.
   
|}
 
|}
   −
Compressed size can be 0 or lower than exepected, this is the case for BSS for example.
+
Compressed/Binary size can be 0 or lower than expected, this is the case for BSS for example.
    
===== Compression =====
 
===== Compression =====
The compression used here is BLZ, with a modified footer since 3ds. The footer is now 0xC bytes instead of 0x8, and has the form u32 compressed_data_len; u32 initial_index; u32 additional_len_when_uncompressed;
+
The compression used here is BLZ, with a modified footer since 3ds. The footer is now 0xC bytes instead of 0x8, and has the form u32 compressed_data_len; u32 footer_size; u32 additional_len_when_uncompressed;
    
== Section 2 ==
 
== Section 2 ==
Line 255: Line 283:  
|-
 
|-
 
! System version
 
! System version
! Package1 maxver constant
+
! Bootloader current version
! Package1 minver constant
+
! Package2 minimum valid version
! Package2 version field
   
|-
 
|-
 
| [[1.0.0]]
 
| [[1.0.0]]
 +
| 0x1
 +
| 0x4
 +
|-
 +
| [[2.0.0]]
 
| 0x2
 
| 0x2
 +
| 0x5
 +
|-
 +
| [[3.0.0]]
 
| 0x3
 
| 0x3
| 0x0104
+
| 0x6
 
|-
 
|-
| [[2.0.0]]
+
| [[3.0.2]]
| 0x3
   
| 0x4
 
| 0x4
| 0x0205
+
| 0x7
 
|-
 
|-
| [[3.0.0]]
+
| [[4.0.0]]
| 0x4
   
| 0x5
 
| 0x5
| 0x0306
+
| 0x8
 
|-
 
|-
| [[3.0.2]]
+
| [[5.0.0]]
| 0x5
   
| 0x6
 
| 0x6
| 0x0407
+
| 0x9
 
|-
 
|-
| [[4.0.0]]
+
| [[6.0.0]]
| 0x6
   
| 0x7
 
| 0x7
| 0x0508
+
| 0xA
 +
|-
 +
| [[6.2.0]]
 +
| 0x8
 +
| 0xB
 +
|-
 +
| [[7.0.0]]
 +
| 0x9
 +
| 0xC
 +
|-
 +
| [[8.1.0]]
 +
| 0xA
 +
| 0xD
 +
|-
 +
| [[9.0.0]]
 +
| 0xB
 +
| 0xE
 +
|-
 +
| [[9.1.0]]
 +
| 0xC
 +
| 0xF
 +
|-
 +
| [[10.0.0]]
 +
| 0xD
 +
| 0x10
 +
|-
 +
| [[11.0.0]]
 +
| 0xE
 +
| 0x11
 +
|-
 +
| [[12.0.2]]
 +
| 0xF
 +
| 0x12
 +
|-
 +
| [[12.1.0]]
 +
| 0xF
 +
| 0x13
 +
|-
 +
| [[13.0.0]]
 +
| 0xF
 +
| 0x14
 
|}
 
|}
   Line 309: Line 379:     
=== Debug Modulus ===
 
=== Debug Modulus ===
<syntaxhighlight>
+
  B3 65 54 FB 0A B0 1E 85 A7 F6 CF 91 8E BA 96 99
00000000: B36554FB 0AB01E85 A7F6CF91 8EBA9699 ³eTû.°.…§öÏ‘Žº–™
+
  0D 8B 91 69 2A EE 01 20 4F 34 5C 2C 4F 4E 37 C7
00000010: 0D8B9169 2AEE0120 4F345C2C 4F4E37C7 .‹‘i*î. O4\,ON7Ç
+
  F1 0B D4 CD A1 7F 93 F1 33 59 CE B1 E9 DD 26 E6
00000020: F10BD4CD A17F93F1 3359CEB1 E9DD26E6 ñ.ÔÍ¡.“ñ3YαéÝ&æ
+
  F3 BB 77 87 46 7A D6 4E 47 4A D1 41 B7 79 4A 38
00000030: F3BB7787 467AD64E 474AD141 B7794A38 ó»w‡FzÖNGJÑA·yJ8
+
  06 6E CF 61 8F CD C1 40 0B FA 26 DC C0 34 51 83
00000040: 066ECF61 8FCDC140 0BFA26DC C0345183 .nÏa.ÍÁ@.ú&ÜÀ4Qƒ
+
  D9 3B 11 54 3B 96 27 32 9A 95 BE 1E 68 11 50 A0
00000050: D93B1154 3B962732 9A95BE1E 681150A0 Ù;.T;–'2š•¾.h.P 
+
  6B 10 A8 83 8B F5 FC BC 90 84 7A 5A 5C 43 52 E6
00000060: 6B10A883 8BF5FCBC 90847A5A 5C4352E6 k.¨ƒ‹õü¼.„zZ\CRæ
+
  C8 26 E9 FE 06 A0 8B 53 0F AF 1E C4 1C 0B CF 50
00000070: C826E9FE 06A08B53 0FAF1EC4 1C0BCF50 È&éþ. ‹S.¯.Ä..ÏP
+
  1A A4 F3 5C FB F0 97 E4 DE 32 0A 9F E3 5A AA B7
00000080: 1AA4F35C FBF097E4 DE320A9F E35AAAB7 .¤ó\ûð—äÞ2.ŸãZª·
+
  44 7F 5C 33 60 B9 0F 22 2D 33 2A E9 69 79 31 42
00000090: 447F5C33 60B90F22 2D332AE9 69793142 D.\3`¹."-3*éiy1B
+
  8F E4 3A 13 8B E7 26 BD 08 87 6C A6 F2 73 F6 8E
000000A0: 8FE43A13 8BE726BD 08876CA6 F273F68E .ä:.‹ç&½.‡l¦òsöŽ
+
  A7 F2 FE FB 6C 28 66 0D BD D7 EB 42 A8 78 E6 B8
000000B0: A7F2FEFB 6C28660D BDD7EB42 A878E6B8 §òþûl(f.½×ëB¨xæ¸
+
  6B AE C7 A9 E2 40 6E 89 20 82 25 8E 3C 6A 60 D7
000000C0: 6BAEC7A9 E2406E89 2082258E 3C6A60D7 k®Ç©â@n‰ ‚%Ž<j`×
+
  F3 56 8E EC 8D 51 8A 63 3C 04 78 23 0E 90 0C B4
000000D0: F3568EEC 8D518A63 3C047823 0E900CB4 óVŽì.QŠc<.x#...´
+
  E7 86 3B 4F 8E 13 09 47 32 0E 04 B8 4D 5B B0 46
000000E0: E7863B4F 8E130947 320E04B8 4D5BB046 ç†;OŽ..G2..¸M[°F
+
  71 B0 5C F4 AD 63 4F C5 E2 AC 1E C4 33 96 09 7B
000000F0: 71B05CF4 AD634FC5 E2AC1EC4 3396097B q°\ô.cOÅâ¬.Ä3–.{
  −
</syntaxhighlight>