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.
169 lines
4.5 KiB
169 lines
4.5 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2021. All rights reserved.
|
|
* Description: Test the file of the msid interface.
|
|
* Author: Hisilicon
|
|
* Create: 2019-09-20
|
|
*/
|
|
#include "sample_otp_base.h"
|
|
|
|
static td_s32 get_msid(td_s32 argc, td_char *argv[]);
|
|
static td_s32 set_msid(td_s32 argc, td_char *argv[]);
|
|
|
|
static otp_sample g_otp_sample_data[] = {
|
|
{ 0, "help", NULL, { "Display this help and exit.", "example: ./sample_otp_msid help" } },
|
|
{
|
|
1, "set", set_msid,
|
|
{ "Set msid --> UAPI_OTP_MSID_BOOT.", "example: ./sample_otp_msid set boot" }
|
|
},
|
|
{
|
|
2, "set", set_msid,
|
|
{ "Set msid --> UAPI_OTP_MSID_TEE.", "example: ./sample_otp_msid set tee" }
|
|
},
|
|
{
|
|
3, "set", set_msid,
|
|
{ "Set msid --> UAPI_OTP_MSID_HRF.", "example: ./sample_otp_msid set hrf" }
|
|
},
|
|
{
|
|
4, "set", set_msid,
|
|
{ "Set msid --> UAPI_OTP_MSID_ADSP.", "example: ./sample_otp_msid set adsp" }
|
|
},
|
|
{
|
|
5, "set", set_msid,
|
|
{ "Set msid --> UAPI_OTP_MSID_VMCU.", "example: ./sample_otp_msid set vmcu" }
|
|
},
|
|
{
|
|
6, "get", get_msid,
|
|
{ "Get msid --> UAPI_OTP_MSID_BOOT.", "example: ./sample_otp_msid get boot" }
|
|
},
|
|
{
|
|
7, "get", get_msid,
|
|
{ "Get msid --> UAPI_OTP_MSID_TEE.", "example: ./sample_otp_msid get tee" }
|
|
},
|
|
{
|
|
8, "get", get_msid,
|
|
{ "Get msid --> UAPI_OTP_MSID_HRF.", "example: ./sample_otp_msid get hrf" }
|
|
},
|
|
{
|
|
9, "get", get_msid,
|
|
{ "Get msid --> UAPI_OTP_MSID_ADSP.", "example: ./sample_otp_msid get adsp" }
|
|
},
|
|
{
|
|
10, "get", get_msid,
|
|
{ "Get msid --> UAPI_OTP_MSID_VMCU.", "example: ./sample_otp_msid get vmcu" }
|
|
},
|
|
};
|
|
|
|
static td_void get_type(td_s32 argc, td_char *argv[], uapi_otp_msid_type *msid_type)
|
|
{
|
|
if (argv[0x2] == TD_NULL) {
|
|
sample_printf("argv[2] is NULL\n");
|
|
goto out;
|
|
}
|
|
|
|
if (msid_type == TD_NULL) {
|
|
sample_printf("msid_type is NULL\n");
|
|
goto out;
|
|
}
|
|
|
|
if (case_strcmp("boot", argv[0x2])) {
|
|
*msid_type = UAPI_OTP_MSID_BOOT;
|
|
} else if (case_strcmp("tee", argv[0x2])) {
|
|
*msid_type = UAPI_OTP_MSID_TEE;
|
|
} else if (case_strcmp("hrf", argv[0x2])) {
|
|
*msid_type = UAPI_OTP_MSID_HRF;
|
|
} else if (case_strcmp("adsp", argv[0x2])) {
|
|
*msid_type = UAPI_OTP_MSID_ADSP;
|
|
} else if (case_strcmp("vmcu", argv[0x2])) {
|
|
*msid_type = UAPI_OTP_MSID_VMCU;
|
|
} else {
|
|
*msid_type = UAPI_OTP_MSID_MAX;
|
|
}
|
|
|
|
unused(argc);
|
|
out:
|
|
return;
|
|
}
|
|
|
|
static td_s32 get_msid(td_s32 argc, td_char *argv[])
|
|
{
|
|
td_s32 ret;
|
|
td_u8 msid[0x4] = {0};
|
|
td_u32 len = sizeof(msid);
|
|
uapi_otp_msid_type msid_type = UAPI_OTP_MSID_MAX;
|
|
|
|
get_type(argc, argv, &msid_type);
|
|
if (msid_type == UAPI_OTP_MSID_MAX) {
|
|
sample_printf("Don't have msid type\n");
|
|
ret = TD_FAILURE;
|
|
goto out;
|
|
}
|
|
|
|
ret = uapi_otp_get_msid(msid_type, msid, &len);
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("Failed to get msid, ret = 0x%x \n", ret);
|
|
goto out;
|
|
}
|
|
|
|
print_buffer("Get msid", msid, sizeof(msid));
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
static td_s32 set_msid(td_s32 argc, td_char *argv[])
|
|
{
|
|
td_s32 ret;
|
|
td_u8 msid[0x4] = { 0x44, 0x55, 0x66, 0x77 };
|
|
uapi_otp_msid_type msid_type = UAPI_OTP_MSID_MAX;
|
|
|
|
get_type(argc, argv, &msid_type);
|
|
if (msid_type == UAPI_OTP_MSID_MAX) {
|
|
sample_printf("Don't have msid\n");
|
|
ret = TD_FAILURE;
|
|
goto out;
|
|
}
|
|
|
|
ret = uapi_otp_set_msid(msid_type, msid, sizeof(msid));
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("Failed to set chip id, ret = 0x%x \n", ret);
|
|
goto out;
|
|
}
|
|
|
|
print_buffer("Set msid", msid, sizeof(msid));
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
td_s32 main(int argc, char *argv[])
|
|
{
|
|
td_s32 ret;
|
|
|
|
if (argc < 0x3) {
|
|
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;
|
|
}
|