Skip to content

Commit 7518a35

Browse files
author
Veijo Pesonen
committed
SFDP: data structures got refactored
1 parent 6108f38 commit 7518a35

File tree

4 files changed

+64
-56
lines changed

4 files changed

+64
-56
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ QSPIFBlockDevice::QSPIFBlockDevice(PinName io0, PinName io1, PinName io2, PinNam
152152
}
153153

154154
// Initialize parameters
155-
_sfdp_info.smtbl._min_common_erase_size = 0;
156-
_sfdp_info.smtbl._regions_count = 1;
157-
_sfdp_info.smtbl._region_erase_types_bitfield[0] = SFDP_ERASE_BITMASK_NONE;
155+
_sfdp_info.smtbl.regions_min_common_erase_size = 0;
156+
_sfdp_info.smtbl.region_cnt = 1;
157+
_sfdp_info.smtbl.region_erase_types_bitfld[0] = SFDP_ERASE_BITMASK_NONE;
158158

159159
// Until proven otherwise, assume no quad enable
160160
_quad_enable_register_idx = QSPIF_NO_QUAD_ENABLE;
@@ -259,9 +259,9 @@ int QSPIFBlockDevice::init()
259259
}
260260

261261
/**************************** Parse Sector Map Table ***********************************/
262-
_sfdp_info.smtbl._region_size_bytes[0] =
262+
_sfdp_info.smtbl.region_size[0] =
263263
_device_size_bytes; // If there's no region map, we have a single region sized the entire device size
264-
_sfdp_info.smtbl._region_high_boundary[0] = _device_size_bytes - 1;
264+
_sfdp_info.smtbl.region_high_boundary[0] = _device_size_bytes - 1;
265265

266266
if ((_sfdp_info.smtbl.addr != 0) && (0 != _sfdp_info.smtbl.size)) {
267267
tr_debug("Init - Parsing Sector Map Table - addr: 0x%lxh, Size: %d", _sfdp_info.smtbl.addr,
@@ -411,7 +411,7 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
411411
// Find region of erased address
412412
int region = _utils_find_addr_region(addr, _sfdp_info.smtbl);
413413
// Erase Types of selected region
414-
uint8_t bitfield = _sfdp_info.smtbl._region_erase_types_bitfield[region];
414+
uint8_t bitfield = _sfdp_info.smtbl.region_erase_types_bitfld[region];
415415

416416
tr_debug("Erase - addr: %llu, in_size: %llu", addr, in_size);
417417

@@ -434,8 +434,8 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
434434
type = _utils_iterate_next_largest_erase_type(bitfield, size, (int)addr,
435435
region,
436436
_sfdp_info.smtbl);
437-
cur_erase_inst = _sfdp_info.smtbl._erase_type_inst_arr[type];
438-
eu_size = _sfdp_info.smtbl._erase_type_size_arr[type];
437+
cur_erase_inst = _sfdp_info.smtbl.erase_type_inst_arr[type];
438+
eu_size = _sfdp_info.smtbl.erase_type_size_arr[type];
439439
} else {
440440
// Must use legacy 4k erase instruction
441441
cur_erase_inst = _legacy_erase_instruction;
@@ -468,10 +468,10 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
468468
addr += chunk;
469469
size -= chunk;
470470

471-
if ((size > 0) && (addr > _sfdp_info.smtbl._region_high_boundary[region])) {
471+
if ((size > 0) && (addr > _sfdp_info.smtbl.region_high_boundary[region])) {
472472
// erase crossed to next region
473473
region++;
474-
bitfield = _sfdp_info.smtbl._region_erase_types_bitfield[region];
474+
bitfield = _sfdp_info.smtbl.region_erase_types_bitfld[region];
475475
}
476476

477477
if (false == _is_mem_ready()) {
@@ -507,7 +507,7 @@ bd_size_t QSPIFBlockDevice::get_program_size() const
507507
bd_size_t QSPIFBlockDevice::get_erase_size() const
508508
{
509509
// return minimal erase size supported by all regions (0 if none exists)
510-
return _sfdp_info.smtbl._min_common_erase_size;
510+
return _sfdp_info.smtbl.regions_min_common_erase_size;
511511
}
512512

513513
const char *QSPIFBlockDevice::get_type() const
@@ -526,7 +526,7 @@ bd_size_t QSPIFBlockDevice::get_erase_size(bd_addr_t addr)
526526
// Find region of current address
527527
int region = _utils_find_addr_region(addr, _sfdp_info.smtbl);
528528

529-
int min_region_erase_size = _sfdp_info.smtbl._min_common_erase_size;
529+
int min_region_erase_size = _sfdp_info.smtbl.regions_min_common_erase_size;
530530
int8_t type_mask = SFDP_ERASE_BITMASK_TYPE1;
531531
int i_ind = 0;
532532

@@ -535,9 +535,9 @@ bd_size_t QSPIFBlockDevice::get_erase_size(bd_addr_t addr)
535535

536536
for (i_ind = 0; i_ind < 4; i_ind++) {
537537
// loop through erase types bitfield supported by region
538-
if (_sfdp_info.smtbl._region_erase_types_bitfield[region] & type_mask) {
538+
if (_sfdp_info.smtbl.region_erase_types_bitfld[region] & type_mask) {
539539

540-
min_region_erase_size = _sfdp_info.smtbl._erase_type_size_arr[i_ind];
540+
min_region_erase_size = _sfdp_info.smtbl.erase_type_size_arr[i_ind];
541541
break;
542542
}
543543
type_mask = type_mask << 1;
@@ -855,26 +855,26 @@ int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_para
855855
if (basic_param_table_size > QSPIF_BASIC_PARAM_TABLE_ERASE_TYPE_1_SIZE_BYTE) {
856856
// Loop Erase Types 1-4
857857
for (int i_ind = 0; i_ind < 4; i_ind++) {
858-
smtbl._erase_type_inst_arr[i_ind] = QSPI_NO_INST; // Default for unsupported type
859-
smtbl._erase_type_size_arr[i_ind] = 1
860-
<< basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_ERASE_TYPE_1_SIZE_BYTE + 2 * i_ind]; // Size is 2^N where N is the table value
861-
tr_debug("Erase Type(A) %d - Inst: 0x%xh, Size: %d", (i_ind + 1), smtbl._erase_type_inst_arr[i_ind],
862-
smtbl._erase_type_size_arr[i_ind]);
863-
if (smtbl._erase_type_size_arr[i_ind] > 1) {
858+
smtbl.erase_type_inst_arr[i_ind] = QSPI_NO_INST; // Default for unsupported type
859+
smtbl.erase_type_size_arr[i_ind] = 1
860+
<< basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_ERASE_TYPE_1_SIZE_BYTE + 2 * i_ind]; // Size is 2^N where N is the table value
861+
tr_debug("Erase Type(A) %d - Inst: 0x%xh, Size: %d", (i_ind + 1), smtbl.erase_type_inst_arr[i_ind],
862+
smtbl.erase_type_size_arr[i_ind]);
863+
if (smtbl.erase_type_size_arr[i_ind] > 1) {
864864
// if size==1 type is not supported
865-
smtbl._erase_type_inst_arr[i_ind] = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_ERASE_TYPE_1_BYTE
866-
+ 2 * i_ind];
865+
smtbl.erase_type_inst_arr[i_ind] = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_ERASE_TYPE_1_BYTE
866+
+ 2 * i_ind];
867867

868-
if ((smtbl._erase_type_size_arr[i_ind] < smtbl._min_common_erase_size)
869-
|| (smtbl._min_common_erase_size == 0)) {
868+
if ((smtbl.erase_type_size_arr[i_ind] < smtbl.regions_min_common_erase_size)
869+
|| (smtbl.regions_min_common_erase_size == 0)) {
870870
//Set default minimal common erase for signal region
871-
smtbl._min_common_erase_size = smtbl._erase_type_size_arr[i_ind];
871+
smtbl.regions_min_common_erase_size = smtbl.erase_type_size_arr[i_ind];
872872
}
873-
smtbl._region_erase_types_bitfield[0] |= bitfield; // If there's no region map, set region "0" types bitfield as default
873+
smtbl.region_erase_types_bitfld[0] |= bitfield; // If there's no region map, set region "0" types bitfield as default
874874
}
875875

876-
tr_debug("Erase Type %d - Inst: 0x%xh, Size: %d", (i_ind + 1), smtbl._erase_type_inst_arr[i_ind],
877-
smtbl._erase_type_size_arr[i_ind]);
876+
tr_debug("Erase Type %d - Inst: 0x%xh, Size: %d", (i_ind + 1), smtbl.erase_type_inst_arr[i_ind],
877+
smtbl.erase_type_size_arr[i_ind]);
878878
bitfield = bitfield << 1;
879879
}
880880
} else {
@@ -1107,7 +1107,7 @@ int QSPIFBlockDevice::_sfdp_detect_reset_protocol_and_reset(uint8_t *basic_param
11071107
return status;
11081108
}
11091109

1110-
int QSPIFBlockDevice::_sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void*, bd_size_t)> sfdp_reader,
1110+
int QSPIFBlockDevice::_sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader,
11111111
sfdp_smtbl_info &smtbl)
11121112
{
11131113
uint8_t sector_map_table[SFDP_BASIC_PARAMS_TBL_SIZE]; /* Up To 20 DWORDS = 80 Bytes */
@@ -1129,8 +1129,8 @@ int QSPIFBlockDevice::_sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void*
11291129
return -1;
11301130
}
11311131

1132-
smtbl._regions_count = sector_map_table[2] + 1;
1133-
if (smtbl._regions_count > SFDP_SECTOR_MAP_MAX_REGIONS) {
1132+
smtbl.region_cnt = sector_map_table[2] + 1;
1133+
if (smtbl.region_cnt > SFDP_SECTOR_MAP_MAX_REGIONS) {
11341134
tr_error("Supporting up to %d regions, current setup to %d regions - fail",
11351135
SFDP_SECTOR_MAP_MAX_REGIONS,
11361136
smtbl.regions_count);
@@ -1139,28 +1139,28 @@ int QSPIFBlockDevice::_sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void*
11391139

11401140
// Loop through Regions and set for each one: size, supported erase types, high boundary offset
11411141
// Calculate minimum Common Erase Type for all Regions
1142-
for (i_ind = 0; i_ind < smtbl._regions_count; i_ind++) {
1142+
for (i_ind = 0; i_ind < smtbl.region_cnt; i_ind++) {
11431143
tmp_region_size = ((*((uint32_t *)&sector_map_table[(i_ind + 1) * 4])) >> 8) & 0x00FFFFFF; // bits 9-32
1144-
smtbl._region_size_bytes[i_ind] = (tmp_region_size + 1) * 256; // Region size is 0 based multiple of 256 bytes;
1145-
smtbl._region_erase_types_bitfield[i_ind] = sector_map_table[(i_ind + 1) * 4] & 0x0F; // bits 1-4
1146-
min_common_erase_type_bits &= smtbl._region_erase_types_bitfield[i_ind];
1147-
smtbl._region_high_boundary[i_ind] = (smtbl._region_size_bytes[i_ind] - 1) + prev_boundary;
1148-
prev_boundary = smtbl._region_high_boundary[i_ind] + 1;
1144+
smtbl.region_size[i_ind] = (tmp_region_size + 1) * 256; // Region size is 0 based multiple of 256 bytes;
1145+
smtbl.region_erase_types_bitfld[i_ind] = sector_map_table[(i_ind + 1) * 4] & 0x0F; // bits 1-4
1146+
min_common_erase_type_bits &= smtbl.region_erase_types_bitfld[i_ind];
1147+
smtbl.region_high_boundary[i_ind] = (smtbl.region_size[i_ind] - 1) + prev_boundary;
1148+
prev_boundary = smtbl.region_high_boundary[i_ind] + 1;
11491149
}
11501150

11511151
// Calc minimum Common Erase Size from min_common_erase_type_bits
11521152
uint8_t type_mask = SFDP_ERASE_BITMASK_TYPE1;
11531153
for (i_ind = 0; i_ind < 4; i_ind++) {
11541154
if (min_common_erase_type_bits & type_mask) {
1155-
smtbl._min_common_erase_size = smtbl._erase_type_size_arr[i_ind];
1155+
smtbl.regions_min_common_erase_size = smtbl.erase_type_size_arr[i_ind];
11561156
break;
11571157
}
11581158
type_mask = type_mask << 1;
11591159
}
11601160

11611161
if (i_ind == 4) {
11621162
// No common erase type was found between regions
1163-
smtbl._min_common_erase_size = 0;
1163+
smtbl.regions_min_common_erase_size = 0;
11641164
}
11651165

11661166
return 0;
@@ -1382,17 +1382,17 @@ bool QSPIFBlockDevice::_is_mem_ready()
13821382
int QSPIFBlockDevice::_utils_find_addr_region(bd_size_t offset, sfdp_smtbl_info &smtbl)
13831383
{
13841384
//Find the region to which the given offset belong to
1385-
if ((offset > _device_size_bytes) || (smtbl._regions_count == 0)) {
1385+
if ((offset > _device_size_bytes) || (smtbl.region_cnt == 0)) {
13861386
return -1;
13871387
}
13881388

1389-
if (smtbl._regions_count == 1) {
1389+
if (smtbl.region_cnt == 1) {
13901390
return 0;
13911391
}
13921392

1393-
for (int i_ind = smtbl._regions_count - 2; i_ind >= 0; i_ind--) {
1393+
for (int i_ind = smtbl.region_cnt - 2; i_ind >= 0; i_ind--) {
13941394

1395-
if (offset > smtbl._region_high_boundary[i_ind]) {
1395+
if (offset > smtbl.region_high_boundary[i_ind]) {
13961396
return (i_ind + 1);
13971397
}
13981398
}
@@ -1414,9 +1414,9 @@ int QSPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t &bitfield,
14141414
for (i_ind = 3; i_ind >= 0; i_ind--) {
14151415
if (bitfield & type_mask) {
14161416
largest_erase_type = i_ind;
1417-
if ((size > (int)(smtbl._erase_type_size_arr[largest_erase_type])) &&
1418-
((_sfdp_info.smtbl._region_high_boundary[region] - offset)
1419-
> (int)(smtbl._erase_type_size_arr[largest_erase_type]))) {
1417+
if ((size > (int)(smtbl.erase_type_size_arr[largest_erase_type])) &&
1418+
((_sfdp_info.smtbl.region_high_boundary[region] - offset)
1419+
> (int)(smtbl.erase_type_size_arr[largest_erase_type]))) {
14201420
break;
14211421
} else {
14221422
bitfield &= ~type_mask;

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
320320
int _sfdp_parse_basic_param_table(uint32_t basic_table_addr, size_t basic_table_size);
321321

322322
// Parse and read information required by Regions Sector Map
323-
int _sfdp_parse_sector_map_table(mbed::Callback<int(mbed::bd_addr_t, void*, mbed::bd_size_t)> sfdp_reader,
323+
int _sfdp_parse_sector_map_table(mbed::Callback<int(mbed::bd_addr_t, void *, mbed::bd_size_t)> sfdp_reader,
324324
mbed::sfdp_smtbl_info &smtbl);
325325

326326
// Detect the soft reset protocol and reset - returns error if soft reset is not supported

drivers/internal/SFDP.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ struct sfdp_bptbl_info {
4747
struct sfdp_smtbl_info {
4848
uint32_t addr;
4949
size_t size;
50-
int _regions_count;
51-
int _region_size_bytes[SFDP_SECTOR_MAP_MAX_REGIONS];
50+
int region_cnt;
51+
int region_size[SFDP_SECTOR_MAP_MAX_REGIONS]; // [Bytes]
5252
//Each Region can support a bit combination of any of the 4 Erase Types
53-
uint8_t _region_erase_types_bitfield[SFDP_SECTOR_MAP_MAX_REGIONS];
54-
unsigned int _min_common_erase_size; // minimal common erase size for all regions (0 if none exists)
55-
bd_size_t _region_high_boundary[SFDP_SECTOR_MAP_MAX_REGIONS]; //region high address offset boundary
53+
uint8_t region_erase_types_bitfld[SFDP_SECTOR_MAP_MAX_REGIONS];
54+
unsigned int regions_min_common_erase_size; // minimal common erase size for all regions (0 if none exists)
55+
bd_size_t region_high_boundary[SFDP_SECTOR_MAP_MAX_REGIONS]; //region high address offset boundary
5656
// Up To 4 Erase Types are supported by SFDP (each with its own command Instruction and Size)
57-
int _erase_type_inst_arr[SFDP_MAX_NUM_OF_ERASE_TYPES];
58-
unsigned int _erase_type_size_arr[SFDP_MAX_NUM_OF_ERASE_TYPES];
57+
int erase_type_inst_arr[SFDP_MAX_NUM_OF_ERASE_TYPES];
58+
unsigned int erase_type_size_arr[SFDP_MAX_NUM_OF_ERASE_TYPES];
5959
};
6060

6161
/** SFDP Parameter Table addresses and sizes */
@@ -108,7 +108,15 @@ int sfdp_parse_single_param_header(sfdp_prm_hdr *parameter_header, sfdp_hdr_info
108108
*/
109109
int sfdp_parse_headers(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader, sfdp_hdr_info &hdr_info);
110110

111-
int sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void*, bd_size_t)> sfdp_reader, sfdp_smtbl_info &smtbl);
111+
/** Parse Sector Map Parameter Table
112+
* Retrieves the table from a device and parses the information contained by the table
113+
*
114+
* @param sfdp_reader Callback function used to read headers from a device
115+
* @param smtbl All information parsed from the table gets passed back on this structure
116+
*
117+
* @return 0 on success, negative error code on failure
118+
*/
119+
int sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader, sfdp_smtbl_info &smtbl);
112120

113121
} /* namespace mbed */
114122
#endif

drivers/source/SFDP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ int sfdp_parse_headers(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader,
134134
return 0;
135135
}
136136

137-
int sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void*, bd_size_t)> sfdp_reader, sfdp_smtbl_info &smtbl)
137+
int sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader, sfdp_smtbl_info &smtbl)
138138
{
139139
return 0;
140140
}

0 commit comments

Comments
 (0)