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.
150 lines
4.0 KiB
150 lines
4.0 KiB
4 months ago
|
/*
|
||
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2021. All rights reserved.
|
||
|
* Description: Test the file of the chip id interface.
|
||
|
* Author: Hisilicon
|
||
|
* Create: 2019-09-20
|
||
|
*/
|
||
|
|
||
|
#include "sample_otp_base.h"
|
||
|
|
||
|
static td_s32 get_chip_id(td_s32 argc, td_char *argv[]);
|
||
|
static td_s32 set_chip_id(td_s32 argc, td_char *argv[]);
|
||
|
|
||
|
static otp_sample g_otp_sample_data[] = {
|
||
|
{ 0, "help", NULL, { "Display this help and exit.", "example: ./sample_otp_chipid help" } },
|
||
|
{
|
||
|
1, "set", set_chip_id,
|
||
|
{ "Set chip id --> UAPI_OTP_CHIPID0.", "example: ./sample_otp_chipid set chip_id0" }
|
||
|
},
|
||
|
{
|
||
|
2, "set", set_chip_id,
|
||
|
{ "Set chip id --> UAPI_OTP_CHIPID1.", "example: ./sample_otp_chipid set chip_id1" }
|
||
|
},
|
||
|
{
|
||
|
3, "set", set_chip_id,
|
||
|
{ "Set chip id --> UAPI_OTP_CHIPID2.", "example: ./sample_otp_chipid set chip_id2" }
|
||
|
},
|
||
|
{
|
||
|
4, "get", get_chip_id,
|
||
|
{ "Get chip id --> UAPI_OTP_CHIPID0.", "example: ./sample_otp_chipid get chip_id0" }
|
||
|
},
|
||
|
{
|
||
|
5, "get", get_chip_id,
|
||
|
{ "Get chip id --> UAPI_OTP_CHIPID1.", "example: ./sample_otp_chipid get chip_id1" }
|
||
|
},
|
||
|
{
|
||
|
6, "get", get_chip_id,
|
||
|
{ "Get chip id --> UAPI_OTP_CHIPID2.", "example: ./sample_otp_chipid get chip_id2" }
|
||
|
},
|
||
|
};
|
||
|
|
||
|
static td_void get_type(td_s32 argc, td_char *argv[], uapi_otp_chipid_sel *chip_id_sel)
|
||
|
{
|
||
|
if (argv[0x2] == TD_NULL) {
|
||
|
sample_printf("argv[2] is NULL\n");
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
if (chip_id_sel == TD_NULL) {
|
||
|
sample_printf("chip_id_sel is NULL\n");
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
if (case_strcmp("chip_id0", argv[0x2])) {
|
||
|
*chip_id_sel = UAPI_OTP_CHIPID0;
|
||
|
} else if (case_strcmp("chip_id1", argv[0x2])) {
|
||
|
*chip_id_sel = UAPI_OTP_CHIPID1;
|
||
|
} else if (case_strcmp("chip_id2", argv[0x2])) {
|
||
|
*chip_id_sel = UAPI_OTP_CHIPID2;
|
||
|
} else {
|
||
|
*chip_id_sel = UAPI_OTP_CHIPID_MAX;
|
||
|
}
|
||
|
|
||
|
unused(argc);
|
||
|
out:
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
static td_s32 get_chip_id(td_s32 argc, td_char *argv[])
|
||
|
{
|
||
|
td_s32 ret;
|
||
|
td_u8 chip_id[0x8] = {0};
|
||
|
td_u32 len = sizeof(chip_id);
|
||
|
uapi_otp_chipid_sel chip_id_sel = UAPI_OTP_CHIPID_MAX;
|
||
|
|
||
|
get_type(argc, argv, &chip_id_sel);
|
||
|
if (chip_id_sel == UAPI_OTP_CHIPID_MAX) {
|
||
|
sample_printf("Don't have chip id sel\n");
|
||
|
ret = TD_FAILURE;
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
ret = uapi_otp_get_chip_id(chip_id_sel, chip_id, &len);
|
||
|
if (ret != TD_SUCCESS) {
|
||
|
sample_printf("Failed to get chip id, ret = 0x%x \n", ret);
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
print_buffer("Get chip id", chip_id, sizeof(chip_id));
|
||
|
|
||
|
out:
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
static td_s32 set_chip_id(td_s32 argc, td_char *argv[])
|
||
|
{
|
||
|
td_s32 ret;
|
||
|
td_u8 chip_id[0x8] = { 0x21, 0x32, 0x43, 0x54, 0x44, 0x55, 0x66, 0x77 };
|
||
|
uapi_otp_chipid_sel chip_id_sel = UAPI_OTP_CHIPID_MAX;
|
||
|
|
||
|
get_type(argc, argv, &chip_id_sel);
|
||
|
if (chip_id_sel == UAPI_OTP_CHIPID_MAX) {
|
||
|
sample_printf("Don't have chip id sel\n");
|
||
|
ret = TD_FAILURE;
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
ret = uapi_otp_set_chip_id(chip_id_sel, chip_id, sizeof(chip_id));
|
||
|
if (ret != TD_SUCCESS) {
|
||
|
sample_printf("Failed to set chip id, ret = 0x%x \n", ret);
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
print_buffer("Set chip id", chip_id, sizeof(chip_id));
|
||
|
|
||
|
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;
|
||
|
}
|