summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Hesling <hesling@chromium.org>2019-11-12 14:07:05 -0800
committerCommit Bot <commit-bot@chromium.org>2020-03-06 17:31:26 +0000
commita40a1bd8e43bfbb02648be2ffa1b35697825a7ef (patch)
tree4fd2d448e824fd6edf9b2f5ba1bb2d5d1040f022
parent5a75964d9b34ee4f76bb13e8372a80dafa4ab7b2 (diff)
downloadchrome-ec-a40a1bd8e43bfbb02648be2ffa1b35697825a7ef.tar.gz
stm32mon: Add connect retries parameter
Currently, stm32mon will try to get the attention of the stm32 bootloader for forever ("Starting monitor"). Retrying forever is odd behavior, in general. Furthermore, this behavior does not allow wrapper scripts to observe the failure and try other retry mechanisms, like resetting the chip. TL;DR This CL sets a default 40 retries for the bootloader connect/sync and adds the "--retries <num-retries>" and "-R <num-retries>" argument for adjustments. Note, this is simply the retry limit for connecting/syncing-with the bootlodaer. You can specify "-R -1" to try forever. BRANCH=nocturne,hatch BUG=b:143374692,b:144729003 TEST=cros_workon --board=nocturne start chromeos-base/ec-devutils emerge-nocturne chromeos-base/ec-devutils cros deploy --root=/usr/local dut1 chromeos-base/ec-devutils # Bind spidev for fpmcu # Enable hardware wp time stm32mon -U -u -p -s /dev/spidev32765.0 -e -w \ /opt/google/biod/fw/nocturne_fp_v2.2.110-b936c0a3c.bin # Check that it tries forever?? time stm32mon -R 10 -U -u -p -s /dev/spidev32765.0 -e -w \ /opt/google/biod/fw/nocturne_fp_v2.2.110-b936c0a3c.bin # Check that is only makes 11 attempts Signed-off-by: Craig Hesling <hesling@chromium.org> Change-Id: I925466fb892b0d17a7ff8b354e3cee302d167d3c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1913332 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> (cherry picked from commit 5908893e03d878d4b3486449bb8adc2a1e8ae19b) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2091135 Reviewed-by: Philip Chen <philipchen@chromium.org> Commit-Queue: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org>
-rw-r--r--util/stm32mon.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/util/stm32mon.c b/util/stm32mon.c
index 324f208352..1b642e96d1 100644
--- a/util/stm32mon.c
+++ b/util/stm32mon.c
@@ -247,6 +247,7 @@ struct stm32_def {
{ 0 }
};
+#define DEFAULT_CONNECT_RETRIES 5
#define DEFAULT_TIMEOUT 4 /* seconds */
#define EXT_ERASE_TIMEOUT 20 /* seconds */
#define DEFAULT_BAUDRATE B38400
@@ -269,6 +270,7 @@ enum interface_mode {
/* store custom parameters */
speed_t baudrate = DEFAULT_BAUDRATE;
+int connect_retries = DEFAULT_CONNECT_RETRIES;
int i2c_adapter = INVALID_I2C_ADAPTER;
const char *spi_adapter;
int i2c_slave_address = DEFAULT_I2C_SLAVE_ADDRESS;
@@ -786,6 +788,7 @@ struct stm32_def *command_get_id(int fd)
int init_monitor(int fd)
{
int res;
+ int attempts = connect_retries + 1;
uint8_t init = mode == MODE_SPI ? SOF : CMD_INIT;
/* Skip in i2c mode */
@@ -795,7 +798,7 @@ int init_monitor(int fd)
printf("Waiting for the monitor startup ...");
fflush(stdout);
- while (1) {
+ while (connect_retries < 0 || attempts--) {
/* Send the command index */
res = write_wrapper(fd, &init, 1);
if (res <= 0) {
@@ -819,6 +822,12 @@ int init_monitor(int fd)
return res;
fflush(stdout);
}
+
+ if (IS_STM32_ERROR(res)) {
+ printf("Giving up after %d attempts.\n", connect_retries + 1);
+ return res;
+ }
+
printf("Done.\n");
/* read trailing chars */
@@ -1090,7 +1099,7 @@ int command_read_unprotect(int fd)
* before the actual reset depending on the bootloader.
*/
usleep(MAX_DELAY_REBOOT);
- if (init_monitor(fd) < 0) {
+ if (IS_STM32_ERROR(init_monitor(fd))) {
fprintf(stderr, "Cannot recover after RU reset\n");
return STM32_EIO;
}
@@ -1120,7 +1129,7 @@ int command_write_unprotect(int fd)
* before the actual reset depending on the bootloader.
*/
usleep(MAX_DELAY_REBOOT);
- if (init_monitor(fd) < 0) {
+ if (IS_STM32_ERROR(init_monitor(fd))) {
fprintf(stderr, "Cannot recover after WP reset\n");
return STM32_EIO;
}
@@ -1405,6 +1414,7 @@ static const struct option longopts[] = {
{"offset", 1, 0, 'o'},
{"progressbar", 0, 0, 'p'},
{"read", 1, 0, 'r'},
+ {"retries", 1, 0, 'R'},
{"spi", 1, 0, 's'},
{"unprotect", 0, 0, 'u'},
{"version", 0, 0, 'v'},
@@ -1442,6 +1452,7 @@ void display_usage(char *program)
fprintf(stderr, "--g[o] : jump to execute flash entrypoint\n");
fprintf(stderr, "--p[rogressbar] : use a progress bar instead of "
"the spinner\n");
+ fprintf(stderr, "--R[etries] <num> : limit connect retries to num\n");
fprintf(stderr, "-L[ogfile] <file> : save all communications exchange "
"in a log file\n");
fprintf(stderr, "-c[r50_mode] : consider device to be a Cr50 interface,"
@@ -1485,7 +1496,7 @@ int parse_parameters(int argc, char **argv)
int flags = 0;
const char *log_file_name = NULL;
- while ((opt = getopt_long(argc, argv, "a:l:b:cd:eghL:n:o:pr:s:w:uUv?",
+ while ((opt = getopt_long(argc, argv, "a:l:b:cd:eghL:n:o:pr:R:s:w:uUv?",
longopts, &idx)) != -1) {
switch (opt) {
case 'a':
@@ -1530,6 +1541,9 @@ int parse_parameters(int argc, char **argv)
case 'r':
input_filename = optarg;
break;
+ case 'R':
+ connect_retries = atoi(optarg);
+ break;
case 's':
spi_adapter = optarg;
mode = MODE_SPI;
@@ -1606,7 +1620,8 @@ int main(int argc, char **argv)
if (ser < 0)
return 1;
/* Trigger embedded monitor detection */
- if (init_monitor(ser) < 0)
+ res = init_monitor(ser);
+ if (IS_STM32_ERROR(res))
goto terminate;
chip = command_get_id(ser);