Reading and writing an MS42 with nfsx
nfsx is an open-source BMW flash toolkit. For the MS42 it supports:
- directmode: raw DS2 over the K-line in the car. Read (no authentication) and write (seed/key, erase, program, verify), full (program + calibration) or calibration-only. Protocol: Flashing.
- bootmode: C167 bootstrap loader on the bench. Full 512 KB read and write, for recovery. Bench-verified on an MS42 (both loader paths).
- checksum and tune: offline tools for a BIN file. Checksum verify / fix for the three MS42 CRC-16s (boot, program, calibration), and field access (VIN, ISN, immobiliser, ECU number, software version, UIF).
| Interface | K+DCAN (FTDI) cable in K-line mode, configured through EDIABAS-X (~/.config/ediabasx/config.json) |
| Detection | automatic: 0x0D hardware-reference key 111011 → MS42. --variant MS42 forces it |
| Speed | reads and writes switch to 38400 baud by default (--write-baud for writes) |
| File layout | 512 KB BIN, ECU address = file offset, the layout the XDFs expect: calibration at 0x48000. A calibration read is a tight 32 KB file |
| Block sizes | 123 bytes per read, 118 per write |
Install and cable setup: nfsx README. In short: pnpm install && pnpm -r build && pnpm link --global --filter @emdzej/nfsx-cli, then configure EDIABAS-X and run nfsx configure.
What's verified on an MS42
From the nfsx code comments and docs. "Verified" means the nfsx authors say they ran it against an MS42:
| Step | Status |
|---|---|
0x0D → 0x06 identification, 4-byte memory read | verified against an MS42 (code comment) |
0x91 baud switch payloads | verified against a real MS42 (code comment) |
Single erase at 0x11000 for both program regions, no poll between erase and first write | found and fixed on an MS42 (code comments) |
| Seed/key | same algorithm as MS43/GS20; the protocol doc lists the MS42 among the verified targets |
| Calibration-only mode | calibrationVerified: true in the MS42 profile |
| Bootmode read / erase / program / verify | bench-verified on an MS42, both MiniMon and JMG paths |
The top-level nfsx README lists directmode as bench-verified against a GS20. It doesn't record a complete MS42 directmode write, so treat the DS2 write path on an MS42 with the usual care: keep a full read and a bench bootmode setup as the fallback.
Command line (directmode)
# identify (IDENT + 0x0D dispatch)
nfsx directmode probe
# back up first: full dump (boot + program + calibration) and calibration only
nfsx directmode read -m full -o ms42_full.bin
nfsx directmode read -m calibration -o ms42_cal.bin
# write the calibration only (32 KB tight file or a full 512 KB BIN)
nfsx directmode write -m calibration -i ms42_tuned.bin --calculate-checksum
# write program + calibration
nfsx directmode write -m full -i ms42_full.bin --calculate-checksumOptions common to all directmode commands: --ediabas-config <path>, --interface <name>, --serial-port <path>, --serial-baud <rate>, --gateway <host:port>, --variant MS42, --json.
write also takes:
| Option | Default | |
|---|---|---|
-m, --mode | required | full (program 0x11000–0x3FFFF + 0x5002C–0x7FFFF, calibration 0x48000–0x4FFEF) or calibration (0x48000–0x4FFEF only) |
--calculate-checksum | off | verify the CRC-16s first and recompute them if any is stale (otherwise a stale image is flashed as-is). With a 32 KB calibration file only the calibration CRC is handled |
--write-baud <rate> | 38400 | 9600, 19200, 38400, 62500 or 125000. Drop to 9600 if writes fail with 0xB0 |
--nonce <n> | 7 | seed/key nonce, 1..23 |
--skip-verify | off | skip the read-back compare |
The boot area is never written in directmode. The 16-byte calibration trailer (0x4FFF0–0x4FFFF) and the 44-byte program header (0x50000–0x5002B) are skipped.
Offline tools
# verify the checksums of a BIN (auto-detects MS42/MS43; a 32 KB file is taken as an MS42 calibration)
nfsx checksum -f ms42_tuned.bin
# recompute and write them (in place, or to -o)
nfsx checksum -f ms42_tuned.bin --rewrite -o ms42_fixed.bin
# read / change BIN fields (no ECU needed)
nfsx tune read -f ms42_full.bin --feature vin # also: immo | isn | ecu-number | software-version | uif
nfsx tune apply -f ms42_full.bin --feature vin --value <17-character VIN> -o ms42_vin.bin
nfsx tune apply -f ms42_full.bin --feature virginize -o ms42_virgin.binMS42 field offsets nfsx uses (ms4x-tune.ts): UIF rows from 0x3C4A, ISN and the immobiliser region at 0x3EDE (virginize fills 66 bytes there with FF), ECU number at 0x3F80, software version at 0x48042 (0110C6 on a 0110C6 image). tune apply recomputes the checksums unless --skip-checksum is passed.
Variant auto-detection looks at which family's CRC slot is populated (0x4FEE0 = MS42 calibration CRC, 0x6FDE0 = MS43 program CRC) and falls back to the MS42 header pointer at 0x502CE. For a 32 KB calibration file nfsx assumes the calibration CRC at 0x4FEE0 and its seed at 0x4800C. The algorithms are on the Checksums page.
Bench recovery (bootmode)
Wiring, BOOT pin and the MS42 write gate: Flashing → C167 bootmode.
nfsx bootmode verify-bundle # check the bundled MiniMon blobs
nfsx bootmode probe -d /dev/cu.usbserial-XXXX # BSL handshake + flash chip ID
nfsx bootmode read -d /dev/cu.usbserial-XXXX -o ms42_bsl.bin
nfsx bootmode write -d /dev/cu.usbserial-XXXX -i ms42_bsl.bin --calculate-checksumOptions: --baud (default 19200), --bsl-id (default 0xC5), --loader-delay <ms>, --alt (JMG blob instead of MiniMon), --skip-verify (write). The input must be exactly 524 288 bytes.
Browser
The nfsx web app runs the same code over Web Serial (Chrome, Edge or Opera, HTTPS). Under Flashing:
- Directmode: Connect K-line, then pick Auto-detect or MS42 in the ECU selector and use Probe ECU. Read Flash takes Full or Cal mode and a baud (default 38400). Write Flash takes a
.bin, Full or Cal mode, a baud and Skip verify. The web write has no checksum option, so fix the file in the Checksum tab first. - Checksum: verify or recompute the MS42/MS43 checksums of a BIN.
- Tune: the offline field editor.
- Bootmode: the bench path.
Recommended order
directmode probe, thenread -m fulland keep the file untouched.- Edit a copy in TunerPro or tunex with the XDF.
nfsx checksum --rewrite, or pass--calculate-checksumto the write.directmode write -m calibrationfor map changes. Only use-m fullwhen the program changes.- If a write is interrupted or the ECU doesn't start afterwards, it stays in its boot software: only
0x07programming commands answer, so IDENT-based auto-detection fails. Repeat a full write with--variant MS42(nfsx doc §4.5: "Recovery is a fresh full flash") [inferred for MS42]. As a last resort, use bootmode on the bench.