Uwe Hermann:
[openocd.git] / src / flash / tms470.c
index 491426ef3a0ee3342cbc1520b888cf7178570d28..cfbb072d789b48a437cce1610de1b437cfa81ff7 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   (c) Copyright 2007, 2008 by Christopher Kilgour                       *
+ *   Copyright (C) 2007,2008 by Christopher Kilgour                        *
  *   techie |_at_| whiterocker |_dot_| com                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -17,7 +17,6 @@
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -109,11 +108,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 +771,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 +819,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 +870,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 +962,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 +990,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 +1079,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);

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)