lib: optee_client v1: support RKFS version 2
1.use get_rkss_version function to get rkss version, if security partition have data with rkss version 1, then we choice rkss version 1, if security partition is empty, then we choice rkss version 2 2.rkss version 2 support dual backup mechanism, security partition total use 1M 3.rkss version 2 R&W 256k data one time Change-Id: I4103b6600666dffccf473ec4ed8854776a46da31 Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
This commit is contained in:
parent
986192a2bc
commit
d079c1a5ed
|
|
@ -29,12 +29,97 @@
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
int tee_supp_rk_fs_init(void);
|
||||
/*
|
||||
* Operations and defines shared with TEE.
|
||||
*/
|
||||
#define TEE_FS_OPEN 1
|
||||
#define TEE_FS_CLOSE 2
|
||||
#define TEE_FS_READ 3
|
||||
#define TEE_FS_WRITE 4
|
||||
#define TEE_FS_SEEK 5
|
||||
#define TEE_FS_UNLINK 6
|
||||
#define TEE_FS_RENAME 7
|
||||
#define TEE_FS_TRUNC 8
|
||||
#define TEE_FS_MKDIR 9
|
||||
#define TEE_FS_OPENDIR 10
|
||||
#define TEE_FS_CLOSEDIR 11
|
||||
#define TEE_FS_READDIR 12
|
||||
#define TEE_FS_RMDIR 13
|
||||
#define TEE_FS_ACCESS 14
|
||||
#define TEE_FS_LINK 15
|
||||
|
||||
int tee_supp_rk_fs_process(void *cmd, uint32_t cmd_size);
|
||||
/*
|
||||
* Open flags, defines shared with TEE.
|
||||
*/
|
||||
#define TEE_FS_O_RDONLY 0x1
|
||||
#define TEE_FS_O_WRONLY 0x2
|
||||
#define TEE_FS_O_RDWR 0x4
|
||||
#define TEE_FS_O_CREAT 0x8
|
||||
#define TEE_FS_O_EXCL 0x10
|
||||
#define TEE_FS_O_APPEND 0x20
|
||||
|
||||
/*
|
||||
* Seek flags, defines shared with TEE.
|
||||
*/
|
||||
#define TEE_FS_SEEK_SET 0x1
|
||||
#define TEE_FS_SEEK_END 0x2
|
||||
#define TEE_FS_SEEK_CUR 0x4
|
||||
|
||||
/*
|
||||
* Mkdir flags, defines shared with TEE.
|
||||
*/
|
||||
#define TEE_FS_S_IWUSR 0x1
|
||||
#define TEE_FS_S_IRUSR 0x2
|
||||
|
||||
/*
|
||||
* Access flags, X_OK not supported, defines shared with TEE.
|
||||
*/
|
||||
#define TEE_FS_R_OK 0x1
|
||||
#define TEE_FS_W_OK 0x2
|
||||
#define TEE_FS_F_OK 0x4
|
||||
|
||||
#define RK_FS_R 0x1
|
||||
#define RK_FS_W 0x2
|
||||
#define RK_FS_D 0x8
|
||||
|
||||
/* Function Defines */
|
||||
#define UNREFERENCED_PARAMETER(P) (P = P)
|
||||
#define CHECKFLAG(flags, flag) (flags & flag)
|
||||
#define ADDFLAG(flags, flag) (flags | flag)
|
||||
|
||||
#define RKSS_VERSION_V1 1
|
||||
#define RKSS_VERSION_V2 2
|
||||
#define RKSS_VERSION_ERR 100
|
||||
|
||||
/*
|
||||
* Structure for file related RPC calls
|
||||
*
|
||||
* @op The operation like open, close, read, write etc
|
||||
* @flags Flags to the operation shared with secure world
|
||||
* @arg Argument to operation
|
||||
* @fd NW file descriptor
|
||||
* @len Length of buffer at the end of this struct
|
||||
* @res Result of the operation
|
||||
*/
|
||||
struct tee_fs_rpc {
|
||||
int op;
|
||||
int flags;
|
||||
int arg;
|
||||
int fd;
|
||||
uint32_t len;
|
||||
int res;
|
||||
};
|
||||
|
||||
int tee_supp_rk_fs_init_v1(void);
|
||||
|
||||
int tee_supp_rk_fs_process_v1(void *cmd, size_t cmd_size);
|
||||
|
||||
int tee_supp_rk_fs_init_v2(void);
|
||||
|
||||
int tee_supp_rk_fs_process_v2(void *cmd, size_t cmd_size);
|
||||
|
||||
int OpteeClientRkFsInit(void);
|
||||
|
||||
int check_security_exist(int print_flag);
|
||||
int OpteeClientRkFsProcess(void *cmd, size_t cmd_size);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ obj-y += OpteeClientRPC.o
|
|||
obj-y += tee_smc-arm64.o
|
||||
|
||||
ifdef CONFIG_OPTEE_V1
|
||||
obj-y += OpteeClientRkFs.o
|
||||
obj-y += OpteeClientRkFs_common.o
|
||||
obj-y += OpteeClientRkFs_v1.o
|
||||
obj-y += OpteeClientRkFs_v2.o
|
||||
endif
|
||||
|
||||
ifdef CONFIG_OPTEE_V2
|
||||
|
|
|
|||
|
|
@ -518,14 +518,9 @@ TEEC_Result OpteeRpcCmdFs(t_teesmc32_arg *TeeSmc32Arg)
|
|||
TEEC_Result TeecResult = TEEC_SUCCESS;
|
||||
t_teesmc32_param *TeeSmc32Param;
|
||||
|
||||
if (check_security_exist(0) < 0) {
|
||||
printf("TEEC: security partition not exist! unable to use RK FS!\n");
|
||||
return TEEC_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
TeeSmc32Param = TEESMC32_GET_PARAMS(TeeSmc32Arg);
|
||||
#ifdef CONFIG_OPTEE_V1
|
||||
TeecResult = tee_supp_rk_fs_process((void *)(size_t)TeeSmc32Param[0].u.memref.buf_ptr,
|
||||
TeecResult = OpteeClientRkFsProcess((void *)(size_t)TeeSmc32Param[0].u.memref.buf_ptr,
|
||||
TeeSmc32Param[0].u.memref.size);
|
||||
#endif
|
||||
#ifdef CONFIG_OPTEE_V2
|
||||
|
|
|
|||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright 2020, Rockchip Electronics Co., Ltd
|
||||
* hisping lin, <hisping.lin@rock-chips.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <stdlib.h>
|
||||
#include <command.h>
|
||||
#include <boot_rkimg.h>
|
||||
#include <part.h>
|
||||
#include <optee_include/OpteeClientRkFs.h>
|
||||
|
||||
static int rkss_version;
|
||||
static int get_rkss_version(void)
|
||||
{
|
||||
struct blk_desc *dev_desc = NULL;
|
||||
disk_partition_t part_info;
|
||||
uint8_t *read_buff;
|
||||
unsigned long ret = 0;
|
||||
uint32_t *version;
|
||||
uint32_t *checkstr;
|
||||
|
||||
if (rkss_version != 0)
|
||||
return rkss_version;
|
||||
|
||||
dev_desc = rockchip_get_bootdev();
|
||||
if (!dev_desc) {
|
||||
printf("TEEC: %s: Could not find device\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (part_get_info_by_name(dev_desc,
|
||||
"security", &part_info) < 0) {
|
||||
printf("TEEC: Waring: Could not find security partition\n");
|
||||
rkss_version = RKSS_VERSION_ERR;
|
||||
return rkss_version;
|
||||
}
|
||||
|
||||
read_buff = (uint8_t *)malloc(512);
|
||||
if (!read_buff) {
|
||||
printf("TEEC: Malloc failed!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = blk_dread(dev_desc, part_info.start, 1, read_buff);
|
||||
if (ret != 1) {
|
||||
printf("TEEC: blk_dread fail\n");
|
||||
free(read_buff);
|
||||
return -1;
|
||||
}
|
||||
|
||||
version = (uint32_t *)(read_buff + 512 - 8);
|
||||
checkstr = (uint32_t *)(read_buff + 512 - 4);
|
||||
|
||||
if (*version == 1 && *checkstr == 0x12345678)
|
||||
rkss_version = RKSS_VERSION_V1;
|
||||
else
|
||||
rkss_version = RKSS_VERSION_V2;
|
||||
|
||||
free(read_buff);
|
||||
return rkss_version;
|
||||
}
|
||||
|
||||
int OpteeClientRkFsInit(void)
|
||||
{
|
||||
int version;
|
||||
|
||||
version = get_rkss_version();
|
||||
debug("TEEC: OpteeClientRkFsInit version=%d\n", version);
|
||||
if (version == RKSS_VERSION_V1)
|
||||
return tee_supp_rk_fs_init_v1();
|
||||
else if (version == RKSS_VERSION_V2)
|
||||
return tee_supp_rk_fs_init_v2();
|
||||
else if (version == RKSS_VERSION_ERR)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
int OpteeClientRkFsProcess(void *cmd, size_t cmd_size)
|
||||
{
|
||||
int version;
|
||||
|
||||
version = get_rkss_version();
|
||||
debug("TEEC: OpteeClientRkFsProcess version=%d\n", version);
|
||||
if (version == RKSS_VERSION_V1)
|
||||
return tee_supp_rk_fs_process_v1(cmd, cmd_size);
|
||||
else if (version == RKSS_VERSION_V2)
|
||||
return tee_supp_rk_fs_process_v2(cmd, cmd_size);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue