blob: 747d36ca0d76917774e4a7774515b5ffff321374 [file] [log] [blame]
David Brown5153bd62017-01-06 11:16:53 -07001/*
2 * Copyright (c) 2012-2014 Wind River Systems, Inc.
Tamas Banee6615d2020-09-30 07:58:48 +01003 * Copyright (c) 2020 Arm Limited
David Brown5153bd62017-01-06 11:16:53 -07004 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Marti Bolivareb940802017-05-01 23:15:29 -040018#include <assert.h>
David Brown5153bd62017-01-06 11:16:53 -070019#include <zephyr.h>
Peter Bigot54c1e3f2020-01-25 05:50:12 -060020#include <drivers/gpio.h>
Andrzej Puzdrowskif1d189c2019-12-12 09:34:11 +010021#include <sys/__assert.h>
Peter Bigot54c1e3f2020-01-25 05:50:12 -060022#include <drivers/flash.h>
Andrzej Puzdrowskif99a4c72019-06-28 15:16:35 +020023#include <drivers/timer/system_timer.h>
Emanuele Di Santoc4bf7802018-07-20 11:39:57 +020024#include <usb/usb_device.h>
Evan Gates4632d8d2018-06-28 13:27:40 -070025#include <soc.h>
Rafał Kuźnia505c6e62020-07-17 13:18:15 +020026#include <linker/linker-defs.h>
David Brown5153bd62017-01-06 11:16:53 -070027
Marti Bolivar51181cf2017-03-20 11:03:41 -040028#include "target.h"
29
Marti Bolivar4a97b4c2017-01-31 18:20:02 -050030#include "bootutil/bootutil_log.h"
Ricardo Salveti3a2c1242017-01-19 10:22:35 -020031#include "bootutil/image.h"
32#include "bootutil/bootutil.h"
Tamas Banee6615d2020-09-30 07:58:48 +010033#include "bootutil/fault_injection_hardening.h"
Andrzej Puzdrowskib788c712018-04-12 12:42:49 +020034#include "flash_map_backend/flash_map_backend.h"
Ricardo Salveti3a2c1242017-01-19 10:22:35 -020035
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +020036#ifdef CONFIG_MCUBOOT_SERIAL
Marko Kiiskila149b4572018-06-06 14:18:54 +030037#include "boot_serial/boot_serial.h"
38#include "serial_adapter/serial_adapter.h"
39
40const struct boot_uart_funcs boot_funcs = {
41 .read = console_read,
42 .write = console_write
43};
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +020044#endif
45
Rajavardhan Gundi51c9d702019-02-20 14:08:52 +053046#ifdef CONFIG_BOOT_WAIT_FOR_USB_DFU
47#include <usb/class/usb_dfu.h>
48#endif
49
Andrzej Puzdrowski9a605b62020-03-16 13:34:30 +010050#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
51#include <arm_cleanup.h>
52#endif
53
Gerard Marull-Paretasa513b8e2021-01-26 22:50:38 +010054/* CONFIG_LOG_MINIMAL is the legacy Kconfig property,
55 * replaced by CONFIG_LOG_MODE_MINIMAL.
56 */
57#define ZEPHYR_LOG_MODE_MINIMAL (defined(CONFIG_LOG_MODE_MINIMAL) ||\
58 defined(CONFIG_LOG_MINIMAL))
59
Henrik Brix Andersene5121812021-01-12 09:52:51 +010060#if defined(CONFIG_LOG) && !defined(CONFIG_LOG_IMMEDIATE) && \
Gerard Marull-Paretasa513b8e2021-01-26 22:50:38 +010061 !ZEPHYR_LOG_MODE_MINIMAL
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +010062#ifdef CONFIG_LOG_PROCESS_THREAD
63#warning "The log internal thread for log processing can't transfer the log"\
64 "well for MCUBoot."
65#else
66#include <logging/log_ctrl.h>
67
Krzysztof Chruscinski821214e2020-03-24 07:50:32 +010068#define BOOT_LOG_PROCESSING_INTERVAL K_MSEC(30) /* [ms] */
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +010069
70/* log are processing in custom routine */
Andrzej Puzdrowskiaf148532020-02-25 12:51:26 +010071K_THREAD_STACK_DEFINE(boot_log_stack, CONFIG_MCUBOOT_LOG_THREAD_STACK_SIZE);
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +010072struct k_thread boot_log_thread;
Andrzej Puzdrowski84591632020-02-24 11:50:19 +010073volatile bool boot_log_stop = false;
74K_SEM_DEFINE(boot_log_sem, 1, 1);
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +010075
76/* log processing need to be initalized by the application */
77#define ZEPHYR_BOOT_LOG_START() zephyr_boot_log_start()
Andrzej Puzdrowski84591632020-02-24 11:50:19 +010078#define ZEPHYR_BOOT_LOG_STOP() zephyr_boot_log_stop()
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +010079#endif /* CONFIG_LOG_PROCESS_THREAD */
80#else
81/* synchronous log mode doesn't need to be initalized by the application */
82#define ZEPHYR_BOOT_LOG_START() do { } while (false)
Andrzej Puzdrowski84591632020-02-24 11:50:19 +010083#define ZEPHYR_BOOT_LOG_STOP() do { } while (false)
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +010084#endif /* defined(CONFIG_LOG) && !defined(CONFIG_LOG_IMMEDIATE) */
85
Jon Helge Nistade58f9bd2019-11-25 15:59:52 +010086#ifdef CONFIG_SOC_FAMILY_NRF
87#include <hal/nrf_power.h>
88
89static inline bool boot_skip_serial_recovery()
90{
Fabio Utzig63b4eac2019-12-17 09:59:47 -030091#if NRF_POWER_HAS_RESETREAS
Kumar Gala0813efe2020-05-27 12:25:41 -050092 uint32_t rr = nrf_power_resetreas_get(NRF_POWER);
Jon Helge Nistade58f9bd2019-11-25 15:59:52 +010093
94 return !(rr == 0 || (rr & NRF_POWER_RESETREAS_RESETPIN_MASK));
95#else
96 return false;
97#endif
98}
99#else
100static inline bool boot_skip_serial_recovery()
101{
102 return false;
103}
104#endif
105
Emanuele Di Santo9f1933d2018-11-20 10:59:59 +0100106MCUBOOT_LOG_MODULE_REGISTER(mcuboot);
107
Andrew Boie7238f512017-03-02 13:39:06 -0800108void os_heap_init(void);
109
110#if defined(CONFIG_ARM)
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200111
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200112#ifdef CONFIG_SW_VECTOR_RELAY
113extern void *_vector_table_pointer;
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200114#endif
115
Andrew Boie7238f512017-03-02 13:39:06 -0800116struct arm_vector_table {
David Brown0d0652a2017-04-11 17:33:30 -0600117 uint32_t msp;
118 uint32_t reset;
David Brown5153bd62017-01-06 11:16:53 -0700119};
120
Emanuele Di Santofcfff582018-11-01 16:06:36 +0100121extern void sys_clock_disable(void);
122
Andrew Boie7238f512017-03-02 13:39:06 -0800123static void do_boot(struct boot_rsp *rsp)
124{
David Brown0d0652a2017-04-11 17:33:30 -0600125 struct arm_vector_table *vt;
Marti Bolivareb940802017-05-01 23:15:29 -0400126 uintptr_t flash_base;
127 int rc;
Andrew Boie7238f512017-03-02 13:39:06 -0800128
David Brown0d0652a2017-04-11 17:33:30 -0600129 /* The beginning of the image is the ARM vector table, containing
130 * the initial stack pointer address and the reset vector
131 * consecutively. Manually set the stack pointer and jump into the
132 * reset vector
133 */
Marti Bolivareb940802017-05-01 23:15:29 -0400134 rc = flash_device_base(rsp->br_flash_dev_id, &flash_base);
135 assert(rc == 0);
136
137 vt = (struct arm_vector_table *)(flash_base +
138 rsp->br_image_off +
David Brown0d0652a2017-04-11 17:33:30 -0600139 rsp->br_hdr->ih_hdr_size);
Arvid Rosén9ed399c2020-08-19 08:57:11 +0200140
David Brown0d0652a2017-04-11 17:33:30 -0600141 irq_lock();
Andrzej Puzdrowski960a2d62019-08-12 16:28:26 +0200142#ifdef CONFIG_SYS_CLOCK_EXISTS
David Brown0d0652a2017-04-11 17:33:30 -0600143 sys_clock_disable();
Andrzej Puzdrowski960a2d62019-08-12 16:28:26 +0200144#endif
Jun Li01bef712019-05-08 21:55:54 -0700145#ifdef CONFIG_USB
Emanuele Di Santoc4bf7802018-07-20 11:39:57 +0200146 /* Disable the USB to prevent it from firing interrupts */
147 usb_disable();
148#endif
Andrzej Puzdrowski9a605b62020-03-16 13:34:30 +0100149#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
150 cleanup_arm_nvic(); /* cleanup NVIC registers */
Ioannis Glaropoulos70af7082020-10-22 15:14:48 +0200151
152#ifdef CONFIG_CPU_CORTEX_M7
153 /* Disable instruction cache and data cache before chain-load the application */
154 SCB_DisableDCache();
155 SCB_DisableICache();
156#endif
157
Henrik Brix Andersen008f4a72020-12-08 14:40:19 +0100158#if CONFIG_CPU_HAS_ARM_MPU || CONFIG_CPU_HAS_NXP_MPU
Ioannis Glaropoulos70af7082020-10-22 15:14:48 +0200159 z_arm_clear_arm_mpu_config();
Andrzej Puzdrowski9a605b62020-03-16 13:34:30 +0100160#endif
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200161
Håkon Øye Amundsen6a8dbba2020-10-01 12:52:38 +0000162#if defined(CONFIG_BUILTIN_STACK_GUARD) && \
163 defined(CONFIG_CPU_CORTEX_M_HAS_SPLIM)
164 /* Reset limit registers to avoid inflicting stack overflow on image
165 * being booted.
166 */
167 __set_PSPLIM(0);
168 __set_MSPLIM(0);
169#endif
170
Ioannis Glaropoulos70af7082020-10-22 15:14:48 +0200171#endif /* CONFIG_MCUBOOT_CLEANUP_ARM_CORE */
172
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200173#ifdef CONFIG_BOOT_INTR_VEC_RELOC
Rafał Kuźnia505c6e62020-07-17 13:18:15 +0200174#if defined(CONFIG_SW_VECTOR_RELAY)
175 _vector_table_pointer = vt;
176#ifdef CONFIG_CPU_CORTEX_M_HAS_VTOR
177 SCB->VTOR = (uint32_t)__vector_relay_table;
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200178#endif
Rafał Kuźnia505c6e62020-07-17 13:18:15 +0200179#elif defined(CONFIG_CPU_CORTEX_M_HAS_VTOR)
180 SCB->VTOR = (uint32_t)vt;
181#endif /* CONFIG_SW_VECTOR_RELAY */
182#else /* CONFIG_BOOT_INTR_VEC_RELOC */
183#if defined(CONFIG_CPU_CORTEX_M_HAS_VTOR) && defined(CONFIG_SW_VECTOR_RELAY)
184 _vector_table_pointer = _vector_start;
185 SCB->VTOR = (uint32_t)__vector_relay_table;
186#endif
187#endif /* CONFIG_BOOT_INTR_VEC_RELOC */
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200188
David Brown57837b92018-03-13 15:56:38 -0600189 __set_MSP(vt->msp);
Andrzej Puzdrowski9a605b62020-03-16 13:34:30 +0100190#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
191 __set_CONTROL(0x00); /* application will configures core on its own */
Andrzej Puzdrowski56c15e72020-10-29 09:16:50 +0100192 __ISB();
Andrzej Puzdrowski9a605b62020-03-16 13:34:30 +0100193#endif
David Brown0d0652a2017-04-11 17:33:30 -0600194 ((void (*)(void))vt->reset)();
Andrew Boie7238f512017-03-02 13:39:06 -0800195}
Rajavardhan Gundi40c28e32018-12-09 13:32:01 +0530196
197#elif defined(CONFIG_XTENSA)
198#define SRAM_BASE_ADDRESS 0xBE030000
199
200static void copy_img_to_SRAM(int slot, unsigned int hdr_offset)
201{
202 const struct flash_area *fap;
203 int area_id;
204 int rc;
205 unsigned char *dst = (unsigned char *)(SRAM_BASE_ADDRESS + hdr_offset);
206
207 BOOT_LOG_INF("Copying image to SRAM");
208
209 area_id = flash_area_id_from_image_slot(slot);
210 rc = flash_area_open(area_id, &fap);
211 if (rc != 0) {
Fabio Utzigcac58f62019-09-06 08:52:35 -0300212 BOOT_LOG_ERR("flash_area_open failed with %d\n", rc);
Rajavardhan Gundi40c28e32018-12-09 13:32:01 +0530213 goto done;
214 }
215
216 rc = flash_area_read(fap, hdr_offset, dst, fap->fa_size - hdr_offset);
217 if (rc != 0) {
Fabio Utzigcac58f62019-09-06 08:52:35 -0300218 BOOT_LOG_ERR("flash_area_read failed with %d\n", rc);
Rajavardhan Gundi40c28e32018-12-09 13:32:01 +0530219 goto done;
220 }
221
222done:
223 flash_area_close(fap);
224}
225
226/* Entry point (.ResetVector) is at the very beginning of the image.
227 * Simply copy the image to a suitable location and jump there.
228 */
229static void do_boot(struct boot_rsp *rsp)
230{
231 void *start;
232
233 BOOT_LOG_INF("br_image_off = 0x%x\n", rsp->br_image_off);
234 BOOT_LOG_INF("ih_hdr_size = 0x%x\n", rsp->br_hdr->ih_hdr_size);
235
236 /* Copy from the flash to HP SRAM */
237 copy_img_to_SRAM(0, rsp->br_hdr->ih_hdr_size);
238
239 /* Jump to entry point */
240 start = (void *)(SRAM_BASE_ADDRESS + rsp->br_hdr->ih_hdr_size);
241 ((void (*)(void))start)();
242}
243
Andrew Boie7238f512017-03-02 13:39:06 -0800244#else
245/* Default: Assume entry point is at the very beginning of the image. Simply
246 * lock interrupts and jump there. This is the right thing to do for X86 and
247 * possibly other platforms.
248 */
249static void do_boot(struct boot_rsp *rsp)
250{
Marti Bolivareb940802017-05-01 23:15:29 -0400251 uintptr_t flash_base;
David Brown0d0652a2017-04-11 17:33:30 -0600252 void *start;
Marti Bolivareb940802017-05-01 23:15:29 -0400253 int rc;
Andrew Boie7238f512017-03-02 13:39:06 -0800254
Marti Bolivareb940802017-05-01 23:15:29 -0400255 rc = flash_device_base(rsp->br_flash_dev_id, &flash_base);
256 assert(rc == 0);
257
258 start = (void *)(flash_base + rsp->br_image_off +
259 rsp->br_hdr->ih_hdr_size);
Andrew Boie7238f512017-03-02 13:39:06 -0800260
David Brown0d0652a2017-04-11 17:33:30 -0600261 /* Lock interrupts and dive into the entry point */
262 irq_lock();
263 ((void (*)(void))start)();
Andrew Boie7238f512017-03-02 13:39:06 -0800264}
265#endif
David Brown5153bd62017-01-06 11:16:53 -0700266
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +0100267#if defined(CONFIG_LOG) && !defined(CONFIG_LOG_IMMEDIATE) &&\
Gerard Marull-Paretasa513b8e2021-01-26 22:50:38 +0100268 !defined(CONFIG_LOG_PROCESS_THREAD) && !ZEPHYR_LOG_MODE_MINIMAL
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +0100269/* The log internal thread for log processing can't transfer log well as has too
270 * low priority.
271 * Dedicated thread for log processing below uses highest application
272 * priority. This allows to transmit all logs without adding k_sleep/k_yield
273 * anywhere else int the code.
274 */
275
276/* most simple log processing theread */
277void boot_log_thread_func(void *dummy1, void *dummy2, void *dummy3)
278{
279 (void)dummy1;
280 (void)dummy2;
281 (void)dummy3;
282
283 log_init();
284
285 while (1) {
286 if (log_process(false) == false) {
Andrzej Puzdrowski84591632020-02-24 11:50:19 +0100287 if (boot_log_stop) {
288 break;
289 }
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +0100290 k_sleep(BOOT_LOG_PROCESSING_INTERVAL);
291 }
292 }
Andrzej Puzdrowski84591632020-02-24 11:50:19 +0100293
294 k_sem_give(&boot_log_sem);
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +0100295}
296
297void zephyr_boot_log_start(void)
298{
299 /* start logging thread */
300 k_thread_create(&boot_log_thread, boot_log_stack,
301 K_THREAD_STACK_SIZEOF(boot_log_stack),
302 boot_log_thread_func, NULL, NULL, NULL,
303 K_HIGHEST_APPLICATION_THREAD_PRIO, 0,
304 BOOT_LOG_PROCESSING_INTERVAL);
305
306 k_thread_name_set(&boot_log_thread, "logging");
307}
Andrzej Puzdrowski84591632020-02-24 11:50:19 +0100308
309void zephyr_boot_log_stop(void)
310{
311 boot_log_stop = true;
312
313 /* wait until log procesing thread expired
314 * This can be reworked using a thread_join() API once a such will be
315 * available in zephyr.
316 * see https://github.com/zephyrproject-rtos/zephyr/issues/21500
317 */
318 (void)k_sem_take(&boot_log_sem, K_FOREVER);
319}
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +0100320#endif/* defined(CONFIG_LOG) && !defined(CONFIG_LOG_IMMEDIATE) &&\
321 !defined(CONFIG_LOG_PROCESS_THREAD) */
322
David Brown5153bd62017-01-06 11:16:53 -0700323void main(void)
324{
David Brown0d0652a2017-04-11 17:33:30 -0600325 struct boot_rsp rsp;
326 int rc;
Tamas Banee6615d2020-09-30 07:58:48 +0100327 fih_int fih_rc = FIH_FAILURE;
David Brown5153bd62017-01-06 11:16:53 -0700328
Andrzej Puzdrowski210b3182020-10-13 13:52:15 +0200329 MCUBOOT_WATCHDOG_FEED();
330
David Brown0d0652a2017-04-11 17:33:30 -0600331 BOOT_LOG_INF("Starting bootloader");
Ricardo Salveti7cf3d9e2017-01-18 16:38:22 -0200332
David Brown0d0652a2017-04-11 17:33:30 -0600333 os_heap_init();
David Brown5153bd62017-01-06 11:16:53 -0700334
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +0100335 ZEPHYR_BOOT_LOG_START();
336
Tamas Banee6615d2020-09-30 07:58:48 +0100337 (void)rc;
338
Kumar Gala32b61f32020-04-08 12:02:03 -0500339#if (!defined(CONFIG_XTENSA) && defined(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL))
340 if (!flash_device_get_binding(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL)) {
341 BOOT_LOG_ERR("Flash device %s not found",
342 DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL);
David Brown0d0652a2017-04-11 17:33:30 -0600343 while (1)
344 ;
345 }
Kumar Gala9a5b9512020-04-08 12:06:21 -0500346#elif (defined(CONFIG_XTENSA) && defined(JEDEC_SPI_NOR_0_LABEL))
347 if (!flash_device_get_binding(JEDEC_SPI_NOR_0_LABEL)) {
348 BOOT_LOG_ERR("Flash device %s not found", JEDEC_SPI_NOR_0_LABEL);
Rajavardhan Gundi40c28e32018-12-09 13:32:01 +0530349 while (1)
350 ;
351 }
Rajavardhan Gundic3353b22018-12-06 17:24:10 +0530352#endif
David Brown5153bd62017-01-06 11:16:53 -0700353
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200354#ifdef CONFIG_MCUBOOT_SERIAL
355
Dominik Ermel1422b4b2020-09-11 11:31:38 +0000356 struct device const *detect_port;
Kumar Gala0813efe2020-05-27 12:25:41 -0500357 uint32_t detect_value = !CONFIG_BOOT_SERIAL_DETECT_PIN_VAL;
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200358
359 detect_port = device_get_binding(CONFIG_BOOT_SERIAL_DETECT_PORT);
360 __ASSERT(detect_port, "Error: Bad port for boot serial detection.\n");
361
Peter Bigot36e90292020-01-30 05:36:47 -0600362 /* The default presence value is 0 which would normally be
363 * active-low, but historically the raw value was checked so we'll
364 * use the raw interface.
365 */
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200366 rc = gpio_pin_configure(detect_port, CONFIG_BOOT_SERIAL_DETECT_PIN,
Peter Bigot36e90292020-01-30 05:36:47 -0600367#ifdef GPIO_INPUT
368 GPIO_INPUT | GPIO_PULL_UP
369#else
370 GPIO_DIR_IN | GPIO_PUD_PULL_UP
371#endif
Andrzej Puzdrowski5d96bd22020-02-20 10:35:33 +0100372 );
Andrzej Puzdrowski82d73952018-06-13 14:55:51 +0200373 __ASSERT(rc == 0, "Error of boot detect pin initialization.\n");
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200374
Peter Bigot36e90292020-01-30 05:36:47 -0600375#ifdef GPIO_INPUT
376 rc = gpio_pin_get_raw(detect_port, CONFIG_BOOT_SERIAL_DETECT_PIN);
377 detect_value = rc;
378#else
Emanuele Di Santofcfff582018-11-01 16:06:36 +0100379 rc = gpio_pin_read(detect_port, CONFIG_BOOT_SERIAL_DETECT_PIN,
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200380 &detect_value);
Peter Bigot36e90292020-01-30 05:36:47 -0600381#endif
382 __ASSERT(rc >= 0, "Error of the reading the detect pin.\n");
Jon Helge Nistade58f9bd2019-11-25 15:59:52 +0100383 if (detect_value == CONFIG_BOOT_SERIAL_DETECT_PIN_VAL &&
384 !boot_skip_serial_recovery()) {
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200385 BOOT_LOG_INF("Enter the serial recovery mode");
Marko Kiiskila149b4572018-06-06 14:18:54 +0300386 rc = boot_console_init();
Carles Cufie2a36122018-06-15 10:51:02 +0200387 __ASSERT(rc == 0, "Error initializing boot console.\n");
Marko Kiiskila149b4572018-06-06 14:18:54 +0300388 boot_serial_start(&boot_funcs);
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200389 __ASSERT(0, "Bootloader serial process was terminated unexpectedly.\n");
390 }
391#endif
392
Rajavardhan Gundi51c9d702019-02-20 14:08:52 +0530393#ifdef CONFIG_BOOT_WAIT_FOR_USB_DFU
Andrzej Puzdrowskiac1f1ff2020-02-05 08:40:12 +0100394 rc = usb_enable(NULL);
395 if (rc) {
396 BOOT_LOG_ERR("Cannot enable USB");
397 } else {
398 BOOT_LOG_INF("Waiting for USB DFU");
399 wait_for_usb_dfu();
400 BOOT_LOG_INF("USB DFU wait time elapsed");
401 }
Rajavardhan Gundi51c9d702019-02-20 14:08:52 +0530402#endif
403
Tamas Banee6615d2020-09-30 07:58:48 +0100404 FIH_CALL(boot_go, fih_rc, &rsp);
405 if (fih_not_eq(fih_rc, FIH_SUCCESS)) {
David Brown0d0652a2017-04-11 17:33:30 -0600406 BOOT_LOG_ERR("Unable to find bootable image");
Tamas Banee6615d2020-09-30 07:58:48 +0100407 FIH_PANIC;
David Brown0d0652a2017-04-11 17:33:30 -0600408 }
David Brown5153bd62017-01-06 11:16:53 -0700409
Marti Bolivar88f48d92017-05-01 22:30:02 -0400410 BOOT_LOG_INF("Bootloader chainload address offset: 0x%x",
411 rsp.br_image_off);
Andrzej Puzdrowskib788c712018-04-12 12:42:49 +0200412
David Brown0d0652a2017-04-11 17:33:30 -0600413 BOOT_LOG_INF("Jumping to the first image slot");
Andrzej Puzdrowski84591632020-02-24 11:50:19 +0100414 ZEPHYR_BOOT_LOG_STOP();
David Brown0d0652a2017-04-11 17:33:30 -0600415 do_boot(&rsp);
David Brown5153bd62017-01-06 11:16:53 -0700416
David Brown0d0652a2017-04-11 17:33:30 -0600417 BOOT_LOG_ERR("Never should get here");
418 while (1)
419 ;
David Brown5153bd62017-01-06 11:16:53 -0700420}