Skip to content

Flashing ​

There are two ways to write an MS42:

  1. DS2 programming over the K-line (in-car). This is the path BMW's WinKFP uses with the .0PA program and .0DA data files, and the one nfsx re-implements as directmode. It works through the ECU's own boot software: security access, block erase, block write, poll.
  2. C167 bootmode (BSL) on the bench. This bypasses the BMW software completely and is the recovery path for an ECU that no longer boots. nfsx's bootmode is bench-verified on an MS42.

The production diagnostic SGBD MS420DS0 has no erase or write jobs. It only has CHECK_FLASH_PROG_SG, which runs seed/key and the programming-status poll 07 0F (see DS2). Everything in the DS2 section below is how nfsx does it (packages/nfsx-directmode/src/session.ts, ecu-tables.ts, seed-key.ts). The prose spec is nfsx's docs/raw-ds2-flashing.md §3 and §5.2. Where the prose and the code disagree, this page follows the code. [V] = implemented in nfsx code, with a code comment that it was verified against an MS42; [I] = inferred, or implemented without an MS42-specific note.

WARNING

Flash only an image with valid checksums (see Checksums), on a stable 13–14 V supply. An interrupted erase or write leaves the ECU in its boot software, and only a fresh write (or bootmode) brings it back.

Summary ​

Address0x12, 9600 8E1, then a baud switch (nfsx default 38400) [V]
Detection0D → pointer at bytes 57–59 → 06 read of 8 bytes → 111011… = MS42 [V]
Read06 00 <addr24> <n> memory read, no authentication, ≤ 123 bytes per request [V]
Unlock90 "BMW" <nonce> seed → 4-byte key → 90 k0 k1 k2 k3 [I: same code path as MS43]
Erase07 06 <addr24> 00: one erase at 0x11000 for both program regions, one at 0x48000 for the calibration [V]
Write07 02 <addr24> <n> <data>, n ≤ 118, runs of FF FF skipped [V]
Poll07 0F <addr24> 00, repeated while the status is 0xA1 [V]
Verifyread back with 06 and compare [V]

Step by step (nfsx writeFlash) ​

1. Identify ​

nfsx sends IDENT (12 04 00). Unless --variant is given, it then runs the hardware-reference dispatch: 12 04 0D, takes the 24-bit pointer at response bytes 57–59, and reads 8 bytes there with 12 09 06 00 <ptr> 08. The first six ASCII characters select the profile: 111011 → MS42 (111430 → MS43, G2210_ → GS20). The 4-byte form of the read (with the 00 segment byte) is noted in the code as "verified against MS42" [V]. The same 111011 prefix appears in the ZL_Referenz of every MS42 .0PA and .0DA file, see Hardware.

The input file must be a 512 KB (0x80000) BIN. For calibration-only mode, a 32 KB (0x8000) calibration dump (what read -m calibration produces) is also accepted [V].

2. Security access ​

TX  12 08 90 42 4D 57 07 D5      seed request, nonce 7 (nfsx default; must be 1..23)
RX  12 2E A0 <43 bytes> XX       LEN 0x2E = seed material
    (RX LEN 0x05 → already unlocked, skip the key)
TX  12 08 90 k0 k1 k2 k3 XX      key, same opcode 0x90
RX  12 05 A0 .. XX

The key is computed from the whole received frame f (f[0] = address, f[1] = 0x2E):

key[i] = ( f[(nonce + i) mod f[1]] + f[18 + i] + f[41 + i] ) & 0xFF      i = 0..3

nfsx uses one algorithm for MS42, MS43 and GS20. Its docs list the MS42 (HWNR 1430844) among the ECUs the SEED/KEY section was verified on [I: no MS42-specific comment in the code]. The SGBD jobs SEED_KEY, CHECK_FLASH_PROG_SG and STEUERN_TESTPLATZ use the same request shape, see DS2.

3. Baud switch ​

After unlocking, nfsx sends 91 00 96 00 01 (38400) and reconfigures its UART. Other rates: 91 00 25 80 01 (9600), 91 00 4B 00 01 (19200), 91 00 F4 24 01 (62500), 91 01 E8 48 01 (125000). The code says these payloads were "verified against a real MS42" [V]. nfsx switches back to 9600 in a finally block, so the next session can IDENT. It notes that the reference tooling its write path was modelled on doesn't change the baud during writes. If 0xB0 rejections show up only at high rates, use --write-baud 9600.

4. Regions ​

The MS42 maps 1:1: ECU address = BIN offset [V].

ModeECU range = BIN offsetErase atBytes
full0x11000–0x3FFFF0x11000192 512 (lower program)
full0x5002C–0x7FFFF(same erase)196 564 (upper program)
full, calibration0x48000–0x4FFEF0x4800032 752 (calibration)
calibration0x48000–0x4FFEF0x4800032 752

The write ranges skip 0x4FFF0–0x4FFFF and 0x50000–0x5002B. nfsx calls them the calibration "CRC trailer" and the program "header". In a stock 0110C6 image both start with the same four bytes in mirrored order (42 24 48 90 at 0x4FFF0, 90 48 24 42 at 0x50000), and the calibration CRC itself sits at 0x4FEE0, inside the written range. So these look like block-valid markers that the boot software writes itself, not checksums [I]. The boot area 0x00000–0x0BFFF is never written over DS2.

One erase for both program regions. The erase at 0x11000 wipes everything between the boot area and the calibration block, so the lower and upper program regions share it. Issuing a second erase at 0x5002C would destroy the lower region just written. nfsx's comment records exactly that failure (a verify mismatch at 0x11000) [V]. How the boot software maps these erase addresses onto the Am29F400BB's sectors isn't documented; the 64 KB sector 0x40000–0x4FFFF holds both the unused 0x40000–0x47FFF and the calibration [I].

5. Erase, write, poll ​

For each erase group, in table order (program first, then calibration in full mode):

(first group only) poll   12 09 07 0F 01 10 00 00 02      wait until status != A1
erase                     12 09 07 06 01 10 00 00 0B      single attempt, 60 s timeout
                          RX status A0, result byte f[8] = 01
write ×N                  12 LL 07 02 AH AM AL nn <nn bytes> XX     LL = nn + 9, nn ≤ 118
                          RX status A0, f[8] = 01
poll                      12 09 07 0F 01 10 00 00 02      loose between groups,
                                                           strict (f[8] must be 01) after the last

For the calibration group the address bytes are 04 80 00: erase 12 09 07 06 04 80 00 00 9E, poll 12 09 07 0F 04 80 00 00 97. A calibration-only write runs just that group, with the pre-poll at 0x48000.

Ordering rules nfsx found by bench testing:

  • No poll between erase and the first write. That makes the first write fail with 0xB0, "verified empirically against MS42" [V].
  • No pre-poll before the second group. An extra 07 0F before the calibration erase makes the next write fail with result 0x02. That one was found on an MS43 in full mode [I for MS42].
  • Never retry an erase while the chip may still be busy. The erase frame gets one attempt with a 60 s read timeout.
  • FF FF skipping. Leading FF FF pairs are skipped and trailing pairs are trimmed from each block. The address still advances, because erased flash already reads FF.

Result byte (f[8]) values nfsx decodes: 01 OK, 02 write-protect / generic erase failure, 09 address out of range, 0A alignment, 0B not erased, 0C voltage out of spec, 0D programming timeout, 0E protection bit, 0F verify / CRC mismatch [V: table in nfsx; the ECU-side meaning of each code is I]. The SGBD's CHECK_FLASH_PROG_SG reads the same byte 8 of the 07 0F response.

6. Verify ​

Unless --skip-verify is given, nfsx reads every written region back with 06 (123-byte chunks) and compares only the bytes it actually sent. Skipped FF runs aren't compared [V]. According to nfsx's docs, the boot software checks the image's checksums before it starts the new program [I]. An image with stale checksums flashes cleanly but won't run. Fix it first with nfsx checksum --rewrite, or pass --calculate-checksum to the write.

Read path ​

Reads need no authentication [V]. A full read covers 0x00000–0x0BFFF (boot), 0x11000–0x3FFFF, 0x48000–0x4FFFF (including the trailer) and 0x50000–0x7FFFF (including the header), each at the same file offset. Everything else in the 512 KB file stays FF: 0x0C000–0x10FFF and 0x40000–0x47FFF. A calibration read is the 32 KB block 0x48000–0x4FFFF as a tight file. See Memory map.

Known inconsistencies in the nfsx docs ​

These disagree with the code. This page follows the code:

  • raw-ds2-flashing.md §3.3–3.4: erase and poll frames are 9 bytes (LEN = 0x09: a 6-byte payload 07 06 A A A 00 plus address, length and XOR), not LEN = 8. Write frames are LEN = n + 9, not n + 7.
  • nfsx-directmode/README.md ("Full vs calibration mode") says the MS42 calibration mode writes "upper region 0x5002C-0x7FFFF only". The code writes 0x48000–0x4FFEF, and the same README's variant list says so too.
  • raw-ds2-flashing.md §5.2 calls the lower program 192 KB. 0x11000–0x3FFFF is 188 KB (192 512 bytes).
  • raw-ds2-flashing.md §5.4 gives the MS42 boot-CRC seed at 0x3FF6. The checksum code (ms4x-checksum.ts) reads it from 0x3FE6. See Checksums.

C167 bootmode recovery ​

Bootmode uses the C167's mask-ROM bootstrap loader. The DME is on the bench, the BOOT pin on the PCB is grounded at power-on, and the host uploads a 32-byte primary loader over the K-line. That loader pulls in a secondary loader with flash primitives. No BMW software runs, there's no seed/key and no region table, so the full 512 KB, including the boot area, can be read, erased and written. That's why it recovers an ECU whose DS2 boot no longer answers. Details: nfsx docs/bootmode.md.

Wiring+12 V → X60001/7 and X60004/26, GND → X60001/4, K-line → X60004/32 (see Pinout), plus BOOT pin to ground on the PCB
Serial8N1, host-chosen baud (the BSL auto-bauds on a 0x00 byte), nfsx default 19200
BSL ID0xC5 (C167CR), the nfsx default (--bsl-id)
MS42 specificsP3.7 must be driven low (active-low write-enable gate on the PCB). Writes go to segment 0x10, reads to 0x08. A19–A23 aren't connected, so the segments alias. MiniMon's bundled A29F400B.hex driver writes to segment 0x80, which is why nfsx uses its own stubs
Path A (default)MiniMon kernel plus nfsx's own erase, program and probe stubs. Probes the Am29F400BB chip ID, erases sector by sector (11 sectors) and programs in 128-byte chunks
Path B (--alt)JMG blob: full-chip erase, page-granular read and program (32 × 16 KB). Its SPI EEPROM commands aren't used on the MS42
Statusboth paths: full erase, 512 KB program and byte-identical read-back bench-verified on an MS42 (2026-05-31 / 2026-06-01 per nfsx docs) [V]
bash
nfsx bootmode probe -d /dev/cu.usbserial-XXXX
nfsx bootmode read  -d /dev/cu.usbserial-XXXX -o ms42_full.bin
nfsx bootmode write -d /dev/cu.usbserial-XXXX -i ms42_full.bin --calculate-checksum

A bootmode write takes a 512 KB image in file layout, the same layout a DS2 full read produces. Because the boot area is written too, the image must contain a valid boot area and whatever the ECU keeps in the ranges DS2 doesn't read: use a full bootmode read of a healthy ECU, not a DS2 dump with FF in 0x0C000–0x10FFF [I].

See Reading / writing with nfsx for the commands.

XDFs (GPL-3.0) and patchlist by the MS4x Dev Team. Not affiliated with BMW or Siemens.