From 86ca2270f40d650a849e778518e7aa9c2c713341 Mon Sep 17 00:00:00 2001 From: oharboe Date: Thu, 28 Feb 2008 10:44:41 +0000 Subject: 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 --- src/flash/tms470.c | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'src/flash/tms470.c') diff --git a/src/flash/tms470.c b/src/flash/tms470.c index 491426ef..55adfd81 100644 --- a/src/flash/tms470.c +++ b/src/flash/tms470.c @@ -109,11 +109,10 @@ int tms470_read_part_info(struct flash_bank_s *bank) u32 part_number; char *part_name; - if (target->state != TARGET_HALTED) - { - WARNING("Cannot communicate... target not halted."); - return ERROR_TARGET_NOT_HALTED; - } + /* we shall not rely on the caller in this test, this function allocates memory, + thus and executing the code more than once may cause memory leak */ + if (tms470_info->device_ident_reg) + return ERROR_OK; /* read and parse the device identification register */ target_read_u32(target, 0xFFFFFFF0, &device_ident_reg); @@ -773,11 +772,13 @@ int tms470_erase(struct flash_bank_s *bank, int first, int last) tms470_flash_bank_t *tms470_info = bank->driver_priv; int sector, result = ERROR_OK; - if (!tms470_info->device_ident_reg) + if (bank->target->state != TARGET_HALTED) { - tms470_read_part_info(bank); + return ERROR_TARGET_NOT_HALTED; } + tms470_read_part_info(bank); + if ((first < 0) || (first >= bank->num_sectors) || (last < 0) || (last >= bank->num_sectors) || (first > last)) { ERROR("Sector range %d to %d invalid.", first, last); @@ -819,11 +820,13 @@ int tms470_protect(struct flash_bank_s *bank, int set, int first, int last) u32 fmmac2, fmbsea, fmbseb; int sector; - if (!tms470_info->device_ident_reg) + if (target->state != TARGET_HALTED) { - tms470_read_part_info(bank); + return ERROR_TARGET_NOT_HALTED; } + tms470_read_part_info(bank); + if ((first < 0) || (first >= bank->num_sectors) || (last < 0) || (last >= bank->num_sectors) || (first > last)) { ERROR("Sector range %d to %d invalid.", first, last); @@ -868,11 +871,13 @@ int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count) u32 glbctrl, fmbac2, orig_fmregopt, fmbsea, fmbseb, fmmaxpp, fmmstat; int i, result = ERROR_OK; - if (!tms470_info->device_ident_reg) + if (target->state != TARGET_HALTED) { - tms470_read_part_info(bank); + return ERROR_TARGET_NOT_HALTED; } + tms470_read_part_info(bank); + INFO("Writing %d bytes starting at 0x%08x", count, bank->base + offset); /* set GLBCTRL.4 */ @@ -958,25 +963,20 @@ int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32 count) int tms470_probe(struct flash_bank_s *bank) { - tms470_flash_bank_t *tms470_info = bank->driver_priv; - - tms470_info->probed = 0; - - if (!tms470_info->device_ident_reg) + if (bank->target->state != TARGET_HALTED) { - tms470_read_part_info(bank); + WARNING("Cannot communicate... target not halted."); + return ERROR_TARGET_NOT_HALTED; } - tms470_info->probed = 1; - - return ERROR_OK; + return tms470_read_part_info(bank); } int tms470_auto_probe(struct flash_bank_s *bank) { tms470_flash_bank_t *tms470_info = bank->driver_priv; - if (tms470_info->probed) + if (tms470_info->device_ident_reg) return ERROR_OK; return tms470_probe(bank); } @@ -991,6 +991,11 @@ int tms470_erase_check(struct flash_bank_s *bank) u32 fmmac2, fmbac2, glbctrl, orig_fmregopt; static u8 buffer[64 * 1024]; + if (target->state != TARGET_HALTED) + { + return ERROR_TARGET_NOT_HALTED; + } + if (!tms470_info->device_ident_reg) { tms470_read_part_info(bank); @@ -1075,6 +1080,11 @@ int tms470_protect_check(struct flash_bank_s *bank) int sector, result = ERROR_OK; u32 fmmac2, fmbsea, fmbseb; + if (target->state != TARGET_HALTED) + { + return ERROR_TARGET_NOT_HALTED; + } + if (!tms470_info->device_ident_reg) { tms470_read_part_info(bank); -- cgit v1.2.3