From 19a23d51905a1d4d47c0a5a177abcc5f7c7564a2 Mon Sep 17 00:00:00 2001 From: Ruibin Chang Date: Tue, 20 Feb 2024 16:54:49 +0800 Subject: [PATCH] bbram: fix bbram dead code issue Clear the whole 192 bytes of bbram, before writing the magic value to it. test pass "west twister -cviG -T tests/drivers/bbram/". Fixes #69119 Signed-off-by: Ruibin Chang --- drivers/bbram/bbram_it8xxx2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/bbram/bbram_it8xxx2.c b/drivers/bbram/bbram_it8xxx2.c index cecf555ee8..1110cf025c 100644 --- a/drivers/bbram/bbram_it8xxx2.c +++ b/drivers/bbram/bbram_it8xxx2.c @@ -81,6 +81,7 @@ static int bbram_it8xxx2_init(const struct device *dev) uint8_t *bram_valid_flag1 = base_addr + BRAM_IDX_VALID_FLAGS1; uint8_t *bram_valid_flag2 = base_addr + BRAM_IDX_VALID_FLAGS2; uint8_t *bram_valid_flag3 = base_addr + BRAM_IDX_VALID_FLAGS3; + int size = config->size; if ((*bram_valid_flag0 != BRAM_VALID_MAGIC_FIELD0) || (*bram_valid_flag1 != BRAM_VALID_MAGIC_FIELD1) || @@ -88,9 +89,9 @@ static int bbram_it8xxx2_init(const struct device *dev) (*bram_valid_flag3 != BRAM_VALID_MAGIC_FIELD3)) { /* * Magic does not match, so BRAM must be uninitialized. Clear - * entire Bank0 BRAM, and set magic value. + * entire Bank0 and Bank1 BRAM, and set magic value. */ - for (int i = 0; i < BRAM_IDX_VALID_FLAGS0; i++) { + for (int i = 0; i < size; i++) { *(base_addr + i) = 0; }