nor: move in driver.h the flash_driver's declaration
[openocd.git] / src / flash / nor / swm050.c
index 241207d879d4c0d8711f6f5a31f5e4186c793625..dcf59d380ee1baf2ab954f25b87cbf8aa9d975d2 100644 (file)
@@ -1,19 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *   Copyright (C) 2019 Icenowy Zheng <icenowy@aosc.io>                    *
  *   Copyright (C) 2019 Caleb Szalacinski <contact@skiboy.net>             *
- *                                                                         *
- *   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  *
- *   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.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
 #define SWM050_SYSCTL_CFG_0    0x400F0000
 #define SWM050_SYSCTL_DBLF     0x400F0008
 
-static int swm050_erase(struct flash_bank *bank, int first, int last)
+static int swm050_erase(struct flash_bank *bank, unsigned int first,
+               unsigned int last)
 {
        struct target *target = bank->target;
-       int retval, curr_page;
-       uint32_t curr_addr;
+       int retval;
 
        if (target->state != TARGET_HALTED) {
                LOG_ERROR("Target not halted");
@@ -54,8 +43,8 @@ static int swm050_erase(struct flash_bank *bank, int first, int last)
        if (retval != ERROR_OK)
                return retval;
 
-       for (curr_page = first; curr_page <= last; curr_page++) {
-               curr_addr = bank->base + (SWM050_FLASH_PAGE_SIZE * curr_page);
+       for (unsigned int curr_page = first; curr_page <= last; curr_page++) {
+               uint32_t curr_addr = bank->base + (SWM050_FLASH_PAGE_SIZE * curr_page);
                /* Perform write */
                retval = target_write_u32(target, curr_addr, SWM050_FLASH_KEY);
                if (retval != ERROR_OK)
@@ -142,7 +131,7 @@ COMMAND_HANDLER(swm050_handle_mass_erase_command)
 
        struct flash_bank *bank;
        int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
-       if (ERROR_OK != retval)
+       if (retval != ERROR_OK)
                return retval;
 
        retval = swm050_mass_erase(bank);
@@ -156,10 +145,7 @@ COMMAND_HANDLER(swm050_handle_mass_erase_command)
 
 FLASH_BANK_COMMAND_HANDLER(swm050_flash_bank_command)
 {
-       if (bank->sectors) {
-               free(bank->sectors);
-               bank->sectors = NULL;
-       }
+       free(bank->sectors);
        bank->write_start_alignment = 4;
        bank->write_end_alignment = 4;
        bank->size = SWM050_FLASH_PAGE_SIZE * SWM050_FLASH_PAGES;
@@ -169,7 +155,7 @@ FLASH_BANK_COMMAND_HANDLER(swm050_flash_bank_command)
        if (!bank->sectors)
                return ERROR_FAIL;
 
-       for (int i = 0; i < bank->num_sectors; i++)
+       for (unsigned int i = 0; i < bank->num_sectors; i++)
                bank->sectors[i].is_protected = 0;
 
        return ERROR_OK;
@@ -197,7 +183,7 @@ static const struct command_registration swm050_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-struct flash_driver swm050_flash = {
+const struct flash_driver swm050_flash = {
        .name = "swm050",
        .commands = swm050_command_handlers,
        .flash_bank_command = swm050_flash_bank_command,

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)