FIRM

FIRM

This page describes the file format for the 3DS' Firmware, it contains up to four ‘sections’ of data comprising the ARM9 and ARM11 kernels, and some fundamental processes. The firmware sections are not encrypted. In a nutshell, a FIRM contains all the data required to set up the ARM9 and ARM11 kernels, and basic operating functionality.

The ARM9 section contains the ARM9 kernel (and loader) and the Process9 NCCH (which is the only process run in user mode on the ARM9). The ARM11 sections contain the ARM11 kernel (and loader), and various ARM11 process NCCHs. For NATIVE_FIRM/SAFE_MODE_FIRM these ARM11 processes are sm, fs, pm, loader, and pxi. Normally the 4th section is not used. The code loaded from FIRM is constantly running on the system until another FIRM is launched. The ARM11 kernel is hard-coded to always decompress the ExeFS .code of embedded ARM11 NCCHs without checking the exheader compression bit.

FIRM Header #

OFFSETSIZEDESCRIPTION
0x0004Magic ‘FIRM’
0x0044Boot priority (highest value = max prio), this is normally zero.
0x0084ARM11 Entrypoint
0x00C4ARM9 Entrypoint
0x0100x030Reserved
0x0400x0C0 (0x030*4)Firmware Section Headers
0x1000x100RSA-2048 signature of the FIRM header’s SHA-256 hash. The signature is checked when bootrom/Process9 are doing FIRM-launch (with the public key being hardcoded in each). The signature is not checked when installing FIRM to the NAND firm0/firm1 partitions.

Firmware Section Headers #

OFFSETSIZEDESCRIPTION
0x0004Byte offset
0x0044Physical address where the section is loaded to.
0x0084Byte-size. While loading FIRM this is the field used to determine whether the section exists or not, by checking for value 0x0.
0x00C4Copy-method (0 = NDMA, 1 = XDMA, 2 = CPU mem-copy), Process9 ignores this field. Boot9 doesn’t immediately throw an error when this isn’t 0..2. In that case it will jump over section-data-loading which then results in the hash verification with the below hash being done with the hash already stored in the SHA hardware.
0x0100x020SHA-256 Hash of Firmware Section

The contents of individual sections may be encrypted if the FIRM is not meant to be booted from NAND, i.e. if it is meant to be booted from SPI flash or NTR cartridge. If hash checks fail for all FIRM sections if treated as plaintext, it may be worth trying to check if the sections are encrypted. The encryption is detailed on the bootloader page.

For New3DS firmwares (NATIVE_FIRM, TWL_FIRM, ..), the ARM9 FIRM binary has an additional layer of crypto. At the end of each ARM9 binary, there’s a plaintext loader. The format of the FIRM header is identical to regular 3DS FIRM(the RSA modulo is the same as regular 3DS too).

Before checking CFG_SYSPROT9 the loader main() does the following:

  • On 9.5.0-X: executes a nop instruction with r0=0 and r1=<address of arm9binhdr+0x50>.
  • Clears bit6 in REG_AESKEYCNT.

If CFG_SYSPROT9 bit 1 is clear (which means the OTP area is unlocked and so it knows that this is a hard reboot), it does the following things:

  • Clears 0x200-bytes on the stack, then reads NAND sector 0x96(NAND image offset 0x12C00), with size 0x200-bytes into that stack buffer.
  • Checks CFG_SYSPROT9 bit 1 again, if it’s set then it executes a panic function(set r0-r2=0, execute nop instruction, then execute instruction “bkpt 0x99”).
  • Hashes data from the OTP region 0x10012000-0x10012090 using SHA256 via the SHA hardware.
  • Clears bit6 in REG_AESKEYCNT. Initializes AES keyslot 0x11 keyX, keyY to the lower and higher portion of the above hash, respectively. Due to the above hashed data, the keyX+keyY here are console-unique.
  • Decrypts the first 0x10-byte block in the above read NAND sector with keyslot 0x11 using AES-ECB. 9.6.0-X: Then it decrypts the 0x10-bytes at offset 0x10 in the sector with keyslot 0x11.
  • Then the normalkey, keyX, and keyY, for keyslot 0x11 are cleared to zero. Runs the TWL key-init/etc code which was originally in the ARM9-kernel, then writes 0x2 to CFG_SYSPROT9 to disable the OTP area.
  • Then it uses the above decrypted block from sector+0 to set the normalkey for keyslot 0x11. Decrypts arm9_bin_buf+0 using keyslot 0x11 with AES-ECB, and initialises keyX for keyslot 0x15 with it.
  • 9.6.0-X: Then it uses the above decrypted block from sector+0 to set the normalkey for keyslot 0x11. Decrypts a 0x10-byte block from arm9loader .(ro)data using keyslot 0x11 with AES-ECB, and initializes keyX for keyslot 0x18 with it(same block as previous versions).
  • 9.6.0-X: Starting with this version keyslot 0x16 keyX init was moved here, see below for details on this. The code for this is same as 9.5.0-X, except the decrypted normalkey from sector+0x10 is used for keyslot 0x11 instead.
  • Initialises KeyX for keyslots 0x18..0x1F(0x19..0x1F with 9.6.0-X) with the output of decrypting a 0x10-byte block with AES-ECB using keyslot 0x11. This block was changed to a new one separate from keyslot 0x18, starting with 9.6.0-X. The last byte in this 0x10-byte input block is increased by 0x01 after initializing each keyslot. Before doing the crypto each time, the loader sets the normal-key for keyslot 0x11 to the plaintext normalkey from sector+0(+0x10 with 9.6.0-X). These are New3DS-specific keys.
  • 9.5.0-X(moved to above with 9.6.0-X): Sets the normal-key for keyslot 0x11 to the same one already decrypted on the stack. Decrypts the 0x10-byte block at arm9binhdr+0x60 with AES-ECB using keyslot 0x11, then sets the keyX for keyslot 0x16 to the output data.
  • 9.5.0-X: The normalkey, keyX, and keyY, for keyslot 0x11 are then cleared to zero.

When CFG_SYSPROT9 bit 1 is set(which means this happens only when this loader runs again for firm-launch), the normalkey, keyX, and keyY, for keyslot 0x11 are cleared to zero.

It sets KeyY for keyslot 0x15(0x16 with 9.5.0-X) to arm9_bin_buf+16, the CTR to arm9_bin_buf+32 (both are unique for every version). It then proceeds to decrypt the binary with AES-CTR. When done, it sets the normal-key for the keyslot used for binary decryption to zeros. It then decrypts arm9_bin_buf+64 using an hardcoded keyY for keyslot 0x15( 9.5.0-X/ 9.6.0-X also uses keyslot 0x15), sets the normal-key for this keyslot to zeros again, then makes sure the output block is all zeroes. If it is, it does some cleanup then it jumps to the entrypoint for the decrypted binary. Otherwise it will clear the keyX, keyY, and normal-key for each of the keyslots initialized by this loader (on 9.6.0-X+, on older versions this was bugged and cleared keys 0x00..0x07 instead of 0x18..0x1F), do cleanup(same cleanup as when the decrypted block is all-zero) then just loop forever.

Thus, the ARM9 binary has the following header:

OFFSETSIZEDESCRIPTION
0x00016Encrypted KeyX (same for all FIRM's)
0x01016KeyY
0x02016CTR
0x0308Size of encrypted binary, as ASCII text?
0x0388?
0x04016Control block
0x05016Added with 9.5.0-X. Only used for hardware debugging: a nop instruction is executed with r0=0 and r1=

.

0x06016Added with 9.5.0-X. Encrypted keyX for keyslot 0x16.

Originally the padding after the header before offset 0x800(start of actual ARM9-binary) was 0xFF bytes, with 9.5.0-X this was changed to 0x0.

For the New3DS NATIVE_FIRM arm9-section header, the only difference between the 8.1.0-0_New3DS version and the 9.0.0-20 version is that the keyY, CTR, and the block at 0x30 in the header were updated.

New3DS ARM9 binary loader versions #

FIRM system version(s)Description
8.1.0-0_New3DS - 9.3.0-XInitial version.
9.5.0-XAdded keyX initialization for keyslot 0x16(see above), and added code for clearing keyslot 0x11 immediately after the code finishes using keyslot 0x11. The keyslot used for arm9bin decryption was changed from 0x15 to 0x16. Added code for clearing keyslot 0x16 when control-block decryption fails. Added code for using arm9bin_hdr+0x50 with a nop instruction, at the very beginning of the main arm9-loader function. Added two new 0x10-blocks to the arm9bin-hdr.
9.6.0-X - 11.3.0-XSee above and here.

New3DS ARM9 kernel #

The only actual code-difference for the Old3DS/New3DS ARM9-kernels’ crt0, besides TWL AES / 0x10012000 related code, is that the New3DS ARM9-kernel writes 0x1 to REG_EXTMEMCNT9 in the crt0.

New3DS Process9 #

The following is all of the differences for Old3DS/New3DS Process9 with 9.3.0-X:

  • The FIRM-launch code called at the end of the New3DS proc9 main() has different mem-range checks.
  • In the New3DS proc9, the v6.0/v7.0 keyinit function at the very beginning(before the original code) had additional code added for setting CTRNAND keyslot 0x5, with keydata from .data. After setting the keyY, the keyY in .data is cleared.
  • In New3DS proc9, the functions for getting the gamecard crypto keyslots / NCCH keyslot can return New3DS keyslots when New3DS flags(NCSD/NCCH) are set.
  • The code/data for the binary near the end of arm9mem is slightly different, because of memory-region sizes.
  • The only difference in .data(besides the above code binary) is that the New3DS proc9 has an additional 0x10-byte block for the keyslot 0x5 keyY, see above.

Variations #

There exists different official firmwares for the 3DS: The default one (NATIVE_FIRM) is used to run all 3DS content and boots by default, while backwards compatibility is handled by TWL_FIRM and AGB_FIRM. There furthermore is a rescue mode provided by SAFE_MODE_FIRM.

NATIVE_FIRM #

NATIVE_FIRM is the FIRM which is installed to the NAND firm partitions, which is loaded by bootrom.

Version history:

System versionold 3DS title versionold 3DS hex title contentIDKernel/FIRM version (old 3DS/new 3DS)FIRM ARM11-sysmodule Product Code
Factory FIRM (titleID 00040001-00000002)v0002.3-0
Pre-1.0. Referenced in the v1.0 Home Menu NCCH plain-region.2.23-X
1.0.0v432002.27-0
1.1.0v1472022.28-0
2.0.0v2516092.29-7
2.1.0v35530B2.30-180608builder
2.2.0v45950F2.31-400909builder
3.0.0v5647182.32-151128builder
4.0.0v66771D2.33-40406builder
4.1.0v77121F2.34-00508builder
5.0.0v8758252.35-60228builder
5.1.0v9792262.36-00401builder
6.0.0v10833292.37-00520builder
6.1.0v118722A2.38-00625builder
7.0.0v129162E2.39-41125builder
7.2.0v13956302.40-00404builder
8.0.0v15047372.44-60701builder
8.1.0-0_New3DSN/AN/A2.45-5
9.0.0v17120382.46-00828builder
9.3.0v181823F2.48-31125builder
9.5.0v19216402.49-00126builder
9.6.0v20262492.50-10311builder
10.0.0v212884B2.50-70812builder
10.2.0v223134C2.50-91009builder
10.4.0v23341502.50-111224builder
11.0.0v24368522.51-00406builder
11.1.0v25396562.51-20805builder
11.2.0v26432582.52-01015builder
11.3.0v274765C2.53-00126builder
11.4.0v285125E2.54-00314builder
11.8.0v29557642.55-00710pseg-ciuser
11.12.0v30593662.56-01021pseg-ciuser
11.14.0v31633692.57-00929pseg-ciuser
11.16.0v326736C2.58-00701pseg-ciuser

The above kernel/FIRM versions are in the format: <KERNEL_VERSIONMAJOR>.<KERNEL_VERSIONMINOR>-<KERNEL_VERSIONREVISION>.

SAFE_MODE_FIRM #

SAFE_MODE is used for running the System Updater. SAFE_MODE_FIRM and NATIVE_FIRM for the initial versions are exactly the same, except for the system core version fields. Kernel/FIRM versions for SAFE_MODE_FIRM are: (old3ds) v432 = 3.27-0, v5632 = 3.32-0, (new3ds) v16081 = 3.45-3.

TWL_FIRM #

TWL_FIRM handles DS(i) backwards compatibility.

The 3DS-mode ARM9 core seems to switch into DSi-mode(for running DSi-mode ARM9 code) by writing to a PDN register(this changes the memory layout to DSi-mode / etc, therefore this register poke *must* be executed from ITCM). This is the final 3DS-mode register poke before the ARM9 switches into DSi-mode. DS(i)-mode ARM7 code is run on the internal ARM7 core, which is started up during TWL_FIRM boot. Trying to read from the exception-vector region(address 0x0) under this DSi-mode ARM7 seems to only return 0x00/0xFF data. Also note that this DSi-mode ARM7 runs code(stored in TWL_FIRM) which pokes some DSi-mode registers that on the DSi were used for disabling access to the DSi bootROMs, however these registers do not affect the 3DS DSi-mode ARM9/ARM7 “bootrom” region(exceptionvector region + 0x8000) at all.

For shutting down the system, TWL_FIRM writes u8 value 8 to I2C MCU register 0x20. For returning to 3DS-mode, TWL_FIRM writes value 4 to that MCU register to trigger a hardware system reboot.

The TWL_FIRM ARM11-process includes a TWL bootloader, see 🔗 here and here for details.

TWL_FIRM verifies all TWL RSA padding with the following. This is different from the DSi “BIOS” code.

  • The first byte must be 0x0.
  • The second byte must be 0x1 or 0x2.
  • Executes a while(). When the second_byte in the message is 0x1, the byte at curpos must be 0xFF(otherwise the non-zero value of the byte at curpos doesn’t matter). This loop must find a zero byte before offset 0x7F in the message otherwise an error is returned.
  • Returns an address for msg_curpos+1.

totalhashdatasize = rsasig_bytesize - above position in the message for the hashdata. The actual “totalhashdatasize” in the RSA message must be <= (0x74 for bootloader). The TWL_FIRM code copies the RSA “hashdata” to the output buffer, using the actual size of the RSA “hashdata”.

AGB_FIRM #

AGB_FIRM handles running GBA VC titles. The ARM9 FIRM section for TWL_FIRM and AGB_FIRM are exactly the same (for TWL_FIRM and AGB_FIRM versions which were updated with the same system-update).

FIRM Launch Parameters #

The FIRM-launch parameters structure is located at FCRAM+0, size 0x1000-bytes. The ARM11-kernel copies this structure elsewhere, then clears the 0x1000-bytes at FCRAM+0. It will not handle an existing structure at FCRAM+0 if CFG_BOOTENV is zero. The ARM9 kernel writes some values about the boot environment to AXI WRAM during init to enable this.

Note: it seems NATIVE_FIRM ARM11-kernel didn’t parse this during boot until 3.0.0-X?

OFFSETSIZEDESCRIPTION
0x0000x300TWL auto-load parameters, passed as-is onto the new title. NS will only read the oldTitleId field from it and add it to the TWL title list if it’s a CTR titleId
0x3000x100‘TLNC’ block created by TWL applications, handled by NS for backwards-compatibility purposes. See here for more info.
0x4000x4Flags
0x4100xCThis is used for overriding the FIRM_* fields in Configuration_Memory, when the flag listed below is set, in the following order(basically just data-copy from here to 0x1FF80060): “FIRM_?”, FIRM_VERSIONREVISION, FIRM_VERSIONMINOR, FIRM_VERSIONMAJOR, FIRM_SYSCOREVER, and FIRM_CTRSDKVERSION.
0x4380x4The kernel checks this field for value 0xFFFF, if it matches the kernel uses the rest of these parameter fields, otherwise FIRM-launch parameters fields are ignored by the kernel.
0x43C0x4CRC32, this is calculated starting at FIRM-params offset 0x400, with size 0x140(with this field cleared to zero during calculation). When invalid the kernel clears the entire buffer used for storing the FIRM-params, therefore no actual FIRM-params are handled after that.
0x4400x10Titleinfo Program Info, used by NS during NS startup, to launch the specified title when the below flag is set.
0x4500x10Titleinfo Program Info. This might be used for returning to the specified title, once the above launched title terminates?
0x4600x4Bit0: 0 = titleinfo structure isn’t set, 1 = titleinfo structure is set.
0x4800x20This can be set via buf1 for APT:SendDeliverArg/ APT:StartApplication.
0x4A00x10This can be set by NSS:SetWirelessRebootInfo.
0x4B00x14SHA1-HMAC of the banner for TWL/NTR titles. This can be set by NSS:SetTWLBannerHMAC.
0x5000x40This is used by APT:LoadSysMenuArg and APT:StoreSysMenuArg.
0xD500x20Atheros WiFi configuration struct
0xD700x290Config data struct for LGY FIRM.

Flags from offset 0x400:

OFFSETSIZEDESCRIPTION
0x00x1This can be used for overriding the default FCRAM memory-regions allocation sizes(APPLICATION, SYSTEM, and BASE). The values for this is the same as Configmem-APPMEMTYPE. Values 0-1 are handled the same way by the kernel. However for NS, 0=titleinfo structure for launching a title isn’t set, while non-zero=titleinfo structure is set.
0x10x3Setting bit0 here enables overriding the FIRM_* fields in Configuration_Memory.

Atheros WiFi configuration struct for booting TWL_FIRM, from offset 0xD50. This struct is copied directly to 0x20005E0 in DSi memory. Since DSi cartridge ROMs include SDIO drivers for the wireless card and can’t be updated, this structure allows interoperability between the original DSi wireless cards (AR6002/DWM-W015 and AR6013/DWM-W024) as well as the 3DS’s AR6014/DWM-W028.

OFFSETSIZEDESCRIPTION
0x00x1WiFi Board Type (1=DWM-W015, 2=DWM-W024, 3=DWM-W028; 0x03 on 3DS)
0x10x1Unknown (0x00)
0x20x2CRC16 from 0x4 to 0x20 (0x1C bytes)
0x40x4Atheros RAM Vars/Host Interest address (0x520000 on 3DS)
0x80x4Atheros RAM base (0x520000 on 3DS)
0xC0x4Atheros RAM size (0x20000 on 3DS)
0x100x10Unknown (Zeroed)

Config struct for booting LGY FIRMs from offset 0xD70:

OFFSETSIZEDESCRIPTION
0x00x1RTC compensation value (config block 0x30000).
0x10x1Sound output mode (config block 0x70001).
0x20x1System language (config block 0xA0002).
0x30x1Region from SecureInfo (“pseudo-block” 0x140000 in LGY FIRM).
0x40xFSerial number from SecureInfo (“pseudo-block” 0x140001 in LGY FIRM).
0x130x1TWL country code (config block 0x100002).
0x140x10TWL “movable” UID, used for DSiWare exports (config block 0x100003).
0x240x2TWL EULA info (config block 0x100000).
0x260x1Cleared to zero.
0x270x1Cleared to zero.
0x280x94TWL parental control data (config block 0x100001).
0xBC0x2LCD flicker calibration data (config block 0x50000).
0xBE0x2Backlight data (config block 0x50001).
0xC00x38Backlight PWM table (config block 0x50002).
0xF80x20Power saving mode (ABL) calibration (config block 0x50004).
0x1180x134CODEC calibration data (config block 0x20000).
0x24C0x10Touch screen calibration data (config block 0x40000).
0x25C0x1CAnalog stick calibration data (config block 0x40001).
0x2780x4Cleared to zero.
0x27C0x4Cleared to zero.
0x2800x8User time offset (config block 0x30001).
0x2880x2CRC16 over the above fields from offset 0x0, size 0x288. If not valid, LGY FIRM uses dummy data from .(ro)data.
0x28A0x2Version, maybe? If non-zero, the size (below) is hardcoded (currently) to value 0x288, otherwise the size field below is used.
0x28C0x4Value 0x288 (size used for verifying the CRC16).

“Cleared to zero” fields above are not read at all by LGY FIRM.