[Q/O/]SPIFBlockDevice: remove logic for unaligned erase, as alignment is checked

[Q/O/SPIFBlockDevice::erase() begin with an alignment check,
after which unaligned erases should not happen or be allowed.

If the erase address is not aligned to the value returned by
sfdp_iterate_next_largest_erase_type(), it indicates an
internal error in erase table parsing which should not be
hidden.
pull/13947/head
Lingkai Dong 2020-11-23 13:24:58 +00:00
parent 52627dbc59
commit 7525134532
3 changed files with 34 additions and 25 deletions

View File

@ -460,8 +460,6 @@ exit_point:
int OSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
{
int type = 0;
uint32_t offset = 0;
uint32_t chunk = 4096;
ospi_inst_t cur_erase_inst = OSPI_NO_INST;
int size = (int)in_size;
bool erase_failed = false;
@ -500,11 +498,16 @@ int OSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
cur_erase_inst = _sfdp_info.bptbl.legacy_erase_instruction;
eu_size = OSPIF_DEFAULT_SE_SIZE;
}
offset = addr % eu_size;
chunk = ((offset + size) < eu_size) ? size : (eu_size - offset);
tr_debug("Erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %lu ",
addr, size, cur_erase_inst, chunk);
if (addr % eu_size != 0 || addr + size < eu_size) {
// Should not happen if the erase table parsing
// and alignment checks were performed correctly
tr_error("internal error: address %llu not aligned to erase size %llu (type %d)",
addr, eu_size, type);
}
tr_debug("Erase - addr: %llu, size:%d, Inst: 0x%xh, erase size: %lu ",
addr, size, cur_erase_inst, eu_size);
tr_debug("Erase - Region: %d, Type:%d ",
region, type);
@ -524,8 +527,8 @@ int OSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
goto exit_point;
}
addr += chunk;
size -= chunk;
addr += eu_size;
size -= eu_size;
if ((size > 0) && (addr > _sfdp_info.smptbl.region_high_boundary[region])) {
// erase crossed to next region

View File

@ -388,8 +388,6 @@ exit_point:
int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
{
int type = 0;
uint32_t offset = 0;
uint32_t chunk = 4096;
qspi_inst_t cur_erase_inst = QSPI_NO_INST;
int size = (int)in_size;
bool erase_failed = false;
@ -427,11 +425,16 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
cur_erase_inst = _sfdp_info.bptbl.legacy_erase_instruction;
eu_size = QSPIF_DEFAULT_SE_SIZE;
}
offset = addr % eu_size;
chunk = ((offset + size) < eu_size) ? size : (eu_size - offset);
tr_debug("Erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %lu ",
addr, size, cur_erase_inst, chunk);
if (addr % eu_size != 0 || addr + size < eu_size) {
// Should not happen if the erase table parsing
// and alignment checks were performed correctly
tr_error("internal error: address %llu not aligned to erase size %llu (type %d)",
addr, eu_size, type);
}
tr_debug("Erase - addr: %llu, size:%d, Inst: 0x%xh, erase size: %lu ",
addr, size, cur_erase_inst, eu_size);
tr_debug("Erase - Region: %d, Type:%d ",
region, type);
@ -451,8 +454,8 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
goto exit_point;
}
addr += chunk;
size -= chunk;
addr += eu_size;
size -= eu_size;
if ((size > 0) && (addr > _sfdp_info.smptbl.region_high_boundary[region])) {
// erase crossed to next region

View File

@ -305,9 +305,8 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
}
int type = 0;
uint32_t offset = 0;
uint32_t chunk = 4096;
int cur_erase_inst = _erase_instruction;
unsigned int curr_erase_size = 0;
int size = (int)in_size;
bool erase_failed = false;
int status = SPIF_BD_ERROR_OK;
@ -339,12 +338,16 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
// find the matching instruction and erase size chunk for that type.
type = sfdp_iterate_next_largest_erase_type(bitfield, size, (unsigned int)addr, region, _sfdp_info.smptbl);
cur_erase_inst = _sfdp_info.smptbl.erase_type_inst_arr[type];
offset = addr % _sfdp_info.smptbl.erase_type_size_arr[type];
chunk = ((offset + size) < _sfdp_info.smptbl.erase_type_size_arr[type]) ?
size : (_sfdp_info.smptbl.erase_type_size_arr[type] - offset);
curr_erase_size = _sfdp_info.smptbl.erase_type_size_arr[type];
if (addr % curr_erase_size != 0 || addr + size < curr_erase_size) {
// Should not happen if the erase table parsing
// and alignment checks were performed correctly
tr_error("internal error: address %llu not aligned to erase size %llu (type %d)",
addr, curr_erase_size, type);
}
tr_debug("erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %" PRIu32 " , ",
addr, size, cur_erase_inst, chunk);
tr_debug("erase - addr: %llu, size:%d, Inst: 0x%xh, erase size: %" PRIu32 " , ",
addr, size, cur_erase_inst, curr_erase_size);
tr_debug("erase - Region: %d, Type:%d",
region, type);
@ -359,8 +362,8 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
_spi_send_erase_command(cur_erase_inst, addr, size);
addr += chunk;
size -= chunk;
addr += curr_erase_size;
size -= curr_erase_size;
if ((size > 0) && (addr > _sfdp_info.smptbl.region_high_boundary[region])) {
// erase crossed to next region