X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/e3ae0257834f7d134c7f80db6fa23668b5a5fa6d..9dbe0941fd481f6371aae1018a50ba17bf5bf6c3:/armsrc/fpgaloader.c diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index 58385588..8cea61b0 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -135,11 +135,24 @@ void FpgaSetupSscDma(BYTE *buf, int len) PDC_CONTROL(SSC_BASE) = PDC_RX_ENABLE; } -// Download the fpga image starting at FpgaImage and with length FpgaImageLen DWORDs (e.g. 4 bytes) +static void DownloadFPGA_byte(unsigned char w) +{ +#define SEND_BIT(x) { if(w & (1<>(j*8); - else - w = v >>((3-j)*8); -#define SEND_BIT(x) { if(w & (1<0) + DownloadFPGA_byte(FpgaImage[(i++)^0x3]); + /* Explanation of the magic in the above line: + * i^0x3 inverts the lower two bits of the integer i, counting backwards + * for each 4 byte increment. The generated sequence of (i++)^3 is + * 3 2 1 0 7 6 5 4 11 10 9 8 15 14 13 12 etc. pp. + */ } + } else { + while(FpgaImageLen-->0) + DownloadFPGA_byte(*FpgaImage++); } LED_D_OFF(); @@ -208,7 +218,7 @@ static int bitparse_init(void * start_address, void *end_address) } } -int bitparse_find_section(char section_name, void **section_start, unsigned int *section_length) +int bitparse_find_section(char section_name, char **section_start, unsigned int *section_length) { char *pos = bitparse_headers_start; int result = 0; @@ -265,10 +275,10 @@ void FpgaDownloadAndGo(void) /* Successfully initialized the .bit parser. Find the 'e' section and * send its contents to the FPGA. */ - void *bitstream_start; + char *bitstream_start; unsigned int bitstream_length; if(bitparse_find_section('e', &bitstream_start, &bitstream_length)) { - DownloadFPGA((DWORD *)bitstream_start, bitstream_length/4, 0); + DownloadFPGA(bitstream_start, bitstream_length, 0); return; /* All done */ } @@ -282,7 +292,7 @@ void FpgaDownloadAndGo(void) * the bytewise download. */ if( *(DWORD*)0x102000 == 0xFFFFFFFF && *(DWORD*)0x102004 == 0xAA995566 ) - DownloadFPGA((DWORD *)0x102000, 10524, 1); + DownloadFPGA((char*)0x102000, 10524*4, 1); } void FpgaGatherVersion(char *dst, int len) @@ -290,26 +300,26 @@ void FpgaGatherVersion(char *dst, int len) char *fpga_info; unsigned int fpga_info_len; dst[0] = 0; - if(!bitparse_find_section('e', (void**)&fpga_info, &fpga_info_len)) { + if(!bitparse_find_section('e', &fpga_info, &fpga_info_len)) { strncat(dst, "FPGA image: legacy image without version information", len-1); } else { strncat(dst, "FPGA image built", len-1); /* USB packets only have 48 bytes data payload, so be terse */ #if 0 - if(bitparse_find_section('a', (void**)&fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) { + if(bitparse_find_section('a', &fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) { strncat(dst, " from ", len-1); strncat(dst, fpga_info, len-1); } - if(bitparse_find_section('b', (void**)&fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) { + if(bitparse_find_section('b', &fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) { strncat(dst, " for ", len-1); strncat(dst, fpga_info, len-1); } #endif - if(bitparse_find_section('c', (void**)&fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) { + if(bitparse_find_section('c', &fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) { strncat(dst, " on ", len-1); strncat(dst, fpga_info, len-1); } - if(bitparse_find_section('d', (void**)&fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) { + if(bitparse_find_section('d', &fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) { strncat(dst, " at ", len-1); strncat(dst, fpga_info, len-1); }