1 /*
2  * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef BL1_2_IMAGE_H
9 #define BL1_2_IMAGE_H
10 
11 #include <stddef.h>
12 #include <stdint.h>
13 #include "crypto.h"
14 #include "region_defs.h"
15 #include "cmsis_compiler.h"
16 #include "fih.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #define BL1_2_IMAGE_DECRYPT_MAGIC_EXPECTED 0xDEADBEEF
23 #define PAD_SIZE (BL1_HEADER_SIZE - CTR_IV_LEN - 1452 - \
24                   sizeof(struct tfm_bl1_image_version_t) - 2 * sizeof(uint32_t))
25 
26 __PACKED_STRUCT tfm_bl1_image_version_t {
27     uint8_t  major;
28     uint8_t  minor;
29     uint16_t revision;
30     uint32_t build_num;
31 };
32 
33 __PACKED_STRUCT bl1_2_image_t {
34     __PACKED_STRUCT  {
35         uint8_t ctr_iv[CTR_IV_LEN];
36         uint8_t sig[1452];
37     } header;
38     __PACKED_STRUCT {
39         struct tfm_bl1_image_version_t version;
40         uint32_t security_counter;
41 
42         __PACKED_STRUCT {
43             uint32_t decrypt_magic;
44             uint8_t pad[PAD_SIZE];
45             uint8_t data[IMAGE_BL2_CODE_SIZE];
46         } encrypted_data;
47     } protected_values;
48 };
49 
50 int32_t bl1_image_get_flash_offset(uint32_t image_id);
51 
52 fih_int bl1_image_copy_to_sram(uint32_t image_id, uint8_t *out);
53 
54 #ifdef __cplusplus
55 }
56 #endif
57 
58 #endif /* BL1_2_IMAGE_H */
59