You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
3.9 KiB
143 lines
3.9 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2021. All rights reserved.
|
|
* Description: Test the file of the trust zone interface.
|
|
* Author: Hisilicon
|
|
* Create: 2019-09-19
|
|
*/
|
|
#include "sample_otp_base.h"
|
|
|
|
static td_s32 get_trust_zone_stat(td_s32 argc, td_char *argv[]);
|
|
static td_s32 get_trust_zone_stat_old(td_s32 argc, td_char *argv[]);
|
|
static td_s32 set_enable_trust_zone(td_s32 argc, td_char *argv[]);
|
|
static td_s32 whole_enable_trust_zone(td_s32 argc, td_char *argv[]);
|
|
|
|
static otp_sample g_otp_sample_data[] = {
|
|
{ 0, "help", NULL, { "Display this help and exit.", "example: ./sample_otp_trustzone help" } },
|
|
{ 1, "set", set_enable_trust_zone, { "Set enable trust zone.", "example: ./sample_otp_trustzone set" } },
|
|
{ 2, "set_all", whole_enable_trust_zone, { "Set enable trust zone.", "example: ./sample_otp_trustzone set_all" } },
|
|
{ 3, "get", get_trust_zone_stat, { "Get trust zone stat.", "example: ./sample_otp_trustzone get" } },
|
|
{ 4, "get_old", get_trust_zone_stat_old, { "Get trust zone old stat.", "example: ./sample_otp_trustzone get_old" } },
|
|
};
|
|
|
|
static td_s32 get_trust_zone_stat(td_s32 argc, td_char *argv[])
|
|
{
|
|
td_s32 ret;
|
|
td_bool stat = TD_FALSE;
|
|
uapi_otp_rootkey root_key_slot = UAPI_OTP_ROOTKEY_MAX;
|
|
|
|
ret = uapi_otp_get_jtag_key_slot(&root_key_slot);
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("Failed to get jtag key slot, ret = 0x%x \n", ret);
|
|
goto out;
|
|
}
|
|
|
|
ret = uapi_otp_get_trust_zone_stat(&stat);
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("Failed to get trust zone stat, ret = 0x%x \n", ret);
|
|
goto out;
|
|
}
|
|
|
|
sample_printf("Get jtag key slot : %d\n", root_key_slot);
|
|
sample_printf("Get trust zone stat : %d\n", stat);
|
|
|
|
unused(argc);
|
|
unused(argv);
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
static td_s32 get_trust_zone_stat_old(td_s32 argc, td_char *argv[])
|
|
{
|
|
td_s32 ret;
|
|
td_bool stat = TD_FALSE;
|
|
|
|
ret = uapi_otp_get_trust_zone_stat(&stat);
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("Failed to get trust zone stat, ret = 0x%x \n", ret);
|
|
goto out;
|
|
}
|
|
|
|
sample_printf("Get trust zone stat : %d\n", stat);
|
|
|
|
unused(argc);
|
|
unused(argv);
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
static td_s32 whole_enable_trust_zone(td_s32 argc, td_char *argv[])
|
|
{
|
|
td_s32 ret;
|
|
|
|
ret = uapi_otp_jtag_key_sel(UAPI_OTP_CAS_ROOTKEY0);
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("Select otp jtag key, ret = 0x%x \n", ret);
|
|
goto out;
|
|
}
|
|
|
|
ret = uapi_otp_burn_to_secure_chipset();
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("Burn to secure chipset, ret = 0x%x \n", ret);
|
|
goto out;
|
|
}
|
|
|
|
ret = uapi_otp_enable_trust_zone();
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("Enable trust zone failed, ret = 0x%x \n", ret);
|
|
goto out;
|
|
}
|
|
|
|
unused(argc);
|
|
unused(argv);
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
static td_s32 set_enable_trust_zone(td_s32 argc, td_char *argv[])
|
|
{
|
|
td_s32 ret;
|
|
|
|
ret = uapi_otp_enable_trust_zone();
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("Enable trust zone failed, ret = 0x%x \n", ret);
|
|
goto out;
|
|
}
|
|
|
|
unused(argc);
|
|
unused(argv);
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
td_s32 main(int argc, char *argv[])
|
|
{
|
|
td_s32 ret;
|
|
|
|
if (argc < 0x2) {
|
|
sample_printf("sample parameter error.\n");
|
|
ret = SOC_ERR_OTP_INVALID_PARA;
|
|
goto out1;
|
|
}
|
|
|
|
if (case_strcmp("help", argv[1])) {
|
|
show_usage(g_otp_sample_data, sizeof(g_otp_sample_data) / sizeof(g_otp_sample_data[0]));
|
|
ret = TD_SUCCESS;
|
|
goto out0;
|
|
}
|
|
|
|
ret = uapi_otp_init();
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("OTP init failed, ret = 0x%x \n", ret);
|
|
goto out1;
|
|
}
|
|
|
|
ret = run_cmdline(argc, argv, g_otp_sample_data, sizeof(g_otp_sample_data) / sizeof(g_otp_sample_data[0]));
|
|
|
|
(td_void)uapi_otp_deinit();
|
|
|
|
out1:
|
|
show_returne_msg(g_otp_sample_data, sizeof(g_otp_sample_data) / sizeof(g_otp_sample_data[0]), ret);
|
|
out0:
|
|
return ret;
|
|
}
|