New button behaviour in bootloader mode:

- Keep button pressed when powering to force entering bootloader
  - Once in bootloader more, you can release the button
- When in bootloader mode (no matter how you entered that mode)
  - One button press to quit bootloader mode and boot main image
This commit is contained in:
Philippe Teuwen 2019-05-26 17:48:20 +02:00
parent ade858b4f5
commit 51e4df533e
2 changed files with 16 additions and 13 deletions

View file

@ -220,11 +220,14 @@ void UsbPacketReceived(uint8_t *packet, int len) {
reply_old(CMD_ACK, arg0, 0, 0, 0, 0);
}
static void flash_mode(int externally_entered) {
static void flash_mode(void) {
start_addr = 0;
end_addr = 0;
bootrom_unlocked = 0;
uint8_t rx[sizeof(PacketCommandOLD)];
common_area.command = COMMON_AREA_COMMAND_NONE;
if (!common_area.flags.button_pressed && BUTTON_PRESS())
common_area.flags.button_pressed = 1;
usb_enable();
@ -241,17 +244,17 @@ static void flash_mode(int externally_entered) {
}
}
if (!externally_entered && !BUTTON_PRESS()) {
if (common_area.flags.button_pressed && !BUTTON_PRESS()) {
common_area.flags.button_pressed = 0;
}
if (!common_area.flags.button_pressed && BUTTON_PRESS()) {
/* Perform a reset to leave flash mode */
common_area.flags.button_pressed = 1;
usb_disable();
LED_B_ON();
AT91C_BASE_RSTC->RSTC_RCR = RST_CONTROL_KEY | AT91C_RSTC_PROCRST;
for (;;) {};
}
if (externally_entered && BUTTON_PRESS()) {
/* Let the user's button press override the automatic leave */
externally_entered = 0;
}
}
}
@ -342,14 +345,13 @@ void BootROM(void) {
}
common_area.flags.bootrom_present = 1;
if (common_area.command == COMMON_AREA_COMMAND_ENTER_FLASH_MODE) {
common_area.command = COMMON_AREA_COMMAND_NONE;
flash_mode(1);
} else if (BUTTON_PRESS()) {
flash_mode(0);
} else if (_osimage_entry == 0xffffffffU) {
flash_mode(1);
if ((common_area.command == COMMON_AREA_COMMAND_ENTER_FLASH_MODE) ||
(!common_area.flags.button_pressed && BUTTON_PRESS()) ||
(_osimage_entry == 0xffffffffU)) {
flash_mode();
} else {
// clear button status, even if button still pressed
common_area.flags.button_pressed = 0;
// jump to Flash address of the osimage entry point (LSBit set for thumb mode)
__asm("bx %0\n" : : "r"(((int)&_osimage_entry) | 0x1));
}

View file

@ -128,6 +128,7 @@ struct common_area {
struct {
unsigned int bootrom_present: 1; /* Set when a bootrom that is capable of parsing the common area is present */
unsigned int osimage_present: 1; /* Set when a osimage that is capable of parsing the common area is present */
unsigned int button_pressed: 1;
} __attribute__((packed)) flags;
int arg1, arg2;
} __attribute__((packed));