Skip to content

Commit 41ffb2c

Browse files
committed
Add partition overlap guards
F/2571
1 parent f8cbad0 commit 41ffb2c

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

include/MPLAB/target.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,41 @@
9090
#define WOLFBOOT_DTS_BOOT_ADDRESS
9191
#define WOLFBOOT_DTS_UPDATE_ADDRESS
9292

93+
#if !defined(WOLFBOOT_PART_USE_ARCH_OFFSET) && !defined(PULL_LINKER_DEFINES)
94+
/*
95+
* Only compare partitions that share the same internal flash address
96+
* space. External partitions and runtime/linker-provided addresses are
97+
* validated elsewhere.
98+
*/
99+
#if !defined(PART_BOOT_EXT) && !defined(PART_UPDATE_EXT) && \
100+
(WOLFBOOT_PARTITION_UPDATE_ADDRESS != 0) && \
101+
((WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE) > \
102+
WOLFBOOT_PARTITION_UPDATE_ADDRESS) && \
103+
(WOLFBOOT_PARTITION_BOOT_ADDRESS < \
104+
(WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE))
105+
#error "Boot and update partitions overlap"
106+
#endif
107+
108+
#if !defined(PART_BOOT_EXT) && !defined(PART_SWAP_EXT) && \
109+
(WOLFBOOT_PARTITION_SWAP_ADDRESS != 0) && \
110+
((WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE) > \
111+
WOLFBOOT_PARTITION_SWAP_ADDRESS) && \
112+
(WOLFBOOT_PARTITION_BOOT_ADDRESS < \
113+
(WOLFBOOT_PARTITION_SWAP_ADDRESS + WOLFBOOT_SECTOR_SIZE))
114+
#error "Boot and swap partitions overlap"
115+
#endif
116+
117+
#if !defined(PART_UPDATE_EXT) && !defined(PART_SWAP_EXT) && \
118+
(WOLFBOOT_PARTITION_UPDATE_ADDRESS != 0) && \
119+
(WOLFBOOT_PARTITION_SWAP_ADDRESS != 0) && \
120+
((WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE) > \
121+
WOLFBOOT_PARTITION_SWAP_ADDRESS) && \
122+
(WOLFBOOT_PARTITION_UPDATE_ADDRESS < \
123+
(WOLFBOOT_PARTITION_SWAP_ADDRESS + WOLFBOOT_SECTOR_SIZE))
124+
#error "Update and swap partitions overlap"
125+
#endif
126+
#endif
127+
93128
#endif /* WOLFBOOT_FIXED_PARTITIONS */
94129

95130
/* Load address in RAM for staged OS (update_ram only) */

include/target.h.in

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,41 @@
110110
#define WOLFBOOT_DTS_BOOT_ADDRESS @WOLFBOOT_DTS_BOOT_ADDRESS@
111111
#define WOLFBOOT_DTS_UPDATE_ADDRESS @WOLFBOOT_DTS_UPDATE_ADDRESS@
112112

113+
#if !defined(WOLFBOOT_PART_USE_ARCH_OFFSET) && !defined(PULL_LINKER_DEFINES)
114+
/*
115+
* Only compare partitions that share the same internal flash address
116+
* space. External partitions and runtime/linker-provided addresses are
117+
* validated elsewhere.
118+
*/
119+
#if !defined(PART_BOOT_EXT) && !defined(PART_UPDATE_EXT) && \
120+
(WOLFBOOT_PARTITION_UPDATE_ADDRESS != 0) && \
121+
((WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE) > \
122+
WOLFBOOT_PARTITION_UPDATE_ADDRESS) && \
123+
(WOLFBOOT_PARTITION_BOOT_ADDRESS < \
124+
(WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE))
125+
#error "Boot and update partitions overlap"
126+
#endif
127+
128+
#if !defined(PART_BOOT_EXT) && !defined(PART_SWAP_EXT) && \
129+
(WOLFBOOT_PARTITION_SWAP_ADDRESS != 0) && \
130+
((WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE) > \
131+
WOLFBOOT_PARTITION_SWAP_ADDRESS) && \
132+
(WOLFBOOT_PARTITION_BOOT_ADDRESS < \
133+
(WOLFBOOT_PARTITION_SWAP_ADDRESS + WOLFBOOT_SECTOR_SIZE))
134+
#error "Boot and swap partitions overlap"
135+
#endif
136+
137+
#if !defined(PART_UPDATE_EXT) && !defined(PART_SWAP_EXT) && \
138+
(WOLFBOOT_PARTITION_UPDATE_ADDRESS != 0) && \
139+
(WOLFBOOT_PARTITION_SWAP_ADDRESS != 0) && \
140+
((WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE) > \
141+
WOLFBOOT_PARTITION_SWAP_ADDRESS) && \
142+
(WOLFBOOT_PARTITION_UPDATE_ADDRESS < \
143+
(WOLFBOOT_PARTITION_SWAP_ADDRESS + WOLFBOOT_SECTOR_SIZE))
144+
#error "Update and swap partitions overlap"
145+
#endif
146+
#endif
147+
113148
#endif /* WOLFBOOT_FIXED_PARTITIONS */
114149

115150
#if !defined(WOLFBOOT_NO_LOAD_ADDRESS)

0 commit comments

Comments
 (0)