blob: e908d07c87329a11136cf274030d4c1c377e4350 [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*******************************************************************************/
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020020/* Cypress pdl headers */
21#include "cy_pdl.h"
Bohdan Kovalchuk77256522020-04-15 18:03:43 +030022#include "cy_retarget_io_pdl.h"
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020023#include "cy_result.h"
24
25#include "sysflash/sysflash.h"
26#include "flash_map_backend/flash_map_backend.h"
27
28#include "bootutil/image.h"
29#include "bootutil/bootutil.h"
30#include "bootutil/sign_key.h"
31
32#include "bootutil/bootutil_log.h"
33
34/* Define pins for UART debug output */
Bohdan Kovalchuk77256522020-04-15 18:03:43 +030035#define CYBSP_UART_ENABLED 1U
36#define CYBSP_UART_HW SCB5
37#define CYBSP_UART_IRQ scb_5_interrupt_IRQn
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020038
39static void do_boot(struct boot_rsp *rsp)
40{
41 uint32_t app_addr = 0;
42
43 app_addr = (rsp->br_image_off + rsp->br_hdr->ih_hdr_size);
44
45 BOOT_LOG_INF("Starting User Application on CM4 (wait)...");
46 Cy_SysLib_Delay(100);
47
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020048 Cy_SysEnableCM4(app_addr);
49
50 while (1)
51 {
52 __WFI() ;
53 }
54}
55
56int main(void)
57{
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020058 struct boot_rsp rsp ;
59
Bohdan Kovalchuk77256522020-04-15 18:03:43 +030060 init_cycfg_clocks();
61 init_cycfg_peripherals();
62 init_cycfg_pins();
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020063 /* enable interrupts */
64 __enable_irq();
65
Bohdan Kovalchuk77256522020-04-15 18:03:43 +030066 /* Initialize retarget-io to use the debug UART port (CYBSP_UART_HW) */
67 cy_retarget_io_pdl_init(115200u);
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020068
69 BOOT_LOG_INF("MCUBoot Bootloader Started");
70
71 if (boot_go(&rsp) == 0) {
72 BOOT_LOG_INF("User Application validated successfully");
73 do_boot(&rsp);
74 } else
75 BOOT_LOG_INF("MCUBoot Bootloader found none of bootable images") ;
76
77 return 0;
78}