From 85b1aadcc1f0cec7eef73a527c5131fb3b1c2f95 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Fri, 19 Aug 2016 15:17:42 -0700 Subject: [PATCH] memlayout: Ensure TIMESTAMP() region is big enough to avoid BUG() The timestamp code asserts that the _timestamp region (allocated in memlayout for pre-RAM stages) is large enough for the assumptions it makes. This is good, except that we often initialize timestamps extremely early in the bootblock, even before console output. Debugging a BUG() that hits before console_init() is no fun. This patch adds a link-time assertion for the size of the _timestamp region in memlayout to prevent people from accidentally running into this issue. Change-Id: Ibe4301fb89c47fde28e883fd11647d6b62a66fb0 Signed-off-by: Julius Werner Reviewed-on: https://review.coreboot.org/16270 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin Reviewed-by: Paul Menzel Tested-by: Raptor Engineering Automated Test Stand --- src/include/memlayout.h | 3 ++- src/lib/timestamp.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/include/memlayout.h b/src/include/memlayout.h index 43a1caca75..a68b21f4d6 100644 --- a/src/include/memlayout.h +++ b/src/include/memlayout.h @@ -75,7 +75,8 @@ #define DRAM_START(addr) SYMBOL(dram, addr) #define TIMESTAMP(addr, size) \ - REGION(timestamp, addr, size, 8) + REGION(timestamp, addr, size, 8) \ + _ = ASSERT(size >= 212, "Timestamp region must fit timestamp_cache!"); #define PRERAM_CBMEM_CONSOLE(addr, size) \ REGION(preram_cbmem_console, addr, size, 4) diff --git a/src/lib/timestamp.c b/src/lib/timestamp.c index d8b93f9755..2f2a5d8752 100644 --- a/src/lib/timestamp.c +++ b/src/lib/timestamp.c @@ -27,6 +27,7 @@ #define MAX_TIMESTAMPS 84 +/* When changing this number, adjust TIMESTAMP() size ASSERT() in memlayout.h */ #define MAX_BSS_TIMESTAMP_CACHE 16 struct __attribute__((__packed__)) timestamp_cache {