Skip to content

Commit f573b39

Browse files
committed
bootutil: extracted app common library from bootutil_misc
Part of code of boot/bootutil/ is re-implemented in zephyr-rtos repository. As some code are defined here and there it becomes problem when need to include it with outstanding feature in a build. It is possible to mitigate problem using #fdefry - but this was rather temporary hack. This patch introduce new module which is common for MCUBoot build and application build. Common code were extracted to bootutil_public.c source file and bootutil_public.h header MCUboot also select DISABLE_MCUBOOT_BOOTUTIL_LIB_OWN_LOG Kconfig option, as it must define log configuration on its own for all its sourcecode. Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
1 parent e512181 commit f573b39

File tree

13 files changed

+731
-505
lines changed

13 files changed

+731
-505
lines changed

boot/bootutil/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ target_sources(bootutil
1818
PRIVATE
1919
src/boot_record.c
2020
src/bootutil_misc.c
21+
src/bootutil_public.c
2122
src/caps.c
2223
src/encrypted.c
2324
src/fault_injection_hardening.c

boot/bootutil/include/bootutil/bootutil.h

+1-32
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,12 @@
3030

3131
#include <inttypes.h>
3232
#include "bootutil/fault_injection_hardening.h"
33+
#include "bootutil/bootutil_public.h"
3334

3435
#ifdef __cplusplus
3536
extern "C" {
3637
#endif
3738

38-
/** Attempt to boot the contents of the primary slot. */
39-
#define BOOT_SWAP_TYPE_NONE 1
40-
41-
/**
42-
* Swap to the secondary slot.
43-
* Absent a confirm command, revert back on next boot.
44-
*/
45-
#define BOOT_SWAP_TYPE_TEST 2
46-
47-
/**
48-
* Swap to the secondary slot,
49-
* and permanently switch to booting its contents.
50-
*/
51-
#define BOOT_SWAP_TYPE_PERM 3
52-
53-
/** Swap back to alternate slot. A confirm changes this state to NONE. */
54-
#define BOOT_SWAP_TYPE_REVERT 4
55-
56-
/** Swap failed because image to be run is not valid */
57-
#define BOOT_SWAP_TYPE_FAIL 5
58-
59-
/** Swapping encountered an unrecoverable error */
60-
#define BOOT_SWAP_TYPE_PANIC 0xff
61-
62-
#define BOOT_MAX_ALIGN 8
63-
6439
struct image_header;
6540
/**
6641
* A response object provided by the boot loader code; indicates where to jump
@@ -97,12 +72,6 @@ fih_int boot_go(struct boot_rsp *rsp);
9772
struct boot_loader_state;
9873
fih_int context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp);
9974

100-
int boot_swap_type_multi(int image_index);
101-
int boot_swap_type(void);
102-
103-
int boot_set_pending(int permanent);
104-
int boot_set_confirmed(void);
105-
10675
#define SPLIT_GO_OK (0)
10776
#define SPLIT_GO_NON_MATCHING (-1)
10877
#define SPLIT_GO_ERR (-2)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
* Copyright (c) 2020 Nordic Semiconductor ASA
8+
*
9+
* Original license:
10+
*
11+
* Licensed to the Apache Software Foundation (ASF) under one
12+
* or more contributor license agreements. See the NOTICE file
13+
* distributed with this work for additional information
14+
* regarding copyright ownership. The ASF licenses this file
15+
* to you under the Apache License, Version 2.0 (the
16+
* "License"); you may not use this file except in compliance
17+
* with the License. You may obtain a copy of the License at
18+
*
19+
* http://www.apache.org/licenses/LICENSE-2.0
20+
*
21+
* Unless required by applicable law or agreed to in writing,
22+
* software distributed under the License is distributed on an
23+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24+
* KIND, either express or implied. See the License for the
25+
* specific language governing permissions and limitations
26+
* under the License.
27+
*/
28+
29+
#ifndef H_BOOTUTIL_PUBLIC
30+
#define H_BOOTUTIL_PUBLIC
31+
32+
#include <inttypes.h>
33+
#include <string.h>
34+
#include <flash_map_backend/flash_map_backend.h>
35+
36+
#ifdef __cplusplus
37+
extern "C" {
38+
#endif
39+
40+
/** Attempt to boot the contents of the primary slot. */
41+
#define BOOT_SWAP_TYPE_NONE 1
42+
43+
/**
44+
* Swap to the secondary slot.
45+
* Absent a confirm command, revert back on next boot.
46+
*/
47+
#define BOOT_SWAP_TYPE_TEST 2
48+
49+
/**
50+
* Swap to the secondary slot,
51+
* and permanently switch to booting its contents.
52+
*/
53+
#define BOOT_SWAP_TYPE_PERM 3
54+
55+
/** Swap back to alternate slot. A confirm changes this state to NONE. */
56+
#define BOOT_SWAP_TYPE_REVERT 4
57+
58+
/** Swap failed because image to be run is not valid */
59+
#define BOOT_SWAP_TYPE_FAIL 5
60+
61+
/** Swapping encountered an unrecoverable error */
62+
#define BOOT_SWAP_TYPE_PANIC 0xff
63+
64+
#define BOOT_MAX_ALIGN 8
65+
66+
#define BOOT_MAGIC_GOOD 1
67+
#define BOOT_MAGIC_BAD 2
68+
#define BOOT_MAGIC_UNSET 3
69+
#define BOOT_MAGIC_ANY 4 /* NOTE: control only, not dependent on sector */
70+
#define BOOT_MAGIC_NOTGOOD 5 /* NOTE: control only, not dependent on sector */
71+
72+
/*
73+
* NOTE: leave BOOT_FLAG_SET equal to one, this is written to flash!
74+
*/
75+
#define BOOT_FLAG_SET 1
76+
#define BOOT_FLAG_BAD 2
77+
#define BOOT_FLAG_UNSET 3
78+
#define BOOT_FLAG_ANY 4 /* NOTE: control only, not dependent on sector */
79+
80+
#define BOOT_MAGIC_SZ (sizeof boot_img_magic)
81+
82+
int boot_swap_type_multi(int image_index);
83+
int boot_swap_type(void);
84+
85+
int boot_set_pending(int permanent);
86+
int boot_set_confirmed(void);
87+
uint32_t boot_swap_info_off(const struct flash_area *fap);
88+
89+
#define BOOT_MAGIC_ARR_SZ \
90+
(sizeof boot_img_magic / sizeof boot_img_magic[0])
91+
92+
extern const uint32_t boot_img_magic[4];
93+
94+
95+
#ifdef __cplusplus
96+
}
97+
#endif
98+
99+
#endif

0 commit comments

Comments
 (0)