xref: /rk3399_rockchip-uboot/arch/arm/mach-rockchip/board.c (revision 008ec9b4bc06f98dd7efdc7d2f44eb066be036e6)
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 <amp.h>
9 #include <android_bootloader.h>
10 #include <android_image.h>
11 #include <bidram.h>
12 #include <boot_rkimg.h>
13 #include <cli.h>
14 #include <clk.h>
15 #include <console.h>
16 #include <debug_uart.h>
17 #include <dm.h>
18 #include <dvfs.h>
19 #include <io-domain.h>
20 #include <key.h>
21 #include <memblk.h>
22 #include <misc.h>
23 #include <of_live.h>
24 #include <ram.h>
25 #include <rockchip_debugger.h>
26 #include <syscon.h>
27 #include <sysmem.h>
28 #include <video_rockchip.h>
29 #include <asm/io.h>
30 #include <asm/gpio.h>
31 #include <dm/uclass-internal.h>
32 #include <dm/root.h>
33 #include <power/charge_display.h>
34 #include <power/regulator.h>
35 #include <asm/arch/boot_mode.h>
36 #include <asm/arch/clock.h>
37 #include <asm/arch/cpu.h>
38 #include <asm/arch/hotkey.h>
39 #include <asm/arch/param.h>
40 #include <asm/arch/periph.h>
41 #include <asm/arch/resource_img.h>
42 #include <asm/arch/rk_atags.h>
43 #include <asm/arch/vendor.h>
44 
45 DECLARE_GLOBAL_DATA_PTR;
46 
47 __weak int rk_board_late_init(void)
48 {
49 	return 0;
50 }
51 
52 __weak int rk_board_fdt_fixup(void *blob)
53 {
54 	return 0;
55 }
56 
57 __weak int soc_clk_dump(void)
58 {
59 	return 0;
60 }
61 
62 __weak int set_armclk_rate(void)
63 {
64 	return 0;
65 }
66 
67 __weak int rk_board_init(void)
68 {
69 	return 0;
70 }
71 
72 /*
73  * define serialno max length, the max length is 512 Bytes
74  * The remaining bytes are used to ensure that the first 512 bytes
75  * are valid when executing 'env_set("serial#", value)'.
76  */
77 #define VENDOR_SN_MAX	513
78 #define CPUID_LEN	0x10
79 #define CPUID_OFF	0x07
80 
81 static int rockchip_set_ethaddr(void)
82 {
83 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION
84 	char buf[ARP_HLEN_ASCII + 1];
85 	u8 ethaddr[ARP_HLEN];
86 	int ret;
87 
88 	ret = vendor_storage_read(VENDOR_LAN_MAC_ID, ethaddr, sizeof(ethaddr));
89 	if (ret > 0 && is_valid_ethaddr(ethaddr)) {
90 		sprintf(buf, "%pM", ethaddr);
91 		env_set("ethaddr", buf);
92 	}
93 #endif
94 	return 0;
95 }
96 
97 static int rockchip_set_serialno(void)
98 {
99 	u8 low[CPUID_LEN / 2], high[CPUID_LEN / 2];
100 	u8 cpuid[CPUID_LEN] = {0};
101 	char serialno_str[VENDOR_SN_MAX];
102 	int ret = 0, i;
103 	u64 serialno;
104 
105 	/* Read serial number from vendor storage part */
106 	memset(serialno_str, 0, VENDOR_SN_MAX);
107 
108 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION
109 	ret = vendor_storage_read(VENDOR_SN_ID, serialno_str, (VENDOR_SN_MAX-1));
110 	if (ret > 0) {
111 		env_set("serial#", serialno_str);
112 	} else {
113 #endif
114 #ifdef CONFIG_ROCKCHIP_EFUSE
115 		struct udevice *dev;
116 
117 		/* retrieve the device */
118 		ret = uclass_get_device_by_driver(UCLASS_MISC,
119 						  DM_GET_DRIVER(rockchip_efuse),
120 						  &dev);
121 		if (ret) {
122 			printf("%s: could not find efuse device\n", __func__);
123 			return ret;
124 		}
125 
126 		/* read the cpu_id range from the efuses */
127 		ret = misc_read(dev, CPUID_OFF, &cpuid, sizeof(cpuid));
128 		if (ret) {
129 			printf("%s: read cpuid from efuses failed, ret=%d\n",
130 			       __func__, ret);
131 			return ret;
132 		}
133 #else
134 		/* generate random cpuid */
135 		for (i = 0; i < CPUID_LEN; i++)
136 			cpuid[i] = (u8)(rand());
137 #endif
138 		/* Generate the serial number based on CPU ID */
139 		for (i = 0; i < 8; i++) {
140 			low[i] = cpuid[1 + (i << 1)];
141 			high[i] = cpuid[i << 1];
142 		}
143 
144 		serialno = crc32_no_comp(0, low, 8);
145 		serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
146 		snprintf(serialno_str, sizeof(serialno_str), "%llx", serialno);
147 
148 		env_set("serial#", serialno_str);
149 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION
150 	}
151 #endif
152 
153 	return ret;
154 }
155 
156 #if defined(CONFIG_USB_FUNCTION_FASTBOOT)
157 int fb_set_reboot_flag(void)
158 {
159 	printf("Setting reboot to fastboot flag ...\n");
160 	writel(BOOT_FASTBOOT, CONFIG_ROCKCHIP_BOOT_MODE_REG);
161 
162 	return 0;
163 }
164 #endif
165 
166 #ifdef CONFIG_ROCKCHIP_USB_BOOT
167 static int boot_from_udisk(void)
168 {
169 	struct blk_desc *desc;
170 	char *devtype;
171 	char *devnum;
172 
173 	devtype = env_get("devtype");
174 	devnum = env_get("devnum");
175 
176 	/* Booting priority: mmc1 > udisk */
177 	if (!strcmp(devtype, "mmc") && !strcmp(devnum, "1"))
178 		return 0;
179 
180 	if (!run_command("usb start", -1)) {
181 		desc = blk_get_devnum_by_type(IF_TYPE_USB, 0);
182 		if (!desc) {
183 			printf("No usb device found\n");
184 			return -ENODEV;
185 		}
186 
187 		if (!run_command("rkimgtest usb 0", -1)) {
188 			rockchip_set_bootdev(desc);
189 			env_set("devtype", "usb");
190 			env_set("devnum", "0");
191 			printf("Boot from usb 0\n");
192 		} else {
193 			printf("No usb dev 0 found\n");
194 			return -ENODEV;
195 		}
196 	}
197 
198 	return 0;
199 }
200 #endif
201 
202 static void env_fixup(void)
203 {
204 	struct memblock mem;
205 	ulong u_addr_r;
206 	phys_size_t end;
207 	char *addr_r;
208 
209 #ifdef ENV_MEM_LAYOUT_SETTINGS1
210 	const char *env_addr0[] = {
211 		"scriptaddr", "pxefile_addr_r",
212 		"fdt_addr_r", "kernel_addr_r", "ramdisk_addr_r",
213 	};
214 	const char *env_addr1[] = {
215 		"scriptaddr1", "pxefile_addr1_r",
216 		"fdt_addr1_r", "kernel_addr1_r", "ramdisk_addr1_r",
217 	};
218 	int i;
219 
220 	/* 128M is a typical ram size for most platform, so as default here */
221 	if (gd->ram_size <= SZ_128M) {
222 		/* Replace orignal xxx_addr_r */
223 		for (i = 0; i < ARRAY_SIZE(env_addr1); i++) {
224 			addr_r = env_get(env_addr1[i]);
225 			if (addr_r)
226 				env_set(env_addr0[i], addr_r);
227 		}
228 	}
229 #endif
230 	/* If bl32 is disabled, maybe kernel can be load to lower address. */
231 	if (!(gd->flags & GD_FLG_BL32_ENABLED)) {
232 		addr_r = env_get("kernel_addr_no_bl32_r");
233 		if (addr_r)
234 			env_set("kernel_addr_r", addr_r);
235 	/* If bl32 is enlarged, we move ramdisk addr right behind it */
236 	} else {
237 		mem = param_parse_optee_mem();
238 		end = mem.base + mem.size;
239 		u_addr_r = env_get_ulong("ramdisk_addr_r", 16, 0);
240 		if (u_addr_r >= mem.base && u_addr_r < end)
241 			env_set_hex("ramdisk_addr_r", end);
242 	}
243 }
244 
245 static void cmdline_handle(void)
246 {
247 #ifdef CONFIG_ROCKCHIP_PRELOADER_ATAGS
248 	struct tag *t;
249 
250 	t = atags_get_tag(ATAG_PUB_KEY);
251 	if (t) {
252 		/* Pass if efuse/otp programmed */
253 		if (t->u.pub_key.flag == PUBKEY_FUSE_PROGRAMMED)
254 			env_update("bootargs", "fuse.programmed=1");
255 		else
256 			env_update("bootargs", "fuse.programmed=0");
257 	}
258 #endif
259 }
260 
261 int board_late_init(void)
262 {
263 	rockchip_set_ethaddr();
264 	rockchip_set_serialno();
265 	setup_download_mode();
266 #if (CONFIG_ROCKCHIP_BOOT_MODE_REG > 0)
267 	setup_boot_mode();
268 #endif
269 #ifdef CONFIG_ROCKCHIP_USB_BOOT
270 	boot_from_udisk();
271 #endif
272 #ifdef CONFIG_DM_CHARGE_DISPLAY
273 	charge_display();
274 #endif
275 #ifdef CONFIG_DRM_ROCKCHIP
276 	rockchip_show_logo();
277 #endif
278 	env_fixup();
279 	soc_clk_dump();
280 	cmdline_handle();
281 
282 	return rk_board_late_init();
283 }
284 
285 static void early_download(void)
286 {
287 #if defined(CONFIG_PWRKEY_DNL_TRIGGER_NUM) && \
288 		(CONFIG_PWRKEY_DNL_TRIGGER_NUM > 0)
289 	if (pwrkey_download_init())
290 		printf("Pwrkey download init failed\n");
291 #endif
292 
293 #if (CONFIG_ROCKCHIP_BOOT_MODE_REG > 0)
294 	if (is_hotkey(HK_BROM_DNL)) {
295 		printf("Enter bootrom download...");
296 		flushc();
297 		writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
298 		do_reset(NULL, 0, 0, NULL);
299 		printf("failed!\n");
300 	}
301 #endif
302 }
303 
304 static void board_debug_init(void)
305 {
306 	if (!gd->serial.using_pre_serial)
307 		board_debug_uart_init();
308 
309 	if (tstc()) {
310 		gd->console_evt = getc();
311 		if (gd->console_evt <= 0x1a) /* 'z' */
312 			printf("Hotkey: ctrl+%c\n", gd->console_evt + 'a' - 1);
313 	}
314 }
315 
316 int board_init(void)
317 {
318 	board_debug_init();
319 
320 #ifdef DEBUG
321 	soc_clk_dump();
322 #endif
323 
324 #ifdef CONFIG_USING_KERNEL_DTB
325 	init_kernel_dtb();
326 #endif
327 	early_download();
328 
329 	/*
330 	 * pmucru isn't referenced on some platforms, so pmucru driver can't
331 	 * probe that the "assigned-clocks" is unused.
332 	 */
333 	clks_probe();
334 #ifdef CONFIG_DM_REGULATOR
335 	if (regulators_enable_boot_on(is_hotkey(HK_REGULATOR)))
336 		debug("%s: Can't enable boot on regulator\n", __func__);
337 #endif
338 
339 #ifdef CONFIG_ROCKCHIP_IO_DOMAIN
340 	io_domain_init();
341 #endif
342 
343 	set_armclk_rate();
344 
345 #ifdef CONFIG_DM_DVFS
346 	dvfs_init(true);
347 #endif
348 
349 	return rk_board_init();
350 }
351 
352 int interrupt_debugger_init(void)
353 {
354 #ifdef CONFIG_ROCKCHIP_DEBUGGER
355 	return rockchip_debugger_init();
356 #else
357 	return 0;
358 #endif
359 }
360 
361 int board_fdt_fixup(void *blob)
362 {
363 	/* Common fixup for DRM */
364 #ifdef CONFIG_DRM_ROCKCHIP
365 	rockchip_display_fixup(blob);
366 #endif
367 
368 	return rk_board_fdt_fixup(blob);
369 }
370 
371 #ifdef CONFIG_ARM64_BOOT_AARCH32
372 /*
373  * Fixup MMU region attr for OP-TEE on ARMv8 CPU:
374  *
375  * What ever U-Boot is 64-bit or 32-bit mode, the OP-TEE is always 64-bit mode.
376  *
377  * Command for OP-TEE:
378  *	64-bit mode: dcache is always enabled;
379  *	32-bit mode: dcache is always disabled(Due to some unknown issue);
380  *
381  * Command for U-Boot:
382  *	64-bit mode: MMU table is static defined in rkxxx.c file, all memory
383  *		     regions are mapped. That's good to match OP-TEE MMU policy.
384  *
385  *	32-bit mode: MMU table is setup according to gd->bd->bi_dram[..] where
386  *		     the OP-TEE region has been reserved, so it can not be
387  *		     mapped(i.e. dcache is disabled). That's also good to match
388  *		     OP-TEE MMU policy.
389  *
390  * For the data coherence when communication between U-Boot and OP-TEE, U-Boot
391  * should follow OP-TEE MMU policy.
392  *
393  * Here is the special:
394  *	When CONFIG_ARM64_BOOT_AARCH32 is enabled, U-Boot is 32-bit mode while
395  *	OP-TEE is still 64-bit mode. U-Boot would not map MMU table for OP-TEE
396  *	region(but OP-TEE requires it cacheable) so we fixup here.
397  */
398 int board_initr_caches_fixup(void)
399 {
400 	struct memblock mem;
401 
402 	mem = param_parse_optee_mem();
403 	if (mem.size)
404 		mmu_set_region_dcache_behaviour(mem.base, mem.size,
405 						DCACHE_WRITEBACK);
406 	return 0;
407 }
408 #endif
409 
410 void arch_preboot_os(uint32_t bootm_state)
411 {
412 	if (bootm_state & BOOTM_STATE_OS_PREP)
413 		hotkey_run(HK_CLI_OS_PRE);
414 }
415 
416 void board_quiesce_devices(void)
417 {
418 	hotkey_run(HK_CMDLINE);
419 	hotkey_run(HK_CLI_OS_GO);
420 
421 #ifdef CONFIG_ROCKCHIP_PRELOADER_ATAGS
422 	/* Destroy atags makes next warm boot safer */
423 	atags_destroy();
424 #endif
425 }
426 
427 void enable_caches(void)
428 {
429 	icache_enable();
430 	dcache_enable();
431 }
432 
433 #ifdef CONFIG_LMB
434 /*
435  * Using last bi_dram[...] to initialize "bootm_low" and "bootm_mapsize".
436  * This makes lmb_alloc_base() always alloc from tail of sdram.
437  * If we don't assign it, bi_dram[0] is used by default and it may cause
438  * lmb_alloc_base() fail when bi_dram[0] range is small.
439  */
440 void board_lmb_reserve(struct lmb *lmb)
441 {
442 	char bootm_mapsize[32];
443 	char bootm_low[32];
444 	u64 start, size;
445 	int i;
446 
447 	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
448 		if (!gd->bd->bi_dram[i].size)
449 			break;
450 	}
451 
452 	start = gd->bd->bi_dram[i - 1].start;
453 	size = gd->bd->bi_dram[i - 1].size;
454 
455 	/*
456 	 * 32-bit kernel: ramdisk/fdt shouldn't be loaded to highmem area(768MB+),
457 	 * otherwise "Unable to handle kernel paging request at virtual address ...".
458 	 *
459 	 * So that we hope limit highest address at 768M, but there comes the the
460 	 * problem: ramdisk is a compressed image and it expands after descompress,
461 	 * so it accesses 768MB+ and brings the above "Unable to handle kernel ...".
462 	 *
463 	 * We make a appointment that the highest memory address is 512MB, it
464 	 * makes lmb alloc safer.
465 	 */
466 #ifndef CONFIG_ARM64
467 	if (start >= ((u64)CONFIG_SYS_SDRAM_BASE + SZ_512M)) {
468 		start = gd->bd->bi_dram[i - 2].start;
469 		size = gd->bd->bi_dram[i - 2].size;
470 	}
471 
472 	if ((start + size) > ((u64)CONFIG_SYS_SDRAM_BASE + SZ_512M))
473 		size = (u64)CONFIG_SYS_SDRAM_BASE + SZ_512M - start;
474 #endif
475 	sprintf(bootm_low, "0x%llx", start);
476 	sprintf(bootm_mapsize, "0x%llx", size);
477 	env_set("bootm_low", bootm_low);
478 	env_set("bootm_mapsize", bootm_mapsize);
479 }
480 #endif
481 
482 #ifdef CONFIG_BIDRAM
483 int board_bidram_reserve(struct bidram *bidram)
484 {
485 	struct memblock mem;
486 	int ret;
487 
488 	/* ATF */
489 	mem = param_parse_atf_mem();
490 	ret = bidram_reserve(MEM_ATF, mem.base, mem.size);
491 	if (ret)
492 		return ret;
493 
494 	/* PSTORE/ATAGS/SHM */
495 	mem = param_parse_common_resv_mem();
496 	ret = bidram_reserve(MEM_SHM, mem.base, mem.size);
497 	if (ret)
498 		return ret;
499 
500 	/* OP-TEE */
501 	mem = param_parse_optee_mem();
502 	ret = bidram_reserve(MEM_OPTEE, mem.base, mem.size);
503 	if (ret)
504 		return ret;
505 
506 	return 0;
507 }
508 
509 parse_fn_t board_bidram_parse_fn(void)
510 {
511 	return param_parse_ddr_mem;
512 }
513 #endif
514 
515 #ifdef CONFIG_ROCKCHIP_AMP
516 void cpu_secondary_init_r(void)
517 {
518 	amp_cpus_on();
519 }
520 #endif
521 
522 #if defined(CONFIG_ROCKCHIP_PRELOADER_SERIAL) && \
523     defined(CONFIG_ROCKCHIP_PRELOADER_ATAGS)
524 int board_init_f_init_serial(void)
525 {
526 	struct tag *t = atags_get_tag(ATAG_SERIAL);
527 
528 	if (t) {
529 		gd->serial.using_pre_serial = t->u.serial.enable;
530 		gd->serial.addr = t->u.serial.addr;
531 		gd->serial.baudrate = t->u.serial.baudrate;
532 		gd->serial.id = t->u.serial.id;
533 
534 		debug("%s: enable=%d, addr=0x%lx, baudrate=%d, id=%d\n",
535 		      __func__, gd->serial.using_pre_serial,
536 		      gd->serial.addr, gd->serial.baudrate,
537 		      gd->serial.id);
538 	}
539 
540 	return 0;
541 }
542 #endif
543 
544 #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
545 #include <fdt_support.h>
546 #include <usb.h>
547 #include <usb/dwc2_udc.h>
548 
549 static struct dwc2_plat_otg_data otg_data = {
550 	.rx_fifo_sz	= 512,
551 	.np_tx_fifo_sz	= 16,
552 	.tx_fifo_sz	= 128,
553 };
554 
555 int board_usb_init(int index, enum usb_init_type init)
556 {
557 	const void *blob = gd->fdt_blob;
558 	const fdt32_t *reg;
559 	fdt_addr_t addr;
560 	int node;
561 
562 	/* find the usb_otg node */
563 	node = fdt_node_offset_by_compatible(blob, -1, "snps,dwc2");
564 
565 retry:
566 	if (node > 0) {
567 		reg = fdt_getprop(blob, node, "reg", NULL);
568 		if (!reg)
569 			return -EINVAL;
570 
571 		addr = fdt_translate_address(blob, node, reg);
572 		if (addr == OF_BAD_ADDR) {
573 			pr_err("Not found usb_otg address\n");
574 			return -EINVAL;
575 		}
576 
577 #if defined(CONFIG_ROCKCHIP_RK3288)
578 		if (addr != 0xff580000) {
579 			node = fdt_node_offset_by_compatible(blob, node,
580 							     "snps,dwc2");
581 			goto retry;
582 		}
583 #endif
584 	} else {
585 		/*
586 		 * With kernel dtb support, rk3288 dwc2 otg node
587 		 * use the rockchip legacy dwc2 driver "dwc_otg_310"
588 		 * with the compatible "rockchip,rk3288_usb20_otg",
589 		 * and rk3368 also use the "dwc_otg_310" driver with
590 		 * the compatible "rockchip,rk3368-usb".
591 		 */
592 #if defined(CONFIG_ROCKCHIP_RK3288)
593 		node = fdt_node_offset_by_compatible(blob, -1,
594 				"rockchip,rk3288_usb20_otg");
595 #elif defined(CONFIG_ROCKCHIP_RK3368)
596 		node = fdt_node_offset_by_compatible(blob, -1,
597 				"rockchip,rk3368-usb");
598 #endif
599 		if (node > 0) {
600 			goto retry;
601 		} else {
602 			pr_err("Not found usb_otg device\n");
603 			return -ENODEV;
604 		}
605 	}
606 
607 	otg_data.regs_otg = (uintptr_t)addr;
608 
609 	return dwc2_udc_probe(&otg_data);
610 }
611 
612 int board_usb_cleanup(int index, enum usb_init_type init)
613 {
614 	return 0;
615 }
616 #endif
617 
618 static void bootm_no_reloc(void)
619 {
620 	char *ramdisk_high;
621 	char *fdt_high;
622 
623 	if (!env_get_yesno("bootm-no-reloc"))
624 		return;
625 
626 	ramdisk_high = env_get("initrd_high");
627 	fdt_high = env_get("fdt_high");
628 
629 	if (!fdt_high) {
630 		env_set_hex("fdt_high", -1UL);
631 		printf("Fdt ");
632 	}
633 
634 	if (!ramdisk_high) {
635 		env_set_hex("initrd_high", -1UL);
636 		printf("Ramdisk ");
637 	}
638 
639 	if (!fdt_high || !ramdisk_high)
640 		printf("skip relocation\n");
641 }
642 
643 int bootm_board_start(void)
644 {
645 	/*
646 	 * print console record data
647 	 *
648 	 * On some rockchip platforms, uart debug and sdmmc pin are multiplex.
649 	 * If boot from sdmmc mode, the console data would be record in buffer,
650 	 * we switch to uart debug function in order to print it after loading
651 	 * images.
652 	 */
653 #if defined(CONFIG_CONSOLE_RECORD)
654 	if (!strcmp("mmc", env_get("devtype")) &&
655 	    !strcmp("1", env_get("devnum"))) {
656 		printf("IOMUX: sdmmc => uart debug");
657 		pinctrl_select_state(gd->cur_serial_dev, "default");
658 		console_record_print_purge();
659 	}
660 #endif
661 	/* disable bootm relcation to save boot time */
662 	bootm_no_reloc();
663 
664 	/* sysmem */
665 	hotkey_run(HK_SYSMEM);
666 	sysmem_overflow_check();
667 
668 	return 0;
669 }
670 
671 /*
672  * Implement it to support CLI command:
673  *   - Android: bootm [aosp addr]
674  *   - FIT:     bootm [fit addr]
675  *   - uImage:  bootm [uimage addr]
676  *
677  * Purpose:
678  *   - The original bootm command args require fdt addr on AOSP,
679  *     which is not flexible on rockchip boot/recovery.img.
680  *   - Take Android/FIT/uImage image into sysmem management to avoid image
681  *     memory overlap.
682  */
683 #if defined(CONFIG_ANDROID_BOOTLOADER) ||	\
684 	defined(CONFIG_ROCKCHIP_FIT_IMAGE) ||	\
685 	defined(CONFIG_ROCKCHIP_UIMAGE)
686 int board_do_bootm(int argc, char * const argv[])
687 {
688 	int format;
689 	void *img;
690 
691 	if (argc != 2)
692 		return 0;
693 
694 	img = (void *)simple_strtoul(argv[1], NULL, 16);
695 	format = (genimg_get_format(img));
696 
697 	/* Android */
698 #ifdef CONFIG_ANDROID_BOOT_IMAGE
699 	if (format == IMAGE_FORMAT_ANDROID) {
700 		struct andr_img_hdr *hdr;
701 		ulong load_addr;
702 		ulong size;
703 		int ret;
704 
705 		hdr = (struct andr_img_hdr *)img;
706 		printf("BOOTM: transferring to board Android\n");
707 
708 #ifdef CONFIG_USING_KERNEL_DTB
709 		sysmem_free((phys_addr_t)gd->fdt_blob);
710 		/* erase magic */
711 		fdt_set_magic((void *)gd->fdt_blob, ~0);
712 		gd->fdt_blob = NULL;
713 #endif
714 		load_addr = env_get_ulong("kernel_addr_r", 16, 0);
715 		load_addr -= hdr->page_size;
716 		size = android_image_get_end(hdr) - (ulong)hdr;
717 
718 		if (!sysmem_alloc_base(MEM_ANDROID, (ulong)hdr, size))
719 			return -ENOMEM;
720 
721 		ret = android_image_memcpy_separate(hdr, &load_addr);
722 		if (ret) {
723 			printf("board do bootm failed, ret=%d\n", ret);
724 			return ret;
725 		}
726 
727 		return android_bootloader_boot_kernel(load_addr);
728 	}
729 #endif
730 
731 	/* FIT */
732 #if IMAGE_ENABLE_FIT
733 	if (format == IMAGE_FORMAT_FIT) {
734 		char boot_cmd[64];
735 
736 		printf("BOOTM: transferring to board FIT\n");
737 		snprintf(boot_cmd, sizeof(boot_cmd), "boot_fit %s", argv[1]);
738 		return run_command(boot_cmd, 0);
739 	}
740 #endif
741 
742 	/* uImage */
743 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
744 	if (format == IMAGE_FORMAT_LEGACY &&
745 	    image_get_type(img) == IH_TYPE_MULTI) {
746 		char boot_cmd[64];
747 
748 		printf("BOOTM: transferring to board uImage\n");
749 		snprintf(boot_cmd, sizeof(boot_cmd), "boot_uimage %s", argv[1]);
750 		return run_command(boot_cmd, 0);
751 	}
752 #endif
753 
754 	return 0;
755 }
756 #endif
757