Skip to content

Commit 400d614

Browse files
committed
fix: Clarify and validate alignment requirements for flashing
1 parent 0785c94 commit 400d614

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

include/esp_loader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ esp_loader_error_t esp_loader_connect_secure_download_mode(esp_loader_connect_ar
181181
/**
182182
* @brief Initiates flash operation
183183
*
184-
* @param offset[in] Address from which flash operation will be performed.
185-
* @param image_size[in] Size of the whole binary to be loaded into flash.
186-
* @param block_size[in] Size of buffer used in subsequent calls to esp_loader_flash_write.
184+
* @param offset[in] Address from which flash operation will be performed. Must be 4 byte aligned.
185+
* @param image_size[in] Size of the whole binary to be loaded into flash. Must be 4 byte aligned.
186+
* @param block_size[in] Size of buffer used in subsequent calls to esp_loader_flash_write.
187187
*
188188
* @note image_size is size of the whole image, whereas, block_size is chunk of data sent
189189
* to the target, each time esp_loader_flash_write function is called.

src/esp_loader.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ esp_loader_error_t esp_loader_flash_start(uint32_t offset, uint32_t image_size,
320320
{
321321
s_flash_write_size = block_size;
322322

323+
// Both the address and image size must be aligned to 4 bytes
324+
if (offset % 4 != 0 || image_size % 4 != 0) {
325+
return ESP_LOADER_ERROR_INVALID_PARAM;
326+
}
327+
323328
/* Flash size will be known in advance if we're in secure download mode or we already read it*/
324329
if (s_target_flash_size == 0) {
325330
if (esp_loader_flash_detect_size(&s_target_flash_size) == ESP_LOADER_SUCCESS) {

0 commit comments

Comments
 (0)