Skip to content

Commit 1c45624

Browse files
committed
boot: Correct MCUBOOT_DIRECT_XIP_REVERT enablement
To avoid potential errors caused by misconfiguration make sure the conditionally compiled snippets of code surrounded by the MCUBOOT_DIRECT_XIP_REVERT macro are only used when direct-xip mode is selected. Change-Id: I6178d8186a7ca05887bc7590f5fa0c8f83f3d731 Signed-off-by: David Vincze <david.vincze@arm.com>
1 parent dd6a84e commit 1c45624

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

boot/bootutil/src/loader.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,16 @@ struct slot_usage_t {
6767
/* Index of the slot chosen to be loaded */
6868
uint32_t active_slot;
6969
bool slot_available[BOOT_NUM_SLOTS];
70-
#ifdef MCUBOOT_RAM_LOAD
70+
#if defined(MCUBOOT_RAM_LOAD)
7171
/* Image destination and size for the active slot */
7272
uint32_t img_dst;
7373
uint32_t img_sz;
74-
#endif /* MCUBOOT_RAM_LOAD */
75-
#ifdef MCUBOOT_DIRECT_XIP_REVERT
74+
#elif defined(MCUBOOT_DIRECT_XIP_REVERT)
7675
/* Swap status for the active slot */
7776
struct boot_swap_state swap_state;
78-
#endif /* MCUBOOT_DIRECT_XIP_REVERT */
79-
};
8077
#endif
78+
};
79+
#endif /* MCUBOOT_DIRECT_XIP || MCUBOOT_RAM_LOAD */
8180

8281
/*
8382
* This macro allows some control on the allocation of local variables.
@@ -2247,7 +2246,7 @@ print_loaded_images(struct boot_loader_state *state,
22472246
}
22482247
#endif
22492248

2250-
#ifdef MCUBOOT_DIRECT_XIP_REVERT
2249+
#if defined(MCUBOOT_DIRECT_XIP) && defined(MCUBOOT_DIRECT_XIP_REVERT)
22512250
/**
22522251
* Checks whether the active slot of the current image was previously selected
22532252
* to run. Erases the image if it was selected but its execution failed,
@@ -2320,7 +2319,7 @@ boot_select_or_erase(struct boot_loader_state *state,
23202319

23212320
return rc;
23222321
}
2323-
#endif /* MCUBOOT_DIRECT_XIP_REVERT */
2322+
#endif /* MCUBOOT_DIRECT_XIP && MCUBOOT_DIRECT_XIP_REVERT */
23242323

23252324
#ifdef MCUBOOT_RAM_LOAD
23262325

@@ -2812,7 +2811,6 @@ boot_load_and_validate_images(struct boot_loader_state *state,
28122811
slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
28132812
continue;
28142813
}
2815-
#endif /* MCUBOOT_DIRECT_XIP */
28162814

28172815
#ifdef MCUBOOT_DIRECT_XIP_REVERT
28182816
rc = boot_select_or_erase(state, slot_usage);
@@ -2823,6 +2821,7 @@ boot_load_and_validate_images(struct boot_loader_state *state,
28232821
continue;
28242822
}
28252823
#endif /* MCUBOOT_DIRECT_XIP_REVERT */
2824+
#endif /* MCUBOOT_DIRECT_XIP */
28262825

28272826
#ifdef MCUBOOT_RAM_LOAD
28282827
/* Image is first loaded to RAM and authenticated there in order to
@@ -2877,7 +2876,7 @@ boot_update_hw_rollback_protection(struct boot_loader_state *state,
28772876
/* Update the stored security counter with the newer (active) image's
28782877
* security counter value.
28792878
*/
2880-
#ifdef MCUBOOT_DIRECT_XIP_REVERT
2879+
#if defined(MCUBOOT_DIRECT_XIP) && defined(MCUBOOT_DIRECT_XIP_REVERT)
28812880
/* When the 'revert' mechanism is enabled in direct-xip mode, the
28822881
* security counter can be increased only after reboot, if the image
28832882
* has been confirmed at runtime (the image_ok flag has been set).
@@ -2892,7 +2891,7 @@ boot_update_hw_rollback_protection(struct boot_loader_state *state,
28922891
"validation.");
28932892
return rc;
28942893
}
2895-
#ifdef MCUBOOT_DIRECT_XIP_REVERT
2894+
#if defined(MCUBOOT_DIRECT_XIP) && defined(MCUBOOT_DIRECT_XIP_REVERT)
28962895
}
28972896
#endif
28982897

docs/design.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,14 @@ the bit-level contents of flash.
347347
### [Revert mechanism in direct-xip mode](#direct-xip-revert)
348348
349349
The direct-xip mode also supports a "revert" mechanism which is the equivalent
350-
of the swap mode's "revert" swap. It can be enabled with the
351-
MCUBOOT_DIRECT_XIP_REVERT config option and an image trailer must also be added
352-
to the signed images (the "--pad" option of the `imgtool` script must be used).
353-
For more information on this please read the [Image Trailer](#image-trailer)
354-
section and the [imgtool](imgtool.md) documentation. Making the images permanent
355-
(marking them as confirmed in advance) is also supported just like in swap mode.
356-
The individual steps of the direct-xip mode's "revert" mechanism are the
357-
following:
350+
of the swap mode's "revert" swap. When the direct-xip mode is selected it can be
351+
enabled with the MCUBOOT_DIRECT_XIP_REVERT config option and an image trailer
352+
must also be added to the signed images (the "--pad" option of the `imgtool`
353+
script must be used). For more information on this please read the
354+
[Image Trailer](#image-trailer) section and the [imgtool](imgtool.md)
355+
documentation. Making the images permanent (marking them as confirmed in
356+
advance) is also supported just like in swap mode. The individual steps of the
357+
direct-xip mode's "revert" mechanism are the following:
358358
359359
1. Select the slot which holds the newest potential image.
360360
2. Was the image previously selected to run (during a previous boot)?

0 commit comments

Comments
 (0)