Roman Okhrimenko | 89ecdac | 2020-02-28 17:05:55 +0200 | [diff] [blame] | 1 | /***************************************************************************//** |
| 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 Okhrimenko | 89ecdac | 2020-02-28 17:05:55 +0200 | [diff] [blame] | 20 | /* Cypress pdl headers */ |
| 21 | #include "cy_pdl.h" |
Bohdan Kovalchuk | 7725652 | 2020-04-15 18:03:43 +0300 | [diff] [blame^] | 22 | #include "cy_retarget_io_pdl.h" |
Roman Okhrimenko | 89ecdac | 2020-02-28 17:05:55 +0200 | [diff] [blame] | 23 | #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 Kovalchuk | 7725652 | 2020-04-15 18:03:43 +0300 | [diff] [blame^] | 35 | #define CYBSP_UART_ENABLED 1U |
| 36 | #define CYBSP_UART_HW SCB5 |
| 37 | #define CYBSP_UART_IRQ scb_5_interrupt_IRQn |
Roman Okhrimenko | 89ecdac | 2020-02-28 17:05:55 +0200 | [diff] [blame] | 38 | |
| 39 | static 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 Okhrimenko | 89ecdac | 2020-02-28 17:05:55 +0200 | [diff] [blame] | 48 | Cy_SysEnableCM4(app_addr); |
| 49 | |
| 50 | while (1) |
| 51 | { |
| 52 | __WFI() ; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | int main(void) |
| 57 | { |
Roman Okhrimenko | 89ecdac | 2020-02-28 17:05:55 +0200 | [diff] [blame] | 58 | struct boot_rsp rsp ; |
| 59 | |
Bohdan Kovalchuk | 7725652 | 2020-04-15 18:03:43 +0300 | [diff] [blame^] | 60 | init_cycfg_clocks(); |
| 61 | init_cycfg_peripherals(); |
| 62 | init_cycfg_pins(); |
Roman Okhrimenko | 89ecdac | 2020-02-28 17:05:55 +0200 | [diff] [blame] | 63 | /* enable interrupts */ |
| 64 | __enable_irq(); |
| 65 | |
Bohdan Kovalchuk | 7725652 | 2020-04-15 18:03:43 +0300 | [diff] [blame^] | 66 | /* Initialize retarget-io to use the debug UART port (CYBSP_UART_HW) */ |
| 67 | cy_retarget_io_pdl_init(115200u); |
Roman Okhrimenko | 89ecdac | 2020-02-28 17:05:55 +0200 | [diff] [blame] | 68 | |
| 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 | } |