1 /* 2 * (C) Copyright 2017 Rockchip Electronics Co., Ltd. 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <version.h> 9 #include <abuf.h> 10 #include <amp.h> 11 #include <android_ab.h> 12 #include <android_bootloader.h> 13 #include <android_image.h> 14 #include <bidram.h> 15 #include <boot_rkimg.h> 16 #include <cli.h> 17 #include <clk.h> 18 #include <console.h> 19 #include <debug_uart.h> 20 #include <dm.h> 21 #include <dvfs.h> 22 #include <fdt_support.h> 23 #include <io-domain.h> 24 #include <image.h> 25 #include <key.h> 26 #include <memblk.h> 27 #include <misc.h> 28 #include <of_live.h> 29 #include <mtd_blk.h> 30 #include <ram.h> 31 #include <rng.h> 32 #include <rockchip_debugger.h> 33 #include <syscon.h> 34 #include <sysmem.h> 35 #include <video_rockchip.h> 36 #include <xbc.h> 37 #include <asm/io.h> 38 #include <asm/gpio.h> 39 #include <android_avb/rk_avb_ops_user.h> 40 #include <dm/uclass-internal.h> 41 #include <dm/root.h> 42 #include <power/charge_display.h> 43 #include <power/regulator.h> 44 #include <optee_include/OpteeClientInterface.h> 45 #include <optee_include/OpteeClientApiLib.h> 46 #include <optee_include/tee_api_defines.h> 47 #include <asm/arch/boot_mode.h> 48 #include <asm/arch/clock.h> 49 #include <asm/arch/cpu.h> 50 #include <asm/arch/hotkey.h> 51 #include <asm/arch/param.h> 52 #include <asm/arch/periph.h> 53 #include <asm/arch/resource_img.h> 54 #include <asm/arch/rk_atags.h> 55 #include <asm/arch/vendor.h> 56 #ifdef CONFIG_ROCKCHIP_EINK_DISPLAY 57 #include <rk_eink.h> 58 #endif 59 60 #ifdef CONFIG_SERDES_DISPLAY 61 #include <serdes-display-core.h> 62 #include <serdes-display-gpio.h> 63 #endif 64 65 #ifdef CONFIG_ROCKCHIP_MINIDUMP 66 #include <rk_mini_dump.h> 67 #endif 68 69 #ifdef CONFIG_ARM64 70 static ulong orig_images_ep; 71 #endif 72 73 __weak int rk_board_late_init(void) 74 { 75 return 0; 76 } 77 78 __weak int rk_board_fdt_fixup(void *blob) 79 { 80 return 0; 81 } 82 83 __weak int rk_board_dm_fdt_fixup(void *blob) 84 { 85 return 0; 86 } 87 88 __weak int soc_clk_dump(void) 89 { 90 return 0; 91 } 92 93 __weak int set_armclk_rate(void) 94 { 95 return 0; 96 } 97 98 __weak int rk_board_init(void) 99 { 100 return 0; 101 } 102 103 #ifdef CONFIG_ROCKCHIP_SET_ETHADDR 104 /* 105 * define serialno max length, the max length is 512 Bytes 106 * The remaining bytes are used to ensure that the first 512 bytes 107 * are valid when executing 'env_set("serial#", value)'. 108 */ 109 #define VENDOR_SN_MAX 513 110 #define CPUID_LEN 0x10 111 112 #define MAX_ETHERNET 0x2 113 114 static int rockchip_set_ethaddr(void) 115 { 116 __maybe_unused bool need_write = false; 117 bool randomed = false; 118 char buf[ARP_HLEN_ASCII + 1], mac[16]; 119 u8 ethaddr[ARP_HLEN * MAX_ETHERNET] = {0}; 120 int i, ret = -EINVAL; 121 122 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION 123 ret = vendor_storage_read(LAN_MAC_ID, ethaddr, sizeof(ethaddr)); 124 #endif 125 for (i = 0; i < MAX_ETHERNET; i++) { 126 if (ret <= 0 || !is_valid_ethaddr(ðaddr[i * ARP_HLEN])) { 127 if (!randomed) { 128 net_random_ethaddr(ðaddr[i * ARP_HLEN]); 129 randomed = true; 130 } else { 131 if (i > 0) { 132 memcpy(ðaddr[i * ARP_HLEN], 133 ðaddr[(i - 1) * ARP_HLEN], 134 ARP_HLEN); 135 ethaddr[i * ARP_HLEN] |= 0x02; 136 ethaddr[i * ARP_HLEN] += (i << 2); 137 } 138 } 139 140 need_write = true; 141 } 142 143 if (is_valid_ethaddr(ðaddr[i * ARP_HLEN])) { 144 snprintf(buf, ARP_HLEN_ASCII + 1, "%pM", ðaddr[i * ARP_HLEN]); 145 if (i == 0) 146 memcpy(mac, "ethaddr", sizeof("ethaddr")); 147 else 148 sprintf(mac, "eth%daddr", i); 149 env_set(mac, buf); 150 } 151 } 152 153 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION 154 if (need_write) { 155 ret = vendor_storage_write(LAN_MAC_ID, 156 ethaddr, sizeof(ethaddr)); 157 if (ret < 0) 158 printf("%s: vendor_storage_write failed %d\n", 159 __func__, ret); 160 } 161 #endif 162 return 0; 163 } 164 #endif 165 166 #ifdef CONFIG_ROCKCHIP_SET_SN 167 static int rockchip_set_serialno(void) 168 { 169 u8 low[CPUID_LEN / 2], high[CPUID_LEN / 2]; 170 u8 cpuid[CPUID_LEN] = {0}; 171 char serialno_str[VENDOR_SN_MAX]; 172 int ret = 0, i; 173 u64 serialno; 174 175 /* Read serial number from vendor storage part */ 176 memset(serialno_str, 0, VENDOR_SN_MAX); 177 178 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION 179 int j; 180 181 ret = vendor_storage_read(SN_ID, serialno_str, (VENDOR_SN_MAX-1)); 182 if (ret > 0) { 183 j = strlen(serialno_str); 184 for (i = 0; i < j; i++) { 185 if ((serialno_str[i] >= 'a' && serialno_str[i] <= 'z') || 186 (serialno_str[i] >= 'A' && serialno_str[i] <= 'Z') || 187 (serialno_str[i] >= '0' && serialno_str[i] <= '9')) { 188 continue; 189 } else { 190 if (i > 0) 191 serialno_str[i] = 0x0; 192 break; 193 } 194 } 195 196 /* valid character count > 0 */ 197 if (i > 0) { 198 serialno_str[i + 1] = 0x0; 199 env_set("serial#", serialno_str); 200 } 201 } 202 #endif 203 if (!env_get("serial#")) { 204 #if defined(CONFIG_ROCKCHIP_EFUSE) || defined(CONFIG_ROCKCHIP_OTP) 205 struct udevice *dev; 206 207 /* retrieve the device */ 208 if (IS_ENABLED(CONFIG_ROCKCHIP_EFUSE)) 209 ret = uclass_get_device_by_driver(UCLASS_MISC, 210 DM_GET_DRIVER(rockchip_efuse), 211 &dev); 212 else 213 ret = uclass_get_device_by_driver(UCLASS_MISC, 214 DM_GET_DRIVER(rockchip_otp), 215 &dev); 216 217 if (ret) { 218 printf("%s: could not find efuse/otp device\n", __func__); 219 return ret; 220 } 221 222 /* read the cpu_id range from the efuses */ 223 ret = misc_read(dev, CFG_CPUID_OFFSET, &cpuid, sizeof(cpuid)); 224 if (ret) { 225 printf("%s: read cpuid from efuse/otp failed, ret=%d\n", 226 __func__, ret); 227 return ret; 228 } 229 #else 230 /* generate random cpuid */ 231 for (i = 0; i < CPUID_LEN; i++) 232 cpuid[i] = (u8)(rand()); 233 #endif 234 /* Generate the serial number based on CPU ID */ 235 for (i = 0; i < 8; i++) { 236 low[i] = cpuid[1 + (i << 1)]; 237 high[i] = cpuid[i << 1]; 238 } 239 240 serialno = crc32_no_comp(0, low, 8); 241 serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32; 242 snprintf(serialno_str, sizeof(serialno_str), "%llx", serialno); 243 244 env_set("serial#", serialno_str); 245 } 246 247 return ret; 248 } 249 #endif 250 251 #if defined(CONFIG_USB_FUNCTION_FASTBOOT) 252 int fb_set_reboot_flag(void) 253 { 254 printf("Setting reboot to fastboot flag ...\n"); 255 writel(BOOT_FASTBOOT, CONFIG_ROCKCHIP_BOOT_MODE_REG); 256 257 return 0; 258 } 259 #endif 260 261 #ifdef CONFIG_ROCKCHIP_USB_BOOT 262 static int boot_from_udisk(void) 263 { 264 struct blk_desc *desc; 265 struct udevice *dev; 266 int devnum = -1; 267 char buf[32]; 268 269 /* Booting priority: mmc1 > udisk */ 270 if (!strcmp(env_get("devtype"), "mmc") && !strcmp(env_get("devnum"), "1")) 271 return 0; 272 273 if (!run_command("usb start", -1)) { 274 for (blk_first_device(IF_TYPE_USB, &dev); 275 dev; 276 blk_next_device(&dev)) { 277 desc = dev_get_uclass_platdata(dev); 278 printf("Scanning usb %d ...\n", desc->devnum); 279 if (desc->type == DEV_TYPE_UNKNOWN) 280 continue; 281 282 if (desc->lba > 0L && desc->blksz > 0L) { 283 devnum = desc->devnum; 284 break; 285 } 286 } 287 if (devnum < 0) { 288 printf("No usb mass storage found\n"); 289 return -ENODEV; 290 } 291 292 desc = blk_get_devnum_by_type(IF_TYPE_USB, devnum); 293 if (!desc) { 294 printf("No usb %d found\n", devnum); 295 return -ENODEV; 296 } 297 298 snprintf(buf, 32, "rkimgtest usb %d", devnum); 299 if (!run_command(buf, -1)) { 300 snprintf(buf, 32, "%d", devnum); 301 rockchip_set_bootdev(desc); 302 env_set("devtype", "usb"); 303 env_set("devnum", buf); 304 printf("=== Booting from usb %d ===\n", devnum); 305 } else { 306 printf("No available udisk image on usb %d\n", devnum); 307 return -ENODEV; 308 } 309 } 310 311 return 0; 312 } 313 #endif 314 315 static void env_fixup(void) 316 { 317 struct memblock mem; 318 ulong u_addr_r; 319 phys_size_t end; 320 char *addr_r; 321 322 #ifdef ENV_MEM_LAYOUT_SETTINGS1 323 const char *env_addr0[] = { 324 "scriptaddr", "pxefile_addr_r", 325 "fdt_addr_r", "kernel_addr_r", "ramdisk_addr_r", 326 }; 327 const char *env_addr1[] = { 328 "scriptaddr1", "pxefile_addr1_r", 329 "fdt_addr1_r", "kernel_addr1_r", "ramdisk_addr1_r", 330 }; 331 int i; 332 333 /* 128M is a typical ram size for most platform, so as default here */ 334 if (gd->ram_size <= SZ_128M) { 335 /* Replace orignal xxx_addr_r */ 336 for (i = 0; i < ARRAY_SIZE(env_addr1); i++) { 337 addr_r = env_get(env_addr1[i]); 338 if (addr_r) 339 env_set(env_addr0[i], addr_r); 340 } 341 } 342 #endif 343 /* No BL32 ? */ 344 if (!(gd->flags & GD_FLG_BL32_ENABLED)) { 345 /* 346 * [1] Move kernel to lower address if possible. 347 */ 348 addr_r = env_get("kernel_addr_no_low_bl32_r"); 349 if (addr_r) 350 env_set("kernel_addr_r", addr_r); 351 352 /* 353 * [2] Move ramdisk at BL32 position if need. 354 * 355 * 0x0a200000 and 0x08400000 are rockchip traditional address 356 * of BL32 and ramdisk: 357 * 358 * |------------|------------| 359 * | BL32 | ramdisk | 360 * |------------|------------| 361 * 362 * Move ramdisk to BL32 address to fix sysmem alloc failed 363 * issue on the board with critical memory(ie. 256MB). 364 */ 365 if (gd->ram_size > SZ_128M && gd->ram_size <= SZ_256M) { 366 u_addr_r = env_get_ulong("ramdisk_addr_r", 16, 0); 367 if (u_addr_r == 0x0a200000) 368 env_set("ramdisk_addr_r", "0x08400000"); 369 } 370 } else { 371 mem = param_parse_optee_mem(); 372 373 /* 374 * [1] Move kernel forward if possible. 375 */ 376 if (mem.base > SZ_128M) { 377 addr_r = env_get("kernel_addr_no_low_bl32_r"); 378 if (addr_r) 379 env_set("kernel_addr_r", addr_r); 380 } 381 382 /* 383 * [2] Move ramdisk backward if optee enlarge. 384 */ 385 end = mem.base + mem.size; 386 u_addr_r = env_get_ulong("ramdisk_addr_r", 16, 0); 387 if (u_addr_r >= mem.base && u_addr_r < end) 388 env_set_hex("ramdisk_addr_r", end); 389 } 390 } 391 392 static void cmdline_handle(void) 393 { 394 struct blk_desc *dev_desc; 395 int if_type; 396 int devnum; 397 398 param_parse_pubkey_fuse_programmed(); 399 400 dev_desc = rockchip_get_bootdev(); 401 if (!dev_desc) 402 return; 403 404 /* 405 * 1. From rk356x, the sd/udisk recovery update flag was moved from 406 * IDB to Android BCB. 407 * 408 * 2. Udisk is init at the late boot_from_udisk(), but 409 * rockchip_get_boot_mode() actually only read once, 410 * we need to update boot mode according to udisk BCB. 411 */ 412 if_type = dev_desc->if_type; 413 devnum = dev_desc->devnum; 414 if ((if_type == IF_TYPE_MMC && devnum == 1) || (if_type == IF_TYPE_USB)) { 415 if (get_bcb_recovery_msg() == BCB_MSG_RECOVERY_RK_FWUPDATE) { 416 if (if_type == IF_TYPE_MMC && devnum == 1) { 417 env_update("bootargs", "sdfwupdate"); 418 } else if (if_type == IF_TYPE_USB) { 419 env_update("bootargs", "usbfwupdate"); 420 env_set("reboot_mode", "recovery-usb"); 421 } 422 } else { 423 if (if_type == IF_TYPE_USB) 424 env_set("reboot_mode", "normal"); 425 } 426 } 427 428 if (rockchip_get_boot_mode() == BOOT_MODE_QUIESCENT) 429 env_update("bootargs", "androidboot.quiescent=1 pwm_bl.quiescent=1"); 430 } 431 432 static void scan_run_cmd(void) 433 { 434 char *config = CONFIG_ROCKCHIP_CMD; 435 char *cmd, *key; 436 437 key = strchr(config, ' '); 438 if (!key) 439 return; 440 441 cmd = strdup(config); 442 cmd[key - config] = 0; 443 key++; 444 445 if (!strcmp(key, "-")) { 446 run_command(cmd, 0); 447 } else { 448 #ifdef CONFIG_DM_KEY 449 ulong map; 450 451 map = simple_strtoul(key, NULL, 10); 452 if (key_is_pressed(key_read(map))) { 453 printf("## Key<%ld> pressed... run cmd '%s'\n", map, cmd); 454 run_command(cmd, 0); 455 } 456 #endif 457 } 458 } 459 460 int board_late_init(void) 461 { 462 #ifdef CONFIG_ROCKCHIP_SET_ETHADDR 463 rockchip_set_ethaddr(); 464 #endif 465 #ifdef CONFIG_ROCKCHIP_SET_SN 466 rockchip_set_serialno(); 467 #endif 468 setup_download_mode(); 469 scan_run_cmd(); 470 #ifdef CONFIG_ROCKCHIP_USB_BOOT 471 boot_from_udisk(); 472 #endif 473 #ifdef CONFIG_DM_CHARGE_DISPLAY 474 charge_display(); 475 #endif 476 477 #ifdef CONFIG_ROCKCHIP_MINIDUMP 478 rk_minidump_init(); 479 #endif 480 481 #ifdef CONFIG_DRM_ROCKCHIP 482 if (rockchip_get_boot_mode() != BOOT_MODE_QUIESCENT) 483 rockchip_show_logo(); 484 #endif 485 #ifdef CONFIG_ROCKCHIP_EINK_DISPLAY 486 rockchip_eink_show_uboot_logo(); 487 #endif 488 #if (CONFIG_ROCKCHIP_BOOT_MODE_REG > 0) 489 setup_boot_mode(); 490 #endif 491 env_fixup(); 492 soc_clk_dump(); 493 cmdline_handle(); 494 #ifdef CONFIG_AMP 495 amp_cpus_on(); 496 #endif 497 return rk_board_late_init(); 498 } 499 500 static void early_download(void) 501 { 502 #if defined(CONFIG_PWRKEY_DNL_TRIGGER_NUM) && \ 503 (CONFIG_PWRKEY_DNL_TRIGGER_NUM > 0) 504 if (pwrkey_download_init()) 505 printf("Pwrkey download init failed\n"); 506 #endif 507 508 #if (CONFIG_ROCKCHIP_BOOT_MODE_REG > 0) 509 if (is_hotkey(HK_BROM_DNL)) { 510 printf("Enter bootrom download..."); 511 flushc(); 512 writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG); 513 do_reset(NULL, 0, 0, NULL); 514 printf("failed!\n"); 515 } 516 #endif 517 } 518 519 static void board_debug_init(void) 520 { 521 if (!gd->serial.using_pre_serial && 522 !(gd->flags & GD_FLG_DISABLE_CONSOLE)) 523 debug_uart_init(); 524 525 if (tstc()) { 526 gd->console_evt = getc(); 527 if (gd->console_evt <= 0x1a) /* 'z' */ 528 printf("Hotkey: ctrl+%c\n", gd->console_evt + 'a' - 1); 529 } 530 531 if (IS_ENABLED(CONFIG_CONSOLE_DISABLE_CLI)) 532 printf("Cmd interface: disabled\n"); 533 } 534 535 int board_init(void) 536 { 537 board_debug_init(); 538 #ifdef DEBUG 539 soc_clk_dump(); 540 #endif 541 #ifdef CONFIG_OPTEE_CLIENT 542 optee_client_init(); 543 #endif 544 #ifdef CONFIG_USING_KERNEL_DTB 545 init_kernel_dtb(); 546 #endif 547 early_download(); 548 549 clks_probe(); 550 #ifdef CONFIG_DM_REGULATOR 551 regulators_enable_boot_on(is_hotkey(HK_REGULATOR)); 552 #endif 553 #ifdef CONFIG_ROCKCHIP_IO_DOMAIN 554 io_domain_init(); 555 #endif 556 set_armclk_rate(); 557 #ifdef CONFIG_DM_DVFS 558 dvfs_init(true); 559 #endif 560 #ifdef CONFIG_ANDROID_AB 561 if (ab_decrease_tries()) 562 printf("Decrease ab tries count fail!\n"); 563 #endif 564 #ifdef CONFIG_SERDES_DISPLAY 565 serdes_power_init(); 566 #endif 567 return rk_board_init(); 568 } 569 570 int interrupt_debugger_init(void) 571 { 572 #ifdef CONFIG_ROCKCHIP_DEBUGGER 573 return rockchip_debugger_init(); 574 #else 575 return 0; 576 #endif 577 } 578 579 int board_fdt_fixup(void *blob) 580 { 581 /* 582 * Device's platdata points to orignal fdt blob property, 583 * access DM device before any fdt fixup. 584 */ 585 rk_board_dm_fdt_fixup(blob); 586 587 /* Common fixup for DRM */ 588 #ifdef CONFIG_DRM_ROCKCHIP 589 rockchip_display_fixup(blob); 590 #endif 591 592 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION 593 vendor_storage_fixup(blob); 594 #endif 595 596 return rk_board_fdt_fixup(blob); 597 } 598 599 #if defined(CONFIG_ARM64_BOOT_AARCH32) || !defined(CONFIG_ARM64) 600 /* 601 * Common for OP-TEE: 602 * 64-bit & 32-bit mode: share memory dcache is always enabled; 603 * 604 * Common for U-Boot: 605 * 64-bit mode: MMU table is static defined in rkxxx.c file, all memory 606 * regions are mapped. That's good to match OP-TEE MMU policy. 607 * 608 * 32-bit mode: MMU table is setup according to gd->bd->bi_dram[..] where 609 * the OP-TEE region has been reserved, so it can not be 610 * mapped(i.e. dcache is disabled). That's *NOT* good to match 611 * OP-TEE MMU policy. 612 * 613 * For the data coherence when communication between U-Boot and OP-TEE, U-Boot 614 * should follow OP-TEE MMU policy. 615 * 616 * So 32-bit mode U-Boot should map OP-TEE share memory as dcache enabled. 617 */ 618 int board_initr_caches_fixup(void) 619 { 620 #ifdef CONFIG_OPTEE_CLIENT 621 struct memblock mem; 622 623 mem.base = 0; 624 mem.size = 0; 625 626 optee_get_shm_config(&mem.base, &mem.size); 627 if (mem.size) 628 mmu_set_region_dcache_behaviour(mem.base, mem.size, 629 DCACHE_WRITEBACK); 630 #endif 631 return 0; 632 } 633 #endif 634 635 void arch_preboot_os(uint32_t bootm_state, bootm_headers_t *images) 636 { 637 if (!(bootm_state & BOOTM_STATE_OS_PREP)) 638 return; 639 640 #ifdef CONFIG_ARM64 641 u8 *data = (void *)images->ep; 642 643 /* 644 * Fix kernel 5.10 arm64 boot warning: 645 * "[Firmware Bug]: Kernel image misaligned at boot, please fix your bootloader!" 646 * 647 * kernel: 5.10 commit 120dc60d0bdb ("arm64: get rid of TEXT_OFFSET") 648 * arm64 kernel version: 649 * data[10] == 0x00 if kernel version >= 5.10: N*2MB align 650 * data[10] == 0x08 if kernel version < 5.10: N*2MB + 0x80000(TEXT_OFFSET) 651 * 652 * Why fix here? 653 * 1. this is the common and final path for any boot command. 654 * 2. don't influence original boot flow, just fix it exactly before 655 * jumping kernel. 656 * 657 * But relocation is in board_quiesce_devices() until all decompress 658 * done, mainly for saving boot time. 659 */ 660 661 orig_images_ep = images->ep; 662 663 if (data[10] == 0x00) { 664 if (round_down(images->ep, SZ_2M) != images->ep) 665 images->ep = round_down(images->ep, SZ_2M); 666 } else { 667 if (IS_ALIGNED(images->ep, SZ_2M)) 668 images->ep += 0x80000; 669 } 670 #endif 671 hotkey_run(HK_CLI_OS_PRE); 672 } 673 674 void enable_caches(void) 675 { 676 icache_enable(); 677 dcache_enable(); 678 } 679 680 #ifdef CONFIG_LMB 681 /* 682 * Using last bi_dram[...] to initialize "bootm_low" and "bootm_mapsize". 683 * This makes lmb_alloc_base() always alloc from tail of sdram. 684 * If we don't assign it, bi_dram[0] is used by default and it may cause 685 * lmb_alloc_base() fail when bi_dram[0] range is small. 686 */ 687 void board_lmb_reserve(struct lmb *lmb) 688 { 689 char bootm_mapsize[32]; 690 char bootm_low[32]; 691 u64 start, size; 692 int i; 693 694 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { 695 if (!gd->bd->bi_dram[i].size) 696 break; 697 } 698 699 start = gd->bd->bi_dram[i - 1].start; 700 size = gd->bd->bi_dram[i - 1].size; 701 702 /* 703 * 32-bit kernel: ramdisk/fdt shouldn't be loaded to highmem area(768MB+), 704 * otherwise "Unable to handle kernel paging request at virtual address ...". 705 * 706 * So that we hope limit highest address at 768M, but there comes the the 707 * problem: ramdisk is a compressed image and it expands after descompress, 708 * so it accesses 768MB+ and brings the above "Unable to handle kernel ...". 709 * 710 * We make a appointment that the highest memory address is 512MB, it 711 * makes lmb alloc safer. 712 */ 713 #ifndef CONFIG_ARM64 714 if (start >= ((u64)CONFIG_SYS_SDRAM_BASE + SZ_512M)) { 715 start = gd->bd->bi_dram[i - 2].start; 716 size = gd->bd->bi_dram[i - 2].size; 717 } 718 719 if ((start + size) > ((u64)CONFIG_SYS_SDRAM_BASE + SZ_512M)) 720 size = (u64)CONFIG_SYS_SDRAM_BASE + SZ_512M - start; 721 #endif 722 sprintf(bootm_low, "0x%llx", start); 723 sprintf(bootm_mapsize, "0x%llx", size); 724 env_set("bootm_low", bootm_low); 725 env_set("bootm_mapsize", bootm_mapsize); 726 } 727 #endif 728 729 #ifdef CONFIG_BIDRAM 730 int board_bidram_reserve(struct bidram *bidram) 731 { 732 struct memblock mem; 733 int ret; 734 735 /* ATF */ 736 mem = param_parse_atf_mem(); 737 ret = bidram_reserve(MEM_ATF, mem.base, mem.size); 738 if (ret) 739 return ret; 740 741 /* PSTORE/ATAGS/SHM */ 742 mem = param_parse_common_resv_mem(); 743 ret = bidram_reserve(MEM_SHM, mem.base, mem.size); 744 if (ret) 745 return ret; 746 747 /* OP-TEE */ 748 mem = param_parse_optee_mem(); 749 ret = bidram_reserve(MEM_OPTEE, mem.base, mem.size); 750 if (ret) 751 return ret; 752 753 return 0; 754 } 755 756 #ifdef CONFIG_SYSMEM 757 int board_sysmem_reserve(struct sysmem *sysmem) 758 { 759 #ifdef CONFIG_SKIP_RELOCATE_UBOOT 760 if (!sysmem_alloc_base_by_name("NO-RELOC-CODE", 761 CONFIG_SYS_TEXT_BASE, SZ_2M)) { 762 printf("Failed to reserve sysmem for U-Boot code\n"); 763 return -ENOMEM; 764 } 765 #endif 766 return 0; 767 } 768 #endif 769 770 parse_fn_t board_bidram_parse_fn(void) 771 { 772 return param_parse_ddr_mem; 773 } 774 #endif 775 776 int board_init_f_boot_flags(void) 777 { 778 int boot_flags = 0; 779 780 #ifdef CONFIG_FPGA_ROCKCHIP 781 arch_fpga_init(); 782 #endif 783 #ifdef CONFIG_PSTORE 784 param_parse_pstore(); 785 #endif 786 param_parse_pre_serial(&boot_flags); 787 788 /* The highest priority to turn off (override) console */ 789 #if defined(CONFIG_DISABLE_CONSOLE) 790 boot_flags |= GD_FLG_DISABLE_CONSOLE; 791 #endif 792 793 return boot_flags; 794 } 795 796 #if defined(CONFIG_USB_GADGET) 797 #include <usb.h> 798 #if defined(CONFIG_USB_GADGET_DWC2_OTG) 799 #include <fdt_support.h> 800 #include <usb/dwc2_udc.h> 801 802 static struct dwc2_plat_otg_data otg_data = { 803 .rx_fifo_sz = 512, 804 .np_tx_fifo_sz = 16, 805 .tx_fifo_sz = 128, 806 }; 807 808 int board_usb_init(int index, enum usb_init_type init) 809 { 810 const void *blob = gd->fdt_blob; 811 const fdt32_t *reg; 812 fdt_addr_t addr; 813 int node; 814 815 /* find the usb_otg node */ 816 node = fdt_node_offset_by_compatible(blob, -1, "snps,dwc2"); 817 818 retry: 819 if (node > 0) { 820 reg = fdt_getprop(blob, node, "reg", NULL); 821 if (!reg) 822 return -EINVAL; 823 824 addr = fdt_translate_address(blob, node, reg); 825 if (addr == OF_BAD_ADDR) { 826 pr_err("Not found usb_otg address\n"); 827 return -EINVAL; 828 } 829 830 #if defined(CONFIG_ROCKCHIP_RK3288) 831 if (addr != 0xff580000) { 832 node = fdt_node_offset_by_compatible(blob, node, 833 "snps,dwc2"); 834 goto retry; 835 } 836 #endif 837 } else { 838 /* 839 * With kernel dtb support, rk3288 dwc2 otg node 840 * use the rockchip legacy dwc2 driver "dwc_otg_310" 841 * with the compatible "rockchip,rk3288_usb20_otg", 842 * and rk3368 also use the "dwc_otg_310" driver with 843 * the compatible "rockchip,rk3368-usb". 844 */ 845 #if defined(CONFIG_ROCKCHIP_RK3288) 846 node = fdt_node_offset_by_compatible(blob, -1, 847 "rockchip,rk3288_usb20_otg"); 848 #elif defined(CONFIG_ROCKCHIP_RK3368) 849 node = fdt_node_offset_by_compatible(blob, -1, 850 "rockchip,rk3368-usb"); 851 #endif 852 if (node > 0) { 853 goto retry; 854 } else { 855 pr_err("Not found usb_otg device\n"); 856 return -ENODEV; 857 } 858 } 859 860 otg_data.regs_otg = (uintptr_t)addr; 861 862 return dwc2_udc_probe(&otg_data); 863 } 864 865 int board_usb_cleanup(int index, enum usb_init_type init) 866 { 867 return 0; 868 } 869 #elif defined(CONFIG_USB_DWC3_GADGET) /* CONFIG_USB_GADGET_DWC2_OTG */ 870 #include <dwc3-uboot.h> 871 872 int board_usb_cleanup(int index, enum usb_init_type init) 873 { 874 dwc3_uboot_exit(index); 875 return 0; 876 } 877 878 #endif /* CONFIG_USB_DWC3_GADGET */ 879 #endif /* CONFIG_USB_GADGET */ 880 881 static void bootm_no_reloc(void) 882 { 883 char *ramdisk_high; 884 char *fdt_high; 885 886 if (!env_get_yesno("bootm-no-reloc")) 887 return; 888 889 ramdisk_high = env_get("initrd_high"); 890 fdt_high = env_get("fdt_high"); 891 892 if (!fdt_high) { 893 env_set_hex("fdt_high", -1UL); 894 printf("Fdt "); 895 } 896 897 if (!ramdisk_high) { 898 env_set_hex("initrd_high", -1UL); 899 printf("Ramdisk "); 900 } 901 902 if (!fdt_high || !ramdisk_high) 903 printf("skip relocation\n"); 904 } 905 906 int bootm_board_start(void) 907 { 908 /* 909 * print console record data 910 * 911 * On some rockchip platforms, uart debug and sdmmc pin are multiplex. 912 * If boot from sdmmc mode, the console data would be record in buffer, 913 * we switch to uart debug function in order to print it after loading 914 * images. 915 */ 916 #if 0 917 if (!strcmp("mmc", env_get("devtype")) && 918 !strcmp("1", env_get("devnum"))) { 919 printf("IOMUX: sdmmc => uart debug"); 920 pinctrl_select_state(gd->cur_serial_dev, "default"); 921 console_record_print_purge(); 922 } 923 #endif 924 /* disable bootm relcation to save boot time */ 925 bootm_no_reloc(); 926 927 /* PCBA test needs more permission */ 928 if (get_bcb_recovery_msg() == BCB_MSG_RECOVERY_PCBA) 929 env_update("bootargs", "androidboot.selinux=permissive"); 930 931 /* sysmem */ 932 hotkey_run(HK_SYSMEM); 933 sysmem_overflow_check(); 934 935 return 0; 936 } 937 938 int bootm_image_populate_dtb(void *img) 939 { 940 if ((gd->flags & GD_FLG_KDTB_READY) && !gd->fdt_blob_kern) 941 sysmem_free((phys_addr_t)gd->fdt_blob); 942 else 943 gd->fdt_blob = (void *)env_get_ulong("fdt_addr_r", 16, 0); 944 945 return rockchip_ram_read_dtb_file(img, (void *)gd->fdt_blob); 946 } 947 948 /* 949 * Implement it to support CLI command: 950 * - Android: bootm [aosp addr] 951 * - FIT: bootm [fit addr] 952 * - uImage: bootm [uimage addr] 953 * 954 * Purpose: 955 * - The original bootm command args require fdt addr on AOSP, 956 * which is not flexible on rockchip boot/recovery.img. 957 * - Take Android/FIT/uImage image into sysmem management to avoid image 958 * memory overlap. 959 */ 960 #if defined(CONFIG_ANDROID_BOOTLOADER) || \ 961 defined(CONFIG_ROCKCHIP_FIT_IMAGE) || \ 962 defined(CONFIG_ROCKCHIP_UIMAGE) 963 int board_do_bootm(int argc, char * const argv[]) 964 { 965 int format; 966 void *img; 967 968 /* only 'bootm' full image goes further */ 969 if (argc != 2) 970 return 0; 971 972 img = (void *)simple_strtoul(argv[1], NULL, 16); 973 format = (genimg_get_format(img)); 974 975 /* Android */ 976 #ifdef CONFIG_ANDROID_BOOT_IMAGE 977 if (format == IMAGE_FORMAT_ANDROID) { 978 struct andr_img_hdr *hdr; 979 ulong load_addr; 980 ulong size; 981 int ret; 982 983 hdr = (struct andr_img_hdr *)img; 984 printf("BOOTM: transferring to board Android\n"); 985 986 load_addr = env_get_ulong("kernel_addr_r", 16, 0); 987 load_addr -= hdr->page_size; 988 size = android_image_get_end(hdr) - (ulong)hdr; 989 990 if (!sysmem_alloc_base(MEM_ANDROID, (ulong)hdr, size)) 991 return -ENOMEM; 992 993 ret = bootm_image_populate_dtb(img); 994 if (ret) { 995 printf("bootm can't read dtb, ret=%d\n", ret); 996 return ret; 997 } 998 999 ret = android_image_memcpy_separate(hdr, &load_addr); 1000 if (ret) { 1001 printf("board do bootm failed, ret=%d\n", ret); 1002 return ret; 1003 } 1004 1005 return android_bootloader_boot_kernel(load_addr); 1006 } 1007 #endif 1008 1009 /* FIT */ 1010 #if IMAGE_ENABLE_FIT 1011 if (format == IMAGE_FORMAT_FIT) { 1012 char boot_cmd[64]; 1013 int ret; 1014 1015 printf("BOOTM: transferring to board FIT\n"); 1016 1017 ret = bootm_image_populate_dtb(img); 1018 if (ret) { 1019 printf("bootm can't read dtb, ret=%d\n", ret); 1020 return ret; 1021 } 1022 snprintf(boot_cmd, sizeof(boot_cmd), "boot_fit %s", argv[1]); 1023 return run_command(boot_cmd, 0); 1024 } 1025 #endif 1026 1027 /* uImage */ 1028 #if 0 1029 #if defined(CONFIG_IMAGE_FORMAT_LEGACY) 1030 if (format == IMAGE_FORMAT_LEGACY && 1031 image_get_type(img) == IH_TYPE_MULTI) { 1032 char boot_cmd[64]; 1033 1034 printf("BOOTM: transferring to board uImage\n"); 1035 snprintf(boot_cmd, sizeof(boot_cmd), "boot_uimage %s", argv[1]); 1036 return run_command(boot_cmd, 0); 1037 } 1038 #endif 1039 #endif 1040 return 0; 1041 } 1042 #endif 1043 1044 void autoboot_command_fail_handle(void) 1045 { 1046 #ifdef CONFIG_ANDROID_AB 1047 if (rk_avb_ab_have_bootable_slot() == true) 1048 run_command("reset;", 0); 1049 else 1050 run_command("fastboot usb 0;", 0); 1051 #endif 1052 1053 #ifdef CONFIG_AVB_VBMETA_PUBLIC_KEY_VALIDATE 1054 run_command("download", 0); 1055 run_command("fastboot usb 0;", 0); 1056 #endif 1057 1058 } 1059 1060 #ifdef CONFIG_FIT_ROLLBACK_PROTECT 1061 1062 #define FIT_ROLLBACK_INDEX_LOCATION 0x66697472 /* "fitr" */ 1063 1064 int fit_read_otp_rollback_index(uint32_t fit_index, uint32_t *otp_index) 1065 { 1066 #ifdef CONFIG_OPTEE_CLIENT 1067 u64 index; 1068 int ret; 1069 1070 ret = trusty_read_rollback_index(FIT_ROLLBACK_INDEX_LOCATION, &index); 1071 if (ret) { 1072 if (ret != TEE_ERROR_ITEM_NOT_FOUND) 1073 return ret; 1074 1075 index = 0; 1076 printf("Initial otp index as %d\n", fit_index); 1077 } 1078 1079 *otp_index = (uint32_t)index; 1080 #else 1081 *otp_index = 0; 1082 #endif 1083 1084 return 0; 1085 } 1086 1087 int fit_write_trusty_rollback_index(u32 trusty_index) 1088 { 1089 if (!trusty_index) 1090 return 0; 1091 #ifdef CONFIG_OPTEE_CLIENT 1092 return trusty_write_rollback_index(FIT_ROLLBACK_INDEX_LOCATION, 1093 (u64)trusty_index); 1094 #else 1095 return 0; 1096 #endif 1097 } 1098 #endif 1099 1100 void board_quiesce_devices(void *images) 1101 { 1102 #ifdef CONFIG_ROCKCHIP_PRELOADER_ATAGS 1103 /* Destroy atags makes next warm boot safer */ 1104 atags_destroy(); 1105 #endif 1106 #ifdef CONFIG_FIT_ROLLBACK_PROTECT 1107 int ret; 1108 1109 ret = fit_write_trusty_rollback_index(gd->rollback_index); 1110 if (ret) { 1111 panic("Failed to write fit rollback index %d, ret=%d", 1112 gd->rollback_index, ret); 1113 } 1114 #endif 1115 #ifdef CONFIG_ROCKCHIP_HW_DECOMPRESS 1116 misc_decompress_cleanup(); 1117 #endif 1118 #ifdef CONFIG_ARM64 1119 bootm_headers_t *bootm_images = (bootm_headers_t *)images; 1120 1121 /* relocate kernel after decompress cleanup */ 1122 if (orig_images_ep && orig_images_ep != bootm_images->ep) { 1123 memmove((char *)bootm_images->ep, (const char *)orig_images_ep, 1124 bootm_images->os.image_len); 1125 printf("== DO RELOCATE == Kernel from 0x%08lx to 0x%08lx\n", 1126 orig_images_ep, bootm_images->ep); 1127 } 1128 #endif 1129 1130 hotkey_run(HK_CMDLINE); 1131 hotkey_run(HK_CLI_OS_GO); 1132 #ifdef CONFIG_ROCKCHIP_REBOOT_TEST 1133 do_reset(NULL, 0, 0, NULL); 1134 #endif 1135 } 1136 1137 /* 1138 * Use hardware rng to seed Linux random 1139 * 1140 * 'Android_14 + GKI' requires this information. 1141 */ 1142 int board_rng_seed(struct abuf *buf) 1143 { 1144 struct udevice *dev; 1145 size_t len = 32; 1146 u64 *data; 1147 1148 data = malloc(len); 1149 if (!data) { 1150 printf("Out of memory\n"); 1151 return -ENOMEM; 1152 } 1153 1154 if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) { 1155 printf("No RNG device\n"); 1156 return -ENODEV; 1157 } 1158 1159 if (dm_rng_read(dev, data, len)) { 1160 printf("Reading RNG failed\n"); 1161 return -EIO; 1162 } 1163 1164 abuf_init_set(buf, data, len); 1165 1166 return 0; 1167 } 1168 1169 /* 1170 * Pass fwver when any available. 1171 */ 1172 static void bootargs_add_fwver(bool verbose) 1173 { 1174 #ifdef CONFIG_ROCKCHIP_PRELOADER_ATAGS 1175 struct tag *t; 1176 char *list1 = NULL; 1177 char *list2 = NULL; 1178 char *fwver = NULL; 1179 char *p = PLAIN_VERSION; 1180 int i, end; 1181 1182 t = atags_get_tag(ATAG_FWVER); 1183 if (t) { 1184 list1 = calloc(1, sizeof(struct tag_fwver)); 1185 if (!list1) 1186 return; 1187 for (i = 0; i < FW_MAX; i++) { 1188 if (t->u.fwver.ver[i][0] != '\0') { 1189 strcat(list1, t->u.fwver.ver[i]); 1190 strcat(list1, ","); 1191 } 1192 } 1193 } 1194 1195 list2 = calloc(1, FWVER_LEN); 1196 if (!list2) 1197 goto out; 1198 strcat(list2, "uboot-"); 1199 /* optional */ 1200 #ifdef BUILD_TAG 1201 strcat(list2, BUILD_TAG); 1202 strcat(list2, "-"); 1203 #endif 1204 /* optional */ 1205 if (strcmp(PLAIN_VERSION, "2017.09")) { 1206 strncat(list2, p + strlen("2017.09-g"), 10); 1207 strcat(list2, "-"); 1208 } 1209 strcat(list2, U_BOOT_DMI_DATE); 1210 1211 /* merge ! */ 1212 if (list1 || list2) { 1213 fwver = calloc(1, sizeof(struct tag_fwver)); 1214 if (!fwver) 1215 goto out; 1216 1217 strcat(fwver, "androidboot.fwver="); 1218 if (list1) 1219 strcat(fwver, list1); 1220 if (list2) { 1221 strcat(fwver, list2); 1222 } else { 1223 end = strlen(fwver) - 1; 1224 fwver[end] = '\0'; /* omit last ',' */ 1225 } 1226 if (verbose) 1227 printf("## fwver: %s\n\n", fwver); 1228 env_update("bootargs", fwver); 1229 env_set("fwver", fwver + strlen("androidboot.")); 1230 } 1231 out: 1232 if (list1) 1233 free(list1); 1234 if (list2) 1235 free(list2); 1236 if (fwver) 1237 free(fwver); 1238 #endif 1239 } 1240 1241 static void bootargs_add_android(bool verbose) 1242 { 1243 #ifdef CONFIG_ANDROID_AB 1244 ab_update_root_partition(); 1245 #endif 1246 1247 /* Android header v4+ need this handle */ 1248 #ifdef CONFIG_ANDROID_BOOT_IMAGE 1249 struct andr_img_hdr *hdr; 1250 char *fwver; 1251 1252 hdr = (void *)env_get_ulong("android_addr_r", 16, 0); 1253 if (hdr && !android_image_check_header(hdr) && hdr->header_version >= 4) { 1254 if (env_update_extract_subset("bootargs", "andr_bootargs", "androidboot.")) 1255 printf("extract androidboot.xxx error\n"); 1256 if (verbose) 1257 printf("## bootargs(android): %s\n\n", env_get("andr_bootargs")); 1258 1259 /* for kernel cmdline can be read */ 1260 fwver = env_get("fwver"); 1261 if (fwver) { 1262 env_update("bootargs", fwver); 1263 env_set("fwver", NULL); 1264 } 1265 } 1266 #endif 1267 } 1268 1269 static void bootargs_add_partition(bool verbose) 1270 { 1271 #if defined(CONFIG_ENVF) || defined(CONFIG_ENV_PARTITION) 1272 char *part_type[] = { "mtdparts", "blkdevparts" }; 1273 char *part_list; 1274 char *env; 1275 int id = 0; 1276 1277 env = env_get(part_type[id]); 1278 if (!env) 1279 env = env_get(part_type[++id]); 1280 if (env) { 1281 if (!strstr(env, part_type[id])) { 1282 part_list = calloc(1, strlen(env) + strlen(part_type[id]) + 2); 1283 if (part_list) { 1284 strcat(part_list, part_type[id]); 1285 strcat(part_list, "="); 1286 strcat(part_list, env); 1287 } 1288 } else { 1289 part_list = env; 1290 } 1291 env_update("bootargs", part_list); 1292 if (verbose) 1293 printf("## parts: %s\n\n", part_list); 1294 } 1295 1296 env = env_get("sys_bootargs"); 1297 if (env) { 1298 env_update("bootargs", env); 1299 if (verbose) 1300 printf("## sys_bootargs: %s\n\n", env); 1301 } 1302 #endif 1303 1304 #ifdef CONFIG_MTD_BLK 1305 if (!env_get("mtdparts")) { 1306 char *mtd_par_info = mtd_part_parse(NULL); 1307 1308 if (mtd_par_info) { 1309 if (memcmp(env_get("devtype"), "mtd", 3) == 0) 1310 env_update("bootargs", mtd_par_info); 1311 } 1312 } 1313 #endif 1314 } 1315 1316 static void bootargs_add_dtb_dtbo(void *fdt, bool verbose) 1317 { 1318 /* bootargs_ext is used when dtbo is applied. */ 1319 const char *arr_bootargs[] = { "bootargs", "bootargs_ext" }; 1320 const char *bootargs; 1321 char *msg = "kernel"; 1322 int i, noffset; 1323 1324 /* find or create "/chosen" node. */ 1325 noffset = fdt_find_or_add_subnode(fdt, 0, "chosen"); 1326 if (noffset < 0) 1327 return; 1328 1329 for (i = 0; i < ARRAY_SIZE(arr_bootargs); i++) { 1330 bootargs = fdt_getprop(fdt, noffset, arr_bootargs[i], NULL); 1331 if (!bootargs) 1332 continue; 1333 if (verbose) 1334 printf("## bootargs(%s-%s): %s\n\n", 1335 msg, arr_bootargs[i], bootargs); 1336 /* 1337 * Append kernel bootargs 1338 * If use AB system, delete default "root=" which route 1339 * to rootfs. Then the ab bootctl will choose the 1340 * high priority system to boot and add its UUID 1341 * to cmdline. The format is "roo=PARTUUID=xxxx...". 1342 */ 1343 #ifdef CONFIG_ANDROID_AB 1344 env_update_filter("bootargs", bootargs, "root="); 1345 #else 1346 env_update("bootargs", bootargs); 1347 #endif 1348 } 1349 } 1350 1351 char *board_fdt_chosen_bootargs(void *fdt) 1352 { 1353 int verbose = is_hotkey(HK_CMDLINE); 1354 const char *bootargs; 1355 1356 /* debug */ 1357 hotkey_run(HK_INITCALL); 1358 if (verbose) 1359 printf("## bootargs(u-boot): %s\n\n", env_get("bootargs")); 1360 1361 bootargs_add_dtb_dtbo(fdt, verbose); 1362 bootargs_add_partition(verbose); 1363 bootargs_add_fwver(verbose); 1364 bootargs_add_android(verbose); 1365 1366 /* 1367 * Initrd fixup: remove unused "initrd=0x...,0x...", 1368 * this for compatible with legacy parameter.txt 1369 */ 1370 env_delete("bootargs", "initrd=", 0); 1371 1372 /* 1373 * If uart is required to be disabled during 1374 * power on, it would be not initialized by 1375 * any pre-loader and U-Boot. 1376 * 1377 * If we don't remove earlycon from commandline, 1378 * kernel hangs while using earlycon to putc/getc 1379 * which may dead loop for waiting uart status. 1380 * (It seems the root cause is baundrate is not 1381 * initilalized) 1382 * 1383 * So let's remove earlycon from commandline. 1384 */ 1385 if (gd->flags & GD_FLG_DISABLE_CONSOLE) 1386 env_delete("bootargs", "earlycon=", 0); 1387 1388 bootargs = env_get("bootargs"); 1389 if (verbose) 1390 printf("## bootargs(merged): %s\n\n", bootargs); 1391 1392 return (char *)bootargs; 1393 } 1394 1395 int ft_verify_fdt(void *fdt) 1396 { 1397 /* for android header v4+, we load bootparams and fixup initrd */ 1398 #if defined(CONFIG_ANDROID_BOOT_IMAGE) && defined(CONFIG_XBC) 1399 struct andr_img_hdr *hdr; 1400 uint64_t initrd_start, initrd_end; 1401 char *bootargs, *p; 1402 int nodeoffset; 1403 int is_u64, err; 1404 u32 len; 1405 1406 hdr = (void *)env_get_ulong("android_addr_r", 16, 0); 1407 if (!hdr || android_image_check_header(hdr) || 1408 hdr->header_version < 4) 1409 return 1; 1410 1411 bootargs = env_get("andr_bootargs"); 1412 if (!bootargs) 1413 return 1; 1414 1415 /* trans character: space to new line */ 1416 p = bootargs; 1417 while (*p++) { 1418 if (*p == ' ') 1419 *p = '\n'; 1420 } 1421 1422 debug("## andr_bootargs: %s\n", bootargs); 1423 1424 /* 1425 * add boot params right after bootconfig 1426 * 1427 * because we can get final full bootargs in board_fdt_chosen_bootargs(), 1428 * android_image_get_ramdisk() is early than that. 1429 * 1430 * we have to add boot params by now. 1431 */ 1432 len = addBootConfigParameters((char *)bootargs, strlen(bootargs), 1433 (u64)hdr->ramdisk_addr + hdr->ramdisk_size + 1434 hdr->vendor_ramdisk_size, hdr->vendor_bootconfig_size); 1435 if (len < 0) { 1436 printf("error: addBootConfigParameters\n"); 1437 return 0; 1438 } 1439 1440 nodeoffset = fdt_subnode_offset(fdt, 0, "chosen"); 1441 if (nodeoffset < 0) { 1442 printf("error: No /chosen node\n"); 1443 return 0; 1444 } 1445 1446 /* fixup initrd with real value */ 1447 fdt_delprop(fdt, nodeoffset, "linux,initrd-start"); 1448 fdt_delprop(fdt, nodeoffset, "linux,initrd-end"); 1449 1450 is_u64 = (fdt_address_cells(fdt, 0) == 2); 1451 initrd_start = hdr->ramdisk_addr; 1452 initrd_end = initrd_start + hdr->ramdisk_size + 1453 hdr->vendor_ramdisk_size + 1454 hdr->vendor_bootconfig_size + len; 1455 err = fdt_setprop_uxx(fdt, nodeoffset, "linux,initrd-start", 1456 initrd_start, is_u64); 1457 if (err < 0) { 1458 printf("WARNING: could not set linux,initrd-start %s.\n", 1459 fdt_strerror(err)); 1460 return 0; 1461 } 1462 err = fdt_setprop_uxx(fdt, nodeoffset, "linux,initrd-end", 1463 initrd_end, is_u64); 1464 if (err < 0) { 1465 printf("WARNING: could not set linux,initrd-end %s.\n", 1466 fdt_strerror(err)); 1467 return 0; 1468 } 1469 #endif 1470 return 1; 1471 } 1472 1473