Step-by-step guide to back up, patch and write the EEPROM firmware of a 345f:2109 capture device (chip ID 0xd7), so it shows color bars, or another built-in test pattern, when no HDMI source is connected.
What the patch does
- Register
0xFEBAselects what the chip shows when there is no signal:0x08= color bars,0x00= black (the default). Other values select other built-in patterns (see Choose a pattern). - The patch adds a 12-byte handler that sets the pattern again each time the ROM clears it. See Background: the pattern handler.
- It changes 15 bytes of the EEPROM, including the checksum.
- With a source connected, the device shows the source as usual.
Choose a pattern
The chip has 17 built-in patterns. A custom image is not possible. The overview shows all 17 patterns, captured at 1280×720.

| Value | Pattern |
|---|---|
0x00 | Black (same as unpatched) |
0x01 | Solid blue |
0x02 | Solid green |
0x03 | Solid red |
0x04 | Solid white |
0x05 | White grid on black |
0x06 | Gray ramp, black to white, left to right |
0x07 | Gray ramp, black to white, top to bottom |
0x08 | 8 color bars: white, yellow, cyan, green, magenta, red, blue, black (default) |
0x09 | 16 gray steps, left to right |
0x0A | 16 gray steps, top to bottom |
0x0B | Gray steps in two rows: dark to light on top, light to dark below |
0x0C | Four ramps, top to bottom: gray, red, green, blue |
0x0D–0x10 | Fine 1-pixel stripes. They look different at each capture resolution. |
Values 0x11 and higher show black. The patch script accepts only 0x00–0x10.
Pattern sizes are fixed in pixels. At small capture sizes such as 320×240, only part of a pattern may show (for example 4 of the 8 color bars).
Before you start
| Requirement | Detail |
|---|---|
| Device | USB ID 345f:2109, chip ID 0xd7, EEPROM MD5 c9ed10fffa81b869280539862471a048. The patch script refuses any other image. |
| Host | Linux with access to /dev/hidraw* and /dev/video* (run as root). Tested on a Raspberry Pi 4 with Debian 13, aarch64. |
| Build machine | Go (tested with 1.27.3) and git, with internet access for the first build. Can be the same host. |
| Files | patch_colorbars.py, ms-tools-chipid-0xd7.patch, v4l2_grab.py. The full text is in the appendix. |
| Optional | uhubctl to power-cycle by command instead of unplugging |
Risk: writing the EEPROM changes the device permanently. If a write stops partway, the device may not boot its EEPROM firmware. Keep the backup from step 3. Restoring a backup (step 9) has not been tested.
1. Build ms-tools with chip ID 0xd7 support
ms-tools talks to the chip over its USB HID interface. Stock ms-tools identifies an MS2109 only by chip ID 0xa7 and rejects 0xd7. Patch it to accept 0xd7, then build it.
1.1 Get the source
git clone https://github.com/BertoldVdb/ms-tools cd ms-tools git checkout 967bb582c20cbe33523f3484d0aaf32801d3a4d9
This guide was tested with commit 967bb58 (2023-11-05). A newer commit may also work, but check the patch first (step 1.2).
1.2 Apply the chip ID patch
The patch is ms-tools-chipid-0xd7.patch (see the appendix). It changes one line in mshal/hal.go:
- case 0xa7: + case 0xa7, 0xd7: // local change: 0xd7 seen on a 345f:2109 device h.deviceType = 2109
Check that it applies, apply it, then confirm:
git apply --check /path/to/ms-tools-chipid-0xd7.patch # no output = OK git apply /path/to/ms-tools-chipid-0xd7.patch grep -n "0xa7, 0xd7" mshal/hal.go # must print one line
If git apply --check fails (for example on a newer commit), make the same change by hand. In mshal/hal.go, find the line case 0xa7: in function New and change it to case 0xa7, 0xd7:. With sed:
sed -i 's/^\tcase 0xa7:$/\tcase 0xa7, 0xd7:/' mshal/hal.go
Run the grep again to confirm.
The change only lets ms-tools accept the chip. It does not change any command it sends. This guide uses only the chip’s built-in ROM commands, which are the same on 0xa7 and 0xd7 chips:
| Command | Use |
|---|---|
0xB5 / 0xB6 | Read / write XDATA (RAM and registers) |
0xE5 / 0xE6 | Read / write EEPROM |
1.3 Build
You need Go (tested with 1.27.3). No other libraries are needed, because the build uses the pure-Go HID backend (-tags puregohid, CGO_ENABLED=0). The result is one static binary.
Build for the machine you are on:
cd cli CGO_ENABLED=0 go build -tags puregohid -o ms-tools-cli-d7 .
Or cross-compile on a PC for a Raspberry Pi (64-bit OS):
cd cli CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -tags puregohid -o ms-tools-cli-d7 .
For a 32-bit Raspberry Pi OS, use GOARCH=arm GOARM=7 instead. That variant was not tested.
The first build downloads the Go modules listed in go.mod.
1.4 Check the binary
file ms-tools-cli-d7 # for the Pi: "ELF 64-bit LSB executable, ARM aarch64 ... statically linked" ./ms-tools-cli-d7 --help # on the target machine: prints "Usage: ms-tools-cli-d7 <command>"
With the pure-Go backend, list-dev does not work. It prints This command is not supported using pure GO HID. Every other command needs --raw-path=/dev/hidrawN (see step 2).
1.5 Copy the files to the host
Copy the binary and the two Python scripts from the appendix to the host that has the device attached, for example:
ssh root@HOST mkdir -p /root/msdump scp ms-tools-cli-d7 /path/to/patch_colorbars.py /path/to/v4l2_grab.py root@HOST:/root/msdump/
The Python scripts need only Python 3. They use no extra packages.
2. Find the device
for h in /sys/class/hidraw/*; do echo "$(basename $h) $(grep -E 'HID_ID|HID_PHYS' $h/device/uevent | tr '\n' ' ')"; done for v in /sys/class/video4linux/video*; do echo "$(basename $v) $(cat $v/name) $(readlink -f $v/device | grep -o '[0-9.-]*:1\.0')"; done
Match the hidraw and video entries by USB path (for example 1-1.1.1). Use the first of the two video nodes. Then set:
cd /root/msdump HID=/dev/hidraw2 # change to your device VID=/dev/video4 # change to your device T="./ms-tools-cli-d7 --no-patch --eeprom-size=2048 --raw-path=$HID"
Always pass --no-patch and --eeprom-size=2048:
--no-patchstops ms-tools from installing its own code in the chip’s RAM.--eeprom-size=2048keeps 8-bit EEPROM addressing. Larger sizes return garbage on this EEPROM.
Check the chip ID. The first byte must be d7:
$T read RAM 0xf800 1
3. Back up the EEPROM
Read it twice and compare:
$T read EEPROM 0 --filename=backup_a.bin $T read EEPROM 0 --filename=backup_b.bin md5sum backup_a.bin backup_b.bin
Both MD5 values must be equal and must be c9ed10fffa81b869280539862471a048. If they differ, stop: the device runs other firmware and this patch does not fit.
Keep backup_a.bin somewhere safe, off the host.
4. Build the patched image
Set the pattern (see Choose a pattern), then build:
PAT=0x08 # color bars; change if you want another pattern python3 -I patch_colorbars.py backup_a.bin patched.bin $PAT cmp -l backup_a.bin patched.bin | wc -l # must print 15
The script checks the header magic, code length, both checksums and the original bytes before it changes anything. It prints the new code checksum.
The 15 changed bytes are the entry jump (0x031–0x032), the handler (0x41C–0x427, pattern value at 0x423) and the code checksum (0x42C–0x42D). See Background: the pattern handler.
5. Optional: test in RAM first
This applies the same change to the copy of the firmware in the chip’s RAM. It is lost at power-off and writes nothing to the EEPROM.
$T write USERCONFIG 4 0 # turn the hook off while patching
a=$((0xCFEC)); for b in bf 0b 06 90 fe ba 74 ${PAT#0x} f0 02 cd 6e; do $T write RAM $a 0x$b; a=$((a+1)); done
$T write RAM 0xcc01 0xcf
$T write RAM 0xcc02 0xec
$T write USERCONFIG 4 1 # turn the hook back on
sleep 5
$T read RAM 0xfeba 1 # must print the pattern value
python3 v4l2_grab.py $VID ram_test.jpg 640 480
ram_test.jpg must show the chosen pattern (8 vertical color bars for 0x08). Turning the hook off first stops the chip from running a half-written jump. PAT must have two hex digits, for example 0x04, not 0x4.
To only preview a pattern without the stub, write the register directly while a capture runs. The ROM clears it again within a few seconds:
$T write RAM 0xfeba $PAT
6. Write the patch to the EEPROM
Write only the 15 changed bytes, in this order:
- The new handler (unused bytes, so a partial write here is harmless).
- The checksum.
- The entry jump, last.
The loop takes each value from patched.bin, so it works for any pattern. Each byte is read back right after it is written. The loop stops at the first mismatch.
for a in 0x41c 0x41d 0x41e 0x41f 0x420 0x421 0x422 0x423 0x424 0x426 0x427 \
0x42c 0x42d \
0x031 0x032; do
v=$(printf "0x%02x" $(od -A n -t u1 -j $((a)) -N 1 patched.bin))
$T write EEPROM $a $v >/dev/null 2>&1
sleep 0.1
r=$($T read EEPROM $a 1 2>&1 | grep -v HAL)
if [ "$r" = "$v" ]; then echo "$a=$v ok"; else echo "$a MISMATCH: got $r, want $v"; break; fi
done
All 15 lines must end in ok. If one shows MISMATCH, stop. Do not power-cycle yet. Run the loop again to retry, or restore the backup (step 9).
7. Verify the EEPROM
$T read EEPROM 0 --filename=after_write.bin cmp after_write.bin patched.bin && echo "EEPROM matches patched image"
8. Power-cycle and test
The chip loads the EEPROM only at power-up. A USB reset or re-enumeration is not enough.
The simplest way is to unplug the device and plug it back in.
With uhubctl on a Raspberry Pi 4, switch off all USB ports, both the USB 2 and USB 3 sides. This also restarts every other USB device on the Pi (Ethernet is not on USB, so SSH stays up):
uhubctl -l 1-1 -a off; uhubctl -l 2 -a off sleep 8 uhubctl -l 2 -a on; uhubctl -l 1-1 -a on sleep 12
These do not cut power to the chip, although the device disappears from USB and comes back:
uhubctl -l 1-1 -p 2 -a cycle(one port of the Pi’s hub)uhubctl -f -l 1-1.2 -a off(a Raspberry Pi USB3 hub, which reports “ganged” power switching)
To check whether a power cycle really happened, write a marker to RAM first (header byte 0x0F is a safe spot), cycle, then read it back. After a real power cycle it is back to the EEPROM value:
$T write RAM 0xcbdf 0x99 # ... power cycle, find the device again (step 2) ... $T read RAM 0xcbdf 1 # must NOT print 0x99
Find the device again (step 2), because the hidraw and video numbers can change. Then check:
$T read RAM 0xcc00 3 # must print 02 cf ec sleep 5 $T read RAM 0xfeba 1 # must print the pattern value python3 v4l2_grab.py $VID bars.jpg 640 480
With no HDMI source, bars.jpg shows the chosen pattern. For 0x08 that is 8 color bars: white, yellow, cyan, green, magenta, red, blue, black.
To check that a real source still works, connect one and capture with a long stream. The device only signals “connected” to the source while it is streaming, so the source needs a few seconds to start sending:
python3 v4l2_grab.py $VID source.jpg 1280 720 450
9. Undo the patch
Not tested. Write the backup back with verification:
$T write-file --verify EEPROM 0 backup_a.bin
Then power-cycle (step 8).
Change the pattern on a patched device
Build a new image from the original backup (step 3), not from the current EEPROM. The script only accepts the unpatched image.
PAT=0x04 python3 -I patch_colorbars.py backup_a.bin patched.bin $PAT
Then run steps 6 to 8. The loop rewrites all 15 bytes; 12 of them already hold the right value. Only 0x423 and the checksum (0x42C–0x42D) change.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Failed to create HAL Unsupported device found | Stock ms-tools, or chip ID is not 0xa7/0xd7 | Use the patched ms-tools-cli-d7. Check the chip ID (step 2). |
ms-tools-cli: error: This command is not supported using pure GO HID | list-dev needs the cgo build | Find the device by hand (step 2) and pass --raw-path |
Patch script fails with not the expected 0xd7 image or unexpected bytes | Different firmware | Stop. This patch does not fit the device. |
0xFEBA reads 0x00 after the patch | The hook is off, or the patch did not load | Check $T read USERCONFIG 4 1 (must be 0x01) and $T read RAM 0xcc00 3 (must be 02 cf ec) |
v4l2_grab.py prints timeout: no frame | Another program uses the video node, or the node is wrong | Close other capture programs. Use the first video node of the device. |
timeout: no frame every time, while HID commands still work | The video output stalled. This happened twice while 0xFEBA was written many times in a row during capture. The cause is unknown. | Reset its USB port, for example uhubctl -l 1-1 -p 1 -a cycle -d 3. This fixed it both times; a full power cycle was not needed. |
Patch does not show after uhubctl | The chip never lost power; it only re-enumerated | Do a real power cycle and check with the marker (step 8) |
Background
Details of the EEPROM format behind the steps above. Where two ROM addresses are given as A / B, the first is for the 0xd7 chip (345f:2109), the second for the 0xa7 chip (534d:2109).
The pattern handler
The ROM clears register 0xFEBA in its no-signal cycle and then calls hook 0x0B. This handler sets the pattern again (0x00 = black, 0x08 = color bars, 17 values 0x00–0x10):
CFEC: BF 0B 06 CJNE R7,#0Bh,CFF5h CFEF: 90 FE BA MOV DPTR,#FEBAh CFF2: 74 xx MOV A,#xx ; pattern, EEPROM offset 0x423 CFF4: F0 MOVX @DPTR,A CFF5: 02 CD 6E LJMP CD6Eh ; original dispatcher
Checksums
- Header checksum: the 16-bit sum of bytes
0x02–0x2F, stored big-endian at0x30 + code length. - Code checksum: the 16-bit sum of the code bytes
0x30 … 0x30 + length − 1, stored big-endian 2 bytes later. - Location in the vendor images: the header checksum is at
0x6ECon an original0xa7image, and at0x42Aon an original or color-bar0xd7image. - Any header change (IDs, strings, flags) needs a new header checksum.
- Any code change needs a new code checksum.
- Changing the code length moves both checksums.
Power cycling
A USB reset or re-enumeration does not reload the EEPROM. The chip keeps its RAM, including any RAM patch, until its supply is really cut.
| Method | Real power cycle? |
|---|---|
| USB port reset or re-enumeration | no |
| Disabling the USB port in software | no |
| Switching port power off in software | not always: the supply often stays on |
| Unplugging and replugging the device | yes |
To check whether a method really cuts power, write a marker byte to an unused RAM address before it and read it back afterwards. If the marker is still there, the chip kept its power.
After any EEPROM write, check the result only after a real power cycle.
Appendix: files
The files are also in a GitHub Gist. Download them there, or save each file under the name in its heading.
ms-tools-chipid-0xd7.patch
One-line change that lets ms-tools accept chip ID 0xd7 (step 1.2).
patch_colorbars.py
Builds the patched EEPROM image (step 4). Python 3, no extra packages.
v4l2_grab.py
Grabs one MJPEG frame from a capture device, for checking the result. Python 3 on 64-bit Linux, no extra packages.