Commit Graph

288 Commits

Author SHA1 Message Date
Cao Sen Miao
dda13f88ea spi_flash: move the unlock patch to bootloader and add support for GD 2022-10-17 19:15:25 +08:00
Michael (XIAO Xufeng)
bab633cf9e bootloader: add xmc spi_flash startup flow to improve reliability 2022-10-17 19:15:25 +08:00
Michael (XIAO Xufeng)
d2f9113d14 bootloader: fix the WRSR format for ISSI flash chips
1. The 2nd bootloader always call `rom_spiflash_unlock()`, but never help to clear the WEL bit when exit. This may cause system unstability.

   This commit helps to clear WEL when flash configuration is done.

   **RISK:** When the app starts, it didn't have to clear the WEL before it actually write/erase. But now the very first write/erase operation should be done after a WEL clear. Though the risk is little (all the following write/erase also need to clear the WEL), we still have to test this carefully, especially for those functions used by the OTA.

2. The `rom_spiflash_unlock()` function in the patch of ESP32 may (1) trigger the QPI, (2) clear the QE or (3) fail to unlock the ISSI chips.

   Status register bitmap of ISSI chip and GD chip:

| SR | ISSI | GD25LQ32C |
| -- | ---- | --------- |
| 0  | WIP  | WIP       |
| 1  | WEL  | WEL       |
| 2  | BP0  | BP0       |
| 3  | BP1  | BP1       |
| 4  | BP2  | BP2       |
| 5  | BP3  | BP3       |
| 6  | QE   | BP4       |
| 7  | SRWD | SRP0      |
| 8  |      | SRP1      |
| 9  |      | QE        |
| 10 |      | SUS2      |
| 11 |      | LB1       |
| 12 |      | LB2       |
| 13 |      | LB3       |
| 14 |      | CMP       |
| 15 |      | SUS1      |

   QE bit of other chips are at the bit 9 of the status register (i.e. bit 1 of SR2), which should be read by RDSR2 command.

   However, the RDSR2 (35H, Read Status 2) command for chip of other vendors happens to be the QIOEN (Enter QPI mode) command of ISSI chips. When the `rom_spiflash_unlock()` function trys to read SR2, it may trigger the QPI of ISSI chips.

   Moreover, when `rom_spiflash_unlock()` try to clear the BP4 bit in the status register, QE (bit 6) of ISSI chip may be cleared by accident. Or if the ISSI chip doesn't accept WRSR command with argument of two bytes (since it only have status register of one byte), it may fail to clear the other protect bits (BP0~BP3) as expected.

   This commit makes the `rom_spiflash_unlock()` check whether the vendor is issi. if so, `rom_spiflash_unlock()` only send RDSR to read the status register, send WRSR with only 1 byte argument, and also avoid clearing the QE bit (bit 6).

3. `rom_spiflash_unlock()` always send WRSR command to clear protection bits even when there is no protection bit active. And the execution of clearing status registers, which takes about 700us, will also happen even when there's no bits cleared.

   This commit skips the clearing of status register if there is no protection bits active.

Also move the execute_flash_command to be a bootloader API; move
implementation of spi_flash_wrap_set to the bootloader
2022-10-17 19:15:25 +08:00
Michael (XIAO Xufeng)
61989e0fbb spi_flash: partially move API functions out of IRAM 2022-10-17 19:15:24 +08:00
Michael (XIAO Xufeng)
4957ddf61d mmap: fixed the issue mmap cannot be called with pointers to psram 2022-04-06 17:24:01 +08:00
Michael (XIAO Xufeng)
b183ef2586 esp_flash: fix write issue using buffer on stack out of lifetime 2022-02-20 03:25:37 +08:00
Michael (XIAO Xufeng)
9bc21c4906 spi_flash_test: remove threshold from unit test 2022-01-18 16:34:19 +08:00
KonstantinKondrashov
a86117223b partition_table: Fix case when a few similar to otadata partitions in the table
It was when in the partition table there is a partition with type="data" and suptype=""(empty),
in this case type=1, suptype=0. It is similar to otadata partition.

This commit fixes it, now it will handle it as type=1, suptype=6 (ESP_PARTITION_SUBTYPE_DATA_UNDEFINED).
2021-10-26 16:49:26 +08:00
Angus Gratton
8d1a99e026 paritition_table: Verify the partition table md5sum when loading the app
Additionally, always enable the partition MD5 check if flash encryption is on in
Release mode. This ensures the partition table ciphertext has not been modified
(CVE-2021-27926).

The exception is pre-V3.1 ESP-IDF bootloaders and partition tables, which
don't have support for the MD5 entry.
2021-06-02 16:31:19 +10:00
wuzhenghui
dcd6e82826 remove othercore cache disable 2021-04-27 14:37:45 +08:00
Cao Sen Miao
2333667cb5 ota: fix ota with flash encryption 2021-03-12 16:44:06 +08:00
Cao Sen Miao
63e4510e9e flash_encryption: Quick fixed the issue that block when flash_encryption_write, Related https://github.com/espressif/esp-idf/issues/6322, Related https://github.com/espressif/esp-idf/issues/6254 2021-03-11 14:11:01 +08:00
Michael (XIAO Xufeng)
f6da7f3305 spi_flash: add config option to override flash size in bootloader header
Sometimes the flash size read from bootloader is not correct. This may
forbid SPI Flash driver from reading the the area larger than the size
in bootloader header.

When the new config option is enabled, the latest configured
ESPTOOLPY_FLAHSIZE in the app header will be used to override the value
read from bootloader header.
2021-02-23 01:23:53 +08:00
Mahavir Jain
e032384c7f spi_flash: add config option to enable encrypted partition read/write
This feature can be disabled to save some IRAM (approx 1KB) for cases
where flash encryption feature is not required.
2021-02-02 05:10:34 +00:00
Mahavir Jain
0715c86211 Revert "esp_partition: disable encrypted reads/writes if flash encryption is disabled"
This reverts commit bf35ef1ce7.

It has been noticed that there are scenarios where even though firmware is not enabled
with flash encryption config feature, it should be able to write to encrypted partitions.

This revert adds the feature back which was removed around v4.0 timelines, and same
change will be backported to all releases (upto v4.0) for consistency.
2021-02-02 05:10:34 +00:00
Li Shuai
ab63824600 added psram stack check in backtrace 2020-11-20 07:13:11 +00:00
Ivan Grokhotkov
37fb85b998 Merge branch 'bugfix/spi_flash_yield_coredump_v4.1' into 'release/v4.1'
spi_flash: don't call vTaskDelay in non-os context (v4.1)

See merge request espressif/esp-idf!10298
2020-10-03 14:52:55 +08:00
jiangguangming
387905a4ad flash_mmap: restore interrupt and cache before err return 2020-09-24 09:59:06 +08:00
jiangguangming
0ff3ceba32 flash_mmap: can mmap after get enough free MMU pages 2020-09-24 09:59:06 +08:00
Ivan Grokhotkov
e348a291ad spi_flash: don't call vTaskDelay in non-os context
Fixes regression in core dump, when a crash happens in interrupt
context.
2020-09-18 15:34:32 +00:00
Angus Gratton
9b7dca3769 Merge branch 'bugfix/bootloader_common_get_sha256_of_partition_v4.1' into 'release/v4.1'
bootloader_support: Fix bootloader_common_get_sha256_of_partition(), can handle a long image (v4.1)

See merge request espressif/esp-idf!9953
2020-08-24 13:37:27 +08:00
Michael (XIAO Xufeng)
d8061fa8d9 Merge branch 'bugfix/esp_flash_revert_qe_clear_4.1' into 'release/v4.1'
esp_flash: fix the regression of non-quad mode by default chip driver, bugs in add_device and deprecate cs_id (4.1)

See merge request espressif/esp-idf!8836
2020-08-20 19:11:00 +08:00
Michael (XIAO Xufeng)
6e148c0051 Merge branch 'bugfix/esp_flash_write_performance_regression_4.1' into 'release/v4.1'
esp_flash: fix the write performance regression (Backport v4.1)

See merge request espressif/esp-idf!8800
2020-08-20 19:09:59 +08:00
KonstantinKondrashov
55fafa887c bootloader_support: Fix bootloader_common_get_sha256_of_partition, can handle a long image
Closes: IDFGH-3594
2020-08-05 22:09:15 +08:00
Mahavir Jain
56accfe4c4 spi_flash: esp32: fix regression in encrypted flash write
In commit 309376f51a, it seems like regression
was added to use ROM level API for disabling flash write protection. This
started random firmware crashes (on specific modules) with exception
`IllegalInstruction` during encrypted flash writes.

Fix here removes relevant ROM API call, since disabling flash write protection
is already ensured by caller of this API.

Closes https://github.com/espressif/esp-idf/issues/5467
2020-06-29 14:51:58 +05:30
Angus Gratton
7ab2ffb45f spi_flash: Use per-chip flash_ops files for legacy API
Looks like when ESP32-S2 Beta support was merged, the separate files
were dropped by accident.
2020-06-29 14:49:28 +05:30
Armando
75dd9835f6 esp_flash: fix cache exception when CS pin is through IOMUX 2020-06-01 15:29:30 +08:00
Armando
bda0c84552 esp_flash: fix the cleanup when add device fails 2020-06-01 15:29:30 +08:00
Armando
eacefba1c6 esp_flash: fix the regression of non-quad mode by default chip driver 2020-06-01 15:29:30 +08:00
Michael (XIAO Xufeng)
6f410cb7c4 spi_flash: add unit test for read/write performance 2020-05-27 15:09:49 +08:00
Michael (XIAO Xufeng)
8df1369d0a esp_flash: fix the write performance regression
Also changed internal delay unit into microsecond.
2020-05-27 15:09:49 +08:00
KonstantinKondrashov
4214179de1 spi_flash(new driver): Add a Kconfig option - Bypass a block erase and always do sector erase
Closes: IDF-1561
2020-05-04 17:16:33 +08:00
KonstantinKondrashov
5c98ff015e spi_flash(LEGACY_IMPL): Add a Kconfig option - Bypass a block erase and always do sector erase
Closes: IDF-1561
2020-05-04 17:16:33 +08:00
KonstantinKondrashov
b56c7d9066 spi_flash: Add into sim/stubs the esp_timer 2020-05-04 17:16:33 +08:00
KonstantinKondrashov
d67e764ef6 spi_flash(new driver): Add vTaskDelay while a long erasing 2020-05-04 17:16:33 +08:00
KonstantinKondrashov
1554fd3d8a spi_flash(LEGACY_IMPL): Add vTaskDelay while a long erasing
Added Kconfig options to enable yield operation during flash erase

Closes: https://github.com/espressif/esp-idf/issues/2083
Closes: https://github.com/espressif/esp-idf/issues/4916
Closes: IDFGH-261
2020-05-04 15:48:22 +08:00
Angus Gratton
425486223e spi_flash: Remove 16KB free internal heap limit for esp_flash_read() into PSRAM
Allocation of the temporary internal buffer will now repeat until a small enough buffer can be
allocated, and only fail if less than a 256 byte block of internal RAM is free.

Adds unit test for the same, and generic test utility for creating memory pressure.
2020-03-05 17:10:22 +11:00
Angus Gratton
d6026823fa spi_flash: Fix over-allocation and OOM crash when reading from SPI flash to PSRAM buffers
Previously would try allocate buffer of minimum size 16KB not maximum size 16KB, causing
out of memory errors for any large reads, or if less than 16KB contiguous free heap.

Also, if using legacy API and internal allocation failed then implementation would abort()
instead of returning the error to the caller.

Added test for using large buffers in PSRAM.

Closes https://github.com/espressif/esp-idf/issues/4769

Also reported on forum: https://esp32.com/viewtopic.php?f=13&t=14304&p=55972
2020-03-05 17:10:22 +11:00
Renz Christian Bagaporo
fb1dec37d8 spi_flash: reenable mmap tests on esp32s2beta 2020-01-10 16:17:01 +11:00
michael
4220752aed ut: Move tests back from "esp32" subfolder
DISABLED_FOR_TARGETS macros are used

Partly revert "ci: disable unavailable tests for esp32s2beta"

This partly reverts commit 76a3a5fb48.

Partly revert "ci: disable UTs for esp32s2beta without runners"

This partly reverts commit eb158e9a22.

Partly revert "fix unit test and examples for s2beta"

This partly reverts commit 9baa7826be.

Partly revert "efuse: Add support for esp32s2beta"

This partly reverts commit db84ba868c.
2020-01-06 17:13:53 +08:00
Angus Gratton
5139934767 bootloader_common: Fix esp_partition_get_sha256(), add unit tests
Regression in 438d513a95

Reported here: https://esp32.com/viewtopic.php?f=13&t=13250&p=52460
2019-12-30 13:47:47 +11:00
Michael (XIAO Xufeng)
2ffe0aca12 esp_flash: increase the timeout for block erase 2019-12-24 16:50:09 +08:00
Renz Christian Bagaporo
e6ad330018 ble_mesh_wifi_coexist example: Disable Wi-Fi RX IRAM optimisation
Otherwise IRAM usage is too high in this example.
2019-11-28 09:20:00 +08:00
chenjianqiang
9f9da9ec96 feat(timer): refator timer group driver
1. add hal and low-level layer for timer group
2. add callback functions to handle interrupt
3. add timer deinit function
4. add timer spinlock take function
2019-11-21 14:14:19 +08:00
Ivan Grokhotkov
a74988ae3b Merge branch 'bugfix/cpp_extern' into 'master'
Add extern C header guards to some files

Closes IDFGH-2025 and IDFGH-2093

See merge request espressif/esp-idf!6611
2019-11-19 19:01:29 +08:00
wanglei
5e55ffc95a fix dummy issue in spi mem and make some spiflash api called from idf 2019-11-15 15:59:07 +00:00
wanglei
8bea8dacbc esp32s2beta: fix some macro and add flash wrap size condition 2019-11-15 15:59:07 +00:00
Gabriel Durante
5f0d257240 Added Cpp compatibility for components/spi_flash/include/esp_flash_spi_init.h
Merges https://github.com/espressif/esp-idf/pull/4260
2019-11-05 14:52:57 +01:00
Michael (XIAO Xufeng)
2660cb82ae spi_flash: support to verify written encrypted data
Also add unit test for encrypted_read
2019-10-30 05:49:50 +00:00
Angus Gratton
36cd75d7ed spi_flash tests: Fix exclusion of new API tests in legacy mode 2019-10-28 18:58:05 +11:00