| .. | .. |
|---|
| 56 | 56 | |
|---|
| 57 | 57 | DECLARE_GLOBAL_DATA_PTR; |
|---|
| 58 | 58 | |
|---|
| 59 | +#ifdef CONFIG_ARM64 |
|---|
| 60 | +static ulong orig_images_ep; |
|---|
| 61 | +#endif |
|---|
| 62 | + |
|---|
| 59 | 63 | __weak int rk_board_late_init(void) |
|---|
| 60 | 64 | { |
|---|
| 61 | 65 | return 0; |
|---|
| .. | .. |
|---|
| 246 | 250 | static int boot_from_udisk(void) |
|---|
| 247 | 251 | { |
|---|
| 248 | 252 | struct blk_desc *desc; |
|---|
| 249 | | - char *devtype; |
|---|
| 250 | | - char *devnum; |
|---|
| 251 | | - |
|---|
| 252 | | - devtype = env_get("devtype"); |
|---|
| 253 | | - devnum = env_get("devnum"); |
|---|
| 253 | + struct udevice *dev; |
|---|
| 254 | + int devnum = -1; |
|---|
| 255 | + char buf[32]; |
|---|
| 254 | 256 | |
|---|
| 255 | 257 | /* Booting priority: mmc1 > udisk */ |
|---|
| 256 | | - if (!strcmp(devtype, "mmc") && !strcmp(devnum, "1")) |
|---|
| 258 | + if (!strcmp(env_get("devtype"), "mmc") && !strcmp(env_get("devnum"), "1")) |
|---|
| 257 | 259 | return 0; |
|---|
| 258 | 260 | |
|---|
| 259 | 261 | if (!run_command("usb start", -1)) { |
|---|
| 260 | | - desc = blk_get_devnum_by_type(IF_TYPE_USB, 0); |
|---|
| 261 | | - if (!desc) { |
|---|
| 262 | | - printf("No usb device found\n"); |
|---|
| 262 | + for (blk_first_device(IF_TYPE_USB, &dev); |
|---|
| 263 | + dev; |
|---|
| 264 | + blk_next_device(&dev)) { |
|---|
| 265 | + desc = dev_get_uclass_platdata(dev); |
|---|
| 266 | + printf("Scanning usb %d ...\n", desc->devnum); |
|---|
| 267 | + if (desc->type == DEV_TYPE_UNKNOWN) |
|---|
| 268 | + continue; |
|---|
| 269 | + |
|---|
| 270 | + if (desc->lba > 0L && desc->blksz > 0L) { |
|---|
| 271 | + devnum = desc->devnum; |
|---|
| 272 | + break; |
|---|
| 273 | + } |
|---|
| 274 | + } |
|---|
| 275 | + if (devnum < 0) { |
|---|
| 276 | + printf("No usb mass storage found\n"); |
|---|
| 263 | 277 | return -ENODEV; |
|---|
| 264 | 278 | } |
|---|
| 265 | 279 | |
|---|
| 266 | | - if (!run_command("rkimgtest usb 0", -1)) { |
|---|
| 280 | + desc = blk_get_devnum_by_type(IF_TYPE_USB, devnum); |
|---|
| 281 | + if (!desc) { |
|---|
| 282 | + printf("No usb %d found\n", devnum); |
|---|
| 283 | + return -ENODEV; |
|---|
| 284 | + } |
|---|
| 285 | + |
|---|
| 286 | + snprintf(buf, 32, "rkimgtest usb %d", devnum); |
|---|
| 287 | + if (!run_command(buf, -1)) { |
|---|
| 288 | + snprintf(buf, 32, "%d", devnum); |
|---|
| 267 | 289 | rockchip_set_bootdev(desc); |
|---|
| 268 | 290 | env_set("devtype", "usb"); |
|---|
| 269 | | - env_set("devnum", "0"); |
|---|
| 270 | | - printf("Boot from usb 0\n"); |
|---|
| 291 | + env_set("devnum", buf); |
|---|
| 292 | + printf("=== Booting from usb %d ===\n", devnum); |
|---|
| 271 | 293 | } else { |
|---|
| 272 | | - printf("No usb dev 0 found\n"); |
|---|
| 294 | + printf("No available udisk image on usb %d\n", devnum); |
|---|
| 273 | 295 | return -ENODEV; |
|---|
| 274 | 296 | } |
|---|
| 275 | 297 | } |
|---|
| .. | .. |
|---|
| 358 | 380 | static void cmdline_handle(void) |
|---|
| 359 | 381 | { |
|---|
| 360 | 382 | struct blk_desc *dev_desc; |
|---|
| 383 | + int if_type; |
|---|
| 384 | + int devnum; |
|---|
| 361 | 385 | |
|---|
| 362 | 386 | param_parse_pubkey_fuse_programmed(); |
|---|
| 363 | 387 | |
|---|
| .. | .. |
|---|
| 373 | 397 | * rockchip_get_boot_mode() actually only read once, |
|---|
| 374 | 398 | * we need to update boot mode according to udisk BCB. |
|---|
| 375 | 399 | */ |
|---|
| 376 | | - if ((dev_desc->if_type == IF_TYPE_MMC && dev_desc->devnum == 1) || |
|---|
| 377 | | - (dev_desc->if_type == IF_TYPE_USB && dev_desc->devnum == 0)) { |
|---|
| 400 | + if_type = dev_desc->if_type; |
|---|
| 401 | + devnum = dev_desc->devnum; |
|---|
| 402 | + if ((if_type == IF_TYPE_MMC && devnum == 1) || (if_type == IF_TYPE_USB)) { |
|---|
| 378 | 403 | if (get_bcb_recovery_msg() == BCB_MSG_RECOVERY_RK_FWUPDATE) { |
|---|
| 379 | | - if (dev_desc->if_type == IF_TYPE_MMC && dev_desc->devnum == 1) { |
|---|
| 404 | + if (if_type == IF_TYPE_MMC && devnum == 1) { |
|---|
| 380 | 405 | env_update("bootargs", "sdfwupdate"); |
|---|
| 381 | | - } else if (dev_desc->if_type == IF_TYPE_USB && dev_desc->devnum == 0) { |
|---|
| 406 | + } else if (if_type == IF_TYPE_USB) { |
|---|
| 382 | 407 | env_update("bootargs", "usbfwupdate"); |
|---|
| 383 | 408 | env_set("reboot_mode", "recovery-usb"); |
|---|
| 384 | 409 | } |
|---|
| 385 | 410 | } else { |
|---|
| 386 | | - if (dev_desc->if_type == IF_TYPE_USB && dev_desc->devnum == 0) |
|---|
| 411 | + if (if_type == IF_TYPE_USB) |
|---|
| 387 | 412 | env_set("reboot_mode", "normal"); |
|---|
| 388 | 413 | } |
|---|
| 414 | + } |
|---|
| 415 | + |
|---|
| 416 | + if (rockchip_get_boot_mode() == BOOT_MODE_QUIESCENT) |
|---|
| 417 | + env_update("bootargs", "androidboot.quiescent=1 pwm_bl.quiescent=1"); |
|---|
| 418 | +} |
|---|
| 419 | + |
|---|
| 420 | +static void scan_run_cmd(void) |
|---|
| 421 | +{ |
|---|
| 422 | + char *config = CONFIG_ROCKCHIP_CMD; |
|---|
| 423 | + char *cmd, *key; |
|---|
| 424 | + |
|---|
| 425 | + key = strchr(config, ' '); |
|---|
| 426 | + if (!key) |
|---|
| 427 | + return; |
|---|
| 428 | + |
|---|
| 429 | + cmd = strdup(config); |
|---|
| 430 | + cmd[key - config] = 0; |
|---|
| 431 | + key++; |
|---|
| 432 | + |
|---|
| 433 | + if (!strcmp(key, "-")) { |
|---|
| 434 | + run_command(cmd, 0); |
|---|
| 435 | + } else { |
|---|
| 436 | +#ifdef CONFIG_DM_KEY |
|---|
| 437 | + ulong map; |
|---|
| 438 | + |
|---|
| 439 | + map = simple_strtoul(key, NULL, 10); |
|---|
| 440 | + if (key_is_pressed(key_read(map))) { |
|---|
| 441 | + printf("## Key<%ld> pressed... run cmd '%s'\n", map, cmd); |
|---|
| 442 | + run_command(cmd, 0); |
|---|
| 443 | + } |
|---|
| 444 | +#endif |
|---|
| 389 | 445 | } |
|---|
| 390 | 446 | } |
|---|
| 391 | 447 | |
|---|
| .. | .. |
|---|
| 398 | 454 | rockchip_set_serialno(); |
|---|
| 399 | 455 | #endif |
|---|
| 400 | 456 | setup_download_mode(); |
|---|
| 401 | | - |
|---|
| 457 | + scan_run_cmd(); |
|---|
| 402 | 458 | #ifdef CONFIG_ROCKCHIP_USB_BOOT |
|---|
| 403 | 459 | boot_from_udisk(); |
|---|
| 404 | 460 | #endif |
|---|
| .. | .. |
|---|
| 406 | 462 | charge_display(); |
|---|
| 407 | 463 | #endif |
|---|
| 408 | 464 | #ifdef CONFIG_DRM_ROCKCHIP |
|---|
| 409 | | - rockchip_show_logo(); |
|---|
| 465 | + if (rockchip_get_boot_mode() != BOOT_MODE_QUIESCENT) |
|---|
| 466 | + rockchip_show_logo(); |
|---|
| 410 | 467 | #endif |
|---|
| 411 | 468 | #ifdef CONFIG_ROCKCHIP_EINK_DISPLAY |
|---|
| 412 | 469 | rockchip_eink_show_uboot_logo(); |
|---|
| .. | .. |
|---|
| 458 | 515 | printf("Cmd interface: disabled\n"); |
|---|
| 459 | 516 | } |
|---|
| 460 | 517 | |
|---|
| 461 | | -#if defined(CONFIG_MTD_BLK) && defined(CONFIG_USING_KERNEL_DTB) |
|---|
| 462 | | -static void board_mtd_blk_map_partitions(void) |
|---|
| 463 | | -{ |
|---|
| 464 | | - struct blk_desc *dev_desc; |
|---|
| 465 | | - |
|---|
| 466 | | - dev_desc = rockchip_get_bootdev(); |
|---|
| 467 | | - if (dev_desc) |
|---|
| 468 | | - mtd_blk_map_partitions(dev_desc); |
|---|
| 469 | | -} |
|---|
| 470 | | -#endif |
|---|
| 471 | | - |
|---|
| 472 | 518 | int board_init(void) |
|---|
| 473 | 519 | { |
|---|
| 474 | 520 | board_debug_init(); |
|---|
| 475 | | - /* optee select security level */ |
|---|
| 476 | | -#ifdef CONFIG_OPTEE_CLIENT |
|---|
| 477 | | - trusty_select_security_level(); |
|---|
| 478 | | -#endif |
|---|
| 479 | | - |
|---|
| 480 | 521 | #ifdef DEBUG |
|---|
| 481 | 522 | soc_clk_dump(); |
|---|
| 482 | 523 | #endif |
|---|
| 483 | | - |
|---|
| 484 | | -#ifdef CONFIG_USING_KERNEL_DTB |
|---|
| 485 | | -#ifdef CONFIG_MTD_BLK |
|---|
| 486 | | - board_mtd_blk_map_partitions(); |
|---|
| 524 | +#ifdef CONFIG_OPTEE_CLIENT |
|---|
| 525 | + trusty_select_security_level(); |
|---|
| 487 | 526 | #endif |
|---|
| 527 | +#ifdef CONFIG_USING_KERNEL_DTB |
|---|
| 488 | 528 | init_kernel_dtb(); |
|---|
| 489 | 529 | #endif |
|---|
| 490 | 530 | early_download(); |
|---|
| 491 | 531 | |
|---|
| 492 | | - /* |
|---|
| 493 | | - * pmucru isn't referenced on some platforms, so pmucru driver can't |
|---|
| 494 | | - * probe that the "assigned-clocks" is unused. |
|---|
| 495 | | - */ |
|---|
| 496 | 532 | clks_probe(); |
|---|
| 497 | 533 | #ifdef CONFIG_DM_REGULATOR |
|---|
| 498 | | - if (regulators_enable_boot_on(is_hotkey(HK_REGULATOR))) |
|---|
| 499 | | - debug("%s: Can't enable boot on regulator\n", __func__); |
|---|
| 534 | + regulators_enable_boot_on(is_hotkey(HK_REGULATOR)); |
|---|
| 500 | 535 | #endif |
|---|
| 501 | | - |
|---|
| 502 | 536 | #ifdef CONFIG_ROCKCHIP_IO_DOMAIN |
|---|
| 503 | 537 | io_domain_init(); |
|---|
| 504 | 538 | #endif |
|---|
| 505 | | - |
|---|
| 506 | 539 | set_armclk_rate(); |
|---|
| 507 | | - |
|---|
| 508 | 540 | #ifdef CONFIG_DM_DVFS |
|---|
| 509 | 541 | dvfs_init(true); |
|---|
| 510 | 542 | #endif |
|---|
| 511 | | - |
|---|
| 512 | 543 | #ifdef CONFIG_ANDROID_AB |
|---|
| 513 | 544 | if (ab_decrease_tries()) |
|---|
| 514 | 545 | printf("Decrease ab tries count fail!\n"); |
|---|
| .. | .. |
|---|
| 537 | 568 | /* Common fixup for DRM */ |
|---|
| 538 | 569 | #ifdef CONFIG_DRM_ROCKCHIP |
|---|
| 539 | 570 | rockchip_display_fixup(blob); |
|---|
| 571 | +#endif |
|---|
| 572 | + |
|---|
| 573 | +#ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION |
|---|
| 574 | + vendor_storage_fixup(blob); |
|---|
| 540 | 575 | #endif |
|---|
| 541 | 576 | |
|---|
| 542 | 577 | return rk_board_fdt_fixup(blob); |
|---|
| .. | .. |
|---|
| 603 | 638 | * But relocation is in board_quiesce_devices() until all decompress |
|---|
| 604 | 639 | * done, mainly for saving boot time. |
|---|
| 605 | 640 | */ |
|---|
| 641 | + |
|---|
| 642 | + orig_images_ep = images->ep; |
|---|
| 643 | + |
|---|
| 606 | 644 | if (data[10] == 0x00) { |
|---|
| 607 | 645 | if (round_down(images->ep, SZ_2M) != images->ep) |
|---|
| 608 | 646 | images->ep = round_down(images->ep, SZ_2M); |
|---|
| .. | .. |
|---|
| 736 | 774 | return boot_flags; |
|---|
| 737 | 775 | } |
|---|
| 738 | 776 | |
|---|
| 739 | | -#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) |
|---|
| 740 | | -#include <fdt_support.h> |
|---|
| 777 | +#if defined(CONFIG_USB_GADGET) |
|---|
| 741 | 778 | #include <usb.h> |
|---|
| 779 | +#if defined(CONFIG_USB_GADGET_DWC2_OTG) |
|---|
| 780 | +#include <fdt_support.h> |
|---|
| 742 | 781 | #include <usb/dwc2_udc.h> |
|---|
| 743 | 782 | |
|---|
| 744 | 783 | static struct dwc2_plat_otg_data otg_data = { |
|---|
| .. | .. |
|---|
| 808 | 847 | { |
|---|
| 809 | 848 | return 0; |
|---|
| 810 | 849 | } |
|---|
| 811 | | -#endif |
|---|
| 850 | +#elif defined(CONFIG_USB_DWC3_GADGET) /* CONFIG_USB_GADGET_DWC2_OTG */ |
|---|
| 851 | +#include <dwc3-uboot.h> |
|---|
| 852 | + |
|---|
| 853 | +int board_usb_cleanup(int index, enum usb_init_type init) |
|---|
| 854 | +{ |
|---|
| 855 | + dwc3_uboot_exit(index); |
|---|
| 856 | + return 0; |
|---|
| 857 | +} |
|---|
| 858 | + |
|---|
| 859 | +#endif /* CONFIG_USB_DWC3_GADGET */ |
|---|
| 860 | +#endif /* CONFIG_USB_GADGET */ |
|---|
| 812 | 861 | |
|---|
| 813 | 862 | static void bootm_no_reloc(void) |
|---|
| 814 | 863 | { |
|---|
| .. | .. |
|---|
| 1049 | 1098 | #endif |
|---|
| 1050 | 1099 | #ifdef CONFIG_ARM64 |
|---|
| 1051 | 1100 | bootm_headers_t *bootm_images = (bootm_headers_t *)images; |
|---|
| 1052 | | - ulong kernel_addr; |
|---|
| 1053 | 1101 | |
|---|
| 1054 | 1102 | /* relocate kernel after decompress cleanup */ |
|---|
| 1055 | | - kernel_addr = env_get_ulong("kernel_addr_r", 16, 0); |
|---|
| 1056 | | - if (kernel_addr != bootm_images->ep) { |
|---|
| 1057 | | - memmove((char *)bootm_images->ep, (const char *)kernel_addr, |
|---|
| 1103 | + if (orig_images_ep && orig_images_ep != bootm_images->ep) { |
|---|
| 1104 | + memmove((char *)bootm_images->ep, (const char *)orig_images_ep, |
|---|
| 1058 | 1105 | bootm_images->os.image_len); |
|---|
| 1059 | 1106 | printf("== DO RELOCATE == Kernel from 0x%08lx to 0x%08lx\n", |
|---|
| 1060 | | - kernel_addr, bootm_images->ep); |
|---|
| 1107 | + orig_images_ep, bootm_images->ep); |
|---|
| 1061 | 1108 | } |
|---|
| 1062 | 1109 | #endif |
|---|
| 1063 | 1110 | |
|---|
| .. | .. |
|---|
| 1109 | 1156 | #endif |
|---|
| 1110 | 1157 | } |
|---|
| 1111 | 1158 | |
|---|
| 1112 | | -#ifdef CONFIG_ENVF |
|---|
| 1113 | | - char * sys_bootargs; |
|---|
| 1159 | +#if defined(CONFIG_ENVF) || defined(CONFIG_ENV_PARTITION) |
|---|
| 1160 | + char *part_type[] = { "mtdparts", "blkdevparts" }; |
|---|
| 1161 | + char *part_list; |
|---|
| 1162 | + char *env; |
|---|
| 1163 | + int id = 0; |
|---|
| 1114 | 1164 | |
|---|
| 1115 | | - sys_bootargs = env_get("sys_bootargs"); |
|---|
| 1116 | | - if (sys_bootargs) { |
|---|
| 1117 | | - env_update("bootargs", sys_bootargs); |
|---|
| 1165 | + env = env_get(part_type[id]); |
|---|
| 1166 | + if (!env) |
|---|
| 1167 | + env = env_get(part_type[++id]); |
|---|
| 1168 | + if (env) { |
|---|
| 1169 | + if (!strstr(env, part_type[id])) { |
|---|
| 1170 | + part_list = calloc(1, strlen(env) + strlen(part_type[id]) + 2); |
|---|
| 1171 | + if (part_list) { |
|---|
| 1172 | + strcat(part_list, part_type[id]); |
|---|
| 1173 | + strcat(part_list, "="); |
|---|
| 1174 | + strcat(part_list, env); |
|---|
| 1175 | + } |
|---|
| 1176 | + } else { |
|---|
| 1177 | + part_list = env; |
|---|
| 1178 | + } |
|---|
| 1179 | + env_update("bootargs", part_list); |
|---|
| 1118 | 1180 | if (dump) |
|---|
| 1119 | | - printf("## sys_bootargs: %s\n\n", sys_bootargs); |
|---|
| 1181 | + printf("## parts: %s\n\n", part_list); |
|---|
| 1182 | + } |
|---|
| 1183 | + |
|---|
| 1184 | + env = env_get("sys_bootargs"); |
|---|
| 1185 | + if (env) { |
|---|
| 1186 | + env_update("bootargs", env); |
|---|
| 1187 | + if (dump) |
|---|
| 1188 | + printf("## sys_bootargs: %s\n\n", env); |
|---|
| 1120 | 1189 | } |
|---|
| 1121 | 1190 | #endif |
|---|
| 1191 | + |
|---|
| 1122 | 1192 | #ifdef CONFIG_MTD_BLK |
|---|
| 1123 | 1193 | if (!env_get("mtdparts")) { |
|---|
| 1124 | 1194 | char *mtd_par_info = mtd_part_parse(NULL); |
|---|
| .. | .. |
|---|
| 1129 | 1199 | } |
|---|
| 1130 | 1200 | } |
|---|
| 1131 | 1201 | #endif |
|---|
| 1202 | + |
|---|
| 1203 | +#ifdef CONFIG_ANDROID_AB |
|---|
| 1204 | + ab_update_root_partition(); |
|---|
| 1205 | +#endif |
|---|
| 1132 | 1206 | /* |
|---|
| 1133 | 1207 | * Initrd fixup: remove unused "initrd=0x...,0x...", |
|---|
| 1134 | 1208 | * this for compatible with legacy parameter.txt |
|---|