From c0e2af85dfeb74f0c3a9fcd27871fa30d25261be Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 17 Aug 2023 08:57:29 -0700 Subject: [PATCH] Add support for iMX RT1050 and RT1060 wolfBoot_printf using DEBUG_UART=1. --- README.md | 2 ++ arch.mk | 30 ++++++++++++++---------------- hal/imx_rt.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 95b94c786..f487fa00c 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ Due to the minimalist design of the bootloader and the tiny HAL API, wolfBoot is from any OS or bare-metal application, and can be easily ported and integrated in existing embedded software projects to provide a secure firmware update mechanism. +Design based on [RFC 9019](https://datatracker.ietf.org/doc/rfc9019/) - A Firmware Update Architecture for Internet of Things. + ## Features - Multi-slot partitioning of the flash device - Integrity verification of the firmware image(s) diff --git a/arch.mk b/arch.mk index 04a378a40..05fb4b8df 100644 --- a/arch.mk +++ b/arch.mk @@ -262,48 +262,46 @@ endif ifeq ($(TARGET),imx_rt) CORTEX_M7=1 - CFLAGS+=-I$(MCUXPRESSO_DRIVERS)/drivers -I$(MCUXPRESSO_DRIVERS) \ + CFLAGS+=\ + -I$(MCUXPRESSO_DRIVERS)/drivers \ + -I$(MCUXPRESSO_DRIVERS) \ -I$(MCUXPRESSO_DRIVERS)/utilities/debug_console/ \ -I$(MCUXPRESSO_DRIVERS)/utilities/str/ \ -I$(MCUXPRESSO)/components/uart/ \ -I$(MCUXPRESSO)/components/flash/nor \ -I$(MCUXPRESSO)/components/flash/nor/flexspi \ -I$(MCUXPRESSO)/components/serial_manager/ \ - -DCPU_$(MCUXPRESSO_CPU) -I$(MCUXPRESSO_CMSIS)/Include \ - -DCPU_$(MCUXPRESSO_CPU) -I$(MCUXPRESSO_CMSIS)/Core/Include \ + -I$(MCUXPRESSO_CMSIS)/Include \ + -I$(MCUXPRESSO_CMSIS)/Core/Include \ + -DCPU_$(MCUXPRESSO_CPU) \ -DDEBUG_CONSOLE_ASSERT_DISABLE=1 -I$(MCUXPRESSO_DRIVERS)/project_template/ \ -DXIP_EXTERNAL_FLASH=1 -DDEBUG_CONSOLE_ASSERT_DISABLE=1 -DPRINTF_ADVANCED_ENABLE=1 \ -DSCANF_ADVANCED_ENABLE=1 -DSERIAL_PORT_TYPE_UART=1 -DNDEBUG=1 OBJS+= $(MCUXPRESSO_DRIVERS)/drivers/fsl_clock.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_flexspi.o + ifeq ($(DEBUG_UART),1) + OBJS+= $(MCUXPRESSO_DRIVERS)/drivers/fsl_lpuart.o + endif ifeq ($(MCUXPRESSO_CPU),MIMXRT1064DVL6A) - ARCH_FLASH_OFFSET=0x70000000 - CFLAGS+=-I$(MCUXPRESSO)/boards/evkmimxrt1064/xip/ - ifeq ($(PKA),1) - PKA_EXTRA_OBJS+= $(MCUXPRESSO)/devices/MIMXRT1064/drivers/fsl_dcp.o - endif + ARCH_FLASH_OFFSET=0x70000000 + CFLAGS+=-I$(MCUXPRESSO)/boards/evkmimxrt1064/xip/ endif ifeq ($(MCUXPRESSO_CPU),MIMXRT1062DVL6A) ARCH_FLASH_OFFSET=0x60000000 CFLAGS+=-I$(MCUXPRESSO)/boards/evkmimxrt1060/xip/ - ifeq ($(PKA),1) - PKA_EXTRA_OBJS+= $(MCUXPRESSO)/devices/MIMXRT1062/drivers/fsl_dcp.o - endif endif ifeq ($(MCUXPRESSO_CPU),MIMXRT1052DVJ6B) ARCH_FLASH_OFFSET=0x60000000 CFLAGS+=-I$(MCUXPRESSO)/boards/evkbimxrt1050/xip/ - ifeq ($(PKA),1) - PKA_EXTRA_OBJS+= $(MCUXPRESSO)/devices/MIMXRT1052/drivers/fsl_dcp.o - endif endif ifeq ($(PKA),1) - PKA_EXTRA_OBJS+=./lib/wolfssl/wolfcrypt/src/port/nxp/dcp_port.o - PKA_EXTRA_CFLAGS+=-DWOLFSSL_IMXRT_DCP + PKA_EXTRA_OBJS+= $(MCUXPRESSO_DRIVERS)/drivers/fsl_dcp.o + PKA_EXTRA_OBJS+=./lib/wolfssl/wolfcrypt/src/port/nxp/dcp_port.o + PKA_EXTRA_CFLAGS+=-DWOLFSSL_IMXRT_DCP endif endif diff --git a/hal/imx_rt.c b/hal/imx_rt.c index 6a053a305..8a6a417fa 100644 --- a/hal/imx_rt.c +++ b/hal/imx_rt.c @@ -29,6 +29,9 @@ #include "fsl_iomuxc.h" #include "fsl_nor_flash.h" #include "fsl_flexspi.h" +#ifdef DEBUG_UART +#include "fsl_lpuart.h" +#endif #ifdef CPU_MIMXRT1062DVL6A #include "evkmimxrt1060_flexspi_nor_config.h" @@ -675,6 +678,32 @@ static void clock_init(void) } +#ifdef DEBUG_UART + +#define UART_BASEADDR LPUART1 +#define UART_BAUDRATE (115200U) + +void uart_init(void) +{ + lpuart_config_t config; + uint32_t uartClkSrcFreq = 20000000U; /* 20 MHz */ + + LPUART_GetDefaultConfig(&config); + config.baudRate_Bps = UART_BAUDRATE; + config.enableTx = true; + config.enableRx = true; + + LPUART_Init(UART_BASEADDR, &config, uartClkSrcFreq); +} + +void uart_write(const char* buf, uint32_t sz) +{ + LPUART_WriteBlocking(UART_BASEADDR, (const uint8_t*)buf, sz); +} + +#endif /* DEBUG_UART */ + + extern void ARM_MPU_Disable(void); extern int wc_dcp_init(void); static int hal_flash_init(void); @@ -686,6 +715,10 @@ void hal_init(void) #endif ARM_MPU_Disable(); clock_init(); +#ifdef DEBUG_UART + uart_init(); + uart_write("wolfBoot HAL Init\n", 19); +#endif hal_flash_init(); }