There are more than 1000 NULL comparisons to be aligned to the
coding style.
For recurrent NULL comparison it's preferable using trivial
scripts in order to minimize the review effort.
Patch generated automatically with the command:
sed -i PATTERN $(find src/ -type f)
where PATTERN is in the list:
's/(\([a-z][a-z0-9_]*\) == NULL)/(!\1)/g'
's/(\([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\) == NULL)/(!\1)/g'
's/(\([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\) == NULL)/(!\1)/g'
's/(\([a-z][a-z0-9_]*\) != NULL)/(\1)/g'
's/(\([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\) != NULL)/(\1)/g'
's/(\([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\) != NULL)/(\1)/g'
's/(NULL == \([a-z][a-z0-9_]*\))/(!\1)/g'
's/(NULL == \([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\))/(!\1)/g'
's/(NULL == \([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\))/(!\1)/g'
's/(NULL != \([a-z][a-z0-9_]*\))/(\1)/g'
's/(NULL != \([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\))/(\1)/g'
's/(NULL != \([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\))/(\1)/g'
Change-Id: Ida103e325d6d0600fb69c0b7a1557ee969db4417
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6350
Tested-by: jenkins
166 files changed:
unsigned get_flash_name_index(const char *name)
{
const char *name_index = strrchr(name, '.');
unsigned get_flash_name_index(const char *name)
{
const char *name_index = strrchr(name, '.');
- if (NULL == name_index)
return 0;
if (name_index[1] < '0' || name_index[1] > '9')
return ~0U;
return 0;
if (name_index[1] < '0' || name_index[1] > '9')
return ~0U;
}
info = calloc(1, sizeof(*info));
}
info = calloc(1, sizeof(*info));
goto fail;
info->eccmode = eccmode;
goto fail;
info->eccmode = eccmode;
duration_start(&state->bench);
duration_start(&state->bench);
- if (NULL != filename) {
int retval = fileio_open(&state->fileio, filename, filemode, FILEIO_BINARY);
if (retval != ERROR_OK) {
const char *msg = (filemode == FILEIO_READ) ? "read" : "write";
int retval = fileio_open(&state->fileio, filename, filemode, FILEIO_BINARY);
if (retval != ERROR_OK) {
const char *msg = (filemode == FILEIO_READ) ? "read" : "write";
if (retval != ERROR_OK)
return retval;
if (retval != ERROR_OK)
return retval;
- if (NULL == nand->device) {
command_print(CMD, "#%s: not probed", CMD_ARGV[0]);
return ERROR_NAND_DEVICE_NOT_PROBED;
}
command_print(CMD, "#%s: not probed", CMD_ARGV[0]);
return ERROR_NAND_DEVICE_NOT_PROBED;
}
size_t total_read = 0;
size_t one_read;
size_t total_read = 0;
size_t one_read;
fileio_read(s->fileio, s->page_size, s->page, &one_read);
if (one_read < s->page_size)
memset(s->page + one_read, 0xff, s->page_size - one_read);
fileio_read(s->fileio, s->page_size, s->page, &one_read);
if (one_read < s->page_size)
memset(s->page + one_read, 0xff, s->page_size - one_read);
nand_calculate_ecc_kw(nand, s->page + i, ecc);
ecc += 10;
}
nand_calculate_ecc_kw(nand, s->page + i, ecc);
ecc += 10;
}
- } else if (NULL != s->oob) {
fileio_read(s->fileio, s->oob_size, s->oob, &one_read);
if (one_read < s->oob_size)
memset(s->oob + one_read, 0xff, s->oob_size - one_read);
fileio_read(s->fileio, s->oob_size, s->oob, &one_read);
if (one_read < s->oob_size)
memset(s->oob + one_read, 0xff, s->oob_size - one_read);
{
struct mx3_nf_controller *mx3_nf_info;
mx3_nf_info = malloc(sizeof(struct mx3_nf_controller));
{
struct mx3_nf_controller *mx3_nf_info;
mx3_nf_info = malloc(sizeof(struct mx3_nf_controller));
- if (mx3_nf_info == NULL) {
LOG_ERROR("no memory for nand controller");
return ERROR_FAIL;
}
LOG_ERROR("no memory for nand controller");
return ERROR_FAIL;
}
int hwecc_needed;
mxc_nf_info = malloc(sizeof(struct mxc_nf_controller));
int hwecc_needed;
mxc_nf_info = malloc(sizeof(struct mxc_nf_controller));
- if (mxc_nf_info == NULL) {
LOG_ERROR("no memory for nand controller");
return ERROR_FAIL;
}
LOG_ERROR("no memory for nand controller");
return ERROR_FAIL;
}
struct s3c24xx_nand_controller *s3c24xx_info;
s3c24xx_info = malloc(sizeof(struct s3c24xx_nand_controller));
struct s3c24xx_nand_controller *s3c24xx_info;
s3c24xx_info = malloc(sizeof(struct s3c24xx_nand_controller));
- if (s3c24xx_info == NULL) {
LOG_ERROR("no memory for nand controller");
return -ENOMEM;
}
LOG_ERROR("no memory for nand controller");
return -ENOMEM;
}
if (retval != ERROR_OK)
return retval;
if (retval != ERROR_OK)
return retval;
- if (NULL == p->device) {
command_print(CMD, "#%s: not probed", CMD_ARGV[0]);
return ERROR_OK;
}
command_print(CMD, "#%s: not probed", CMD_ARGV[0]);
return ERROR_OK;
}
fileio_write(s.fileio, s.page_size, s.page, &size_written);
fileio_write(s.fileio, s.page_size, s.page, &size_written);
fileio_write(s.fileio, s.oob_size, s.oob, &size_written);
s.size -= nand->page_size;
fileio_write(s.fileio, s.oob_size, s.oob, &size_written);
s.size -= nand->page_size;
if (retval != ERROR_OK)
return retval;
if (retval != ERROR_OK)
return retval;
- if (NULL == p->device) {
command_print(CMD, "#%s: not probed", CMD_ARGV[0]);
return ERROR_OK;
}
command_print(CMD, "#%s: not probed", CMD_ARGV[0]);
return ERROR_OK;
}
return ERROR_COMMAND_ARGUMENT_INVALID;
}
return ERROR_COMMAND_ARGUMENT_INVALID;
}
- if (NULL != controller->commands) {
+ if (controller->commands) {
retval = register_commands(CMD_CTX, NULL,
controller->commands);
if (retval != ERROR_OK)
return retval;
}
c = malloc(sizeof(struct nand_device));
retval = register_commands(CMD_CTX, NULL,
controller->commands);
if (retval != ERROR_OK)
return retval;
}
c = malloc(sizeof(struct nand_device));
LOG_ERROR("End of memory");
return ERROR_FAIL;
}
LOG_ERROR("End of memory");
return ERROR_FAIL;
}
- if (controller->usage == NULL)
+ if (!controller->usage)
LOG_DEBUG("'%s' driver usage field missing", controller->name);
nand_device_add(c);
LOG_DEBUG("'%s' driver usage field missing", controller->name);
nand_device_add(c);
const char *driver_name = CMD_ARGV[0];
struct nand_flash_controller *controller;
controller = nand_driver_find_by_name(CMD_ARGV[0]);
const char *driver_name = CMD_ARGV[0];
struct nand_flash_controller *controller;
controller = nand_driver_find_by_name(CMD_ARGV[0]);
- if (NULL == controller) {
LOG_ERROR("No valid NAND flash driver found (%s)", driver_name);
return CALL_COMMAND_HANDLER(handle_nand_list_drivers);
}
LOG_ERROR("No valid NAND flash driver found (%s)", driver_name);
return CALL_COMMAND_HANDLER(handle_nand_list_drivers);
}
{
struct sam3_chip *chip;
{
struct sam3_chip *chip;
return NULL;
chip = all_sam3_chips;
return NULL;
chip = all_sam3_chips;
- if (details->name == NULL) {
LOG_ERROR("SAM3 ChipID 0x%08x not found in table (perhaps you can ID this chip?)",
(unsigned int)(private->chip->cfg.CHIPID_CIDR));
/* Help the victim, print details about the chip */
LOG_ERROR("SAM3 ChipID 0x%08x not found in table (perhaps you can ID this chip?)",
(unsigned int)(private->chip->cfg.CHIPID_CIDR));
/* Help the victim, print details about the chip */
- if (bank->sectors == NULL) {
bank->sectors = calloc(private->nsectors, (sizeof((bank->sectors)[0])));
bank->sectors = calloc(private->nsectors, (sizeof((bank->sectors)[0])));
- if (bank->sectors == NULL) {
LOG_ERROR("No memory!");
return ERROR_FAIL;
}
LOG_ERROR("No memory!");
return ERROR_FAIL;
}
{
struct sam4_chip *chip;
{
struct sam4_chip *chip;
return NULL;
chip = all_sam4_chips;
return NULL;
chip = all_sam4_chips;
- if (details->name == NULL) {
LOG_ERROR("SAM4 ChipID 0x%08x not found in table (perhaps you can ID this chip?)",
(unsigned int)(private->chip->cfg.CHIPID_CIDR));
/* Help the victim, print details about the chip */
LOG_ERROR("SAM4 ChipID 0x%08x not found in table (perhaps you can ID this chip?)",
(unsigned int)(private->chip->cfg.CHIPID_CIDR));
/* Help the victim, print details about the chip */
int k = bank->size / 1024;
private = get_sam4_bank_private(bank);
int k = bank->size / 1024;
private = get_sam4_bank_private(bank);
return ERROR_FAIL;
command_print_sameline(cmd, "%s bank %d: %d kB at " TARGET_ADDR_FMT,
return ERROR_FAIL;
command_print_sameline(cmd, "%s bank %d: %d kB at " TARGET_ADDR_FMT,
- if (bank->sectors == NULL) {
bank->sectors = calloc(private->nsectors, (sizeof((bank->sectors)[0])));
bank->sectors = calloc(private->nsectors, (sizeof((bank->sectors)[0])));
- if (bank->sectors == NULL) {
LOG_ERROR("No memory!");
return ERROR_FAIL;
}
LOG_ERROR("No memory!");
return ERROR_FAIL;
}
{
uint8_t devsel = SAMD_GET_DEVSEL(id);
const struct samd_family *family = samd_find_family(id);
{
uint8_t devsel = SAMD_GET_DEVSEL(id);
const struct samd_family *family = samd_find_family(id);
return NULL;
for (unsigned i = 0; i < family->num_parts; i++) {
return NULL;
for (unsigned i = 0; i < family->num_parts; i++) {
}
part = samd_find_part(id);
}
part = samd_find_part(id);
LOG_ERROR("Couldn't find part corresponding to DID %08" PRIx32, id);
return ERROR_FAIL;
}
LOG_ERROR("Couldn't find part corresponding to DID %08" PRIx32, id);
return ERROR_FAIL;
}
}
const struct samd_family *family;
family = samd_find_family(id);
}
const struct samd_family *family;
family = samd_find_family(id);
LOG_ERROR("Couldn't determine device family");
return ERROR_FAIL;
}
LOG_ERROR("Couldn't determine device family");
return ERROR_FAIL;
}
{
uint8_t devsel = SAMD_GET_DEVSEL(id);
const struct samd_family *family = samd_find_family(id);
{
uint8_t devsel = SAMD_GET_DEVSEL(id);
const struct samd_family *family = samd_find_family(id);
return NULL;
for (unsigned i = 0; i < family->num_parts; i++) {
return NULL;
for (unsigned i = 0; i < family->num_parts; i++) {
}
part = samd_find_part(id);
}
part = samd_find_part(id);
LOG_ERROR("Couldn't find part corresponding to DID %08" PRIx32, id);
return ERROR_FAIL;
}
LOG_ERROR("Couldn't find part corresponding to DID %08" PRIx32, id);
return ERROR_FAIL;
}
- if (avr_info != NULL) {
free(bank->sectors);
/* chip found */
free(bank->sectors);
/* chip found */
- if (avr_info != NULL) {
/* chip found */
command_print_sameline(cmd, "%s - Rev: 0x%" PRIx32 "", avr_info->name,
EXTRACT_VER(device_id));
/* chip found */
command_print_sameline(cmd, "%s - Rev: 0x%" PRIx32 "", avr_info->name,
EXTRACT_VER(device_id));
bluenrgx_info = calloc(1, sizeof(*bluenrgx_info));
/* Check allocation */
bluenrgx_info = calloc(1, sizeof(*bluenrgx_info));
/* Check allocation */
- if (bluenrgx_info == NULL) {
LOG_ERROR("failed to allocate bank structure");
return ERROR_FAIL;
}
LOG_ERROR("failed to allocate bank structure");
return ERROR_FAIL;
}
return retval;
/* Check for working area to use for flash helper algorithm */
return retval;
/* Check for working area to use for flash helper algorithm */
- if (NULL != cc26xx_bank->working_area)
+ if (cc26xx_bank->working_area)
target_free_working_area(target, cc26xx_bank->working_area);
retval = target_alloc_working_area(target, cc26xx_bank->algo_working_size,
&cc26xx_bank->working_area);
target_free_working_area(target, cc26xx_bank->working_area);
retval = target_alloc_working_area(target, cc26xx_bank->algo_working_size,
&cc26xx_bank->working_area);
return ERROR_COMMAND_SYNTAX_ERROR;
cc26xx_bank = malloc(sizeof(struct cc26xx_bank));
return ERROR_COMMAND_SYNTAX_ERROR;
cc26xx_bank = malloc(sizeof(struct cc26xx_bank));
- if (NULL == cc26xx_bank)
return ERROR_FAIL;
/* Initialize private flash information */
return ERROR_FAIL;
/* Initialize private flash information */
num_sectors = max_sectors;
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
num_sectors = max_sectors;
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
- if (NULL == bank->sectors)
return ERROR_FAIL;
bank->base = CC26XX_FLASH_BASE_ADDR;
return ERROR_FAIL;
bank->base = CC26XX_FLASH_BASE_ADDR;
return ERROR_COMMAND_SYNTAX_ERROR;
cc3220sf_bank = malloc(sizeof(struct cc3220sf_bank));
return ERROR_COMMAND_SYNTAX_ERROR;
cc3220sf_bank = malloc(sizeof(struct cc3220sf_bank));
- if (NULL == cc3220sf_bank)
return ERROR_FAIL;
/* Initialize private flash information */
return ERROR_FAIL;
/* Initialize private flash information */
free(bank->sectors);
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
free(bank->sectors);
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
- if (NULL == bank->sectors)
return ERROR_FAIL;
bank->base = base;
return ERROR_FAIL;
bank->base = base;
free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_intel_pri_ext));
free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_intel_pri_ext));
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext));
free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext));
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext));
free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext));
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
}
cfi_info = calloc(1, sizeof(struct cfi_flash_bank));
}
cfi_info = calloc(1, sizeof(struct cfi_flash_bank));
- if (cfi_info == NULL) {
LOG_ERROR("No memory for flash bank info");
return ERROR_FAIL;
}
LOG_ERROR("No memory for flash bank info");
return ERROR_FAIL;
}
/* convert bus-width dependent algorithm code to correct endianness */
target_code = malloc(target_code_size);
/* convert bus-width dependent algorithm code to correct endianness */
target_code = malloc(target_code_size);
- if (target_code == NULL) {
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
/* convert bus-width dependent algorithm code to correct endianness */
target_code = malloc(target_code_size);
/* convert bus-width dependent algorithm code to correct endianness */
target_code = malloc(target_code_size);
- if (target_code == NULL) {
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
if (flash_banks) {
/* find last flash bank */
struct flash_bank *p = flash_banks;
if (flash_banks) {
/* find last flash bank */
struct flash_bank *p = flash_banks;
- while (NULL != p->next) {
bank_num += 1;
p = p->next;
}
bank_num += 1;
p = p->next;
}
int retval;
bank = get_flash_bank_by_name_noprobe(name);
int retval;
bank = get_flash_bank_by_name_noprobe(name);
retval = bank->driver->auto_probe(bank);
if (retval != ERROR_OK) {
retval = bank->driver->auto_probe(bank);
if (retval != ERROR_OK) {
struct flash_bank *p = get_flash_bank_by_num_noprobe(num);
int retval;
struct flash_bank *p = get_flash_bank_by_num_noprobe(num);
int retval;
return ERROR_FAIL;
retval = p->driver->auto_probe(p);
return ERROR_FAIL;
retval = p->driver->auto_probe(p);
struct target_memory_check_block *block_array;
block_array = malloc(bank->num_sectors * sizeof(struct target_memory_check_block));
struct target_memory_check_block *block_array;
block_array = malloc(bank->num_sectors * sizeof(struct target_memory_check_block));
- if (block_array == NULL)
return default_flash_mem_blank_check(bank);
for (unsigned int i = 0; i < bank->num_sectors; i++) {
return default_flash_mem_blank_check(bank);
for (unsigned int i = 0; i < bank->num_sectors; i++) {
retval = get_flash_bank_by_addr(target, run_address, false, &c);
if (retval != ERROR_OK)
goto done;
retval = get_flash_bank_by_addr(target, run_address, false, &c);
if (retval != ERROR_OK)
goto done;
LOG_WARNING("no flash bank found for address " TARGET_ADDR_FMT, run_address);
section++; /* and skip it */
section_offset = 0;
LOG_WARNING("no flash bank found for address " TARGET_ADDR_FMT, run_address);
section++; /* and skip it */
section_offset = 0;
/* allocate buffer */
buffer = malloc(run_size);
/* allocate buffer */
buffer = malloc(run_size);
LOG_ERROR("Out of memory for flash bank buffer");
retval = ERROR_FAIL;
goto done;
LOG_ERROR("Out of memory for flash bank buffer");
retval = ERROR_FAIL;
goto done;
*written += run_size; /* add run size to total written counter */
}
*written += run_size; /* add run size to total written counter */
}
unsigned int num_blocks)
{
struct flash_sector *array = calloc(num_blocks, sizeof(struct flash_sector));
unsigned int num_blocks)
{
struct flash_sector *array = calloc(num_blocks, sizeof(struct flash_sector));
return NULL;
for (unsigned int i = 0; i < num_blocks; i++) {
return NULL;
for (unsigned int i = 0; i < num_blocks; i++) {
efm32_info->family_data = &efm32_families[i];
}
efm32_info->family_data = &efm32_families[i];
}
- if (efm32_info->family_data == NULL) {
+ if (!efm32_info->family_data) {
LOG_ERROR("Unknown MCU family %d", efm32_info->part_family);
return ERROR_FAIL;
}
LOG_ERROR("Unknown MCU family %d", efm32_info->part_family);
return ERROR_FAIL;
}
uint32_t old_count = count;
count = (old_count | 3) + 1;
new_buffer = malloc(count);
uint32_t old_count = count;
count = (old_count | 3) + 1;
new_buffer = malloc(count);
- if (new_buffer == NULL) {
LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer");
return ERROR_FAIL;
LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer");
return ERROR_FAIL;
- assert(NULL != bank->sectors);
for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = efm32x_get_page_lock(bank, i);
for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = efm32x_get_page_lock(bank, i);
return ERROR_COMMAND_SYNTAX_ERROR;
info = malloc(sizeof(struct faux_flash_bank));
return ERROR_COMMAND_SYNTAX_ERROR;
info = malloc(sizeof(struct faux_flash_bank));
LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL;
}
info->memory = malloc(bank->size);
LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL;
}
info->memory = malloc(bank->size);
- if (info->memory == NULL) {
free(info);
LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL;
free(info);
LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL;
}
info->target = get_target(CMD_ARGV[5]);
}
info->target = get_target(CMD_ARGV[5]);
- if (info->target == NULL) {
LOG_ERROR("target '%s' not defined", CMD_ARGV[5]);
free(info->memory);
free(info);
LOG_ERROR("target '%s' not defined", CMD_ARGV[5]);
free(info->memory);
free(info);
return ERROR_COMMAND_SYNTAX_ERROR;
fespi_info = malloc(sizeof(struct fespi_flash_bank));
return ERROR_COMMAND_SYNTAX_ERROR;
fespi_info = malloc(sizeof(struct fespi_flash_bank));
- if (fespi_info == NULL) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
/* create and fill sectors array */
bank->num_sectors = fespi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
/* create and fill sectors array */
bank->num_sectors = fespi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
return ERROR_COMMAND_SYNTAX_ERROR;
info = malloc(sizeof(struct jtagspi_flash_bank));
return ERROR_COMMAND_SYNTAX_ERROR;
info = malloc(sizeof(struct jtagspi_flash_bank));
LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL;
}
LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL;
}
lenb = DIV_ROUND_UP(len, 8);
data_buf = malloc(lenb);
if (lenb > 0) {
lenb = DIV_ROUND_UP(len, 8);
data_buf = malloc(lenb);
if (lenb > 0) {
- if (data_buf == NULL) {
LOG_ERROR("no memory for spi buffer");
return ERROR_FAIL;
}
LOG_ERROR("no memory for spi buffer");
return ERROR_FAIL;
}
/* create and fill sectors array */
bank->num_sectors = info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
/* create and fill sectors array */
bank->num_sectors = info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
k_chip = kinetis_get_chip(target);
k_chip = kinetis_get_chip(target);
k_chip = calloc(sizeof(struct kinetis_chip), 1);
k_chip = calloc(sizeof(struct kinetis_chip), 1);
LOG_ERROR("No memory");
return ERROR_FAIL;
}
LOG_ERROR("No memory");
return ERROR_FAIL;
}
static void kinetis_free_driver_priv(struct flash_bank *bank)
{
struct kinetis_flash_bank *k_bank = bank->driver_priv;
static void kinetis_free_driver_priv(struct flash_bank *bank)
{
struct kinetis_flash_bank *k_bank = bank->driver_priv;
return;
struct kinetis_chip *k_chip = k_bank->k_chip;
return;
struct kinetis_chip *k_chip = k_bank->k_chip;
return;
k_chip->num_banks--;
return;
k_chip->num_banks--;
}
bank = calloc(sizeof(struct flash_bank), 1);
}
bank = calloc(sizeof(struct flash_bank), 1);
return ERROR_FAIL;
bank->target = k_chip->target;
return ERROR_FAIL;
bank->target = k_chip->target;
struct target *target = get_current_target(CMD_CTX);
struct kinetis_chip *k_chip = kinetis_get_chip(target);
struct target *target = get_current_target(CMD_CTX);
struct kinetis_chip *k_chip = kinetis_get_chip(target);
return ERROR_FAIL;
if (CMD_ARGC > 0)
return ERROR_FAIL;
if (CMD_ARGC > 0)
k_bank = &(k_chip->banks[bank_idx]);
bank_iter = k_bank->bank;
k_bank = &(k_chip->banks[bank_idx]);
bank_iter = k_bank->bank;
- if (bank_iter == NULL) {
LOG_WARNING("Missing bank %u configuration, FCF protection flags may be incomplete", bank_idx);
continue;
}
LOG_WARNING("Missing bank %u configuration, FCF protection flags may be incomplete", bank_idx);
continue;
}
uint8_t pmstat;
struct target *target;
uint8_t pmstat;
struct target *target;
LOG_ERROR("Chip not probed.");
return ERROR_FAIL;
}
LOG_ERROR("Chip not probed.");
return ERROR_FAIL;
}
uint32_t old_count = count;
count = (old_count | 3) + 1;
new_buffer = malloc(count);
uint32_t old_count = count;
count = (old_count | 3) + 1;
new_buffer = malloc(count);
- if (new_buffer == NULL) {
LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer");
return ERROR_FAIL;
LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer");
return ERROR_FAIL;
}
switch (sz_type) {
case SHOW_INFO:
}
switch (sz_type) {
case SHOW_INFO:
LOG_ERROR("Chip not probed.");
return ERROR_FAIL;
}
LOG_ERROR("Chip not probed.");
return ERROR_FAIL;
}
if (result != ERROR_OK)
return result;
if (result != ERROR_OK)
return result;
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
uint32_t old_count = count;
count = (old_count | 3) + 1;
new_buffer = malloc(count);
uint32_t old_count = count;
count = (old_count | 3) + 1;
new_buffer = malloc(count);
- if (new_buffer == NULL) {
LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer");
return ERROR_FAIL;
LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer");
return ERROR_FAIL;
return ERROR_COMMAND_SYNTAX_ERROR;
lpcspifi_info = malloc(sizeof(struct lpcspifi_flash_bank));
return ERROR_COMMAND_SYNTAX_ERROR;
lpcspifi_info = malloc(sizeof(struct lpcspifi_flash_bank));
- if (lpcspifi_info == NULL) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
/* create and fill sectors array */
bank->num_sectors = lpcspifi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
/* create and fill sectors array */
bank->num_sectors = lpcspifi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
int rem = count % 4;
if (rem) {
new_buffer = malloc(count + rem);
int rem = count % 4;
if (rem) {
new_buffer = malloc(count + rem);
- if (new_buffer == NULL) {
LOG_ERROR("odd number of bytes to write and no memory for padding buffer");
return ERROR_FAIL;
}
LOG_ERROR("odd number of bytes to write and no memory for padding buffer");
return ERROR_FAIL;
}
/* create and fill sectors array */
bank->num_sectors = mrvlqspi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
/* create and fill sectors array */
bank->num_sectors = mrvlqspi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
return ERROR_COMMAND_SYNTAX_ERROR;
mrvlqspi_info = malloc(sizeof(struct mrvlqspi_flash_bank));
return ERROR_COMMAND_SYNTAX_ERROR;
mrvlqspi_info = malloc(sizeof(struct mrvlqspi_flash_bank));
- if (mrvlqspi_info == NULL) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
}
/* Check for working area to use for flash helper algorithm */
}
/* Check for working area to use for flash helper algorithm */
- if (NULL != msp432_bank->working_area)
+ if (msp432_bank->working_area)
target_free_working_area(target, msp432_bank->working_area);
retval = target_alloc_working_area(target, ALGO_WORKING_SIZE,
&msp432_bank->working_area);
target_free_working_area(target, msp432_bank->working_area);
retval = target_alloc_working_area(target, ALGO_WORKING_SIZE,
&msp432_bank->working_area);
/* Create shared private struct for flash banks */
msp432_bank = malloc(sizeof(struct msp432_bank));
/* Create shared private struct for flash banks */
msp432_bank = malloc(sizeof(struct msp432_bank));
- if (NULL == msp432_bank)
return ERROR_FAIL;
/* Initialize private flash information */
return ERROR_FAIL;
/* Initialize private flash information */
if (num_sectors > 0) {
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
if (num_sectors > 0) {
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
- if (NULL == bank->sectors)
if (is_main && MSP432P4 == msp432_bank->family_type) {
/* Create the info flash bank needed by MSP432P4 variants */
struct flash_bank *info = calloc(sizeof(struct flash_bank), 1);
if (is_main && MSP432P4 == msp432_bank->family_type) {
/* Create the info flash bank needed by MSP432P4 variants */
struct flash_bank *info = calloc(sizeof(struct flash_bank), 1);
return ERROR_FAIL;
/* Create a name for the info bank, append "_1" to main name */
return ERROR_FAIL;
/* Create a name for the info bank, append "_1" to main name */
int rem = count % 16;
if (rem) {
new_buffer = malloc(count + 16 - rem);
int rem = count % 16;
if (rem) {
new_buffer = malloc(count + 16 - rem);
- if (new_buffer == NULL) {
LOG_ERROR("Odd number of words to write and no memory for padding buffer");
return ERROR_FAIL;
}
LOG_ERROR("Odd number of words to write and no memory for padding buffer");
return ERROR_FAIL;
}
{
struct nrf5_bank *nbank = bank->driver_priv;
{
struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_info *chip = nbank->chip;
struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_info *chip = nbank->chip;
res = target_read_u32(chip->target, NRF51_FICR_CLENR0,
&clenr0);
res = target_read_u32(chip->target, NRF51_FICR_CLENR0,
&clenr0);
struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_info *chip = nbank->chip;
struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_info *chip = nbank->chip;
static uint32_t nrf5_bprot_offsets[4] = { 0x600, 0x604, 0x610, 0x614 };
uint32_t bprot_reg = 0;
static uint32_t nrf5_bprot_offsets[4] = { 0x600, 0x604, 0x610, 0x614 };
uint32_t bprot_reg = 0;
struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_info *chip = nbank->chip;
struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_info *chip = nbank->chip;
if (chip->features & NRF5_FEATURE_BPROT)
return nrf5_protect_check_bprot(bank);
if (chip->features & NRF5_FEATURE_BPROT)
return nrf5_protect_check_bprot(bank);
{
struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_info *chip = nbank->chip;
{
struct nrf5_bank *nbank = bank->driver_priv;
struct nrf5_info *chip = nbank->chip;
return;
chip->refcount--;
return;
chip->refcount--;
nbank = &chip->bank[1];
break;
}
nbank = &chip->bank[1];
break;
}
chip->refcount++;
nbank->chip = chip;
chip->refcount++;
nbank->chip = chip;
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
init_reg_param(®_params[2], "r2", 32, PARAM_OUT); /* number of words to program */
struct armv7m_common *armv7m = target_to_armv7m(target);
init_reg_param(®_params[2], "r2", 32, PARAM_OUT); /* number of words to program */
struct armv7m_common *armv7m = target_to_armv7m(target);
/* something is very wrong if armv7m is NULL */
LOG_ERROR("unable to get armv7m target");
return retval;
/* something is very wrong if armv7m is NULL */
LOG_ERROR("unable to get armv7m target");
return retval;
uint8_t *new_buffer = NULL;
if (row_offset && (count >= (row_size / 4))) {
new_buffer = malloc(buffer_size);
uint8_t *new_buffer = NULL;
if (row_offset && (count >= (row_size / 4))) {
new_buffer = malloc(buffer_size);
- if (new_buffer == NULL) {
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
sysreq_wait_algorithm->address + sysreq_wait_algorithm->size);
struct armv7m_common *armv7m = target_to_armv7m(target);
sysreq_wait_algorithm->address + sysreq_wait_algorithm->size);
struct armv7m_common *armv7m = target_to_armv7m(target);
/* something is very wrong if armv7m is NULL */
LOG_ERROR("unable to get armv7m target");
retval = ERROR_FAIL;
/* something is very wrong if armv7m is NULL */
LOG_ERROR("unable to get armv7m target");
retval = ERROR_FAIL;
int prot_sz = num_bits / 8;
sysrq_buffer = malloc(param_sz + prot_sz);
int prot_sz = num_bits / 8;
sysrq_buffer = malloc(param_sz + prot_sz);
- if (sysrq_buffer == NULL) {
LOG_ERROR("no memory for row buffer");
return ERROR_FAIL;
}
LOG_ERROR("no memory for row buffer");
return ERROR_FAIL;
}
return retval;
sysrq_buffer = malloc(param_sz + psoc4_info->row_size);
return retval;
sysrq_buffer = malloc(param_sz + psoc4_info->row_size);
- if (sysrq_buffer == NULL) {
LOG_ERROR("no memory for row buffer");
return ERROR_FAIL;
}
LOG_ERROR("no memory for row buffer");
return ERROR_FAIL;
}
bank->size = num_rows * row_size;
bank->num_sectors = num_rows;
bank->sectors = alloc_block_array(0, row_size, num_rows);
bank->size = num_rows * row_size;
bank->num_sectors = num_rows;
bank->sectors = alloc_block_array(0, row_size, num_rows);
- if (bank->sectors == NULL)
return ERROR_FAIL;
LOG_DEBUG("flash bank set %" PRIu32 " rows", num_rows);
return ERROR_FAIL;
LOG_DEBUG("flash bank set %" PRIu32 " rows", num_rows);
struct target_memory_check_block *block_array;
block_array = malloc(num_sectors * sizeof(struct target_memory_check_block));
struct target_memory_check_block *block_array;
block_array = malloc(num_sectors * sizeof(struct target_memory_check_block));
- if (block_array == NULL)
return ERROR_FAIL;
for (unsigned int i = 0; i < num_sectors; i++) {
return ERROR_FAIL;
for (unsigned int i = 0; i < num_sectors; i++) {
nph = ((header.revision >> 16) & 0xFF) + 1;
LOG_DEBUG("parameter headers: %d", nph);
pheaders = malloc(sizeof(struct sfdp_phdr) * nph);
nph = ((header.revision >> 16) & 0xFF) + 1;
LOG_DEBUG("parameter headers: %d", nph);
pheaders = malloc(sizeof(struct sfdp_phdr) * nph);
- if (pheaders == NULL) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
/* retrieve parameter table */
ptable = malloc(words << 2);
/* retrieve parameter table */
ptable = malloc(words << 2);
LOG_ERROR("not enough memory");
retval = ERROR_FAIL;
goto err;
LOG_ERROR("not enough memory");
retval = ERROR_FAIL;
goto err;
count++;
new_buffer = malloc(count);
count++;
new_buffer = malloc(count);
- if (new_buffer == NULL) {
LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer");
return ERROR_FAIL;
LOG_ERROR("odd number of bytes to write and no memory "
"for padding buffer");
return ERROR_FAIL;
struct cortex_m_common *cortex_m = target_to_cm(target);
struct adiv5_dap *dap = cortex_m->armv7m.arm.dap;
struct cortex_m_common *cortex_m = target_to_cm(target);
struct adiv5_dap *dap = cortex_m->armv7m.arm.dap;
/* Used debug interface doesn't support direct DAP access */
LOG_ERROR("mass_erase can't be used by this debug interface");
return ERROR_FAIL;
/* Used debug interface doesn't support direct DAP access */
LOG_ERROR("mass_erase can't be used by this debug interface");
return ERROR_FAIL;
struct cortex_m_common *cortex_m = target_to_cm(target);
struct adiv5_dap *dap = cortex_m->armv7m.arm.dap;
struct cortex_m_common *cortex_m = target_to_cm(target);
struct adiv5_dap *dap = cortex_m->armv7m.arm.dap;
/* Used debug interface doesn't support direct DAP access */
LOG_INFO("Target can't by unlocked by this debug interface");
/* Used debug interface doesn't support direct DAP access */
LOG_INFO("Target can't by unlocked by this debug interface");
LOG_ERROR("Unexpected lock word value");
/* SIM3X_AP_ID_VALUE is not checked */
LOG_ERROR("Unexpected lock word value");
/* SIM3X_AP_ID_VALUE is not checked */
LOG_INFO("Maybe this isn't a SiM3x MCU");
return ERROR_FAIL;
LOG_INFO("Maybe this isn't a SiM3x MCU");
return ERROR_FAIL;
* discrete accesses. */
if (count & 1) {
new_buffer = malloc(count + 1);
* discrete accesses. */
if (count & 1) {
new_buffer = malloc(count + 1);
- if (new_buffer == NULL) {
LOG_ERROR("odd number of bytes to write and no memory for padding buffer");
return ERROR_FAIL;
}
LOG_ERROR("odd number of bytes to write and no memory for padding buffer");
return ERROR_FAIL;
}
command_print_sameline(cmd, "%s - Rev: %s", device_str, rev_str);
else
command_print_sameline(cmd, "%s - Rev: unknown (0x%04x)", device_str, rev_id);
command_print_sameline(cmd, "%s - Rev: %s", device_str, rev_str);
else
command_print_sameline(cmd, "%s - Rev: unknown (0x%04x)", device_str, rev_id);
command_print_sameline(cmd, "%s - Rev: %s", device_str, rev_str);
else
command_print_sameline(cmd, "%s - Rev: unknown (0x%04" PRIx16 ")", device_str, rev_id);
command_print_sameline(cmd, "%s - Rev: %s", device_str, rev_str);
else
command_print_sameline(cmd, "%s - Rev: unknown (0x%04" PRIx16 ")", device_str, rev_id);
bank->sectors = alloc_block_array(0, stm32x_info->part_info->page_size_kb * 1024,
bank->num_sectors);
bank->sectors = alloc_block_array(0, stm32x_info->part_info->page_size_kb * 1024,
bank->num_sectors);
- if (bank->sectors == NULL) {
LOG_ERROR("failed to allocate bank sectors");
return ERROR_FAIL;
}
LOG_ERROR("failed to allocate bank sectors");
return ERROR_FAIL;
}
bank->prot_blocks = alloc_block_array(0, stm32x_info->part_info->page_size_kb * wpsn * 1024,
bank->num_prot_blocks);
bank->prot_blocks = alloc_block_array(0, stm32x_info->part_info->page_size_kb * wpsn * 1024,
bank->num_prot_blocks);
- if (bank->prot_blocks == NULL) {
+ if (!bank->prot_blocks) {
LOG_ERROR("failed to allocate bank prot_block");
return ERROR_FAIL;
}
LOG_ERROR("failed to allocate bank prot_block");
return ERROR_FAIL;
}
if (rev_id == info->revs[i].rev)
rev_str = info->revs[i].str;
if (rev_id == info->revs[i].rev)
rev_str = info->revs[i].str;
command_print_sameline(cmd, "%s - Rev: %s",
stm32x_info->part_info->device_str, rev_str);
} else {
command_print_sameline(cmd, "%s - Rev: %s",
stm32x_info->part_info->device_str, rev_str);
} else {
bank->size = (flash_size_kb + gap_size_kb) * 1024;
bank->num_sectors = num_pages;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
bank->size = (flash_size_kb + gap_size_kb) * 1024;
bank->num_sectors = num_pages;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
- if (bank->sectors == NULL) {
LOG_ERROR("failed to allocate bank sectors");
return ERROR_FAIL;
}
LOG_ERROR("failed to allocate bank sectors");
return ERROR_FAIL;
}
stm32lx_info = calloc(1, sizeof(*stm32lx_info));
/* Check allocation */
stm32lx_info = calloc(1, sizeof(*stm32lx_info));
/* Check allocation */
- if (stm32lx_info == NULL) {
LOG_ERROR("failed to allocate bank structure");
return ERROR_FAIL;
}
LOG_ERROR("failed to allocate bank structure");
return ERROR_FAIL;
}
}
struct armv7m_common *armv7m = target_to_armv7m(target);
}
struct armv7m_common *armv7m = target_to_armv7m(target);
/* something is very wrong if armv7m is NULL */
LOG_ERROR("unable to get armv7m target");
/* something is very wrong if armv7m is NULL */
LOG_ERROR("unable to get armv7m target");
bank->base = base_address;
bank->num_sectors = num_sectors;
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
bank->base = base_address;
bank->num_sectors = num_sectors;
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
- if (bank->sectors == NULL) {
LOG_ERROR("failed to allocate bank sectors");
return ERROR_FAIL;
}
LOG_ERROR("failed to allocate bank sectors");
return ERROR_FAIL;
}
if (rev_id == info->revs[i].rev)
rev_str = info->revs[i].str;
if (rev_id == info->revs[i].rev)
rev_str = info->revs[i].str;
command_print_sameline(cmd, "%s - Rev: %s", info->device_str, rev_str);
} else {
command_print_sameline(cmd, "%s - Rev: unknown (0x%04x)", info->device_str, rev_id);
command_print_sameline(cmd, "%s - Rev: %s", info->device_str, rev_str);
} else {
command_print_sameline(cmd, "%s - Rev: unknown (0x%04x)", info->device_str, rev_id);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], io_base);
stmqspi_info = malloc(sizeof(struct stmqspi_flash_bank));
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], io_base);
stmqspi_info = malloc(sizeof(struct stmqspi_flash_bank));
- if (stmqspi_info == NULL) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
bank->num_sectors =
stmqspi_info->dev.size_in_bytes / stmqspi_info->dev.sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
bank->num_sectors =
stmqspi_info->dev.size_in_bytes / stmqspi_info->dev.sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
/* create and fill sectors array */
bank->num_sectors = stmqspi_info->dev.size_in_bytes / stmqspi_info->dev.sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
/* create and fill sectors array */
bank->num_sectors = stmqspi_info->dev.size_in_bytes / stmqspi_info->dev.sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
LOG_ERROR("not enough memory");
retval = ERROR_FAIL;
goto err;
LOG_ERROR("not enough memory");
retval = ERROR_FAIL;
goto err;
return ERROR_COMMAND_SYNTAX_ERROR;
stmsmi_info = malloc(sizeof(struct stmsmi_flash_bank));
return ERROR_COMMAND_SYNTAX_ERROR;
stmsmi_info = malloc(sizeof(struct stmsmi_flash_bank));
- if (stmsmi_info == NULL) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
bank->num_sectors =
stmsmi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
bank->num_sectors =
stmsmi_info->dev->size_in_bytes / sectorsize;
sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
static int str9xpec_set_instr(struct jtag_tap *tap, uint32_t new_instr, tap_state_t end_state)
{
static int str9xpec_set_instr(struct jtag_tap *tap, uint32_t new_instr, tap_state_t end_state)
{
return ERROR_TARGET_INVALID;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
return ERROR_TARGET_INVALID;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
/* remove arm core from chain - enter turbo mode */
tap0 = str9xpec_info->tap;
/* remove arm core from chain - enter turbo mode */
tap0 = str9xpec_info->tap;
/* things are *WRONG* */
command_print(CMD, "**STR9FLASH** (tap0) invalid chain?");
return ERROR_FAIL;
}
tap1 = tap0->next_tap;
/* things are *WRONG* */
command_print(CMD, "**STR9FLASH** (tap0) invalid chain?");
return ERROR_FAIL;
}
tap1 = tap0->next_tap;
/* things are *WRONG* */
command_print(CMD, "**STR9FLASH** (tap1) invalid chain?");
return ERROR_FAIL;
}
tap2 = tap1->next_tap;
/* things are *WRONG* */
command_print(CMD, "**STR9FLASH** (tap1) invalid chain?");
return ERROR_FAIL;
}
tap2 = tap1->next_tap;
/* things are *WRONG* */
command_print(CMD, "**STR9FLASH** (tap2) invalid chain?");
return ERROR_FAIL;
/* things are *WRONG* */
command_print(CMD, "**STR9FLASH** (tap2) invalid chain?");
return ERROR_FAIL;
str9xpec_info = bank->driver_priv;
tap = str9xpec_info->tap;
str9xpec_info = bank->driver_priv;
tap = str9xpec_info->tap;
return ERROR_FAIL;
/* exit turbo mode via RESET */
return ERROR_FAIL;
/* exit turbo mode via RESET */
if (retval != ERROR_OK)
return retval;
if (retval != ERROR_OK)
return retval;
int num_blocks;
struct flash_sector *block_array;
int num_blocks;
struct flash_sector *block_array;
uint32_t padding_at_end = aligned_end - end_addr;
uint8_t *buffer = malloc(aligned_size);
uint32_t padding_at_end = aligned_end - end_addr;
uint8_t *buffer = malloc(aligned_size);
return ERROR_FAIL;
if (padding_at_start) {
return ERROR_FAIL;
if (padding_at_start) {
}
uint8_t *buffer = calloc(count, wordsize);
}
uint8_t *buffer = calloc(count, wordsize);
command_print(CMD, "No memory for flash read buffer");
return ERROR_FAIL;
}
command_print(CMD, "No memory for flash read buffer");
return ERROR_FAIL;
}
uint32_t padding_at_end = aligned_end - end_addr;
buffer = malloc(aligned_size);
uint32_t padding_at_end = aligned_end - end_addr;
buffer = malloc(aligned_size);
fileio_close(fileio);
LOG_ERROR("Out of memory");
return ERROR_FAIL;
fileio_close(fileio);
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
buffer = malloc(length);
}
buffer = malloc(length);
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
"first %zu bytes of the file", length);
buffer_file = malloc(length);
"first %zu bytes of the file", length);
buffer_file = malloc(length);
- if (buffer_file == NULL) {
LOG_ERROR("Out of memory");
fileio_close(fileio);
return ERROR_FAIL;
LOG_ERROR("Out of memory");
fileio_close(fileio);
return ERROR_FAIL;
}
buffer_flash = malloc(length);
}
buffer_flash = malloc(length);
- if (buffer_flash == NULL) {
LOG_ERROR("Out of memory");
free(buffer_file);
return ERROR_FAIL;
LOG_ERROR("Out of memory");
free(buffer_file);
return ERROR_FAIL;
CMD_ARGC--;
struct target *target = get_target(CMD_ARGV[5]);
CMD_ARGC--;
struct target *target = get_target(CMD_ARGV[5]);
LOG_ERROR("target '%s' not defined", CMD_ARGV[5]);
return ERROR_FAIL;
}
const char *driver_name = CMD_ARGV[0];
const struct flash_driver *driver = flash_driver_find_by_name(driver_name);
LOG_ERROR("target '%s' not defined", CMD_ARGV[5]);
return ERROR_FAIL;
}
const char *driver_name = CMD_ARGV[0];
const struct flash_driver *driver = flash_driver_find_by_name(driver_name);
/* no matching flash driver found */
LOG_ERROR("flash driver '%s' not found", driver_name);
return ERROR_FAIL;
/* no matching flash driver found */
LOG_ERROR("flash driver '%s' not found", driver_name);
return ERROR_FAIL;
}
/* register flash specific commands */
}
/* register flash specific commands */
- if (NULL != driver->commands) {
+ if (driver->commands) {
int retval = register_commands(CMD_CTX, NULL,
driver->commands);
if (retval != ERROR_OK) {
int retval = register_commands(CMD_CTX, NULL,
driver->commands);
if (retval != ERROR_OK) {
- if (driver->usage == NULL)
LOG_DEBUG("'%s' driver usage field missing", driver_name);
flash_bank_add(c);
LOG_DEBUG("'%s' driver usage field missing", driver_name);
flash_bank_add(c);
struct flash_bank *master_bank;
master_bank = get_flash_bank_by_name_noprobe(bank->driver_priv);
struct flash_bank *master_bank;
master_bank = get_flash_bank_by_name_noprobe(bank->driver_priv);
- if (master_bank == NULL)
LOG_ERROR("master flash bank '%s' does not exist", (char *)bank->driver_priv);
return master_bank;
LOG_ERROR("master flash bank '%s' does not exist", (char *)bank->driver_priv);
return master_bank;
{
struct flash_bank *master_bank = virtual_get_master_bank(bank);
{
struct flash_bank *master_bank = virtual_get_master_bank(bank);
- if (master_bank == NULL)
return;
/* update the info we do not have */
return;
/* update the info we do not have */
const char *bank_name = CMD_ARGV[6];
struct flash_bank *master_bank = get_flash_bank_by_name_noprobe(bank_name);
const char *bank_name = CMD_ARGV[6];
struct flash_bank *master_bank = get_flash_bank_by_name_noprobe(bank_name);
- if (master_bank == NULL) {
LOG_ERROR("master flash bank '%s' does not exist", bank_name);
return ERROR_FLASH_OPERATION_FAILED;
}
LOG_ERROR("master flash bank '%s' does not exist", bank_name);
return ERROR_FLASH_OPERATION_FAILED;
}
{
struct flash_bank *master_bank = virtual_get_master_bank(bank);
{
struct flash_bank *master_bank = virtual_get_master_bank(bank);
- if (master_bank == NULL)
return ERROR_FLASH_OPERATION_FAILED;
return flash_driver_protect(master_bank, set, first, last);
return ERROR_FLASH_OPERATION_FAILED;
return flash_driver_protect(master_bank, set, first, last);
{
struct flash_bank *master_bank = virtual_get_master_bank(bank);
{
struct flash_bank *master_bank = virtual_get_master_bank(bank);
- if (master_bank == NULL)
return ERROR_FLASH_OPERATION_FAILED;
if (master_bank->driver->protect_check == NULL)
return ERROR_FLASH_OPERATION_FAILED;
if (master_bank->driver->protect_check == NULL)
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
- if (master_bank == NULL)
return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */
return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
- if (master_bank == NULL)
return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */
return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
- if (master_bank == NULL)
return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */
return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
- if (master_bank == NULL)
return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */
return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */
{
struct flash_bank *master_bank = virtual_get_master_bank(bank);
{
struct flash_bank *master_bank = virtual_get_master_bank(bank);
- if (master_bank == NULL)
return ERROR_FLASH_OPERATION_FAILED;
command_print_sameline(cmd, "%s driver for flash bank %s at " TARGET_ADDR_FMT,
return ERROR_FLASH_OPERATION_FAILED;
command_print_sameline(cmd, "%s driver for flash bank %s at " TARGET_ADDR_FMT,
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
- if (master_bank == NULL)
return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */
return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
struct flash_bank *master_bank = virtual_get_master_bank(bank);
int retval;
- if (master_bank == NULL)
return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */
return ERROR_FLASH_OPERATION_FAILED;
/* call master handler */
struct xcf_priv *priv;
priv = malloc(sizeof(struct xcf_priv));
struct xcf_priv *priv;
priv = malloc(sizeof(struct xcf_priv));
LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL;
}
LOG_ERROR("no memory for flash bank info");
return ERROR_FAIL;
}
}
bank->sectors = malloc(bank->num_sectors * sizeof(struct flash_sector));
}
bank->sectors = malloc(bank->num_sectors * sizeof(struct flash_sector));
- if (bank->sectors == NULL) {
LOG_ERROR("No memory for sector table");
return ERROR_FAIL;
}
LOG_ERROR("No memory for sector table");
return ERROR_FAIL;
}
command_print_sameline(cmd, "%s - Rev: %s%s", dev_str, rev_str, prot_str);
else
command_print_sameline(cmd, "%s - Rev: unknown (0x%01x)%s", dev_str, rev_id, prot_str);
command_print_sameline(cmd, "%s - Rev: %s%s", dev_str, rev_str, prot_str);
else
command_print_sameline(cmd, "%s - Rev: unknown (0x%01x)%s", dev_str, rev_id, prot_str);
*/
static void command_log_capture_finish(struct log_capture_state *state)
{
*/
static void command_log_capture_finish(struct log_capture_state *state)
{
return;
log_remove_callback(tcl_output, state);
return;
log_remove_callback(tcl_output, state);
static int command_retval_set(Jim_Interp *interp, int retval)
{
int *return_retval = Jim_GetAssocData(interp, "retval");
static int command_retval_set(Jim_Interp *interp, int retval)
{
int *return_retval = Jim_GetAssocData(interp, "retval");
- if (return_retval != NULL)
*return_retval = retval;
return (retval == ERROR_OK) ? JIM_OK : retval;
*return_retval = retval;
return (retval == ERROR_OK) ? JIM_OK : retval;
unsigned argc, Jim_Obj * const *argv, unsigned *nwords)
{
char **words = malloc(argc * sizeof(char *));
unsigned argc, Jim_Obj * const *argv, unsigned *nwords)
{
char **words = malloc(argc * sizeof(char *));
{
/* grab the command context from the associated data */
struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context");
{
/* grab the command context from the associated data */
struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context");
/* Tcl can invoke commands directly instead of via command_run_line(). This would
* happen when the Jim Tcl interpreter is provided by eCos or if we are running
* commands in a startup script.
/* Tcl can invoke commands directly instead of via command_run_line(). This would
* happen when the Jim Tcl interpreter is provided by eCos or if we are running
* commands in a startup script.
full_name);
struct command *c = calloc(1, sizeof(struct command));
full_name);
struct command *c = calloc(1, sizeof(struct command));
return NULL;
c->name = strdup(cr->name);
return NULL;
c->name = strdup(cr->name);
const struct command_registration *cr = cmds + i;
struct command *c = NULL;
const struct command_registration *cr = cmds + i;
struct command *c = NULL;
- if (NULL != cr->name) {
c = register_command(cmd_ctx, cmd_prefix, cr);
c = register_command(cmd_ctx, cmd_prefix, cr);
retval = ERROR_FAIL;
break;
}
c->jim_handler_data = data;
c->jim_override_target = override_target;
}
retval = ERROR_FAIL;
break;
}
c->jim_handler_data = data;
c->jim_override_target = override_target;
}
- if (NULL != cr->chain) {
if (cr->name) {
if (cmd_prefix) {
char *new_prefix = alloc_printf("%s %s", cmd_prefix, cr->name);
if (cr->name) {
if (cmd_prefix) {
char *new_prefix = alloc_printf("%s %s", cmd_prefix, cr->name);
va_list ap;
va_start(ap, format);
string = alloc_vprintf(format, ap);
va_list ap;
va_start(ap, format);
string = alloc_vprintf(format, ap);
retval = command_run_line(context, string);
free(string);
}
retval = command_run_line(context, string);
free(string);
}
void command_done(struct command_context *cmd_ctx)
{
void command_done(struct command_context *cmd_ctx)
{
return JIM_ERR;
const char *file = Jim_GetString(argv[1], NULL);
char *full_path = find_file(file);
return JIM_ERR;
const char *file = Jim_GetString(argv[1], NULL);
char *full_path = find_file(file);
return JIM_ERR;
Jim_Obj *result = Jim_NewStringObj(interp, full_path, strlen(full_path));
free(full_path);
return JIM_ERR;
Jim_Obj *result = Jim_NewStringObj(interp, full_path, strlen(full_path));
free(full_path);
/* If the match string occurs anywhere, we print out
* stuff for this command. */
bool is_match = (strstr(c->cmd_name, cmd_match) != NULL) ||
/* If the match string occurs anywhere, we print out
* stuff for this command. */
bool is_match = (strstr(c->cmd_name, cmd_match) != NULL) ||
- ((c->usage != NULL) && (strstr(c->usage, cmd_match) != NULL)) ||
- ((c->help != NULL) && (strstr(c->help, cmd_match) != NULL));
+ ((c->usage) && (strstr(c->usage, cmd_match) != NULL)) ||
+ ((c->help) && (strstr(c->help, cmd_match) != NULL));
if (is_match) {
if (c->usage && strlen(c->usage) > 0) {
if (is_match) {
if (c->usage && strlen(c->usage) > 0) {
} else
msg = alloc_printf("%s", c->help ? c->help : "");
} else
msg = alloc_printf("%s", c->help ? c->help : "");
command_help_show_wrap(msg, n + 3, n + 3);
free(msg);
} else
command_help_show_wrap(msg, n + 3, n + 3);
free(msg);
} else
- if (cmd_match == NULL) {
LOG_ERROR("unable to build search string");
return -ENOMEM;
}
LOG_ERROR("unable to build search string");
return -ENOMEM;
}
INIT_LIST_HEAD(context->help_list);
/* Create a jim interpreter if we were not handed one */
INIT_LIST_HEAD(context->help_list);
/* Create a jim interpreter if we were not handed one */
/* Create an interpreter */
interp = Jim_CreateInterp();
/* Add all the Jim core commands */
/* Create an interpreter */
interp = Jim_CreateInterp();
/* Add all the Jim core commands */
return fopen(file, mode);
else {
char *full_path = find_file(file);
return fopen(file, mode);
else {
char *full_path = find_file(file);
return NULL;
FILE *fp = NULL;
fp = fopen(full_path, mode);
return NULL;
FILE *fp = NULL;
fp = fopen(full_path, mode);
{
char *home = getenv("HOME");
{
char *home = getenv("HOME");
#ifdef _WIN32
home = getenv("USERPROFILE");
#ifdef _WIN32
home = getenv("USERPROFILE");
char homepath[MAX_PATH];
char *drive = getenv("HOMEDRIVE");
char homepath[MAX_PATH];
char *drive = getenv("HOMEDRIVE");
return home;
char *home_path;
return home;
char *home_path;
}
if (puthere)
*puthere = o;
}
if (puthere)
*puthere = o;
return JIM_OK;
else
return JIM_ERR;
return JIM_OK;
else
return JIM_ERR;
Jim_Obj *o;
double _safe;
Jim_Obj *o;
double _safe;
puthere = &_safe;
r = jim_getopt_obj(goi, &o);
puthere = &_safe;
r = jim_getopt_obj(goi, &o);
Jim_Obj *o;
jim_wide _safe;
Jim_Obj *o;
jim_wide _safe;
puthere = &_safe;
r = jim_getopt_obj(goi, &o);
puthere = &_safe;
r = jim_getopt_obj(goi, &o);
puthere = &_safe;
e = jim_getopt_obj(goi, &o);
puthere = &_safe;
e = jim_getopt_obj(goi, &o);
puthere = &_safe;
e = jim_getopt_obj(goi, &o);
if (e == JIM_OK)
puthere = &_safe;
e = jim_getopt_obj(goi, &o);
if (e == JIM_OK)
}
f = strrchr(file, '/');
}
f = strrchr(file, '/');
file = f + 1;
if (strlen(string) > 0) {
file = f + 1;
if (strlen(string) > 0) {
va_start(ap, format);
string = alloc_vprintf(format, ap);
va_start(ap, format);
string = alloc_vprintf(format, ap);
log_puts(level, file, line, function, string);
free(string);
}
log_puts(level, file, line, function, string);
free(string);
}
}
if (CMD_ARGC == 1) {
FILE *file = fopen(CMD_ARGV[0], "w");
}
if (CMD_ARGC == 1) {
FILE *file = fopen(CMD_ARGV[0], "w");
LOG_ERROR("failed to open output log '%s'", CMD_ARGV[0]);
return ERROR_FAIL;
}
LOG_ERROR("failed to open output log '%s'", CMD_ARGV[0]);
return ERROR_FAIL;
}
/* set defaults for daemon configuration,
* if not set by cmdline or cfgfile */
char *debug_env = getenv("OPENOCD_DEBUG_LEVEL");
/* set defaults for daemon configuration,
* if not set by cmdline or cfgfile */
char *debug_env = getenv("OPENOCD_DEBUG_LEVEL");
- if (NULL != debug_env) {
int value;
int retval = parse_int(debug_env, &value);
if (retval == ERROR_OK &&
int value;
int retval = parse_int(debug_env, &value);
if (retval == ERROR_OK &&
- if (log_output == NULL)
log_output = stderr;
start = last_time = timeval_ms();
log_output = stderr;
start = last_time = timeval_ms();
/* alloc memory, it is safe just to return in case of an error, no need for the caller to
*check this */
cb = malloc(sizeof(struct log_callback));
/* alloc memory, it is safe just to return in case of an error, no need for the caller to
*check this */
cb = malloc(sizeof(struct log_callback));
return ERROR_BUF_TOO_SMALL;
/* add item to the beginning of the linked list */
return ERROR_BUF_TOO_SMALL;
/* add item to the beginning of the linked list */
* other code depend on that. They should be probably be fixed, but for
* now reserve the extra byte. */
string = malloc(len + 2);
* other code depend on that. They should be probably be fixed, but for
* now reserve the extra byte. */
string = malloc(len + 2);
return NULL;
/* do the real work */
return NULL;
/* do the real work */
do {
#if IS_WIN32 && !IS_CYGWIN
exepath = malloc(MAX_PATH);
do {
#if IS_WIN32 && !IS_CYGWIN
exepath = malloc(MAX_PATH);
break;
GetModuleFileName(NULL, exepath, MAX_PATH);
break;
GetModuleFileName(NULL, exepath, MAX_PATH);
#elif IS_DARWIN
exepath = malloc(PROC_PIDPATHINFO_MAXSIZE);
#elif IS_DARWIN
exepath = malloc(PROC_PIDPATHINFO_MAXSIZE);
break;
if (proc_pidpath(getpid(), exepath, PROC_PIDPATHINFO_MAXSIZE) <= 0) {
free(exepath);
break;
if (proc_pidpath(getpid(), exepath, PROC_PIDPATHINFO_MAXSIZE) <= 0) {
free(exepath);
#define PATH_MAX 1024
#endif
char *path = malloc(PATH_MAX);
#define PATH_MAX 1024
#endif
char *path = malloc(PATH_MAX);
break;
int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t size = PATH_MAX;
break;
int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t size = PATH_MAX;
#elif defined(HAVE_REALPATH) /* Assume POSIX.1-2008 */
/* Try Unices in order of likelihood. */
exepath = realpath("/proc/self/exe", NULL); /* Linux/Cygwin */
#elif defined(HAVE_REALPATH) /* Assume POSIX.1-2008 */
/* Try Unices in order of likelihood. */
exepath = realpath("/proc/self/exe", NULL); /* Linux/Cygwin */
exepath = realpath("/proc/self/path/a.out", NULL); /* Solaris */
exepath = realpath("/proc/self/path/a.out", NULL); /* Solaris */
exepath = realpath("/proc/curproc/file", NULL); /* FreeBSD (Should be covered above) */
#endif
} while (0);
exepath = realpath("/proc/curproc/file", NULL); /* FreeBSD (Should be covered above) */
#endif
} while (0);
/* Strip executable file name, leaving path */
*strrchr(exepath, '/') = '\0';
} else {
/* Strip executable file name, leaving path */
*strrchr(exepath, '/') = '\0';
} else {
if (from[0] != '/')
i++;
char *next = strchr(from, '/');
if (from[0] != '/')
i++;
char *next = strchr(from, '/');
break;
from = next + 1;
}
break;
from = next + 1;
}
void *clear_malloc(size_t size)
{
void *t = malloc(size);
void *clear_malloc(size_t size)
{
void *t = malloc(size);
memset(t, 0x00, size);
return t;
}
memset(t, 0x00, size);
return t;
}
void *fill_malloc(size_t size)
{
void *t = malloc(size);
void *fill_malloc(size_t size)
{
void *t = malloc(size);
/* We want to initialize memory to some known bad state.
* 0 and 0xff yields 0 and -1 as integers, which often
* have meaningful values. 0x5555... is not often a valid
/* We want to initialize memory to some known bad state.
* 0 and 0xff yields 0 and -1 as integers, which often
* have meaningful values. 0x5555... is not often a valid
size_t len = strnlen(s, n);
char *new = malloc(len + 1);
size_t len = strnlen(s, n);
char *new = malloc(len + 1);
return NULL;
new[len] = '\0';
return NULL;
new[len] = '\0';
#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
/* calculate how long we need to wait in milliseconds */
#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
/* calculate how long we need to wait in milliseconds */
ms_total = INFINITE;
else {
ms_total = tv->tv_sec * 1000;
ms_total = INFINITE;
else {
ms_total = tv->tv_sec * 1000;
unsigned expected_len = sizeof(uint32_t) * tap->expected_ids_cnt;
uint32_t *new_expected_ids = malloc(expected_len + sizeof(uint32_t));
unsigned expected_len = sizeof(uint32_t) * tap->expected_ids_cnt;
uint32_t *new_expected_ids = malloc(expected_len + sizeof(uint32_t));
- if (new_expected_ids == NULL) {
+ if (!new_expected_ids) {
Jim_SetResultFormatted(goi->interp, "no memory");
return JIM_ERR;
}
Jim_SetResultFormatted(goi->interp, "no memory");
return JIM_ERR;
}
bool set_op;
script_fd = fopen(script, "r");
bool set_op;
script_fd = fopen(script, "r");
- if (script_fd == NULL) {
return ERROR_FAIL;
} else {
while (fgets(line_buffer, LINE_BUFFER_SIZE, script_fd) != NULL) {
/* execute operations */
set_op = false;
op_str = strstr(line_buffer, "set");
return ERROR_FAIL;
} else {
while (fgets(line_buffer, LINE_BUFFER_SIZE, script_fd) != NULL) {
/* execute operations */
set_op = false;
op_str = strstr(line_buffer, "set");
set_op = true;
goto get_reset_type;
}
op_str = strstr(line_buffer, "clear");
set_op = true;
goto get_reset_type;
}
op_str = strstr(line_buffer, "clear");
continue;
get_reset_type:
reset_str = strstr(op_str, "srst");
continue;
get_reset_type:
reset_str = strstr(op_str, "srst");
- if (reset_str != NULL) {
if (set_op)
write_ctrl_value = AICE_CUSTOM_DELAY_SET_SRST;
else
if (set_op)
write_ctrl_value = AICE_CUSTOM_DELAY_SET_SRST;
else
goto get_delay;
}
reset_str = strstr(op_str, "dbgi");
goto get_delay;
}
reset_str = strstr(op_str, "dbgi");
- if (reset_str != NULL) {
if (set_op)
write_ctrl_value = AICE_CUSTOM_DELAY_SET_DBGI;
else
if (set_op)
write_ctrl_value = AICE_CUSTOM_DELAY_SET_DBGI;
else
goto get_delay;
}
reset_str = strstr(op_str, "trst");
goto get_delay;
}
reset_str = strstr(op_str, "trst");
- if (reset_str != NULL) {
if (set_op)
write_ctrl_value = AICE_CUSTOM_DELAY_SET_TRST;
else
if (set_op)
write_ctrl_value = AICE_CUSTOM_DELAY_SET_TRST;
else
return ERROR_FAIL;
/* issue TRST */
return ERROR_FAIL;
/* issue TRST */
- if (custom_trst_script == NULL) {
+ if (!custom_trst_script) {
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_TRST) != ERROR_OK)
return ERROR_FAIL;
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_TRST) != ERROR_OK)
return ERROR_FAIL;
/* After issuing srst, target will be running. So we need to restore EDM_CTL. */
aice_restore_edm_registers(coreid);
/* After issuing srst, target will be running. So we need to restore EDM_CTL. */
aice_restore_edm_registers(coreid);
- if (custom_srst_script == NULL) {
+ if (!custom_srst_script) {
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_SRST) != ERROR_OK)
return ERROR_FAIL;
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_SRST) != ERROR_OK)
return ERROR_FAIL;
aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status & (~0x4));
/* issue restart */
aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status & (~0x4));
/* issue restart */
- if (custom_restart_script == NULL) {
+ if (!custom_restart_script) {
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_RESTART) != ERROR_OK)
return ERROR_FAIL;
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_RESTART) != ERROR_OK)
return ERROR_FAIL;
aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status | 0x4);
/* issue restart again */
aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status | 0x4);
/* issue restart again */
- if (custom_restart_script == NULL) {
+ if (!custom_restart_script) {
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_RESTART) != ERROR_OK)
return ERROR_FAIL;
if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
AICE_JTAG_PIN_CONTROL_RESTART) != ERROR_OK)
return ERROR_FAIL;
/* init strtok() */
command_str = strtok(command_sequence, ";");
/* init strtok() */
command_str = strtok(command_sequence, ";");
- if (command_str == NULL)
reg_name_0 = strstr(command_str, "gen_port0");
reg_name_1 = strstr(command_str, "gen_port1");
reg_name_0 = strstr(command_str, "gen_port0");
reg_name_1 = strstr(command_str, "gen_port1");
- if (reg_name_0 != NULL) {
data_value = strtoul(reg_name_0 + 9, NULL, 0);
if (aice_write_misc(coreid,
NDS_EDM_MISC_GEN_PORT0, data_value) != ERROR_OK)
return ERROR_FAIL;
data_value = strtoul(reg_name_0 + 9, NULL, 0);
if (aice_write_misc(coreid,
NDS_EDM_MISC_GEN_PORT0, data_value) != ERROR_OK)
return ERROR_FAIL;
- } else if (reg_name_1 != NULL) {
+ } else if (reg_name_1) {
data_value = strtoul(reg_name_1 + 9, NULL, 0);
if (aice_write_misc(coreid,
data_value = strtoul(reg_name_1 + 9, NULL, 0);
if (aice_write_misc(coreid,
/* update command_str */
command_str = strtok(NULL, ";");
/* update command_str */
command_str = strtok(NULL, ";");
- } while (command_str != NULL);
cmd->next = NULL;
struct jtag_command **last_cmd = next_command_pointer;
cmd->next = NULL;
struct jtag_command **last_cmd = next_command_pointer;
- assert(NULL != last_cmd);
assert(NULL == *last_cmd);
*last_cmd = cmd;
assert(NULL == *last_cmd);
*last_cmd = cmd;
const char *jtag_tap_name(const struct jtag_tap *tap)
{
const char *jtag_tap_name(const struct jtag_tap *tap)
{
- return (tap == NULL) ? "(unknown)" : tap->dotted_name;
+ return (!tap) ? "(unknown)" : tap->dotted_name;
{
struct jtag_event_callback **callbacks_p = &jtag_event_callbacks;
{
struct jtag_event_callback **callbacks_p = &jtag_event_callbacks;
return ERROR_COMMAND_SYNTAX_ERROR;
if (*callbacks_p) {
return ERROR_COMMAND_SYNTAX_ERROR;
if (*callbacks_p) {
{
struct jtag_event_callback **p = &jtag_event_callbacks, *temp;
{
struct jtag_event_callback **p = &jtag_event_callbacks, *temp;
return ERROR_COMMAND_SYNTAX_ERROR;
while (*p) {
return ERROR_COMMAND_SYNTAX_ERROR;
while (*p) {
void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits,
tap_state_t state)
{
void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits,
tap_state_t state)
{
- assert(out_bits != NULL);
assert(state != TAP_RESET);
jtag_prelude(state);
assert(state != TAP_RESET);
jtag_prelude(state);
void jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits,
tap_state_t state)
{
void jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits,
tap_state_t state)
{
- assert(out_bits != NULL);
assert(state != TAP_RESET);
jtag_prelude(state);
assert(state != TAP_RESET);
jtag_prelude(state);
void jtag_check_value_mask(struct scan_field *field, uint8_t *value, uint8_t *mask)
{
void jtag_check_value_mask(struct scan_field *field, uint8_t *value, uint8_t *mask)
{
- assert(field->in_value != NULL);
+ assert(field->in_value);
/* no checking to do */
return;
}
/* no checking to do */
return;
}
int default_interface_jtag_execute_queue(void)
{
int default_interface_jtag_execute_queue(void)
{
LOG_ERROR("No JTAG interface configured yet. "
"Issue 'init' command in startup scripts "
"before communicating with targets.");
LOG_ERROR("No JTAG interface configured yet. "
"Issue 'init' command in startup scripts "
"before communicating with targets.");
max_taps++;
uint8_t *idcode_buffer = calloc(4, max_taps);
max_taps++;
uint8_t *idcode_buffer = calloc(4, max_taps);
- if (idcode_buffer == NULL)
return ERROR_JTAG_INIT_FAILED;
/* DR scan to collect BYPASS or IDCODE register contents.
return ERROR_JTAG_INIT_FAILED;
/* DR scan to collect BYPASS or IDCODE register contents.
uint32_t idcode = buf_get_u32(idcode_buffer, bit_count, 32);
/* No predefined TAP? Auto-probe. */
uint32_t idcode = buf_get_u32(idcode_buffer, bit_count, 32);
/* No predefined TAP? Auto-probe. */
/* Is there another TAP? */
if (jtag_idcode_is_final(idcode))
break;
/* Is there another TAP? */
if (jtag_idcode_is_final(idcode))
break;
total_ir_length += 2;
ir_test = malloc(DIV_ROUND_UP(total_ir_length, 8));
total_ir_length += 2;
ir_test = malloc(DIV_ROUND_UP(total_ir_length, 8));
return ERROR_FAIL;
/* after this scan, all TAPs will capture BYPASS instructions */
return ERROR_FAIL;
/* after this scan, all TAPs will capture BYPASS instructions */
for (;; ) {
tap = jtag_tap_next_enabled(tap);
for (;; ) {
tap = jtag_tap_next_enabled(tap);
break;
/* If we're autoprobing, guess IR lengths. They must be at
break;
/* If we're autoprobing, guess IR lengths. They must be at
return retval;
jtag = adapter_driver;
return retval;
jtag = adapter_driver;
- if (jtag->speed == NULL) {
LOG_INFO("This adapter doesn't support configurable speed");
return ERROR_OK;
}
LOG_INFO("This adapter doesn't support configurable speed");
return ERROR_OK;
}
LOG_DEBUG("Init JTAG chain");
tap = jtag_tap_next_enabled(NULL);
LOG_DEBUG("Init JTAG chain");
tap = jtag_tap_next_enabled(NULL);
/* Once JTAG itself is properly set up, and the scan chain
* isn't absurdly large, IDCODE autoprobe should work fine.
*
/* Once JTAG itself is properly set up, and the scan chain
* isn't absurdly large, IDCODE autoprobe should work fine.
*
int jtag_power_dropout(int *dropout)
{
int jtag_power_dropout(int *dropout)
{
/* TODO: as the jtag interface is not valid all
* we can do at the moment is exit OpenOCD */
LOG_ERROR("No Valid JTAG Interface Configured.");
/* TODO: as the jtag interface is not valid all
* we can do at the moment is exit OpenOCD */
LOG_ERROR("No Valid JTAG Interface Configured.");
enum scan_type type;
uint8_t *buffer;
enum scan_type type;
uint8_t *buffer;
switch (cmd->type) {
case JTAG_RUNTEST:
LOG_DEBUG_IO("runtest %i cycles, end in %i",
switch (cmd->type) {
case JTAG_RUNTEST:
LOG_DEBUG_IO("runtest %i cycles, end in %i",
- if (field->out_value == NULL) {
+ if (!field->out_value) {
/* just send zeros and request data from TDO */
for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--)
bitq_io(0, 0, tdo_req);
/* just send zeros and request data from TDO */
for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--)
bitq_io(0, 0, tdo_req);
static int buspirate_init(void)
{
static int buspirate_init(void)
{
- if (buspirate_port == NULL) {
LOG_ERROR("You need to specify the serial port!");
return ERROR_JTAG_INIT_FAILED;
}
LOG_ERROR("You need to specify the serial port!");
return ERROR_JTAG_INIT_FAILED;
}
if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR;
if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR;
- if (buspirate_port == NULL)
buspirate_port = strdup(CMD_ARGV[0]);
return ERROR_OK;
buspirate_port = strdup(CMD_ARGV[0]);
return ERROR_OK;
const struct cmsis_dap_backend *backend = NULL;
struct cmsis_dap *dap = calloc(1, sizeof(struct cmsis_dap));
const struct cmsis_dap_backend *backend = NULL;
struct cmsis_dap *dap = calloc(1, sizeof(struct cmsis_dap));
LOG_ERROR("unable to allocate memory");
return ERROR_FAIL;
}
LOG_ERROR("unable to allocate memory");
return ERROR_FAIL;
}
LOG_ERROR("unable to find a matching CMSIS-DAP device");
free(dap);
return ERROR_FAIL;
LOG_ERROR("unable to find a matching CMSIS-DAP device");
free(dap);
return ERROR_FAIL;
(tdo_buffer != NULL ? DAP_JTAG_SEQ_TDO : 0) |
(s_len == 64 ? 0 : s_len);
(tdo_buffer != NULL ? DAP_JTAG_SEQ_TDO : 0) |
(s_len == 64 ? 0 : s_len);
bit_copy(&queued_seq_buf[queued_seq_buf_end + 1], 0, sequence, s_offset, s_len);
else
memset(&queued_seq_buf[queued_seq_buf_end + 1], 0, DIV_ROUND_UP(s_len, 8));
queued_seq_buf_end += cmd_len;
bit_copy(&queued_seq_buf[queued_seq_buf_end + 1], 0, sequence, s_offset, s_len);
else
memset(&queued_seq_buf[queued_seq_buf_end + 1], 0, DIV_ROUND_UP(s_len, 8));
queued_seq_buf_end += cmd_len;
- if (tdo_buffer != NULL) {
struct pending_scan_result *scan = &pending_scan_results[pending_scan_result_count++];
scan->first = queued_seq_tdo_ptr;
queued_seq_tdo_ptr += DIV_ROUND_UP(s_len, 8);
struct pending_scan_result *scan = &pending_scan_results[pending_scan_result_count++];
scan->first = queued_seq_tdo_ptr;
queued_seq_tdo_ptr += DIV_ROUND_UP(s_len, 8);
{
struct jtag_command *cmd = jtag_command_queue;
{
struct jtag_command *cmd = jtag_command_queue;
cmsis_dap_execute_command(cmd);
cmd = cmd->next;
}
cmsis_dap_execute_command(cmd);
cmd = cmd->next;
}
LOG_WARNING("could not claim interface: %s", libusb_strerror(err));
dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data));
LOG_WARNING("could not claim interface: %s", libusb_strerror(err));
dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data));
- if (dap->bdata == NULL) {
LOG_ERROR("unable to allocate memory");
libusb_release_interface(dev_handle, interface_num);
libusb_close(dev_handle);
LOG_ERROR("unable to allocate memory");
libusb_release_interface(dev_handle, interface_num);
libusb_close(dev_handle);
dap->bdata->interface = interface_num;
dap->packet_buffer = malloc(dap->packet_buffer_size);
dap->bdata->interface = interface_num;
dap->packet_buffer = malloc(dap->packet_buffer_size);
- if (dap->packet_buffer == NULL) {
+ if (!dap->packet_buffer) {
LOG_ERROR("unable to allocate memory");
cmsis_dap_usb_close(dap);
return ERROR_FAIL;
LOG_ERROR("unable to allocate memory");
cmsis_dap_usb_close(dap);
return ERROR_FAIL;
static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
{
uint8_t *buf = malloc(pkt_sz);
static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
{
uint8_t *buf = malloc(pkt_sz);
LOG_ERROR("unable to allocate CMSIS-DAP packet buffer");
return ERROR_FAIL;
}
LOG_ERROR("unable to allocate CMSIS-DAP packet buffer");
return ERROR_FAIL;
}
*/
devs = hid_enumerate(0x0, 0x0);
cur_dev = devs;
*/
devs = hid_enumerate(0x0, 0x0);
cur_dev = devs;
- while (NULL != cur_dev) {
bool found = false;
if (0 == vids[0]) {
bool found = false;
if (0 == vids[0]) {
- if (NULL == cur_dev->product_string) {
+ if (!cur_dev->product_string) {
LOG_DEBUG("Cannot read product string of device 0x%x:0x%x",
cur_dev->vendor_id, cur_dev->product_id);
} else if (wcsstr(cur_dev->product_string, L"CMSIS-DAP")) {
LOG_DEBUG("Cannot read product string of device 0x%x:0x%x",
cur_dev->vendor_id, cur_dev->product_id);
} else if (wcsstr(cur_dev->product_string, L"CMSIS-DAP")) {
if (found) {
/* check serial number matches if given */
if (found) {
/* check serial number matches if given */
- if (cur_dev->serial_number != NULL) {
+ if (cur_dev->serial_number) {
size_t len = (strlen(serial) + 1) * sizeof(wchar_t);
wchar_t *wserial = malloc(len);
mbstowcs(wserial, serial, len);
size_t len = (strlen(serial) + 1) * sizeof(wchar_t);
wchar_t *wserial = malloc(len);
mbstowcs(wserial, serial, len);
cur_dev = cur_dev->next;
}
cur_dev = cur_dev->next;
}
target_vid = cur_dev->vendor_id;
target_pid = cur_dev->product_id;
}
target_vid = cur_dev->vendor_id;
target_pid = cur_dev->product_id;
}
}
dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data));
}
dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data));
- if (dap->bdata == NULL) {
LOG_ERROR("unable to allocate memory");
return ERROR_FAIL;
}
LOG_ERROR("unable to allocate memory");
return ERROR_FAIL;
}
dev = hid_open_path(cur_dev->path);
hid_free_enumeration(devs);
dev = hid_open_path(cur_dev->path);
hid_free_enumeration(devs);
LOG_ERROR("unable to open CMSIS-DAP device 0x%x:0x%x", target_vid, target_pid);
return ERROR_FAIL;
}
LOG_ERROR("unable to open CMSIS-DAP device 0x%x:0x%x", target_vid, target_pid);
return ERROR_FAIL;
}
{
unsigned int packet_buffer_size = pkt_sz + REPORT_ID_SIZE;
uint8_t *buf = malloc(packet_buffer_size);
{
unsigned int packet_buffer_size = pkt_sz + REPORT_ID_SIZE;
uint8_t *buf = malloc(packet_buffer_size);
LOG_ERROR("unable to allocate CMSIS-DAP packet buffer");
return ERROR_FAIL;
}
LOG_ERROR("unable to allocate CMSIS-DAP packet buffer");
return ERROR_FAIL;
}
struct jtag_command *cmd;
cmd = cmd_queue_alloc(sizeof(struct jtag_command));
struct jtag_command *cmd;
cmd = cmd_queue_alloc(sizeof(struct jtag_command));
return ERROR_FAIL;
cmd->type = JTAG_TMS;
return ERROR_FAIL;
cmd->type = JTAG_TMS;
entry->data2 = data2;
entry->data3 = data3;
entry->data2 = data2;
entry->data3 = data3;
- if (jtag_callback_queue_head == NULL) {
+ if (!jtag_callback_queue_head) {
jtag_callback_queue_head = entry;
jtag_callback_queue_tail = entry;
} else {
jtag_callback_queue_head = entry;
jtag_callback_queue_tail = entry;
} else {
if (new_buf_size >= ft232r_buf_size) {
new_buf_size += FT232R_BUF_SIZE_EXTRA;
new_buf_ptr = realloc(ft232r_output, new_buf_size);
if (new_buf_size >= ft232r_buf_size) {
new_buf_size += FT232R_BUF_SIZE_EXTRA;
new_buf_ptr = realloc(ft232r_output, new_buf_size);
- if (new_buf_ptr != NULL) {
ft232r_output = new_buf_ptr;
ft232r_buf_size = new_buf_size;
}
ft232r_output = new_buf_ptr;
ft232r_buf_size = new_buf_size;
}
uint16_t apids[] = {ft232r_pid, 0};
if (jtag_libusb_open(avids, apids, ft232r_serial_desc, &adapter, NULL)) {
LOG_ERROR("ft232r not found: vid=%04x, pid=%04x, serial=%s\n",
uint16_t apids[] = {ft232r_pid, 0};
if (jtag_libusb_open(avids, apids, ft232r_serial_desc, &adapter, NULL)) {
LOG_ERROR("ft232r not found: vid=%04x, pid=%04x, serial=%s\n",
- ft232r_vid, ft232r_pid, (ft232r_serial_desc == NULL) ? "[any]" : ft232r_serial_desc);
+ ft232r_vid, ft232r_pid, (!ft232r_serial_desc) ? "[any]" : ft232r_serial_desc);
return ERROR_JTAG_INIT_FAILED;
}
return ERROR_JTAG_INIT_FAILED;
}
}
ft232r_output = malloc(ft232r_buf_size);
}
ft232r_output = malloc(ft232r_buf_size);
- if (ft232r_output == NULL) {
LOG_ERROR("Unable to allocate memory for the buffer");
return ERROR_JTAG_INIT_FAILED;
}
LOG_ERROR("Unable to allocate memory for the buffer");
return ERROR_JTAG_INIT_FAILED;
}
if (CMD_ARGC > 0) {
n = jim_nvp_name2value_simple(nvp_ftdi_jtag_modes, CMD_ARGV[0]);
if (CMD_ARGC > 0) {
n = jim_nvp_name2value_simple(nvp_ftdi_jtag_modes, CMD_ARGV[0]);
return ERROR_COMMAND_SYNTAX_ERROR;
ftdi_jtag_mode = n->value;
return ERROR_COMMAND_SYNTAX_ERROR;
ftdi_jtag_mode = n->value;
* pointers into the queue which may be invalid after the realloc. */
queued_retval = ftdi_swd_run_queue();
struct swd_cmd_queue_entry *q = realloc(swd_cmd_queue, swd_cmd_queue_alloced * 2 * sizeof(*swd_cmd_queue));
* pointers into the queue which may be invalid after the realloc. */
queued_retval = ftdi_swd_run_queue();
struct swd_cmd_queue_entry *q = realloc(swd_cmd_queue, swd_cmd_queue_alloced * 2 * sizeof(*swd_cmd_queue));
swd_cmd_queue = q;
swd_cmd_queue_alloced *= 2;
LOG_DEBUG("Increased SWD command queue to %zu elements", swd_cmd_queue_alloced);
swd_cmd_queue = q;
swd_cmd_queue_alloced *= 2;
LOG_DEBUG("Increased SWD command queue to %zu elements", swd_cmd_queue_alloced);
int ret;
struct jtag_command *cmd = jtag_command_queue;
int ret;
struct jtag_command *cmd = jtag_command_queue;
ret = jlink_execute_command(cmd);
if (ret != ERROR_OK)
ret = jlink_execute_command(cmd);
if (ret != ERROR_OK)
static int write_sock(char *buf, size_t len)
{
static int write_sock(char *buf, size_t len)
{
LOG_ERROR("%s: NULL 'buf' argument, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
LOG_ERROR("%s: NULL 'buf' argument, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
static int read_sock(char *buf, size_t len)
{
static int read_sock(char *buf, size_t len)
{
LOG_ERROR("%s: NULL 'buf' argument, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
LOG_ERROR("%s: NULL 'buf' argument, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
int ret = ERROR_OK;
num_bits = jtag_build_buffer(cmd, &data_buf);
int ret = ERROR_OK;
num_bits = jtag_build_buffer(cmd, &data_buf);
- if (data_buf == NULL) {
LOG_ERROR("jtag_build_buffer call failed, data_buf == NULL, "
"file %s, line %d", __FILE__, __LINE__);
return ERROR_FAIL;
LOG_ERROR("jtag_build_buffer call failed, data_buf == NULL, "
"file %s, line %d", __FILE__, __LINE__);
return ERROR_FAIL;
if (cmd->ir_scan) {
free(last_ir_buf);
last_ir_buf = (uint8_t *)malloc(bytes * sizeof(uint8_t));
if (cmd->ir_scan) {
free(last_ir_buf);
last_ir_buf = (uint8_t *)malloc(bytes * sizeof(uint8_t));
- if (last_ir_buf == NULL) {
LOG_ERROR("%s: malloc fail, file %s, line %d",
__func__, __FILE__, __LINE__);
ret = ERROR_FAIL;
LOG_ERROR("%s: malloc fail, file %s, line %d",
__func__, __FILE__, __LINE__);
ret = ERROR_FAIL;
int num_bits = last_ir_num_bits, bytes;
int ret = ERROR_OK;
int num_bits = last_ir_num_bits, bytes;
int ret = ERROR_OK;
- if (data_buf == NULL) {
LOG_ERROR("%s: NULL 'data_buf' argument, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
LOG_ERROR("%s: NULL 'data_buf' argument, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
bytes = DIV_ROUND_UP(num_bits, 8);
read_scan = (uint8_t *)malloc(bytes * sizeof(uint8_t));
bytes = DIV_ROUND_UP(num_bits, 8);
read_scan = (uint8_t *)malloc(bytes * sizeof(uint8_t));
- if (read_scan == NULL) {
LOG_ERROR("%s: malloc fail, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
LOG_ERROR("%s: malloc fail, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(server_port);
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(server_port);
- if (server_address == NULL) {
server_address = strdup(SERVER_ADDRESS);
server_address = strdup(SERVER_ADDRESS);
- if (server_address == NULL) {
LOG_ERROR("%s: strdup fail, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
LOG_ERROR("%s: strdup fail, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
if (CMD_ARGC > 1)
return ERROR_COMMAND_SYNTAX_ERROR;
else if (CMD_ARGC == 0) {
if (CMD_ARGC > 1)
return ERROR_COMMAND_SYNTAX_ERROR;
else if (CMD_ARGC == 0) {
- if (server_address == NULL) {
server_address = strdup(SERVER_ADDRESS);
server_address = strdup(SERVER_ADDRESS);
- if (server_address == NULL) {
LOG_ERROR("%s: strdup fail, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
LOG_ERROR("%s: strdup fail, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
} else {
free(server_address);
server_address = strdup(CMD_ARGV[0]);
} else {
free(server_address);
server_address = strdup(CMD_ARGV[0]);
- if (server_address == NULL) {
LOG_ERROR("%s: strdup fail, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
LOG_ERROR("%s: strdup fail, file %s, line %d",
__func__, __FILE__, __LINE__);
return ERROR_FAIL;
string_length = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGTH);
ptr = strtok(loc, "-");
string_length = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGTH);
ptr = strtok(loc, "-");
LOG_WARNING("no '-' in usb path\n");
goto done;
}
LOG_WARNING("no '-' in usb path\n");
goto done;
}
ptr = strtok(NULL, ".");
/* no more tokens in path */
ptr = strtok(NULL, ".");
/* no more tokens in path */
break;
/* path mismatch at some step */
break;
/* path mismatch at some step */
int retval;
kitprog_handle = malloc(sizeof(struct kitprog));
int retval;
kitprog_handle = malloc(sizeof(struct kitprog));
- if (kitprog_handle == NULL) {
LOG_ERROR("Failed to allocate memory");
return ERROR_FAIL;
}
LOG_ERROR("Failed to allocate memory");
return ERROR_FAIL;
}
/* Allocate packet buffers and queues */
kitprog_handle->packet_size = SWD_MAX_BUFFER_LENGTH;
kitprog_handle->packet_buffer = malloc(SWD_MAX_BUFFER_LENGTH);
/* Allocate packet buffers and queues */
kitprog_handle->packet_size = SWD_MAX_BUFFER_LENGTH;
kitprog_handle->packet_buffer = malloc(SWD_MAX_BUFFER_LENGTH);
- if (kitprog_handle->packet_buffer == NULL) {
+ if (!kitprog_handle->packet_buffer) {
LOG_ERROR("Failed to allocate memory for the packet buffer");
return ERROR_FAIL;
}
pending_queue_len = SWD_MAX_BUFFER_LENGTH / 5;
pending_transfers = malloc(pending_queue_len * sizeof(*pending_transfers));
LOG_ERROR("Failed to allocate memory for the packet buffer");
return ERROR_FAIL;
}
pending_queue_len = SWD_MAX_BUFFER_LENGTH / 5;
pending_transfers = malloc(pending_queue_len * sizeof(*pending_transfers));
- if (pending_transfers == NULL) {
+ if (!pending_transfers) {
LOG_ERROR("Failed to allocate memory for the SWD transfer queue");
return ERROR_FAIL;
}
LOG_ERROR("Failed to allocate memory for the SWD transfer queue");
return ERROR_FAIL;
}
/* Allocate memory for the serial number */
kitprog_handle->serial = calloc(retval + 1, sizeof(char));
/* Allocate memory for the serial number */
kitprog_handle->serial = calloc(retval + 1, sizeof(char));
- if (kitprog_handle->serial == NULL) {
+ if (!kitprog_handle->serial) {
LOG_ERROR("Failed to allocate memory for the serial number");
return ERROR_FAIL;
}
LOG_ERROR("Failed to allocate memory for the serial number");
return ERROR_FAIL;
}
/* Convert the ASCII serial number into a (wchar_t *) */
size_t len = strlen(kitprog_handle->serial);
wchar_t *hid_serial = calloc(len + 1, sizeof(wchar_t));
/* Convert the ASCII serial number into a (wchar_t *) */
size_t len = strlen(kitprog_handle->serial);
wchar_t *hid_serial = calloc(len + 1, sizeof(wchar_t));
- if (hid_serial == NULL) {
LOG_ERROR("Failed to allocate memory for the serial number");
return ERROR_FAIL;
}
LOG_ERROR("Failed to allocate memory for the serial number");
return ERROR_FAIL;
}
/* Use HID for the KitBridge interface */
kitprog_handle->hid_handle = hid_open(VID, PID, hid_serial);
free(hid_serial);
/* Use HID for the KitBridge interface */
kitprog_handle->hid_handle = hid_open(VID, PID, hid_serial);
free(hid_serial);
- if (kitprog_handle->hid_handle == NULL) {
+ if (!kitprog_handle->hid_handle) {
LOG_ERROR("Failed to open KitBridge (HID) interface");
return ERROR_FAIL;
}
LOG_ERROR("Failed to open KitBridge (HID) interface");
return ERROR_FAIL;
}
static void kitprog_usb_close(void)
{
static void kitprog_usb_close(void)
{
- if (kitprog_handle->hid_handle != NULL) {
+ if (kitprog_handle->hid_handle) {
hid_close(kitprog_handle->hid_handle);
hid_exit();
}
hid_close(kitprog_handle->hid_handle);
hid_exit();
}
{
if (CMD_ARGC == 1) {
kitprog_serial = strdup(CMD_ARGV[0]);
{
if (CMD_ARGC == 1) {
kitprog_serial = strdup(CMD_ARGV[0]);
- if (kitprog_serial == NULL) {
LOG_ERROR("Failed to allocate memory for the serial number");
return ERROR_FAIL;
}
LOG_ERROR("Failed to allocate memory for the serial number");
return ERROR_FAIL;
}
char *alternate_serial = adapter_get_alternate_serial(device, dev_desc);
/* check possible failures */
char *alternate_serial = adapter_get_alternate_serial(device, dev_desc);
/* check possible failures */
- if (alternate_serial == NULL)
return false;
/* then compare and free the alternate serial */
return false;
/* then compare and free the alternate serial */
LOG_DEBUG("linuxgpiod_reset");
/* assume active low */
LOG_DEBUG("linuxgpiod_reset");
/* assume active low */
- if (gpiod_srst != NULL) {
retval1 = gpiod_line_set_value(gpiod_srst, srst ? 0 : 1);
if (retval1 < 0)
LOG_WARNING("set srst value failed");
}
/* assume active low */
retval1 = gpiod_line_set_value(gpiod_srst, srst ? 0 : 1);
if (retval1 < 0)
LOG_WARNING("set srst value failed");
}
/* assume active low */
- if (gpiod_trst != NULL) {
retval2 = gpiod_line_set_value(gpiod_trst, trst ? 0 : 1);
if (retval2 < 0)
LOG_WARNING("set trst value failed");
retval2 = gpiod_line_set_value(gpiod_trst, trst ? 0 : 1);
if (retval2 < 0)
LOG_WARNING("set trst value failed");
int retval;
line = gpiod_chip_get_line(gpiod_chip, offset);
int retval;
line = gpiod_chip_get_line(gpiod_chip, offset);
LOG_ERROR("Error get line %s", label);
return NULL;
}
LOG_ERROR("Error get line %s", label);
return NULL;
}
int retval;
line = gpiod_chip_get_line(gpiod_chip, offset);
int retval;
line = gpiod_chip_get_line(gpiod_chip, offset);
LOG_ERROR("Error get line %s", label);
return NULL;
}
LOG_ERROR("Error get line %s", label);
return NULL;
}
bitbang_interface = &linuxgpiod_bitbang;
gpiod_chip = gpiod_chip_open_by_number(gpiochip);
bitbang_interface = &linuxgpiod_bitbang;
gpiod_chip = gpiod_chip_open_by_number(gpiochip);
- if (gpiod_chip == NULL) {
LOG_ERROR("Cannot open LinuxGPIOD gpiochip %d", gpiochip);
return ERROR_JTAG_INIT_FAILED;
}
LOG_ERROR("Cannot open LinuxGPIOD gpiochip %d", gpiochip);
return ERROR_JTAG_INIT_FAILED;
}
}
gpiod_tdo = helper_get_input_line("tdo", tdo_gpio);
}
gpiod_tdo = helper_get_input_line("tdo", tdo_gpio);
goto out_error;
gpiod_tdi = helper_get_output_line("tdi", tdi_gpio, 0);
goto out_error;
gpiod_tdi = helper_get_output_line("tdi", tdi_gpio, 0);
goto out_error;
gpiod_tck = helper_get_output_line("tck", tck_gpio, 0);
goto out_error;
gpiod_tck = helper_get_output_line("tck", tck_gpio, 0);
goto out_error;
gpiod_tms = helper_get_output_line("tms", tms_gpio, 1);
goto out_error;
gpiod_tms = helper_get_output_line("tms", tms_gpio, 1);
goto out_error;
if (is_gpio_valid(trst_gpio)) {
gpiod_trst = helper_get_output_line("trst", trst_gpio, 1);
goto out_error;
if (is_gpio_valid(trst_gpio)) {
gpiod_trst = helper_get_output_line("trst", trst_gpio, 1);
- if (gpiod_trst == NULL)
}
gpiod_swclk = helper_get_output_line("swclk", swclk_gpio, 1);
}
gpiod_swclk = helper_get_output_line("swclk", swclk_gpio, 1);
- if (gpiod_swclk == NULL)
goto out_error;
gpiod_swdio = helper_get_output_line("swdio", swdio_gpio, 1);
goto out_error;
gpiod_swdio = helper_get_output_line("swdio", swdio_gpio, 1);
- if (gpiod_swdio == NULL)
goto out_error;
}
if (is_gpio_valid(srst_gpio)) {
gpiod_srst = helper_get_output_line("srst", srst_gpio, 1);
goto out_error;
}
if (is_gpio_valid(srst_gpio)) {
gpiod_srst = helper_get_output_line("srst", srst_gpio, 1);
- if (gpiod_srst == NULL)
goto out_error;
}
if (is_gpio_valid(led_gpio)) {
gpiod_led = helper_get_output_line("led", led_gpio, 0);
goto out_error;
}
if (is_gpio_valid(led_gpio)) {
gpiod_led = helper_get_output_line("led", led_gpio, 0);
LOG_DEBUG("device path has %i steps", path_len);
ptr = strtok(loc, "-:");
LOG_DEBUG("device path has %i steps", path_len);
ptr = strtok(loc, "-:");
LOG_DEBUG("no ':' in path");
goto done;
}
LOG_DEBUG("no ':' in path");
goto done;
}
path_step = 0;
while (path_step < 7) {
ptr = strtok(NULL, ".,");
path_step = 0;
while (path_step < 7) {
ptr = strtok(NULL, ".,");
LOG_DEBUG("no more tokens in path at step %i", path_step);
break;
}
LOG_DEBUG("no more tokens in path at step %i", path_step);
break;
}
return ERROR_OK;
/* only if the cable name wasn't overwritten by cmdline */
return ERROR_OK;
/* only if the cable name wasn't overwritten by cmdline */
- if (opendous_type == NULL) {
/* REVISIT first verify that it's listed in cables[] ... */
opendous_type = strdup(CMD_ARGV[0]);
}
/* REVISIT first verify that it's listed in cables[] ... */
opendous_type = strdup(CMD_ARGV[0]);
}
enum scan_type type;
uint8_t *buffer;
enum scan_type type;
uint8_t *buffer;
switch (cmd->type) {
case JTAG_RUNTEST:
LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles,
switch (cmd->type) {
case JTAG_RUNTEST:
LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles,
cur_opendous_probe = opendous_probes;
cur_opendous_probe = opendous_probes;
- if (opendous_type == NULL) {
opendous_type = strdup("opendous");
LOG_WARNING("No opendous_type specified, using default 'opendous'");
}
opendous_type = strdup("opendous");
LOG_WARNING("No opendous_type specified, using default 'opendous'");
}
uint8_t latency_timer;
/* Open by device description */
uint8_t latency_timer;
/* Open by device description */
- if (openjtag_device_desc == NULL) {
+ if (!openjtag_device_desc) {
LOG_WARNING("no openjtag device description specified, "
"using default 'Open JTAG Project'");
openjtag_device_desc = "Open JTAG Project";
LOG_WARNING("no openjtag device description specified, "
"using default 'Open JTAG Project'");
openjtag_device_desc = "Open JTAG Project";
jtag_libusb_close(usbh);
return ERROR_JTAG_INIT_FAILED;
}
jtag_libusb_close(usbh);
return ERROR_JTAG_INIT_FAILED;
}
{
struct jtag_command *cmd = jtag_command_queue;
{
struct jtag_command *cmd = jtag_command_queue;
openjtag_execute_command(cmd);
cmd = cmd->next;
}
openjtag_execute_command(cmd);
cmd = cmd->next;
}
- if (parport_cable == NULL) {
parport_cable = strdup("wiggler");
LOG_WARNING("No parport cable specified, using default 'wiggler'");
}
parport_cable = strdup("wiggler");
LOG_WARNING("No parport cable specified, using default 'wiggler'");
}
{
if (presto_open(presto_serial) != ERROR_OK) {
presto_close();
{
if (presto_open(presto_serial) != ERROR_OK) {
presto_close();
- if (presto_serial != NULL)
LOG_ERROR("Cannot open PRESTO, serial number '%s'", presto_serial);
else
LOG_ERROR("Cannot open PRESTO");
LOG_ERROR("Cannot open PRESTO, serial number '%s'", presto_serial);
else
LOG_ERROR("Cannot open PRESTO");
freeaddrinfo(result); /* No longer needed */
freeaddrinfo(result); /* No longer needed */
- if (rp == NULL) { /* No address succeeded */
+ if (!rp) { /* No address succeeded */
log_socket_error("Failed to connect");
return ERROR_FAIL;
}
log_socket_error("Failed to connect");
return ERROR_FAIL;
}
static int remote_bitbang_init_unix(void)
{
static int remote_bitbang_init_unix(void)
{
- if (remote_bitbang_host == NULL) {
+ if (!remote_bitbang_host) {
LOG_ERROR("host/socket not specified");
return ERROR_FAIL;
}
LOG_ERROR("host/socket not specified");
return ERROR_FAIL;
}
remote_bitbang_recv_buf_end = 0;
LOG_INFO("Initializing remote_bitbang driver");
remote_bitbang_recv_buf_end = 0;
LOG_INFO("Initializing remote_bitbang driver");
- if (remote_bitbang_port == NULL)
+ if (!remote_bitbang_port)
remote_bitbang_fd = remote_bitbang_init_unix();
else
remote_bitbang_fd = remote_bitbang_init_tcp();
remote_bitbang_fd = remote_bitbang_init_unix();
else
remote_bitbang_fd = remote_bitbang_init_tcp();
struct dtc_reply_queue_entry *rq_entry;
rq_entry = malloc(sizeof(struct dtc_reply_queue_entry));
struct dtc_reply_queue_entry *rq_entry;
rq_entry = malloc(sizeof(struct dtc_reply_queue_entry));
- if (rq_entry != NULL) {
rq_entry->scan.type = type;
rq_entry->scan.buffer = buffer;
rq_entry->scan.size = size;
rq_entry->scan.type = type;
rq_entry->scan.buffer = buffer;
rq_entry->scan.size = size;
rq_entry->cmd = cmd;
rq_entry->next = NULL;
rq_entry->cmd = cmd;
rq_entry->next = NULL;
- if (dtc_queue.rq_head == NULL)
+ if (!dtc_queue.rq_head)
dtc_queue.rq_head = rq_entry;
else
dtc_queue.rq_tail->next = rq_entry;
dtc_queue.rq_head = rq_entry;
else
dtc_queue.rq_tail->next = rq_entry;
- if (dtc_queue.rq_head != NULL) {
+ if (dtc_queue.rq_head) {
/* process the reply, which empties the reply queue and frees its entries */
dtc_p = reply_buffer;
/* process the reply, which empties the reply queue and frees its entries */
dtc_p = reply_buffer;
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (h->version.flags & STLINK_F_HAS_RW8_512BYTES)
return STLINKV3_MAX_RW8;
if (h->version.flags & STLINK_F_HAS_RW8_512BYTES)
return STLINKV3_MAX_RW8;
struct stlink_usb_handle_s *h = handle;
int tr, ret;
struct stlink_usb_handle_s *h = handle;
int tr, ret;
- assert(handle != NULL);
/* read status */
memset(h->cmdbuf, 0, STLINK_SG_SIZE);
/* read status */
memset(h->cmdbuf, 0, STLINK_SG_SIZE);
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
size_t n_transfers = 0;
struct jtag_xfer transfers[2];
size_t n_transfers = 0;
struct jtag_xfer transfers[2];
struct stlink_usb_handle_s *h = handle;
int tr, ret;
struct stlink_usb_handle_s *h = handle;
int tr, ret;
- assert(handle != NULL);
ret = jtag_libusb_bulk_write(h->usb_backend_priv.fd, h->tx_ep, (char *)h->cmdbuf,
cmdsize, STLINK_WRITE_TIMEOUT, &tr);
ret = jtag_libusb_bulk_write(h->usb_backend_priv.fd, h->tx_ep, (char *)h->cmdbuf,
cmdsize, STLINK_WRITE_TIMEOUT, &tr);
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
stlink_usb_init_buffer(handle, h->rx_ep, 16);
stlink_usb_init_buffer(handle, h->rx_ep, 16);
int err, cmdsize = STLINK_CMD_SIZE_V2;
struct stlink_usb_handle_s *h = handle;
int err, cmdsize = STLINK_CMD_SIZE_V2;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (h->version.stlink == 1) {
cmdsize = STLINK_SG_SIZE;
if (h->version.stlink == 1) {
cmdsize = STLINK_SG_SIZE;
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
/* send the TCP command */
int sent_size = send(h->tcp_backend_priv.fd, (void *)h->tcp_backend_priv.send_buf, send_size, 0);
/* send the TCP command */
int sent_size = send(h->tcp_backend_priv.fd, (void *)h->tcp_backend_priv.send_buf, send_size, 0);
int send_size = STLINK_TCP_USB_CMD_SIZE;
int recv_size = STLINK_TCP_SS_SIZE;
int send_size = STLINK_TCP_USB_CMD_SIZE;
int recv_size = STLINK_TCP_SS_SIZE;
- assert(handle != NULL);
/* prepare the TCP command */
h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_SEND_USB_CMD;
/* prepare the TCP command */
h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_SEND_USB_CMD;
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (h->st_mode == STLINK_MODE_DEBUG_SWIM) {
switch (h->databuf[0]) {
if (h->st_mode == STLINK_MODE_DEBUG_SWIM) {
switch (h->databuf[0]) {
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
assert(h->version.flags & STLINK_F_HAS_TRACE);
assert(h->version.flags & STLINK_F_HAS_TRACE);
char *p;
struct stlink_usb_handle_s *h = handle;
char *p;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
stlink_usb_init_buffer(handle, h->rx_ep, 6);
stlink_usb_init_buffer(handle, h->rx_ep, 6);
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (!(h->version.flags & STLINK_F_HAS_SWD_SET_FREQ))
return ERROR_COMMAND_NOTFOUND;
if (!(h->version.flags & STLINK_F_HAS_SWD_SET_FREQ))
return ERROR_COMMAND_NOTFOUND;
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (!(h->version.flags & STLINK_F_HAS_JTAG_SET_FREQ))
return ERROR_COMMAND_NOTFOUND;
if (!(h->version.flags & STLINK_F_HAS_JTAG_SET_FREQ))
return ERROR_COMMAND_NOTFOUND;
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
int rx_size = 0;
struct stlink_usb_handle_s *h = handle;
int rx_size = 0;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
/* on api V2 we are able the read the latest command
* status
/* on api V2 we are able the read the latest command
* status
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
/* command with no reply, use a valid endpoint but zero size */
stlink_usb_init_buffer(handle, h->rx_ep, 0);
/* command with no reply, use a valid endpoint but zero size */
stlink_usb_init_buffer(handle, h->rx_ep, 0);
uint8_t mode;
enum stlink_mode emode;
uint8_t mode;
enum stlink_mode emode;
- assert(handle != NULL);
res = stlink_usb_current_mode(handle, &mode);
res = stlink_usb_current_mode(handle, &mode);
enum stlink_mode emode;
struct stlink_usb_handle_s *h = handle;
enum stlink_mode emode;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
res = stlink_usb_exit_mode(handle);
if (res != ERROR_OK)
res = stlink_usb_exit_mode(handle);
if (res != ERROR_OK)
int res, offset;
struct stlink_usb_handle_s *h = handle;
int res, offset;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
/* there is no swim read core id cmd */
if (h->st_mode == STLINK_MODE_DEBUG_SWIM) {
/* there is no swim read core id cmd */
if (h->st_mode == STLINK_MODE_DEBUG_SWIM) {
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
int res;
- assert(handle != NULL);
stlink_usb_init_buffer(handle, h->rx_ep, 8);
stlink_usb_init_buffer(handle, h->rx_ep, 8);
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (h->trace.enabled && (h->version.flags & STLINK_F_HAS_TRACE)) {
int res;
if (h->trace.enabled && (h->version.flags & STLINK_F_HAS_TRACE)) {
int res;
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (h->reconnect_pending) {
LOG_INFO("Previous state query failed, trying to reconnect");
if (h->reconnect_pending) {
LOG_INFO("Previous state query failed, trying to reconnect");
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (h->st_mode == STLINK_MODE_DEBUG_SWIM)
return stlink_swim_assert_reset(handle, srst);
if (h->st_mode == STLINK_MODE_DEBUG_SWIM)
return stlink_swim_assert_reset(handle, srst);
int res = ERROR_OK;
struct stlink_usb_handle_s *h = handle;
int res = ERROR_OK;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
assert(h->version.flags & STLINK_F_HAS_TRACE);
assert(h->version.flags & STLINK_F_HAS_TRACE);
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (h->version.flags & STLINK_F_HAS_TRACE) {
stlink_usb_init_buffer(handle, h->rx_ep, 10);
if (h->version.flags & STLINK_F_HAS_TRACE) {
stlink_usb_init_buffer(handle, h->rx_ep, 10);
struct stlink_usb_handle_s *h = handle;
int retval;
struct stlink_usb_handle_s *h = handle;
int retval;
- assert(handle != NULL);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (h->version.jtag_api != STLINK_JTAG_API_V1) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_DEBUGEN);
if (h->version.jtag_api != STLINK_JTAG_API_V1) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_DEBUGEN);
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (h->version.jtag_api != STLINK_JTAG_API_V1) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_DEBUGEN);
if (h->version.jtag_api != STLINK_JTAG_API_V1) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_DEBUGEN);
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (h->version.jtag_api != STLINK_JTAG_API_V1) {
/* TODO: this emulates the v1 api, it should really use a similar auto mask isr
if (h->version.jtag_api != STLINK_JTAG_API_V1) {
/* TODO: this emulates the v1 api, it should really use a similar auto mask isr
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
stlink_usb_init_buffer(handle, h->rx_ep, 88);
stlink_usb_init_buffer(handle, h->rx_ep, 88);
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (STLINK_REGSEL_IS_FPU(regsel) && !(h->version.flags & STLINK_F_HAS_FPU_REG)) {
res = stlink_usb_write_debug_reg(h, DCB_DCRSR, regsel & 0x7f);
if (STLINK_REGSEL_IS_FPU(regsel) && !(h->version.flags & STLINK_F_HAS_FPU_REG)) {
res = stlink_usb_write_debug_reg(h, DCB_DCRSR, regsel & 0x7f);
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (STLINK_REGSEL_IS_FPU(regsel) && !(h->version.flags & STLINK_F_HAS_FPU_REG)) {
int res = stlink_usb_write_debug_reg(h, DCB_DCRDR, val);
if (STLINK_REGSEL_IS_FPU(regsel) && !(h->version.flags & STLINK_F_HAS_FPU_REG)) {
int res = stlink_usb_write_debug_reg(h, DCB_DCRDR, val);
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (h->version.jtag_api == STLINK_JTAG_API_V1)
return ERROR_OK;
if (h->version.jtag_api == STLINK_JTAG_API_V1)
return ERROR_OK;
uint16_t read_len = len;
struct stlink_usb_handle_s *h = handle;
uint16_t read_len = len;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
/* max 8 bit read/write is 64 bytes or 512 bytes for v3 */
if (len > stlink_usb_block(h)) {
/* max 8 bit read/write is 64 bytes or 512 bytes for v3 */
if (len > stlink_usb_block(h)) {
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
/* max 8 bit read/write is 64 bytes or 512 bytes for v3 */
if (len > stlink_usb_block(h)) {
/* max 8 bit read/write is 64 bytes or 512 bytes for v3 */
if (len > stlink_usb_block(h)) {
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT))
return ERROR_COMMAND_NOTFOUND;
if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT))
return ERROR_COMMAND_NOTFOUND;
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT))
return ERROR_COMMAND_NOTFOUND;
if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT))
return ERROR_COMMAND_NOTFOUND;
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
/* data must be a multiple of 4 and word aligned */
if (len % 4 || addr % 4) {
/* data must be a multiple of 4 and word aligned */
if (len % 4 || addr % 4) {
int res;
struct stlink_usb_handle_s *h = handle;
int res;
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
/* data must be a multiple of 4 and word aligned */
if (len % 4 || addr % 4) {
/* data must be a multiple of 4 and word aligned */
if (len % 4 || addr % 4) {
/** */
static int stlink_close(void *handle)
{
/** */
static int stlink_close(void *handle)
{
struct stlink_usb_handle_s *h = handle;
stlink_usb_close(handle);
struct stlink_usb_handle_s *h = handle;
stlink_usb_close(handle);
/* else (len == 26) => buggy ST-Link */
char *alternate_serial = malloc((STLINK_SERIAL_LEN + 1) * sizeof(char));
/* else (len == 26) => buggy ST-Link */
char *alternate_serial = malloc((STLINK_SERIAL_LEN + 1) * sizeof(char));
- if (alternate_serial == NULL)
return NULL;
for (unsigned int i = 0; i < STLINK_SERIAL_LEN; i += 2)
return NULL;
for (unsigned int i = 0; i < STLINK_SERIAL_LEN; i += 2)
char serial[STLINK_TCP_SERIAL_SIZE + 1] = {0};
uint8_t stlink_used;
bool stlink_id_matched = false;
char serial[STLINK_TCP_SERIAL_SIZE + 1] = {0};
uint8_t stlink_used;
bool stlink_id_matched = false;
- bool stlink_serial_matched = (param->serial == NULL);
+ bool stlink_serial_matched = (!param->serial);
for (uint32_t stlink_id = 0; stlink_id < connected_stlinks; stlink_id++) {
/* get the stlink info */
for (uint32_t stlink_id = 0; stlink_id < connected_stlinks; stlink_id++) {
/* get the stlink info */
- assert(trace_freq != NULL);
- assert(prescaler != NULL);
+ assert(trace_freq);
+ assert(prescaler);
if (pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART) {
LOG_ERROR("The attached ST-LINK version doesn't support this trace mode");
if (pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART) {
LOG_ERROR("The attached ST-LINK version doesn't support this trace mode");
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (!(h->version.flags & STLINK_F_HAS_AP_INIT))
return ERROR_COMMAND_NOTFOUND;
if (!(h->version.flags & STLINK_F_HAS_AP_INIT))
return ERROR_COMMAND_NOTFOUND;
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (!(h->version.flags & STLINK_F_HAS_AP_INIT))
return ERROR_COMMAND_NOTFOUND;
if (!(h->version.flags & STLINK_F_HAS_AP_INIT))
return ERROR_COMMAND_NOTFOUND;
struct stlink_usb_handle_s *h = handle;
int retval;
struct stlink_usb_handle_s *h = handle;
int retval;
- assert(handle != NULL);
if (!(h->version.flags & STLINK_F_HAS_DAP_REG))
return ERROR_COMMAND_NOTFOUND;
if (!(h->version.flags & STLINK_F_HAS_DAP_REG))
return ERROR_COMMAND_NOTFOUND;
{
struct stlink_usb_handle_s *h = handle;
{
struct stlink_usb_handle_s *h = handle;
- assert(handle != NULL);
if (!(h->version.flags & STLINK_F_HAS_DAP_REG))
return ERROR_COMMAND_NOTFOUND;
if (!(h->version.flags & STLINK_F_HAS_DAP_REG))
return ERROR_COMMAND_NOTFOUND;
int result, retry = 0;
int transferred = 0;
int result, retry = 0;
int transferred = 0;
- assert(handle != NULL);
/* check we have a large enough buffer for checksum "#00" */
if (len + 3 > h->max_packet) {
/* check we have a large enough buffer for checksum "#00" */
if (len + 3 > h->max_packet) {
- assert(handle != NULL);
do {
ch = h->read_buffer[offset++];
do {
ch = h->read_buffer[offset++];
payload = calloc(size, sizeof(uint8_t));
payload = calloc(size, sizeof(uint8_t));
LOG_ERROR("Could not allocate OpenULINK command payload: out of memory");
return ERROR_FAIL;
}
switch (direction) {
case PAYLOAD_DIRECTION_OUT:
LOG_ERROR("Could not allocate OpenULINK command payload: out of memory");
return ERROR_FAIL;
}
switch (direction) {
case PAYLOAD_DIRECTION_OUT:
- if (ulink_cmd->payload_out != NULL) {
+ if (ulink_cmd->payload_out) {
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
free(payload);
return ERROR_FAIL;
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
free(payload);
return ERROR_FAIL;
}
break;
case PAYLOAD_DIRECTION_IN:
}
break;
case PAYLOAD_DIRECTION_IN:
- if (ulink_cmd->payload_in_start != NULL) {
+ if (ulink_cmd->payload_in_start) {
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
free(payload);
return ERROR_FAIL;
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
free(payload);
return ERROR_FAIL;
struct ulink_cmd *current = device->queue_start;
int sum = 0;
struct ulink_cmd *current = device->queue_start;
int sum = 0;
- while (current != NULL) {
switch (direction) {
case PAYLOAD_DIRECTION_OUT:
sum += current->payload_out_size + 1; /* + 1 byte for Command ID */
switch (direction) {
case PAYLOAD_DIRECTION_OUT:
sum += current->payload_out_size + 1; /* + 1 byte for Command ID */
struct ulink_cmd *current = device->queue_start;
struct ulink_cmd *next = NULL;
struct ulink_cmd *current = device->queue_start;
struct ulink_cmd *next = NULL;
- while (current != NULL) {
/* Save pointer to next element */
next = current->next;
/* Save pointer to next element */
next = current->next;
ulink_clear_queue(device);
}
ulink_clear_queue(device);
}
- if (device->queue_start == NULL) {
+ if (!device->queue_start) {
/* Queue was empty */
device->commands_in_queue = 1;
/* Queue was empty */
device->commands_in_queue = 1;
int ret, i, scan_size_bytes;
uint8_t bits_last_byte;
int ret, i, scan_size_bytes;
uint8_t bits_last_byte;
return ERROR_FAIL;
/* Check size of command. USB buffer can hold 64 bytes, 1 byte is command ID,
return ERROR_FAIL;
/* Check size of command. USB buffer can hold 64 bytes, 1 byte is command ID,
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
return ERROR_FAIL;
if (device->delay_clock_tms < 0)
return ERROR_FAIL;
if (device->delay_clock_tms < 0)
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
return ERROR_FAIL;
if (device->delay_clock_tck < 0)
return ERROR_FAIL;
if (device->delay_clock_tck < 0)
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
return ERROR_FAIL;
cmd->id = CMD_GET_SIGNALS;
return ERROR_FAIL;
cmd->id = CMD_GET_SIGNALS;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
return ERROR_FAIL;
cmd->id = CMD_SET_SIGNALS;
return ERROR_FAIL;
cmd->id = CMD_SET_SIGNALS;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
return ERROR_FAIL;
cmd->id = CMD_SLEEP_US;
return ERROR_FAIL;
cmd->id = CMD_SLEEP_US;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
return ERROR_FAIL;
cmd->id = CMD_CONFIGURE_TCK_FREQ;
return ERROR_FAIL;
cmd->id = CMD_CONFIGURE_TCK_FREQ;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
return ERROR_FAIL;
cmd->id = CMD_SET_LEDS;
return ERROR_FAIL;
cmd->id = CMD_SET_LEDS;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
int ret;
return ERROR_FAIL;
cmd->id = CMD_TEST;
return ERROR_FAIL;
cmd->id = CMD_TEST;
if ((type == SCAN_IN) || (type == SCAN_IO)) {
tdo_buffer_start = calloc(sizeof(uint8_t), scan_size_bytes);
if ((type == SCAN_IN) || (type == SCAN_IO)) {
tdo_buffer_start = calloc(sizeof(uint8_t), scan_size_bytes);
- if (tdo_buffer_start == NULL)
return ERROR_FAIL;
tdo_buffer = tdo_buffer_start;
return ERROR_FAIL;
tdo_buffer = tdo_buffer_start;
bytecount -= 58;
/* Update TDI and TDO buffer pointers */
bytecount -= 58;
/* Update TDI and TDO buffer pointers */
- if (tdi_buffer_start != NULL)
- if (tdo_buffer_start != NULL)
tdo_buffer += 58;
} else if (bytecount == 58) { /* Full scan, no further scans */
tms_count_end = last_tms_count;
tdo_buffer += 58;
} else if (bytecount == 58) { /* Full scan, no further scans */
tms_count_end = last_tms_count;
current = device->queue_start;
current = device->queue_start;
- while (current != NULL) {
openocd_cmd = current->cmd_origin;
/* Check if a corresponding OpenOCD command is stored for this
* OpenULINK command */
openocd_cmd = current->cmd_origin;
/* Check if a corresponding OpenOCD command is stored for this
* OpenULINK command */
- if ((current->needs_postprocessing == true) && (openocd_cmd != NULL)) {
+ if ((current->needs_postprocessing == true) && (openocd_cmd)) {
switch (openocd_cmd->type) {
case JTAG_SCAN:
ret = ulink_post_process_scan(current);
switch (openocd_cmd->type) {
case JTAG_SCAN:
ret = ulink_post_process_scan(current);
uint8_t input_signals, output_signals;
ulink_handle = calloc(1, sizeof(struct ulink));
uint8_t input_signals, output_signals;
ulink_handle = calloc(1, sizeof(struct ulink));
- if (ulink_handle == NULL)
return ERROR_FAIL;
libusb_init(&ulink_handle->libusb_ctx);
return ERROR_FAIL;
libusb_init(&ulink_handle->libusb_ctx);
{
struct versaloon_pending_t *pending = (struct versaloon_pending_t *)p;
{
struct versaloon_pending_t *pending = (struct versaloon_pending_t *)p;
- if (pending->extra_data != NULL)
+ if (pending->extra_data)
*((uint8_t *)pending->extra_data) = src[0];
return ERROR_OK;
*((uint8_t *)pending->extra_data) = src[0];
return ERROR_OK;
{
struct versaloon_pending_t *pending = (struct versaloon_pending_t *)p;
{
struct versaloon_pending_t *pending = (struct versaloon_pending_t *)p;
- if (pending->extra_data != NULL)
+ if (pending->extra_data)
*((uint8_t *)pending->extra_data) = src[0];
/* mark it processed to ignore other input data */
*((uint8_t *)pending->extra_data) = src[0];
/* mark it processed to ignore other input data */
parity += (request >> 4) & 1;
parity &= 1;
buff[0] = (request | 0x81 | (parity << 5)) & ~0x40;
parity += (request >> 4) & 1;
parity &= 1;
buff[0] = (request | 0x81 | (parity << 5)) & ~0x40;
SET_LE_U32(&buff[1], *data);
else
memset(buff + 1, 0, 4);
SET_LE_U32(&buff[1], *data);
else
memset(buff + 1, 0, 4);
{
if (type_pre > 0) {
/* not the first command */
{
if (type_pre > 0) {
/* not the first command */
- if (NULL == usbtoxxx_buffer) {
+ if (!usbtoxxx_buffer) {
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(usbtoxxx_buffer));
return ERRCODE_INVALID_BUFFER;
}
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(usbtoxxx_buffer));
return ERRCODE_INVALID_BUFFER;
}
struct versaloon_want_pos_t *tmp;
tmp = versaloon_pending[i].pos;
struct versaloon_want_pos_t *tmp;
tmp = versaloon_pending[i].pos;
- while (tmp != NULL) {
- if ((tmp->buff != NULL) && (tmp->size > 0)) {
+ while (tmp) {
+ if ((tmp->buff) && (tmp->size > 0)) {
memcpy(tmp->buff,
versaloon_buf + usbtoxxx_buffer_index
+ tmp->offset,
memcpy(tmp->buff,
versaloon_buf + usbtoxxx_buffer_index
+ tmp->offset,
if (ERROR_OK != usbtoxxx_ensure_buffer_size(cmdlen + 6))
return ERROR_FAIL;
if (ERROR_OK != usbtoxxx_ensure_buffer_size(cmdlen + 6))
return ERROR_FAIL;
- if ((type_pre != type) || (NULL == usbtoxxx_buffer)) {
+ if ((type_pre != type) || (!usbtoxxx_buffer)) {
if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
return ERRCODE_FAILURE_OPERATION;
if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
return ERRCODE_FAILURE_OPERATION;
SET_LE_U16(&usbtoxxx_buffer[collect_index], len_tmp);
}
SET_LE_U16(&usbtoxxx_buffer[collect_index], len_tmp);
}
memcpy(usbtoxxx_buffer + usbtoxxx_current_cmd_index, cmdbuf, cmdlen);
usbtoxxx_current_cmd_index += cmdlen;
}
memcpy(usbtoxxx_buffer + usbtoxxx_current_cmd_index, cmdbuf, cmdlen);
usbtoxxx_current_cmd_index += cmdlen;
}
struct versaloon_want_pos_t *tmp, *free_tmp;
tmp = versaloon_want_pos;
struct versaloon_want_pos_t *tmp, *free_tmp;
tmp = versaloon_want_pos;
free_tmp = tmp;
tmp = tmp->next;
free(free_tmp);
free_tmp = tmp;
tmp = tmp->next;
free(free_tmp);
for (i = 0; i < ARRAY_SIZE(versaloon_pending); i++) {
tmp = versaloon_pending[i].pos;
for (i = 0; i < ARRAY_SIZE(versaloon_pending); i++) {
tmp = versaloon_pending[i].pos;
free_tmp = tmp;
tmp = tmp->next;
free(free_tmp);
free_tmp = tmp;
tmp = tmp->next;
free(free_tmp);
struct versaloon_want_pos_t *new_pos = NULL;
new_pos = malloc(sizeof(*new_pos));
struct versaloon_want_pos_t *new_pos = NULL;
new_pos = malloc(sizeof(*new_pos));
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY;
}
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY;
}
new_pos->buff = buff;
new_pos->next = NULL;
new_pos->buff = buff;
new_pos->next = NULL;
- if (NULL == versaloon_want_pos)
+ if (!versaloon_want_pos)
versaloon_want_pos = new_pos;
else {
struct versaloon_want_pos_t *tmp = versaloon_want_pos;
versaloon_want_pos = new_pos;
else {
struct versaloon_want_pos_t *tmp = versaloon_want_pos;
- while (tmp->next != NULL)
tmp = tmp->next;
tmp->next = new_pos;
}
tmp = tmp->next;
tmp->next = new_pos;
}
int transferred;
#if PARAM_CHECK
int transferred;
#if PARAM_CHECK
- if (NULL == versaloon_buf) {
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf));
return ERRCODE_INVALID_BUFFER;
}
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf));
return ERRCODE_INVALID_BUFFER;
}
return ERRCODE_FAILURE_OPERATION;
}
return ERRCODE_FAILURE_OPERATION;
}
ret = libusb_bulk_transfer(versaloon_usb_device_handle,
versaloon_interface.usb_setting.ep_in,
versaloon_buf, versaloon_interface.usb_setting.buf_size,
ret = libusb_bulk_transfer(versaloon_usb_device_handle,
versaloon_interface.usb_setting.ep_in,
versaloon_buf, versaloon_interface.usb_setting.buf_size,
/* malloc temporary buffer */
versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size);
/* malloc temporary buffer */
versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size);
- if (NULL == versaloon_buf) {
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY;
}
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY;
}
versaloon_buf = NULL;
versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size);
versaloon_buf = NULL;
versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size);
- if (NULL == versaloon_buf) {
versaloon_fini();
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY;
}
versaloon_cmd_buf = malloc(versaloon_interface.usb_setting.buf_size - 3);
versaloon_fini();
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY;
}
versaloon_cmd_buf = malloc(versaloon_interface.usb_setting.buf_size - 3);
- if (NULL == versaloon_cmd_buf) {
+ if (!versaloon_cmd_buf) {
versaloon_fini();
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY;
versaloon_fini();
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY;
static RESULT versaloon_fini(void)
{
static RESULT versaloon_fini(void)
{
- if (versaloon_usb_device_handle != NULL) {
+ if (versaloon_usb_device_handle) {
usbtoxxx_fini();
versaloon_free_want_pos();
usbtoxxx_fini();
versaloon_free_want_pos();
uint16_t inlen;
#if PARAM_CHECK
uint16_t inlen;
#if PARAM_CHECK
- if (NULL == versaloon_buf) {
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf));
return ERRCODE_INVALID_BUFFER;
}
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf));
return ERRCODE_INVALID_BUFFER;
}
LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
return ERRCODE_INVALID_PARAMETER;
}
LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
return ERRCODE_INVALID_PARAMETER;
}
" vsllink "
"-------------------------------------");
" vsllink "
"-------------------------------------");
switch (cmd->type) {
case JTAG_RUNTEST:
LOG_DEBUG_IO("runtest %i cycles, end in %s",
switch (cmd->type) {
case JTAG_RUNTEST:
LOG_DEBUG_IO("runtest %i cycles, end in %s",
static int vsllink_interface_init(void)
{
vsllink_handle = malloc(sizeof(struct vsllink));
static int vsllink_interface_init(void)
{
vsllink_handle = malloc(sizeof(struct vsllink));
- if (NULL == vsllink_handle) {
LOG_ERROR("unable to allocate memory");
return ERROR_FAIL;
}
LOG_ERROR("unable to allocate memory");
return ERROR_FAIL;
}
tdi_buffer = malloc(tap_buffer_size);
tdo_buffer = malloc(tap_buffer_size);
tms_buffer = malloc(tap_buffer_size);
tdi_buffer = malloc(tap_buffer_size);
tdo_buffer = malloc(tap_buffer_size);
tms_buffer = malloc(tap_buffer_size);
- if ((NULL == tdi_buffer) || (NULL == tdo_buffer) || (NULL == tms_buffer)) {
+ if ((!tdi_buffer) || (!tdo_buffer) || (!tms_buffer)) {
vsllink_quit();
return ERROR_FAIL;
}
vsllink_quit();
return ERROR_FAIL;
}
* 2) didn't find the XDS110, and no devices are currently open
*/
* 2) didn't find the XDS110, and no devices are currently open
*/
/* Free the device list, we're done with it */
libusb_free_device_list(list, 1);
}
/* Free the device list, we're done with it */
libusb_free_device_list(list, 1);
}
/* On an error, clean up what we can */
if (0 != result) {
/* On an error, clean up what we can */
if (0 != result) {
/* Release the debug and data interface on the XDS110 */
(void)libusb_release_interface(dev, xds110.interface);
libusb_close(dev);
}
/* Release the debug and data interface on the XDS110 */
(void)libusb_release_interface(dev, xds110.interface);
libusb_close(dev);
}
libusb_exit(ctx);
xds110.ctx = NULL;
xds110.dev = NULL;
libusb_exit(ctx);
xds110.ctx = NULL;
xds110.dev = NULL;
static void usb_disconnect(void)
{
static void usb_disconnect(void)
{
- if (NULL != xds110.dev) {
/* Release the debug and data interface on the XDS110 */
(void)libusb_release_interface(xds110.dev, xds110.interface);
libusb_close(xds110.dev);
xds110.dev = NULL;
}
/* Release the debug and data interface on the XDS110 */
(void)libusb_release_interface(xds110.dev, xds110.interface);
libusb_close(xds110.dev);
xds110.dev = NULL;
}
- if (NULL != xds110.ctx) {
libusb_exit(xds110.ctx);
xds110.ctx = NULL;
}
libusb_exit(xds110.ctx);
xds110.ctx = NULL;
}
*written = bytes_written;
return (result == 0 && size == bytes_written) ? true : false;
*written = bytes_written;
return (result == 0 && size == bytes_written) ? true : false;
/* Abort now if we didn't receive a valid response */
if (!success) {
/* Abort now if we didn't receive a valid response */
if (!success) {
- if (NULL != total_bytes_read)
*total_bytes_read = 0;
return false;
}
*total_bytes_read = 0;
return false;
}
- if (NULL != total_bytes_read)
*total_bytes_read = count;
return success;
*total_bytes_read = count;
return success;
int error = 0;
uint32_t bytes_read = 0;
int error = 0;
uint32_t bytes_read = 0;
- if (NULL == xds110.dev)
return false;
while (!done && attempts > 0) {
return false;
while (!done && attempts > 0) {
DEFAULT_TIMEOUT);
if (success) {
DEFAULT_TIMEOUT);
if (success) {
- if (NULL != firmware_id)
*firmware_id = xds110_get_u32(fw_id_pntr);
*firmware_id = xds110_get_u32(fw_id_pntr);
- if (NULL != hardware_id)
*hardware_id = xds110_get_u16(hw_id_pntr);
}
*hardware_id = xds110_get_u16(hw_id_pntr);
}
DEFAULT_TIMEOUT);
if (success) {
DEFAULT_TIMEOUT);
if (success) {
*idcode = xds110_get_u32(idcode_pntr);
}
*idcode = xds110_get_u32(idcode_pntr);
}
DEFAULT_TIMEOUT);
if (success) {
DEFAULT_TIMEOUT);
if (success) {
*value = xds110_get_u32(value_pntr);
}
*value = xds110_get_u32(value_pntr);
}
return false;
xds110.write_payload[0] = CMAPI_REG_WRITE;
return false;
xds110.write_payload[0] = CMAPI_REG_WRITE;
return false;
xds110.write_payload[0] = OCD_PATHMOVE;
return false;
xds110.write_payload[0] = OCD_PATHMOVE;
/* Handle result of read attempt */
if (!success)
LOG_ERROR("XDS110: failed to read DAP register");
/* Handle result of read attempt */
if (!success)
LOG_ERROR("XDS110: failed to read DAP register");
- else if (NULL != value)
*value = reg_value;
if (success && DAP_AP == type) {
*value = reg_value;
if (success && DAP_AP == type) {
{
struct jtag_command *cmd = jtag_command_queue;
{
struct jtag_command *cmd = jtag_command_queue;
xds110_execute_command(cmd);
cmd = cmd->next;
}
xds110_execute_command(cmd);
cmd = cmd->next;
}
if (hl_if.layout->api->speed == NULL)
return ERROR_OK;
if (hl_if.layout->api->speed == NULL)
return ERROR_OK;
- if (hl_if.handle == NULL) {
/* pass speed as initial param as interface not open yet */
hl_if.param.initial_interface_speed = speed;
return ERROR_OK;
/* pass speed as initial param as interface not open yet */
hl_if.param.initial_interface_speed = speed;
return ERROR_OK;
{
LOG_DEBUG("hl_layout_init");
{
LOG_DEBUG("hl_layout_init");
- if (adapter->layout == NULL) {
+ if (!adapter->layout) {
LOG_ERROR("no layout specified");
return ERROR_FAIL;
}
LOG_ERROR("no layout specified");
return ERROR_FAIL;
}
{
const char *cp = Jim_GetString(o, NULL);
struct jtag_tap *t = cp ? jtag_tap_by_string(cp) : NULL;
{
const char *cp = Jim_GetString(o, NULL);
struct jtag_tap *t = cp ? jtag_tap_by_string(cp) : NULL;
Jim_SetResultFormatted(interp, "Tap '%s' could not be found", cp);
return t;
}
Jim_SetResultFormatted(interp, "Tap '%s' could not be found", cp);
return t;
}
assert(e == JIM_OK);
tap = jtag_tap_by_jim_obj(interp, args[1]);
assert(e == JIM_OK);
tap = jtag_tap_by_jim_obj(interp, args[1]);
return JIM_ERR;
num_fields = (argc-2)/2;
return JIM_ERR;
num_fields = (argc-2)/2;
if (goi->isconfigure) {
if (!found)
jteap = calloc(1, sizeof(*jteap));
if (goi->isconfigure) {
if (!found)
jteap = calloc(1, sizeof(*jteap));
- else if (NULL != jteap->body)
Jim_DecrRefCount(goi->interp, jteap->body);
jteap->interp = goi->interp;
Jim_DecrRefCount(goi->interp, jteap->body);
jteap->interp = goi->interp;
struct jtag_tap *t;
t = jtag_tap_by_jim_obj(goi.interp, goi.argv[0]);
struct jtag_tap *t;
t = jtag_tap_by_jim_obj(goi.interp, goi.argv[0]);
return JIM_ERR;
if (strcasecmp(cmd_name, "tapisenabled") == 0) {
return JIM_ERR;
if (strcasecmp(cmd_name, "tapisenabled") == 0) {
Jim_Obj *o;
jim_getopt_obj(&goi, &o);
t = jtag_tap_by_jim_obj(goi.interp, o);
Jim_Obj *o;
jim_getopt_obj(&goi, &o);
t = jtag_tap_by_jim_obj(goi.interp, o);
return JIM_ERR;
return jtag_tap_configure_cmd(&goi, t);
return JIM_ERR;
return jtag_tap_configure_cmd(&goi, t);
int retval;
for (i = 0; i < num_fields; i++) {
tap = jtag_tap_by_string(CMD_ARGV[i*2]);
int retval;
for (i = 0; i < num_fields; i++) {
tap = jtag_tap_by_string(CMD_ARGV[i*2]);
free(fields);
command_print(CMD, "Tap: %s unknown", CMD_ARGV[i*2]);
free(fields);
command_print(CMD, "Tap: %s unknown", CMD_ARGV[i*2]);
static int virtex2_set_instr(struct jtag_tap *tap, uint32_t new_instr)
{
static int virtex2_set_instr(struct jtag_tap *tap, uint32_t new_instr)
{
return ERROR_FAIL;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
return ERROR_FAIL;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
return ERROR_COMMAND_SYNTAX_ERROR;
tap = jtag_tap_by_string(CMD_ARGV[1]);
return ERROR_COMMAND_SYNTAX_ERROR;
tap = jtag_tap_by_string(CMD_ARGV[1]);
command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]);
return ERROR_OK;
}
command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]);
return ERROR_OK;
}
}
input_file = fopen(filename, "rb");
}
input_file = fopen(filename, "rb");
- if (input_file == NULL) {
LOG_ERROR("couldn't open %s: %s", filename, strerror(errno));
return ERROR_PLD_FILE_LOAD_FAILED;
}
LOG_ERROR("couldn't open %s: %s", filename, strerror(errno));
return ERROR_PLD_FILE_LOAD_FAILED;
}
unsigned int tasks_found = 0;
const struct freertos_params *param;
unsigned int tasks_found = 0;
const struct freertos_params *param;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
return -1;
param = (const struct freertos_params *) rtos->rtos_specific_params;
return -1;
param = (const struct freertos_params *) rtos->rtos_specific_params;
- if (rtos->symbols == NULL) {
LOG_ERROR("No symbols for FreeRTOS");
return -3;
}
LOG_ERROR("No symbols for FreeRTOS");
return -3;
}
const struct freertos_params *param;
int64_t stack_ptr = 0;
const struct freertos_params *param;
int64_t stack_ptr = 0;
return -1;
if (thread_id == 0)
return -2;
return -1;
if (thread_id == 0)
return -2;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
return -1;
param = (const struct freertos_params *) rtos->rtos_specific_params;
return -1;
param = (const struct freertos_params *) rtos->rtos_specific_params;
int retval;
const struct freertos_params *param;
int retval;
const struct freertos_params *param;
return -1;
if (thread_id == 0)
return -2;
return -1;
if (thread_id == 0)
return -2;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
return -3;
param = (const struct freertos_params *) rtos->rtos_specific_params;
return -3;
param = (const struct freertos_params *) rtos->rtos_specific_params;
{
const struct threadx_params *param = (const struct threadx_params *) rtos->rtos_specific_params;
{
const struct threadx_params *param = (const struct threadx_params *) rtos->rtos_specific_params;
- if (param->fn_get_stacking_info != NULL)
+ if (param->fn_get_stacking_info)
return param->fn_get_stacking_info(rtos, stack_ptr);
return param->stacking_info + 0;
return param->fn_get_stacking_info(rtos, stack_ptr);
return param->stacking_info + 0;
{
const struct threadx_params *param;
{
const struct threadx_params *param;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
return 0; /* invalid */
param = (const struct threadx_params *) rtos->rtos_specific_params;
return 0; /* invalid */
param = (const struct threadx_params *) rtos->rtos_specific_params;
- if (param->fn_is_thread_id_valid != NULL)
+ if (param->fn_is_thread_id_valid)
return param->fn_is_thread_id_valid(rtos, thread_id);
return (thread_id != 0);
return param->fn_is_thread_id_valid(rtos, thread_id);
return (thread_id != 0);
int thread_list_size = 0;
const struct threadx_params *param;
int thread_list_size = 0;
const struct threadx_params *param;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
return -3;
param = (const struct threadx_params *) rtos->rtos_specific_params;
return -3;
param = (const struct threadx_params *) rtos->rtos_specific_params;
- if (rtos->symbols == NULL) {
LOG_ERROR("No symbols for ThreadX");
return -4;
}
LOG_ERROR("No symbols for ThreadX");
return -4;
}
int retval;
const struct threadx_params *param;
int retval;
const struct threadx_params *param;
return -1;
if (!is_thread_id_valid(rtos, thread_id))
return -2;
return -1;
if (!is_thread_id_valid(rtos, thread_id))
return -2;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
return -3;
param = (const struct threadx_params *) rtos->rtos_specific_params;
return -3;
param = (const struct threadx_params *) rtos->rtos_specific_params;
const struct rtos_register_stacking *stacking_info =
get_stacking_info(rtos, stack_ptr);
const struct rtos_register_stacking *stacking_info =
get_stacking_info(rtos, stack_ptr);
- if (stacking_info == NULL) {
LOG_ERROR("Unknown stacking info for thread id=0x%" PRIx64, (uint64_t)thread_id);
return -6;
}
LOG_ERROR("Unknown stacking info for thread id=0x%" PRIx64, (uint64_t)thread_id);
return -6;
}
const struct threadx_params *param;
const struct threadx_params *param;
return -1;
if (thread_id == 0)
return -2;
return -1;
if (thread_id == 0)
return -2;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
return -3;
param = (const struct threadx_params *) rtos->rtos_specific_params;
return -3;
param = (const struct threadx_params *) rtos->rtos_specific_params;
- if (rtos->symbols == NULL) {
LOG_ERROR("No symbols for ThreadX");
return -3;
}
LOG_ERROR("No symbols for ThreadX");
return -3;
}
const struct chibios_params *param;
uint32_t stack_ptr = 0;
const struct chibios_params *param;
uint32_t stack_ptr = 0;
- if ((rtos == NULL) || (thread_id == 0) ||
- (rtos->rtos_specific_params == NULL))
+ if ((!rtos) || (thread_id == 0) ||
+ (!rtos->rtos_specific_params))
return -1;
param = (const struct chibios_params *) rtos->rtos_specific_params;
return -1;
param = (const struct chibios_params *) rtos->rtos_specific_params;
int thread_list_size = 0;
const struct ecos_params *param;
int thread_list_size = 0;
const struct ecos_params *param;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
return -3;
param = (const struct ecos_params *) rtos->rtos_specific_params;
return -3;
param = (const struct ecos_params *) rtos->rtos_specific_params;
- if (rtos->symbols == NULL) {
LOG_ERROR("No symbols for eCos");
return -4;
}
LOG_ERROR("No symbols for eCos");
return -4;
}
int retval;
const struct ecos_params *param;
int retval;
const struct ecos_params *param;
return -1;
if (thread_id == 0)
return -2;
return -1;
if (thread_id == 0)
return -2;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
return -3;
param = (const struct ecos_params *) rtos->rtos_specific_params;
return -3;
param = (const struct ecos_params *) rtos->rtos_specific_params;
int retval;
const struct embkernel_params *param;
int retval;
const struct embkernel_params *param;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
- if (rtos->symbols == NULL) {
LOG_ERROR("No symbols for embKernel");
return -4;
}
LOG_ERROR("No symbols for embKernel");
return -4;
}
const struct embkernel_params *param;
int64_t stack_ptr = 0;
const struct embkernel_params *param;
int64_t stack_ptr = 0;
return -1;
if (thread_id == 0)
return -2;
return -1;
if (thread_id == 0)
return -2;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
return -1;
param = (const struct embkernel_params *) rtos->rtos_specific_params;
return -1;
param = (const struct embkernel_params *) rtos->rtos_specific_params;
int64_t current_thread = 0;
enum target_debug_reason current_reason = DBG_REASON_UNDEFINED;
int64_t current_thread = 0;
enum target_debug_reason current_reason = DBG_REASON_UNDEFINED;
return -1;
target = rtos->target;
return -1;
target = rtos->target;
static struct target *hwthread_find_thread(struct target *target, int64_t thread_id)
{
/* Find the thread with that thread_id */
static struct target *hwthread_find_thread(struct target *target, int64_t thread_id)
{
/* Find the thread with that thread_id */
return NULL;
if (target->smp) {
for (struct target_list *head = target->head; head != NULL; head = head->next) {
return NULL;
if (target->smp) {
for (struct target_list *head = target->head; head != NULL; head = head->next) {
static int hwthread_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
struct rtos_reg **rtos_reg_list, int *rtos_reg_list_size)
{
static int hwthread_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
struct rtos_reg **rtos_reg_list, int *rtos_reg_list_size)
{
return ERROR_FAIL;
struct target *target = rtos->target;
struct target *curr = hwthread_find_thread(target, thread_id);
return ERROR_FAIL;
struct target *target = rtos->target;
struct target *curr = hwthread_find_thread(target, thread_id);
return ERROR_FAIL;
if (!target_was_examined(curr))
return ERROR_FAIL;
if (!target_was_examined(curr))
static int hwthread_get_thread_reg(struct rtos *rtos, int64_t thread_id,
uint32_t reg_num, struct rtos_reg *rtos_reg)
{
static int hwthread_get_thread_reg(struct rtos *rtos, int64_t thread_id,
uint32_t reg_num, struct rtos_reg *rtos_reg)
{
return ERROR_FAIL;
struct target *target = rtos->target;
struct target *curr = hwthread_find_thread(target, thread_id);
return ERROR_FAIL;
struct target *target = rtos->target;
struct target *curr = hwthread_find_thread(target, thread_id);
LOG_ERROR("Couldn't find RTOS thread for id %" PRId64 ".", thread_id);
return ERROR_FAIL;
}
LOG_ERROR("Couldn't find RTOS thread for id %" PRId64 ".", thread_id);
return ERROR_FAIL;
}
static int hwthread_set_reg(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value)
{
static int hwthread_set_reg(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value)
{
return ERROR_FAIL;
struct target *target = rtos->target;
struct target *curr = hwthread_find_thread(target, rtos->current_thread);
return ERROR_FAIL;
struct target *target = rtos->target;
struct target *curr = hwthread_find_thread(target, rtos->current_thread);
return ERROR_FAIL;
struct reg *reg = register_get_by_number(curr->reg_cache, reg_num, true);
return ERROR_FAIL;
struct reg *reg = register_get_by_number(curr->reg_cache, reg_num, true);
struct target *target = get_target_from_connection(connection);
struct target *curr = hwthread_find_thread(target, thread_id);
struct target *target = get_target_from_connection(connection);
struct target *curr = hwthread_find_thread(target, thread_id);
return ERROR_FAIL;
*p_target = curr;
return ERROR_FAIL;
*p_target = curr;
found = 1;
else
next = next->next;
found = 1;
else
next = next->next;
- } while ((found == 0) && (next != tmp) && (next != NULL));
+ } while ((found == 0) && (next != tmp) && (next));
if (found == 0) {
LOG_ERROR("could not find thread: %" PRIx64, thread_id);
if (found == 0) {
LOG_ERROR("could not find thread: %" PRIx64, thread_id);
struct current_thread *ctt = linux_os->current_threads;
/* invalid current threads content */
struct current_thread *ctt = linux_os->current_threads;
/* invalid current threads content */
ctt->threadid = -1;
ctt->TS = 0xdeadbeef;
ctt = ctt->next;
ctt->threadid = -1;
ctt->TS = 0xdeadbeef;
ctt = ctt->next;
linux_os->current_threads;
cpu = head->target->coreid;
linux_os->current_threads;
cpu = head->target->coreid;
- while ((ct != NULL) && (ct->core_id != (int32_t) cpu))
+ while ((ct) && (ct->core_id != (int32_t) cpu))
- if ((ct != NULL) && (ct->TS == 0xdeadbeef))
+ if ((ct) && (ct->TS == 0xdeadbeef))
ct->TS = TS;
else
LOG_ERROR
ct->TS = TS;
else
LOG_ERROR
- if (currents == NULL) {
currents = ct;
return currents;
} else {
struct current_thread *temp = currents;
currents = ct;
return currents;
} else {
struct current_thread *temp = currents;
- while (temp->next != NULL)
temp = temp->next;
temp->next = ct;
temp = temp->next;
temp->next = ct;
t->next = NULL;
if (*last == NULL)
t->next = NULL;
if (*last == NULL)
- if (task_list == NULL) {
task_list = t;
return task_list;
} else {
struct threads *temp = task_list;
task_list = t;
return task_list;
} else {
struct threads *temp = task_list;
- while (temp->next != NULL)
temp = temp->next;
temp->next = t;
temp = temp->next;
temp->next = t;
struct current_thread *ct = linux_os->current_threads;
#ifdef PID_CHECK
struct current_thread *ct = linux_os->current_threads;
#ifdef PID_CHECK
- while ((ct != NULL) && (ct->pid != pid))
+ while ((ct) && (ct->pid != pid))
- while ((ct != NULL) && (ct->TS != base_addr))
+ while ((ct) && (ct->TS != base_addr))
#endif
ct = ct->next;
#ifdef PID_CHECK
#endif
ct = ct->next;
#ifdef PID_CHECK
- if ((ct != NULL) && (ct->pid == pid))
+ if ((ct) && (ct->pid == pid))
- if ((ct != NULL) && (ct->TS == base_addr))
+ if ((ct) && (ct->TS == base_addr))
target->rtos->rtos_specific_params;
struct threads *old, *temp = linux_os->thread_list;
target->rtos->rtos_specific_params;
struct threads *old, *temp = linux_os->thread_list;
old = temp;
free(temp->context);
old = temp;
free(temp->context);
t->status = 1;
t->next = NULL;
t->status = 1;
t->next = NULL;
linux_os->thread_list = t;
else {
linux_os->thread_list = t;
else {
- while (temp->next != NULL)
temp = temp->next;
t->next = NULL;
temp = temp->next;
t->next = NULL;
struct current_thread *ct = linux_os->current_threads;
struct threads *t = NULL;
struct current_thread *ct = linux_os->current_threads;
struct threads *t = NULL;
if (ct->threadid == -1) {
/* un-identified thread */
if (ct->threadid == -1) {
/* un-identified thread */
/* search in the list of threads if pid
already present */
/* search in the list of threads if pid
already present */
- while ((thread_list != NULL) && (found == 0)) {
+ while ((thread_list) && (found == 0)) {
#ifdef PID_CHECK
if (thread_list->pid == t->pid) {
#else
#ifdef PID_CHECK
if (thread_list->pid == t->pid) {
#else
linux_os->thread_count = 0;
/*thread_list = thread_list->next; skip init_task*/
linux_os->thread_count = 0;
/*thread_list = thread_list->next; skip init_task*/
- while (thread_list != NULL) {
thread_list->status = 0; /*setting all tasks to dead state*/
free(thread_list->context);
thread_list->status = 0; /*setting all tasks to dead state*/
free(thread_list->context);
thread_list = linux_os->thread_list;
thread_list = linux_os->thread_list;
- while (thread_list != NULL) {
#ifdef PID_CHECK
if (t->pid == thread_list->pid) {
#else
#ifdef PID_CHECK
if (t->pid == thread_list->pid) {
#else
tmp_str += sprintf(tmp_str, "m");
struct threads *temp = linux_os->thread_list;
tmp_str += sprintf(tmp_str, "m");
struct threads *temp = linux_os->thread_list;
tmp_str += sprintf(tmp_str, "%016" PRIx64, temp->threadid);
temp = temp->next;
if (temp)
tmp_str += sprintf(tmp_str, "%016" PRIx64, temp->threadid);
temp = temp->next;
if (temp)
target->rtos->rtos_specific_params;
struct threads *temp = linux_os->thread_list;
target->rtos->rtos_specific_params;
struct threads *temp = linux_os->thread_list;
if (temp->threadid == linux_os->preupdtate_threadid_count + 1) {
/*LOG_INFO("FOUND");*/
found = 1;
if (temp->threadid == linux_os->preupdtate_threadid_count + 1) {
/*LOG_INFO("FOUND");*/
found = 1;
/*LOG_INFO("INTO GDB THREAD UPDATE WHILE");*/
tmp_strr += sprintf(tmp_strr, ",");
tmp_strr +=
/*LOG_INFO("INTO GDB THREAD UPDATE WHILE");*/
tmp_strr += sprintf(tmp_strr, ",");
tmp_strr +=
/*LOG_INFO("lookup extra info for thread %" SCNx64, threadid);*/
struct threads *temp = linux_os->thread_list;
/*LOG_INFO("lookup extra info for thread %" SCNx64, threadid);*/
struct threads *temp = linux_os->thread_list;
if (temp->threadid == threadid) {
char *pid = " PID: ";
char *pid_current = "*PID: ";
if (temp->threadid == threadid) {
char *pid = " PID: ";
char *pid_current = "*PID: ";
struct threads *temp = linux_os->thread_list;
struct threads *prev = NULL;
struct threads *temp = linux_os->thread_list;
struct threads *prev = NULL;
if (temp->threadid == threadid) {
if (temp->status != 0) {
gdb_put_packet(connection, "OK", 2);
if (temp->threadid == threadid) {
if (temp->status != 0) {
gdb_put_packet(connection, "OK", 2);
retval = linux_task_update(target, 1);
struct threads *temp = linux_os->thread_list;
retval = linux_task_update(target, 1);
struct threads *temp = linux_os->thread_list;
if (temp->threadid == threadid) {
if (temp->status == 1) {
gdb_put_packet(connection, "OK", 2);
if (temp->threadid == threadid) {
if (temp->status == 1) {
gdb_put_packet(connection, "OK", 2);
struct current_thread *ct = linux_os->current_threads;
/* select to display the current thread of the selected target */
struct current_thread *ct = linux_os->current_threads;
/* select to display the current thread of the selected target */
- while ((ct != NULL) && (ct->core_id != target->coreid))
+ while ((ct) && (ct->core_id != target->coreid))
ct = ct->next;
int64_t current_gdb_thread_rq;
if (linux_os->threads_lookup == 1) {
ct = ct->next;
int64_t current_gdb_thread_rq;
if (linux_os->threads_lookup == 1) {
- if ((ct != NULL) && (ct->threadid == -1)) {
+ if ((ct) && (ct->threadid == -1)) {
ct = linux_os->current_threads;
ct = linux_os->current_threads;
- while ((ct != NULL) && (ct->threadid == -1))
+ while ((ct) && (ct->threadid == -1))
/* no current thread can be identified
* any way with smp */
LOG_INFO("no current thread identified");
/* no current thread can be identified
* any way with smp */
LOG_INFO("no current thread identified");
struct threads t;
ct = linux_os->current_threads;
struct threads t;
ct = linux_os->current_threads;
- while ((ct != NULL) && (ct->threadid == -1)) {
+ while ((ct) && (ct->threadid == -1)) {
t.base_addr = ct->TS;
get_name(target, &t);
LOG_INFO("name of unidentified thread %s",
t.base_addr = ct->TS;
get_name(target, &t);
LOG_INFO("name of unidentified thread %s",
break;
} else if (strncmp(packet, "qfThreadInfo", 12) == 0) {
break;
} else if (strncmp(packet, "qfThreadInfo", 12) == 0) {
- if (linux_os->thread_list == NULL) {
+ if (!linux_os->thread_list) {
retval = linux_gdb_thread_packet(target,
connection,
packet,
retval = linux_gdb_thread_packet(target,
connection,
packet,
if (linux_os->threads_lookup == 1) {
ct = linux_os->current_threads;
if (linux_os->threads_lookup == 1) {
ct = linux_os->current_threads;
- while ((ct != NULL) && (ct->core_id) != target->coreid)
+ while ((ct) && (ct->core_id) != target->coreid)
- if ((ct != NULL) && (ct->threadid == -1)) {
+ if ((ct) && (ct->threadid == -1)) {
ct = linux_os->current_threads;
ct = linux_os->current_threads;
- while ((ct != NULL) && (ct->threadid == -1))
+ while ((ct) && (ct->threadid == -1))
- if ((ct != NULL) && (ct->threadid !=
+ if ((ct) && (ct->threadid !=
target->rtos->current_threadid)
&& (target->rtos->current_threadid != -1))
LOG_WARNING("WARNING! current GDB thread do not match "
target->rtos->current_threadid)
&& (target->rtos->current_threadid != -1))
LOG_WARNING("WARNING! current GDB thread do not match "
tmp += sprintf(tmp, "PID\t\tCPU\t\tASID\t\tNAME\n");
tmp += sprintf(tmp, "---\t\t---\t\t----\t\t----\n");
tmp += sprintf(tmp, "PID\t\tCPU\t\tASID\t\tNAME\n");
tmp += sprintf(tmp, "---\t\t---\t\t----\t\t----\n");
if (temp->status) {
if (temp->context)
tmp +=
if (temp->status) {
if (temp->context)
tmp +=
rtos->thread_count = task_queue_size;
rtos->current_thread = 0;
rtos->thread_details = calloc(rtos->thread_count, sizeof(struct thread_detail));
rtos->thread_count = task_queue_size;
rtos->current_thread = 0;
rtos->thread_details = calloc(rtos->thread_count, sizeof(struct thread_detail));
- if (NULL == rtos->thread_details)
+ if (!rtos->thread_details)
return ERROR_FAIL;
/* loop over each task and setup thread details,
return ERROR_FAIL;
/* loop over each task and setup thread details,
uint32_t i;
uint8_t state;
uint32_t i;
uint8_t state;
- if (rtos->symbols == NULL) {
LOG_ERROR("No symbols for NuttX");
return -3;
}
LOG_ERROR("No symbols for NuttX");
return -3;
}
unsigned int tasks_found = 0;
const struct riot_params *param;
unsigned int tasks_found = 0;
const struct riot_params *param;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
return ERROR_FAIL;
param = (const struct riot_params *)rtos->rtos_specific_params;
return ERROR_FAIL;
param = (const struct riot_params *)rtos->rtos_specific_params;
- if (rtos->symbols == NULL) {
LOG_ERROR("No symbols for RIOT");
return ERROR_FAIL;
}
LOG_ERROR("No symbols for RIOT");
return ERROR_FAIL;
}
/* Allocate memory for thread description */
rtos->thread_details = calloc(thread_count, sizeof(struct thread_detail));
/* Allocate memory for thread description */
rtos->thread_details = calloc(thread_count, sizeof(struct thread_detail));
- if (rtos->thread_details == NULL) {
+ if (!rtos->thread_details) {
LOG_ERROR("RIOT: out of memory");
return ERROR_FAIL;
}
LOG_ERROR("RIOT: out of memory");
return ERROR_FAIL;
}
int retval;
const struct riot_params *param;
int retval;
const struct riot_params *param;
return ERROR_FAIL;
if (thread_id == 0)
return ERROR_FAIL;
return ERROR_FAIL;
if (thread_id == 0)
return ERROR_FAIL;
- if (rtos->rtos_specific_params == NULL)
+ if (!rtos->rtos_specific_params)
return ERROR_FAIL;
param = (const struct riot_params *)rtos->rtos_specific_params;
return ERROR_FAIL;
param = (const struct riot_params *)rtos->rtos_specific_params;
int gdb_thread_packet(struct connection *connection, char const *packet, int packet_size)
{
struct target *target = get_target_from_connection(connection);
int gdb_thread_packet(struct connection *connection, char const *packet, int packet_size)
{
struct target *target = get_target_from_connection(connection);
- if (target->rtos == NULL)
return rtos_thread_packet(connection, packet, packet_size); /* thread not
*found*/
return target->rtos->gdb_thread_packet(connection, packet, packet_size);
return rtos_thread_packet(connection, packet, packet_size); /* thread not
*found*/
return target->rtos->gdb_thread_packet(connection, packet, packet_size);
struct target *target = get_target_from_connection(connection);
if (strncmp(packet, "qThreadExtraInfo,", 17) == 0) {
struct target *target = get_target_from_connection(connection);
if (strncmp(packet, "qThreadExtraInfo,", 17) == 0) {
- if ((target->rtos != NULL) && (target->rtos->thread_details != NULL) &&
+ if ((target->rtos) && (target->rtos->thread_details != NULL) &&
(target->rtos->thread_count != 0)) {
threadid_t threadid = 0;
int found = -1;
sscanf(packet, "qThreadExtraInfo,%" SCNx64, &threadid);
(target->rtos->thread_count != 0)) {
threadid_t threadid = 0;
int found = -1;
sscanf(packet, "qThreadExtraInfo,%" SCNx64, &threadid);
- if ((target->rtos != NULL) && (target->rtos->thread_details != NULL)) {
+ if ((target->rtos) && (target->rtos->thread_details != NULL)) {
int thread_num;
for (thread_num = 0; thread_num < target->rtos->thread_count; thread_num++) {
if (target->rtos->thread_details[thread_num].threadid == threadid) {
int thread_num;
for (thread_num = 0; thread_num < target->rtos->thread_count; thread_num++) {
if (target->rtos->thread_details[thread_num].threadid == threadid) {
struct thread_detail *detail = &target->rtos->thread_details[found];
int str_size = 0;
struct thread_detail *detail = &target->rtos->thread_details[found];
int str_size = 0;
- if (detail->thread_name_str != NULL)
+ if (detail->thread_name_str)
str_size += strlen(detail->thread_name_str);
str_size += strlen(detail->thread_name_str);
- if (detail->extra_info_str != NULL)
+ if (detail->extra_info_str)
str_size += strlen(detail->extra_info_str);
char *tmp_str = calloc(str_size + 9, sizeof(char));
char *tmp_str_ptr = tmp_str;
str_size += strlen(detail->extra_info_str);
char *tmp_str = calloc(str_size + 9, sizeof(char));
char *tmp_str_ptr = tmp_str;
- if (detail->thread_name_str != NULL)
+ if (detail->thread_name_str)
tmp_str_ptr += sprintf(tmp_str_ptr, "Name: %s", detail->thread_name_str);
tmp_str_ptr += sprintf(tmp_str_ptr, "Name: %s", detail->thread_name_str);
- if (detail->extra_info_str != NULL) {
+ if (detail->extra_info_str) {
if (tmp_str_ptr != tmp_str)
tmp_str_ptr += sprintf(tmp_str_ptr, ", ");
tmp_str_ptr += sprintf(tmp_str_ptr, "%s", detail->extra_info_str);
if (tmp_str_ptr != tmp_str)
tmp_str_ptr += sprintf(tmp_str_ptr, ", ");
tmp_str_ptr += sprintf(tmp_str_ptr, "%s", detail->extra_info_str);
return ERROR_OK;
} else if (strncmp(packet, "qfThreadInfo", 12) == 0) {
int i;
return ERROR_OK;
} else if (strncmp(packet, "qfThreadInfo", 12) == 0) {
int i;
- if (target->rtos != NULL) {
if (target->rtos->thread_count == 0) {
gdb_put_packet(connection, "l", 1);
} else {
if (target->rtos->thread_count == 0) {
gdb_put_packet(connection, "l", 1);
} else {
* otherwise it gets incorrectly handled */
return GDB_THREAD_PACKET_NOT_CONSUMED;
} else if (strncmp(packet, "qC", 2) == 0) {
* otherwise it gets incorrectly handled */
return GDB_THREAD_PACKET_NOT_CONSUMED;
} else if (strncmp(packet, "qC", 2) == 0) {
- if (target->rtos != NULL) {
char buffer[19];
int size;
size = snprintf(buffer, 19, "QC%016" PRIx64, target->rtos->current_thread);
char buffer[19];
int size;
size = snprintf(buffer, 19, "QC%016" PRIx64, target->rtos->current_thread);
threadid_t threadid;
int found = -1;
sscanf(packet, "T%" SCNx64, &threadid);
threadid_t threadid;
int found = -1;
sscanf(packet, "T%" SCNx64, &threadid);
- if ((target->rtos != NULL) && (target->rtos->thread_details != NULL)) {
+ if ((target->rtos) && (target->rtos->thread_details != NULL)) {
int thread_num;
for (thread_num = 0; thread_num < target->rtos->thread_count; thread_num++) {
if (target->rtos->thread_details[thread_num].threadid == threadid) {
int thread_num;
for (thread_num = 0; thread_num < target->rtos->thread_count; thread_num++) {
if (target->rtos->thread_details[thread_num].threadid == threadid) {
return ERROR_OK;
} else if (packet[0] == 'H') { /* Set current thread ( 'c' for step and continue, 'g' for
* all other operations ) */
return ERROR_OK;
} else if (packet[0] == 'H') { /* Set current thread ( 'c' for step and continue, 'g' for
* all other operations ) */
- if ((packet[1] == 'g') && (target->rtos != NULL)) {
+ if ((packet[1] == 'g') && (target->rtos)) {
threadid_t threadid;
sscanf(packet, "Hg%16" SCNx64, &threadid);
LOG_DEBUG("RTOS: GDB requested to set current thread to 0x%" PRIx64, threadid);
threadid_t threadid;
sscanf(packet, "Hg%16" SCNx64, &threadid);
LOG_DEBUG("RTOS: GDB requested to set current thread to 0x%" PRIx64, threadid);
{
struct target *target = get_target_from_connection(connection);
int64_t current_threadid = target->rtos->current_threadid;
{
struct target *target = get_target_from_connection(connection);
int64_t current_threadid = target->rtos->current_threadid;
- if ((target->rtos != NULL) && (current_threadid != -1) &&
+ if ((target->rtos) && (current_threadid != -1) &&
(current_threadid != 0) &&
((current_threadid != target->rtos->current_thread) ||
(target->smp))) { /* in smp several current thread are possible */
(current_threadid != 0) &&
((current_threadid != target->rtos->current_thread) ||
(target->smp))) { /* in smp several current thread are possible */
{
struct target *target = get_target_from_connection(connection);
int64_t current_threadid = target->rtos->current_threadid;
{
struct target *target = get_target_from_connection(connection);
int64_t current_threadid = target->rtos->current_threadid;
- if ((target->rtos != NULL) && (current_threadid != -1) &&
+ if ((target->rtos) && (current_threadid != -1) &&
(current_threadid != 0) &&
((current_threadid != target->rtos->current_thread) ||
(target->smp))) { /* in smp several current thread are possible */
(current_threadid != 0) &&
((current_threadid != target->rtos->current_thread) ||
(target->smp))) { /* in smp several current thread are possible */
{
struct target *target = get_target_from_connection(connection);
int64_t current_threadid = target->rtos->current_threadid;
{
struct target *target = get_target_from_connection(connection);
int64_t current_threadid = target->rtos->current_threadid;
- if ((target->rtos != NULL) &&
(target->rtos->type->set_reg != NULL) &&
(current_threadid != -1) &&
(current_threadid != 0)) {
(target->rtos->type->set_reg != NULL) &&
(current_threadid != -1) &&
(current_threadid != 0)) {
#endif
int64_t new_stack_ptr;
#endif
int64_t new_stack_ptr;
- if (stacking->calculate_process_stack != NULL) {
+ if (stacking->calculate_process_stack) {
new_stack_ptr = stacking->calculate_process_stack(target,
stack_data, stacking, stack_ptr);
} else {
new_stack_ptr = stacking->calculate_process_stack(target,
stack_data, stacking, stack_ptr);
} else {
int rtos_update_threads(struct target *target)
{
int rtos_update_threads(struct target *target)
{
- if ((target->rtos != NULL) && (target->rtos->type != NULL))
+ if ((target->rtos) && (target->rtos->type != NULL))
target->rtos->type->update_threads(target->rtos);
return ERROR_OK;
}
target->rtos->type->update_threads(target->rtos);
return ERROR_OK;
}
for (size_t i = 0; i < ARRAY_SIZE(ucos_iii_params_list); i++)
if (strcmp(ucos_iii_params_list[i].target_name, target->type->name) == 0) {
params = malloc(sizeof(*params) + (UCOS_III_MAX_THREADS * sizeof(*params->threads)));
for (size_t i = 0; i < ARRAY_SIZE(ucos_iii_params_list); i++)
if (strcmp(ucos_iii_params_list[i].target_name, target->type->name) == 0) {
params = malloc(sizeof(*params) + (UCOS_III_MAX_THREADS * sizeof(*params->threads)));
LOG_ERROR("uCOS-III: out of memory");
return ERROR_FAIL;
}
LOG_ERROR("uCOS-III: out of memory");
return ERROR_FAIL;
}
struct ucos_iii_params *params = rtos->rtos_specific_params;
int retval;
struct ucos_iii_params *params = rtos->rtos_specific_params;
int retval;
- if (rtos->symbols == NULL) {
LOG_ERROR("uCOS-III: symbol list not loaded");
return ERROR_FAIL;
}
LOG_ERROR("uCOS-III: symbol list not loaded");
return ERROR_FAIL;
}
if (!rtos_running) {
rtos->thread_details = calloc(1, sizeof(struct thread_detail));
if (!rtos_running) {
rtos->thread_details = calloc(1, sizeof(struct thread_detail));
- if (rtos->thread_details == NULL) {
+ if (!rtos->thread_details) {
LOG_ERROR("uCOS-III: out of memory");
return ERROR_FAIL;
}
LOG_ERROR("uCOS-III: out of memory");
return ERROR_FAIL;
}
}
rtos->thread_details = calloc(rtos->thread_count, sizeof(struct thread_detail));
}
rtos->thread_details = calloc(rtos->thread_count, sizeof(struct thread_detail));
- if (rtos->thread_details == NULL) {
+ if (!rtos->thread_details) {
LOG_ERROR("uCOS-III: out of memory");
return ERROR_FAIL;
}
LOG_ERROR("uCOS-III: out of memory");
return ERROR_FAIL;
}
LOG_INFO("Getting thread %" PRId64 " reg list", thread_id);
LOG_INFO("Getting thread %" PRId64 " reg list", thread_id);
return ERROR_FAIL;
if (thread_id == 0)
return ERROR_FAIL;
params = rtos->rtos_specific_params;
return ERROR_FAIL;
if (thread_id == 0)
return ERROR_FAIL;
params = rtos->rtos_specific_params;
return ERROR_FAIL;
addr = thread_id + params->offsets[OFFSET_T_STACK_POINTER]
return ERROR_FAIL;
addr = thread_id + params->offsets[OFFSET_T_STACK_POINTER]
fd_set read_fds;
struct gdb_connection *gdb_con = connection->priv;
int t;
fd_set read_fds;
struct gdb_connection *gdb_con = connection->priv;
int t;
got_data = &t;
*got_data = 0;
got_data = &t;
*got_data = 0;
/* Does packet at least have a prefix that is printable?
* Look within the first 50 chars of the packet. */
const char *colon = memchr(packet, ':', MIN(50, packet_len));
/* Does packet at least have a prefix that is printable?
* Look within the first 50 chars of the packet. */
const char *colon = memchr(packet, ':', MIN(50, packet_len));
- const bool packet_has_prefix = (colon != NULL);
+ const bool packet_has_prefix = (colon);
const bool packet_prefix_printable = (packet_has_prefix && nonprint > colon);
if (packet_prefix_printable) {
const bool packet_prefix_printable = (packet_has_prefix && nonprint > colon);
if (packet_prefix_printable) {
bin_size = strlen(line);
hex_buffer = malloc(bin_size * 2 + 2);
bin_size = strlen(line);
hex_buffer = malloc(bin_size * 2 + 2);
- if (hex_buffer == NULL)
return ERROR_GDB_BUFFER_TOO_SMALL;
hex_buffer[0] = 'O';
return ERROR_GDB_BUFFER_TOO_SMALL;
hex_buffer[0] = 'O';
sig_reply_len = snprintf(sig_reply, sizeof(sig_reply), "W00");
} else {
struct target *ct;
sig_reply_len = snprintf(sig_reply, sizeof(sig_reply), "W00");
} else {
struct target *ct;
- if (target->rtos != NULL) {
target->rtos->current_threadid = target->rtos->current_thread;
target->rtos->gdb_target_for_threadid(connection, target->rtos->current_threadid, &ct);
} else {
target->rtos->current_threadid = target->rtos->current_thread;
target->rtos->gdb_target_for_threadid(connection, target->rtos->current_threadid, &ct);
} else {
}
current_thread[0] = '\0';
}
current_thread[0] = '\0';
- if (target->rtos != NULL)
snprintf(current_thread, sizeof(current_thread), "thread:%" PRIx64 ";",
target->rtos->current_thread);
snprintf(current_thread, sizeof(current_thread), "thread:%" PRIx64 ";",
target->rtos->current_thread);
- if ((target->rtos != NULL) && (ERROR_OK == rtos_get_gdb_reg_list(connection)))
+ if ((target->rtos) && (ERROR_OK == rtos_get_gdb_reg_list(connection)))
return ERROR_OK;
retval = target_get_gdb_reg_list(target, ®_list, ®_list_size,
return ERROR_OK;
retval = target_get_gdb_reg_list(target, ®_list, ®_list_size,
assert(reg_packet_size > 0);
reg_packet = malloc(reg_packet_size + 1); /* plus one for string termination null */
assert(reg_packet_size > 0);
reg_packet = malloc(reg_packet_size + 1); /* plus one for string termination null */
- if (reg_packet == NULL)
return ERROR_FAIL;
reg_packet_p = reg_packet;
return ERROR_FAIL;
reg_packet_p = reg_packet;
- if ((target->rtos != NULL) && (ERROR_OK == rtos_get_gdb_reg(connection, reg_num)))
+ if ((target->rtos) && (ERROR_OK == rtos_get_gdb_reg(connection, reg_num)))
return ERROR_OK;
retval = target_get_gdb_reg_list_noread(target, ®_list, ®_list_size,
return ERROR_OK;
retval = target_get_gdb_reg_list_noread(target, ®_list, ®_list_size,
uint8_t *bin_buf = malloc(chars / 2);
gdb_target_to_reg(target, separator + 1, chars, bin_buf);
uint8_t *bin_buf = malloc(chars / 2);
gdb_target_to_reg(target, separator + 1, chars, bin_buf);
- if ((target->rtos != NULL) &&
(ERROR_OK == rtos_set_reg(connection, reg_num, bin_buf))) {
free(bin_buf);
gdb_put_packet(connection, "OK", 2);
(ERROR_OK == rtos_set_reg(connection, reg_num, bin_buf))) {
free(bin_buf);
gdb_put_packet(connection, "OK", 2);
{
/* Locate the annex. */
const char *annex_end = strchr(buf, ':');
{
/* Locate the annex. */
const char *annex_end = strchr(buf, ':');
return ERROR_FAIL;
/* After the read marker and annex, qXfer looks like a
return ERROR_FAIL;
/* After the read marker and annex, qXfer looks like a
*len = strtoul(separator + 1, NULL, 16);
/* Extract the annex if needed */
*len = strtoul(separator + 1, NULL, 16);
/* Extract the annex if needed */
*annex = strndup(buf, annex_end - buf);
if (*annex == NULL)
return ERROR_FAIL;
*annex = strndup(buf, annex_end - buf);
if (*annex == NULL)
return ERROR_FAIL;
} else if (type->type_class == REG_TYPE_CLASS_UNION) {
struct reg_data_type_union_field *field;
field = type->reg_type_union->fields;
} else if (type->type_class == REG_TYPE_CLASS_UNION) {
struct reg_data_type_union_field *field;
field = type->reg_type_union->fields;
- while (field != NULL) {
struct reg_data_type *data_type = field->type;
if (data_type->type == REG_TYPE_ARCH_DEFINED) {
if (lookup_add_arch_defined_types(arch_defined_types_list, data_type->id,
struct reg_data_type *data_type = field->type;
if (data_type->type == REG_TYPE_ARCH_DEFINED) {
if (lookup_add_arch_defined_types(arch_defined_types_list, data_type->id,
type->id);
field = type->reg_type_union->fields;
type->id);
field = type->reg_type_union->fields;
- while (field != NULL) {
xml_printf(&retval, tdesc, pos, size,
"<field name=\"%s\" type=\"%s\"/>\n",
field->name, field->type->id);
xml_printf(&retval, tdesc, pos, size,
"<field name=\"%s\" type=\"%s\"/>\n",
field->name, field->type->id);
xml_printf(&retval, tdesc, pos, size,
"<struct id=\"%s\" size=\"%" PRIu32 "\">\n",
type->id, type->reg_type_struct->size);
xml_printf(&retval, tdesc, pos, size,
"<struct id=\"%s\" size=\"%" PRIu32 "\">\n",
type->id, type->reg_type_struct->size);
- while (field != NULL) {
xml_printf(&retval, tdesc, pos, size,
"<field name=\"%s\" start=\"%" PRIu32 "\" end=\"%" PRIu32 "\" type=\"%s\" />\n",
field->name, field->bitfield->start, field->bitfield->end,
xml_printf(&retval, tdesc, pos, size,
"<field name=\"%s\" start=\"%" PRIu32 "\" end=\"%" PRIu32 "\" type=\"%s\" />\n",
field->name, field->bitfield->start, field->bitfield->end,
field = field->next;
}
} else {
field = field->next;
}
} else {
- while (field != NULL) {
struct reg_data_type *data_type = field->type;
if (data_type->type == REG_TYPE_ARCH_DEFINED) {
if (lookup_add_arch_defined_types(arch_defined_types_list, data_type->id,
struct reg_data_type *data_type = field->type;
if (data_type->type == REG_TYPE_ARCH_DEFINED) {
if (lookup_add_arch_defined_types(arch_defined_types_list, data_type->id,
xml_printf(&retval, tdesc, pos, size,
"<struct id=\"%s\">\n",
type->id);
xml_printf(&retval, tdesc, pos, size,
"<struct id=\"%s\">\n",
type->id);
- while (field != NULL) {
xml_printf(&retval, tdesc, pos, size,
"<field name=\"%s\" type=\"%s\"/>\n",
field->name, field->type->id);
xml_printf(&retval, tdesc, pos, size,
"<field name=\"%s\" type=\"%s\"/>\n",
field->name, field->type->id);
struct reg_data_type_flags_field *field;
field = type->reg_type_flags->fields;
struct reg_data_type_flags_field *field;
field = type->reg_type_flags->fields;
- while (field != NULL) {
xml_printf(&retval, tdesc, pos, size,
"<field name=\"%s\" start=\"%" PRIu32 "\" end=\"%" PRIu32 "\" type=\"%s\" />\n",
field->name, field->bitfield->start, field->bitfield->end,
xml_printf(&retval, tdesc, pos, size,
"<field name=\"%s\" start=\"%" PRIu32 "\" end=\"%" PRIu32 "\" type=\"%s\" />\n",
field->name, field->bitfield->start, field->bitfield->end,
/* generate architecture element if supported by target */
architecture = target_get_gdb_arch(target);
/* generate architecture element if supported by target */
architecture = target_get_gdb_arch(target);
- if (architecture != NULL)
xml_printf(&retval, &tdesc, &pos, &size,
"<architecture>%s</architecture>\n", architecture);
/* generate target description according to register list */
xml_printf(&retval, &tdesc, &pos, &size,
"<architecture>%s</architecture>\n", architecture);
/* generate target description according to register list */
- if (features != NULL) {
while (features[current_feature]) {
char const **arch_defined_types = NULL;
int num_arch_defined_types = 0;
while (features[current_feature]) {
char const **arch_defined_types = NULL;
int num_arch_defined_types = 0;
static int gdb_get_target_description_chunk(struct target *target, struct target_desc_format *target_desc,
char **chunk, int32_t offset, uint32_t length)
{
static int gdb_get_target_description_chunk(struct target *target, struct target_desc_format *target_desc,
char **chunk, int32_t offset, uint32_t length)
{
- if (target_desc == NULL) {
LOG_ERROR("Unable to Generate Target Description");
return ERROR_FAIL;
}
LOG_ERROR("Unable to Generate Target Description");
return ERROR_FAIL;
}
char *tdesc = target_desc->tdesc;
uint32_t tdesc_length = target_desc->tdesc_length;
char *tdesc = target_desc->tdesc;
uint32_t tdesc_length = target_desc->tdesc_length;
int retval = gdb_generate_target_description(target, &tdesc);
if (retval != ERROR_OK) {
LOG_ERROR("Unable to Generate Target Description");
int retval = gdb_generate_target_description(target, &tdesc);
if (retval != ERROR_OK) {
LOG_ERROR("Unable to Generate Target Description");
"<?xml version=\"1.0\"?>\n"
"<threads>\n");
"<?xml version=\"1.0\"?>\n"
"<threads>\n");
for (int i = 0; i < rtos->thread_count; i++) {
struct thread_detail *thread_detail = &rtos->thread_details[i];
for (int i = 0; i < rtos->thread_count; i++) {
struct thread_detail *thread_detail = &rtos->thread_details[i];
xml_printf(&retval, &thread_list, &pos, &size,
"<thread id=\"%" PRIx64 "\">", thread_detail->threadid);
xml_printf(&retval, &thread_list, &pos, &size,
"<thread id=\"%" PRIx64 "\">", thread_detail->threadid);
- if (thread_detail->thread_name_str != NULL)
+ if (thread_detail->thread_name_str)
xml_printf(&retval, &thread_list, &pos, &size,
"Name: %s", thread_detail->thread_name_str);
xml_printf(&retval, &thread_list, &pos, &size,
"Name: %s", thread_detail->thread_name_str);
- if (thread_detail->extra_info_str != NULL) {
- if (thread_detail->thread_name_str != NULL)
+ if (thread_detail->extra_info_str) {
+ if (thread_detail->thread_name_str)
xml_printf(&retval, &thread_list, &pos, &size,
", ");
xml_printf(&retval, &thread_list, &pos, &size,
xml_printf(&retval, &thread_list, &pos, &size,
", ");
xml_printf(&retval, &thread_list, &pos, &size,
packet_size -= 2;
thread_id = strtoll(parse, &endp, 16);
packet_size -= 2;
thread_id = strtoll(parse, &endp, 16);
packet_size -= endp - parse;
parse = endp;
}
packet_size -= endp - parse;
parse = endp;
}
- if (target->rtos != NULL) {
/* FIXME: why is this necessary? rtos state should be up-to-date here already! */
rtos_update_threads(target);
/* FIXME: why is this necessary? rtos state should be up-to-date here already! */
rtos_update_threads(target);
return NULL;
const char *end = strchr(hex, sep);
return NULL;
const char *end = strchr(hex, sep);
hexlen = strlen(hex);
else
hexlen = end - hex;
hexlen = strlen(hex);
else
hexlen = end - hex;
size_t count = hexlen / 2;
char *decoded = malloc(count + 1);
size_t count = hexlen / 2;
char *decoded = malloc(count + 1);
return NULL;
size_t converted = unhexify((void *)decoded, hex, count);
return NULL;
size_t converted = unhexify((void *)decoded, hex, count);
- if (cmdline != NULL) {
- if (target->semihosting != NULL) {
+ if (cmdline) {
+ if (target->semihosting) {
LOG_INFO("GDB set inferior command line to '%s'", cmdline);
free(target->semihosting->cmdline);
target->semihosting->cmdline = cmdline;
LOG_INFO("GDB set inferior command line to '%s'", cmdline);
free(target->semihosting->cmdline);
target->semihosting->cmdline = cmdline;
length = packet_size - (parse - packet);
/* create a new image if there isn't already one */
length = packet_size - (parse - packet);
/* create a new image if there isn't already one */
- if (gdb_connection->vflash_image == NULL) {
+ if (!gdb_connection->vflash_image) {
gdb_connection->vflash_image = malloc(sizeof(struct image));
image_open(gdb_connection->vflash_image, "", "build");
}
gdb_connection->vflash_image = malloc(sizeof(struct image));
image_open(gdb_connection->vflash_image, "", "build");
}
int ret;
gdb_service = malloc(sizeof(struct gdb_service));
int ret;
gdb_service = malloc(sizeof(struct gdb_service));
- if (NULL == gdb_service)
return -ENOMEM;
LOG_INFO("starting gdb server for %s on %s", target_name(target), port);
return -ENOMEM;
LOG_INFO("starting gdb server for %s on %s", target_name(target), port);
int gdb_target_add_all(struct target *target)
{
int gdb_target_add_all(struct target *target)
{
LOG_WARNING("gdb services need one or more targets defined");
return ERROR_OK;
}
LOG_WARNING("gdb services need one or more targets defined");
return ERROR_OK;
}
- while (NULL != target) {
int retval = gdb_target_add_one(target);
if (retval != ERROR_OK)
return retval;
int retval = gdb_target_add_one(target);
if (retval != ERROR_OK)
return retval;
if (CMD_ARGC != 0)
return ERROR_COMMAND_SYNTAX_ERROR;
if (CMD_ARGC != 0)
return ERROR_COMMAND_SYNTAX_ERROR;
- if (current_gdb_connection == NULL) {
+ if (!current_gdb_connection) {
command_print(CMD,
"gdb_sync command can only be run from within gdb using \"monitor gdb_sync\"");
return ERROR_FAIL;
command_print(CMD,
"gdb_sync command can only be run from within gdb using \"monitor gdb_sync\"");
return ERROR_FAIL;
size_t size_written;
char *tdesc_filename = alloc_printf("%s.xml", target_type_name(target));
size_t size_written;
char *tdesc_filename = alloc_printf("%s.xml", target_type_name(target));
- if (tdesc_filename == NULL) {
retval = ERROR_FAIL;
goto out;
}
retval = ERROR_FAIL;
goto out;
}
memset(&c->sin, 0, sizeof(c->sin));
c->sin.sin_family = AF_INET;
memset(&c->sin, 0, sizeof(c->sin));
c->sin.sin_family = AF_INET;
- if (bindto_name == NULL)
c->sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
else {
hp = gethostbyname(bindto_name);
c->sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
else {
hp = gethostbyname(bindto_name);
LOG_ERROR("couldn't resolve bindto address: %s", bindto_name);
close_socket(c->fd);
free_service(c);
LOG_ERROR("couldn't resolve bindto address: %s", bindto_name);
close_socket(c->fd);
free_service(c);
struct tcl_connection *tclc;
tclc = calloc(1, sizeof(struct tcl_connection));
struct tcl_connection *tclc;
tclc = calloc(1, sizeof(struct tcl_connection));
return ERROR_CONNECTION_REJECTED;
tclc->tc_line_size = TCL_LINE_INITIAL;
tclc->tc_line = malloc(tclc->tc_line_size);
return ERROR_CONNECTION_REJECTED;
tclc->tc_line_size = TCL_LINE_INITIAL;
tclc->tc_line = malloc(tclc->tc_line_size);
- if (tclc->tc_line == NULL) {
free(tclc);
return ERROR_CONNECTION_REJECTED;
}
free(tclc);
return ERROR_CONNECTION_REJECTED;
}
connection->priv = tclc;
struct target *target = get_current_target_or_null(connection->cmd_ctx);
connection->priv = tclc;
struct target *target = get_current_target_or_null(connection->cmd_ctx);
tclc->tc_laststate = target->state;
/* store the connection object on cmd_ctx so we can access it from command handlers */
tclc->tc_laststate = target->state;
/* store the connection object on cmd_ctx so we can access it from command handlers */
}
tclc = connection->priv;
}
tclc = connection->priv;
return ERROR_CONNECTION_REJECTED;
/* push as much data into the line as possible */
return ERROR_CONNECTION_REJECTED;
/* push as much data into the line as possible */
tc_line_size_new = TCL_LINE_MAX;
tc_line_new = realloc(tclc->tc_line, tc_line_size_new);
tc_line_size_new = TCL_LINE_MAX;
tc_line_new = realloc(tclc->tc_line, tc_line_size_new);
- if (tc_line_new == NULL) {
tclc->tc_linedrop = 1;
} else {
tclc->tc_line = tc_line_new;
tclc->tc_linedrop = 1;
} else {
tclc->tc_line = tc_line_new;
char *history = get_home_dir(TELNET_HISTORY);
char *history = get_home_dir(TELNET_HISTORY);
LOG_INFO("unable to get user home directory, telnet history will be disabled");
return;
}
LOG_INFO("unable to get user home directory, telnet history will be disabled");
return;
}
char *history = get_home_dir(TELNET_HISTORY);
char *history = get_home_dir(TELNET_HISTORY);
LOG_INFO("unable to get user home directory, telnet history will be disabled");
return;
}
LOG_INFO("unable to get user home directory, telnet history will be disabled");
return;
}
static void svf_free_xxd_para(struct svf_xxr_para *para)
{
static void svf_free_xxd_para(struct svf_xxr_para *para)
{
free(para->tdi);
para->tdi = NULL;
free(para->tdi);
para->tdi = NULL;
svf_ignore_error = 1;
else {
svf_fd = fopen(CMD_ARGV[i], "r");
svf_ignore_error = 1;
else {
svf_fd = fopen(CMD_ARGV[i], "r");
int err = errno;
command_print(CMD, "open(\"%s\"): %s", CMD_ARGV[i], strerror(err));
/* no need to free anything now */
int err = errno;
command_print(CMD, "open(\"%s\"): %s", CMD_ARGV[i], strerror(err));
/* no need to free anything now */
return ERROR_COMMAND_SYNTAX_ERROR;
/* get time */
return ERROR_COMMAND_SYNTAX_ERROR;
/* get time */
svf_check_tdo_para_index = 0;
svf_check_tdo_para = malloc(sizeof(struct svf_check_tdo_para) * SVF_CHECK_TDO_PARA_SIZE);
svf_check_tdo_para_index = 0;
svf_check_tdo_para = malloc(sizeof(struct svf_check_tdo_para) * SVF_CHECK_TDO_PARA_SIZE);
- if (NULL == svf_check_tdo_para) {
+ if (!svf_check_tdo_para) {
LOG_ERROR("not enough memory");
ret = ERROR_FAIL;
goto free_all;
LOG_ERROR("not enough memory");
ret = ERROR_FAIL;
goto free_all;
if (cmd_pos + 3 > svf_command_buffer_size) {
svf_command_buffer = realloc(svf_command_buffer, cmd_pos + 3);
svf_command_buffer_size = cmd_pos + 3;
if (cmd_pos + 3 > svf_command_buffer_size) {
svf_command_buffer = realloc(svf_command_buffer, cmd_pos + 3);
svf_command_buffer_size = cmd_pos + 3;
- if (svf_command_buffer == NULL) {
+ if (!svf_command_buffer) {
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
}
/* If TDO is absent, no comparison is needed, set the mask to 0 */
if (!(xxr_para_tmp->data_mask & XXR_TDO)) {
}
/* If TDO is absent, no comparison is needed, set the mask to 0 */
if (!(xxr_para_tmp->data_mask & XXR_TDO)) {
- if (NULL == xxr_para_tmp->tdo) {
+ if (!xxr_para_tmp->tdo) {
if (ERROR_OK !=
svf_adjust_array_length(&xxr_para_tmp->tdo, i_tmp,
xxr_para_tmp->len)) {
if (ERROR_OK !=
svf_adjust_array_length(&xxr_para_tmp->tdo, i_tmp,
xxr_para_tmp->len)) {
- if (NULL == xxr_para_tmp->mask) {
+ if (!xxr_para_tmp->mask) {
if (ERROR_OK !=
svf_adjust_array_length(&xxr_para_tmp->mask, i_tmp,
xxr_para_tmp->len)) {
if (ERROR_OK !=
svf_adjust_array_length(&xxr_para_tmp->mask, i_tmp,
xxr_para_tmp->len)) {
if (num_of_argu > 2) {
/* STATE pathstate1 ... stable_state */
path = malloc((num_of_argu - 1) * sizeof(tap_state_t));
if (num_of_argu > 2) {
/* STATE pathstate1 ... stable_state */
path = malloc((num_of_argu - 1) * sizeof(tap_state_t));
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
LOG_DEBUG("target %s exc %i", target_name(target), exc_target);
LOG_DEBUG("target %s exc %i", target_name(target), exc_target);
struct target *curr = head->target;
struct armv8_common *armv8 = target_to_armv8(curr);
head = head->next;
struct target *curr = head->target;
struct armv8_common *armv8 = target_to_armv8(curr);
head = head->next;
LOG_DEBUG("target %s prepared", target_name(curr));
LOG_DEBUG("target %s prepared", target_name(curr));
if (curr->state == TARGET_HALTED)
continue;
/* remember the gdb_service->target */
if (curr->state == TARGET_HALTED)
continue;
/* remember the gdb_service->target */
- if (curr->gdb_service != NULL)
gdb_target = curr->gdb_service->target;
/* skip it */
if (curr == gdb_target)
gdb_target = curr->gdb_service->target;
/* skip it */
if (curr == gdb_target)
break;
}
/* remember the first valid target in the group */
break;
}
/* remember the first valid target in the group */
if (retval != ERROR_OK)
return retval;
if (retval != ERROR_OK)
return retval;
retval = aarch64_do_restart_one(first, RESTART_LAZY);
if (retval != ERROR_OK) {
LOG_DEBUG("error restarting target %s", target_name(first));
retval = aarch64_do_restart_one(first, RESTART_LAZY);
if (retval != ERROR_OK) {
LOG_DEBUG("error restarting target %s", target_name(first));
uint32_t tmp0, tmp1, tmp2, tmp3;
debug = ttypr = cpuid = 0;
uint32_t tmp0, tmp1, tmp2, tmp3;
debug = ttypr = cpuid = 0;
return ERROR_FAIL;
if (pc->adiv5_config.ap_num == DP_APSEL_INVALID) {
return ERROR_FAIL;
if (pc->adiv5_config.ap_num == DP_APSEL_INVALID) {
LOG_DEBUG("ttypr = 0x%08" PRIx64, ttypr);
LOG_DEBUG("debug = 0x%08" PRIx64, debug);
LOG_DEBUG("ttypr = 0x%08" PRIx64, ttypr);
LOG_DEBUG("debug = 0x%08" PRIx64, debug);
return ERROR_FAIL;
armv8->cti = pc->cti;
return ERROR_FAIL;
armv8->cti = pc->cti;
return ERROR_FAIL;
aarch64 = calloc(1, sizeof(struct aarch64_common));
return ERROR_FAIL;
aarch64 = calloc(1, sizeof(struct aarch64_common));
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
int e;
pc = (struct aarch64_private_config *)target->private_config;
int e;
pc = (struct aarch64_private_config *)target->private_config;
pc = calloc(1, sizeof(struct aarch64_private_config));
pc->adiv5_config.ap_num = DP_APSEL_INVALID;
target->private_config = pc;
pc = calloc(1, sizeof(struct aarch64_private_config));
pc->adiv5_config.ap_num = DP_APSEL_INVALID;
target->private_config = pc;
if (e != JIM_OK)
return e;
cti = cti_instance_by_jim_obj(goi->interp, o_cti);
if (e != JIM_OK)
return e;
cti = cti_instance_by_jim_obj(goi->interp, o_cti);
Jim_SetResultString(goi->interp, "CTI name invalid!", -1);
return JIM_ERR;
}
Jim_SetResultString(goi->interp, "CTI name invalid!", -1);
return JIM_ERR;
}
{
struct target *target = get_current_target(CMD_CTX);
{
struct target *target = get_current_target(CMD_CTX);
LOG_ERROR("No target selected");
return ERROR_FAIL;
}
LOG_ERROR("No target selected");
return ERROR_FAIL;
}
if (CMD_ARGC > 0) {
n = jim_nvp_name2value_simple(nvp_maskisr_modes, CMD_ARGV[0]);
if (CMD_ARGC > 0) {
n = jim_nvp_name2value_simple(nvp_maskisr_modes, CMD_ARGV[0]);
LOG_ERROR("Unknown parameter: %s - should be off or on", CMD_ARGV[0]);
return ERROR_COMMAND_SYNTAX_ERROR;
}
LOG_ERROR("Unknown parameter: %s - should be off or on", CMD_ARGV[0]);
return ERROR_COMMAND_SYNTAX_ERROR;
}
}
context = current_command_context(interp);
}
context = current_command_context(interp);
- assert(context != NULL);
target = get_current_target(context);
target = get_current_target(context);
LOG_ERROR("%s: no current target", __func__);
return JIM_ERR;
}
LOG_ERROR("%s: no current target", __func__);
return JIM_ERR;
}
if (list_empty(&dap->cmd_pool)) {
pool = calloc(1, sizeof(struct dap_cmd_pool));
if (list_empty(&dap->cmd_pool)) {
pool = calloc(1, sizeof(struct dap_cmd_pool));
return NULL;
} else {
pool = list_first_entry(&dap->cmd_pool, struct dap_cmd_pool, lh);
return NULL;
} else {
pool = list_first_entry(&dap->cmd_pool, struct dap_cmd_pool, lh);
cmd->instr = instr;
cmd->reg_addr = reg_addr;
cmd->rnw = rnw;
cmd->instr = instr;
cmd->reg_addr = reg_addr;
cmd->rnw = rnw;
memcpy(cmd->outvalue_buf, outvalue, 4);
memcpy(cmd->outvalue_buf, outvalue, 4);
- cmd->invalue = (invalue != NULL) ? invalue : cmd->invalue_buf;
+ cmd->invalue = (invalue) ? invalue : cmd->invalue_buf;
cmd->memaccess_tck = memaccess_tck;
return cmd;
cmd->memaccess_tck = memaccess_tck;
return cmd;
cmd->fields[0].num_bits = 3;
buf_set_u32(&cmd->out_addr_buf, 0, 3, ((cmd->reg_addr >> 1) & 0x6) | (cmd->rnw & 0x1));
cmd->fields[0].out_value = &cmd->out_addr_buf;
cmd->fields[0].num_bits = 3;
buf_set_u32(&cmd->out_addr_buf, 0, 3, ((cmd->reg_addr >> 1) & 0x6) | (cmd->rnw & 0x1));
cmd->fields[0].out_value = &cmd->out_addr_buf;
- cmd->fields[0].in_value = (ack != NULL) ? ack : &cmd->ack;
+ cmd->fields[0].in_value = (ack) ? ack : &cmd->ack;
/* NOTE: if we receive JTAG_ACK_WAIT, the previous operation did not
* complete; data we write is discarded, data we read is unpredictable.
/* NOTE: if we receive JTAG_ACK_WAIT, the previous operation did not
* complete; data we write is discarded, data we read is unpredictable.
int retval;
cmd = dap_cmd_new(dap, instr, reg_addr, rnw, outvalue, invalue, memaccess_tck);
int retval;
cmd = dap_cmd_new(dap, instr, reg_addr, rnw, outvalue, invalue, memaccess_tck);
cmd->dp_select = dap->select;
else
return ERROR_JTAG_DEVICE_ERROR;
cmd->dp_select = dap->select;
else
return ERROR_JTAG_DEVICE_ERROR;
- if (dap->last_read != NULL) {
retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC,
DP_RDBUFF, DPAP_READ, 0, dap->last_read, 0, NULL);
dap->last_read = NULL;
retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC,
DP_RDBUFF, DPAP_READ, 0, dap->last_read, 0, NULL);
dap->last_read = NULL;
/* For reads, collect posted value; RDBUFF has no other effect.
* Assumes read gets acked with OK/FAULT, and CTRL_STAT says "OK".
*/
/* For reads, collect posted value; RDBUFF has no other effect.
* Assumes read gets acked with OK/FAULT, and CTRL_STAT says "OK".
*/
- if ((rnw == DPAP_READ) && (invalue != NULL)) {
+ if ((rnw == DPAP_READ) && (invalue)) {
retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC,
DP_RDBUFF, DPAP_READ, 0, invalue, 0, NULL);
if (retval != ERROR_OK)
retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC,
DP_RDBUFF, DPAP_READ, 0, invalue, 0, NULL);
if (retval != ERROR_OK)
log_dap_cmd("LST", el);
/*
log_dap_cmd("LST", el);
/*
*/
tmp = dap_cmd_new(dap, JTAG_DP_DPACC,
DP_RDBUFF, DPAP_READ, NULL, NULL, 0);
*/
tmp = dap_cmd_new(dap, JTAG_DP_DPACC,
DP_RDBUFF, DPAP_READ, NULL, NULL, 0);
retval = ERROR_JTAG_DEVICE_ERROR;
goto done;
}
retval = ERROR_JTAG_DEVICE_ERROR;
goto done;
}
el = list_first_entry(&replay_list, struct dap_cmd, lh);
tmp = dap_cmd_new(dap, JTAG_DP_DPACC,
DP_SELECT, DPAP_WRITE, (uint8_t *)&el->dp_select, NULL, 0);
el = list_first_entry(&replay_list, struct dap_cmd, lh);
tmp = dap_cmd_new(dap, JTAG_DP_DPACC,
DP_SELECT, DPAP_WRITE, (uint8_t *)&el->dp_select, NULL, 0);
retval = ERROR_JTAG_DEVICE_ERROR;
goto done;
}
retval = ERROR_JTAG_DEVICE_ERROR;
goto done;
}
static void swd_finish_read(struct adiv5_dap *dap)
{
const struct swd_driver *swd = adiv5_dap_swd_driver(dap);
static void swd_finish_read(struct adiv5_dap *dap)
{
const struct swd_driver *swd = adiv5_dap_swd_driver(dap);
- if (dap->last_read != NULL) {
swd->read_reg(swd_cmd(true, false, DP_RDBUFF), dap->last_read, 0);
dap->last_read = NULL;
}
swd->read_reg(swd_cmd(true, false, DP_RDBUFF), dap->last_read, 0);
dap->last_read = NULL;
}
static int get_current_actionpoint(struct target *target,
struct arc_actionpoint **actionpoint)
{
static int get_current_actionpoint(struct target *target,
struct arc_actionpoint **actionpoint)
{
- assert(target != NULL);
- assert(actionpoint != NULL);
+ assert(target);
+ assert(actionpoint);
uint32_t debug_ah;
/* Check if actionpoint caused halt */
uint32_t debug_ah;
/* Check if actionpoint caused halt */
struct arc_actionpoint *actionpoint = NULL;
CHECK_RETVAL(get_current_actionpoint(target, &actionpoint));
struct arc_actionpoint *actionpoint = NULL;
CHECK_RETVAL(get_current_actionpoint(target, &actionpoint));
- if (actionpoint != NULL) {
if (!actionpoint->used)
LOG_WARNING("Target halted by an unused actionpoint.");
if (!actionpoint->used)
LOG_WARNING("Target halted by an unused actionpoint.");
struct arc_actionpoint *actionpoint = NULL;
CHECK_RETVAL(get_current_actionpoint(target, &actionpoint));
struct arc_actionpoint *actionpoint = NULL;
CHECK_RETVAL(get_current_actionpoint(target, &actionpoint));
- if (actionpoint != NULL) {
if (!actionpoint->used)
LOG_WARNING("Target halted by unused actionpoint.");
if (!actionpoint->used)
LOG_WARNING("Target halted by unused actionpoint.");
/** Convert target handle to generic ARM target state handle. */
static inline struct arm *target_to_arm(struct target *target)
{
/** Convert target handle to generic ARM target state handle. */
static inline struct arm *target_to_arm(struct target *target)
{
- assert(target != NULL);
return target->arch_info;
}
static inline bool is_arm(struct arm *arm)
{
return target->arch_info;
}
static inline bool is_arm(struct arm *arm)
{
return arm->common_magic == ARM_COMMON_MAGIC;
}
return arm->common_magic == ARM_COMMON_MAGIC;
}
{
struct arm11_common *arm11;
{
struct arm11_common *arm11;
- if (target->tap == NULL)
return ERROR_FAIL;
if (target->tap->ir_length != 5) {
return ERROR_FAIL;
if (target->tap->ir_length != 5) {
unsigned bytes = sizeof(*readies)*readies_num;
readies = malloc(bytes);
unsigned bytes = sizeof(*readies)*readies_num;
readies = malloc(bytes);
LOG_ERROR("Out of memory allocating %u bytes", bytes);
return ERROR_FAIL;
}
LOG_ERROR("Out of memory allocating %u bytes", bytes);
return ERROR_FAIL;
}
struct breakpoint *breakpoint;
breakpoint = breakpoint_find(target,
buf_get_u32(arm->pc->value, 0, 32));
struct breakpoint *breakpoint;
breakpoint = breakpoint_find(target,
buf_get_u32(arm->pc->value, 0, 32));
- if (breakpoint != NULL) {
LOG_DEBUG("unset breakpoint at 0x%8.8" TARGET_PRIxADDR " (id: %" PRIu32,
breakpoint->address,
breakpoint->unique_id);
LOG_DEBUG("unset breakpoint at 0x%8.8" TARGET_PRIxADDR " (id: %" PRIu32,
breakpoint->address,
breakpoint->unique_id);
/* the front-end may request us not to handle breakpoints */
if (handle_breakpoints)
breakpoint = breakpoint_find(target, current_pc);
/* the front-end may request us not to handle breakpoints */
if (handle_breakpoints)
breakpoint = breakpoint_find(target, current_pc);
- if (breakpoint != NULL) {
retval = arm7_9_unset_breakpoint(target, breakpoint);
if (retval != ERROR_OK)
return retval;
retval = arm7_9_unset_breakpoint(target, breakpoint);
if (retval != ERROR_OK)
return retval;
struct reg_cache *t, **cache_p;
t = embeddedice_build_reg_cache(target, arm7_9);
struct reg_cache *t, **cache_p;
t = embeddedice_build_reg_cache(target, arm7_9);
return ERROR_FAIL;
cache_p = register_get_last_cache_p(&target->reg_cache);
return ERROR_FAIL;
cache_p = register_get_last_cache_p(&target->reg_cache);
return ERROR_COMMAND_SYNTAX_ERROR;
output = fopen(CMD_ARGV[0], "w");
return ERROR_COMMAND_SYNTAX_ERROR;
output = fopen(CMD_ARGV[0], "w");
LOG_DEBUG("error opening cache content file");
return ERROR_OK;
}
LOG_DEBUG("error opening cache content file");
return ERROR_OK;
}
return ERROR_COMMAND_SYNTAX_ERROR;
output = fopen(CMD_ARGV[0], "w");
return ERROR_COMMAND_SYNTAX_ERROR;
output = fopen(CMD_ARGV[0], "w");
LOG_DEBUG("error opening mmu content file");
return ERROR_OK;
}
LOG_DEBUG("error opening mmu content file");
return ERROR_OK;
}
uint32_t *read_buf = calloc(count, sizeof(uint32_t));
/* Multiplication count * sizeof(uint32_t) may overflow, calloc() is safe */
uint32_t *read_ptr = read_buf;
uint32_t *read_buf = calloc(count, sizeof(uint32_t));
/* Multiplication count * sizeof(uint32_t) may overflow, calloc() is safe */
uint32_t *read_ptr = read_buf;
- if (read_buf == NULL) {
LOG_ERROR("Failed to allocate read buffer");
return ERROR_FAIL;
}
LOG_ERROR("Failed to allocate read buffer");
return ERROR_FAIL;
}
int e;
pc = (struct adiv5_private_config *)target->private_config;
int e;
pc = (struct adiv5_private_config *)target->private_config;
pc = calloc(1, sizeof(struct adiv5_private_config));
pc->ap_num = DP_APSEL_INVALID;
target->private_config = pc;
pc = calloc(1, sizeof(struct adiv5_private_config));
pc->ap_num = DP_APSEL_INVALID;
target->private_config = pc;
int adiv5_verify_config(struct adiv5_private_config *pc)
{
int adiv5_verify_config(struct adiv5_private_config *pc)
{
return ERROR_FAIL;
return ERROR_OK;
return ERROR_FAIL;
return ERROR_OK;
static inline int dap_send_sequence(struct adiv5_dap *dap,
enum swd_special_seq seq)
{
static inline int dap_send_sequence(struct adiv5_dap *dap,
enum swd_special_seq seq)
{
- assert(dap->ops != NULL);
return dap->ops->send_sequence(dap, seq);
}
return dap->ops->send_sequence(dap, seq);
}
static inline int dap_queue_dp_read(struct adiv5_dap *dap,
unsigned reg, uint32_t *data)
{
static inline int dap_queue_dp_read(struct adiv5_dap *dap,
unsigned reg, uint32_t *data)
{
- assert(dap->ops != NULL);
return dap->ops->queue_dp_read(dap, reg, data);
}
return dap->ops->queue_dp_read(dap, reg, data);
}
static inline int dap_queue_dp_write(struct adiv5_dap *dap,
unsigned reg, uint32_t data)
{
static inline int dap_queue_dp_write(struct adiv5_dap *dap,
unsigned reg, uint32_t data)
{
- assert(dap->ops != NULL);
return dap->ops->queue_dp_write(dap, reg, data);
}
return dap->ops->queue_dp_write(dap, reg, data);
}
*/
static inline int dap_queue_ap_abort(struct adiv5_dap *dap, uint8_t *ack)
{
*/
static inline int dap_queue_ap_abort(struct adiv5_dap *dap, uint8_t *ack)
{
- assert(dap->ops != NULL);
return dap->ops->queue_ap_abort(dap, ack);
}
return dap->ops->queue_ap_abort(dap, ack);
}
*/
static inline int dap_run(struct adiv5_dap *dap)
{
*/
static inline int dap_run(struct adiv5_dap *dap)
{
- assert(dap->ops != NULL);
return dap->ops->run(dap);
}
static inline int dap_sync(struct adiv5_dap *dap)
{
return dap->ops->run(dap);
}
static inline int dap_sync(struct adiv5_dap *dap)
{
- assert(dap->ops != NULL);
if (dap->ops->sync)
return dap->ops->sync(dap);
return ERROR_OK;
if (dap->ops->sync)
return dap->ops->sync(dap);
return ERROR_OK;
{
struct adiv5_ap *ap = dap_ap(self->spot.dap, self->spot.ap_num);
{
struct adiv5_ap *ap = dap_ap(self->spot.dap, self->spot.ap_num);
return ERROR_COMMAND_ARGUMENT_INVALID;
return mem_ap_read_atomic_u32(ap, self->spot.base + reg, p_value);
return ERROR_COMMAND_ARGUMENT_INVALID;
return mem_ap_read_atomic_u32(ap, self->spot.base + reg, p_value);
int e;
cmd_ctx = current_command_context(goi->interp);
int e;
cmd_ctx = current_command_context(goi->interp);
- assert(cmd_ctx != NULL);
if (goi->argc < 3) {
Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ..options...");
if (goi->argc < 3) {
Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ..options...");
/* Create it */
cti = calloc(1, sizeof(*cti));
/* Create it */
cti = calloc(1, sizeof(*cti));
return JIM_ERR;
adiv5_mem_ap_spot_init(&cti->spot);
return JIM_ERR;
adiv5_mem_ap_spot_init(&cti->spot);
if (e != JIM_OK)
return e;
tap = jtag_tap_by_jim_obj(goi->interp, o_t);
if (e != JIM_OK)
return e;
tap = jtag_tap_by_jim_obj(goi->interp, o_t);
Jim_SetResultString(goi->interp, "-chain-position is invalid", -1);
return JIM_ERR;
}
Jim_SetResultString(goi->interp, "-chain-position is invalid", -1);
return JIM_ERR;
}
Jim_SetResultString(goi->interp, "-chain-position required when creating DAP", -1);
return JIM_ERR;
}
Jim_SetResultString(goi->interp, "-chain-position required when creating DAP", -1);
return JIM_ERR;
}
int e;
cmd_ctx = current_command_context(goi->interp);
int e;
cmd_ctx = current_command_context(goi->interp);
- assert(cmd_ctx != NULL);
if (goi->argc < 3) {
Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ..options...");
if (goi->argc < 3) {
Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ..options...");
/* Create it */
dap = calloc(1, sizeof(struct arm_dap_object));
/* Create it */
dap = calloc(1, sizeof(struct arm_dap_object));
return JIM_ERR;
e = dap_configure(goi, dap);
return JIM_ERR;
e = dap_configure(goi, dap);
struct adiv5_dap *dap = arm->dap;
uint32_t apsel;
struct adiv5_dap *dap = arm->dap;
uint32_t apsel;
LOG_ERROR("DAP instance not available. Probably a HLA target...");
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
}
LOG_ERROR("DAP instance not available. Probably a HLA target...");
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
}
arm->read_core_reg = arm_dpm_read_core_reg;
arm->write_core_reg = arm_dpm_write_core_reg;
arm->read_core_reg = arm_dpm_read_core_reg;
arm->write_core_reg = arm_dpm_write_core_reg;
- if (arm->core_cache == NULL) {
+ if (!arm->core_cache) {
cache = arm_build_reg_cache(target, arm);
if (!cache)
return ERROR_FAIL;
cache = arm_build_reg_cache(target, arm);
if (!cache)
return ERROR_FAIL;
buf_set_u32(t, 0, field.num_bits, new_instr);
field.in_value = NULL;
buf_set_u32(t, 0, field.num_bits, new_instr);
field.in_value = NULL;
- if (no_verify_capture == NULL)
+ if (!no_verify_capture)
jtag_add_ir_scan(tap, &field, end_state);
else {
/* FIX!!!! this is a kludge!!! arm926ejs.c should reimplement this arm_jtag_set_instr to
jtag_add_ir_scan(tap, &field, end_state);
else {
/* FIX!!!! this is a kludge!!! arm926ejs.c should reimplement this arm_jtag_set_instr to
static int arm_tpiu_swo_configure(struct jim_getopt_info *goi, struct arm_tpiu_swo_object *obj)
{
static int arm_tpiu_swo_configure(struct jim_getopt_info *goi, struct arm_tpiu_swo_object *obj)
{
if (goi->isconfigure && obj->enabled) {
Jim_SetResultFormatted(goi->interp, "Cannot configure TPIU/SWO; %s is enabled!", obj->name);
if (goi->isconfigure && obj->enabled) {
Jim_SetResultFormatted(goi->interp, "Cannot configure TPIU/SWO; %s is enabled!", obj->name);
int e;
cmd_ctx = current_command_context(interp);
int e;
cmd_ctx = current_command_context(interp);
- assert(cmd_ctx != NULL);
/* does this command exist? */
cmd = Jim_GetCommand(interp, Jim_NewStringObj(interp, obj->name, -1), JIM_ERRMSG);
/* does this command exist? */
cmd = Jim_GetCommand(interp, Jim_NewStringObj(interp, obj->name, -1), JIM_ERRMSG);
#if HAVE_CAPSTONE
struct target *target = get_current_target(CMD_CTX);
#if HAVE_CAPSTONE
struct target *target = get_current_target(CMD_CTX);
LOG_ERROR("No target selected");
return ERROR_FAIL;
}
LOG_ERROR("No target selected");
return ERROR_FAIL;
}
int retval;
context = current_command_context(interp);
int retval;
context = current_command_context(interp);
- assert(context != NULL);
target = get_current_target(context);
target = get_current_target(context);
LOG_ERROR("%s: no current target", __func__);
return JIM_ERR;
}
LOG_ERROR("%s: no current target", __func__);
return JIM_ERR;
}
command_print(cmd, "Outer unified cache Base Address 0x%" PRIx32 ", %" PRIu32 " ways",
l2x_cache->base, l2x_cache->way);
command_print(cmd, "Outer unified cache Base Address 0x%" PRIx32 ", %" PRIu32 " ways",
l2x_cache->base, l2x_cache->way);
LOG_USER("Page Directory at (phys): %8.8" TARGET_PRIxADDR, ttb);
first_lvl_ptbl = malloc(sizeof(uint32_t)*(max_pt_idx+1));
LOG_USER("Page Directory at (phys): %8.8" TARGET_PRIxADDR, ttb);
first_lvl_ptbl = malloc(sizeof(uint32_t)*(max_pt_idx+1));
- if (first_lvl_ptbl == NULL)
blocks_to_check = num_blocks;
struct algo_block *params = malloc((blocks_to_check+1)*sizeof(struct algo_block));
blocks_to_check = num_blocks;
struct algo_block *params = malloc((blocks_to_check+1)*sizeof(struct algo_block));
retval = ERROR_FAIL;
goto cleanup1;
}
retval = ERROR_FAIL;
goto cleanup1;
}
return retval;
n = jim_nvp_value2name_simple(nvp_ecatch_modes, edeccr & 0x0f);
return retval;
n = jim_nvp_value2name_simple(nvp_ecatch_modes, edeccr & 0x0f);
sec = n->name;
n = jim_nvp_value2name_simple(nvp_ecatch_modes, edeccr & 0xf0);
sec = n->name;
n = jim_nvp_value2name_simple(nvp_ecatch_modes, edeccr & 0xf0);
nsec = n->name;
if (sec == NULL || nsec == NULL) {
nsec = n->name;
if (sec == NULL || nsec == NULL) {
while (CMD_ARGC > argp) {
n = jim_nvp_name2value_simple(nvp_ecatch_modes, CMD_ARGV[argp]);
while (CMD_ARGC > argp) {
n = jim_nvp_name2value_simple(nvp_ecatch_modes, CMD_ARGV[argp]);
LOG_ERROR("Unknown option: %s", CMD_ARGV[argp]);
return ERROR_FAIL;
}
LOG_ERROR("Unknown option: %s", CMD_ARGV[argp]);
return ERROR_FAIL;
}
struct reg_cache *cache = NULL, *cache32 = NULL;
cache = arm->core_cache;
struct reg_cache *cache = NULL, *cache32 = NULL;
cache = arm->core_cache;
cache32 = cache->next;
armv8_free_cache(cache32, true);
armv8_free_cache(cache, false);
cache32 = cache->next;
armv8_free_cache(cache32, true);
armv8_free_cache(cache, false);
arm->read_core_reg = armv8_dpm_read_core_reg;
arm->write_core_reg = armv8_dpm_write_core_reg;
arm->read_core_reg = armv8_dpm_read_core_reg;
arm->write_core_reg = armv8_dpm_write_core_reg;
- if (arm->core_cache == NULL) {
+ if (!arm->core_cache) {
cache = armv8_build_reg_cache(target);
if (!cache)
return ERROR_FAIL;
cache = armv8_build_reg_cache(target);
if (!cache)
return ERROR_FAIL;
int busy = 0;
tap = jtag_info->tap;
int busy = 0;
tap = jtag_info->tap;
return ERROR_FAIL;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != (uint32_t)new_instr) {
return ERROR_FAIL;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != (uint32_t)new_instr) {
static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out,
int ir_len, int rti)
{
static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out,
int ir_len, int rti)
{
LOG_ERROR("invalid tap");
return ERROR_FAIL;
}
LOG_ERROR("invalid tap");
return ERROR_FAIL;
}
static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out,
int dr_len, int rti)
{
static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out,
int dr_len, int rti)
{
LOG_ERROR("invalid tap");
return ERROR_FAIL;
}
LOG_ERROR("invalid tap");
return ERROR_FAIL;
}
{
LOG_DEBUG("Delete all breakpoints for target: %s",
target_name(target));
{
LOG_DEBUG("Delete all breakpoints for target: %s",
target_name(target));
- while (target->breakpoints != NULL)
+ while (target->breakpoints)
breakpoint_free(target, target->breakpoints);
}
breakpoint_free(target, target->breakpoints);
}
{
LOG_DEBUG("Delete all watchpoints for target: %s",
target_name(target));
{
LOG_DEBUG("Delete all watchpoints for target: %s",
target_name(target));
- while (target->watchpoints != NULL)
+ while (target->watchpoints)
watchpoint_free(target, target->watchpoints);
}
watchpoint_free(target, target->watchpoints);
}
struct cortex_a_common *cortex_a;
struct adiv5_private_config *pc;
struct cortex_a_common *cortex_a;
struct adiv5_private_config *pc;
- if (target->private_config == NULL)
+ if (!target->private_config)
return ERROR_FAIL;
pc = (struct adiv5_private_config *)target->private_config;
cortex_a = calloc(1, sizeof(struct cortex_a_common));
return ERROR_FAIL;
pc = (struct adiv5_private_config *)target->private_config;
cortex_a = calloc(1, sizeof(struct cortex_a_common));
- if (cortex_a == NULL) {
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
return ERROR_FAIL;
cortex_a = calloc(1, sizeof(struct cortex_a_common));
return ERROR_FAIL;
cortex_a = calloc(1, sizeof(struct cortex_a_common));
- if (cortex_a == NULL) {
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
if (CMD_ARGC > 0) {
n = jim_nvp_name2value_simple(nvp_maskisr_modes, CMD_ARGV[0]);
if (CMD_ARGC > 0) {
n = jim_nvp_name2value_simple(nvp_maskisr_modes, CMD_ARGV[0]);
LOG_ERROR("Unknown parameter: %s - should be off or on", CMD_ARGV[0]);
return ERROR_COMMAND_SYNTAX_ERROR;
}
LOG_ERROR("Unknown parameter: %s - should be off or on", CMD_ARGV[0]);
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (CMD_ARGC > 0) {
n = jim_nvp_name2value_simple(nvp_dacrfixup_modes, CMD_ARGV[0]);
if (CMD_ARGC > 0) {
n = jim_nvp_name2value_simple(nvp_dacrfixup_modes, CMD_ARGV[0]);
return ERROR_COMMAND_SYNTAX_ERROR;
cortex_a->dacrfixup_mode = n->value;
return ERROR_COMMAND_SYNTAX_ERROR;
cortex_a->dacrfixup_mode = n->value;
return ERROR_FAIL;
struct cortex_m_common *cortex_m = calloc(1, sizeof(struct cortex_m_common));
return ERROR_FAIL;
struct cortex_m_common *cortex_m = calloc(1, sizeof(struct cortex_m_common));
- if (cortex_m == NULL) {
LOG_ERROR("No memory creating target");
return ERROR_FAIL;
}
LOG_ERROR("No memory creating target");
return ERROR_FAIL;
}
if (CMD_ARGC > 0) {
n = jim_nvp_name2value_simple(nvp_maskisr_modes, CMD_ARGV[0]);
if (CMD_ARGC > 0) {
n = jim_nvp_name2value_simple(nvp_maskisr_modes, CMD_ARGV[0]);
return ERROR_COMMAND_SYNTAX_ERROR;
cortex_m->isrmasking_mode = n->value;
cortex_m_set_maskints_for_halt(target);
return ERROR_COMMAND_SYNTAX_ERROR;
cortex_m->isrmasking_mode = n->value;
cortex_m_set_maskints_for_halt(target);
*/
int retval = ERROR_OK;
*/
int retval = ERROR_OK;
- if (NULL == target->tap) {
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_INVALID_TAP,
"Invalid tap");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_INVALID_TAP,
"Invalid tap");
err_check(retval, DSP5680XX_ERROR_JTAG_DRSCAN,
"drscan failed!");
}
err_check(retval, DSP5680XX_ERROR_JTAG_DRSCAN,
"drscan failed!");
}
LOG_DEBUG("Data read (%d bits): 0x%04X", len, *d_out);
else
LOG_DEBUG("Data read was discarded.");
LOG_DEBUG("Data read (%d bits): 0x%04X", len, *d_out);
else
LOG_DEBUG("Data read was discarded.");
uint16_t tap_ir_len = DSP5680XX_JTAG_MASTER_TAP_IRLEN;
uint16_t tap_ir_len = DSP5680XX_JTAG_MASTER_TAP_IRLEN;
- if (NULL == target->tap) {
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_INVALID_TAP,
"Invalid tap");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_INVALID_TAP,
"Invalid tap");
} else {
struct jtag_tap *t =
jtag_tap_by_string("dsp568013.chp");
} else {
struct jtag_tap *t =
jtag_tap_by_string("dsp568013.chp");
|| ((t->enabled) && (ir_len != tap_ir_len))) {
retval = ERROR_FAIL;
err_check(retval,
|| ((t->enabled) && (ir_len != tap_ir_len))) {
retval = ERROR_FAIL;
err_check(retval,
dsp5680xx_irscan(target, &instr, &read_from_ir,
DSP5680XX_JTAG_CORE_TAP_IRLEN);
err_check_propagate(retval);
dsp5680xx_irscan(target, &instr, &read_from_ir,
DSP5680XX_JTAG_CORE_TAP_IRLEN);
err_check_propagate(retval);
*status = (uint8_t) read_from_ir;
return ERROR_OK;
}
*status = (uint8_t) read_from_ir;
return ERROR_OK;
}
dsp5680xx_drscan(target, (uint8_t *) &instr,
(uint8_t *) &data_read_dummy, num_bits);
err_check_propagate(retval);
dsp5680xx_drscan(target, (uint8_t *) &instr,
(uint8_t *) &data_read_dummy, num_bits);
err_check_propagate(retval);
*data_read = data_read_dummy;
return retval;
}
*data_read = data_read_dummy;
return retval;
}
retval = jtag_data_write(target, instr_with_flags, 8, &dr_out_tmp);
err_check_propagate(retval);
retval = jtag_data_write(target, instr_with_flags, 8, &dr_out_tmp);
err_check_propagate(retval);
- if (eonce_status != NULL)
*eonce_status = (uint8_t) dr_out_tmp;
return retval;
}
*eonce_status = (uint8_t) dr_out_tmp;
return retval;
}
uint32_t ir_out; /* not used, just to make jtag happy. */
uint32_t ir_out; /* not used, just to make jtag happy. */
- if (master_tap == NULL) {
master_tap = jtag_tap_by_string("dsp568013.chp");
master_tap = jtag_tap_by_string("dsp568013.chp");
- if (master_tap == NULL) {
retval = ERROR_FAIL;
const char *msg = "Failed to get master tap.";
retval = ERROR_FAIL;
const char *msg = "Failed to get master tap.";
- if (core_tap == NULL) {
core_tap = jtag_tap_by_string("dsp568013.cpu");
core_tap = jtag_tap_by_string("dsp568013.cpu");
- if (core_tap == NULL) {
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_CORE,
"Failed to get core tap.");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_CORE,
"Failed to get core tap.");
*/
err_check_propagate(retval);
}
*/
err_check_propagate(retval);
}
- if (eonce_status != NULL)
*eonce_status = data_read_from_dr;
return retval;
}
*eonce_status = data_read_from_dr;
return retval;
}
struct jtag_tap *tap_cpu;
tap_chp = jtag_tap_by_string("dsp568013.chp");
struct jtag_tap *tap_cpu;
tap_chp = jtag_tap_by_string("dsp568013.chp");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_MASTER,
"Failed to get master tap.");
}
tap_cpu = jtag_tap_by_string("dsp568013.cpu");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_MASTER,
"Failed to get master tap.");
}
tap_cpu = jtag_tap_by_string("dsp568013.cpu");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_CORE,
"Failed to get master tap.");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_FIND_CORE,
"Failed to get master tap.");
retval = ERROR_TARGET_FAILURE;
err_check(retval, DSP5680XX_ERROR_ENTER_DEBUG_MODE, msg);
}
retval = ERROR_TARGET_FAILURE;
err_check(retval, DSP5680XX_ERROR_ENTER_DEBUG_MODE, msg);
}
- if (eonce_status != NULL)
*eonce_status = data_read_from_dr;
return retval;
}
*eonce_status = data_read_from_dr;
return retval;
}
int retval;
check_halt_and_debug(target);
int retval;
check_halt_and_debug(target);
- if (protected == NULL) {
const char *msg = "NULL pointer not valid.";
err_check(ERROR_FAIL,
const char *msg = "NULL pointer not valid.";
err_check(ERROR_FAIL,
retval =
dsp5680xx_f_ex(target, HFM_ERASE_VERIFY, tmp, 0, &hfm_ustat, 1);
err_check_propagate(retval);
retval =
dsp5680xx_f_ex(target, HFM_ERASE_VERIFY, tmp, 0, &hfm_ustat, 1);
err_check_propagate(retval);
*erased = (uint8_t) (hfm_ustat & HFM_USTAT_MASK_BLANK);
return retval;
}
*erased = (uint8_t) (hfm_ustat & HFM_USTAT_MASK_BLANK);
return retval;
}
struct jtag_tap *tap_cpu;
tap_chp = jtag_tap_by_string("dsp568013.chp");
struct jtag_tap *tap_cpu;
tap_chp = jtag_tap_by_string("dsp568013.chp");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_ENABLE_MASTER,
"Failed to get master tap.");
}
tap_cpu = jtag_tap_by_string("dsp568013.cpu");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_ENABLE_MASTER,
"Failed to get master tap.");
}
tap_cpu = jtag_tap_by_string("dsp568013.cpu");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_ENABLE_CORE,
"Failed to get master tap.");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_ENABLE_CORE,
"Failed to get master tap.");
jtag_add_sleep(TIME_DIV_FREESCALE * 300 * 1000);
tap_chp = jtag_tap_by_string("dsp568013.chp");
jtag_add_sleep(TIME_DIV_FREESCALE * 300 * 1000);
tap_chp = jtag_tap_by_string("dsp568013.chp");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_ENABLE_MASTER,
"Failed to get master tap.");
}
tap_cpu = jtag_tap_by_string("dsp568013.cpu");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_ENABLE_MASTER,
"Failed to get master tap.");
}
tap_cpu = jtag_tap_by_string("dsp568013.cpu");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_ENABLE_CORE,
"Failed to get master tap.");
retval = ERROR_FAIL;
err_check(retval, DSP5680XX_ERROR_JTAG_TAP_ENABLE_CORE,
"Failed to get master tap.");
- while (breakpoint != NULL) {
if (breakpoint->set == 0)
esirisc_add_breakpoint(target, breakpoint);
if (breakpoint->set == 0)
esirisc_add_breakpoint(target, breakpoint);
- while (watchpoint != NULL) {
if (watchpoint->set == 0)
esirisc_add_watchpoint(target, watchpoint);
if (watchpoint->set == 0)
esirisc_add_watchpoint(target, watchpoint);
if (handle_breakpoints) {
breakpoint = breakpoint_find(target, address);
if (handle_breakpoints) {
breakpoint = breakpoint_find(target, address);
- if (breakpoint != NULL)
esirisc_remove_breakpoint(target, breakpoint);
}
esirisc_remove_breakpoint(target, breakpoint);
}
case EID_INST_BREAKPOINT:
breakpoint = breakpoint_find(target,
buf_get_u32(esirisc->epc->value, 0, esirisc->epc->size));
case EID_INST_BREAKPOINT:
breakpoint = breakpoint_find(target,
buf_get_u32(esirisc->epc->value, 0, esirisc->epc->size));
- target->debug_reason = (breakpoint != NULL) ?
+ target->debug_reason = (breakpoint) ?
DBG_REASON_BREAKPOINT : DBG_REASON_DBGRQ;
break;
DBG_REASON_BREAKPOINT : DBG_REASON_DBGRQ;
break;
struct jtag_tap *tap = target->tap;
struct esirisc_common *esirisc;
struct jtag_tap *tap = target->tap;
struct esirisc_common *esirisc;
return ERROR_FAIL;
if (tap->ir_length != INSTR_LENGTH) {
return ERROR_FAIL;
if (tap->ir_length != INSTR_LENGTH) {
}
esirisc = calloc(1, sizeof(struct esirisc_common));
}
esirisc = calloc(1, sizeof(struct esirisc_common));
return ERROR_FAIL;
esirisc->target = target;
return ERROR_FAIL;
esirisc->target = target;
size = esirisc_trace_buffer_size(trace_info);
buffer = calloc(1, size);
size = esirisc_trace_buffer_size(trace_info);
buffer = calloc(1, size);
command_print(cmd, "out of memory");
return ERROR_FAIL;
}
command_print(cmd, "out of memory");
return ERROR_FAIL;
}
int retval;
buffer = calloc(1, size);
int retval;
buffer = calloc(1, size);
command_print(cmd, "out of memory");
return ERROR_FAIL;
}
command_print(cmd, "out of memory");
return ERROR_FAIL;
}
size = esirisc_trace_buffer_size(trace_info);
buffer = calloc(1, size);
size = esirisc_trace_buffer_size(trace_info);
buffer = calloc(1, size);
command_print(cmd, "out of memory");
return ERROR_FAIL;
}
command_print(cmd, "out of memory");
return ERROR_FAIL;
}
int retval;
buffer = calloc(1, size);
int retval;
buffer = calloc(1, size);
command_print(cmd, "out of memory");
return ERROR_FAIL;
}
command_print(cmd, "out of memory");
return ERROR_FAIL;
}
struct jtag_tap *tap;
tap = etb->tap;
struct jtag_tap *tap;
tap = etb->tap;
return ERROR_FAIL;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
return ERROR_FAIL;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
}
tap = jtag_tap_by_string(CMD_ARGV[1]);
}
tap = jtag_tap_by_string(CMD_ARGV[1]);
command_print(CMD, "ETB: TAP %s does not exist", CMD_ARGV[1]);
return ERROR_FAIL;
}
command_print(CMD, "ETB: TAP %s does not exist", CMD_ARGV[1]);
return ERROR_FAIL;
}
fileio_read_u32(file, &etm_ctx->trace_depth);
}
etm_ctx->trace_data = malloc(sizeof(struct etmv1_trace_data) * etm_ctx->trace_depth);
fileio_read_u32(file, &etm_ctx->trace_depth);
}
etm_ctx->trace_data = malloc(sizeof(struct etmv1_trace_data) * etm_ctx->trace_depth);
- if (etm_ctx->trace_data == NULL) {
+ if (!etm_ctx->trace_data) {
command_print(CMD, "not enough memory to perform operation");
fileio_close(file);
return ERROR_FAIL;
command_print(CMD, "not enough memory to perform operation");
fileio_close(file);
return ERROR_FAIL;
}
struct cortex_m_common *cortex_m = calloc(1, sizeof(struct cortex_m_common));
}
struct cortex_m_common *cortex_m = calloc(1, sizeof(struct cortex_m_common));
- if (cortex_m == NULL) {
LOG_ERROR("No memory creating target");
return ERROR_FAIL;
}
LOG_ERROR("No memory creating target");
return ERROR_FAIL;
}
static int image_ihex_buffer_complete(struct image *image)
{
char *lpsz_line = malloc(1023);
static int image_ihex_buffer_complete(struct image *image)
{
char *lpsz_line = malloc(1023);
- if (lpsz_line == NULL) {
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
struct imagesection *section = malloc(sizeof(struct imagesection) * IMAGE_MAX_SECTIONS);
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
struct imagesection *section = malloc(sizeof(struct imagesection) * IMAGE_MAX_SECTIONS);
free(lpsz_line);
LOG_ERROR("Out of memory");
return ERROR_FAIL;
free(lpsz_line);
LOG_ERROR("Out of memory");
return ERROR_FAIL;
elf->header32 = malloc(sizeof(Elf32_Ehdr));
elf->header32 = malloc(sizeof(Elf32_Ehdr));
- if (elf->header32 == NULL) {
LOG_ERROR("insufficient memory to perform operation");
return ERROR_FILEIO_OPERATION_FAILED;
}
LOG_ERROR("insufficient memory to perform operation");
return ERROR_FILEIO_OPERATION_FAILED;
}
}
elf->segments32 = malloc(elf->segment_count*sizeof(Elf32_Phdr));
}
elf->segments32 = malloc(elf->segment_count*sizeof(Elf32_Phdr));
- if (elf->segments32 == NULL) {
+ if (!elf->segments32) {
LOG_ERROR("insufficient memory to perform operation");
return ERROR_FILEIO_OPERATION_FAILED;
}
LOG_ERROR("insufficient memory to perform operation");
return ERROR_FILEIO_OPERATION_FAILED;
}
/* alloc and fill sections array with loadable segments */
image->sections = malloc(image->num_sections * sizeof(struct imagesection));
/* alloc and fill sections array with loadable segments */
image->sections = malloc(image->num_sections * sizeof(struct imagesection));
- if (image->sections == NULL) {
+ if (!image->sections) {
LOG_ERROR("insufficient memory to perform operation");
return ERROR_FILEIO_OPERATION_FAILED;
}
LOG_ERROR("insufficient memory to perform operation");
return ERROR_FILEIO_OPERATION_FAILED;
}
elf->header64 = malloc(sizeof(Elf64_Ehdr));
elf->header64 = malloc(sizeof(Elf64_Ehdr));
- if (elf->header64 == NULL) {
LOG_ERROR("insufficient memory to perform operation");
return ERROR_FILEIO_OPERATION_FAILED;
}
LOG_ERROR("insufficient memory to perform operation");
return ERROR_FILEIO_OPERATION_FAILED;
}
}
elf->segments64 = malloc(elf->segment_count*sizeof(Elf64_Phdr));
}
elf->segments64 = malloc(elf->segment_count*sizeof(Elf64_Phdr));
- if (elf->segments64 == NULL) {
+ if (!elf->segments64) {
LOG_ERROR("insufficient memory to perform operation");
return ERROR_FILEIO_OPERATION_FAILED;
}
LOG_ERROR("insufficient memory to perform operation");
return ERROR_FILEIO_OPERATION_FAILED;
}
/* alloc and fill sections array with loadable segments */
image->sections = malloc(image->num_sections * sizeof(struct imagesection));
/* alloc and fill sections array with loadable segments */
image->sections = malloc(image->num_sections * sizeof(struct imagesection));
- if (image->sections == NULL) {
+ if (!image->sections) {
LOG_ERROR("insufficient memory to perform operation");
return ERROR_FILEIO_OPERATION_FAILED;
}
LOG_ERROR("insufficient memory to perform operation");
return ERROR_FILEIO_OPERATION_FAILED;
}
static int image_mot_buffer_complete(struct image *image)
{
char *lpsz_line = malloc(1023);
static int image_mot_buffer_complete(struct image *image)
{
char *lpsz_line = malloc(1023);
- if (lpsz_line == NULL) {
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
struct imagesection *section = malloc(sizeof(struct imagesection) * IMAGE_MAX_SECTIONS);
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
struct imagesection *section = malloc(sizeof(struct imagesection) * IMAGE_MAX_SECTIONS);
free(lpsz_line);
LOG_ERROR("Out of memory");
return ERROR_FAIL;
free(lpsz_line);
LOG_ERROR("Out of memory");
return ERROR_FAIL;
} else if (image->type == IMAGE_MEMORY) {
struct target *target = get_target(url);
} else if (image->type == IMAGE_MEMORY) {
struct target *target = get_target(url);
LOG_ERROR("target '%s' not defined", url);
return ERROR_FAIL;
}
LOG_ERROR("target '%s' not defined", url);
return ERROR_FAIL;
}
{
int retval = ERROR_OK;
struct x86_32_common *x86_32 = target_to_x86_32(t);
{
int retval = ERROR_OK;
struct x86_32_common *x86_32 = target_to_x86_32(t);
retval = ERROR_FAIL;
LOG_ERROR("%s invalid target tap", __func__);
return retval;
retval = ERROR_FAIL;
LOG_ERROR("%s invalid target tap", __func__);
return retval;
int retval = ERROR_OK;
uint64_t data = 0;
struct x86_32_common *x86_32 = target_to_x86_32(t);
int retval = ERROR_OK;
uint64_t data = 0;
struct x86_32_common *x86_32 = target_to_x86_32(t);
retval = ERROR_FAIL;
LOG_ERROR("%s invalid target tap", __func__);
return retval;
retval = ERROR_FAIL;
LOG_ERROR("%s invalid target tap", __func__);
return retval;
if (len >= 8) {
for (int n = (len / 8) - 1 ; n >= 0; n--)
data = (data << 8) + *(in+n);
if (len >= 8) {
for (int n = (len / 8) - 1 ; n >= 0; n--)
data = (data << 8) + *(in+n);
*/
struct breakpoint *bp = NULL;
bp = breakpoint_find(t, eip-1);
*/
struct breakpoint *bp = NULL;
bp = breakpoint_find(t, eip-1);
t->debug_reason = DBG_REASON_BREAKPOINT;
if (bp->type == BKPT_SOFT) {
/* The EIP is now pointing the next byte after the
t->debug_reason = DBG_REASON_BREAKPOINT;
if (bp->type == BKPT_SOFT) {
/* The EIP is now pointing the next byte after the
/* prepare resetbreak setting the proper bits in CLTAPC_CPU_VPREQ */
x86_32->curr_tap = jtag_tap_by_position(1);
/* prepare resetbreak setting the proper bits in CLTAPC_CPU_VPREQ */
x86_32->curr_tap = jtag_tap_by_position(1);
- if (x86_32->curr_tap == NULL) {
+ if (!x86_32->curr_tap) {
x86_32->curr_tap = saved_tap;
LOG_ERROR("%s could not select quark_x10xx.cltap", __func__);
return ERROR_FAIL;
x86_32->curr_tap = saved_tap;
LOG_ERROR("%s could not select quark_x10xx.cltap", __func__);
return ERROR_FAIL;
struct adiv5_private_config *pc;
pc = (struct adiv5_private_config *)target->private_config;
struct adiv5_private_config *pc;
pc = (struct adiv5_private_config *)target->private_config;
return ERROR_FAIL;
if (pc->ap_num == DP_APSEL_INVALID) {
return ERROR_FAIL;
if (pc->ap_num == DP_APSEL_INVALID) {
}
mem_ap = calloc(1, sizeof(struct mem_ap));
}
mem_ap = calloc(1, sizeof(struct mem_ap));
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
} scan_32;
} *scan_in = malloc(sizeof(union scan_in) * (ctx->code_count + ctx->store_count));
} scan_32;
} *scan_in = malloc(sizeof(union scan_in) * (ctx->code_count + ctx->store_count));
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
uint32_t *data = NULL;
if (size != 4) {
data = malloc(256 * sizeof(uint32_t));
uint32_t *data = NULL;
if (size != 4) {
data = malloc(256 * sizeof(uint32_t));
LOG_ERROR("Out of memory");
goto exit;
}
LOG_ERROR("Out of memory");
goto exit;
}
return ERROR_JTAG_DEVICE_ERROR;
}
return ERROR_JTAG_DEVICE_ERROR;
}
- if (ctx->local_iparam == NULL) {
+ if (!ctx->local_iparam) {
LOG_ERROR("Error: unexpected reading of input parameter");
return ERROR_JTAG_DEVICE_ERROR;
}
LOG_ERROR("Error: unexpected reading of input parameter");
return ERROR_JTAG_DEVICE_ERROR;
}
&& (address < MIPS64_PRACC_PARAM_OUT + ctx->num_oparam * MIPS64_PRACC_DATA_STEP)) {
offset = (address - MIPS64_PRACC_PARAM_OUT) / MIPS64_PRACC_DATA_STEP;
&& (address < MIPS64_PRACC_PARAM_OUT + ctx->num_oparam * MIPS64_PRACC_DATA_STEP)) {
offset = (address - MIPS64_PRACC_PARAM_OUT) / MIPS64_PRACC_DATA_STEP;
- if (ctx->local_oparam == NULL) {
+ if (!ctx->local_oparam) {
LOG_ERROR("Error: unexpected reading of output parameter");
return ERROR_JTAG_DEVICE_ERROR;
}
LOG_ERROR("Error: unexpected reading of output parameter");
return ERROR_JTAG_DEVICE_ERROR;
}
if ((address >= MIPS64_PRACC_PARAM_IN)
&& (address < MIPS64_PRACC_PARAM_IN + ctx->num_iparam * MIPS64_PRACC_DATA_STEP)) {
offset = (address - MIPS64_PRACC_PARAM_IN) / MIPS64_PRACC_DATA_STEP;
if ((address >= MIPS64_PRACC_PARAM_IN)
&& (address < MIPS64_PRACC_PARAM_IN + ctx->num_iparam * MIPS64_PRACC_DATA_STEP)) {
offset = (address - MIPS64_PRACC_PARAM_IN) / MIPS64_PRACC_DATA_STEP;
- if (ctx->local_iparam == NULL) {
+ if (!ctx->local_iparam) {
LOG_ERROR("Error: unexpected writing of input parameter");
return ERROR_JTAG_DEVICE_ERROR;
}
LOG_ERROR("Error: unexpected writing of input parameter");
return ERROR_JTAG_DEVICE_ERROR;
}
} else if ((address >= MIPS64_PRACC_PARAM_OUT)
&& (address < MIPS64_PRACC_PARAM_OUT + ctx->num_oparam * MIPS64_PRACC_DATA_STEP)) {
offset = (address - MIPS64_PRACC_PARAM_OUT) / MIPS64_PRACC_DATA_STEP;
} else if ((address >= MIPS64_PRACC_PARAM_OUT)
&& (address < MIPS64_PRACC_PARAM_OUT + ctx->num_oparam * MIPS64_PRACC_DATA_STEP)) {
offset = (address - MIPS64_PRACC_PARAM_OUT) / MIPS64_PRACC_DATA_STEP;
- if (ctx->local_oparam == NULL) {
+ if (!ctx->local_oparam) {
LOG_ERROR("Error: unexpected writing of output parameter");
return ERROR_JTAG_DEVICE_ERROR;
}
LOG_ERROR("Error: unexpected writing of output parameter");
return ERROR_JTAG_DEVICE_ERROR;
}
void mips_ejtag_set_instr(struct mips_ejtag *ejtag_info, uint32_t new_instr)
{
void mips_ejtag_set_instr(struct mips_ejtag *ejtag_info, uint32_t new_instr)
{
- assert(ejtag_info->tap != NULL);
+ assert(ejtag_info->tap);
struct jtag_tap *tap = ejtag_info->tap;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
struct jtag_tap *tap = ejtag_info->tap;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
void mips_ejtag_add_scan_96(struct mips_ejtag *ejtag_info, uint32_t ctrl, uint32_t data, uint8_t *in_scan_buf)
{
void mips_ejtag_add_scan_96(struct mips_ejtag *ejtag_info, uint32_t ctrl, uint32_t data, uint8_t *in_scan_buf)
{
- assert(ejtag_info->tap != NULL);
+ assert(ejtag_info->tap);
struct jtag_tap *tap = ejtag_info->tap;
struct scan_field field;
struct jtag_tap *tap = ejtag_info->tap;
struct scan_field field;
struct jtag_tap *tap;
tap = ejtag_info->tap;
struct jtag_tap *tap;
tap = ejtag_info->tap;
return ERROR_FAIL;
struct scan_field field;
uint8_t t[8] = { 0 }, r[8];
return ERROR_FAIL;
struct scan_field field;
uint8_t t[8] = { 0 }, r[8];
static void mips_ejtag_drscan_32_queued(struct mips_ejtag *ejtag_info,
uint32_t data_out, uint8_t *data_in)
{
static void mips_ejtag_drscan_32_queued(struct mips_ejtag *ejtag_info,
uint32_t data_out, uint8_t *data_in)
{
- assert(ejtag_info->tap != NULL);
+ assert(ejtag_info->tap);
struct jtag_tap *tap = ejtag_info->tap;
struct scan_field field;
struct jtag_tap *tap = ejtag_info->tap;
struct scan_field field;
int mips_ejtag_drscan_8(struct mips_ejtag *ejtag_info, uint8_t *data)
{
int mips_ejtag_drscan_8(struct mips_ejtag *ejtag_info, uint8_t *data)
{
- assert(ejtag_info->tap != NULL);
+ assert(ejtag_info->tap);
struct jtag_tap *tap = ejtag_info->tap;
struct scan_field field;
struct jtag_tap *tap = ejtag_info->tap;
struct scan_field field;
void mips_ejtag_drscan_8_out(struct mips_ejtag *ejtag_info, uint8_t data)
{
void mips_ejtag_drscan_8_out(struct mips_ejtag *ejtag_info, uint8_t data)
{
- assert(ejtag_info->tap != NULL);
+ assert(ejtag_info->tap);
struct jtag_tap *tap = ejtag_info->tap;
struct scan_field field;
struct jtag_tap *tap = ejtag_info->tap;
struct scan_field field;
int mips_ejtag_fastdata_scan(struct mips_ejtag *ejtag_info, int write_t, uint32_t *data)
{
int mips_ejtag_fastdata_scan(struct mips_ejtag *ejtag_info, int write_t, uint32_t *data)
{
- assert(ejtag_info->tap != NULL);
+ assert(ejtag_info->tap);
struct jtag_tap *tap = ejtag_info->tap;
struct scan_field fields[2];
struct jtag_tap *tap = ejtag_info->tap;
struct scan_field fields[2];
struct jtag_tap *tap;
tap = ejtag_info->tap;
struct jtag_tap *tap;
tap = ejtag_info->tap;
struct scan_field fields[2];
uint8_t spracc = 0;
struct scan_field fields[2];
uint8_t spracc = 0;
if (size > 1) {
t = malloc(count * size * sizeof(uint8_t));
if (size > 1) {
t = malloc(count * size * sizeof(uint8_t));
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
/* mips32_..._write_mem with size 4/2 requires uint32_t/uint16_t in host */
/* endianness, but byte array represents target endianness */
t = malloc(count * size * sizeof(uint8_t));
/* mips32_..._write_mem with size 4/2 requires uint32_t/uint16_t in host */
/* endianness, but byte array represents target endianness */
t = malloc(count * size * sizeof(uint8_t));
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
if (address & 0x3u)
return ERROR_TARGET_UNALIGNED_ACCESS;
if (address & 0x3u)
return ERROR_TARGET_UNALIGNED_ACCESS;
- if (mips32->fast_data_area == NULL) {
+ if (!mips32->fast_data_area) {
/* Get memory for block write handler
* we preserve this area between calls and gain a speed increase
* of about 3kb/sec when writing flash
/* Get memory for block write handler
* we preserve this area between calls and gain a speed increase
* of about 3kb/sec when writing flash
/* but byte array represents target endianness */
uint32_t *t = NULL;
t = malloc(count * sizeof(uint32_t));
/* but byte array represents target endianness */
uint32_t *t = NULL;
t = malloc(count * sizeof(uint32_t));
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_DEBUG("nds32_login");
LOG_DEBUG("nds32_login");
- if (nds32->edm_passcode != NULL) {
+ if (nds32->edm_passcode) {
/* convert EDM passcode to command sequences */
passcode_length = strlen(nds32->edm_passcode);
command_sequence[0] = '\0';
/* convert EDM passcode to command sequences */
passcode_length = strlen(nds32->edm_passcode);
command_sequence[0] = '\0';
int nds32_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info)
{
/* fill syscall parameters to file-I/O info */
int nds32_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info)
{
/* fill syscall parameters to file-I/O info */
- if (NULL == fileio_info) {
LOG_ERROR("Target has not initial file-I/O data structure");
return ERROR_FAIL;
}
LOG_ERROR("Target has not initial file-I/O data structure");
return ERROR_FAIL;
}
/** Convert target handle to generic Andes target state handle. */
static inline struct nds32 *target_to_nds32(struct target *target)
{
/** Convert target handle to generic Andes target state handle. */
static inline struct nds32 *target_to_nds32(struct target *target)
{
- assert(target != NULL);
return target->arch_info;
}
/** */
static inline struct aice_port_s *target_to_aice(struct target *target)
{
return target->arch_info;
}
/** */
static inline struct aice_port_s *target_to_aice(struct target *target)
{
- assert(target != NULL);
return target->tap->priv;
}
static inline bool is_nds32(struct nds32 *nds32)
{
return target->tap->priv;
}
static inline bool is_nds32(struct nds32 *nds32)
{
return nds32->common_magic == NDS32_COMMON_MAGIC;
}
static inline bool nds32_reach_max_interrupt_level(struct nds32 *nds32)
{
return nds32->common_magic == NDS32_COMMON_MAGIC;
}
static inline bool nds32_reach_max_interrupt_level(struct nds32 *nds32)
{
return nds32->max_interrupt_level == nds32->current_interrupt_level;
}
return nds32->max_interrupt_level == nds32->current_interrupt_level;
}
return e;
uint32_t *data = malloc(count * sizeof(uint32_t));
return e;
uint32_t *data = malloc(count * sizeof(uint32_t));
return JIM_ERR;
jim_wide i;
return JIM_ERR;
jim_wide i;
struct or1k_du *du_core = or1k_to_du(or1k);
struct or1k_jtag *jtag = &or1k->jtag;
struct or1k_du *du_core = or1k_to_du(or1k);
struct or1k_jtag *jtag = &or1k->jtag;
LOG_ERROR("No debug unit selected");
return ERROR_FAIL;
}
LOG_ERROR("No debug unit selected");
return ERROR_FAIL;
}
- if (jtag->tap_ip == NULL) {
LOG_ERROR("No tap selected");
return ERROR_FAIL;
}
LOG_ERROR("No tap selected");
return ERROR_FAIL;
}
static int or1k_target_create(struct target *target, Jim_Interp *interp)
{
static int or1k_target_create(struct target *target, Jim_Interp *interp)
{
- if (target->tap == NULL)
return ERROR_FAIL;
struct or1k_common *or1k = calloc(1, sizeof(struct or1k_common));
return ERROR_FAIL;
struct or1k_common *or1k = calloc(1, sizeof(struct or1k_common));
struct target *target = jtag_info->target;
if ((target->endianness == TARGET_BIG_ENDIAN) && (size != 1)) {
t = malloc(count * size * sizeof(uint8_t));
struct target *target = jtag_info->target;
if ((target->endianness == TARGET_BIG_ENDIAN) && (size != 1)) {
t = malloc(count * size * sizeof(uint8_t));
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
static int quark_d20xx_target_create(struct target *t, Jim_Interp *interp)
{
struct x86_32_common *x86_32 = calloc(1, sizeof(struct x86_32_common));
static int quark_d20xx_target_create(struct target *t, Jim_Interp *interp)
{
struct x86_32_common *x86_32 = calloc(1, sizeof(struct x86_32_common));
LOG_ERROR("%s out of memory", __func__);
return ERROR_FAIL;
}
LOG_ERROR("%s out of memory", __func__);
return ERROR_FAIL;
}
if (debug_level < LOG_LVL_DEBUG)
return;
if (debug_level < LOG_LVL_DEBUG)
return;
- assert(field->out_value != NULL);
+ assert(field->out_value);
uint64_t out = buf_get_u64(field->out_value, 0, field->num_bits);
unsigned int out_op = get_field(out, DTM_DMI_OP);
unsigned int out_data = get_field(out, DTM_DMI_DATA);
uint64_t out = buf_get_u64(field->out_value, 0, field->num_bits);
unsigned int out_op = get_field(out, DTM_DMI_OP);
unsigned int out_data = get_field(out, DTM_DMI_DATA);
{
RISCV_INFO(r);
LOG_DEBUG("handle_breakpoints=%d", handle_breakpoints);
{
RISCV_INFO(r);
LOG_DEBUG("handle_breakpoints=%d", handle_breakpoints);
- if (r->is_halted == NULL)
return oldriscv_step(target, current, address, handle_breakpoints);
else
return riscv_openocd_step(target, current, address, handle_breakpoints);
return oldriscv_step(target, current, address, handle_breakpoints);
else
return riscv_openocd_step(target, current, address, handle_breakpoints);
LOG_DEBUG(" version=0x%x", info->dtm_version);
struct target_type *tt = get_target_type(target);
LOG_DEBUG(" version=0x%x", info->dtm_version);
struct target_type *tt = get_target_type(target);
return ERROR_FAIL;
int result = tt->init_target(info->cmd_ctx, target);
return ERROR_FAIL;
int result = tt->init_target(info->cmd_ctx, target);
static int old_or_new_riscv_poll(struct target *target)
{
RISCV_INFO(r);
static int old_or_new_riscv_poll(struct target *target)
{
RISCV_INFO(r);
- if (r->is_halted == NULL)
return oldriscv_poll(target);
else
return riscv_openocd_poll(target);
return oldriscv_poll(target);
else
return riscv_openocd_poll(target);
{
riscv_info_t *r = riscv_info(target);
int result;
{
riscv_info_t *r = riscv_info(target);
int result;
- if (r->is_halted == NULL) {
struct target_type *tt = get_target_type(target);
result = tt->halt(target);
} else {
struct target_type *tt = get_target_type(target);
result = tt->halt(target);
} else {
- if (r->is_halted == NULL) {
struct target_type *tt = get_target_type(target);
return tt->halt(target);
}
struct target_type *tt = get_target_type(target);
return tt->halt(target);
}
{
riscv_info_t *r = riscv_info(target);
int result;
{
riscv_info_t *r = riscv_info(target);
int result;
- if (r->is_halted == NULL) {
struct target_type *tt = get_target_type(target);
result = tt->resume(target, current, address, handle_breakpoints,
debug_execution);
struct target_type *tt = get_target_type(target);
result = tt->resume(target, current, address, handle_breakpoints,
debug_execution);
int riscv_count_harts(struct target *target)
{
int riscv_count_harts(struct target *target)
{
return 1;
RISCV_INFO(r);
if (r == NULL || r->hart_count == NULL)
return 1;
RISCV_INFO(r);
if (r == NULL || r->hart_count == NULL)
LOG_DEBUG(" ");
target->fileio_info = malloc(sizeof(*target->fileio_info));
LOG_DEBUG(" ");
target->fileio_info = malloc(sizeof(*target->fileio_info));
- if (target->fileio_info == NULL) {
+ if (!target->fileio_info) {
LOG_ERROR("out of memory");
return ERROR_FAIL;
}
LOG_ERROR("out of memory");
return ERROR_FAIL;
}
struct semihosting *semihosting;
semihosting = malloc(sizeof(*target->semihosting));
struct semihosting *semihosting;
semihosting = malloc(sizeof(*target->semihosting));
- if (semihosting == NULL) {
LOG_ERROR("out of memory");
return ERROR_FAIL;
}
LOG_ERROR("out of memory");
return ERROR_FAIL;
}
{
struct target *target = get_current_target(CMD_CTX);
{
struct target *target = get_current_target(CMD_CTX);
LOG_ERROR("No target selected");
return ERROR_FAIL;
}
LOG_ERROR("No target selected");
return ERROR_FAIL;
}
{
struct target *target = get_current_target(CMD_CTX);
{
struct target *target = get_current_target(CMD_CTX);
LOG_ERROR("No target selected");
return ERROR_FAIL;
}
LOG_ERROR("No target selected");
return ERROR_FAIL;
}
struct target *target = get_current_target(CMD_CTX);
unsigned int i;
struct target *target = get_current_target(CMD_CTX);
unsigned int i;
LOG_ERROR("No target selected");
return ERROR_FAIL;
}
LOG_ERROR("No target selected");
return ERROR_FAIL;
}
for (i = 1; i < CMD_ARGC; i++) {
char *cmdline = alloc_printf("%s %s", semihosting->cmdline, CMD_ARGV[i]);
for (i = 1; i < CMD_ARGC; i++) {
char *cmdline = alloc_printf("%s %s", semihosting->cmdline, CMD_ARGV[i]);
break;
free(semihosting->cmdline);
semihosting->cmdline = cmdline;
break;
free(semihosting->cmdline);
semihosting->cmdline = cmdline;
{
struct target *target = get_current_target(CMD_CTX);
{
struct target *target = get_current_target(CMD_CTX);
LOG_ERROR("No target selected");
return ERROR_FAIL;
}
LOG_ERROR("No target selected");
return ERROR_FAIL;
}
#include "server/server.h"
#define foreach_smp_target(pos, head) \
#include "server/server.h"
#define foreach_smp_target(pos, head) \
- for (pos = head; (pos != NULL); pos = pos->next)
+ for (pos = head; (pos); pos = pos->next)
extern const struct command_registration smp_command_handlers[];
extern const struct command_registration smp_command_handlers[];
const struct jim_nvp *n;
n = jim_nvp_value2name_simple(nvp_error_target, err);
const struct jim_nvp *n;
n = jim_nvp_value2name_simple(nvp_error_target, err);
return "unknown";
else
return n->name;
return "unknown";
else
return n->name;
{
struct target *target = get_current_target_or_null(cmd_ctx);
{
struct target *target = get_current_target_or_null(cmd_ctx);
LOG_ERROR("BUG: current_target out of bounds");
exit(-1);
}
LOG_ERROR("BUG: current_target out of bounds");
exit(-1);
}
int retval;
struct jim_nvp *n;
n = jim_nvp_value2name_simple(nvp_reset_modes, reset_mode);
int retval;
struct jim_nvp *n;
n = jim_nvp_value2name_simple(nvp_reset_modes, reset_mode);
LOG_ERROR("invalid reset mode");
return ERROR_FAIL;
}
LOG_ERROR("invalid reset mode");
return ERROR_FAIL;
}
target_reset_examined(target);
struct target_type *type = target->type;
target_reset_examined(target);
struct target_type *type = target->type;
- if (type->examine == NULL)
type->examine = default_examine;
type->examine = default_examine;
- if (type->check_reset == NULL)
+ if (!type->check_reset)
type->check_reset = default_check_reset;
type->check_reset = default_check_reset;
- assert(type->init_target != NULL);
+ assert(type->init_target);
int retval = type->init_target(cmd_ctx, target);
if (retval != ERROR_OK) {
int retval = type->init_target(cmd_ctx, target);
if (retval != ERROR_OK) {
* implement it in stages, but warn if we need to do so.
*/
if (type->mmu) {
* implement it in stages, but warn if we need to do so.
*/
if (type->mmu) {
- if (type->virt2phys == NULL) {
+ if (!type->virt2phys) {
LOG_ERROR("type '%s' is missing virt2phys", type->name);
type->virt2phys = identity_virt2phys;
}
LOG_ERROR("type '%s' is missing virt2phys", type->name);
type->virt2phys = identity_virt2phys;
}
{
struct target_event_callback **callbacks_p = &target_event_callbacks;
{
struct target_event_callback **callbacks_p = &target_event_callbacks;
return ERROR_COMMAND_SYNTAX_ERROR;
if (*callbacks_p) {
return ERROR_COMMAND_SYNTAX_ERROR;
if (*callbacks_p) {
{
struct target_reset_callback *entry;
{
struct target_reset_callback *entry;
return ERROR_COMMAND_SYNTAX_ERROR;
entry = malloc(sizeof(struct target_reset_callback));
return ERROR_COMMAND_SYNTAX_ERROR;
entry = malloc(sizeof(struct target_reset_callback));
LOG_ERROR("error allocating buffer for reset callback entry");
return ERROR_COMMAND_SYNTAX_ERROR;
}
LOG_ERROR("error allocating buffer for reset callback entry");
return ERROR_COMMAND_SYNTAX_ERROR;
}
{
struct target_trace_callback *entry;
{
struct target_trace_callback *entry;
return ERROR_COMMAND_SYNTAX_ERROR;
entry = malloc(sizeof(struct target_trace_callback));
return ERROR_COMMAND_SYNTAX_ERROR;
entry = malloc(sizeof(struct target_trace_callback));
LOG_ERROR("error allocating buffer for trace callback entry");
return ERROR_COMMAND_SYNTAX_ERROR;
}
LOG_ERROR("error allocating buffer for trace callback entry");
return ERROR_COMMAND_SYNTAX_ERROR;
}
{
struct target_timer_callback **callbacks_p = &target_timer_callbacks;
{
struct target_timer_callback **callbacks_p = &target_timer_callbacks;
return ERROR_COMMAND_SYNTAX_ERROR;
if (*callbacks_p) {
return ERROR_COMMAND_SYNTAX_ERROR;
if (*callbacks_p) {
struct target_event_callback **p = &target_event_callbacks;
struct target_event_callback *c = target_event_callbacks;
struct target_event_callback **p = &target_event_callbacks;
struct target_event_callback *c = target_event_callbacks;
return ERROR_COMMAND_SYNTAX_ERROR;
while (c) {
return ERROR_COMMAND_SYNTAX_ERROR;
while (c) {
{
struct target_reset_callback *entry;
{
struct target_reset_callback *entry;
return ERROR_COMMAND_SYNTAX_ERROR;
list_for_each_entry(entry, &target_reset_callback_list, list) {
return ERROR_COMMAND_SYNTAX_ERROR;
list_for_each_entry(entry, &target_reset_callback_list, list) {
{
struct target_trace_callback *entry;
{
struct target_trace_callback *entry;
return ERROR_COMMAND_SYNTAX_ERROR;
list_for_each_entry(entry, &target_trace_callback_list, list) {
return ERROR_COMMAND_SYNTAX_ERROR;
list_for_each_entry(entry, &target_trace_callback_list, list) {
int target_unregister_timer_callback(int (*callback)(void *priv), void *priv)
{
int target_unregister_timer_callback(int (*callback)(void *priv), void *priv)
{
return ERROR_COMMAND_SYNTAX_ERROR;
for (struct target_timer_callback *c = target_timer_callbacks;
return ERROR_COMMAND_SYNTAX_ERROR;
for (struct target_timer_callback *c = target_timer_callbacks;
if (size < area->size) {
struct working_area *new_wa = malloc(sizeof(*new_wa));
if (size < area->size) {
struct working_area *new_wa = malloc(sizeof(*new_wa));
return;
new_wa->next = area->next;
return;
new_wa->next = area->next;
int target_alloc_working_area_try(struct target *target, uint32_t size, struct working_area **area)
{
/* Reevaluate working area address based on MMU state*/
int target_alloc_working_area_try(struct target *target, uint32_t size, struct working_area **area)
{
/* Reevaluate working area address based on MMU state*/
- if (target->working_areas == NULL) {
+ if (!target->working_areas) {
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
/* Split the working area into the requested size */
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
/* Split the working area into the requested size */
size, c->address);
if (target->backup_working_area) {
size, c->address);
if (target->backup_working_area) {
- if (c->backup == NULL) {
c->backup = malloc(c->size);
c->backup = malloc(c->size);
struct working_area *c = target->working_areas;
uint32_t max_size = 0;
struct working_area *c = target->working_areas;
uint32_t max_size = 0;
return target->working_area_size;
while (c) {
return target->working_area_size;
while (c) {
/* release the targets SMP list */
if (target->smp) {
struct target_list *head = target->head;
/* release the targets SMP list */
if (target->smp) {
struct target_list *head = target->head;
struct target_list *pos = head->next;
head->target->smp = 0;
free(head);
struct target_list *pos = head->next;
head->target->smp = 0;
free(head);
int target_arch_state(struct target *target)
{
int retval;
int target_arch_state(struct target *target)
{
int retval;
LOG_WARNING("No target has been configured");
return ERROR_OK;
}
LOG_WARNING("No target has been configured");
return ERROR_OK;
}
retval = target->type->checksum_memory(target, address, size, &checksum);
if (retval != ERROR_OK) {
buffer = malloc(size);
retval = target->type->checksum_memory(target, address, size, &checksum);
if (retval != ERROR_OK) {
buffer = malloc(size);
LOG_ERROR("error allocating buffer for section (%" PRIu32 " bytes)", size);
return ERROR_COMMAND_SYNTAX_ERROR;
}
LOG_ERROR("error allocating buffer for section (%" PRIu32 " bytes)", size);
return ERROR_COMMAND_SYNTAX_ERROR;
}
static int find_target(struct command_invocation *cmd, const char *name)
{
struct target *target = get_target(name);
static int find_target(struct command_invocation *cmd, const char *name)
{
struct target *target = get_target(name);
command_print(cmd, "Target: %s is unknown, try one of:\n", name);
return ERROR_FAIL;
}
command_print(cmd, "Target: %s is unknown, try one of:\n", name);
return ERROR_FAIL;
}
- assert(reg != NULL); /* give clang a hint that we *know* reg is != NULL here */
+ assert(reg); /* give clang a hint that we *know* reg is != NULL here */
if (!reg->exist)
goto not_found;
if (!reg->exist)
goto not_found;
/* set register value */
if (CMD_ARGC == 2) {
uint8_t *buf = malloc(DIV_ROUND_UP(reg->size, 8));
/* set register value */
if (CMD_ARGC == 2) {
uint8_t *buf = malloc(DIV_ROUND_UP(reg->size, 8));
return ERROR_FAIL;
str_to_buf(CMD_ARGV[1], strlen(CMD_ARGV[1]), buf, reg->size, 0);
return ERROR_FAIL;
str_to_buf(CMD_ARGV[1], strlen(CMD_ARGV[1]), buf, reg->size, 0);
if (CMD_ARGC == 1) {
const struct jim_nvp *n;
n = jim_nvp_name2value_simple(nvp_reset_modes, CMD_ARGV[0]);
if (CMD_ARGC == 1) {
const struct jim_nvp *n;
n = jim_nvp_name2value_simple(nvp_reset_modes, CMD_ARGV[0]);
- if ((n->name == NULL) || (n->value == RESET_UNKNOWN))
+ if ((!n->name) || (n->value == RESET_UNKNOWN))
return ERROR_COMMAND_SYNTAX_ERROR;
reset_mode = n->value;
}
return ERROR_COMMAND_SYNTAX_ERROR;
reset_mode = n->value;
}
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], count);
uint8_t *buffer = calloc(count, size);
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], count);
uint8_t *buffer = calloc(count, size);
LOG_ERROR("Failed to allocate md read buffer");
return ERROR_FAIL;
}
LOG_ERROR("Failed to allocate md read buffer");
return ERROR_FAIL;
}
* to fill large memory areas with any sane speed */
const unsigned chunk_size = 16384;
uint8_t *target_buf = malloc(chunk_size * data_size);
* to fill large memory areas with any sane speed */
const unsigned chunk_size = 16384;
uint8_t *target_buf = malloc(chunk_size * data_size);
- if (target_buf == NULL) {
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
LOG_ERROR("Out of memory");
return ERROR_FAIL;
}
retval = ERROR_OK;
for (unsigned int i = 0; i < image.num_sections; i++) {
buffer = malloc(image.sections[i].size);
retval = ERROR_OK;
for (unsigned int i = 0; i < image.num_sections; i++) {
buffer = malloc(image.sections[i].size);
command_print(CMD,
"error allocating buffer for section (%d bytes)",
(int)(image.sections[i].size));
command_print(CMD,
"error allocating buffer for section (%d bytes)",
(int)(image.sections[i].size));
retval = ERROR_OK;
for (unsigned int i = 0; i < image.num_sections; i++) {
buffer = malloc(image.sections[i].size);
retval = ERROR_OK;
for (unsigned int i = 0; i < image.num_sections; i++) {
buffer = malloc(image.sections[i].size);
command_print(CMD,
"error allocating buffer for section (%" PRIu32 " bytes)",
image.sections[i].size);
command_print(CMD,
"error allocating buffer for section (%" PRIu32 " bytes)",
image.sections[i].size);
{
uint32_t i;
FILE *f = fopen(filename, "w");
{
uint32_t i;
FILE *f = fopen(filename, "w");
return;
write_string(f, "gmon");
write_long(f, 0x00000001, target); /* Version */
return;
write_string(f, "gmon");
write_long(f, 0x00000001, target); /* Version */
if (num_buckets > max_buckets)
num_buckets = max_buckets;
int *buckets = malloc(sizeof(int) * num_buckets);
if (num_buckets > max_buckets)
num_buckets = max_buckets;
int *buckets = malloc(sizeof(int) * num_buckets);
/*append binary memory gmon.out profile_hist_data (profile_hist_data + profile_hist_hdr.hist_size) */
char *data = malloc(2 * num_buckets);
/*append binary memory gmon.out profile_hist_data (profile_hist_data + profile_hist_hdr.hist_size) */
char *data = malloc(2 * num_buckets);
for (i = 0; i < num_buckets; i++) {
int val;
val = buckets[i];
for (i = 0; i < num_buckets; i++) {
int val;
val = buckets[i];
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], offset);
uint32_t *samples = malloc(sizeof(uint32_t) * MAX_PROFILE_SAMPLE_NUM);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], offset);
uint32_t *samples = malloc(sizeof(uint32_t) * MAX_PROFILE_SAMPLE_NUM);
LOG_ERROR("No memory to store samples.");
return ERROR_FAIL;
}
LOG_ERROR("No memory to store samples.");
return ERROR_FAIL;
}
struct target *target;
context = current_command_context(interp);
struct target *target;
context = current_command_context(interp);
- assert(context != NULL);
target = get_current_target(context);
target = get_current_target(context);
LOG_ERROR("mem2array: no current target");
return JIM_ERR;
}
LOG_ERROR("mem2array: no current target");
return JIM_ERR;
}
const size_t buffersize = 4096;
uint8_t *buffer = malloc(buffersize);
const size_t buffersize = 4096;
uint8_t *buffer = malloc(buffersize);
return JIM_ERR;
/* assume ok */
return JIM_ERR;
/* assume ok */
Jim_Obj *obj_val = Jim_GetVariable(interp, obj_name, JIM_ERRMSG);
Jim_DecrRefCount(interp, obj_name);
free(namebuf);
Jim_Obj *obj_val = Jim_GetVariable(interp, obj_name, JIM_ERRMSG);
Jim_DecrRefCount(interp, obj_name);
free(namebuf);
return JIM_ERR;
jim_wide wide_val;
return JIM_ERR;
jim_wide wide_val;
struct target *target;
context = current_command_context(interp);
struct target *target;
context = current_command_context(interp);
- assert(context != NULL);
target = get_current_target(context);
target = get_current_target(context);
LOG_ERROR("array2mem: no current target");
return JIM_ERR;
}
LOG_ERROR("array2mem: no current target");
return JIM_ERR;
}
const size_t buffersize = 4096;
uint8_t *buffer = malloc(buffersize);
const size_t buffersize = 4096;
uint8_t *buffer = malloc(buffersize);
return JIM_ERR;
/* index counter */
return JIM_ERR;
/* index counter */
/* END_DEPRECATED_TPIU */
bool replace = true;
/* END_DEPRECATED_TPIU */
bool replace = true;
/* create new */
teap = calloc(1, sizeof(*teap));
replace = false;
/* create new */
teap = calloc(1, sizeof(*teap));
replace = false;
Jim_SetEmptyResult(goi->interp);
} else {
/* get */
Jim_SetEmptyResult(goi->interp);
} else {
/* get */
Jim_SetEmptyResult(goi->interp);
else
Jim_SetResult(goi->interp, Jim_DuplicateObj(goi->interp, teap->body));
Jim_SetEmptyResult(goi->interp);
else
Jim_SetResult(goi->interp, Jim_DuplicateObj(goi->interp, teap->body));
goto no_params;
}
n = jim_nvp_value2name_simple(nvp_target_endian, target->endianness);
goto no_params;
}
n = jim_nvp_value2name_simple(nvp_target_endian, target->endianness);
target->endianness = TARGET_LITTLE_ENDIAN;
n = jim_nvp_value2name_simple(nvp_target_endian, target->endianness);
}
target->endianness = TARGET_LITTLE_ENDIAN;
n = jim_nvp_value2name_simple(nvp_target_endian, target->endianness);
}
if (e != JIM_OK)
return e;
tap = jtag_tap_by_jim_obj(goi->interp, o_t);
if (e != JIM_OK)
return e;
tap = jtag_tap_by_jim_obj(goi->interp, o_t);
return JIM_ERR;
target->tap = tap;
target->tap_configured = true;
return JIM_ERR;
target->tap = tap;
target->tap_configured = true;
struct command_context *cmd_ctx;
cmd_ctx = current_command_context(goi->interp);
struct command_context *cmd_ctx;
cmd_ctx = current_command_context(goi->interp);
- assert(cmd_ctx != NULL);
if (goi->argc < 3) {
Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ?type? ..options...");
if (goi->argc < 3) {
Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ?type? ..options...");
}
}
/* tap must be set after target was configured */
}
}
/* tap must be set after target was configured */
- if (target->tap == NULL)
return JIM_ERR;
}
struct command_context *cmd_ctx = current_command_context(interp);
return JIM_ERR;
}
struct command_context *cmd_ctx = current_command_context(interp);
- assert(cmd_ctx != NULL);
struct target *target = get_current_target_or_null(cmd_ctx);
if (target)
struct target *target = get_current_target_or_null(cmd_ctx);
if (target)
static void free_fastload(void)
{
static void free_fastload(void)
{
- if (fastload != NULL) {
for (int i = 0; i < fastload_num; i++)
free(fastload[i].data);
free(fastload);
for (int i = 0; i < fastload_num; i++)
free(fastload[i].data);
free(fastload);
retval = ERROR_OK;
fastload_num = image.num_sections;
fastload = malloc(sizeof(struct fast_load)*image.num_sections);
retval = ERROR_OK;
fastload_num = image.num_sections;
fastload = malloc(sizeof(struct fast_load)*image.num_sections);
- if (fastload == NULL) {
command_print(CMD, "out of memory");
image_close(&image);
return ERROR_FAIL;
command_print(CMD, "out of memory");
image_close(&image);
return ERROR_FAIL;
memset(fastload, 0, sizeof(struct fast_load)*image.num_sections);
for (unsigned int i = 0; i < image.num_sections; i++) {
buffer = malloc(image.sections[i].size);
memset(fastload, 0, sizeof(struct fast_load)*image.num_sections);
for (unsigned int i = 0; i < image.num_sections; i++) {
buffer = malloc(image.sections[i].size);
command_print(CMD, "error allocating buffer for section (%d bytes)",
(int)(image.sections[i].size));
retval = ERROR_FAIL;
command_print(CMD, "error allocating buffer for section (%d bytes)",
(int)(image.sections[i].size));
retval = ERROR_FAIL;
{
if (CMD_ARGC > 0)
return ERROR_COMMAND_SYNTAX_ERROR;
{
if (CMD_ARGC > 0)
return ERROR_COMMAND_SYNTAX_ERROR;
- if (fastload == NULL) {
LOG_ERROR("No image in memory");
return ERROR_FAIL;
}
LOG_ERROR("No image in memory");
return ERROR_FAIL;
}
static void binprint(struct command_invocation *cmd, const char *text, const uint8_t *buf, int size)
{
static void binprint(struct command_invocation *cmd, const char *text, const uint8_t *buf, int size)
{
command_print_sameline(cmd, "%s", text);
for (int i = 0; i < size; i++)
command_print_sameline(cmd, " %02x", buf[i]);
command_print_sameline(cmd, "%s", text);
for (int i = 0; i < size; i++)
command_print_sameline(cmd, " %02x", buf[i]);
target_free_working_area(target, wa);
/* Test writes */
target_free_working_area(target, wa);
/* Test writes */
target_free_working_area(target, wa);
return retval;
}
target_free_working_area(target, wa);
return retval;
}
{
struct debug_msg_receiver **p = &target->dbgmsg;
{
struct debug_msg_receiver **p = &target->dbgmsg;
return ERROR_COMMAND_SYNTAX_ERROR;
/* see if there's already a list */
return ERROR_COMMAND_SYNTAX_ERROR;
/* see if there's already a list */
int do_all_targets = 0;
/* if no target has been specified search all of them */
int do_all_targets = 0;
/* if no target has been specified search all of them */
/* if no targets haven been specified */
/* if no targets haven been specified */
- if (all_targets == NULL)
return NULL;
target = all_targets;
return NULL;
target = all_targets;
int do_all_targets = 0;
/* if no target has been specified search all of them */
int do_all_targets = 0;
/* if no target has been specified search all of them */
/* if no targets haven been specified */
/* if no targets haven been specified */
- if (all_targets == NULL)
return ERROR_OK;
target = all_targets;
return ERROR_OK;
target = all_targets;
x86_32->num_hw_bpoints = MAX_DEBUG_REGS;
x86_32->hw_break_list = calloc(x86_32->num_hw_bpoints,
sizeof(struct x86_32_dbg_reg));
x86_32->num_hw_bpoints = MAX_DEBUG_REGS;
x86_32->hw_break_list = calloc(x86_32->num_hw_bpoints,
sizeof(struct x86_32_dbg_reg));
- if (x86_32->hw_break_list == NULL) {
+ if (!x86_32->hw_break_list) {
LOG_ERROR("%s out of memory", __func__);
return ERROR_FAIL;
}
LOG_ERROR("%s out of memory", __func__);
return ERROR_FAIL;
}
* with the original instructions again.
*/
struct swbp_mem_patch *iter = x86_32->swbbp_mem_patch_list;
* with the original instructions again.
*/
struct swbp_mem_patch *iter = x86_32->swbbp_mem_patch_list;
if (iter->physaddr >= phys_address && iter->physaddr < phys_address+(size*count)) {
uint32_t offset = iter->physaddr - phys_address;
buffer[offset] = iter->orig_byte;
if (iter->physaddr >= phys_address && iter->physaddr < phys_address+(size*count)) {
uint32_t offset = iter->physaddr - phys_address;
buffer[offset] = iter->orig_byte;
* breakpoint instruction.
*/
newbuffer = malloc(size*count);
* breakpoint instruction.
*/
newbuffer = malloc(size*count);
- if (newbuffer == NULL) {
LOG_ERROR("%s out of memory", __func__);
return ERROR_FAIL;
}
memcpy(newbuffer, buffer, size*count);
struct swbp_mem_patch *iter = x86_32->swbbp_mem_patch_list;
LOG_ERROR("%s out of memory", __func__);
return ERROR_FAIL;
}
memcpy(newbuffer, buffer, size*count);
struct swbp_mem_patch *iter = x86_32->swbbp_mem_patch_list;
if (iter->physaddr >= phys_address && iter->physaddr < phys_address+(size*count)) {
uint32_t offset = iter->physaddr - phys_address;
newbuffer[offset] = SW_BP_OPCODE;
if (iter->physaddr >= phys_address && iter->physaddr < phys_address+(size*count)) {
uint32_t offset = iter->physaddr - phys_address;
newbuffer[offset] = SW_BP_OPCODE;
/* add the memory patch */
struct swbp_mem_patch *new_patch = malloc(sizeof(struct swbp_mem_patch));
/* add the memory patch */
struct swbp_mem_patch *new_patch = malloc(sizeof(struct swbp_mem_patch));
- if (new_patch == NULL) {
LOG_ERROR("%s out of memory", __func__);
return ERROR_FAIL;
}
LOG_ERROR("%s out of memory", __func__);
return ERROR_FAIL;
}
new_patch->swbp_unique_id = bp->unique_id;
struct swbp_mem_patch *addto = x86_32->swbbp_mem_patch_list;
new_patch->swbp_unique_id = bp->unique_id;
struct swbp_mem_patch *addto = x86_32->swbbp_mem_patch_list;
x86_32->swbbp_mem_patch_list = new_patch;
else {
x86_32->swbbp_mem_patch_list = new_patch;
else {
- while (addto->next != NULL)
addto = addto->next;
addto->next = new_patch;
}
addto = addto->next;
addto->next = new_patch;
}
/* remove from patch */
struct swbp_mem_patch *iter = x86_32->swbbp_mem_patch_list;
/* remove from patch */
struct swbp_mem_patch *iter = x86_32->swbbp_mem_patch_list;
if (iter->swbp_unique_id == bp->unique_id) {
/* it's the first item */
x86_32->swbbp_mem_patch_list = iter->next;
if (iter->swbp_unique_id == bp->unique_id) {
/* it's the first item */
x86_32->swbbp_mem_patch_list = iter->next;
} else {
while (iter->next != NULL && iter->next->swbp_unique_id != bp->unique_id)
iter = iter->next;
} else {
while (iter->next != NULL && iter->next->swbp_unique_id != bp->unique_id)
iter = iter->next;
- if (iter->next != NULL) {
/* it's the next one */
struct swbp_mem_patch *freeme = iter->next;
iter->next = iter->next->next;
/* it's the next one */
struct swbp_mem_patch *freeme = iter->next;
iter->next = iter->next->next;
static int xscale_jtag_set_instr(struct jtag_tap *tap, uint32_t new_instr, tap_state_t end_state)
{
static int xscale_jtag_set_instr(struct jtag_tap *tap, uint32_t new_instr, tap_state_t end_state)
{
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
struct scan_field field;
if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
struct scan_field field;
struct breakpoint *breakpoint;
breakpoint = breakpoint_find(target,
buf_get_u32(arm->pc->value, 0, 32));
struct breakpoint *breakpoint;
breakpoint = breakpoint_find(target,
buf_get_u32(arm->pc->value, 0, 32));
- if (breakpoint != NULL) {
uint32_t next_pc;
enum trace_mode saved_trace_mode;
uint32_t next_pc;
enum trace_mode saved_trace_mode;
if (handle_breakpoints)
breakpoint = breakpoint_find(target,
buf_get_u32(arm->pc->value, 0, 32));
if (handle_breakpoints)
breakpoint = breakpoint_find(target,
buf_get_u32(arm->pc->value, 0, 32));
- if (breakpoint != NULL) {
retval = xscale_unset_breakpoint(target, breakpoint);
if (retval != ERROR_OK)
return retval;
retval = xscale_unset_breakpoint(target, breakpoint);
if (retval != ERROR_OK)
return retval;
return ERROR_COMMAND_SYNTAX_ERROR;
target = get_target(CMD_ARGV[0]);
return ERROR_COMMAND_SYNTAX_ERROR;
target = get_target(CMD_ARGV[0]);
LOG_ERROR("target '%s' not defined", CMD_ARGV[0]);
return ERROR_FAIL;
}
LOG_ERROR("target '%s' not defined", CMD_ARGV[0]);
return ERROR_FAIL;
}
return ERROR_COMMAND_SYNTAX_ERROR;
target = get_target(CMD_ARGV[0]);
return ERROR_COMMAND_SYNTAX_ERROR;
target = get_target(CMD_ARGV[0]);
LOG_ERROR("target '%s' not defined", CMD_ARGV[0]);
return ERROR_FAIL;
}
LOG_ERROR("target '%s' not defined", CMD_ARGV[0]);
return ERROR_FAIL;
}
/* our return vector must be NULL terminated */
argv = calloc(n + 1, sizeof(char *));
/* our return vector must be NULL terminated */
argv = calloc(n + 1, sizeof(char *));
return ERROR_FAIL;
for (unsigned i = 0; i < n; i++) {
return ERROR_FAIL;
for (unsigned i = 0; i < n; i++) {
field.out_value = dr_out_buf;
field.in_value = calloc(DIV_ROUND_UP(field.num_bits, 8), 1);
field.out_value = dr_out_buf;
field.in_value = calloc(DIV_ROUND_UP(field.num_bits, 8), 1);
jtag_add_plain_dr_scan(field.num_bits,
field.out_value,
field.in_value,
jtag_add_plain_dr_scan(field.num_bits,
field.out_value,
field.in_value,
jtag_add_plain_ir_scan(field.num_bits,
field.out_value, field.in_value, my_end_state);
else
jtag_add_plain_ir_scan(field.num_bits,
field.out_value, field.in_value, my_end_state);
else
if (attempt > 0 && verbose)
LOG_USER("LSDR retry %d", attempt);
if (attempt > 0 && verbose)
LOG_USER("LSDR retry %d", attempt);
jtag_add_plain_dr_scan(field.num_bits,
field.out_value,
field.in_value,
jtag_add_plain_dr_scan(field.num_bits,
field.out_value,
field.in_value,