When I first built a native macOS firmware flasher for the Discovery TX-500 back in September—documented in my earlier reverse-engineering write-up—Lab599 only distributed official updaters for Windows (1.0.2) and x86_64 Linux (1.0.1).

Recently, Lab599 released Firmware Updater v1.2 for Windows alongside their first official macOS build (UpdateFirmware.app v1.2.0)—just as newer firmware images like mtrx1.31.02.fw have surfaced. That raised an immediate engineering question for Lab599 Utility:

Did Lab599 change the firmware update protocol in v1.2 / v1.2.0, or is the new macOS release simply a recompile of the exact same transfer mechanism?

To find out with certainty—not guesswork—I disassembled and compared all four official binaries side by side:

  1. Lab599-Firmware-Update-1.0.1(linux-x64) — 381,760 bytes (ELF 64-bit x86_64)
  2. Lab599-Firmware-Update-1.0.2(x86).exe — 228,864 bytes (PE32 x86)
  3. Lab599-Firmware-Update-1.2(x86).exe — 446,976 bytes (PE32 x86)
  4. UpdateFirmware.app (1.2.0, com.miltrx.updatefirmware) — 432,224 bytes (Mach-O 64-bit x86_64)

The short answer: Lab599 did nothing new at the update protocol layer. On the serial wire, 1.2 and 1.2.0 speak the exact same 57600 8N1 two-ACK BL20 protocol as 1.0.1 and 1.0.2. No changes are required in Lab599 Utility.


Binary Architecture & Toolchain

One immediate surprise from inspecting the executables is that all four official Lab599 updaters are compiled with PureBasic:

Binary Format & Arch GUI / Serial Backend Notable Metadata
1.0.1 (Linux) ELF64 x86_64 PureBasic + Qt5 + POSIX termios ERROR:1–ERROR:7
1.0.2 (Windows) PE32 i386 PureBasic + Win32 CreateFileW/DCB ERROR:1–ERROR:5
1.2 (Windows) PE32 i386 PureBasic + Win32 CreateFileW/DCB ERROR:1–ERROR:8
1.2.0 (macOS) Mach-O x86_64 PureBasic + Cocoa + POSIX termios CFBundleSignature: PURE, LSMinimumSystemVersion: 10.7, LSAppNapIsDisabled: true

Two details stand out in the macOS UpdateFirmware.app bundle:

  • Intel-only (x86_64): There is no arm64 slice in Contents/MacOS/UpdateFirmware; on Apple Silicon Macs it runs under Rosetta 2.
  • Identical PureBasic source: Disassembling the worker thread in win_1.2 (0x00401000–0x0040174c) and mac_1.2.0 (0x100002390–0x100002a0d) shows a near 1:1 instruction-level correspondence—same constants, same error switch table, same buffer sizes, and same loop bounds—compiled from the same PureBasic codebase.

The Wire Protocol: Byte-for-Byte Unchanged

Comparing the serial I/O routines across 1.0.1, 1.0.2, 1.2, and 1.2.0 confirms that every single parameter and state transition on the serial line is preserved identically:

Stage Official 1.0.1 / 1.0.2 Official 1.2 / 1.2.0 Changed?
Serial port settings 57600 (0xe100), 8N1, no parity, no flow control 57600 (0xe100), 8N1, no parity, no flow control No
Pre-header settle 100 ms delay (0x64) + drain RX buffer 100 ms delay (0x64) + drain RX buffer (up to 17 reads) No
Header transmission Raw file[0..15] (16 bytes) Raw file[0..15] (16 bytes) No
Header ACK wait Poll up to 5000 ms (0x1388), expect 0x4F 0x4B ("OK") Poll up to 5000 ms (0x1388), expect 0x4F 0x4B ("OK") No
Post-header settle 100 ms delay (0x64) + drain RX buffer 100 ms delay (0x64) + drain RX buffer (up to 17 reads) No
Payload framing Raw file[16..end], no checksums, no packet headers, no per-block ACK Raw file[16..end], no checksums, no packet headers, no per-block ACK No
Final ACK wait Poll up to 5000 ms (0x1388), expect 0x4F 0x4B ("OK") Poll up to 5000 ms (0x1388), expect 0x4F 0x4B ("OK") No
Post-flash commands None (closes serial port and file) None (closes serial port and file) No
\[\text{Open 57600 8N1} \xrightarrow{100\,\text{ms} + \text{drain}} \text{Send } \texttt{file[0:16]} \longrightarrow \text{Wait } \texttt{"OK"} \xrightarrow{100\,\text{ms} + \text{drain}} \text{Send } \texttt{file[16:end]} \longrightarrow \text{Wait } \texttt{"OK"}\]

Firmware Image Format & Header Inspection

Checking the firmware binaries themselves—from mtrx1.13.08.fw (224,792 bytes) and mtrx1.30.00.fw (246,384 bytes) up through mtrx1.31.02.fw (251,816 bytes)—confirms the .fw container is still identical: a 16-byte header starting with ASCII BL20 (42 4c 32 30 ...) followed by the raw encrypted/packed payload.

Interestingly, a literal byte search across all four official Lab599 updater binaries shows that the string BL20 does not appear anywhere in any of them. None of Lab599’s official tools validate the BL20 magic bytes, target radio model, or SHA-256 integrity before streaming bytes to the radio.


What Actually Changed in v1.2 / v1.2.0 (Client Wrapper Only)

While the bootloader protocol stayed completely untouched, Lab599 cleaned up several brittle areas in the PureBasic host application between 1.0.x and 1.2.0:

1. Chunked 8 KB Writes Instead of 1-Byte-at-a-Time Loops

  • In 1.0.1 / 1.0.2: The main payload loop read 1 byte at a time from disk (ReadByte), wrote 1 byte to the serial port (WriteSerialPortData(..., 1)), updated the progress bar, and spun on AvailableSerialPortOutput() until the output queue hit 0—with no timeout. Unplugging the USB adapter mid-flash could hang that loop indefinitely.
  • In 1.2 / 1.2.0: The entire payload (file_size - 16) is loaded into a 1,572,865-byte (0x180001) buffer and written in chunks of up to 8192 bytes (0x2000). Before each chunk, if AvailableSerialPortOutput() (implemented via ioctl(fd, TIOCOUTQ, ...) = 0x40047473 on macOS) is >= 16384 bytes (0x4000), the thread yields in 5 ms steps. Each write retries in 1 ms steps for up to 5000 iterations, and the post-transfer output-queue drain polls every 10 ms with a ~10.68 s (0x29b7 / 0x42d) timeout, returning ERROR:6 (Update failed: data transfer error or timeout.) instead of hanging.

2. Larger Serial Buffers & Explicit Size Bounds (ERROR:8)

  • Serial RX/TX buffers passed to OpenSerialPort increased from 16 B / 512 KB (0x80000) in 1.0.1–1.0.2 to 4096 B (0x1000) / 1536 KB (0x180000) in 1.2–1.2.0.
  • 1.2 / 1.2.0 adds an explicit file size check before opening the port: files smaller than 16 bytes or larger than 1536 KB abort immediately with ERROR:8 (Bad firmware size (must be 16 bytes .. 1536 KB).).

3. Input Waiting Fix (>= 2 Instead of == 2)

  • In 1.0.1 / 1.0.2: The ACK waiter checked AvailableSerialPortInput() == 2 (cmp eax, 2). If a single stray noise byte arrived alongside "OK", the loop timed out even though "OK" was already in the buffer.
  • In 1.2 / 1.2.0: The check uses AvailableSerialPortInput() >= 2 (cmp rax, 2; jl) and reads the 2-byte reply inside a 1000 ms retry loop before verifying reply[0] == 'O' && reply[1] == 'K'.

4. Threading & UI Isolation

  • In 1.2 / 1.2.0, the worker thread never touches GUI gadgets directly. It writes shared state (progress 0–99% during streaming, marquee/indeterminate flag while waiting on queue drain or ACK, 100% at completion, and error code 0–8), while the main event loop polls every 20 ms (WaitWindowEvent(20)) and blocks window close ("Firmware update is in progress. Please wait until it finishes.") until the thread finishes.

5. Serial Port Discovery

  • macOS (1.2.0): Scans /dev for cu.* first; only if zero matching cu.* devices are found does it fall back to tty.*. Entries are filtered case-insensitively to keep names containing usb, slab, wch, ch34, ftdi, serial, uart, or acm, while excluding bluetooth and debug-console.
  • Windows (1.2): Probes COM1 through COM255 at 9600 baud on startup to populate the dropdown, showing "No USB serial ports found. Connect the device and restart the program." if none open.

6. Unified Error Codes (ERROR:1 – ERROR:8)

Code Message in 1.2 / 1.2.0 Trigger Condition
0 Device updated successfully. Final "OK" (4F 4B) received
ERROR:1 Firmware file is missing or cannot be read. ReadFile / ReadData failure
ERROR:2 Can't open the serial port: <port> OpenSerialPort(..., 57600, ...) failed
ERROR:3 Device does not respond (timeout). < 2 bytes received within 5000 ms
ERROR:4 Device returned an unexpected answer. First ACK (after 16-byte header) was not "OK"
ERROR:5 Update failed: device rejected the firmware. Final ACK (after payload) was not "OK"
ERROR:6 Update failed: data transfer error or timeout. Write timeout (5000 retries) or TX drain timeout (~10.68 s)
ERROR:7 Unknown error (<code>) Fallback default case
ERROR:8 Bad firmware size (must be 16 bytes .. 1536 KB). file_size < 16 or file_size > 1,572,865 bytes

Impact on Lab599 Utility

Because the bootloader wire protocol in 1.2 / 1.2.0 is 100% identical to 1.0.1 / 1.0.2, nothing in Lab599 Utility’s flashing mechanism needs to be rewritten.

In fact, comparing Lab599’s official 1.2.0 macOS app against Lab599 Utility’s TX500Transfer.m and Lab599Utility.m highlights how much extra protection the third-party utility already provides:

  • Native Universal Binary (arm64 + x86_64) instead of x86_64-only under Rosetta 2.
  • Pre-flight integrity & model verification: Checks the BL20 header, validates firmware SHA-256 against cataloged releases, and verifies the connected radio’s identity over normal-mode CAT (ID;) before entering the bootloader—preventing accidental cross-model flashes (such as TX-500 Discovery vs. TX-500MP).
  • Battery pack safety guard: Detects BP-500/550 voltage ranges and warns about the 10-second auto-shutoff behavior in bootloader mode documented in Lab599’s manual.
  • Exclusive port lock & clean flush: Uses TIOCEXCL and tcflush(..., TCIFLUSH) before transmitting the header, plus NSProcessInfo activity assertions to inhibit system sleep.

Two Minor Optional Refinements

While no protocol update is needed, two small implementation details from 1.2.0 are worth noting for future maintenance of TX500Transfer.m:

  1. Post-header 100 ms settle: All four official Lab599 binaries insert a 100 ms pause (and RX drain) immediately after receiving the first "OK" before sending byte 16. TX500Transfer.m begins streaming byte 16 immediately after "OK". If it already works reliably on your rig, there is no urgency, though a brief settle matches the official timing budget.
  2. Chunked writes vs. per-byte TIOCOUTQ: TX500Transfer.m currently writes 1 byte at a time and polls ioctl(..., TIOCOUTQ, ...) after every byte (mirroring 1.0.1 / 1.0.2). Switching to 8192-byte writes gated by TIOCOUTQ < 16384 (with a final TIOCOUTQ == 0 drain) significantly reduces syscall overhead and keeps progress smoother on certain USB-UART kernel drivers.

Bottom Line

If you were worried that Lab599’s v1.2 / v1.2.0 release introduced encrypted handshakes, new BL20 framing, or macOS-specific bootloader quirks—rest easy. Nothing changed on the wire. Lab599 simply modernized their PureBasic wrapper and compiled it for macOS x86_64, leaving the underlying TX-500 bootloader protocol completely untouched.

73 de EP2AES