Merge branch 'bugfix/bootloader_oversize_after_xmc' into 'release/v3.3'

bootloader: disable XMC startup flow by default to reduce bootloader size

See merge request espressif/esp-idf!16683
This commit is contained in:
Jiang Jiang Jian 2022-01-21 06:33:31 +00:00
commit 56f6378727
3 changed files with 22 additions and 41 deletions

View File

@ -233,14 +233,15 @@ menu "Bootloader config"
It allow to test anti-rollback implemention without permanent write eFuse bits.
In partition table should be exist this partition `emul_efuse, data, 5, , 0x2000`.
config BOOTLOADER_FLASH_XMC_SUPPORT
config BOOTLOADER_FLASH_XMC_SUPPORT_ENA
bool "Enable the support for flash chips of XMC (READ HELP FIRST)"
default y
default n
help
Perform the startup flow recommended by XMC. Please consult XMC for the details of this flow.
XMC chips will be forbidden to be used, when this option is disabled.
DON'T DISABLE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
Due to the limitation of Flash size, this flow is disabled by default on IDF v3.3. You may need to disable
some bootloader features to enable it.
endmenu # Bootloader

View File

@ -146,12 +146,14 @@ static esp_err_t bootloader_main()
bootloader_clock_configure();
uart_console_configure();
#if CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT_ENA
/* Check and run XMC startup flow. The function depends on the clock and console, so it's run right after these stuff
* are initialized. */
if (bootloader_flash_xmc_startup() != ESP_OK) {
ESP_LOGE(TAG, "failed when running XMC startup flow, reboot!");
return ESP_FAIL;
}
#endif
wdt_reset_check();
ESP_LOGI(TAG, "ESP-IDF %s 2nd stage bootloader", IDF_VER);

View File

@ -264,8 +264,6 @@ IRAM_ATTR static uint32_t bootloader_flash_execute_command_common(
uint8_t mosi_len, uint32_t mosi_data,
uint8_t miso_len)
{
assert(mosi_len <= 32);
assert(miso_len <= 32);
uint32_t old_ctrl_reg = SPIFLASH.ctrl.val;
uint32_t old_user_reg = SPIFLASH.user.val;
uint32_t old_user1_reg = SPIFLASH.user1.val;
@ -320,26 +318,11 @@ static uint32_t IRAM_ATTR execute_flash_command(uint8_t command, uint32_t mosi_d
dummy_len, mosi_len, mosi_data, miso_len);
}
// cmd(0x5A) + 24bit address + 8 cycles dummy
uint32_t IRAM_ATTR bootloader_flash_read_sfdp(uint32_t sfdp_addr, unsigned int miso_byte_num)
{
assert(miso_byte_num <= 4);
const uint8_t command = CMD_RDSFDP;
const uint8_t addr_len = 24;
const uint8_t dummy_len = 8;
const uint8_t mosi_len = 0;
const uint32_t mosi_data = 0;
const uint8_t miso_len = miso_byte_num * 8;
return bootloader_flash_execute_command_common(command, addr_len, sfdp_addr,
dummy_len, mosi_len, mosi_data, miso_len);
}
/*******************************************************************************
* XMC startup flow
******************************************************************************/
#define XMC_SUPPORT CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT
#define XMC_SUPPORT CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT_ENA
#define XMC_VENDOR_ID 0x20
#if BOOTLOADER_BUILD
@ -360,7 +343,21 @@ uint32_t IRAM_ATTR bootloader_flash_read_sfdp(uint32_t sfdp_addr, unsigned int m
#endif
#if XMC_SUPPORT
#if XMC_SUPPORT || !BOOTLOADER_BUILD
// cmd(0x5A) + 24bit address + 8 cycles dummy
uint32_t IRAM_ATTR bootloader_flash_read_sfdp(uint32_t sfdp_addr, unsigned int miso_byte_num)
{
const uint8_t command = CMD_RDSFDP;
const uint8_t addr_len = 24;
const uint8_t dummy_len = 8;
const uint8_t mosi_len = 0;
const uint32_t mosi_data = 0;
const uint8_t miso_len = miso_byte_num * 8;
return bootloader_flash_execute_command_common(command, addr_len, sfdp_addr,
dummy_len, mosi_len, mosi_data, miso_len);
}
//strictly check the model
static IRAM_ATTR bool is_xmc_chip_strict(uint32_t rdid)
{
@ -421,29 +418,10 @@ esp_err_t IRAM_ATTR bootloader_flash_xmc_startup(void)
// Read flash ID and check again
g_rom_flashchip.device_id = bootloader_read_flash_id();
if (!is_xmc_chip_strict(g_rom_flashchip.device_id)) {
BOOTLOADER_FLASH_LOG(E, "XMC flash startup fail");
return ESP_FAIL;
}
return ESP_OK;
}
#else
//only compare the vendor id
static IRAM_ATTR bool is_xmc_chip(uint32_t rdid)
{
uint32_t vendor_id = (rdid >> 16) & 0xFF;
return (vendor_id == XMC_VENDOR_ID);
}
esp_err_t IRAM_ATTR bootloader_flash_xmc_startup(void)
{
if (is_xmc_chip(g_rom_flashchip.device_id)) {
BOOTLOADER_FLASH_LOG(E, "XMC chip detected (%08X) while support disabled.", g_rom_flashchip.device_id);
return ESP_FAIL;
}
return ESP_OK;
}
#endif //XMC_SUPPORT