misc: change return type of scan routines to size_t

This commit is contained in:
Rafael Silva 2022-08-06 20:44:32 +01:00 committed by Rachel Mant
parent 7db6c71095
commit 4f01ffe56c
8 changed files with 37 additions and 35 deletions

View File

@ -201,7 +201,7 @@ static bool cmd_jtag_scan(target *t, int argc, const char **argv)
if (connect_assert_nrst)
platform_nrst_set_val(true); /* will be deasserted after attach */
int devs = -1;
uint32_t devs = 0;
volatile struct exception e;
TRY_CATCH (e, EXCEPTION_ALL) {
#if PC_HOSTED == 1
@ -242,7 +242,7 @@ bool cmd_swdp_scan(target *t, int argc, const char **argv)
if (connect_assert_nrst)
platform_nrst_set_val(true); /* will be deasserted after attach */
int devs = -1;
uint32_t devs = 0;
volatile struct exception e;
TRY_CATCH (e, EXCEPTION_ALL) {
#if PC_HOSTED == 1
@ -260,7 +260,7 @@ bool cmd_swdp_scan(target *t, int argc, const char **argv)
break;
}
if (devs <= 0) {
if (devs == 0) {
platform_nrst_set_val(false);
gdb_out("SW-DP scan failed!\n");
return false;
@ -282,7 +282,7 @@ bool cmd_auto_scan(target *t, int argc, const char **argv)
if (connect_assert_nrst)
platform_nrst_set_val(true); /* will be deasserted after attach */
int devs = -1;
uint32_t devs = 0;
volatile struct exception e;
TRY_CATCH (e, EXCEPTION_ALL) {
#if PC_HOSTED == 1
@ -314,7 +314,7 @@ bool cmd_auto_scan(target *t, int argc, const char **argv)
gdb_outf("Exception: %s\n", e.msg);
break;
}
if (devs <= 0) {
if (devs == 0) {
platform_nrst_set_val(false);
gdb_out("auto scan failed!\n");
return false;

View File

@ -35,10 +35,10 @@ typedef uint32_t target_addr;
struct target_controller;
#if PC_HOSTED == 1
int platform_adiv5_swdp_scan(uint32_t targetid);
int platform_jtag_scan(const uint8_t *lrlens);
uint32_t platform_adiv5_swdp_scan(uint32_t targetid);
uint32_t platform_jtag_scan(const uint8_t *lrlens);
#endif
int adiv5_swdp_scan(uint32_t targetid);
uint32_t adiv5_swdp_scan(uint32_t targetid);
uint32_t jtag_scan(const uint8_t *lrlens);
int target_foreach(void (*cb)(int i, target *t, void *context), void *context);

View File

@ -50,7 +50,7 @@
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-parameter"
int jlink_init(bmp_info_t *info) { return -1; }
int jlink_swdp_scan(bmp_info_t *info) { return 0; }
uint32_t jlink_swdp_scan(bmp_info_t *info) { return 0; }
int jlink_jtagtap_init(bmp_info_t *info, jtag_proc_t *jtag_proc) { return 0; }
const char *jlink_target_voltage(bmp_info_t *info) { return "ERROR"; }
void jlink_nrst_set_val(bmp_info_t *info, bool assert) { }
@ -97,7 +97,7 @@ enum jaylink_device_capability {
int jlink_init(bmp_info_t *info);
int jlink_swdp_scan(bmp_info_t *info);
uint32_t jlink_swdp_scan(bmp_info_t *info);
int jlink_jtagtap_init(bmp_info_t *info, jtag_proc_t *jtag_proc);
const char *jlink_target_voltage(bmp_info_t *info);
void jlink_nrst_set_val(bmp_info_t *info, bool assert);

View File

@ -76,14 +76,14 @@ static int line_reset(bmp_info_t *info)
return 0;
}
static int jlink_swdptap_init(bmp_info_t *info)
static bool jlink_swdptap_init(bmp_info_t *info)
{
uint8_t cmd[2] = {CMD_GET_SELECT_IF, JLINK_IF_GET_AVAILABLE};
uint8_t res[4];
send_recv(info->usb_link, cmd, 2, res, sizeof(res));
if (!(res[0] & JLINK_IF_SWD))
return -1;
return false;
cmd[1] = SELECT_IF_SWD;
send_recv(info->usb_link, cmd, 2, res, sizeof(res));
@ -92,14 +92,15 @@ static int jlink_swdptap_init(bmp_info_t *info)
/* SWD speed is fixed. Do not set it here*/
return 0;
return true;
}
int jlink_swdp_scan(bmp_info_t *info)
uint32_t jlink_swdp_scan(bmp_info_t *info)
{
target_list_free();
jlink_swdptap_init(info);
if (!jlink_swdptap_init(info))
return 0;
uint8_t cmd[44];
memset(cmd, 0, sizeof(cmd));

View File

@ -135,7 +135,7 @@ void platform_init(int argc, char **argv)
}
}
int platform_adiv5_swdp_scan(uint32_t targetid)
uint32_t platform_adiv5_swdp_scan(uint32_t targetid)
{
info.is_jtag = false;
platform_max_frequency_set(cl_opts.opt_max_swj_frequency);
@ -156,7 +156,6 @@ int platform_adiv5_swdp_scan(uint32_t targetid)
default:
return 0;
}
return 0;
}
int swdptap_init(ADIv5_DP_t *dp)
@ -186,7 +185,7 @@ void platform_add_jtag_dev(uint32_t i, const jtag_dev_t *jtag_dev)
remote_add_jtag_dev(i, jtag_dev);
}
int platform_jtag_scan(const uint8_t *lrlens)
uint32_t platform_jtag_scan(const uint8_t *lrlens)
{
info.is_jtag = true;
@ -203,7 +202,7 @@ int platform_jtag_scan(const uint8_t *lrlens)
return jtag_scan_stlinkv2(&info, lrlens);
default:
return -1;
return 0;
}
}

View File

@ -684,7 +684,7 @@ static int stlink_enter_debug_jtag(bmp_info_t *info)
// return id;
// }
static int stlink_read_idcodes(bmp_info_t *info, uint32_t *idcodes)
static size_t stlink_read_idcodes(bmp_info_t *info, uint32_t *idcodes)
{
uint8_t cmd[16] = {STLINK_DEBUG_COMMAND,
STLINK_DEBUG_APIV2_READ_IDCODES};
@ -692,10 +692,10 @@ static int stlink_read_idcodes(bmp_info_t *info, uint32_t *idcodes)
send_recv(info->usb_link, cmd, 16, data, 12);
if (stlink_usb_error_check(data, true))
return 0;
uint8_t *p = data + 4;
idcodes[0] = p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
p += 4;
idcodes[1] = p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
uint8_t *p = data + 4U;
idcodes[0] = p[0] | p[1] << 8U | p[2] << 16U | p[3] << 24U;
p += 4U;
idcodes[1] = p[0] | p[1] << 8U | p[2] << 16U | p[3] << 24U;
return 2;
}
@ -1018,7 +1018,7 @@ static uint32_t stlink_ap_read(ADIv5_AP_t *ap, uint16_t addr)
return ret;
}
int jtag_scan_stlinkv2(bmp_info_t *info, const uint8_t *irlens)
uint32_t jtag_scan_stlinkv2(bmp_info_t *info, const uint8_t *irlens)
{
uint32_t idcodes[JTAG_MAX_DEVS+1];
(void) *irlens;
@ -1032,14 +1032,16 @@ int jtag_scan_stlinkv2(bmp_info_t *info, const uint8_t *irlens)
/* Check for known devices and handle accordingly */
for(uint32_t i = 0; i < jtag_dev_count; i++)
jtag_devs[i].jd_idcode = idcodes[i];
for(uint32_t i = 0; i < jtag_dev_count; i++)
for(size_t j = 0; dev_descr[j].idcode; j++)
for(uint32_t i = 0; i < jtag_dev_count; i++) {
for(size_t j = 0; dev_descr[j].idcode; j++) {
if((jtag_devs[i].jd_idcode & dev_descr[j].idmask) ==
dev_descr[j].idcode) {
if(dev_descr[j].handler)
dev_descr[j].handler(i);
break;
}
}
}
return jtag_dev_count;
}
@ -1068,7 +1070,7 @@ void stlink_adiv5_dp_defaults(ADIv5_DP_t *dp)
dp->mem_write_sized = stlink_mem_write_sized;
}
int stlink_swdp_scan(bmp_info_t *info)
uint32_t stlink_swdp_scan(bmp_info_t *info)
{
target_list_free();

View File

@ -32,10 +32,10 @@ int stlink_hwversion(void) { return -1; }
const char *stlink_target_voltage(bmp_info_t *info) { return "ERROR"; }
void stlink_nrst_set_val(bmp_info_t *info, bool assert) { }
bool stlink_nrst_get_val(void) { return true; }
int stlink_swdp_scan(bmp_info_t *info) { return 0; }
uint32_t stlink_swdp_scan(bmp_info_t *info) { return 0; }
void stlink_adiv5_dp_defaults(ADIv5_DP_t *dp) { }
int stlink_jtag_dp_init(ADIv5_DP_t *dp) { return false; }
int jtag_scan_stlinkv2(bmp_info_t *info, const uint8_t *irlens) { return 0; }
uint32_t jtag_scan_stlinkv2(bmp_info_t *info, const uint8_t *irlens) { return 0; }
void stlink_exit_function(bmp_info_t *info) { }
void stlink_max_frequency_set(bmp_info_t *info, uint32_t freq) { }
uint32_t stlink_max_frequency_get(bmp_info_t *info) { return 0; }
@ -46,10 +46,10 @@ int stlink_hwversion(void);
const char *stlink_target_voltage(bmp_info_t *info);
void stlink_nrst_set_val(bmp_info_t *info, bool assert);
bool stlink_nrst_get_val(void);
int stlink_swdp_scan(bmp_info_t *info);
uint32_t stlink_swdp_scan(bmp_info_t *info);
void stlink_adiv5_dp_defaults(ADIv5_DP_t *dp);
int stlink_jtag_dp_init(ADIv5_DP_t *dp);
int jtag_scan_stlinkv2(bmp_info_t *info, const uint8_t *irlens);
uint32_t jtag_scan_stlinkv2(bmp_info_t *info, const uint8_t *irlens);
void stlink_exit_function(bmp_info_t *info);
void stlink_max_frequency_set(bmp_info_t *info, uint32_t freq);
uint32_t stlink_max_frequency_get(bmp_info_t *info);

View File

@ -67,7 +67,7 @@ bool firmware_dp_low_write(ADIv5_DP_t *dp, uint16_t addr, const uint32_t data)
* If target id given, scan DPs 0 .. 15 on that device and return.
* Otherwise
*/
int adiv5_swdp_scan(uint32_t targetid)
uint32_t adiv5_swdp_scan(uint32_t targetid)
{
volatile struct exception e;
@ -83,7 +83,7 @@ int adiv5_swdp_scan(uint32_t targetid)
ADIv5_DP_t *initial_dp = &idp;
if (swdptap_init(initial_dp))
return -1;
return 0;
/* DORMANT-> SWD sequence*/
initial_dp->seq_out(0xFFFFFFFF, 32);
@ -127,7 +127,7 @@ int adiv5_swdp_scan(uint32_t targetid)
}
if (e.type || initial_dp->fault) {
DEBUG_WARN("No usable DP found\n");
return -1;
return 0;
}
}