/* * Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2021. All rights reserved. * Description: Test the file of the privdata interface. * Author: Hisilicon * Create: 2019-09-19 */ #include "sample_otp_base.h" static td_s32 get_privdata(td_s32 argc, td_char *argv[]); static td_s32 set_privdata(td_s32 argc, td_char *argv[]); static otp_sample g_otp_sample_data[] = { { 0, "help", NULL, { "Display this help and exit.", "example: ./sample_otp_privdata help" } }, { 1, "set", set_privdata, { "Set privdata.", "example: ./sample_otp_privdata set" } }, { 2, "get", get_privdata, { "Get privdata.", "example: ./sample_otp_privdata get" } }, }; static td_s32 get_privdata(td_s32 argc, td_char *argv[]) { td_s32 ret; td_u8 privdata[KEY_LEN] = {0}; td_u32 i; for (i = 0; i < KEY_LEN; i++) { ret = uapi_otp_get_priv_data(i, &privdata[i], 0x1); if (ret != TD_SUCCESS) { sample_printf("Failed to get private data, ret = 0x%x \n", ret); goto out; } } print_buffer("Get private data", privdata, sizeof(privdata)); unused(argc); unused(argv); out: return ret; } static td_s32 set_privdata(td_s32 argc, td_char *argv[]) { td_s32 ret; td_u8 privdata[KEY_LEN] = { 0x10, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, }; td_u32 i; for (i = 0; i < KEY_LEN; i++) { ret = uapi_otp_set_priv_data(i, &privdata[i], 0x1); if (ret != TD_SUCCESS) { sample_printf("Failed to set private data, ret = 0x%x \n", ret); goto out; } } print_buffer("Set private data", privdata, sizeof(privdata)); 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; }