flash/stm32f1x: fix maximum flash size for some devices
[fw/openocd] / src / flash / nor / atsamv.c
index 77fb7e68b86a454eb6f2b4ee36f62c42e60a0900..d6f1a0a48f28d4d079f7f11b7bda96f0e4649a1e 100644 (file)
  *   (atsamv, atsams, and atsame support)                                  *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General public License as published by  *
+ *   it under the terms of the GNU General Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
  *                                                                         *
  *   This program is distributed in the hope that it will be useful,       *
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE.  See the         *
- *   GNU General public License for more details.                          *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   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, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 /* Some of the the lower level code was based on code supplied by
@@ -92,7 +94,7 @@
 #define SAMV_PAGE_SIZE                 512
 #define SAMV_FLASH_BASE         0x00400000
 
-extern struct flash_driver atsamv_flash;
+extern const struct flash_driver atsamv_flash;
 
 struct samv_flash_bank {
        int      probed;
@@ -145,7 +147,7 @@ static int samv_efc_perform_command(struct target *target,
 {
        int r;
        uint32_t v;
-       long long ms_now, ms_end;
+       int64_t ms_now, ms_end;
 
        if (status)
                *status = 0;
@@ -361,6 +363,9 @@ static int samv_probe(struct flash_bank *bank)
 
        uint8_t nvm_size_code = (device_id >> 8) & 0xf;
        switch (nvm_size_code) {
+               case 10:
+                       bank->size = 512 * 1024;
+                       break;
                case 12:
                        bank->size = 1024 * 1024;
                        break;
@@ -667,22 +672,22 @@ showall:
                                r = samv_get_gpnvm(target, x, &v);
                                if (r != ERROR_OK)
                                        break;
-                               command_print(CMD_CTX, "samv-gpnvm%u: %u", x, v);
+                               command_print(CMD, "samv-gpnvm%u: %u", x, v);
                        }
                        return r;
                }
                if ((who >= 0) && (((unsigned)who) < SAMV_NUM_GPNVM_BITS)) {
                        r = samv_get_gpnvm(target, who, &v);
-                       command_print(CMD_CTX, "samv-gpnvm%u: %u", who, v);
+                       command_print(CMD, "samv-gpnvm%u: %u", who, v);
                        return r;
                } else {
-                       command_print(CMD_CTX, "invalid gpnvm: %u", who);
+                       command_print(CMD, "invalid gpnvm: %u", who);
                        return ERROR_COMMAND_SYNTAX_ERROR;
                }
        }
 
        if (who == -1) {
-               command_print(CMD_CTX, "missing gpnvm number");
+               command_print(CMD, "missing gpnvm number");
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
@@ -691,7 +696,7 @@ showall:
        else if (!strcmp("clr", CMD_ARGV[0]) || !strcmp("clear", CMD_ARGV[0]))
                r = samv_clear_gpnvm(target, who);
        else {
-               command_print(CMD_CTX, "unknown command: %s", CMD_ARGV[0]);
+               command_print(CMD, "unknown command: %s", CMD_ARGV[0]);
                r = ERROR_COMMAND_SYNTAX_ERROR;
        }
        return r;
@@ -721,7 +726,7 @@ static const struct command_registration atsamv_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-struct flash_driver atsamv_flash = {
+const struct flash_driver atsamv_flash = {
        .name = "atsamv",
        .commands = atsamv_command_handlers,
        .flash_bank_command = samv_flash_bank_command,
@@ -734,4 +739,5 @@ struct flash_driver atsamv_flash = {
        .erase_check = default_flash_blank_check,
        .protect_check = samv_protect_check,
        .info = samv_get_info,
+       .free_driver_priv = default_flash_free_driver_priv,
 };