Skip to content

Commit cabc30e

Browse files
authored
Merge pull request #2621 from dhalbert/flash-erase-check
correct check for flash erase boundaries
2 parents e97b0cf + dc97b0d commit cabc30e

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

ports/atmel-samd/mpconfigport.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@
109109
#define CIRCUITPY_DEFAULT_STACK_SIZE 4096
110110
#endif
111111

112+
// Smallest unit of flash that can be erased.
113+
#define FLASH_ERASE_SIZE NVMCTRL_ROW_SIZE
114+
112115
#endif // SAMD21
113116

114117
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -123,6 +126,9 @@
123126
#define CIRCUITPY_DEFAULT_STACK_SIZE (24*1024)
124127
#endif
125128

129+
// Smallest unit of flash that can be erased.
130+
#define FLASH_ERASE_SIZE NVMCTRL_BLOCK_SIZE
131+
126132
// If CIRCUITPY is internal, use half of flash for it.
127133
#if INTERNAL_FLASH_FILESYSTEM
128134
#ifndef CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE
@@ -187,25 +193,25 @@
187193
#error BOOTLOADER_START_ADDR must be on a flash page boundary.
188194
#endif
189195

190-
#if CIRCUITPY_INTERNAL_NVM_START_ADDR % FLASH_PAGE_SIZE != 0
191-
#error CIRCUITPY_INTERNAL_NVM_START_ADDR must be on a flash page boundary.
196+
#if CIRCUITPY_INTERNAL_NVM_START_ADDR % FLASH_ERASE_SIZE != 0
197+
#error CIRCUITPY_INTERNAL_NVM_START_ADDR must be on a flash erase (row or block) boundary.
192198
#endif
193-
#if CIRCUITPY_INTERNAL_NVM_SIZE % FLASH_PAGE_SIZE != 0
194-
#error CIRCUITPY_INTERNAL_NVM_SIZE must be a multiple of FLASH_PAGE_SIZE.
199+
#if CIRCUITPY_INTERNAL_NVM_SIZE % FLASH_ERASE_SIZE != 0
200+
#error CIRCUITPY_INTERNAL_NVM_SIZE must be a multiple of FLASH_ERASE_SIZE.
195201
#endif
196202

197-
#if CIRCUITPY_INTERNAL_CONFIG_START_ADDR % FLASH_PAGE_SIZE != 0
198-
#error CIRCUITPY_INTERNAL_CONFIG_SIZE must be on a flash page boundary.
203+
#if CIRCUITPY_INTERNAL_CONFIG_START_ADDR % FLASH_ERASE_SIZE != 0
204+
#error CIRCUITPY_INTERNAL_CONFIG_SIZE must be on a flash erase (row or block) boundary.
199205
#endif
200-
#if CIRCUITPY_INTERNAL_CONFIG_SIZE % FLASH_PAGE_SIZE != 0
201-
#error CIRCUITPY_INTERNAL_CONFIG_SIZE must be a multiple of FLASH_PAGE_SIZE.
206+
#if CIRCUITPY_INTERNAL_CONFIG_SIZE % FLASH_ERASE_SIZE != 0
207+
#error CIRCUITPY_INTERNAL_CONFIG_SIZE must be a multiple of FLASH_ERASE_SIZE.
202208
#endif
203209

204-
#if CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR % FLASH_PAGE_SIZE != 0
205-
#error CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE must be on a flash page boundary.
210+
#if CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR % FLASH_ERASE_SIZE != 0
211+
#error CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE must be on a flash erase (row or block) boundary.
206212
#endif
207-
#if CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE % FLASH_PAGE_SIZE != 0
208-
#error CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE must be a multiple of FLASH_PAGE_SIZE.
213+
#if CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE % FLASH_ERASE_SIZE != 0
214+
#error CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE must be a multiple of FLASH_ERASE_SIZE.
209215
#endif
210216

211217
#if CIRCUITPY_FIRMWARE_SIZE < 0

ports/nrf/mpconfigport.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
#define ISR_START_ADDR (SD_FLASH_START_ADDR + SD_FLASH_SIZE)
105105
#define ISR_SIZE (0x1000) // 4kiB
106106

107+
// Smallest unit of flash that can be erased.
108+
#define FLASH_ERASE_SIZE FLASH_PAGE_SIZE
109+
107110
#define CIRCUITPY_FIRMWARE_START_ADDR (ISR_START_ADDR + ISR_SIZE)
108111

109112
// Define these regions starting down from the bootloader:
@@ -129,29 +132,29 @@
129132
// The firmware space is the space left over between the fixed lower and upper regions.
130133
#define CIRCUITPY_FIRMWARE_SIZE (CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR - CIRCUITPY_FIRMWARE_START_ADDR)
131134

132-
#if BOOTLOADER_START_ADDR % FLASH_PAGE_SIZE != 0
133-
#error BOOTLOADER_START_ADDR must be on a flash page boundary.
135+
#if BOOTLOADER_START_ADDR % FLASH_ERASE_SIZE != 0
136+
#error BOOTLOADER_START_ADDR must be on a flash erase boundary.
134137
#endif
135138

136-
#if CIRCUITPY_INTERNAL_NVM_START_ADDR % FLASH_PAGE_SIZE != 0
137-
#error CIRCUITPY_INTERNAL_NVM_START_ADDR must be on a flash page boundary.
139+
#if CIRCUITPY_INTERNAL_NVM_START_ADDR % FLASH_ERASE_SIZE != 0
140+
#error CIRCUITPY_INTERNAL_NVM_START_ADDR must be on a flash erase boundary.
138141
#endif
139-
#if CIRCUITPY_INTERNAL_NVM_SIZE % FLASH_PAGE_SIZE != 0
140-
#error CIRCUITPY_INTERNAL_NVM_SIZE must be a multiple of FLASH_PAGE_SIZE.
142+
#if CIRCUITPY_INTERNAL_NVM_SIZE % FLASH_ERASE_SIZE != 0
143+
#error CIRCUITPY_INTERNAL_NVM_SIZE must be a multiple of FLASH_ERASE_SIZE.
141144
#endif
142145

143-
#if CIRCUITPY_BLE_CONFIG_START_ADDR % FLASH_PAGE_SIZE != 0
144-
#error CIRCUITPY_BLE_CONFIG_SIZE must be on a flash page boundary.
146+
#if CIRCUITPY_BLE_CONFIG_START_ADDR % FLASH_ERASE_SIZE != 0
147+
#error CIRCUITPY_BLE_CONFIG_SIZE must be on a flash erase boundary.
145148
#endif
146-
#if CIRCUITPY_BLE_CONFIG_SIZE % FLASH_PAGE_SIZE != 0
147-
#error CIRCUITPY_BLE_CONFIG_SIZE must be a multiple of FLASH_PAGE_SIZE.
149+
#if CIRCUITPY_BLE_CONFIG_SIZE % FLASH_ERASE_SIZE != 0
150+
#error CIRCUITPY_BLE_CONFIG_SIZE must be a multiple of FLASH_ERASE_SIZE.
148151
#endif
149152

150-
#if CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR % FLASH_PAGE_SIZE != 0
151-
#error CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE must be on a flash page boundary.
153+
#if CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR % FLASH_ERASE_SIZE != 0
154+
#error CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE must be on a flash erase boundary.
152155
#endif
153-
#if CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE % FLASH_PAGE_SIZE != 0
154-
#error CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE must be a multiple of FLASH_PAGE_SIZE.
156+
#if CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE % FLASH_ERASE_SIZE != 0
157+
#error CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE must be a multiple of FLASH_ERASE_SIZE.
155158
#endif
156159

157160
#if CIRCUITPY_FIRMWARE_SIZE < 0

0 commit comments

Comments
 (0)