cypress: Rework makefiles, reorganise source, add 062_1M and 062_512k support
Signed-off-by: Roman Okhrimenko <roman.okhrimenko@cypress.com>
Signed-off-by: Roman Okhrimenko <roman.okhrimenko@infineon.com>
diff --git a/boot/cypress/MCUBootApp/MCUBootApp.ld b/boot/cypress/MCUBootApp/MCUBootApp.ld
index c620479..c78c598 100644
--- a/boot/cypress/MCUBootApp/MCUBootApp.ld
+++ b/boot/cypress/MCUBootApp/MCUBootApp.ld
@@ -63,7 +63,8 @@
* Your changes must be aligned with the corresponding memory regions for the CM4 core in 'xx_cm4_dual.ld',
* where 'xx' is the device group; for example, 'cy8c6xx7_cm4_dual.ld'.
*/
- ram (rwx) : ORIGIN = 0x08020000, LENGTH = 0x20000
+ public_ram (rw) : ORIGIN = 0x08000000, LENGTH = 0x800
+ ram (rwx) : ORIGIN = 0x08000800, LENGTH = 0x1F800
flash (rx) : ORIGIN = 0x10000000, LENGTH = 0x18000
/* This is a 32K flash region used for EEPROM emulation. This region can also be used as the general purpose flash.
@@ -233,6 +234,15 @@
__ram_vectors_end__ = .;
} > ram
+ /* Unprotected public RAM */
+ .cy_sharedmem (NOLOAD):
+ {
+ . = ALIGN(4);
+ __public_ram_start__ = .;
+ KEEP(*(.cy_sharedmem))
+ . = ALIGN(4);
+ __public_ram_end__ = .;
+ } > public_ram
.data __ram_vectors_end__ : AT (__etext)
{
diff --git a/boot/cypress/MCUBootApp/MCUBootApp.mk b/boot/cypress/MCUBootApp/MCUBootApp.mk
index 7a15ce5..44da2fb 100644
--- a/boot/cypress/MCUBootApp/MCUBootApp.mk
+++ b/boot/cypress/MCUBootApp/MCUBootApp.mk
@@ -23,6 +23,8 @@
# limitations under the License.
################################################################################
+include host.mk
+
# Cypress' MCUBoot Application supports GCC ARM only at this moment
# Set default compiler to GCC if not specified from command line
COMPILER ?= GCC_ARM
@@ -32,15 +34,18 @@
MCUBOOT_IMAGE_NUMBER ?= 1
ENC_IMG ?= 0
+# For which core this application is built
+CORE ?= CM0P
+
ifneq ($(COMPILER), GCC_ARM)
$(error Only GCC ARM is supported at this moment)
endif
-CUR_APP_PATH = $(CURDIR)/$(APP_NAME)
+CUR_APP_PATH = $(PRJ_DIR)/$(APP_NAME)
-include $(CUR_APP_PATH)/platforms.mk
-include $(CUR_APP_PATH)/libs.mk
-include $(CUR_APP_PATH)/toolchains.mk
+include $(PRJ_DIR)/platforms.mk
+include $(PRJ_DIR)/common_libs.mk
+include $(PRJ_DIR)/toolchains.mk
# default slot size is 0x10000, 512bytes per row/sector, so 128 sectors
MAX_IMG_SECTORS ?= 128
@@ -91,6 +96,7 @@
INCLUDE_DIRS_APP += $(addprefix -I, $(CUR_APP_PATH)/os)
ASM_FILES_APP :=
+ASM_FILES_APP += $(ASM_FILES_STARTUP)
# Output folder
OUT := $(APP_NAME)/out
diff --git a/boot/cypress/MCUBootApp/config/mcuboot_config/mcuboot_config.h b/boot/cypress/MCUBootApp/config/mcuboot_config/mcuboot_config.h
index 196bbd6..a58d584 100644
--- a/boot/cypress/MCUBootApp/config/mcuboot_config/mcuboot_config.h
+++ b/boot/cypress/MCUBootApp/config/mcuboot_config/mcuboot_config.h
@@ -129,7 +129,8 @@
* defining BOOT_LOG_LEVEL before #including `bootutil_log.h`
*/
#define MCUBOOT_HAVE_LOGGING 1
-
+/* Define this to support native mcuboot logging system */
+#define CONFIG_MCUBOOT 1
/*
* Assertions
*/
diff --git a/boot/cypress/MCUBootApp/libs.mk b/boot/cypress/MCUBootApp/libs.mk
index 3dc7027..3fe8220 100644
--- a/boot/cypress/MCUBootApp/libs.mk
+++ b/boot/cypress/MCUBootApp/libs.mk
@@ -28,79 +28,69 @@
################################################################################
PDL_VERSION = 121
-CUR_LIBS_PATH = $(CURDIR)/libs
-MBEDTLS_PATH = $(CURDIR)/../../ext
+THIS_APP_PATH = $(PRJ_DIR)/libs
+MBEDTLS_PATH = $(PRJ_DIR)/../../ext
-# Collect source files for PDL
-SOURCES_PDL := $(wildcard $(CUR_LIBS_PATH)/pdl/psoc6pdl/drivers/source/*.c)
-SOURCES_WATCHDOG := $(wildcard $(CUR_LIBS_PATH)/watchdog/*.c)
+# Add platform folder to build
+SOURCES_PLATFORM += $(wildcard $(PRJ_DIR)/platforms/*.c)
+SOURCES_WATCHDOG := $(wildcard $(THIS_APP_PATH)/watchdog/*.c)
-# PDL related include directories
-INCLUDE_DIRS_PDL := $(CUR_LIBS_PATH)/pdl/psoc6pdl/drivers/include
-INCLUDE_DIRS_PDL += $(CUR_LIBS_PATH)/pdl/psoc6pdl/devices/include/ip
-INCLUDE_DIRS_PDL += $(CUR_LIBS_PATH)/pdl/psoc6pdl/devices/include
-INCLUDE_DIRS_PDL += $(CUR_LIBS_PATH)/pdl/psoc6pdl/cmsis/include
+# Add retartget IO implementation using pdl
+SOURCES_RETARGET_IO_PDL += $(wildcard $(THIS_APP_PATH)/retarget_io_pdl/*.c)
-# core-libs related include directories
-INCLUDE_DIRS_CORE_LIB := $(CUR_LIBS_PATH)/core-lib/include
-INCLUDE_DIRS_WATCHDOG := $(CUR_LIBS_PATH)/watchdog
+# Collect dirrectories containing headers for PLATFORM
+INCLUDE_RETARGET_IO_PDL += $(THIS_APP_PATH)/retarget_io_pdl
+
+# PSOC6HAL source files
+SOURCES_HAL += $(THIS_APP_PATH)/psoc6hal/COMPONENT_PSOC6HAL/source/cyhal_crypto_common.c
+SOURCES_HAL += $(THIS_APP_PATH)/psoc6hal/COMPONENT_PSOC6HAL/source/cyhal_hwmgr.c
+
+# MbedTLS source files
+SOURCES_MBEDTLS := $(wildcard $(MBEDTLS_PATH)/mbedtls/library/*.c)
+SOURCES_MBEDTLS += $(wildcard $(MBEDTLS_PATH)/mbedtls/crypto/library/*.c)
# Collected source files for libraries
-SOURCES_LIBS := $(SOURCES_PDL)
+SOURCES_LIBS += $(SOURCES_HAL)
+SOURCES_LIBS += $(SOURCES_MBEDTLS)
SOURCES_LIBS += $(SOURCES_WATCHDOG)
SOURCES_LIBS += $(SOURCES_PLATFORM)
+SOURCES_LIBS += $(SOURCES_RETARGET_IO_PDL)
-# Collected include directories for libraries
-INCLUDE_DIRS_LIBS := $(addprefix -I,$(INCLUDE_DIRS_PDL))
-INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_PLATFORM))
-INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_CORE_LIB))
-INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_WATCHDOG))
-INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_HAL))
+# Include platforms folder
+INCLUDE_DIRS_PLATFORM := $(PRJ_DIR)/platforms
-################################################################################
-# mbedTLS settings
-################################################################################
+# needed for Crypto HW Acceleration and headers inclusion, do not use for peripherals
+# peripherals should be accessed
+INCLUDE_DIRS_HAL := $(THIS_APP_PATH)/psoc6hal/COMPONENT_PSOC6HAL/include
+INCLUDE_DIRS_HAL += $(THIS_APP_PATH)/psoc6hal/include
+INCLUDE_DIRS_HAL += $(THIS_APP_PATH)/psoc6hal/COMPONENT_PSOC6HAL/include/pin_packages
+
# MbedTLS related include directories
INCLUDE_DIRS_MBEDTLS += $(MBEDTLS_PATH)/mbedtls/include
INCLUDE_DIRS_MBEDTLS += $(MBEDTLS_PATH)/mbedtls/include/mbedtls
INCLUDE_DIRS_MBEDTLS += $(MBEDTLS_PATH)/mbedtls/crypto/include
INCLUDE_DIRS_MBEDTLS += $(MBEDTLS_PATH)/mbedtls/crypto/include/mbedtls
-#
+
+# Watchdog related includes
+INCLUDE_DIRS_WATCHDOG := $(THIS_APP_PATH)/watchdog
+
+# Collected include directories for libraries
+INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_HAL))
+INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_WATCHDOG))
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_MBEDTLS))
-# Collect source files for MbedTLS
-SOURCES_MBEDTLS := $(wildcard $(MBEDTLS_PATH)/mbedtls/library/*.c)
-SOURCES_MBEDTLS += $(wildcard $(MBEDTLS_PATH)/mbedtls/crypto/library/*.c)
-# Collected source files for libraries
-SOURCES_LIBS += $(SOURCES_MBEDTLS)
-## mbedTLS settings
+INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_RETARGET_IO_PDL))
+INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_PLATFORM))
################################################################################
-# mbedTLS acceleration settings
+# mbedTLS hardware acceleration settings
################################################################################
ifeq ($(USE_CRYPTO_HW), 1)
# cy-mbedtls-acceleration related include directories
-INCLUDE_DIRS_MBEDTLS_MXCRYPTO := $(CUR_LIBS_PATH)/cy-mbedtls-acceleration/mbedtls_MXCRYPTO
+INCLUDE_DIRS_MBEDTLS_MXCRYPTO := $(THIS_APP_PATH)/cy-mbedtls-acceleration/mbedtls_MXCRYPTO
# Collect source files for MbedTLS acceleration
-SOURCES_MBEDTLS_MXCRYPTO := $(wildcard $(CUR_LIBS_PATH)/cy-mbedtls-acceleration/mbedtls_MXCRYPTO/*.c)
+SOURCES_MBEDTLS_MXCRYPTO := $(wildcard $(THIS_APP_PATH)/cy-mbedtls-acceleration/mbedtls_MXCRYPTO/*.c)
#
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_MBEDTLS_MXCRYPTO))
# Collected source files for libraries
SOURCES_LIBS += $(SOURCES_MBEDTLS_MXCRYPTO)
endif
-## mbedTLS acceleration settings
-
-ASM_FILES_PDL :=
-ifeq ($(COMPILER), GCC_ARM)
-ASM_FILES_PDL += $(CUR_LIBS_PATH)/pdl/psoc6pdl/drivers/source/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.S
-else
-$(error Only GCC ARM is supported at this moment)
-endif
-
-ASM_FILES_LIBS := $(ASM_FILES_PDL)
-ASM_FILES_LIBS += $(ASM_FILES_PLATFORM)
-
-# Add define for PDL version
-DEFINES_PDL += -DPDL_VERSION=$(PDL_VERSION)
-
-DEFINES_LIBS := $(DEFINES_PLATFORM)
-DEFINES_LIBS += $(DEFINES_PDL)
diff --git a/boot/cypress/MCUBootApp/main.c b/boot/cypress/MCUBootApp/main.c
index 6c28ba0..6f987a6 100644
--- a/boot/cypress/MCUBootApp/main.c
+++ b/boot/cypress/MCUBootApp/main.c
@@ -84,10 +84,25 @@
bool boot_succeeded = false;
fih_int fih_rc = FIH_FAILURE;
- init_cycfg_clocks();
+ SystemInit();
+ //init_cycfg_clocks();
init_cycfg_peripherals();
init_cycfg_pins();
+ /* Certain PSoC 6 devices enable CM4 by default at startup. It must be
+ * either disabled or enabled & running a valid application for flash write
+ * to work from CM0+. Since flash write may happen in boot_go() for updating
+ * the image before this bootloader app can enable CM4 in do_boot(), we need
+ * to keep CM4 disabled. Note that debugging of CM4 is not supported when it
+ * is disabled.
+ */
+ #if defined(CY_DEVICE_PSOC6ABLE2)
+ if (CY_SYS_CM4_STATUS_ENABLED == Cy_SysGetCM4Status())
+ {
+ Cy_SysDisableCM4();
+ }
+ #endif /* #if defined(CY_DEVICE_PSOC6ABLE2) */
+
/* enable interrupts */
__enable_irq();
diff --git a/boot/cypress/MCUBootApp/platforms.mk b/boot/cypress/MCUBootApp/platforms.mk
deleted file mode 100644
index d454a90..0000000
--- a/boot/cypress/MCUBootApp/platforms.mk
+++ /dev/null
@@ -1,84 +0,0 @@
-################################################################################
-# \file targets.mk
-# \version 1.0
-#
-# \brief
-# Makefile to describe supported boards and platforms for Cypress MCUBoot based applications.
-#
-################################################################################
-# \copyright
-# Copyright 2018-2019 Cypress Semiconductor Corporation
-# SPDX-License-Identifier: Apache-2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-################################################################################
-
-# Target platform MCUBootApp is built for. PSOC_062_2M is set by default# Supported:
-# - PSOC_062_2M
-
-# default PLATFORM
-PLATFORM ?= PSOC_062_2M
-#
-PLATFORMS := PSOC_062_2M
-
-# For which core this application is built
-CORE := CM0P
-
-# Set paths for related folders
-PLATFORM_PATH := $(CURDIR)/platforms
-
-# MCU device selection, based on target device.
-# Default chips are used for supported platforms
-# This can be redefined in case of other chip usage
-ifeq ($(PLATFORM), PSOC_062_2M)
-DEVICE ?= CY8C624ABZI-D44
-PLATFORM_SUFFIX := 02
-endif
-
-# Collect C source files for PLATFORM
-SOURCES_PLATFORM += $(wildcard $(PLATFORM_PATH)/*.c)
-SOURCES_PLATFORM := $(filter-out %/system_psoc6_cm4.c, $(SOURCES_PLATFORM))
-SOURCES_PLATFORM += $(wildcard $(PLATFORM_PATH)/retarget_io_pdl/*.c)
-
-# Collect dirrectories containing headers for PLATFORM
-INCLUDE_DIRS_PLATFORM := $(PLATFORM_PATH)
-INCLUDE_DIRS_PLATFORM += $(PLATFORM_PATH)/retarget_io_pdl
-# Collect Assembler files for PLATFORM
-# Include _01_, _02_ or _03_ PLATFORM_SUFFIX depending on device family.
-STARTUP_FILE := $(PLATFORM_PATH)/$(PLATFORM)/$(CORE)/$(COMPILER)/startup_psoc6_$(PLATFORM_SUFFIX)_cm0plus
-
-ifeq ($(COMPILER), GCC_ARM)
- ASM_FILES_PLATFORM := $(STARTUP_FILE).S
-else
-$(error Only GCC ARM is supported at this moment)
-endif
-
-# Add device name to defines
-DEFINES += $(DEVICE)
-DEFINES += $(PLATFORM)
-
-# Convert defines it to regular -DMY_NAME style
-ifneq ($(DEFINES),)
- DEFINES_PLATFORM :=$(addprefix -D, $(subst -,_,$(DEFINES)))
-endif
-
-ifeq ($(COMPILER), GCC_ARM)
-LINKER_SCRIPT ?= $(PLATFORM_PATH)/$(PLATFORM)/$(CORE)/$(COMPILER)/*_cm0plus.ld
-else
-$(error Only GCC ARM is supported at this moment)
-endif
-
-ifeq ($(MAKEINFO) , 1)
-$(info $(SOURCES_PLATFORM))
-$(info $(ASM_FILES_PLATFORM))
-endif
diff --git a/boot/cypress/MCUBootApp/toolchains.mk b/boot/cypress/MCUBootApp/toolchains.mk
deleted file mode 100644
index 562ce73..0000000
--- a/boot/cypress/MCUBootApp/toolchains.mk
+++ /dev/null
@@ -1,141 +0,0 @@
-################################################################################
-# \file toolchains.mk
-# \version 1.0
-#
-# \brief
-# Makefile to describe supported toolchains for Cypress MCUBoot based applications.
-#
-################################################################################
-# \copyright
-# Copyright 2018-2019 Cypress Semiconductor Corporation
-# SPDX-License-Identifier: Apache-2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-################################################################################
-
-# Compilers
-GCC_ARM := 1
-IAR := 2
-ARM := 3
-OTHER := 4
-
-ifeq ($(MAKEINFO), 1)
-$(info $(COMPILER))
-endif
-# Detect host OS to make resolving compiler pathes easier
-UNAME_S := $(shell uname -s)
-ifeq ($(UNAME_S), Darwin)
- HOST_OS = osx
-else
- ifeq ($(UNAME_S), Linux)
- HOST_OS = linux
- else
- HOST_OS = win
- endif
-endif
-
-# Path to the compiler installation
-# NOTE: Absolute pathes for now for the sake of development
-ifeq ($(HOST_OS), win)
- ifeq ($(COMPILER), GCC_ARM)
- TOOLCHAIN_PATH ?= c:/Users/$(USERNAME)/ModusToolbox/tools_2.1/gcc-7.2.1
- MY_TOOLCHAIN_PATH:=$(subst \,/,$(TOOLCHAIN_PATH))
- TOOLCHAIN_PATH := $(MY_TOOLCHAIN_PATH)
- GCC_PATH := $(TOOLCHAIN_PATH)
- # executables
- CC := "$(GCC_PATH)/bin/arm-none-eabi-gcc"
- LD := $(CC)
-
- else ifeq ($(COMPILER), IAR)
- IAR_PATH := C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm
- # executables
- CC := "$(IAR_PATH)/bin/iccarm.exe"
- AS := "$(IAR_PATH)/bin/iasmarm.exe"
- LD := "$(IAR_PATH)/bin/ilinkarm.exe"
- endif
-
-else ifeq ($(HOST_OS), osx)
- TOOLCHAIN_PATH ?= /opt/gcc-arm-none-eabi
- GCC_PATH := $(TOOLCHAIN_PATH)
-
- CC := "$(GCC_PATH)/bin/arm-none-eabi-gcc"
- LD := $(CC)
-
-else ifeq ($(HOST_OS), linux)
- TOOLCHAIN_PATH ?= /usr/bin/gcc-arm-none-eabi/bin/arm-none-eabi-gcc
- GCC_PATH := $(TOOLCHAIN_PATH)
- # executables
- CC := "$(GCC_PATH)/bin/arm-none-eabi-gcc"
- LD := $(CC)
-endif
-
-PDL_ELFTOOL := "hal/tools/$(HOST_OS)/elf/cymcuelftool"
-
-# Set executable names for compilers
-ifeq ($(COMPILER), GCC_ARM)
- CC := "$(GCC_PATH)/bin/arm-none-eabi-gcc"
- LD := $(CC)
-else
- CC := "$(IAR_PATH)/bin/iccarm.exe"
- AS := "$(IAR_PATH)/bin/iasmarm.exe"
- LD := "$(IAR_PATH)/bin/ilinkarm.exe"
-endif
-
-OBJDUMP := "$(GCC_PATH)/bin/arm-none-eabi-objdump"
-OBJCOPY := "$(GCC_PATH)/bin/arm-none-eabi-objcopy"
-
-# Set flags for toolchain executables
-
-ifeq ($(COMPILER), GCC_ARM)
- # set build-in compiler flags
- CFLAGS_COMMON := -mcpu=cortex-m0plus -mthumb -mfloat-abi=soft -fno-stack-protector -ffunction-sections -fdata-sections -ffat-lto-objects -fstrict-aliasing -g -Wall -Wextra
- ifeq ($(BUILDCFG), Debug)
- CFLAGS_COMMON += -Og -g3
- else ifeq ($(BUILDCFG), Release)
- CFLAGS_COMMON += -Os -g
- else
-$(error BUILDCFG : '$(BUILDCFG)' is not supported)
- endif
- # add defines and includes
- CFLAGS := $(CFLAGS_COMMON) $(INCLUDES)
- CC_DEPEND = -MD -MP -MF
-
- LDFLAGS_COMMON := -mcpu=cortex-m0plus -mthumb -specs=nano.specs -ffunction-sections -fdata-sections -Wl,--gc-sections -L "$(GCC_PATH)/lib/gcc/arm-none-eabi/7.2.1/thumb/v6-m" -ffat-lto-objects -g --enable-objc-gc
- ifeq ($(BUILDCFG), Debug)
- LDFLAGS_COMMON += -Og
- else ifeq ($(BUILDCFG), Release)
- LDFLAGS_COMMON += -Os
- else
-$(error BUILDCFG : '$(BUILDCFG)' is not supported)
- endif
- LDFLAGS_NANO := -L "$(GCC_PATH)/arm-none-eabi/lib/thumb/v6-m"
- # TODO: check .map name
- LDFLAGS := $(LDFLAGS_COMMON) $(LDFLAGS_NANO)
-
-else ifeq ($(COMPILER), IAR)
-
- CFLAGS := --debug --endian=little --cpu=Cortex-M0+ -e --fpu=None --dlib_config "$(IAR_PATH)\INC\c\DLib_Config_Normal.h"
- CFLAGS += -Ohz --silent
-# CFLAGS += $(DEFINES) $(INCLUDES)
- CFLAGS += $(INCLUDES)
- CC_DEPEND = --dependencies
-
- AS_FLAGS := -s+ "-M<>" -w+ -r --cpu Cortex-M0+ --fpu None -S
-
- LINKER_SCRIPT := $(CHIP_SERIES).icf
-
- #options to extend stack analize: --log call_graph --log_file $(OUT)/stack_usage_$(SUFFIX).txt
- LDFLAGS_STACK_USAGE := --stack_usage_control $(STACK_CONTROL_FILE) --diag_suppress=Ls015 --diag_suppress=Ls016
- LDFLAGS_COMMON := --vfe --text_out locale --silent --inline --merge_duplicate_sections
- LDFLAGS := $(LDFLAGS_COMMON) $(LDFLAGS_STACK_USAGE) --config $(LINKER_SCRIPT) --map $(OUT_APP)/$(APP_NAME).map --entry Cy_FB_ResetHandler --no_exceptions
-endif