Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TFM: Add missing IPC file for PSA Firmware Update #14945

Merged
merged 1 commit into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ target_sources(mbed-psa
INTERFACE
src/os_wrapper_cmsis_rtos_v2.c
src/tfm_crypto_ipc_api.c
src/tfm_firmware_update_ipc_api.c
src/tfm_initial_attestation_ipc_api.c
src/tfm_its_ipc_api.c
src/tfm_platform_ipc_api.c
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
* Copyright (c) 2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/

#include "psa/update.h"
#include "tfm_api.h"

#include "psa/client.h"
#include "psa_manifest/sid.h"

#define IOVEC_LEN(x) (uint32_t)(sizeof(x)/sizeof(x[0]))

psa_status_t psa_fwu_write(const psa_image_id_t image_id,
size_t block_offset,
const void *block,
size_t block_size)
{
psa_status_t status;
psa_handle_t handle;

psa_invec in_vec[] = {
{ .base = &image_id, .len = sizeof(image_id) },
{ .base = &block_offset, .len = sizeof(block_offset) },
{ .base = block, .len = block_size }
};

handle = psa_connect(TFM_FWU_WRITE_SID, TFM_FWU_WRITE_VERSION);
if (!PSA_HANDLE_IS_VALID(handle)) {
return PSA_ERROR_GENERIC_ERROR;
}

status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), NULL,
0);

psa_close(handle);

if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) {
return PSA_ERROR_INVALID_ARGUMENT;
}

return status;
}

psa_status_t psa_fwu_install(const psa_image_id_t image_id,
psa_image_id_t *dependency_uuid,
psa_image_version_t *dependency_version)
{
psa_status_t status;
psa_handle_t handle;

psa_invec in_vec[] = {
{ .base = &image_id, .len = sizeof(image_id) }
};

psa_outvec out_vec[] = {
{ .base = dependency_uuid, .len = sizeof(*dependency_uuid) },
{ .base = dependency_version, .len = sizeof(*dependency_version)}
};

if ((dependency_uuid == NULL) || (dependency_version == NULL)) {
return PSA_ERROR_INVALID_ARGUMENT;
}

handle = psa_connect(TFM_FWU_INSTALL_SID, TFM_FWU_INSTALL_VERSION);
if (!PSA_HANDLE_IS_VALID(handle)) {
return PSA_ERROR_GENERIC_ERROR;
}

status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec),
out_vec, IOVEC_LEN(out_vec));

psa_close(handle);

if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) {
return PSA_ERROR_INVALID_ARGUMENT;
}

return status;
}

psa_status_t psa_fwu_abort(const psa_image_id_t image_id)
{
psa_status_t status;
psa_handle_t handle;

psa_invec in_vec[] = {
{ .base = &image_id, .len = sizeof(image_id) }
};

handle = psa_connect(TFM_FWU_ABORT_SID, TFM_FWU_ABORT_VERSION);
if (!PSA_HANDLE_IS_VALID(handle)) {
return PSA_ERROR_GENERIC_ERROR;
}

status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), NULL,
0);

psa_close(handle);

if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) {
return PSA_ERROR_INVALID_ARGUMENT;
}

return status;
}

psa_status_t psa_fwu_query(const psa_image_id_t image_id, psa_image_info_t *info)
{
psa_status_t status;
psa_handle_t handle;

psa_invec in_vec[] = {
{ .base = &image_id, .len = sizeof(image_id) }
};
psa_outvec out_vec[] = {
{ .base = info, .len = sizeof(*info)}
};

handle = psa_connect(TFM_FWU_QUERY_SID, TFM_FWU_QUERY_VERSION);
if (!PSA_HANDLE_IS_VALID(handle)) {
return PSA_ERROR_GENERIC_ERROR;
}

status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), out_vec,
IOVEC_LEN(out_vec));

psa_close(handle);

if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) {
return PSA_ERROR_INVALID_ARGUMENT;
}

return status;
}

psa_status_t psa_fwu_request_reboot(void)
{
psa_handle_t handle;
psa_status_t status;

handle = psa_connect(TFM_FWU_REQUEST_REBOOT_SID,
TFM_FWU_REQUEST_REBOOT_VERSION);
if (!PSA_HANDLE_IS_VALID(handle)) {
return PSA_ERROR_GENERIC_ERROR;
}

status = psa_call(handle, PSA_IPC_CALL, NULL, 0, NULL, 0);

psa_close(handle);

if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) {
return PSA_ERROR_INVALID_ARGUMENT;
}

return status;
}

psa_status_t psa_fwu_accept(void)
{
psa_handle_t handle;
psa_status_t status;

handle = psa_connect(TFM_FWU_ACCEPT_SID,
TFM_FWU_ACCEPT_VERSION);
if (!PSA_HANDLE_IS_VALID(handle)) {
return PSA_ERROR_GENERIC_ERROR;
}

status = psa_call(handle, PSA_IPC_CALL, NULL, 0, NULL, 0);

psa_close(handle);

if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) {
return PSA_ERROR_INVALID_ARGUMENT;
}

return status;
}

psa_status_t psa_fwu_set_manifest(psa_image_id_t image_id,
const void *manifest,
size_t manifest_size,
psa_hash_t *manifest_dependency)
{
psa_status_t status;

status = PSA_ERROR_NOT_SUPPORTED;

return status;
}