From 322aa325b62ca1f7390a53f5922010d85a62de58 Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 27 Sep 2024 15:31:49 -0700 Subject: [PATCH] Consolidate duplicate TEST_FLASH code. --- Makefile | 1 + hal/hal.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ hal/imx_rt.c | 55 ++-------------------------------- hal/nrf5340.c | 63 +-------------------------------------- hal/nxp_p1021.c | 56 ----------------------------------- hal/nxp_t1024.c | 55 ---------------------------------- hal/renesas-rx.c | 62 -------------------------------------- include/hal.h | 4 +++ src/loader.c | 3 ++ 9 files changed, 88 insertions(+), 288 deletions(-) create mode 100644 hal/hal.c diff --git a/Makefile b/Makefile index 2bc191e9..829b3bce 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ OBJS:= \ ./src/string.o \ ./src/image.o \ ./src/libwolfboot.o \ + ./hal/hal.o \ ./hal/$(TARGET).o ifeq ($(SIGN),NONE) diff --git a/hal/hal.c b/hal/hal.c new file mode 100644 index 00000000..a2979394 --- /dev/null +++ b/hal/hal.c @@ -0,0 +1,77 @@ +/* hal.c + * + * Copyright (C) 2024 wolfSSL Inc. + * + * This file is part of wolfBoot. + * + * wolfBoot is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfBoot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +/* Code shared between all HAL's */ + +#include +#include "hal.h" +#include "string.h" +#include "printf.h" + +/* Test for internal flash erase/write */ +/* Use TEST_EXT_FLASH to test ext flash (see spi_flash.c or qspi_flash.c) */ +#ifdef TEST_FLASH + +#ifndef TEST_ADDRESS + #define TEST_SZ WOLFBOOT_SECTOR_SIZE + #define TEST_ADDRESS WOLFBOOT_PARTITION_UPDATE_ADDRESS +#endif + +int hal_flash_test(void) +{ + int ret = 0; + uint32_t i, len; + uint8_t* pagePtr = (uint8_t*)TEST_ADDRESS; + static uint8_t pageData[TEST_SZ]; + + wolfBoot_printf("Internal flash test at 0x%x\n", TEST_ADDRESS); + + /* Setup test data */ + for (i=0; i