1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7 #include <android_bootloader.h> 8 #include <android_bootloader_message.h> 9 #include <android_avb/avb_slot_verify.h> 10 #include <android_avb/avb_ops_user.h> 11 #include <android_avb/rk_avb_ops_user.h> 12 13 #include <cli.h> 14 #include <common.h> 15 #include <malloc.h> 16 #include <fs.h> 17 #include <boot_rkimg.h> 18 #include <attestation_key.h> 19 #include <optee_include/OpteeClientInterface.h> 20 21 #define ANDROID_PARTITION_BOOT "boot" 22 #define ANDROID_PARTITION_MISC "misc" 23 #define ANDROID_PARTITION_OEM "oem" 24 #define ANDROID_PARTITION_RECOVERY "recovery" 25 #define ANDROID_PARTITION_SYSTEM "system" 26 27 #define ANDROID_ARG_SLOT_SUFFIX "androidboot.slot_suffix=" 28 #define ANDROID_ARG_ROOT "root=" 29 #define ANDROID_ARG_SERIALNO "androidboot.serialno=" 30 #ifdef CONFIG_ROCKCHIP_RESOURCE_IMAGE 31 #define ANDROID_ARG_FDT_FILENAME "rk-kernel.dtb" 32 #define BOOTLOADER_MESSAGE_OFFSET_IN_MISC (16 * 1024) 33 #define BOOTLOADER_MESSAGE_BLK_OFFSET (BOOTLOADER_MESSAGE_OFFSET_IN_MISC >> 9) 34 #else 35 #define ANDROID_ARG_FDT_FILENAME "kernel.dtb" 36 #endif 37 #define OEM_UNLOCK_ARG_SIZE 30 38 39 char *android_str_append(char *base_name, char *slot_suffix) 40 { 41 char *part_name; 42 size_t part_name_len; 43 44 part_name_len = strlen(base_name) + 1; 45 if (slot_suffix) 46 part_name_len += strlen(slot_suffix); 47 part_name = malloc(part_name_len); 48 if (!part_name) 49 return NULL; 50 strcpy(part_name, base_name); 51 if (slot_suffix && (slot_suffix[0] != '\0')) 52 strcat(part_name, slot_suffix); 53 54 return part_name; 55 } 56 57 int android_bootloader_message_load( 58 struct blk_desc *dev_desc, 59 const disk_partition_t *part_info, 60 struct android_bootloader_message *message) 61 { 62 ulong message_blocks = sizeof(struct android_bootloader_message) / 63 part_info->blksz; 64 if (message_blocks > part_info->size) { 65 printf("misc partition too small.\n"); 66 return -1; 67 } 68 69 #ifdef CONFIG_RKIMG_BOOTLOADER 70 if (blk_dread(dev_desc, part_info->start + BOOTLOADER_MESSAGE_BLK_OFFSET, 71 message_blocks, message) != 72 #else 73 if (blk_dread(dev_desc, part_info->start, message_blocks, message) != 74 #endif 75 message_blocks) { 76 printf("Could not read from misc partition\n"); 77 return -1; 78 } 79 debug("ANDROID: Loaded BCB, %lu blocks.\n", message_blocks); 80 return 0; 81 } 82 83 static int android_bootloader_message_write( 84 struct blk_desc *dev_desc, 85 const disk_partition_t *part_info, 86 struct android_bootloader_message *message) 87 { 88 #ifdef CONFIG_RKIMG_BOOTLOADER 89 ulong message_blocks = sizeof(struct android_bootloader_message) / 90 part_info->blksz + BOOTLOADER_MESSAGE_BLK_OFFSET; 91 #else 92 ulong message_blocks = sizeof(struct android_bootloader_message) / 93 part_info->blksz; 94 #endif 95 if (message_blocks > part_info->size) { 96 printf("misc partition too small.\n"); 97 return -1; 98 } 99 100 if (blk_dwrite(dev_desc, part_info->start, message_blocks, message) != 101 message_blocks) { 102 printf("Could not write to misc partition\n"); 103 return -1; 104 } 105 debug("ANDROID: Wrote new BCB, %lu blocks.\n", message_blocks); 106 return 0; 107 } 108 109 static enum android_boot_mode android_bootloader_load_and_clear_mode( 110 struct blk_desc *dev_desc, 111 const disk_partition_t *misc_part_info) 112 { 113 struct android_bootloader_message bcb; 114 115 #ifdef CONFIG_FASTBOOT 116 char *bootloader_str; 117 118 /* Check for message from bootloader stored in RAM from a previous boot. 119 */ 120 bootloader_str = (char *)CONFIG_FASTBOOT_BUF_ADDR; 121 if (!strcmp("reboot-bootloader", bootloader_str)) { 122 bootloader_str[0] = '\0'; 123 return ANDROID_BOOT_MODE_BOOTLOADER; 124 } 125 #endif 126 127 /* Check and update the BCB message if needed. */ 128 if (android_bootloader_message_load(dev_desc, misc_part_info, &bcb) < 129 0) { 130 printf("WARNING: Unable to load the BCB.\n"); 131 return ANDROID_BOOT_MODE_NORMAL; 132 } 133 134 if (!strcmp("bootonce-bootloader", bcb.command)) { 135 /* Erase the message in the BCB since this value should be used 136 * only once. 137 */ 138 memset(bcb.command, 0, sizeof(bcb.command)); 139 android_bootloader_message_write(dev_desc, misc_part_info, 140 &bcb); 141 return ANDROID_BOOT_MODE_BOOTLOADER; 142 } 143 144 if (!strcmp("boot-recovery", bcb.command)) 145 return ANDROID_BOOT_MODE_RECOVERY; 146 147 return ANDROID_BOOT_MODE_NORMAL; 148 } 149 150 /** 151 * Return the reboot reason string for the passed boot mode. 152 * 153 * @param mode The Android Boot mode. 154 * @return a pointer to the reboot reason string for mode. 155 */ 156 static const char *android_boot_mode_str(enum android_boot_mode mode) 157 { 158 switch (mode) { 159 case ANDROID_BOOT_MODE_NORMAL: 160 return "(none)"; 161 case ANDROID_BOOT_MODE_RECOVERY: 162 return "recovery"; 163 case ANDROID_BOOT_MODE_BOOTLOADER: 164 return "bootloader"; 165 } 166 return NULL; 167 } 168 169 static int android_part_get_info_by_name_suffix(struct blk_desc *dev_desc, 170 const char *base_name, 171 const char *slot_suffix, 172 disk_partition_t *part_info) 173 { 174 char *part_name; 175 int part_num; 176 size_t part_name_len; 177 178 part_name_len = strlen(base_name) + 1; 179 if (slot_suffix) 180 part_name_len += strlen(slot_suffix); 181 part_name = malloc(part_name_len); 182 if (!part_name) 183 return -1; 184 strcpy(part_name, base_name); 185 if (slot_suffix && (slot_suffix[0] != '\0')) 186 strcat(part_name, slot_suffix); 187 188 part_num = part_get_info_by_name(dev_desc, part_name, part_info); 189 if (part_num < 0) { 190 debug("ANDROID: Could not find partition \"%s\"\n", part_name); 191 part_num = -1; 192 } 193 194 free(part_name); 195 return part_num; 196 } 197 198 static int android_bootloader_boot_bootloader(void) 199 { 200 const char *fastboot_cmd = env_get("fastbootcmd"); 201 202 if (fastboot_cmd == NULL) { 203 printf("fastboot_cmd is null, run default fastboot_cmd!\n"); 204 fastboot_cmd = "fastboot usb 0"; 205 } 206 207 return run_command(fastboot_cmd, CMD_FLAG_ENV); 208 } 209 210 #ifdef CONFIG_SUPPORT_OEM_DTB 211 static int android_bootloader_get_fdt(const char *part_name, 212 const char *load_file_name) 213 { 214 const char *dev_iface = "mmc"; 215 struct blk_desc *dev_desc; 216 disk_partition_t boot_part_info; 217 char *fdt_addr = NULL; 218 char slot_suffix[5] = {0}; 219 char dev_part[3] = {0}; 220 loff_t bytes = 0; 221 loff_t pos = 0; 222 loff_t len_read; 223 unsigned long addr = 0; 224 int part_num = -1; 225 int dev_num = 0; 226 int ret; 227 228 dev_desc = blk_get_dev(dev_iface, dev_num); 229 if (!dev_desc) { 230 printf("Could not find %s %d\n", dev_iface, dev_num); 231 return -1; 232 } 233 234 memset(&boot_part_info, 0, sizeof(boot_part_info)); 235 236 #ifdef CONFIG_RK_AVB_LIBAVB_USER 237 if (rk_avb_get_current_slot(slot_suffix)) { 238 printf("ANDROID: Get Current Slot error.\n"); 239 return -1; 240 } 241 242 part_num = android_part_get_info_by_name_suffix(dev_desc, 243 part_name, 244 slot_suffix, &boot_part_info); 245 #else 246 part_num = part_get_info_by_name(dev_desc, part_name, &boot_part_info); 247 if (part_num < 0) { 248 printf("ANDROID: Could not find partition \"%s\"\n", part_name); 249 return -1; 250 } 251 #endif 252 253 snprintf(dev_part, ARRAY_SIZE(dev_part), ":%x", part_num); 254 if (fs_set_blk_dev(dev_iface, dev_part, FS_TYPE_EXT)) 255 return -1; 256 257 fdt_addr = env_get("fdt_addr_r"); 258 if (!fdt_addr) { 259 printf("ANDROID: No Found FDT Load Address.\n"); 260 return -1; 261 } 262 addr = simple_strtoul(fdt_addr, NULL, 16); 263 264 ret = fs_read(load_file_name, addr, pos, bytes, &len_read); 265 if (ret < 0) 266 return -1; 267 268 return 0; 269 } 270 #endif 271 272 int android_bootloader_boot_kernel(unsigned long kernel_address) 273 { 274 char kernel_addr_str[12]; 275 char *fdt_addr = env_get("fdt_addr"); 276 char *bootm_args[] = { 277 "bootm", kernel_addr_str, kernel_addr_str, fdt_addr, NULL }; 278 279 sprintf(kernel_addr_str, "0x%lx", kernel_address); 280 281 printf("Booting kernel at %s with fdt at %s...\n\n\n", 282 kernel_addr_str, fdt_addr); 283 do_bootm(NULL, 0, 4, bootm_args); 284 285 return -1; 286 } 287 288 static char *strjoin(const char **chunks, char separator) 289 { 290 int len, joined_len = 0; 291 char *ret, *current; 292 const char **p; 293 294 for (p = chunks; *p; p++) 295 joined_len += strlen(*p) + 1; 296 297 if (!joined_len) { 298 ret = malloc(1); 299 if (ret) 300 ret[0] = '\0'; 301 return ret; 302 } 303 304 ret = malloc(joined_len); 305 current = ret; 306 if (!ret) 307 return ret; 308 309 for (p = chunks; *p; p++) { 310 len = strlen(*p); 311 memcpy(current, *p, len); 312 current += len; 313 *current = separator; 314 current++; 315 } 316 /* Replace the last separator by a \0. */ 317 current[-1] = '\0'; 318 return ret; 319 } 320 321 /** android_assemble_cmdline - Assemble the command line to pass to the kernel 322 * @return a newly allocated string 323 */ 324 char *android_assemble_cmdline(const char *slot_suffix, 325 const char *extra_args) 326 { 327 const char *cmdline_chunks[16]; 328 const char **current_chunk = cmdline_chunks; 329 char *env_cmdline, *cmdline, *rootdev_input, *serialno; 330 char *allocated_suffix = NULL; 331 char *allocated_serialno = NULL; 332 char *allocated_rootdev = NULL; 333 unsigned long rootdev_len; 334 335 env_cmdline = env_get("bootargs"); 336 if (env_cmdline) 337 *(current_chunk++) = env_cmdline; 338 339 /* The |slot_suffix| needs to be passed to the kernel to know what 340 * slot to boot from. 341 */ 342 if (slot_suffix) { 343 allocated_suffix = malloc(strlen(ANDROID_ARG_SLOT_SUFFIX) + 344 strlen(slot_suffix) + 1); 345 memset(allocated_suffix, 0, strlen(ANDROID_ARG_SLOT_SUFFIX) 346 + strlen(slot_suffix) + 1); 347 strcpy(allocated_suffix, ANDROID_ARG_SLOT_SUFFIX); 348 strcat(allocated_suffix, slot_suffix); 349 *(current_chunk++) = allocated_suffix; 350 } 351 352 serialno = env_get("serial#"); 353 if (serialno) { 354 allocated_serialno = malloc(strlen(ANDROID_ARG_SERIALNO) + 355 strlen(serialno) + 1); 356 memset(allocated_serialno, 0, strlen(ANDROID_ARG_SERIALNO) + 357 strlen(serialno) + 1); 358 strcpy(allocated_serialno, ANDROID_ARG_SERIALNO); 359 strcat(allocated_serialno, serialno); 360 *(current_chunk++) = allocated_serialno; 361 } 362 363 rootdev_input = env_get("android_rootdev"); 364 if (rootdev_input) { 365 rootdev_len = strlen(ANDROID_ARG_ROOT) + CONFIG_SYS_CBSIZE + 1; 366 allocated_rootdev = malloc(rootdev_len); 367 strcpy(allocated_rootdev, ANDROID_ARG_ROOT); 368 cli_simple_process_macros(rootdev_input, 369 allocated_rootdev + 370 strlen(ANDROID_ARG_ROOT)); 371 /* Make sure that the string is null-terminated since the 372 * previous could not copy to the end of the input string if it 373 * is too big. 374 */ 375 allocated_rootdev[rootdev_len - 1] = '\0'; 376 *(current_chunk++) = allocated_rootdev; 377 } 378 379 if (extra_args) 380 *(current_chunk++) = extra_args; 381 382 *(current_chunk++) = NULL; 383 cmdline = strjoin(cmdline_chunks, ' '); 384 free(allocated_suffix); 385 free(allocated_rootdev); 386 return cmdline; 387 } 388 389 #ifdef CONFIG_ANDROID_AVB 390 static void slot_set_unbootable(AvbABSlotData* slot) 391 { 392 slot->priority = 0; 393 slot->tries_remaining = 0; 394 slot->successful_boot = 0; 395 } 396 397 static AvbSlotVerifyResult android_slot_verify(char *boot_partname, 398 unsigned long load_address, 399 char *slot_suffix) 400 { 401 const char *requested_partitions[1] = {NULL}; 402 uint8_t unlocked = true; 403 AvbOps *ops; 404 AvbSlotVerifyFlags flags; 405 AvbSlotVerifyData *slot_data[1] = {NULL}; 406 AvbSlotVerifyResult verify_result; 407 AvbABData ab_data, ab_data_orig; 408 size_t slot_index_to_boot = 0; 409 410 requested_partitions[0] = boot_partname; 411 ops = avb_ops_user_new(); 412 if (ops == NULL) { 413 printf("avb_ops_user_new() failed!\n"); 414 return AVB_SLOT_VERIFY_RESULT_ERROR_OOM; 415 } 416 417 if (ops->read_is_device_unlocked(ops, (bool *)&unlocked) != AVB_IO_RESULT_OK) 418 printf("Error determining whether device is unlocked.\n"); 419 420 printf("read_is_device_unlocked() ops returned that device is %s\n", 421 (unlocked & LOCK_MASK)? "UNLOCKED" : "LOCKED"); 422 423 flags = AVB_SLOT_VERIFY_FLAGS_NONE; 424 if (unlocked & LOCK_MASK) 425 flags |= AVB_SLOT_VERIFY_FLAGS_ALLOW_VERIFICATION_ERROR; 426 427 if(load_metadata(ops->ab_ops, &ab_data, &ab_data_orig)) { 428 printf("Can not load metadata\n"); 429 return AVB_SLOT_VERIFY_RESULT_ERROR_IO; 430 } 431 432 if (strncmp(slot_suffix, "_a", 2)) 433 slot_index_to_boot = 0; 434 else if(strncmp(slot_suffix, "_b", 2)) 435 slot_index_to_boot = 1; 436 else 437 slot_index_to_boot = 0; 438 439 verify_result = 440 avb_slot_verify(ops, 441 requested_partitions, 442 slot_suffix, 443 flags, 444 AVB_HASHTREE_ERROR_MODE_RESTART_AND_INVALIDATE, 445 &slot_data[0]); 446 447 if (verify_result != AVB_SLOT_VERIFY_RESULT_OK && !(unlocked & LOCK_MASK)) { 448 slot_set_unbootable(&ab_data.slots[slot_index_to_boot]); 449 goto out; 450 } 451 452 memcpy((uint8_t*)load_address, 453 slot_data[0]->loaded_partitions->data, 454 slot_data[0]->loaded_partitions->data_size); 455 env_set("bootargs", slot_data[0]->cmdline); 456 457 /* ... and decrement tries remaining, if applicable. */ 458 if (!ab_data.slots[slot_index_to_boot].successful_boot && 459 ab_data.slots[slot_index_to_boot].tries_remaining > 0) { 460 ab_data.slots[slot_index_to_boot].tries_remaining -= 1; 461 } 462 out: 463 if (save_metadata_if_changed(ops->ab_ops, &ab_data, &ab_data_orig)) { 464 printf("Can not save metadata\n"); 465 verify_result = AVB_SLOT_VERIFY_RESULT_ERROR_IO; 466 } 467 468 if (slot_data[0] != NULL) 469 avb_slot_verify_data_free(slot_data[0]); 470 471 if (unlocked & LOCK_MASK) 472 return 0; 473 else 474 return verify_result; 475 } 476 #endif 477 478 int android_bootloader_boot_flow(struct blk_desc *dev_desc, 479 unsigned long load_address) 480 { 481 enum android_boot_mode mode; 482 disk_partition_t misc_part_info; 483 int part_num; 484 int ret; 485 char *command_line; 486 char slot_suffix[3] = {0}; 487 const char *mode_cmdline = NULL; 488 char *boot_partname = ANDROID_PARTITION_BOOT; 489 ulong fdt_addr; 490 491 /* 492 * 1. Load MISC partition and determine the boot mode 493 * clear its value for the next boot if needed. 494 */ 495 part_num = part_get_info_by_name(dev_desc, ANDROID_PARTITION_MISC, 496 &misc_part_info); 497 if (part_num < 0) 498 printf("%s Could not find misc partition\n", __func__); 499 500 #ifdef CONFIG_OPTEE_CLIENT 501 /* load attestation key from misc partition. */ 502 load_attestation_key(dev_desc, &misc_part_info); 503 #endif 504 505 mode = android_bootloader_load_and_clear_mode(dev_desc, &misc_part_info); 506 #ifdef CONFIG_RKIMG_BOOTLOADER 507 if (mode == ANDROID_BOOT_MODE_NORMAL) { 508 if (rockchip_get_boot_mode() == BOOT_MODE_RECOVERY) 509 mode = ANDROID_BOOT_MODE_RECOVERY; 510 } 511 #endif 512 printf("ANDROID: reboot reason: \"%s\"\n", android_boot_mode_str(mode)); 513 514 switch (mode) { 515 case ANDROID_BOOT_MODE_NORMAL: 516 /* In normal mode, we load the kernel from "boot" but append 517 * "skip_initramfs" to the cmdline to make it ignore the 518 * recovery initramfs in the boot partition. 519 */ 520 #ifdef CONFIG_ANDROID_AB 521 mode_cmdline = "skip_initramfs"; 522 #endif 523 break; 524 case ANDROID_BOOT_MODE_RECOVERY: 525 /* In recovery mode we still boot the kernel from "boot" but 526 * don't skip the initramfs so it boots to recovery. 527 */ 528 #ifndef CONFIG_ANDROID_AB 529 boot_partname = ANDROID_PARTITION_RECOVERY; 530 #endif 531 break; 532 case ANDROID_BOOT_MODE_BOOTLOADER: 533 /* Bootloader mode enters fastboot. If this operation fails we 534 * simply return since we can't recover from this situation by 535 * switching to another slot. 536 */ 537 return android_bootloader_boot_bootloader(); 538 } 539 540 #ifdef CONFIG_ANDROID_AB 541 /*TODO: get from pre-loader or misc partition*/ 542 if (rk_avb_get_current_slot(slot_suffix)) 543 return -1; 544 545 if (slot_suffix[0] != '_') { 546 printf("There is no bootable slot!\n"); 547 return -1; 548 } 549 #endif 550 551 #ifdef CONFIG_ANDROID_AVB 552 if (android_slot_verify(boot_partname, load_address, slot_suffix)) 553 return -1; 554 #else 555 /* 556 * 2. Load the boot/recovery from the desired "boot" partition. 557 * Determine if this is an AOSP image. 558 */ 559 disk_partition_t boot_part_info; 560 part_num = 561 android_part_get_info_by_name_suffix(dev_desc, 562 boot_partname, 563 slot_suffix, &boot_part_info); 564 if (part_num < 0) { 565 printf("%s Could not found bootable partition %s\n", __func__, 566 boot_partname); 567 return -1; 568 } 569 debug("ANDROID: Loading kernel from \"%s\", partition %d.\n", 570 boot_part_info.name, part_num); 571 572 load_address = android_image_load(dev_desc, &boot_part_info, load_address, 573 -1UL); 574 if (load_address < 0) { 575 printf("%s %s part load fail\n", __func__, boot_part_info.name); 576 return load_address; 577 } 578 #endif 579 580 /* Set Android root variables. */ 581 env_set_ulong("android_root_devnum", dev_desc->devnum); 582 env_set("android_slotsufix", slot_suffix); 583 584 #ifdef CONFIG_OPTEE_CLIENT 585 /* read oem unlock status and attach to bootargs */ 586 uint8_t unlock = 0; 587 TEEC_Result result; 588 char oem_unlock[OEM_UNLOCK_ARG_SIZE] = {0}; 589 result = trusty_read_oem_unlock(&unlock); 590 if (result) { 591 printf("read oem unlock status with error : 0x%x\n", result); 592 } else { 593 snprintf(oem_unlock, OEM_UNLOCK_ARG_SIZE, "androidboot.oem_unlocked=%d", unlock); 594 env_update("bootargs", oem_unlock); 595 } 596 #endif 597 598 /* Assemble the command line */ 599 command_line = android_assemble_cmdline(slot_suffix, mode_cmdline); 600 env_update("bootargs", command_line); 601 602 debug("ANDROID: bootargs: \"%s\"\n", command_line); 603 604 #ifdef CONFIG_SUPPORT_OEM_DTB 605 if (android_bootloader_get_fdt(ANDROID_PARTITION_OEM, 606 ANDROID_ARG_FDT_FILENAME)) { 607 printf("Can not get the fdt data from oem!\n"); 608 } 609 #else 610 ret = android_image_get_fdt((void *)load_address, &fdt_addr); 611 if (!ret) 612 env_set_hex("fdt_addr", fdt_addr); 613 #endif 614 android_bootloader_boot_kernel(load_address); 615 616 /* TODO: If the kernel doesn't boot mark the selected slot as bad. */ 617 return -1; 618 } 619 620 int android_avb_boot_flow(char *slot_suffix, unsigned long kernel_address) 621 { 622 const char *dev_iface = "mmc"; 623 int dev_num = 0; 624 struct blk_desc *dev_desc; 625 disk_partition_t boot_part_info; 626 int ret; 627 dev_desc = blk_get_dev(dev_iface, dev_num); 628 if (!dev_desc) { 629 printf("Could not find %s %d\n", dev_iface, dev_num); 630 return -1; 631 } 632 /* Load the kernel from the desired "boot" partition. */ 633 android_part_get_info_by_name_suffix(dev_desc, 634 ANDROID_PARTITION_BOOT, 635 slot_suffix, &boot_part_info); 636 ret = android_image_load(dev_desc, &boot_part_info, kernel_address, 637 -1UL); 638 if (ret < 0) 639 return ret; 640 android_bootloader_boot_kernel(kernel_address); 641 642 /* TODO: If the kernel doesn't boot mark the selected slot as bad. */ 643 return -1; 644 } 645 646 int android_boot_flow(unsigned long kernel_address) 647 { 648 const char *dev_iface = "mmc"; 649 int dev_num = 0; 650 struct blk_desc *dev_desc; 651 disk_partition_t boot_part_info; 652 int ret; 653 dev_desc = blk_get_dev(dev_iface, dev_num); 654 if (!dev_desc) { 655 printf("Could not find %s %d\n", dev_iface, dev_num); 656 return -1; 657 } 658 /* Load the kernel from the desired "boot" partition. */ 659 part_get_info_by_name(dev_desc, ANDROID_PARTITION_BOOT, &boot_part_info); 660 ret = android_image_load(dev_desc, &boot_part_info, kernel_address, 661 -1UL); 662 if (ret < 0) 663 return ret; 664 android_bootloader_boot_kernel(kernel_address); 665 666 /* TODO: If the kernel doesn't boot mark the selected slot as bad. */ 667 return -1; 668 } 669