armv7: Place reset vector + CBFS header + bootblock dynamically

This replaces hard-coded bootblock offsets using the new scheme.
The assembler will place the initial branch instruction after BL1,
skip 2 aligned chunks, and place the remaining bootblock code after.

It will also leave an anchor string, currently 0xdeadbeef which
cbfstool will find. Once found, cbfstool will place the master CBFS
header at the next aligned offset.

Here is how it looks:

             0x0000 |--------------|
                    |     BL1      |
             0x2000 |--------------|
                    |    branch    |
    0x2000 + align  |--------------|
                    |  CBFS header |
0x2000 + align * 2  |--------------|
                    |   bootblock  |
                    |--------------|

TODO: The option for alignment passed into cbfstool has always been
64. Can we set it to 16 instead?

Change-Id: Icbe817cbd8a37f11990aaf060aab77d2dc113cb1
Signed-off-by: David Hendricks <dhendrix@chromium.org>
Reviewed-on: http://review.coreboot.org/2148
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
This commit is contained in:
David Hendricks 2013-01-14 20:58:50 -08:00 committed by Ronald G. Minnich
parent 3d7344a7a1
commit 0b23d47ffd
3 changed files with 28 additions and 20 deletions

View File

@ -48,8 +48,7 @@ prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
$(obj)/coreboot.pre1: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(CBFSTOOL) $(obj)/coreboot.pre1: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(CBFSTOOL)
$(CBFSTOOL) $@.tmp create -m armv7 -s $(CONFIG_COREBOOT_ROMSIZE_KB)K \ $(CBFSTOOL) $@.tmp create -m armv7 -s $(CONFIG_COREBOOT_ROMSIZE_KB)K \
-B $(objcbfs)/bootblock.bin -a 64 \ -B $(objcbfs)/bootblock.bin -a 64
-o $$(( $(CONFIG_ROM_SIZE) - $(CONFIG_CBFS_SIZE) ))
$(prebuild-files) true $(prebuild-files) true
mv $@.tmp $@ mv $@.tmp $@
else else

View File

@ -43,11 +43,11 @@ _start: b reset
.balignl 16,0xdeadbeef .balignl 16,0xdeadbeef
_cbfs_master_header: _cbfs_master_header:
/* The CBFS master header is inserted here by cbfstool /* The CBFS master header is inserted by cbfstool at the first
* when coreboot.rom is being created. Hence, we leave * aligned offset after the above anchor string is found.
* some space for it. * Hence, we leave some space for it.
*/ */
.skip 64 .skip 128 @ Assumes 64-byte alignment
reset: reset:
/* /*

View File

@ -565,23 +565,32 @@ int create_cbfs_image(const char *romfile, uint32_t _romsize,
/* Set up physical/virtual mapping */ /* Set up physical/virtual mapping */
offset = romarea; offset = romarea;
// should be aligned to align
uint32_t *arm_vec = (uint32_t *)(romarea + offs);
master_header = (struct cbfs_header *)(romarea + offs + 0x20);
loadfile(bootblock, &bootblocksize, romarea + offs + 0x20 +
sizeof(struct cbfs_header), SEEK_SET);
/* /*
* Encoding for this branch instruction is: * The initial jump instruction and bootblock will be placed
* 31:28 - condition (0xe for always/unconditional) * before and after the master header, respectively. The
* 27:24 - Branch (0xa, encoding A1) * bootblock image must contain a blank, aligned region large
* 23: 0 - sign-extended offset (in multiples of 4) * enough for the master header to fit.
* *
* When executing the branch, the PC will read as the address * An anchor string must be left such that when cbfstool is run
* of current instruction + 8. * we can find it and insert the master header at the next
* aligned boundary.
*/ */
uint32_t imm = ((0x20 + sizeof(struct cbfs_header)) - 8) / 4; loadfile(bootblock, &bootblocksize, romarea + offs, SEEK_SET);
arm_vec[0] = imm | (0xa << 24) | (0xe << 28);
unsigned char *p = romarea + offs;
while (1) {
/* FIXME: assumes little endian... */
if (*(uint32_t *)p == 0xdeadbeef)
break;
if (p >= (romarea + _romsize)) {
fprintf(stderr, "E: Could not determine CBFS "
"header location.\n", bootblock);
return 1;
}
p += (sizeof(unsigned int));
}
unsigned int u = ALIGN((unsigned int)(p - romarea), align);
master_header = (struct cbfs_header *)(romarea + u);
master_header->magic = ntohl(CBFS_HEADER_MAGIC); master_header->magic = ntohl(CBFS_HEADER_MAGIC);
master_header->version = ntohl(CBFS_HEADER_VERSION); master_header->version = ntohl(CBFS_HEADER_VERSION);