From 6def5b0efce2531a411de38a0cbaf2746d02951a Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Mon, 23 Jan 2023 00:39:19 +0100 Subject: [PATCH] [SC64][SW] Reduced update file size --- README.md | 4 ++-- sw/bootloader/Makefile | 2 +- sw/bootloader/N64.ld | 13 ++++++------- sw/bootloader/tools/strip.py | 11 +++++++---- sw/controller/app.ld | 5 ++++- sw/controller/app.mk | 1 - sw/controller/common.mk | 2 +- sw/controller/loader.mk | 1 - sw/controller/primer.mk | 1 - 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f88240e..3dff0e8 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ - Enhanced [UltraCIC_C](https://github.com/jago85/UltraCIC_C) emulation with automatic region switching and programmable seed/checksum values - PC app for communicating with flashcart (game/save data upload/download, feature enable control and debug terminal) - [UNFLoader](https://github.com/buu342/N64-UNFLoader) support - - Initial board programming via UART header on board or dedicated JTAG/SWD interfaces - - Software and firmware update via USB interface + - Initial programming via UART header or dedicated JTAG/SWD interfaces + - Software and firmware updatable via USB interface - 3D printable plastic shell --- diff --git a/sw/bootloader/Makefile b/sw/bootloader/Makefile index 2e8257b..145d929 100644 --- a/sw/bootloader/Makefile +++ b/sw/bootloader/Makefile @@ -70,7 +70,7 @@ $(BUILD_DIR)/bootloader.elf: $(OBJS) N64.ld $(BUILD_DIR)/bootloader.bin: $(BUILD_DIR)/bootloader.elf tools/strip.py @$(OBJCOPY) -O binary $< $@ @chksum64 $@ > /dev/null - @$(PYTHON) tools/strip.py $@ + @$(PYTHON) tools/strip.py $@ 1024 $(BUILD_DIR)/bootloader.hex: $(BUILD_DIR)/bootloader.bin @$(OBJCOPY) -I binary -O ihex $< $@ diff --git a/sw/bootloader/N64.ld b/sw/bootloader/N64.ld index a44e160..5044985 100644 --- a/sw/bootloader/N64.ld +++ b/sw/bootloader/N64.ld @@ -45,6 +45,12 @@ SECTIONS { _ebss = .; } > ram + .fill : { + FILL(0xFF); + BYTE(0xFF); + . = ORIGIN(rom) + LENGTH(rom); + } > rom + _sheap = .; . = ORIGIN(ram) + LENGTH(ram) - __exception_stack_size - __stack_size; _eheap = .; @@ -55,13 +61,6 @@ SECTIONS { . += __stack_size; _sp = .; - .fill : { - . = ALIGN(1024) - 4; - LONG(0xDEADBEEF); - FILL(0xFFFFFFFF); - . = ORIGIN(rom) + LENGTH(rom); - } > rom - /DISCARD/ : { *(.MIPS.*) } diff --git a/sw/bootloader/tools/strip.py b/sw/bootloader/tools/strip.py index 0693835..568e0ed 100644 --- a/sw/bootloader/tools/strip.py +++ b/sw/bootloader/tools/strip.py @@ -5,18 +5,21 @@ import sys if __name__ == "__main__": - if (len(sys.argv) != 2): - print(f"Usage: python {sys.argv[0]} file_path") + if (len(sys.argv) != 3): + print(f"Usage: python {sys.argv[0]} file_path align") sys.exit(1) file = sys.argv[1] + align = int(sys.argv[2], base=0) try: data = b'' with open(file, 'rb') as f: - data = f.read() + data = f.read().strip(b'\xFF') with open(file, 'wb') as f: - f.write(data.strip(b'\xFF')) + modulo = (len(data) % align) if (align > 0) else 0 + data += b'\xFF' * ((align - modulo) if (modulo != 0) else 0) + f.write(data) except FileNotFoundError: print(f"Couldn't open file \"{file}\"") sys.exit(2) diff --git a/sw/controller/app.ld b/sw/controller/app.ld index bea3e0c..dbcb537 100644 --- a/sw/controller/app.ld +++ b/sw/controller/app.ld @@ -6,6 +6,8 @@ MEMORY { ENTRY(Reset_Handler) +__bin_align = 8; + SECTIONS { .loader : { . = ALIGN(4); @@ -53,7 +55,8 @@ SECTIONS { . = ALIGN(4); *(.rodata) *(.rodata*) - . = ALIGN(4); + FILL(0xFF); + . = ALIGN(__bin_align); } > code _estack = ORIGIN(ram) + LENGTH(ram); diff --git a/sw/controller/app.mk b/sw/controller/app.mk index 6e67cdc..e2da4ec 100644 --- a/sw/controller/app.mk +++ b/sw/controller/app.mk @@ -2,7 +2,6 @@ EXE_NAME = app BUILD_DIR = build/app LD_SCRIPT = app.ld -PAD_TO = 0x08008000 SRC_FILES = \ app.S \ diff --git a/sw/controller/common.mk b/sw/controller/common.mk index 5e6fdc3..b76e5ee 100644 --- a/sw/controller/common.mk +++ b/sw/controller/common.mk @@ -29,7 +29,7 @@ $(BUILD_DIR)/$(EXE_NAME).elf: $(OBJS) $(LD_SCRIPT) @$(OBJDUMP) -S -D $@ > $(BUILD_DIR)/$(EXE_NAME).lst $(BUILD_DIR)/$(EXE_NAME).bin: $(BUILD_DIR)/$(EXE_NAME).elf - $(OBJCOPY) -O binary --gap-fill 0xFF --pad-to $(PAD_TO) $< $@ + $(OBJCOPY) -O binary --gap-fill 0xFF $< $@ $(BUILD_DIR)/$(EXE_NAME).hex: $(BUILD_DIR)/$(EXE_NAME).bin @$(OBJCOPY) -I binary -O ihex $< $@ diff --git a/sw/controller/loader.mk b/sw/controller/loader.mk index 0637f73..4773b3e 100644 --- a/sw/controller/loader.mk +++ b/sw/controller/loader.mk @@ -2,7 +2,6 @@ EXE_NAME = loader BUILD_DIR = build/loader LD_SCRIPT = loader.ld -PAD_TO = 0x08001000 SRC_FILES = \ loader.S \ diff --git a/sw/controller/primer.mk b/sw/controller/primer.mk index 1abc92f..3d1dbcf 100644 --- a/sw/controller/primer.mk +++ b/sw/controller/primer.mk @@ -2,7 +2,6 @@ EXE_NAME = primer BUILD_DIR = build/primer LD_SCRIPT = primer.ld -PAD_TO = 0x20002000 SRC_FILES = \ primer.S \