flash/nor/nrf5: refactor sector allocation to use alloc_block_array()
Change-Id: Ied8ea917cec492fc6bb8836a92d8c4ceaf3b499b Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: http://openocd.zylin.com/4865 Tested-by: jenkins
This commit is contained in:
parent
b2dbaf9e15
commit
e3fb76374c
|
@ -748,46 +748,31 @@ static int nrf5_probe(struct flash_bank *bank)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bank->base == NRF5_FLASH_BASE) {
|
if (bank->base == NRF5_FLASH_BASE) {
|
||||||
bank->num_sectors = num_sectors;
|
|
||||||
bank->size = num_sectors * flash_page_size;
|
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (chip->spec && chip->flash_size_kb != chip->spec->flash_size_kb)
|
if (chip->spec && chip->flash_size_kb != chip->spec->flash_size_kb)
|
||||||
LOG_WARNING("Chip's reported Flash capacity does not match expected one");
|
LOG_WARNING("Chip's reported Flash capacity does not match expected one");
|
||||||
if (chip->ficr_info_valid && chip->flash_size_kb != chip->ficr_info.flash)
|
if (chip->ficr_info_valid && chip->flash_size_kb != chip->ficr_info.flash)
|
||||||
LOG_WARNING("Chip's reported Flash capacity does not match FICR INFO.FLASH");
|
LOG_WARNING("Chip's reported Flash capacity does not match FICR INFO.FLASH");
|
||||||
|
|
||||||
bank->sectors = calloc(bank->num_sectors,
|
bank->num_sectors = num_sectors;
|
||||||
sizeof((bank->sectors)[0]));
|
bank->size = num_sectors * flash_page_size;
|
||||||
|
|
||||||
|
bank->sectors = alloc_block_array(0, flash_page_size, num_sectors);
|
||||||
if (!bank->sectors)
|
if (!bank->sectors)
|
||||||
return ERROR_FLASH_BANK_NOT_PROBED;
|
return ERROR_FAIL;
|
||||||
|
|
||||||
/* Fill out the sector information: all NRF5 sectors are the same size and
|
|
||||||
* there is always a fixed number of them. */
|
|
||||||
for (int i = 0; i < bank->num_sectors; i++) {
|
|
||||||
bank->sectors[i].size = flash_page_size;
|
|
||||||
bank->sectors[i].offset = i * flash_page_size;
|
|
||||||
|
|
||||||
/* mark as unknown */
|
|
||||||
bank->sectors[i].is_erased = -1;
|
|
||||||
bank->sectors[i].is_protected = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
nrf5_protect_check(bank);
|
nrf5_protect_check(bank);
|
||||||
|
|
||||||
chip->bank[0].probed = true;
|
chip->bank[0].probed = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
bank->size = flash_page_size;
|
|
||||||
bank->num_sectors = 1;
|
bank->num_sectors = 1;
|
||||||
bank->sectors = calloc(bank->num_sectors,
|
bank->size = flash_page_size;
|
||||||
sizeof((bank->sectors)[0]));
|
|
||||||
|
bank->sectors = alloc_block_array(0, flash_page_size, num_sectors);
|
||||||
if (!bank->sectors)
|
if (!bank->sectors)
|
||||||
return ERROR_FLASH_BANK_NOT_PROBED;
|
return ERROR_FAIL;
|
||||||
|
|
||||||
bank->sectors[0].size = bank->size;
|
|
||||||
bank->sectors[0].offset = 0;
|
|
||||||
|
|
||||||
bank->sectors[0].is_erased = 0;
|
|
||||||
bank->sectors[0].is_protected = 0;
|
bank->sectors[0].is_protected = 0;
|
||||||
|
|
||||||
chip->bank[1].probed = true;
|
chip->bank[1].probed = true;
|
||||||
|
|
Loading…
Reference in New Issue