Skip to content

Commit 0b42286

Browse files
committed
MCUboot library: remove precompiled library and add source code
1 parent f6f20ca commit 0b42286

23 files changed

+3596
-20
lines changed

libraries/MCUboot/library.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@ paragraph=
77
category=Other
88
url=
99
architectures=mbed,mbed_portenta
10-
precompiled=true
11-
ldflags=-lbootutil

libraries/MCUboot/src/MCUboot.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "MCUboot.h"
2-
#include "bootutil.h"
2+
#include "bootutil/bootutil_public.h"
3+
#include "STM32H747_System.h"
4+
35

46
void MCUboot::confirmSketch()
57
{
@@ -13,5 +15,13 @@ void MCUboot::applyUpdate(int permanent)
1315

1416
void MCUboot::bootDebug(int enable)
1517
{
16-
boot_set_debug(enable);
18+
unsigned int rtc_reg = STM32H747::readBackupRegister(RTCBackup::DR7);
19+
20+
if(enable) {
21+
rtc_reg |= 0x00000001;
22+
} else {
23+
rtc_reg &= ~0x00000001;
24+
}
25+
26+
return STM32H747::writeBackupRegister(RTCBackup::DR7, rtc_reg);
1727
}

libraries/MCUboot/src/bootutil.h

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2021 Nordic Semiconductor ASA
5+
*
6+
* Original license:
7+
*
8+
* Licensed to the Apache Software Foundation (ASF) under one
9+
* or more contributor license agreements. See the NOTICE file
10+
* distributed with this work for additional information
11+
* regarding copyright ownership. The ASF licenses this file
12+
* to you under the Apache License, Version 2.0 (the
13+
* "License"); you may not use this file except in compliance
14+
* with the License. You may obtain a copy of the License at
15+
*
16+
* http://www.apache.org/licenses/LICENSE-2.0
17+
*
18+
* Unless required by applicable law or agreed to in writing,
19+
* software distributed under the License is distributed on an
20+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
* KIND, either express or implied. See the License for the
22+
* specific language governing permissions and limitations
23+
* under the License.
24+
*/
25+
26+
/**
27+
* @file
28+
* @brief Hooks definition implementation API
29+
*
30+
* This file contains API interface definition for hooks which can be
31+
* implemented to overide or to amend some of MCUboot's native routines.
32+
*/
33+
34+
#ifndef H_BOOTUTIL_HOOKS
35+
#define H_BOOTUTIL_HOOKS
36+
37+
#ifdef MCUBOOT_IMAGE_ACCESS_HOOKS
38+
39+
#define BOOT_HOOK_CALL(f, ret_default, ...) f(__VA_ARGS__)
40+
41+
#define BOOT_HOOK_CALL_FIH(f, fih_ret_default, fih_rc, ...) \
42+
do { \
43+
FIH_CALL(f, fih_rc, __VA_ARGS__); \
44+
} while(0);
45+
46+
#else
47+
48+
#define BOOT_HOOK_CALL(f, ret_default, ...) ret_default
49+
50+
#define BOOT_HOOK_CALL_FIH(f, fih_ret_default, fih_rc, ...) \
51+
do { \
52+
fih_rc = fih_ret_default; \
53+
} while(0);
54+
55+
#endif
56+
57+
/** Hook for provide image header data.
58+
*
59+
* This Hook may be used to overide image header read implementation or doing
60+
* a custom action before.
61+
*
62+
* @param img_index the index of the image pair
63+
* @param slot slot number
64+
* @param img_head image header structure to be populated
65+
*
66+
* @retval 0: header was read/populated, skip direct header data read
67+
* BOOT_HOOK_REGULAR: follow the normal execution path,
68+
* otherwise an error-code value.
69+
*/
70+
int boot_read_image_header_hook(int img_index, int slot,
71+
struct image_header *img_head);
72+
73+
/** Hook for Validate image hash/signature
74+
*
75+
* This Hook may be used to overide image validation procedure or doing
76+
* a custom action before.
77+
*
78+
* @param img_index the index of the image pair
79+
* @param slot slot number
80+
*
81+
* @retval FIH_SUCCESS: image is valid, skip direct validation
82+
* FIH_FAILURE: image is invalid, skip direct validation
83+
* fih encoded BOOT_HOOK_REGULAR: follow the normal execution path.
84+
*/
85+
fih_int boot_image_check_hook(int img_index, int slot);
86+
87+
/** Hook for implement image update
88+
*
89+
* This hook is for for implementing an alternative mechanism of image update or
90+
* doing a custom action before.
91+
*
92+
* @param img_index the index of the image pair
93+
* @param img_head the image header of the secondary image
94+
* @param area the flash area of the secondary image.
95+
*
96+
* @retval 0: update was done, skip performing the update
97+
* BOOT_HOOK_REGULAR: follow the normal execution path,
98+
* otherwise an error-code value.
99+
*/
100+
int boot_perform_update_hook(int img_index, struct image_header *img_head,
101+
const struct flash_area *area);
102+
103+
/** Hook for implement image's post copying action
104+
*
105+
* This hook is for implement action which might be done right after image was
106+
* copied to the primary slot. This hook is called in MCUBOOT_OVERWRITE_ONLY
107+
* mode only.
108+
*
109+
* @param img_index the index of the image pair
110+
* @param area the flash area of the primary image.
111+
* @param size size of copied image.
112+
*
113+
* @retval 0: success, mcuboot will follow normal code execution flow after
114+
* execution of this call.
115+
* non-zero: an error, mcuboot will return from
116+
* boot_copy_image() with error.
117+
* Update will be undone so might be resume on the next boot.
118+
*/
119+
int boot_copy_region_post_hook(int img_index, const struct flash_area *area,
120+
size_t size);
121+
122+
/** Hook for implement image's post recovery upload action
123+
*
124+
* This hook is for implement action which might be done right after image was
125+
* copied to the primary slot. This hook is called in serial recovery upload
126+
* operation.
127+
*
128+
* @param img_index the index of the image pair
129+
* @param area the flash area of the primary image.
130+
* @param size size of copied image.
131+
*
132+
* @retval 0: success, mcuboot will follow normal code execution flow after
133+
* execution of this call.
134+
* non-zero: an error, will be transferred as part of comand response
135+
* as "rc" entry.
136+
*/
137+
int boot_serial_uploaded_hook(int img_index, const struct flash_area *area,
138+
size_t size);
139+
140+
/** Hook for implement the image's slot installation status fetch operation for
141+
* the MGMT custom command.
142+
*
143+
* The image's slot installation status is custom property. It's detailed
144+
* definition depends on user implementation. It is only defined that the status
145+
* will be set to 0 if this hook not provides another value.
146+
*
147+
* @param img_index the index of the image pair
148+
* @param slot slot number
149+
* @param img_install_stat the image installation status to be populated
150+
*
151+
* @retval 0: the installaton status was fetched successfully,
152+
* BOOT_HOOK_REGULAR: follow the normal execution path, status will be
153+
* set to 0
154+
* otherwise an error-code value. Error-code is ignored, but it is up to
155+
* the implementation to reflect this error in img_install_stat.
156+
*/
157+
int boot_img_install_stat_hook(int image_index, int slot,
158+
int *img_install_stat);
159+
160+
#endif /*H_BOOTUTIL_HOOKS*/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2021 Nordic Semiconductor ASA
5+
*
6+
* Original license:
7+
*
8+
* Licensed to the Apache Software Foundation (ASF) under one
9+
* or more contributor license agreements. See the NOTICE file
10+
* distributed with this work for additional information
11+
* regarding copyright ownership. The ASF licenses this file
12+
* to you under the Apache License, Version 2.0 (the
13+
* "License"); you may not use this file except in compliance
14+
* with the License. You may obtain a copy of the License at
15+
*
16+
* http://www.apache.org/licenses/LICENSE-2.0
17+
*
18+
* Unless required by applicable law or agreed to in writing,
19+
* software distributed under the License is distributed on an
20+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
* KIND, either express or implied. See the License for the
22+
* specific language governing permissions and limitations
23+
* under the License.
24+
*/
25+
26+
/**
27+
* @file
28+
* @brief Hooks definition implementation API
29+
*
30+
* This file contains API interface definition for hooks which can be
31+
* implemented for overide some of MCUboot's native routines.
32+
*/
33+
34+
#ifndef H_BOOTUTIL_PUBLIC_HOOKS
35+
#define H_BOOTUTIL_PUBLIC_HOOKS
36+
37+
#include "bootutil/boot_hooks.h"
38+
39+
/** Hook for provide primary image swap state.
40+
*
41+
* @param img_index the index of the image pair
42+
* @param state image swap state structure to be populated
43+
*
44+
* @retval 0: header was read/populated
45+
* FIH_FAILURE: image is invalid,
46+
* BOOT_HOOK_REGULAR if hook not implemented for the image-slot,
47+
* othervise an error-code value.
48+
*/
49+
int boot_read_swap_state_primary_slot_hook(int image_index,
50+
struct boot_swap_state *state);
51+
52+
#endif /*H_BOOTUTIL_PUBLIC_HOOKS*/
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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-2020 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+
struct image_header;
40+
/**
41+
* A response object provided by the boot loader code; indicates where to jump
42+
* to execute the main image.
43+
*/
44+
struct boot_rsp {
45+
/** A pointer to the header of the image to be executed. */
46+
const struct image_header *br_hdr;
47+
48+
/**
49+
* The flash offset of the image to execute. Indicates the position of
50+
* the image header within its flash device.
51+
*/
52+
uint8_t br_flash_dev_id;
53+
uint32_t br_image_off;
54+
};
55+
56+
/* This is not actually used by mcuboot's code but can be used by apps
57+
* when attempting to read/write a trailer.
58+
*/
59+
struct image_trailer {
60+
uint8_t swap_type;
61+
uint8_t pad1[BOOT_MAX_ALIGN - 1];
62+
uint8_t copy_done;
63+
uint8_t pad2[BOOT_MAX_ALIGN - 1];
64+
uint8_t image_ok;
65+
uint8_t pad3[BOOT_MAX_ALIGN - 1];
66+
#if BOOT_MAX_ALIGN > BOOT_MAGIC_SZ
67+
uint8_t pad4[BOOT_MAGIC_ALIGN_SIZE - BOOT_MAGIC_SZ];
68+
#endif
69+
uint8_t magic[BOOT_MAGIC_SZ];
70+
};
71+
72+
/* you must have pre-allocated all the entries within this structure */
73+
fih_int boot_go(struct boot_rsp *rsp);
74+
75+
struct boot_loader_state;
76+
fih_int context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp);
77+
78+
#define SPLIT_GO_OK (0)
79+
#define SPLIT_GO_NON_MATCHING (-1)
80+
#define SPLIT_GO_ERR (-2)
81+
82+
fih_int split_go(int loader_slot, int split_slot, void **entry);
83+
84+
#ifdef __cplusplus
85+
}
86+
#endif
87+
88+
#endif

0 commit comments

Comments
 (0)