mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-06 05:04:26 +00:00
8b1312662b
If OP-TEE core is compiled with support of REE FS and RPMB
at the same time (CFG_RPMB_FS ?= y; CFG_RPMB_FS ?= y), and persistent
storage API is used with TEE_STORAGE_PRIVATE storage id, it will
lead to TA panic.
E/TC:? 0 TA panicked with code 0xffff0009
.....
E/TC:? 0 Call stack:
E/TC:? 0 0x000000004002f2f8 TEE_OpenPersistentObject at
lib/libutee/tee_api_objects.c:422
In this particular case TEE_ERROR_STORAGE_NOT_AVAILABLE is more suitable
than TEE_ERROR_NOT_IMPLEMENTED, as it provides to a TA a possibility
to handle this error code [1].
>From GPD TEE Internal Core specification [2]:
TEE_ERROR_STORAGE_NOT_AVAILABLE - if the persistent object is stored in a
storage area which is currently inaccessible. It may be associated with
the device but unplugged, busy, or inaccessible for some other reason.
[1]: 94db01ef44/lib/libutee/tee_api_objects.c (L419)
[2]: https://globalplatform.org/wp-content/uploads/2018/06/GPD_TEE_Internal_Core_API_Specification_v1.1.2.50_PublicReview.pdf
Signed-off-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
96 lines
2.1 KiB
C
96 lines
2.1 KiB
C
// SPDX-License-Identifier: BSD-2-Clause
|
|
/*
|
|
* Copyright (c) 2018, Linaro Limited
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <log.h>
|
|
#include <tee.h>
|
|
#include <linux/types.h>
|
|
|
|
#include "optee_msg.h"
|
|
#include "optee_msg_supplicant.h"
|
|
#include "optee_private.h"
|
|
#include "optee_smc.h"
|
|
|
|
static void cmd_shm_alloc(struct udevice *dev, struct optee_msg_arg *arg,
|
|
void **page_list)
|
|
{
|
|
int rc;
|
|
struct tee_shm *shm;
|
|
void *pl;
|
|
u64 ph_ptr;
|
|
|
|
arg->ret_origin = TEE_ORIGIN_COMMS;
|
|
|
|
if (arg->num_params != 1 ||
|
|
arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_INPUT) {
|
|
arg->ret = TEE_ERROR_BAD_PARAMETERS;
|
|
return;
|
|
}
|
|
|
|
rc = __tee_shm_add(dev, 0, NULL, arg->params[0].u.value.b,
|
|
TEE_SHM_REGISTER | TEE_SHM_ALLOC, &shm);
|
|
if (rc) {
|
|
if (rc == -ENOMEM)
|
|
arg->ret = TEE_ERROR_OUT_OF_MEMORY;
|
|
else
|
|
arg->ret = TEE_ERROR_GENERIC;
|
|
return;
|
|
}
|
|
|
|
pl = optee_alloc_and_init_page_list(shm->addr, shm->size, &ph_ptr);
|
|
if (!pl) {
|
|
arg->ret = TEE_ERROR_OUT_OF_MEMORY;
|
|
tee_shm_free(shm);
|
|
return;
|
|
}
|
|
|
|
*page_list = pl;
|
|
arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT |
|
|
OPTEE_MSG_ATTR_NONCONTIG;
|
|
arg->params[0].u.tmem.buf_ptr = ph_ptr;
|
|
arg->params[0].u.tmem.size = shm->size;
|
|
arg->params[0].u.tmem.shm_ref = (ulong)shm;
|
|
arg->ret = TEE_SUCCESS;
|
|
}
|
|
|
|
static void cmd_shm_free(struct optee_msg_arg *arg)
|
|
{
|
|
arg->ret_origin = TEE_ORIGIN_COMMS;
|
|
|
|
if (arg->num_params != 1 ||
|
|
arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_INPUT) {
|
|
arg->ret = TEE_ERROR_BAD_PARAMETERS;
|
|
return;
|
|
}
|
|
|
|
tee_shm_free((struct tee_shm *)(ulong)arg->params[0].u.value.b);
|
|
arg->ret = TEE_SUCCESS;
|
|
}
|
|
|
|
void optee_suppl_cmd(struct udevice *dev, struct tee_shm *shm_arg,
|
|
void **page_list)
|
|
{
|
|
struct optee_msg_arg *arg = shm_arg->addr;
|
|
|
|
switch (arg->cmd) {
|
|
case OPTEE_MSG_RPC_CMD_SHM_ALLOC:
|
|
cmd_shm_alloc(dev, arg, page_list);
|
|
break;
|
|
case OPTEE_MSG_RPC_CMD_SHM_FREE:
|
|
cmd_shm_free(arg);
|
|
break;
|
|
case OPTEE_MSG_RPC_CMD_FS:
|
|
debug("REE FS storage isn't available\n");
|
|
arg->ret = TEE_ERROR_STORAGE_NOT_AVAILABLE;
|
|
break;
|
|
case OPTEE_MSG_RPC_CMD_RPMB:
|
|
optee_suppl_cmd_rpmb(dev, arg);
|
|
break;
|
|
default:
|
|
arg->ret = TEE_ERROR_NOT_IMPLEMENTED;
|
|
}
|
|
|
|
arg->ret_origin = TEE_ORIGIN_COMMS;
|
|
}
|