blob: e1697db9f97892977358e8075d0151ce73c28de7 [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
Henrik Brix Andersene5121812021-01-12 09:52:51 +010054#if defined(CONFIG_LOG) && !defined(CONFIG_LOG_IMMEDIATE) && \
55 !defined(CONFIG_LOG_MINIMAL)
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +010056#ifdef CONFIG_LOG_PROCESS_THREAD
57#warning "The log internal thread for log processing can't transfer the log"\
58 "well for MCUBoot."
59#else
60#include <logging/log_ctrl.h>
61
Krzysztof Chruscinski821214e2020-03-24 07:50:32 +010062#define BOOT_LOG_PROCESSING_INTERVAL K_MSEC(30) /* [ms] */
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +010063
64/* log are processing in custom routine */
Andrzej Puzdrowskiaf148532020-02-25 12:51:26 +010065K_THREAD_STACK_DEFINE(boot_log_stack, CONFIG_MCUBOOT_LOG_THREAD_STACK_SIZE);
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +010066struct k_thread boot_log_thread;
Andrzej Puzdrowski84591632020-02-24 11:50:19 +010067volatile bool boot_log_stop = false;
68K_SEM_DEFINE(boot_log_sem, 1, 1);
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +010069
70/* log processing need to be initalized by the application */
71#define ZEPHYR_BOOT_LOG_START() zephyr_boot_log_start()
Andrzej Puzdrowski84591632020-02-24 11:50:19 +010072#define ZEPHYR_BOOT_LOG_STOP() zephyr_boot_log_stop()
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +010073#endif /* CONFIG_LOG_PROCESS_THREAD */
74#else
75/* synchronous log mode doesn't need to be initalized by the application */
76#define ZEPHYR_BOOT_LOG_START() do { } while (false)
Andrzej Puzdrowski84591632020-02-24 11:50:19 +010077#define ZEPHYR_BOOT_LOG_STOP() do { } while (false)
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +010078#endif /* defined(CONFIG_LOG) && !defined(CONFIG_LOG_IMMEDIATE) */
79
Jon Helge Nistade58f9bd2019-11-25 15:59:52 +010080#ifdef CONFIG_SOC_FAMILY_NRF
81#include <hal/nrf_power.h>
82
83static inline bool boot_skip_serial_recovery()
84{
Fabio Utzig63b4eac2019-12-17 09:59:47 -030085#if NRF_POWER_HAS_RESETREAS
Kumar Gala0813efe2020-05-27 12:25:41 -050086 uint32_t rr = nrf_power_resetreas_get(NRF_POWER);
Jon Helge Nistade58f9bd2019-11-25 15:59:52 +010087
88 return !(rr == 0 || (rr & NRF_POWER_RESETREAS_RESETPIN_MASK));
89#else
90 return false;
91#endif
92}
93#else
94static inline bool boot_skip_serial_recovery()
95{
96 return false;
97}
98#endif
99
Emanuele Di Santo9f1933d2018-11-20 10:59:59 +0100100MCUBOOT_LOG_MODULE_REGISTER(mcuboot);
101
Andrew Boie7238f512017-03-02 13:39:06 -0800102void os_heap_init(void);
103
104#if defined(CONFIG_ARM)
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200105
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200106#ifdef CONFIG_SW_VECTOR_RELAY
107extern void *_vector_table_pointer;
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200108#endif
109
Andrew Boie7238f512017-03-02 13:39:06 -0800110struct arm_vector_table {
David Brown0d0652a2017-04-11 17:33:30 -0600111 uint32_t msp;
112 uint32_t reset;
David Brown5153bd62017-01-06 11:16:53 -0700113};
114
Emanuele Di Santofcfff582018-11-01 16:06:36 +0100115extern void sys_clock_disable(void);
116
Andrew Boie7238f512017-03-02 13:39:06 -0800117static void do_boot(struct boot_rsp *rsp)
118{
David Brown0d0652a2017-04-11 17:33:30 -0600119 struct arm_vector_table *vt;
Marti Bolivareb940802017-05-01 23:15:29 -0400120 uintptr_t flash_base;
121 int rc;
Andrew Boie7238f512017-03-02 13:39:06 -0800122
David Brown0d0652a2017-04-11 17:33:30 -0600123 /* The beginning of the image is the ARM vector table, containing
124 * the initial stack pointer address and the reset vector
125 * consecutively. Manually set the stack pointer and jump into the
126 * reset vector
127 */
Marti Bolivareb940802017-05-01 23:15:29 -0400128 rc = flash_device_base(rsp->br_flash_dev_id, &flash_base);
129 assert(rc == 0);
130
131 vt = (struct arm_vector_table *)(flash_base +
132 rsp->br_image_off +
David Brown0d0652a2017-04-11 17:33:30 -0600133 rsp->br_hdr->ih_hdr_size);
Arvid Rosén9ed399c2020-08-19 08:57:11 +0200134
David Brown0d0652a2017-04-11 17:33:30 -0600135 irq_lock();
Andrzej Puzdrowski960a2d62019-08-12 16:28:26 +0200136#ifdef CONFIG_SYS_CLOCK_EXISTS
David Brown0d0652a2017-04-11 17:33:30 -0600137 sys_clock_disable();
Andrzej Puzdrowski960a2d62019-08-12 16:28:26 +0200138#endif
Jun Li01bef712019-05-08 21:55:54 -0700139#ifdef CONFIG_USB
Emanuele Di Santoc4bf7802018-07-20 11:39:57 +0200140 /* Disable the USB to prevent it from firing interrupts */
141 usb_disable();
142#endif
Andrzej Puzdrowski9a605b62020-03-16 13:34:30 +0100143#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
144 cleanup_arm_nvic(); /* cleanup NVIC registers */
Ioannis Glaropoulos70af7082020-10-22 15:14:48 +0200145
146#ifdef CONFIG_CPU_CORTEX_M7
147 /* Disable instruction cache and data cache before chain-load the application */
148 SCB_DisableDCache();
149 SCB_DisableICache();
150#endif
151
Henrik Brix Andersen008f4a72020-12-08 14:40:19 +0100152#if CONFIG_CPU_HAS_ARM_MPU || CONFIG_CPU_HAS_NXP_MPU
Ioannis Glaropoulos70af7082020-10-22 15:14:48 +0200153 z_arm_clear_arm_mpu_config();
Andrzej Puzdrowski9a605b62020-03-16 13:34:30 +0100154#endif
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200155
Håkon Øye Amundsen6a8dbba2020-10-01 12:52:38 +0000156#if defined(CONFIG_BUILTIN_STACK_GUARD) && \
157 defined(CONFIG_CPU_CORTEX_M_HAS_SPLIM)
158 /* Reset limit registers to avoid inflicting stack overflow on image
159 * being booted.
160 */
161 __set_PSPLIM(0);
162 __set_MSPLIM(0);
163#endif
164
Ioannis Glaropoulos70af7082020-10-22 15:14:48 +0200165#endif /* CONFIG_MCUBOOT_CLEANUP_ARM_CORE */
166
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200167#ifdef CONFIG_BOOT_INTR_VEC_RELOC
Rafał Kuźnia505c6e62020-07-17 13:18:15 +0200168#if defined(CONFIG_SW_VECTOR_RELAY)
169 _vector_table_pointer = vt;
170#ifdef CONFIG_CPU_CORTEX_M_HAS_VTOR
171 SCB->VTOR = (uint32_t)__vector_relay_table;
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200172#endif
Rafał Kuźnia505c6e62020-07-17 13:18:15 +0200173#elif defined(CONFIG_CPU_CORTEX_M_HAS_VTOR)
174 SCB->VTOR = (uint32_t)vt;
175#endif /* CONFIG_SW_VECTOR_RELAY */
176#else /* CONFIG_BOOT_INTR_VEC_RELOC */
177#if defined(CONFIG_CPU_CORTEX_M_HAS_VTOR) && defined(CONFIG_SW_VECTOR_RELAY)
178 _vector_table_pointer = _vector_start;
179 SCB->VTOR = (uint32_t)__vector_relay_table;
180#endif
181#endif /* CONFIG_BOOT_INTR_VEC_RELOC */
Rafał Kuźniad854bb62020-06-17 15:06:47 +0200182
David Brown57837b92018-03-13 15:56:38 -0600183 __set_MSP(vt->msp);
Andrzej Puzdrowski9a605b62020-03-16 13:34:30 +0100184#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
185 __set_CONTROL(0x00); /* application will configures core on its own */
Andrzej Puzdrowski56c15e72020-10-29 09:16:50 +0100186 __ISB();
Andrzej Puzdrowski9a605b62020-03-16 13:34:30 +0100187#endif
David Brown0d0652a2017-04-11 17:33:30 -0600188 ((void (*)(void))vt->reset)();
Andrew Boie7238f512017-03-02 13:39:06 -0800189}
Rajavardhan Gundi40c28e32018-12-09 13:32:01 +0530190
191#elif defined(CONFIG_XTENSA)
192#define SRAM_BASE_ADDRESS 0xBE030000
193
194static void copy_img_to_SRAM(int slot, unsigned int hdr_offset)
195{
196 const struct flash_area *fap;
197 int area_id;
198 int rc;
199 unsigned char *dst = (unsigned char *)(SRAM_BASE_ADDRESS + hdr_offset);
200
201 BOOT_LOG_INF("Copying image to SRAM");
202
203 area_id = flash_area_id_from_image_slot(slot);
204 rc = flash_area_open(area_id, &fap);
205 if (rc != 0) {
Fabio Utzigcac58f62019-09-06 08:52:35 -0300206 BOOT_LOG_ERR("flash_area_open failed with %d\n", rc);
Rajavardhan Gundi40c28e32018-12-09 13:32:01 +0530207 goto done;
208 }
209
210 rc = flash_area_read(fap, hdr_offset, dst, fap->fa_size - hdr_offset);
211 if (rc != 0) {
Fabio Utzigcac58f62019-09-06 08:52:35 -0300212 BOOT_LOG_ERR("flash_area_read failed with %d\n", rc);
Rajavardhan Gundi40c28e32018-12-09 13:32:01 +0530213 goto done;
214 }
215
216done:
217 flash_area_close(fap);
218}
219
220/* Entry point (.ResetVector) is at the very beginning of the image.
221 * Simply copy the image to a suitable location and jump there.
222 */
223static void do_boot(struct boot_rsp *rsp)
224{
225 void *start;
226
227 BOOT_LOG_INF("br_image_off = 0x%x\n", rsp->br_image_off);
228 BOOT_LOG_INF("ih_hdr_size = 0x%x\n", rsp->br_hdr->ih_hdr_size);
229
230 /* Copy from the flash to HP SRAM */
231 copy_img_to_SRAM(0, rsp->br_hdr->ih_hdr_size);
232
233 /* Jump to entry point */
234 start = (void *)(SRAM_BASE_ADDRESS + rsp->br_hdr->ih_hdr_size);
235 ((void (*)(void))start)();
236}
237
Andrew Boie7238f512017-03-02 13:39:06 -0800238#else
239/* Default: Assume entry point is at the very beginning of the image. Simply
240 * lock interrupts and jump there. This is the right thing to do for X86 and
241 * possibly other platforms.
242 */
243static void do_boot(struct boot_rsp *rsp)
244{
Marti Bolivareb940802017-05-01 23:15:29 -0400245 uintptr_t flash_base;
David Brown0d0652a2017-04-11 17:33:30 -0600246 void *start;
Marti Bolivareb940802017-05-01 23:15:29 -0400247 int rc;
Andrew Boie7238f512017-03-02 13:39:06 -0800248
Marti Bolivareb940802017-05-01 23:15:29 -0400249 rc = flash_device_base(rsp->br_flash_dev_id, &flash_base);
250 assert(rc == 0);
251
252 start = (void *)(flash_base + rsp->br_image_off +
253 rsp->br_hdr->ih_hdr_size);
Andrew Boie7238f512017-03-02 13:39:06 -0800254
David Brown0d0652a2017-04-11 17:33:30 -0600255 /* Lock interrupts and dive into the entry point */
256 irq_lock();
257 ((void (*)(void))start)();
Andrew Boie7238f512017-03-02 13:39:06 -0800258}
259#endif
David Brown5153bd62017-01-06 11:16:53 -0700260
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +0100261#if defined(CONFIG_LOG) && !defined(CONFIG_LOG_IMMEDIATE) &&\
Henrik Brix Andersene5121812021-01-12 09:52:51 +0100262 !defined(CONFIG_LOG_PROCESS_THREAD) && !defined(CONFIG_LOG_MINIMAL)
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +0100263/* The log internal thread for log processing can't transfer log well as has too
264 * low priority.
265 * Dedicated thread for log processing below uses highest application
266 * priority. This allows to transmit all logs without adding k_sleep/k_yield
267 * anywhere else int the code.
268 */
269
270/* most simple log processing theread */
271void boot_log_thread_func(void *dummy1, void *dummy2, void *dummy3)
272{
273 (void)dummy1;
274 (void)dummy2;
275 (void)dummy3;
276
277 log_init();
278
279 while (1) {
280 if (log_process(false) == false) {
Andrzej Puzdrowski84591632020-02-24 11:50:19 +0100281 if (boot_log_stop) {
282 break;
283 }
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +0100284 k_sleep(BOOT_LOG_PROCESSING_INTERVAL);
285 }
286 }
Andrzej Puzdrowski84591632020-02-24 11:50:19 +0100287
288 k_sem_give(&boot_log_sem);
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +0100289}
290
291void zephyr_boot_log_start(void)
292{
293 /* start logging thread */
294 k_thread_create(&boot_log_thread, boot_log_stack,
295 K_THREAD_STACK_SIZEOF(boot_log_stack),
296 boot_log_thread_func, NULL, NULL, NULL,
297 K_HIGHEST_APPLICATION_THREAD_PRIO, 0,
298 BOOT_LOG_PROCESSING_INTERVAL);
299
300 k_thread_name_set(&boot_log_thread, "logging");
301}
Andrzej Puzdrowski84591632020-02-24 11:50:19 +0100302
303void zephyr_boot_log_stop(void)
304{
305 boot_log_stop = true;
306
307 /* wait until log procesing thread expired
308 * This can be reworked using a thread_join() API once a such will be
309 * available in zephyr.
310 * see https://github.com/zephyrproject-rtos/zephyr/issues/21500
311 */
312 (void)k_sem_take(&boot_log_sem, K_FOREVER);
313}
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +0100314#endif/* defined(CONFIG_LOG) && !defined(CONFIG_LOG_IMMEDIATE) &&\
315 !defined(CONFIG_LOG_PROCESS_THREAD) */
316
David Brown5153bd62017-01-06 11:16:53 -0700317void main(void)
318{
David Brown0d0652a2017-04-11 17:33:30 -0600319 struct boot_rsp rsp;
320 int rc;
Tamas Banee6615d2020-09-30 07:58:48 +0100321 fih_int fih_rc = FIH_FAILURE;
David Brown5153bd62017-01-06 11:16:53 -0700322
Andrzej Puzdrowski210b3182020-10-13 13:52:15 +0200323 MCUBOOT_WATCHDOG_FEED();
324
David Brown0d0652a2017-04-11 17:33:30 -0600325 BOOT_LOG_INF("Starting bootloader");
Ricardo Salveti7cf3d9e2017-01-18 16:38:22 -0200326
David Brown0d0652a2017-04-11 17:33:30 -0600327 os_heap_init();
David Brown5153bd62017-01-06 11:16:53 -0700328
Andrzej Puzdrowski3f092bd2020-02-17 13:25:32 +0100329 ZEPHYR_BOOT_LOG_START();
330
Tamas Banee6615d2020-09-30 07:58:48 +0100331 (void)rc;
332
Kumar Gala32b61f32020-04-08 12:02:03 -0500333#if (!defined(CONFIG_XTENSA) && defined(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL))
334 if (!flash_device_get_binding(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL)) {
335 BOOT_LOG_ERR("Flash device %s not found",
336 DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL);
David Brown0d0652a2017-04-11 17:33:30 -0600337 while (1)
338 ;
339 }
Kumar Gala9a5b9512020-04-08 12:06:21 -0500340#elif (defined(CONFIG_XTENSA) && defined(JEDEC_SPI_NOR_0_LABEL))
341 if (!flash_device_get_binding(JEDEC_SPI_NOR_0_LABEL)) {
342 BOOT_LOG_ERR("Flash device %s not found", JEDEC_SPI_NOR_0_LABEL);
Rajavardhan Gundi40c28e32018-12-09 13:32:01 +0530343 while (1)
344 ;
345 }
Rajavardhan Gundic3353b22018-12-06 17:24:10 +0530346#endif
David Brown5153bd62017-01-06 11:16:53 -0700347
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200348#ifdef CONFIG_MCUBOOT_SERIAL
349
Dominik Ermel1422b4b2020-09-11 11:31:38 +0000350 struct device const *detect_port;
Kumar Gala0813efe2020-05-27 12:25:41 -0500351 uint32_t detect_value = !CONFIG_BOOT_SERIAL_DETECT_PIN_VAL;
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200352
353 detect_port = device_get_binding(CONFIG_BOOT_SERIAL_DETECT_PORT);
354 __ASSERT(detect_port, "Error: Bad port for boot serial detection.\n");
355
Peter Bigot36e90292020-01-30 05:36:47 -0600356 /* The default presence value is 0 which would normally be
357 * active-low, but historically the raw value was checked so we'll
358 * use the raw interface.
359 */
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200360 rc = gpio_pin_configure(detect_port, CONFIG_BOOT_SERIAL_DETECT_PIN,
Peter Bigot36e90292020-01-30 05:36:47 -0600361#ifdef GPIO_INPUT
362 GPIO_INPUT | GPIO_PULL_UP
363#else
364 GPIO_DIR_IN | GPIO_PUD_PULL_UP
365#endif
Andrzej Puzdrowski5d96bd22020-02-20 10:35:33 +0100366 );
Andrzej Puzdrowski82d73952018-06-13 14:55:51 +0200367 __ASSERT(rc == 0, "Error of boot detect pin initialization.\n");
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200368
Peter Bigot36e90292020-01-30 05:36:47 -0600369#ifdef GPIO_INPUT
370 rc = gpio_pin_get_raw(detect_port, CONFIG_BOOT_SERIAL_DETECT_PIN);
371 detect_value = rc;
372#else
Emanuele Di Santofcfff582018-11-01 16:06:36 +0100373 rc = gpio_pin_read(detect_port, CONFIG_BOOT_SERIAL_DETECT_PIN,
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200374 &detect_value);
Peter Bigot36e90292020-01-30 05:36:47 -0600375#endif
376 __ASSERT(rc >= 0, "Error of the reading the detect pin.\n");
Jon Helge Nistade58f9bd2019-11-25 15:59:52 +0100377 if (detect_value == CONFIG_BOOT_SERIAL_DETECT_PIN_VAL &&
378 !boot_skip_serial_recovery()) {
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200379 BOOT_LOG_INF("Enter the serial recovery mode");
Marko Kiiskila149b4572018-06-06 14:18:54 +0300380 rc = boot_console_init();
Carles Cufie2a36122018-06-15 10:51:02 +0200381 __ASSERT(rc == 0, "Error initializing boot console.\n");
Marko Kiiskila149b4572018-06-06 14:18:54 +0300382 boot_serial_start(&boot_funcs);
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200383 __ASSERT(0, "Bootloader serial process was terminated unexpectedly.\n");
384 }
385#endif
386
Rajavardhan Gundi51c9d702019-02-20 14:08:52 +0530387#ifdef CONFIG_BOOT_WAIT_FOR_USB_DFU
Andrzej Puzdrowskiac1f1ff2020-02-05 08:40:12 +0100388 rc = usb_enable(NULL);
389 if (rc) {
390 BOOT_LOG_ERR("Cannot enable USB");
391 } else {
392 BOOT_LOG_INF("Waiting for USB DFU");
393 wait_for_usb_dfu();
394 BOOT_LOG_INF("USB DFU wait time elapsed");
395 }
Rajavardhan Gundi51c9d702019-02-20 14:08:52 +0530396#endif
397
Tamas Banee6615d2020-09-30 07:58:48 +0100398 FIH_CALL(boot_go, fih_rc, &rsp);
399 if (fih_not_eq(fih_rc, FIH_SUCCESS)) {
David Brown0d0652a2017-04-11 17:33:30 -0600400 BOOT_LOG_ERR("Unable to find bootable image");
Tamas Banee6615d2020-09-30 07:58:48 +0100401 FIH_PANIC;
David Brown0d0652a2017-04-11 17:33:30 -0600402 }
David Brown5153bd62017-01-06 11:16:53 -0700403
Marti Bolivar88f48d92017-05-01 22:30:02 -0400404 BOOT_LOG_INF("Bootloader chainload address offset: 0x%x",
405 rsp.br_image_off);
Andrzej Puzdrowskib788c712018-04-12 12:42:49 +0200406
David Brown0d0652a2017-04-11 17:33:30 -0600407 BOOT_LOG_INF("Jumping to the first image slot");
Andrzej Puzdrowski84591632020-02-24 11:50:19 +0100408 ZEPHYR_BOOT_LOG_STOP();
David Brown0d0652a2017-04-11 17:33:30 -0600409 do_boot(&rsp);
David Brown5153bd62017-01-06 11:16:53 -0700410
David Brown0d0652a2017-04-11 17:33:30 -0600411 BOOT_LOG_ERR("Never should get here");
412 while (1)
413 ;
David Brown5153bd62017-01-06 11:16:53 -0700414}