Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Marvell International Ltd. |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 4 | * https://spdx.org/licenses |
| 5 | */ |
| 6 | |
| 7 | #include <config.h> |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 10 | #include <env.h> |
Simon Glass | 85f1378 | 2019-12-28 10:45:03 -0700 | [diff] [blame] | 11 | #include <image.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 12 | #include <net.h> |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 13 | #include <vsprintf.h> |
| 14 | #include <errno.h> |
| 15 | #include <dm.h> |
Pali Rohár | d83e04a | 2022-08-23 14:52:24 +0200 | [diff] [blame] | 16 | #include <fuse.h> |
| 17 | #include <mach/efuse.h> |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 18 | |
| 19 | #include <spi_flash.h> |
| 20 | #include <spi.h> |
| 21 | #include <nand.h> |
Pali Rohár | 2a27fc2 | 2023-01-22 01:25:12 +0100 | [diff] [blame] | 22 | #include <scsi.h> |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 23 | #include <usb.h> |
| 24 | #include <fs.h> |
| 25 | #include <mmc.h> |
Konstantin Porotchkin | a89c055 | 2017-01-08 16:52:06 +0200 | [diff] [blame] | 26 | #ifdef CONFIG_BLK |
| 27 | #include <blk.h> |
| 28 | #endif |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 29 | #include <u-boot/sha1.h> |
| 30 | #include <u-boot/sha256.h> |
Pali Rohár | a4bbb2c | 2022-07-26 16:11:58 +0200 | [diff] [blame] | 31 | #include <u-boot/sha512.h> |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 32 | |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 33 | #if defined(CONFIG_ARMADA_8K) |
| 34 | #define MAIN_HDR_MAGIC 0xB105B002 |
| 35 | |
| 36 | struct mvebu_image_header { |
| 37 | u32 magic; /* 0-3 */ |
| 38 | u32 prolog_size; /* 4-7 */ |
| 39 | u32 prolog_checksum; /* 8-11 */ |
| 40 | u32 boot_image_size; /* 12-15 */ |
| 41 | u32 boot_image_checksum; /* 16-19 */ |
| 42 | u32 rsrvd0; /* 20-23 */ |
| 43 | u32 load_addr; /* 24-27 */ |
| 44 | u32 exec_addr; /* 28-31 */ |
| 45 | u8 uart_cfg; /* 32 */ |
| 46 | u8 baudrate; /* 33 */ |
| 47 | u8 ext_count; /* 34 */ |
| 48 | u8 aux_flags; /* 35 */ |
| 49 | u32 io_arg_0; /* 36-39 */ |
| 50 | u32 io_arg_1; /* 40-43 */ |
| 51 | u32 io_arg_2; /* 43-47 */ |
| 52 | u32 io_arg_3; /* 48-51 */ |
| 53 | u32 rsrvd1; /* 52-55 */ |
| 54 | u32 rsrvd2; /* 56-59 */ |
| 55 | u32 rsrvd3; /* 60-63 */ |
| 56 | }; |
| 57 | #elif defined(CONFIG_ARMADA_3700) /* A3700 */ |
| 58 | #define HASH_SUM_LEN 16 |
| 59 | #define IMAGE_VERSION_3_6_0 0x030600 |
| 60 | #define IMAGE_VERSION_3_5_0 0x030500 |
| 61 | |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 62 | struct tim_boot_flash_sign { |
| 63 | unsigned int id; |
| 64 | const char *name; |
| 65 | }; |
| 66 | |
| 67 | struct tim_boot_flash_sign tim_boot_flash_signs[] = { |
| 68 | { 0x454d4d08, "mmc" }, |
| 69 | { 0x454d4d0b, "mmc" }, |
| 70 | { 0x5350490a, "spi" }, |
| 71 | { 0x5350491a, "nand" }, |
| 72 | { 0x55415223, "uart" }, |
| 73 | { 0x53415432, "sata" }, |
| 74 | {}, |
| 75 | }; |
| 76 | |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 77 | struct common_tim_data { |
| 78 | u32 version; |
| 79 | u32 identifier; |
| 80 | u32 trusted; |
| 81 | u32 issue_date; |
| 82 | u32 oem_unique_id; |
| 83 | u32 reserved[5]; /* Reserve 20 bytes */ |
| 84 | u32 boot_flash_sign; |
| 85 | u32 num_images; |
| 86 | u32 num_keys; |
| 87 | u32 size_of_reserved; |
| 88 | }; |
| 89 | |
| 90 | struct mvebu_image_info { |
| 91 | u32 image_id; |
| 92 | u32 next_image_id; |
| 93 | u32 flash_entry_addr; |
| 94 | u32 load_addr; |
| 95 | u32 image_size; |
| 96 | u32 image_size_to_hash; |
| 97 | u32 hash_algorithm_id; |
| 98 | u32 hash[HASH_SUM_LEN]; /* Reserve 512 bits for the hash */ |
| 99 | u32 partition_number; |
| 100 | u32 enc_algorithm_id; |
| 101 | u32 encrypt_start_offset; |
| 102 | u32 encrypt_size; |
| 103 | }; |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 104 | #elif defined(CONFIG_ARMADA_32BIT) |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 105 | |
Pali Rohár | 0f7df22 | 2021-10-22 12:41:10 +0200 | [diff] [blame] | 106 | /* Structure of the main header, version 1 (Armada 370/XP/375/38x/39x) */ |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 107 | struct a38x_main_hdr_v1 { |
| 108 | u8 blockid; /* 0x0 */ |
| 109 | u8 flags; /* 0x1 */ |
Pali Rohár | 7fea884 | 2021-10-22 12:37:48 +0200 | [diff] [blame] | 110 | u16 nandpagesize; /* 0x2-0x3 */ |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 111 | u32 blocksize; /* 0x4-0x7 */ |
| 112 | u8 version; /* 0x8 */ |
| 113 | u8 headersz_msb; /* 0x9 */ |
| 114 | u16 headersz_lsb; /* 0xA-0xB */ |
| 115 | u32 srcaddr; /* 0xC-0xF */ |
| 116 | u32 destaddr; /* 0x10-0x13 */ |
| 117 | u32 execaddr; /* 0x14-0x17 */ |
| 118 | u8 options; /* 0x18 */ |
| 119 | u8 nandblocksize; /* 0x19 */ |
| 120 | u8 nandbadblklocation; /* 0x1A */ |
| 121 | u8 reserved4; /* 0x1B */ |
| 122 | u16 reserved5; /* 0x1C-0x1D */ |
| 123 | u8 ext; /* 0x1E */ |
| 124 | u8 checksum; /* 0x1F */ |
| 125 | }; |
Joel Johnson | ab5dd30 | 2020-04-17 09:38:06 -0600 | [diff] [blame] | 126 | |
Pali Rohár | d83e04a | 2022-08-23 14:52:24 +0200 | [diff] [blame] | 127 | /* |
| 128 | * Header for the optional headers, version 1 (Armada 370/XP/375/38x/39x) |
| 129 | */ |
| 130 | struct a38x_opt_hdr_v1 { |
| 131 | u8 headertype; |
| 132 | u8 headersz_msb; |
| 133 | u16 headersz_lsb; |
| 134 | u8 data[0]; |
| 135 | }; |
| 136 | #define A38X_OPT_HDR_V1_SECURE_TYPE 0x1 |
| 137 | |
Joel Johnson | ab5dd30 | 2020-04-17 09:38:06 -0600 | [diff] [blame] | 138 | struct a38x_boot_mode { |
| 139 | unsigned int id; |
| 140 | const char *name; |
| 141 | }; |
| 142 | |
| 143 | /* The blockid header field values used to indicate boot device of image */ |
| 144 | struct a38x_boot_mode a38x_boot_modes[] = { |
| 145 | { 0x4D, "i2c" }, |
| 146 | { 0x5A, "spi" }, |
| 147 | { 0x69, "uart" }, |
| 148 | { 0x78, "sata" }, |
| 149 | { 0x8B, "nand" }, |
| 150 | { 0x9C, "pex" }, |
| 151 | { 0xAE, "mmc" }, |
| 152 | {}, |
| 153 | }; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 154 | |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 155 | #endif |
| 156 | |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 157 | struct bubt_dev { |
| 158 | char name[8]; |
| 159 | size_t (*read)(const char *file_name); |
| 160 | int (*write)(size_t image_size); |
| 161 | int (*active)(void); |
| 162 | }; |
| 163 | |
| 164 | static ulong get_load_addr(void) |
| 165 | { |
| 166 | const char *addr_str; |
| 167 | unsigned long addr; |
| 168 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 169 | addr_str = env_get("loadaddr"); |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 170 | if (addr_str) |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 171 | addr = hextoul(addr_str, NULL); |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 172 | else |
| 173 | addr = CONFIG_SYS_LOAD_ADDR; |
| 174 | |
| 175 | return addr; |
| 176 | } |
| 177 | |
| 178 | /******************************************************************** |
| 179 | * eMMC services |
| 180 | ********************************************************************/ |
Jean-Jacques Hiblot | d053167 | 2018-01-04 15:23:32 +0100 | [diff] [blame] | 181 | #if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(MMC_WRITE) |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 182 | static int mmc_burn_image(size_t image_size) |
| 183 | { |
| 184 | struct mmc *mmc; |
| 185 | lbaint_t start_lba; |
| 186 | lbaint_t blk_count; |
| 187 | ulong blk_written; |
| 188 | int err; |
| 189 | const u8 mmc_dev_num = CONFIG_SYS_MMC_ENV_DEV; |
Konstantin Porotchkin | a89c055 | 2017-01-08 16:52:06 +0200 | [diff] [blame] | 190 | #ifdef CONFIG_BLK |
| 191 | struct blk_desc *blk_desc; |
| 192 | #endif |
Pali Rohár | e4e6777 | 2023-01-21 22:58:28 +0100 | [diff] [blame] | 193 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
| 194 | u8 part; |
| 195 | u8 orig_part; |
| 196 | #endif |
| 197 | |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 198 | mmc = find_mmc_device(mmc_dev_num); |
| 199 | if (!mmc) { |
| 200 | printf("No SD/MMC/eMMC card found\n"); |
| 201 | return -ENOMEDIUM; |
| 202 | } |
| 203 | |
| 204 | err = mmc_init(mmc); |
| 205 | if (err) { |
| 206 | printf("%s(%d) init failed\n", IS_SD(mmc) ? "SD" : "MMC", |
| 207 | mmc_dev_num); |
| 208 | return err; |
| 209 | } |
Pali Rohár | e4e6777 | 2023-01-21 22:58:28 +0100 | [diff] [blame] | 210 | |
| 211 | #ifdef CONFIG_BLK |
| 212 | blk_desc = mmc_get_blk_desc(mmc); |
| 213 | if (!blk_desc) { |
| 214 | printf("Error - failed to obtain block descriptor\n"); |
| 215 | return -ENODEV; |
| 216 | } |
| 217 | #endif |
| 218 | |
| 219 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
| 220 | #ifdef CONFIG_BLK |
| 221 | orig_part = blk_desc->hwpart; |
| 222 | #else |
| 223 | orig_part = mmc->block_dev.hwpart; |
| 224 | #endif |
| 225 | |
| 226 | part = (mmc->part_config >> 3) & PART_ACCESS_MASK; |
| 227 | |
| 228 | if (part == 7) |
| 229 | part = 0; |
| 230 | |
| 231 | #ifdef CONFIG_BLK |
| 232 | err = blk_dselect_hwpart(blk_desc, part); |
| 233 | #else |
| 234 | err = mmc_switch_part(mmc, part); |
| 235 | #endif |
| 236 | |
| 237 | if (err) { |
| 238 | printf("Error - MMC partition switch failed\n"); |
| 239 | return err; |
| 240 | } |
| 241 | #endif |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 242 | |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 243 | /* SD reserves LBA-0 for MBR and boots from LBA-1, |
| 244 | * MMC/eMMC boots from LBA-0 |
| 245 | */ |
| 246 | start_lba = IS_SD(mmc) ? 1 : 0; |
Konstantin Porotchkin | a89c055 | 2017-01-08 16:52:06 +0200 | [diff] [blame] | 247 | #ifdef CONFIG_BLK |
| 248 | blk_count = image_size / mmc->write_bl_len; |
| 249 | if (image_size % mmc->write_bl_len) |
| 250 | blk_count += 1; |
| 251 | |
Konstantin Porotchkin | a89c055 | 2017-01-08 16:52:06 +0200 | [diff] [blame] | 252 | blk_written = blk_dwrite(blk_desc, start_lba, blk_count, |
| 253 | (void *)get_load_addr()); |
| 254 | #else |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 255 | blk_count = image_size / mmc->block_dev.blksz; |
| 256 | if (image_size % mmc->block_dev.blksz) |
| 257 | blk_count += 1; |
| 258 | |
| 259 | blk_written = mmc->block_dev.block_write(mmc_dev_num, |
Konstantin Porotchkin | a89c055 | 2017-01-08 16:52:06 +0200 | [diff] [blame] | 260 | start_lba, blk_count, |
| 261 | (void *)get_load_addr()); |
| 262 | #endif /* CONFIG_BLK */ |
Pali Rohár | e4e6777 | 2023-01-21 22:58:28 +0100 | [diff] [blame] | 263 | |
| 264 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
| 265 | #ifdef CONFIG_BLK |
| 266 | err = blk_dselect_hwpart(blk_desc, orig_part); |
| 267 | #else |
| 268 | err = mmc_switch_part(mmc, orig_part); |
| 269 | #endif |
| 270 | if (err) |
| 271 | printf("Error - MMC failed to switch back to original partition\n"); |
| 272 | #endif |
| 273 | |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 274 | if (blk_written != blk_count) { |
| 275 | printf("Error - written %#lx blocks\n", blk_written); |
| 276 | return -ENOSPC; |
| 277 | } |
| 278 | printf("Done!\n"); |
| 279 | |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | static size_t mmc_read_file(const char *file_name) |
| 284 | { |
| 285 | loff_t act_read = 0; |
| 286 | int rc; |
| 287 | struct mmc *mmc; |
| 288 | const u8 mmc_dev_num = CONFIG_SYS_MMC_ENV_DEV; |
| 289 | |
| 290 | mmc = find_mmc_device(mmc_dev_num); |
| 291 | if (!mmc) { |
| 292 | printf("No SD/MMC/eMMC card found\n"); |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | if (mmc_init(mmc)) { |
| 297 | printf("%s(%d) init failed\n", IS_SD(mmc) ? "SD" : "MMC", |
| 298 | mmc_dev_num); |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | /* Load from data partition (0) */ |
| 303 | if (fs_set_blk_dev("mmc", "0", FS_TYPE_ANY)) { |
| 304 | printf("Error: MMC 0 not found\n"); |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | /* Perfrom file read */ |
| 309 | rc = fs_read(file_name, get_load_addr(), 0, 0, &act_read); |
| 310 | if (rc) |
| 311 | return 0; |
| 312 | |
| 313 | return act_read; |
| 314 | } |
| 315 | |
| 316 | static int is_mmc_active(void) |
| 317 | { |
| 318 | return 1; |
| 319 | } |
| 320 | #else /* CONFIG_DM_MMC */ |
| 321 | static int mmc_burn_image(size_t image_size) |
| 322 | { |
| 323 | return -ENODEV; |
| 324 | } |
| 325 | |
| 326 | static size_t mmc_read_file(const char *file_name) |
| 327 | { |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static int is_mmc_active(void) |
| 332 | { |
| 333 | return 0; |
| 334 | } |
| 335 | #endif /* CONFIG_DM_MMC */ |
| 336 | |
| 337 | /******************************************************************** |
Pali Rohár | 2a27fc2 | 2023-01-22 01:25:12 +0100 | [diff] [blame] | 338 | * SATA services |
| 339 | ********************************************************************/ |
| 340 | #if defined(CONFIG_SCSI) && defined(CONFIG_BLK) |
| 341 | static int sata_burn_image(size_t image_size) |
| 342 | { |
| 343 | #if defined(CONFIG_ARMADA_3700) || defined(CONFIG_ARMADA_32BIT) |
| 344 | lbaint_t start_lba; |
| 345 | lbaint_t blk_count; |
| 346 | ulong blk_written; |
| 347 | struct blk_desc *blk_desc; |
| 348 | #ifdef CONFIG_ARMADA_3700 |
| 349 | struct disk_partition info; |
| 350 | int part; |
| 351 | #endif |
| 352 | |
| 353 | scsi_scan(false); |
| 354 | |
| 355 | blk_desc = blk_get_devnum_by_uclass_id(UCLASS_SCSI, 0); |
| 356 | if (!blk_desc) |
| 357 | return -ENODEV; |
| 358 | |
| 359 | #ifdef CONFIG_ARMADA_3700 |
| 360 | /* |
| 361 | * 64-bit Armada 3700 BootROM loads SATA firmware from |
| 362 | * GPT 'Marvell Armada 3700 Boot partition' or from |
| 363 | * MBR 'M' (0x4d) partition. |
| 364 | */ |
| 365 | switch (blk_desc->part_type) { |
| 366 | case PART_TYPE_DOS: |
| 367 | for (part = 1; part <= 4; part++) { |
| 368 | info.sys_ind = 0; |
| 369 | if (part_get_info(blk_desc, part, &info)) |
| 370 | continue; |
| 371 | if (info.sys_ind == 'M') |
| 372 | break; |
| 373 | } |
| 374 | if (part > 4) { |
| 375 | printf("Error - cannot find MBR 'M' (0x4d) partition on SATA disk\n"); |
| 376 | return -ENODEV; |
| 377 | } |
| 378 | start_lba = info.start; |
| 379 | break; |
| 380 | case PART_TYPE_EFI: |
| 381 | for (part = 1; part <= 64; part++) { |
| 382 | info.type_guid[0] = 0; |
| 383 | if (part_get_info(blk_desc, part, &info)) |
| 384 | continue; |
| 385 | /* Check for GPT type GUID of 'Marvell Armada 3700 Boot partition' */ |
| 386 | if (strcmp(info.type_guid, "6828311A-BA55-42A4-BCDE-A89BB5EDECAE") == 0) |
| 387 | break; |
| 388 | } |
| 389 | if (part > 64) { |
| 390 | printf("Error - cannot find GPT 'Marvell Armada 3700 Boot partition' on SATA disk\n"); |
| 391 | return -ENODEV; |
| 392 | } |
| 393 | start_lba = info.start; |
| 394 | break; |
| 395 | default: |
| 396 | printf("Error - no partitions on SATA disk\n"); |
| 397 | return -ENODEV; |
| 398 | } |
| 399 | #else |
| 400 | /* 32-bit Armada BootROM loads SATA firmware from the sector 1. */ |
| 401 | start_lba = 1; |
| 402 | #endif |
| 403 | |
| 404 | blk_count = image_size / blk_desc->blksz; |
| 405 | if (image_size % blk_desc->blksz) |
| 406 | blk_count += 1; |
| 407 | |
| 408 | blk_written = blk_dwrite(blk_desc, start_lba, blk_count, |
| 409 | (void *)get_load_addr()); |
| 410 | |
| 411 | if (blk_written != blk_count) { |
| 412 | printf("Error - written %#lx blocks\n", blk_written); |
| 413 | return -ENOSPC; |
| 414 | } |
| 415 | |
| 416 | printf("Done!\n"); |
| 417 | return 0; |
| 418 | #else |
| 419 | return -ENODEV; |
| 420 | #endif |
| 421 | } |
| 422 | |
Pali Rohár | c61feb9 | 2023-01-21 23:29:36 +0100 | [diff] [blame] | 423 | static size_t sata_read_file(const char *file_name) |
| 424 | { |
| 425 | loff_t act_read = 0; |
| 426 | struct udevice *dev; |
| 427 | int rc; |
| 428 | |
| 429 | /* try to recognize storage devices immediately */ |
| 430 | scsi_scan(false); |
| 431 | |
| 432 | /* Try to recognize storage devices immediately */ |
| 433 | blk_first_device(UCLASS_SCSI, &dev); |
| 434 | if (!dev) { |
| 435 | printf("Error: SATA device not found\n"); |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | /* Always load from scsi 0 */ |
| 440 | if (fs_set_blk_dev("scsi", "0", FS_TYPE_ANY)) { |
| 441 | printf("Error: SATA 0 not found\n"); |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | /* Perfrom file read */ |
| 446 | rc = fs_read(file_name, get_load_addr(), 0, 0, &act_read); |
| 447 | if (rc) |
| 448 | return 0; |
| 449 | |
| 450 | return act_read; |
| 451 | } |
| 452 | |
Pali Rohár | 2a27fc2 | 2023-01-22 01:25:12 +0100 | [diff] [blame] | 453 | static int is_sata_active(void) |
| 454 | { |
| 455 | return 1; |
| 456 | } |
| 457 | #else /* CONFIG_SCSI */ |
| 458 | static int sata_burn_image(size_t image_size) |
| 459 | { |
| 460 | return -ENODEV; |
| 461 | } |
| 462 | |
Pali Rohár | c61feb9 | 2023-01-21 23:29:36 +0100 | [diff] [blame] | 463 | static size_t sata_read_file(const char *file_name) |
| 464 | { |
| 465 | return 0; |
| 466 | } |
| 467 | |
Pali Rohár | 2a27fc2 | 2023-01-22 01:25:12 +0100 | [diff] [blame] | 468 | static int is_sata_active(void) |
| 469 | { |
| 470 | return 0; |
| 471 | } |
| 472 | #endif /* CONFIG_SCSI */ |
| 473 | |
| 474 | /******************************************************************** |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 475 | * SPI services |
| 476 | ********************************************************************/ |
| 477 | #ifdef CONFIG_SPI_FLASH |
| 478 | static int spi_burn_image(size_t image_size) |
| 479 | { |
| 480 | int ret; |
| 481 | struct spi_flash *flash; |
| 482 | u32 erase_bytes; |
| 483 | |
| 484 | /* Probe the SPI bus to get the flash device */ |
Tom Rini | 119d2fb | 2021-12-11 14:55:48 -0500 | [diff] [blame] | 485 | flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, |
| 486 | CONFIG_SF_DEFAULT_CS, |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 487 | CONFIG_SF_DEFAULT_SPEED, |
| 488 | CONFIG_SF_DEFAULT_MODE); |
| 489 | if (!flash) { |
| 490 | printf("Failed to probe SPI Flash\n"); |
| 491 | return -ENOMEDIUM; |
| 492 | } |
| 493 | |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 494 | erase_bytes = image_size + |
| 495 | (flash->erase_size - image_size % flash->erase_size); |
| 496 | printf("Erasing %d bytes (%d blocks) at offset 0 ...", |
| 497 | erase_bytes, erase_bytes / flash->erase_size); |
| 498 | ret = spi_flash_erase(flash, 0, erase_bytes); |
| 499 | if (ret) |
| 500 | printf("Error!\n"); |
| 501 | else |
| 502 | printf("Done!\n"); |
| 503 | |
| 504 | printf("Writing %d bytes from 0x%lx to offset 0 ...", |
| 505 | (int)image_size, get_load_addr()); |
| 506 | ret = spi_flash_write(flash, 0, image_size, (void *)get_load_addr()); |
| 507 | if (ret) |
| 508 | printf("Error!\n"); |
| 509 | else |
| 510 | printf("Done!\n"); |
| 511 | |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 512 | return ret; |
| 513 | } |
| 514 | |
| 515 | static int is_spi_active(void) |
| 516 | { |
| 517 | return 1; |
| 518 | } |
| 519 | |
| 520 | #else /* CONFIG_SPI_FLASH */ |
| 521 | static int spi_burn_image(size_t image_size) |
| 522 | { |
| 523 | return -ENODEV; |
| 524 | } |
| 525 | |
| 526 | static int is_spi_active(void) |
| 527 | { |
| 528 | return 0; |
| 529 | } |
| 530 | #endif /* CONFIG_SPI_FLASH */ |
| 531 | |
| 532 | /******************************************************************** |
| 533 | * NAND services |
| 534 | ********************************************************************/ |
| 535 | #ifdef CONFIG_CMD_NAND |
| 536 | static int nand_burn_image(size_t image_size) |
| 537 | { |
Konstantin Porotchkin | c6db27b | 2017-03-28 18:16:56 +0300 | [diff] [blame] | 538 | int ret; |
| 539 | uint32_t block_size; |
Grygorii Strashko | 4a240bc | 2017-06-26 19:13:02 -0500 | [diff] [blame] | 540 | struct mtd_info *mtd; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 541 | |
Grygorii Strashko | 4a240bc | 2017-06-26 19:13:02 -0500 | [diff] [blame] | 542 | mtd = get_nand_dev_by_index(nand_curr_device); |
| 543 | if (!mtd) { |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 544 | puts("\nno devices available\n"); |
| 545 | return -ENOMEDIUM; |
| 546 | } |
Grygorii Strashko | 4a240bc | 2017-06-26 19:13:02 -0500 | [diff] [blame] | 547 | block_size = mtd->erasesize; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 548 | |
| 549 | /* Align U-Boot size to currently used blocksize */ |
| 550 | image_size = ((image_size + (block_size - 1)) & (~(block_size - 1))); |
| 551 | |
Joel Johnson | 22d78e4 | 2020-04-17 09:38:05 -0600 | [diff] [blame] | 552 | /* Erase the U-Boot image space */ |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 553 | printf("Erasing 0x%x - 0x%x:...", 0, (int)image_size); |
Grygorii Strashko | 4a240bc | 2017-06-26 19:13:02 -0500 | [diff] [blame] | 554 | ret = nand_erase(mtd, 0, image_size); |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 555 | if (ret) { |
| 556 | printf("Error!\n"); |
| 557 | goto error; |
| 558 | } |
| 559 | printf("Done!\n"); |
| 560 | |
| 561 | /* Write the image to flash */ |
Konstantin Porotchkin | c6db27b | 2017-03-28 18:16:56 +0300 | [diff] [blame] | 562 | printf("Writing %d bytes from 0x%lx to offset 0 ... ", |
| 563 | (int)image_size, get_load_addr()); |
Grygorii Strashko | 4a240bc | 2017-06-26 19:13:02 -0500 | [diff] [blame] | 564 | ret = nand_write(mtd, 0, &image_size, (void *)get_load_addr()); |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 565 | if (ret) |
| 566 | printf("Error!\n"); |
| 567 | else |
| 568 | printf("Done!\n"); |
| 569 | |
| 570 | error: |
| 571 | return ret; |
| 572 | } |
| 573 | |
| 574 | static int is_nand_active(void) |
| 575 | { |
| 576 | return 1; |
| 577 | } |
| 578 | |
| 579 | #else /* CONFIG_CMD_NAND */ |
| 580 | static int nand_burn_image(size_t image_size) |
| 581 | { |
| 582 | return -ENODEV; |
| 583 | } |
| 584 | |
| 585 | static int is_nand_active(void) |
| 586 | { |
| 587 | return 0; |
| 588 | } |
| 589 | #endif /* CONFIG_CMD_NAND */ |
| 590 | |
| 591 | /******************************************************************** |
| 592 | * USB services |
| 593 | ********************************************************************/ |
| 594 | #if defined(CONFIG_USB_STORAGE) && defined(CONFIG_BLK) |
| 595 | static size_t usb_read_file(const char *file_name) |
| 596 | { |
| 597 | loff_t act_read = 0; |
| 598 | struct udevice *dev; |
| 599 | int rc; |
| 600 | |
| 601 | usb_stop(); |
| 602 | |
| 603 | if (usb_init() < 0) { |
| 604 | printf("Error: usb_init failed\n"); |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | /* Try to recognize storage devices immediately */ |
Simon Glass | dbfa32c | 2022-08-11 19:34:59 -0600 | [diff] [blame] | 609 | blk_first_device(UCLASS_USB, &dev); |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 610 | if (!dev) { |
| 611 | printf("Error: USB storage device not found\n"); |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | /* Always load from usb 0 */ |
| 616 | if (fs_set_blk_dev("usb", "0", FS_TYPE_ANY)) { |
| 617 | printf("Error: USB 0 not found\n"); |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | /* Perfrom file read */ |
| 622 | rc = fs_read(file_name, get_load_addr(), 0, 0, &act_read); |
| 623 | if (rc) |
| 624 | return 0; |
| 625 | |
| 626 | return act_read; |
| 627 | } |
| 628 | |
| 629 | static int is_usb_active(void) |
| 630 | { |
| 631 | return 1; |
| 632 | } |
| 633 | |
| 634 | #else /* defined(CONFIG_USB_STORAGE) && defined (CONFIG_BLK) */ |
| 635 | static size_t usb_read_file(const char *file_name) |
| 636 | { |
| 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | static int is_usb_active(void) |
| 641 | { |
| 642 | return 0; |
| 643 | } |
| 644 | #endif /* defined(CONFIG_USB_STORAGE) && defined (CONFIG_BLK) */ |
| 645 | |
| 646 | /******************************************************************** |
| 647 | * Network services |
| 648 | ********************************************************************/ |
| 649 | #ifdef CONFIG_CMD_NET |
| 650 | static size_t tftp_read_file(const char *file_name) |
| 651 | { |
Pali Rohár | 2c96d02 | 2022-07-26 16:11:57 +0200 | [diff] [blame] | 652 | int ret; |
| 653 | |
Simon Glass | 892265d | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 654 | /* |
| 655 | * update global variable image_load_addr before tftp file from network |
| 656 | */ |
| 657 | image_load_addr = get_load_addr(); |
Pali Rohár | 2c96d02 | 2022-07-26 16:11:57 +0200 | [diff] [blame] | 658 | ret = net_loop(TFTPGET); |
| 659 | return ret > 0 ? ret : 0; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static int is_tftp_active(void) |
| 663 | { |
| 664 | return 1; |
| 665 | } |
| 666 | |
| 667 | #else |
| 668 | static size_t tftp_read_file(const char *file_name) |
| 669 | { |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | static int is_tftp_active(void) |
| 674 | { |
| 675 | return 0; |
| 676 | } |
| 677 | #endif /* CONFIG_CMD_NET */ |
| 678 | |
| 679 | enum bubt_devices { |
| 680 | BUBT_DEV_NET = 0, |
| 681 | BUBT_DEV_USB, |
| 682 | BUBT_DEV_MMC, |
Pali Rohár | 2a27fc2 | 2023-01-22 01:25:12 +0100 | [diff] [blame] | 683 | BUBT_DEV_SATA, |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 684 | BUBT_DEV_SPI, |
| 685 | BUBT_DEV_NAND, |
| 686 | |
| 687 | BUBT_MAX_DEV |
| 688 | }; |
| 689 | |
Pali Rohár | 4b25596 | 2023-01-10 22:47:17 +0100 | [diff] [blame] | 690 | static struct bubt_dev bubt_devs[BUBT_MAX_DEV] = { |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 691 | {"tftp", tftp_read_file, NULL, is_tftp_active}, |
| 692 | {"usb", usb_read_file, NULL, is_usb_active}, |
| 693 | {"mmc", mmc_read_file, mmc_burn_image, is_mmc_active}, |
Pali Rohár | c61feb9 | 2023-01-21 23:29:36 +0100 | [diff] [blame] | 694 | {"sata", sata_read_file, sata_burn_image, is_sata_active}, |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 695 | {"spi", NULL, spi_burn_image, is_spi_active}, |
| 696 | {"nand", NULL, nand_burn_image, is_nand_active}, |
| 697 | }; |
| 698 | |
| 699 | static int bubt_write_file(struct bubt_dev *dst, size_t image_size) |
| 700 | { |
| 701 | if (!dst->write) { |
| 702 | printf("Error: Write not supported on device %s\n", dst->name); |
| 703 | return -ENOTSUPP; |
| 704 | } |
| 705 | |
| 706 | return dst->write(image_size); |
| 707 | } |
| 708 | |
| 709 | #if defined(CONFIG_ARMADA_8K) |
Pali Rohár | 4b25596 | 2023-01-10 22:47:17 +0100 | [diff] [blame] | 710 | static u32 do_checksum32(u32 *start, int32_t len) |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 711 | { |
| 712 | u32 sum = 0; |
| 713 | u32 *startp = start; |
| 714 | |
| 715 | do { |
| 716 | sum += *startp; |
| 717 | startp++; |
| 718 | len -= 4; |
| 719 | } while (len > 0); |
| 720 | |
| 721 | return sum; |
| 722 | } |
| 723 | |
| 724 | static int check_image_header(void) |
| 725 | { |
| 726 | struct mvebu_image_header *hdr = |
| 727 | (struct mvebu_image_header *)get_load_addr(); |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 728 | u32 checksum; |
Pali Rohár | 0cebe10 | 2023-01-29 18:49:04 +0100 | [diff] [blame] | 729 | u32 checksum_ref; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 730 | |
| 731 | /* |
| 732 | * For now compare checksum, and magic. Later we can |
| 733 | * verify more stuff on the header like interface type, etc |
| 734 | */ |
| 735 | if (hdr->magic != MAIN_HDR_MAGIC) { |
| 736 | printf("ERROR: Bad MAGIC 0x%08x != 0x%08x\n", |
| 737 | hdr->magic, MAIN_HDR_MAGIC); |
| 738 | return -ENOEXEC; |
| 739 | } |
| 740 | |
Pali Rohár | 0cebe10 | 2023-01-29 18:49:04 +0100 | [diff] [blame] | 741 | checksum_ref = hdr->prolog_checksum; |
| 742 | checksum = do_checksum32((u32 *)hdr, hdr->prolog_size); |
Pali Rohár | b4a76fd | 2023-01-29 18:38:11 +0100 | [diff] [blame] | 743 | checksum -= hdr->prolog_checksum; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 744 | if (checksum != checksum_ref) { |
Pali Rohár | 0cebe10 | 2023-01-29 18:49:04 +0100 | [diff] [blame] | 745 | printf("Error: Bad Prolog checksum. 0x%x != 0x%x\n", |
| 746 | checksum, checksum_ref); |
| 747 | return -ENOEXEC; |
| 748 | } |
| 749 | |
| 750 | checksum_ref = hdr->boot_image_checksum; |
| 751 | checksum = do_checksum32((u32 *)((u8 *)hdr + hdr->prolog_size), hdr->boot_image_size); |
| 752 | if (checksum != checksum_ref) { |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 753 | printf("Error: Bad Image checksum. 0x%x != 0x%x\n", |
| 754 | checksum, checksum_ref); |
| 755 | return -ENOEXEC; |
| 756 | } |
| 757 | |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 758 | printf("Image checksum...OK!\n"); |
| 759 | |
| 760 | return 0; |
| 761 | } |
| 762 | #elif defined(CONFIG_ARMADA_3700) /* Armada 3700 */ |
| 763 | static int check_image_header(void) |
| 764 | { |
| 765 | struct common_tim_data *hdr = (struct common_tim_data *)get_load_addr(); |
| 766 | int image_num; |
| 767 | u8 hash_160_output[SHA1_SUM_LEN]; |
| 768 | u8 hash_256_output[SHA256_SUM_LEN]; |
Pali Rohár | a4bbb2c | 2022-07-26 16:11:58 +0200 | [diff] [blame] | 769 | u8 hash_512_output[SHA512_SUM_LEN]; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 770 | sha1_context hash1_text; |
| 771 | sha256_context hash256_text; |
Pali Rohár | a4bbb2c | 2022-07-26 16:11:58 +0200 | [diff] [blame] | 772 | sha512_context hash512_text; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 773 | u8 *hash_output; |
| 774 | u32 hash_algorithm_id; |
| 775 | u32 image_size_to_hash; |
| 776 | u32 flash_entry_addr; |
| 777 | u32 *hash_value; |
| 778 | u32 internal_hash[HASH_SUM_LEN]; |
| 779 | const u8 *buff; |
| 780 | u32 num_of_image = hdr->num_images; |
| 781 | u32 version = hdr->version; |
| 782 | u32 trusted = hdr->trusted; |
| 783 | |
| 784 | /* bubt checksum validation only supports nontrusted images */ |
| 785 | if (trusted == 1) { |
| 786 | printf("bypass image validation, "); |
| 787 | printf("only untrusted image is supported now\n"); |
| 788 | return 0; |
| 789 | } |
| 790 | /* only supports image version 3.5 and 3.6 */ |
| 791 | if (version != IMAGE_VERSION_3_5_0 && version != IMAGE_VERSION_3_6_0) { |
| 792 | printf("Error: Unsupported Image version = 0x%08x\n", version); |
| 793 | return -ENOEXEC; |
| 794 | } |
| 795 | /* validate images hash value */ |
| 796 | for (image_num = 0; image_num < num_of_image; image_num++) { |
| 797 | struct mvebu_image_info *info = |
| 798 | (struct mvebu_image_info *)(get_load_addr() + |
| 799 | sizeof(struct common_tim_data) + |
| 800 | image_num * sizeof(struct mvebu_image_info)); |
| 801 | hash_algorithm_id = info->hash_algorithm_id; |
| 802 | image_size_to_hash = info->image_size_to_hash; |
| 803 | flash_entry_addr = info->flash_entry_addr; |
| 804 | hash_value = info->hash; |
| 805 | buff = (const u8 *)(get_load_addr() + flash_entry_addr); |
| 806 | |
| 807 | if (image_num == 0) { |
| 808 | /* |
| 809 | * The first image includes hash values in its content. |
| 810 | * For hash calculation, we need to save the original |
| 811 | * hash values to a local variable that will be |
| 812 | * copied back for comparsion and set all zeros to |
| 813 | * the orignal hash values for calculating new value. |
| 814 | * First image original format : |
| 815 | * x...x (datum1) x...x(orig. hash values) x...x(datum2) |
| 816 | * Replaced first image format : |
| 817 | * x...x (datum1) 0...0(hash values) x...x(datum2) |
| 818 | */ |
| 819 | memcpy(internal_hash, hash_value, |
| 820 | sizeof(internal_hash)); |
| 821 | memset(hash_value, 0, sizeof(internal_hash)); |
| 822 | } |
| 823 | if (image_size_to_hash == 0) { |
| 824 | printf("Warning: Image_%d hash checksum is disabled, ", |
| 825 | image_num); |
| 826 | printf("skip the image validation.\n"); |
| 827 | continue; |
| 828 | } |
| 829 | switch (hash_algorithm_id) { |
| 830 | case SHA1_SUM_LEN: |
| 831 | sha1_starts(&hash1_text); |
| 832 | sha1_update(&hash1_text, buff, image_size_to_hash); |
| 833 | sha1_finish(&hash1_text, hash_160_output); |
| 834 | hash_output = hash_160_output; |
| 835 | break; |
| 836 | case SHA256_SUM_LEN: |
| 837 | sha256_starts(&hash256_text); |
| 838 | sha256_update(&hash256_text, buff, image_size_to_hash); |
| 839 | sha256_finish(&hash256_text, hash_256_output); |
| 840 | hash_output = hash_256_output; |
| 841 | break; |
Pali Rohár | a4bbb2c | 2022-07-26 16:11:58 +0200 | [diff] [blame] | 842 | case SHA512_SUM_LEN: |
| 843 | sha512_starts(&hash512_text); |
| 844 | sha512_update(&hash512_text, buff, image_size_to_hash); |
| 845 | sha512_finish(&hash512_text, hash_512_output); |
| 846 | hash_output = hash_512_output; |
| 847 | break; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 848 | default: |
| 849 | printf("Error: Unsupported hash_algorithm_id = %d\n", |
| 850 | hash_algorithm_id); |
| 851 | return -ENOEXEC; |
| 852 | } |
| 853 | if (image_num == 0) |
| 854 | memcpy(hash_value, internal_hash, |
| 855 | sizeof(internal_hash)); |
| 856 | if (memcmp(hash_value, hash_output, hash_algorithm_id) != 0) { |
| 857 | printf("Error: Image_%d checksum is not correct\n", |
| 858 | image_num); |
| 859 | return -ENOEXEC; |
| 860 | } |
| 861 | } |
| 862 | printf("Image checksum...OK!\n"); |
| 863 | |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 864 | return 0; |
| 865 | } |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 866 | #elif defined(CONFIG_ARMADA_32BIT) |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 867 | static size_t a38x_header_size(const struct a38x_main_hdr_v1 *h) |
| 868 | { |
| 869 | if (h->version == 1) |
| 870 | return (h->headersz_msb << 16) | le16_to_cpu(h->headersz_lsb); |
| 871 | |
| 872 | printf("Error: Invalid A38x image (header version 0x%x unknown)!\n", |
| 873 | h->version); |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 874 | return 0; |
| 875 | } |
| 876 | |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 877 | static uint8_t image_checksum8(const void *start, size_t len) |
| 878 | { |
| 879 | u8 csum = 0; |
| 880 | const u8 *p = start; |
| 881 | |
| 882 | while (len) { |
| 883 | csum += *p; |
| 884 | ++p; |
| 885 | --len; |
| 886 | } |
| 887 | |
| 888 | return csum; |
| 889 | } |
| 890 | |
Pali Rohár | 05781ff | 2022-08-23 14:52:23 +0200 | [diff] [blame] | 891 | static uint32_t image_checksum32(const void *start, size_t len) |
| 892 | { |
| 893 | u32 csum = 0; |
| 894 | const u32 *p = start; |
| 895 | |
| 896 | while (len) { |
| 897 | csum += *p; |
| 898 | ++p; |
| 899 | len -= sizeof(u32); |
| 900 | } |
| 901 | |
| 902 | return csum; |
| 903 | } |
| 904 | |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 905 | static int check_image_header(void) |
| 906 | { |
| 907 | u8 checksum; |
Pali Rohár | 05781ff | 2022-08-23 14:52:23 +0200 | [diff] [blame] | 908 | u32 checksum32, exp_checksum32; |
| 909 | u32 offset, size; |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 910 | const struct a38x_main_hdr_v1 *hdr = |
| 911 | (struct a38x_main_hdr_v1 *)get_load_addr(); |
Pali Rohár | fc2b914 | 2023-01-08 14:31:28 +0100 | [diff] [blame] | 912 | const size_t hdr_size = a38x_header_size(hdr); |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 913 | |
Pali Rohár | fc2b914 | 2023-01-08 14:31:28 +0100 | [diff] [blame] | 914 | if (!hdr_size) |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 915 | return -ENOEXEC; |
| 916 | |
Pali Rohár | fc2b914 | 2023-01-08 14:31:28 +0100 | [diff] [blame] | 917 | checksum = image_checksum8(hdr, hdr_size); |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 918 | checksum -= hdr->checksum; |
| 919 | if (checksum != hdr->checksum) { |
Pali Rohár | 05781ff | 2022-08-23 14:52:23 +0200 | [diff] [blame] | 920 | printf("Error: Bad A38x image header checksum. 0x%x != 0x%x\n", |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 921 | checksum, hdr->checksum); |
| 922 | return -ENOEXEC; |
| 923 | } |
| 924 | |
Pali Rohár | 05781ff | 2022-08-23 14:52:23 +0200 | [diff] [blame] | 925 | offset = le32_to_cpu(hdr->srcaddr); |
| 926 | size = le32_to_cpu(hdr->blocksize); |
| 927 | |
Pali Rohár | 42cc795 | 2023-01-21 13:59:20 +0100 | [diff] [blame] | 928 | if (hdr->blockid == 0x78) /* SATA id */ |
Pali Rohár | 05781ff | 2022-08-23 14:52:23 +0200 | [diff] [blame] | 929 | offset *= 512; |
Pali Rohár | 05781ff | 2022-08-23 14:52:23 +0200 | [diff] [blame] | 930 | |
Pali Rohár | 05781ff | 2022-08-23 14:52:23 +0200 | [diff] [blame] | 931 | if (offset % 4 != 0 || size < 4 || size % 4 != 0) { |
| 932 | printf("Error: Bad A38x image blocksize.\n"); |
| 933 | return -ENOEXEC; |
| 934 | } |
| 935 | |
| 936 | checksum32 = image_checksum32((u8 *)hdr + offset, size - 4); |
| 937 | exp_checksum32 = *(u32 *)((u8 *)hdr + offset + size - 4); |
| 938 | if (checksum32 != exp_checksum32) { |
| 939 | printf("Error: Bad A38x image data checksum. 0x%08x != 0x%08x\n", |
| 940 | checksum32, exp_checksum32); |
| 941 | return -ENOEXEC; |
| 942 | } |
| 943 | |
Joel Johnson | 37b9c12 | 2020-04-17 09:38:04 -0600 | [diff] [blame] | 944 | printf("Image checksum...OK!\n"); |
| 945 | return 0; |
| 946 | } |
Pali Rohár | d83e04a | 2022-08-23 14:52:24 +0200 | [diff] [blame] | 947 | |
| 948 | #if defined(CONFIG_ARMADA_38X) |
| 949 | static int a38x_image_is_secure(const struct a38x_main_hdr_v1 *hdr) |
| 950 | { |
Pali Rohár | fc2b914 | 2023-01-08 14:31:28 +0100 | [diff] [blame] | 951 | const size_t hdr_size = a38x_header_size(hdr); |
Pali Rohár | d83e04a | 2022-08-23 14:52:24 +0200 | [diff] [blame] | 952 | struct a38x_opt_hdr_v1 *ohdr; |
| 953 | u32 ohdr_size; |
| 954 | |
| 955 | if (hdr->version != 1) |
| 956 | return 0; |
| 957 | |
| 958 | if (!hdr->ext) |
| 959 | return 0; |
| 960 | |
| 961 | ohdr = (struct a38x_opt_hdr_v1 *)(hdr + 1); |
| 962 | do { |
| 963 | if (ohdr->headertype == A38X_OPT_HDR_V1_SECURE_TYPE) |
| 964 | return 1; |
| 965 | |
| 966 | ohdr_size = (ohdr->headersz_msb << 16) | le16_to_cpu(ohdr->headersz_lsb); |
| 967 | |
| 968 | if (!*((u8 *)ohdr + ohdr_size - 4)) |
| 969 | break; |
| 970 | |
| 971 | ohdr = (struct a38x_opt_hdr_v1 *)((u8 *)ohdr + ohdr_size); |
Pali Rohár | fc2b914 | 2023-01-08 14:31:28 +0100 | [diff] [blame] | 972 | if ((u8 *)ohdr >= (u8 *)hdr + hdr_size) |
Pali Rohár | d83e04a | 2022-08-23 14:52:24 +0200 | [diff] [blame] | 973 | break; |
| 974 | } while (1); |
| 975 | |
| 976 | return 0; |
| 977 | } |
| 978 | #endif |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 979 | #else /* Not ARMADA? */ |
| 980 | static int check_image_header(void) |
| 981 | { |
| 982 | printf("bubt cmd does not support this SoC device or family!\n"); |
| 983 | return -ENOEXEC; |
| 984 | } |
| 985 | #endif |
| 986 | |
Pali Rohár | 85f2a7c | 2023-02-20 22:42:54 +0100 | [diff] [blame] | 987 | #if defined(CONFIG_ARMADA_3700) || defined(CONFIG_ARMADA_38X) |
Pali Rohár | d83e04a | 2022-08-23 14:52:24 +0200 | [diff] [blame] | 988 | static u64 fuse_read_u64(u32 bank) |
| 989 | { |
| 990 | u32 val[2]; |
| 991 | int ret; |
| 992 | |
| 993 | ret = fuse_read(bank, 0, &val[0]); |
| 994 | if (ret < 0) |
| 995 | return -1; |
| 996 | |
| 997 | ret = fuse_read(bank, 1, &val[1]); |
| 998 | if (ret < 0) |
| 999 | return -1; |
| 1000 | |
| 1001 | return ((u64)val[1] << 32) | val[0]; |
| 1002 | } |
| 1003 | #endif |
| 1004 | |
| 1005 | #if defined(CONFIG_ARMADA_3700) |
| 1006 | static inline u8 maj3(u8 val) |
| 1007 | { |
| 1008 | /* return majority vote of 3 bits */ |
| 1009 | return ((val & 0x7) == 3 || (val & 0x7) > 4) ? 1 : 0; |
| 1010 | } |
| 1011 | #endif |
| 1012 | |
Joel Johnson | ab5dd30 | 2020-04-17 09:38:06 -0600 | [diff] [blame] | 1013 | static int bubt_check_boot_mode(const struct bubt_dev *dst) |
| 1014 | { |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 1015 | #if defined(CONFIG_ARMADA_3700) || defined(CONFIG_ARMADA_32BIT) |
Pali Rohár | 85f2a7c | 2023-02-20 22:42:54 +0100 | [diff] [blame] | 1016 | int mode; |
| 1017 | #if defined(CONFIG_ARMADA_3700) || defined(CONFIG_ARMADA_38X) |
| 1018 | int secure_mode; |
| 1019 | #endif |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 1020 | #if defined(CONFIG_ARMADA_3700) |
| 1021 | const struct tim_boot_flash_sign *boot_modes = tim_boot_flash_signs; |
| 1022 | const struct common_tim_data *hdr = |
| 1023 | (struct common_tim_data *)get_load_addr(); |
| 1024 | u32 id = hdr->boot_flash_sign; |
Pali Rohár | d83e04a | 2022-08-23 14:52:24 +0200 | [diff] [blame] | 1025 | int is_secure = hdr->trusted != 0; |
| 1026 | u64 otp_secure_bits = fuse_read_u64(1); |
| 1027 | int otp_secure_boot = ((maj3(otp_secure_bits >> 0) << 0) | |
| 1028 | (maj3(otp_secure_bits >> 4) << 1)) == 2; |
| 1029 | unsigned int otp_boot_device = (maj3(otp_secure_bits >> 48) << 0) | |
| 1030 | (maj3(otp_secure_bits >> 52) << 1) | |
| 1031 | (maj3(otp_secure_bits >> 56) << 2) | |
| 1032 | (maj3(otp_secure_bits >> 60) << 3); |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 1033 | #elif defined(CONFIG_ARMADA_32BIT) |
| 1034 | const struct a38x_boot_mode *boot_modes = a38x_boot_modes; |
| 1035 | const struct a38x_main_hdr_v1 *hdr = |
| 1036 | (struct a38x_main_hdr_v1 *)get_load_addr(); |
| 1037 | u32 id = hdr->blockid; |
Pali Rohár | d83e04a | 2022-08-23 14:52:24 +0200 | [diff] [blame] | 1038 | #if defined(CONFIG_ARMADA_38X) |
| 1039 | int is_secure = a38x_image_is_secure(hdr); |
| 1040 | u64 otp_secure_bits = fuse_read_u64(EFUSE_LINE_SECURE_BOOT); |
| 1041 | int otp_secure_boot = otp_secure_bits & 0x1; |
| 1042 | unsigned int otp_boot_device = (otp_secure_bits >> 8) & 0x7; |
| 1043 | #endif |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 1044 | #endif |
Joel Johnson | ab5dd30 | 2020-04-17 09:38:06 -0600 | [diff] [blame] | 1045 | |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 1046 | for (mode = 0; boot_modes[mode].name; mode++) { |
| 1047 | if (boot_modes[mode].id == id) |
| 1048 | break; |
| 1049 | } |
Joel Johnson | 27e9d07 | 2020-04-17 09:38:08 -0600 | [diff] [blame] | 1050 | |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 1051 | if (!boot_modes[mode].name) { |
| 1052 | printf("Error: unknown boot device in image header: 0x%x\n", id); |
Joel Johnson | ab5dd30 | 2020-04-17 09:38:06 -0600 | [diff] [blame] | 1053 | return -ENOEXEC; |
Joel Johnson | ab5dd30 | 2020-04-17 09:38:06 -0600 | [diff] [blame] | 1054 | } |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 1055 | |
Pali Rohár | d83e04a | 2022-08-23 14:52:24 +0200 | [diff] [blame] | 1056 | if (strcmp(boot_modes[mode].name, dst->name) != 0) { |
| 1057 | printf("Error: image meant to be booted from \"%s\", not \"%s\"!\n", |
| 1058 | boot_modes[mode].name, dst->name); |
| 1059 | return -ENOEXEC; |
| 1060 | } |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 1061 | |
Pali Rohár | d83e04a | 2022-08-23 14:52:24 +0200 | [diff] [blame] | 1062 | #if defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_3700) |
| 1063 | if (otp_secure_bits == (u64)-1) { |
| 1064 | printf("Error: cannot read OTP secure bits\n"); |
| 1065 | return -ENOEXEC; |
| 1066 | } else { |
| 1067 | if (otp_secure_boot && !is_secure) { |
| 1068 | printf("Error: secure boot is enabled in OTP but image does not have secure boot header!\n"); |
| 1069 | return -ENOEXEC; |
| 1070 | } else if (!otp_secure_boot && is_secure) { |
| 1071 | #if defined(CONFIG_ARMADA_3700) |
| 1072 | /* |
| 1073 | * Armada 3700 BootROM rejects trusted image when secure boot is not enabled. |
| 1074 | * Armada 385 BootROM accepts image with secure boot header also when secure boot is not enabled. |
| 1075 | */ |
| 1076 | printf("Error: secure boot is disabled in OTP but image has secure boot header!\n"); |
| 1077 | return -ENOEXEC; |
Pali Rohár | 1ce57b8 | 2022-07-26 16:11:56 +0200 | [diff] [blame] | 1078 | #endif |
Pali Rohár | d83e04a | 2022-08-23 14:52:24 +0200 | [diff] [blame] | 1079 | } else if (otp_boot_device && otp_boot_device != id) { |
| 1080 | for (secure_mode = 0; boot_modes[secure_mode].name; secure_mode++) { |
| 1081 | if (boot_modes[secure_mode].id == otp_boot_device) |
| 1082 | break; |
| 1083 | } |
| 1084 | printf("Error: boot source is set to \"%s\" in OTP but image is for \"%s\"!\n", |
| 1085 | boot_modes[secure_mode].name ?: "unknown", dst->name); |
| 1086 | return -ENOEXEC; |
| 1087 | } |
| 1088 | } |
| 1089 | #endif |
| 1090 | #endif |
| 1091 | return 0; |
Joel Johnson | ab5dd30 | 2020-04-17 09:38:06 -0600 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | static int bubt_verify(const struct bubt_dev *dst) |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1095 | { |
| 1096 | int err; |
| 1097 | |
| 1098 | /* Check a correct image header exists */ |
| 1099 | err = check_image_header(); |
| 1100 | if (err) { |
| 1101 | printf("Error: Image header verification failed\n"); |
| 1102 | return err; |
| 1103 | } |
| 1104 | |
Joel Johnson | ab5dd30 | 2020-04-17 09:38:06 -0600 | [diff] [blame] | 1105 | err = bubt_check_boot_mode(dst); |
| 1106 | if (err) { |
| 1107 | printf("Error: Image boot mode verification failed\n"); |
| 1108 | return err; |
| 1109 | } |
| 1110 | |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1111 | return 0; |
| 1112 | } |
| 1113 | |
| 1114 | static int bubt_read_file(struct bubt_dev *src) |
| 1115 | { |
| 1116 | size_t image_size; |
| 1117 | |
| 1118 | if (!src->read) { |
| 1119 | printf("Error: Read not supported on device \"%s\"\n", |
| 1120 | src->name); |
| 1121 | return 0; |
| 1122 | } |
| 1123 | |
| 1124 | image_size = src->read(net_boot_file_name); |
| 1125 | if (image_size <= 0) { |
| 1126 | printf("Error: Failed to read file %s from %s\n", |
| 1127 | net_boot_file_name, src->name); |
| 1128 | return 0; |
| 1129 | } |
| 1130 | |
| 1131 | return image_size; |
| 1132 | } |
| 1133 | |
| 1134 | static int bubt_is_dev_active(struct bubt_dev *dev) |
| 1135 | { |
| 1136 | if (!dev->active) { |
Joel Johnson | 22d78e4 | 2020-04-17 09:38:05 -0600 | [diff] [blame] | 1137 | printf("Device \"%s\" not supported by U-Boot image\n", |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1138 | dev->name); |
| 1139 | return 0; |
| 1140 | } |
| 1141 | |
| 1142 | if (!dev->active()) { |
| 1143 | printf("Device \"%s\" is inactive\n", dev->name); |
| 1144 | return 0; |
| 1145 | } |
| 1146 | |
| 1147 | return 1; |
| 1148 | } |
| 1149 | |
Pali Rohár | 4b25596 | 2023-01-10 22:47:17 +0100 | [diff] [blame] | 1150 | static struct bubt_dev *find_bubt_dev(char *dev_name) |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1151 | { |
| 1152 | int dev; |
| 1153 | |
| 1154 | for (dev = 0; dev < BUBT_MAX_DEV; dev++) { |
| 1155 | if (strcmp(bubt_devs[dev].name, dev_name) == 0) |
| 1156 | return &bubt_devs[dev]; |
| 1157 | } |
| 1158 | |
| 1159 | return 0; |
| 1160 | } |
| 1161 | |
| 1162 | #define DEFAULT_BUBT_SRC "tftp" |
| 1163 | |
| 1164 | #ifndef DEFAULT_BUBT_DST |
| 1165 | #ifdef CONFIG_MVEBU_SPI_BOOT |
| 1166 | #define DEFAULT_BUBT_DST "spi" |
| 1167 | #elif defined(CONFIG_MVEBU_NAND_BOOT) |
| 1168 | #define DEFAULT_BUBT_DST "nand" |
| 1169 | #elif defined(CONFIG_MVEBU_MMC_BOOT) |
| 1170 | #define DEFAULT_BUBT_DST "mmc" |
Pali Rohár | 2a27fc2 | 2023-01-22 01:25:12 +0100 | [diff] [blame] | 1171 | #elif defined(CONFIG_MVEBU_SATA_BOOT) |
| 1172 | #define DEFAULT_BUBT_DST "sata" |
Konstantin Porotchkin | e78a389 | 2021-03-17 18:53:43 +0200 | [diff] [blame] | 1173 | #else |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1174 | #define DEFAULT_BUBT_DST "error" |
| 1175 | #endif |
| 1176 | #endif /* DEFAULT_BUBT_DST */ |
| 1177 | |
Pali Rohár | 4b25596 | 2023-01-10 22:47:17 +0100 | [diff] [blame] | 1178 | static int do_bubt_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1179 | { |
| 1180 | struct bubt_dev *src, *dst; |
| 1181 | size_t image_size; |
| 1182 | char src_dev_name[8]; |
| 1183 | char dst_dev_name[8]; |
| 1184 | char *name; |
| 1185 | int err; |
| 1186 | |
| 1187 | if (argc < 2) |
| 1188 | copy_filename(net_boot_file_name, |
| 1189 | CONFIG_MVEBU_UBOOT_DFLT_NAME, |
| 1190 | sizeof(net_boot_file_name)); |
| 1191 | else |
| 1192 | copy_filename(net_boot_file_name, argv[1], |
| 1193 | sizeof(net_boot_file_name)); |
| 1194 | |
| 1195 | if (argc >= 3) { |
| 1196 | strncpy(dst_dev_name, argv[2], 8); |
| 1197 | } else { |
| 1198 | name = DEFAULT_BUBT_DST; |
| 1199 | strncpy(dst_dev_name, name, 8); |
| 1200 | } |
| 1201 | |
| 1202 | if (argc >= 4) |
| 1203 | strncpy(src_dev_name, argv[3], 8); |
| 1204 | else |
| 1205 | strncpy(src_dev_name, DEFAULT_BUBT_SRC, 8); |
| 1206 | |
| 1207 | /* Figure out the destination device */ |
| 1208 | dst = find_bubt_dev(dst_dev_name); |
| 1209 | if (!dst) { |
| 1210 | printf("Error: Unknown destination \"%s\"\n", dst_dev_name); |
Pali Rohár | 873fc6a | 2022-07-26 16:11:59 +0200 | [diff] [blame] | 1211 | return 1; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | if (!bubt_is_dev_active(dst)) |
Pali Rohár | 873fc6a | 2022-07-26 16:11:59 +0200 | [diff] [blame] | 1215 | return 1; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1216 | |
| 1217 | /* Figure out the source device */ |
| 1218 | src = find_bubt_dev(src_dev_name); |
| 1219 | if (!src) { |
| 1220 | printf("Error: Unknown source \"%s\"\n", src_dev_name); |
| 1221 | return 1; |
| 1222 | } |
| 1223 | |
| 1224 | if (!bubt_is_dev_active(src)) |
| 1225 | return -ENODEV; |
| 1226 | |
Joel Johnson | 22d78e4 | 2020-04-17 09:38:05 -0600 | [diff] [blame] | 1227 | printf("Burning U-Boot image \"%s\" from \"%s\" to \"%s\"\n", |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1228 | net_boot_file_name, src->name, dst->name); |
| 1229 | |
| 1230 | image_size = bubt_read_file(src); |
| 1231 | if (!image_size) |
Pali Rohár | 873fc6a | 2022-07-26 16:11:59 +0200 | [diff] [blame] | 1232 | return 1; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1233 | |
Joel Johnson | ab5dd30 | 2020-04-17 09:38:06 -0600 | [diff] [blame] | 1234 | err = bubt_verify(dst); |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1235 | if (err) |
Pali Rohár | 873fc6a | 2022-07-26 16:11:59 +0200 | [diff] [blame] | 1236 | return 1; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1237 | |
| 1238 | err = bubt_write_file(dst, image_size); |
| 1239 | if (err) |
Pali Rohár | 873fc6a | 2022-07-26 16:11:59 +0200 | [diff] [blame] | 1240 | return 1; |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1241 | |
| 1242 | return 0; |
| 1243 | } |
| 1244 | |
| 1245 | U_BOOT_CMD( |
| 1246 | bubt, 4, 0, do_bubt_cmd, |
| 1247 | "Burn a u-boot image to flash", |
| 1248 | "[file-name] [destination [source]]\n" |
Pali Rohár | b418820 | 2021-01-27 11:56:02 +0100 | [diff] [blame] | 1249 | "\t-file-name The image file name to burn. Default = " CONFIG_MVEBU_UBOOT_DFLT_NAME "\n" |
Pali Rohár | 2a27fc2 | 2023-01-22 01:25:12 +0100 | [diff] [blame] | 1250 | "\t-destination Flash to burn to [spi, nand, mmc, sata]. Default = " DEFAULT_BUBT_DST "\n" |
Pali Rohár | c61feb9 | 2023-01-21 23:29:36 +0100 | [diff] [blame] | 1251 | "\t-source The source to load image from [tftp, usb, mmc, sata]. Default = " DEFAULT_BUBT_SRC "\n" |
Konstantin Porotchkin | 97d2678 | 2016-12-08 12:22:28 +0200 | [diff] [blame] | 1252 | "Examples:\n" |
| 1253 | "\tbubt - Burn flash-image.bin from tftp to active boot device\n" |
| 1254 | "\tbubt flash-image-new.bin nand - Burn flash-image-new.bin from tftp to NAND flash\n" |
| 1255 | "\tbubt backup-flash-image.bin mmc usb - Burn backup-flash-image.bin from usb to MMC\n" |
| 1256 | |
| 1257 | ); |