diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 9e8a9d72b..9771939d3 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1169,7 +1169,7 @@ void UsbPacketReceived(uint8_t *packet, int len) { LED_B_OFF(); break; } - case CMD_WIPE_FLASH_MEM: + case CMD_WIPE_FLASH_MEM: { LED_B_ON(); uint8_t page = c->arg[0]; uint8_t initalwipe = c->arg[1]; @@ -1186,6 +1186,7 @@ void UsbPacketReceived(uint8_t *packet, int len) { cmd_send(CMD_ACK, isok, 0, 0, 0, 0); LED_B_OFF(); break; + } case CMD_DOWNLOAND_FLASH_MEM: { LED_B_ON(); @@ -1197,8 +1198,6 @@ void UsbPacketReceived(uint8_t *packet, int len) { // arg0 = startindex // arg1 = length bytes to transfer // arg2 = RFU - //Dbprintf("transfer to client parameters: %" PRIu32 " | %" PRIu32 " | %" PRIu32, startidx, numofbytes, c->arg[2]); - for (size_t i = 0; i < numofbytes; i += USB_CMD_DATA_SIZE) { len = MIN((numofbytes - i), USB_CMD_DATA_SIZE); @@ -1215,6 +1214,23 @@ void UsbPacketReceived(uint8_t *packet, int len) { LED_B_OFF(); break; } + case CMD_INFO_FLASH_MEM: { + + LED_B_ON(); + rdv40_validation_t *info = (rdv40_validation_t*)BigBuf_malloc( sizeof(rdv40_validation_t) ); + + bool isok = Flash_ReadData(FLASH_MEM_SIGNATURE_OFFSET, info->signature, FLASH_MEM_SIGNATURE_LEN); + + if (FlashInit()) { + Flash_UniqueID( info->flashid); + FlashStop(); + } + cmd_send(CMD_ACK, isok, 0, 0, info, sizeof(rdv40_validation_t)); + BigBuf_free(); + + LED_B_OFF(); + break; + } #endif case CMD_SET_LF_DIVISOR: FpgaDownloadAndGo(FPGA_BITSTREAM_LF); diff --git a/include/common.h b/include/common.h index fe5eaeb59..8fdb45ab0 100644 --- a/include/common.h +++ b/include/common.h @@ -4,7 +4,7 @@ // This code is licensed to you under the terms of the GNU GPL, version 2 or, // at your option, any later version. See the LICENSE.txt file for the text of // the license. - +// //----------------------------------------------------------------------------- // Interlib Definitions //----------------------------------------------------------------------------- @@ -46,6 +46,35 @@ extern int MF_DBGLEVEL; #endif #define RAMFUNC __attribute((long_call, section(".ramfunc"))) +// RDV40 Section +#ifndef FLASH_MEM_BLOCK_SIZE +# define FLASH_MEM_BLOCK_SIZE 256 +#endif + +#ifndef FLASH_MEM_MAX_SIZE +# define FLASH_MEM_MAX_SIZE 0x3FFFF +#endif + +#ifndef FLASH_MEM_ID_LEN +# define FLASH_MEM_ID_LEN 8 +#endif + +#ifndef FLASH_MEM_SIGNATURE_LEN +# define FLASH_MEM_SIGNATURE_LEN 128 +#endif + +#ifndef FLASH_MEM_SIGNATURE_OFFSET +# define FLASH_MEM_SIGNATURE_OFFSET (FLASH_MEM_MAX_SIZE - FLASH_MEM_SIGNATURE_LEN) +#endif + + +// RDV40, validation structure to help identifying that client/firmware is talking with RDV40 +typedef struct { + uint8_t magic[4]; + uint8_t flashid[FLASH_MEM_ID_LEN]; + uint8_t signature[FLASH_MEM_SIGNATURE_LEN]; +} __attribute__((__packed__)) rdv40_validation_t; + #ifdef __cplusplus } diff --git a/include/usb_cmd.h b/include/usb_cmd.h index 477258c58..ea8d45461 100644 --- a/include/usb_cmd.h +++ b/include/usb_cmd.h @@ -67,12 +67,13 @@ typedef struct{ #define CMD_DOWNLOAD_EML_BIGBUF 0x0110 #define CMD_DOWNLOADED_EML_BIGBUF 0x0111 -// For Flash memory operations +// RDV40, Flash memory operations #define CMD_READ_FLASH_MEM 0x0120 #define CMD_WRITE_FLASH_MEM 0x0121 #define CMD_WIPE_FLASH_MEM 0x0122 #define CMD_DOWNLOAND_FLASH_MEM 0x0123 #define CMD_DOWNLOADED_FLASHMEM 0x0124 +#define CMD_INFO_FLASH_MEM 0x0125 // For low-frequency tags #define CMD_READ_TI_TYPE 0x0202