Add parameter to stay in bootloader

This commit is contained in:
Olaf Rempel 2021-03-02 13:23:16 +01:00
parent ce3a80b747
commit ebe79687f0
2 changed files with 27 additions and 4 deletions

View File

@ -51,6 +51,7 @@ typedef struct bfly_privdata_s
uint8_t twi_address; uint8_t twi_address;
uint8_t chip_erase; uint8_t chip_erase;
uint8_t stay_in_bootloader;
uint16_t buffersize; uint16_t buffersize;
uint16_t flashsize; uint16_t flashsize;
@ -64,6 +65,7 @@ static struct option bfly_optargs[] =
{ "address", 1, 0, 'a' }, /* [ -a <address ] */ { "address", 1, 0, 'a' }, /* [ -a <address ] */
{ "device", 1, 0, 'd' }, /* -d <device> */ { "device", 1, 0, 'd' }, /* -d <device> */
{ "erase", 0, 0, 'e' }, /* [ -e ] */ { "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; p_priv->chip_erase = 1;
break; break;
case 's': /* stay in bootloader */
p_priv->stay_in_bootloader = 1;
break;
case 'h': case 'h':
case '?': /* error */ case '?': /* error */
fprintf(stderr, "Usage: butterfly_prog [options]\n" fprintf(stderr, "Usage: butterfly_prog [options]\n"
" -a <address> - optional: twi address for twiboot bridge mode\n" " -a <address> - optional: twi address for twiboot bridge mode\n"
" -d <device> - selects butterfly serial device\n" " -d <device> - selects butterfly serial device\n"
" -e - executes a chip erase\n" " -e - executes a chip erase\n"
" -s - stay in bootloader afterwards\n"
" -r <flash|eeprom>:<file> - reads flash/eeprom to file (.bin | .hex | -)\n" " -r <flash|eeprom>:<file> - reads flash/eeprom to file (.bin | .hex | -)\n"
" -w <flash|eeprom>:<file> - write flash/eeprom from file (.bin | .hex)\n" " -w <flash|eeprom>:<file> - write flash/eeprom from file (.bin | .hex)\n"
" -n - disable verify after write\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) 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); return butterfly_expect_cr(p_priv);
} /* butterfly_leave_progmode */ } /* butterfly_leave_progmode */

View File

@ -74,6 +74,7 @@ struct twi_privdata
uint8_t address; uint8_t address;
int fd; int fd;
int connected; int connected;
int stay_in_bootloader;
uint8_t pagesize; uint8_t pagesize;
uint16_t flashsize; uint16_t flashsize;
@ -82,8 +83,9 @@ struct twi_privdata
static struct option twi_optargs[] = static struct option twi_optargs[] =
{ {
{ "address", 1, 0, 'a'}, /* -a <addr> */ { "address", 1, 0, 'a' }, /* -a <addr> */
{ "device", 1, 0, 'd'}, /* [ -d <device> ] */ { "device", 1, 0, 'd' }, /* [ -d <device> ] */
{ "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; 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); twi_switch_application(twi, BOOTTYPE_APPLICATION);
} }
@ -535,11 +537,16 @@ static int twi_optarg_cb(int val, const char *arg, void *privdata)
} }
break; break;
case 's': /* stay in bootloader */
twi->stay_in_bootloader = 1;
break;
case 'h': case 'h':
case '?': /* error */ case '?': /* error */
fprintf(stderr, "Usage: twiboot [options]\n" fprintf(stderr, "Usage: twiboot [options]\n"
" -a <address> - selects i2c address (0x01 - 0x7F)\n" " -a <address> - selects i2c address (0x01 - 0x7F)\n"
" -d <device> - selects i2c device (default: /dev/i2c-0)\n" " -d <device> - selects i2c device (default: /dev/i2c-0)\n"
" -s - stay in bootloader afterwards\n"
" -r <flash|eeprom>:<file> - reads flash/eeprom to file (.bin | .hex | -)\n" " -r <flash|eeprom>:<file> - reads flash/eeprom to file (.bin | .hex | -)\n"
" -w <flash|eeprom>:<file> - write flash/eeprom from file (.bin | .hex)\n" " -w <flash|eeprom>:<file> - write flash/eeprom from file (.bin | .hex)\n"
" -n - disable verify after write\n" " -n - disable verify after write\n"