flash/nor: improved API of flash_driver.info & fixed buffer overruns

1) The API of "info" callback in "struct flash_driver" has been
improved. Fixed buffers for strings

2) Removed the calls to snprintf() from the flash_driver.info
implementations. Many of them were used in an unsafe manner
(buffer overruns were possible).

Change-Id: I42ab8a8018d01f9af43c5ba49f650c3cb5d31dcb
Signed-off-by: Jan Matyas <matyas@codasip.com>
Reviewed-on: http://openocd.zylin.com/6182
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
This commit is contained in:
Jan Matyas
2021-04-23 10:47:17 +02:00
committed by Antonio Borneo
parent f2958fc04b
commit 64c2e03b23
51 changed files with 290 additions and 442 deletions

View File

@@ -161,10 +161,9 @@ FLASH_BANK_COMMAND_HANDLER(ambiqmicro_flash_bank_command)
return ERROR_OK;
}
static int get_ambiqmicro_info(struct flash_bank *bank, char *buf, int buf_size)
static int get_ambiqmicro_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv;
int printed;
char *classname;
if (!ambiqmicro_info->probed) {
@@ -178,16 +177,12 @@ static int get_ambiqmicro_info(struct flash_bank *bank, char *buf, int buf_size)
else
classname = ambiqmicroClassname[0];
printed = snprintf(buf,
buf_size,
"\nAmbiq Micro information: Chip is "
command_print_sameline(cmd, "\nAmbiq Micro information: Chip is "
"class %d (%s) %s\n",
ambiqmicro_info->target_class,
classname,
ambiqmicro_info->target_name);
if ((printed < 0))
return ERROR_BUF_TOO_SMALL;
return ERROR_OK;
}

View File

@@ -256,7 +256,7 @@ static struct sam3_chip *get_current_sam3(struct command_invocation *cmd)
t = get_current_target(cmd->ctx);
if (!t) {
command_print(cmd, "No current target?");
command_print_sameline(cmd, "No current target?\n");
return NULL;
}
@@ -264,7 +264,7 @@ static struct sam3_chip *get_current_sam3(struct command_invocation *cmd)
if (!p) {
/* this should not happen */
/* the command is not registered until the chip is created? */
command_print(cmd, "No SAM3 chips exist?");
command_print_sameline(cmd, "No SAM3 chips exist?\n");
return NULL;
}
@@ -273,7 +273,7 @@ static struct sam3_chip *get_current_sam3(struct command_invocation *cmd)
return p;
p = p->next;
}
command_print(cmd, "Cannot find SAM3 chip?");
command_print_sameline(cmd, "Cannot find SAM3 chip?\n");
return NULL;
}

View File

@@ -235,7 +235,7 @@ static struct sam4_chip *get_current_sam4(struct command_invocation *cmd)
t = get_current_target(cmd->ctx);
if (!t) {
command_print(cmd, "No current target?");
command_print_sameline(cmd, "No current target?\n");
return NULL;
}
@@ -243,7 +243,7 @@ static struct sam4_chip *get_current_sam4(struct command_invocation *cmd)
if (!p) {
/* this should not happen */
/* the command is not registered until the chip is created? */
command_print(cmd, "No SAM4 chips exist?");
command_print_sameline(cmd, "No SAM4 chips exist?\n");
return NULL;
}
@@ -252,7 +252,7 @@ static struct sam4_chip *get_current_sam4(struct command_invocation *cmd)
return p;
p = p->next;
}
command_print(cmd, "Cannot find SAM4 chip?");
command_print_sameline(cmd, "Cannot find SAM4 chip?\n");
return NULL;
}
@@ -2656,19 +2656,16 @@ static int sam4_GetDetails(struct sam4_bank_private *pPrivate)
return ERROR_OK;
}
static int sam4_info(struct flash_bank *bank, char *buf, int buf_size)
static int sam4_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct sam4_bank_private *pPrivate;
int k = bank->size / 1024;
pPrivate = get_sam4_bank_private(bank);
if (pPrivate == NULL) {
buf[0] = '\0';
if (pPrivate == NULL)
return ERROR_FAIL;
}
snprintf(buf, buf_size,
"%s bank %d: %d kB at " TARGET_ADDR_FMT,
command_print_sameline(cmd, "%s bank %d: %d kB at " TARGET_ADDR_FMT,
pPrivate->pChip->details.name,
pPrivate->bank_number,
k,

View File

@@ -978,23 +978,17 @@ static int at91sam7_probe(struct flash_bank *bank)
return ERROR_OK;
}
static int get_at91sam7_info(struct flash_bank *bank, char *buf, int buf_size)
static int get_at91sam7_info(struct flash_bank *bank, struct command_invocation *cmd)
{
int printed;
struct at91sam7_flash_bank *at91sam7_info = bank->driver_priv;
if (at91sam7_info->cidr == 0)
return ERROR_FLASH_BANK_NOT_PROBED;
printed = snprintf(buf, buf_size,
"\n at91sam7 driver information: Chip is %s\n",
command_print_sameline(cmd, "\n at91sam7 driver information: Chip is %s\n",
at91sam7_info->target_name);
buf += printed;
buf_size -= printed;
printed = snprintf(buf,
buf_size,
command_print_sameline(cmd,
" Cidr: 0x%8.8" PRIx32 " | Arch: 0x%4.4x | Eproc: %s | Version: 0x%3.3x | "
"Flashsize: 0x%8.8" PRIx32 "\n",
at91sam7_info->cidr,
@@ -1003,31 +997,20 @@ static int get_at91sam7_info(struct flash_bank *bank, char *buf, int buf_size)
at91sam7_info->cidr_version,
bank->size);
buf += printed;
buf_size -= printed;
printed = snprintf(buf, buf_size,
" Master clock (estimated): %u KHz | External clock: %u KHz\n",
command_print_sameline(cmd,
" Master clock (estimated): %u kHz | External clock: %u kHz\n",
(unsigned)(at91sam7_info->mck_freq / 1000),
(unsigned)(at91sam7_info->ext_freq / 1000));
buf += printed;
buf_size -= printed;
printed = snprintf(buf,
buf_size,
command_print_sameline(cmd,
" Pagesize: %i bytes | Lockbits(%u): %i 0x%4.4x | Pages in lock region: %i\n",
at91sam7_info->pagesize,
bank->num_sectors,
at91sam7_info->num_lockbits_on,
at91sam7_info->lockbits,
at91sam7_info->pages_per_sector*at91sam7_info->num_lockbits_on);
at91sam7_info->pages_per_sector * at91sam7_info->num_lockbits_on);
buf += printed;
buf_size -= printed;
snprintf(buf, buf_size,
" Securitybit: %i | Nvmbits(%i): %i 0x%1.1x\n",
command_print_sameline(cmd, " Securitybit: %i | Nvmbits(%i): %i 0x%1.1x\n",
at91sam7_info->securitybit, at91sam7_info->num_nvmbits,
at91sam7_info->num_nvmbits_on, at91sam7_info->nvmbits);

View File

@@ -875,17 +875,16 @@ static int ath79_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
static int get_ath79_info(struct flash_bank *bank, char *buf, int buf_size)
static int get_ath79_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct ath79_flash_bank *ath79_info = bank->driver_priv;
if (!ath79_info->probed) {
snprintf(buf, buf_size,
"\nATH79 flash bank not probed yet\n");
command_print_sameline(cmd, "\nATH79 flash bank not probed yet\n");
return ERROR_OK;
}
snprintf(buf, buf_size, "\nATH79 flash information:\n"
command_print_sameline(cmd, "\nATH79 flash information:\n"
" Device \'%s\' (ID 0x%08" PRIx32 ")\n",
ath79_info->dev->name, ath79_info->dev->device_id);

View File

@@ -607,7 +607,7 @@ static int samv_write(struct flash_bank *bank, const uint8_t *buffer,
return ERROR_OK;
}
static int samv_get_info(struct flash_bank *bank, char *buf, int buf_size)
static int samv_get_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct samv_flash_bank *samv_info = bank->driver_priv;
if (!samv_info->probed) {
@@ -615,7 +615,7 @@ static int samv_get_info(struct flash_bank *bank, char *buf, int buf_size)
if (ERROR_OK != r)
return r;
}
snprintf(buf, buf_size, "Cortex-M7 detected with %" PRIu32 " kB flash",
command_print_sameline(cmd, "Cortex-M7 detected with %" PRIu32 " kB flash\n",
bank->size / 1024);
return ERROR_OK;
}

View File

@@ -367,7 +367,7 @@ static int avrf_auto_probe(struct flash_bank *bank)
return avrf_probe(bank);
}
static int avrf_info(struct flash_bank *bank, char *buf, int buf_size)
static int avrf_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct target *target = bank->target;
struct avr_common *avr = target->arch_info;
@@ -400,12 +400,12 @@ static int avrf_info(struct flash_bank *bank, char *buf, int buf_size)
if (avr_info != NULL) {
/* chip found */
snprintf(buf, buf_size, "%s - Rev: 0x%" PRIx32 "", avr_info->name,
command_print_sameline(cmd, "%s - Rev: 0x%" PRIx32 "", avr_info->name,
EXTRACT_VER(device_id));
return ERROR_OK;
} else {
/* chip not supported */
snprintf(buf, buf_size, "Cannot identify target as a avr\n");
command_print_sameline(cmd, "Cannot identify target as a avr\n");
return ERROR_FLASH_OPERATION_FAILED;
}
}

View File

@@ -429,7 +429,7 @@ static int bluenrgx_auto_probe(struct flash_bank *bank)
}
/* This method must return a string displaying information about the bank */
static int bluenrgx_get_info(struct flash_bank *bank, char *buf, int buf_size)
static int bluenrgx_get_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct bluenrgx_flash_bank *bluenrgx_info = bank->driver_priv;
int mask_number, cut_number;
@@ -437,8 +437,7 @@ static int bluenrgx_get_info(struct flash_bank *bank, char *buf, int buf_size)
if (!bluenrgx_info->probed) {
int retval = bluenrgx_probe(bank);
if (retval != ERROR_OK) {
snprintf(buf, buf_size,
"Unable to find bank information.");
command_print_sameline(cmd, "Unable to find bank information.");
return retval;
}
}
@@ -446,8 +445,8 @@ static int bluenrgx_get_info(struct flash_bank *bank, char *buf, int buf_size)
mask_number = (bluenrgx_info->die_id >> 4) & 0xF;
cut_number = bluenrgx_info->die_id & 0xF;
snprintf(buf, buf_size,
"%s - Rev: %d.%d", bluenrgx_info->flash_ptr->part_name, mask_number, cut_number);
command_print_sameline(cmd, "%s - Rev: %d.%d",
bluenrgx_info->flash_ptr->part_name, mask_number, cut_number);
return ERROR_OK;
}

View File

@@ -498,10 +498,9 @@ static int cc26xx_auto_probe(struct flash_bank *bank)
return retval;
}
static int cc26xx_info(struct flash_bank *bank, char *buf, int buf_size)
static int cc26xx_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct cc26xx_bank *cc26xx_bank = bank->driver_priv;
int printed = 0;
const char *device;
switch (cc26xx_bank->device_type) {
@@ -526,13 +525,10 @@ static int cc26xx_info(struct flash_bank *bank, char *buf, int buf_size)
break;
}
printed = snprintf(buf, buf_size,
command_print_sameline(cmd,
"%s device: ICEPick ID 0x%08" PRIx32 ", USER ID 0x%08" PRIx32 "\n",
device, cc26xx_bank->icepick_id, cc26xx_bank->user_id);
if (printed >= buf_size)
return ERROR_BUF_TOO_SMALL;
return ERROR_OK;
}

View File

@@ -477,15 +477,9 @@ static int cc3220sf_auto_probe(struct flash_bank *bank)
return retval;
}
static int cc3220sf_info(struct flash_bank *bank, char *buf, int buf_size)
static int cc3220sf_info(struct flash_bank *bank, struct command_invocation *cmd)
{
int printed;
printed = snprintf(buf, buf_size, "CC3220SF with 1MB internal flash\n");
if (printed >= buf_size)
return ERROR_BUF_TOO_SMALL;
command_print_sameline(cmd, "CC3220SF with 1MB internal flash\n");
return ERROR_OK;
}

View File

@@ -728,79 +728,57 @@ static int cfi_read_0002_pri_ext(struct flash_bank *bank)
return cfi_read_spansion_pri_ext(bank);
}
static int cfi_spansion_info(struct flash_bank *bank, char *buf, int buf_size)
static int cfi_spansion_info(struct flash_bank *bank, struct command_invocation *cmd)
{
int printed;
struct cfi_flash_bank *cfi_info = bank->driver_priv;
struct cfi_spansion_pri_ext *pri_ext = cfi_info->pri_ext;
printed = snprintf(buf, buf_size, "\nSpansion primary algorithm extend information:\n");
buf += printed;
buf_size -= printed;
command_print_sameline(cmd, "\nSpansion primary algorithm extend information:\n");
printed = snprintf(buf, buf_size, "pri: '%c%c%c', version: %c.%c\n", pri_ext->pri[0],
pri_ext->pri[1], pri_ext->pri[2],
command_print_sameline(cmd, "pri: '%c%c%c', version: %c.%c\n",
pri_ext->pri[0], pri_ext->pri[1], pri_ext->pri[2],
pri_ext->major_version, pri_ext->minor_version);
buf += printed;
buf_size -= printed;
printed = snprintf(buf, buf_size, "Silicon Rev.: 0x%x, Address Sensitive unlock: 0x%x\n",
command_print_sameline(cmd, "Silicon Rev.: 0x%x, Address Sensitive unlock: 0x%x\n",
(pri_ext->SiliconRevision) >> 2,
(pri_ext->SiliconRevision) & 0x03);
buf += printed;
buf_size -= printed;
printed = snprintf(buf, buf_size, "Erase Suspend: 0x%x, Sector Protect: 0x%x\n",
command_print_sameline(cmd, "Erase Suspend: 0x%x, Sector Protect: 0x%x\n",
pri_ext->EraseSuspend,
pri_ext->BlkProt);
buf += printed;
buf_size -= printed;
snprintf(buf, buf_size, "VppMin: %u.%x, VppMax: %u.%x\n",
command_print_sameline(cmd, "VppMin: %u.%x, VppMax: %u.%x\n",
(pri_ext->VppMin & 0xf0) >> 4, pri_ext->VppMin & 0x0f,
(pri_ext->VppMax & 0xf0) >> 4, pri_ext->VppMax & 0x0f);
return ERROR_OK;
}
static int cfi_intel_info(struct flash_bank *bank, char *buf, int buf_size)
static int cfi_intel_info(struct flash_bank *bank, struct command_invocation *cmd)
{
int printed;
struct cfi_flash_bank *cfi_info = bank->driver_priv;
struct cfi_intel_pri_ext *pri_ext = cfi_info->pri_ext;
printed = snprintf(buf, buf_size, "\nintel primary algorithm extend information:\n");
buf += printed;
buf_size -= printed;
command_print_sameline(cmd, "\nintel primary algorithm extend information:\n");
printed = snprintf(buf,
buf_size,
"pri: '%c%c%c', version: %c.%c\n",
command_print_sameline(cmd, "pri: '%c%c%c', version: %c.%c\n",
pri_ext->pri[0],
pri_ext->pri[1],
pri_ext->pri[2],
pri_ext->major_version,
pri_ext->minor_version);
buf += printed;
buf_size -= printed;
printed = snprintf(buf,
buf_size,
"feature_support: 0x%" PRIx32 ", "
command_print_sameline(cmd, "feature_support: 0x%" PRIx32 ", "
"suspend_cmd_support: 0x%x, blk_status_reg_mask: 0x%x\n",
pri_ext->feature_support,
pri_ext->suspend_cmd_support,
pri_ext->blk_status_reg_mask);
buf += printed;
buf_size -= printed;
printed = snprintf(buf, buf_size, "Vcc opt: %x.%x, Vpp opt: %u.%x\n",
command_print_sameline(cmd, "Vcc opt: %x.%x, Vpp opt: %u.%x\n",
(pri_ext->vcc_optimal & 0xf0) >> 4, pri_ext->vcc_optimal & 0x0f,
(pri_ext->vpp_optimal & 0xf0) >> 4, pri_ext->vpp_optimal & 0x0f);
buf += printed;
buf_size -= printed;
snprintf(buf, buf_size, "protection_fields: %i, prot_reg_addr: 0x%x, "
command_print_sameline(cmd, "protection_fields: %i, prot_reg_addr: 0x%x, "
"factory pre-programmed: %i, user programmable: %i\n",
pri_ext->num_protection_fields, pri_ext->prot_reg_addr,
1 << pri_ext->fact_prot_reg_size, 1 << pri_ext->user_prot_reg_size);
@@ -2992,45 +2970,36 @@ int cfi_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
int cfi_get_info(struct flash_bank *bank, char *buf, int buf_size)
int cfi_get_info(struct flash_bank *bank, struct command_invocation *cmd)
{
int printed;
struct cfi_flash_bank *cfi_info = bank->driver_priv;
if (cfi_info->qry[0] == 0xff) {
snprintf(buf, buf_size, "\ncfi flash bank not probed yet\n");
command_print_sameline(cmd, "\ncfi flash bank not probed yet\n");
return ERROR_OK;
}
if (!cfi_info->not_cfi)
printed = snprintf(buf, buf_size, "\nCFI flash: ");
command_print_sameline(cmd, "\nCFI flash: ");
else
printed = snprintf(buf, buf_size, "\nnon-CFI flash: ");
buf += printed;
buf_size -= printed;
command_print_sameline(cmd, "\nnon-CFI flash: ");
printed = snprintf(buf, buf_size, "mfr: 0x%4.4x, id:0x%4.4x\n\n",
command_print_sameline(cmd, "mfr: 0x%4.4x, id:0x%4.4x\n",
cfi_info->manufacturer, cfi_info->device_id);
buf += printed;
buf_size -= printed;
printed = snprintf(buf, buf_size, "qry: '%c%c%c', pri_id: 0x%4.4x, pri_addr: "
command_print_sameline(cmd, "qry: '%c%c%c', pri_id: 0x%4.4x, pri_addr: "
"0x%4.4x, alt_id: 0x%4.4x, alt_addr: 0x%4.4x\n",
cfi_info->qry[0], cfi_info->qry[1], cfi_info->qry[2],
cfi_info->pri_id, cfi_info->pri_addr, cfi_info->alt_id, cfi_info->alt_addr);
buf += printed;
buf_size -= printed;
printed = snprintf(buf, buf_size, "Vcc min: %x.%x, Vcc max: %x.%x, "
command_print_sameline(cmd, "Vcc min: %x.%x, Vcc max: %x.%x, "
"Vpp min: %u.%x, Vpp max: %u.%x\n",
(cfi_info->vcc_min & 0xf0) >> 4, cfi_info->vcc_min & 0x0f,
(cfi_info->vcc_max & 0xf0) >> 4, cfi_info->vcc_max & 0x0f,
(cfi_info->vpp_min & 0xf0) >> 4, cfi_info->vpp_min & 0x0f,
(cfi_info->vpp_max & 0xf0) >> 4, cfi_info->vpp_max & 0x0f);
buf += printed;
buf_size -= printed;
printed = snprintf(buf, buf_size, "typ. word write timeout: %u us, "
command_print_sameline(cmd, "typ. word write timeout: %u us, "
"typ. buf write timeout: %u us, "
"typ. block erase timeout: %u ms, "
"typ. chip erase timeout: %u ms\n",
@@ -3038,12 +3007,8 @@ int cfi_get_info(struct flash_bank *bank, char *buf, int buf_size)
1 << cfi_info->buf_write_timeout_typ,
1 << cfi_info->block_erase_timeout_typ,
1 << cfi_info->chip_erase_timeout_typ);
buf += printed;
buf_size -= printed;
printed = snprintf(buf,
buf_size,
"max. word write timeout: %u us, "
command_print_sameline(cmd, "max. word write timeout: %u us, "
"max. buf write timeout: %u us, max. "
"block erase timeout: %u ms, max. chip erase timeout: %u ms\n",
(1 <<
@@ -3056,24 +3021,20 @@ int cfi_get_info(struct flash_bank *bank, char *buf, int buf_size)
(1 <<
cfi_info->chip_erase_timeout_max) *
(1 << cfi_info->chip_erase_timeout_typ));
buf += printed;
buf_size -= printed;
printed = snprintf(buf, buf_size, "size: 0x%" PRIx32 ", interface desc: %i, "
command_print_sameline(cmd, "size: 0x%" PRIx32 ", interface desc: %i, "
"max buffer write size: 0x%x\n",
cfi_info->dev_size,
cfi_info->interface_desc,
1 << cfi_info->max_buf_write_size);
buf += printed;
buf_size -= printed;
switch (cfi_info->pri_id) {
case 1:
case 3:
cfi_intel_info(bank, buf, buf_size);
cfi_intel_info(bank, cmd);
break;
case 2:
cfi_spansion_info(bank, buf, buf_size);
cfi_spansion_info(bank, cmd);
break;
default:
LOG_ERROR("cfi primary command set %i unsupported", cfi_info->pri_id);

View File

@@ -160,7 +160,7 @@ int cfi_protect(struct flash_bank *bank, int set, unsigned int first,
int cfi_probe(struct flash_bank *bank);
int cfi_auto_probe(struct flash_bank *bank);
int cfi_protect_check(struct flash_bank *bank);
int cfi_get_info(struct flash_bank *bank, char *buf, int buf_size);
int cfi_get_info(struct flash_bank *bank, struct command_invocation *cmd);
int cfi_flash_bank_cmd(struct flash_bank *bank, unsigned int argc, const char **argv);
uint32_t cfi_flash_address(struct flash_bank *bank, int sector, uint32_t offset);

View File

@@ -205,15 +205,14 @@ struct flash_driver {
/**
* Display human-readable information about the flash
* bank into the given buffer. Drivers must be careful to avoid
* overflowing the buffer.
* bank.
*
* @param bank - the bank to get info about
* @param char - where to put the text for the human to read
* @param buf_size - the size of the human buffer.
* @param cmd - command invocation instance for which to generate
* the textual output
* @returns ERROR_OK if successful; otherwise, an error code.
*/
int (*info)(struct flash_bank *bank, char *buf, int buf_size);
int (*info)(struct flash_bank *bank, struct command_invocation *cmd);
/**
* A more gentle flavor of flash_driver_s::probe, performing

View File

@@ -324,23 +324,7 @@ static int efm32x_read_info(struct flash_bank *bank,
return ERROR_OK;
}
/*
* Helper to create a human friendly string describing a part
*/
static int efm32x_decode_info(struct efm32_info *info, char *buf, int buf_size)
{
int printed = 0;
printed = snprintf(buf, buf_size, "%s Gecko, rev %d",
info->family_data->name, info->prod_rev);
if (printed >= buf_size)
return ERROR_BUF_TOO_SMALL;
return ERROR_OK;
}
/* flash bank efm32 <base> <size> 0 0 <target#>
*/
/* flash bank efm32 <base> <size> 0 0 <target#> */
FLASH_BANK_COMMAND_HANDLER(efm32x_flash_bank_command)
{
struct efm32x_flash_bank *efm32x_info;
@@ -961,7 +945,6 @@ static int efm32x_probe(struct flash_bank *bank)
struct efm32_info efm32_mcu_info;
int ret;
uint32_t base_address = 0x00000000;
char buf[256];
efm32x_info->probed = false;
memset(efm32x_info->lb_page, 0xff, LOCKBITS_PAGE_SZ);
@@ -970,11 +953,8 @@ static int efm32x_probe(struct flash_bank *bank)
if (ERROR_OK != ret)
return ret;
ret = efm32x_decode_info(&efm32_mcu_info, buf, sizeof(buf));
if (ERROR_OK != ret)
return ret;
LOG_INFO("detected part: %s", buf);
LOG_INFO("detected part: %s Gecko, rev %d",
efm32_mcu_info.family_data->name, efm32_mcu_info.prod_rev);
LOG_INFO("flash size = %dkbytes", efm32_mcu_info.flash_sz_kib);
LOG_INFO("flash page size = %dbytes", efm32_mcu_info.page_size);
@@ -1044,10 +1024,10 @@ static int efm32x_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
static int get_efm32x_info(struct flash_bank *bank, char *buf, int buf_size)
static int get_efm32x_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct efm32_info info;
int ret = 0;
int ret;
ret = efm32x_read_info(bank, &info);
if (ERROR_OK != ret) {
@@ -1055,7 +1035,8 @@ static int get_efm32x_info(struct flash_bank *bank, char *buf, int buf_size)
return ret;
}
return efm32x_decode_info(&info, buf, buf_size);
command_print_sameline(cmd, "%s Gecko, rev %d", info.family_data->name, info.prod_rev);
return ERROR_OK;
}
COMMAND_HANDLER(efm32x_handle_debuglock_command)

View File

@@ -487,11 +487,11 @@ static int esirisc_flash_auto_probe(struct flash_bank *bank)
return esirisc_flash_probe(bank);
}
static int esirisc_flash_info(struct flash_bank *bank, char *buf, int buf_size)
static int esirisc_flash_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct esirisc_flash_bank *esirisc_info = bank->driver_priv;
snprintf(buf, buf_size,
command_print_sameline(cmd,
"%4s cfg at 0x%" PRIx32 ", clock %" PRIu32 ", wait_states %" PRIu32,
"", /* align with first line */
esirisc_info->cfg,

View File

@@ -92,9 +92,9 @@ static int faux_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t o
return ERROR_OK;
}
static int faux_info(struct flash_bank *bank, char *buf, int buf_size)
static int faux_info(struct flash_bank *bank, struct command_invocation *cmd)
{
snprintf(buf, buf_size, "faux flash driver");
command_print_sameline(cmd, "faux flash driver");
return ERROR_OK;
}

View File

@@ -1017,17 +1017,16 @@ static int fespi_protect_check(struct flash_bank *bank)
return ERROR_OK;
}
static int get_fespi_info(struct flash_bank *bank, char *buf, int buf_size)
static int get_fespi_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct fespi_flash_bank *fespi_info = bank->driver_priv;
if (!(fespi_info->probed)) {
snprintf(buf, buf_size,
"\nFESPI flash bank not probed yet\n");
command_print_sameline(cmd, "\nFESPI flash bank not probed yet\n");
return ERROR_OK;
}
snprintf(buf, buf_size, "\nFESPI flash information:\n"
command_print_sameline(cmd, "\nFESPI flash information:\n"
" Device \'%s\' (ID 0x%08" PRIx32 ")\n",
fespi_info->dev->name, fespi_info->dev->device_id);

View File

@@ -539,7 +539,7 @@ static int fm4_auto_probe(struct flash_bank *bank)
return fm4_probe(bank);
}
static int fm4_get_info_command(struct flash_bank *bank, char *buf, int buf_size)
static int fm4_get_info_command(struct flash_bank *bank, struct command_invocation *cmd)
{
struct fm4_flash_bank *fm4_bank = bank->driver_priv;
const char *name;
@@ -586,11 +586,10 @@ static int fm4_get_info_command(struct flash_bank *bank, char *buf, int buf_size
case s6e2cx8:
case s6e2cx9:
case s6e2cxa:
snprintf(buf, buf_size, "%s MainFlash Macro #%i",
name, fm4_bank->macro_nr);
command_print_sameline(cmd, "%s MainFlash Macro #%i", name, fm4_bank->macro_nr);
break;
default:
snprintf(buf, buf_size, "%s MainFlash", name);
command_print_sameline(cmd, "%s MainFlash", name);
break;
}

View File

@@ -421,16 +421,16 @@ static int jtagspi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_
return ERROR_OK;
}
static int jtagspi_info(struct flash_bank *bank, char *buf, int buf_size)
static int jtagspi_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct jtagspi_flash_bank *info = bank->driver_priv;
if (!(info->probed)) {
snprintf(buf, buf_size, "\nJTAGSPI flash bank not probed yet\n");
command_print_sameline(cmd, "\nJTAGSPI flash bank not probed yet\n");
return ERROR_OK;
}
snprintf(buf, buf_size, "\nSPIFI flash information:\n"
command_print_sameline(cmd, "\nSPIFI flash information:\n"
" Device \'%s\' (ID 0x%08" PRIx32 ")\n",
info->dev->name, info->dev->device_id);

View File

@@ -2778,7 +2778,7 @@ static int kinetis_auto_probe(struct flash_bank *bank)
return kinetis_probe(bank);
}
static int kinetis_info(struct flash_bank *bank, char *buf, int buf_size)
static int kinetis_info(struct flash_bank *bank, struct command_invocation *cmd)
{
const char *bank_class_names[] = {
"(ANY)", "PFlash", "FlexNVM", "FlexRAM"
@@ -2788,7 +2788,7 @@ static int kinetis_info(struct flash_bank *bank, char *buf, int buf_size)
struct kinetis_chip *k_chip = k_bank->k_chip;
uint32_t size_k = bank->size / 1024;
snprintf(buf, buf_size,
command_print_sameline(cmd,
"%s %s: %" PRIu32 "k %s bank %s at " TARGET_ADDR_FMT,
bank->driver->name, k_chip->name,
size_k, bank_class_names[k_bank->flash_class],

Some files were not shown because too many files have changed in this diff Show More