build: cleanup src/flash/nor directory
Change-Id: Ic299de969ce566282c055ba4dd8b94892c4c4311 Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk> Reviewed-on: http://openocd.zylin.com/420 Tested-by: jenkins
This commit is contained in:
+97
-118
@@ -20,6 +20,7 @@
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
@@ -32,12 +33,12 @@ struct kinetis_flash_bank {
|
||||
};
|
||||
|
||||
static int kinetis_get_master_bank(struct flash_bank *bank,
|
||||
struct flash_bank **master_bank)
|
||||
struct flash_bank **master_bank)
|
||||
{
|
||||
*master_bank = get_flash_bank_by_name_noprobe(bank->name);
|
||||
if (*master_bank == NULL) {
|
||||
LOG_ERROR("master flash bank '%s' does not exist",
|
||||
(char *)bank->driver_priv);
|
||||
(char *)bank->driver_priv);
|
||||
return ERROR_FLASH_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
@@ -51,9 +52,8 @@ static int kinetis_update_bank_info(struct flash_bank *bank)
|
||||
|
||||
result = kinetis_get_master_bank(bank, &master_bank);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* update the info we do not have */
|
||||
bank->size = master_bank->size;
|
||||
@@ -69,9 +69,8 @@ FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command)
|
||||
{
|
||||
struct kinetis_flash_bank *bank_info;
|
||||
|
||||
if (CMD_ARGC < 6) {
|
||||
if (CMD_ARGC < 6)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
LOG_INFO("add flash_bank kinetis %s", bank->name);
|
||||
|
||||
@@ -85,16 +84,15 @@ FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command)
|
||||
}
|
||||
|
||||
static int kinetis_protect(struct flash_bank *bank, int set, int first,
|
||||
int last)
|
||||
int last)
|
||||
{
|
||||
int result;
|
||||
struct flash_bank *master_bank;
|
||||
|
||||
result = kinetis_get_master_bank(bank, &master_bank);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
LOG_WARNING("kinetis_protect not supported yet");
|
||||
|
||||
@@ -121,16 +119,14 @@ static int kinetis_protect_check(struct flash_bank *bank)
|
||||
|
||||
result = kinetis_get_master_bank(bank, &master_bank);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* read protection register FTFL_FPROT */
|
||||
result = target_read_memory(bank->target, 0x40020010, 1, 4, buffer);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
fprot = target_buffer_get_u32(bank->target, buffer);
|
||||
|
||||
@@ -157,7 +153,7 @@ static int kinetis_protect_check(struct flash_bank *bank)
|
||||
}
|
||||
|
||||
static int kinetis_ftfl_command(struct flash_bank *bank, uint32_t w0,
|
||||
uint32_t w1, uint32_t w2)
|
||||
uint32_t w1, uint32_t w2)
|
||||
{
|
||||
uint8_t buffer[12];
|
||||
int result, i;
|
||||
@@ -165,11 +161,10 @@ static int kinetis_ftfl_command(struct flash_bank *bank, uint32_t w0,
|
||||
/* wait for done */
|
||||
for (i = 0; i < 50; i++) {
|
||||
result =
|
||||
target_read_memory(bank->target, 0x40020000, 1, 1, buffer);
|
||||
target_read_memory(bank->target, 0x40020000, 1, 1, buffer);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
if (buffer[0] & 0x80)
|
||||
break;
|
||||
@@ -181,10 +176,9 @@ static int kinetis_ftfl_command(struct flash_bank *bank, uint32_t w0,
|
||||
/* reset error flags */
|
||||
buffer[0] = 0x30;
|
||||
result =
|
||||
target_write_memory(bank->target, 0x40020000, 1, 1, buffer);
|
||||
if (result != ERROR_OK) {
|
||||
target_write_memory(bank->target, 0x40020000, 1, 1, buffer);
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
target_buffer_set_u32(bank->target, buffer, w0);
|
||||
@@ -193,25 +187,22 @@ static int kinetis_ftfl_command(struct flash_bank *bank, uint32_t w0,
|
||||
|
||||
result = target_write_memory(bank->target, 0x40020004, 4, 3, buffer);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* start command */
|
||||
buffer[0] = 0x80;
|
||||
result = target_write_memory(bank->target, 0x40020000, 1, 1, buffer);
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* wait for done */
|
||||
for (i = 0; i < 50; i++) {
|
||||
result =
|
||||
target_read_memory(bank->target, 0x40020000, 1, 1, buffer);
|
||||
target_read_memory(bank->target, 0x40020000, 1, 1, buffer);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
if (buffer[0] & 0x80)
|
||||
break;
|
||||
@@ -221,8 +212,8 @@ static int kinetis_ftfl_command(struct flash_bank *bank, uint32_t w0,
|
||||
|
||||
if (buffer[0] != 0x80) {
|
||||
LOG_ERROR
|
||||
("ftfl command failed FSTAT: %02X W0: %08X W1: %08X W2: %08X",
|
||||
buffer[0], w0, w1, w2);
|
||||
("ftfl command failed FSTAT: %02X W0: %08X W1: %08X W2: %08X",
|
||||
buffer[0], w0, w1, w2);
|
||||
|
||||
return ERROR_FLASH_OPERATION_FAILED;
|
||||
}
|
||||
@@ -243,13 +234,11 @@ static int kinetis_erase(struct flash_bank *bank, int first, int last)
|
||||
|
||||
result = kinetis_get_master_bank(bank, &master_bank);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((first > bank->num_sectors) || (last > bank->num_sectors)) {
|
||||
if ((first > bank->num_sectors) || (last > bank->num_sectors))
|
||||
return ERROR_FLASH_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
for (i = first; i <= last; i++) {
|
||||
/* set command and sector address */
|
||||
@@ -267,20 +256,20 @@ static int kinetis_erase(struct flash_bank *bank, int first, int last)
|
||||
|
||||
if (first == 0) {
|
||||
LOG_WARNING
|
||||
("flash configuration field erased, please reset the device");
|
||||
("flash configuration field erased, please reset the device");
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
static int kinetis_write(struct flash_bank *bank, uint8_t * buffer,
|
||||
uint32_t offset, uint32_t count)
|
||||
static int kinetis_write(struct flash_bank *bank, uint8_t *buffer,
|
||||
uint32_t offset, uint32_t count)
|
||||
{
|
||||
struct flash_bank *master_bank;
|
||||
unsigned int i, result, fallback = 0, nvm = 0;
|
||||
uint8_t buf[8];
|
||||
uint32_t wc, w0 = 0, w1 = 0, w2 = 0;
|
||||
struct kinetis_flash_bank * kbank = (struct kinetis_flash_bank *)
|
||||
struct kinetis_flash_bank *kbank = (struct kinetis_flash_bank *)
|
||||
bank->driver_priv;
|
||||
|
||||
if (bank->target->state != TARGET_HALTED) {
|
||||
@@ -290,9 +279,8 @@ static int kinetis_write(struct flash_bank *bank, uint8_t * buffer,
|
||||
|
||||
result = kinetis_get_master_bank(bank, &master_bank);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
if (offset >= kbank->nvm_start)
|
||||
nvm = 1;
|
||||
@@ -327,8 +315,8 @@ static int kinetis_write(struct flash_bank *bank, uint8_t * buffer,
|
||||
/* fallback to longword write */
|
||||
fallback = 1;
|
||||
|
||||
LOG_WARNING("ram not ready, fallback to slow longword write (FCNFG: %02X)",
|
||||
buf[0]);
|
||||
LOG_WARNING("ram not ready, fallback to slow longword write (FCNFG: %02X)",
|
||||
buf[0]);
|
||||
}
|
||||
} else {
|
||||
LOG_DEBUG("flash write into PFLASH @08%X", offset);
|
||||
@@ -347,12 +335,12 @@ static int kinetis_write(struct flash_bank *bank, uint8_t * buffer,
|
||||
}
|
||||
|
||||
LOG_DEBUG("write section @ %08X with length %d",
|
||||
offset + i, wc * 4);
|
||||
offset + i, wc * 4);
|
||||
|
||||
/* write data to flexram */
|
||||
result =
|
||||
target_write_memory(bank->target, 0x14000000, 4, wc,
|
||||
buffer + i);
|
||||
target_write_memory(bank->target, 0x14000000, 4, wc,
|
||||
buffer + i);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
LOG_ERROR("target_write_memory failed");
|
||||
@@ -366,9 +354,8 @@ static int kinetis_write(struct flash_bank *bank, uint8_t * buffer,
|
||||
|
||||
result = kinetis_ftfl_command(bank, w0, w1, w2);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return ERROR_FLASH_OPERATION_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* program longword command */
|
||||
@@ -381,9 +368,8 @@ static int kinetis_write(struct flash_bank *bank, uint8_t * buffer,
|
||||
|
||||
result = kinetis_ftfl_command(bank, w0, w1, w2);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return ERROR_FLASH_OPERATION_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,97 +391,93 @@ static int kinetis_probe(struct flash_bank *bank)
|
||||
|
||||
result = kinetis_get_master_bank(bank, &master_bank);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
result = target_read_memory(bank->target, 0x40048024, 1, 4, buf);
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
sim_sdid = target_buffer_get_u32(bank->target, buf);
|
||||
result = target_read_memory(bank->target, 0x4004804c, 1, 4, buf);
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
sim_fcfg1 = target_buffer_get_u32(bank->target, buf);
|
||||
result = target_read_memory(bank->target, 0x40048050, 1, 4, buf);
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
sim_fcfg2 = target_buffer_get_u32(bank->target, buf);
|
||||
|
||||
LOG_DEBUG("SDID: %08X FCFG1: %08X FCFG2: %08X", sim_sdid, sim_fcfg1,
|
||||
sim_fcfg2);
|
||||
sim_fcfg2);
|
||||
|
||||
switch ((sim_fcfg1 >> 28) & 0x0f) {
|
||||
case 0x07:
|
||||
nvm_size = 128 * 1024;
|
||||
break;
|
||||
case 0x09:
|
||||
case 0x0f:
|
||||
nvm_size = 256 * 1024;
|
||||
break;
|
||||
default:
|
||||
nvm_size = 0;
|
||||
break;
|
||||
case 0x07:
|
||||
nvm_size = 128 * 1024;
|
||||
break;
|
||||
case 0x09:
|
||||
case 0x0f:
|
||||
nvm_size = 256 * 1024;
|
||||
break;
|
||||
default:
|
||||
nvm_size = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
switch ((sim_fcfg1 >> 24) & 0x0f) {
|
||||
case 0x07:
|
||||
pf_size = 128 * 1024;
|
||||
break;
|
||||
case 0x09:
|
||||
pf_size = 256 * 1024;
|
||||
break;
|
||||
case 0x0b:
|
||||
case 0x0f:
|
||||
pf_size = 512 * 1024;
|
||||
break;
|
||||
default:
|
||||
pf_size = 0;
|
||||
break;
|
||||
case 0x07:
|
||||
pf_size = 128 * 1024;
|
||||
break;
|
||||
case 0x09:
|
||||
pf_size = 256 * 1024;
|
||||
break;
|
||||
case 0x0b:
|
||||
case 0x0f:
|
||||
pf_size = 512 * 1024;
|
||||
break;
|
||||
default:
|
||||
pf_size = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
switch ((sim_fcfg1 >> 16) & 0x0f) {
|
||||
case 0x02:
|
||||
ee_size = 4 * 1024;
|
||||
break;
|
||||
case 0x03:
|
||||
ee_size = 2 * 1024;
|
||||
break;
|
||||
case 0x04:
|
||||
ee_size = 1 * 1024;
|
||||
break;
|
||||
case 0x05:
|
||||
ee_size = 512;
|
||||
break;
|
||||
case 0x06:
|
||||
ee_size = 256;
|
||||
break;
|
||||
case 0x07:
|
||||
ee_size = 128;
|
||||
break;
|
||||
case 0x08:
|
||||
ee_size = 64;
|
||||
break;
|
||||
case 0x09:
|
||||
ee_size = 32;
|
||||
break;
|
||||
default:
|
||||
ee_size = 0;
|
||||
break;
|
||||
case 0x02:
|
||||
ee_size = 4 * 1024;
|
||||
break;
|
||||
case 0x03:
|
||||
ee_size = 2 * 1024;
|
||||
break;
|
||||
case 0x04:
|
||||
ee_size = 1 * 1024;
|
||||
break;
|
||||
case 0x05:
|
||||
ee_size = 512;
|
||||
break;
|
||||
case 0x06:
|
||||
ee_size = 256;
|
||||
break;
|
||||
case 0x07:
|
||||
ee_size = 128;
|
||||
break;
|
||||
case 0x08:
|
||||
ee_size = 64;
|
||||
break;
|
||||
case 0x09:
|
||||
ee_size = 32;
|
||||
break;
|
||||
default:
|
||||
ee_size = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
((struct kinetis_flash_bank *) bank->driver_priv)->nvm_start =
|
||||
pf_size - nvm_size;
|
||||
|
||||
LOG_DEBUG("NVM: %d PF: %d EE: %d BL1: %d", nvm_size, pf_size, ee_size,
|
||||
(sim_fcfg2 >> 23) & 1);
|
||||
(sim_fcfg2 >> 23) & 1);
|
||||
|
||||
if (pf_size != bank->size) {
|
||||
LOG_WARNING("flash size is different %d != %d", pf_size,
|
||||
bank->size);
|
||||
bank->size);
|
||||
}
|
||||
|
||||
bank->num_sectors = bank->size / (2 * 1024);
|
||||
@@ -526,13 +508,12 @@ static int kinetis_info(struct flash_bank *bank, char *buf, int buf_size)
|
||||
|
||||
result = kinetis_get_master_bank(bank, &master_bank);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
snprintf(buf, buf_size,
|
||||
"%s driver for flash bank %s at 0x%8.8" PRIx32 "",
|
||||
bank->driver->name, master_bank->name, master_bank->base);
|
||||
"%s driver for flash bank %s at 0x%8.8" PRIx32 "",
|
||||
bank->driver->name, master_bank->name, master_bank->base);
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
@@ -551,15 +532,14 @@ static int kinetis_blank_check(struct flash_bank *bank)
|
||||
|
||||
result = kinetis_get_master_bank(bank, &master_bank);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
static int kinetis_flash_read(struct flash_bank *bank,
|
||||
uint8_t * buffer, uint32_t offset, uint32_t count)
|
||||
uint8_t *buffer, uint32_t offset, uint32_t count)
|
||||
{
|
||||
int result;
|
||||
struct flash_bank *master_bank;
|
||||
@@ -573,9 +553,8 @@ static int kinetis_flash_read(struct flash_bank *bank,
|
||||
|
||||
result = kinetis_get_master_bank(bank, &master_bank);
|
||||
|
||||
if (result != ERROR_OK) {
|
||||
if (result != ERROR_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user