Skip to content

Commit 7563839

Browse files
danielinuxdgarske
authored andcommitted
Initial draft for psoc6 support
1 parent 6a82cd5 commit 7563839

7 files changed

Lines changed: 263 additions & 18 deletions

File tree

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: 31 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,37 @@ ifeq ($(TARGET),stm32wb)
162151
endif
163152
endif
164153

154+
ifeq ($(TARGET),psoc6)
155+
PKA_EXTRA_OBJS+= $(CYPRESS_PDL)/drivers/source/cy_flash.o \
156+
$(CYPRESS_PDL)/drivers/source/cy_ipc_pipe.o \
157+
$(CYPRESS_PDL)/drivers/source/cy_ipc_sema.o \
158+
$(CYPRESS_PDL)/drivers/source/cy_ipc_drv.o \
159+
$(CYPRESS_PDL)/drivers/source/cy_device.o \
160+
$(CYPRESS_PDL)/drivers/source/cy_sysclk.o \
161+
$(CYPRESS_PDL)/drivers/source/cy_ble_clk.o \
162+
$(CYPRESS_PDL)/devices/templates/COMPONENT_MTB/COMPONENT_CM4/system_psoc6_cm4.o \
163+
$(CYPRESS_PDL)/drivers/source/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.o
164+
PKA_EXTRA_CFLAGS+=-I$(CYPRESS_PDL)/drivers/include/ \
165+
-I$(CYPRESS_PDL)/devices/psoc6/psoc63/include/ \
166+
-I$(CYPRESS_PDL)/devices/include \
167+
-I$(CYPRESS_PDL)/cmsis/include \
168+
-I$(CYPRESS_PDL)/core-lib/include \
169+
-I$(CYPRESS_PDL)/devices/templates/COMPONENT_MTB \
170+
-DCY8C6248FNI_S2D43
171+
ARCH_FLASH_OFFSET=0x10000000
172+
endif
173+
174+
CFLAGS+=-DARCH_FLASH_OFFSET=$(ARCH_FLASH_OFFSET)
175+
176+
## Toolchain setup
177+
CC=$(CROSS_COMPILE)gcc
178+
LD=$(CROSS_COMPILE)gcc
179+
AS=$(CROSS_COMPILE)gcc
180+
OBJCOPY:=$(CROSS_COMPILE)objcopy
181+
SIZE:=$(CROSS_COMPILE)size
182+
BOOT_IMG?=test-app/image.bin
183+
184+
165185

166186
## Update mechanism
167187
ifeq ($(ARCH),AARCH64)

hal/psoc6.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 "image.h"
25+
26+
#include "cy_device_headers.h"
27+
28+
#include "cy_flash.h"
29+
#include "cy_syspm.h"
30+
#include "cy_ipc_drv.h"
31+
32+
#ifndef NVM_FLASH_WRITEONCE
33+
# error "wolfBoot psoc6 HAL: no WRITEONCE support detected. Please define NVM_FLASH_WRITEONCE"
34+
#endif
35+
36+
37+
#ifdef __WOLFBOOT
38+
void hal_init(void)
39+
{
40+
/* TODO: how to set clock full speed? */
41+
}
42+
43+
void hal_prepare_boot(void)
44+
{
45+
/* TODO: how to restore boot-default clock speed? */
46+
}
47+
48+
#endif
49+
50+
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
51+
{
52+
if (len != WOLFBOOT_SECTOR_SIZE)
53+
return -1;
54+
Cy_Flash_WriteRow(address,(const uint32_t *) data);
55+
return 0;
56+
}
57+
58+
void RAMFUNCTION hal_flash_unlock(void)
59+
{
60+
}
61+
62+
void RAMFUNCTION hal_flash_lock(void)
63+
{
64+
}
65+
66+
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
67+
{
68+
int start = -1, end = -1;
69+
uint32_t end_address;
70+
uint32_t p;
71+
if (len == 0)
72+
return -1;
73+
end_address = address + len - 1;
74+
for (p = address; p < end_address; p += WOLFBOOT_SECTOR_SIZE) {
75+
Cy_Flash_EraseRow(p);
76+
}
77+
return 0;
78+
}
79+

hal/psoc6.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 = 0x10000000, 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);

hal/skeleton.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* skeleton.c
2+
*
3+
* Stubs for custom HAL implementation. Defines the
4+
* functions used by wolfboot for a specific target.
5+
*
6+
* Copyright (C) 2020 wolfSSL Inc.
7+
*
8+
* This file is part of wolfBoot.
9+
*
10+
* wolfBoot is free software; you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation; either version 2 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* wolfBoot is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program; if not, write to the Free Software
22+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
23+
*/
24+
25+
#include <stdint.h>
26+
#include <target.h>
27+
#include "image.h"
28+
29+
30+
#ifdef __WOLFBOOT
31+
void hal_init(void)
32+
{
33+
}
34+
35+
void hal_prepare_boot(void)
36+
{
37+
}
38+
39+
#endif
40+
41+
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
42+
{
43+
}
44+
45+
void RAMFUNCTION hal_flash_unlock(void)
46+
{
47+
}
48+
49+
void RAMFUNCTION hal_flash_lock(void)
50+
{
51+
}
52+
53+
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
54+
{
55+
}
56+

test-app/app_psoc6.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* main.c
2+
*
3+
* Test bare-metal boot-led-on application
4+
*
5+
* Copyright (C) 2020 wolfSSL Inc.
6+
*
7+
* This file is part of wolfBoot.
8+
*
9+
* wolfBoot is free software; you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation; either version 2 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* wolfBoot is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program; if not, write to the Free Software
21+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
22+
*/
23+
24+
#include <stdlib.h>
25+
#include <stdint.h>
26+
#include <string.h>
27+
#include "wolfboot/wolfboot.h"
28+
29+
30+
void main(void) {
31+
/* Wait for reboot */
32+
while(1)
33+
;
34+
}
35+

tools/config.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ifeq ($(ARCH),)
1010
MCUXPRESSO_CMSIS?=$(MCUXPRESSO)/CMSIS
1111
FREEDOM_E_SDK?=$(HOME)/src/freedom-e-sdk
1212
STM32CUBE?=$(HOME)/STM32Cube/Repository/STM32Cube_FW_WB_V1.3.0
13+
CYPRESS_PDL?=$(HOME)/src/Cypress-Peripheral-Driver-Library-v3.0.1
1314
DEBUG?=0
1415
VTOR?=1
1516
CORTEX_M0?=0
@@ -41,7 +42,7 @@ endif
4142

4243

4344
CONFIG_VARS:= ARCH TARGET SIGN HASH MCUXPRESSO MCUXPRESSO_CPU MCUXPRESSO_DRIVERS \
44-
MCUXPRESSO_CMSIS FREEDOM_E_SDK STM32CUBE DEBUG VTOR CORTEX_M0 NO_ASM EXT_FLASH \
45+
MCUXPRESSO_CMSIS FREEDOM_E_SDK STM32CUBE CYPRESS_PDL DEBUG VTOR CORTEX_M0 NO_ASM EXT_FLASH \
4546
SPI_FLASH NO_XIP UART_FLASH ALLOW_DOWNGRADE NVM_FLASH_WRITEONCE WOLFBOOT_VERSION V \
4647
SPMATH RAM_CODE DUALBANK_SWAP IMAGE_HEADER_SIZE PKA WOLFTPM \
4748
WOLFBOOT_PARTITION_SIZE WOLFBOOT_SECTOR_SIZE \

0 commit comments

Comments
 (0)