From 8961872603f6d7b66ef97d444711e83d6a55e2f4 Mon Sep 17 00:00:00 2001 From: Allen Webb Date: Tue, 21 Aug 2018 07:44:37 -0700 Subject: common: flash and nvmem fixes for compatibility with the host board. This CL 1) Forces alignment of __host_flash so it can be used with nvcounter 2) Disables a compile time check for the host board that failes because the host board uses a variable to emulate flash memory. 3) Disables nvmem_vars console commands that are specific to a unit test for fuzzing targets. BRANCH=none BUG=chromium:876582 TEST=make -j buildfuzztests (with cr50_fuzz CL) Change-Id: Id6257132d8f2dd73ae07e796efd0da3df83b30d6 Signed-off-by: Allen Webb Reviewed-on: https://chromium-review.googlesource.com/1183533 Reviewed-by: Randall Spangler --- chip/host/flash.c | 4 +++- common/nvcounter.c | 8 +++++++- common/nvmem_vars.c | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/chip/host/flash.c b/chip/host/flash.c index b83d72ff5f..4961db1578 100644 --- a/chip/host/flash.c +++ b/chip/host/flash.c @@ -8,11 +8,13 @@ #include #include "common.h" +#include "config_chip.h" #include "flash.h" #include "persistence.h" #include "util.h" -char __host_flash[CONFIG_FLASH_SIZE]; +/* This needs to be aligned to the erase bank size for NVCTR. */ +__aligned(CONFIG_FLASH_ERASE_SIZE) char __host_flash[CONFIG_FLASH_SIZE]; uint8_t __host_flash_protect[PHYSICAL_BANKS]; /* Override this function to make flash erase/write operation fail */ diff --git a/common/nvcounter.c b/common/nvcounter.c index de00d8857c..6c267e3a4c 100644 --- a/common/nvcounter.c +++ b/common/nvcounter.c @@ -21,9 +21,15 @@ static uint32_t *FLASH_CNT_LO = (uint32_t *)CONFIG_FLASH_NVCTR_BASE_A; static uint32_t *FLASH_CNT_HI = (uint32_t *)CONFIG_FLASH_NVCTR_BASE_B; -/* Ensure the 2 flash counter areas are aligned on flash pages */ + +#ifndef CHIP_HOST +/* Ensure the 2 flash counter areas are aligned on flash pages except for the + * host board which simulates flash with a variable that cannot be checked + * at compile time. + */ BUILD_ASSERT(CONFIG_FLASH_NVCTR_BASE_A % CONFIG_FLASH_ERASE_SIZE == 0); BUILD_ASSERT(CONFIG_FLASH_NVCTR_BASE_B % CONFIG_FLASH_ERASE_SIZE == 0); +#endif /* * An anti-rollback, persistent flash counter. This counter requires two pages diff --git a/common/nvmem_vars.c b/common/nvmem_vars.c index 746c47d1d7..d90fe37f9e 100644 --- a/common/nvmem_vars.c +++ b/common/nvmem_vars.c @@ -344,7 +344,7 @@ int writevars(void) } /****************************************************************************/ -#ifdef TEST_BUILD +#if defined(TEST_BUILD) && !defined(TEST_FUZZ) #include "console.h" static void print_blob(const uint8_t *blob, int blob_len) -- cgit v1.2.1