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.

88 lines
2.4 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2021. All rights reserved.
* Description: Test the file of the boot version id interface.
* Author: Hisilicon
* Create: 2019-09-20
*/
#include "sample_otp_base.h"
static td_s32 get_boot_version_id(td_s32 argc, td_char *argv[]);
static td_s32 set_boot_version_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_bootversionid help" } },
{ 1, "set", set_boot_version_id, { "Set boot version id.", "example: ./sample_otp_bootversionid set" } },
{ 2, "get", get_boot_version_id, { "Get boot version id.", "example: ./sample_otp_bootversionid get" } },
};
static td_s32 get_boot_version_id(td_s32 argc, td_char *argv[])
{
td_s32 ret;
td_u8 version_id[0x4] = {0};
td_u32 len = sizeof(version_id);
ret = uapi_otp_get_boot_version_id(version_id, &len);
if (ret != TD_SUCCESS) {
sample_printf("Failed to get boot version id, ret = 0x%x \n", ret);
goto out;
}
print_buffer("Get boot version id", version_id, sizeof(version_id));
unused(argc);
unused(argv);
out:
return ret;
}
static td_s32 set_boot_version_id(td_s32 argc, td_char *argv[])
{
td_s32 ret;
td_u8 version_id[0x4] = { 0x21, 0x32, 0x43, 0x54 };
ret = uapi_otp_set_boot_version_id(version_id, sizeof(version_id));
if (ret != TD_SUCCESS) {
sample_printf("Failed to set boot version id, ret = 0x%x \n", ret);
goto out;
}
print_buffer("Set boot version id", version_id, sizeof(version_id));
unused(argc);
unused(argv);
out:
return ret;
}
td_s32 main(int argc, char *argv[])
{
td_s32 ret;
if (argc < 0x2 || argv == TD_NULL) {
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;
}