mirror of https://github.com/ARMmbed/mbed-os.git
[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
parent
52627dbc59
commit
7525134532
|
@ -460,8 +460,6 @@ exit_point:
|
||||||
int OSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
int OSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
||||||
{
|
{
|
||||||
int type = 0;
|
int type = 0;
|
||||||
uint32_t offset = 0;
|
|
||||||
uint32_t chunk = 4096;
|
|
||||||
ospi_inst_t cur_erase_inst = OSPI_NO_INST;
|
ospi_inst_t cur_erase_inst = OSPI_NO_INST;
|
||||||
int size = (int)in_size;
|
int size = (int)in_size;
|
||||||
bool erase_failed = false;
|
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;
|
cur_erase_inst = _sfdp_info.bptbl.legacy_erase_instruction;
|
||||||
eu_size = OSPIF_DEFAULT_SE_SIZE;
|
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 ",
|
if (addr % eu_size != 0 || addr + size < eu_size) {
|
||||||
addr, size, cur_erase_inst, chunk);
|
// 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 ",
|
tr_debug("Erase - Region: %d, Type:%d ",
|
||||||
region, type);
|
region, type);
|
||||||
|
|
||||||
|
@ -524,8 +527,8 @@ int OSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
||||||
goto exit_point;
|
goto exit_point;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr += chunk;
|
addr += eu_size;
|
||||||
size -= chunk;
|
size -= eu_size;
|
||||||
|
|
||||||
if ((size > 0) && (addr > _sfdp_info.smptbl.region_high_boundary[region])) {
|
if ((size > 0) && (addr > _sfdp_info.smptbl.region_high_boundary[region])) {
|
||||||
// erase crossed to next region
|
// erase crossed to next region
|
||||||
|
|
|
@ -388,8 +388,6 @@ exit_point:
|
||||||
int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
||||||
{
|
{
|
||||||
int type = 0;
|
int type = 0;
|
||||||
uint32_t offset = 0;
|
|
||||||
uint32_t chunk = 4096;
|
|
||||||
qspi_inst_t cur_erase_inst = QSPI_NO_INST;
|
qspi_inst_t cur_erase_inst = QSPI_NO_INST;
|
||||||
int size = (int)in_size;
|
int size = (int)in_size;
|
||||||
bool erase_failed = false;
|
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;
|
cur_erase_inst = _sfdp_info.bptbl.legacy_erase_instruction;
|
||||||
eu_size = QSPIF_DEFAULT_SE_SIZE;
|
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 ",
|
if (addr % eu_size != 0 || addr + size < eu_size) {
|
||||||
addr, size, cur_erase_inst, chunk);
|
// 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 ",
|
tr_debug("Erase - Region: %d, Type:%d ",
|
||||||
region, type);
|
region, type);
|
||||||
|
|
||||||
|
@ -451,8 +454,8 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
||||||
goto exit_point;
|
goto exit_point;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr += chunk;
|
addr += eu_size;
|
||||||
size -= chunk;
|
size -= eu_size;
|
||||||
|
|
||||||
if ((size > 0) && (addr > _sfdp_info.smptbl.region_high_boundary[region])) {
|
if ((size > 0) && (addr > _sfdp_info.smptbl.region_high_boundary[region])) {
|
||||||
// erase crossed to next region
|
// erase crossed to next region
|
||||||
|
|
|
@ -305,9 +305,8 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
int type = 0;
|
int type = 0;
|
||||||
uint32_t offset = 0;
|
|
||||||
uint32_t chunk = 4096;
|
|
||||||
int cur_erase_inst = _erase_instruction;
|
int cur_erase_inst = _erase_instruction;
|
||||||
|
unsigned int curr_erase_size = 0;
|
||||||
int size = (int)in_size;
|
int size = (int)in_size;
|
||||||
bool erase_failed = false;
|
bool erase_failed = false;
|
||||||
int status = SPIF_BD_ERROR_OK;
|
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.
|
// 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);
|
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];
|
cur_erase_inst = _sfdp_info.smptbl.erase_type_inst_arr[type];
|
||||||
offset = addr % _sfdp_info.smptbl.erase_type_size_arr[type];
|
curr_erase_size = _sfdp_info.smptbl.erase_type_size_arr[type];
|
||||||
chunk = ((offset + size) < _sfdp_info.smptbl.erase_type_size_arr[type]) ?
|
if (addr % curr_erase_size != 0 || addr + size < curr_erase_size) {
|
||||||
size : (_sfdp_info.smptbl.erase_type_size_arr[type] - offset);
|
// 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 " , ",
|
tr_debug("erase - addr: %llu, size:%d, Inst: 0x%xh, erase size: %" PRIu32 " , ",
|
||||||
addr, size, cur_erase_inst, chunk);
|
addr, size, cur_erase_inst, curr_erase_size);
|
||||||
tr_debug("erase - Region: %d, Type:%d",
|
tr_debug("erase - Region: %d, Type:%d",
|
||||||
region, type);
|
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);
|
_spi_send_erase_command(cur_erase_inst, addr, size);
|
||||||
|
|
||||||
addr += chunk;
|
addr += curr_erase_size;
|
||||||
size -= chunk;
|
size -= curr_erase_size;
|
||||||
|
|
||||||
if ((size > 0) && (addr > _sfdp_info.smptbl.region_high_boundary[region])) {
|
if ((size > 0) && (addr > _sfdp_info.smptbl.region_high_boundary[region])) {
|
||||||
// erase crossed to next region
|
// erase crossed to next region
|
||||||
|
|
Loading…
Reference in New Issue