1 /*
2  * Copyright (c) 2018-2021 Arm Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __BOOT_RECORD_H__
18 #define __BOOT_RECORD_H__
19 
20 #include <stdint.h>
21 #include <stddef.h>
22 #include "bootutil/image.h"
23 #include "bootutil/bootutil.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /** Error codes for using the shared memory area. */
30 enum shared_memory_status {
31     SHARED_MEMORY_OK           = 0,
32     SHARED_MEMORY_OVERFLOW,
33     SHARED_MEMORY_OVERWRITE,
34     SHARED_MEMORY_GEN_ERROR,
35     SHARED_MEMORY_WRITE_ERROR,
36     SHARED_MEMORY_READ_ERROR,
37 };
38 
39 /**
40  * @brief Add a data item to the shared data area between bootloader and
41  *        runtime SW
42  *
43  * @param[in] major_type  TLV major type, identify consumer
44  * @param[in] minor_type  TLV minor type, identify TLV type
45  * @param[in] size        length of added data
46  * @param[in] data        pointer to data
47  *
48  * @return                0 on success; nonzero on failure.
49  */
50 int boot_add_data_to_shared_area(uint8_t        major_type,
51                                  uint16_t       minor_type,
52                                  size_t         size,
53                                  const uint8_t *data);
54 
55 /**
56  * Add an image's all boot status information to the shared memory area
57  * between the bootloader and runtime SW.
58  *
59  * @param[in]  sw_module  Identifier of the SW component.
60  * @param[in]  hdr        Pointer to the image header stored in RAM.
61  * @param[in]  fap        Pointer to the flash area where image is stored.
62  *
63  * @return                0 on success; nonzero on failure.
64  */
65 int boot_save_boot_status(uint8_t sw_module,
66                           const struct image_header *hdr,
67                           const struct flash_area *fap);
68 
69 /**
70  * Add application specific data to the shared memory area between the
71  * bootloader and runtime SW.
72  *
73  * @param[in]  hdr           Pointer to the image header stored in RAM.
74  * @param[in]  fap           Pointer to the flash area where image is stored.
75  * @param[in]  slot          The currently active slot being booted.
76  * @param[in]  max_app_sizes The maximum sizes of images that can be loaded.
77  *
78  * @return                    0 on success; nonzero on failure.
79  */
80 int boot_save_shared_data(const struct image_header *hdr,
81                           const struct flash_area *fap,
82                           const uint8_t active_slot,
83                           const struct image_max_size *max_app_sizes);
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 #endif /* __BOOT_RECORD_H__ */
90