Skip to content

Commit a48bc60

Browse files
authored
Merge pull request #44 from wolfSSL/psoc6
Psoc6 support
2 parents 6a82cd5 + 1adb2bc commit a48bc60

19 files changed

Lines changed: 592 additions & 30 deletions

File tree

.gdbinit

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
tar rem:3333
22
file wolfboot.elf
33
foc c
4-

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ ifeq ($(SIGN),ED25519)
5757
./lib/wolfssl/wolfcrypt/src/wolfmath.o \
5858
./lib/wolfssl/wolfcrypt/src/fe_low_mem.o
5959
PUBLIC_KEY_OBJS=./src/ed25519_pub_key.o
60-
CFLAGS+=-DWOLFBOOT_SIGN_ED25519 -nostdlib \
60+
CFLAGS+=-DWOLFBOOT_SIGN_ED25519 \
6161
-Wstack-usage=1024
62-
LDFLAGS+=-nostdlib
6362
endif
6463

6564
ifeq ($(SIGN),RSA2048)
@@ -191,10 +190,6 @@ wolfboot.bin: wolfboot.elf
191190
@echo "\t[BIN] $@"
192191
$(Q)$(OBJCOPY) -O binary $^ $@
193192

194-
wolfboot.hex: wolfboot.elf
195-
@echo "\t[HEX] $@"
196-
$(Q)$(OBJCOPY) -O ihex $^ $@
197-
198193
align: wolfboot-align.bin
199194

200195
.bootloader-partition-size:
@@ -256,6 +251,12 @@ $(LSCRIPT): hal/$(TARGET).ld .bootloader-partition-size FORCE
256251
sed -e "s/##WOLFBOOT_PARTITION_BOOT_ADDRESS##/`cat .bootloader-partition-size`/g" \
257252
> $@
258253

254+
hex: wolfboot.hex
255+
256+
%.hex:%.elf
257+
@echo "\t[ELF2HEX] $@"
258+
@$(OBJCOPY) -O ihex $^ $@
259+
259260
src/ed25519_pub_key.c: ed25519.der
260261

261262
src/ecc256_pub_key.c: ecc256.der

arch.mk

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,6 @@ ifeq ($(TARGET),lpc)
134134
OBJS+=$(MCUXPRESSO_DRIVERS)/drivers/fsl_usart.o $(MCUXPRESSO_DRIVERS)/drivers/fsl_flexcomm.o
135135
endif
136136

137-
138-
CFLAGS+=-DARCH_FLASH_OFFSET=$(ARCH_FLASH_OFFSET)
139-
140-
## Toolchain setup
141-
CC=$(CROSS_COMPILE)gcc
142-
LD=$(CROSS_COMPILE)gcc
143-
AS=$(CROSS_COMPILE)gcc
144-
OBJCOPY:=$(CROSS_COMPILE)objcopy
145-
SIZE:=$(CROSS_COMPILE)size
146-
BOOT_IMG?=test-app/image.bin
147-
148137
ifeq ($(TARGET),stm32f4)
149138
SPI_TARGET=stm32
150139
endif
@@ -162,6 +151,42 @@ ifeq ($(TARGET),stm32wb)
162151
endif
163152
endif
164153

154+
ifeq ($(TARGET),psoc6)
155+
CORTEX_M0=1
156+
PKA_EXTRA_OBJS+= $(CYPRESS_PDL)/drivers/source/cy_flash.o \
157+
$(CYPRESS_PDL)/drivers/source/cy_ipc_pipe.o \
158+
$(CYPRESS_PDL)/drivers/source/cy_ipc_sema.o \
159+
$(CYPRESS_PDL)/drivers/source/cy_ipc_drv.o \
160+
$(CYPRESS_PDL)/drivers/source/cy_device.o \
161+
$(CYPRESS_PDL)/drivers/source/cy_sysclk.o \
162+
$(CYPRESS_PDL)/drivers/source/cy_sysint.o \
163+
$(CYPRESS_PDL)/drivers/source/cy_syslib.o \
164+
$(CYPRESS_PDL)/drivers/source/cy_ble_clk.o \
165+
$(CYPRESS_PDL)/drivers/source/cy_wdt.o \
166+
$(CYPRESS_PDL)/drivers/source/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.o \
167+
$(CYPRESS_PDL)/devices/templates/COMPONENT_MTB/COMPONENT_CM0P/system_psoc6_cm0plus.o
168+
CFLAGS+=-I$(CYPRESS_PDL)/drivers/include/ \
169+
-I$(CYPRESS_PDL)/devices/include \
170+
-I$(CYPRESS_PDL)/cmsis/include \
171+
-I$(CYPRESS_TARGET_LIB) \
172+
-I$(CYPRESS_CORE_LIB)/include \
173+
-I$(CYPRESS_PDL)/devices/include/ip \
174+
-I$(CYPRESS_PDL)/devices/templates/COMPONENT_MTB \
175+
-DCY8C624ABZI_D44
176+
ARCH_FLASH_OFFSET=0x10000000
177+
endif
178+
179+
CFLAGS+=-DARCH_FLASH_OFFSET=$(ARCH_FLASH_OFFSET)
180+
181+
## Toolchain setup
182+
CC=$(CROSS_COMPILE)gcc
183+
LD=$(CROSS_COMPILE)gcc
184+
AS=$(CROSS_COMPILE)gcc
185+
OBJCOPY:=$(CROSS_COMPILE)objcopy
186+
SIZE:=$(CROSS_COMPILE)size
187+
BOOT_IMG?=test-app/image.bin
188+
189+
165190

166191
## Update mechanism
167192
ifeq ($(ARCH),AARCH64)

config/examples/cypsoc6.config

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
ARCH?=ARM
2+
TARGET?=psoc6
3+
SIGN?=ED25519
4+
HASH?=SHA256
5+
CYPRESS_PDL?=./lib/psoc6pdl
6+
CYPRESS_TARGET_LIB?=./lib/TARGET_CY8CKIT-062S2-43012
7+
CYPRESS_CORE_LIB?=./lib/core-lib
8+
DEBUG?=1
9+
VTOR?=1
10+
CORTEX_M0?=1
11+
NO_ASM?=0
12+
EXT_FLASH?=0
13+
SPI_FLASH?=0
14+
NO_XIP?=0
15+
UART_FLASH?=0
16+
ALLOW_DOWNGRADE?=0
17+
NVM_FLASH_WRITEONCE?=1
18+
WOLFBOOT_VERSION?=0
19+
V?=0
20+
SPMATH?=1
21+
RAM_CODE?=0
22+
DUALBANK_SWAP?=0
23+
IMAGE_HEADER_SIZE?=256
24+
PKA?=1
25+
WOLFTPM?=0
26+
WOLFBOOT_PARTITION_SIZE?=0x80000
27+
WOLFBOOT_SECTOR_SIZE?=4096
28+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x10080000
29+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x10100000
30+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=10010000

docs/Targets.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,3 +552,94 @@ make CROSS_COMPILE=aarch64-unknown-nto-qnx7.0.0-
552552
#### Signing
553553

554554
`tools/keytools/sign.py --rsa4096 --sha3 /srv/linux-rpi4/vmlinux.bin rsa4096.der 1`
555+
556+
## Cypress PSoC-62S2 (CY8CKIT-062S2)
557+
558+
The Cypress PSoC 62S2 is a dual-core Cortex-M4 & Cortex-M0+ MCU. The secure boot process is managed by the M0+.
559+
WolfBoot can be compiled as second stage flash bootloader to manage application verification and firmware updates.
560+
561+
### Building
562+
563+
The following configuration has been tested using PSoC 62S2 Wi-Fi BT Pioneer Kit (CY8CKIT-052S2-43012).
564+
565+
#### Target specific requirements
566+
567+
wolfBoot uses the following components to access peripherals on the PSoC:
568+
569+
* [Cypress Core Library](https://github.com/cypresssemiconductorco/core-lib)
570+
* [PSoC 6 Peripheral Driver Library](https://github.com/cypresssemiconductorco/psoc6pdl)
571+
* [CY8CKIT-062S2-43012 BSP](https://github.com/cypresssemiconductorco/TARGET_CY8CKIT-062S2-43012)
572+
573+
Cypress provides a [customized OpenOCD](https://github.com/cypresssemiconductorco/Openocd) for programming the flash and
574+
debugging.
575+
576+
577+
### Clock settings
578+
579+
wolfBoot configures PLL1 to run at 100 MHz and is driving `CLK_FAST`, `CLK_PERI`, and `CLK_SLOW` at that frequency.
580+
581+
#### Build configuration
582+
583+
The following configuration has been tested on the PSoC CY8CKIT-62S2-43012:
584+
585+
```
586+
make TARGET=psoc6 \
587+
NVM_FLASH_WRITEONCE=1 \
588+
CYPRESS_PDL=./lib/psoc6pdl \
589+
CYPRESS_TARGET_LIB=./lib/TARGET_CY8CKIT-062S2-43012 \
590+
CYPRESS_CORE_LIB=./lib/core-lib \
591+
WOLFBOOT_SECTOR_SIZE=4096
592+
```
593+
594+
Note: A reference `.config` can be found in `./config/examples/cypsoc6.config`.
595+
596+
#### OpenOCD installation
597+
598+
Compile and install the customized OpenOCD.
599+
600+
Use the following configuration file when running `openocd` to connect to the PSoC6 board:
601+
602+
```
603+
# openocd.cfg for PSoC-62S2
604+
605+
source [find interface/kitprog3.cfg]
606+
transport select swd
607+
adapter speed 1000
608+
source [find target/psoc6_2m.cfg]
609+
init
610+
reset init
611+
```
612+
613+
### Loading the firmware
614+
615+
To upload `factory.bin` to the device with OpenOCD, connect the device,
616+
run OpenOCD with the configuration from the previous section, then connect
617+
to the local openOCD server running on TCP port 4444 using `telnet localhost 4444`.
618+
619+
From the telnet console, type:
620+
621+
`program factory.bin 0x10000000`
622+
623+
When the transfer is finished, you can either close openOCD or start a debugging session.
624+
625+
### Debugging
626+
627+
Debugging with OpenOCD:
628+
629+
Use the OpenOCD configuration from the previous sections to run OpenOCD.
630+
631+
From another console, connect using gdb, e.g.:
632+
633+
```
634+
arm-none-eabi-gdb
635+
(gdb) target remote:3333
636+
```
637+
638+
To reset the board to start from the M0+ flash bootloader position (wolfBoot reset handler), use
639+
the monitor command sequence below:
640+
641+
```
642+
(gdb) mon init
643+
(gdb) mon reset init
644+
(gdb) mon psoc6 reset_halt
645+
```

hal/psoc6.c

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/* psoc6.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 <string.h>
25+
#include "image.h"
26+
27+
#include "cy_device_headers.h"
28+
29+
#include "cy_flash.h"
30+
#include "cy_syspm.h"
31+
#include "cy_sysclk.h"
32+
#include "cy_syslib.h"
33+
#include "cy_ipc_drv.h"
34+
35+
#include "psoc6_02_config.h"
36+
37+
#define ROW_SIZE (0x1000)
38+
#define FLASH_BASE_ADDRESS (0x10000000)
39+
#define CPU_FREQ (100000000)
40+
41+
uint8_t psoc6_write_buffer[ROW_SIZE];
42+
43+
#ifndef NVM_FLASH_WRITEONCE
44+
# error "wolfBoot psoc6 HAL: no WRITEONCE support detected. Please define NVM_FLASH_WRITEONCE"
45+
#endif
46+
47+
#ifdef __WOLFBOOT
48+
static const cy_stc_pll_manual_config_t srss_0_clock_0_pll_0_pllConfig =
49+
{
50+
.feedbackDiv = 100,
51+
.referenceDiv = 2,
52+
.outputDiv = 4,
53+
.lfMode = false,
54+
.outputMode = CY_SYSCLK_FLLPLL_OUTPUT_AUTO,
55+
};
56+
57+
static void hal_set_pll(void)
58+
{
59+
/*Set clock path 1 source to IMO, this feeds PLL1*/
60+
Cy_SysClk_ClkPathSetSource(1U, CY_SYSCLK_CLKPATH_IN_IMO);
61+
62+
/*Set the input for CLK_HF0 to the output of the PLL, which is on clock path 1*/
63+
Cy_SysClk_ClkHfSetSource(0U, CY_SYSCLK_CLKHF_IN_CLKPATH1);
64+
Cy_SysClk_ClkHfSetDivider(0U, CY_SYSCLK_CLKHF_NO_DIVIDE);
65+
66+
/*Set divider for CM4 clock to 0, might be able to lower this to save power if needed*/
67+
Cy_SysClk_ClkFastSetDivider(0U);
68+
69+
/*Set divider for peripheral and CM0 clock to 0 - This must be 0 to get fastest clock to CM0*/
70+
Cy_SysClk_ClkPeriSetDivider(0U);
71+
72+
/*Set divider for CM0 clock to 0*/
73+
Cy_SysClk_ClkSlowSetDivider(0U);
74+
75+
/*Set flash memory wait states */
76+
Cy_SysLib_SetWaitStates(false, 100);
77+
78+
/*Configure PLL for 100 MHz*/
79+
if (CY_SYSCLK_SUCCESS != Cy_SysClk_PllManualConfigure(1U, &srss_0_clock_0_pll_0_pllConfig))
80+
{
81+
while(1)
82+
;
83+
}
84+
/*Enable PLL*/
85+
if (CY_SYSCLK_SUCCESS != Cy_SysClk_PllEnable(1U, 10000u))
86+
{
87+
while(1)
88+
;
89+
}
90+
}
91+
92+
void hal_init(void)
93+
{
94+
Cy_PDL_Init(CY_DEVICE_CFG);
95+
Cy_Flash_Init();
96+
hal_set_pll();
97+
}
98+
99+
void hal_prepare_boot(void)
100+
{
101+
}
102+
103+
#endif
104+
105+
106+
/* Only Row-aligned writes allowed. This is guaranteed by wolfBoot if NVM_CACHE is
107+
* in use (via NVM_FLASH_WRITEONCE=1), as unaligned writes become cached.
108+
*/
109+
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
110+
{
111+
const uint8_t *src = data;
112+
if (len < ROW_SIZE)
113+
return -1;
114+
if ((((uint32_t)data) & FLASH_BASE_ADDRESS) == FLASH_BASE_ADDRESS) {
115+
if (len != ROW_SIZE) {
116+
return -1;
117+
}
118+
memcpy(psoc6_write_buffer, data, len);
119+
src = psoc6_write_buffer;
120+
}
121+
while (len) {
122+
Cy_Flash_ProgramRow(address, (const uint32_t *) src);
123+
len -= ROW_SIZE;
124+
if ((len > 0) && (len < ROW_SIZE))
125+
return -1;
126+
}
127+
return 0;
128+
}
129+
130+
void RAMFUNCTION hal_flash_unlock(void)
131+
{
132+
}
133+
134+
void RAMFUNCTION hal_flash_lock(void)
135+
{
136+
}
137+
138+
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
139+
{
140+
int start = -1, end = -1;
141+
uint32_t end_address;
142+
uint32_t p = (uint32_t)address;
143+
if (len == 0)
144+
return -1;
145+
end_address = address + len;
146+
while ((end_address - p) >= ROW_SIZE) {
147+
Cy_Flash_EraseRow(p);
148+
p += ROW_SIZE;
149+
}
150+
return 0;
151+
}
152+

0 commit comments

Comments
 (0)