From ac2d88912df833f31337458508397a20c95c4ab3 Mon Sep 17 00:00:00 2001 From: Cao Sen Miao Date: Mon, 11 Mar 2024 15:18:33 +0800 Subject: [PATCH] fix(spi_flash): Fix MXIC chip flash size detected wrong, Closes https://github.com/espressif/esp-idf/issues/12222 --- components/spi_flash/spi_flash_chip_mxic.c | 40 ++++++++++++------- .../sdkconfig.ci.release_f8r8 | 1 + tools/ci/check_copyright_ignore.txt | 1 - 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/components/spi_flash/spi_flash_chip_mxic.c b/components/spi_flash/spi_flash_chip_mxic.c index fef8f99f19..089e08cff8 100644 --- a/components/spi_flash/spi_flash_chip_mxic.c +++ b/components/spi_flash/spi_flash_chip_mxic.c @@ -1,16 +1,8 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include "spi_flash_chip_generic.h" @@ -35,6 +27,26 @@ esp_err_t spi_flash_chip_mxic_probe(esp_flash_t *chip, uint32_t flash_id) return ESP_OK; } +esp_err_t spi_flash_chip_mxic_detect_size(esp_flash_t *chip, uint32_t *size) +{ + uint32_t id = chip->chip_id; + *size = 0; + + /* Can't detect size unless the high byte of the product ID matches the same convention, which is usually 0x40 or + * 0xC0 or similar. */ + if (((id & 0xFFFF) == 0x0000) || ((id & 0xFFFF) == 0xFFFF)) { + return ESP_ERR_FLASH_UNSUPPORTED_CHIP; + } + + uint32_t mem_density = (id & 0xFF); + if (mem_density > 0x30) { // For OPI chips + mem_density -= 0x20; + } + + *size = (mem_density <= 31) ? (1U << mem_density) : 0; + return ESP_OK; +} + esp_err_t spi_flash_chip_issi_set_io_mode(esp_flash_t *chip); esp_err_t spi_flash_chip_issi_get_io_mode(esp_flash_t *chip, esp_flash_io_mode_t* out_io_mode); @@ -61,7 +73,7 @@ const spi_flash_chip_t esp_flash_chip_mxic = { .timeout = &spi_flash_chip_generic_timeout, .probe = spi_flash_chip_mxic_probe, .reset = spi_flash_chip_generic_reset, - .detect_size = spi_flash_chip_generic_detect_size, + .detect_size = spi_flash_chip_mxic_detect_size, .erase_chip = spi_flash_chip_generic_erase_chip, .erase_sector = spi_flash_chip_generic_erase_sector, .erase_block = spi_flash_chip_generic_erase_block, diff --git a/components/spi_flash/test_apps/flash_encryption/sdkconfig.ci.release_f8r8 b/components/spi_flash/test_apps/flash_encryption/sdkconfig.ci.release_f8r8 index 840771961e..b31f5907ca 100644 --- a/components/spi_flash/test_apps/flash_encryption/sdkconfig.ci.release_f8r8 +++ b/components/spi_flash/test_apps/flash_encryption/sdkconfig.ci.release_f8r8 @@ -16,4 +16,5 @@ CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE=y CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED=y CONFIG_SPIRAM_MODE_OCT=y CONFIG_SPIRAM_TYPE_AUTO=y +CONFIG_ESPTOOLPY_OCT_FLASH=y CONFIG_ESPTOOLPY_FLASHMODE_OPI=y diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 8cabaeb70f..53bd690747 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -792,7 +792,6 @@ components/spi_flash/include/spi_flash_chip_mxic.h components/spi_flash/include/spi_flash_chip_winbond.h components/spi_flash/spi_flash_chip_boya.c components/spi_flash/spi_flash_chip_issi.c -components/spi_flash/spi_flash_chip_mxic.c components/tcp_transport/include/esp_transport_ws.h components/unity/include/priv/setjmp.h components/unity/include/unity_config.h