Skip to content

Commit 50c1cb7

Browse files
authored
Merge pull request #38 from danielinux/lpc54xxx
Support for Lpc54xxx
2 parents 19f328c + 6ff8473 commit 50c1cb7

12 files changed

Lines changed: 331 additions & 30 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ test-app/image.bin: wolfboot-align.bin
203203
standalone:
204204
@make -C test-app TARGET=$(TARGET) EXT_FLASH=$(EXT_FLASH) SPI_FLASH=$(SPI_FLASH) ARCH=$(ARCH) \
205205
V=$(V) RAM_CODE=$(RAM_CODE) WOLFBOOT_VERSION=$(WOLFBOOT_VERSION)\
206-
KINETIS=$(KINETIS) KINETIS_CPU=$(KINETIS_CPU) KINETIS_DRIVERS=$(KINETIS_DRIVERS) \
207-
KINETIS_CMSIS=$(KINETIS_CMSIS) NVM_FLASH_WRITEONCE=$(NVM_FLASH_WRITEONCE) \
206+
MCUXPRESSO=$(MCUXPRESSO) MCUXPRESSO_CPU=$(MCUXPRESSO_CPU) MCUXPRESSO_DRIVERS=$(MCUXPRESSO_DRIVERS) \
207+
MCUXPRESSO_CMSIS=$(MCUXPRESSO_CMSIS) NVM_FLASH_WRITEONCE=$(NVM_FLASH_WRITEONCE) \
208208
FREEDOM_E_SDK=$(FREEDOM_E_SDK) standalone
209209
$(Q)$(OBJCOPY) -O binary test-app/image.elf standalone.bin
210210
@$(SIZE) test-app/image.elf

arch.mk

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,23 @@ endif
105105

106106

107107
ifeq ($(TARGET),kinetis)
108-
CFLAGS+= -I$(KINETIS_DRIVERS)/drivers -I$(KINETIS_DRIVERS) -DCPU_$(KINETIS_CPU) -I$(KINETIS_CMSIS)/Include -DDEBUG_CONSOLE_ASSERT_DISABLE=1
109-
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
108+
CFLAGS+= -I$(MCUXPRESSO_DRIVERS)/drivers -I$(MCUXPRESSO_DRIVERS) -DCPU_$(MCUXPRESSO_CPU) -I$(MCUXPRESSO_CMSIS)/Include -DDEBUG_CONSOLE_ASSERT_DISABLE=1
109+
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
110110
## The following lines can be used to enable HW acceleration
111-
ifeq ($(KINETIS_CPU),MK82FN256VLL15)
111+
ifeq ($(MCUXPRESSO_CPU),MK82FN256VLL15)
112112
ifeq ($(PKA),1)
113113
PKA_EXTRA_CFLAGS+=-DFREESCALE_LTC_ECC -DFREESCALE_USE_LTC -DFREESCALE_LTC_TFM
114-
PKA_EXTRA_OBJS+=./lib/wolfssl/wolfcrypt/src/port/nxp/ksdk_port.o $(KINETIS_DRIVERS)/drivers/fsl_ltc.o
114+
PKA_EXTRA_OBJS+=./lib/wolfssl/wolfcrypt/src/port/nxp/ksdk_port.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_ltc.o
115115
endif
116116
endif
117117
endif
118118

119+
ifeq ($(TARGET),lpc)
120+
CFLAGS+=-I$(MCUXPRESSO_DRIVERS)/drivers -I$(MCUXPRESSO_DRIVERS) -DCPU_$(MCUXPRESSO_CPU) -I$(MCUXPRESSO_CMSIS)/Include -DDEBUG_CONSOLE_ASSERT_DISABLE=1
121+
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
122+
OBJS+=$(MCUXPRESSO_DRIVERS)/mcuxpresso/libpower_softabi.a $(MCUXPRESSO_DRIVERS)/drivers/fsl_common.o
123+
endif
124+
119125

120126
CFLAGS+=-DARCH_FLASH_OFFSET=$(ARCH_FLASH_OFFSET)
121127

config/examples/kinetis-k82f.config

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
ARCH?=ARM
22
TARGET?=kinetis
33
SIGN?=ECC256
4-
KINETIS?=$(HOME)/src/FRDM-K82F
5-
KINETIS_CPU?=MK82FN256VLL15
6-
KINETIS_DRIVERS?=$(KINETIS)/devices/MK82F25615
7-
KINETIS_CMSIS?=$(HOME)/src/FRDM-K64F/CMSIS
4+
MCUXPRESSO?=$(HOME)/src/FRDM-K82F
5+
MCUXPRESSO_CPU?=MK82FN256VLL15
6+
MCUXPRESSO_DRIVERS?=$(MCUXPRESSO)/devices/MK82F25615
7+
MCUXPRESSO_CMSIS?=$(HOME)/src/FRDM-K64F/CMSIS
88
FREEDOM_E_SDK?=$(HOME)/src/freedom-e-sdk
99
DEBUG?=0
1010
VTOR?=1
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ARCH?=ARM
2+
TARGET?=lpc
3+
SIGN?=ECC256
4+
MCUXPRESSO?=$(HOME)/src/LPC54606J512
5+
MCUXPRESSO_CPU?=LPC54606J512BD208
6+
MCUXPRESSO_DRIVERS?=$(MCUXPRESSO)/devices/LPC54606
7+
MCUXPRESSO_CMSIS?=$(HOME)/src/LPC54606J512/CMSIS
8+
DEBUG?=0
9+
HASH?=SHA256
10+
VTOR?=1
11+
CORTEX_M0?=0
12+
NO_ASM?=0
13+
EXT_FLASH?=0
14+
SPI_FLASH?=0
15+
ALLOW_DOWNGRADE?=0
16+
NVM_FLASH_WRITEONCE?=0
17+
WOLFBOOT_VERSION?=0
18+
V?=0
19+
SPMATH?=1
20+
RAM_CODE?=0
21+
DUALBANK_SWAP?=0
22+
IMAGE_HEADER_SIZE?=256
23+
PKA?=1
24+
WOLFBOOT_PARTITION_SIZE?=0x38000
25+
WOLFBOOT_SECTOR_SIZE?=0x8000
26+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x8000
27+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x40000
28+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x78000

docs/Targets.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,18 +413,43 @@ If the accepted candidate image resides on BANK B (like in this case), wolfBoot
413413
booting.
414414

415415

416-
### Debugging
416+
## LPC54606
417417

418-
Debugging with OpenOCD:
418+
### Build Options
419419

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

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

424-
Add wolfboot.elf to the make.
424+
```
425+
make TARGET=lpc SIGN=ECC256 MCUXPRESSO?=/path/to/LPC54606J512/SDK
426+
MCUXPRESSO_CPU?=LPC54606J512BD208 \
427+
MCUXPRESSO_DRIVERS?=$(MCUXPRESSO)/devices/LPC54606 \
428+
MCUXPRESSO_CMSIS?=$(MCUXPRESSO)/CMSIS
429+
```
430+
431+
### Loading the firmware
432+
433+
Loading with JLink (example: LPC54606J512)
425434

426435
```
427-
arm-none-eabi-gdb wolfboot.elf -ex "set remotetimeout 240" -ex "target extended-remote localhost:3333"
428-
(gdb) add-symbol-file test-app/image.elf 0x08020000
429-
(gdb) add-symbol-file wolfboot.elf 0x08000000
436+
JLinkExe -device LPC606J512 -if SWD -speed 4000
437+
erase
438+
loadbin factory.bin 0
439+
r
440+
h
441+
```
442+
443+
### Debugging
444+
445+
Debugging with JLink:
446+
```
447+
JLinkGDBServer -device LPC606J512 -if SWD -speed 4000 -port 3333
448+
```
449+
450+
Then, from another console:
451+
452+
```
453+
arm-none-eabi-gdb wolfboot.elf -ex "target remote localhost:3333"
454+
(gdb) add-symbol-file test-app/image.elf 0x0000a100
430455
```

hal/lpc.c

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/* lpc.c
2+
*
3+
* Copyright (C) 2020 wolfSSL Inc.
4+
*
5+
* This file is part of wolfBoot.
6+
*
7+
* wolfBoot is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfBoot is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
22+
#include <stdint.h>
23+
#include <target.h>
24+
#include "image.h"
25+
#include "fsl_common.h"
26+
#include "fsl_flashiap.h"
27+
#include "fsl_power.h"
28+
29+
static int flash_init = 0;
30+
uint32_t SystemCoreClock;
31+
32+
#ifdef NVM_FLASH_WRITEONCE
33+
# error "wolfBoot LPC HAL: WRITEONCE support detected. Please do not define NVM_FLASH_WRITEONCE on this platform."
34+
#endif
35+
36+
#define BOARD_BOOTCLOCKPLL180M_CORE_CLOCK 180000000U
37+
#ifdef __WOLFBOOT
38+
39+
/*******************************************************************************
40+
* Code for BOARD_BootClockPLL180M configuration (automatically generated by SDK)
41+
******************************************************************************/
42+
void BOARD_BootClockPLL180M(void)
43+
{
44+
/*!< Set up the clock sources */
45+
/*!< Set up FRO */
46+
POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
47+
CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without
48+
accidentally being below the voltage for current speed */
49+
POWER_DisablePD(kPDRUNCFG_PD_SYS_OSC); /*!< Enable System Oscillator Power */
50+
SYSCON->SYSOSCCTRL = ((SYSCON->SYSOSCCTRL & ~SYSCON_SYSOSCCTRL_FREQRANGE_MASK) |
51+
SYSCON_SYSOSCCTRL_FREQRANGE(0U)); /*!< Set system oscillator range */
52+
POWER_SetVoltageForFreq(
53+
180000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
54+
CLOCK_SetFLASHAccessCyclesForFreq(180000000U); /*!< Set FLASH wait states for core */
55+
56+
/*!< Set up SYS PLL */
57+
const pll_setup_t pllSetup = {
58+
.pllctrl = SYSCON_SYSPLLCTRL_SELI(32U) | SYSCON_SYSPLLCTRL_SELP(16U) | SYSCON_SYSPLLCTRL_SELR(0U),
59+
.pllmdec = (SYSCON_SYSPLLMDEC_MDEC(8191U)),
60+
.pllndec = (SYSCON_SYSPLLNDEC_NDEC(770U)),
61+
.pllpdec = (SYSCON_SYSPLLPDEC_PDEC(98U)),
62+
.pllRate = 180000000U,
63+
.flags = PLL_SETUPFLAG_WAITLOCK | PLL_SETUPFLAG_POWERUP};
64+
CLOCK_AttachClk(kFRO12M_to_SYS_PLL); /*!< Set sys pll clock source*/
65+
CLOCK_SetPLLFreq(&pllSetup); /*!< Configure PLL to the desired value */
66+
/*!< Need to make sure ROM and OTP has power(PDRUNCFG0[17,29]= 0U)
67+
before calling this API since this API is implemented in ROM code */
68+
CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */
69+
70+
/*!< Set up dividers */
71+
CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Reset divider counter and set divider to value 1 */
72+
CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 0U, true); /*!< Reset USB0CLKDIV divider counter and halt it */
73+
CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 1U, false); /*!< Set USB0CLKDIV divider to value 1 */
74+
75+
/*!< Set up clock selectors - Attach clocks to the peripheries */
76+
CLOCK_AttachClk(kSYS_PLL_to_MAIN_CLK); /*!< Switch MAIN_CLK to SYS_PLL */
77+
CLOCK_AttachClk(kFRO_HF_to_USB0_CLK); /*!< Switch USB0_CLK to FRO_HF */
78+
SYSCON->MAINCLKSELA =
79+
((SYSCON->MAINCLKSELA & ~SYSCON_MAINCLKSELA_SEL_MASK) |
80+
SYSCON_MAINCLKSELA_SEL(0U)); /*!< Switch MAINCLKSELA to FRO12M even it is not used for MAINCLKSELB */
81+
/* Set SystemCoreClock variable. */
82+
SystemCoreClock = BOARD_BOOTCLOCKPLL180M_CORE_CLOCK;
83+
}
84+
85+
/* Assert hook needed by SDK */
86+
void __assert_func(const char *a, int b, const char *c, const char *d)
87+
{
88+
while(1)
89+
;
90+
}
91+
92+
void hal_init(void)
93+
{
94+
BOARD_BootClockPLL180M();
95+
}
96+
97+
void hal_prepare_boot(void)
98+
{
99+
}
100+
101+
#endif
102+
103+
#define FLASH_PAGE_SIZE 0x100 /* 256 bytes */
104+
105+
static uint8_t flash_page_cache[FLASH_PAGE_SIZE];
106+
107+
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
108+
{
109+
int w = 0;
110+
int ret;
111+
int idx = 0;
112+
uint32_t page_address;
113+
uint32_t offset;
114+
int size;
115+
while (idx < len) {
116+
page_address = ((address + idx) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE;
117+
offset = address - page_address;
118+
size = FLASH_PAGE_SIZE - offset;
119+
if (size > (len - idx))
120+
size = len - idx;
121+
122+
if (size > 0) {
123+
memcpy(flash_page_cache, (void *)page_address, FLASH_PAGE_SIZE);
124+
memcpy(flash_page_cache + offset, data + idx, size);
125+
FLASHIAP_PrepareSectorForWrite(page_address / WOLFBOOT_SECTOR_SIZE, page_address / WOLFBOOT_SECTOR_SIZE);
126+
FLASHIAP_CopyRamToFlash(page_address, (uint32_t *)flash_page_cache, FLASH_PAGE_SIZE, SystemCoreClock);
127+
}
128+
idx += size;
129+
}
130+
memset(flash_page_cache, 0xFF, FLASH_PAGE_SIZE);
131+
return 0;
132+
}
133+
134+
void RAMFUNCTION hal_flash_unlock(void)
135+
{
136+
}
137+
138+
void RAMFUNCTION hal_flash_lock(void)
139+
{
140+
}
141+
142+
143+
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
144+
{
145+
uint32_t start, end;
146+
start = address / WOLFBOOT_SECTOR_SIZE;
147+
end = (address + (len - 1)) / WOLFBOOT_SECTOR_SIZE;
148+
FLASHIAP_PrepareSectorForWrite(start, end);
149+
FLASHIAP_EraseSector(start, end, SystemCoreClock);
150+
return 0;
151+
}
152+
153+
154+

hal/lpc.ld

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
MEMORY
2+
{
3+
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = ##WOLFBOOT_PARTITION_BOOT_ADDRESS##
4+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
5+
}
6+
7+
SECTIONS
8+
{
9+
10+
.text :
11+
{
12+
_start_text = .;
13+
KEEP(*(.isr_vector))
14+
. = ALIGN(0x400);
15+
*(.text*)
16+
*(.rodata*)
17+
*(.init*)
18+
*(.fini*)
19+
. = ALIGN(4);
20+
_end_text = .;
21+
} > FLASH
22+
23+
.edidx :
24+
{
25+
. = ALIGN(4);
26+
*(.ARM.exidx*)
27+
} > FLASH
28+
29+
_stored_data = .;
30+
31+
.data : AT (_stored_data)
32+
{
33+
_start_data = .;
34+
KEEP(*(.data*))
35+
. = ALIGN(4);
36+
_end_data = .;
37+
} > RAM
38+
39+
.bss (NOLOAD) :
40+
{
41+
_start_bss = .;
42+
__bss_start__ = .;
43+
*(.bss*)
44+
*(COMMON)
45+
. = ALIGN(4);
46+
_end_bss = .;
47+
__bss_end__ = .;
48+
_end = .;
49+
} > RAM
50+
. = ALIGN(4);
51+
}
52+
53+
END_STACK = ORIGIN(RAM) + LENGTH(RAM);

lib/wolfssl

Submodule wolfssl updated 628 files

src/boot_arm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern void main(void);
3737

3838
void isr_reset(void) {
3939
register unsigned int *src, *dst;
40-
#ifdef PLATFORM_kinetis
40+
#if defined(PLATFORM_kinetis)
4141
/* Immediately disable Watchdog after boot */
4242
/* Write Keys to unlock register */
4343
*((volatile unsigned short *)0x4005200E) = 0xC520;

test-app/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-include ../tools/config.mk
33
TARGET?=none
44
ARCH?=ARM
5-
KINETIS_CMSIS?=$(KINETIS)/CMSIS
5+
MCUXPRESSO_CMSIS?=$(MCUXPRESSO)/CMSIS
66

77
ifeq ($(SIGN),RSA2048)
88
IMAGE_HEADER_SIZE:=512
@@ -57,9 +57,9 @@ ifeq ($(SPI_FLASH),1)
5757
endif
5858

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

6565
ifeq ($(TARGET),stm32g0)

0 commit comments

Comments
 (0)