在OP-TEE黄皮书中有关于文件保存的章节:
章节secStor_test和密钥下发章节save_key;
Invokecommand failed,ReturnCode=0Xffff ReturnOrigin=0x04
屏蔽掉删除函数,去重复的创建、写、读、创建 然后就会出上述 错误提示;
test_fun()
{
g_SecStorCa_CreateFile();
g_SecStorCa_WiteFile();
g_SecStorCa_ReadFile();
//g_SecStorCa_DeleteFile();
}
自从我发现了这个bug之后,就各种手贱去点他。并尝试从错误代码找该bug的结局方案。
一位业内大神这样说:《你把详细的错误信息好好看看追追,说不定就找到问题了。》
另外一位大神(帅峰云),《你在重新创建的时候是否又先close一下, 在代码中加一些Log看看报错在哪里,然后追一下代码》
后来在我实际使用过程中发现,严谨点根本不会出这种问题,比如你可以这样处理:
写函数:
TEEC_Result ca_write(char * name, char * buf, int length)
{
TEEC_Result res;
printf("-execute write tast.\n");
res = read_secure_object(&ctx, name,
buf, sizeof(buf));
if (res != TEEC_SUCCESS && res != TEEC_ERROR_ITEM_NOT_FOUND)
{
errx(1, "Unexpected status when reading an object : 0x%x", res);
}
if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
//char data[] = "This is data stored in the secure storage.\n";
printf("- Object not found in TA secure storage, create it.\n");
res = write_secure_object(&ctx, name,
buf, sizeof(buf));
if (res != TEEC_SUCCESS)
{
errx(1, "Failed to create/load an object");
}else {
printf("-first write success.\n");
}
} else if (res == TEEC_SUCCESS) {
printf("- Object found in TA secure storage, delete it.\n");
res = delete_secure_object(&ctx, name);
if (res != TEEC_SUCCESS)
{
errx(1, "Failed to delete an object");
}
res = write_secure_object(&ctx, name,
buf, sizeof(buf));
if (res != TEEC_SUCCESS)
{
errx(1, "Failed to create/load an object");
}else {
printf("-first delete is ,ren write success.\n");
}
}
return res;
}
读函数:
TEEC_Result ca_read(char * name, char * buf, int length)
{
TEEC_Result res;
printf("-execute write tast.\n");
res = read_secure_object(&ctx, name,
buf, sizeof(buf));
if (res != TEEC_SUCCESS && res != TEEC_ERROR_ITEM_NOT_FOUND)
{
errx(1, "Unexpected status when reading an object : 0x%x", res);
}
if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
//char data[] = "This is data stored in the secure storage.\n";
printf("- First read this file,Object not found in TA secure storage, create it.\n");
res = write_secure_object(&ctx, name,
buf, sizeof(buf));
if (res != TEEC_SUCCESS)
{
errx(1, "Failed to create/load an object");
}else {
printf("-first write success.\n");
}
} else if (res == TEEC_SUCCESS)
{
printf("- Object found in TA secure storage, read it.\n");
}
return res;
}