efuse: Add MAX_BLK_LEN define for changing len of field

Added docs, improved efuse_table_gen.py, and minor fixes

Checking the generated files for compliance with the coding scheme.
This commit is contained in:
Konstantin Kondrashov 2018-12-12 15:50:31 +08:00 committed by bot
parent 95b6273c7c
commit 1d7b901aeb
7 changed files with 126 additions and 35 deletions

View file

@ -166,7 +166,7 @@ class FuseTable(list):
def calc_md5(self):
txt_table = ''
for p in self:
txt_table += "%s %s %d %d %s" % (p.field_name, p.efuse_block, p.bit_start, p.bit_count, p.comment) + "\n"
txt_table += "%s %s %d %s %s" % (p.field_name, p.efuse_block, p.bit_start, str(p.get_bit_count()), p.comment) + "\n"
self.md5_digest_table = hashlib.md5(txt_table.encode('utf-8')).hexdigest()
def show_range_used_bits(self):
@ -194,6 +194,19 @@ class FuseTable(list):
rows += '\nNote: Not printed ranges are free for using. (bits in EFUSE_BLK0 are reserved for Espressif)\n'
return rows
def get_str_position_last_free_bit_in_blk(self, blk):
last_used_bit = 0
for p in self:
if p.efuse_block == blk:
if p.define is not None:
return p.get_bit_count()
else:
if last_used_bit < p.bit_start + p.bit_count:
last_used_bit = p.bit_start + p.bit_count
if last_used_bit == 0:
return None
return str(last_used_bit)
def to_header(self, file_name):
rows = [copyright]
rows += ["#ifdef __cplusplus",
@ -202,9 +215,10 @@ class FuseTable(list):
"",
"",
"// md5_digest_table " + self.md5_digest_table,
"// This file was generated automatically from the file " + file_name + ".csv. DO NOT CHANGE THIS FILE MANUALLY.",
"// If you want to change some fields, you need to change " + file_name + ".csv file then build system will generate this header file",
"// To show efuse_table run the command 'make show_efuse_table'.",
"// This file was generated from the file " + file_name + ".csv. DO NOT CHANGE THIS FILE MANUALLY.",
"// If you want to change some fields, you need to change " + file_name + ".csv file",
"// then run `efuse_common_table` or `efuse_custom_table` command it will generate this file.",
"// To show efuse_table run the command 'show_efuse_table'.",
"",
""]
@ -223,15 +237,54 @@ class FuseTable(list):
def to_c_file(self, file_name, debug):
rows = [copyright]
rows += ['#include "esp_efuse.h"',
rows += ['#include "sdkconfig.h"',
'#include "esp_efuse.h"',
'#include <assert.h>',
'#include "' + file_name + '.h"',
"",
"// md5_digest_table " + self.md5_digest_table,
"// This file was generated automatically from the file " + file_name + ".csv. DO NOT CHANGE THIS FILE MANUALLY.",
"// If you want to change some fields, you need to change " + file_name + ".csv file then build system will generate this header file",
"// To show efuse_table run the command 'make show_efuse_table'.",
"",
""]
"// This file was generated from the file " + file_name + ".csv. DO NOT CHANGE THIS FILE MANUALLY.",
"// If you want to change some fields, you need to change " + file_name + ".csv file",
"// then run `efuse_common_table` or `efuse_custom_table` command it will generate this file.",
"// To show efuse_table run the command 'show_efuse_table'."]
rows += [""]
rows += ["#if (CONFIG_EFUSE_CODE_SCHEME == 0)",
"#define MAX_BLK_LEN 256",
"#elif (CONFIG_EFUSE_CODE_SCHEME == 1)",
"#define MAX_BLK_LEN 192",
"#elif (CONFIG_EFUSE_CODE_SCHEME == 2)",
"#define MAX_BLK_LEN 128",
"#endif"]
rows += [""]
last_free_bit_blk1 = self.get_str_position_last_free_bit_in_blk("EFUSE_BLK1")
last_free_bit_blk2 = self.get_str_position_last_free_bit_in_blk("EFUSE_BLK2")
last_free_bit_blk3 = self.get_str_position_last_free_bit_in_blk("EFUSE_BLK3")
rows += ["// The last free bit in the block is counted over the entire file."]
if last_free_bit_blk1 is not None:
rows += ["#define LAST_FREE_BIT_BLK1 " + last_free_bit_blk1]
if last_free_bit_blk2 is not None:
rows += ["#define LAST_FREE_BIT_BLK2 " + last_free_bit_blk2]
if last_free_bit_blk3 is not None:
rows += ["#define LAST_FREE_BIT_BLK3 " + last_free_bit_blk3]
rows += [""]
if last_free_bit_blk1 is not None:
rows += ['_Static_assert(LAST_FREE_BIT_BLK1 <= MAX_BLK_LEN, "The eFuse table does not match the coding scheme. '
'Edit the table and restart the efuse_common_table or efuse_custom_table command to regenerate the new files.");']
if last_free_bit_blk2 is not None:
rows += ['_Static_assert(LAST_FREE_BIT_BLK2 <= MAX_BLK_LEN, "The eFuse table does not match the coding scheme. '
'Edit the table and restart the efuse_common_table or efuse_custom_table command to regenerate the new files.");']
if last_free_bit_blk3 is not None:
rows += ['_Static_assert(LAST_FREE_BIT_BLK3 <= MAX_BLK_LEN, "The eFuse table does not match the coding scheme. '
'Edit the table and restart the efuse_common_table or efuse_custom_table command to regenerate the new files.");']
rows += [""]
last_name = ''
for p in self:
@ -267,6 +320,7 @@ class FuseDefinition(object):
self.efuse_block = ""
self.bit_start = None
self.bit_count = None
self.define = None
self.comment = ""
@classmethod
@ -279,7 +333,7 @@ class FuseDefinition(object):
res.field_name = fields[0]
res.efuse_block = res.parse_block(fields[1])
res.bit_start = res.parse_num(fields[2])
res.bit_count = res.parse_num(fields[3])
res.bit_count = res.parse_bit_count(fields[3])
if res.bit_count is None or res.bit_count == 0:
raise InputError("Field bit_count can't be empty")
res.comment = fields[4]
@ -290,6 +344,13 @@ class FuseDefinition(object):
return None # Field will fill in default
return self.parse_int(strval)
def parse_bit_count(self, strval):
if strval == "MAX_BLK_LEN":
self.define = strval
return self.get_max_bits_of_block()
else:
return self.parse_num(strval)
def parse_int(self, v):
try:
return int(v, 0)
@ -343,13 +404,19 @@ class FuseDefinition(object):
return self.field_name + get_postfix(self.group)
def get_bit_count(self, check_define=True):
if check_define is True and self.define is not None:
return self.define
else:
return self.bit_count
def to_struct(self, debug):
start = " {"
if debug is True:
start = " {" + '"' + self.field_name + '" ,'
return ", ".join([start + self.efuse_block,
str(self.bit_start),
str(self.bit_count) + "}, \t // " + self.comment])
str(self.get_bit_count()) + "}, \t // " + self.comment])
def process_input_file(file, type_table):

View file

@ -12,14 +12,33 @@
// See the License for the specific language governing permissions and
// limitations under the License
#include "sdkconfig.h"
#include "esp_efuse.h"
#include <assert.h>
#include "esp_efuse_table.h"
// md5_digest_table 20db0282fe17fec59ea46716026f5fce
// This file was generated automatically from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY.
// If you want to change some fields, you need to change esp_efuse_table.csv file then build system will generate this header file
// To show efuse_table run the command 'make show_efuse_table'.
// md5_digest_table 840523b9e1313240e6102615e3a497a5
// This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY.
// If you want to change some fields, you need to change esp_efuse_table.csv file
// then run `efuse_common_table` or `efuse_custom_table` command it will generate this file.
// To show efuse_table run the command 'show_efuse_table'.
#if (CONFIG_EFUSE_CODE_SCHEME == 0)
#define MAX_BLK_LEN 256
#elif (CONFIG_EFUSE_CODE_SCHEME == 1)
#define MAX_BLK_LEN 192
#elif (CONFIG_EFUSE_CODE_SCHEME == 2)
#define MAX_BLK_LEN 128
#endif
// The last free bit in the block is counted over the entire file.
#define LAST_FREE_BIT_BLK1 MAX_BLK_LEN
#define LAST_FREE_BIT_BLK2 MAX_BLK_LEN
#define LAST_FREE_BIT_BLK3 192
_Static_assert(LAST_FREE_BIT_BLK1 <= MAX_BLK_LEN, "The eFuse table does not match the coding scheme. Edit the table and restart the efuse_common_table or efuse_custom_table command to regenerate the new files.");
_Static_assert(LAST_FREE_BIT_BLK2 <= MAX_BLK_LEN, "The eFuse table does not match the coding scheme. Edit the table and restart the efuse_common_table or efuse_custom_table command to regenerate the new files.");
_Static_assert(LAST_FREE_BIT_BLK3 <= MAX_BLK_LEN, "The eFuse table does not match the coding scheme. Edit the table and restart the efuse_common_table or efuse_custom_table command to regenerate the new files.");
static const esp_efuse_desc_t MAC_FACTORY[] = {
{EFUSE_BLK0, 72, 8}, // Factory MAC addr [0],
@ -47,7 +66,7 @@ static const esp_efuse_desc_t MAC_CUSTOM_VER[] = {
};
static const esp_efuse_desc_t SECURE_BOOT_KEY[] = {
{EFUSE_BLK2, 0, 256}, // Security boot. Key.,
{EFUSE_BLK2, 0, MAX_BLK_LEN}, // Security boot. Key. (length = "None" - 256. "3/4" - 192. "REPEAT" - 128),
};
static const esp_efuse_desc_t ABS_DONE_0[] = {
@ -55,7 +74,7 @@ static const esp_efuse_desc_t ABS_DONE_0[] = {
};
static const esp_efuse_desc_t ENCRYPT_FLASH_KEY[] = {
{EFUSE_BLK1, 0, 256}, // Flash encrypt. Key.,
{EFUSE_BLK1, 0, MAX_BLK_LEN}, // Flash encrypt. Key. (length = "None" - 256. "3/4" - 192. "REPEAT" - 128),
};
static const esp_efuse_desc_t ENCRYPT_CONFIG[] = {
@ -209,7 +228,7 @@ const esp_efuse_desc_t* ESP_EFUSE_MAC_CUSTOM_VER[] = {
};
const esp_efuse_desc_t* ESP_EFUSE_SECURE_BOOT_KEY[] = {
&SECURE_BOOT_KEY[0], // Security boot. Key.
&SECURE_BOOT_KEY[0], // Security boot. Key. (length = "None" - 256. "3/4" - 192. "REPEAT" - 128)
NULL
};
@ -219,7 +238,7 @@ const esp_efuse_desc_t* ESP_EFUSE_ABS_DONE_0[] = {
};
const esp_efuse_desc_t* ESP_EFUSE_ENCRYPT_FLASH_KEY[] = {
&ENCRYPT_FLASH_KEY[0], // Flash encrypt. Key.
&ENCRYPT_FLASH_KEY[0], // Flash encrypt. Key. (length = "None" - 256. "3/4" - 192. "REPEAT" - 128)
NULL
};

View file

@ -1,9 +1,10 @@
# field_name, | efuse_block, | bit_start, | bit_count, |comment #
# | (EFUSE_BLK0 | (0..255) | (1..256) | #
# | EFUSE_BLK1 | | | #
# | (EFUSE_BLK0 | (0..255) | (1..-) | #
# | EFUSE_BLK1 | |MAX_BLK_LEN*| #
# | EFUSE_BLK2 | | | #
# | EFUSE_BLK3) | | | #
##########################################################################
# *) The value MAX_BLK_LEN depends on CONFIG_EFUSE_CODE_SCHEME, will be replaced with "None" - 256. "3/4" - 192. "REPEAT" - 128.
# !!!!!!!!!!! #
# After editing this file, run the command manually "make efuse_common_table" or "idf.py efuse_common_table"
# this will generate new source files, next rebuild all the sources.
@ -27,12 +28,12 @@ MAC_CUSTOM_VER, EFUSE_BLK3, 184, 8, Custom MAC version
# Security boot #
#################
SECURE_BOOT_KEY, EFUSE_BLK2, 0, 256, Security boot. Key.
SECURE_BOOT_KEY, EFUSE_BLK2, 0, MAX_BLK_LEN, Security boot. Key. (length = "None" - 256. "3/4" - 192. "REPEAT" - 128)
ABS_DONE_0, EFUSE_BLK0, 196, 1, Secure boot is enabled for bootloader image. EFUSE_RD_ABS_DONE_0
# Flash encrypt #
#################
ENCRYPT_FLASH_KEY, EFUSE_BLK1, 0, 256, Flash encrypt. Key.
ENCRYPT_FLASH_KEY, EFUSE_BLK1, 0, MAX_BLK_LEN, Flash encrypt. Key. (length = "None" - 256. "3/4" - 192. "REPEAT" - 128)
ENCRYPT_CONFIG, EFUSE_BLK0, 188, 4, Flash encrypt. EFUSE_FLASH_CRYPT_CONFIG_M
DISABLE_DL_ENCRYPT, EFUSE_BLK0, 199, 1, Flash encrypt. Disable UART bootloader encryption. EFUSE_DISABLE_DL_ENCRYPT.

Can't render this file because it contains an unexpected character in line 8 and column 53.

View file

@ -17,10 +17,11 @@ extern "C" {
#endif
// md5_digest_table 20db0282fe17fec59ea46716026f5fce
// This file was generated automatically from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY.
// If you want to change some fields, you need to change esp_efuse_table.csv file then build system will generate this header file
// To show efuse_table run the command 'make show_efuse_table'.
// md5_digest_table 840523b9e1313240e6102615e3a497a5
// This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY.
// If you want to change some fields, you need to change esp_efuse_table.csv file
// then run `efuse_common_table` or `efuse_custom_table` command it will generate this file.
// To show efuse_table run the command 'show_efuse_table'.
extern const esp_efuse_desc_t* ESP_EFUSE_MAC_FACTORY[];

View file

@ -160,7 +160,7 @@ esp_err_t esp_efuse_set_read_protect(esp_efuse_block_t blk);
*
* @return Returns the number of bits used by field.
*/
esp_err_t esp_efuse_get_field_size(const esp_efuse_desc_t* field[]);
int esp_efuse_get_field_size(const esp_efuse_desc_t* field[]);
/**
* @brief Returns value of efuse register.

View file

@ -143,12 +143,13 @@ esp_err_t esp_efuse_set_read_protect(esp_efuse_block_t blk)
// get the length of the field in bits
int esp_efuse_get_field_size(const esp_efuse_desc_t* field[])
{
assert(field != NULL);
int bits_counter = 0;
int i = 0;
while (field[i] != NULL) {
bits_counter += field[i]->bit_count;
++i;
if (field != NULL) {
int i = 0;
while (field[i] != NULL) {
bits_counter += field[i]->bit_count;
++i;
}
}
return bits_counter;
}

View file

@ -58,7 +58,7 @@ bit_start
Start bit number (0..255). The bit_start field can be omitted. In this case, it will be set to bit_start + bit_count from the previous record, if it has the same efuse_block. Otherwise (if efuse_block is different, or this is the first entry), an error will be generated.
bit_count
The number of bits to use in this field (1..256). This parameter can not be omitted.
The number of bits to use in this field (1..-). This parameter can not be omitted. This field also may be ``MAX_BLK_LEN`` in this case, the field length will have the maximum block length, taking into account the coding scheme (applicable for ``ESP_EFUSE_SECURE_BOOT_KEY`` and ``ESP_EFUSE_ENCRYPT_FLASH_KEY`` fields). The value ``MAX_BLK_LEN`` depends on :envvar:`CONFIG_EFUSE_CODE_SCHEME`, will be replaced with "None" - 256, "3/4" - 192, "REPEAT" - 128.
comment
This param is using for comment field, it also move to C-header file. The comment field can be omitted.
@ -146,6 +146,8 @@ Also, 3/4 coding scheme imposes restrictions on writing bits belonging to one co
It turns out that only one field can be written into one coding unit. Repeated rewriting in one coding unit is prohibited. But if the record was made in advance or through a :cpp:func:`esp_efuse_write_block` function, then reading the fields belonging to one coding unit is possible.
After changing the coding scheme, run ``efuse_common_table`` and ``efuse_custom_table`` commands to check the tables of the new coding scheme.
eFuse API
---------