efuse: fix

This commit is contained in:
KonstantinKondrashov 2022-04-21 00:44:24 +08:00
parent dffcb3d0fb
commit 83728f3832
4 changed files with 33 additions and 36 deletions

View File

@ -18,6 +18,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

@ -22,6 +22,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
@ -90,22 +92,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
@ -144,7 +138,7 @@ esp_err_t esp_efuse_utility_burn_efuses(void)
virt_blocks[num_block][subblock++] |= REG_READ(addr_wr_block);
}
}
#else
#else // CONFIG_EFUSE_VIRTUAL
if (esp_efuse_set_timing() != ESP_OK) {
ESP_LOGE(TAG, "Efuse fields are not burnt");
} else {
@ -172,12 +166,12 @@ esp_err_t esp_efuse_utility_burn_efuses(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;
apply_repeat_encoding((void *)range_write_addr_blocks[num_block].start, (uint32_t *)start_write_addr[num_block], ESP_EFUSE_LEN_OF_REPEAT_BLOCK_IN_BYTES);
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);
@ -303,7 +297,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

@ -23,6 +23,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
@ -78,11 +80,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;
}
@ -108,7 +108,7 @@ esp_err_t esp_efuse_utility_burn_efuses(void)
virt_blocks[num_block][subblock++] |= REG_READ(addr_wr_block);
}
}
#else
#else // CONFIG_EFUSE_VIRTUAL
if (esp_efuse_set_timing() != ESP_OK) {
ESP_LOGE(TAG, "Efuse fields are not burnt");
} else {

View File

@ -363,19 +363,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;