[coreboot-gerrit] Patch set updated for coreboot: memlayout: Fix unified CBFS_CACHE macro

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Tue Jan 19 17:08:26 CET 2016


Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/12933

-gerrit

commit 1de8cb6b3642aa64d0d46840a91a1028faabd522
Author: Julius Werner <jwerner at chromium.org>
Date:   Wed Dec 16 16:07:39 2015 -0800

    memlayout: Fix unified CBFS_CACHE macro
    
    CL:314311 introduced a bug that makes the rarely-used unified
    CBFS_CACHE() memlayout macro break when used in conjunction with
    cbfs_spi.c (since that macro does not define a separate
    postram_cbfs_cache region). This patch fixes the problem by making all
    three region names always available for both the unified and split
    macros in every stage (and adds code to ensure we don't reinitialize
    the same buffer again in romstage, which might be a bad idea if
    previous mappings are still in use).
    
    BRANCH=None
    BUG=None
    TEST=Compiled for both kinds of macros, manually checked symbols in
    disassembled stages.
    
    Change-Id: I114933e93080c8eceab04bfdba3aabf0f75f8ef9
    Signed-off-by: Patrick Georgi <pgeorgi at chromium.org>
    Original-Commit-Id: 0f270f88e54b42afb8b5057b0773644c4ef357ef
    Original-Change-Id: If172d9fa3d1fe587aa449bd4de7b5ca87d0f4915
    Original-Signed-off-by: Julius Werner <jwerner at chromium.org>
    Original-Reviewed-on: https://chromium-review.googlesource.com/318834
    Original-Reviewed-by: Aaron Durbin <adurbin at chromium.org>
---
 src/include/memlayout.h | 25 ++++++++++++++++---------
 src/include/symbols.h   |  4 ++++
 src/lib/cbfs_spi.c      |  9 +++++----
 3 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/src/include/memlayout.h b/src/include/memlayout.h
index 3178bc4..42d5608 100644
--- a/src/include/memlayout.h
+++ b/src/include/memlayout.h
@@ -63,6 +63,10 @@
 		STR(name must be aligned to expected_align!)); \
 	SYMBOL(e##name, addr + size)
 
+#define ALIAS_REGION(name, alias) \
+	_##alias = _##name; \
+	_e##alias = _e##name;
+
 /* Declare according to SRAM/DRAM ranges in SoC hardware-defined address map. */
 #define SRAM_START(addr) SYMBOL(sram, addr)
 
@@ -77,20 +81,23 @@
 	REGION(preram_cbmem_console, addr, size, 4)
 
 /* Use either CBFS_CACHE (unified) or both (PRERAM|POSTRAM)_CBFS_CACHE */
-#define CBFS_CACHE(addr, size) REGION(cbfs_cache, addr, size, 4)
+#define CBFS_CACHE(addr, size) \
+	REGION(cbfs_cache, addr, size, 4) \
+	ALIAS_REGION(cbfs_cache, preram_cbfs_cache) \
+	ALIAS_REGION(cbfs_cache, postram_cbfs_cache)
 
-#if ENV_ROMSTAGE
-	#define PRERAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size)
+#if defined(__PRE_RAM__)
+	#define PRERAM_CBFS_CACHE(addr, size) \
+		REGION(preram_cbfs_cache, addr, size, 4) \
+		ALIAS_REGION(preram_cbfs_cache, cbfs_cache)
 	#define POSTRAM_CBFS_CACHE(addr, size) \
 		REGION(postram_cbfs_cache, addr, size, 4)
-#elif defined(__PRE_RAM__)
-	#define PRERAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size)
-	#define POSTRAM_CBFS_CACHE(addr, size) \
-		REGION(unused_cbfs_cache, addr, size, 4)
 #else
 	#define PRERAM_CBFS_CACHE(addr, size) \
-		REGION(unused_cbfs_cache, addr, size, 4)
-	#define POSTRAM_CBFS_CACHE(addr, size) CBFS_CACHE(addr, size)
+		REGION(preram_cbfs_cache, addr, size, 4)
+	#define POSTRAM_CBFS_CACHE(addr, size) \
+		REGION(postram_cbfs_cache, addr, size, 4) \
+		ALIAS_REGION(postram_cbfs_cache, cbfs_cache)
 #endif
 
 /* Careful: 'INCLUDE <filename>' must always be at the end of the output line */
diff --git a/src/include/symbols.h b/src/include/symbols.h
index 662f44e..4276176 100644
--- a/src/include/symbols.h
+++ b/src/include/symbols.h
@@ -41,6 +41,10 @@ extern u8 _stack[];
 extern u8 _estack[];
 #define _stack_size (_estack - _stack)
 
+extern u8 _preram_cbfs_cache[];
+extern u8 _epreram_cbfs_cache[];
+#define _preram_cbfs_cache_size (_epreram_cbfs_cache - _preram_cbfs_cache)
+
 extern u8 _postram_cbfs_cache[];
 extern u8 _epostram_cbfs_cache[];
 #define _postram_cbfs_cache_size (_epostram_cbfs_cache - _postram_cbfs_cache)
diff --git a/src/lib/cbfs_spi.c b/src/lib/cbfs_spi.c
index ffa0628..2677ac4 100644
--- a/src/lib/cbfs_spi.c
+++ b/src/lib/cbfs_spi.c
@@ -43,7 +43,7 @@ static const struct region_device_ops spi_ops = {
 static struct mmap_helper_region_device mdev =
 	MMAP_HELPER_REGION_INIT(&spi_ops, 0, CONFIG_ROM_SIZE);
 
-static void initialize_mdev(int unused)
+static void switch_to_postram_cache(int unused)
 {
 	/*
 	 * Call boot_device_init() to ensure spi_flash is initialized before
@@ -51,10 +51,11 @@ static void initialize_mdev(int unused)
 	 * being overwritten if spi_flash was not accessed before dram was up.
 	 */
 	boot_device_init();
-	mmap_helper_device_init(&mdev, _postram_cbfs_cache,
-				_postram_cbfs_cache_size);
+	if (_preram_cbfs_cache != _postram_cbfs_cache)
+		mmap_helper_device_init(&mdev, _postram_cbfs_cache,
+					_postram_cbfs_cache_size);
 }
-ROMSTAGE_CBMEM_INIT_HOOK(initialize_mdev);
+ROMSTAGE_CBMEM_INIT_HOOK(switch_to_postram_cache);
 
 void boot_device_init(void)
 {



More information about the coreboot-gerrit mailing list