1 /*
2  * Copyright (c) 2021, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  * FWU metadata information as per the specification section 4.1:
7  * https://developer.arm.com/documentation/den0118/latest/
8  *
9  */
10 
11 #ifndef FWU_METADATA_H
12 #define FWU_METADATA_H
13 
14 #include <stdint.h>
15 #include <tools_share/uuid.h>
16 
17 #define NR_OF_MAX_FW_BANKS	4
18 
19 /* Properties of image in a bank */
20 struct fwu_image_bank_info {
21 
22 	/* GUID of the image in this bank */
23 	struct efi_guid img_guid;
24 
25 	/* [0]: bit describing the image acceptance status –
26 	 *      1 means the image is accepted
27 	 * [31:1]: MBZ
28 	 */
29 	uint32_t accepted;
30 
31 	/* reserved (MBZ) */
32 	uint32_t reserved;
33 
34 } __packed;
35 
36 /* Image entry information */
37 struct fwu_image_entry {
38 
39 	/* GUID identifying the image type */
40 	struct efi_guid img_type_guid;
41 
42 	/* GUID of the storage volume where the image is located */
43 	struct efi_guid location_guid;
44 
45 	/* Properties of images with img_type_guid in the different FW banks */
46 	struct fwu_image_bank_info img_bank_info[NR_OF_FW_BANKS];
47 
48 } __packed;
49 
50 /* Firmware Image descriptor */
51 struct fwu_fw_store_descriptor {
52 
53 	/* Number of Banks */
54 	uint8_t num_banks;
55 
56 	/* Reserved */
57 	uint8_t reserved;
58 
59 	/* Number of images per bank */
60 	uint16_t num_images;
61 
62 	/* Size of image_entry(all banks) in bytes */
63 	uint16_t img_entry_size;
64 
65 	/* Size of image bank info structure in bytes */
66 	uint16_t bank_info_entry_size;
67 
68 	/* Array of fwu_image_entry structs */
69 	struct fwu_image_entry img_entry[NR_OF_IMAGES_IN_FW_BANK];
70 
71 } __packed;
72 
73 /*
74  * FWU metadata filled by the updater and consumed by TF-A for
75  * various purposes as below:
76  * 1. Get active FW bank.
77  * 2. Rollback to previous working FW bank.
78  * 3. Get properties of all images present in all banks.
79  */
80 struct fwu_metadata {
81 
82 	/* Metadata CRC value */
83 	uint32_t crc_32;
84 
85 	/* Metadata version */
86 	uint32_t version;
87 
88 	/* Bank index with which device boots */
89 	uint32_t active_index;
90 
91 	/* Previous bank index with which device booted successfully */
92 	uint32_t previous_active_index;
93 
94 	/* Size of the entire metadata in bytes */
95 	uint32_t metadata_size;
96 
97 	/* Offset of the image descriptor structure */
98 	uint16_t desc_offset;
99 
100 	/* Reserved */
101 	uint16_t reserved1;
102 
103 	/* Bank state */
104 	uint8_t bank_state[NR_OF_MAX_FW_BANKS];
105 
106 	/* Reserved */
107 	uint32_t reserved2;
108 
109 #if PSA_FWU_METADATA_FW_STORE_DESC
110 	/* Image entry information */
111 	struct fwu_fw_store_descriptor fw_desc;
112 #endif
113 
114 } __packed;
115 
116 #endif /* FWU_METADATA_H */
117