1 /*
2  * SPDX-License-Identifier: Apache-2.0
3  *
4  * Copyright (c) 2017-2019 Linaro LTD
5  * Copyright (c) 2016-2019 JUUL Labs
6  * Copyright (c) 2019-2021 Arm Limited
7  *
8  * Original license:
9  *
10  * Licensed to the Apache Software Foundation (ASF) under one
11  * or more contributor license agreements.  See the NOTICE file
12  * distributed with this work for additional information
13  * regarding copyright ownership.  The ASF licenses this file
14  * to you under the Apache License, Version 2.0 (the
15  * "License"); you may not use this file except in compliance
16  * with the License.  You may obtain a copy of the License at
17  *
18  *  http://www.apache.org/licenses/LICENSE-2.0
19  *
20  * Unless required by applicable law or agreed to in writing,
21  * software distributed under the License is distributed on an
22  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23  * KIND, either express or implied.  See the License for the
24  * specific language governing permissions and limitations
25  * under the License.
26  */
27 
28 #ifndef H_BOOTUTIL_
29 #define H_BOOTUTIL_
30 
31 #include <inttypes.h>
32 #include "bootutil/fault_injection_hardening.h"
33 #include "bootutil/bootutil_public.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #ifdef MCUBOOT_IMAGE_NUMBER
40 #define BOOT_IMAGE_NUMBER          MCUBOOT_IMAGE_NUMBER
41 #else
42 #define BOOT_IMAGE_NUMBER          1
43 #endif
44 
45 _Static_assert(BOOT_IMAGE_NUMBER > 0, "Invalid value for BOOT_IMAGE_NUMBER");
46 
47 struct image_header;
48 /**
49  * A response object provided by the boot loader code; indicates where to jump
50  * to execute the main image.
51  */
52 struct boot_rsp {
53     /** A pointer to the header of the image to be executed. */
54     const struct image_header *br_hdr;
55 
56     /**
57      * The flash offset of the image to execute.  Indicates the position of
58      * the image header within its flash device.
59      */
60     uint8_t br_flash_dev_id;
61     uint32_t br_image_off;
62 };
63 
64 /* This is not actually used by mcuboot's code but can be used by apps
65  * when attempting to read/write a trailer.
66  */
67 struct image_trailer {
68     uint8_t swap_type;
69     uint8_t pad1[BOOT_MAX_ALIGN - 1];
70     uint8_t copy_done;
71     uint8_t pad2[BOOT_MAX_ALIGN - 1];
72     uint8_t image_ok;
73     uint8_t pad3[BOOT_MAX_ALIGN - 1];
74 #if BOOT_MAX_ALIGN > BOOT_MAGIC_SZ
75     uint8_t pad4[BOOT_MAGIC_ALIGN_SIZE - BOOT_MAGIC_SZ];
76 #endif
77     uint8_t magic[BOOT_MAGIC_SZ];
78 };
79 
80 /* you must have pre-allocated all the entries within this structure */
81 fih_ret boot_go(struct boot_rsp *rsp);
82 fih_ret boot_go_for_image_id(struct boot_rsp *rsp, uint32_t image_id);
83 
84 struct boot_loader_state;
85 void boot_state_clear(struct boot_loader_state *state);
86 fih_ret context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp);
87 
88 #define SPLIT_GO_OK                 (0)
89 #define SPLIT_GO_NON_MATCHING       (-1)
90 #define SPLIT_GO_ERR                (-2)
91 
92 fih_ret split_go(int loader_slot, int split_slot, void **entry);
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 #endif
99