blob: 7c19c8640947f53f5496b42efb4bd8c25dfda884 [file] [log] [blame]
Gustavo Henrique Nihei7bcf9862021-07-26 14:39:16 -03001/****************************************************************************
2 * boot/nuttx/main.c
3 *
4 * Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 ****************************************************************************/
19
20/****************************************************************************
21 * Included Files
22 ****************************************************************************/
23
24#include <nuttx/config.h>
25
Gerson Fernando Budked9307312021-12-20 19:51:38 -030026#include <syslog.h>
Gustavo Henrique Nihei7bcf9862021-07-26 14:39:16 -030027
28#include <sys/boardctl.h>
29
30#include <bootutil/bootutil.h>
31#include <bootutil/image.h>
32
33#include "flash_map_backend/flash_map_backend.h"
34
35/****************************************************************************
36 * Private Functions
37 ****************************************************************************/
38
39/****************************************************************************
40 * do_boot
41 ****************************************************************************/
42
43static void do_boot(struct boot_rsp *rsp)
44{
Gustavo Henrique Niheifca1aa42021-08-20 10:30:44 -030045 const struct flash_area *flash_area;
Gustavo Henrique Nihei7bcf9862021-07-26 14:39:16 -030046 struct boardioc_boot_info_s info;
47 int area_id;
48 int ret;
49
50 area_id = flash_area_id_from_image_offset(rsp->br_image_off);
51
52 ret = flash_area_open(area_id, &flash_area);
53 assert(ret == OK);
54
Gerson Fernando Budked9307312021-12-20 19:51:38 -030055 syslog(LOG_INFO, "Booting from %s...\n", flash_area->fa_mtd_path);
Gustavo Henrique Nihei7bcf9862021-07-26 14:39:16 -030056
57 info.path = flash_area->fa_mtd_path;
58 info.header_size = rsp->br_hdr->ih_hdr_size;
59
60 flash_area_close(flash_area);
61
Gustavo Henrique Niheifca1aa42021-08-20 10:30:44 -030062 if (boardctl(BOARDIOC_BOOT_IMAGE, (uintptr_t)&info) != OK)
Gustavo Henrique Nihei7bcf9862021-07-26 14:39:16 -030063 {
Gerson Fernando Budked9307312021-12-20 19:51:38 -030064 syslog(LOG_ERR, "Failed to load application image!\n");
Gustavo Henrique Nihei7bcf9862021-07-26 14:39:16 -030065 FIH_PANIC;
66 }
67}
68
69/****************************************************************************
70 * Public Functions
71 ****************************************************************************/
72
73/****************************************************************************
74 * main
75 ****************************************************************************/
76
77int main(int argc, FAR char *argv[])
78{
79 struct boot_rsp rsp;
80 fih_int fih_rc = FIH_FAILURE;
81
Gerson Fernando Budked9307312021-12-20 19:51:38 -030082 syslog(LOG_INFO, "*** Booting MCUboot build %s ***\n", CONFIG_MCUBOOT_VERSION);
Gustavo Henrique Nihei7bcf9862021-07-26 14:39:16 -030083
84 FIH_CALL(boot_go, fih_rc, &rsp);
85
86 if (fih_not_eq(fih_rc, FIH_SUCCESS))
87 {
Gerson Fernando Budked9307312021-12-20 19:51:38 -030088 syslog(LOG_ERR, "Unable to find bootable image\n");
Gustavo Henrique Nihei7bcf9862021-07-26 14:39:16 -030089 FIH_PANIC;
90 }
91
92 do_boot(&rsp);
93
94 while (1);
95}