Import bootloader from esp-idf v3
[apeos.git] / components / bootloader_support / src / efuse.c
blob40bb6d451efde917b1922efccf6e1c9046016d22
1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include "esp_efuse.h"
15 #include "esp_log.h"
17 #define EFUSE_CONF_WRITE 0x5A5A /* efuse_pgm_op_ena, force no rd/wr disable */
18 #define EFUSE_CONF_READ 0x5AA5 /* efuse_read_op_ena, release force */
20 #define EFUSE_CMD_PGM 0x02
21 #define EFUSE_CMD_READ 0x01
23 static const char *TAG = "efuse";
25 void esp_efuse_burn_new_values(void)
27 REG_WRITE(EFUSE_CONF_REG, EFUSE_CONF_WRITE);
28 REG_WRITE(EFUSE_CMD_REG, EFUSE_CMD_PGM);
29 while (REG_READ(EFUSE_CMD_REG) != 0) {
31 REG_WRITE(EFUSE_CONF_REG, EFUSE_CONF_READ);
32 REG_WRITE(EFUSE_CMD_REG, EFUSE_CMD_READ);
33 while (REG_READ(EFUSE_CMD_REG) != 0) {
35 esp_efuse_reset();
38 void esp_efuse_reset(void)
40 REG_WRITE(EFUSE_CONF_REG, EFUSE_CONF_READ);
41 const uint32_t block_start[4] = { EFUSE_BLK0_WDATA0_REG, EFUSE_BLK1_WDATA0_REG,
42 EFUSE_BLK2_WDATA0_REG, EFUSE_BLK3_WDATA0_REG };
43 const uint32_t block_end[4] = { EFUSE_BLK0_WDATA6_REG, EFUSE_BLK1_WDATA7_REG,
44 EFUSE_BLK2_WDATA7_REG, EFUSE_BLK3_WDATA7_REG };
45 for (int i = 0; i < 4; i++) {
46 for (uint32_t r = block_start[i]; r <= block_end[i]; r+= 4) {
47 REG_WRITE(r, 0);
52 void esp_efuse_disable_basic_rom_console(void)
54 if ((REG_READ(EFUSE_BLK0_RDATA6_REG) & EFUSE_RD_CONSOLE_DEBUG_DISABLE) == 0) {
55 ESP_EARLY_LOGI(TAG, "Disable BASIC ROM Console fallback via efuse...");
56 esp_efuse_reset();
57 REG_WRITE(EFUSE_BLK0_WDATA6_REG, EFUSE_RD_CONSOLE_DEBUG_DISABLE);
58 esp_efuse_burn_new_values();