Skip to content

Flashing ​

There are two ways to write an MS43:

  1. DS2 programming over the K-line (in-car). This is the path BMW's WinKFP uses with the .0PA program files, and the one nfsx re-implements as directmode. It works through the ECU's own boot software: security access, sector 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.

The production diagnostic SGBD MS430DS0 has no flash jobs. Erase, write and poll are DS2 sub-commands of 0x07 that only programming tools send. 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 in nfsx's docs/raw-ds2-flashing.md §3–§5.3. [V] = implemented in nfsx code and exercised against hardware per the nfsx comments; [I] = inferred or documented but not tested on an MS43.

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 full flash (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 → 111430… = MS43 [V]
Read06 memory read, no authentication, ≤ 123 bytes per request [V]
Unlock90 "BMW" <nonce> seed → 4-byte key → 90 k0 k1 k2 k3 [V]
Erase07 06 <addr24> 00, one telegram per erase block (0x90000 program, 0x70000 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: 111430 → MS43 (111011 → MS42, G2210_ → GS20) [V]. The same 111430 prefix appears in the ZL_Referenz of every MS43 .0PA file, see Hardware.

The input file must be a 512 KB (0x80000) BIN. For calibration-only mode, a 64 KB 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) [V]:

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

The SGBD job SEED_KEY uses the same request shape with a clock-derived index (Z_ZAHL), 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). It switches back to 9600 in a finally block, so the next session can IDENT [V]. nfsx 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 ​

ECU addresses are what goes on the wire. The program area sits at ECU 0x90000, which is BIN offset 0x10000 [V]:

ModeECU rangeBIN offsetErase atBytes
full0x90000–0xEFFEF0x100000x90000393 200 (program)
full, calibration0x70000–0x7FFEE0x700000x7000065 519 (calibration)

The write ranges stop short of the checksum trailers (0xEFFF0–0xEFFFF, 0x7FFEF–0x7FFFF). The boot sector 0x00000–0x0BFFF is never written over DS2. One erase command clears the whole block: the boot software erases all flash sectors in the range itself [V for MS43 per nfsx comments; sector mapping I].

5. Erase, write, poll ​

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

(first group only) poll   12 09 07 0F 09 00 00 00 1A      wait until status != A1
erase                     12 09 07 06 09 00 00 00 13      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 09 00 00 00 1A      loose between groups,
                                                           strict (f[8] must be 01) after the last

(For the calibration group the address bytes are 07 00 00: erase 12 09 07 06 07 00 00 00 1D.)

nfsx found several ordering rules by bench testing [V]:

  • No pre-poll before the second group. An extra 07 0F before the calibration erase makes the next write fail with result 0x02 ("verified empirically on MS43 full mode").
  • No poll between erase and the first write. That makes the first write fail with 0xB0 (seen on an 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].

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, the boot software also 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), 0x90000–0xEFFFF → BIN 0x10000, and 0x70000–0x7FFFF. Everything else in the 512 KB file stays FF, including 0x0C000–0x0FFFF, which the C167's internal RAM/SFR window hides. A calibration read is the 64 KB block 0x70000–0x7FFFF as a tight file. See Memory map.

Known inconsistencies in the nfsx prose doc ​

raw-ds2-flashing.md sometimes disagrees with the code. This page follows the code:

  • Erase and poll frames are 9 bytes (LEN = 0x09): a 6-byte payload 07 06 A A A 00 plus address, length and XOR. The doc says LEN = 8.
  • Write frames are LEN = n + 9. The doc says n + 7.
  • The block size is 118 bytes per write and 123 per read for MS43 (protocol class p). Doc §4.3.2 mentions 246, which is the GS20 value.

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 sector, 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 (nfsx)+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 (BSL auto-bauds on a 0x00 byte), nfsx default 19200
BSL IDnfsx expects 0xC5 (C167CR) by default (--bsl-id)
Path A (default)MiniMon kernel plus nfsx's own erase, program and probe stubs. Erases sector by sector (Am29F400BB, 11 sectors) and programs in 128-byte chunks
Path B (--alt)JMG blob: full-chip erase, native read/program, plus SPI EEPROM read/write (0xA8/0xA9, MS43 only)
Statusnfsx reports full erase, program and verify bench-verified on an MS42. MS43 is listed as supported, but its docs don't record a bench run [I for MS43]
bash
nfsx bootmode probe -d /dev/cu.usbserial-XXXX
nfsx bootmode read  -d /dev/cu.usbserial-XXXX -o ms43_full.bin
nfsx bootmode write -d /dev/cu.usbserial-XXXX -i ms43_full.bin --calculate-checksum

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

See Reading / writing with nfsx for the commands.