我只在5.1.2上面进行过测试,我稍后在6.0上测试下
如果和demo完全一致将会导致编译问题,我在移植时并没有更改代码本身的逻辑,相同逻辑的代码在qemu上验证过,这个问题应该还是OP-TEE本身问题,我试过运行程序每次只进行一次打开persist操作就不会有这样的问题。
比如我将main函数改成这样
int main(int argc, char *argv[])
{
struct test_ctx ctx;
char obj1_id[] = "object#1"; /* string identification for the object */
char obj2_id[] = "object#2"; /* string identification for the object */
char obj1_data[TEST_OBJECT_SIZE];
char read_data[TEST_OBJECT_SIZE];
TEEC_Result res;
int go=0;
int opt;
printf("Prepare session with the TA\n");
prepare_tee_session(&ctx);
// 解析命令行选项
while ((opt = getopt(argc, argv, "abc")) != -1) {
switch (opt) {
case 'a':
go=1;
break;
case 'b':
go=2;
break;
case 'c':
go=3;
break;
default:
fprintf(stderr, "Usage: %s [-a] [-b] [-c]\n", argv[0]);
exit(EXIT_FAILURE);
}
}
if(1==go)
{ /*
* Create object, read it, delete it.
*/
printf("\nTest on object \"%s\"\n", obj1_id);
printf("- Create and load object in the TA secure storage\n");
memset(obj1_data, 0xA1, sizeof(obj1_data));
res = write_secure_object(&ctx, obj1_id,
obj1_data, sizeof(obj1_data));
if (res != TEEC_SUCCESS)
errx(1, "Failed to create an object in the secure storage");
printf("- Read back the object\n");
res = read_secure_object(&ctx, obj1_id,
read_data, sizeof(read_data));
if (res != TEEC_SUCCESS)
errx(1, "Failed to read an object from the secure storage");
if (memcmp(obj1_data, read_data, sizeof(obj1_data)))
errx(1, "Unexpected content found in secure storage");
}
//2
if(2==go)
{ printf("- Delete the object\n");
res = delete_secure_object(&ctx, obj1_id);
if (res != TEEC_SUCCESS)
errx(1, "Failed to delete the object: 0x%x", res);
}
//3
if(3==go)
{ /*
* Non volatile storage: create object2 if not found, delete it if found
*/
printf("\nTest on object \"%s\"\n", obj2_id);
res = read_secure_object(&ctx, obj2_id,
read_data, sizeof(read_data));
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, obj2_id,
data, sizeof(data));
if (res != TEEC_SUCCESS)
errx(1, "Failed to create/load an object");
} else if (res == TEEC_SUCCESS) {
printf("- Object found in TA secure storage, delete it.\n");
res = delete_secure_object(&ctx, obj2_id);
if (res != TEEC_SUCCESS)
errx(1, "Failed to delete an object");
}
}
printf("\nWe're done, close and release TEE resources\n");
terminate_tee_session(&ctx);
return 0;
}
我的运行结果
zme@zme-0020:~$ sudo nvsecure_storage-app -a
Prepare session with the TA
Test on object "object#1"
- Create and load object in the TA secure storage
- Read back the object
We're done, close and release TEE resources
zme@zme-0020:~$
zme@zme-0020:~$ sudo nvsecure_storage-app -b
Prepare session with the TA
- Delete the object
We're done, close and release TEE resources
zme@zme-0020:~$
zme@zme-0020:~$ sudo nvsecure_storage-app -b
Prepare session with the TA
- Delete the object
nvsecure_storage-app: Failed to delete the object: 0xffff0008
zme@zme-0020:~$
zme@zme-0020:~$ sudo nvsecure_storage-app -c
Prepare session with the TA
Test on object "object#2"
- Object found in TA secure storage, delete it.
Command DELETE failed: 0xffff0003 / 4
nvsecure_storage-app: Failed to delete an object
zme@zme-0020:~$
create_raw_object包含TEE_CreatePersistentObject
read_raw_object和delete_object包含TEE_OpenPersistentObject
当我单独运行-a 和 -b时不会有问题,因为无论如何只会有一次open操作。
当我运行-c时,此时同时read和delete就会报0xffff0003的错误,该错误的错误码是TEE_ERROR_ACCESS_CONFLICT。我猜测是否在5.1.2的源码中并没有正确的close PersistentObject?
如果方便的话,可否帮忙在您那边测试下?
这是我的op-tee版本信息
nv-optee
commit 3002010db67633448c9733611886f7d45db1f2f3 (HEAD -> mybranch_2024-01-30-1706579528, tag: jetson_35.4.1, origin/l4t/l4t-r35.4.ga, mybranch_2024-01-29-1706529276, mybranch_2024-01-25-1706162118, mybranch_2024-01-25-1706155266)
ATF
commit 794affd212cd6488079861dd18d57c0d510d6da9 (HEAD -> mybranch_2024-01-30-1706579528, tag: jetson_35.4.1, origin/l4t/l4t-r35.4.ga, mybranch_2024-01-29-1706529276, mybranch_2024-01-25-1706162117, mybranch_2024-01-25-1706155262)