efuse: Burn func can return an error

esp_efuse_utility_burn_chip()
This commit is contained in:
KonstantinKondrashov 2022-04-06 22:39:17 +08:00 committed by BOT
parent 114608142a
commit 24af86071d
8 changed files with 69 additions and 29 deletions

View File

@ -102,14 +102,30 @@ static bool efuse_hal_is_coding_error_in_block(unsigned block)
#endif // ifndef CONFIG_EFUSE_VIRTUAL #endif // ifndef CONFIG_EFUSE_VIRTUAL
static void efuse_hal_clear_program_registers(void)
{
for (uint32_t r = EFUSE_BLK0_WDATA0_REG; r <= EFUSE_BLK0_WDATA6_REG; r += 4) {
REG_WRITE(r, 0);
}
for (uint32_t r = EFUSE_BLK1_WDATA0_REG; r <= EFUSE_BLK1_WDATA7_REG; r += 4) {
REG_WRITE(r, 0);
}
for (uint32_t r = EFUSE_BLK2_WDATA0_REG; r <= EFUSE_BLK2_WDATA7_REG; r += 4) {
REG_WRITE(r, 0);
}
for (uint32_t r = EFUSE_BLK3_WDATA0_REG; r <= EFUSE_BLK3_WDATA7_REG; r += 4) {
REG_WRITE(r, 0);
}
}
// Efuse read operation: copies data from physical efuses to efuse read registers. // Efuse read operation: copies data from physical efuses to efuse read registers.
void esp_efuse_utility_clear_program_registers(void) void esp_efuse_utility_clear_program_registers(void)
{ {
REG_WRITE(EFUSE_CONF_REG, EFUSE_CONF_READ); efuse_hal_clear_program_registers();
} }
// Burn values written to the efuse write registers // Burn values written to the efuse write registers
void esp_efuse_utility_burn_chip(void) esp_err_t esp_efuse_utility_burn_chip(void)
{ {
#ifdef CONFIG_EFUSE_VIRTUAL #ifdef CONFIG_EFUSE_VIRTUAL
ESP_LOGW(TAG, "Virtual efuses enabled: Not really burning eFuses"); ESP_LOGW(TAG, "Virtual efuses enabled: Not really burning eFuses");
@ -132,6 +148,7 @@ void esp_efuse_utility_burn_chip(void)
esp_efuse_coding_scheme_t scheme = esp_efuse_get_coding_scheme(num_block); esp_efuse_coding_scheme_t scheme = esp_efuse_get_coding_scheme(num_block);
for (uint32_t addr_wr_block = range_write_addr_blocks[num_block].start; addr_wr_block <= range_write_addr_blocks[num_block].end; addr_wr_block += 4) { for (uint32_t addr_wr_block = range_write_addr_blocks[num_block].start; addr_wr_block <= range_write_addr_blocks[num_block].end; addr_wr_block += 4) {
if (REG_READ(addr_wr_block) != 0) { if (REG_READ(addr_wr_block) != 0) {
efuse_hal_clear_program_registers();
unsigned w_data_len; unsigned w_data_len;
unsigned r_data_len; unsigned r_data_len;
if (scheme == EFUSE_CODING_SCHEME_3_4) { if (scheme == EFUSE_CODING_SCHEME_3_4) {
@ -178,12 +195,13 @@ void esp_efuse_utility_burn_chip(void)
} }
} while ((!correct_written_data || coding_error_occurred) && repeat_burn_op++ < 3); } while ((!correct_written_data || coding_error_occurred) && repeat_burn_op++ < 3);
if (!correct_written_data) {
ESP_LOGE(TAG, "Written data are incorrect");
}
if (coding_error_occurred) { if (coding_error_occurred) {
ESP_LOGE(TAG, "Coding error occurred in block"); ESP_LOGE(TAG, "Coding error occurred in block");
} }
if (!correct_written_data) {
ESP_LOGE(TAG, "Written data are incorrect");
return ESP_FAIL;
}
break; break;
} }
} }
@ -191,6 +209,7 @@ void esp_efuse_utility_burn_chip(void)
} }
#endif // CONFIG_EFUSE_VIRTUAL #endif // CONFIG_EFUSE_VIRTUAL
esp_efuse_utility_reset(); esp_efuse_utility_reset();
return ESP_OK;
} }
esp_err_t esp_efuse_utility_apply_34_encoding(const uint8_t *in_bytes, uint32_t *out_words, size_t in_bytes_len) esp_err_t esp_efuse_utility_apply_34_encoding(const uint8_t *in_bytes, uint32_t *out_words, size_t in_bytes_len)

View File

@ -116,7 +116,7 @@ void esp_efuse_utility_clear_program_registers(void)
} }
// Burn values written to the efuse write registers // Burn values written to the efuse write registers
void esp_efuse_utility_burn_chip(void) esp_err_t esp_efuse_utility_burn_chip(void)
{ {
#ifdef CONFIG_EFUSE_VIRTUAL #ifdef CONFIG_EFUSE_VIRTUAL
ESP_LOGW(TAG, "Virtual efuses enabled: Not really burning eFuses"); ESP_LOGW(TAG, "Virtual efuses enabled: Not really burning eFuses");
@ -138,6 +138,7 @@ void esp_efuse_utility_burn_chip(void)
for (int num_block = EFUSE_BLK_MAX - 1; num_block >= EFUSE_BLK0; num_block--) { for (int num_block = EFUSE_BLK_MAX - 1; num_block >= EFUSE_BLK0; num_block--) {
for (uint32_t addr_wr_block = range_write_addr_blocks[num_block].start; addr_wr_block <= range_write_addr_blocks[num_block].end; addr_wr_block += 4) { for (uint32_t addr_wr_block = range_write_addr_blocks[num_block].start; addr_wr_block <= range_write_addr_blocks[num_block].end; addr_wr_block += 4) {
if (REG_READ(addr_wr_block) != 0) { if (REG_READ(addr_wr_block) != 0) {
ets_efuse_clear_program_registers();
if (esp_efuse_get_coding_scheme(num_block) == EFUSE_CODING_SCHEME_RS) { if (esp_efuse_get_coding_scheme(num_block) == EFUSE_CODING_SCHEME_RS) {
uint8_t block_rs[12]; uint8_t block_rs[12];
ets_efuse_rs_calculate((void *)range_write_addr_blocks[num_block].start, block_rs); ets_efuse_rs_calculate((void *)range_write_addr_blocks[num_block].start, block_rs);
@ -178,12 +179,13 @@ void esp_efuse_utility_burn_chip(void)
} }
} while ((!correct_written_data || coding_error_occurred) && repeat_burn_op++ < 3); } while ((!correct_written_data || coding_error_occurred) && repeat_burn_op++ < 3);
if (!correct_written_data) {
ESP_LOGE(TAG, "Written data are incorrect");
}
if (coding_error_occurred) { if (coding_error_occurred) {
ESP_LOGE(TAG, "Coding error occurred in block"); ESP_LOGE(TAG, "Coding error occurred in block");
} }
if (!correct_written_data) {
ESP_LOGE(TAG, "Written data are incorrect");
return ESP_FAIL;
}
break; break;
} }
} }
@ -191,6 +193,7 @@ void esp_efuse_utility_burn_chip(void)
} }
#endif // CONFIG_EFUSE_VIRTUAL #endif // CONFIG_EFUSE_VIRTUAL
esp_efuse_utility_reset(); esp_efuse_utility_reset();
return ESP_OK;
} }
// After esp_efuse_write.. functions EFUSE_BLKx_WDATAx_REG were filled is not coded values. // After esp_efuse_write.. functions EFUSE_BLKx_WDATAx_REG were filled is not coded values.

View File

@ -96,7 +96,7 @@ void esp_efuse_utility_clear_program_registers(void)
} }
// Burn values written to the efuse write registers // Burn values written to the efuse write registers
void esp_efuse_utility_burn_chip(void) esp_err_t esp_efuse_utility_burn_chip(void)
{ {
#ifdef CONFIG_EFUSE_VIRTUAL #ifdef CONFIG_EFUSE_VIRTUAL
ESP_LOGW(TAG, "Virtual efuses enabled: Not really burning eFuses"); ESP_LOGW(TAG, "Virtual efuses enabled: Not really burning eFuses");
@ -118,6 +118,7 @@ void esp_efuse_utility_burn_chip(void)
for (int num_block = EFUSE_BLK_MAX - 1; num_block >= EFUSE_BLK0; num_block--) { for (int num_block = EFUSE_BLK_MAX - 1; num_block >= EFUSE_BLK0; num_block--) {
for (uint32_t addr_wr_block = range_write_addr_blocks[num_block].start; addr_wr_block <= range_write_addr_blocks[num_block].end; addr_wr_block += 4) { for (uint32_t addr_wr_block = range_write_addr_blocks[num_block].start; addr_wr_block <= range_write_addr_blocks[num_block].end; addr_wr_block += 4) {
if (REG_READ(addr_wr_block) != 0) { if (REG_READ(addr_wr_block) != 0) {
ets_efuse_clear_program_registers();
if (esp_efuse_get_coding_scheme(num_block) == EFUSE_CODING_SCHEME_RS) { if (esp_efuse_get_coding_scheme(num_block) == EFUSE_CODING_SCHEME_RS) {
uint8_t block_rs[12]; uint8_t block_rs[12];
ets_efuse_rs_calculate((void *)range_write_addr_blocks[num_block].start, block_rs); ets_efuse_rs_calculate((void *)range_write_addr_blocks[num_block].start, block_rs);
@ -158,12 +159,13 @@ void esp_efuse_utility_burn_chip(void)
} }
} while ((!correct_written_data || coding_error_occurred) && repeat_burn_op++ < 3); } while ((!correct_written_data || coding_error_occurred) && repeat_burn_op++ < 3);
if (!correct_written_data) {
ESP_LOGE(TAG, "Written data are incorrect");
}
if (coding_error_occurred) { if (coding_error_occurred) {
ESP_LOGE(TAG, "Coding error occurred in block"); ESP_LOGE(TAG, "Coding error occurred in block");
} }
if (!correct_written_data) {
ESP_LOGE(TAG, "Written data are incorrect");
return ESP_FAIL;
}
break; break;
} }
} }
@ -171,6 +173,7 @@ void esp_efuse_utility_burn_chip(void)
} }
#endif // CONFIG_EFUSE_VIRTUAL #endif // CONFIG_EFUSE_VIRTUAL
esp_efuse_utility_reset(); esp_efuse_utility_reset();
return ESP_OK;
} }
// After esp_efuse_write.. functions EFUSE_BLKx_WDATAx_REG were filled is not coded values. // After esp_efuse_write.. functions EFUSE_BLKx_WDATAx_REG were filled is not coded values.

View File

@ -89,7 +89,7 @@ void esp_efuse_utility_clear_program_registers(void)
} }
// Burn values written to the efuse write registers // Burn values written to the efuse write registers
void esp_efuse_utility_burn_chip(void) esp_err_t esp_efuse_utility_burn_chip(void)
{ {
#ifdef CONFIG_EFUSE_VIRTUAL #ifdef CONFIG_EFUSE_VIRTUAL
ESP_LOGW(TAG, "Virtual efuses enabled: Not really burning eFuses"); ESP_LOGW(TAG, "Virtual efuses enabled: Not really burning eFuses");
@ -111,6 +111,7 @@ void esp_efuse_utility_burn_chip(void)
for (int num_block = EFUSE_BLK_MAX - 1; num_block >= EFUSE_BLK0; num_block--) { for (int num_block = EFUSE_BLK_MAX - 1; num_block >= EFUSE_BLK0; num_block--) {
for (uint32_t addr_wr_block = range_write_addr_blocks[num_block].start; addr_wr_block <= range_write_addr_blocks[num_block].end; addr_wr_block += 4) { for (uint32_t addr_wr_block = range_write_addr_blocks[num_block].start; addr_wr_block <= range_write_addr_blocks[num_block].end; addr_wr_block += 4) {
if (REG_READ(addr_wr_block) != 0) { if (REG_READ(addr_wr_block) != 0) {
ets_efuse_clear_program_registers();
if (esp_efuse_get_coding_scheme(num_block) == EFUSE_CODING_SCHEME_RS) { if (esp_efuse_get_coding_scheme(num_block) == EFUSE_CODING_SCHEME_RS) {
uint8_t block_rs[12]; uint8_t block_rs[12];
ets_efuse_rs_calculate((void *)range_write_addr_blocks[num_block].start, block_rs); ets_efuse_rs_calculate((void *)range_write_addr_blocks[num_block].start, block_rs);
@ -151,12 +152,13 @@ void esp_efuse_utility_burn_chip(void)
} }
} while ((!correct_written_data || coding_error_occurred) && repeat_burn_op++ < 3); } while ((!correct_written_data || coding_error_occurred) && repeat_burn_op++ < 3);
if (!correct_written_data) {
ESP_LOGE(TAG, "Written data are incorrect");
}
if (coding_error_occurred) { if (coding_error_occurred) {
ESP_LOGE(TAG, "Coding error occurred in block"); ESP_LOGE(TAG, "Coding error occurred in block");
} }
if (!correct_written_data) {
ESP_LOGE(TAG, "Written data are incorrect");
return ESP_FAIL;
}
break; break;
} }
} }
@ -164,6 +166,7 @@ void esp_efuse_utility_burn_chip(void)
} }
#endif // CONFIG_EFUSE_VIRTUAL #endif // CONFIG_EFUSE_VIRTUAL
esp_efuse_utility_reset(); esp_efuse_utility_reset();
return ESP_OK;
} }
// After esp_efuse_write.. functions EFUSE_BLKx_WDATAx_REG were filled is not coded values. // After esp_efuse_write.. functions EFUSE_BLKx_WDATAx_REG were filled is not coded values.

View File

@ -114,7 +114,7 @@ void esp_efuse_utility_clear_program_registers(void)
} }
// Burn values written to the efuse write registers // Burn values written to the efuse write registers
void esp_efuse_utility_burn_chip(void) esp_err_t esp_efuse_utility_burn_chip(void)
{ {
#ifdef CONFIG_EFUSE_VIRTUAL #ifdef CONFIG_EFUSE_VIRTUAL
ESP_LOGW(TAG, "Virtual efuses enabled: Not really burning eFuses"); ESP_LOGW(TAG, "Virtual efuses enabled: Not really burning eFuses");
@ -136,6 +136,7 @@ void esp_efuse_utility_burn_chip(void)
for (int num_block = EFUSE_BLK_MAX - 1; num_block >= EFUSE_BLK0; num_block--) { for (int num_block = EFUSE_BLK_MAX - 1; num_block >= EFUSE_BLK0; num_block--) {
for (uint32_t addr_wr_block = range_write_addr_blocks[num_block].start; addr_wr_block <= range_write_addr_blocks[num_block].end; addr_wr_block += 4) { for (uint32_t addr_wr_block = range_write_addr_blocks[num_block].start; addr_wr_block <= range_write_addr_blocks[num_block].end; addr_wr_block += 4) {
if (REG_READ(addr_wr_block) != 0) { if (REG_READ(addr_wr_block) != 0) {
ets_efuse_clear_program_registers();
if (esp_efuse_get_coding_scheme(num_block) == EFUSE_CODING_SCHEME_RS) { if (esp_efuse_get_coding_scheme(num_block) == EFUSE_CODING_SCHEME_RS) {
uint8_t block_rs[12]; uint8_t block_rs[12];
ets_efuse_rs_calculate((void *)range_write_addr_blocks[num_block].start, block_rs); ets_efuse_rs_calculate((void *)range_write_addr_blocks[num_block].start, block_rs);
@ -176,12 +177,13 @@ void esp_efuse_utility_burn_chip(void)
} }
} while ((!correct_written_data || coding_error_occurred) && repeat_burn_op++ < 3); } while ((!correct_written_data || coding_error_occurred) && repeat_burn_op++ < 3);
if (!correct_written_data) {
ESP_LOGE(TAG, "Written data are incorrect");
}
if (coding_error_occurred) { if (coding_error_occurred) {
ESP_LOGE(TAG, "Coding error occurred in block"); ESP_LOGE(TAG, "Coding error occurred in block");
} }
if (!correct_written_data) {
ESP_LOGE(TAG, "Written data are incorrect");
return ESP_FAIL;
}
break; break;
} }
} }
@ -189,6 +191,7 @@ void esp_efuse_utility_burn_chip(void)
} }
#endif // CONFIG_EFUSE_VIRTUAL #endif // CONFIG_EFUSE_VIRTUAL
esp_efuse_utility_reset(); esp_efuse_utility_reset();
return ESP_OK;
} }
// After esp_efuse_write.. functions EFUSE_BLKx_WDATAx_REG were filled is not coded values. // After esp_efuse_write.. functions EFUSE_BLKx_WDATAx_REG were filled is not coded values.

View File

@ -93,8 +93,12 @@ esp_err_t esp_efuse_utility_fill_buff(unsigned int num_reg, esp_efuse_block_t ef
* *
* If CONFIG_EFUSE_VIRTUAL is set, writing will not be performed. * If CONFIG_EFUSE_VIRTUAL is set, writing will not be performed.
* After the function is completed, the writing registers are cleared. * After the function is completed, the writing registers are cleared.
*
* @return
* - ESP_OK: The operation was successfully completed.
* - ESP_FAIL: The operation was not successfully completed.
*/ */
void esp_efuse_utility_burn_efuses(void); esp_err_t esp_efuse_utility_burn_efuses(void);
/** /**
* @brief Chip specific operations to perform the burn of values written to the efuse write registers. * @brief Chip specific operations to perform the burn of values written to the efuse write registers.
@ -103,8 +107,12 @@ void esp_efuse_utility_burn_efuses(void);
* *
* If CONFIG_EFUSE_VIRTUAL is set, writing will not be performed. * If CONFIG_EFUSE_VIRTUAL is set, writing will not be performed.
* After the function is completed, the writing registers are cleared. * After the function is completed, the writing registers are cleared.
*
* @return
* - ESP_OK: The operation was successfully completed.
* - ESP_FAIL: The operation was not successfully completed.
*/ */
void esp_efuse_utility_burn_chip(void); esp_err_t esp_efuse_utility_burn_chip(void);
/** /**
* @brief Returns the number of array elements for placing these "bits" in an array with the length of each element equal to "size_of_base". * @brief Returns the number of array elements for placing these "bits" in an array with the length of each element equal to "size_of_base".

View File

@ -94,7 +94,7 @@ esp_err_t esp_efuse_write_field_blob(const esp_efuse_desc_t* field[], const void
if (err == ESP_OK) { if (err == ESP_OK) {
err = esp_efuse_utility_apply_new_coding_scheme(); err = esp_efuse_utility_apply_new_coding_scheme();
if (err == ESP_OK) { if (err == ESP_OK) {
esp_efuse_utility_burn_efuses(); err = esp_efuse_utility_burn_efuses();
} }
} }
esp_efuse_utility_reset(); esp_efuse_utility_reset();
@ -129,7 +129,7 @@ esp_err_t esp_efuse_write_field_cnt(const esp_efuse_desc_t* field[], size_t cnt)
if (err == ESP_OK) { if (err == ESP_OK) {
err = esp_efuse_utility_apply_new_coding_scheme(); err = esp_efuse_utility_apply_new_coding_scheme();
if (err == ESP_OK) { if (err == ESP_OK) {
esp_efuse_utility_burn_efuses(); err = esp_efuse_utility_burn_efuses();
} }
} }
esp_efuse_utility_reset(); esp_efuse_utility_reset();
@ -194,7 +194,7 @@ esp_err_t esp_efuse_write_reg(esp_efuse_block_t blk, unsigned int num_reg, uint3
if (err == ESP_OK) { if (err == ESP_OK) {
err = esp_efuse_utility_apply_new_coding_scheme(); err = esp_efuse_utility_apply_new_coding_scheme();
if (err == ESP_OK) { if (err == ESP_OK) {
esp_efuse_utility_burn_efuses(); err = esp_efuse_utility_burn_efuses();
} }
} }
esp_efuse_utility_reset(); esp_efuse_utility_reset();
@ -277,7 +277,7 @@ esp_err_t esp_efuse_batch_write_commit(void)
if (--s_batch_writing_mode == 0) { if (--s_batch_writing_mode == 0) {
esp_err_t err = esp_efuse_utility_apply_new_coding_scheme(); esp_err_t err = esp_efuse_utility_apply_new_coding_scheme();
if (err == ESP_OK) { if (err == ESP_OK) {
esp_efuse_utility_burn_efuses(); err = esp_efuse_utility_burn_efuses();
ESP_LOGI(TAG, "Batch mode. Prepared fields are committed"); ESP_LOGI(TAG, "Batch mode. Prepared fields are committed");
} else { } else {
esp_efuse_utility_reset(); esp_efuse_utility_reset();

View File

@ -165,11 +165,12 @@ void esp_efuse_utility_reset(void)
} }
// Burn values written to the efuse write registers // Burn values written to the efuse write registers
void esp_efuse_utility_burn_efuses(void) esp_err_t esp_efuse_utility_burn_efuses(void)
{ {
++s_burn_counter; ++s_burn_counter;
esp_efuse_utility_burn_chip(); esp_err_t err = esp_efuse_utility_burn_chip();
++s_burn_counter; ++s_burn_counter;
return err;
} }
// Erase the virt_blocks array. // Erase the virt_blocks array.