[coreboot] New patch to review for coreboot: 0969480 armv7: dynamically calculate the branch offset in cbfstool

David Hendricks (dhendrix@chromium.org) gerrit at coreboot.org
Thu Jan 10 02:48:00 CET 2013


David Hendricks (dhendrix at chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/2125

-gerrit

commit 0969480ea0dc788f0406a6f0479759108ab2a903
Author: David Hendricks <dhendrix at chromium.org>
Date:   Wed Jan 9 17:45:19 2013 -0800

    armv7: dynamically calculate the branch offset in cbfstool
    
    This tidies up the ARMV7 case when creating cbfs:
    - Calculate the offset using the size of the master header and offsets
      rather than using a magic constant.
    - Re-order some assignments so things happen in a logical order.
    
    Change-Id: Id9cdbc3389c8bb504fa99436c9771936cc4c1c23
    Signed-off-by: David Hendricks <dhendrix at chromium.org>
---
 util/cbfstool/common.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index 3b63e54..195cda1 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -565,22 +565,23 @@ int create_cbfs_image(const char *romfile, uint32_t _romsize,
 		/* Set up physical/virtual mapping */
 		offset = romarea;
 
-		// should be aligned to align but then we need to dynamically
-		// create the jump to the bootblock
-		loadfile(bootblock, &bootblocksize, romarea + offs + 0x20 +
-			 sizeof(struct cbfs_header), SEEK_SET);
-		master_header = (struct cbfs_header *)(romarea + offs + 0x20);
+		// 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:
 		 * 31:28 - condition (0xe for always/unconditional)
-		 * 27:24 - 0xa
+		 * 27:24 - Branch (0xa, encoding A1)
 		 * 23: 0 - sign-extended offset (in multiples of 4)
 		 *
 		 * When executing the branch, the PC will read as the address
 		 * of current instruction + 8.
 		 */
-		arm_vec[0] = htonl(0x0e0000ea);  // branch to . + 64 bytes
+		uint32_t imm = ((0x20 + sizeof(struct cbfs_header)) - 8) / 4;
+		arm_vec[0] = imm | (0xa << 24) | (0xe << 28);
 
 		master_header->magic = ntohl(CBFS_HEADER_MAGIC);
 		master_header->version = ntohl(CBFS_HEADER_VERSION);



More information about the coreboot mailing list