blob: 47f494ac61770832c9fbb31867c229ea1efcd028 [file] [log] [blame]
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +02001/***************************************************************************//**
2* \file main.c
3* \version 1.0
4********************************************************************************
5* \copyright
6* SPDX-License-Identifier: Apache-2.0
7*
8* Licensed under the Apache License, Version 2.0 (the "License");
9* you may not use this file except in compliance with the License.
10* You may obtain a copy of the License at
11*
12* http://www.apache.org/licenses/LICENSE-2.0
13*
14* Unless required by applicable law or agreed to in writing, software
15* distributed under the License is distributed on an "AS IS" BASIS,
16* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17* See the License for the specific language governing permissions and
18* limitations under the License.
19*******************************************************************************/
20
21/* Cypress pdl headers */
22#include "cy_pdl.h"
23#include "cyhal.h"
24#include "cy_retarget_io.h"
25#include "cy_result.h"
26
27#include "sysflash/sysflash.h"
28#include "flash_map_backend/flash_map_backend.h"
29
30#include "bootutil/image.h"
31#include "bootutil/bootutil.h"
32#include "bootutil/sign_key.h"
33
34#include "bootutil/bootutil_log.h"
35
36/* Define pins for UART debug output */
37
38#define CY_DEBUG_UART_TX (P5_1)
39#define CY_DEBUG_UART_RX (P5_0)
40
41static void do_boot(struct boot_rsp *rsp)
42{
43 uint32_t app_addr = 0;
44
45 app_addr = (rsp->br_image_off + rsp->br_hdr->ih_hdr_size);
46
47 BOOT_LOG_INF("Starting User Application on CM4 (wait)...");
48 Cy_SysLib_Delay(100);
49
50 cy_retarget_io_deinit();
51
52 Cy_SysEnableCM4(app_addr);
53
54 while (1)
55 {
56 __WFI() ;
57 }
58}
59
60int main(void)
61{
62 cy_rslt_t rc = !CY_RSLT_SUCCESS;
63 struct boot_rsp rsp ;
64
65 /* enable interrupts */
66 __enable_irq();
67
68 /* Initialize retarget-io to use the debug UART port */
69 cy_retarget_io_init(CY_DEBUG_UART_TX, CY_DEBUG_UART_RX, CY_RETARGET_IO_BAUDRATE);
70
71 BOOT_LOG_INF("MCUBoot Bootloader Started");
72
73 if (boot_go(&rsp) == 0) {
74 BOOT_LOG_INF("User Application validated successfully");
75 do_boot(&rsp);
76 } else
77 BOOT_LOG_INF("MCUBoot Bootloader found none of bootable images") ;
78
79 return 0;
80}