]> git.sur5r.net Git - openocd/commitdiff
flash/nor: implement flash bank deallocation on OpenOCD exit
authorTomas Vanek <vanekt@fbl.cz>
Thu, 15 Feb 2018 01:29:56 +0000 (02:29 +0100)
committerMatthias Welwarsky <matthias@welwarsky.de>
Fri, 30 Mar 2018 09:13:09 +0000 (10:13 +0100)
Change-Id: I8fcf09b2a85b3b68743f5fd68a31edea933b9b17
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4414
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
src/flash/nor/core.c
src/flash/nor/core.h
src/flash/nor/driver.h
src/openocd.c

index 6eb7052ef56c69e62f06ca8d90bab04ae6b11210..636d50c517a1463ed52e2b592579887001fd3a36 100644 (file)
@@ -171,6 +171,31 @@ int flash_get_bank_count(void)
        return i;
 }
 
+void default_flash_free_driver_priv(struct flash_bank *bank)
+{
+       free(bank->driver_priv);
+       bank->driver_priv = NULL;
+}
+
+void flash_free_all_banks(void)
+{
+       struct flash_bank *bank = flash_banks;
+       while (bank) {
+               struct flash_bank *next = bank->next;
+               if (bank->driver->free_driver_priv)
+                       bank->driver->free_driver_priv(bank);
+               else
+                       LOG_WARNING("Flash driver of %s does not support free_driver_priv()", bank->name);
+
+               free(bank->name);
+               free(bank->sectors);
+               free(bank->prot_blocks);
+               free(bank);
+               bank = next;
+       }
+       flash_banks = NULL;
+}
+
 struct flash_bank *get_flash_bank_by_name_noprobe(const char *name)
 {
        unsigned requested = get_flash_name_index(name);
index 338363e2acad9713bfeccb1b786ab686e84cb529..1bfe1ab977641828a47efe0f9869833e17ceb776 100644 (file)
@@ -76,7 +76,7 @@ struct flash_sector {
  * per-bank basis, if required.
  */
 struct flash_bank {
-       const char *name;
+       char *name;
 
        struct target *target; /**< Target to which this bank belongs. */
 
@@ -153,8 +153,15 @@ int flash_write(struct target *target,
  * This routine must be called when the system may modify the status.
  */
 void flash_set_dirty(void);
+
 /** @returns The number of flash banks currently defined. */
 int flash_get_bank_count(void);
+
+/** Deallocates bank->driver_priv */
+void default_flash_free_driver_priv(struct flash_bank *bank);
+
+/** Deallocates all flash banks */
+void flash_free_all_banks(void);
 /**
  * Provides default read implementation for flash memory.
  * @param bank The bank to read.
index 0ae4d8e20453991ad55fb2247d15e518f3a05144..e7b3234439d73f13ff39c7d7a54781ad487fd2d3 100644 (file)
@@ -209,6 +209,14 @@ struct flash_driver {
         * @returns ERROR_OK if successful; otherwise, an error code.
         */
        int (*auto_probe)(struct flash_bank *bank);
+
+       /**
+        * Deallocates private driver structures.
+        * Use default_flash_free_driver_priv() to simply free(bank->driver_priv)
+        *
+        * @param bank - the bank being destroyed
+        */
+       void (*free_driver_priv)(struct flash_bank *bank);
 };
 
 #define FLASH_BANK_COMMAND_HANDLER(name) \
index bd52f4acf57b36aee476ae1b79f5a0dd6dc41bdb..1874530cb2fc4d053052835e19febf591c1599e2 100644 (file)
@@ -353,6 +353,7 @@ int openocd_main(int argc, char *argv[])
        /* Start the executable meat that can evolve into thread in future. */
        ret = openocd_thread(argc, argv, cmd_ctx);
 
+       flash_free_all_banks();
        gdb_service_free();
        server_free();