From ebe79687f06b7648c2de87d9debd4ea93275eb49 Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Tue, 2 Mar 2021 13:23:16 +0100 Subject: [PATCH] Add parameter to stay in bootloader --- butterfly_prog.c | 18 +++++++++++++++++- twiboot.c | 13 ++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/butterfly_prog.c b/butterfly_prog.c index ee88b8a..ad3565e 100644 --- a/butterfly_prog.c +++ b/butterfly_prog.c @@ -51,6 +51,7 @@ typedef struct bfly_privdata_s uint8_t twi_address; uint8_t chip_erase; + uint8_t stay_in_bootloader; uint16_t buffersize; uint16_t flashsize; @@ -64,6 +65,7 @@ static struct option bfly_optargs[] = { "address", 1, 0, 'a' }, /* [ -a
*/ { "erase", 0, 0, 'e' }, /* [ -e ] */ + { "stay", 0, 0, 's' }, /* [ -s ] */ }; /* ************************************************************************* @@ -112,12 +114,17 @@ static int bfly_optarg_cb(int val, const char *arg, void *privdata) p_priv->chip_erase = 1; break; + case 's': /* stay in bootloader */ + p_priv->stay_in_bootloader = 1; + break; + case 'h': case '?': /* error */ fprintf(stderr, "Usage: butterfly_prog [options]\n" " -a
- optional: twi address for twiboot bridge mode\n" " -d - selects butterfly serial device\n" " -e - executes a chip erase\n" + " -s - stay in bootloader afterwards\n" " -r : - reads flash/eeprom to file (.bin | .hex | -)\n" " -w : - write flash/eeprom from file (.bin | .hex)\n" " -n - disable verify after write\n" @@ -389,7 +396,16 @@ static int butterfly_enter_progmode(bfly_privdata_t * p_priv) * ************************************************************************* */ static int butterfly_leave_progmode(bfly_privdata_t * p_priv) { - (void)write(p_priv->fd, "L", 1); + if (p_priv->stay_in_bootloader) + { + /* Leave programming mode */ + (void)write(p_priv->fd, "L", 1); + } + else + { + /* Exit Bootloader */ + (void)write(p_priv->fd, "E", 1); + } return butterfly_expect_cr(p_priv); } /* butterfly_leave_progmode */ diff --git a/twiboot.c b/twiboot.c index 2e58b52..0bb5a14 100644 --- a/twiboot.c +++ b/twiboot.c @@ -74,6 +74,7 @@ struct twi_privdata uint8_t address; int fd; int connected; + int stay_in_bootloader; uint8_t pagesize; uint16_t flashsize; @@ -82,8 +83,9 @@ struct twi_privdata static struct option twi_optargs[] = { - { "address", 1, 0, 'a'}, /* -a */ - { "device", 1, 0, 'd'}, /* [ -d ] */ + { "address", 1, 0, 'a' }, /* -a */ + { "device", 1, 0, 'd' }, /* [ -d ] */ + { "stay", 0, 0, 's' }, /* [ -s ] */ }; @@ -299,7 +301,7 @@ static int twi_close(struct multiboot *mboot) { struct twi_privdata *twi = (struct twi_privdata *)mboot->privdata; - if (twi->connected) + if (twi->connected && !twi->stay_in_bootloader) { twi_switch_application(twi, BOOTTYPE_APPLICATION); } @@ -535,11 +537,16 @@ static int twi_optarg_cb(int val, const char *arg, void *privdata) } break; + case 's': /* stay in bootloader */ + twi->stay_in_bootloader = 1; + break; + case 'h': case '?': /* error */ fprintf(stderr, "Usage: twiboot [options]\n" " -a
- selects i2c address (0x01 - 0x7F)\n" " -d - selects i2c device (default: /dev/i2c-0)\n" + " -s - stay in bootloader afterwards\n" " -r : - reads flash/eeprom to file (.bin | .hex | -)\n" " -w : - write flash/eeprom from file (.bin | .hex)\n" " -n - disable verify after write\n"