2017-12-07 07:02:05 +00:00
|
|
|
/*
|
|
|
|
|
* (C) Copyright 2017 Rockchip Electronics Co., Ltd
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-07-10 08:14:23 +00:00
|
|
|
#include <boot_rkimg.h>
|
|
|
|
|
#include <keymaster.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
|
|
|
|
|
|
|
|
static int do_boot_rockchip(cmd_tbl_t *cmdtp, int flag, int argc,
|
2019-07-10 08:14:23 +00:00
|
|
|
char *const argv[])
|
2017-12-07 07:02:05 +00:00
|
|
|
{
|
2019-07-10 08:14:23 +00:00
|
|
|
char *boot_partname = PART_BOOT;
|
2017-12-07 07:02:05 +00:00
|
|
|
disk_partition_t part_info;
|
|
|
|
|
struct blk_desc *dev_desc;
|
2019-07-10 08:14:23 +00:00
|
|
|
int i, ret;
|
|
|
|
|
int mode;
|
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__);
|
2019-03-08 07:58:26 +00:00
|
|
|
return CMD_RET_FAILURE;
|
2018-07-03 11:22:24 +00:00
|
|
|
}
|
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
|
|
|
/* load attestation key from misc partition. */
|
2019-07-10 08:14:23 +00:00
|
|
|
ret = part_get_info_by_name(dev_desc, PART_MISC, &part_info);
|
2018-03-19 06:39:06 +00:00
|
|
|
if (ret < 0)
|
2019-07-10 08:14:23 +00:00
|
|
|
printf("%s: Could not find misc partition\n", __func__);
|
2018-03-19 06:39:06 +00:00
|
|
|
else
|
2019-07-10 08:14:23 +00:00
|
|
|
load_attestation_key(dev_desc, &part_info);
|
2018-03-19 06:39:06 +00:00
|
|
|
#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 */
|
2019-07-10 08:14:23 +00:00
|
|
|
char oem_unlock[30] = {0};
|
2018-03-28 10:03:45 +00:00
|
|
|
TEEC_Result result;
|
2019-07-10 08:14:23 +00:00
|
|
|
uint8_t unlock = 0;
|
|
|
|
|
|
2018-03-28 10:03:45 +00:00
|
|
|
result = trusty_read_oem_unlock(&unlock);
|
|
|
|
|
if (result) {
|
2019-07-10 08:14:23 +00:00
|
|
|
printf("%s: Read oem unlock status failed: %d\n",
|
|
|
|
|
__func__, result);
|
2018-03-28 10:03:45 +00:00
|
|
|
} else {
|
2019-07-10 08:14:23 +00:00
|
|
|
snprintf(oem_unlock, sizeof(oem_unlock),
|
|
|
|
|
"androidboot.oem_unlocked=%d", unlock);
|
2018-03-28 10:03:45 +00:00
|
|
|
env_update("bootargs", oem_unlock);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-12-07 07:02:05 +00:00
|
|
|
mode = rockchip_get_boot_mode();
|
2019-07-10 08:14:23 +00:00
|
|
|
if (mode == BOOT_MODE_RECOVERY)
|
2017-12-07 07:02:05 +00:00
|
|
|
boot_partname = PART_RECOVERY;
|
2018-03-28 08:57:01 +00:00
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
|
if (!strcmp(argv[i], "boot-recovery")) {
|
|
|
|
|
boot_partname = PART_RECOVERY;
|
2019-07-10 08:14:23 +00:00
|
|
|
printf("Boot from Recovery partition\n");
|
2018-03-28 08:57:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-07 07:02:05 +00:00
|
|
|
ret = part_get_info_by_name(dev_desc, boot_partname, &part_info);
|
2019-07-10 08:14:23 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
|
printf("%s: Could not find %s part\n", __func__, part_info.name);
|
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
}
|
2017-12-07 07:02:05 +00:00
|
|
|
|
2019-07-10 08:14:23 +00:00
|
|
|
return boot_rockchip_image(dev_desc, &part_info) ? CMD_RET_FAILURE : 0;
|
2017-12-07 07:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2019-07-10 08:14:23 +00:00
|
|
|
char *const argv[])
|
2018-04-28 08:54:21 +00:00
|
|
|
{
|
|
|
|
|
struct blk_desc *dev_desc;
|
2019-07-10 08:14:23 +00:00
|
|
|
u32 *buffer;
|
|
|
|
|
int ret;
|
2018-04-28 08:54:21 +00:00
|
|
|
|
|
|
|
|
dev_desc = blk_get_dev(argv[1], simple_strtoul(argv[2], NULL, 16));
|
2019-07-10 08:14:23 +00:00
|
|
|
if (!dev_desc) {
|
|
|
|
|
printf("%s: dev_desc is NULL!\n", __func__);
|
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
}
|
2018-04-28 08:54:21 +00:00
|
|
|
|
2019-07-10 08:14:23 +00:00
|
|
|
/* Read one block from beginning of IDB data */
|
2018-04-28 08:54:21 +00:00
|
|
|
buffer = memalign(ARCH_DMA_MINALIGN, 1024);
|
|
|
|
|
ret = blk_dread(dev_desc, 64, 2, buffer);
|
2018-05-08 08:01:50 +00:00
|
|
|
if (ret != 2) {
|
2019-07-10 08:14:23 +00:00
|
|
|
printf("%s: Fail to read data from IDB\n", __func__);
|
2018-04-28 08:54:21 +00:00
|
|
|
free(buffer);
|
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-10 08:14:23 +00:00
|
|
|
if (buffer[0] == 0xFCDC8C3B) {
|
|
|
|
|
printf("Found IDB in SDcard\n");
|
2019-10-14 12:23:14 +00:00
|
|
|
ret = CMD_RET_SUCCESS;
|
2018-04-28 08:54:21 +00:00
|
|
|
if (0 == buffer[128 + 104 / 4]) /* TAG in IDB */
|
|
|
|
|
env_update("bootargs", "sdfwupdate");
|
2019-10-14 12:23:14 +00:00
|
|
|
} else {
|
|
|
|
|
ret = CMD_RET_FAILURE;
|
2018-04-28 08:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
|
|
2019-10-14 12:23:14 +00:00
|
|
|
return ret;
|
2018-04-28 08:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
|
rkimgtest, 3, 0, do_rkimg_test,
|
|
|
|
|
"Test if storage media have rockchip image",
|
|
|
|
|
""
|
|
|
|
|
);
|