From be6013d70cd337921ec8d4fdac74720e9e49e3a8 Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Fri, 27 Sep 2024 01:02:18 +0300 Subject: [PATCH] fix potential race condition in boot-cypress --- firmware/boot-cypress/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/firmware/boot-cypress/main.c b/firmware/boot-cypress/main.c index b8f9d31..9b8c4b4 100644 --- a/firmware/boot-cypress/main.c +++ b/firmware/boot-cypress/main.c @@ -147,13 +147,14 @@ void handle_pending_usb_setup(void) { } SETUP_EP0_BUF(len); } else { - SETUP_EP0_BUF(0); + SETUP_EP0_OUT_BUF(); while(EP0CS & _BUSY); if(!eeprom_write(arg_chip, arg_addr, EP0BUF, len, arg_dbyte, page_size, /*timeout=*/166)) { STALL_EP0(); break; } + ACK_EP0(); } arg_len -= len; @@ -179,9 +180,10 @@ void handle_pending_usb_setup(void) { xmemcpy(EP0BUF, (__xdata void *)arg_addr, len); SETUP_EP0_BUF(len); } else { - SETUP_EP0_BUF(0); + SETUP_EP0_OUT_BUF(); while(EP0CS & _BUSY); xmemcpy((__xdata void *)arg_addr, EP0BUF, arg_len); + ACK_EP0(); } arg_len -= len;