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 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /** Error codes for using the shared memory area. */
29 enum shared_memory_status {
30     SHARED_MEMORY_OK           = 0,
31     SHARED_MEMORY_OVERFLOW,
32     SHARED_MEMORY_OVERWRITE,
33     SHARED_MEMORY_GEN_ERROR,
34     SHARED_MEMORY_WRITE_ERROR,
35     SHARED_MEMORY_READ_ERROR,
36 };
37 
38 /**
39  * @brief Add a data item to the shared data area between bootloader and
40  *        runtime SW
41  *
42  * @param[in] major_type  TLV major type, identify consumer
43  * @param[in] minor_type  TLV minor type, identify TLV type
44  * @param[in] size        length of added data
45  * @param[in] data        pointer to data
46  *
47  * @return                0 on success; nonzero on failure.
48  */
49 int boot_add_data_to_shared_area(uint8_t        major_type,
50                                  uint16_t       minor_type,
51                                  size_t         size,
52                                  const uint8_t *data);
53 
54 /**
55  * Add an image's all boot status information to the shared memory area
56  * between the bootloader and runtime SW.
57  *
58  * @param[in]  sw_module  Identifier of the SW component.
59  * @param[in]  hdr        Pointer to the image header stored in RAM.
60  * @param[in]  fap        Pointer to the flash area where image is stored.
61  *
62  * @return                0 on success; nonzero on failure.
63  */
64 int boot_save_boot_status(uint8_t sw_module,
65                           const struct image_header *hdr,
66                           const struct flash_area *fap);
67 
68 /**
69  * Add application specific data to the shared memory area between the
70  * bootloader and runtime SW.
71  *
72  * @param[in]  hdr           Pointer to the image header stored in RAM.
73  * @param[in]  fap           Pointer to the flash area where image is stored.
74  * @param[in]  slot          The currently active slot being booted.
75  * @param[in]  max_app_size  The maximum size of an image that can be loaded.
76  *
77  * @return                    0 on success; nonzero on failure.
78  */
79 int boot_save_shared_data(const struct image_header *hdr,
80                           const struct flash_area *fap,
81                           const uint8_t active_slot,
82                           const int max_app_size);
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 
88 #endif /* __BOOT_RECORD_H__ */
89