Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. 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, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | #include <assert.h> |
| 20 | #include <stddef.h> |
| 21 | #include <inttypes.h> |
| 22 | #include <ctype.h> |
| 23 | #include <stdio.h> |
| 24 | |
| 25 | #include "sysflash/sysflash.h" |
| 26 | |
Fabio Utzig | 1a2e41a | 2017-11-17 12:13:09 -0200 | [diff] [blame] | 27 | #include "bootutil/bootutil_log.h" |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 28 | #include "zcbor_encode.h" |
Fabio Utzig | 1a2e41a | 2017-11-17 12:13:09 -0200 | [diff] [blame] | 29 | |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 30 | #ifdef __ZEPHYR__ |
Dominik Ermel | 1eedec3 | 2021-12-16 12:55:02 +0000 | [diff] [blame] | 31 | #include <sys/reboot.h> |
Andrzej Puzdrowski | f1d189c | 2019-12-12 09:34:11 +0100 | [diff] [blame] | 32 | #include <sys/byteorder.h> |
| 33 | #include <sys/__assert.h> |
Peter Bigot | 54c1e3f | 2020-01-25 05:50:12 -0600 | [diff] [blame] | 34 | #include <drivers/flash.h> |
Andrzej Puzdrowski | f1d189c | 2019-12-12 09:34:11 +0100 | [diff] [blame] | 35 | #include <sys/crc.h> |
| 36 | #include <sys/base64.h> |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 37 | #else |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 38 | #include <bsp/bsp.h> |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 39 | #include <hal/hal_system.h> |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 40 | #include <os/endian.h> |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 41 | #include <os/os_cputime.h> |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 42 | #include <crc/crc16.h> |
| 43 | #include <base64/base64.h> |
Andrzej Puzdrowski | 386b592 | 2018-04-06 19:26:24 +0200 | [diff] [blame] | 44 | #endif /* __ZEPHYR__ */ |
| 45 | |
Andrzej Puzdrowski | b788c71 | 2018-04-12 12:42:49 +0200 | [diff] [blame] | 46 | #include <flash_map_backend/flash_map_backend.h> |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 47 | #include <hal/hal_flash.h> |
| 48 | #include <os/os.h> |
| 49 | #include <os/os_malloc.h> |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 50 | |
| 51 | #include <bootutil/image.h> |
Andrzej Puzdrowski | f48de7a | 2020-10-19 09:42:02 +0200 | [diff] [blame] | 52 | #include <bootutil/bootutil.h> |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 53 | |
| 54 | #include "boot_serial/boot_serial.h" |
| 55 | #include "boot_serial_priv.h" |
| 56 | |
Dominik Ermel | 3d4e55d | 2021-07-09 11:14:10 +0000 | [diff] [blame] | 57 | #ifdef MCUBOOT_ERASE_PROGRESSIVELY |
Andrzej Puzdrowski | c2e30cf | 2018-07-20 16:19:09 +0200 | [diff] [blame] | 58 | #include "bootutil_priv.h" |
| 59 | #endif |
| 60 | |
Wouter Cappelle | 953a761 | 2021-05-03 16:53:05 +0200 | [diff] [blame] | 61 | #ifdef MCUBOOT_ENC_IMAGES |
| 62 | #include "single_loader.h" |
| 63 | #endif |
| 64 | |
Øyvind Rønningstad | f42a820 | 2019-12-13 03:27:54 +0100 | [diff] [blame] | 65 | #include "serial_recovery_cbor.h" |
Dominik Ermel | 88bd567 | 2022-06-07 15:17:06 +0000 | [diff] [blame] | 66 | #include "serial_recovery_echo.h" |
Andrzej Puzdrowski | 4f9c730 | 2021-07-16 17:34:43 +0200 | [diff] [blame] | 67 | #include "bootutil/boot_hooks.h" |
Øyvind Rønningstad | f42a820 | 2019-12-13 03:27:54 +0100 | [diff] [blame] | 68 | |
Carlos Falgueras García | a4b4b0f | 2021-06-22 10:00:22 +0200 | [diff] [blame] | 69 | BOOT_LOG_MODULE_DECLARE(mcuboot); |
Emanuele Di Santo | 9f1933d | 2018-11-20 10:59:59 +0100 | [diff] [blame] | 70 | |
Marko Kiiskila | 149b457 | 2018-06-06 14:18:54 +0300 | [diff] [blame] | 71 | #define BOOT_SERIAL_INPUT_MAX 512 |
Andrzej Puzdrowski | c9ac5cc | 2021-11-19 11:58:05 +0100 | [diff] [blame] | 72 | #define BOOT_SERIAL_OUT_MAX (128 * BOOT_IMAGE_NUMBER) |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 73 | |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 74 | #ifdef __ZEPHYR__ |
Carles Cufi | 0165be8 | 2018-03-26 17:43:51 +0200 | [diff] [blame] | 75 | /* base64 lib encodes data to null-terminated string */ |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 76 | #define BASE64_ENCODE_SIZE(in_size) ((((((in_size) - 1) / 3) * 4) + 4) + 1) |
| 77 | |
| 78 | #define CRC16_INITIAL_CRC 0 /* what to seed crc16 with */ |
| 79 | #define CRC_CITT_POLYMINAL 0x1021 |
| 80 | |
| 81 | #define ntohs(x) sys_be16_to_cpu(x) |
| 82 | #define htons(x) sys_cpu_to_be16(x) |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 83 | #endif |
Emanuele Di Santo | 9f1933d | 2018-11-20 10:59:59 +0100 | [diff] [blame] | 84 | |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 85 | #if (BOOT_IMAGE_NUMBER > 1) |
| 86 | #define IMAGES_ITER(x) for ((x) = 0; (x) < BOOT_IMAGE_NUMBER; ++(x)) |
| 87 | #else |
| 88 | #define IMAGES_ITER(x) |
| 89 | #endif |
| 90 | |
Marko Kiiskila | 149b457 | 2018-06-06 14:18:54 +0300 | [diff] [blame] | 91 | static char in_buf[BOOT_SERIAL_INPUT_MAX + 1]; |
| 92 | static char dec_buf[BOOT_SERIAL_INPUT_MAX + 1]; |
Marko Kiiskila | 8b1ce3a | 2018-06-14 13:20:46 -0700 | [diff] [blame] | 93 | const struct boot_uart_funcs *boot_uf; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 94 | static struct nmgr_hdr *bs_hdr; |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 95 | static bool bs_entry; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 96 | |
| 97 | static char bs_obuf[BOOT_SERIAL_OUT_MAX]; |
| 98 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 99 | static void boot_serial_output(void); |
| 100 | |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 101 | static zcbor_state_t cbor_state[2]; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 102 | |
Dominik Ermel | 4c0f6c1 | 2022-03-04 15:47:37 +0000 | [diff] [blame] | 103 | void reset_cbor_state(void) |
| 104 | { |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 105 | zcbor_new_encode_state(cbor_state, 2, (uint8_t *)bs_obuf, |
| 106 | (size_t)bs_obuf + sizeof(bs_obuf), 0); |
Dominik Ermel | 4c0f6c1 | 2022-03-04 15:47:37 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Dominik Ermel | 3d51e43 | 2021-06-25 17:29:50 +0000 | [diff] [blame] | 109 | /** |
Dominik Ermel | bd69c3d | 2021-07-28 11:27:31 +0000 | [diff] [blame] | 110 | * Function that processes MGMT_GROUP_ID_PERUSER mcumgr group and may be |
| 111 | * used to process any groups that have not been processed by generic boot |
| 112 | * serial implementation. |
Dominik Ermel | 3d51e43 | 2021-06-25 17:29:50 +0000 | [diff] [blame] | 113 | * |
| 114 | * @param[in] hdr -- the decoded header of mcumgr message; |
| 115 | * @param[in] buffer -- buffer with first mcumgr message; |
| 116 | * @param[in] len -- length of of data in buffer; |
| 117 | * @param[out] *cs -- object with encoded response. |
| 118 | * |
| 119 | * @return 0 on success; non-0 error code otherwise. |
| 120 | */ |
| 121 | extern int bs_peruser_system_specific(const struct nmgr_hdr *hdr, |
| 122 | const char *buffer, |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 123 | int len, zcbor_state_t *cs); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 124 | |
Dominik Ermel | d49cfc1 | 2022-06-09 08:24:48 +0000 | [diff] [blame] | 125 | #define zcbor_tstr_put_lit_cast(state, string) \ |
| 126 | zcbor_tstr_encode_ptr(state, (uint8_t *)string, sizeof(string) - 1) |
| 127 | |
| 128 | #ifndef MCUBOOT_USE_SNPRINTF |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 129 | /* |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 130 | * Convert version into string without use of snprintf(). |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 131 | */ |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 132 | static int |
| 133 | u32toa(char *tgt, uint32_t val) |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 134 | { |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 135 | char *dst; |
| 136 | uint32_t d = 1; |
| 137 | uint32_t dgt; |
| 138 | int n = 0; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 139 | |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 140 | dst = tgt; |
| 141 | while (val / d >= 10) { |
| 142 | d *= 10; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 143 | } |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 144 | while (d) { |
| 145 | dgt = val / d; |
| 146 | val %= d; |
| 147 | d /= 10; |
| 148 | if (n || dgt > 0 || d == 0) { |
| 149 | *dst++ = dgt + '0'; |
| 150 | ++n; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 151 | } |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 152 | } |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 153 | *dst = '\0'; |
| 154 | |
| 155 | return dst - tgt; |
| 156 | } |
| 157 | |
| 158 | /* |
| 159 | * dst has to be able to fit "255.255.65535.4294967295" (25 characters). |
| 160 | */ |
| 161 | static void |
| 162 | bs_list_img_ver(char *dst, int maxlen, struct image_version *ver) |
| 163 | { |
| 164 | int off; |
| 165 | |
| 166 | off = u32toa(dst, ver->iv_major); |
| 167 | dst[off++] = '.'; |
| 168 | off += u32toa(dst + off, ver->iv_minor); |
| 169 | dst[off++] = '.'; |
| 170 | off += u32toa(dst + off, ver->iv_revision); |
| 171 | dst[off++] = '.'; |
| 172 | off += u32toa(dst + off, ver->iv_build_num); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 173 | } |
Dominik Ermel | d49cfc1 | 2022-06-09 08:24:48 +0000 | [diff] [blame] | 174 | #else |
| 175 | /* |
| 176 | * dst has to be able to fit "255.255.65535.4294967295" (25 characters). |
| 177 | */ |
| 178 | static void |
| 179 | bs_list_img_ver(char *dst, int maxlen, struct image_version *ver) |
| 180 | { |
| 181 | snprintf(dst, maxlen, "%hu.%hu.%hu.%u", (uint16_t)ver->iv_major, |
| 182 | (uint16_t)ver->iv_minor, ver->iv_revision, ver->iv_build_num); |
| 183 | } |
| 184 | #endif /* !MCUBOOT_USE_SNPRINTF */ |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 185 | |
| 186 | /* |
| 187 | * List images. |
| 188 | */ |
| 189 | static void |
| 190 | bs_list(char *buf, int len) |
| 191 | { |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 192 | struct image_header hdr; |
| 193 | uint8_t tmpbuf[64]; |
Øyvind Rønningstad | 9f4aefd | 2021-03-08 21:11:25 +0100 | [diff] [blame] | 194 | uint32_t slot, area_id; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 195 | const struct flash_area *fap; |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 196 | uint8_t image_index; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 197 | |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 198 | zcbor_map_start_encode(cbor_state, 1); |
| 199 | zcbor_tstr_put_lit_cast(cbor_state, "images"); |
| 200 | zcbor_list_start_encode(cbor_state, 5); |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 201 | image_index = 0; |
| 202 | IMAGES_ITER(image_index) { |
| 203 | for (slot = 0; slot < 2; slot++) { |
| 204 | area_id = flash_area_id_from_multi_image_slot(image_index, slot); |
| 205 | if (flash_area_open(area_id, &fap)) { |
| 206 | continue; |
| 207 | } |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 208 | |
Andrzej Puzdrowski | 4f9c730 | 2021-07-16 17:34:43 +0200 | [diff] [blame] | 209 | int rc = BOOT_HOOK_CALL(boot_read_image_header_hook, |
| 210 | BOOT_HOOK_REGULAR, image_index, slot, &hdr); |
| 211 | if (rc == BOOT_HOOK_REGULAR) |
| 212 | { |
| 213 | flash_area_read(fap, 0, &hdr, sizeof(hdr)); |
| 214 | } |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 215 | |
Andrzej Puzdrowski | 4f9c730 | 2021-07-16 17:34:43 +0200 | [diff] [blame] | 216 | fih_int fih_rc = FIH_FAILURE; |
| 217 | |
| 218 | if (hdr.ih_magic == IMAGE_MAGIC) |
| 219 | { |
| 220 | BOOT_HOOK_CALL_FIH(boot_image_check_hook, |
| 221 | fih_int_encode(BOOT_HOOK_REGULAR), |
| 222 | fih_rc, image_index, slot); |
| 223 | if (fih_eq(fih_rc, BOOT_HOOK_REGULAR)) |
| 224 | { |
Wouter Cappelle | 953a761 | 2021-05-03 16:53:05 +0200 | [diff] [blame] | 225 | #ifdef MCUBOOT_ENC_IMAGES |
| 226 | if (slot == 0 && IS_ENCRYPTED(&hdr)) { |
| 227 | /* Clear the encrypted flag we didn't supply a key |
| 228 | * This flag could be set if there was a decryption in place |
| 229 | * performed before. We will try to validate the image without |
| 230 | * decryption by clearing the flag in the heder. If |
| 231 | * still encrypted the validation will fail. |
| 232 | */ |
| 233 | hdr.ih_flags &= ~(ENCRYPTIONFLAGS); |
| 234 | } |
| 235 | #endif |
Andrzej Puzdrowski | 4f9c730 | 2021-07-16 17:34:43 +0200 | [diff] [blame] | 236 | FIH_CALL(bootutil_img_validate, fih_rc, NULL, 0, &hdr, fap, tmpbuf, sizeof(tmpbuf), |
| 237 | NULL, 0, NULL); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | flash_area_close(fap); |
| 242 | |
| 243 | if (fih_not_eq(fih_rc, FIH_SUCCESS)) { |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 244 | continue; |
| 245 | } |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 246 | |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 247 | zcbor_map_start_encode(cbor_state, 20); |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 248 | |
| 249 | #if (BOOT_IMAGE_NUMBER > 1) |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 250 | zcbor_tstr_put_lit_cast(cbor_state, "image"); |
| 251 | zcbor_uint32_put(cbor_state, image_index); |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 252 | #endif |
| 253 | |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 254 | zcbor_tstr_put_lit_cast(cbor_state, "slot"); |
| 255 | zcbor_uint32_put(cbor_state, slot); |
| 256 | zcbor_tstr_put_lit_cast(cbor_state, "version"); |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 257 | |
| 258 | bs_list_img_ver((char *)tmpbuf, sizeof(tmpbuf), &hdr.ih_ver); |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 259 | zcbor_tstr_encode_ptr(cbor_state, tmpbuf, strlen((char *)tmpbuf)); |
| 260 | zcbor_map_end_encode(cbor_state, 20); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 261 | } |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 262 | } |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 263 | zcbor_list_end_encode(cbor_state, 5); |
| 264 | zcbor_map_end_encode(cbor_state, 1); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 265 | boot_serial_output(); |
| 266 | } |
| 267 | |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 268 | #ifdef MCUBOOT_ERASE_PROGRESSIVELY |
| 269 | |
| 270 | /** Erases range of flash, aligned to sector size |
| 271 | * |
| 272 | * Function will erase all sectors withing [start, end] range; it does not check |
| 273 | * the @p start for alignment, and it will use @p end to find boundaries of las |
| 274 | * sector to erase. Function returns offset of the first byte past the last |
| 275 | * erased sector, so basically offset of next sector to be erased if needed. |
| 276 | * The function is intended to be called iteratively with previously returned |
| 277 | * offset as @p start. |
| 278 | * |
| 279 | * @param start starting offset, aligned to sector offset; |
| 280 | * @param end ending offset, maybe anywhere within sector; |
| 281 | * |
| 282 | * @retval On success: offset of the first byte past last erased sector; |
| 283 | * On failure: -EINVAL. |
| 284 | */ |
| 285 | static off_t erase_range(const struct flash_area *fap, off_t start, off_t end) |
| 286 | { |
| 287 | struct flash_sector sect; |
| 288 | size_t size; |
| 289 | int rc; |
| 290 | |
| 291 | if (end >= flash_area_get_size(fap)) { |
| 292 | return -EINVAL; |
| 293 | } |
| 294 | |
| 295 | if (end < start) { |
| 296 | return start; |
| 297 | } |
| 298 | |
| 299 | if (flash_area_sector_from_off(end, §)) { |
| 300 | return -EINVAL; |
| 301 | } |
| 302 | |
| 303 | size = flash_sector_get_off(§) + flash_sector_get_size(§) - start; |
| 304 | BOOT_LOG_INF("Erasing range 0x%x:0x%x", start, start + size - 1); |
| 305 | |
| 306 | rc = flash_area_erase(fap, start, size); |
| 307 | if (rc != 0) { |
| 308 | BOOT_LOG_ERR("Error %d while erasing range", rc); |
| 309 | return -EINVAL; |
| 310 | } |
| 311 | |
| 312 | return start + size; |
| 313 | } |
| 314 | #endif |
| 315 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 316 | /* |
| 317 | * Image upload request. |
| 318 | */ |
| 319 | static void |
| 320 | bs_upload(char *buf, int len) |
| 321 | { |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 322 | static size_t img_size; /* Total image size, held for duration of upload */ |
| 323 | static uint32_t curr_off; /* Expected current offset */ |
| 324 | const uint8_t *img_chunk = NULL; /* Pointer to buffer with received image chunk */ |
| 325 | size_t img_chunk_len = 0; /* Length of received image chunk */ |
| 326 | size_t img_chunk_off = SIZE_MAX; /* Offset of image chunk within image */ |
| 327 | uint8_t rem_bytes; /* Reminder bytes after aligning chunk write to |
| 328 | * to flash alignment */ |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 329 | int img_num; |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 330 | size_t img_size_tmp = SIZE_MAX; /* Temp variable for image size */ |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 331 | const struct flash_area *fap = NULL; |
| 332 | int rc; |
Dominik Ermel | 3d4e55d | 2021-07-09 11:14:10 +0000 | [diff] [blame] | 333 | #ifdef MCUBOOT_ERASE_PROGRESSIVELY |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 334 | static off_t not_yet_erased = 0; /* Offset of next byte to erase; writes to flash |
| 335 | * are done in consecutive manner and erases are done |
| 336 | * to allow currently received chunk to be written; |
| 337 | * this state variable holds information where last |
| 338 | * erase has stopped to let us know whether erase |
| 339 | * is needed to be able to write current chunk. |
| 340 | */ |
| 341 | static struct flash_sector status_sector; |
Emanuele Di Santo | 205c8c6 | 2018-07-20 11:42:31 +0200 | [diff] [blame] | 342 | #endif |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 343 | |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 344 | img_num = 0; |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 345 | |
| 346 | /* |
| 347 | * Expected data format. |
| 348 | * { |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 349 | * "image":<image number in a multi-image set (OPTIONAL)> |
| 350 | * "data":<image data> |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 351 | * "len":<image len> |
| 352 | * "off":<current offset of image data> |
| 353 | * } |
| 354 | */ |
| 355 | |
Øyvind Rønningstad | 212a35b | 2021-05-07 21:06:48 +0200 | [diff] [blame] | 356 | struct Upload upload; |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 357 | size_t decoded_len; |
| 358 | uint_fast8_t result = cbor_decode_Upload((const uint8_t *)buf, len, &upload, &decoded_len); |
Øyvind Rønningstad | 212a35b | 2021-05-07 21:06:48 +0200 | [diff] [blame] | 359 | |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 360 | if ((result != ZCBOR_SUCCESS) || (len != decoded_len)) { |
Øyvind Rønningstad | f42a820 | 2019-12-13 03:27:54 +0100 | [diff] [blame] | 361 | goto out_invalid_data; |
| 362 | } |
Dominik Ermel | 470e2f3 | 2020-01-10 13:28:48 +0000 | [diff] [blame] | 363 | |
Øyvind Rønningstad | f42a820 | 2019-12-13 03:27:54 +0100 | [diff] [blame] | 364 | for (int i = 0; i < upload._Upload_members_count; i++) { |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 365 | struct Member_ *member = &upload._Upload_members[i]._Upload_members; |
Øyvind Rønningstad | f42a820 | 2019-12-13 03:27:54 +0100 | [diff] [blame] | 366 | switch(member->_Member_choice) { |
| 367 | case _Member_image: |
| 368 | img_num = member->_Member_image; |
| 369 | break; |
| 370 | case _Member_data: |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 371 | img_chunk = member->_Member_data.value; |
| 372 | img_chunk_len = member->_Member_data.len; |
Øyvind Rønningstad | f42a820 | 2019-12-13 03:27:54 +0100 | [diff] [blame] | 373 | break; |
| 374 | case _Member_len: |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 375 | img_size_tmp = member->_Member_len; |
Øyvind Rønningstad | f42a820 | 2019-12-13 03:27:54 +0100 | [diff] [blame] | 376 | break; |
| 377 | case _Member_off: |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 378 | img_chunk_off = member->_Member_off; |
Øyvind Rønningstad | f42a820 | 2019-12-13 03:27:54 +0100 | [diff] [blame] | 379 | break; |
| 380 | case _Member_sha: |
| 381 | default: |
| 382 | /* Nothing to do. */ |
| 383 | break; |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 384 | } |
| 385 | } |
Øyvind Rønningstad | f42a820 | 2019-12-13 03:27:54 +0100 | [diff] [blame] | 386 | |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 387 | if (img_chunk_off == SIZE_MAX || img_chunk == NULL) { |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 388 | /* |
| 389 | * Offset must be set in every block. |
| 390 | */ |
| 391 | goto out_invalid_data; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Dominik Ermel | 48decca | 2021-07-09 10:23:58 +0000 | [diff] [blame] | 394 | #if !defined(MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD) |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 395 | rc = flash_area_open(flash_area_id_from_multi_image_slot(img_num, 0), &fap); |
Dominik Ermel | 48decca | 2021-07-09 10:23:58 +0000 | [diff] [blame] | 396 | #else |
| 397 | rc = flash_area_open(flash_area_id_from_direct_image(img_num), &fap); |
| 398 | #endif |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 399 | if (rc) { |
| 400 | rc = MGMT_ERR_EINVAL; |
| 401 | goto out; |
| 402 | } |
| 403 | |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 404 | if (img_chunk_off == 0) { |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 405 | /* Receiving chunk with 0 offset resets the upload state; this basically |
| 406 | * means that upload has started from beginning. |
| 407 | */ |
| 408 | const size_t area_size = flash_area_get_size(fap); |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 409 | |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 410 | curr_off = 0; |
| 411 | #ifdef MCUBOOT_ERASE_PROGRESSIVELY |
| 412 | /* Get trailer sector information; this is done early because inability to get |
| 413 | * that sector information means that upload will not work anyway. |
| 414 | * TODO: This is single occurrence issue, it should get detected during tests |
| 415 | * and fixed otherwise you are deploying broken mcuboot. |
| 416 | */ |
| 417 | if (flash_area_sector_from_off(boot_status_off(fap), &status_sector)) { |
| 418 | rc = MGMT_ERR_EUNKNOWN; |
| 419 | BOOT_LOG_ERR("Unable to determine flash sector of the image trailer"); |
| 420 | goto out; |
| 421 | } |
| 422 | #endif |
| 423 | |
| 424 | |
Wouter Cappelle | bb7a39d | 2021-05-03 16:44:44 +0200 | [diff] [blame] | 425 | #if defined(MCUBOOT_VALIDATE_PRIMARY_SLOT_ONCE) |
| 426 | /* We are using swap state at end of flash area to store validation |
| 427 | * result. Make sure the user cannot write it from an image to skip validation. |
| 428 | */ |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 429 | if (img_size_tmp > (area_size - BOOT_MAGIC_SZ)) { |
Wouter Cappelle | bb7a39d | 2021-05-03 16:44:44 +0200 | [diff] [blame] | 430 | goto out_invalid_data; |
| 431 | } |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 432 | #else |
| 433 | if (img_size_tmp > area_size) { |
| 434 | goto out_invalid_data; |
| 435 | } |
| 436 | |
Wouter Cappelle | bb7a39d | 2021-05-03 16:44:44 +0200 | [diff] [blame] | 437 | #endif |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 438 | |
Dominik Ermel | 3d4e55d | 2021-07-09 11:14:10 +0000 | [diff] [blame] | 439 | #ifndef MCUBOOT_ERASE_PROGRESSIVELY |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 440 | /* Non-progressive erase erases entire image slot when first chunk of |
| 441 | * an image is received. |
| 442 | */ |
| 443 | rc = flash_area_erase(fap, 0, area_size); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 444 | if (rc) { |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 445 | goto out_invalid_data; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 446 | } |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 447 | #else |
| 448 | not_yet_erased = 0; |
Emanuele Di Santo | 205c8c6 | 2018-07-20 11:42:31 +0200 | [diff] [blame] | 449 | #endif |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 450 | |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 451 | img_size = img_size_tmp; |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 452 | } else if (img_chunk_off != curr_off) { |
| 453 | /* If received chunk offset does not match expected one jump, pretend |
| 454 | * success and jump to out; out will respond to client with success |
| 455 | * and request the expected offset, held by curr_off. |
| 456 | */ |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 457 | rc = 0; |
| 458 | goto out; |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 459 | } else if (curr_off + img_chunk_len > img_size) { |
Andrzej Puzdrowski | f48de7a | 2020-10-19 09:42:02 +0200 | [diff] [blame] | 460 | rc = MGMT_ERR_EINVAL; |
| 461 | goto out; |
| 462 | } |
| 463 | |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 464 | #ifdef MCUBOOT_ERASE_PROGRESSIVELY |
| 465 | /* Progressive erase will erase enough flash, aligned to sector size, |
| 466 | * as needed for the current chunk to be written. |
| 467 | */ |
| 468 | not_yet_erased = erase_range(fap, not_yet_erased, |
| 469 | curr_off + img_chunk_len - 1); |
| 470 | |
| 471 | if (not_yet_erased < 0) { |
| 472 | rc = MGMT_ERR_EINVAL; |
| 473 | goto out; |
| 474 | } |
| 475 | #endif |
| 476 | |
| 477 | /* Writes are aligned to flash write alignment, so may drop a few bytes |
| 478 | * from the end of the buffer; we will request these bytes again with |
| 479 | * new buffer by responding with request for offset after the last aligned |
| 480 | * write. |
| 481 | */ |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 482 | rem_bytes = img_chunk_len % flash_area_align(fap); |
Andrzej Puzdrowski | f48de7a | 2020-10-19 09:42:02 +0200 | [diff] [blame] | 483 | |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 484 | if ((curr_off + img_chunk_len < img_size) && rem_bytes) { |
| 485 | img_chunk_len -= rem_bytes; |
Andrzej Puzdrowski | f48de7a | 2020-10-19 09:42:02 +0200 | [diff] [blame] | 486 | rem_bytes = 0; |
Fabio Utzig | 30f6b2a | 2018-03-29 16:18:53 -0300 | [diff] [blame] | 487 | } |
Emanuele Di Santo | 205c8c6 | 2018-07-20 11:42:31 +0200 | [diff] [blame] | 488 | |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 489 | BOOT_LOG_INF("Writing at 0x%x until 0x%x", curr_off, curr_off + img_chunk_len); |
Andrzej Puzdrowski | f48de7a | 2020-10-19 09:42:02 +0200 | [diff] [blame] | 490 | if (rem_bytes) { |
| 491 | /* the last chunk of the image might be unaligned */ |
| 492 | uint8_t wbs_aligned[BOOT_MAX_ALIGN]; |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 493 | size_t w_size = img_chunk_len - rem_bytes; |
Andrzej Puzdrowski | f48de7a | 2020-10-19 09:42:02 +0200 | [diff] [blame] | 494 | |
| 495 | if (w_size) { |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 496 | rc = flash_area_write(fap, curr_off, img_chunk, w_size); |
Andrzej Puzdrowski | f48de7a | 2020-10-19 09:42:02 +0200 | [diff] [blame] | 497 | if (rc) { |
| 498 | goto out_invalid_data; |
| 499 | } |
| 500 | curr_off += w_size; |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 501 | img_chunk_len -= w_size; |
| 502 | img_chunk += w_size; |
Andrzej Puzdrowski | f48de7a | 2020-10-19 09:42:02 +0200 | [diff] [blame] | 503 | } |
| 504 | |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 505 | if (img_chunk_len) { |
| 506 | memcpy(wbs_aligned, img_chunk, rem_bytes); |
Andrzej Puzdrowski | f48de7a | 2020-10-19 09:42:02 +0200 | [diff] [blame] | 507 | memset(wbs_aligned + rem_bytes, flash_area_erased_val(fap), |
| 508 | sizeof(wbs_aligned) - rem_bytes); |
| 509 | rc = flash_area_write(fap, curr_off, wbs_aligned, flash_area_align(fap)); |
| 510 | } |
Andrzej Puzdrowski | f48de7a | 2020-10-19 09:42:02 +0200 | [diff] [blame] | 511 | } else { |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 512 | rc = flash_area_write(fap, curr_off, img_chunk, img_chunk_len); |
Andrzej Puzdrowski | f48de7a | 2020-10-19 09:42:02 +0200 | [diff] [blame] | 513 | } |
| 514 | |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 515 | if (rc == 0) { |
Dominik Ermel | 5bd8744 | 2022-06-13 15:14:01 +0000 | [diff] [blame] | 516 | curr_off += img_chunk_len; |
Andrzej Puzdrowski | c2e30cf | 2018-07-20 16:19:09 +0200 | [diff] [blame] | 517 | if (curr_off == img_size) { |
Andrzej Puzdrowski | 4f9c730 | 2021-07-16 17:34:43 +0200 | [diff] [blame] | 518 | #ifdef MCUBOOT_ERASE_PROGRESSIVELY |
Andrzej Puzdrowski | c2e30cf | 2018-07-20 16:19:09 +0200 | [diff] [blame] | 519 | /* Assure that sector for image trailer was erased. */ |
| 520 | /* Check whether it was erased during previous upload. */ |
Dominik Ermel | bcc17b4 | 2022-06-15 15:33:04 +0000 | [diff] [blame^] | 521 | off_t start = flash_sector_get_off(&status_sector); |
| 522 | |
| 523 | if (erase_range(fap, start, start) < 0) { |
| 524 | rc = MGMT_ERR_EUNKNOWN; |
| 525 | goto out; |
Andrzej Puzdrowski | c2e30cf | 2018-07-20 16:19:09 +0200 | [diff] [blame] | 526 | } |
Andrzej Puzdrowski | c2e30cf | 2018-07-20 16:19:09 +0200 | [diff] [blame] | 527 | #endif |
Andrzej Puzdrowski | 4f9c730 | 2021-07-16 17:34:43 +0200 | [diff] [blame] | 528 | rc = BOOT_HOOK_CALL(boot_serial_uploaded_hook, 0, img_num, fap, |
| 529 | img_size); |
| 530 | if (rc) { |
| 531 | BOOT_LOG_ERR("Error %d post upload hook", rc); |
| 532 | goto out; |
| 533 | } |
| 534 | } |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 535 | } else { |
| 536 | out_invalid_data: |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 537 | rc = MGMT_ERR_EINVAL; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 538 | } |
Emanuele Di Santo | 205c8c6 | 2018-07-20 11:42:31 +0200 | [diff] [blame] | 539 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 540 | out: |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 541 | BOOT_LOG_INF("RX: 0x%x", rc); |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 542 | zcbor_map_start_encode(cbor_state, 10); |
| 543 | zcbor_tstr_put_lit_cast(cbor_state, "rc"); |
| 544 | zcbor_uint32_put(cbor_state, rc); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 545 | if (rc == 0) { |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 546 | zcbor_tstr_put_lit_cast(cbor_state, "off"); |
| 547 | zcbor_uint32_put(cbor_state, curr_off); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 548 | } |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 549 | zcbor_map_end_encode(cbor_state, 10); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 550 | |
| 551 | boot_serial_output(); |
| 552 | flash_area_close(fap); |
Wouter Cappelle | 953a761 | 2021-05-03 16:53:05 +0200 | [diff] [blame] | 553 | |
| 554 | #ifdef MCUBOOT_ENC_IMAGES |
| 555 | if (curr_off == img_size) { |
| 556 | /* Last sector received, now start a decryption on the image if it is encrypted*/ |
| 557 | rc = boot_handle_enc_fw(); |
| 558 | } |
| 559 | #endif //#ifdef MCUBOOT_ENC_IMAGES |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Dominik Ermel | 4c0f6c1 | 2022-03-04 15:47:37 +0000 | [diff] [blame] | 562 | /* |
| 563 | * Send rc code only. |
| 564 | */ |
| 565 | static void |
| 566 | bs_rc_rsp(int rc_code) |
| 567 | { |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 568 | zcbor_map_start_encode(cbor_state, 10); |
| 569 | zcbor_tstr_put_lit_cast(cbor_state, "rc"); |
| 570 | zcbor_uint32_put(cbor_state, rc_code); |
| 571 | zcbor_map_end_encode(cbor_state, 10); |
Dominik Ermel | 4c0f6c1 | 2022-03-04 15:47:37 +0000 | [diff] [blame] | 572 | boot_serial_output(); |
| 573 | } |
| 574 | |
| 575 | |
Wouter Cappelle | e3ff175 | 2021-05-03 16:36:22 +0200 | [diff] [blame] | 576 | #ifdef MCUBOOT_BOOT_MGMT_ECHO |
Wouter Cappelle | e3ff175 | 2021-05-03 16:36:22 +0200 | [diff] [blame] | 577 | static void |
| 578 | bs_echo(char *buf, int len) |
| 579 | { |
Dominik Ermel | 88bd567 | 2022-06-07 15:17:06 +0000 | [diff] [blame] | 580 | struct Echo echo = { 0 }; |
| 581 | size_t decoded_len; |
| 582 | uint32_t rc = MGMT_ERR_EINVAL; |
| 583 | uint_fast8_t result = cbor_decode_Echo((const uint8_t *)buf, len, &echo, &decoded_len); |
Wouter Cappelle | e3ff175 | 2021-05-03 16:36:22 +0200 | [diff] [blame] | 584 | |
Dominik Ermel | 88bd567 | 2022-06-07 15:17:06 +0000 | [diff] [blame] | 585 | if ((result != ZCBOR_SUCCESS) || (len != decoded_len)) { |
| 586 | goto out; |
Wouter Cappelle | e3ff175 | 2021-05-03 16:36:22 +0200 | [diff] [blame] | 587 | } |
Dominik Ermel | 88bd567 | 2022-06-07 15:17:06 +0000 | [diff] [blame] | 588 | |
| 589 | if (echo._Echo_d.value == NULL) { |
| 590 | goto out; |
| 591 | } |
| 592 | |
| 593 | zcbor_map_start_encode(cbor_state, 10); |
| 594 | zcbor_tstr_put_term(cbor_state, "r"); |
| 595 | if (zcbor_tstr_encode(cbor_state, &echo._Echo_d) && zcbor_map_end_encode(cbor_state, 10)) { |
| 596 | boot_serial_output(); |
| 597 | return; |
| 598 | } else { |
| 599 | rc = MGMT_ERR_ENOMEM; |
| 600 | } |
| 601 | |
| 602 | out: |
| 603 | reset_cbor_state(); |
| 604 | bs_rc_rsp(rc); |
Wouter Cappelle | e3ff175 | 2021-05-03 16:36:22 +0200 | [diff] [blame] | 605 | } |
| 606 | #endif |
| 607 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 608 | /* |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 609 | * Reset, and (presumably) boot to newly uploaded image. Flush console |
| 610 | * before restarting. |
| 611 | */ |
Andrzej Puzdrowski | 268cdd0 | 2018-04-10 12:57:54 +0200 | [diff] [blame] | 612 | static void |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 613 | bs_reset(char *buf, int len) |
| 614 | { |
Dominik Ermel | c9dc224 | 2021-07-28 17:08:23 +0000 | [diff] [blame] | 615 | bs_rc_rsp(0); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 616 | |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 617 | #ifdef __ZEPHYR__ |
Andrzej Puzdrowski | 0cf0dbd | 2021-05-14 11:55:57 +0200 | [diff] [blame] | 618 | #ifdef CONFIG_MULTITHREADING |
Carles Cufi | 7e7b4ad | 2020-03-30 19:12:02 +0200 | [diff] [blame] | 619 | k_sleep(K_MSEC(250)); |
Andrzej Puzdrowski | 0cf0dbd | 2021-05-14 11:55:57 +0200 | [diff] [blame] | 620 | #else |
| 621 | k_busy_wait(250000); |
| 622 | #endif |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 623 | sys_reboot(SYS_REBOOT_COLD); |
| 624 | #else |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 625 | os_cputime_delay_usecs(250000); |
| 626 | hal_system_reset(); |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 627 | #endif |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /* |
| 631 | * Parse incoming line of input from console. |
| 632 | * Expect newtmgr protocol with serial transport. |
| 633 | */ |
| 634 | void |
| 635 | boot_serial_input(char *buf, int len) |
| 636 | { |
| 637 | struct nmgr_hdr *hdr; |
| 638 | |
| 639 | hdr = (struct nmgr_hdr *)buf; |
| 640 | if (len < sizeof(*hdr) || |
| 641 | (hdr->nh_op != NMGR_OP_READ && hdr->nh_op != NMGR_OP_WRITE) || |
| 642 | (ntohs(hdr->nh_len) < len - sizeof(*hdr))) { |
| 643 | return; |
| 644 | } |
| 645 | bs_hdr = hdr; |
| 646 | hdr->nh_group = ntohs(hdr->nh_group); |
| 647 | |
| 648 | buf += sizeof(*hdr); |
| 649 | len -= sizeof(*hdr); |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 650 | |
Dominik Ermel | 4c0f6c1 | 2022-03-04 15:47:37 +0000 | [diff] [blame] | 651 | reset_cbor_state(); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 652 | |
| 653 | /* |
| 654 | * Limited support for commands. |
| 655 | */ |
| 656 | if (hdr->nh_group == MGMT_GROUP_ID_IMAGE) { |
| 657 | switch (hdr->nh_id) { |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 658 | case IMGMGR_NMGR_ID_STATE: |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 659 | bs_list(buf, len); |
| 660 | break; |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 661 | case IMGMGR_NMGR_ID_UPLOAD: |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 662 | bs_upload(buf, len); |
| 663 | break; |
| 664 | default: |
Dominik Ermel | c9dc224 | 2021-07-28 17:08:23 +0000 | [diff] [blame] | 665 | bs_rc_rsp(MGMT_ERR_ENOTSUP); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 666 | break; |
| 667 | } |
| 668 | } else if (hdr->nh_group == MGMT_GROUP_ID_DEFAULT) { |
| 669 | switch (hdr->nh_id) { |
Wouter Cappelle | e3ff175 | 2021-05-03 16:36:22 +0200 | [diff] [blame] | 670 | case NMGR_ID_ECHO: |
| 671 | #ifdef MCUBOOT_BOOT_MGMT_ECHO |
| 672 | bs_echo(buf, len); |
| 673 | #endif |
| 674 | break; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 675 | case NMGR_ID_CONS_ECHO_CTRL: |
Dominik Ermel | c9dc224 | 2021-07-28 17:08:23 +0000 | [diff] [blame] | 676 | bs_rc_rsp(0); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 677 | break; |
| 678 | case NMGR_ID_RESET: |
| 679 | bs_reset(buf, len); |
| 680 | break; |
| 681 | default: |
Dominik Ermel | c9dc224 | 2021-07-28 17:08:23 +0000 | [diff] [blame] | 682 | bs_rc_rsp(MGMT_ERR_ENOTSUP); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 683 | break; |
| 684 | } |
Dominik Ermel | bd69c3d | 2021-07-28 11:27:31 +0000 | [diff] [blame] | 685 | } else if (MCUBOOT_PERUSER_MGMT_GROUP_ENABLED == 1) { |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 686 | if (bs_peruser_system_specific(hdr, buf, len, cbor_state) == 0) { |
Dominik Ermel | 3d51e43 | 2021-06-25 17:29:50 +0000 | [diff] [blame] | 687 | boot_serial_output(); |
| 688 | } |
Dominik Ermel | c9dc224 | 2021-07-28 17:08:23 +0000 | [diff] [blame] | 689 | } else { |
| 690 | bs_rc_rsp(MGMT_ERR_ENOTSUP); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 691 | } |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 692 | #ifdef MCUBOOT_SERIAL_WAIT_FOR_DFU |
| 693 | bs_entry = true; |
| 694 | #endif |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | static void |
| 698 | boot_serial_output(void) |
| 699 | { |
| 700 | char *data; |
| 701 | int len; |
| 702 | uint16_t crc; |
| 703 | uint16_t totlen; |
| 704 | char pkt_start[2] = { SHELL_NLIP_PKT_START1, SHELL_NLIP_PKT_START2 }; |
Dominik Ermel | 5ff8958 | 2022-03-03 17:09:07 +0000 | [diff] [blame] | 705 | char buf[BOOT_SERIAL_OUT_MAX + sizeof(*bs_hdr) + sizeof(crc) + sizeof(totlen)]; |
| 706 | char encoded_buf[BASE64_ENCODE_SIZE(sizeof(buf))]; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 707 | |
| 708 | data = bs_obuf; |
Øyvind Rønningstad | a7d34ca | 2022-02-28 13:47:57 +0100 | [diff] [blame] | 709 | len = (uint32_t)cbor_state->payload_mut - (uint32_t)bs_obuf; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 710 | |
| 711 | bs_hdr->nh_op++; |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 712 | bs_hdr->nh_flags = 0; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 713 | bs_hdr->nh_len = htons(len); |
| 714 | bs_hdr->nh_group = htons(bs_hdr->nh_group); |
| 715 | |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 716 | #ifdef __ZEPHYR__ |
Carles Cufi | b9192a4 | 2022-02-10 11:41:57 +0100 | [diff] [blame] | 717 | crc = crc16_itu_t(CRC16_INITIAL_CRC, (uint8_t *)bs_hdr, sizeof(*bs_hdr)); |
| 718 | crc = crc16_itu_t(crc, data, len); |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 719 | #else |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 720 | crc = crc16_ccitt(CRC16_INITIAL_CRC, bs_hdr, sizeof(*bs_hdr)); |
| 721 | crc = crc16_ccitt(crc, data, len); |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 722 | #endif |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 723 | crc = htons(crc); |
| 724 | |
Marko Kiiskila | 149b457 | 2018-06-06 14:18:54 +0300 | [diff] [blame] | 725 | boot_uf->write(pkt_start, sizeof(pkt_start)); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 726 | |
| 727 | totlen = len + sizeof(*bs_hdr) + sizeof(crc); |
| 728 | totlen = htons(totlen); |
| 729 | |
| 730 | memcpy(buf, &totlen, sizeof(totlen)); |
| 731 | totlen = sizeof(totlen); |
| 732 | memcpy(&buf[totlen], bs_hdr, sizeof(*bs_hdr)); |
| 733 | totlen += sizeof(*bs_hdr); |
| 734 | memcpy(&buf[totlen], data, len); |
| 735 | totlen += len; |
| 736 | memcpy(&buf[totlen], &crc, sizeof(crc)); |
| 737 | totlen += sizeof(crc); |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 738 | #ifdef __ZEPHYR__ |
| 739 | size_t enc_len; |
Carles Cufi | 0165be8 | 2018-03-26 17:43:51 +0200 | [diff] [blame] | 740 | base64_encode(encoded_buf, sizeof(encoded_buf), &enc_len, buf, totlen); |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 741 | totlen = enc_len; |
| 742 | #else |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 743 | totlen = base64_encode(buf, totlen, encoded_buf, 1); |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 744 | #endif |
Marko Kiiskila | 149b457 | 2018-06-06 14:18:54 +0300 | [diff] [blame] | 745 | boot_uf->write(encoded_buf, totlen); |
Dominik Ermel | 2f2b31c | 2022-03-03 12:39:27 +0000 | [diff] [blame] | 746 | boot_uf->write("\n", 1); |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 747 | BOOT_LOG_INF("TX"); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /* |
| 751 | * Returns 1 if full packet has been received. |
| 752 | */ |
| 753 | static int |
| 754 | boot_serial_in_dec(char *in, int inlen, char *out, int *out_off, int maxout) |
| 755 | { |
| 756 | int rc; |
| 757 | uint16_t crc; |
| 758 | uint16_t len; |
Marko Kiiskila | e5aeee4 | 2018-12-21 15:00:16 +0200 | [diff] [blame] | 759 | |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 760 | #ifdef __ZEPHYR__ |
| 761 | int err; |
Andrzej Puzdrowski | ec1e4d1 | 2018-06-18 14:36:14 +0200 | [diff] [blame] | 762 | err = base64_decode( &out[*out_off], maxout - *out_off, &rc, in, inlen - 2); |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 763 | if (err) { |
| 764 | return -1; |
| 765 | } |
| 766 | #else |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 767 | if (*out_off + base64_decode_len(in) >= maxout) { |
| 768 | return -1; |
| 769 | } |
| 770 | rc = base64_decode(in, &out[*out_off]); |
| 771 | if (rc < 0) { |
| 772 | return -1; |
| 773 | } |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 774 | #endif |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 775 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 776 | *out_off += rc; |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 777 | if (*out_off <= sizeof(uint16_t)) { |
| 778 | return 0; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 779 | } |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 780 | |
| 781 | len = ntohs(*(uint16_t *)out); |
| 782 | if (len != *out_off - sizeof(uint16_t)) { |
| 783 | return 0; |
| 784 | } |
| 785 | |
| 786 | if (len > *out_off - sizeof(uint16_t)) { |
| 787 | len = *out_off - sizeof(uint16_t); |
| 788 | } |
| 789 | |
| 790 | out += sizeof(uint16_t); |
| 791 | #ifdef __ZEPHYR__ |
Carles Cufi | b9192a4 | 2022-02-10 11:41:57 +0100 | [diff] [blame] | 792 | crc = crc16_itu_t(CRC16_INITIAL_CRC, out, len); |
Fabio Utzig | 6f49c27 | 2019-08-23 11:42:58 -0300 | [diff] [blame] | 793 | #else |
| 794 | crc = crc16_ccitt(CRC16_INITIAL_CRC, out, len); |
| 795 | #endif |
| 796 | if (crc || len <= sizeof(crc)) { |
| 797 | return 0; |
| 798 | } |
| 799 | *out_off -= sizeof(crc); |
| 800 | out[*out_off] = '\0'; |
| 801 | |
| 802 | return 1; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | /* |
| 806 | * Task which waits reading console, expecting to get image over |
| 807 | * serial port. |
| 808 | */ |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 809 | static void |
| 810 | boot_serial_read_console(const struct boot_uart_funcs *f,int timeout_in_ms) |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 811 | { |
| 812 | int rc; |
| 813 | int off; |
David Brown | 57f0df3 | 2020-05-12 08:39:21 -0600 | [diff] [blame] | 814 | int dec_off = 0; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 815 | int full_line; |
Marko Kiiskila | 149b457 | 2018-06-06 14:18:54 +0300 | [diff] [blame] | 816 | int max_input; |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 817 | int elapsed_in_ms = 0; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 818 | |
Marko Kiiskila | 149b457 | 2018-06-06 14:18:54 +0300 | [diff] [blame] | 819 | boot_uf = f; |
Marko Kiiskila | 149b457 | 2018-06-06 14:18:54 +0300 | [diff] [blame] | 820 | max_input = sizeof(in_buf); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 821 | |
| 822 | off = 0; |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 823 | while (timeout_in_ms > 0 || bs_entry) { |
Andrzej Puzdrowski | aea38eb | 2021-06-11 12:28:59 +0200 | [diff] [blame] | 824 | MCUBOOT_CPU_IDLE(); |
Hein Wessels | 56d28f0 | 2021-11-19 08:42:08 +0100 | [diff] [blame] | 825 | MCUBOOT_WATCHDOG_FEED(); |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 826 | #ifdef MCUBOOT_SERIAL_WAIT_FOR_DFU |
| 827 | uint32_t start = k_uptime_get_32(); |
| 828 | #endif |
Andrzej Puzdrowski | ec1e4d1 | 2018-06-18 14:36:14 +0200 | [diff] [blame] | 829 | rc = f->read(in_buf + off, sizeof(in_buf) - off, &full_line); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 830 | if (rc <= 0 && !full_line) { |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 831 | goto check_timeout; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 832 | } |
| 833 | off += rc; |
| 834 | if (!full_line) { |
Marko Kiiskila | ce50ab0 | 2018-06-06 11:33:33 +0300 | [diff] [blame] | 835 | if (off == max_input) { |
| 836 | /* |
| 837 | * Full line, no newline yet. Reset the input buffer. |
| 838 | */ |
| 839 | off = 0; |
| 840 | } |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 841 | goto check_timeout; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 842 | } |
Andrzej Puzdrowski | ec1e4d1 | 2018-06-18 14:36:14 +0200 | [diff] [blame] | 843 | if (in_buf[0] == SHELL_NLIP_PKT_START1 && |
| 844 | in_buf[1] == SHELL_NLIP_PKT_START2) { |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 845 | dec_off = 0; |
Andrzej Puzdrowski | ec1e4d1 | 2018-06-18 14:36:14 +0200 | [diff] [blame] | 846 | rc = boot_serial_in_dec(&in_buf[2], off - 2, dec_buf, &dec_off, max_input); |
| 847 | } else if (in_buf[0] == SHELL_NLIP_DATA_START1 && |
| 848 | in_buf[1] == SHELL_NLIP_DATA_START2) { |
| 849 | rc = boot_serial_in_dec(&in_buf[2], off - 2, dec_buf, &dec_off, max_input); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 850 | } |
Andrzej Puzdrowski | ec1e4d1 | 2018-06-18 14:36:14 +0200 | [diff] [blame] | 851 | |
| 852 | /* serve errors: out of decode memory, or bad encoding */ |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 853 | if (rc == 1) { |
Andrzej Puzdrowski | ec1e4d1 | 2018-06-18 14:36:14 +0200 | [diff] [blame] | 854 | boot_serial_input(&dec_buf[2], dec_off - 2); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 855 | } |
| 856 | off = 0; |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 857 | check_timeout: |
| 858 | /* Subtract elapsed time */ |
| 859 | #ifdef MCUBOOT_SERIAL_WAIT_FOR_DFU |
| 860 | elapsed_in_ms = (k_uptime_get_32() - start); |
| 861 | #endif |
| 862 | timeout_in_ms -= elapsed_in_ms; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 863 | } |
| 864 | } |
Wouter Cappelle | e3822f8 | 2022-01-19 15:39:43 +0100 | [diff] [blame] | 865 | |
| 866 | /* |
| 867 | * Task which waits reading console, expecting to get image over |
| 868 | * serial port. |
| 869 | */ |
| 870 | void |
| 871 | boot_serial_start(const struct boot_uart_funcs *f) |
| 872 | { |
| 873 | bs_entry = true; |
| 874 | boot_serial_read_console(f,0); |
| 875 | } |
| 876 | |
| 877 | #ifdef MCUBOOT_SERIAL_WAIT_FOR_DFU |
| 878 | /* |
| 879 | * Task which waits reading console for a certain amount of timeout. |
| 880 | * If within this timeout no mcumgr command is received, the function is |
| 881 | * returning, else the serial boot is never exited |
| 882 | */ |
| 883 | void |
| 884 | boot_serial_check_start(const struct boot_uart_funcs *f, int timeout_in_ms) |
| 885 | { |
| 886 | bs_entry = false; |
| 887 | boot_serial_read_console(f,timeout_in_ms); |
| 888 | } |
| 889 | #endif |