diff --git a/README.md b/README.md index a86cbe8..04b04fe 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,6 @@ Tool to generate ms21xx firmware with custom VID, PID, EDID, descriptors and serial number -## TODOs - -- Support MS2109 - ## Installation You can install the package via pip: @@ -35,14 +31,14 @@ options: ## Tutorial -1. Generate a firmware file using the generator tool. If you have multiple devices, make sure to use unique serial number so that OS can properly identify the devices. +1. Generate a firmware file using the generator tool. If you have multiple devices, make sure to use unique serial number so that OS can properly identify the devices. Serial number is not supported in ms2109 yet. ``` ms21xx-firmware --chip ms2130 --vid 345f --pid 2130 --firmware-version 12345678 --video "Patched Video" --audio "Patched Audio" --edid 00ffffffffffff00215730210a663401311f0103803c2278022895a7554ea3260f50542108008100814081806ec09500a9c0d1c00100023a801871382d40582c4500c48e2100001e011d007251d01e206e28550055502100001e000000fd0017551e641e000a202020202020000000fc0048444d4920544f205553420a20015402032f715401020304101112131e223e4b454c5f6421223c3d230907078301000067030c000000003ce50e616066658c0ad08a20e02d10103e9600c48e210000188c0ad090204031200c405500c48e210000184e1f008051001e3040803700c48e21000018000000000000000000000000000000000000000000000000000072 --serial 12345678 --output output.bin ``` 1. Connect your ms21xx device to your PC. 1. Use MS21XX&91XXDownloadTool or ms-tools to patch the firmware to your device. 1. Disconnect and reconnect your device. -1. Verify if your device is properly patched. +1. Verify if your device is properly patched. If the values are not updated, try uninstalling the device and reconnect it. - Video Name diff --git a/ms21xx_firmware/generate.py b/ms21xx_firmware/generate.py index 29554ce..1c45a1a 100644 --- a/ms21xx_firmware/generate.py +++ b/ms21xx_firmware/generate.py @@ -80,7 +80,45 @@ def main(): # data generation if args.chip == "ms2109": - raise NotImplementedError + with open(MS2109, "rb") as fp: + data = fp.read() + + # convert to string for easier manipulation + data = data.hex() + + # modify the firmware data + video_data = args.video.encode() + video_len = (len(video_data) + 1).to_bytes(1) + audio_data = args.audio.encode() + audio_len = (len(audio_data) + 1).to_bytes(1) + + data = replace_at_index(data, 0x06, args.vid) + data = replace_at_index(data, 0x08, args.pid) + data = replace_at_index(data, 0x0C, args.firmware_version) + data = replace_at_index(data, 0x10, video_len.hex()) + data = replace_at_index(data, 0x11, video_data.hex()) + data = replace_at_index(data, 0x20, audio_len.hex()) + data = replace_at_index(data, 0x21, audio_data.hex()) + if args.edid: + edid_idx = data.index("00ffffffffffff00") // 2 + data = replace_at_index(data, edid_idx, args.edid) + + if args.serial: + raise NotImplementedError("Serial is not supported in ms2109 yet.") + + # change the data back to bytes + data = bytes.fromhex(data) + + # replace the checksum of firmware with correct checksum + header = data[2:48] + code = data[48:-4] + header_checksum = checksum_as_bytes(header) + code_checksum = checksum_as_bytes(code) + data = data[:-4] + header_checksum + code_checksum + + # write the generated firmware + with open(args.output, "wb") as fp: + fp.write(data) if args.chip == "ms2130": with open(MS2130, "rb") as fp: diff --git a/pyproject.toml b/pyproject.toml index ffb62ba..6612bc6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "ms21xx-firmware" -version = "1.0.0" +version = "1.0.1" dependencies = [] requires-python = ">=3" authors = [{ name = "Pradish Bijukchhe", email = "pradish@sandbox.com.np" }]