xref: /rk3399_rockchip-uboot/cmd/bootrkp.c (revision 73ec4e0398125f41aa20c70f6316416e96a4e8d2)
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 <boot_rkimg.h>
9 #include <keymaster.h>
10 #include <malloc.h>
11 #include <android_bootloader.h>
12 #include <attestation_key.h>
13 
14 static int do_boot_rockchip(cmd_tbl_t *cmdtp, int flag, int argc,
15 			    char *const argv[])
16 {
17 	char *boot_partname = PART_BOOT;
18 	disk_partition_t part_info;
19 	struct blk_desc *dev_desc;
20 	int i, ret;
21 	int mode;
22 
23 	dev_desc = rockchip_get_bootdev();
24 	if (!dev_desc) {
25 		printf("%s: dev_desc is NULL!\n", __func__);
26 		return CMD_RET_FAILURE;
27 	}
28 
29 #ifdef CONFIG_ANDROID_KEYMASTER_CA
30 	/* load attestation key from misc partition. */
31 	ret = part_get_info_by_name(dev_desc, PART_MISC, &part_info);
32 	if (ret < 0)
33 		printf("%s: Could not find misc partition\n", __func__);
34 	else
35 		load_attestation_key(dev_desc, &part_info);
36 #endif
37 
38 #ifdef CONFIG_FASTBOOT_OEM_UNLOCK
39 	/* read oem unlock status and attach to bootargs */
40 	char oem_unlock[30] = {0};
41 	TEEC_Result result;
42 	uint8_t unlock = 0;
43 
44 	result = trusty_read_oem_unlock(&unlock);
45 	if (result) {
46 		printf("%s: Read oem unlock status failed: %d\n",
47 		       __func__, result);
48 	} else {
49 		snprintf(oem_unlock, sizeof(oem_unlock),
50 			 "androidboot.oem_unlocked=%d", unlock);
51 		env_update("bootargs", oem_unlock);
52 	}
53 #endif
54 
55 	mode = rockchip_get_boot_mode();
56 	if (mode == BOOT_MODE_RECOVERY)
57 		boot_partname = PART_RECOVERY;
58 
59 	for (i = 0; i < argc; i++) {
60 		if (!strcmp(argv[i], "boot-recovery")) {
61 			boot_partname = PART_RECOVERY;
62 			printf("Boot from Recovery partition\n");
63 		}
64 	}
65 
66 	ret = part_get_info_by_name(dev_desc, boot_partname, &part_info);
67 	if (ret < 0) {
68 		printf("%s: Could not find %s part\n", __func__, part_info.name);
69 		return CMD_RET_FAILURE;
70 	}
71 
72 	return boot_rockchip_image(dev_desc, &part_info) ? CMD_RET_FAILURE : 0;
73 }
74 
75 U_BOOT_CMD(
76 	bootrkp,  CONFIG_SYS_MAXARGS,     1,      do_boot_rockchip,
77 	"Boot Linux Image from rockchip image type",
78 	"kernel.img: zImage/Image\n"
79 	"boot.img: ramdisk\n"
80 	"resource.img: dtb, u-boot logo, kernel logo"
81 );
82