[coreboot-gerrit] Patch set updated for coreboot: b6840ba Refactor usage of walkcbfs to permit access to CBFS headers

Alexandru Gagniuc (mr.nuke.me@gmail.com) gerrit at coreboot.org
Sun Dec 8 17:59:12 CET 2013


Alexandru Gagniuc (mr.nuke.me at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4504

-gerrit

commit b6840ba7298efa160de15e60b92823dbbe55d703
Author: Alexandru Gagniuc <mr.nuke.me at gmail.com>
Date:   Sun Dec 8 01:13:43 2013 -0600

    Refactor usage of walkcbfs to permit access to CBFS headers
    
    walkcbfs is only used when applying microcode updates during the bootblock
    phase. The function used to return only a pointer to the data of the CBFS
    file, while making the header completely inaccessible. Since the header
    contains the length of the CBFS file, the caller did not have a way to know
    how long the data was. Then, other conventions had to be used to determine
    the EOF, which might present problems if the user replaces the CBFS file.
    
    Refactor walkcbfs_asm to return a pointer to the CBFS file header rather
    than the data, and fix the usage in the one place where walkcbfs is used.
    
    Change-Id: I21cbf19e130e1480e2749754e5d5130d36036f8e
    Signed-off-by: Alexandru Gagniuc <mr.nuke.me at gmail.com>
---
 src/arch/x86/include/arch/cbfs.h    |  4 +++-
 src/arch/x86/lib/walkcbfs.S         |  4 +---
 src/cpu/intel/microcode/microcode.c |  9 ++++++---
 src/include/cbfs_core.h             | 14 +++++++++++---
 4 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/arch/x86/include/arch/cbfs.h b/src/arch/x86/include/arch/cbfs.h
index 8a61d6e..e9390a0 100644
--- a/src/arch/x86/include/arch/cbfs.h
+++ b/src/arch/x86/include/arch/cbfs.h
@@ -20,7 +20,9 @@
 #ifndef __INCLUDE_ARCH_CBFS__
 #define __INCLUDE_ARCH_CBFS__
 
-static void *walkcbfs(char *target)
+#include <cbfs_core.h>
+
+static struct cbfs_file *walkcbfs(char *target)
 {
 	void *entry;
 	asm volatile (
diff --git a/src/arch/x86/lib/walkcbfs.S b/src/arch/x86/lib/walkcbfs.S
index 2dc9617..3a96d64 100644
--- a/src/arch/x86/lib/walkcbfs.S
+++ b/src/arch/x86/lib/walkcbfs.S
@@ -59,9 +59,7 @@ walker:
 	jnz tryharder
 
 	/* we found it! */
-	mov CBFS_FILE_OFFSET(%ebx), %eax
-	bswap %eax
-	add %ebx, %eax
+	mov %ebx, %eax
 	jmp *%esp
 
 tryharder:
diff --git a/src/cpu/intel/microcode/microcode.c b/src/cpu/intel/microcode/microcode.c
index 3d6af67..ef04e03 100644
--- a/src/cpu/intel/microcode/microcode.c
+++ b/src/cpu/intel/microcode/microcode.c
@@ -109,7 +109,8 @@ void intel_microcode_load_unlocked(const void *microcode_patch)
 
 const void *intel_microcode_find(void)
 {
-	void *microcode_updates;
+	struct cbfs_file *microcode_updates;
+	void *microcode_data;
 	u32 eax;
 	u32 pf, rev, sig;
 	unsigned int x86_model, x86_family;
@@ -152,8 +153,10 @@ const void *intel_microcode_find(void)
 			sig, pf, rev);
 #endif
 
-	m = microcode_updates;
-	for(c = microcode_updates; m->hdrver; m = (const struct microcode *)c) {
+	microcode_data = CBFS_SUBHEADER(microcode_updates);
+
+	m = microcode_data;
+	for(c = microcode_data; m->hdrver; m = (const struct microcode *)c) {
 		if ((m->sig == sig) && (m->pf & pf))
 			return m;
 
diff --git a/src/include/cbfs_core.h b/src/include/cbfs_core.h
index 08fe815..04b5dd7 100644
--- a/src/include/cbfs_core.h
+++ b/src/include/cbfs_core.h
@@ -134,6 +134,15 @@ struct cbfs_file {
 	uint32_t offset;
 } __attribute__((packed));
 
+#define CBFS_NAME(_c) (((char *) (_c)) + sizeof(struct cbfs_file))
+#define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
+
+/*
+ * ROMCC does not understand uint64_t, so we hide future definitions as they are
+ * unlikely to be ever needed from ROMCC
+ */
+#ifndef __ROMCC__
+
 /*** Component sub-headers ***/
 
 /* Following are component sub-headers for the "standard"
@@ -177,9 +186,6 @@ struct cbfs_optionrom {
 	uint32_t len;
 } __attribute__((packed));
 
-#define CBFS_NAME(_c) (((char *) (_c)) + sizeof(struct cbfs_file))
-#define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
-
 #define CBFS_MEDIA_INVALID_MAP_ADDRESS	((void*)(0xffffffff))
 #define CBFS_DEFAULT_MEDIA		((void*)(0x0))
 
@@ -225,4 +231,6 @@ int cbfs_decompress(int algo, void *src, void *dst, int len);
  *  on failure */
 const struct cbfs_header *cbfs_get_header(struct cbfs_media *media);
 
+#endif /* __ROMCC__ */
+
 #endif



More information about the coreboot-gerrit mailing list