X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/ba8a80b30c4da36ef10854b53b06d9ff9acaca44..d4086fe2b78e1a3f4fa58901f2184cd10ffcaba5:/armsrc/fpgaloader.c diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index 88fdc4cf..86a7a405 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(); @@ -268,21 +278,21 @@ void FpgaDownloadAndGo(void) void *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 */ } } /* Fallback for the old flash image format: Check for the magic marker 0xFFFFFFFF - * 0xAA995566 at address 0x2000. This is raw bitstream with a size of 336,768 bits + * 0xAA995566 at address 0x102000. This is raw bitstream with a size of 336,768 bits * = 10,524 DWORDs, stored as DWORDS e.g. little-endian in memory, but each DWORD * is still to be transmitted in MSBit first order. Set the invert flag to indicate * that the DownloadFPGA function should invert every 4 byte sequence when doing * the bytewise download. */ - if( *(DWORD*)0x2000 == 0xFFFFFFFF && *(DWORD*)0x2004 == 0xAA995566 ) - DownloadFPGA((DWORD *)0x2000, 10524, 1); + if( *(DWORD*)0x102000 == 0xFFFFFFFF && *(DWORD*)0x102004 == 0xAA995566 ) + DownloadFPGA((char*)0x102000, 10524*4, 1); } void FpgaGatherVersion(char *dst, int len)