Skip to content

Commit b495d38

Browse files
committed
[nrf fromtree] Revert "loader: Allow to specify slot number in version"
This reverts commit dce784a. Signed-off-by: Tomasz Chyrowicz <[email protected]> (cherry picked from commit b192716c969ad358bb3a1db60c898212f3275c55)
1 parent 17052c2 commit b495d38

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
@@ -391,24 +391,6 @@ boot_verify_slot_dependency(struct boot_loader_state *state,
391391
uint8_t swap_type = state->swap_type[dep->image_id];
392392
dep_slot = BOOT_IS_UPGRADE(swap_type) ? BOOT_SLOT_SECONDARY
393393
: BOOT_SLOT_PRIMARY;
394-
#elif defined(MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER)
395-
switch(dep->slot) {
396-
case VERSION_DEP_SLOT_ACTIVE:
397-
dep_slot = state->slot_usage[dep->image_id].active_slot;
398-
break;
399-
case VERSION_DEP_SLOT_PRIMARY:
400-
dep_slot = BOOT_SLOT_PRIMARY;
401-
break;
402-
case VERSION_DEP_SLOT_SECONDARY:
403-
dep_slot = BOOT_SLOT_SECONDARY;
404-
break;
405-
default:
406-
return -1;
407-
}
408-
409-
if (!state->slot_usage[dep->image_id].slot_available[dep_slot]) {
410-
return -1;
411-
}
412394
#else
413395
dep_slot = state->slot_usage[dep->image_id].active_slot;
414396
#endif
@@ -446,27 +428,7 @@ boot_verify_slot_dependency(struct boot_loader_state *state,
446428
}
447429
#endif
448430

449-
#ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
450-
if (rc == 0) {
451-
switch(dep->slot) {
452-
case VERSION_DEP_SLOT_PRIMARY:
453-
state->slot_usage[dep->image_id].slot_available[BOOT_SLOT_PRIMARY] = true;
454-
state->slot_usage[dep->image_id].slot_available[BOOT_SLOT_SECONDARY] = false;
455-
state->slot_usage[dep->image_id].active_slot = BOOT_SLOT_PRIMARY;
456-
break;
457-
case VERSION_DEP_SLOT_SECONDARY:
458-
state->slot_usage[dep->image_id].slot_available[BOOT_SLOT_PRIMARY] = false;
459-
state->slot_usage[dep->image_id].slot_available[BOOT_SLOT_SECONDARY] = true;
460-
state->slot_usage[dep->image_id].active_slot = BOOT_SLOT_SECONDARY;
461-
break;
462-
case VERSION_DEP_SLOT_ACTIVE:
463-
default:
464-
break;
465-
}
466-
}
467-
#endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
468-
469-
return rc;
431+
return rc;
470432
}
471433

472434
#if !defined(MCUBOOT_DIRECT_XIP) && !defined(MCUBOOT_RAM_LOAD)
@@ -614,19 +576,6 @@ boot_verify_slot_dependencies(struct boot_loader_state *state, uint32_t slot)
614576
goto done;
615577
}
616578

617-
#ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
618-
/* Validate against possible dependency slot values. */
619-
switch(dep.slot) {
620-
case VERSION_DEP_SLOT_ACTIVE:
621-
case VERSION_DEP_SLOT_PRIMARY:
622-
case VERSION_DEP_SLOT_SECONDARY:
623-
break;
624-
default:
625-
rc = BOOT_EBADARGS;
626-
goto done;
627-
}
628-
#endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
629-
630579
/* Verify dependency and modify the swap type if not satisfied. */
631580
rc = boot_verify_slot_dependency(state, &dep);
632581
if (rc != 0) {
@@ -3281,124 +3230,6 @@ boot_select_or_erase(struct boot_loader_state *state)
32813230
}
32823231
#endif /* MCUBOOT_DIRECT_XIP && MCUBOOT_DIRECT_XIP_REVERT */
32833232

3284-
#ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
3285-
/**
3286-
* Tries to load a slot for all the images with validation.
3287-
*
3288-
* @param state Boot loader status information.
3289-
*
3290-
* @return 0 on success; nonzero on failure.
3291-
*/
3292-
fih_ret
3293-
boot_load_and_validate_images(struct boot_loader_state *state)
3294-
{
3295-
uint32_t active_slot;
3296-
int rc;
3297-
fih_ret fih_rc;
3298-
uint32_t slot;
3299-
3300-
/* Go over all the images and all slots and validate them */
3301-
IMAGES_ITER(BOOT_CURR_IMG(state)) {
3302-
for (slot = 0; slot < BOOT_NUM_SLOTS; slot++) {
3303-
#if BOOT_IMAGE_NUMBER > 1
3304-
if (state->img_mask[BOOT_CURR_IMG(state)]) {
3305-
continue;
3306-
}
3307-
#endif
3308-
3309-
/* Save the number of the active slot. */
3310-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = slot;
3311-
3312-
#ifdef MCUBOOT_DIRECT_XIP
3313-
rc = boot_rom_address_check(state);
3314-
if (rc != 0) {
3315-
/* The image is placed in an unsuitable slot. */
3316-
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
3317-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
3318-
continue;
3319-
}
3320-
3321-
#ifdef MCUBOOT_DIRECT_XIP_REVERT
3322-
rc = boot_select_or_erase(state);
3323-
if (rc != 0) {
3324-
/* The selected image slot has been erased. */
3325-
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
3326-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
3327-
continue;
3328-
}
3329-
#endif /* MCUBOOT_DIRECT_XIP_REVERT */
3330-
#endif /* MCUBOOT_DIRECT_XIP */
3331-
3332-
#ifdef MCUBOOT_RAM_LOAD
3333-
/* Image is first loaded to RAM and authenticated there in order to
3334-
* prevent TOCTOU attack during image copy. This could be applied
3335-
* when loading images from external (untrusted) flash to internal
3336-
* (trusted) RAM and image is authenticated before copying.
3337-
*/
3338-
rc = boot_load_image_to_sram(state);
3339-
if (rc != 0 ) {
3340-
/* Image cannot be ramloaded. */
3341-
boot_remove_image_from_flash(state, slot);
3342-
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
3343-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
3344-
continue;
3345-
}
3346-
#endif /* MCUBOOT_RAM_LOAD */
3347-
3348-
FIH_CALL(boot_validate_slot, fih_rc, state, slot, NULL, 0);
3349-
if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) {
3350-
/* Image is invalid. */
3351-
#ifdef MCUBOOT_RAM_LOAD
3352-
boot_remove_image_from_sram(state);
3353-
#endif /* MCUBOOT_RAM_LOAD */
3354-
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
3355-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
3356-
continue;
3357-
}
3358-
3359-
/* Valid image loaded from a slot, go to the next slot. */
3360-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = BOOT_SLOT_NONE;
3361-
}
3362-
}
3363-
3364-
/* Go over all the images and all slots and validate them */
3365-
IMAGES_ITER(BOOT_CURR_IMG(state)) {
3366-
/* All slots tried until a valid image found. Breaking from this loop
3367-
* means that a valid image found or already loaded. If no slot is
3368-
* found the function returns with error code. */
3369-
while (true) {
3370-
/* Go over all the slots and try to load one */
3371-
active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
3372-
if (active_slot != BOOT_SLOT_NONE){
3373-
/* A slot is already active, go to next image. */
3374-
break;
3375-
}
3376-
3377-
rc = BOOT_HOOK_FIND_SLOT_CALL(boot_find_next_slot_hook, BOOT_HOOK_REGULAR,
3378-
state, BOOT_CURR_IMG(state), &active_slot);
3379-
if (rc == BOOT_HOOK_REGULAR) {
3380-
active_slot = find_slot_with_highest_version(state);
3381-
}
3382-
3383-
if (active_slot == BOOT_SLOT_NONE) {
3384-
BOOT_LOG_INF("No slot to load for image %d",
3385-
BOOT_CURR_IMG(state));
3386-
FIH_RET(FIH_FAILURE);
3387-
}
3388-
3389-
/* Save the number of the active slot. */
3390-
state->slot_usage[BOOT_CURR_IMG(state)].active_slot = active_slot;
3391-
3392-
/* Valid image loaded from a slot, go to the next image. */
3393-
break;
3394-
}
3395-
}
3396-
3397-
FIH_RET(FIH_SUCCESS);
3398-
}
3399-
3400-
#else /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
3401-
34023233
/**
34033234
* Tries to load a slot for all the images with validation.
34043235
*
@@ -3501,7 +3332,6 @@ boot_load_and_validate_images(struct boot_loader_state *state)
35013332

35023333
FIH_RET(FIH_SUCCESS);
35033334
}
3504-
#endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
35053335

35063336
/**
35073337
* 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
@@ -1103,15 +1103,6 @@ config BOOT_VERSION_CMP_USE_BUILD_NUMBER
11031103
minor and revision. Enable this option to take into account the build
11041104
number as well.
11051105

1106-
config BOOT_VERSION_CMP_USE_SLOT_NUMBER
1107-
bool "Use slot number while comparing image version"
1108-
depends on (UPDATEABLE_IMAGE_NUMBER > 1) || BOOT_DIRECT_XIP || \
1109-
BOOT_RAM_LOAD || MCUBOOT_DOWNGRADE_PREVENTION
1110-
help
1111-
By default, the image slot comparison relies only on active slot.
1112-
Enable this option to take into account the specified slot number
1113-
instead.
1114-
11151106
choice BOOT_DOWNGRADE_PREVENTION_CHOICE
11161107
prompt "Downgrade prevention"
11171108
optional

boot/zephyr/include/mcuboot_config/mcuboot_config.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@
130130
#define MCUBOOT_VERSION_CMP_USE_BUILD_NUMBER
131131
#endif
132132

133-
#ifdef CONFIG_BOOT_VERSION_CMP_USE_SLOT_NUMBER
134-
#define MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
135-
#endif
136-
137133
#ifdef CONFIG_BOOT_SWAP_SAVE_ENCTLV
138134
#define MCUBOOT_SWAP_SAVE_ENCTLV 1
139135
#endif

docs/design.md

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

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

966949
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
@@ -627,9 +627,8 @@ def create(self, key, public_key_format, enckey, dependencies=None,
627627
if dependencies is not None:
628628
for i in range(dependencies_num):
629629
payload = struct.pack(
630-
e + 'BB2x' + 'BBHI',
630+
e + 'B3x' + 'BBHI',
631631
int(dependencies[DEP_IMAGES_KEY][i]),
632-
dependencies[DEP_VERSIONS_KEY][i].slot,
633632
dependencies[DEP_VERSIONS_KEY][i].major,
634633
dependencies[DEP_VERSIONS_KEY][i].minor,
635634
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
@@ -429,7 +403,7 @@ def convert(self, value, param, ctx):
429403
'(for mcuboot <1.5)')
430404
@click.option('-d', '--dependencies', callback=get_dependencies,
431405
required=False, help='''Add dependence on another image, format:
432-
"(<image_ID>,[<slot:active|primary|secondary>,]<image_version>), ... "''')
406+
"(<image_ID>,<image_version>), ... "''')
433407
@click.option('-s', '--security-counter', callback=validate_security_counter,
434408
help='Specify the value of security counter. Use the `auto` '
435409
'keyword to automatically generate it from the image version.')

0 commit comments

Comments
 (0)