From cceb37e69490191d00459c6578e4a201a4d09214 Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Thu, 7 Dec 2023 18:20:49 +0100 Subject: [PATCH] Updated libdragon (now incorporating open source IPL3) --- Makefile | 10 ++----- src/boot/cic.c | 1 + tools/strip_debug_data.py | 58 --------------------------------------- 3 files changed, 4 insertions(+), 65 deletions(-) delete mode 100644 tools/strip_debug_data.py diff --git a/Makefile b/Makefile index 25a7d14a..3e949f64 100644 --- a/Makefile +++ b/Makefile @@ -96,23 +96,19 @@ $(@info $(shell mkdir -p ./$(OUTPUT_DIR) &> /dev/null)) $(OUTPUT_DIR)/$(PROJECT_NAME).n64: $(PROJECT_NAME).z64 @mv $< $@ -$(BUILD_DIR)/$(PROJECT_NAME)_stripped.n64: $(OUTPUT_DIR)/$(PROJECT_NAME).n64 - python3 ./tools/strip_debug_data.py $(BUILD_DIR)/$(PROJECT_NAME).elf $< $@ - @$(N64_CHKSUM) $@ > /dev/null - 64drive: $(OUTPUT_DIR)/$(PROJECT_NAME).n64 @cp $< $(OUTPUT_DIR)/menu.bin .PHONY: 64drive -ed64: $(BUILD_DIR)/$(PROJECT_NAME)_stripped.n64 +ed64: $(OUTPUT_DIR)/$(PROJECT_NAME).n64 @cp $< $(OUTPUT_DIR)/OS64.v64 .PHONY: ed64 -ed64-clone: $(BUILD_DIR)/$(PROJECT_NAME)_stripped.n64 +ed64-clone: $(OUTPUT_DIR)/$(PROJECT_NAME).n64 @cp $< $(OUTPUT_DIR)/OS64P.v64 .PHONY: ed64-clone -sc64: $(BUILD_DIR)/$(PROJECT_NAME)_stripped.n64 +sc64: $(OUTPUT_DIR)/$(PROJECT_NAME).n64 @cp $< $(OUTPUT_DIR)/sc64menu.n64 .PHONY: sc64 diff --git a/src/boot/cic.c b/src/boot/cic.c index 54455030..f817d838 100644 --- a/src/boot/cic.c +++ b/src/boot/cic.c @@ -67,6 +67,7 @@ static uint64_t cic_calculate_ipl3_checksum (uint8_t *ipl3, uint8_t seed) { } next = _get(ipl3, i); + buf[10] = _sum(_add(buf[10], data), next, i); buf[11] = _sum(buf[11] ^ data, next, i); buf[12] = _add(buf[12], buf[8] ^ data); diff --git a/tools/strip_debug_data.py b/tools/strip_debug_data.py deleted file mode 100644 index f2de0040..00000000 --- a/tools/strip_debug_data.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python3 - -import sys -from subprocess import Popen, PIPE - - -def get_symbol_address(elf, symbol): - p1 = Popen(f'readelf -s --wide {elf}'.split(), stdout=PIPE) - p2 = Popen(f'grep -m 1 {symbol}'.split(), stdin=p1.stdout, stdout=PIPE) - stdout, _ = p2.communicate() - - symbol_data = stdout.decode('UTF-8').split() - address = symbol_data[1] - name = symbol_data[7] - - if (symbol != name): - raise Exception(f'Inexact symbol name found [{symbol} != {name}]') - - return int(address, 16) - - -def get_rom_data_end_offset(elf): - ROM_ENTRY_OFFSET = 0x1000 - - libdragon_text_start = get_symbol_address(elf, '__libdragon_text_start') - rom_end = get_symbol_address(elf, '__rom_end') - - return ROM_ENTRY_OFFSET + (rom_end - libdragon_text_start) - - - -if __name__ == '__main__': - if (len(sys.argv) != 4): - print(f'Usage: python {sys.argv[0]} elf input output') - sys.exit(1) - - elf_file = sys.argv[1] - input_file = sys.argv[2] - output_file = sys.argv[3] - - ALIGN = 512 - - try: - length = get_rom_data_end_offset(elf_file) - except Exception as e: - print(e) - sys.exit(2) - - stripped_data = b'' - with open(input_file, 'rb') as f: - stripped_data = f.read(length) - - modulo = (length % ALIGN) - if (modulo > 0): - stripped_data += b'\x00' * (ALIGN - modulo) - - with open(output_file, 'wb') as f: - f.write(stripped_data)