2017-12-07 07:02:05 +00:00
|
|
|
/*
|
|
|
|
|
* (C) Copyright 2017 Rockchip Electronics Co., Ltd
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <common.h>
|
2018-04-28 08:54:21 +00:00
|
|
|
#include <malloc.h>
|
2017-12-07 07:02:05 +00:00
|
|
|
#include <android_bootloader.h>
|
2018-03-19 06:39:06 +00:00
|
|
|
#include <attestation_key.h>
|
2017-12-07 07:02:05 +00:00
|
|
|
#include <boot_rkimg.h>
|
2019-01-05 04:11:22 +00:00
|
|
|
#include <keymaster.h>
|
2018-03-28 10:03:45 +00:00
|
|
|
|
|
|
|
|
#define OEM_UNLOCK_ARG_SIZE 30
|
2017-12-07 07:02:05 +00:00
|
|
|
|
|
|
|
|
static int do_boot_rockchip(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
|
char * const argv[])
|
|
|
|
|
{
|
|
|
|
|
disk_partition_t part_info;
|
|
|
|
|
struct blk_desc *dev_desc;
|
|
|
|
|
int mode = 0;
|
|
|
|
|
char *boot_partname = PART_BOOT;
|
|
|
|
|
int ret = 0;
|
2018-03-28 08:57:01 +00:00
|
|
|
int i = 0;
|
2017-12-07 07:02:05 +00:00
|
|
|
|
|
|
|
|
dev_desc = rockchip_get_bootdev();
|
2018-07-03 11:22:24 +00:00
|
|
|
if (!dev_desc) {
|
|
|
|
|
printf("%s: dev_desc is NULL!\n", __func__);
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
2018-03-19 06:39:06 +00:00
|
|
|
|
2019-01-05 04:11:22 +00:00
|
|
|
#ifdef CONFIG_ANDROID_KEYMASTER_CA
|
2018-03-19 06:39:06 +00:00
|
|
|
disk_partition_t misc_part_info;
|
|
|
|
|
|
|
|
|
|
/* load attestation key from misc partition. */
|
|
|
|
|
ret = part_get_info_by_name(dev_desc, "misc",
|
|
|
|
|
&misc_part_info);
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
printf("%s Could not find misc partition\n", __func__);
|
|
|
|
|
else
|
|
|
|
|
load_attestation_key(dev_desc, &misc_part_info);
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-05 01:09:55 +00:00
|
|
|
#ifdef CONFIG_FASTBOOT_OEM_UNLOCK
|
2018-03-28 10:03:45 +00:00
|
|
|
/* read oem unlock status and attach to bootargs */
|
|
|
|
|
uint8_t unlock = 0;
|
|
|
|
|
TEEC_Result result;
|
|
|
|
|
char oem_unlock[OEM_UNLOCK_ARG_SIZE] = {0};
|
|
|
|
|
result = trusty_read_oem_unlock(&unlock);
|
|
|
|
|
if (result) {
|
|
|
|
|
printf("read oem unlock status with error : 0x%x\n", result);
|
|
|
|
|
} else {
|
|
|
|
|
snprintf(oem_unlock, OEM_UNLOCK_ARG_SIZE, "androidboot.oem_unlocked=%d", unlock);
|
|
|
|
|
env_update("bootargs", oem_unlock);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-12-07 07:02:05 +00:00
|
|
|
mode = rockchip_get_boot_mode();
|
2018-01-12 07:38:35 +00:00
|
|
|
if (mode == BOOT_MODE_RECOVERY) {
|
2017-12-07 07:02:05 +00:00
|
|
|
boot_partname = PART_RECOVERY;
|
2018-01-12 07:38:35 +00:00
|
|
|
printf("%s boot from Recovery partition!\n", __func__);
|
|
|
|
|
}
|
2018-03-28 08:57:01 +00:00
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
|
if (!strcmp(argv[i], "boot-recovery")) {
|
|
|
|
|
boot_partname = PART_RECOVERY;
|
|
|
|
|
printf("%s argv%d:%s boot from Recovery partition!\n",
|
|
|
|
|
__func__, i, argv[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-07 07:02:05 +00:00
|
|
|
ret = part_get_info_by_name(dev_desc, boot_partname, &part_info);
|
|
|
|
|
|
|
|
|
|
if(boot_rockchip_image(dev_desc, &part_info))
|
|
|
|
|
ret = CMD_RET_FAILURE;
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
2017-12-21 08:36:31 +00:00
|
|
|
bootrkp, CONFIG_SYS_MAXARGS, 1, do_boot_rockchip,
|
|
|
|
|
"Boot Linux Image from rockchip image type",
|
|
|
|
|
"kernel.img: zImage/Image\n"
|
|
|
|
|
"boot.img: ramdisk\n"
|
|
|
|
|
"resource.img: dtb, u-boot logo, kernel logo"
|
2017-12-07 07:02:05 +00:00
|
|
|
);
|
2018-04-28 08:54:21 +00:00
|
|
|
|
|
|
|
|
static int do_rkimg_test(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
|
char * const argv[])
|
|
|
|
|
{
|
|
|
|
|
struct blk_desc *dev_desc;
|
|
|
|
|
u32* buffer;
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
|
|
dev_desc = blk_get_dev(argv[1], simple_strtoul(argv[2], NULL, 16));
|
|
|
|
|
|
|
|
|
|
buffer = memalign(ARCH_DMA_MINALIGN, 1024);
|
|
|
|
|
/* Read one block from begining of IDB data */
|
|
|
|
|
ret = blk_dread(dev_desc, 64, 2, buffer);
|
2018-05-08 08:01:50 +00:00
|
|
|
if (ret != 2) {
|
2018-04-28 08:54:21 +00:00
|
|
|
printf("%s fail to read data from IDB\n", __func__);
|
|
|
|
|
free(buffer);
|
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buffer[0] == 0xFCDC8C3B){
|
|
|
|
|
printf("%s found IDB in SDcard\n", __func__);
|
|
|
|
|
ret = CMD_RET_SUCCESS;
|
|
|
|
|
if (0 == buffer[128 + 104 / 4]) /* TAG in IDB */
|
|
|
|
|
env_update("bootargs", "sdfwupdate");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
|
rkimgtest, 3, 0, do_rkimg_test,
|
|
|
|
|
"Test if storage media have rockchip image",
|
|
|
|
|
""
|
|
|
|
|
);
|