Skip to content

Commit

Permalink
Merge pull request wolfSSL#38 from danielinux/lpc54xxx
Browse files Browse the repository at this point in the history
Support for Lpc54xxx
  • Loading branch information
dgarske authored Mar 4, 2020
2 parents 19f328c + 6ff8473 commit 50c1cb7
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ test-app/image.bin: wolfboot-align.bin
standalone:
@make -C test-app TARGET=$(TARGET) EXT_FLASH=$(EXT_FLASH) SPI_FLASH=$(SPI_FLASH) ARCH=$(ARCH) \
V=$(V) RAM_CODE=$(RAM_CODE) WOLFBOOT_VERSION=$(WOLFBOOT_VERSION)\
KINETIS=$(KINETIS) KINETIS_CPU=$(KINETIS_CPU) KINETIS_DRIVERS=$(KINETIS_DRIVERS) \
KINETIS_CMSIS=$(KINETIS_CMSIS) NVM_FLASH_WRITEONCE=$(NVM_FLASH_WRITEONCE) \
MCUXPRESSO=$(MCUXPRESSO) MCUXPRESSO_CPU=$(MCUXPRESSO_CPU) MCUXPRESSO_DRIVERS=$(MCUXPRESSO_DRIVERS) \
MCUXPRESSO_CMSIS=$(MCUXPRESSO_CMSIS) NVM_FLASH_WRITEONCE=$(NVM_FLASH_WRITEONCE) \
FREEDOM_E_SDK=$(FREEDOM_E_SDK) standalone
$(Q)$(OBJCOPY) -O binary test-app/image.elf standalone.bin
@$(SIZE) test-app/image.elf
Expand Down
14 changes: 10 additions & 4 deletions arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,23 @@ endif


ifeq ($(TARGET),kinetis)
CFLAGS+= -I$(KINETIS_DRIVERS)/drivers -I$(KINETIS_DRIVERS) -DCPU_$(KINETIS_CPU) -I$(KINETIS_CMSIS)/Include -DDEBUG_CONSOLE_ASSERT_DISABLE=1
OBJS+= $(KINETIS_DRIVERS)/drivers/fsl_clock.o $(KINETIS_DRIVERS)/drivers/fsl_ftfx_flash.o $(KINETIS_DRIVERS)/drivers/fsl_ftfx_cache.o $(KINETIS_DRIVERS)/drivers/fsl_ftfx_controller.o
CFLAGS+= -I$(MCUXPRESSO_DRIVERS)/drivers -I$(MCUXPRESSO_DRIVERS) -DCPU_$(MCUXPRESSO_CPU) -I$(MCUXPRESSO_CMSIS)/Include -DDEBUG_CONSOLE_ASSERT_DISABLE=1
OBJS+= $(MCUXPRESSO_DRIVERS)/drivers/fsl_clock.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_ftfx_flash.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_ftfx_cache.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_ftfx_controller.o
## The following lines can be used to enable HW acceleration
ifeq ($(KINETIS_CPU),MK82FN256VLL15)
ifeq ($(MCUXPRESSO_CPU),MK82FN256VLL15)
ifeq ($(PKA),1)
PKA_EXTRA_CFLAGS+=-DFREESCALE_LTC_ECC -DFREESCALE_USE_LTC -DFREESCALE_LTC_TFM
PKA_EXTRA_OBJS+=./lib/wolfssl/wolfcrypt/src/port/nxp/ksdk_port.o $(KINETIS_DRIVERS)/drivers/fsl_ltc.o
PKA_EXTRA_OBJS+=./lib/wolfssl/wolfcrypt/src/port/nxp/ksdk_port.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_ltc.o
endif
endif
endif

ifeq ($(TARGET),lpc)
CFLAGS+=-I$(MCUXPRESSO_DRIVERS)/drivers -I$(MCUXPRESSO_DRIVERS) -DCPU_$(MCUXPRESSO_CPU) -I$(MCUXPRESSO_CMSIS)/Include -DDEBUG_CONSOLE_ASSERT_DISABLE=1
OBJS+=$(MCUXPRESSO_DRIVERS)/drivers/fsl_clock.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_flashiap.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_power.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_reset.o
OBJS+=$(MCUXPRESSO_DRIVERS)/mcuxpresso/libpower_softabi.a $(MCUXPRESSO_DRIVERS)/drivers/fsl_common.o
endif


CFLAGS+=-DARCH_FLASH_OFFSET=$(ARCH_FLASH_OFFSET)

Expand Down
8 changes: 4 additions & 4 deletions config/examples/kinetis-k82f.config
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
ARCH?=ARM
TARGET?=kinetis
SIGN?=ECC256
KINETIS?=$(HOME)/src/FRDM-K82F
KINETIS_CPU?=MK82FN256VLL15
KINETIS_DRIVERS?=$(KINETIS)/devices/MK82F25615
KINETIS_CMSIS?=$(HOME)/src/FRDM-K64F/CMSIS
MCUXPRESSO?=$(HOME)/src/FRDM-K82F
MCUXPRESSO_CPU?=MK82FN256VLL15
MCUXPRESSO_DRIVERS?=$(MCUXPRESSO)/devices/MK82F25615
MCUXPRESSO_CMSIS?=$(HOME)/src/FRDM-K64F/CMSIS
FREEDOM_E_SDK?=$(HOME)/src/freedom-e-sdk
DEBUG?=0
VTOR?=1
Expand Down
28 changes: 28 additions & 0 deletions config/examples/lpc54606j512.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ARCH?=ARM
TARGET?=lpc
SIGN?=ECC256
MCUXPRESSO?=$(HOME)/src/LPC54606J512
MCUXPRESSO_CPU?=LPC54606J512BD208
MCUXPRESSO_DRIVERS?=$(MCUXPRESSO)/devices/LPC54606
MCUXPRESSO_CMSIS?=$(HOME)/src/LPC54606J512/CMSIS
DEBUG?=0
HASH?=SHA256
VTOR?=1
CORTEX_M0?=0
NO_ASM?=0
EXT_FLASH?=0
SPI_FLASH?=0
ALLOW_DOWNGRADE?=0
NVM_FLASH_WRITEONCE?=0
WOLFBOOT_VERSION?=0
V?=0
SPMATH?=1
RAM_CODE?=0
DUALBANK_SWAP?=0
IMAGE_HEADER_SIZE?=256
PKA?=1
WOLFBOOT_PARTITION_SIZE?=0x38000
WOLFBOOT_SECTOR_SIZE?=0x8000
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x8000
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x40000
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x78000
41 changes: 33 additions & 8 deletions docs/Targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,43 @@ If the accepted candidate image resides on BANK B (like in this case), wolfBoot
booting.


### Debugging
## LPC54606

Debugging with OpenOCD:
### Build Options

Use the OpenOCD configuration from the previous section to run OpenOCD.
The LPC54xxx build can be obtained by specifying the CPU type and the MCUXpresso SDK path at compile time.

From another console, connect using gdb, e.g.:
The following configuration has been tested against LPC54606J512BD208:

Add wolfboot.elf to the make.
```
make TARGET=lpc SIGN=ECC256 MCUXPRESSO?=/path/to/LPC54606J512/SDK
MCUXPRESSO_CPU?=LPC54606J512BD208 \
MCUXPRESSO_DRIVERS?=$(MCUXPRESSO)/devices/LPC54606 \
MCUXPRESSO_CMSIS?=$(MCUXPRESSO)/CMSIS
```

### Loading the firmware

Loading with JLink (example: LPC54606J512)

```
arm-none-eabi-gdb wolfboot.elf -ex "set remotetimeout 240" -ex "target extended-remote localhost:3333"
(gdb) add-symbol-file test-app/image.elf 0x08020000
(gdb) add-symbol-file wolfboot.elf 0x08000000
JLinkExe -device LPC606J512 -if SWD -speed 4000
erase
loadbin factory.bin 0
r
h
```

### Debugging

Debugging with JLink:
```
JLinkGDBServer -device LPC606J512 -if SWD -speed 4000 -port 3333
```

Then, from another console:

```
arm-none-eabi-gdb wolfboot.elf -ex "target remote localhost:3333"
(gdb) add-symbol-file test-app/image.elf 0x0000a100
```
154 changes: 154 additions & 0 deletions hal/lpc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/* lpc.c
*
* Copyright (C) 2020 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 2 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
*/

#include <stdint.h>
#include <target.h>
#include "image.h"
#include "fsl_common.h"
#include "fsl_flashiap.h"
#include "fsl_power.h"

static int flash_init = 0;
uint32_t SystemCoreClock;

#ifdef NVM_FLASH_WRITEONCE
# error "wolfBoot LPC HAL: WRITEONCE support detected. Please do not define NVM_FLASH_WRITEONCE on this platform."
#endif

#define BOARD_BOOTCLOCKPLL180M_CORE_CLOCK 180000000U
#ifdef __WOLFBOOT

/*******************************************************************************
* Code for BOARD_BootClockPLL180M configuration (automatically generated by SDK)
******************************************************************************/
void BOARD_BootClockPLL180M(void)
{
/*!< Set up the clock sources */
/*!< Set up FRO */
POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without
accidentally being below the voltage for current speed */
POWER_DisablePD(kPDRUNCFG_PD_SYS_OSC); /*!< Enable System Oscillator Power */
SYSCON->SYSOSCCTRL = ((SYSCON->SYSOSCCTRL & ~SYSCON_SYSOSCCTRL_FREQRANGE_MASK) |
SYSCON_SYSOSCCTRL_FREQRANGE(0U)); /*!< Set system oscillator range */
POWER_SetVoltageForFreq(
180000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
CLOCK_SetFLASHAccessCyclesForFreq(180000000U); /*!< Set FLASH wait states for core */

/*!< Set up SYS PLL */
const pll_setup_t pllSetup = {
.pllctrl = SYSCON_SYSPLLCTRL_SELI(32U) | SYSCON_SYSPLLCTRL_SELP(16U) | SYSCON_SYSPLLCTRL_SELR(0U),
.pllmdec = (SYSCON_SYSPLLMDEC_MDEC(8191U)),
.pllndec = (SYSCON_SYSPLLNDEC_NDEC(770U)),
.pllpdec = (SYSCON_SYSPLLPDEC_PDEC(98U)),
.pllRate = 180000000U,
.flags = PLL_SETUPFLAG_WAITLOCK | PLL_SETUPFLAG_POWERUP};
CLOCK_AttachClk(kFRO12M_to_SYS_PLL); /*!< Set sys pll clock source*/
CLOCK_SetPLLFreq(&pllSetup); /*!< Configure PLL to the desired value */
/*!< Need to make sure ROM and OTP has power(PDRUNCFG0[17,29]= 0U)
before calling this API since this API is implemented in ROM code */
CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */

/*!< Set up dividers */
CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Reset divider counter and set divider to value 1 */
CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 0U, true); /*!< Reset USB0CLKDIV divider counter and halt it */
CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 1U, false); /*!< Set USB0CLKDIV divider to value 1 */

/*!< Set up clock selectors - Attach clocks to the peripheries */
CLOCK_AttachClk(kSYS_PLL_to_MAIN_CLK); /*!< Switch MAIN_CLK to SYS_PLL */
CLOCK_AttachClk(kFRO_HF_to_USB0_CLK); /*!< Switch USB0_CLK to FRO_HF */
SYSCON->MAINCLKSELA =
((SYSCON->MAINCLKSELA & ~SYSCON_MAINCLKSELA_SEL_MASK) |
SYSCON_MAINCLKSELA_SEL(0U)); /*!< Switch MAINCLKSELA to FRO12M even it is not used for MAINCLKSELB */
/* Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKPLL180M_CORE_CLOCK;
}

/* Assert hook needed by SDK */
void __assert_func(const char *a, int b, const char *c, const char *d)
{
while(1)
;
}

void hal_init(void)
{
BOARD_BootClockPLL180M();
}

void hal_prepare_boot(void)
{
}

#endif

#define FLASH_PAGE_SIZE 0x100 /* 256 bytes */

static uint8_t flash_page_cache[FLASH_PAGE_SIZE];

int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
{
int w = 0;
int ret;
int idx = 0;
uint32_t page_address;
uint32_t offset;
int size;
while (idx < len) {
page_address = ((address + idx) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE;
offset = address - page_address;
size = FLASH_PAGE_SIZE - offset;
if (size > (len - idx))
size = len - idx;

if (size > 0) {
memcpy(flash_page_cache, (void *)page_address, FLASH_PAGE_SIZE);
memcpy(flash_page_cache + offset, data + idx, size);
FLASHIAP_PrepareSectorForWrite(page_address / WOLFBOOT_SECTOR_SIZE, page_address / WOLFBOOT_SECTOR_SIZE);
FLASHIAP_CopyRamToFlash(page_address, (uint32_t *)flash_page_cache, FLASH_PAGE_SIZE, SystemCoreClock);
}
idx += size;
}
memset(flash_page_cache, 0xFF, FLASH_PAGE_SIZE);
return 0;
}

void RAMFUNCTION hal_flash_unlock(void)
{
}

void RAMFUNCTION hal_flash_lock(void)
{
}


int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
{
uint32_t start, end;
start = address / WOLFBOOT_SECTOR_SIZE;
end = (address + (len - 1)) / WOLFBOOT_SECTOR_SIZE;
FLASHIAP_PrepareSectorForWrite(start, end);
FLASHIAP_EraseSector(start, end, SystemCoreClock);
return 0;
}



53 changes: 53 additions & 0 deletions hal/lpc.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = ##WOLFBOOT_PARTITION_BOOT_ADDRESS##
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
}

SECTIONS
{

.text :
{
_start_text = .;
KEEP(*(.isr_vector))
. = ALIGN(0x400);
*(.text*)
*(.rodata*)
*(.init*)
*(.fini*)
. = ALIGN(4);
_end_text = .;
} > FLASH

.edidx :
{
. = ALIGN(4);
*(.ARM.exidx*)
} > FLASH

_stored_data = .;

.data : AT (_stored_data)
{
_start_data = .;
KEEP(*(.data*))
. = ALIGN(4);
_end_data = .;
} > RAM

.bss (NOLOAD) :
{
_start_bss = .;
__bss_start__ = .;
*(.bss*)
*(COMMON)
. = ALIGN(4);
_end_bss = .;
__bss_end__ = .;
_end = .;
} > RAM
. = ALIGN(4);
}

END_STACK = ORIGIN(RAM) + LENGTH(RAM);
2 changes: 1 addition & 1 deletion lib/wolfssl
Submodule wolfssl updated 628 files
2 changes: 1 addition & 1 deletion src/boot_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern void main(void);

void isr_reset(void) {
register unsigned int *src, *dst;
#ifdef PLATFORM_kinetis
#if defined(PLATFORM_kinetis)
/* Immediately disable Watchdog after boot */
/* Write Keys to unlock register */
*((volatile unsigned short *)0x4005200E) = 0xC520;
Expand Down
8 changes: 4 additions & 4 deletions test-app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-include ../tools/config.mk
TARGET?=none
ARCH?=ARM
KINETIS_CMSIS?=$(KINETIS)/CMSIS
MCUXPRESSO_CMSIS?=$(MCUXPRESSO)/CMSIS

ifeq ($(SIGN),RSA2048)
IMAGE_HEADER_SIZE:=512
Expand Down Expand Up @@ -57,9 +57,9 @@ ifeq ($(SPI_FLASH),1)
endif

ifeq ($(TARGET),kinetis)
CFLAGS+= -I$(KINETIS_DRIVERS)/drivers -I$(KINETIS_DRIVERS) -DCPU_$(KINETIS_CPU) -I$(KINETIS_CMSIS)/Include -DDEBUG_CONSOLE_ASSERT_DISABLE=1 -DNVM_FLASH_WRITEONCE=1
APP_OBJS+= $(KINETIS_DRIVERS)/drivers/fsl_clock.o $(KINETIS_DRIVERS)/drivers/fsl_ftfx_flash.o $(KINETIS_DRIVERS)/drivers/fsl_ftfx_cache.o \
$(KINETIS_DRIVERS)/drivers/fsl_ftfx_controller.o $(KINETIS_DRIVERS)/drivers/fsl_gpio.o
CFLAGS+= -I$(MCUXPRESSO_DRIVERS)/drivers -I$(MCUXPRESSO_DRIVERS) -DCPU_$(MCUXPRESSO_CPU) -I$(MCUXPRESSO_CMSIS)/Include -DDEBUG_CONSOLE_ASSERT_DISABLE=1 -DNVM_FLASH_WRITEONCE=1
APP_OBJS+= $(MCUXPRESSO_DRIVERS)/drivers/fsl_clock.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_ftfx_flash.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_ftfx_cache.o \
$(MCUXPRESSO_DRIVERS)/drivers/fsl_ftfx_controller.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_gpio.o
endif

ifeq ($(TARGET),stm32g0)
Expand Down
Loading

0 comments on commit 50c1cb7

Please sign in to comment.