Skip to content

Commit b192716

Browse files
tomchynordicjm
authored andcommitted
Revert "loader: Allow to specify slot number in version"
This reverts commit dce784a. Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent cf2387c commit b192716

File tree

8 files changed

+6
-252
lines changed

8 files changed

+6
-252
lines changed

boot/bootutil/include/bootutil/image.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ extern "C" {
146146
*/
147147
#define IMAGE_TLV_ANY 0xffff /* Used to iterate over all TLV */
148148

149-
#define VERSION_DEP_SLOT_ACTIVE 0x00 /* Check dependency against active slot. */
150-
#define VERSION_DEP_SLOT_PRIMARY 0x01 /* Check dependency against primary slot. */
151-
#define VERSION_DEP_SLOT_SECONDARY 0x02 /* Check dependency against secondary slot. */
152-
153149
STRUCT_PACKED image_version {
154150
uint8_t iv_major;
155151
uint8_t iv_minor;
@@ -159,11 +155,7 @@ STRUCT_PACKED image_version {
159155

160156
struct image_dependency {
161157
uint8_t image_id; /* Image index (from 0) */
162-
#ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
163-
uint8_t slot; /* Image slot */
164-
#else
165158
uint8_t _pad1;
166-
#endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
167159
uint16_t _pad2;
168160
struct image_version image_min_version; /* Indicates at minimum which
169161
* version of firmware must be

boot/bootutil/src/loader.c

Lines changed: 1 addition & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -324,24 +324,6 @@ boot_verify_slot_dependency(struct boot_loader_state *state,
324324
uint8_t swap_type = state->swap_type[dep->image_id];
325325
dep_slot = BOOT_IS_UPGRADE(swap_type) ? BOOT_SLOT_SECONDARY
326326
: BOOT_SLOT_PRIMARY;
327-
#elif defined(MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER)
328-
switch(dep->slot) {
329-
case VERSION_DEP_SLOT_ACTIVE:
330-
dep_slot = state->slot_usage[dep->image_id].active_slot;
331-
break;
332-
case VERSION_DEP_SLOT_PRIMARY:
333-
dep_slot = BOOT_SLOT_PRIMARY;
334-
break;
335-
case VERSION_DEP_SLOT_SECONDARY:
336-
dep_slot = BOOT_SLOT_SECONDARY;
337-
break;
338-
default:
339-
return -1;
340-
}
341-
342-
if (!state->slot_usage[dep->image_id].slot_available[dep_slot]) {
343-
return -1;
344-
}
345327
#else
346328
dep_slot = state->slot_usage[dep->image_id].active_slot;
347329
#endif
@@ -379,27 +361,7 @@ boot_verify_slot_dependency(struct boot_loader_state *state,
379361
}
380362
#endif
381363

382-
#ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
383-
if (rc == 0) {
384-
switch(dep->slot) {
385-
case VERSION_DEP_SLOT_PRIMARY:
386-
state->slot_usage[dep->image_id].slot_available[BOOT_SLOT_PRIMARY] = true;
387-
state->slot_usage[dep->image_id].slot_available[BOOT_SLOT_SECONDARY] = false;
388-
state->slot_usage[dep->image_id].active_slot = BOOT_SLOT_PRIMARY;
389-
break;
390-
case VERSION_DEP_SLOT_SECONDARY:
391-
state->slot_usage[dep->image_id].slot_available[BOOT_SLOT_PRIMARY] = false;
392-
state->slot_usage[dep->image_id].slot_available[BOOT_SLOT_SECONDARY] = true;
393-
state->slot_usage[dep->image_id].active_slot = BOOT_SLOT_SECONDARY;
394-
break;
395-
case VERSION_DEP_SLOT_ACTIVE:
396-
default:
397-
break;
398-
}
399-
}
400-
#endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
401-
402-
return rc;
364+
return rc;
403365
}
404366

405367
#if !defined(MCUBOOT_DIRECT_XIP) && !defined(MCUBOOT_RAM_LOAD)
@@ -544,19 +506,6 @@ boot_verify_slot_dependencies(struct boot_loader_state *state, uint32_t slot)
544506
goto done;
545507
}
546508

547-
#ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
548-
/* Validate against possible dependency slot values. */
549-
switch(dep.slot) {
550-
case VERSION_DEP_SLOT_ACTIVE:
551-
case VERSION_DEP_SLOT_PRIMARY:
552-
case VERSION_DEP_SLOT_SECONDARY:
553-
break;
554-
default:
555-
rc = BOOT_EBADARGS;
556-
goto done;
557-
}
558-
#endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
559-
560509
/* Verify dependency and modify the swap type if not satisfied. */
561510
rc = boot_verify_slot_dependency(state, &dep);
562511
if (rc != 0) {
@@ -2751,124 +2700,6 @@ boot_select_or_erase(struct boot_loader_state *state)
27512700
}
27522701
#endif /* MCUBOOT_DIRECT_XIP && MCUBOOT_DIRECT_XIP_REVERT */
27532702

2754-
#ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
2755-
/**
2756-
* Tries to load a slot for all the images with validation.
2757-
*
2758-
* @param state Boot loader status information.
2759-
*
2760-
* @return 0 on success; nonzero on failure.
2761-
*/
2762-
fih_ret
2763-
boot_load_and_validate_images(struct boot_loader_state *state)
2764-
{
2765-
uint32_t active_slot;
2766-
int rc;
2767-
fih_ret fih_rc;
2768-
uint32_t slot;
2769-
2770-
/* Go over all the images and all slots and validate them */
2771-
IMAGES_ITER(BOOT_CURR_IMG(state)) {
2772-
for (slot = 0; slot < BOOT_NUM_SLOTS; slot++) {
2773-
#if BOOT_IMAGE_NUMBER > 1
2774-
if (state->img_mask[BOOT_CURR_IMG(state)]) {
2775-
continue;
2776-
}
2777-
#endif
2778-
2779-
/* Save the number of the active slot. */
2780-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = slot;
2781-
2782-
#ifdef MCUBOOT_DIRECT_XIP
2783-
rc = boot_rom_address_check(state);
2784-
if (rc != 0) {
2785-
/* The image is placed in an unsuitable slot. */
2786-
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
2787-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
2788-
continue;
2789-
}
2790-
2791-
#ifdef MCUBOOT_DIRECT_XIP_REVERT
2792-
rc = boot_select_or_erase(state);
2793-
if (rc != 0) {
2794-
/* The selected image slot has been erased. */
2795-
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
2796-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
2797-
continue;
2798-
}
2799-
#endif /* MCUBOOT_DIRECT_XIP_REVERT */
2800-
#endif /* MCUBOOT_DIRECT_XIP */
2801-
2802-
#ifdef MCUBOOT_RAM_LOAD
2803-
/* Image is first loaded to RAM and authenticated there in order to
2804-
* prevent TOCTOU attack during image copy. This could be applied
2805-
* when loading images from external (untrusted) flash to internal
2806-
* (trusted) RAM and image is authenticated before copying.
2807-
*/
2808-
rc = boot_load_image_to_sram(state);
2809-
if (rc != 0 ) {
2810-
/* Image cannot be ramloaded. */
2811-
boot_remove_image_from_flash(state, slot);
2812-
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
2813-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
2814-
continue;
2815-
}
2816-
#endif /* MCUBOOT_RAM_LOAD */
2817-
2818-
FIH_CALL(boot_validate_slot, fih_rc, state, slot, NULL, 0);
2819-
if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) {
2820-
/* Image is invalid. */
2821-
#ifdef MCUBOOT_RAM_LOAD
2822-
boot_remove_image_from_sram(state);
2823-
#endif /* MCUBOOT_RAM_LOAD */
2824-
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
2825-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
2826-
continue;
2827-
}
2828-
2829-
/* Valid image loaded from a slot, go to the next slot. */
2830-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
2831-
}
2832-
}
2833-
2834-
/* Go over all the images and all slots and validate them */
2835-
IMAGES_ITER(BOOT_CURR_IMG(state)) {
2836-
/* All slots tried until a valid image found. Breaking from this loop
2837-
* means that a valid image found or already loaded. If no slot is
2838-
* found the function returns with error code. */
2839-
while (true) {
2840-
/* Go over all the slots and try to load one */
2841-
active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
2842-
if (active_slot != BOOT_SLOT_NONE){
2843-
/* A slot is already active, go to next image. */
2844-
break;
2845-
}
2846-
2847-
rc = BOOT_HOOK_FIND_SLOT_CALL(boot_find_next_slot_hook, BOOT_HOOK_REGULAR,
2848-
state, BOOT_CURR_IMG(state), &active_slot);
2849-
if (rc == BOOT_HOOK_REGULAR) {
2850-
active_slot = find_slot_with_highest_version(state);
2851-
}
2852-
2853-
if (active_slot == BOOT_SLOT_NONE) {
2854-
BOOT_LOG_INF("No slot to load for image %d",
2855-
BOOT_CURR_IMG(state));
2856-
FIH_RET(FIH_FAILURE);
2857-
}
2858-
2859-
/* Save the number of the active slot. */
2860-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = active_slot;
2861-
2862-
/* Valid image loaded from a slot, go to the next image. */
2863-
break;
2864-
}
2865-
}
2866-
2867-
FIH_RET(FIH_SUCCESS);
2868-
}
2869-
2870-
#else /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
2871-
28722703
/**
28732704
* Tries to load a slot for all the images with validation.
28742705
*
@@ -2971,7 +2802,6 @@ boot_load_and_validate_images(struct boot_loader_state *state)
29712802

29722803
FIH_RET(FIH_SUCCESS);
29732804
}
2974-
#endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
29752805

29762806
/**
29772807
* Updates the security counter for the current image.

boot/zephyr/Kconfig

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,15 +1016,6 @@ config BOOT_VERSION_CMP_USE_BUILD_NUMBER
10161016
minor and revision. Enable this option to take into account the build
10171017
number as well.
10181018

1019-
config BOOT_VERSION_CMP_USE_SLOT_NUMBER
1020-
bool "Use slot number while comparing image version"
1021-
depends on (UPDATEABLE_IMAGE_NUMBER > 1) || BOOT_DIRECT_XIP || \
1022-
BOOT_RAM_LOAD || MCUBOOT_DOWNGRADE_PREVENTION
1023-
help
1024-
By default, the image slot comparison relies only on active slot.
1025-
Enable this option to take into account the specified slot number
1026-
instead.
1027-
10281019
choice BOOT_DOWNGRADE_PREVENTION_CHOICE
10291020
prompt "Downgrade prevention"
10301021
optional

boot/zephyr/include/mcuboot_config/mcuboot_config.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@
124124
#define MCUBOOT_VERSION_CMP_USE_BUILD_NUMBER
125125
#endif
126126

127-
#ifdef CONFIG_BOOT_VERSION_CMP_USE_SLOT_NUMBER
128-
#define MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
129-
#endif
130-
131127
#ifdef CONFIG_BOOT_SWAP_SAVE_ENCTLV
132128
#define MCUBOOT_SWAP_SAVE_ENCTLV 1
133129
#endif

docs/design.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -951,23 +951,6 @@ process is presented below.
951951
+ Boot into image in the primary slot of the 0th image position\
952952
(other image in the boot chain is started by another image).
953953

954-
By enabling the `MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER` configuration option,
955-
the dependency check may be extended to match for a specified slot of a specific
956-
image. This functionality is useful in a multi-core system when Direct XIP mode
957-
is used.
958-
In this case, the main image can be started from one of the two (primary or
959-
secondary) slots.
960-
If there is a fixed connection between the slots of two different images,
961-
e.g. if the main image always chainloads a companion image from the same slot,
962-
the check must take this into account and only consider a matching slot when
963-
resolving dependencies.
964-
965-
There are three values that can be passed when specifying dependencies:
966-
967-
1. ``active``: the dependency should be checked against either primary or secondary slot.
968-
2. ``primary``: the dependency should be checked only against primary slot.
969-
3. ``secondary``: the dependency should be checked only against secondary slot.
970-
971954
### [Multiple image boot for RAM loading and direct-xip](#multiple-image-boot-for-ram-loading-and-direct-xip)
972955

973956
The operation of the bootloader is different when the ram-load or the

docs/imgtool.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ primary slot and adds a header and trailer that the bootloader is expecting:
9191
the `auto` keyword to automatically generate
9292
it from the image version.
9393
-d, --dependencies TEXT Add dependence on another image, format:
94-
"(<image_ID>,[<slot:active|primary|secondary>,]
95-
<image_version>), ... "
94+
"(<image_ID>,<image_version>), ... "
9695
--pad-sig Add 0-2 bytes of padding to ECDSA signature
9796
(for mcuboot <1.5)
9897
-H, --header-size INTEGER [required]
@@ -183,16 +182,6 @@ which the current image depends on. The `image_version` is the minimum version
183182
of that image to satisfy compliance. For example `-d "(1, 1.2.3+0)"` means this
184183
image depends on Image 1 which version has to be at least 1.2.3+0.
185184

186-
In addition, a dependency can specify the slot as follows:
187-
`-d "(image_id, slot, image_version)"`. The `image_id` is the number of the
188-
image on which the current image depends.
189-
The slot specifies which slots of the image are to be taken into account
190-
(`active`: primary or secondary, `primary`: only primary `secondary`: only
191-
secondary slot). The `image_version` is the minimum version of that image to
192-
fulfill the requirements.
193-
For example `-d "(1, primary, 1.2.3+0)"` means that this image depends on the
194-
primary slot of the Image 1, whose version must be at least 1.2.3+0.
195-
196185
The `--public-key-format` argument can be used to distinguish where the public
197186
key is stored for image authentication. The `hash` option is used by default, in
198187
which case only the hash of the public key is added to the TLV area (the full

scripts/imgtool/image.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,8 @@ def create(self, key, public_key_format, enckey, dependencies=None,
630630
if dependencies is not None:
631631
for i in range(dependencies_num):
632632
payload = struct.pack(
633-
e + 'BB2x' + 'BBHI',
633+
e + 'B3x' + 'BBHI',
634634
int(dependencies[DEP_IMAGES_KEY][i]),
635-
dependencies[DEP_VERSIONS_KEY][i].slot,
636635
dependencies[DEP_VERSIONS_KEY][i].major,
637636
dependencies[DEP_VERSIONS_KEY][i].minor,
638637
dependencies[DEP_VERSIONS_KEY][i].revision,

scripts/imgtool/main.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import re
2424
import struct
2525
import sys
26-
from collections import namedtuple
2726

2827
import click
2928

@@ -45,14 +44,6 @@
4544
if sys.version_info < MIN_PYTHON_VERSION:
4645
sys.exit("Python {}.{} or newer is required by imgtool.".format(*MIN_PYTHON_VERSION))
4746

48-
SlottedSemiSemVersion = namedtuple('SemiSemVersion', ['major', 'minor', 'revision',
49-
'build', 'slot'])
50-
51-
DEPENDENCY_SLOT_VALUES = {
52-
'active': 0x00,
53-
'primary': 0x01,
54-
'secondary': 0x02
55-
}
5647

5748
def gen_rsa2048(keyfile, passwd):
5849
keys.RSA.generate().export_private(path=keyfile, passwd=passwd)
@@ -309,33 +300,16 @@ def get_dependencies(ctx, param, value):
309300
if len(images) == 0:
310301
raise click.BadParameter(
311302
f"Image dependency format is invalid: {value}")
312-
raw_versions = re.findall(r",\s*((active|primary|secondary)\s*,)?\s*([0-9.+]+)\)", value)
303+
raw_versions = re.findall(r",\s*([0-9.+]+)\)", value)
313304
if len(images) != len(raw_versions):
314305
raise click.BadParameter(
315306
f'''There's a mismatch between the number of dependency images
316307
and versions in: {value}''')
317308
for raw_version in raw_versions:
318309
try:
319-
decoded_version = decode_version(raw_version[2])
320-
if len(raw_version[1]) > 0:
321-
slotted_version = SlottedSemiSemVersion(
322-
decoded_version.major,
323-
decoded_version.minor,
324-
decoded_version.revision,
325-
decoded_version.build,
326-
DEPENDENCY_SLOT_VALUES[raw_version[1]]
327-
)
328-
else:
329-
slotted_version = SlottedSemiSemVersion(
330-
decoded_version.major,
331-
decoded_version.minor,
332-
decoded_version.revision,
333-
decoded_version.build,
334-
0
335-
)
310+
versions.append(decode_version(raw_version))
336311
except ValueError as e:
337312
raise click.BadParameter(f"{e}")
338-
versions.append(slotted_version)
339313
dependencies = dict()
340314
dependencies[image.DEP_IMAGES_KEY] = images
341315
dependencies[image.DEP_VERSIONS_KEY] = versions
@@ -432,7 +406,7 @@ def convert(self, value, param, ctx):
432406
'(for mcuboot <1.5)')
433407
@click.option('-d', '--dependencies', callback=get_dependencies,
434408
required=False, help='''Add dependence on another image, format:
435-
"(<image_ID>,[<slot:active|primary|secondary>,]<image_version>), ... "''')
409+
"(<image_ID>,<image_version>), ... "''')
436410
@click.option('-s', '--security-counter', callback=validate_security_counter,
437411
help='Specify the value of security counter. Use the `auto` '
438412
'keyword to automatically generate it from the image version.')

0 commit comments

Comments
 (0)