xref: /rk3399_rockchip-uboot/cmd/bootrkp.c (revision f61a997e298454f34bee822067d9a5ee37105519)
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 <android_bootloader.h>
9 #include <attestation_key.h>
10 #include <boot_rkimg.h>
11 
12 static int do_boot_rockchip(cmd_tbl_t *cmdtp, int flag, int argc,
13 		      char * const argv[])
14 {
15 	disk_partition_t part_info;
16 	struct blk_desc *dev_desc;
17 	int mode = 0;
18 	char *boot_partname = PART_BOOT;
19 	int ret = 0;
20 	int i = 0;
21 
22 	dev_desc = rockchip_get_bootdev();
23 
24 #ifdef CONFIG_OPTEE_CLIENT
25 	disk_partition_t misc_part_info;
26 
27 	/* load attestation key from misc partition. */
28 	ret = part_get_info_by_name(dev_desc, "misc",
29 				    &misc_part_info);
30 	if (ret < 0)
31 		printf("%s Could not find misc partition\n", __func__);
32 	else
33 		load_attestation_key(dev_desc, &misc_part_info);
34 #endif
35 
36 	mode = rockchip_get_boot_mode();
37 	if (mode == BOOT_MODE_RECOVERY) {
38 		boot_partname = PART_RECOVERY;
39 		printf("%s boot from Recovery partition!\n", __func__);
40 	}
41 
42 	for (i = 0; i < argc; i++) {
43 		if (!strcmp(argv[i], "boot-recovery")) {
44 			boot_partname = PART_RECOVERY;
45 			printf("%s argv%d:%s boot from Recovery partition!\n",
46 				__func__, i, argv[i]);
47 		}
48 	}
49 
50 	ret = part_get_info_by_name(dev_desc, boot_partname, &part_info);
51 
52 	if(boot_rockchip_image(dev_desc, &part_info))
53 		ret = CMD_RET_FAILURE;
54 
55 	return ret;
56 }
57 
58 U_BOOT_CMD(
59 	bootrkp,  CONFIG_SYS_MAXARGS,     1,      do_boot_rockchip,
60 	"Boot Linux Image from rockchip image type",
61 	"kernel.img: zImage/Image\n"
62 	"boot.img: ramdisk\n"
63 	"resource.img: dtb, u-boot logo, kernel logo"
64 );
65