Skip to content

Commit fe7faf7

Browse files
committed
Added dependencies for eboot.ld and Makefile to Makefile.
Updated eboot.ld to not fill with zeros through the CS field on its way to the CRC. Added size test to elf2bin.py
1 parent 9e9515b commit fe7faf7

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

bootloaders/eboot/Makefile

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ CFLAGS += $(INC)
2929

3030
CFLAGS += $(UZLIB_FLAGS)
3131

32-
LDFLAGS += -nostdlib -Wl,--no-check-sections -Wl,--gc-sections -umain
32+
LDFLAGS += -nostdlib -Wl,--no-check-sections -Wl,--gc-sections -umain -Wl,-Map,$(@:.elf=.map)
3333

3434
LD_SCRIPT := -Teboot.ld
3535

36-
APP_OUT:= eboot.elf
37-
APP_AR := eboot.a
38-
APP_FW := eboot.bin
36+
APP_OUT := eboot.elf
37+
APP_AR := eboot.a
38+
APP_FW := eboot.bin
3939

4040

4141
all: $(APP_OUT)
@@ -49,13 +49,14 @@ tinfgzip.o: $(UZLIB_PATH)/tinfgzip.c $(UZLIB_PATH)/uzlib.h $(UZLIB_PATH)/uzlib_c
4949
$(APP_AR): $(TARGET_OBJ_PATHS) tinflate.o tinfgzip.o
5050
$(AR) cru $@ $^
5151

52-
$(APP_OUT): $(APP_AR)
52+
$(APP_OUT): $(APP_AR) eboot.ld | Makefile
5353
$(LD) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group -Wl,--whole-archive $(APP_AR) -Wl,--end-group -o $@
5454

5555
clean:
5656
rm -f *.o
5757
rm -f $(APP_AR)
5858
rm -f $(APP_OUT)
59+
rm -f *.map
5960

6061

6162
.PHONY: all clean default

bootloaders/eboot/eboot.elf

136 Bytes
Binary file not shown.

bootloaders/eboot/eboot.ld

+18-6
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,24 @@ SECTIONS
154154
*(.gnu.linkonce.b.*)
155155
. = ALIGN (8);
156156
_bss_end = ABSOLUTE(.);
157-
/* CRC stored in last 8 bytes */
158-
ASSERT((. < 4096 - 8), "Error: No space for CRC in bootloader sector.");
159-
. = _stext + 4096 - 8;
160-
_crc_size = .;
161-
. = . + 4;
162-
_crc_val = .;
157+
_free_space = 4096 - 17 - (. - _stext);
158+
/*
159+
The boot loader checksum must be before the CRC, which is written by elf2bin.py.
160+
This leaves 16 bytes after the checksum for the CRC placed at the end of the
161+
4096-byte sector. */
162+
_cs_here = (ALIGN((. + 1), 16) == ALIGN(16)) ? (ALIGN(16) - 1) : (. + 0x0F);
163+
164+
/*
165+
The filling (padding) and values for _crc_size and _crc_val are handled by
166+
elf2bin.py. With this, we give values to the symbols without explicitly
167+
assigning space. This avoids the linkers back *fill* operation that causes
168+
trouble.
169+
170+
The CRC info is stored in last 8 bytes. */
171+
_crc_size = _stext + 4096 - 8;
172+
_crc_val = _stext + 4096 - 4;
173+
ASSERT((4096 > (17 + (. - _stext))), "Error: No space for CS and CRC in bootloader sector.");
174+
ASSERT((_crc_size > _cs_here), "Error: CRC must be located after CS.");
163175
} >iram1_0_seg :iram1_0_phdr
164176

165177
.lit4 : ALIGN(4)

tools/elf2bin.py

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ def write_bin(out, elf, segments, to_addr, flash_mode, flash_size, flash_freq, p
9393
out.write(bytearray([0]))
9494
out.write(bytearray([checksum]))
9595
if to_addr != 0:
96+
if total_size + 8 > to_addr:
97+
raise Exception('Bin image of ' + elf + ' is too big, actual size ' + str(total_size + 8) + ', target size ' + str(to_addr) + '.')
9698
while total_size < to_addr:
9799
out.write(bytearray([0xaa]))
98100
total_size += 1

0 commit comments

Comments
 (0)