efuse: fix

This commit is contained in:
KonstantinKondrashov 2022-04-21 00:44:24 +08:00 committed by BOT
parent 8c063a326e
commit 06aeeff54e
7 changed files with 48 additions and 52 deletions

View File

@ -14,6 +14,8 @@
static const char *TAG = "efuse";
#define ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block) ((error_reg) & (0x0F << (4 * (block))))
#ifdef CONFIG_EFUSE_VIRTUAL
extern uint32_t virt_blocks[EFUSE_BLK_MAX][COUNT_EFUSE_REG_PER_BLOCK];
#endif // CONFIG_EFUSE_VIRTUAL
@ -82,22 +84,14 @@ __attribute__((always_inline)) static inline bool efuse_ll_get_dec_warnings(unsi
return false;
}
uint32_t error_reg = REG_GET_FIELD(EFUSE_DEC_STATUS_REG, EFUSE_DEC_WARNINGS);
if (((error_reg >> (4 * (block - 1))) & 0x0F) != 0) {
return true;
}
return false;
return ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block - 1) != 0;
}
static bool efuse_hal_is_coding_error_in_block(unsigned block)
bool efuse_hal_is_coding_error_in_block(unsigned block)
{
if (block > 0) {
if (esp_efuse_get_coding_scheme(block) == EFUSE_CODING_SCHEME_3_4) {
if (efuse_ll_get_dec_warnings(block)) {
return true;
}
}
}
return false;
return block > 0 &&
esp_efuse_get_coding_scheme(block) == EFUSE_CODING_SCHEME_3_4 &&
efuse_ll_get_dec_warnings(block);
}
#endif // ifndef CONFIG_EFUSE_VIRTUAL
@ -139,7 +133,7 @@ esp_err_t esp_efuse_utility_burn_chip(void)
#ifdef CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
esp_efuse_utility_write_efuses_to_flash();
#endif
#else
#else // CONFIG_EFUSE_VIRTUAL
if (esp_efuse_set_timing() != ESP_OK) {
ESP_LOGE(TAG, "Efuse fields are not burnt");
} else {
@ -167,12 +161,12 @@ esp_err_t esp_efuse_utility_burn_chip(void)
unsigned w_data_len;
unsigned r_data_len;
if (scheme == EFUSE_CODING_SCHEME_3_4) {
esp_efuse_utility_apply_34_encoding((void *)range_write_addr_blocks[num_block].start, (uint32_t *)start_write_addr[num_block], 24);
r_data_len = 24;
esp_efuse_utility_apply_34_encoding((void *)range_write_addr_blocks[num_block].start, (uint32_t *)start_write_addr[num_block], ESP_EFUSE_LEN_OF_3_4_SCHEME_BLOCK_IN_BYTES);
r_data_len = ESP_EFUSE_LEN_OF_3_4_SCHEME_BLOCK_IN_BYTES;
w_data_len = 32;
} else if (scheme == EFUSE_CODING_SCHEME_REPEAT) {
apply_repeat_encoding((void *)range_write_addr_blocks[num_block].start, (uint32_t *)start_write_addr[num_block], 16);
r_data_len = 16;
r_data_len = ESP_EFUSE_LEN_OF_REPEAT_BLOCK_IN_BYTES;
w_data_len = 32;
} else {
r_data_len = (range_read_addr_blocks[num_block].end - range_read_addr_blocks[num_block].start) + sizeof(uint32_t);
@ -298,7 +292,7 @@ esp_err_t esp_efuse_utility_apply_new_coding_scheme()
if (*((uint32_t*)buf_w_data + 6) != 0 || *((uint32_t*)buf_w_data + 7) != 0) {
return ESP_ERR_CODING;
}
for (int i = 0; i < 24; ++i) {
for (int i = 0; i < ESP_EFUSE_LEN_OF_3_4_SCHEME_BLOCK_IN_BYTES; ++i) {
if (buf_w_data[i] != 0) {
int st_offset_buf = (i / 6) * 6;
// check that place is free.

View File

@ -10,6 +10,9 @@
extern "C" {
#endif
#define ESP_EFUSE_LEN_OF_3_4_SCHEME_BLOCK_IN_BYTES (24)
#define ESP_EFUSE_LEN_OF_REPEAT_BLOCK_IN_BYTES (16)
#define COUNT_EFUSE_REG_PER_BLOCK 8 /* The number of registers per block. */
#define ESP_EFUSE_SECURE_VERSION_NUM_BLOCK EFUSE_BLK3

View File

@ -15,6 +15,8 @@
static const char *TAG = "efuse";
#define ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block) ((error_reg) & (0x0F << (4 * (block))))
#ifdef CONFIG_EFUSE_VIRTUAL
extern uint32_t virt_blocks[EFUSE_BLK_MAX][COUNT_EFUSE_REG_PER_BLOCK];
#endif // CONFIG_EFUSE_VIRTUAL
@ -98,10 +100,7 @@ static bool efuse_hal_is_coding_error_in_block(unsigned block)
// EFUSE_RD_RS_ERR1_REG: BLOCK9, BLOCK8
// BLOCK10 is not presented in the error regs.
uint32_t error_reg = REG_READ(EFUSE_RD_RS_ERR0_REG + (block / 8) * 4);
unsigned offset = (block >= 8) ? block - 8 : block;
if (((error_reg >> (4 * offset)) & 0x0F) != 0) {
return true;
}
return ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block % 8) != 0;
}
return false;
}
@ -130,7 +129,7 @@ esp_err_t esp_efuse_utility_burn_chip(void)
#ifdef CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
esp_efuse_utility_write_efuses_to_flash();
#endif
#else
#else // CONFIG_EFUSE_VIRTUAL
if (esp_efuse_set_timing() != ESP_OK) {
ESP_LOGE(TAG, "Efuse fields are not burnt");
} else {

View File

@ -15,6 +15,8 @@
static const char *TAG = "efuse";
#define ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block) ((error_reg) & (0x0F << (4 * (block))))
#ifdef CONFIG_EFUSE_VIRTUAL
extern uint32_t virt_blocks[EFUSE_BLK_MAX][COUNT_EFUSE_REG_PER_BLOCK];
#endif // CONFIG_EFUSE_VIRTUAL
@ -77,11 +79,9 @@ static bool efuse_hal_is_coding_error_in_block(unsigned block)
} else if (block <= 10) {
// EFUSE_RD_RS_ERR0_REG: (hi) BLOCK8, BLOCK7, BLOCK6, BLOCK5, BLOCK4, BLOCK3, BLOCK2, BLOCK1 (low)
// EFUSE_RD_RS_ERR1_REG: BLOCK10, BLOCK9
uint32_t error_reg = REG_READ(EFUSE_RD_RS_ERR0_REG + (block / 9) * 4);
unsigned offset = (block >= 9) ? block - 9 : block - 1;
if (((error_reg >> (4 * offset)) & 0x0F) != 0) {
return true;
}
block--;
uint32_t error_reg = REG_READ(EFUSE_RD_RS_ERR0_REG + (block / 8) * 4);
return ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block % 8) != 0;
}
return false;
}
@ -110,7 +110,7 @@ esp_err_t esp_efuse_utility_burn_chip(void)
#ifdef CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
esp_efuse_utility_write_efuses_to_flash();
#endif
#else
#else // CONFIG_EFUSE_VIRTUAL
if (esp_efuse_set_timing() != ESP_OK) {
ESP_LOGE(TAG, "Efuse fields are not burnt");
} else {

View File

@ -15,6 +15,8 @@
static const char *TAG = "efuse";
#define ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block) ((error_reg) & (0x0F << (4 * (block))))
#ifdef CONFIG_EFUSE_VIRTUAL
extern uint32_t virt_blocks[EFUSE_BLK_MAX][COUNT_EFUSE_REG_PER_BLOCK];
#endif // CONFIG_EFUSE_VIRTUAL
@ -70,11 +72,9 @@ static bool efuse_hal_is_coding_error_in_block(unsigned block)
} else if (block <= 10) {
// EFUSE_RD_RS_ERR0_REG: (hi) BLOCK8, BLOCK7, BLOCK6, BLOCK5, BLOCK4, BLOCK3, BLOCK2, BLOCK1 (low)
// EFUSE_RD_RS_ERR1_REG: BLOCK10, BLOCK9
uint32_t error_reg = REG_READ(EFUSE_RD_RS_ERR0_REG + (block / 9) * 4);
unsigned offset = (block >= 9) ? block - 9 : block - 1;
if (((error_reg >> (4 * offset)) & 0x0F) != 0) {
return true;
}
block--;
uint32_t error_reg = REG_READ(EFUSE_RD_RS_ERR0_REG + (block / 8) * 4);
return ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block % 8) != 0;
}
return false;
}
@ -103,7 +103,7 @@ esp_err_t esp_efuse_utility_burn_chip(void)
#ifdef CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
esp_efuse_utility_write_efuses_to_flash();
#endif
#else
#else // CONFIG_EFUSE_VIRTUAL
if (esp_efuse_set_timing() != ESP_OK) {
ESP_LOGE(TAG, "Efuse fields are not burnt");
} else {

View File

@ -15,6 +15,8 @@
static const char *TAG = "efuse";
#define ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block) ((error_reg) & (0x0F << (4 * (block))))
#ifdef CONFIG_EFUSE_VIRTUAL
extern uint32_t virt_blocks[EFUSE_BLK_MAX][COUNT_EFUSE_REG_PER_BLOCK];
#endif // CONFIG_EFUSE_VIRTUAL
@ -95,11 +97,9 @@ static bool efuse_hal_is_coding_error_in_block(unsigned block)
} else if (block <= 10) {
// EFUSE_RD_RS_ERR0_REG: (hi) BLOCK8, BLOCK7, BLOCK6, BLOCK5, BLOCK4, BLOCK3, BLOCK2, BLOCK1 (low)
// EFUSE_RD_RS_ERR1_REG: BLOCK10, BLOCK9
uint32_t error_reg = REG_READ(EFUSE_RD_RS_ERR0_REG + (block / 9) * 4);
unsigned offset = (block >= 9) ? block - 9 : block - 1;
if (((error_reg >> (4 * offset)) & 0x0F) != 0) {
return true;
}
block--;
uint32_t error_reg = REG_READ(EFUSE_RD_RS_ERR0_REG + (block / 8) * 4);
return ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block % 8) != 0;
}
return false;
}
@ -128,7 +128,7 @@ esp_err_t esp_efuse_utility_burn_chip(void)
#ifdef CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
esp_efuse_utility_write_efuses_to_flash();
#endif
#else
#else // CONFIG_EFUSE_VIRTUAL
if (esp_efuse_set_timing() != ESP_OK) {
ESP_LOGE(TAG, "Efuse fields are not burnt");
} else {

View File

@ -484,19 +484,19 @@ bool esp_efuse_utility_is_correct_written_data(esp_efuse_block_t block, unsigned
bool correct_written_data = memcmp(w_data, r_data, r_data_len) == 0;
if (correct_written_data) {
ESP_LOGI(TAG, "BURN BLOCK%d - OK (write block == read block)", block);
} else {
correct_written_data = true;
for (unsigned i = 0; i < r_data_len / 4; i++) {
if ((*(r_data + i) & *(w_data + i)) != *(w_data + i)) {
correct_written_data = false;
break;
}
}
if (correct_written_data) {
ESP_LOGI(TAG, "BURN BLOCK%d - OK (all write block bits are set)", block);
return true;
}
correct_written_data = true;
for (unsigned i = 0; i < r_data_len / 4; i++) {
if ((*(r_data + i) & *(w_data + i)) != *(w_data + i)) {
correct_written_data = false;
break;
}
}
if (!correct_written_data) {
if (correct_written_data) {
ESP_LOGI(TAG, "BURN BLOCK%d - OK (all write block bits are set)", block);
} else {
ESP_LOGE(TAG, "BURN BLOCK%d - ERROR (written bits != read bits)", block);
}
return correct_written_data;