blob: 3c78a6540538db0c70c06b898f8606af9ea25379 [file] [log] [blame]
Julian Hall56387ba2022-11-18 11:47:44 +00001/*
2 * Copyright (c) 2022-2023, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include <assert.h>
9#include <stdbool.h>
10#include <stddef.h>
11#include <protocols/service/fwu/packed-c/status.h>
12#include "installer.h"
13
14void installer_init(
15 struct installer *installer,
16 enum install_type install_type,
17 uint32_t location_id,
18 const struct uuid_octets *location_uuid,
19 void *context,
20 const struct installer_interface *interface)
21{
22 assert(installer);
23 assert(location_uuid);
24 assert(context);
25 assert(interface);
26
27 installer->install_type = install_type;
28 installer->location_id = location_id;
29 installer->location_uuid = *location_uuid;
30 installer->context = context;
31 installer->interface = interface;
32
33 installer->install_status = FWU_STATUS_SUCCESS;
34 installer->is_active = false;
35 installer->next = NULL;
36}
37
38int installer_begin(
39 struct installer *installer,
40 uint32_t current_volume_id,
41 uint32_t update_volume_id)
42{
43 assert(installer);
44 assert(installer->interface);
45 assert(installer->interface->begin);
46
47 installer->install_status = FWU_STATUS_SUCCESS;
48 installer->is_active = true;
49
50 return installer->interface->begin(
51 installer->context,
52 current_volume_id,
53 update_volume_id);
54}
55
56int installer_finalize(
57 struct installer *installer)
58{
59 assert(installer);
60 assert(installer->interface);
61 assert(installer->interface->finalize);
62
63 installer->is_active = false;
64
65 return installer->interface->finalize(
66 installer->context);
67}
68
69void installer_abort(
70 struct installer *installer)
71{
72 assert(installer);
73 assert(installer->interface);
74 assert(installer->interface->abort);
75
76 installer->is_active = false;
77
78 installer->interface->abort(
79 installer->context);
80}
81
82int installer_open(
83 struct installer *installer,
84 const struct image_info *image_info)
85{
86 assert(installer);
87 assert(installer->interface);
88 assert(installer->interface->open);
89
90 int status = installer->interface->open(
91 installer->context,
92 image_info);
93
94 if (status && !installer->install_status)
95 installer->install_status = status;
96
97 return status;
98}
99
100int installer_commit(
101 struct installer *installer)
102{
103 assert(installer);
104 assert(installer->interface);
105 assert(installer->interface->commit);
106
107 int status = installer->interface->commit(
108 installer->context);
109
110 if (status && !installer->install_status)
111 installer->install_status = status;
112
113 return status;
114}
115
116int installer_write(
117 struct installer *installer,
118 const uint8_t *data,
119 size_t data_len)
120{
121 assert(installer);
122 assert(installer->interface);
123 assert(installer->interface->write);
124
125 int status = installer->interface->write(
126 installer->context,
127 data, data_len);
128
129 if (status && !installer->install_status)
130 installer->install_status = status;
131
132 return status;
133}
134
135int installer_enumerate(
136 struct installer *installer,
137 uint32_t volume_id,
138 struct fw_directory *fw_directory)
139{
140 assert(installer);
141 assert(installer->interface);
142 assert(installer->interface->enumerate);
143
144 return installer->interface->enumerate(
145 installer->context,
146 volume_id,
147 fw_directory);
148}