Commit 86ca2270 authored by oharboe's avatar oharboe
Browse files

Pavel Chromy cleaned up checks for halted, error messages, etc.

git-svn-id: svn://svn.berlios.de/openocd/trunk@374 b42882b7-edfa-0310-969c-e2dbd0fdcd60
parent b008ff7a
...@@ -314,11 +314,6 @@ int at91sam7_read_part_info(struct flash_bank_s *bank) ...@@ -314,11 +314,6 @@ int at91sam7_read_part_info(struct flash_bank_s *bank)
u32 cidr, status; u32 cidr, status;
int sectornum; int sectornum;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
/* Read and parse chip identification register */ /* Read and parse chip identification register */
target_read_u32(target, DBGU_CIDR, &cidr); target_read_u32(target, DBGU_CIDR, &cidr);
...@@ -584,6 +579,11 @@ int at91sam7_protect_check(struct flash_bank_s *bank) ...@@ -584,6 +579,11 @@ int at91sam7_protect_check(struct flash_bank_s *bank)
at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv; at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
if (at91sam7_info->cidr == 0) if (at91sam7_info->cidr == 0)
{ {
at91sam7_read_part_info(bank); at91sam7_read_part_info(bank);
...@@ -738,6 +738,11 @@ int at91sam7_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) ...@@ -738,6 +738,11 @@ int at91sam7_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
u32 first_page, last_page, pagen, buffer_pos; u32 first_page, last_page, pagen, buffer_pos;
u8 flashplane; u8 flashplane;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
if (at91sam7_info->cidr == 0) if (at91sam7_info->cidr == 0)
{ {
at91sam7_read_part_info(bank); at91sam7_read_part_info(bank);
...@@ -806,6 +811,11 @@ int at91sam7_probe(struct flash_bank_s *bank) ...@@ -806,6 +811,11 @@ int at91sam7_probe(struct flash_bank_s *bank)
at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv; at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
at91sam7_info->probed = 0; at91sam7_info->probed = 0;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
if (at91sam7_info->cidr == 0) if (at91sam7_info->cidr == 0)
{ {
at91sam7_read_part_info(bank); at91sam7_read_part_info(bank);
...@@ -836,6 +846,11 @@ int at91sam7_info(struct flash_bank_s *bank, char *buf, int buf_size) ...@@ -836,6 +846,11 @@ int at91sam7_info(struct flash_bank_s *bank, char *buf, int buf_size)
int printed, flashplane; int printed, flashplane;
at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv; at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
at91sam7_read_part_info(bank); at91sam7_read_part_info(bank);
if (at91sam7_info->cidr == 0) if (at91sam7_info->cidr == 0)
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "replacements.h" #include "replacements.h"
#include "cfi.h" #include "cfi.h"
#include "non_cfi.h"
#include "flash.h" #include "flash.h"
#include "target.h" #include "target.h"
...@@ -78,7 +79,6 @@ cfi_unlock_addresses_t cfi_unlock_addresses[] = ...@@ -78,7 +79,6 @@ cfi_unlock_addresses_t cfi_unlock_addresses[] =
}; };
/* CFI fixups foward declarations */ /* CFI fixups foward declarations */
void cfi_fixup_non_cfi(flash_bank_t *flash, void *param);
void cfi_fixup_0002_erase_regions(flash_bank_t *flash, void *param); void cfi_fixup_0002_erase_regions(flash_bank_t *flash, void *param);
void cfi_fixup_0002_unlock_addresses(flash_bank_t *flash, void *param); void cfi_fixup_0002_unlock_addresses(flash_bank_t *flash, void *param);
void cfi_fixup_atmel_reversed_erase_regions(flash_bank_t *flash, void *param); void cfi_fixup_atmel_reversed_erase_regions(flash_bank_t *flash, void *param);
...@@ -898,30 +898,35 @@ int cfi_protect(struct flash_bank_s *bank, int set, int first, int last) ...@@ -898,30 +898,35 @@ int cfi_protect(struct flash_bank_s *bank, int set, int first, int last)
/* FIXME Replace this by a simple memcpy() - still unsure about sideeffects */ /* FIXME Replace this by a simple memcpy() - still unsure about sideeffects */
static void cfi_add_byte(struct flash_bank_s *bank, u8 *word, u8 byte) static void cfi_add_byte(struct flash_bank_s *bank, u8 *word, u8 byte)
{ {
//target_t *target = bank->target; /* target_t *target = bank->target; */
int i; int i;
// NOTE: /* NOTE:
// The data to flash must not be changed in endian! We write a bytestrem in * The data to flash must not be changed in endian! We write a bytestrem in
// target byte order already. Only the control and status byte lane of the flash * target byte order already. Only the control and status byte lane of the flash
// WSM is interpreted by the CPU in different ways, when read a u16 or u32 * WSM is interpreted by the CPU in different ways, when read a u16 or u32
// word (data seems to be in the upper or lower byte lane for u16 accesses). * word (data seems to be in the upper or lower byte lane for u16 accesses).
*/
//if (target->endianness == TARGET_LITTLE_ENDIAN) #if 0
//{ if (target->endianness == TARGET_LITTLE_ENDIAN)
{
#endif
/* shift bytes */ /* shift bytes */
for (i = 0; i < bank->bus_width - 1; i++) for (i = 0; i < bank->bus_width - 1; i++)
word[i] = word[i + 1]; word[i] = word[i + 1];
word[bank->bus_width - 1] = byte; word[bank->bus_width - 1] = byte;
//} #if 0
//else }
//{ else
// /* shift bytes */ {
// for (i = bank->bus_width - 1; i > 0; i--) /* shift bytes */
// word[i] = word[i - 1]; for (i = bank->bus_width - 1; i > 0; i--)
// word[0] = byte; word[i] = word[i - 1];
//} word[0] = byte;
}
#endif
} }
/* Convert code image to target endian */ /* Convert code image to target endian */
...@@ -1160,9 +1165,9 @@ int cfi_intel_write_block(struct flash_bank_s *bank, u8 *buffer, u32 address, u3 ...@@ -1160,9 +1165,9 @@ int cfi_intel_write_block(struct flash_bank_s *bank, u8 *buffer, u32 address, u3
cfi_intel_clear_status_register(bank); cfi_intel_clear_status_register(bank);
ERROR("Execution of flash algorythm failed. Can't fall back. Please report."); ERROR("Execution of flash algorythm failed. Can't fall back. Please report.");
retval = ERROR_FLASH_OPERATION_FAILED; retval = ERROR_FLASH_OPERATION_FAILED;
//retval = ERROR_TARGET_RESOURCE_NOT_AVAILABLE; /* retval = ERROR_TARGET_RESOURCE_NOT_AVAILABLE; */
// FIXME To allow fall back or recovery, we must save the actual status /* FIXME To allow fall back or recovery, we must save the actual status
// somewhere, so that a higher level code can start recovery. somewhere, so that a higher level code can start recovery. */
goto cleanup; goto cleanup;
} }
...@@ -1622,7 +1627,7 @@ int cfi_write_words(struct flash_bank_s *bank, u8 *word, u32 wordcount, u32 addr ...@@ -1622,7 +1627,7 @@ int cfi_write_words(struct flash_bank_s *bank, u8 *word, u32 wordcount, u32 addr
return cfi_intel_write_words(bank, word, wordcount, address); return cfi_intel_write_words(bank, word, wordcount, address);
break; break;
case 2: case 2:
//return cfi_spansion_write_words(bank, word, address); /* return cfi_spansion_write_words(bank, word, address); */
ERROR("cfi primary command set %i unimplemented - FIXME", cfi_info->pri_id); ERROR("cfi primary command set %i unimplemented - FIXME", cfi_info->pri_id);
break; break;
default: default:
...@@ -1645,6 +1650,9 @@ int cfi_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) ...@@ -1645,6 +1650,9 @@ int cfi_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
int i; int i;
int retval; int retval;
if (bank->target->state != TARGET_HALTED)
return ERROR_TARGET_NOT_HALTED;
if (offset + count > bank->size) if (offset + count > bank->size)
return ERROR_FLASH_DST_OUT_OF_BANK; return ERROR_FLASH_DST_OUT_OF_BANK;
...@@ -1868,6 +1876,11 @@ int cfi_probe(struct flash_bank_s *bank) ...@@ -1868,6 +1876,11 @@ int cfi_probe(struct flash_bank_s *bank)
u32 unlock1 = 0x555; u32 unlock1 = 0x555;
u32 unlock2 = 0x2aa; u32 unlock2 = 0x2aa;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
cfi_info->probed = 0; cfi_info->probed = 0;
/* JEDEC standard JESD21C uses 0x5555 and 0x2aaa as unlock addresses, /* JEDEC standard JESD21C uses 0x5555 and 0x2aaa as unlock addresses,
...@@ -2098,6 +2111,11 @@ int cfi_erase_check(struct flash_bank_s *bank) ...@@ -2098,6 +2111,11 @@ int cfi_erase_check(struct flash_bank_s *bank)
int i; int i;
int retval; int retval;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
if (!cfi_info->erase_check_algorithm) if (!cfi_info->erase_check_algorithm)
{ {
u32 erase_check_code[] = u32 erase_check_code[] =
...@@ -2270,6 +2288,11 @@ int cfi_protect_check(struct flash_bank_s *bank) ...@@ -2270,6 +2288,11 @@ int cfi_protect_check(struct flash_bank_s *bank)
{ {
cfi_flash_bank_t *cfi_info = bank->driver_priv; cfi_flash_bank_t *cfi_info = bank->driver_priv;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
if (cfi_info->qry[0] != 'Q') if (cfi_info->qry[0] != 'Q')
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
......
...@@ -200,7 +200,7 @@ flash_bank_t *get_flash_bank_by_num_noprobe(int num) ...@@ -200,7 +200,7 @@ flash_bank_t *get_flash_bank_by_num_noprobe(int num)
return p; return p;
} }
} }
ERROR("Flash bank %d does not exist", num); ERROR("flash bank %d does not exist", num);
return NULL; return NULL;
} }
......
...@@ -40,20 +40,16 @@ typedef struct flash_driver_s ...@@ -40,20 +40,16 @@ typedef struct flash_driver_s
char *name; char *name;
int (*register_commands)(struct command_context_s *cmd_ctx); int (*register_commands)(struct command_context_s *cmd_ctx);
int (*flash_bank_command)(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank); int (*flash_bank_command)(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
/* low level flash erase. Only invoke from flash_driver_erase()
* /* use flash_driver_erase() wrapper to invoke */
* Will only be invoked when target is halted.
*/
int (*erase)(struct flash_bank_s *bank, int first, int last); int (*erase)(struct flash_bank_s *bank, int first, int last);
/* invoked only from flash_driver_protect().
* /* use flash_driver_protect() wrapper to invoke */
* Only invoked if target is halted
*/
int (*protect)(struct flash_bank_s *bank, int set, int first, int last); int (*protect)(struct flash_bank_s *bank, int set, int first, int last);
/* low level flash write. Will only be invoked if the target is halted.
* use the flash_driver_write() wrapper to invoke. /* use the flash_driver_write() wrapper to invoke. */
*/
int (*write)(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count); int (*write)(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);
int (*probe)(struct flash_bank_s *bank); int (*probe)(struct flash_bank_s *bank);
int (*erase_check)(struct flash_bank_s *bank); int (*erase_check)(struct flash_bank_s *bank);
int (*protect_check)(struct flash_bank_s *bank); int (*protect_check)(struct flash_bank_s *bank);
......
...@@ -416,6 +416,11 @@ int lpc2000_erase(struct flash_bank_s *bank, int first, int last) ...@@ -416,6 +416,11 @@ int lpc2000_erase(struct flash_bank_s *bank, int first, int last)
u32 result_table[2]; u32 result_table[2];
int status_code; int status_code;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
param_table[0] = first; param_table[0] = first;
param_table[1] = last; param_table[1] = last;
param_table[2] = lpc2000_info->cclk; param_table[2] = lpc2000_info->cclk;
...@@ -476,6 +481,11 @@ int lpc2000_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) ...@@ -476,6 +481,11 @@ int lpc2000_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
int i; int i;
working_area_t *download_area; working_area_t *download_area;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
/* allocate a working area */ /* allocate a working area */
if (target_alloc_working_area(target, lpc2000_info->cmd51_max_buffer, &download_area) != ERROR_OK) if (target_alloc_working_area(target, lpc2000_info->cmd51_max_buffer, &download_area) != ERROR_OK)
{ {
...@@ -645,7 +655,6 @@ int lpc2000_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, ...@@ -645,7 +655,6 @@ int lpc2000_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd,
u32 param_table[5]; u32 param_table[5];
u32 result_table[2]; u32 result_table[2];
int status_code; int status_code;
lpc2000_flash_bank_t *lpc2000_info;
if (argc < 1) if (argc < 1)
{ {
...@@ -659,7 +668,6 @@ int lpc2000_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, ...@@ -659,7 +668,6 @@ int lpc2000_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd,
return ERROR_OK; return ERROR_OK;
} }
lpc2000_info = bank->driver_priv;
if (bank->target->state != TARGET_HALTED) if (bank->target->state != TARGET_HALTED)
{ {
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
......
...@@ -391,7 +391,6 @@ u32 stellaris_wait_status_busy(flash_bank_t *bank, u32 waitbits, int timeout) ...@@ -391,7 +391,6 @@ u32 stellaris_wait_status_busy(flash_bank_t *bank, u32 waitbits, int timeout)
int stellaris_flash_command(struct flash_bank_s *bank,u8 cmd,u16 pagen) int stellaris_flash_command(struct flash_bank_s *bank,u8 cmd,u16 pagen)
{ {
u32 fmc; u32 fmc;
// stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
target_t *target = bank->target; target_t *target = bank->target;
fmc = FMC_WRKEY | cmd; fmc = FMC_WRKEY | cmd;
...@@ -428,6 +427,12 @@ int stellaris_read_part_info(struct flash_bank_s *bank) ...@@ -428,6 +427,12 @@ int stellaris_read_part_info(struct flash_bank_s *bank)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
if (did1 == 0)
{
WARNING("Cannot identify target as a Stellaris");
return ERROR_FLASH_OPERATION_FAILED;
}
ver = did1 >> 28; ver = did1 >> 28;
fam = (did1 >> 24) & 0xF; fam = (did1 >> 24) & 0xF;
if(((ver != 0) && (ver != 1)) || (fam != 0)) if(((ver != 0) && (ver != 1)) || (fam != 0))
...@@ -435,12 +440,6 @@ int stellaris_read_part_info(struct flash_bank_s *bank) ...@@ -435,12 +440,6 @@ int stellaris_read_part_info(struct flash_bank_s *bank)
WARNING("Unknown did1 version/family, cannot positively identify target as a Stellaris"); WARNING("Unknown did1 version/family, cannot positively identify target as a Stellaris");
} }
if (did1 == 0)
{
WARNING("Cannot identify target as a Stellaris");
return ERROR_FLASH_OPERATION_FAILED;
}
for (i=0;StellarisParts[i].partno;i++) for (i=0;StellarisParts[i].partno;i++)
{ {
if (StellarisParts[i].partno==((did1>>16)&0xFF)) if (StellarisParts[i].partno==((did1>>16)&0xFF))
...@@ -459,7 +458,7 @@ int stellaris_read_part_info(struct flash_bank_s *bank) ...@@ -459,7 +458,7 @@ int stellaris_read_part_info(struct flash_bank_s *bank)
stellaris_info->pages_in_lockregion = 2; stellaris_info->pages_in_lockregion = 2;
target_read_u32(target, SCB_BASE|FMPPE, &stellaris_info->lockbits); target_read_u32(target, SCB_BASE|FMPPE, &stellaris_info->lockbits);
// Read main and master clock freqency register /* Read main and master clock freqency register */
stellaris_read_clock_info(bank); stellaris_read_clock_info(bank);
status = stellaris_get_flash_status(bank); status = stellaris_get_flash_status(bank);
...@@ -490,6 +489,11 @@ int stellaris_protect_check(struct flash_bank_s *bank) ...@@ -490,6 +489,11 @@ int stellaris_protect_check(struct flash_bank_s *bank)
stellaris_flash_bank_t *stellaris_info = bank->driver_priv; stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
if (stellaris_info->did1 == 0) if (stellaris_info->did1 == 0)
{ {
stellaris_read_part_info(bank); stellaris_read_part_info(bank);
...@@ -514,6 +518,11 @@ int stellaris_erase(struct flash_bank_s *bank, int first, int last) ...@@ -514,6 +518,11 @@ int stellaris_erase(struct flash_bank_s *bank, int first, int last)
stellaris_flash_bank_t *stellaris_info = bank->driver_priv; stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
target_t *target = bank->target; target_t *target = bank->target;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
if (stellaris_info->did1 == 0) if (stellaris_info->did1 == 0)
{ {
stellaris_read_part_info(bank); stellaris_read_part_info(bank);
...@@ -707,7 +716,6 @@ u8 stellaris_write_code[] = ...@@ -707,7 +716,6 @@ u8 stellaris_write_code[] =
int stellaris_write_block(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 wcount) int stellaris_write_block(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 wcount)
{ {
// stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
target_t *target = bank->target; target_t *target = bank->target;
u32 buffer_size = 8192; u32 buffer_size = 8192;
working_area_t *source; working_area_t *source;
...@@ -809,6 +817,11 @@ int stellaris_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count ...@@ -809,6 +817,11 @@ int stellaris_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count
u32 flash_cris,flash_fmc; u32 flash_cris,flash_fmc;
u32 retval; u32 retval;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
DEBUG("(bank=%08X buffer=%08X offset=%08X count=%08X)", DEBUG("(bank=%08X buffer=%08X offset=%08X count=%08X)",
(unsigned int)bank, (unsigned int)buffer, offset, count); (unsigned int)bank, (unsigned int)buffer, offset, count);
...@@ -879,7 +892,7 @@ int stellaris_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count ...@@ -879,7 +892,7 @@ int stellaris_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count
target_write_u32(target, FLASH_FMA, address); target_write_u32(target, FLASH_FMA, address);
target_write_buffer(target, FLASH_FMD, 4, buffer); target_write_buffer(target, FLASH_FMD, 4, buffer);
target_write_u32(target, FLASH_FMC, FMC_WRKEY | FMC_WRITE); target_write_u32(target, FLASH_FMC, FMC_WRKEY | FMC_WRITE);
//DEBUG("0x%x 0x%x 0x%x",address,buf_get_u32(buffer, 0, 32),FMC_WRKEY | FMC_WRITE); /* DEBUG("0x%x 0x%x 0x%x",address,buf_get_u32(buffer, 0, 32),FMC_WRKEY | FMC_WRITE); */
/* Wait until write complete */ /* Wait until write complete */
do do
{ {
...@@ -906,30 +919,20 @@ int stellaris_probe(struct flash_bank_s *bank) ...@@ -906,30 +919,20 @@ int stellaris_probe(struct flash_bank_s *bank)
/* we can't probe on an stellaris /* we can't probe on an stellaris
* if this is an stellaris, it has the configured flash * if this is an stellaris, it has the configured flash
*/ */
stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
stellaris_info->probed = 0; if (bank->target->state != TARGET_HALTED)
if (stellaris_info->did1 == 0)
{ {
stellaris_read_part_info(bank); return ERROR_TARGET_NOT_HALTED;
} }
if (stellaris_info->did1 == 0) /* stellaris_read_part_info() already takes care about error checking and reporting */
{ return stellaris_read_part_info(bank);
WARNING("Cannot identify target as a LMI Stellaris");
return ERROR_FLASH_OPERATION_FAILED;
}
stellaris_info->probed = 1;
return ERROR_OK;
} }
int stellaris_auto_probe(struct flash_bank_s *bank) int stellaris_auto_probe(struct flash_bank_s *bank)
{ {
stellaris_flash_bank_t *stellaris_info = bank->driver_priv; stellaris_flash_bank_t *stellaris_info = bank->driver_priv;
if (stellaris_info->probed) if (stellaris_info->did1)
return ERROR_OK; return ERROR_OK;
return stellaris_probe(bank); return stellaris_probe(bank);
} }
...@@ -49,8 +49,6 @@ typedef struct stellaris_flash_bank_s ...@@ -49,8 +49,6 @@ typedef struct stellaris_flash_bank_s
u8 mck_valid; u8 mck_valid;
u32 mck_freq; u32 mck_freq;
int probed;
} stellaris_flash_bank_t; } stellaris_flash_bank_t;
/* STELLARIS control registers */ /* STELLARIS control registers */
......
...@@ -292,7 +292,7 @@ int stm32x_blank_check(struct flash_bank_s *bank, int first, int last) ...@@ -292,7 +292,7 @@ int stm32x_blank_check(struct flash_bank_s *bank, int first, int last)
{ {
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
buffer = malloc(256); buffer = malloc(256);
for (i = first; i <= last; i++) for (i = first; i <= last; i++)
...@@ -356,6 +356,11 @@ int stm32x_erase(struct flash_bank_s *bank, int first, int last) ...@@ -356,6 +356,11 @@ int stm32x_erase(struct flash_bank_s *bank, int first, int last)
int i; int i;
u32 status; u32 status;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
/* unlock flash registers */ /* unlock flash registers */
target_write_u32(target, STM32_FLASH_KEYR, KEY1); target_write_u32(target, STM32_FLASH_KEYR, KEY1);
target_write_u32(target, STM32_FLASH_KEYR, KEY2); target_write_u32(target, STM32_FLASH_KEYR, KEY2);
...@@ -547,6 +552,11 @@ int stm32x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) ...@@ -547,6 +552,11 @@ int stm32x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
u8 status; u8 status;
u32 retval; u32 retval;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
if (offset & 0x1) if (offset & 0x1)
{ {
WARNING("offset 0x%x breaks required 2-byte alignment", offset); WARNING("offset 0x%x breaks required 2-byte alignment", offset);
...@@ -636,6 +646,11 @@ int stm32x_probe(struct flash_bank_s *bank) ...@@ -636,6 +646,11 @@ int stm32x_probe(struct flash_bank_s *bank)
u16 num_sectors; u16 num_sectors;
u32 device_id; u32 device_id;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
stm32x_info->probed = 0; stm32x_info->probed = 0;
/* read stm32 device id register */