Merge pull request #1 from makigumo/master

add python script
This commit is contained in:
sorgelig
2019-01-26 22:57:35 +08:00
committed by GitHub
2 changed files with 39 additions and 0 deletions

View File

@@ -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

35
injector.py Executable file
View File

@@ -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 <core.rbf> <boot.rom> <my_new_core.rbf>" % 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())