blob: 6c59554d9f5ab93d86a1d87c61cf55f80674a4ed [file] [log] [blame]
Julian Hallc1353f72022-11-18 12:00:09 +00001/*
2 * Copyright (c) 2022, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef FW_DIRECTORY_H
9#define FW_DIRECTORY_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"
Julian Hallc1353f72022-11-18 12:00:09 +000016#include "install_type.h"
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22/**
23 * The default maximum number of images that can be held by the fw_directory.
24 * Can be overridden by an external definition.
25 */
26#ifndef FWU_MAX_FW_DIRECTORY_ENTRIES
Gyorgy Szing3c446242023-03-31 01:53:15 +020027#define FWU_MAX_FW_DIRECTORY_ENTRIES (20)
Julian Hallc1353f72022-11-18 12:00:09 +000028#endif
29
30/**
31 * \brief Boot information structure definition
32 *
33 * The boot_info structure holds information obtained from the boot loader
34 * about the most recent boot.
35 */
36struct boot_info {
37 /* Identifies the bank that was used during boot */
38 uint32_t boot_index;
39
40 /* The state of the active_index metadata variable during boot */
41 uint32_t active_index;
42
43 /* The state of the previous_active_index metadata variable during boot */
44 uint32_t previous_active_index;
45};
46
47/**
48 * \brief Image information structure definition
49 *
50 * Information about an updatable image. Firmware may consist of an arbitrary
51 * number of images that may be updated as a single unit. Images may correspond
52 * to individual components, such as the Crypto SP image, or a collection of
53 * components contained within a package understood by firmware such as a FIP.
54 */
55struct image_info {
56 /* Unique identifier for the image type. This corresponds to the UUID/GUID
57 * assigned by the originator of the update package to identify the image.
58 */
59 struct uuid_octets img_type_uuid;
60
61 /* The maximum size that can be accommodated for an image of this type.
62 * A platform integrator will have sized back-end storage to provide
63 * sufficient headroom to accommodate updates.
64 */
65 size_t max_size;
66
67 /* The lowest accepted version number for this image. This will correspond
68 * to the NV anti-rollback counter value associated with the image.
69 */
70 uint32_t lowest_accepted_version;
71
72 /* The version of the currently active version of this image. */
73 uint32_t active_version;
74
Gyorgy Szing3c446242023-03-31 01:53:15 +020075 /* Bitmap of access permissions for this image. */
Julian Hallc1353f72022-11-18 12:00:09 +000076 uint32_t permissions;
77
78 /* The index [0..n] of the image in the fw directory. */
79 uint32_t image_index;
80
81 /* The location_id assigned by the platform integrator. A fw_store may
82 * be distributed over multiple locations (e.g. different storage partitions).
83 * The location_id is used to associate installers to storage volumes.
84 */
85 uint32_t location_id;
86
87 /* Identifies the type of installation needed for the image. */
88 enum install_type install_type;
89};
90
91/**
92 * \brief Firmware directory structure definition
93 *
94 * The fw_directory holds information about currently active firmware. Information
95 * will have been collected via a trusted pathway. A subset of the information held
96 * is presented to external clients.
97 */
98struct fw_directory {
99 struct boot_info boot_info;
100 size_t num_images;
101 struct image_info entries[FWU_MAX_FW_DIRECTORY_ENTRIES];
102};
103
104/**
105 * \brief Initialise a fw_directory
106 *
107 * Initialises the subject fw_directory. After initialisation, the empty fw_directory
108 * will need to be populated by a trusted agent (the fw_inspector).
109 *
110 * \param[in] fw_directory The subject fw_directory
111 */
Gyorgy Szing3c446242023-03-31 01:53:15 +0200112void fw_directory_init(struct fw_directory *fw_directory);
Julian Hallc1353f72022-11-18 12:00:09 +0000113
114/**
115 * \brief De-initialise a fw_directory
116 *
117 * \param[in] fw_directory The subject fw_directory
118 */
Gyorgy Szing3c446242023-03-31 01:53:15 +0200119void fw_directory_deinit(struct fw_directory *fw_directory);
Julian Hallc1353f72022-11-18 12:00:09 +0000120
121/**
122 * \brief Sets the boot_info held by the fw_directory
123 *
124 * Used by a fw_inspector to set the boot_info for the most recent system boot.
125 *
126 * \param[in] fw_directory The subject fw_directory
127 * \param[in] boot_info boot_info for most recent system boot
128 */
Gyorgy Szing3c446242023-03-31 01:53:15 +0200129void fw_directory_set_boot_info(struct fw_directory *fw_directory,
130 const struct boot_info *boot_info);
Julian Hallc1353f72022-11-18 12:00:09 +0000131
132/**
133 * \brief Adds an image_info to the directory
134 *
135 * Used by a fw_inspector to add an image_info entry to the directory.
136 *
137 * \param[in] fw_directory The subject fw_directory
138 * \param[in] image_info The entry to add
139 *
140 * \return FWU status
141 */
Gyorgy Szing3c446242023-03-31 01:53:15 +0200142int fw_directory_add_image_info(struct fw_directory *fw_directory,
143 const struct image_info *image_info);
Julian Hallc1353f72022-11-18 12:00:09 +0000144
145/**
146 * \brief Find an image_info entry
147 *
148 * Query to find an image_info entry using the image type UUID as the key.
149 *
150 * \param[in] fw_directory The subject fw_directory
151 * \param[in] image_type_uuid Image type UUID
152 *
153 * \return Pointer to image_info or NULL
154 */
Gyorgy Szing3c446242023-03-31 01:53:15 +0200155const struct image_info *fw_directory_find_image_info(const struct fw_directory *fw_directory,
156 const struct uuid_octets *img_type_uuid);
Julian Hallc1353f72022-11-18 12:00:09 +0000157
158/**
159 * \brief Get the boot_info
160 *
161 * \param[in] fw_directory The subject fw_directory
162 *
163 * \return Pointer to the boot_info
164 */
Gyorgy Szing3c446242023-03-31 01:53:15 +0200165const struct boot_info *fw_directory_get_boot_info(const struct fw_directory *fw_directory);
Julian Hallc1353f72022-11-18 12:00:09 +0000166
167/**
168 * \brief Get an image_info by index
169 *
170 * Can be used for iterating over all image_info objects held.
171 *
172 * \param[in] fw_directory The subject fw_directory
173 * \param[in] index Index in range [0..num_images-1]
174 *
175 * \return Pointer to the image_info or NULL if index invalid
176 */
Gyorgy Szing3c446242023-03-31 01:53:15 +0200177const struct image_info *fw_directory_get_image_info(const struct fw_directory *fw_directory,
178 size_t index);
Julian Hallc1353f72022-11-18 12:00:09 +0000179
180/**
181 * \brief Get the number of image_info entries held
182 *
183 * \param[in] fw_directory The subject fw_directory
184 *
185 * \return Number of entries
186 */
Gyorgy Szing3c446242023-03-31 01:53:15 +0200187size_t fw_directory_num_images(const struct fw_directory *fw_directory);
Julian Hallc1353f72022-11-18 12:00:09 +0000188
189#ifdef __cplusplus
190}
191#endif
192
193#endif /* FW_DIRECTORY_H */