Compare commits
3 Commits
04cfb2ea0e
...
85c41eed53
Author | SHA1 | Date | |
---|---|---|---|
85c41eed53 | |||
838388caaf | |||
c0395c9a7e |
8
Makefile
8
Makefile
@ -7,6 +7,12 @@ OBJ = \
|
|||||||
|
|
||||||
all: cartridge.bin
|
all: cartridge.bin
|
||||||
|
|
||||||
|
arm9/arm9.bin:
|
||||||
|
make -C arm9/
|
||||||
|
|
||||||
|
arm7/arm7.bin:
|
||||||
|
make -C arm7/
|
||||||
|
|
||||||
cartridge.elf: $(OBJ)
|
cartridge.elf: $(OBJ)
|
||||||
|
|
||||||
TARGET = arm-none-eabi-
|
TARGET = arm-none-eabi-
|
||||||
@ -14,3 +20,5 @@ AARCH = -march=armv4t -mlittle-endian
|
|||||||
OBJARCH = -O elf32-littlearm -B armv4t
|
OBJARCH = -O elf32-littlearm -B armv4t
|
||||||
LDSCRIPT = cartridge.lds
|
LDSCRIPT = cartridge.lds
|
||||||
include common.mk
|
include common.mk
|
||||||
|
|
||||||
|
.PHONY: arm9/arm9.bin arm7/arm7.bin
|
||||||
|
@ -17,23 +17,28 @@ SECTIONS
|
|||||||
|
|
||||||
. = 0x02000000;
|
. = 0x02000000;
|
||||||
|
|
||||||
|
_arm9 = .;
|
||||||
|
|
||||||
.text.arm9 ALIGN(4) :
|
.text.arm9 ALIGN(4) :
|
||||||
{
|
{
|
||||||
KEEP(arm9/arm9.bin.o(*))
|
KEEP(*(.data.arm9/arm9.bin))
|
||||||
} AT>rom
|
} AT>rom
|
||||||
|
|
||||||
. = 0x02000000 + 0x8000;
|
. = 0x02000000 + 0x8000;
|
||||||
|
|
||||||
|
_arm7 = .;
|
||||||
|
|
||||||
.text.arm7 ALIGN(4) :
|
.text.arm7 ALIGN(4) :
|
||||||
{
|
{
|
||||||
KEEP(arm7/arm7.bin.o(*))
|
KEEP(*(.data.arm7/arm7.bin))
|
||||||
} AT>rom
|
} AT>rom
|
||||||
|
|
||||||
/DISCARD/ :
|
/DISCARD/ :
|
||||||
{
|
{
|
||||||
*(.glue_7) *(.glue_7t) *(.vfp11_veneer) *(.v4_bx)
|
*(.glue_7) *(.glue_7t) *(.vfp11_veneer) *(.v4_bx)
|
||||||
*(.ARM.attributes) *(.iplt) *(.rel.iplt) *(.igot.plt)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INCLUDE "debug.lds"
|
||||||
}
|
}
|
||||||
|
|
||||||
/* header symbols */
|
/* header symbols */
|
||||||
|
67
dump.py
Normal file
67
dump.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import struct
|
||||||
|
import sys
|
||||||
|
|
||||||
|
fields = [
|
||||||
|
("game title", 0x000, 0xc),
|
||||||
|
("game code", 0x00c, 0x4),
|
||||||
|
("maker code", 0x010, 0x2),
|
||||||
|
("main unit code", 0x012, 0x1),
|
||||||
|
("device type", 0x013, 0x1),
|
||||||
|
("device capacity", 0x014, 0x1),
|
||||||
|
("reserved 015", 0x015, 0x8),
|
||||||
|
("specific", 0x01d, 0x1),
|
||||||
|
("rom version", 0x01e, 0x1),
|
||||||
|
("reserved 01f", 0x01f, 0x1),
|
||||||
|
("arm9 resident module rom offset", 0x020, 0x4),
|
||||||
|
("arm9 resident module entry address", 0x024, 0x4),
|
||||||
|
("arm9 resident module ram address", 0x028, 0x4),
|
||||||
|
("arm9 resident module rom size", 0x02c, 0x4),
|
||||||
|
("arm7 resident module rom offset", 0x030, 0x4),
|
||||||
|
("arm7 resident module entry address", 0x034, 0x4),
|
||||||
|
("arm7 resident module ram address", 0x038, 0x4),
|
||||||
|
("arm7 resident module rom size", 0x03c, 0x4),
|
||||||
|
("file name table rom offset", 0x040, 0x4),
|
||||||
|
("file name table rom size", 0x044, 0x4),
|
||||||
|
("file allocation table rom offset", 0x048, 0x4),
|
||||||
|
("file allocation table rom size", 0x04c, 0x4),
|
||||||
|
("arm9 overlay table rom offset", 0x050, 0x4),
|
||||||
|
("arm9 overlay table rom size", 0x054, 0x4),
|
||||||
|
("arm7 overlay table rom offset", 0x058, 0x4),
|
||||||
|
("arm7 overlay table rom size", 0x05c, 0x4),
|
||||||
|
("rom control information 060", 0x060, 0x4),
|
||||||
|
("rom control information 064", 0x064, 0x4),
|
||||||
|
("banner file rom offset", 0x068, 0x4),
|
||||||
|
("secure area crc", 0x06c, 0x2),
|
||||||
|
("rom control information 06e", 0x06e, 0x2),
|
||||||
|
("arm9 auto load list ram address", 0x070, 0x4),
|
||||||
|
("arm7 auto load list ram address", 0x074, 0x4),
|
||||||
|
("rom information reserved region", 0x078, 0x8),
|
||||||
|
("application", 0x080, 0x4),
|
||||||
|
("rom header size", 0x084, 0x4),
|
||||||
|
("arm9 module parameter address", 0x088, 0x4),
|
||||||
|
("arm7 module parameter address", 0x08c, 0x4),
|
||||||
|
]
|
||||||
|
|
||||||
|
with open(sys.argv[1], 'rb') as f:
|
||||||
|
buf = f.read()
|
||||||
|
|
||||||
|
file_offset = 0
|
||||||
|
|
||||||
|
for name, offset, size in fields:
|
||||||
|
assert offset == file_offset, (hex(offset), hex(file_offset))
|
||||||
|
file_offset += size
|
||||||
|
pad = ' ' * (35 - len(name))
|
||||||
|
print(f"{name}: {pad}", end='')
|
||||||
|
if size < 16:
|
||||||
|
for i in range(size):
|
||||||
|
b = buf[offset + i]
|
||||||
|
print(f'{b:02x}', end='')
|
||||||
|
|
||||||
|
pad = ' ' * (17 * 2 - size * 2)
|
||||||
|
if size == 4:
|
||||||
|
n, = struct.unpack('<I', buf[offset:offset+size])
|
||||||
|
print(pad, f"0x{n:08x}", end='')
|
||||||
|
if size == 2:
|
||||||
|
n, = struct.unpack('<H', buf[offset:offset+size])
|
||||||
|
print(pad, f"0x{n:04x}", end='')
|
||||||
|
print()
|
29
patch.py
29
patch.py
@ -35,28 +35,39 @@ logo = [
|
|||||||
logo_b = bytes(logo)
|
logo_b = bytes(logo)
|
||||||
assert crc16_modbus(logo_b) == 0xcf56
|
assert crc16_modbus(logo_b) == 0xcf56
|
||||||
|
|
||||||
|
import struct
|
||||||
import sys
|
import sys
|
||||||
with open(sys.argv[1], 'rb') as f:
|
with open(sys.argv[1], 'rb') as f:
|
||||||
buf = bytearray(f.read())
|
buf = bytearray(f.read())
|
||||||
|
|
||||||
assert buf[0x15c] == 0x56
|
#assert buf[0x15c] == 0x56
|
||||||
assert buf[0x15d] == 0xcf
|
#assert buf[0x15d] == 0xcf
|
||||||
|
|
||||||
logo_crc = crc16_modbus(buf[0x0c0:0xc0 + 0x9c])
|
logo_crc = crc16_modbus(buf[0x0c0:0x15b+1])
|
||||||
print("logo", hex(logo_crc))
|
print("logo", hex(logo_crc))
|
||||||
assert logo_crc == 0xcf56
|
if logo_crc != 0xcf56:
|
||||||
|
for i, e in enumerate(logo):
|
||||||
header_crc = crc16_modbus(buf[0:0x15e])
|
print(i, e, hex (0xc0+i))
|
||||||
print("header", hex(header_crc))
|
buf[0x0c0 + i] = e
|
||||||
|
logo_crc = crc16_modbus(buf[0x0c0:0x15b+1])
|
||||||
|
print("logo2", hex(logo_crc))
|
||||||
|
|
||||||
secure_area_crc = crc16_modbus(buf[0x4000:0x8000])
|
secure_area_crc = crc16_modbus(buf[0x4000:0x8000])
|
||||||
print("secure area", hex(secure_area_crc))
|
print("secure area", hex(secure_area_crc))
|
||||||
|
secure_area_crc_b = struct.pack('<H', secure_area_crc)
|
||||||
|
buf[0x06c] = secure_area_crc_b[0]
|
||||||
|
buf[0x06d] = secure_area_crc_b[1]
|
||||||
|
|
||||||
import struct
|
header_crc = crc16_modbus(buf[0:0x15d + 1])
|
||||||
|
print("header", hex(header_crc))
|
||||||
header_crc_b = struct.pack('<H', header_crc)
|
header_crc_b = struct.pack('<H', header_crc)
|
||||||
|
|
||||||
buf[0x15e] = header_crc_b[0]
|
buf[0x15e] = header_crc_b[0]
|
||||||
buf[0x15f] = header_crc_b[1]
|
buf[0x15f] = header_crc_b[1]
|
||||||
|
|
||||||
with open(sys.argv[2], 'wb') as f:
|
with open(sys.argv[2], 'wb') as f:
|
||||||
f.write(buf)
|
f.write(buf)
|
||||||
|
assert len(buf) <= 131072, len(buf)
|
||||||
|
i = 131072 - len(buf)
|
||||||
|
while i > 0:
|
||||||
|
f.write(bytes([0]))
|
||||||
|
i -= 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user