diff --git a/bootloaders/eboot/Makefile b/bootloaders/eboot/Makefile index dc28219b6..ff4489e47 100644 --- a/bootloaders/eboot/Makefile +++ b/bootloaders/eboot/Makefile @@ -29,13 +29,13 @@ CFLAGS += $(INC) CFLAGS += $(UZLIB_FLAGS) -LDFLAGS += -nostdlib -Wl,--no-check-sections -Wl,--gc-sections -umain +LDFLAGS += -nostdlib -Wl,--no-check-sections -Wl,--gc-sections -umain -Wl,-Map,$(@:.elf=.map) LD_SCRIPT := -Teboot.ld -APP_OUT:= eboot.elf -APP_AR := eboot.a -APP_FW := eboot.bin +APP_OUT := eboot.elf +APP_AR := eboot.a +APP_FW := eboot.bin all: $(APP_OUT) @@ -49,13 +49,14 @@ tinfgzip.o: $(UZLIB_PATH)/tinfgzip.c $(UZLIB_PATH)/uzlib.h $(UZLIB_PATH)/uzlib_c $(APP_AR): $(TARGET_OBJ_PATHS) tinflate.o tinfgzip.o $(AR) cru $@ $^ -$(APP_OUT): $(APP_AR) +$(APP_OUT): $(APP_AR) eboot.ld | Makefile $(LD) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group -Wl,--whole-archive $(APP_AR) -Wl,--end-group -o $@ clean: rm -f *.o rm -f $(APP_AR) rm -f $(APP_OUT) + rm -f *.map .PHONY: all clean default diff --git a/bootloaders/eboot/eboot.elf b/bootloaders/eboot/eboot.elf index 7ef036b4d..0d862f6a9 100755 Binary files a/bootloaders/eboot/eboot.elf and b/bootloaders/eboot/eboot.elf differ diff --git a/bootloaders/eboot/eboot.ld b/bootloaders/eboot/eboot.ld index b969bcf06..c664daf66 100644 --- a/bootloaders/eboot/eboot.ld +++ b/bootloaders/eboot/eboot.ld @@ -154,12 +154,24 @@ SECTIONS *(.gnu.linkonce.b.*) . = ALIGN (8); _bss_end = ABSOLUTE(.); - /* CRC stored in last 8 bytes */ - ASSERT((. < 4096 - 8), "Error: No space for CRC in bootloader sector."); - . = _stext + 4096 - 8; - _crc_size = .; - . = . + 4; - _crc_val = .; + _free_space = 4096 - 17 - (. - _stext); +/* +The boot loader checksum must be before the CRC, which is written by elf2bin.py. +This leaves 16 bytes after the checksum for the CRC placed at the end of the +4096-byte sector. */ + _cs_here = (ALIGN((. + 1), 16) == ALIGN(16)) ? (ALIGN(16) - 1) : (. + 0x0F); + +/* +The filling (padding) and values for _crc_size and _crc_val are handled by +elf2bin.py. With this, we give values to the symbols without explicitly +assigning space. This avoids the linkers back *fill* operation that causes +trouble. + +The CRC info is stored in last 8 bytes. */ + _crc_size = _stext + 4096 - 8; + _crc_val = _stext + 4096 - 4; + ASSERT((4096 > (17 + (. - _stext))), "Error: No space for CS and CRC in bootloader sector."); + ASSERT((_crc_size > _cs_here), "Error: CRC must be located after CS."); } >iram1_0_seg :iram1_0_phdr .lit4 : ALIGN(4) diff --git a/tools/elf2bin.py b/tools/elf2bin.py index 607d07405..9c4a1b2ce 100755 --- a/tools/elf2bin.py +++ b/tools/elf2bin.py @@ -93,6 +93,8 @@ def write_bin(out, elf, segments, to_addr, flash_mode, flash_size, flash_freq, p out.write(bytearray([0])) out.write(bytearray([checksum])) if to_addr != 0: + if total_size + 8 > to_addr: + raise Exception('Bin image of ' + elf + ' is too big, actual size ' + str(total_size + 8) + ', target size ' + str(to_addr) + '.') while total_size < to_addr: out.write(bytearray([0xaa])) total_size += 1