From 1dd593996bc2d36a6b5c4b790001a5834e265ff4 Mon Sep 17 00:00:00 2001 From: Dan Date: Sat, 26 Jan 2019 14:45:55 +0100 Subject: [PATCH] add python script --- Readme.txt | 4 ++++ injector.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 injector.py diff --git a/Readme.txt b/Readme.txt index b0e6ae6..dacf2e8 100644 --- a/Readme.txt +++ b/Readme.txt @@ -3,4 +3,8 @@ Useful to make core with alternative boot ROM. Usage. In command prompt type: +For Windows: injector.exe core.rbf boot.rom my_new_core.rbf + +For Linux/macOS: +./injector.py core.rbf boot.rom my_new_core.rbf diff --git a/injector.py b/injector.py new file mode 100755 index 0000000..97612b9 --- /dev/null +++ b/injector.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + + +import os +import struct +import sys + +MAGIC = 'MiSTer\0\0\0\0\0\0' + + +def print_usage(): + print("Utility to inject ROM into RBF file for MiSTer.") + print("Usage: %s " % sys.argv[0]) + + +if len(sys.argv) < 3: + print_usage() + exit(1) + + +with open(sys.argv[3], 'wb') as rbf_out: + with open(sys.argv[1], 'rb') as rbf: + rbf_data = rbf.read() + if (rbf_data.startswith(MAGIC)): + print("Source core already injected with ROM.") + exit(2) + # header is 16 bytes + # 6 bytes magic + rbf_out.write(MAGIC) + # 4 bytes size of core, after which the rom follows + rbf_size = len(rbf_data) + rbf_out.write(struct.pack("i", rbf_size)) + rbf_out.write(rbf_data) + with open(sys.argv[2], 'rb') as rom: + rbf_out.write(rom.read())