From 09c000eca8341b1b5ee4706befc2af02591323be Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 19 Dec 2020 16:25:03 +0100 Subject: [PATCH] hosted: Really handle setting tpwr on remote on the command line #817 Expect the command to fail, due to old firmware or remote not implementing the power switch. --- src/platforms/hosted/bmp_remote.c | 5 +++-- src/platforms/hosted/bmp_remote.h | 2 +- src/platforms/hosted/platform.c | 14 ++++++++++++++ src/platforms/pc/cl_utils.c | 3 --- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/platforms/hosted/bmp_remote.c b/src/platforms/hosted/bmp_remote.c index 66d1b92..b8dc1d2 100644 --- a/src/platforms/hosted/bmp_remote.c +++ b/src/platforms/hosted/bmp_remote.c @@ -73,7 +73,7 @@ bool remote_target_get_power(void) return (construct[1] == '1'); } -void remote_target_set_power(bool power) +bool remote_target_set_power(bool power) { uint8_t construct[REMOTE_MAX_MSG_SIZE]; int s; @@ -87,8 +87,9 @@ void remote_target_set_power(bool power) if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { DEBUG_WARN("platform_target_set_power failed, error %s\n", s ? (char *)&(construct[1]) : "unknown"); - exit(-1); + return false; } + return true; } void remote_srst_set_val(bool assert) diff --git a/src/platforms/hosted/bmp_remote.h b/src/platforms/hosted/bmp_remote.h index c61cb02..cff7563 100644 --- a/src/platforms/hosted/bmp_remote.h +++ b/src/platforms/hosted/bmp_remote.h @@ -34,7 +34,7 @@ int remote_swdptap_init(swd_proc_t *swd_proc); int remote_jtagtap_init(jtag_proc_t *jtag_proc); bool remote_target_get_power(void); const char *remote_target_voltage(void); -void remote_target_set_power(bool power); +bool remote_target_set_power(bool power); void remote_srst_set_val(bool assert); bool remote_srst_get_val(void); void remote_max_frequency_set(uint32_t freq); diff --git a/src/platforms/hosted/platform.c b/src/platforms/hosted/platform.c index 5e55603..7b95c8d 100644 --- a/src/platforms/hosted/platform.c +++ b/src/platforms/hosted/platform.c @@ -377,6 +377,20 @@ uint32_t platform_max_frequency_get(void) return false; } +void platform_target_set_power(bool power) +{ + switch (info.bmp_type) { + case BMP_TYPE_BMP: + if (remote_target_set_power(power)) + DEBUG_INFO("Powering up device!\n"); + else + DEBUG_WARN("Powering up device unimplemented or failed\n"); + break; + default: + break; + } +} + void platform_buffer_flush(void) { switch (info.bmp_type) { diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 78ba5b5..686828f 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -313,13 +313,10 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) { int res = -1; int num_targets; -#if defined(PLATFORM_HAS_POWER_SWITCH) if (opt->opt_tpwr) { - DEBUG_INFO("Powering up device"); platform_target_set_power(true); platform_delay(500); } -#endif if (opt->opt_connect_under_reset) DEBUG_INFO("Connecting under reset\n"); connect_assert_srst = opt->opt_connect_under_reset;