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 isAA/55/A0+ data, with DQ7/DQ5 polling. [V] - The erase/program primitives are copied into RAM at
0xFF8010and 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]:
| Cmd | Flag | Handler | Purpose |
|---|---|---|---|
0x00 | 0 | 0x1CE2 | IDENT: 42-byte identity block (also the seed material) |
0x90 | 0 | 0x1E2A → 0x2D04 | Seed/key security access |
0x06 | 1 | 0x21E0 | Memory read (ROM_LESEN / RAM_LESEN) |
0x07 | 1 | 0x22E8 | Program / erase / status (sub-mode in byte 3) |
0x0A | 1 | 0x1E3A | Coding checksum |
0x0D | 1 | 0x1F56 | System addresses |
0x91 | 1 | 0x1E62 | Baud-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)copies0x9Ebytes of the primitive (FUN_000017D4program /FUN_00001872erase) to0xFF8010and sets the call pointer0xFF8838/0xFF883C.
Both primitives do the following:
- Mask interrupts (
ori #0x700,SR). - Set bits
0x6000in0xFFFA4E[I: flash write-enable gate]. - Issue the JEDEC sequence to
0xAAAA/0x5554. - Poll DQ7, with DQ5 as the timeout flag, servicing the watchdog
0xFFFA27(0x55/0xAA) on each pass. On timeout they write0xF0(reset). - Clear the
0x6000bits 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:
| Address | Finalizer writes (2 bytes) | Value in valid images | Meaning |
|---|---|---|---|
0x3FFFC | 55 FF | 0x55FFAA00 | program valid |
0x0FFFC | 00 55 | 0x0055FFAA | calibration 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]) & 0xFFKey: 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 |
|---|---|
2 | Program a data block (may include the 0xFFFC trailer) |
6 | Calibration / 0x8000 path. Validates ident + Kennung and can run the full erase + reprogram (FUN_00002974, FUN_00002A70) |
0x0E | Programming 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 |
0x0F | Program 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 marker0x8000 is a two-stage programming marker:
| Value | Meaning |
|---|---|
AA55AA55 | programmed |
AA55FFFF | second half not written, so programming was interrupted |
FFFFFFFF | erased |
Session order (reconstructed) [I]
- Get the ECU into boot. Either the image is already invalid, or you start in boot after an erase cleared the trailers.
12 04 00IDENT.12 08 90 42 4D 57 <nonce>: seed.- Key frame (LEN 8, 32-bit key): unlock.
- Optional
0x91baud change (below). 0x07erase, then program blocks (≤ 255 bytes, 24-bit address, read-back verified).- Write the CRCs: program
0x37560, cal0xFFFA, CRC-16/ARC (see Checksums). Then write the trailers0x3FFFC/0xFFFClast. - 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:
| Rate | Divisor (SCCR0) |
|---|---|
| 9600 | 0x34 (reset default) |
| 19200 | 0x1A |
| 38400 | 0x0D |
| 50000 | 0x0A |
| 100000 | 0x05 |
| 125000 | 0x04 |
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
0x07sub-mode sequence the BMW programming tool uses. - Meaning of
0xFFFA4Ebits0x6000(write-enable, chip-select or Vpp). - Whether the application forwards
0x07/0x91to the boot, or the tester must force boot mode first.