1 /*
2 * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include "ps_service_context.h"
8 #include "service/block_storage/factory/client/block_store_factory.h"
9 #include "service/secure_storage/backend/secure_flash_store/secure_flash_store.h"
10 #include "service/secure_storage/frontend/secure_storage_provider/secure_storage_uuid.h"
11 #include "media/disk/guid.h"
12 #include <assert.h>
13 #include <compiler.h>
14
ps_service_context(const char * sn)15 ps_service_context::ps_service_context(const char *sn) :
16 standalone_service_context(sn),
17 m_storage_provider(),
18 m_sfs_flash_adapter(),
19 m_block_store(NULL)
20 {
21
22 }
23
~ps_service_context()24 ps_service_context::~ps_service_context()
25 {
26
27 }
28
do_init()29 void ps_service_context::do_init()
30 {
31 struct uuid_octets guid;
32 const struct sfs_flash_info_t *flash_info = NULL;
33 const struct rpc_uuid service_uuid = {.uuid = TS_PSA_PROTECTED_STORAGE_UUID };
34
35 uuid_guid_octets_from_canonical(&guid,
36 DISK_GUID_UNIQUE_PARTITION_PSA_PS);
37
38 m_block_store = client_block_store_factory_create("sn:trustedfirmware.org:block-storage:0");
39 assert(m_block_store != NULL);
40
41 __maybe_unused psa_status_t status = sfs_flash_block_store_adapter_init(
42 &m_sfs_flash_adapter,
43 0,
44 m_block_store,
45 &guid,
46 MIN_FLASH_BLOCK_SIZE,
47 MAX_NUM_FILES,
48 &flash_info);
49
50 assert(status == PSA_SUCCESS);
51
52 struct storage_backend *storage_backend = sfs_init(flash_info);
53 struct rpc_service_interface *storage_ep = secure_storage_provider_init(
54 &m_storage_provider, storage_backend, &service_uuid);
55
56 standalone_service_context::set_rpc_interface(storage_ep);
57 }
58
do_deinit()59 void ps_service_context::do_deinit()
60 {
61 secure_storage_provider_deinit(&m_storage_provider);
62 client_block_store_factory_destroy(m_block_store);
63 m_block_store = NULL;
64 }
65