1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

fix(legacy): prevent handling RebootToBootloader recursing by flushing USB write

This commit is contained in:
Ondrej Mikle 2021-12-06 22:08:20 +01:00
parent 2bcbbec0a2
commit 199729e57a
5 changed files with 25 additions and 2 deletions

View File

@ -0,0 +1 @@
Prevent recursing in handling RebootToBootloader by USB flush.

View File

@ -360,8 +360,7 @@ void fsm_msgRebootToBootloader(void) {
oledRefresh();
fsm_sendSuccess(_("Rebooting"));
// make sure the outgoing message is sent
usbPoll();
usbSleep(500);
usbFlush(500);
#if !EMULATOR
svc_reboot_to_bootloader();
#else

View File

@ -70,3 +70,5 @@ char usbTiny(char set) {
tiny = set;
return old;
}
void usbFlush(uint32_t millis) { usbSleep(millis); }

View File

@ -457,3 +457,23 @@ void usbSleep(uint32_t millis) {
}
}
}
void usbFlush(uint32_t millis) {
if (usbd_dev == NULL) {
return;
}
static const uint8_t *data;
data = msg_out_data();
if (data) {
while (usbd_ep_write_packet(usbd_dev, ENDPOINT_ADDRESS_MAIN_IN, data,
USB_PACKET_SIZE) != USB_PACKET_SIZE) {
}
}
uint32_t start = timer_ms();
while ((timer_ms() - start) < millis) {
asm("nop");
}
}

View File

@ -27,5 +27,6 @@ void usbPoll(void);
void usbReconnect(void);
char usbTiny(char set);
void usbSleep(uint32_t millis);
void usbFlush(uint32_t millis);
#endif