Skip to content

Commit 83c0fdf

Browse files
author
Veijo Pesonen
committed
QSPIFBlockDevice: Sector Map Table parsing moved under SFDP
1 parent 7518a35 commit 83c0fdf

File tree

3 files changed

+55
-65
lines changed

3 files changed

+55
-65
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ int QSPIFBlockDevice::init()
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,
268268
_sfdp_info.smtbl.size);
269-
if (_sfdp_parse_sector_map_table(callback(this, &QSPIFBlockDevice::_qspi_send_read_sfdp_command),
270-
_sfdp_info.smtbl) < 0) {
269+
if (sfdp_parse_sector_map_table(callback(this, &QSPIFBlockDevice::_qspi_send_read_sfdp_command),
270+
_sfdp_info.smtbl) < 0) {
271271
tr_error("Init - Parse Sector Map Table Failed");
272272
status = QSPIF_BD_ERROR_PARSING_FAILED;
273273
goto exit_point;
@@ -1107,65 +1107,6 @@ 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,
1111-
sfdp_smtbl_info &smtbl)
1112-
{
1113-
uint8_t sector_map_table[SFDP_BASIC_PARAMS_TBL_SIZE]; /* Up To 20 DWORDS = 80 Bytes */
1114-
uint32_t tmp_region_size = 0;
1115-
int i_ind = 0;
1116-
int prev_boundary = 0;
1117-
// Default set to all type bits 1-4 are common
1118-
int min_common_erase_type_bits = SFDP_ERASE_BITMASK_ALL;
1119-
1120-
int status = sfdp_reader(smtbl.addr, sector_map_table, smtbl.size);
1121-
if (status < 0) {
1122-
tr_error("table retrieval failed");
1123-
return -1;
1124-
}
1125-
1126-
// Currently we support only Single Map Descriptor
1127-
if (!((sector_map_table[0] & 0x3) == 0x03) && (sector_map_table[1] == 0x0)) {
1128-
tr_error("Sector Map - Supporting Only Single! Map Descriptor (not map commands)");
1129-
return -1;
1130-
}
1131-
1132-
smtbl.region_cnt = sector_map_table[2] + 1;
1133-
if (smtbl.region_cnt > SFDP_SECTOR_MAP_MAX_REGIONS) {
1134-
tr_error("Supporting up to %d regions, current setup to %d regions - fail",
1135-
SFDP_SECTOR_MAP_MAX_REGIONS,
1136-
smtbl.regions_count);
1137-
return -1;
1138-
}
1139-
1140-
// Loop through Regions and set for each one: size, supported erase types, high boundary offset
1141-
// Calculate minimum Common Erase Type for all Regions
1142-
for (i_ind = 0; i_ind < smtbl.region_cnt; i_ind++) {
1143-
tmp_region_size = ((*((uint32_t *)&sector_map_table[(i_ind + 1) * 4])) >> 8) & 0x00FFFFFF; // bits 9-32
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;
1149-
}
1150-
1151-
// Calc minimum Common Erase Size from min_common_erase_type_bits
1152-
uint8_t type_mask = SFDP_ERASE_BITMASK_TYPE1;
1153-
for (i_ind = 0; i_ind < 4; i_ind++) {
1154-
if (min_common_erase_type_bits & type_mask) {
1155-
smtbl.regions_min_common_erase_size = smtbl.erase_type_size_arr[i_ind];
1156-
break;
1157-
}
1158-
type_mask = type_mask << 1;
1159-
}
1160-
1161-
if (i_ind == 4) {
1162-
// No common erase type was found between regions
1163-
smtbl.regions_min_common_erase_size = 0;
1164-
}
1165-
1166-
return 0;
1167-
}
1168-
11691110
int QSPIFBlockDevice::_handle_vendor_quirks()
11701111
{
11711112
uint8_t vendor_device_ids[QSPI_RDID_DATA_LENGTH] = {0};

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,6 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
319319
// Parse and Detect required Basic Parameters from Table
320320
int _sfdp_parse_basic_param_table(uint32_t basic_table_addr, size_t basic_table_size);
321321

322-
// 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,
324-
mbed::sfdp_smtbl_info &smtbl);
325-
326322
// Detect the soft reset protocol and reset - returns error if soft reset is not supported
327323
int _sfdp_detect_reset_protocol_and_reset(uint8_t *basic_param_table_ptr);
328324

drivers/source/SFDP.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,59 @@ int sfdp_parse_headers(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader,
136136

137137
int sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader, sfdp_smtbl_info &smtbl)
138138
{
139+
uint8_t sector_map_table[SFDP_BASIC_PARAMS_TBL_SIZE]; /* Up To 20 DWORDS = 80 Bytes */
140+
uint32_t tmp_region_size = 0;
141+
int i_ind = 0;
142+
int prev_boundary = 0;
143+
// Default set to all type bits 1-4 are common
144+
int min_common_erase_type_bits = SFDP_ERASE_BITMASK_ALL;
145+
146+
int status = sfdp_reader(smtbl.addr, sector_map_table, smtbl.size);
147+
if (status < 0) {
148+
tr_error("table retrieval failed");
149+
return -1;
150+
}
151+
152+
// Currently we support only Single Map Descriptor
153+
if (!((sector_map_table[0] & 0x3) == 0x03) && (sector_map_table[1] == 0x0)) {
154+
tr_error("Sector Map - Supporting Only Single! Map Descriptor (not map commands)");
155+
return -1;
156+
}
157+
158+
smtbl.region_cnt = sector_map_table[2] + 1;
159+
if (smtbl.region_cnt > SFDP_SECTOR_MAP_MAX_REGIONS) {
160+
tr_error("Supporting up to %d regions, current setup to %d regions - fail",
161+
SFDP_SECTOR_MAP_MAX_REGIONS,
162+
smtbl.region_cnt);
163+
return -1;
164+
}
165+
166+
// Loop through Regions and set for each one: size, supported erase types, high boundary offset
167+
// Calculate minimum Common Erase Type for all Regions
168+
for (i_ind = 0; i_ind < smtbl.region_cnt; i_ind++) {
169+
tmp_region_size = ((*((uint32_t *)&sector_map_table[(i_ind + 1) * 4])) >> 8) & 0x00FFFFFF; // bits 9-32
170+
smtbl.region_size[i_ind] = (tmp_region_size + 1) * 256; // Region size is 0 based multiple of 256 bytes;
171+
smtbl.region_erase_types_bitfld[i_ind] = sector_map_table[(i_ind + 1) * 4] & 0x0F; // bits 1-4
172+
min_common_erase_type_bits &= smtbl.region_erase_types_bitfld[i_ind];
173+
smtbl.region_high_boundary[i_ind] = (smtbl.region_size[i_ind] - 1) + prev_boundary;
174+
prev_boundary = smtbl.region_high_boundary[i_ind] + 1;
175+
}
176+
177+
// Calc minimum Common Erase Size from min_common_erase_type_bits
178+
uint8_t type_mask = SFDP_ERASE_BITMASK_TYPE1;
179+
for (i_ind = 0; i_ind < 4; i_ind++) {
180+
if (min_common_erase_type_bits & type_mask) {
181+
smtbl.regions_min_common_erase_size = smtbl.erase_type_size_arr[i_ind];
182+
break;
183+
}
184+
type_mask = type_mask << 1;
185+
}
186+
187+
if (i_ind == 4) {
188+
// No common erase type was found between regions
189+
smtbl.regions_min_common_erase_size = 0;
190+
}
191+
139192
return 0;
140193
}
141194

0 commit comments

Comments
 (0)