blob: e8bddb070d238c66b8b4f0dba697860f3ec2ef5b [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#ifndef FWU_INSTALLATION_INSTALLER_H
9#define FWU_INSTALLATION_INSTALLER_H
10
11#include <stdbool.h>
12#include <stddef.h>
13#include <stdint.h>
Gyorgy Szing3c446242023-03-31 01:53:15 +020014
15#include "common/uuid/uuid.h"
16#include "service/fwu/agent/install_type.h"
Julian Hall56387ba2022-11-18 11:47:44 +000017
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22/**
23 * Interface dependencies
24 */
25struct image_info;
26struct fw_directory;
27
28/**
29 * \brief Image installer interface
30 *
31 * The installer_interface structure provides a common interface for
32 * any image installer. Concrete installers will implement installation
33 * strategies that match the class of image being installed (e.g. component,
34 * whole firmware).
35 */
36struct installer_interface {
37 /**
38 * \brief Begin a transaction of one or more image install operations
39 *
40 * \param[in] context The concrete installer context
41 * \param[in] current_volume_id Where the active fw was loaded from
42 * \param[out] update_volume_id Where the update should be installed
43 *
44 * \return FWU status
45 */
Gyorgy Szing3c446242023-03-31 01:53:15 +020046 int (*begin)(void *context, uint32_t current_volume_id, uint32_t update_volume_id);
Julian Hall56387ba2022-11-18 11:47:44 +000047
48 /**
49 * \brief Finalize a transaction of one or more image install operations
50 *
51 * \param[in] context The concrete installer context
52 *
53 * \return FWU status
54 */
55 int (*finalize)(void *context);
56
57 /**
58 * \brief Abort a transaction
59 *
60 * \param[in] context The concrete installer context
61 */
62 void (*abort)(void *context);
63
64 /**
65 * \brief Open a stream for writing installation data
66 *
67 * \param[in] context The concrete installer context
68 * \param[in] image_info Describes the image to install
69 *
70 * \return FWU status
71 */
Gyorgy Szing3c446242023-03-31 01:53:15 +020072 int (*open)(void *context, const struct image_info *image_info);
Julian Hall56387ba2022-11-18 11:47:44 +000073
74 /**
75 * \brief Commit installed data (called once per open)
76 *
77 * \param[in] context The concrete installer context
78 *
79 * \return FWU status
80 */
81 int (*commit)(void *context);
82
83 /**
84 * \brief Write installation data to an opened installer
85 *
86 * \param[in] context The concrete installer context
87 * \param[in] data Data to write
88 * \param[in] data_len Length of data
89 *
90 * \return FWU status
91 */
Gyorgy Szing3c446242023-03-31 01:53:15 +020092 int (*write)(void *context, const uint8_t *data, size_t data_len);
Julian Hall56387ba2022-11-18 11:47:44 +000093
94 /**
95 * \brief Enumerate the collection of images that can be handled by the installer
96 *
97 * A concrete installer will use its specialized knowledge of the associated
98 * storage volume to enumerate the set of images that can be handled by the
99 * installer.
100 *
101 * \param[in] context The concrete installer context
102 * \param[in] volume_id Identifies the target volume
103 * \param[in] fw_directory Add results to this fw_directory
104 *
105 * \return FWU status
106 */
Gyorgy Szing3c446242023-03-31 01:53:15 +0200107 int (*enumerate)(void *context, uint32_t volume_id, struct fw_directory *fw_directory);
Julian Hall56387ba2022-11-18 11:47:44 +0000108};
109
110/**
111 * \brief Base installer structure
112 *
113 */
114struct installer {
Julian Hall56387ba2022-11-18 11:47:44 +0000115 /* The installation type handled by the installer */
116 enum install_type install_type;
117
118 /* The location id is a short ID that identifies an updatable logical
119 * portion of the firmware store. The location id only needs to be
120 * unique within the device and will have been assigned dynamically
121 * during FWU configuration. The location id is used to bind a set of
122 * installers to the intended set of target volumes.
123 */
124 uint32_t location_id;
125
126 /* The location UUID is a globally unique ID that reflects the same
127 * logical scope as a location id. It is used to associate incoming
128 * update images, either directly or indirectly, to the corresponding
129 * location within the firmware store. For images contained within a
130 * disk partition, this will correspond to the partition type UUID.
131 */
132 struct uuid_octets location_uuid;
133
134 /* The opaque context for the concrete installer */
135 void *context;
136
137 /* Pointer to a concrete installer_interface */
138 const struct installer_interface *interface;
139
140 /* Error status encountered during an update transaction. During an update,
141 * an installer will be called multiple times. If one or more errors are encountered
142 * during the update transaction, the first error status is saved to allow for
143 * appropriate handling.
144 */
145 uint32_t install_status;
146
147 /**
148 * During a multi-image update, images may be delegated to different concrete
149 * installers to allow for alternative installation strategies and install destinations.
150 * Each active installer must be sequenced through a begin->finalize transaction to
151 * ensure that installation operations are completed for all images handled by an
152 * installer and by all installers used during the update.
153 */
154 bool is_active;
155 struct installer *next;
156};
157
158static inline bool installer_is_active(const struct installer *installer)
159{
160 return installer->is_active;
161}
162
163static inline uint32_t installer_status(const struct installer *installer)
164{
165 return installer->install_status;
166}
167
Gyorgy Szing3c446242023-03-31 01:53:15 +0200168void installer_init(struct installer *installer, enum install_type install_type,
169 uint32_t location_id, const struct uuid_octets *location_uuid, void *context,
170 const struct installer_interface *interface);
Julian Hall56387ba2022-11-18 11:47:44 +0000171
Gyorgy Szing3c446242023-03-31 01:53:15 +0200172int installer_begin(struct installer *installer, uint32_t current_volume_id,
173 uint32_t update_volume_id);
Julian Hall56387ba2022-11-18 11:47:44 +0000174
Gyorgy Szing3c446242023-03-31 01:53:15 +0200175int installer_finalize(struct installer *installer);
Julian Hall56387ba2022-11-18 11:47:44 +0000176
Gyorgy Szing3c446242023-03-31 01:53:15 +0200177void installer_abort(struct installer *installer);
Julian Hall56387ba2022-11-18 11:47:44 +0000178
Gyorgy Szing3c446242023-03-31 01:53:15 +0200179int installer_open(struct installer *installer, const struct image_info *image_info);
Julian Hall56387ba2022-11-18 11:47:44 +0000180
Gyorgy Szing3c446242023-03-31 01:53:15 +0200181int installer_commit(struct installer *installer);
Julian Hall56387ba2022-11-18 11:47:44 +0000182
Gyorgy Szing3c446242023-03-31 01:53:15 +0200183int installer_write(struct installer *installer, const uint8_t *data, size_t data_len);
Julian Hall56387ba2022-11-18 11:47:44 +0000184
Gyorgy Szing3c446242023-03-31 01:53:15 +0200185int installer_enumerate(struct installer *installer, uint32_t volume_id,
186 struct fw_directory *fw_directory);
Julian Hall56387ba2022-11-18 11:47:44 +0000187
188#ifdef __cplusplus
189}
190#endif
191
192#endif /* FWU_INSTALLATION_INSTALLER_H */