From 1cca109429eb462993a9479ada49d3ba77b1c52b Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Oct 2017 12:48:04 +0200 Subject: [PATCH] chg: validating we got a full usbcommand (512b) --- armsrc/appmain.c | 25 +++++++++++++++++-------- common/cmd.c | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 2476f442c..7ff3f7d5f 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -307,6 +307,9 @@ void SendVersion(void) { FpgaGatherVersion(FPGA_BITSTREAM_HF, temp, sizeof(temp)); strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1); + FpgaGatherVersion(FPGA_BITSTREAM_NFC, temp, sizeof(temp)); + strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1); + // Send Chip ID and used flash memory uint32_t text_and_rodata_section_size = (uint32_t)&__data_src_start__ - (uint32_t)&_flash_start; uint32_t compressed_data_section_size = common_area.arg1; @@ -1090,9 +1093,8 @@ void UsbPacketReceived(uint8_t *packet, int len) { usb_disable(); SpinDelay(2000); AT91C_BASE_RSTC->RSTC_RCR = RST_CONTROL_KEY | AT91C_RSTC_PROCRST; - for(;;) { - // We're going to reset, and the bootrom will take control. - } + // We're going to reset, and the bootrom will take control. + for(;;) {} break; case CMD_START_FLASH: @@ -1101,7 +1103,8 @@ void UsbPacketReceived(uint8_t *packet, int len) { } usb_disable(); AT91C_BASE_RSTC->RSTC_RCR = RST_CONTROL_KEY | AT91C_RSTC_PROCRST; - for(;;); + // We're going to flash, and the bootrom will take control. + for(;;) {} break; case CMD_DEVICE_INFO: { @@ -1158,15 +1161,21 @@ void __attribute__((noreturn)) AppMain(void) { #endif byte_t rx[sizeof(UsbCommand)]; - size_t rx_len; + size_t rx_len = 0; for(;;) { + + // Check if there is a usb packet available if ( usb_poll_validate_length() ) { + + // Try to retrieve the available command frame rx_len = usb_read(rx, sizeof(UsbCommand)); - - if (rx_len) - UsbPacketReceived(rx, rx_len); + + // Check if the transfer was complete + if (rx_len == sizeof(UsbCommand)) + UsbPacketReceived(rx, rx_len); } + WDT_HIT(); // Press button for one second to enter a possible standalone mode diff --git a/common/cmd.c b/common/cmd.c index 12c364ed0..ae2768a8d 100644 --- a/common/cmd.c +++ b/common/cmd.c @@ -38,7 +38,7 @@ bool cmd_receive(UsbCommand* cmd) { if (!usb_poll_validate_length()) return false; // Try to retrieve the available command frame - size_t rxlen = usb_read((byte_t*)cmd,sizeof(UsbCommand)); + size_t rxlen = usb_read((byte_t*)cmd, sizeof(UsbCommand)); // Check if the transfer was complete if (rxlen != sizeof(UsbCommand)) return false;