David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012-2014 Wind River Systems, Inc. |
Tamas Ban | ee6615d | 2020-09-30 07:58:48 +0100 | [diff] [blame] | 3 | * Copyright (c) 2020 Arm Limited |
Jamie McCrae | b3e3ce3 | 2023-02-22 09:11:57 +0000 | [diff] [blame] | 4 | * Copyright (c) 2021-2023 Nordic Semiconductor ASA |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 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 | |
Marti Bolivar | eb94080 | 2017-05-01 23:15:29 -0400 | [diff] [blame] | 19 | #include <assert.h> |
Gerard Marull-Paretas | 34dd9e7 | 2022-05-09 12:13:12 +0200 | [diff] [blame] | 20 | #include <zephyr/kernel.h> |
Gerard Marull-Paretas | 3cd2cec | 2022-05-09 12:10:05 +0200 | [diff] [blame] | 21 | #include <zephyr/devicetree.h> |
| 22 | #include <zephyr/drivers/gpio.h> |
| 23 | #include <zephyr/sys/__assert.h> |
| 24 | #include <zephyr/drivers/flash.h> |
| 25 | #include <zephyr/drivers/timer/system_timer.h> |
| 26 | #include <zephyr/usb/usb_device.h> |
Evan Gates | 4632d8d | 2018-06-28 13:27:40 -0700 | [diff] [blame] | 27 | #include <soc.h> |
Gerard Marull-Paretas | 3cd2cec | 2022-05-09 12:10:05 +0200 | [diff] [blame] | 28 | #include <zephyr/linker/linker-defs.h> |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 29 | |
Jamie McCrae | 24ac8cc | 2024-03-19 08:18:44 +0000 | [diff] [blame] | 30 | #if defined(CONFIG_BOOT_DISABLE_CACHES) |
| 31 | #include <zephyr/cache.h> |
| 32 | #endif |
| 33 | |
Lucas Tamborrino | 9bf7ce8 | 2023-09-05 11:20:50 -0300 | [diff] [blame] | 34 | #if defined(CONFIG_ARM) |
Gerard Marull-Paretas | 11ecbf6 | 2023-06-30 09:58:41 +0200 | [diff] [blame] | 35 | #include <cmsis_core.h> |
Lucas Tamborrino | 9bf7ce8 | 2023-09-05 11:20:50 -0300 | [diff] [blame] | 36 | #endif |
Yonatan Schachter | b22eb6a | 2022-07-29 18:16:09 +0300 | [diff] [blame] | 37 | |
Jamie McCrae | 433b848 | 2023-08-16 07:33:24 +0100 | [diff] [blame] | 38 | #include "io/io.h" |
Marti Bolivar | 51181cf | 2017-03-20 11:03:41 -0400 | [diff] [blame] | 39 | #include "target.h" |
| 40 | |
Marti Bolivar | 4a97b4c | 2017-01-31 18:20:02 -0500 | [diff] [blame] | 41 | #include "bootutil/bootutil_log.h" |
Ricardo Salveti | 3a2c124 | 2017-01-19 10:22:35 -0200 | [diff] [blame] | 42 | #include "bootutil/image.h" |
| 43 | #include "bootutil/bootutil.h" |
Tamas Ban | ee6615d | 2020-09-30 07:58:48 +0100 | [diff] [blame] | 44 | #include "bootutil/fault_injection_hardening.h" |
Jamie McCrae | 56cb610 | 2022-03-23 11:57:03 +0000 | [diff] [blame] | 45 | #include "bootutil/mcuboot_status.h" |
Andrzej Puzdrowski | b788c71 | 2018-04-12 12:42:49 +0200 | [diff] [blame] | 46 | #include "flash_map_backend/flash_map_backend.h" |
Ricardo Salveti | 3a2c124 | 2017-01-19 10:22:35 -0200 | [diff] [blame] | 47 | |
Marek Matej | 6769344 | 2023-01-23 17:54:36 +0100 | [diff] [blame] | 48 | /* Check if Espressif target is supported */ |
Sylvio Alves | b794d33 | 2024-03-04 10:08:30 -0300 | [diff] [blame] | 49 | #ifdef CONFIG_SOC_FAMILY_ESPRESSIF_ESP32 |
Marek Matej | 6769344 | 2023-01-23 17:54:36 +0100 | [diff] [blame] | 50 | |
| 51 | #include <bootloader_init.h> |
Marek Matej | c87d41e | 2024-08-16 22:41:36 +0200 | [diff] [blame] | 52 | #include <esp_image_loader.h> |
Marek Matej | 6769344 | 2023-01-23 17:54:36 +0100 | [diff] [blame] | 53 | |
| 54 | #define IMAGE_INDEX_0 0 |
| 55 | #define IMAGE_INDEX_1 1 |
| 56 | |
| 57 | #define PRIMARY_SLOT 0 |
| 58 | #define SECONDARY_SLOT 1 |
| 59 | |
| 60 | #define IMAGE0_PRIMARY_START_ADDRESS \ |
| 61 | DT_PROP_BY_IDX(DT_NODE_BY_FIXED_PARTITION_LABEL(image_0), reg, 0) |
| 62 | #define IMAGE0_PRIMARY_SIZE \ |
| 63 | DT_PROP_BY_IDX(DT_NODE_BY_FIXED_PARTITION_LABEL(image_0), reg, 1) |
| 64 | |
| 65 | #define IMAGE1_PRIMARY_START_ADDRESS \ |
| 66 | DT_PROP_BY_IDX(DT_NODE_BY_FIXED_PARTITION_LABEL(image_1), reg, 0) |
| 67 | #define IMAGE1_PRIMARY_SIZE \ |
| 68 | DT_PROP_BY_IDX(DT_NODE_BY_FIXED_PARTITION_LABEL(image_1), reg, 1) |
| 69 | |
Sylvio Alves | b794d33 | 2024-03-04 10:08:30 -0300 | [diff] [blame] | 70 | #endif /* CONFIG_SOC_FAMILY_ESPRESSIF_ESP32 */ |
Marek Matej | 6769344 | 2023-01-23 17:54:36 +0100 | [diff] [blame] | 71 | |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 72 | #ifdef CONFIG_MCUBOOT_SERIAL |
Marko Kiiskila | 149b457 | 2018-06-06 14:18:54 +0300 | [diff] [blame] | 73 | #include "boot_serial/boot_serial.h" |
| 74 | #include "serial_adapter/serial_adapter.h" |
| 75 | |
| 76 | const struct boot_uart_funcs boot_funcs = { |
| 77 | .read = console_read, |
| 78 | .write = console_write |
| 79 | }; |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 80 | #endif |
| 81 | |
Josh Gao | 837cf88 | 2020-11-13 18:51:27 -0800 | [diff] [blame] | 82 | #if defined(CONFIG_BOOT_USB_DFU_WAIT) || defined(CONFIG_BOOT_USB_DFU_GPIO) |
Gerard Marull-Paretas | 3cd2cec | 2022-05-09 12:10:05 +0200 | [diff] [blame] | 83 | #include <zephyr/usb/class/usb_dfu.h> |
Rajavardhan Gundi | 51c9d70 | 2019-02-20 14:08:52 +0530 | [diff] [blame] | 84 | #endif |
| 85 | |
Andrzej Puzdrowski | 9a605b6 | 2020-03-16 13:34:30 +0100 | [diff] [blame] | 86 | #if CONFIG_MCUBOOT_CLEANUP_ARM_CORE |
| 87 | #include <arm_cleanup.h> |
| 88 | #endif |
| 89 | |
Gerard Marull-Paretas | a513b8e | 2021-01-26 22:50:38 +0100 | [diff] [blame] | 90 | /* CONFIG_LOG_MINIMAL is the legacy Kconfig property, |
| 91 | * replaced by CONFIG_LOG_MODE_MINIMAL. |
| 92 | */ |
Dominik Ermel | 5b7ed6a | 2021-02-26 14:26:48 +0000 | [diff] [blame] | 93 | #if (defined(CONFIG_LOG_MODE_MINIMAL) || defined(CONFIG_LOG_MINIMAL)) |
| 94 | #define ZEPHYR_LOG_MODE_MINIMAL 1 |
| 95 | #endif |
Gerard Marull-Paretas | a513b8e | 2021-01-26 22:50:38 +0100 | [diff] [blame] | 96 | |
Marek Pieta | fb47d2e | 2022-03-11 14:24:07 +0100 | [diff] [blame] | 97 | /* CONFIG_LOG_IMMEDIATE is the legacy Kconfig property, |
| 98 | * replaced by CONFIG_LOG_MODE_IMMEDIATE. |
| 99 | */ |
| 100 | #if (defined(CONFIG_LOG_MODE_IMMEDIATE) || defined(CONFIG_LOG_IMMEDIATE)) |
| 101 | #define ZEPHYR_LOG_MODE_IMMEDIATE 1 |
| 102 | #endif |
| 103 | |
| 104 | #if defined(CONFIG_LOG) && !defined(ZEPHYR_LOG_MODE_IMMEDIATE) && \ |
Dominik Ermel | 5b7ed6a | 2021-02-26 14:26:48 +0000 | [diff] [blame] | 105 | !defined(ZEPHYR_LOG_MODE_MINIMAL) |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 106 | #ifdef CONFIG_LOG_PROCESS_THREAD |
| 107 | #warning "The log internal thread for log processing can't transfer the log"\ |
| 108 | "well for MCUBoot." |
| 109 | #else |
Gerard Marull-Paretas | 3cd2cec | 2022-05-09 12:10:05 +0200 | [diff] [blame] | 110 | #include <zephyr/logging/log_ctrl.h> |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 111 | |
Krzysztof Chruscinski | 821214e | 2020-03-24 07:50:32 +0100 | [diff] [blame] | 112 | #define BOOT_LOG_PROCESSING_INTERVAL K_MSEC(30) /* [ms] */ |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 113 | |
| 114 | /* log are processing in custom routine */ |
Andrzej Puzdrowski | af14853 | 2020-02-25 12:51:26 +0100 | [diff] [blame] | 115 | K_THREAD_STACK_DEFINE(boot_log_stack, CONFIG_MCUBOOT_LOG_THREAD_STACK_SIZE); |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 116 | struct k_thread boot_log_thread; |
Andrzej Puzdrowski | 8459163 | 2020-02-24 11:50:19 +0100 | [diff] [blame] | 117 | volatile bool boot_log_stop = false; |
| 118 | K_SEM_DEFINE(boot_log_sem, 1, 1); |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 119 | |
| 120 | /* log processing need to be initalized by the application */ |
| 121 | #define ZEPHYR_BOOT_LOG_START() zephyr_boot_log_start() |
Andrzej Puzdrowski | 8459163 | 2020-02-24 11:50:19 +0100 | [diff] [blame] | 122 | #define ZEPHYR_BOOT_LOG_STOP() zephyr_boot_log_stop() |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 123 | #endif /* CONFIG_LOG_PROCESS_THREAD */ |
| 124 | #else |
| 125 | /* synchronous log mode doesn't need to be initalized by the application */ |
| 126 | #define ZEPHYR_BOOT_LOG_START() do { } while (false) |
Andrzej Puzdrowski | 8459163 | 2020-02-24 11:50:19 +0100 | [diff] [blame] | 127 | #define ZEPHYR_BOOT_LOG_STOP() do { } while (false) |
Marek Pieta | fb47d2e | 2022-03-11 14:24:07 +0100 | [diff] [blame] | 128 | #endif /* defined(CONFIG_LOG) && !defined(ZEPHYR_LOG_MODE_IMMEDIATE) && \ |
| 129 | * !defined(ZEPHYR_LOG_MODE_MINIMAL) |
| 130 | */ |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 131 | |
Carlos Falgueras GarcÃa | a4b4b0f | 2021-06-22 10:00:22 +0200 | [diff] [blame] | 132 | BOOT_LOG_MODULE_REGISTER(mcuboot); |
Emanuele Di Santo | 9f1933d | 2018-11-20 10:59:59 +0100 | [diff] [blame] | 133 | |
Andrew Boie | 7238f51 | 2017-03-02 13:39:06 -0800 | [diff] [blame] | 134 | void os_heap_init(void); |
| 135 | |
| 136 | #if defined(CONFIG_ARM) |
Rafał Kuźnia | d854bb6 | 2020-06-17 15:06:47 +0200 | [diff] [blame] | 137 | |
Rafał Kuźnia | d854bb6 | 2020-06-17 15:06:47 +0200 | [diff] [blame] | 138 | #ifdef CONFIG_SW_VECTOR_RELAY |
| 139 | extern void *_vector_table_pointer; |
Rafał Kuźnia | d854bb6 | 2020-06-17 15:06:47 +0200 | [diff] [blame] | 140 | #endif |
| 141 | |
Andrew Boie | 7238f51 | 2017-03-02 13:39:06 -0800 | [diff] [blame] | 142 | struct arm_vector_table { |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 143 | uint32_t msp; |
| 144 | uint32_t reset; |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
Andrew Boie | 7238f51 | 2017-03-02 13:39:06 -0800 | [diff] [blame] | 147 | static void do_boot(struct boot_rsp *rsp) |
| 148 | { |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 149 | struct arm_vector_table *vt; |
Andrew Boie | 7238f51 | 2017-03-02 13:39:06 -0800 | [diff] [blame] | 150 | |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 151 | /* The beginning of the image is the ARM vector table, containing |
| 152 | * the initial stack pointer address and the reset vector |
| 153 | * consecutively. Manually set the stack pointer and jump into the |
| 154 | * reset vector |
| 155 | */ |
Daniel DeGrasse | e457444 | 2022-09-01 15:47:01 -0500 | [diff] [blame] | 156 | #ifdef CONFIG_BOOT_RAM_LOAD |
| 157 | /* Get ram address for image */ |
| 158 | vt = (struct arm_vector_table *)(rsp->br_hdr->ih_load_addr + rsp->br_hdr->ih_hdr_size); |
| 159 | #else |
Daniel DeGrasse | e457444 | 2022-09-01 15:47:01 -0500 | [diff] [blame] | 160 | int rc; |
Mahesh Mahadevan | 453096b | 2024-02-06 21:06:54 -0600 | [diff] [blame] | 161 | const struct flash_area *fap; |
| 162 | static uint32_t dst[2]; |
Daniel DeGrasse | e457444 | 2022-09-01 15:47:01 -0500 | [diff] [blame] | 163 | |
| 164 | /* Jump to flash image */ |
Mahesh Mahadevan | 453096b | 2024-02-06 21:06:54 -0600 | [diff] [blame] | 165 | rc = flash_area_open(rsp->br_flash_dev_id, &fap); |
Marti Bolivar | eb94080 | 2017-05-01 23:15:29 -0400 | [diff] [blame] | 166 | assert(rc == 0); |
| 167 | |
Mahesh Mahadevan | 453096b | 2024-02-06 21:06:54 -0600 | [diff] [blame] | 168 | rc = flash_area_read(fap, rsp->br_hdr->ih_hdr_size, dst, sizeof(dst)); |
| 169 | assert(rc == 0); |
| 170 | #ifndef CONFIG_ASSERT |
| 171 | /* Enter a lock up as asserts are disabled */ |
| 172 | if (rc != 0) { |
| 173 | while (1); |
| 174 | } |
| 175 | #endif |
| 176 | |
| 177 | flash_area_close(fap); |
| 178 | |
| 179 | vt = (struct arm_vector_table *)dst; |
Daniel DeGrasse | e457444 | 2022-09-01 15:47:01 -0500 | [diff] [blame] | 180 | #endif |
Arvid Rosén | 9ed399c | 2020-08-19 08:57:11 +0200 | [diff] [blame] | 181 | |
Joakim Andersson | 90b8f69 | 2022-12-21 15:52:53 +0100 | [diff] [blame] | 182 | if (IS_ENABLED(CONFIG_SYSTEM_TIMER_HAS_DISABLE_SUPPORT)) { |
| 183 | sys_clock_disable(); |
| 184 | } |
Andrzej Puzdrowski | e9c6b4d | 2021-12-14 14:09:02 +0100 | [diff] [blame] | 185 | |
Johann Fischer | d2e87aa | 2021-08-27 13:30:07 +0200 | [diff] [blame] | 186 | #ifdef CONFIG_USB_DEVICE_STACK |
Emanuele Di Santo | c4bf780 | 2018-07-20 11:39:57 +0200 | [diff] [blame] | 187 | /* Disable the USB to prevent it from firing interrupts */ |
| 188 | usb_disable(); |
| 189 | #endif |
Andrzej Puzdrowski | 9a605b6 | 2020-03-16 13:34:30 +0100 | [diff] [blame] | 190 | #if CONFIG_MCUBOOT_CLEANUP_ARM_CORE |
| 191 | cleanup_arm_nvic(); /* cleanup NVIC registers */ |
Ioannis Glaropoulos | 70af708 | 2020-10-22 15:14:48 +0200 | [diff] [blame] | 192 | |
Jamie McCrae | 24ac8cc | 2024-03-19 08:18:44 +0000 | [diff] [blame] | 193 | #if defined(CONFIG_BOOT_DISABLE_CACHES) |
| 194 | /* Flush and disable instruction/data caches before chain-loading the application */ |
| 195 | (void)sys_cache_instr_flush_all(); |
| 196 | (void)sys_cache_data_flush_all(); |
| 197 | sys_cache_instr_disable(); |
| 198 | sys_cache_data_disable(); |
Ioannis Glaropoulos | 70af708 | 2020-10-22 15:14:48 +0200 | [diff] [blame] | 199 | #endif |
| 200 | |
Henrik Brix Andersen | 008f4a7 | 2020-12-08 14:40:19 +0100 | [diff] [blame] | 201 | #if CONFIG_CPU_HAS_ARM_MPU || CONFIG_CPU_HAS_NXP_MPU |
Ioannis Glaropoulos | 70af708 | 2020-10-22 15:14:48 +0200 | [diff] [blame] | 202 | z_arm_clear_arm_mpu_config(); |
Andrzej Puzdrowski | 9a605b6 | 2020-03-16 13:34:30 +0100 | [diff] [blame] | 203 | #endif |
Rafał Kuźnia | d854bb6 | 2020-06-17 15:06:47 +0200 | [diff] [blame] | 204 | |
Håkon Øye Amundsen | 6a8dbba | 2020-10-01 12:52:38 +0000 | [diff] [blame] | 205 | #if defined(CONFIG_BUILTIN_STACK_GUARD) && \ |
| 206 | defined(CONFIG_CPU_CORTEX_M_HAS_SPLIM) |
| 207 | /* Reset limit registers to avoid inflicting stack overflow on image |
| 208 | * being booted. |
| 209 | */ |
| 210 | __set_PSPLIM(0); |
| 211 | __set_MSPLIM(0); |
| 212 | #endif |
| 213 | |
Sigvart Hovland | 9647c46 | 2021-08-20 16:33:55 +0200 | [diff] [blame] | 214 | #else |
| 215 | irq_lock(); |
Ioannis Glaropoulos | 70af708 | 2020-10-22 15:14:48 +0200 | [diff] [blame] | 216 | #endif /* CONFIG_MCUBOOT_CLEANUP_ARM_CORE */ |
| 217 | |
Rafał Kuźnia | d854bb6 | 2020-06-17 15:06:47 +0200 | [diff] [blame] | 218 | #ifdef CONFIG_BOOT_INTR_VEC_RELOC |
Rafał Kuźnia | 505c6e6 | 2020-07-17 13:18:15 +0200 | [diff] [blame] | 219 | #if defined(CONFIG_SW_VECTOR_RELAY) |
| 220 | _vector_table_pointer = vt; |
| 221 | #ifdef CONFIG_CPU_CORTEX_M_HAS_VTOR |
| 222 | SCB->VTOR = (uint32_t)__vector_relay_table; |
Rafał Kuźnia | d854bb6 | 2020-06-17 15:06:47 +0200 | [diff] [blame] | 223 | #endif |
Rafał Kuźnia | 505c6e6 | 2020-07-17 13:18:15 +0200 | [diff] [blame] | 224 | #elif defined(CONFIG_CPU_CORTEX_M_HAS_VTOR) |
| 225 | SCB->VTOR = (uint32_t)vt; |
| 226 | #endif /* CONFIG_SW_VECTOR_RELAY */ |
| 227 | #else /* CONFIG_BOOT_INTR_VEC_RELOC */ |
| 228 | #if defined(CONFIG_CPU_CORTEX_M_HAS_VTOR) && defined(CONFIG_SW_VECTOR_RELAY) |
| 229 | _vector_table_pointer = _vector_start; |
| 230 | SCB->VTOR = (uint32_t)__vector_relay_table; |
| 231 | #endif |
| 232 | #endif /* CONFIG_BOOT_INTR_VEC_RELOC */ |
Rafał Kuźnia | d854bb6 | 2020-06-17 15:06:47 +0200 | [diff] [blame] | 233 | |
David Brown | 57837b9 | 2018-03-13 15:56:38 -0600 | [diff] [blame] | 234 | __set_MSP(vt->msp); |
Andrzej Puzdrowski | 9a605b6 | 2020-03-16 13:34:30 +0100 | [diff] [blame] | 235 | #if CONFIG_MCUBOOT_CLEANUP_ARM_CORE |
| 236 | __set_CONTROL(0x00); /* application will configures core on its own */ |
Andrzej Puzdrowski | 56c15e7 | 2020-10-29 09:16:50 +0100 | [diff] [blame] | 237 | __ISB(); |
Andrzej Puzdrowski | 9a605b6 | 2020-03-16 13:34:30 +0100 | [diff] [blame] | 238 | #endif |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 239 | ((void (*)(void))vt->reset)(); |
Andrew Boie | 7238f51 | 2017-03-02 13:39:06 -0800 | [diff] [blame] | 240 | } |
Rajavardhan Gundi | 40c28e3 | 2018-12-09 13:32:01 +0530 | [diff] [blame] | 241 | |
Marek Matej | 6769344 | 2023-01-23 17:54:36 +0100 | [diff] [blame] | 242 | #elif defined(CONFIG_XTENSA) || defined(CONFIG_RISCV) |
| 243 | |
Sylvio Alves | b794d33 | 2024-03-04 10:08:30 -0300 | [diff] [blame] | 244 | #ifndef CONFIG_SOC_FAMILY_ESPRESSIF_ESP32 |
Marek Matej | 6769344 | 2023-01-23 17:54:36 +0100 | [diff] [blame] | 245 | |
Rajavardhan Gundi | 40c28e3 | 2018-12-09 13:32:01 +0530 | [diff] [blame] | 246 | #define SRAM_BASE_ADDRESS 0xBE030000 |
| 247 | |
| 248 | static void copy_img_to_SRAM(int slot, unsigned int hdr_offset) |
| 249 | { |
| 250 | const struct flash_area *fap; |
| 251 | int area_id; |
| 252 | int rc; |
| 253 | unsigned char *dst = (unsigned char *)(SRAM_BASE_ADDRESS + hdr_offset); |
| 254 | |
| 255 | BOOT_LOG_INF("Copying image to SRAM"); |
| 256 | |
| 257 | area_id = flash_area_id_from_image_slot(slot); |
| 258 | rc = flash_area_open(area_id, &fap); |
| 259 | if (rc != 0) { |
Fabio Utzig | cac58f6 | 2019-09-06 08:52:35 -0300 | [diff] [blame] | 260 | BOOT_LOG_ERR("flash_area_open failed with %d\n", rc); |
Rajavardhan Gundi | 40c28e3 | 2018-12-09 13:32:01 +0530 | [diff] [blame] | 261 | goto done; |
| 262 | } |
| 263 | |
| 264 | rc = flash_area_read(fap, hdr_offset, dst, fap->fa_size - hdr_offset); |
| 265 | if (rc != 0) { |
Fabio Utzig | cac58f6 | 2019-09-06 08:52:35 -0300 | [diff] [blame] | 266 | BOOT_LOG_ERR("flash_area_read failed with %d\n", rc); |
Rajavardhan Gundi | 40c28e3 | 2018-12-09 13:32:01 +0530 | [diff] [blame] | 267 | goto done; |
| 268 | } |
| 269 | |
| 270 | done: |
| 271 | flash_area_close(fap); |
| 272 | } |
Sylvio Alves | b794d33 | 2024-03-04 10:08:30 -0300 | [diff] [blame] | 273 | #endif /* !CONFIG_SOC_FAMILY_ESPRESSIF_ESP32 */ |
Rajavardhan Gundi | 40c28e3 | 2018-12-09 13:32:01 +0530 | [diff] [blame] | 274 | |
| 275 | /* Entry point (.ResetVector) is at the very beginning of the image. |
| 276 | * Simply copy the image to a suitable location and jump there. |
| 277 | */ |
| 278 | static void do_boot(struct boot_rsp *rsp) |
| 279 | { |
Sylvio Alves | 334d2c2 | 2024-07-01 13:12:27 -0300 | [diff] [blame] | 280 | #ifndef CONFIG_SOC_FAMILY_ESPRESSIF_ESP32 |
Rajavardhan Gundi | 40c28e3 | 2018-12-09 13:32:01 +0530 | [diff] [blame] | 281 | void *start; |
Sylvio Alves | 334d2c2 | 2024-07-01 13:12:27 -0300 | [diff] [blame] | 282 | #endif /* CONFIG_SOC_FAMILY_ESPRESSIF_ESP32 */ |
Rajavardhan Gundi | 40c28e3 | 2018-12-09 13:32:01 +0530 | [diff] [blame] | 283 | |
| 284 | BOOT_LOG_INF("br_image_off = 0x%x\n", rsp->br_image_off); |
| 285 | BOOT_LOG_INF("ih_hdr_size = 0x%x\n", rsp->br_hdr->ih_hdr_size); |
| 286 | |
Sylvio Alves | b794d33 | 2024-03-04 10:08:30 -0300 | [diff] [blame] | 287 | #ifdef CONFIG_SOC_FAMILY_ESPRESSIF_ESP32 |
Marek Matej | 6769344 | 2023-01-23 17:54:36 +0100 | [diff] [blame] | 288 | int slot = (rsp->br_image_off == IMAGE0_PRIMARY_START_ADDRESS) ? |
| 289 | PRIMARY_SLOT : SECONDARY_SLOT; |
| 290 | /* Load memory segments and start from entry point */ |
| 291 | start_cpu0_image(IMAGE_INDEX_0, slot, rsp->br_hdr->ih_hdr_size); |
| 292 | #else |
Rajavardhan Gundi | 40c28e3 | 2018-12-09 13:32:01 +0530 | [diff] [blame] | 293 | /* Copy from the flash to HP SRAM */ |
| 294 | copy_img_to_SRAM(0, rsp->br_hdr->ih_hdr_size); |
| 295 | |
| 296 | /* Jump to entry point */ |
| 297 | start = (void *)(SRAM_BASE_ADDRESS + rsp->br_hdr->ih_hdr_size); |
| 298 | ((void (*)(void))start)(); |
Sylvio Alves | b794d33 | 2024-03-04 10:08:30 -0300 | [diff] [blame] | 299 | #endif /* CONFIG_SOC_FAMILY_ESPRESSIF_ESP32 */ |
Rajavardhan Gundi | 40c28e3 | 2018-12-09 13:32:01 +0530 | [diff] [blame] | 300 | } |
| 301 | |
Andrew Boie | 7238f51 | 2017-03-02 13:39:06 -0800 | [diff] [blame] | 302 | #else |
| 303 | /* Default: Assume entry point is at the very beginning of the image. Simply |
| 304 | * lock interrupts and jump there. This is the right thing to do for X86 and |
| 305 | * possibly other platforms. |
| 306 | */ |
| 307 | static void do_boot(struct boot_rsp *rsp) |
| 308 | { |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 309 | void *start; |
Martin Jäger | 477ed81 | 2022-07-21 11:45:45 +0200 | [diff] [blame] | 310 | |
Jim Tan | ee1b7b9 | 2022-04-07 11:26:28 +0800 | [diff] [blame] | 311 | #if defined(MCUBOOT_RAM_LOAD) |
| 312 | start = (void *)(rsp->br_hdr->ih_load_addr + rsp->br_hdr->ih_hdr_size); |
| 313 | #else |
| 314 | uintptr_t flash_base; |
Marti Bolivar | eb94080 | 2017-05-01 23:15:29 -0400 | [diff] [blame] | 315 | int rc; |
Andrew Boie | 7238f51 | 2017-03-02 13:39:06 -0800 | [diff] [blame] | 316 | |
Marti Bolivar | eb94080 | 2017-05-01 23:15:29 -0400 | [diff] [blame] | 317 | rc = flash_device_base(rsp->br_flash_dev_id, &flash_base); |
| 318 | assert(rc == 0); |
| 319 | |
| 320 | start = (void *)(flash_base + rsp->br_image_off + |
| 321 | rsp->br_hdr->ih_hdr_size); |
Jim Tan | ee1b7b9 | 2022-04-07 11:26:28 +0800 | [diff] [blame] | 322 | #endif |
Andrew Boie | 7238f51 | 2017-03-02 13:39:06 -0800 | [diff] [blame] | 323 | |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 324 | /* Lock interrupts and dive into the entry point */ |
| 325 | irq_lock(); |
| 326 | ((void (*)(void))start)(); |
Andrew Boie | 7238f51 | 2017-03-02 13:39:06 -0800 | [diff] [blame] | 327 | } |
| 328 | #endif |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 329 | |
Marek Pieta | fb47d2e | 2022-03-11 14:24:07 +0100 | [diff] [blame] | 330 | #if defined(CONFIG_LOG) && !defined(ZEPHYR_LOG_MODE_IMMEDIATE) && \ |
Dominik Ermel | 5b7ed6a | 2021-02-26 14:26:48 +0000 | [diff] [blame] | 331 | !defined(CONFIG_LOG_PROCESS_THREAD) && !defined(ZEPHYR_LOG_MODE_MINIMAL) |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 332 | /* The log internal thread for log processing can't transfer log well as has too |
| 333 | * low priority. |
| 334 | * Dedicated thread for log processing below uses highest application |
| 335 | * priority. This allows to transmit all logs without adding k_sleep/k_yield |
| 336 | * anywhere else int the code. |
| 337 | */ |
| 338 | |
| 339 | /* most simple log processing theread */ |
| 340 | void boot_log_thread_func(void *dummy1, void *dummy2, void *dummy3) |
| 341 | { |
| 342 | (void)dummy1; |
| 343 | (void)dummy2; |
| 344 | (void)dummy3; |
| 345 | |
Martin Jäger | 477ed81 | 2022-07-21 11:45:45 +0200 | [diff] [blame] | 346 | log_init(); |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 347 | |
Martin Jäger | 477ed81 | 2022-07-21 11:45:45 +0200 | [diff] [blame] | 348 | while (1) { |
Martin Jäger | 3175182 | 2022-07-21 11:49:32 +0200 | [diff] [blame] | 349 | #if defined(CONFIG_LOG1) || defined(CONFIG_LOG2) |
| 350 | /* support Zephyr legacy logging implementation before commit c5f2cde */ |
Martin Jäger | 477ed81 | 2022-07-21 11:45:45 +0200 | [diff] [blame] | 351 | if (log_process(false) == false) { |
Martin Jäger | 3175182 | 2022-07-21 11:49:32 +0200 | [diff] [blame] | 352 | #else |
| 353 | if (log_process() == false) { |
| 354 | #endif |
Martin Jäger | 477ed81 | 2022-07-21 11:45:45 +0200 | [diff] [blame] | 355 | if (boot_log_stop) { |
| 356 | break; |
| 357 | } |
| 358 | k_sleep(BOOT_LOG_PROCESSING_INTERVAL); |
| 359 | } |
| 360 | } |
Andrzej Puzdrowski | 8459163 | 2020-02-24 11:50:19 +0100 | [diff] [blame] | 361 | |
Martin Jäger | 477ed81 | 2022-07-21 11:45:45 +0200 | [diff] [blame] | 362 | k_sem_give(&boot_log_sem); |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void zephyr_boot_log_start(void) |
| 366 | { |
Martin Jäger | 477ed81 | 2022-07-21 11:45:45 +0200 | [diff] [blame] | 367 | /* start logging thread */ |
| 368 | k_thread_create(&boot_log_thread, boot_log_stack, |
| 369 | K_THREAD_STACK_SIZEOF(boot_log_stack), |
| 370 | boot_log_thread_func, NULL, NULL, NULL, |
| 371 | K_HIGHEST_APPLICATION_THREAD_PRIO, 0, |
| 372 | BOOT_LOG_PROCESSING_INTERVAL); |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 373 | |
Martin Jäger | 477ed81 | 2022-07-21 11:45:45 +0200 | [diff] [blame] | 374 | k_thread_name_set(&boot_log_thread, "logging"); |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 375 | } |
Andrzej Puzdrowski | 8459163 | 2020-02-24 11:50:19 +0100 | [diff] [blame] | 376 | |
| 377 | void zephyr_boot_log_stop(void) |
| 378 | { |
| 379 | boot_log_stop = true; |
| 380 | |
| 381 | /* wait until log procesing thread expired |
| 382 | * This can be reworked using a thread_join() API once a such will be |
| 383 | * available in zephyr. |
| 384 | * see https://github.com/zephyrproject-rtos/zephyr/issues/21500 |
| 385 | */ |
| 386 | (void)k_sem_take(&boot_log_sem, K_FOREVER); |
| 387 | } |
Marek Pieta | fb47d2e | 2022-03-11 14:24:07 +0100 | [diff] [blame] | 388 | #endif /* defined(CONFIG_LOG) && !defined(ZEPHYR_LOG_MODE_IMMEDIATE) && \ |
| 389 | * !defined(CONFIG_LOG_PROCESS_THREAD) && !defined(ZEPHYR_LOG_MODE_MINIMAL) |
| 390 | */ |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 391 | |
Jamie McCrae | 6902abb | 2023-04-04 13:50:43 +0100 | [diff] [blame] | 392 | #ifdef CONFIG_MCUBOOT_SERIAL |
| 393 | static void boot_serial_enter() |
| 394 | { |
| 395 | int rc; |
| 396 | |
| 397 | #ifdef CONFIG_MCUBOOT_INDICATION_LED |
Piotr Dymacz | 2a74a2b | 2023-12-05 14:26:22 +0100 | [diff] [blame] | 398 | io_led_set(1); |
Jamie McCrae | 6902abb | 2023-04-04 13:50:43 +0100 | [diff] [blame] | 399 | #endif |
| 400 | |
| 401 | mcuboot_status_change(MCUBOOT_STATUS_SERIAL_DFU_ENTERED); |
| 402 | |
| 403 | BOOT_LOG_INF("Enter the serial recovery mode"); |
| 404 | rc = boot_console_init(); |
| 405 | __ASSERT(rc == 0, "Error initializing boot console.\n"); |
| 406 | boot_serial_start(&boot_funcs); |
| 407 | __ASSERT(0, "Bootloader serial process was terminated unexpectedly.\n"); |
| 408 | } |
| 409 | #endif |
| 410 | |
Keith Packard | ec2ac82 | 2023-04-27 09:56:10 -0700 | [diff] [blame] | 411 | int main(void) |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 412 | { |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 413 | struct boot_rsp rsp; |
| 414 | int rc; |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 415 | FIH_DECLARE(fih_rc, FIH_FAILURE); |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 416 | |
Jeppe Odgaard | 4420bb6 | 2023-04-11 09:43:10 +0200 | [diff] [blame] | 417 | MCUBOOT_WATCHDOG_SETUP(); |
Andrzej Puzdrowski | 210b318 | 2020-10-13 13:52:15 +0200 | [diff] [blame] | 418 | MCUBOOT_WATCHDOG_FEED(); |
| 419 | |
Dominik Ermel | cd07ed3 | 2021-02-17 15:18:01 +0000 | [diff] [blame] | 420 | #if !defined(MCUBOOT_DIRECT_XIP) |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 421 | BOOT_LOG_INF("Starting bootloader"); |
Dominik Ermel | cd07ed3 | 2021-02-17 15:18:01 +0000 | [diff] [blame] | 422 | #else |
| 423 | BOOT_LOG_INF("Starting Direct-XIP bootloader"); |
| 424 | #endif |
Ricardo Salveti | 7cf3d9e | 2017-01-18 16:38:22 -0200 | [diff] [blame] | 425 | |
Jared Wolff | 8e4d791 | 2021-01-21 19:34:05 -0500 | [diff] [blame] | 426 | #ifdef CONFIG_MCUBOOT_INDICATION_LED |
| 427 | /* LED init */ |
Piotr Dymacz | d99154f | 2023-12-05 13:41:59 +0100 | [diff] [blame] | 428 | io_led_init(); |
Jared Wolff | 8e4d791 | 2021-01-21 19:34:05 -0500 | [diff] [blame] | 429 | #endif |
| 430 | |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 431 | os_heap_init(); |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 432 | |
Andrzej Puzdrowski | 3f092bd | 2020-02-17 13:25:32 +0100 | [diff] [blame] | 433 | ZEPHYR_BOOT_LOG_START(); |
| 434 | |
Tamas Ban | ee6615d | 2020-09-30 07:58:48 +0100 | [diff] [blame] | 435 | (void)rc; |
| 436 | |
Jamie McCrae | 56cb610 | 2022-03-23 11:57:03 +0000 | [diff] [blame] | 437 | mcuboot_status_change(MCUBOOT_STATUS_STARTUP); |
| 438 | |
Jamie McCrae | b3e3ce3 | 2023-02-22 09:11:57 +0000 | [diff] [blame] | 439 | #ifdef CONFIG_BOOT_SERIAL_ENTRANCE_GPIO |
Jamie McCrae | 433b848 | 2023-08-16 07:33:24 +0100 | [diff] [blame] | 440 | if (io_detect_pin() && |
| 441 | !io_boot_skip_serial_recovery()) { |
Jamie McCrae | 6902abb | 2023-04-04 13:50:43 +0100 | [diff] [blame] | 442 | boot_serial_enter(); |
Josh Gao | 837cf88 | 2020-11-13 18:51:27 -0800 | [diff] [blame] | 443 | } |
| 444 | #endif |
| 445 | |
Jamie McCrae | 35941fe | 2023-03-28 10:04:18 +0100 | [diff] [blame] | 446 | #ifdef CONFIG_BOOT_SERIAL_PIN_RESET |
Jamie McCrae | 433b848 | 2023-08-16 07:33:24 +0100 | [diff] [blame] | 447 | if (io_detect_pin_reset()) { |
Jamie McCrae | 6902abb | 2023-04-04 13:50:43 +0100 | [diff] [blame] | 448 | boot_serial_enter(); |
Jamie McCrae | 35941fe | 2023-03-28 10:04:18 +0100 | [diff] [blame] | 449 | } |
| 450 | #endif |
| 451 | |
Josh Gao | 837cf88 | 2020-11-13 18:51:27 -0800 | [diff] [blame] | 452 | #if defined(CONFIG_BOOT_USB_DFU_GPIO) |
Jamie McCrae | 433b848 | 2023-08-16 07:33:24 +0100 | [diff] [blame] | 453 | if (io_detect_pin()) { |
Josh Gao | 837cf88 | 2020-11-13 18:51:27 -0800 | [diff] [blame] | 454 | #ifdef CONFIG_MCUBOOT_INDICATION_LED |
Piotr Dymacz | 2a74a2b | 2023-12-05 14:26:22 +0100 | [diff] [blame] | 455 | io_led_set(1); |
Josh Gao | 837cf88 | 2020-11-13 18:51:27 -0800 | [diff] [blame] | 456 | #endif |
Jamie McCrae | 56cb610 | 2022-03-23 11:57:03 +0000 | [diff] [blame] | 457 | |
| 458 | mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_ENTERED); |
| 459 | |
Josh Gao | 837cf88 | 2020-11-13 18:51:27 -0800 | [diff] [blame] | 460 | rc = usb_enable(NULL); |
| 461 | if (rc) { |
| 462 | BOOT_LOG_ERR("Cannot enable USB"); |
| 463 | } else { |
| 464 | BOOT_LOG_INF("Waiting for USB DFU"); |
| 465 | wait_for_usb_dfu(K_FOREVER); |
| 466 | BOOT_LOG_INF("USB DFU wait time elapsed"); |
| 467 | } |
| 468 | } |
| 469 | #elif defined(CONFIG_BOOT_USB_DFU_WAIT) |
Andrzej Puzdrowski | ac1f1ff | 2020-02-05 08:40:12 +0100 | [diff] [blame] | 470 | rc = usb_enable(NULL); |
| 471 | if (rc) { |
| 472 | BOOT_LOG_ERR("Cannot enable USB"); |
| 473 | } else { |
| 474 | BOOT_LOG_INF("Waiting for USB DFU"); |
Jamie McCrae | 56cb610 | 2022-03-23 11:57:03 +0000 | [diff] [blame] | 475 | |
| 476 | mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_WAITING); |
| 477 | |
Josh Gao | 837cf88 | 2020-11-13 18:51:27 -0800 | [diff] [blame] | 478 | wait_for_usb_dfu(K_MSEC(CONFIG_BOOT_USB_DFU_WAIT_DELAY_MS)); |
Andrzej Puzdrowski | ac1f1ff | 2020-02-05 08:40:12 +0100 | [diff] [blame] | 479 | BOOT_LOG_INF("USB DFU wait time elapsed"); |
Jamie McCrae | 56cb610 | 2022-03-23 11:57:03 +0000 | [diff] [blame] | 480 | |
| 481 | mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_TIMED_OUT); |
Andrzej Puzdrowski | ac1f1ff | 2020-02-05 08:40:12 +0100 | [diff] [blame] | 482 | } |
Rajavardhan Gundi | 51c9d70 | 2019-02-20 14:08:52 +0530 | [diff] [blame] | 483 | #endif |
| 484 | |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 485 | #ifdef CONFIG_BOOT_SERIAL_WAIT_FOR_DFU |
| 486 | /* Initialize the boot console, so we can already fill up our buffers while |
| 487 | * waiting for the boot image check to finish. This image check, can take |
| 488 | * some time, so it's better to reuse thistime to already receive the |
| 489 | * initial mcumgr command(s) into our buffers |
| 490 | */ |
| 491 | rc = boot_console_init(); |
| 492 | int timeout_in_ms = CONFIG_BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT; |
| 493 | uint32_t start = k_uptime_get_32(); |
Piotr Dymacz | 3790f5f | 2022-12-15 14:58:45 +0100 | [diff] [blame] | 494 | |
| 495 | #ifdef CONFIG_MCUBOOT_INDICATION_LED |
Piotr Dymacz | 2a74a2b | 2023-12-05 14:26:22 +0100 | [diff] [blame] | 496 | io_led_set(1); |
Piotr Dymacz | 3790f5f | 2022-12-15 14:58:45 +0100 | [diff] [blame] | 497 | #endif |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 498 | #endif |
| 499 | |
Tamas Ban | ee6615d | 2020-09-30 07:58:48 +0100 | [diff] [blame] | 500 | FIH_CALL(boot_go, fih_rc, &rsp); |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 501 | |
Jamie McCrae | b3e3ce3 | 2023-02-22 09:11:57 +0000 | [diff] [blame] | 502 | #ifdef CONFIG_BOOT_SERIAL_BOOT_MODE |
Jamie McCrae | 433b848 | 2023-08-16 07:33:24 +0100 | [diff] [blame] | 503 | if (io_detect_boot_mode()) { |
Jamie McCrae | b3e3ce3 | 2023-02-22 09:11:57 +0000 | [diff] [blame] | 504 | /* Boot mode to stay in bootloader, clear status and enter serial |
| 505 | * recovery mode |
| 506 | */ |
Jamie McCrae | 6902abb | 2023-04-04 13:50:43 +0100 | [diff] [blame] | 507 | boot_serial_enter(); |
Jamie McCrae | b3e3ce3 | 2023-02-22 09:11:57 +0000 | [diff] [blame] | 508 | } |
| 509 | #endif |
| 510 | |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 511 | #ifdef CONFIG_BOOT_SERIAL_WAIT_FOR_DFU |
| 512 | timeout_in_ms -= (k_uptime_get_32() - start); |
| 513 | if( timeout_in_ms <= 0 ) { |
| 514 | /* at least one check if time was expired */ |
| 515 | timeout_in_ms = 1; |
| 516 | } |
Jamie McCrae | 254714b | 2022-04-07 09:00:31 +0100 | [diff] [blame] | 517 | boot_serial_check_start(&boot_funcs,timeout_in_ms); |
Piotr Dymacz | 3790f5f | 2022-12-15 14:58:45 +0100 | [diff] [blame] | 518 | |
| 519 | #ifdef CONFIG_MCUBOOT_INDICATION_LED |
Piotr Dymacz | 2a74a2b | 2023-12-05 14:26:22 +0100 | [diff] [blame] | 520 | io_led_set(0); |
Piotr Dymacz | 3790f5f | 2022-12-15 14:58:45 +0100 | [diff] [blame] | 521 | #endif |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 522 | #endif |
| 523 | |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 524 | if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) { |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 525 | BOOT_LOG_ERR("Unable to find bootable image"); |
Jamie McCrae | 56cb610 | 2022-03-23 11:57:03 +0000 | [diff] [blame] | 526 | |
| 527 | mcuboot_status_change(MCUBOOT_STATUS_NO_BOOTABLE_IMAGE_FOUND); |
| 528 | |
Jamie McCrae | fd79db3 | 2023-03-10 11:19:36 +0000 | [diff] [blame] | 529 | #ifdef CONFIG_BOOT_SERIAL_NO_APPLICATION |
| 530 | /* No bootable image and configuration set to remain in serial |
| 531 | * recovery mode |
| 532 | */ |
Jamie McCrae | 6902abb | 2023-04-04 13:50:43 +0100 | [diff] [blame] | 533 | boot_serial_enter(); |
Fabian Pflug | ca06b9f | 2024-08-24 11:15:39 +0200 | [diff] [blame] | 534 | #elif defined(CONFIG_BOOT_USB_DFU_NO_APPLICATION) |
| 535 | rc = usb_enable(NULL); |
| 536 | if (rc && rc != -EALREADY) { |
| 537 | BOOT_LOG_ERR("Cannot enable USB"); |
| 538 | } else { |
| 539 | BOOT_LOG_INF("Waiting for USB DFU"); |
| 540 | wait_for_usb_dfu(K_FOREVER); |
| 541 | } |
Jamie McCrae | fd79db3 | 2023-03-10 11:19:36 +0000 | [diff] [blame] | 542 | #endif |
| 543 | |
Tamas Ban | ee6615d | 2020-09-30 07:58:48 +0100 | [diff] [blame] | 544 | FIH_PANIC; |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 545 | } |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 546 | |
Jamie McCrae | 7fc3ad3 | 2024-07-24 14:09:45 +0100 | [diff] [blame] | 547 | #ifdef CONFIG_BOOT_RAM_LOAD |
| 548 | BOOT_LOG_INF("Bootloader chainload address offset: 0x%x", |
| 549 | rsp.br_hdr->ih_load_addr); |
| 550 | #else |
Marti Bolivar | 88f48d9 | 2017-05-01 22:30:02 -0400 | [diff] [blame] | 551 | BOOT_LOG_INF("Bootloader chainload address offset: 0x%x", |
| 552 | rsp.br_image_off); |
Jamie McCrae | 7fc3ad3 | 2024-07-24 14:09:45 +0100 | [diff] [blame] | 553 | #endif |
Andrzej Puzdrowski | b788c71 | 2018-04-12 12:42:49 +0200 | [diff] [blame] | 554 | |
Dominik Ermel | cd07ed3 | 2021-02-17 15:18:01 +0000 | [diff] [blame] | 555 | #if defined(MCUBOOT_DIRECT_XIP) |
| 556 | BOOT_LOG_INF("Jumping to the image slot"); |
| 557 | #else |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 558 | BOOT_LOG_INF("Jumping to the first image slot"); |
Dominik Ermel | cd07ed3 | 2021-02-17 15:18:01 +0000 | [diff] [blame] | 559 | #endif |
Jamie McCrae | 56cb610 | 2022-03-23 11:57:03 +0000 | [diff] [blame] | 560 | |
| 561 | mcuboot_status_change(MCUBOOT_STATUS_BOOTABLE_IMAGE_FOUND); |
| 562 | |
Andrzej Puzdrowski | 8459163 | 2020-02-24 11:50:19 +0100 | [diff] [blame] | 563 | ZEPHYR_BOOT_LOG_STOP(); |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 564 | do_boot(&rsp); |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 565 | |
Jamie McCrae | 56cb610 | 2022-03-23 11:57:03 +0000 | [diff] [blame] | 566 | mcuboot_status_change(MCUBOOT_STATUS_BOOT_FAILED); |
| 567 | |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 568 | BOOT_LOG_ERR("Never should get here"); |
| 569 | while (1) |
| 570 | ; |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 571 | } |