Commit 7725652e authored by Bohdan Kovalchuk's avatar Bohdan Kovalchuk Committed by David Brown
Browse files

Add files to eliminate HAL dependency, build/compile pass

parent 80a76f4a
Loading
Loading
Loading
Loading
+6 −6
Changes for boot/cypress/MCUBootApp/MCUBootApp.mk: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
################################################################################
# \file targets.mk
# \file MCUBootApp.mk
# \version 1.0
#
# \brief
# Makefile to describe supported boards and platforms for Cypress MCUBoot based applications.
# Makefile for Cypress MCUBoot-based application.
#
################################################################################
# \copyright
@@ -46,7 +46,6 @@ DEFINES_APP += -DECC256_KEY_FILE="\"keys/$(SIGN_KEY_FILE).pub\""
DEFINES_APP += -DCORE=$(CORE)
DEFINES_APP += -DMCUBOOT_IMAGE_NUMBER=$(MCUBOOT_IMAGE_NUMBER)


ifeq ($(USE_CRYPTO_HW), 1)
DEFINES_APP += -DMBEDTLS_USER_CONFIG_FILE="\"mcuboot_crypto_acc_config.h\""
endif
@@ -61,8 +60,9 @@ SOURCES_APP := $(SOURCES_MCUBOOT)
SOURCES_APP += $(SOURCES_APP_SRC)
SOURCES_APP += $(SOURCES_FLASH_PORT)

INCLUDES_DIRS_MCUBOOT := $(addprefix -I, $(CURDIR)/../bootutil/include)
INCLUDES_DIRS_MCUBOOT += $(addprefix -I, $(CURDIR)/../bootutil/src)
INCLUDE_DIRS_MCUBOOT := $(addprefix -I, $(CURDIR)/../bootutil/include)
INCLUDE_DIRS_MCUBOOT += $(addprefix -I, $(CURDIR)/../bootutil/src)
INCLUDE_DIRS_MCUBOOT += $(addprefix -I, $(CURDIR)/..)

INCLUDE_DIRS_APP := $(addprefix -I, $(CURDIR))
INCLUDE_DIRS_APP += $(addprefix -I, $(CURDIR)/cy_flash_pal/include)
@@ -80,7 +80,7 @@ OUT_TARGET := $(OUT)/$(PLATFORM)

OUT_CFG := $(OUT_TARGET)/$(BUILDCFG)

# Overwite path to linker script if custom is required, otherwise default from BSP is used
# Overwite path to linker script if custom is required
ifeq ($(COMPILER), GCC_ARM)
LINKER_SCRIPT := $(subst /cygdrive/c,c:,$(CUR_APP_PATH)/$(APP_NAME).ld)
else
+26 −0
Changes for boot/cypress/MCUBootApp/README.md: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -129,6 +129,32 @@ This folder contains make files infrastructure for building MCUBoot Bootloader.

Root directory for build is **boot/cypress.**

**Programming solution**

There are couple ways of programming hex of MCUBootApp and BlinkyApp. Following instructions assume one of Cypress development kits, for example `CY8CPROTO_062_4343W`.

1. Direct usage of OpenOCD.
OpenOCD package is supplied with ModuToolbox IDE and can be found in installation folder under `./tools_2.1/openocd`.
Open terminal application -  and execute following command after substitution `PATH_TO_APPLICATION.hex` and `OPENOCD` paths.

Connect a board to your computer. Switch Kitprog3 to DAP-BULK mode by pressing `SW3 MODE` button until `LED2 STATUS` constantly shines.

        export OPENOCD=/Applications/ModusToolbox/tools_2.1/openocd 

        ${OPENOCD}/bin/openocd -s ${OPENOCD}/scripts \
                            -f ${OPENOCD}/scripts/interface/kitprog3.cfg \
                            -f ${OPENOCD}/scripts/target/psoc6_2m.cfg \
                            -c "init; reset init; program PATH_TO_APPLICATION.hex" \
                            -c "resume; reset; exit" 

2. Using GUI tool `Cypress Programmer` - follow [link](https://www.cypress.com/products/psoc-programming-solutions) to download.
   Connect board to your computer. Switch Kitprog3 to DAP-BULK mode by pressing `SW3 MODE` button until `LED2 STATUS` constantly shines. Open `Cypress Programmer` and click `Connect`, then choose hex file: `MCUBootApp.hex` or `BlinkyApp.hex` and click `Program`.  Check log to ensure programming success. Reset board.

3. Using `DAPLINK`.
   Connect board to your computer. Switch embeded  Kitprog3 to `DAPLINK` mode by pressing `SW3 MODE` button until `LED2 STATUS` blinks fast and mass storage device appeared in OS. Drag and drop `hex` files you wish to program to `DAPLINK` drive in your OS.



**Currently supported platforms:**

* PSOC_062_2M
+244 −0
Changes for boot/cypress/MCUBootApp/cy_retarget_io_pdl.c: 244 added lines, 0 removed lines.
Original line number Diff line number Diff line
/***************************************************************************//**
* \file cy_retarget_io.c
*
* \brief
* Provides APIs for retargeting stdio to UART hardware contained on the Cypress
* kits.
*
********************************************************************************
* \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.
*******************************************************************************/

#include "cy_retarget_io_pdl.h"

#include "cycfg_peripherals.h"

#include "cy_sysint.h"
#include "cy_scb_uart.h"

#if defined(__cplusplus)
extern "C" {
#endif

/* Tracks the previous character sent to output stream */
#ifdef CY_RETARGET_IO_CONVERT_LF_TO_CRLF
static char cy_retarget_io_stdout_prev_char = 0;
#endif /* CY_RETARGET_IO_CONVERT_LF_TO_CRLF */

cy_stc_scb_uart_context_t CYBSP_UART_context;

static uint8_t cy_retarget_io_getchar(void);
static void cy_retarget_io_putchar(char c);

#if defined(__ARMCC_VERSION) /* ARM-MDK */
    /***************************************************************************
    * Function Name: fputc
    ***************************************************************************/
    __attribute__((weak)) int fputc(int ch, FILE *f)
    {
        (void)f;
    #ifdef CY_RETARGET_IO_CONVERT_LF_TO_CRLF
        if ((char)ch == '\n' && cy_retarget_io_stdout_prev_char != '\r')
        {
            cy_retarget_io_putchar('\r');
        }

        cy_retarget_io_stdout_prev_char = (char)ch;
    #endif /* CY_RETARGET_IO_CONVERT_LF_TO_CRLF */
        cy_retarget_io_putchar(ch);
        return (ch);
    }
#elif defined (__ICCARM__) /* IAR */
    #include <yfuns.h>

    /***************************************************************************
    * Function Name: __write
    ***************************************************************************/
    __weak size_t __write(int handle, const unsigned char * buffer, size_t size)
    {
        size_t nChars = 0;
        /* This template only writes to "standard out", for all other file
        * handles it returns failure. */
        if (handle != _LLIO_STDOUT)
        {
            return (_LLIO_ERROR);
        }
        if (buffer != NULL)
        {
            for (/* Empty */; nChars < size; ++nChars)
            {
            #ifdef CY_RETARGET_IO_CONVERT_LF_TO_CRLF
                if (*buffer == '\n' && cy_retarget_io_stdout_prev_char != '\r')
                {
                    cy_retarget_io_putchar('\r');
                }

                cy_retarget_io_stdout_prev_char = *buffer;
            #endif /* CY_RETARGET_IO_CONVERT_LF_TO_CRLF */
                cy_retarget_io_putchar(*buffer);
                ++buffer;
            }
        }
        return (nChars);
    }
#else /* (__GNUC__)  GCC */
    /* Add an explicit reference to the floating point printf library to allow
    the usage of floating point conversion specifier. */
    __asm (".global _printf_float");
    /***************************************************************************
    * Function Name: _write
    ***************************************************************************/
    __attribute__((weak)) int _write (int fd, const char *ptr, int len)
    {
        int nChars = 0;
        (void)fd;
        if (ptr != NULL)
        {
            for (/* Empty */; nChars < len; ++nChars)
            {
            #ifdef CY_RETARGET_IO_CONVERT_LF_TO_CRLF
                if (*ptr == '\n' && cy_retarget_io_stdout_prev_char != '\r')
                {
                    cy_retarget_io_putchar('\r');
                }

                cy_retarget_io_stdout_prev_char = *ptr;
            #endif /* CY_RETARGET_IO_CONVERT_LF_TO_CRLF */
                cy_retarget_io_putchar((uint32_t)*ptr);
                ++ptr;
            }
        }
        return (nChars);
    }
#endif


#if defined(__ARMCC_VERSION) /* ARM-MDK */
    /***************************************************************************
    * Function Name: fgetc
    ***************************************************************************/
    __attribute__((weak)) int fgetc(FILE *f)
    {
        (void)f;
        return (cy_retarget_io_getchar());
    }
#elif defined (__ICCARM__) /* IAR */
    __weak size_t __read(int handle, unsigned char * buffer, size_t size)
    {
        /* This template only reads from "standard in", for all other file
        handles it returns failure. */
        if ((handle != _LLIO_STDIN) || (buffer == NULL))
        {
            return (_LLIO_ERROR);
        }
        else
        {
            *buffer = cy_retarget_io_getchar();
            return (1);
        }
    }
#else /* (__GNUC__)  GCC */
    /* Add an explicit reference to the floating point scanf library to allow
    the usage of floating point conversion specifier. */
    __asm (".global _scanf_float");
    __attribute__((weak)) int _read (int fd, char *ptr, int len)
    {
        int nChars = 0;
        (void)fd;
        if (ptr != NULL)
        {
            for(/* Empty */;nChars < len;++ptr)
            {
                *ptr = (char)cy_retarget_io_getchar();
                ++nChars;
                if((*ptr == '\n') || (*ptr == '\r'))
                {
                    break;
                }
            }
        }
        return (nChars);
    }
#endif

static uint8_t cy_retarget_io_getchar(void)
{
    uint32_t read_value = Cy_SCB_UART_Get(CYBSP_UART_HW);
    while (read_value == CY_SCB_UART_RX_NO_DATA)
    {
        read_value = Cy_SCB_UART_Get(CYBSP_UART_HW);
    }

    return (uint8_t)read_value;
}

static void cy_retarget_io_putchar(char c)
{
    uint32_t count = 0;
    while (count == 0)
    {
        count = Cy_SCB_UART_Put(CYBSP_UART_HW, c);
    }
}

static cy_rslt_t cy_retarget_io_pdl_setbaud(CySCB_Type *base, uint32_t baudrate)
{
    cy_rslt_t status;

    uint8_t oversample_value = 8u;
    uint8_t frac_bits = 0u;
    uint32_t divider;

    Cy_SCB_UART_Disable(base, NULL);

    Cy_SysClk_PeriphDisableDivider(CY_SYSCLK_DIV_16_BIT, 0);

    divider = ((Cy_SysClk_ClkPeriGetFrequency() * (1 << frac_bits)) + ((baudrate * oversample_value) / 2)) / (baudrate * oversample_value) - 1;

    status = (cy_rslt_t) Cy_SysClk_PeriphSetDivider(CY_SYSCLK_DIV_16_BIT, 0u, divider);

    Cy_SysClk_PeriphEnableDivider(CY_SYSCLK_DIV_16_BIT, 0u);

    Cy_SCB_UART_Enable(base);

    return status;
}

cy_rslt_t cy_retarget_io_pdl_init(uint32_t baudrate)
{
    cy_rslt_t result;

    /* Configure and enable UART */
    (void)Cy_SCB_UART_Init(CYBSP_UART_HW, &CYBSP_UART_config, &CYBSP_UART_context);

    cy_retarget_io_pdl_setbaud(CYBSP_UART_HW, baudrate);

    Cy_SCB_UART_Enable(CYBSP_UART_HW);

    result = CY_RSLT_SUCCESS;

    return result;
}

void cy_retarget_io_pdl_deinit()
{
    Cy_SCB_UART_DeInit(CYBSP_UART_HW);
}

#if defined(__cplusplus)
}
#endif
+60 −0
Changes for boot/cypress/MCUBootApp/cy_retarget_io_pdl.h: 60 added lines, 0 removed lines.
Original line number Diff line number Diff line
/***************************************************************************//**
* \file cy_retarget_io.h
*
* \brief
* Provides APIs for transmitting messages to or from the board via standard
* printf/scanf functions. Messages are transmitted over a UART connection which
* is generally connected to a host machine. Transmission is done at 115200 baud
* using the tx and rx pins provided by the user of this library. The UART
* instance is made available via cy_retarget_io_uart_obj in case any changes
* to the default configuration are desired.
* NOTE: If the application is built using newlib-nano, by default, floating
* point format strings (%f) are not supported. To enable this support you must
* add '-u _printf_float' to the linker command line.
*
********************************************************************************
* \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.
*******************************************************************************/

#pragma once

#include <stdio.h>
#include "cy_result.h"
#include "cy_pdl.h"

#if defined(__cplusplus)
extern "C" {
#endif

/** UART baud rate */
#define CY_RETARGET_IO_BAUDRATE             (115200)

/** Defining this macro enables conversion of line feed (LF) into carriage
 * return followed by line feed (CR & LF) on the output direction (STDOUT). You
 * can define this macro through the DEFINES variable in the application
 * Makefile.
 */
#define CY_RETARGET_IO_CONVERT_LF_TO_CRLF

cy_rslt_t cy_retarget_io_pdl_init(uint32_t baudrate);

void cy_retarget_io_pdl_deinit(void);

#if defined(__cplusplus)
}
#endif
+44 −0
Changes for boot/cypress/MCUBootApp/cy_security_cnt.c: 44 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
 * Copyright (c) 2020 Arm Limited.
 *
 * 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.
 */

#include "bootutil/security_cnt.h"
#include <stdint.h>

int32_t
boot_nv_security_counter_init(void)
{
    /* Do nothing. */
    return 0;
}

int32_t
boot_nv_security_counter_get(uint32_t image_id, uint32_t *security_cnt)
{
    (void)image_id;
    *security_cnt = 30;

    return 0;
}

int32_t
boot_nv_security_counter_update(uint32_t image_id, uint32_t img_security_cnt)
{
    (void)image_id;
    (void)img_security_cnt;

    /* Do nothing. */
    return 0;
}
Loading