Skip to content

Commit 83ca12c

Browse files
committed
fix(esp_flash): fixed issue of escaping boundary check
Also patched corresponding ROM functions
1 parent b971cf5 commit 83ca12c

File tree

19 files changed

+214
-53
lines changed

19 files changed

+214
-53
lines changed

components/esp_rom/esp32c2/ld/esp32c2.rom.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,15 @@ PROVIDE( esp_flash_chip_driver_initialized = 0x40000430 );
272272
PROVIDE( esp_flash_read_id = 0x40000434 );
273273
PROVIDE( esp_flash_get_size = 0x40000438 );
274274
PROVIDE( esp_flash_erase_chip = 0x4000043c );
275-
PROVIDE( esp_flash_erase_region = 0x40000440 );
275+
PROVIDE( rom_esp_flash_erase_region = 0x40000440 );
276276
PROVIDE( esp_flash_get_chip_write_protect = 0x40000444 );
277277
PROVIDE( esp_flash_set_chip_write_protect = 0x40000448 );
278278
PROVIDE( esp_flash_get_protectable_regions = 0x4000044c );
279279
PROVIDE( esp_flash_get_protected_region = 0x40000450 );
280280
PROVIDE( esp_flash_set_protected_region = 0x40000454 );
281281
PROVIDE( esp_flash_read = 0x40000458 );
282-
PROVIDE( esp_flash_write = 0x4000045c );
283-
PROVIDE( esp_flash_write_encrypted = 0x40000460 );
282+
PROVIDE( rom_esp_flash_write = 0x4000045c );
283+
PROVIDE( rom_esp_flash_write_encrypted = 0x40000460 );
284284
PROVIDE( esp_flash_read_encrypted = 0x40000464 );
285285
PROVIDE( esp_flash_get_io_mode = 0x40000468 );
286286
PROVIDE( esp_flash_set_io_mode = 0x4000046c );

components/esp_rom/esp32c3/ld/esp32c3.rom.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ PROVIDE( esp_flash_get_protectable_regions = 0x40000318 );
267267
PROVIDE( esp_flash_get_protected_region = 0x4000031c );
268268
PROVIDE( esp_flash_set_protected_region = 0x40000320 );
269269
PROVIDE( esp_flash_read = 0x40000324 );
270-
PROVIDE( esp_flash_write = 0x40000328 );
271-
PROVIDE( esp_flash_write_encrypted = 0x4000032c );
270+
PROVIDE( rom_esp_flash_write = 0x40000328 );
271+
PROVIDE( rom_esp_flash_write_encrypted = 0x4000032c );
272272
PROVIDE( esp_flash_read_encrypted = 0x40000330 );
273273
PROVIDE( esp_flash_get_io_mode = 0x40000334 );
274274
PROVIDE( esp_flash_set_io_mode = 0x40000338 );

components/esp_rom/esp32c5/ld/esp32c5.rom.spiflash.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ esp_flash_chip_driver_initialized = 0x40000240;
5151
esp_flash_read_id = 0x40000244;
5252
esp_flash_get_size = 0x40000248;
5353
esp_flash_erase_chip = 0x4000024c;
54-
esp_flash_erase_region = 0x40000250;
54+
rom_esp_flash_erase_region = 0x40000250;
5555
esp_flash_get_chip_write_protect = 0x40000254;
5656
esp_flash_set_chip_write_protect = 0x40000258;
5757
esp_flash_get_protectable_regions = 0x4000025c;
5858
esp_flash_get_protected_region = 0x40000260;
5959
esp_flash_set_protected_region = 0x40000264;
6060
esp_flash_read = 0x40000268;
61-
esp_flash_write = 0x4000026c;
62-
esp_flash_write_encrypted = 0x40000270;
61+
rom_esp_flash_write = 0x4000026c;
62+
rom_esp_flash_write_encrypted = 0x40000270;
6363
esp_flash_read_encrypted = 0x40000274;
6464
esp_flash_get_io_mode = 0x40000278;
6565
esp_flash_set_io_mode = 0x4000027c;

components/esp_rom/esp32c6/ld/esp32c6.rom.spiflash.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ esp_flash_chip_driver_initialized = 0x4000022c;
5050
esp_flash_read_id = 0x40000230;
5151
esp_flash_get_size = 0x40000234;
5252
esp_flash_erase_chip = 0x40000238;
53-
esp_flash_erase_region = 0x4000023c;
53+
rom_esp_flash_erase_region = 0x4000023c;
5454
esp_flash_get_chip_write_protect = 0x40000240;
5555
esp_flash_set_chip_write_protect = 0x40000244;
5656
esp_flash_get_protectable_regions = 0x40000248;
5757
esp_flash_get_protected_region = 0x4000024c;
5858
esp_flash_set_protected_region = 0x40000250;
5959
esp_flash_read = 0x40000254;
60-
esp_flash_write = 0x40000258;
61-
esp_flash_write_encrypted = 0x4000025c;
60+
rom_esp_flash_write = 0x40000258;
61+
rom_esp_flash_write_encrypted = 0x4000025c;
6262
esp_flash_read_encrypted = 0x40000260;
6363
esp_flash_get_io_mode = 0x40000264;
6464
esp_flash_set_io_mode = 0x40000268;

components/esp_rom/esp32c61/ld/esp32c61.rom.spiflash.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ esp_flash_chip_driver_initialized = 0x40000240;
5151
esp_flash_read_id = 0x40000244;
5252
esp_flash_get_size = 0x40000248;
5353
esp_flash_erase_chip = 0x4000024c;
54-
esp_flash_erase_region = 0x40000250;
54+
rom_esp_flash_erase_region = 0x40000250;
5555
esp_flash_get_chip_write_protect = 0x40000254;
5656
esp_flash_set_chip_write_protect = 0x40000258;
5757
esp_flash_get_protectable_regions = 0x4000025c;
5858
esp_flash_get_protected_region = 0x40000260;
5959
esp_flash_set_protected_region = 0x40000264;
6060
esp_flash_read = 0x40000268;
61-
esp_flash_write = 0x4000026c;
62-
esp_flash_write_encrypted = 0x40000270;
61+
rom_esp_flash_write = 0x4000026c;
62+
rom_esp_flash_write_encrypted = 0x40000270;
6363
esp_flash_read_encrypted = 0x40000274;
6464
esp_flash_get_io_mode = 0x40000278;
6565
esp_flash_set_io_mode = 0x4000027c;

components/esp_rom/esp32h2/ld/esp32h2.rom.spiflash.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ esp_flash_chip_driver_initialized = 0x40000224;
5050
esp_flash_read_id = 0x40000228;
5151
esp_flash_get_size = 0x4000022c;
5252
esp_flash_erase_chip = 0x40000230;
53-
esp_flash_erase_region = 0x40000234;
53+
rom_esp_flash_erase_region = 0x40000234;
5454
esp_flash_get_chip_write_protect = 0x40000238;
5555
esp_flash_set_chip_write_protect = 0x4000023c;
5656
esp_flash_get_protectable_regions = 0x40000240;
5757
esp_flash_get_protected_region = 0x40000244;
5858
esp_flash_set_protected_region = 0x40000248;
5959
esp_flash_read = 0x4000024c;
60-
esp_flash_write = 0x40000250;
61-
esp_flash_write_encrypted = 0x40000254;
60+
rom_esp_flash_write = 0x40000250;
61+
rom_esp_flash_write_encrypted = 0x40000254;
6262
esp_flash_read_encrypted = 0x40000258;
6363
esp_flash_get_io_mode = 0x4000025c;
6464
esp_flash_set_io_mode = 0x40000260;

components/esp_rom/esp32h21/ld/esp32h21.rom.spiflash.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ esp_flash_chip_driver_initialized = 0x40000224;
5151
esp_flash_read_id = 0x40000228;
5252
esp_flash_get_size = 0x4000022c;
5353
esp_flash_erase_chip = 0x40000230;
54-
esp_flash_erase_region = 0x40000234;
54+
rom_esp_flash_erase_region = 0x40000234;
5555
esp_flash_get_chip_write_protect = 0x40000238;
5656
esp_flash_set_chip_write_protect = 0x4000023c;
5757
esp_flash_get_protectable_regions = 0x40000240;
5858
esp_flash_get_protected_region = 0x40000244;
5959
esp_flash_set_protected_region = 0x40000248;
6060
esp_flash_read = 0x4000024c;
61-
esp_flash_write = 0x40000250;
62-
esp_flash_write_encrypted = 0x40000254;
61+
rom_esp_flash_write = 0x40000250;
62+
rom_esp_flash_write_encrypted = 0x40000254;
6363
esp_flash_read_encrypted = 0x40000258;
6464
esp_flash_get_io_mode = 0x4000025c;
6565
esp_flash_set_io_mode = 0x40000260;

components/esp_rom/esp32h4/ld/esp32h4.rom.spiflash.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ esp_flash_chip_driver_initialized = 0x4000020c;
3434
esp_flash_read_id = 0x40000210;
3535
esp_flash_get_size = 0x40000214;
3636
esp_flash_erase_chip = 0x40000218;
37-
esp_flash_erase_region = 0x4000021c;
37+
rom_esp_flash_erase_region = 0x4000021c;
3838
esp_flash_get_chip_write_protect = 0x40000220;
3939
esp_flash_set_chip_write_protect = 0x40000224;
4040
esp_flash_get_protectable_regions = 0x40000228;
4141
esp_flash_get_protected_region = 0x4000022c;
4242
esp_flash_set_protected_region = 0x40000230;
4343
esp_flash_read = 0x40000234;
44-
esp_flash_write = 0x40000238;
45-
esp_flash_write_encrypted = 0x4000023c;
44+
rom_esp_flash_write = 0x40000238;
45+
rom_esp_flash_write_encrypted = 0x4000023c;
4646
esp_flash_read_encrypted = 0x40000240;
4747
esp_flash_get_io_mode = 0x40000244;
4848
esp_flash_set_io_mode = 0x40000248;

components/esp_rom/esp32s3/ld/esp32s3.rom.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ PROVIDE( esp_flash_get_protectable_regions = 0x40001110 );
318318
PROVIDE( esp_flash_get_protected_region = 0x4000111c );
319319
PROVIDE( esp_flash_set_protected_region = 0x40001128 );
320320
PROVIDE( esp_flash_read = 0x40001134 );
321-
PROVIDE( esp_flash_write = 0x40001140 );
322-
PROVIDE( esp_flash_write_encrypted = 0x4000114c );
321+
PROVIDE( rom_esp_flash_write = 0x40001140 );
322+
PROVIDE( rom_esp_flash_write_encrypted = 0x4000114c );
323323
PROVIDE( esp_flash_read_encrypted = 0x40001158 );
324324
PROVIDE( esp_flash_get_io_mode = 0x40001164 );
325325
PROVIDE( esp_flash_set_io_mode = 0x40001170 );

components/spi_flash/esp_flash_api.c

Lines changed: 95 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,6 @@ esp_err_t esp_flash_get_physical_size(esp_flash_t *chip, uint32_t *flash_size)
557557

558558
#ifndef CONFIG_SPI_FLASH_ROM_IMPL
559559

560-
/* Return true if regions 'a' and 'b' overlap at all, based on their start offsets and lengths. */
561-
inline static IRAM_ATTR bool regions_overlap(uint32_t a_start, uint32_t a_len,uint32_t b_start, uint32_t b_len);
562-
563560
esp_err_t esp_flash_get_size(esp_flash_t *chip, uint32_t *out_size)
564561
{
565562
esp_err_t err = rom_spiflash_api_funcs->chip_check(&chip);
@@ -590,7 +587,21 @@ esp_err_t esp_flash_erase_chip(esp_flash_t *chip)
590587
err = esp_flash_erase_region(chip, 0, size);
591588
return err;
592589
}
590+
#endif // !CONFIG_SPI_FLASH_ROM_IMPL
591+
592+
#ifndef CONFIG_SPI_FLASH_ROM_IMPL
593+
inline static IRAM_ATTR bool regions_overlap(uint32_t a_start, uint32_t a_len,uint32_t b_start, uint32_t b_len)
594+
{
595+
uint32_t a_end = a_start + a_len;
596+
uint32_t b_end = b_start + b_len;
597+
return (a_end > b_start && b_end > a_start);
598+
}
593599

600+
/* ROM and patch information
601+
* Latest: Fixed region check escape
602+
* V2: Fixed size == 0 bug.
603+
* V1 (ESP_ROM_HAS_ERASE_0_REGION_BUG): Added to ROM
604+
*/
594605
esp_err_t esp_flash_erase_region(esp_flash_t *chip, uint32_t start, uint32_t len)
595606
{
596607
esp_err_t err = rom_spiflash_api_funcs->chip_check(&chip);
@@ -606,7 +617,7 @@ esp_err_t esp_flash_erase_region(esp_flash_t *chip, uint32_t start, uint32_t len
606617
if (sector_size == 0 || (block_erase_size % sector_size) != 0) {
607618
return ESP_ERR_FLASH_NOT_INITIALISED;
608619
}
609-
if (start > chip->size || start + len > chip->size) {
620+
if (start > chip->size || len > chip->size - start) {
610621
return ESP_ERR_INVALID_ARG;
611622
}
612623
if ((start % chip->chip_drv->sector_size) != 0 || (len % chip->chip_drv->sector_size) != 0) {
@@ -701,26 +712,45 @@ esp_err_t esp_flash_erase_region(esp_flash_t *chip, uint32_t start, uint32_t len
701712

702713
return rom_spiflash_api_funcs->flash_end_flush_cache(chip, err, bus_acquired, start, len);
703714
}
704-
705-
#endif // !CONFIG_SPI_FLASH_ROM_IMPL
706-
707-
#if defined(CONFIG_SPI_FLASH_ROM_IMPL) && ESP_ROM_HAS_ERASE_0_REGION_BUG
708-
709-
/* ROM esp_flash_erase_region implementation doesn't handle 0 erase size correctly.
715+
#else //!CONFIG_SPI_FLASH_ROM_IMPL
716+
extern esp_err_t rom_esp_flash_erase_region(esp_flash_t *chip, uint32_t start, uint32_t len);
717+
# if ESP_ROM_HAS_ERASE_0_REGION_BUG
718+
// Usel ROM impl v1 but workaround ESP_ROM_HAS_ERASE_0_REGION_BUG and region check escape.
719+
/* ROM V1 esp_flash_erase_region implementation doesn't handle 0 erase size correctly.
710720
* Check the size and call ROM function instead of overriding it completely.
711-
* The behavior is slightly different from esp_flash_erase_region above, thought:
721+
* The behavior is slightly different from latest esp_flash_erase_region above, thought:
712722
* here the check for 0 size is done first, but in esp_flash_erase_region the check is
713723
* done after the other arguments are checked.
714724
*/
715-
extern esp_err_t rom_esp_flash_erase_region(esp_flash_t *chip, uint32_t start, uint32_t len);
716725
esp_err_t esp_flash_erase_region(esp_flash_t *chip, uint32_t start, uint32_t len)
717726
{
727+
esp_err_t err = rom_spiflash_api_funcs->chip_check(&chip);
728+
if (err != ESP_OK) {
729+
return err;
730+
}
718731
if (len == 0) {
719732
return ESP_OK;
720733
}
734+
if (len > chip->size - start) {
735+
return ESP_ERR_INVALID_ARG;
736+
}
737+
return rom_esp_flash_erase_region(chip, start, len);
738+
}
739+
# else
740+
// Usel ROM impl v2 but workaround region check escape.
741+
esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, uint32_t len)
742+
{
743+
esp_err_t err = rom_spiflash_api_funcs->chip_check(&chip);
744+
if (err != ESP_OK) {
745+
return err;
746+
}
747+
if (len > chip->size - start) {
748+
return ESP_ERR_INVALID_ARG;
749+
}
721750
return rom_esp_flash_erase_region(chip, start, len);
722751
}
723-
#endif // defined(CONFIG_SPI_FLASH_ROM_IMPL) && ESP_ROM_HAS_ERASE_0_REGION_BUG
752+
# endif // ESP_ROM_HAS_ERASE_0_REGION_BUG
753+
#endif // !CONFIG_SPI_FLASH_ROM_IMPL
724754

725755
#ifndef CONFIG_SPI_FLASH_ROM_IMPL
726756

@@ -925,7 +955,10 @@ esp_err_t esp_flash_read(esp_flash_t *chip, void *buffer, uint32_t address, uint
925955
COUNTER_STOP(read);
926956
return err;
927957
}
958+
#endif //!CONFIG_SPI_FLASH_ROM_IMPL
928959

960+
#ifndef CONFIG_SPI_FLASH_ROM_IMPL
961+
//This checking is available only when !CONFIG_SPI_FLASH_ROM_IMPL
929962
#if CONFIG_SPI_FLASH_WARN_SETTING_ZERO_TO_ONE
930963
static esp_err_t s_check_setting_zero_to_one(esp_flash_t *chip, uint32_t verify_address, uint32_t remain_verify_len, const uint32_t *to_write_buf, bool is_encrypted)
931964
{
@@ -965,6 +998,7 @@ static esp_err_t s_check_setting_zero_to_one(esp_flash_t *chip, uint32_t verify_
965998
}
966999
#endif //#if CONFIG_SPI_FLASH_WARN_SETTING_ZERO_TO_ONE
9671000

1001+
//This checking is available only when !CONFIG_SPI_FLASH_ROM_IMPL
9681002
#if CONFIG_SPI_FLASH_VERIFY_WRITE
9691003
static esp_err_t s_verify_write(esp_flash_t *chip, uint32_t verify_address, uint32_t remain_verify_len, const uint32_t *expected_buf, bool is_encrypted)
9701004
{
@@ -1003,6 +1037,13 @@ static esp_err_t s_verify_write(esp_flash_t *chip, uint32_t verify_address, uint
10031037
}
10041038
#endif //#if CONFIG_SPI_FLASH_VERIFY_WRITE
10051039

1040+
/* ROM and patch information
1041+
* Latest:
1042+
- Provide debugging utils (CONFIG_SPI_FLASH_WARN_SETTING_ZERO_TO_ONE, CONFIG_SPI_FLASH_VERIFY_WRITE)
1043+
- Fixed region check escape
1044+
* V1: added to ROM
1045+
*/
1046+
//When use the ROM impl, can't use these debugging utils.
10061047
esp_err_t esp_flash_write(esp_flash_t *chip, const void *buffer, uint32_t address, uint32_t length)
10071048
{
10081049
esp_err_t ret = ESP_FAIL;
@@ -1014,7 +1055,7 @@ esp_err_t esp_flash_write(esp_flash_t *chip, const void *buffer, uint32_t addres
10141055
esp_err_t err = rom_spiflash_api_funcs->chip_check(&chip);
10151056
VERIFY_CHIP_OP(write);
10161057
CHECK_WRITE_ADDRESS(chip, address, length);
1017-
if (buffer == NULL || address > chip->size || address+length > chip->size) {
1058+
if (buffer == NULL || address > chip->size || length > chip->size - address) {
10181059
return ESP_ERR_INVALID_ARG;
10191060
}
10201061
if (length == 0) {
@@ -1124,14 +1165,23 @@ esp_err_t esp_flash_write(esp_flash_t *chip, const void *buffer, uint32_t addres
11241165

11251166
return err;
11261167
}
1127-
1128-
inline static bool regions_overlap(uint32_t a_start, uint32_t a_len,uint32_t b_start, uint32_t b_len)
1168+
#else
1169+
extern esp_err_t rom_esp_flash_write(esp_flash_t *chip, const void *buffer, uint32_t address, uint32_t length);
1170+
// Usel ROM impl v1 but workaround region check escape.
1171+
esp_err_t IRAM_ATTR esp_flash_write(esp_flash_t *chip, const void *buffer, uint32_t address, uint32_t length)
11291172
{
1130-
uint32_t a_end = a_start + a_len;
1131-
uint32_t b_end = b_start + b_len;
1132-
return (a_end > b_start && b_end > a_start);
1173+
esp_err_t err = rom_spiflash_api_funcs->chip_check(&chip);
1174+
if (err != ESP_OK) {
1175+
return err;
1176+
}
1177+
if (length > chip->size - address) {
1178+
return ESP_ERR_INVALID_ARG;
1179+
}
1180+
return rom_esp_flash_write(chip, buffer, address, length);
11331181
}
1182+
#endif //!CONFIG_SPI_FLASH_ROM_IMPL
11341183

1184+
#ifndef CONFIG_SPI_FLASH_ROM_IMPL
11351185
esp_err_t esp_flash_read_encrypted(esp_flash_t *chip, uint32_t address, void *out_buffer, uint32_t length)
11361186
{
11371187
esp_err_t err = rom_spiflash_api_funcs->chip_check(&chip);
@@ -1198,9 +1248,8 @@ esp_err_t esp_flash_set_io_mode(esp_flash_t* chip, bool qe)
11981248
}
11991249
#endif //CONFIG_SPI_FLASH_ROM_IMPL
12001250

1201-
#if !CONFIG_SPI_FLASH_ROM_IMPL || ESP_ROM_HAS_ENCRYPTED_WRITES_USING_LEGACY_DRV
1202-
// use `esp_flash_write_encrypted` ROM version not in C3 and S3
1203-
1251+
#if !(CONFIG_SPI_FLASH_ROM_IMPL && !ESP_ROM_HAS_ENCRYPTED_WRITES_USING_LEGACY_DRV)
1252+
// use `esp_flash_write_encrypted` ROM version on chips later than C3 and S3
12041253
FORCE_INLINE_ATTR esp_err_t s_encryption_write_lock(esp_flash_t *chip) {
12051254
#if CONFIG_IDF_TARGET_ESP32S2
12061255
esp_crypto_dma_lock_acquire();
@@ -1216,6 +1265,14 @@ FORCE_INLINE_ATTR esp_err_t s_encryption_write_unlock(esp_flash_t *chip) {
12161265
return err;
12171266
}
12181267

1268+
/* ROM and patch information
1269+
* Latest:
1270+
- Provide debugging utils (CONFIG_SPI_FLASH_WARN_SETTING_ZERO_TO_ONE, CONFIG_SPI_FLASH_VERIFY_WRITE)
1271+
- Fixed region check escape
1272+
* V2: Bug fixed
1273+
* V1 (ESP_ROM_HAS_ENCRYPTED_WRITES_USING_LEGACY_DRV): added to ROM but has bug
1274+
*/
1275+
//When use the ROM impl, can't use these debugging utils.
12191276
esp_err_t esp_flash_write_encrypted(esp_flash_t *chip, uint32_t address, const void *buffer, uint32_t length)
12201277
{
12211278
esp_err_t ret = ESP_FAIL;
@@ -1232,7 +1289,7 @@ esp_err_t esp_flash_write_encrypted(esp_flash_t *chip, uint32_t address, const v
12321289
}
12331290
CHECK_WRITE_ADDRESS(chip, address, length);
12341291

1235-
if (buffer == NULL || address + length > chip->size) {
1292+
if (buffer == NULL || address > chip->size || length > chip->size - address) {
12361293
return ESP_ERR_INVALID_ARG;
12371294
}
12381295

@@ -1435,8 +1492,21 @@ esp_err_t esp_flash_write_encrypted(esp_flash_t *chip, uint32_t address, const v
14351492

14361493
return err;
14371494
}
1438-
1439-
#endif // !CONFIG_SPI_FLASH_ROM_IMPL || ESP_ROM_HAS_ENCRYPTED_WRITES_USING_LEGACY_DRV
1495+
#else
1496+
extern esp_err_t rom_esp_flash_write_encrypted(esp_flash_t *chip, uint32_t address, const void *buffer, uint32_t length);
1497+
// Usel ROM impl v2 but workaround region check escape.
1498+
esp_err_t IRAM_ATTR esp_flash_write_encrypted(esp_flash_t *chip, uint32_t address, const void *buffer, uint32_t length)
1499+
{
1500+
esp_err_t err = rom_spiflash_api_funcs->chip_check(&chip);
1501+
if (err != ESP_OK) {
1502+
return err;
1503+
}
1504+
if (length > chip->size - address) {
1505+
return ESP_ERR_INVALID_ARG;
1506+
}
1507+
return rom_esp_flash_write_encrypted(chip, address, buffer, length);
1508+
}
1509+
#endif // !(CONFIG_SPI_FLASH_ROM_IMPL && !ESP_ROM_HAS_ENCRYPTED_WRITES_USING_LEGACY_DRV)
14401510

14411511
//init suspend mode cmd, uses internal.
14421512
esp_err_t esp_flash_suspend_cmd_init(esp_flash_t* chip)

0 commit comments

Comments
 (0)