diff --git a/components/bootloader_support/CMakeLists.txt b/components/bootloader_support/CMakeLists.txt index c66b4207be..311dad0e24 100644 --- a/components/bootloader_support/CMakeLists.txt +++ b/components/bootloader_support/CMakeLists.txt @@ -8,6 +8,7 @@ set(srcs "src/flash_partitions.c" "src/flash_qio_mode.c" "src/bootloader_flash_config_${IDF_TARGET}.c" + "src/bootloader_efuse_${IDF_TARGET}.c" ) if(IDF_TARGET STREQUAL "esp32") @@ -26,7 +27,6 @@ if(BOOTLOADER_BUILD) "src/${IDF_TARGET}/secure_boot_signatures.c" "src/${IDF_TARGET}/secure_boot.c" "src/${IDF_TARGET}/bootloader_${IDF_TARGET}.c" - "src/${IDF_TARGET}/bootloader_clock_${IDF_TARGET}.c" ) else() list(APPEND srcs diff --git a/components/bootloader_support/component.mk b/components/bootloader_support/component.mk index 762099f944..18c560abd7 100644 --- a/components/bootloader_support/component.mk +++ b/components/bootloader_support/component.mk @@ -19,7 +19,8 @@ ifndef IS_BOOTLOADER_BUILD COMPONENT_OBJEXCLUDE := src/bootloader_init.o endif -COMPONENT_OBJEXCLUDE += src/bootloader_flash_config_esp32s2beta.o +COMPONENT_OBJEXCLUDE += src/bootloader_flash_config_esp32s2beta.o \ + src/bootloader_efuse_esp32s2beta.o # # Secure boot signing key support diff --git a/components/bootloader_support/src/bootloader_common.c b/components/bootloader_support/src/bootloader_common.c index 4300a1499d..d694739439 100644 --- a/components/bootloader_support/src/bootloader_common.c +++ b/components/bootloader_support/src/bootloader_common.c @@ -33,7 +33,6 @@ #include "soc/gpio_periph.h" #include "soc/rtc.h" #include "soc/efuse_reg.h" -#include "soc/apb_ctrl_reg.h" #include "esp_image_format.h" #include "bootloader_sha.h" #include "sys/param.h" @@ -280,35 +279,6 @@ void bootloader_common_vddsdio_configure(void) #endif // CONFIG_BOOTLOADER_VDDSDIO_BOOST } -#ifdef CONFIG_IDF_TARGET_ESP32 -uint8_t bootloader_common_get_chip_revision(void) -{ - uint8_t eco_bit0, eco_bit1, eco_bit2; - eco_bit0 = (REG_READ(EFUSE_BLK0_RDATA3_REG) & 0xF000) >> 15; - eco_bit1 = (REG_READ(EFUSE_BLK0_RDATA5_REG) & 0x100000) >> 20; - eco_bit2 = (REG_READ(APB_CTRL_DATE_REG) & 0x80000000) >> 31; - uint32_t combine_value = (eco_bit2 << 2) | (eco_bit1 << 1) | eco_bit0; - uint8_t chip_ver = 0; - switch (combine_value) { - case 0: - chip_ver = 0; - break; - case 1: - chip_ver = 1; - break; - case 3: - chip_ver = 2; - break; - case 7: - chip_ver = 3; - break; - default: - chip_ver = 0; - break; - } - return chip_ver; -} -#endif esp_err_t bootloader_common_check_chip_validity(const esp_image_header_t* img_hdr) { diff --git a/components/bootloader_support/src/bootloader_efuse_esp32.c b/components/bootloader_support/src/bootloader_efuse_esp32.c new file mode 100644 index 0000000000..35f8e9f88b --- /dev/null +++ b/components/bootloader_support/src/bootloader_efuse_esp32.c @@ -0,0 +1,56 @@ +// Copyright 2019 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. + +#include "bootloader_common.h" +#include "bootloader_clock.h" +#include "soc/efuse_reg.h" +#include "soc/apb_ctrl_reg.h" + +uint8_t bootloader_common_get_chip_revision(void) +{ + uint8_t eco_bit0, eco_bit1, eco_bit2; + eco_bit0 = (REG_READ(EFUSE_BLK0_RDATA3_REG) & 0xF000) >> 15; + eco_bit1 = (REG_READ(EFUSE_BLK0_RDATA5_REG) & 0x100000) >> 20; + eco_bit2 = (REG_READ(APB_CTRL_DATE_REG) & 0x80000000) >> 31; + uint32_t combine_value = (eco_bit2 << 2) | (eco_bit1 << 1) | eco_bit0; + uint8_t chip_ver = 0; + switch (combine_value) { + case 0: + chip_ver = 0; + break; + case 1: + chip_ver = 1; + break; + case 3: + chip_ver = 2; + break; + case 7: + chip_ver = 3; + break; + default: + chip_ver = 0; + break; + } + return chip_ver; +} + +int bootloader_clock_get_rated_freq_mhz() +{ + //Check if ESP32 is rated for a CPU frequency of 160MHz only + if (REG_GET_BIT(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_CPU_FREQ_RATED) && + REG_GET_BIT(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_CPU_FREQ_LOW)) { + return 160; + } + return 240; +} diff --git a/components/bootloader_support/src/bootloader_efuse_esp32s2beta.c b/components/bootloader_support/src/bootloader_efuse_esp32s2beta.c new file mode 100644 index 0000000000..b762d2c4f8 --- /dev/null +++ b/components/bootloader_support/src/bootloader_efuse_esp32s2beta.c @@ -0,0 +1,29 @@ +// Copyright 2019 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. + +#include "sdkconfig.h" +#include "bootloader_clock.h" +#include "bootloader_common.h" + +int bootloader_clock_get_rated_freq_mhz() +{ + /* No known limitation: all chips are 240MHz rated */ + return 240; +} + +uint8_t bootloader_common_get_chip_revision(void) +{ + /* No other revisions for ESP32-S2beta */ + return 0; +} diff --git a/components/bootloader_support/src/esp32/bootloader_clock_esp32.c b/components/bootloader_support/src/esp32/bootloader_clock_esp32.c deleted file mode 100644 index fb69d84b3b..0000000000 --- a/components/bootloader_support/src/esp32/bootloader_clock_esp32.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "soc/efuse_reg.h" -#include "bootloader_clock.h" - -int bootloader_clock_get_rated_freq_mhz() -{ - //Check if ESP32 is rated for a CPU frequency of 160MHz only - if (REG_GET_BIT(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_CPU_FREQ_RATED) && - REG_GET_BIT(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_CPU_FREQ_LOW)) { - return 160; - } - return 240; -} - diff --git a/components/bootloader_support/src/esp32/bootloader_esp32.c b/components/bootloader_support/src/esp32/bootloader_esp32.c index a6a1705162..7e9cba9130 100644 --- a/components/bootloader_support/src/esp32/bootloader_esp32.c +++ b/components/bootloader_support/src/esp32/bootloader_esp32.c @@ -1,3 +1,17 @@ +// Copyright 2019 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. + #include "bootloader_common.h" #include "sdkconfig.h" #include "soc/efuse_reg.h" diff --git a/components/bootloader_support/src/esp32s2beta/bootloader_clock_esp32s2beta.c b/components/bootloader_support/src/esp32s2beta/bootloader_clock_esp32s2beta.c deleted file mode 100644 index 6a09987f26..0000000000 --- a/components/bootloader_support/src/esp32s2beta/bootloader_clock_esp32s2beta.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "sdkconfig.h" -#include "bootloader_clock.h" - -int bootloader_clock_get_rated_freq_mhz() -{ -// TODO: implement bootloader_clock_get_rated_freq_mhz for esp32s2beta - IDF-758 - return 999; -} - - diff --git a/components/bootloader_support/src/esp32s2beta/bootloader_esp32s2beta.c b/components/bootloader_support/src/esp32s2beta/bootloader_esp32s2beta.c index 5f925ca20f..452974f7d0 100644 --- a/components/bootloader_support/src/esp32s2beta/bootloader_esp32s2beta.c +++ b/components/bootloader_support/src/esp32s2beta/bootloader_esp32s2beta.c @@ -1,3 +1,17 @@ +// Copyright 2019 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. + #include "bootloader_common.h" #include "sdkconfig.h" #include "soc/efuse_reg.h"