Arthur Heymans has uploaded this change for review.

View Change

cpu/allwinner: Prepend the BOOT0 header to the bootblock.bin

Instead of prepending the BOOT0 header to the full coreboot.rom to
create a new file called BOOT0, prepend to the bootblock.bin that gets
included in BOOTBLOCK FMAP region.

This updates mksunxiboot to reflect that it only operates on the raw
bootblock.bin and not the final image:
- given the necessary alignment on some boot media assume that the
remainder bytes after the bootblock will be filled with 1's
- don't allow bootblocks larger than 24K as the BROM won't load these
fully anyway.

Change-Id: I974a6aaa1a340c6b26f78b9d038be0f580331831
Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
---
M src/cpu/allwinner/a10/Makefile.inc
M util/arm_boot_tools/mksunxiboot/mksunxiboot.c
2 files changed, 15 insertions(+), 10 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/11/35411/1
diff --git a/src/cpu/allwinner/a10/Makefile.inc b/src/cpu/allwinner/a10/Makefile.inc
index a6cd4b4..9f5f6ac 100644
--- a/src/cpu/allwinner/a10/Makefile.inc
+++ b/src/cpu/allwinner/a10/Makefile.inc
@@ -25,8 +25,6 @@
romstage-y += uart.c uart_console.c
ramstage-y += uart.c uart_console.c

-real-target: $(obj)/BOOT0
-
get_bootblock_size= \
$(eval bb_s=$(shell $(CBFSTOOL) $(1) print | grep bootblocksize | \
sed 's/[^0-9 ]//g')) \
@@ -46,11 +44,11 @@
# under util/arm_boot_tools/mksunxiboot. The boot ROM will load at most 24KiB of
# data to SRAM. The BOOT0 header takes 32 bytes, so bootblock is limited to
# 24KiB - 32 bytes.
-# TODO: make mksunxiboot take the bootblock size as a parameter
# TODO: print an error if bootblock is too large (maybe place ROMSTAGE at the
# exact offset needed to collide with the bootblock)
# FIXME: A10 loads 24KiB. According to Oliver other chips load a little more
#
-$(obj)/BOOT0: $(obj)/coreboot.rom $(MKSUNXIBOOT)
- @printf " BOOT0 $(subst $(obj)/,,$(^))\n"
+
+$(objcbfs)/bootblock.bin: $(objcbfs)/bootblock.raw.bin $(MKSUNXIBOOT)
+ @printf " Prepending BOOT0 header $(subst $(obj)/,,$(^))\n"
$(MKSUNXIBOOT) $(word 1, $^) $@
diff --git a/util/arm_boot_tools/mksunxiboot/mksunxiboot.c b/util/arm_boot_tools/mksunxiboot/mksunxiboot.c
index 58765b1..50771e9 100644
--- a/util/arm_boot_tools/mksunxiboot/mksunxiboot.c
+++ b/util/arm_boot_tools/mksunxiboot/mksunxiboot.c
@@ -62,7 +62,7 @@
}

/* Check sum function from sun4i boot code */
-static int fill_check_sum(struct boot_file_head *hdr, const void *boot_code)
+static int fill_check_sum(struct boot_file_head *hdr, const void *boot_code, size_t load_size)
{
size_t i;
uint8_t raw_hdr[HEADER_SIZE];
@@ -83,9 +83,14 @@
chksum += le32_to_h(raw_hdr + i);

/* Checksum the boot code */
- for (i = 0; i < hdr->length - HEADER_SIZE; i += 4)
+ for (i = 0; i < load_size; i += 4)
chksum += le32_to_h(boot_code + i);

+ /* Given that the hdr.length is aligned one can assume that the
+ remaining bytes covered by the length are all 1's */
+ for (i = 0; i < hdr->length - load_size- HEADER_SIZE; i +=4)
+ chksum += 0xffffffff;
+
/* write back check sum */
hdr->check_sum = chksum;

@@ -165,8 +170,10 @@

load_size = align(file_size, sizeof(uint32_t));

- if (load_size > SRAM_LOAD_MAX_SIZE)
- load_size = SRAM_LOAD_MAX_SIZE;
+ if (load_size > SRAM_LOAD_MAX_SIZE) {
+ fprintf(stderr, "Bootblock larger than the max 24K!\n");
+ return EXIT_FAILURE;
+ }

printf("Load size: 0x%x\n", load_size);

@@ -178,7 +185,7 @@

/* Fill the header */
fill_header(&hdr, load_size);
- fill_check_sum(&hdr, file_data);
+ fill_check_sum(&hdr, file_data, load_size);

/* Now write the header */
serialize_header(raw_hdr, &hdr);

To view, visit change 35411. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I974a6aaa1a340c6b26f78b9d038be0f580331831
Gerrit-Change-Number: 35411
Gerrit-PatchSet: 1
Gerrit-Owner: Arthur Heymans <arthur@aheymans.xyz>
Gerrit-MessageType: newchange