flash/nor/stm32: Eliminate working area leak
[openocd.git] / src / flash / nor / tms470.c
index 3851504d67f4ec6c93c23ca57d1b03dde3ac3c14..2435e79905ddce4b55775b08e1f49ce472d0e843 100644 (file)
@@ -13,9 +13,7 @@
  *   GNU General Public License for more details.                          *
  *                                                                         *
  *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -153,6 +151,7 @@ static int tms470_read_part_info(struct flash_bank *bank)
        if (bank->sectors) {
                free(bank->sectors);
                bank->sectors = NULL;
+               bank->num_sectors = 0;
        }
 
        /*
@@ -756,9 +755,6 @@ static int tms470_erase_sector(struct flash_bank *bank, int sector)
        target_write_u32(target, 0xFFFFFFDC, glbctrl);
        LOG_DEBUG("set glbctrl = 0x%08" PRIx32 "", glbctrl);
 
-       if (result == ERROR_OK)
-               bank->sectors[sector].is_erased = 1;
-
        return result;
 }
 
@@ -890,7 +886,7 @@ static int tms470_protect(struct flash_bank *bank, int set, int first, int last)
 
 /* ---------------------------------------------------------------------- */
 
-static int tms470_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
+static int tms470_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 {
        struct target *target = bank->target;
        uint32_t glbctrl, fmbac2, orig_fmregopt, fmbsea, fmbseb, fmmaxpp, fmmstat;
@@ -1046,27 +1042,17 @@ static int tms470_erase_check(struct flash_bank *bank)
         * an attempt to reduce the JTAG overhead.
         */
        for (sector = 0; sector < bank->num_sectors; sector++) {
-               if (bank->sectors[sector].is_erased != 1) {
-                       uint32_t i, addr = bank->base + bank->sectors[sector].offset;
-
-                       LOG_INFO("checking flash bank %d sector %d", tms470_info->ordinal, sector);
-
-                       target_read_buffer(target, addr, bank->sectors[sector].size, buffer);
-
-                       bank->sectors[sector].is_erased = 1;
-                       for (i = 0; i < bank->sectors[sector].size; i++) {
-                               if (buffer[i] != 0xff) {
-                                       LOG_WARNING("tms470 bank %d, sector %d, not erased.",
-                                               tms470_info->ordinal,
-                                               sector);
-                                       LOG_WARNING(
-                                               "at location 0x%08" PRIx32 ": flash data is 0x%02x.",
-                                               addr + i,
-                                               buffer[i]);
-
-                                       bank->sectors[sector].is_erased = 0;
-                                       break;
-                               }
+               uint32_t i, addr = bank->base + bank->sectors[sector].offset;
+
+               LOG_INFO("checking flash bank %d sector %d", tms470_info->ordinal, sector);
+
+               target_read_buffer(target, addr, bank->sectors[sector].size, buffer);
+
+               bank->sectors[sector].is_erased = 1;
+               for (i = 0; i < bank->sectors[sector].size; i++) {
+                       if (buffer[i] != 0xff) {
+                               bank->sectors[sector].is_erased = 0;
+                               break;
                        }
                }
                if (bank->sectors[sector].is_erased != 1) {
@@ -1188,4 +1174,5 @@ struct flash_driver tms470_flash = {
        .erase_check = tms470_erase_check,
        .protect_check = tms470_protect_check,
        .info = get_tms470_info,
+       .free_driver_priv = default_flash_free_driver_priv,
 };

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)