From 3b2e8648eb0daa53b06c306bb9de169d26188c66 Mon Sep 17 00:00:00 2001 From: "Michael (XIAO Xufeng)" Date: Mon, 13 Jul 2020 03:23:12 +0800 Subject: [PATCH] bootloader: create public bootloader_flash.h header Move non-public functions into bootloader_flash_priv.h header --- components/app_update/test/test_switch_ota.c | 2 +- .../include/bootloader_flash.h | 30 +++++++++++++++++++ ...loader_flash.h => bootloader_flash_priv.h} | 11 +------ .../src/bootloader_common.c | 2 +- .../bootloader_support/src/bootloader_flash.c | 2 +- .../bootloader_support/src/bootloader_init.c | 2 +- .../src/bootloader_utility.c | 2 +- .../src/esp32/bootloader_esp32.c | 2 +- .../src/esp32/flash_encrypt.c | 2 +- .../src/esp32/secure_boot.c | 4 +-- .../src/esp32/secure_boot_signatures.c | 2 +- .../src/esp32s2/bootloader_esp32s2.c | 2 +- .../src/esp32s2/flash_encrypt.c | 6 ++-- .../src/esp32s2/secure_boot.c | 2 +- .../src/esp32s2/secure_boot_signatures.c | 2 +- .../bootloader_support/src/esp_image_format.c | 2 +- .../bootloader_support/src/flash_qio_mode.c | 2 +- .../src/idf/bootloader_sha.c | 2 +- .../src/idf/secure_boot_signatures.c | 4 +-- components/efuse/src/esp_efuse_fields.c | 2 +- 20 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 components/bootloader_support/include/bootloader_flash.h rename components/bootloader_support/include_bootloader/{bootloader_flash.h => bootloader_flash_priv.h} (95%) diff --git a/components/app_update/test/test_switch_ota.c b/components/app_update/test/test_switch_ota.c index 5cbb8c0908..ec1847135a 100644 --- a/components/app_update/test/test_switch_ota.c +++ b/components/app_update/test/test_switch_ota.c @@ -23,7 +23,7 @@ #include "unity.h" #include "bootloader_common.h" -#include "../include_bootloader/bootloader_flash.h" +#include "../include_bootloader/bootloader_flash_priv.h" #include "esp_log.h" #include "esp_ota_ops.h" diff --git a/components/bootloader_support/include/bootloader_flash.h b/components/bootloader_support/include/bootloader_flash.h new file mode 100644 index 0000000000..5b74596544 --- /dev/null +++ b/components/bootloader_support/include/bootloader_flash.h @@ -0,0 +1,30 @@ +// Copyright 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. +#pragma once + +#include +#include /* including in bootloader for error values */ +#include "sdkconfig.h" +#include "soc/soc_caps.h" + +#if SOC_CACHE_SUPPORT_WRAP +/** + * @brief Set the burst mode setting command for specified wrap mode. + * + * @param mode The specified warp mode. + * @return always ESP_OK + */ +esp_err_t bootloader_flash_wrap_set(spi_flash_wrap_mode_t mode); +#endif + diff --git a/components/bootloader_support/include_bootloader/bootloader_flash.h b/components/bootloader_support/include_bootloader/bootloader_flash_priv.h similarity index 95% rename from components/bootloader_support/include_bootloader/bootloader_flash.h rename to components/bootloader_support/include_bootloader/bootloader_flash_priv.h index e2e0f3ed65..45b7b06008 100644 --- a/components/bootloader_support/include_bootloader/bootloader_flash.h +++ b/components/bootloader_support/include_bootloader/bootloader_flash_priv.h @@ -20,6 +20,7 @@ #include #include /* including in bootloader for error values */ #include "sdkconfig.h" +#include "bootloader_flash.h" #define FLASH_SECTOR_SIZE 0x1000 #define FLASH_BLOCK_SIZE 0x10000 @@ -167,14 +168,4 @@ uint32_t bootloader_execute_flash_command(uint8_t command, uint32_t mosi_data, u */ void bootloader_enable_wp(void); -#if CONFIG_IDF_TARGET_ESP32S2 -/** - * @brief Set the burst mode setting command for specified wrap mode. - * - * @param mode The specified warp mode. - * @return always ESP_OK - */ -esp_err_t bootloader_flash_wrap_set(spi_flash_wrap_mode_t mode); -#endif - #endif diff --git a/components/bootloader_support/src/bootloader_common.c b/components/bootloader_support/src/bootloader_common.c index 09de9c246a..cc57d13273 100644 --- a/components/bootloader_support/src/bootloader_common.c +++ b/components/bootloader_support/src/bootloader_common.c @@ -26,7 +26,7 @@ #include "esp_rom_gpio.h" #include "esp_rom_sys.h" #include "esp_flash_partitions.h" -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "bootloader_common.h" #include "bootloader_utility.h" #include "soc/gpio_periph.h" diff --git a/components/bootloader_support/src/bootloader_flash.c b/components/bootloader_support/src/bootloader_flash.c index 6716e3bc53..d91c1cb4f3 100644 --- a/components/bootloader_support/src/bootloader_flash.c +++ b/components/bootloader_support/src/bootloader_flash.c @@ -13,7 +13,7 @@ // limitations under the License. #include -#include +#include #include #include #include "sdkconfig.h" diff --git a/components/bootloader_support/src/bootloader_init.c b/components/bootloader_support/src/bootloader_init.c index 8938dc7571..d662f2d32c 100644 --- a/components/bootloader_support/src/bootloader_init.c +++ b/components/bootloader_support/src/bootloader_init.c @@ -17,7 +17,7 @@ #include "esp_attr.h" #include "esp_log.h" #include "bootloader_init.h" -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "bootloader_flash_config.h" #include "bootloader_random.h" #include "bootloader_clock.h" diff --git a/components/bootloader_support/src/bootloader_utility.c b/components/bootloader_support/src/bootloader_utility.c index 965fd0d12c..6c4662695e 100644 --- a/components/bootloader_support/src/bootloader_utility.c +++ b/components/bootloader_support/src/bootloader_utility.c @@ -51,7 +51,7 @@ #include "esp_secure_boot.h" #include "esp_flash_encrypt.h" #include "esp_flash_partitions.h" -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "bootloader_random.h" #include "bootloader_config.h" #include "bootloader_common.h" diff --git a/components/bootloader_support/src/esp32/bootloader_esp32.c b/components/bootloader_support/src/esp32/bootloader_esp32.c index 61501eed55..4bd3d04680 100644 --- a/components/bootloader_support/src/esp32/bootloader_esp32.c +++ b/components/bootloader_support/src/esp32/bootloader_esp32.c @@ -24,7 +24,7 @@ #include "bootloader_flash_config.h" #include "bootloader_mem.h" #include "bootloader_console.h" -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "soc/cpu.h" #include "soc/dport_reg.h" diff --git a/components/bootloader_support/src/esp32/flash_encrypt.c b/components/bootloader_support/src/esp32/flash_encrypt.c index 6212228701..0a75ae6cf3 100644 --- a/components/bootloader_support/src/esp32/flash_encrypt.c +++ b/components/bootloader_support/src/esp32/flash_encrypt.c @@ -14,7 +14,7 @@ #include -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "esp_image_format.h" #include "esp_flash_encrypt.h" #include "esp_flash_partitions.h" diff --git a/components/bootloader_support/src/esp32/secure_boot.c b/components/bootloader_support/src/esp32/secure_boot.c index e54e65b6c0..99d7ebe024 100644 --- a/components/bootloader_support/src/esp32/secure_boot.c +++ b/components/bootloader_support/src/esp32/secure_boot.c @@ -28,7 +28,7 @@ #include "sdkconfig.h" -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "bootloader_random.h" #include "esp_image_format.h" #include "esp_secure_boot.h" @@ -322,7 +322,7 @@ esp_err_t esp_secure_boot_v2_permanently_enable(const esp_image_metadata_t *imag uint32_t dis_reg = REG_READ(EFUSE_BLK0_RDATA0_REG); bool efuse_key_read_protected = dis_reg & EFUSE_RD_DIS_BLK2; bool efuse_key_write_protected = dis_reg & EFUSE_WR_DIS_BLK2; - if (efuse_key_write_protected == false + if (efuse_key_write_protected == false && efuse_key_read_protected == false && REG_READ(EFUSE_BLK2_RDATA0_REG) == 0 && REG_READ(EFUSE_BLK2_RDATA1_REG) == 0 diff --git a/components/bootloader_support/src/esp32/secure_boot_signatures.c b/components/bootloader_support/src/esp32/secure_boot_signatures.c index 1ff4999b85..e38e98201b 100644 --- a/components/bootloader_support/src/esp32/secure_boot_signatures.c +++ b/components/bootloader_support/src/esp32/secure_boot_signatures.c @@ -13,7 +13,7 @@ // limitations under the License. #include "sdkconfig.h" -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "bootloader_sha.h" #include "bootloader_utility.h" #include "esp_log.h" diff --git a/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c b/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c index 882c656eec..47c1a18020 100644 --- a/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c +++ b/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c @@ -27,7 +27,7 @@ #include "bootloader_flash_config.h" #include "bootloader_mem.h" #include "bootloader_console.h" -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "esp_rom_sys.h" #include "esp32s2/rom/cache.h" diff --git a/components/bootloader_support/src/esp32s2/flash_encrypt.c b/components/bootloader_support/src/esp32s2/flash_encrypt.c index 9d9acf754f..017c42d8c0 100644 --- a/components/bootloader_support/src/esp32s2/flash_encrypt.c +++ b/components/bootloader_support/src/esp32s2/flash_encrypt.c @@ -14,7 +14,7 @@ #include -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "bootloader_random.h" #include "bootloader_utility.h" #include "esp_image_format.h" @@ -299,8 +299,8 @@ static esp_err_t encrypt_bootloader(void) if (err != ESP_OK) { ESP_LOGE(TAG, "Failed to encrypt bootloader in place: 0x%x", err); return err; - } - + } + ESP_LOGI(TAG, "bootloader encrypted successfully"); return err; } diff --git a/components/bootloader_support/src/esp32s2/secure_boot.c b/components/bootloader_support/src/esp32s2/secure_boot.c index e5dd3b93b4..7a8ac94f6a 100644 --- a/components/bootloader_support/src/esp32s2/secure_boot.c +++ b/components/bootloader_support/src/esp32s2/secure_boot.c @@ -17,7 +17,7 @@ #include "esp_secure_boot.h" #include "soc/efuse_reg.h" -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "bootloader_sha.h" #include "bootloader_utility.h" diff --git a/components/bootloader_support/src/esp32s2/secure_boot_signatures.c b/components/bootloader_support/src/esp32s2/secure_boot_signatures.c index e60fcacaf1..3da88b262c 100644 --- a/components/bootloader_support/src/esp32s2/secure_boot_signatures.c +++ b/components/bootloader_support/src/esp32s2/secure_boot_signatures.c @@ -15,7 +15,7 @@ #include #include "esp_fault.h" -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "bootloader_sha.h" #include "bootloader_utility.h" #include "esp_log.h" diff --git a/components/bootloader_support/src/esp_image_format.c b/components/bootloader_support/src/esp_image_format.c index 2d02329019..eb03a2e581 100644 --- a/components/bootloader_support/src/esp_image_format.c +++ b/components/bootloader_support/src/esp_image_format.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include "bootloader_util.h" diff --git a/components/bootloader_support/src/flash_qio_mode.c b/components/bootloader_support/src/flash_qio_mode.c index 0dd3d41506..f142f7c284 100644 --- a/components/bootloader_support/src/flash_qio_mode.c +++ b/components/bootloader_support/src/flash_qio_mode.c @@ -15,7 +15,7 @@ #include #include "bootloader_flash_config.h" #include "flash_qio_mode.h" -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "esp_log.h" #include "esp_err.h" #include "esp_rom_efuse.h" diff --git a/components/bootloader_support/src/idf/bootloader_sha.c b/components/bootloader_support/src/idf/bootloader_sha.c index 8d70406c72..40308b667f 100644 --- a/components/bootloader_support/src/idf/bootloader_sha.c +++ b/components/bootloader_support/src/idf/bootloader_sha.c @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. #include "bootloader_sha.h" -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include #include #include diff --git a/components/bootloader_support/src/idf/secure_boot_signatures.c b/components/bootloader_support/src/idf/secure_boot_signatures.c index 8f7acb9ea7..fd7017424a 100644 --- a/components/bootloader_support/src/idf/secure_boot_signatures.c +++ b/components/bootloader_support/src/idf/secure_boot_signatures.c @@ -13,7 +13,7 @@ // limitations under the License. #include "sdkconfig.h" -#include "bootloader_flash.h" +#include "bootloader_flash_priv.h" #include "bootloader_sha.h" #include "bootloader_utility.h" #include "esp_log.h" @@ -325,7 +325,7 @@ esp_err_t esp_secure_boot_verify_rsa_signature_block(const ets_secure_boot_signa break; } } - + free(sig_be); free(buf); #if CONFIG_IDF_TARGET_ESP32 diff --git a/components/efuse/src/esp_efuse_fields.c b/components/efuse/src/esp_efuse_fields.c index 54d577a0ed..5cc8bc75fc 100644 --- a/components/efuse/src/esp_efuse_fields.c +++ b/components/efuse/src/esp_efuse_fields.c @@ -41,7 +41,7 @@ void esp_efuse_reset(void) #ifdef CONFIG_BOOTLOADER_EFUSE_SECURE_VERSION_EMULATE -#include "../include_bootloader/bootloader_flash.h" +#include "../include_bootloader/bootloader_flash_priv.h" #include "esp_flash_encrypt.h" static uint32_t esp_efuse_flash_offset = 0;