+// 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");
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)
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);
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;
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;
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,