Skip to content

Commit 4f4ef60

Browse files
author
Veijo Pesonen
committed
SFDP: Sector Map Parameter Table naming improvements
1 parent f51600c commit 4f4ef60

File tree

6 files changed

+118
-118
lines changed

6 files changed

+118
-118
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.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;
155+
_sfdp_info.smptbl.regions_min_common_erase_size = 0;
156+
_sfdp_info.smptbl.region_cnt = 1;
157+
_sfdp_info.smptbl.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;
@@ -200,8 +200,8 @@ int QSPIFBlockDevice::init()
200200
int status = QSPIF_BD_ERROR_OK;
201201
_sfdp_info.bptbl.addr = 0x0;
202202
_sfdp_info.bptbl.size = 0;
203-
_sfdp_info.smtbl.addr = 0x0;
204-
_sfdp_info.smtbl.size = 0;
203+
_sfdp_info.smptbl.addr = 0x0;
204+
_sfdp_info.smptbl.size = 0;
205205

206206
_mutex.lock();
207207

@@ -259,15 +259,15 @@ int QSPIFBlockDevice::init()
259259
}
260260

261261
/**************************** Parse Sector Map Table ***********************************/
262-
_sfdp_info.smtbl.region_size[0] =
262+
_sfdp_info.smptbl.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.smptbl.region_high_boundary[0] = _device_size_bytes - 1;
265265

266-
if ((_sfdp_info.smtbl.addr != 0) && (0 != _sfdp_info.smtbl.size)) {
267-
tr_debug("Init - Parsing Sector Map Table - addr: 0x%lxh, Size: %d", _sfdp_info.smtbl.addr,
268-
_sfdp_info.smtbl.size);
266+
if ((_sfdp_info.smptbl.addr != 0) && (0 != _sfdp_info.smptbl.size)) {
267+
tr_debug("Init - Parsing Sector Map Table - addr: 0x%lxh, Size: %d", _sfdp_info.smptbl.addr,
268+
_sfdp_info.smptbl.size);
269269
if (sfdp_parse_sector_map_table(callback(this, &QSPIFBlockDevice::_qspi_send_read_sfdp_command),
270-
_sfdp_info.smtbl) < 0) {
270+
_sfdp_info.smptbl) < 0) {
271271
tr_error("Init - Parse Sector Map Table Failed");
272272
status = QSPIF_BD_ERROR_PARSING_FAILED;
273273
goto exit_point;
@@ -409,9 +409,9 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
409409
bool erase_failed = false;
410410
int status = QSPIF_BD_ERROR_OK;
411411
// Find region of erased address
412-
int region = _utils_find_addr_region(addr, _sfdp_info.smtbl);
412+
int region = _utils_find_addr_region(addr, _sfdp_info.smptbl);
413413
// Erase Types of selected region
414-
uint8_t bitfield = _sfdp_info.smtbl.region_erase_types_bitfld[region];
414+
uint8_t bitfield = _sfdp_info.smptbl.region_erase_types_bitfld[region];
415415

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

@@ -433,9 +433,9 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
433433
// Find the matching instruction and erase size chunk for that type.
434434
type = _utils_iterate_next_largest_erase_type(bitfield, size, (int)addr,
435435
region,
436-
_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];
436+
_sfdp_info.smptbl);
437+
cur_erase_inst = _sfdp_info.smptbl.erase_type_inst_arr[type];
438+
eu_size = _sfdp_info.smptbl.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.smptbl.region_high_boundary[region])) {
472472
// erase crossed to next region
473473
region++;
474-
bitfield = _sfdp_info.smtbl.region_erase_types_bitfld[region];
474+
bitfield = _sfdp_info.smptbl.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.regions_min_common_erase_size;
510+
return _sfdp_info.smptbl.regions_min_common_erase_size;
511511
}
512512

513513
const char *QSPIFBlockDevice::get_type() const
@@ -524,9 +524,9 @@ bd_size_t QSPIFBlockDevice::get_erase_size(bd_addr_t addr)
524524
}
525525

526526
// Find region of current address
527-
int region = _utils_find_addr_region(addr, _sfdp_info.smtbl);
527+
int region = _utils_find_addr_region(addr, _sfdp_info.smptbl);
528528

529-
int min_region_erase_size = _sfdp_info.smtbl.regions_min_common_erase_size;
529+
int min_region_erase_size = _sfdp_info.smptbl.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_bitfld[region] & type_mask) {
538+
if (_sfdp_info.smptbl.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.smptbl.erase_type_size_arr[i_ind];
541541
break;
542542
}
543543
type_mask = type_mask << 1;
@@ -661,7 +661,7 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
661661
bool shouldSetQuadEnable = false;
662662
bool is_qpi_mode = false;
663663

664-
if (_sfdp_detect_erase_types_inst_and_size(param_table, basic_table_size, _sfdp_info.smtbl) != 0) {
664+
if (_sfdp_detect_erase_types_inst_and_size(param_table, basic_table_size, _sfdp_info.smptbl) != 0) {
665665
tr_error("Init - Detecting erase types instructions/sizes failed");
666666
return -1;
667667
}
@@ -847,34 +847,34 @@ int QSPIFBlockDevice::_sfdp_detect_page_size(uint8_t *basic_param_table_ptr, int
847847

848848
int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr,
849849
int basic_param_table_size,
850-
sfdp_smtbl_info &smtbl)
850+
sfdp_smptbl_info &smptbl)
851851
{
852852
uint8_t bitfield = 0x01;
853853

854854
// Erase 4K Inst is taken either from param table legacy 4K erase or superseded by erase Instruction for type of size 4K
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
858+
smptbl.erase_type_inst_arr[i_ind] = QSPI_NO_INST; // Default for unsupported type
859+
smptbl.erase_type_size_arr[i_ind] = 1
860860
<< 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) {
861+
tr_debug("Erase Type(A) %d - Inst: 0x%xh, Size: %d", (i_ind + 1), smptbl.erase_type_inst_arr[i_ind],
862+
smptbl.erase_type_size_arr[i_ind]);
863+
if (smptbl.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
865+
smptbl.erase_type_inst_arr[i_ind] = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_ERASE_TYPE_1_BYTE
866866
+ 2 * i_ind];
867867

868-
if ((smtbl.erase_type_size_arr[i_ind] < smtbl.regions_min_common_erase_size)
869-
|| (smtbl.regions_min_common_erase_size == 0)) {
868+
if ((smptbl.erase_type_size_arr[i_ind] < smptbl.regions_min_common_erase_size)
869+
|| (smptbl.regions_min_common_erase_size == 0)) {
870870
//Set default minimal common erase for signal region
871-
smtbl.regions_min_common_erase_size = smtbl.erase_type_size_arr[i_ind];
871+
smptbl.regions_min_common_erase_size = smptbl.erase_type_size_arr[i_ind];
872872
}
873-
smtbl.region_erase_types_bitfld[0] |= bitfield; // If there's no region map, set region "0" types bitfield as default
873+
smptbl.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), smptbl.erase_type_inst_arr[i_ind],
877+
smptbl.erase_type_size_arr[i_ind]);
878878
bitfield = bitfield << 1;
879879
}
880880
} else {
@@ -1320,20 +1320,20 @@ bool QSPIFBlockDevice::_is_mem_ready()
13201320
/*********************************************/
13211321
/************* Utility Functions *************/
13221322
/*********************************************/
1323-
int QSPIFBlockDevice::_utils_find_addr_region(bd_size_t offset, sfdp_smtbl_info &smtbl)
1323+
int QSPIFBlockDevice::_utils_find_addr_region(bd_size_t offset, sfdp_smptbl_info &smptbl)
13241324
{
13251325
//Find the region to which the given offset belong to
1326-
if ((offset > _device_size_bytes) || (smtbl.region_cnt == 0)) {
1326+
if ((offset > _device_size_bytes) || (smptbl.region_cnt == 0)) {
13271327
return -1;
13281328
}
13291329

1330-
if (smtbl.region_cnt == 1) {
1330+
if (smptbl.region_cnt == 1) {
13311331
return 0;
13321332
}
13331333

1334-
for (int i_ind = smtbl.region_cnt - 2; i_ind >= 0; i_ind--) {
1334+
for (int i_ind = smptbl.region_cnt - 2; i_ind >= 0; i_ind--) {
13351335

1336-
if (offset > smtbl.region_high_boundary[i_ind]) {
1336+
if (offset > smptbl.region_high_boundary[i_ind]) {
13371337
return (i_ind + 1);
13381338
}
13391339
}
@@ -1345,7 +1345,7 @@ int QSPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t &bitfield,
13451345
int size,
13461346
int offset,
13471347
int region,
1348-
sfdp_smtbl_info &smtbl)
1348+
sfdp_smptbl_info &smptbl)
13491349
{
13501350
// Iterate on all supported Erase Types of the Region to which the offset belong to.
13511351
// Iterates from highest type to lowest
@@ -1355,9 +1355,9 @@ int QSPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t &bitfield,
13551355
for (i_ind = 3; i_ind >= 0; i_ind--) {
13561356
if (bitfield & type_mask) {
13571357
largest_erase_type = i_ind;
1358-
if ((size > (int)(smtbl.erase_type_size_arr[largest_erase_type])) &&
1359-
((_sfdp_info.smtbl.region_high_boundary[region] - offset)
1360-
> (int)(smtbl.erase_type_size_arr[largest_erase_type]))) {
1358+
if ((size > (int)(smptbl.erase_type_size_arr[largest_erase_type])) &&
1359+
((_sfdp_info.smptbl.region_high_boundary[region] - offset)
1360+
> (int)(smptbl.erase_type_size_arr[largest_erase_type]))) {
13611361
break;
13621362
} else {
13631363
bitfield &= ~type_mask;

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
338338
// Detect all supported erase types
339339
int _sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr,
340340
int basic_param_table_size,
341-
mbed::sfdp_smtbl_info &smtbl);
341+
mbed::sfdp_smptbl_info &smptbl);
342342

343343
// Detect 4-byte addressing mode and enable it if supported
344344
int _sfdp_detect_and_enable_4byte_addressing(uint8_t *basic_param_table_ptr, int basic_param_table_size);
@@ -350,15 +350,15 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
350350
/* Utilities Functions */
351351
/***********************/
352352
// Find the region to which the given offset belong to
353-
int _utils_find_addr_region(mbed::bd_size_t offset, mbed::sfdp_smtbl_info &smtbl);
353+
int _utils_find_addr_region(mbed::bd_size_t offset, mbed::sfdp_smptbl_info &smptbl);
354354

355355
// Iterate on all supported Erase Types of the Region to which the offset belong to.
356356
// Iterates from highest type to lowest
357357
int _utils_iterate_next_largest_erase_type(uint8_t &bitfield,
358358
int size,
359359
int offset,
360360
int region,
361-
mbed::sfdp_smtbl_info &smtbl);
361+
mbed::sfdp_smptbl_info &smptbl);
362362

363363
private:
364364
enum qspif_clear_protection_method_t {

0 commit comments

Comments
 (0)