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 <malloc.h> 9 #include <android_bootloader.h> 10 #include <attestation_key.h> 11 #include <boot_rkimg.h> 12 #include <optee_include/OpteeClientInterface.h> 13 14 #define OEM_UNLOCK_ARG_SIZE 30 15 16 static int do_boot_rockchip(cmd_tbl_t *cmdtp, int flag, int argc, 17 char * const argv[]) 18 { 19 disk_partition_t part_info; 20 struct blk_desc *dev_desc; 21 int mode = 0; 22 char *boot_partname = PART_BOOT; 23 int ret = 0; 24 int i = 0; 25 26 dev_desc = rockchip_get_bootdev(); 27 28 #ifdef CONFIG_OPTEE_CLIENT 29 disk_partition_t misc_part_info; 30 31 /* load attestation key from misc partition. */ 32 ret = part_get_info_by_name(dev_desc, "misc", 33 &misc_part_info); 34 if (ret < 0) 35 printf("%s Could not find misc partition\n", __func__); 36 else 37 load_attestation_key(dev_desc, &misc_part_info); 38 #endif 39 40 #ifdef CONFIG_OPTEE_CLIENT 41 /* read oem unlock status and attach to bootargs */ 42 uint8_t unlock = 0; 43 TEEC_Result result; 44 char oem_unlock[OEM_UNLOCK_ARG_SIZE] = {0}; 45 result = trusty_read_oem_unlock(&unlock); 46 if (result) { 47 printf("read oem unlock status with error : 0x%x\n", result); 48 } else { 49 snprintf(oem_unlock, OEM_UNLOCK_ARG_SIZE, "androidboot.oem_unlocked=%d", unlock); 50 env_update("bootargs", oem_unlock); 51 } 52 #endif 53 54 mode = rockchip_get_boot_mode(); 55 if (mode == BOOT_MODE_RECOVERY) { 56 boot_partname = PART_RECOVERY; 57 printf("%s boot from Recovery partition!\n", __func__); 58 } 59 60 for (i = 0; i < argc; i++) { 61 if (!strcmp(argv[i], "boot-recovery")) { 62 boot_partname = PART_RECOVERY; 63 printf("%s argv%d:%s boot from Recovery partition!\n", 64 __func__, i, argv[i]); 65 } 66 } 67 68 ret = part_get_info_by_name(dev_desc, boot_partname, &part_info); 69 70 if(boot_rockchip_image(dev_desc, &part_info)) 71 ret = CMD_RET_FAILURE; 72 73 return ret; 74 } 75 76 U_BOOT_CMD( 77 bootrkp, CONFIG_SYS_MAXARGS, 1, do_boot_rockchip, 78 "Boot Linux Image from rockchip image type", 79 "kernel.img: zImage/Image\n" 80 "boot.img: ramdisk\n" 81 "resource.img: dtb, u-boot logo, kernel logo" 82 ); 83 84 static int do_rkimg_test(cmd_tbl_t *cmdtp, int flag, int argc, 85 char * const argv[]) 86 { 87 struct blk_desc *dev_desc; 88 u32* buffer; 89 int ret = 0; 90 91 dev_desc = blk_get_dev(argv[1], simple_strtoul(argv[2], NULL, 16)); 92 93 buffer = memalign(ARCH_DMA_MINALIGN, 1024); 94 /* Read one block from begining of IDB data */ 95 ret = blk_dread(dev_desc, 64, 2, buffer); 96 if (ret != 2) { 97 printf("%s fail to read data from IDB\n", __func__); 98 free(buffer); 99 return CMD_RET_FAILURE; 100 } 101 102 if (buffer[0] == 0xFCDC8C3B){ 103 printf("%s found IDB in SDcard\n", __func__); 104 ret = CMD_RET_SUCCESS; 105 if (0 == buffer[128 + 104 / 4]) /* TAG in IDB */ 106 env_update("bootargs", "sdfwupdate"); 107 } 108 109 free(buffer); 110 111 return ret; 112 } 113 114 U_BOOT_CMD( 115 rkimgtest, 3, 0, do_rkimg_test, 116 "Test if storage media have rockchip image", 117 "" 118 ); 119