Skip to content

Flashing (write path) ​

Static analysis only

Everything on this page was reconstructed from the boot code of 01119700F000P2AG (the only dump with a populated boot sector) with Ghidra. No write session has been captured or run on hardware. No public tool implements this yet, and nfsx is read-only. [V] = verified in disassembly or raw bytes; [I] = inferred.

All addresses are ROM (full-dump) offsets; ff8xxx are RAM.

Summary ​

  • Erase and program are handled by the boot code (0x0000–0x3FFF), not the engine application. The boot's DS2 dispatcher has its own command table. [V]
  • The flash is an external AMD/JEDEC-command-set chip in 16-bit mode (Am29F200-class). Sector erase is AA/55/80/AA/55/30, word program is AA/55/A0 + data, with DQ7/DQ5 polling. [V]
  • The erase/program primitives are copied into RAM at 0xFF8010 and run from there, because the flash array can't be read while it's busy. [V]
  • Programming is gated by a seed/key exchange (0x90 "BMW" <nonce>). Three wrong keys lock it. [V]
  • Validity trailers (0x3FFFC, 0xFFFC) are written last, so an interrupted flash leaves the ECU in boot, where it can be re-flashed. [V]

Boot DS2 command table (0x36B6) [V] ​

Seven records of [cmd:u8][flag:u8][handler:u32]:

CmdFlagHandlerPurpose
0x0000x1CE2IDENT: 42-byte identity block (also the seed material)
0x9000x1E2A → 0x2D04Seed/key security access
0x0610x21E0Memory read (ROM_LESEN / RAM_LESEN)
0x0710x22E8Program / erase / status (sub-mode in byte 3)
0x0A10x1E3ACoding checksum
0x0D10x1F56System addresses
0x9110x1E62Baud-rate change

flag = 0 for the two commands allowed before unlock [I]. Frame layout for the memory commands: [12][LEN][CMD][segment][addr:24][len][XOR], validated by FUN_00000BE4 (address 0x12, length, XOR). The address ranges each segment may touch come from the table at 0x36E0 (10-byte records [id][pad][start:u32][end:u32]). For example, segment 4 covers RAM 0xFF8000–0xFF9DFF and segments 2/6 cover ROM 0–0x3FFFF.

Flash driver [V] ​

FUN_00001910(mode, dest, src, len, &status) is the driver entry point:

  • mode 2 = program, mode 9 = sector erase.
  • FUN_00001AB0(mode) copies 0x9E bytes of the primitive (FUN_000017D4 program / FUN_00001872 erase) to 0xFF8010 and sets the call pointer 0xFF8838 / 0xFF883C.

Both primitives do the following:

  1. Mask interrupts (ori #0x700,SR).
  2. Set bits 0x6000 in 0xFFFA4E [I: flash write-enable gate].
  3. Issue the JEDEC sequence to 0xAAAA / 0x5554.
  4. Poll DQ7, with DQ5 as the timeout flag, servicing the watchdog 0xFFFA27 (0x55/0xAA) on each pass. On timeout they write 0xF0 (reset).
  5. Clear the 0x6000 bits again.

The block loop FUN_0000197C read-back-verifies every word.

Full re-flash (FUN_00002A70) erases sectors 0x4000, 0x6000, 0x10000, 0x20000 and 0x30000 and then programs the payload. The boot sector 0x0000 is never erased. The trailers are written at the end:

AddressFinalizer writes (2 bytes)Value in valid imagesMeaning
0x3FFFC55 FF0x55FFAA00program valid
0x0FFFC00 550x0055FFAAcalibration valid

The second half of each trailer presumably comes with the image data [I].

Security access (0x90) [V mechanism] ​

The request is 12 08 90 42 4D 57 <nonce> <xor>. The ASCII "BMW" comes from the tester and is checked by the ECU, not stored in it. State lives in ff83af (&0x70 phase, &0x0F fail counter, max 3) and ff83ae (bit 0 = programming unlocked, bit 4 = application mode). These boot-time RAM bytes are re-used by the application as Engine_Knock3 / Engine_Knock4.

Seed: the reply is the 42-byte IDENT block. From it the ECU computes the expected 32-bit key into ff83b0, one byte j = 0..3 at a time:

idx     = (nonce + j) % 0x2E
src     = idx < 3     ? {0x12, 0x2E, 0xA0}[idx]   // reply header
        : idx == 0x2D ? xor_of_reply              // running XOR
        :               reply[idx]                // IDENT byte
key[j]  = (src + reply[0x29 + j] + reply[0x12 + j]) & 0xFF

Key: the tester sends the 32 bits in a LEN-8 frame. On a match, FUN_000030C0 sets ff83ae = unlocked and replies 0xA0. On a mismatch it increments the fail counter and forces the locked state.

To verify on a bench

The fold above is read from the disassembly and has not been checked against a real exchange. Capture one seed/key pair before building a tool on it.

0x07 sub-modes (FUN_000022E8) [V switch / I usage] ​

These run only while not in application mode (ff83ae & 0x10 == 0). Replies go through FUN_000028D8 (0xA0 ok, 0xA2 rejected, 0xB0 parameter error).

frame[3]Action
2Program a data block (may include the 0xFFFC trailer)
6Calibration / 0x8000 path. Validates ident + Kennung and can run the full erase + reprogram (FUN_00002974, FUN_00002A70)
0x0EProgramming status query. Walks the hardware ref 0x3FE6, program ident 0x3FCB0, trailers and the cal ident, and returns a code 0x01, 0x07…0x0F telling how much of the image is valid
0x0FProgram a block anywhere in 0x800F–0x3FFFF (guarded)

Block length is at most 0xFF (MAX_BLOCK_LAENGE at 0x373D).

Boot-or-application decision (FUN_00003002) [V path / I meaning] ​

if (*0x3FFFC == 0x55FFAA00 && *0x10000 == 0xFFFFFFFF)   -> stay in boot (inconsistent image)
else if (*0xFFFC == 0x0055FFAA || *0x8000 != 0xAA55FFFF) -> start application
else  write 0xAA55 to 0x8002, stay in boot               // finish half-written marker

0x8000 is a two-stage programming marker:

ValueMeaning
AA55AA55programmed
AA55FFFFsecond half not written, so programming was interrupted
FFFFFFFFerased

Session order (reconstructed) [I] ​

  1. Get the ECU into boot. Either the image is already invalid, or you start in boot after an erase cleared the trailers.
  2. 12 04 00 IDENT.
  3. 12 08 90 42 4D 57 <nonce>: seed.
  4. Key frame (LEN 8, 32-bit key): unlock.
  5. Optional 0x91 baud change (below).
  6. 0x07 erase, then program blocks (≤ 255 bytes, 24-bit address, read-back verified).
  7. Write the CRCs: program 0x37560, cal 0xFFFA, CRC-16/ARC (see Checksums). Then write the trailers 0x3FFFC / 0xFFFC last.
  8. Reset. The boot validates the trailers and idents (0x3002, 0x34FA) and starts the new application.

Baud rates (0x91) [V] ​

The table at 0x3F20 is identical in every dump with a boot sector. Rates are 24-bit; the SCI divisors are at 0x3F36:

RateDivisor (SCCR0)
96000x34 (reset default)
192000x1A
384000x0D
500000x0A
1000000x05
1250000x04

This gives fsys ≈ 16 MHz. FUN_00001E62 matches frame[3..5] against the table. frame[6] must be in 1..0x19; it is stored to ff838a and its meaning is unknown. On a match the handler stages the divisor in ff839c, sets ff839b = 1 and replies 0xA0 at the old rate. FUN_000017B4 then writes SCCR0 (0xFFFC08), so the tester must switch after receiving the ack. No match → 0xB0.

The handler lives in the boot dispatcher. Whether the running application also accepts 0x91 (it would allow faster dumps with nfsx) is not yet confirmed.

Open ​

  • Bench-verify the key fold and the exact 0x07 sub-mode sequence the BMW programming tool uses.
  • Meaning of 0xFFFA4E bits 0x6000 (write-enable, chip-select or Vpp).
  • Whether the application forwards 0x07 / 0x91 to the boot, or the tester must force boot mode first.