+// SPDX-License-Identifier: GPL-2.0-or-later
+
/***************************************************************************
* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
* Copyright (C) 2008 by Spencer Oliver *
* spen@spen-soft.co.uk *
- * *
- * 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, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
uint8_t options[8];
};
-static int str9xpec_erase_area(struct flash_bank *bank, int first, int last);
+static int str9xpec_erase_area(struct flash_bank *bank, unsigned int first,
+ unsigned int last);
static int str9xpec_set_address(struct flash_bank *bank, uint8_t sector);
static int str9xpec_write_options(struct flash_bank *bank);
static int str9xpec_set_instr(struct jtag_tap *tap, uint32_t new_instr, tap_state_t end_state)
{
- if (tap == NULL)
+ if (!tap)
return ERROR_TARGET_INVALID;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
int i;
- int num_sectors;
+ unsigned int num_sectors;
int b0_sectors = 0, b1_sectors = 0;
uint32_t offset = 0;
int b1_size = 0x2000;
return ERROR_OK;
}
-static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
+static int str9xpec_blank_check(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct scan_field field;
uint8_t status;
struct jtag_tap *tap;
- int i;
uint8_t *buffer = NULL;
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
buffer = calloc(DIV_ROUND_UP(64, 8), 1);
- LOG_DEBUG("blank check: first_bank: %i, last_bank: %i", first, last);
+ LOG_DEBUG("blank check: first_bank: %u, last_bank: %u", first, last);
- for (i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
buf_set_u32(buffer, str9xpec_info->sector_bits[i], 1, 1);
/* execute ISC_BLANK_CHECK command */
status = str9xpec_isc_status(tap);
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
if (buf_get_u32(buffer, str9xpec_info->sector_bits[i], 1))
bank->sectors[i].is_erased = 0;
else
static int str9xpec_protect_check(struct flash_bank *bank)
{
uint8_t status;
- int i;
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
status = str9xpec_read_config(bank);
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (buf_get_u32(str9xpec_info->options, str9xpec_info->sector_bits[i], 1))
bank->sectors[i].is_protected = 1;
else
return ERROR_OK;
}
-static int str9xpec_erase_area(struct flash_bank *bank, int first, int last)
+static int str9xpec_erase_area(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
struct scan_field field;
uint8_t status;
struct jtag_tap *tap;
- int i;
uint8_t *buffer = NULL;
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
buffer = calloc(DIV_ROUND_UP(64, 8), 1);
- LOG_DEBUG("erase: first_bank: %i, last_bank: %i", first, last);
+ LOG_DEBUG("erase: first_bank: %u, last_bank: %u", first, last);
/* last bank: 0xFF signals a full erase (unlock complete device) */
/* last bank: 0xFE signals a option byte erase */
if (last == 0xFF) {
- for (i = 0; i < 64; i++)
+ for (unsigned int i = 0; i < 64; i++)
buf_set_u32(buffer, i, 1, 1);
} else if (last == 0xFE)
buf_set_u32(buffer, 49, 1, 1);
else {
- for (i = first; i <= last; i++)
+ for (unsigned int i = first; i <= last; i++)
buf_set_u32(buffer, str9xpec_info->sector_bits[i], 1, 1);
}
return status;
}
-static int str9xpec_erase(struct flash_bank *bank, int first, int last)
+static int str9xpec_erase(struct flash_bank *bank, unsigned int first,
+ unsigned int last)
{
int status;
return status;
}
-static int str9xpec_protect(struct flash_bank *bank, int set, int first, int last)
+static int str9xpec_protect(struct flash_bank *bank, int set,
+ unsigned int first, unsigned int last)
{
uint8_t status;
- int i;
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS)
return ERROR_FLASH_OPERATION_FAILED;
- LOG_DEBUG("protect: first_bank: %i, last_bank: %i", first, last);
+ LOG_DEBUG("protect: first_bank: %u, last_bank: %u", first, last);
/* last bank: 0xFF signals a full device protect */
if (last == 0xFF) {
status = str9xpec_unlock_device(bank);
}
} else {
- for (i = first; i <= last; i++) {
+ for (unsigned int i = first; i <= last; i++) {
if (set)
buf_set_u32(str9xpec_info->options, str9xpec_info->sector_bits[i], 1, 1);
else
return ERROR_OK;
}
-static int str9xpec_write(struct flash_bank *bank, uint8_t *buffer,
+static int str9xpec_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t offset, uint32_t count)
{
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
struct jtag_tap *tap;
struct scan_field field;
uint8_t *scanbuf;
- int i;
- int first_sector = 0;
- int last_sector = 0;
+ unsigned int first_sector = 0;
+ unsigned int last_sector = 0;
tap = str9xpec_info->tap;
return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
}
- for (i = 0; i < bank->num_sectors; i++) {
+ for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint32_t sec_start = bank->sectors[i].offset;
uint32_t sec_end = sec_start + bank->sectors[i].size;
LOG_DEBUG("ISC_PROGRAM");
- for (i = first_sector; i <= last_sector; i++) {
+ for (unsigned int i = first_sector; i <= last_sector; i++) {
str9xpec_set_address(bank, str9xpec_info->sector_bits[i]);
dwords_remaining = dwords_remaining < (bank->sectors[i].size/8)
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;
str9xpec_info = bank->driver_priv;
idcode = buf_get_u32(buffer, 0, 32);
- command_print(CMD_CTX, "str9xpec part id: 0x%8.8" PRIx32 "", idcode);
+ command_print(CMD, "str9xpec part id: 0x%8.8" PRIx32 "", idcode);
free(buffer);
return str9xpec_blank_check(bank, 0, bank->num_sectors - 1);
}
-static int get_str9xpec_info(struct flash_bank *bank, char *buf, int buf_size)
-{
- snprintf(buf, buf_size, "str9xpec flash driver info");
- return ERROR_OK;
-}
-
COMMAND_HANDLER(str9xpec_handle_flash_options_read_command)
{
uint8_t status;
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;
str9xpec_info = bank->driver_priv;
/* boot bank */
if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_CSMAPBIT, 1))
- command_print(CMD_CTX, "CS Map: bank1");
+ command_print(CMD, "CS Map: bank1");
else
- command_print(CMD_CTX, "CS Map: bank0");
+ command_print(CMD, "CS Map: bank0");
/* OTP lock */
if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_OTPBIT, 1))
- command_print(CMD_CTX, "OTP Lock: OTP Locked");
+ command_print(CMD, "OTP Lock: OTP Locked");
else
- command_print(CMD_CTX, "OTP Lock: OTP Unlocked");
+ command_print(CMD, "OTP Lock: OTP Unlocked");
/* LVD Threshold */
if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDTHRESBIT, 1))
- command_print(CMD_CTX, "LVD Threshold: 2.7v");
+ command_print(CMD, "LVD Threshold: 2.7v");
else
- command_print(CMD_CTX, "LVD Threshold: 2.4v");
+ command_print(CMD, "LVD Threshold: 2.4v");
/* LVD reset warning */
if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDWARNBIT, 1))
- command_print(CMD_CTX, "LVD Reset Warning: VDD or VDDQ Inputs");
+ command_print(CMD, "LVD Reset Warning: VDD or VDDQ Inputs");
else
- command_print(CMD_CTX, "LVD Reset Warning: VDD Input Only");
+ command_print(CMD, "LVD Reset Warning: VDD Input Only");
/* LVD reset select */
if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDSELBIT, 1))
- command_print(CMD_CTX, "LVD Reset Selection: VDD or VDDQ Inputs");
+ command_print(CMD, "LVD Reset Selection: VDD or VDDQ Inputs");
else
- command_print(CMD_CTX, "LVD Reset Selection: VDD Input Only");
+ command_print(CMD, "LVD Reset Selection: VDD Input Only");
return 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;
status = str9xpec_write_options(bank);
if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS)
return ERROR_FLASH_OPERATION_FAILED;
- command_print(CMD_CTX, "str9xpec write options complete.\n"
+ command_print(CMD, "str9xpec write options complete.\n"
"INFO: a reset or power cycle is required "
"for the new settings to take effect.");
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;
str9xpec_info = bank->driver_priv;
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;
str9xpec_info = bank->driver_priv;
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;
str9xpec_info = bank->driver_priv;
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;
str9xpec_info = bank->driver_priv;
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;
status = str9xpec_lock_device(bank);
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;
status = str9xpec_unlock_device(bank);
if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS)
return ERROR_FLASH_OPERATION_FAILED;
- command_print(CMD_CTX, "str9xpec unlocked.\n"
+ command_print(CMD, "str9xpec unlocked.\n"
"INFO: a reset or power cycle is required "
"for the new settings to take effect.");
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;
str9xpec_info = bank->driver_priv;
/* remove arm core from chain - enter turbo mode */
tap0 = str9xpec_info->tap;
- if (tap0 == NULL) {
+ if (!tap0) {
/* things are *WRONG* */
- command_print(CMD_CTX, "**STR9FLASH** (tap0) invalid chain?");
+ command_print(CMD, "**STR9FLASH** (tap0) invalid chain?");
return ERROR_FAIL;
}
tap1 = tap0->next_tap;
- if (tap1 == NULL) {
+ if (!tap1) {
/* things are *WRONG* */
- command_print(CMD_CTX, "**STR9FLASH** (tap1) invalid chain?");
+ command_print(CMD, "**STR9FLASH** (tap1) invalid chain?");
return ERROR_FAIL;
}
tap2 = tap1->next_tap;
- if (tap2 == NULL) {
+ if (!tap2) {
/* things are *WRONG* */
- command_print(CMD_CTX, "**STR9FLASH** (tap2) invalid chain?");
+ command_print(CMD, "**STR9FLASH** (tap2) invalid chain?");
return ERROR_FAIL;
}
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;
str9xpec_info = bank->driver_priv;
tap = str9xpec_info->tap;
- if (tap == NULL)
+ if (!tap)
return ERROR_FAIL;
/* exit turbo mode via RESET */
},
{
.name = "part_id",
+ .usage = "<bank>",
.handler = str9xpec_handle_part_id_command,
.mode = COMMAND_EXEC,
- .help = "print part id of str9xpec flash bank <num>",
+ .help = "print part id of str9xpec flash bank",
},
COMMAND_REGISTRATION_DONE
};
COMMAND_REGISTRATION_DONE
};
-struct flash_driver str9xpec_flash = {
+const struct flash_driver str9xpec_flash = {
.name = "str9xpec",
.commands = str9xpec_command_handlers,
.flash_bank_command = str9xpec_flash_bank_command,
.auto_probe = str9xpec_probe,
.erase_check = str9xpec_erase_check,
.protect_check = str9xpec_protect_check,
- .info = get_str9xpec_info,
+ .free_driver_priv = default_flash_free_driver_priv,
};