2021-05-31 00:43:23 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2019-06-18 07:34:05 -04:00
|
|
|
|
|
|
|
#include "esp_efuse.h"
|
|
|
|
#include "esp_efuse_utility.h"
|
|
|
|
#include "esp_efuse_table.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
#include "esp_types.h"
|
|
|
|
#include "assert.h"
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "esp_log.h"
|
|
|
|
#include "soc/efuse_periph.h"
|
|
|
|
#include "bootloader_random.h"
|
|
|
|
#include "sys/param.h"
|
|
|
|
|
|
|
|
const static char *TAG = "efuse";
|
|
|
|
|
|
|
|
// Contains functions that provide access to efuse fields which are often used in IDF.
|
|
|
|
|
|
|
|
// Returns chip version from efuse
|
|
|
|
uint8_t esp_efuse_get_chip_ver(void)
|
|
|
|
{
|
2020-06-08 10:14:21 -04:00
|
|
|
// should return the same value as bootloader_common_get_chip_revision()
|
2019-06-18 07:34:05 -04:00
|
|
|
uint32_t chip_ver = 0;
|
2020-01-16 22:47:08 -05:00
|
|
|
// TODO: ESP32S2 does not have this field
|
2019-06-18 07:34:05 -04:00
|
|
|
return chip_ver;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns chip package from efuse
|
|
|
|
uint32_t esp_efuse_get_pkg_ver(void)
|
|
|
|
{
|
|
|
|
uint32_t pkg_ver = 0;
|
2020-06-08 10:14:21 -04:00
|
|
|
esp_efuse_read_field_blob(ESP_EFUSE_PKG_VERSION, &pkg_ver, 4);
|
2019-06-18 07:34:05 -04:00
|
|
|
return pkg_ver;
|
|
|
|
}
|
|
|
|
|
|
|
|
void esp_efuse_write_random_key(uint32_t blk_wdata0_reg)
|
|
|
|
{
|
|
|
|
uint32_t buf[8];
|
|
|
|
uint8_t raw[24];
|
|
|
|
|
|
|
|
bootloader_fill_random(buf, sizeof(buf));
|
|
|
|
|
|
|
|
ESP_LOGV(TAG, "Writing random values to address 0x%08x", blk_wdata0_reg);
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
ESP_LOGV(TAG, "EFUSE_BLKx_WDATA%d_REG = 0x%08x", i, buf[i]);
|
2021-01-26 08:07:22 -05:00
|
|
|
REG_WRITE(blk_wdata0_reg + 4 * i, buf[i]);
|
2019-06-18 07:34:05 -04:00
|
|
|
}
|
|
|
|
bzero(buf, sizeof(buf));
|
|
|
|
bzero(raw, sizeof(raw));
|
|
|
|
}
|
2020-04-25 02:36:53 -04:00
|
|
|
|
|
|
|
esp_err_t esp_efuse_disable_rom_download_mode(void)
|
|
|
|
{
|
|
|
|
return esp_efuse_write_field_bit(ESP_EFUSE_DIS_DOWNLOAD_MODE);
|
|
|
|
}
|
|
|
|
|
2021-01-26 08:07:22 -05:00
|
|
|
esp_err_t esp_efuse_set_rom_log_scheme(esp_efuse_rom_log_scheme_t log_scheme)
|
|
|
|
{
|
|
|
|
int cur_log_scheme = 0;
|
|
|
|
esp_efuse_read_field_blob(ESP_EFUSE_UART_PRINT_CONTROL, &cur_log_scheme, 2);
|
|
|
|
if (!cur_log_scheme) { // not burned yet
|
|
|
|
return esp_efuse_write_field_blob(ESP_EFUSE_UART_PRINT_CONTROL, &log_scheme, 2);
|
|
|
|
} else {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-25 02:36:53 -04:00
|
|
|
esp_err_t esp_efuse_enable_rom_secure_download_mode(void)
|
|
|
|
{
|
|
|
|
if (esp_efuse_read_field_bit(ESP_EFUSE_DIS_DOWNLOAD_MODE)) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
return esp_efuse_write_field_bit(ESP_EFUSE_ENABLE_SECURITY_DOWNLOAD);
|
|
|
|
}
|