NCSD

From 3dbrew
Revision as of 17:10, 28 July 2012 by 3dsguy (talk | contribs) (Undo revision 3631 by Neimod (talk))
Jump to navigation Jump to search

This page documents the format of NCSD.

Overview

There are two known specialisations of the NCSD container format. The CTR Cart Image (CCI) format and the CTR System Update (CSU). CCI is the format of retail game ROM dumps. CSU is used with developer system updates and tools

NCSD images start with a NCSD header, followed by up to a maximum of 8 NCCH partitions. The first partition(NCCH 0) usually starts at 0x4000, this is generally the main NCCH (Executable). The following info on partitions 1, 2, and 7 are only valid for .CCI. The second partition(NCCH 1) contains the game "Manual"(title ID for the .CFA containing the Manual always starts with '0005'). The third partition(NCCH 2) contains the download play "Child"(The title ID for the .CFA containing the DLP Child always starts with '0006'). The eighth block(NCCH 7) contains "Update Data"(The title ID for the .CFA containing the Update Data always starts with '8000') The format of partitions can be determined from the partition FS flags, while the contents can be determined from the partitions flags.

NCSD header

Offset Size Description
0x000 0x100 RSA-2048 SHA-256 signature of the NCSD header
0x100 4 Magic Number 'NCSD'
0x104 4 Size of the NCSD image, in media units (1 media unit = 0x200 bytes)
0x108 8 Title/Program ID
0x110 8 Partitions FS type
0x118 8 Partitions crypt type
0x120 0x40=(4+4)*8 Offset & Length partition table
0x160 0x20 Exheader SHA-256 hash
0x180 0x4 Additional header size
0x184 0x4 Sector zero offset
0x188 8 Partition Flags: byte[5]-byte[7] indicate content type ( system update, application, manual, ... ) size of media units ( 512*2^byte[6] ) and encryption.
0x190 0x40=8*8 Partitions' Title ID table
0x1D0 0x28 Reserved
0x1F8 8 Unknown
0x200 4 Always 0xFFFFFFFF
0x204 252 Padding?
0x300 4 Used ROM size in bytes
0x304 28 Padding
0x320 8 NVer Title ID (Only Present in retail .CCI)
0x328 8 NVer Title Version (Only Present in retail .CCI)

Parts of the first NCCH block's header are found around 0x1000 for whatever reason. NCSD can hold up to 8 partitions. (i.e. Mario Kart 7 holds 4 NCCHs, most we've seen so far)

The region-specific NVer title for this NCSD presumably must exist on NAND. The NVer title version may also be used to check whether a system update is required before running the app.

NCSD "Unknown Section"

OFFSET SIZE DESCRIPTION
0x1000 8 Title ID of main NCCH
0x1008 8 Reserved
0x1010 0x30 Initial Data
0x1040 0xC0 Reserved
0x1100 4 Magic ID, always 'NCCH'
0x1104 4 Content size, in media units (1 media unit = 0x200 bytes)
0x1108 8 Partition ID
0x1110 2 Maker code
0x1112 2 Version
0x1114 4 Reserved
0x1118 8 Program ID
0x1120 1 Temp flag
0x1121 0x2F Reserved
0x1150 0x10 Product code
0x1160 0x20 Extended header hash (SHA-256), over the cleartext ExHeader
0x1180 4 Extended header size
0x1184 4 Reserved
0x1188 8 Flags: byte[5]-byte[7] indicate content type ( system update, application, manual, ... ) size of media unit ( 512*2^byte[6] ) and encryption.
0x1190 4 Plain region offset, in media units
0x1194 4 Plain region size, in media units
0x1198 8 Reserved
0x11A0 4 ExeFS offset, in media units
0x11A4 4 ExeFS size, in media units
0x11A8 4 ExeFS hash region size, in media units
0x11AC 4 Reserved
0x11B0 4 RomFS offset, in media units
0x11B4 4 RomFS size, in media units
0x11B8 4 RomFS hash region size, in media units
0x11BC 4 Reserved
0x11C0 0x20 ExeFS superblock hash, over the cleartext ExeFS
0x11E0 0x20 RomFS superblock hash
0x1200 0x2E00 Reserved/Unused (Is filled with either 'F's or '0's)

From the magic 'NCCH' to the end of the 'RomFS superblock hash' the data is identical to the NCCH Header of the Executable NCCH Partition (NCCH 0).