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 #include <optee_include/OpteeClientInterface.h> 12 13 #define OEM_UNLOCK_ARG_SIZE 30 14 15 static int do_boot_rockchip(cmd_tbl_t *cmdtp, int flag, int argc, 16 char * const argv[]) 17 { 18 disk_partition_t part_info; 19 struct blk_desc *dev_desc; 20 int mode = 0; 21 char *boot_partname = PART_BOOT; 22 int ret = 0; 23 int i = 0; 24 25 dev_desc = rockchip_get_bootdev(); 26 27 #ifdef CONFIG_OPTEE_CLIENT 28 disk_partition_t misc_part_info; 29 30 /* load attestation key from misc partition. */ 31 ret = part_get_info_by_name(dev_desc, "misc", 32 &misc_part_info); 33 if (ret < 0) 34 printf("%s Could not find misc partition\n", __func__); 35 else 36 load_attestation_key(dev_desc, &misc_part_info); 37 #endif 38 39 #ifdef CONFIG_OPTEE_CLIENT 40 /* read oem unlock status and attach to bootargs */ 41 uint8_t unlock = 0; 42 TEEC_Result result; 43 char oem_unlock[OEM_UNLOCK_ARG_SIZE] = {0}; 44 result = trusty_read_oem_unlock(&unlock); 45 if (result) { 46 printf("read oem unlock status with error : 0x%x\n", result); 47 } else { 48 snprintf(oem_unlock, OEM_UNLOCK_ARG_SIZE, "androidboot.oem_unlocked=%d", unlock); 49 env_update("bootargs", oem_unlock); 50 } 51 #endif 52 53 mode = rockchip_get_boot_mode(); 54 if (mode == BOOT_MODE_RECOVERY) { 55 boot_partname = PART_RECOVERY; 56 printf("%s boot from Recovery partition!\n", __func__); 57 } 58 59 for (i = 0; i < argc; i++) { 60 if (!strcmp(argv[i], "boot-recovery")) { 61 boot_partname = PART_RECOVERY; 62 printf("%s argv%d:%s boot from Recovery partition!\n", 63 __func__, i, argv[i]); 64 } 65 } 66 67 ret = part_get_info_by_name(dev_desc, boot_partname, &part_info); 68 69 if(boot_rockchip_image(dev_desc, &part_info)) 70 ret = CMD_RET_FAILURE; 71 72 return ret; 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