1 /* 2 * SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include "esp_efuse.h" 8 #include "esp_efuse_utility.h" 9 #include "esp_efuse_table.h" 10 #include "stdlib.h" 11 #include "esp_types.h" 12 #include "assert.h" 13 #include "esp_err.h" 14 #include "esp_log.h" 15 #include "soc/efuse_periph.h" 16 #include "bootloader_random.h" 17 #include "sys/param.h" 18 19 static __attribute__((unused)) const char *TAG = "efuse"; 20 21 // Contains functions that provide access to efuse fields which are often used in IDF. 22 23 // Returns chip version from efuse esp_efuse_get_chip_ver(void)24uint8_t esp_efuse_get_chip_ver(void) 25 { 26 // should return the same value as bootloader_common_get_chip_revision() 27 uint32_t chip_ver = 0; 28 esp_efuse_read_field_blob(ESP_EFUSE_WAFER_VERSION, &chip_ver, ESP_EFUSE_WAFER_VERSION[0]->bit_count); 29 return chip_ver; 30 } 31 32 // Returns chip package from efuse esp_efuse_get_pkg_ver(void)33uint32_t esp_efuse_get_pkg_ver(void) 34 { 35 uint32_t pkg_ver = 0; 36 esp_efuse_read_field_blob(ESP_EFUSE_PKG_VERSION, &pkg_ver, 4); 37 return pkg_ver; 38 } 39 esp_efuse_disable_rom_download_mode(void)40esp_err_t esp_efuse_disable_rom_download_mode(void) 41 { 42 return esp_efuse_write_field_bit(ESP_EFUSE_DIS_DOWNLOAD_MODE); 43 } 44 esp_efuse_set_rom_log_scheme(esp_efuse_rom_log_scheme_t log_scheme)45esp_err_t esp_efuse_set_rom_log_scheme(esp_efuse_rom_log_scheme_t log_scheme) 46 { 47 int cur_log_scheme = 0; 48 esp_efuse_read_field_blob(ESP_EFUSE_UART_PRINT_CONTROL, &cur_log_scheme, 2); 49 if (!cur_log_scheme) { // not burned yet 50 return esp_efuse_write_field_blob(ESP_EFUSE_UART_PRINT_CONTROL, &log_scheme, 2); 51 } else { 52 return ESP_ERR_INVALID_STATE; 53 } 54 } 55 esp_efuse_enable_rom_secure_download_mode(void)56esp_err_t esp_efuse_enable_rom_secure_download_mode(void) 57 { 58 if (esp_efuse_read_field_bit(ESP_EFUSE_DIS_DOWNLOAD_MODE)) { 59 return ESP_ERR_INVALID_STATE; 60 } 61 return esp_efuse_write_field_bit(ESP_EFUSE_ENABLE_SECURITY_DOWNLOAD); 62 } 63