diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2016-08-05 09:39:51 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-08-08 20:19:44 -0700 |
commit | 37784e1e868fc9c722a80dbf1179a72782c87056 (patch) | |
tree | 0f2fc7795818e06b373447bb74e5a3312edd5d0e | |
parent | 7e14583689f2e6e89f3f27e1abb171910ea875a7 (diff) | |
download | chrome-ec-37784e1e868fc9c722a80dbf1179a72782c87056.tar.gz |
cr50: fix nvmem calculations
The nvmem space defined in the ec code base for the cr50 board is used
by the TPM2 library, which has its own nvram size definition. The two
definitions must match.
On top of the fact that the definitions are not locked to each other,
there is a third completely unrelated nvram size definition in
board/cr50/board.c.
This patch unifies nvmem size definitions between cr50 and tpm2
repositories by adding a compile time check for the size to be the
same on both sides.
Also, it turns out that two certificates (RSA and ECC) together do not
quite fit into the cr50 TPM nvram. Hence the total allocated nvmem
space is being increased to 20K (note that the actual nvram size
available to the TPM is less than half of this).
BRANCH=none
BUG=chrome-os-partner:55898
TEST=tpm does not lock up any more when 'tpm_client --own' is ran on the
Kevin-tpm2 command line
CQ-DEPEND=CL:367010
Change-Id: I20b4f54118bd2fa12e5bd5741d6c58fbe91f65d1
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/366796
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r-- | board/cr50/board.c | 38 | ||||
-rw-r--r-- | chip/g/config_chip.h | 2 | ||||
-rw-r--r-- | common/nvmem.c | 7 | ||||
-rw-r--r-- | include/nvmem.h | 7 |
4 files changed, 36 insertions, 18 deletions
diff --git a/board/cr50/board.c b/board/cr50/board.c index 9d383f5b26..12b0c58773 100644 --- a/board/cr50/board.c +++ b/board/cr50/board.c @@ -31,17 +31,35 @@ #include "cryptoc/sha.h" /* - * TODO: NV_MEMORY_SIZE is defined in 2 places. Here and in - * /src/third_party/tmp2/Implementation.h. This needs to be - * fixed so that it's only defined in one location to ensure that the TPM2.0 lib - * code and the NvMem code specific to Cr50 is consistent. Will - * either reference existing issue or create one to track - * this as ultimately only want this defined in 1 place. + * Need to include Implementation.h here to make sure that NVRAM size + * definitions match across different git repos. + * + * MAX() definition from include/utils.h does not work in Implementation.h, as + * it is used in a preprocessor expression there; + * + * SHA_DIGEST_SIZE is defined to be the same in both git repos, but using + * different expressions. + * + * To untangle compiler errors let's just undefine MAX() and SHA_DIGEST_SIZE + * here, as nether is necessary in this case: all we want from + * Implementation.h at this point is the definition for NV_MEMORY_SIZE. */ -#define NV_MEMORY_SIZE 7168 -#define NVMEM_TPM_SIZE NV_MEMORY_SIZE -#define NVMEM_CR50_SIZE (NVMEM_PARTITION_SIZE - NVMEM_TPM_SIZE - \ - sizeof(struct nvmem_tag)) +#undef MAX +#undef SHA_DIGEST_SIZE +#include "Implementation.h" + +#define NVMEM_CR50_SIZE 300 +#define NVMEM_TPM_SIZE ((sizeof((struct nvmem_partition *)0)->buffer) \ + - NVMEM_CR50_SIZE) + +/* + * Make sure NV memory size definition in Implementation.h matches reality. It + * should be set to + * + * NVMEM_PARTITION_SIZE - NVMEM_CR50_SIZE - 8 + */ +BUILD_ASSERT(NVMEM_TPM_SIZE == NV_MEMORY_SIZE); + /* NvMem user buffer lengths table */ uint32_t nvmem_user_sizes[NVMEM_NUM_USERS] = { NVMEM_TPM_SIZE, diff --git a/chip/g/config_chip.h b/chip/g/config_chip.h index 97cc56ba94..f0c508e2e9 100644 --- a/chip/g/config_chip.h +++ b/chip/g/config_chip.h @@ -93,7 +93,7 @@ * use these two areas for the same thing, it's just more convenient to make * them the same size. */ -#define CFG_TOP_SIZE 0x4000 +#define CFG_TOP_SIZE 0x5000 #define CFG_TOP_A_OFF (CFG_FLASH_HALF - CFG_TOP_SIZE) #define CFG_TOP_B_OFF (CONFIG_FLASH_SIZE - CFG_TOP_SIZE) diff --git a/common/nvmem.c b/common/nvmem.c index 8cf88909c0..36784b4ec5 100644 --- a/common/nvmem.c +++ b/common/nvmem.c @@ -19,13 +19,6 @@ #define NVMEM_ACQUIRE_CACHE_MAX_ATTEMPTS (250 / NVMEM_ACQUIRE_CACHE_SLEEP_MS) #define NVMEM_NOT_INITIALIZED (-1) -/* Structure MvMem Partition */ -struct nvmem_partition { - struct nvmem_tag tag; - uint8_t buffer[NVMEM_PARTITION_SIZE - - sizeof(struct nvmem_tag)]; -}; - /* NvMem user buffer start offset table */ static uint32_t nvmem_user_start_offset[NVMEM_NUM_USERS]; diff --git a/include/nvmem.h b/include/nvmem.h index 2785cfdafc..82942dbe8e 100644 --- a/include/nvmem.h +++ b/include/nvmem.h @@ -70,6 +70,13 @@ struct nvmem_tag { uint8_t reserved[3]; }; +/* Structure MvMem Partition */ +struct nvmem_partition { + struct nvmem_tag tag; + uint8_t buffer[NVMEM_PARTITION_SIZE - + sizeof(struct nvmem_tag)]; +}; + /** * Initialize NVMem translation table and state variables * |