From 24af86071d1111f30978ed6b468894000a5b4f48 Mon Sep 17 00:00:00 2001 From: KonstantinKondrashov Date: Wed, 6 Apr 2022 22:39:17 +0800 Subject: [PATCH] efuse: Burn func can return an error esp_efuse_utility_burn_chip() --- components/efuse/esp32/esp_efuse_utility.c | 29 +++++++++++++++---- components/efuse/esp32c3/esp_efuse_utility.c | 11 ++++--- components/efuse/esp32h2/esp_efuse_utility.c | 11 ++++--- components/efuse/esp32s2/esp_efuse_utility.c | 11 ++++--- components/efuse/esp32s3/esp_efuse_utility.c | 11 ++++--- .../efuse/private_include/esp_efuse_utility.h | 12 ++++++-- components/efuse/src/esp_efuse_api.c | 8 ++--- components/efuse/src/esp_efuse_utility.c | 5 ++-- 8 files changed, 69 insertions(+), 29 deletions(-) diff --git a/components/efuse/esp32/esp_efuse_utility.c b/components/efuse/esp32/esp_efuse_utility.c index ff32ea2486..3be5190d82 100644 --- a/components/efuse/esp32/esp_efuse_utility.c +++ b/components/efuse/esp32/esp_efuse_utility.c @@ -102,14 +102,30 @@ static bool efuse_hal_is_coding_error_in_block(unsigned block) #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. 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 -void esp_efuse_utility_burn_chip(void) +esp_err_t esp_efuse_utility_burn_chip(void) { #ifdef CONFIG_EFUSE_VIRTUAL 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); 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) { + efuse_hal_clear_program_registers(); unsigned w_data_len; unsigned r_data_len; 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); - if (!correct_written_data) { - ESP_LOGE(TAG, "Written data are incorrect"); - } if (coding_error_occurred) { ESP_LOGE(TAG, "Coding error occurred in block"); } + if (!correct_written_data) { + ESP_LOGE(TAG, "Written data are incorrect"); + return ESP_FAIL; + } break; } } @@ -191,6 +209,7 @@ void esp_efuse_utility_burn_chip(void) } #endif // CONFIG_EFUSE_VIRTUAL 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) diff --git a/components/efuse/esp32c3/esp_efuse_utility.c b/components/efuse/esp32c3/esp_efuse_utility.c index 037e571c29..66c1e2af14 100644 --- a/components/efuse/esp32c3/esp_efuse_utility.c +++ b/components/efuse/esp32c3/esp_efuse_utility.c @@ -116,7 +116,7 @@ void esp_efuse_utility_clear_program_registers(void) } // 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 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 (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) { + ets_efuse_clear_program_registers(); if (esp_efuse_get_coding_scheme(num_block) == EFUSE_CODING_SCHEME_RS) { uint8_t block_rs[12]; 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); - if (!correct_written_data) { - ESP_LOGE(TAG, "Written data are incorrect"); - } if (coding_error_occurred) { ESP_LOGE(TAG, "Coding error occurred in block"); } + if (!correct_written_data) { + ESP_LOGE(TAG, "Written data are incorrect"); + return ESP_FAIL; + } break; } } @@ -191,6 +193,7 @@ void esp_efuse_utility_burn_chip(void) } #endif // CONFIG_EFUSE_VIRTUAL esp_efuse_utility_reset(); + return ESP_OK; } // After esp_efuse_write.. functions EFUSE_BLKx_WDATAx_REG were filled is not coded values. diff --git a/components/efuse/esp32h2/esp_efuse_utility.c b/components/efuse/esp32h2/esp_efuse_utility.c index c8c1fdde0f..13f772a534 100644 --- a/components/efuse/esp32h2/esp_efuse_utility.c +++ b/components/efuse/esp32h2/esp_efuse_utility.c @@ -96,7 +96,7 @@ void esp_efuse_utility_clear_program_registers(void) } // 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 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 (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) { + ets_efuse_clear_program_registers(); if (esp_efuse_get_coding_scheme(num_block) == EFUSE_CODING_SCHEME_RS) { uint8_t block_rs[12]; 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); - if (!correct_written_data) { - ESP_LOGE(TAG, "Written data are incorrect"); - } if (coding_error_occurred) { ESP_LOGE(TAG, "Coding error occurred in block"); } + if (!correct_written_data) { + ESP_LOGE(TAG, "Written data are incorrect"); + return ESP_FAIL; + } break; } } @@ -171,6 +173,7 @@ void esp_efuse_utility_burn_chip(void) } #endif // CONFIG_EFUSE_VIRTUAL esp_efuse_utility_reset(); + return ESP_OK; } // After esp_efuse_write.. functions EFUSE_BLKx_WDATAx_REG were filled is not coded values. diff --git a/components/efuse/esp32s2/esp_efuse_utility.c b/components/efuse/esp32s2/esp_efuse_utility.c index cc54729038..73477f46e8 100644 --- a/components/efuse/esp32s2/esp_efuse_utility.c +++ b/components/efuse/esp32s2/esp_efuse_utility.c @@ -89,7 +89,7 @@ void esp_efuse_utility_clear_program_registers(void) } // 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 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 (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) { + ets_efuse_clear_program_registers(); if (esp_efuse_get_coding_scheme(num_block) == EFUSE_CODING_SCHEME_RS) { uint8_t block_rs[12]; 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); - if (!correct_written_data) { - ESP_LOGE(TAG, "Written data are incorrect"); - } if (coding_error_occurred) { ESP_LOGE(TAG, "Coding error occurred in block"); } + if (!correct_written_data) { + ESP_LOGE(TAG, "Written data are incorrect"); + return ESP_FAIL; + } break; } } @@ -164,6 +166,7 @@ void esp_efuse_utility_burn_chip(void) } #endif // CONFIG_EFUSE_VIRTUAL esp_efuse_utility_reset(); + return ESP_OK; } // After esp_efuse_write.. functions EFUSE_BLKx_WDATAx_REG were filled is not coded values. diff --git a/components/efuse/esp32s3/esp_efuse_utility.c b/components/efuse/esp32s3/esp_efuse_utility.c index 8cd4bcecec..ff5ac656c4 100644 --- a/components/efuse/esp32s3/esp_efuse_utility.c +++ b/components/efuse/esp32s3/esp_efuse_utility.c @@ -114,7 +114,7 @@ void esp_efuse_utility_clear_program_registers(void) } // 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 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 (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) { + ets_efuse_clear_program_registers(); if (esp_efuse_get_coding_scheme(num_block) == EFUSE_CODING_SCHEME_RS) { uint8_t block_rs[12]; 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); - if (!correct_written_data) { - ESP_LOGE(TAG, "Written data are incorrect"); - } if (coding_error_occurred) { ESP_LOGE(TAG, "Coding error occurred in block"); } + if (!correct_written_data) { + ESP_LOGE(TAG, "Written data are incorrect"); + return ESP_FAIL; + } break; } } @@ -189,6 +191,7 @@ void esp_efuse_utility_burn_chip(void) } #endif // CONFIG_EFUSE_VIRTUAL esp_efuse_utility_reset(); + return ESP_OK; } // After esp_efuse_write.. functions EFUSE_BLKx_WDATAx_REG were filled is not coded values. diff --git a/components/efuse/private_include/esp_efuse_utility.h b/components/efuse/private_include/esp_efuse_utility.h index 710e1d618f..0fd026e3e7 100644 --- a/components/efuse/private_include/esp_efuse_utility.h +++ b/components/efuse/private_include/esp_efuse_utility.h @@ -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. * 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. @@ -103,8 +107,12 @@ void esp_efuse_utility_burn_efuses(void); * * If CONFIG_EFUSE_VIRTUAL is set, writing will not be performed. * 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". diff --git a/components/efuse/src/esp_efuse_api.c b/components/efuse/src/esp_efuse_api.c index a89205fc82..09c55bb50c 100644 --- a/components/efuse/src/esp_efuse_api.c +++ b/components/efuse/src/esp_efuse_api.c @@ -94,7 +94,7 @@ esp_err_t esp_efuse_write_field_blob(const esp_efuse_desc_t* field[], const void if (err == ESP_OK) { err = esp_efuse_utility_apply_new_coding_scheme(); if (err == ESP_OK) { - esp_efuse_utility_burn_efuses(); + err = esp_efuse_utility_burn_efuses(); } } 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) { err = esp_efuse_utility_apply_new_coding_scheme(); if (err == ESP_OK) { - esp_efuse_utility_burn_efuses(); + err = esp_efuse_utility_burn_efuses(); } } 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) { err = esp_efuse_utility_apply_new_coding_scheme(); if (err == ESP_OK) { - esp_efuse_utility_burn_efuses(); + err = esp_efuse_utility_burn_efuses(); } } esp_efuse_utility_reset(); @@ -277,7 +277,7 @@ esp_err_t esp_efuse_batch_write_commit(void) if (--s_batch_writing_mode == 0) { esp_err_t err = esp_efuse_utility_apply_new_coding_scheme(); if (err == ESP_OK) { - esp_efuse_utility_burn_efuses(); + err = esp_efuse_utility_burn_efuses(); ESP_LOGI(TAG, "Batch mode. Prepared fields are committed"); } else { esp_efuse_utility_reset(); diff --git a/components/efuse/src/esp_efuse_utility.c b/components/efuse/src/esp_efuse_utility.c index 903087ee28..ea50eb0a69 100644 --- a/components/efuse/src/esp_efuse_utility.c +++ b/components/efuse/src/esp_efuse_utility.c @@ -165,11 +165,12 @@ void esp_efuse_utility_reset(void) } // 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; - esp_efuse_utility_burn_chip(); + esp_err_t err = esp_efuse_utility_burn_chip(); ++s_burn_counter; + return err; } // Erase the virt_blocks array.