From 48e6e0a65af0225b8b1a678e305ac9e11e9fdccb Mon Sep 17 00:00:00 2001 From: skamkar Date: Tue, 4 Aug 2009 18:21:55 +0000 Subject: [PATCH 01/16] compile in OS X --- linux/usb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linux/usb.c b/linux/usb.c index 6337c21a..4f3b4e7e 100644 --- a/linux/usb.c +++ b/linux/usb.c @@ -153,11 +153,13 @@ usb_dev_handle* OpenProxmark(int verbose) { if (!handle) return NULL; +#ifndef __APPLE__ /* detach kernel driver first */ ret = usb_detach_kernel_driver_np(handle, iface); /* don't complain if no driver attached */ if (ret<0 && ret != -61 && verbose) fprintf(stderr, "detach kernel driver failed: (%d) %s!\n", ret, usb_strerror()); +#endif ret = usb_claim_interface(handle, iface); if (ret<0) { if (verbose) -- 2.39.5 From c0bc73bc35791d8a4f87f70d161bc2e4f303eb9d Mon Sep 17 00:00:00 2001 From: d18c7db Date: Wed, 5 Aug 2009 08:11:09 +0000 Subject: [PATCH 02/16] Junk Eclipse environment files. Not source code. --- .cdtproject | 88 --------------------------------------- .cproject | 118 ---------------------------------------------------- .project | 85 ------------------------------------- 3 files changed, 291 deletions(-) delete mode 100644 .cdtproject delete mode 100644 .cproject delete mode 100644 .project diff --git a/.cdtproject b/.cdtproject deleted file mode 100644 index 07ab80bb..00000000 --- a/.cdtproject +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -make - -all -false -true - - -make - -all -false -true - - -make --f Makefile.linux -all -false -false - - -make --f Makefile.linux -clean -false -false - - - - - diff --git a/.cproject b/.cproject deleted file mode 100644 index c157cc59..00000000 --- a/.cproject +++ /dev/null @@ -1,118 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -make --f Makefile.linux -all -false -false -true - - -make --f Makefile.linux -clean -false -false -true - - -make - -all -false -true -true - - -make - -clean -false -true -true - - -make --f Makefile.linux -all -false -false -true - - -make --f Makefile.linux -clean -false -false -true - - - - - - diff --git a/.project b/.project deleted file mode 100644 index 0ad67cd4..00000000 --- a/.project +++ /dev/null @@ -1,85 +0,0 @@ - - - Proxmark3-SVN - - - - - - org.eclipse.cdt.make.core.makeBuilder - clean,full,incremental, - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.stopOnError - false - - - org.eclipse.cdt.make.core.enabledIncrementalBuild - true - - - org.eclipse.cdt.make.core.build.command - make - - - org.eclipse.cdt.make.core.build.target.inc - all - - - org.eclipse.cdt.make.core.build.arguments - - - - org.eclipse.cdt.make.core.environment - PATH=/usr/local/new/gnuarm-4.3.0/bin:/home/lafargue/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games| - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - true - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.build.target.auto - all - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.build.target.clean - clean - - - org.eclipse.cdt.make.core.build.location - - - - org.eclipse.cdt.core.errorOutputParser - org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.VCErrorParser; - - - - - org.eclipse.cdt.make.core.ScannerConfigBuilder - - - - - - org.eclipse.cdt.core.cnature - org.eclipse.cdt.make.core.makeNature - org.eclipse.cdt.make.core.ScannerConfigNature - - -- 2.39.5 From 7381e8f2f285aad4ce3919fa1964638cc08c3899 Mon Sep 17 00:00:00 2001 From: d18c7db Date: Thu, 6 Aug 2009 12:53:06 +0000 Subject: [PATCH 03/16] Added tiread command to demod TI tags on the PM3 --- armsrc/appmain.c | 16 +--- armsrc/apps.h | 2 +- armsrc/lfops.c | 230 +++++++++++++++++++++++++++++++++++---------- include/usb_cmd.h | 2 - winsrc/command.cpp | 169 ++++++++++++++------------------- 5 files changed, 255 insertions(+), 164 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 7dba687f..74448fe5 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -597,10 +597,6 @@ void UsbPacketReceived(BYTE *packet, int len) LED_D_OFF(); // LED D indicates field ON or OFF break; - case CMD_ACQUIRE_RAW_BITS_TI_TYPE: - AcquireRawBitsTI(); - break; - case CMD_READ_TI_TYPE: ReadTItag(); break; @@ -609,8 +605,7 @@ void UsbPacketReceived(BYTE *packet, int len) WriteTItag(c->ext1,c->ext2,c->ext3); break; - case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K: - case CMD_DOWNLOAD_RAW_BITS_TI_TYPE: { + case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K: { UsbCommand n; if(c->cmd == CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K) { n.cmd = CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K; @@ -632,11 +627,6 @@ void UsbPacketReceived(BYTE *packet, int len) SimulateTagLowFrequency(c->ext1, 1); LED_A_OFF(); break; -#ifdef WITH_LCD - case CMD_LCD_RESET: - LCDReset(); - break; -#endif case CMD_READ_MEM: ReadMem(c->ext1); break; @@ -644,6 +634,9 @@ void UsbPacketReceived(BYTE *packet, int len) FpgaSendCommand(FPGA_CMD_SET_DIVISOR, c->ext1); break; #ifdef WITH_LCD + case CMD_LCD_RESET: + LCDReset(); + break; case CMD_LCD: LCDSend(c->ext1); break; @@ -660,7 +653,6 @@ void UsbPacketReceived(BYTE *packet, int len) } break; - default: DbpString("unknown command"); break; diff --git a/armsrc/apps.h b/armsrc/apps.h index af6006e7..878ec526 100644 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@ -9,7 +9,7 @@ // The large multi-purpose buffer, typically used to hold A/D samples, // maybe processed in some way. -DWORD BigBuf[10000]; +DWORD BigBuf[12000]; /// appmain.h void ReadMem(int addr); diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 6ac4e725..f9aee43e 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -115,15 +115,181 @@ void ModThenAcquireRawAdcSamples125k(int delay_off,int period_0,int period_1,BYT DoAcquisition125k(at134khz); } +/* blank r/w tag data stream +...0000000000000000 01111111 +1010101010101010101010101010101010101010101010101010101010101010 +0011010010100001 +01111111 +101010101010101[0]000... + +[5555fe852c5555555555555555fe0000] +*/ +void ReadTItag() +{ + // some hardcoded initial params + // when we read a TI tag we sample the zerocross line at 2Mhz + // TI tags modulate a 1 as 16 cycles of 123.2Khz + // TI tags modulate a 0 as 16 cycles of 134.2Khz + #define FSAMPLE 2000000 + #define FREQLO 123200 + #define FREQHI 134200 + + signed char *dest = (signed char *)BigBuf; + int n = sizeof(BigBuf); +// int *dest = GraphBuffer; +// int n = GraphTraceLen; + + // 128 bit shift register [shift3:shift2:shift1:shift0] + DWORD shift3 = 0, shift2 = 0, shift1 = 0, shift0 = 0; + + int i, cycles=0, samples=0; + // how many sample points fit in 16 cycles of each frequency + DWORD sampleslo = (FSAMPLE<<4)/FREQLO, sampleshi = (FSAMPLE<<4)/FREQHI; + // when to tell if we're close enough to one freq or another + DWORD threshold = (sampleslo - sampleshi + 1)>>1; + + // TI tags charge at 134.2Khz + FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz + + // Place FPGA in passthrough mode, in this mode the CROSS_LO line + // connects to SSP_DIN and the SSP_DOUT logic level controls + // whether we're modulating the antenna (high) + // or listening to the antenna (low) + FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_PASSTHRU); + + // get TI tag data into the buffer + AcquireTiType(); + + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + + for (i=0; i0) ) { + cycles++; + // after 16 cycles, measure the frequency + if (cycles>15) { + cycles=0; + samples=i-samples; // number of samples in these 16 cycles + + // TI bits are coming to us lsb first so shift them + // right through our 128 bit right shift register + shift0 = (shift0>>1) | (shift1 << 31); + shift1 = (shift1>>1) | (shift2 << 31); + shift2 = (shift2>>1) | (shift3 << 31); + shift3 >>= 1; + + // check if the cycles fall close to the number + // expected for either the low or high frequency + if ( (samples>(sampleslo-threshold)) && (samples<(sampleslo+threshold)) ) { + // low frequency represents a 1 + shift3 |= (1<<31); + } else if ( (samples>(sampleshi-threshold)) && (samples<(sampleshi+threshold)) ) { + // high frequency represents a 0 + } else { + // probably detected a gay waveform or noise + // use this as gaydar or discard shift register and start again + shift3 = shift2 = shift1 = shift0 = 0; + } + samples = i; + + // for each bit we receive, test if we've detected a valid tag + + // if we see 17 zeroes followed by 6 ones, we might have a tag + // remember the bits are backwards + if ( ((shift0 & 0x7fffff) == 0x7e0000) ) { + // if start and end bytes match, we have a tag so break out of the loop + if ( ((shift0>>16)&0xff) == ((shift3>>8)&0xff) ) { + cycles = 0xF0B; //use this as a flag (ugly but whatever) + break; + } + } + } + } + } + + // if flag is set we have a tag + if (cycles!=0xF0B) { + DbpString("Info: No valid tag detected."); + } else { + // put 64 bit data into shift1 and shift0 + shift0 = (shift0>>24) | (shift1 << 8); + shift1 = (shift1>>24) | (shift2 << 8); + + // align 16 bit crc into lower half of shift2 + shift2 = ((shift2>>24) | (shift3 << 8)) & 0x0ffff; + + // if r/w tag, check ident match + if ( shift3&(1<<15) ) { + DbpString("Info: TI tag is rewriteable"); + // only 15 bits compare, last bit of ident is not valid + if ( ((shift3>>16)^shift0)&0x7fff ) { + DbpString("Error: Ident mismatch!"); + } else { + DbpString("Info: TI tag ident is valid"); + } + } else { + DbpString("Info: TI tag is readonly"); + } + + // WARNING the order of the bytes in which we calc crc below needs checking + // i'm 99% sure the crc algorithm is correct, but it may need to eat the + // bytes in reverse or something + // calculate CRC + DWORD crc=0; + + crc = update_crc16(crc, (shift0)&0xff); + crc = update_crc16(crc, (shift0>>8)&0xff); + crc = update_crc16(crc, (shift0>>16)&0xff); + crc = update_crc16(crc, (shift0>>24)&0xff); + crc = update_crc16(crc, (shift1)&0xff); + crc = update_crc16(crc, (shift1>>8)&0xff); + crc = update_crc16(crc, (shift1>>16)&0xff); + crc = update_crc16(crc, (shift1>>24)&0xff); + + DbpString("Info: Tag data_hi, data_lo, crc = "); + DbpIntegers(shift1, shift0, shift2&0xffff); + if (crc != (shift2&0xffff)) { + DbpString("Error: CRC mismatch, expected"); + DbpIntegers(0, 0, crc); + } else { + DbpString("Info: CRC is good"); + } + } +} + +void WriteTIbyte(BYTE b) +{ + int i = 0; + + // modulate 8 bits out to the antenna + for (i=0; i<8; i++) + { + if (b&(1<= n) return; + i++; if(i >= TIBUFLEN) break; } WDT_HIT(); } @@ -171,54 +337,22 @@ void AcquireTiType(void) // return stolen pin to SSP PIO_DISABLE = (1<=0; i--) { +// DbpIntegers(0, 0, BigBuf[i]); + for (j=0; j<32; j++) { + if(BigBuf[i] & (1 << j)) { + dest[--n] = 1; + } else { + dest[--n] = -1; + } } } } -void AcquireRawBitsTI(void) -{ - // TI tags charge at 134.2Khz - FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz - - // Place FPGA in passthrough mode, in this mode the CROSS_LO line - // connects to SSP_DIN and the SSP_DOUT logic level controls - // whether we're modulating the antenna (high) - // or listening to the antenna (low) - FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_PASSTHRU); - - // get TI tag data into the buffer - AcquireTiType(); - - FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); -} - // arguments: 64bit data split into 32bit idhi:idlo and optional 16bit crc // if crc provided, it will be written with the data verbatim (even if bogus) // if not provided a valid crc will be computed from the data and written. @@ -292,7 +426,7 @@ void WriteTItag(DWORD idhi, DWORD idlo, WORD crc) AcquireTiType(); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); - DbpString("Now use tibits and tidemod"); + DbpString("Now use tiread to check"); } void SimulateTagLowFrequency(int period, int ledcontrol) diff --git a/include/usb_cmd.h b/include/usb_cmd.h index 8245bae2..6818bb5e 100644 --- a/include/usb_cmd.h +++ b/include/usb_cmd.h @@ -37,8 +37,6 @@ typedef struct { #define CMD_READ_MEM 0x0106 // For low-frequency tags -#define CMD_ACQUIRE_RAW_BITS_TI_TYPE 0x0200 -#define CMD_DOWNLOAD_RAW_BITS_TI_TYPE 0x0201 #define CMD_READ_TI_TYPE 0x0202 #define CMD_WRITE_TI_TYPE 0x0203 #define CMD_DOWNLOADED_RAW_BITS_TI_TYPE 0x0204 diff --git a/winsrc/command.cpp b/winsrc/command.cpp index 454fbab2..08feb3dd 100644 --- a/winsrc/command.cpp +++ b/winsrc/command.cpp @@ -1397,45 +1397,6 @@ static void CmdHi15demod(char *str) PrintToScrollback("CRC=%04x", Iso15693Crc(outBuf, k-2)); } -static void CmdTIReadRaw(char *str) -{ - UsbCommand c; - c.cmd = CMD_ACQUIRE_RAW_BITS_TI_TYPE; - SendCommand(&c, FALSE); -} - -static void CmdTIBits(char *str) -{ - int cnt = 0; - int i; -// for(i = 0; i < 1536; i += 12) { - for(i = 0; i < 4000; i += 12) { - UsbCommand c; - c.cmd = CMD_DOWNLOAD_RAW_BITS_TI_TYPE; - c.ext1 = i; - SendCommand(&c, FALSE); - ReceiveCommand(&c); - if(c.cmd != CMD_DOWNLOADED_RAW_BITS_TI_TYPE) { - PrintToScrollback("bad resp"); - return; - } - int j; - for(j = 0; j < 12; j++) { - int k; - for(k = 31; k >= 0; k--) { - if(c.d.asDwords[j] & (1 << k)) { - GraphBuffer[cnt++] = 1; - } else { - GraphBuffer[cnt++] = -1; - } - } - } - } -// GraphTraceLen = 1536*32; - GraphTraceLen = 4000*32; - RepaintGraphWindow(); -} - static void CmdFSKdemod(char *cmdline) { static const int LowTone[] = { @@ -1454,13 +1415,13 @@ static void CmdFSKdemod(char *cmdline) 1, 1, 1, 1, -1, -1, -1, -1, -1, }; - int convLen = max(arraylen(HighTone), arraylen(LowTone)); + int lowLen = sizeof(LowTone)/sizeof(int); + int highLen = sizeof(HighTone)/sizeof(int); + int convLen = (highLen>lowLen)?highLen:lowLen; DWORD hi = 0, lo = 0; int i, j; int minMark=0, maxMark=0; - int lowLen = arraylen(LowTone); - int highLen = arraylen(HighTone); for(i = 0; i < GraphTraceLen - convLen; i++) { int lowSum = 0, highSum = 0; @@ -1499,10 +1460,10 @@ static void CmdFSKdemod(char *cmdline) int max = 0, maxPos = 0; for(i = 0; i < 6000; i++) { int dec = 0; - for(j = 0; j < 3*arraylen(LowTone); j++) { + for(j = 0; j < 3*lowLen; j++) { dec -= GraphBuffer[i+j]; } - for(; j < 3*(arraylen(LowTone) + arraylen(HighTone) ); j++) { + for(; j < 3*(lowLen + highLen ); j++) { dec += GraphBuffer[i+j]; } if(dec > max) { @@ -1522,7 +1483,7 @@ static void CmdFSKdemod(char *cmdline) GraphBuffer[maxPos+1] = minMark; PrintToScrollback("actual data bits start at sample %d", maxPos); - PrintToScrollback("length %d/%d", arraylen(HighTone), arraylen(LowTone)); + PrintToScrollback("length %d/%d", highLen, lowLen); BYTE bits[46]; bits[sizeof(bits)-1] = '\0'; @@ -1530,10 +1491,10 @@ static void CmdFSKdemod(char *cmdline) // find bit pairs and manchester decode them for(i = 0; i < arraylen(bits)-1; i++) { int dec = 0; - for(j = 0; j < arraylen(LowTone); j++) { + for(j = 0; j < lowLen; j++) { dec -= GraphBuffer[maxPos+j]; } - for(; j < arraylen(LowTone) + arraylen(HighTone); j++) { + for(; j < lowLen + highLen; j++) { dec += GraphBuffer[maxPos+j]; } maxPos += j; @@ -1574,7 +1535,7 @@ static void CmdTIWrite(char *str) res = sscanf(str, "0x%x 0x%x 0x%x ", &c.ext1, &c.ext2, &c.ext3); if (res == 2) c.ext3=0; if (res<2) - PrintToScrollback("Please specify 2 or three hex strings, eg 0x1234 0x5678"); + PrintToScrollback("Please specify the data as two hex strings, optionally the CRC as a third"); else SendCommand(&c, FALSE); } @@ -1595,52 +1556,57 @@ h = 2*pi*ones(1, floor(f_s*T_h))*(f_h/f_s); l = sign(sin(cumsum(l))); h = sign(sin(cumsum(h))); */ + +// 2M*16/134.2k = 238 static const int LowTone[] = { - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1 }; +// 2M*16/123.2k = 260 static const int HighTone[] = { - 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, + 1, 1, 1, 1, 1, 1, 1, 1 }; - - int convLen = max(arraylen(HighTone), arraylen(LowTone)); + int lowLen = sizeof(LowTone)/sizeof(int); + int highLen = sizeof(HighTone)/sizeof(int); + int convLen = (highLen>lowLen)?highLen:lowLen; WORD crc; - int i, TagType; + int i, j, TagType; + int lowSum = 0, highSum = 0;; + int lowTot = 0, highTot = 0; + for(i = 0; i < GraphTraceLen - convLen; i++) { - int j; - int lowSum = 0, highSum = 0;; - int lowLen = arraylen(LowTone); - int highLen = arraylen(HighTone); + lowSum = 0; + highSum = 0;; for(j = 0; j < lowLen; j++) { lowSum += LowTone[j]*GraphBuffer[i+j]; @@ -1650,12 +1616,15 @@ h = sign(sin(cumsum(h))); } lowSum = abs((100*lowSum) / lowLen); highSum = abs((100*highSum) / highLen); + lowSum = (lowSum<0)?-lowSum:lowSum; + highSum = (highSum<0)?-highSum:highSum; + GraphBuffer[i] = (highSum << 16) | lowSum; } for(i = 0; i < GraphTraceLen - convLen - 16; i++) { - int j; - int lowTot = 0, highTot = 0; + lowTot = 0; + highTot = 0; // 16 and 15 are f_s divided by f_l and f_h, rounded for(j = 0; j < 16; j++) { lowTot += (GraphBuffer[i+j] & 0xffff); @@ -1688,11 +1657,11 @@ h = sign(sin(cumsum(h))); int j; int dec = 0; // searching 17 consecutive lows - for(j = 0; j < 17*arraylen(LowTone); j++) { + for(j = 0; j < 17*lowLen; j++) { dec -= GraphBuffer[i+j]; } // searching 7 consecutive highs - for(; j < 17*arraylen(LowTone) + 6*arraylen(HighTone); j++) { + for(; j < 17*lowLen + 6*highLen; j++) { dec += GraphBuffer[i+j]; } if(dec > max) { @@ -1707,8 +1676,8 @@ h = sign(sin(cumsum(h))); GraphBuffer[maxPos+1] = -800; // advance pointer to start of actual data stream (after 16 pre and 8 start bits) - maxPos += 17*arraylen(LowTone); - maxPos += 6*arraylen(HighTone); + maxPos += 17*lowLen; + maxPos += 6*highLen; // place a marker in the buffer to visually aid location // of the end of sync @@ -1717,7 +1686,7 @@ h = sign(sin(cumsum(h))); PrintToScrollback("actual data bits start at sample %d", maxPos); - PrintToScrollback("length %d/%d", arraylen(HighTone), arraylen(LowTone)); + PrintToScrollback("length %d/%d", highLen, lowLen); BYTE bits[1+64+16+8+16]; bits[sizeof(bits)-1] = '\0'; @@ -1728,21 +1697,21 @@ h = sign(sin(cumsum(h))); int high = 0; int low = 0; int j; - for(j = 0; j < arraylen(LowTone); j++) { + for(j = 0; j < lowLen; j++) { low -= GraphBuffer[maxPos+j]; } - for(j = 0; j < arraylen(HighTone); j++) { + for(j = 0; j < highLen; j++) { high += GraphBuffer[maxPos+j]; } if(high > low) { bits[i] = '1'; - maxPos += arraylen(HighTone); + maxPos += highLen; // bitstream arrives lsb first so shift right shift3 |= (1<<31); } else { bits[i] = '.'; - maxPos += arraylen(LowTone); + maxPos += lowLen; } // 128 bit right shift register @@ -2870,9 +2839,7 @@ static struct { {"scale", CmdScale, 1, " -- Set cursor display scale"}, {"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"}, {"sri512read", CmdSri512read, 0, " -- Read contents of a SRI512 tag"}, - {"tibits", CmdTIBits, 0, "Get raw bits for TI-type LF tag"}, {"tidemod", CmdTIDemod, 1, "Demodulate raw bits for TI-type LF tag"}, - {"tireadraw", CmdTIReadRaw, 0, "Read a TI-type 134 kHz tag in raw mode"}, {"tiread", CmdTIRead, 0, "Read and decode a TI 134 kHz tag"}, {"tiwrite", CmdTIWrite, 0, "Write new data to a r/w TI 134 kHz tag"}, {"threshold", CmdThreshold, 1, "Maximize/minimize every value in the graph window depending on threshold"}, -- 2.39.5 From 14ac2f1ea0abcc336e698c5f99b36468d6d22cac Mon Sep 17 00:00:00 2001 From: skamkar Date: Sat, 8 Aug 2009 05:50:54 +0000 Subject: [PATCH 04/16] look for binary data in other data --- tools/rfidtest.pl | 119 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 tools/rfidtest.pl diff --git a/tools/rfidtest.pl b/tools/rfidtest.pl new file mode 100644 index 00000000..db898d32 --- /dev/null +++ b/tools/rfidtest.pl @@ -0,0 +1,119 @@ +#!/usr/bin/perl +# -samy kamkar, rfid@samy.pl + +use strict; + +die "usage: $0 \n" unless @ARGV == 2; + +my ($file, $search) = @ARGV; +$search =~ s/\s//g; + +# sure, these aren't perfect, but simplifies usability if you know what you're doing +# if in doubt, use binary + +# binary, cool +if ($search =~ /^[01]+$/) { } +# decimal +elsif ($search =~ /^\d+$/) +{ + $search = unpack("B*", pack("N", $search)); + $search =~ s/^0*//; +} +# hex +elsif ($search =~ /^[\da-fA-F]+$/) +{ + $search = unpack("B*", pack("H*", $search)); + $search =~ s/^0*//; +} +# ascii +else +{ + $search = unpack("B*", $search); + $search =~ s/^0*//; +} + + +# read file contents +open(F, "<$file") || die "Can't read $file: $!"; +my $data = join("", ); +close(F); + +# convert to binary +$data =~ s/\s//g; +# binary, great +if ($data =~ /^[01]+$/) { } +elsif ($data =~ /^[\da-fA-F]+$/) +{ + $data = unpack("B*", pack("H*", $data)); + $search =~ s/^0*//; +} +else +{ + die "Seriously. What sort of data is this file? Binary or hex only please.\n"; +} + + +# search every method we know how +print "Testing normally...\n"; +test_all($data, $search); + +print "Testing with flipped bits...\n"; +test_all($data, $search, 1); + +# now try manchester demodulating +my @bits = split(//, $data); +my $man; +my $last = 0; +for (my $i = 1; $i < @bits; $i++) +{ + # if we changed, flip our bit + if ($bits[$i-1] == 1) + { + $last ^= 1; + } + $man .= $last; +} + +print "Testing with manchester demodulation...\n"; +test_all($man, $search); + +print "Testing with flipped manchester demodulation...\n"; +test_all($man, $search, 1); + + +sub test_all +{ + my ($data, $search, $flip) = @_; + + if ($flip) + { + $data =~ s/(.)/$1 ^ 1/eg; + } + + # first just see if our data is in the stream + if ($data =~ /$search/) + { + print "Found $search in our stream ($data)\n"; + } + + # try removing parity every 4 and 8 bits + foreach my $parity (4, 8) + { + # try removing a parity bit every $parity bits + # test by cutting off a bit at a time in case we're in the wrong bit position + my $tmp = $data; + foreach (1 .. $parity) + { + my $test = $tmp; + $test =~ s/(.{$parity})./$1/g; + + if ($test =~ /$search/) + { + print "Found $search with parity every " . ($parity + 1) . "th bit, round $_ out of $parity ($test)\n"; + } + + # chop of a bit to change our bit position next round + $tmp =~ s/^.//; + } + } +} -- 2.39.5 From 50722269b6e7b1ce8601ee2fc8d30100e5639d34 Mon Sep 17 00:00:00 2001 From: skamkar Date: Sat, 8 Aug 2009 07:42:51 +0000 Subject: [PATCH 05/16] detect usb or no usb for standalone mode [ryan] --- armsrc/appmain.c | 13 ++++++------- common/usb.c | 8 ++++++++ include/proxmark3.h | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 74448fe5..33df93c4 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -13,7 +13,6 @@ #include "LCD.h" #endif -int usbattached = 0; //============================================================================= // A buffer where we can queue things up to be sent through the FPGA, for @@ -64,8 +63,8 @@ void ToSendStuffBit(int b) void DbpString(char *str) { /* this holds up stuff unless we're connected to usb */ -// if (!usbattached) -// return; + if (!UsbConnected()) + return; UsbCommand c; c.cmd = CMD_DEBUG_PRINT_STRING; @@ -80,8 +79,8 @@ void DbpString(char *str) void DbpIntegers(int x1, int x2, int x3) { /* this holds up stuff unless we're connected to usb */ -// if (!usbattached) -// return; + if (!UsbConnected()) + return; UsbCommand c; c.cmd = CMD_DEBUG_PRINT_INTEGERS; @@ -266,7 +265,7 @@ void SamyRun() for (;;) { - usbattached = UsbPoll(FALSE); + UsbPoll(FALSE); WDT_HIT(); // Was our button held down or pressed? @@ -715,7 +714,7 @@ void AppMain(void) #endif for(;;) { - usbattached = UsbPoll(FALSE); + UsbPoll(FALSE); WDT_HIT(); if (BUTTON_HELD(1000) > 0) diff --git a/common/usb.c b/common/usb.c index f0b95291..50a9fc69 100644 --- a/common/usb.c +++ b/common/usb.c @@ -436,6 +436,14 @@ void UsbStart(void) } } +BOOL UsbConnected() +{ + if (UDP_GLOBAL_STATE & UDP_GLOBAL_STATE_CONFIGURED) + return TRUE; + else + return FALSE; +} + BOOL UsbPoll(BOOL blinkLeds) { BOOL ret = FALSE; diff --git a/include/proxmark3.h b/include/proxmark3.h index a94435e8..2f3b4838 100644 --- a/include/proxmark3.h +++ b/include/proxmark3.h @@ -52,6 +52,7 @@ typedef signed short SWORD; // USB declarations void UsbSendPacket(BYTE *packet, int len); +BOOL UsbConnected(); BOOL UsbPoll(BOOL blinkLeds); void UsbStart(void); -- 2.39.5 From 2ff385b2a8e182d4465d9fb43dd21d7879fc5369 Mon Sep 17 00:00:00 2001 From: skamkar Date: Sat, 8 Aug 2009 07:43:57 +0000 Subject: [PATCH 06/16] unnecessary --- LOG.txt | 3 --- README-gj.txt | 28 ---------------------------- 2 files changed, 31 deletions(-) delete mode 100644 LOG.txt delete mode 100644 README-gj.txt diff --git a/LOG.txt b/LOG.txt deleted file mode 100644 index 43d215c1..00000000 --- a/LOG.txt +++ /dev/null @@ -1,3 +0,0 @@ - -MAY 2008: Added ISO14443 type A support, Gerhard de Koning Gans - diff --git a/README-gj.txt b/README-gj.txt deleted file mode 100644 index 9ce27983..00000000 --- a/README-gj.txt +++ /dev/null @@ -1,28 +0,0 @@ -Modifications to 20081211 release by d18c7db on proxmark.org - -This compiles fine under the pre-built windows compile environment ProxSpace - -I make no apologies for the utterly cr@p coding. It's rubbish, you've been warned. - -Changes made to armsrc and winsrc, no changed to fpga code. Works fine with the bootloader and fpga images that you will build using the 20081211 release. - - -Extra functionality includes: - -ISO1443a support -================ - -i) Support for cascade 2 select (used for UID's longer than 4 bytes) -ii) Hard-coded (some) responses in for DESfire - - -ISO15563 support -================ - -i) demodulation all moved onto the arm -ii) Addition of a command, hi15reader (a reader simulator) -iii) Addition of a command, hi15sim (a tag simulator) - not working too well - - - -greg.jones@digitalassurance.com \ No newline at end of file -- 2.39.5 From a5d5146c4892355b04201fcd17674b5f20d6adae Mon Sep 17 00:00:00 2001 From: d18c7db Date: Tue, 11 Aug 2009 10:05:52 +0000 Subject: [PATCH 07/16] Junk Eclipse environment files. Not source code. --- .settings/org.eclipse.cdt.core.prefs | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .settings/org.eclipse.cdt.core.prefs diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs deleted file mode 100644 index a0061784..00000000 --- a/.settings/org.eclipse.cdt.core.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Tue Apr 21 17:19:37 CEST 2009 -eclipse.preferences.version=1 -indexerId=org.eclipse.cdt.core.fastIndexer -- 2.39.5 From bea2a8660edd6cabce704207548d669761ef4a6d Mon Sep 17 00:00:00 2001 From: "henryk@ploetzli.ch" Date: Wed, 19 Aug 2009 23:35:35 +0000 Subject: [PATCH 08/16] Add pretty field strength lights for ListenReaderField() also in LF mode. --- armsrc/appmain.c | 146 +++++++++++++++++++++-------------------------- 1 file changed, 65 insertions(+), 81 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 33df93c4..a3871eb6 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -372,56 +372,47 @@ your antenna. You will probably not get some good results if there is a LF and a at the same place! :-) LIGHT SCHEME USED: - -Light scheme | Descriptiong ----------------------------------------------------- - ---- | No field detected - X--- | 14% of maximum current detected - -X-- | 29% of maximum current detected - --X- | 43% of maximum current detected - ---X | 57% of maximum current detected - --XX | 71% of maximum current detected - -XXX | 86% of maximum current detected - XXXX | 100% of maximum current detected - -TODO: -Add the LF part for MODE 2 - */ +static const char LIGHT_SCHEME[] = { + 0x0, /* ---- | No field detected */ + 0x1, /* X--- | 14% of maximum current detected */ + 0x2, /* -X-- | 29% of maximum current detected */ + 0x4, /* --X- | 43% of maximum current detected */ + 0x8, /* ---X | 57% of maximum current detected */ + 0xC, /* --XX | 71% of maximum current detected */ + 0xE, /* -XXX | 86% of maximum current detected */ + 0xF, /* XXXX | 100% of maximum current detected */ +}; +static const int LIGHT_LEN = sizeof(LIGHT_SCHEME)/sizeof(LIGHT_SCHEME[0]); + void ListenReaderField(int limit) { - int lf_av, lf_av_new, lf_baseline= 0, lf_count= 0; + int lf_av, lf_av_new, lf_baseline= 0, lf_count= 0, lf_max; int hf_av, hf_av_new, hf_baseline= 0, hf_count= 0, hf_max; - int mode=1; + int mode=1, display_val, display_max, i; #define LF_ONLY 1 #define HF_ONLY 2 - LED_A_OFF(); - LED_B_OFF(); - LED_C_OFF(); - LED_D_OFF(); + LEDsoff(); - lf_av= ReadAdc(ADC_CHAN_LF); + lf_av=lf_max=ReadAdc(ADC_CHAN_LF); - if(limit != HF_ONLY) - { + if(limit != HF_ONLY) { DbpString("LF 125/134 Baseline:"); DbpIntegers(lf_av,0,0); lf_baseline= lf_av; - } + } hf_av=hf_max=ReadAdc(ADC_CHAN_HF); - if (limit != LF_ONLY) - { + if (limit != LF_ONLY) { DbpString("HF 13.56 Baseline:"); DbpIntegers(hf_av,0,0); hf_baseline= hf_av; - } + } - for(;;) - { + for(;;) { if (BUTTON_PRESS()) { SpinDelay(500); switch (mode) { @@ -432,85 +423,78 @@ void ListenReaderField(int limit) case 2: default: DbpString("Stopped"); - LED_A_OFF(); - LED_B_OFF(); - LED_C_OFF(); - LED_D_OFF(); + LEDsoff(); return; break; } } WDT_HIT(); - if (limit != HF_ONLY) - { - if (abs(lf_av - lf_baseline) > 10) - LED_D_ON(); - else - LED_D_OFF(); + if (limit != HF_ONLY) { + if(mode==1) { + if (abs(lf_av - lf_baseline) > 10) LED_D_ON(); + else LED_D_OFF(); + } + ++lf_count; lf_av_new= ReadAdc(ADC_CHAN_LF); // see if there's a significant change - if(abs(lf_av - lf_av_new) > 10) - { + if(abs(lf_av - lf_av_new) > 10) { DbpString("LF 125/134 Field Change:"); DbpIntegers(lf_av,lf_av_new,lf_count); lf_av= lf_av_new; + if (lf_av > lf_max) + lf_max = lf_av; lf_count= 0; - } } + } - if (limit != LF_ONLY) - { - if (abs(hf_av - hf_baseline) > 10) { - if (mode == 1) - LED_B_ON(); - if (mode == 2) { - if ( hf_av>(hf_max/7)*6) { - LED_A_ON(); LED_B_ON(); LED_C_ON(); LED_D_ON(); - } - if ( (hf_av>(hf_max/7)*5) && (hf_av<=(hf_max/7)*6) ) { - LED_A_ON(); LED_B_ON(); LED_C_OFF(); LED_D_ON(); - } - if ( (hf_av>(hf_max/7)*4) && (hf_av<=(hf_max/7)*5) ) { - LED_A_OFF(); LED_B_ON(); LED_C_OFF(); LED_D_ON(); - } - if ( (hf_av>(hf_max/7)*3) && (hf_av<=(hf_max/7)*4) ) { - LED_A_OFF(); LED_B_OFF(); LED_C_OFF(); LED_D_ON(); - } - if ( (hf_av>(hf_max/7)*2) && (hf_av<=(hf_max/7)*3) ) { - LED_A_OFF(); LED_B_ON(); LED_C_OFF(); LED_D_OFF(); - } - if ( (hf_av>(hf_max/7)*1) && (hf_av<=(hf_max/7)*2) ) { - LED_A_ON(); LED_B_OFF(); LED_C_OFF(); LED_D_OFF(); - } - if ( (hf_av>(hf_max/7)*0) && (hf_av<=(hf_max/7)*1) ) { - LED_A_OFF(); LED_B_OFF(); LED_C_ON(); LED_D_OFF(); - } - } - } else { - if (mode == 1) { - LED_B_OFF(); - } - if (mode == 2) { - LED_A_OFF(); LED_B_OFF(); LED_C_OFF(); LED_D_OFF(); - } + if (limit != LF_ONLY) { + if (mode == 1){ + if (abs(hf_av - hf_baseline) > 10) LED_B_ON(); + else LED_B_OFF(); } - + ++hf_count; hf_av_new= ReadAdc(ADC_CHAN_HF); // see if there's a significant change - if(abs(hf_av - hf_av_new) > 10) - { + if(abs(hf_av - hf_av_new) > 10) { DbpString("HF 13.56 Field Change:"); DbpIntegers(hf_av,hf_av_new,hf_count); hf_av= hf_av_new; if (hf_av > hf_max) hf_max = hf_av; hf_count= 0; + } + } + + if(mode == 2) { + if (limit == LF_ONLY) { + display_val = lf_av; + display_max = lf_max; + } else if (limit == HF_ONLY) { + display_val = hf_av; + display_max = hf_max; + } else { /* Pick one at random */ + if( (hf_max - hf_baseline) > (lf_max - lf_baseline) ) { + display_val = hf_av; + display_max = hf_max; + } else { + display_val = lf_av; + display_max = lf_max; + } + } + for (i=0; i= ((display_max/LIGHT_LEN)*i) && display_val <= ((display_max/LIGHT_LEN)*(i+1))) { + if (LIGHT_SCHEME[i] & 0x1) LED_C_ON(); else LED_C_OFF(); + if (LIGHT_SCHEME[i] & 0x2) LED_A_ON(); else LED_A_OFF(); + if (LIGHT_SCHEME[i] & 0x4) LED_B_ON(); else LED_B_OFF(); + if (LIGHT_SCHEME[i] & 0x8) LED_D_ON(); else LED_D_OFF(); + break; } } } + } } void UsbPacketReceived(BYTE *packet, int len) -- 2.39.5 From 093cbaf63e09d4472f7f923541521e611ed77daa Mon Sep 17 00:00:00 2001 From: "adam@algroup.co.uk" Date: Mon, 24 Aug 2009 12:09:43 +0000 Subject: [PATCH 09/16] fix Mifare AUTH for hi14areader command --- armsrc/iso14443a.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index c5557d39..6cd217f1 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -914,8 +914,6 @@ static const BYTE response2a[] = { 0x51, 0x48, 0x1d, 0x80, 0x84 }; // uid - cas BYTE response3a[] = { 0x20, 0x00, 0x00 }; // SAK Select (cascade2) successful response (DESFire) ComputeCrc14443(CRC_14443_A, response3a, 1, &response3a[1], &response3a[2]); -// When reader tries to authenticate - // static const BYTE cmd5[] = { 0x60, 0x00, 0xf5, 0x7b }; static const BYTE response5[] = { 0x00, 0x00, 0x00, 0x00 }; // Very random tag nonce BYTE *resp; @@ -1503,6 +1501,9 @@ void ReaderIso14443a(DWORD parameter) //BYTE cmd6[] = { 0xe0,0x50,0xbc,0xa5 }; // original RATS BYTE cmd6[] = { 0xe0,0x21,0xb2,0xc7 }; // Desfire RATS + // Mifare AUTH + BYTE cmd7[] = { 0x60, 0x00, 0x00, 0x00 }; + int reqaddr = 2024; // was 2024 - tied to other size changes int reqsize = 60; @@ -1525,8 +1526,8 @@ void ReaderIso14443a(DWORD parameter) BYTE *req6 = (((BYTE *)BigBuf) + reqaddr + (reqsize * 5)); int req6Len; - //BYTE *req7 = (((BYTE *)BigBuf) + reqaddr + (reqsize * 6)); - //int req7Len; + BYTE *req7 = (((BYTE *)BigBuf) + reqaddr + (reqsize * 6)); + int req7Len; BYTE *receivedAnswer = (((BYTE *)BigBuf) + 3560); // was 3560 - tied to other size changes @@ -1771,13 +1772,15 @@ void ReaderIso14443a(DWORD parameter) } // Secondly compute the two CRC bytes at the end - ComputeCrc14443(CRC_14443_A, cmd5, 2, &cmd5[2], &cmd5[3]); + ComputeCrc14443(CRC_14443_A, cmd7, 2, &cmd7[2], &cmd7[3]); + CodeIso14443aAsReader(cmd7, sizeof(cmd7)); + memcpy(req7, ToSend, ToSendMax); req7Len = ToSendMax; // Send authentication request (Mifare Classic) - TransmitFor14443a(req5, req5Len, &samples, &wait); + TransmitFor14443a(req7, req7Len, &samples, &wait); trace[traceLen++] = 0; trace[traceLen++] = 0; trace[traceLen++] = 0; trace[traceLen++] = 0; trace[traceLen++] = 0; trace[traceLen++] = 0; trace[traceLen++] = 0; trace[traceLen++] = 0; trace[traceLen++] = 4; - memcpy(trace+traceLen, cmd5, 4); + memcpy(trace+traceLen, cmd7, 4); traceLen += 4; if(traceLen > TRACE_LENGTH) goto done; if(GetIso14443aAnswerFromTag(receivedAnswer, 100, &samples, &elapsed)) { @@ -1808,9 +1811,7 @@ void ReaderIso14443a(DWORD parameter) } done: - LED_A_OFF(); - LED_B_OFF(); - LED_C_OFF(); + LEDsoff(); DbpIntegers(rsamples, 0xCC, 0xCC); DbpString("ready.."); } -- 2.39.5 From 5435eb0ca20821a392d33b99d6149f3b6275ff9a Mon Sep 17 00:00:00 2001 From: "adam@algroup.co.uk" Date: Mon, 24 Aug 2009 12:20:54 +0000 Subject: [PATCH 10/16] switch off reader field after hi14areader command --- armsrc/iso14443a.c | 1 + 1 file changed, 1 insertion(+) diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 6cd217f1..1571be0a 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -1811,6 +1811,7 @@ void ReaderIso14443a(DWORD parameter) } done: + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); LEDsoff(); DbpIntegers(rsamples, 0xCC, 0xCC); DbpString("ready.."); -- 2.39.5 From 7e931bbd32c878f6795a9c07d70ee96df2f675b2 Mon Sep 17 00:00:00 2001 From: "henryk@ploetzli.ch" Date: Wed, 26 Aug 2009 11:17:05 +0000 Subject: [PATCH 11/16] Consolidate Linux/Windows Makefiles into one, see http://www.proxmark.org/forum/topic/312/consolidating-makefile/ + Needs GNU make for Windows, a new release of the Windows development environment will follow + Is based on the Windows Makefile, so will build everything in Thumb mode, doesn't have flash commands (yet) --- armsrc/Makefile | 71 +++++++++++++----------------- armsrc/Makefile.linux | 99 ------------------------------------------ bootrom/Makefile | 75 +++++++++++++------------------- bootrom/Makefile.linux | 65 --------------------------- common/Makefile.common | 43 ++++++++++++++++++ 5 files changed, 103 insertions(+), 250 deletions(-) delete mode 100644 armsrc/Makefile.linux delete mode 100644 bootrom/Makefile.linux create mode 100644 common/Makefile.common diff --git a/armsrc/Makefile b/armsrc/Makefile index 8ad442f1..1acfdd88 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -1,19 +1,11 @@ -PATH=..\..\devkitARM\bin;%PATH% -CC = arm-elf-gcc -AS = arm-elf-as -LD = arm-elf-ld -OBJCOPY = arm-elf-objcopy +# Makefile for armsrc, see ../common/Makefile.common for common settings +include ../common/Makefile.common -OBJDIR = obj +APP_INCLUDES = apps.h -INCLUDE = -I../include - -INCLUDES = ../include/proxmark3.h ../include/at91sam7s128.h ../include/config_gpio.h ../include/usb_cmd.h apps.h -LIB = "..\..\devkitARM\lib\gcc\arm-elf\4.1.0\interwork" - -# Add the "-DWITH_LCD" flag in CLFAGS to add support for LCD +# Add the "-DWITH_LCD" flag in APP_CLFAGS to add support for LCD # and add OBJLCD to OBJ too -CFLAGS = -O6 -c $(INCLUDE) -Wall +APP_CFLAGS = -O6 OBJLCD = $(OBJDIR)/fonts.o \ $(OBJDIR)/LCD.o @@ -25,42 +17,37 @@ OBJ = $(OBJDIR)/start.o \ $(OBJDIR)/iso14443.o \ $(OBJDIR)/iso14443a.o \ $(OBJDIR)/iso15693.o \ - $(OBJDIR)/util.o + $(OBJDIR)/util.o \ + $(OBJDIR)/usb.o OBJFPGA = \ $(OBJDIR)/fpgaimg.o -OBJCOMMON = \ - $(OBJDIR)/usb.o - -all: osimage.s19 - -$(OBJDIR)/fpgaimage.s19: $(OBJDIR)/fpgaimg.o - @echo obj/fpgaimage.s19 - @$(LD) -g -Tldscript-fpga -o $(OBJDIR)\fpgaimage.elf -Map=obj/fpgaimage.map $(OBJDIR)/fpgaimg.o - @$(OBJCOPY) -Osrec --srec-forceS3 $(OBJDIR)\fpgaimage.elf $(OBJDIR)\fpgaimage.s19 - -$(OBJDIR)/osimage.s19: $(OBJ) $(OBJCOMMON) - @echo obj/osimage.s19 - @$(LD) -g -Tldscript -o $(OBJDIR)\osimage.elf $(OBJ) $(OBJCOMMON) -Map=obj/osimage.map $(LIB)\libgcc.a - @$(OBJCOPY) -Osrec --srec-forceS3 $(OBJDIR)\osimage.elf $(OBJDIR)\osimage.s19 +all: $(OBJDIR)/osimage.s19 $(OBJDIR)/fpgaimage.s19 -osimage.s19: $(OBJDIR)/osimage.s19 $(OBJDIR)/fpgaimage.s19 - @echo osimage.s19 +$(OBJDIR)/fpgaimage.elf: $(OBJDIR)/fpgaimg.o + $(LD) -g -Tldscript-fpga -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ -$(OBJ): $(@B).c $(INCLUDES) - @echo $(@B).c - @$(CC) $(CFLAGS) -mthumb -mthumb-interwork $(@B).c -o $(OBJDIR)/$(@B).o +$(OBJDIR)/osimage.elf: $(OBJ) $(OBJCOMMON) $(ARMLIB)/libgcc.a + $(LD) -g -Tldscript -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ -$(OBJCOMMON): ../common/$(@B).c $(INCLUDES) - @echo $(@B).c - @$(CC) $(CFLAGS) -mthumb -mthumb-interwork ../common/$(@B).c -o $(OBJDIR)/$(@B).o +$(OBJDIR)/%.s19: $(OBJDIR)/%.elf + $(OBJCOPY) -Osrec --srec-forceS3 $^ $@ -$(OBJFPGA): $(@B).c $(INCLUDES) - @echo $(@B).c - @$(CC) $(CFLAGS) -mthumb -mthumb-interwork $(@B).c -o $(OBJDIR)/$(@B).o +$(OBJ) $(OBJFPGA): $(OBJDIR)/%.o: %.c $(INCLUDES) + $(CC) $(CFLAGS) -mthumb -mthumb-interwork $< -o $@ clean: - del /q obj\*.o - del /q obj\*.elf - del /q obj\*.s19 + $(DELETE) $(OBJDIR)$(PATHSEP)*.o + $(DELETE) $(OBJDIR)$(PATHSEP)*.elf + $(DELETE) $(OBJDIR)$(PATHSEP)*.s19 + $(DELETE) $(OBJDIR)$(PATHSEP)*.map + +.PHONY: all clean help +help: + @echo Multi-OS Makefile, you are running on $(DETECTED_OS) + @echo Possible targets: + @echo + all - Make both: + @echo + osimage.s19 - The OS image + @echo + fpgaimage.s19 - The FPGA image + @echo + clean - Clean $(OBJDIR) diff --git a/armsrc/Makefile.linux b/armsrc/Makefile.linux deleted file mode 100644 index 3862b4f7..00000000 --- a/armsrc/Makefile.linux +++ /dev/null @@ -1,99 +0,0 @@ -# This makefile needs to be edited to reflect the location -# of your own arm-elf-gcc toolchain (ARMLIB variable) - -CC = arm-elf-gcc -AS = arm-elf-as -LD = arm-elf-ld -OBJCOPY = arm-elf-objcopy - -# Indicate where your gnuarm toolchain libgcc.a interworking library is located -# or set $ARMLIB in your environment: -#ARMLIB = /usr/local/lib/gcc/arm-elf/4.3.3/interwork - - -# Add -DWITH_LCD to EXTRA_CFLAGS if you want support for LCD -# in your firmware (add OBJLCD to OBJ too!) -#EXTRA_CFLAGS = -DWITH_LCD -EXTRA_CFLAGS = - -### You should not need to edit below this line - -INCLUDE = -I../include -INCLUDES = ../include/proxmark3.h ../include/at91sam7s128.h ../include/config_gpio.h ../include/usb_cmd.h apps.h -CFLAGS_COMMON = -O6 -c $(INCLUDE) -Wall -mthumb-interwork -CFLAGS = $(CFLAGS_COMMON) $(EXTRA_CFLAGS) -mthumb - - -OBJDIR = obj - -OBJLCD = $(OBJDIR)/LCD.o\ - $(OBJDIR)/fonts.o - -OBJ = $(OBJDIR)/start.o \ - $(OBJDIR)/appmain.o \ - $(OBJDIR)/fpga.o \ - $(OBJDIR)/lfops.o \ - $(OBJDIR)/iso15693.o \ - $(OBJDIR)/util.o - -# To be compiled in ARM mode, not thumb mode: larger but faster -# Alleviates the 'blew circular buffer' issues somehow... -OBJFAST = $(OBJDIR)/iso14443.o \ - $(OBJDIR)/iso14443a.o - -OBJFPGA = $(OBJDIR)/fpgaimg.o - -OBJCOMMON = $(OBJDIR)/usb.o - -all: osimage.s19 fpgaimage.s19 fullimage.s19 - -fpgaimage.s19: $(OBJFPGA) - @echo fpgaimage.s19 - $(LD) -g -Tldscript-fpga -o $(OBJDIR)/fpgaimage.elf $^ - $(OBJCOPY) -Osrec --srec-forceS3 $(OBJDIR)/fpgaimage.elf fpgaimage.s19 - -osimage.s19: $(OBJ) $(OBJFAST) $(OBJCOMMON) - @echo osimage.s19 - $(LD) -g -Tldscript -o $(OBJDIR)/osimage.elf -Map=osimage.map $^ $(ARMLIB)/libgcc.a - $(OBJCOPY) -Osrec --srec-forceS3 $(OBJDIR)/osimage.elf osimage.s19 - -fullimage.s19: $(OBJ) $(OBJFAST) $(OBJCOMMON) $(OBJFAST) $(OBJFPGA) - @echo fullimage.s19 - $(LD) -g -Tldscript-full -o $(OBJDIR)/fullimage.elf $^ $(ARMLIB)/libgcc.a - $(OBJCOPY) -Osrec --srec-forceS3 $(OBJDIR)/fullimage.elf fullimage.s19 - -# Directives to put the *.o in the OBJDIR directory: -$(OBJ): $(OBJDIR)/%.o : %.c - $(CC) $(CFLAGS) $< -o $@ - -$(OBJFPGA): $(OBJDIR)/%.o : %.c - $(CC) $(CFLAGS) $< -o $@ - -$(OBJFAST): $(OBJDIR)/%.o : %.c - $(CC) $(CFLAGS_COMMON) $< -o $@ - -$(OBJCOMMON): $(OBJDIR)/%.o : ../common/%.c - $(CC) $(CFLAGS) $< -o $@ - -flash-both: flash flash-fpga - -flash-fpga: fpgaimage.s19 - ../linux/flasher fpga fpgaimage.s19 - -flash: osimage.s19 - ../linux/flasher os osimage.s19 - -# Those do not work on the current firmware ! -jtag-flash-full: fullimage.s19 - ../../OpenOCD/openocd -c "halt; flash write_image fullimage.s19 0x00100000; halt; reset; resume; poll; exit" - -jtag-flash-fpga: fpgaimage.s19 - ../../OpenOCD/openocd -c "halt; flash write_image fpgaimage.s19 0x00100000; halt; reset; resume; poll; exit" - -jtag-flash: osimage.s19 - ../../OpenOCD/openocd -c "halt; flash write_image osimage.s19 0x00100000; halt; reset; resume; poll; exit" - -clean: - rm -f $(OBJDIR)/*.o $(OBJDIR)/*.elf *.s19 osimage.map - -.PHONY: all clean diff --git a/bootrom/Makefile b/bootrom/Makefile index 7a61cadb..652e0ae2 100644 --- a/bootrom/Makefile +++ b/bootrom/Makefile @@ -1,58 +1,45 @@ -CC = arm-elf-gcc -AS = arm-elf-as -LD = arm-elf-ld -OBJCOPY = arm-elf-objcopy - -OBJDIR = obj - -INCLUDE = -I../include - -INCLUDES = ../include/proxmark3.h ../include/at91sam7s128.h ../include/config_gpio.h ../include/usb_cmd.h - -CFLAGS = -g -c $(INCLUDE) -Wall +# Makefile for bootrom, see ../common/Makefile.common for common settings +include ../common/Makefile.common OBJJTAG = $(OBJDIR)/bootrom.o $(OBJDIR)/ram-reset.o $(OBJDIR)/usb.o - OBJFLASH = $(OBJDIR)/flash-reset.o $(OBJDIR)/fromflash.o -all: bootrom.s19 +THUMBSRC = usb.c fromflash.c bootrom.c +ASMSRC = ram-reset.s flash-reset.s -bootrom.s19: $(OBJDIR)/bootrom.s19 $(OBJDIR)/bootrom-forjtag.s19 - @echo bootrom.s19 - @perl ..\tools\merge-srec.pl $(OBJDIR)\bootrom.s19 $(OBJDIR)\bootrom-forjtag.s19 > $(OBJDIR)\bootrom-merged.s19 - @perl ..\tools\srecswap.pl $(OBJDIR)\bootrom-forjtag.s19 > $(OBJDIR)\bootrom-forjtag-swapped.s19 +THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC)) +ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(ASMSRC)) -$(OBJDIR)/bootrom.s19: $(OBJFLASH) - @echo obj/bootrom.s19 - @$(LD) -g -Tldscript-flash --oformat elf32-littlearm -Map=obj/bootrom.map -o $(OBJDIR)/bootrom.elf $(OBJFLASH) - @$(OBJCOPY) -Osrec --srec-forceS3 $(OBJDIR)/bootrom.elf $(OBJDIR)/bootrom.s19 +all: bootrom-merged.s19 -$(OBJDIR)/bootrom-forjtag.s19: $(OBJJTAG) - @echo obj/bootrom-forjtag.s19 - @$(LD) -g -Tldscript-ram-jtag --oformat elf32-littlearm -Map=obj/bootrom-forjtag.map -o $(OBJDIR)/bootrom-forjtag.elf $(OBJJTAG) - @$(OBJCOPY) -Osrec --srec-forceS3 $(OBJDIR)/bootrom-forjtag.elf $(OBJDIR)/bootrom-forjtag.s19 +bootrom-merged.s19: $(OBJDIR)/bootrom.s19 $(OBJDIR)/bootrom-forjtag.s19 + perl ../tools/merge-srec.pl $(OBJDIR)/bootrom.s19 $(OBJDIR)/bootrom-forjtag.s19 > bootrom-merged.s19 -$(OBJDIR)/bootrom.o: bootrom.c $(INCLUDES) - @echo $(@B).c - @$(CC) $(CFLAGS) -mthumb -mthumb-interwork bootrom.c -o $(OBJDIR)/bootrom.o +$(OBJDIR)/bootrom.elf: $(OBJFLASH) + $(LD) -g -Tldscript-flash --oformat elf32-littlearm -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ -$(OBJDIR)/fromflash.o: fromflash.c $(INCLUDES) - @echo $(@B).c - @$(CC) $(CFLAGS) -mthumb -mthumb-interwork fromflash.c -o $(OBJDIR)/fromflash.o +$(OBJDIR)/bootrom-forjtag.elf: $(OBJJTAG) + $(LD) -g -Tldscript-ram-jtag --oformat elf32-littlearm -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ -$(OBJDIR)/usb.o: ../common/usb.c $(INCLUDES) - @echo $(@B).c - @$(CC) $(CFLAGS) -mthumb -mthumb-interwork ../common/usb.c -o $(OBJDIR)/usb.o +$(OBJDIR)/%.s19: $(OBJDIR)/%.elf + $(OBJCOPY) -Osrec --srec-forceS3 $^ $@ -$(OBJDIR)/ram-reset.o: ram-reset.s - @echo $(@B).s - @$(CC) $(CFLAGS) -mthumb-interwork -o $(OBJDIR)/ram-reset.o ram-reset.s +$(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) + $(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $< -$(OBJDIR)/flash-reset.o: flash-reset.s - @echo $(@B).s - @$(CC) $(CFLAGS) -mthumb-interwork -o $(OBJDIR)/flash-reset.o flash-reset.s +$(ASMOBJ): $(OBJDIR)/%.o: %.s + $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< clean: - del /q obj\*.o - del /q obj\*.elf - del /q obj\*.s19 + $(DELETE) $(OBJDIR)$(PATHSEP)*.o + $(DELETE) $(OBJDIR)$(PATHSEP)*.elf + $(DELETE) $(OBJDIR)$(PATHSEP)*.s19 + $(DELETE) $(OBJDIR)$(PATHSEP)*.map + $(DELETE) bootrom-merged.s19 + +.PHONY: all clean help +help: + @echo Multi-OS Makefile, you are running on $(DETECTED_OS) + @echo Possible targets: + @echo + all - Make bootrom-merged.s19, the main bootrom + @echo + clean - Clean $(OBJDIR) diff --git a/bootrom/Makefile.linux b/bootrom/Makefile.linux deleted file mode 100644 index d558cc72..00000000 --- a/bootrom/Makefile.linux +++ /dev/null @@ -1,65 +0,0 @@ -CC = arm-elf-gcc -AS = arm-elf-as -LD = arm-elf-ld -OBJCOPY = arm-elf-objcopy - -OBJDIR = obj - -INCLUDE = -I../include - -INCLUDES = ../include/proxmark3.h ../include/at91sam7s128.h ../include/config_gpio.h ../include/usb_cmd.h - -CFLAGS = -g -c $(INCLUDE) -Wall - -OBJJTAG = $(OBJDIR)/bootrom.o $(OBJDIR)/ram-reset.o $(OBJDIR)/usb.o - -OBJFLASH = $(OBJDIR)/flash-reset.o $(OBJDIR)/fromflash.o - -all: bootrom.s19 bootrom-forjtag-swapped.s19 - -bootrom-merged.s19: bootrom.s19 bootrom-forjtag.s19 - perl ../tools/merge-srec.pl bootrom.s19 bootrom-forjtag.s19 > bootrom-merged.s19 - -bootrom-forjtag-swapped.s19: bootrom-merged.s19 - perl ../tools/srecswap.pl bootrom-forjtag.s19 > bootrom-forjtag-swapped.s19 - -bootrom.s19: $(OBJFLASH) - @echo bootrom.s19 - $(LD) -g -Tldscript-flash --oformat elf32-littlearm -o $(OBJDIR)/bootrom.elf $(OBJFLASH) - $(OBJCOPY) -Osrec --srec-forceS3 $(OBJDIR)/bootrom.elf bootrom.s19 - -bootrom-forjtag.s19: $(OBJJTAG) - @echo bootrom-forjtag.s19 - $(LD) -g -Tldscript-ram-jtag --oformat elf32-littlearm -o $(OBJDIR)/bootrom-forjtag.elf $(OBJJTAG) - $(OBJCOPY) -Osrec --srec-forceS3 $(OBJDIR)/bootrom-forjtag.elf bootrom-forjtag.s19 - -$(OBJDIR)/bootrom.o: bootrom.c $(INCLUDES) - @echo $@ - $(CC) $(CFLAGS) -mthumb -mthumb-interwork $< -o $@ - -$(OBJDIR)/fromflash.o: fromflash.c $(INCLUDES) - @echo $@ - $(CC) $(CFLAGS) -mthumb -mthumb-interwork $< -o $@ - -$(OBJDIR)/usb.o: ../common/usb.c $(INCLUDES) - @echo $@ - $(CC) $(CFLAGS) -mthumb -mthumb-interwork $< -o $@ - -$(OBJDIR)/ram-reset.o: ram-reset.s - @echo $@ - $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< - -$(OBJDIR)/flash-reset.o: flash-reset.s - @echo $@ - $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< - -# Those do not work in this Firmware distribution! -flash: bootrom-merged.s19 - ../linux/flasher bootrom bootrom-merged.s19 - -jtag-flash: bootrom-merged.s19 - ../../OpenOCD/openocd -c "halt; flash write_image bootrom-merged.s19 0x00100000; halt; reset; resume; poll; exit" - -clean: - rm -f $(OBJDIR)/*.o $(OBJDIR)/*.elf *.s19 - diff --git a/common/Makefile.common b/common/Makefile.common new file mode 100644 index 00000000..38271f51 --- /dev/null +++ b/common/Makefile.common @@ -0,0 +1,43 @@ +# This new makefile replaces the previous Makefile/Makefile.linux +# with as much common code for both environments as possible. +# Following is a short OS detection to set up variables, all the +# remaining Makefile should be portable and only depend on these +# variables + +# Windows' echo echos its input verbatim, on Posix there is some +# amount of shell command line parsing going on. echo "" on +# Windows yields literal "", on Linux yields an empty line +ifeq ($(shell echo ""),) +# This is properly a proper system, so we can use uname +UNAME := $(shell uname) +ifeq ($(UNAME), Linux) +# Linux. (Todo: Add MacOS X if appropriate) +DELETE=rm -rf +PATHSEP=/ +DETECTED_OS=Linux +# You may/should set this in your environment +ARMLIB ?= /usr/local/lib/gcc/arm-elf/4.3.3/interwork +endif +else +# Assume that we are running on Windows. +DELETE=del /q +PATHSEP=\\# +ARMLIB ?= ../../devkitARM/lib/gcc/arm-elf/4.1.0/interwork +DETECTED_OS=Windows +endif + +CC = arm-elf-gcc +AS = arm-elf-as +LD = arm-elf-ld +OBJCOPY = arm-elf-objcopy + +OBJDIR = obj + +INCLUDE = -I../include + +# Also search prerequisites in the common directory (for usb.c) +VPATH = . ../common/ + +INCLUDES = ../include/proxmark3.h ../include/at91sam7s128.h ../include/config_gpio.h ../include/usb_cmd.h $(APP_INCLUDES) + +CFLAGS = -c $(INCLUDE) -Wall $(APP_CFLAGS) -- 2.39.5 From 97a82e8f362e3731bf45a1f9b3598d5f0a3459b4 Mon Sep 17 00:00:00 2001 From: "henryk@ploetzli.ch" Date: Wed, 26 Aug 2009 11:21:05 +0000 Subject: [PATCH 12/16] Change make calls in the cockpit batch files --- cockpit/1makearm.bat | 4 ++-- cockpit/2makeboot.bat | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cockpit/1makearm.bat b/cockpit/1makearm.bat index a8ecb6e4..d925fd3c 100644 --- a/cockpit/1makearm.bat +++ b/cockpit/1makearm.bat @@ -1,5 +1,5 @@ @echo off cd ..\armsrc -rem nmake clean -nmake +rem make clean +make cd ..\cockpit diff --git a/cockpit/2makeboot.bat b/cockpit/2makeboot.bat index a56fcfe0..4258d9bb 100644 --- a/cockpit/2makeboot.bat +++ b/cockpit/2makeboot.bat @@ -1,5 +1,5 @@ @echo off cd ..\bootrom -rem nmake clean -nmake +rem make clean +make cd ..\cockpit -- 2.39.5 From 0fc0fca5830c9d1a430f40ff935fb399f91b8adc Mon Sep 17 00:00:00 2001 From: "henryk@ploetzli.ch" Date: Wed, 26 Aug 2009 17:34:19 +0000 Subject: [PATCH 13/16] Move most rules to Makefile.common Add automatic dependency generation Compile ISO14443 files in ARM mode, as was the case with the Linux Makefile before --- armsrc/Makefile | 47 ++++++++++++++++++++++-------------------- bootrom/Makefile | 15 +++----------- common/Makefile.common | 40 +++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 34 deletions(-) diff --git a/armsrc/Makefile b/armsrc/Makefile index 1acfdd88..ce1ad087 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -1,47 +1,49 @@ # Makefile for armsrc, see ../common/Makefile.common for common settings -include ../common/Makefile.common APP_INCLUDES = apps.h # Add the "-DWITH_LCD" flag in APP_CLFAGS to add support for LCD -# and add OBJLCD to OBJ too +# and add SRC_LCD to SRC_MAIN APP_CFLAGS = -O6 -OBJLCD = $(OBJDIR)/fonts.o \ - $(OBJDIR)/LCD.o +SRC_LCD = fonts.c LCD.c + +SRC_MAIN = start.c \ + appmain.c \ + fpga.c \ + lfops.c \ + iso15693.c \ + util.c \ + usb.c + +# These are to be compiled in ARM mode +SRC_MAIN_FAST = iso14443.c \ + iso14443a.c -OBJ = $(OBJDIR)/start.o \ - $(OBJDIR)/appmain.o \ - $(OBJDIR)/fpga.o \ - $(OBJDIR)/lfops.o \ - $(OBJDIR)/iso14443.o \ - $(OBJDIR)/iso14443a.o \ - $(OBJDIR)/iso15693.o \ - $(OBJDIR)/util.o \ - $(OBJDIR)/usb.o +SRC_FPGA = fpgaimg.c -OBJFPGA = \ - $(OBJDIR)/fpgaimg.o +THUMBSRC = $(SRC_MAIN) $(SRC_FPGA) +ARMSRC = $(SRC_MAIN_FAST) + +MAIN_OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(SRC_MAIN) $(SRC_MAIN_FAST)) + +# Do not move this inclusion before the definition of {THUMB,ASM,ARM}{OBJ,SRC} +include ../common/Makefile.common all: $(OBJDIR)/osimage.s19 $(OBJDIR)/fpgaimage.s19 $(OBJDIR)/fpgaimage.elf: $(OBJDIR)/fpgaimg.o $(LD) -g -Tldscript-fpga -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ -$(OBJDIR)/osimage.elf: $(OBJ) $(OBJCOMMON) $(ARMLIB)/libgcc.a +$(OBJDIR)/osimage.elf: $(MAIN_OBJ) $(ARMLIB)/libgcc.a $(LD) -g -Tldscript -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ -$(OBJDIR)/%.s19: $(OBJDIR)/%.elf - $(OBJCOPY) -Osrec --srec-forceS3 $^ $@ - -$(OBJ) $(OBJFPGA): $(OBJDIR)/%.o: %.c $(INCLUDES) - $(CC) $(CFLAGS) -mthumb -mthumb-interwork $< -o $@ - clean: $(DELETE) $(OBJDIR)$(PATHSEP)*.o $(DELETE) $(OBJDIR)$(PATHSEP)*.elf $(DELETE) $(OBJDIR)$(PATHSEP)*.s19 $(DELETE) $(OBJDIR)$(PATHSEP)*.map + $(DELETE) $(OBJDIR)$(PATHSEP)*.d .PHONY: all clean help help: @@ -51,3 +53,4 @@ help: @echo + osimage.s19 - The OS image @echo + fpgaimage.s19 - The FPGA image @echo + clean - Clean $(OBJDIR) + diff --git a/bootrom/Makefile b/bootrom/Makefile index 652e0ae2..2ab91286 100644 --- a/bootrom/Makefile +++ b/bootrom/Makefile @@ -1,5 +1,4 @@ # Makefile for bootrom, see ../common/Makefile.common for common settings -include ../common/Makefile.common OBJJTAG = $(OBJDIR)/bootrom.o $(OBJDIR)/ram-reset.o $(OBJDIR)/usb.o OBJFLASH = $(OBJDIR)/flash-reset.o $(OBJDIR)/fromflash.o @@ -7,8 +6,8 @@ OBJFLASH = $(OBJDIR)/flash-reset.o $(OBJDIR)/fromflash.o THUMBSRC = usb.c fromflash.c bootrom.c ASMSRC = ram-reset.s flash-reset.s -THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC)) -ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(ASMSRC)) +# Do not move this inclusion before the definition of {THUMB,ASM,ARM}{OBJ,SRC} +include ../common/Makefile.common all: bootrom-merged.s19 @@ -21,20 +20,12 @@ $(OBJDIR)/bootrom.elf: $(OBJFLASH) $(OBJDIR)/bootrom-forjtag.elf: $(OBJJTAG) $(LD) -g -Tldscript-ram-jtag --oformat elf32-littlearm -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ -$(OBJDIR)/%.s19: $(OBJDIR)/%.elf - $(OBJCOPY) -Osrec --srec-forceS3 $^ $@ - -$(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) - $(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $< - -$(ASMOBJ): $(OBJDIR)/%.o: %.s - $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< - clean: $(DELETE) $(OBJDIR)$(PATHSEP)*.o $(DELETE) $(OBJDIR)$(PATHSEP)*.elf $(DELETE) $(OBJDIR)$(PATHSEP)*.s19 $(DELETE) $(OBJDIR)$(PATHSEP)*.map + $(DELETE) $(OBJDIR)$(PATHSEP)*.d $(DELETE) bootrom-merged.s19 .PHONY: all clean help diff --git a/common/Makefile.common b/common/Makefile.common index 38271f51..c4da75e1 100644 --- a/common/Makefile.common +++ b/common/Makefile.common @@ -3,27 +3,38 @@ # Following is a short OS detection to set up variables, all the # remaining Makefile should be portable and only depend on these # variables +# + +# Make sure that all is the default target +# (The including Makefile still needs to define what 'all' is) +all: # Windows' echo echos its input verbatim, on Posix there is some # amount of shell command line parsing going on. echo "" on # Windows yields literal "", on Linux yields an empty line ifeq ($(shell echo ""),) + # This is properly a proper system, so we can use uname UNAME := $(shell uname) ifeq ($(UNAME), Linux) # Linux. (Todo: Add MacOS X if appropriate) DELETE=rm -rf +MOVE=mv PATHSEP=/ DETECTED_OS=Linux # You may/should set this in your environment ARMLIB ?= /usr/local/lib/gcc/arm-elf/4.3.3/interwork endif + else + # Assume that we are running on Windows. DELETE=del /q +MOVE=ren PATHSEP=\\# ARMLIB ?= ../../devkitARM/lib/gcc/arm-elf/4.1.0/interwork DETECTED_OS=Windows + endif CC = arm-elf-gcc @@ -41,3 +52,32 @@ VPATH = . ../common/ INCLUDES = ../include/proxmark3.h ../include/at91sam7s128.h ../include/config_gpio.h ../include/usb_cmd.h $(APP_INCLUDES) CFLAGS = -c $(INCLUDE) -Wall $(APP_CFLAGS) + +THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC)) +ARMOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(ARMSRC)) +ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(ASMSRC)) + +$(THUMBOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) + $(CC) $(CFLAGS) -mthumb -mthumb-interwork -o $@ $< + +$(ARMOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) + $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< + +$(ASMOBJ): $(OBJDIR)/%.o: %.s + $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< + +$(OBJDIR)/%.s19: $(OBJDIR)/%.elf + $(OBJCOPY) -Osrec --srec-forceS3 $^ $@ + +# Automatic dependency generation +DEPENDENCY_FILES = $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(THUMBSRC))) \ + $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(ARMSRC))) \ + $(patsubst %.s,$(OBJDIR)/%.d,$(notdir $(ASMSRC))) + +$(DEPENDENCY_FILES): Makefile ../common/Makefile.common +$(OBJDIR)/%.d: %.c + $(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ +$(OBJDIR)/%.d: %.s + $(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ + +-include $(DEPENDENCY_FILES) -- 2.39.5 From 8652988d62b19631e498b62a3800f0decb5e743a Mon Sep 17 00:00:00 2001 From: "henryk@ploetzli.ch" Date: Thu, 27 Aug 2009 04:25:34 +0000 Subject: [PATCH 14/16] Merge linker scripts in bootrom to have a single linker script for the bootloader proper (previously known as bootrom-merged.s19) Remove the now unnecessary files (merge-srec.pl, ldscript-ram-jtag) Note that this drops the dependency on perl for bootrom build, so end-users who don't touch the FPGA bitstream will not need perl anymore --- armsrc/Makefile | 8 +++---- bootrom/Makefile | 22 ++++++------------- bootrom/flash-reset.s | 10 ++++----- bootrom/fromflash.c | 2 +- bootrom/ldscript-flash | 46 +++++++++++++++++++++++++++++++++------ bootrom/ldscript-ram-jtag | 10 --------- bootrom/ram-reset.s | 10 ++++----- common/Makefile.common | 4 ++-- tools/merge-srec.pl | 23 -------------------- 9 files changed, 63 insertions(+), 72 deletions(-) delete mode 100644 bootrom/ldscript-ram-jtag delete mode 100644 tools/merge-srec.pl diff --git a/armsrc/Makefile b/armsrc/Makefile index ce1ad087..567c8d12 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -49,8 +49,8 @@ clean: help: @echo Multi-OS Makefile, you are running on $(DETECTED_OS) @echo Possible targets: - @echo + all - Make both: - @echo + osimage.s19 - The OS image - @echo + fpgaimage.s19 - The FPGA image - @echo + clean - Clean $(OBJDIR) + @echo + all - Make both: + @echo + $(OBJDIR)/osimage.s19 - The OS image + @echo + $(OBJDIR)/fpgaimage.s19 - The FPGA image + @echo + clean - Clean $(OBJDIR) diff --git a/bootrom/Makefile b/bootrom/Makefile index 2ab91286..43e2533f 100644 --- a/bootrom/Makefile +++ b/bootrom/Makefile @@ -1,36 +1,28 @@ # Makefile for bootrom, see ../common/Makefile.common for common settings -OBJJTAG = $(OBJDIR)/bootrom.o $(OBJDIR)/ram-reset.o $(OBJDIR)/usb.o -OBJFLASH = $(OBJDIR)/flash-reset.o $(OBJDIR)/fromflash.o - -THUMBSRC = usb.c fromflash.c bootrom.c -ASMSRC = ram-reset.s flash-reset.s +# DO NOT use thumb mode in the phase 1 bootloader since that generates a section with glue code +ARMSRC = fromflash.c +THUMBSRC = usb.c bootrom.c +ASMSRC = ram-reset.s flash-reset.s # Do not move this inclusion before the definition of {THUMB,ASM,ARM}{OBJ,SRC} include ../common/Makefile.common -all: bootrom-merged.s19 - -bootrom-merged.s19: $(OBJDIR)/bootrom.s19 $(OBJDIR)/bootrom-forjtag.s19 - perl ../tools/merge-srec.pl $(OBJDIR)/bootrom.s19 $(OBJDIR)/bootrom-forjtag.s19 > bootrom-merged.s19 +all: $(OBJDIR)/bootrom.s19 -$(OBJDIR)/bootrom.elf: $(OBJFLASH) +$(OBJDIR)/bootrom.elf: $(ASMOBJ) $(ARMOBJ) $(THUMBOBJ) $(LD) -g -Tldscript-flash --oformat elf32-littlearm -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ -$(OBJDIR)/bootrom-forjtag.elf: $(OBJJTAG) - $(LD) -g -Tldscript-ram-jtag --oformat elf32-littlearm -Map=$(patsubst %.elf,%.map,$@) -o $@ $^ - clean: $(DELETE) $(OBJDIR)$(PATHSEP)*.o $(DELETE) $(OBJDIR)$(PATHSEP)*.elf $(DELETE) $(OBJDIR)$(PATHSEP)*.s19 $(DELETE) $(OBJDIR)$(PATHSEP)*.map $(DELETE) $(OBJDIR)$(PATHSEP)*.d - $(DELETE) bootrom-merged.s19 .PHONY: all clean help help: @echo Multi-OS Makefile, you are running on $(DETECTED_OS) @echo Possible targets: - @echo + all - Make bootrom-merged.s19, the main bootrom + @echo + all - Make $(OBJDIR)/bootrom.s19, the main bootrom @echo + clean - Clean $(OBJDIR) diff --git a/bootrom/flash-reset.s b/bootrom/flash-reset.s index afb658a4..48c111a7 100644 --- a/bootrom/flash-reset.s +++ b/bootrom/flash-reset.s @@ -1,11 +1,11 @@ .extern CopyBootToRAM -.text -.code 32 -.align 0 +.section .startup,"ax" + .code 32 + .align 0 -.global start -start: +.global flashstart +flashstart: b Reset b UndefinedInstruction b SoftwareInterrupt diff --git a/bootrom/fromflash.c b/bootrom/fromflash.c index e6868092..f6d5237c 100644 --- a/bootrom/fromflash.c +++ b/bootrom/fromflash.c @@ -1,6 +1,6 @@ #include -void CopyBootToRAM(void) +void __attribute__((section("bootphase1"))) CopyBootToRAM(void) { int i; diff --git a/bootrom/ldscript-flash b/bootrom/ldscript-flash index 0d5d7325..fa6fb26e 100644 --- a/bootrom/ldscript-flash +++ b/bootrom/ldscript-flash @@ -1,11 +1,43 @@ +MEMORY +{ + /* AT91SAM7S256 has 256k Flash and 64k RAM */ + /* Important note: the correct ORIGIN for bootphase1 is 0x00100000 and for bootphase2 is 0x00100200 + However, this will confuse the currently deployed flash code which expects logical and and not + physical addresses and performs no sanity checks at all. If confronted with physical addresses, + it will happily erase everything and brick the device. So for the time being pretend these addresses + to start at 0x0 while updating all the flash code with proper sanity checks, then come back later and + fix the addresses. -- Henryk Plötz 2009-08-27 */ + bootphase1 : ORIGIN = 0x00000000, LENGTH = 0x200 /* Phase 1 bootloader: Copies real bootloader to RAM */ + bootphase2 : ORIGIN = 0x00000200, LENGTH = 0x2000 - 0x200 /* Main bootloader code, stored in Flash, executed from RAM */ + ram : ORIGIN = 0x00200000, LENGTH = 32K +} + + SECTIONS { - . = 0x00000000; - .text : { obj/flash-reset.o(.text) *(.text) } - .rodata : { *(.rodata) } - . = 0x00200000; - .data : { *(.data) } - __bss_start__ = .; - .bss : { *(.bss) } + . = 0; + + bootphase1 : { + *(.startup) + *(.bootphase1) + } >bootphase1 + + bootphase2 : { + __bootphase2_start__ = .; + *(.startphase2) + *(.text) + *(.glue_7) + *(.rodata) + *(.data) + . = ALIGN( 32 / 8 ); + __bootphase2_end__ = .; + } >ram AT>bootphase2 + + .bss : { + __bss_start__ = .; + *(.bss) + } >ram + + . = ALIGN( 32 / 8 ); __bss_end__ = .; } diff --git a/bootrom/ldscript-ram-jtag b/bootrom/ldscript-ram-jtag deleted file mode 100644 index 5dd57061..00000000 --- a/bootrom/ldscript-ram-jtag +++ /dev/null @@ -1,10 +0,0 @@ -SECTIONS -{ - . = 0x00200000; - .text : { obj/ram-reset.o(.text) *(.text) } - .rodata : { *(.rodata) } - .data : { *(.data) } - __bss_start__ = .; - .bss : { *(.bss) } - __bss_end__ = .; -} diff --git a/bootrom/ram-reset.s b/bootrom/ram-reset.s index 56bf36e3..6155b002 100644 --- a/bootrom/ram-reset.s +++ b/bootrom/ram-reset.s @@ -1,10 +1,10 @@ .extern BootROM -.text -.code 32 -.align 0 +.section .startphase2,"ax" + .code 32 + .align 0 -.global start -start: +.global ramstart +ramstart: ldr sp, = 0x0020FFF8 bl BootROM diff --git a/common/Makefile.common b/common/Makefile.common index c4da75e1..eab96080 100644 --- a/common/Makefile.common +++ b/common/Makefile.common @@ -76,8 +76,8 @@ DEPENDENCY_FILES = $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(THUMBSRC))) \ $(DEPENDENCY_FILES): Makefile ../common/Makefile.common $(OBJDIR)/%.d: %.c - $(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ + @$(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ $(OBJDIR)/%.d: %.s - $(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ + @$(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@ -include $(DEPENDENCY_FILES) diff --git a/tools/merge-srec.pl b/tools/merge-srec.pl deleted file mode 100644 index 683e6d3c..00000000 --- a/tools/merge-srec.pl +++ /dev/null @@ -1,23 +0,0 @@ -# merge the code that initially executes out of flash with the RAM image - -($flashFile, $ramFile) = @ARGV; - -open(FLASH, $flashFile) or die "$flashFile: $!\n"; - -while() { - print if /^S3/; - $EOF_record = $_ if /^S[789]/; -} - -open(RAM, $ramFile) or die "$ramFile: $!\n"; - -while() { - if(/^S3(..)(........)(.*)([0-9a-fA-F]{2})/) { - $addr = sprintf('%08X', hex($2) - 0x00200000 + 0x200); - $line = "$1$addr$3"; - $checksum = 0; - $checksum += $_ foreach map(hex, unpack("a2"x40, $line)); - print "S3$line", sprintf("%02X", ($checksum%256)^0xff ), "\n"; - } -} -print $EOF_record; -- 2.39.5 From fb6e5aa8630a2d181bcc82d7a3b2b3108d57937f Mon Sep 17 00:00:00 2001 From: "henryk@ploetzli.ch" Date: Thu, 27 Aug 2009 04:46:31 +0000 Subject: [PATCH 15/16] The older gnuarm in the windows toolchain seems to need the glue_7t section --- bootrom/ldscript-flash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bootrom/ldscript-flash b/bootrom/ldscript-flash index fa6fb26e..55078012 100644 --- a/bootrom/ldscript-flash +++ b/bootrom/ldscript-flash @@ -9,7 +9,7 @@ MEMORY fix the addresses. -- Henryk Plötz 2009-08-27 */ bootphase1 : ORIGIN = 0x00000000, LENGTH = 0x200 /* Phase 1 bootloader: Copies real bootloader to RAM */ bootphase2 : ORIGIN = 0x00000200, LENGTH = 0x2000 - 0x200 /* Main bootloader code, stored in Flash, executed from RAM */ - ram : ORIGIN = 0x00200000, LENGTH = 32K + ram : ORIGIN = 0x00200000, LENGTH = 64K } @@ -27,6 +27,7 @@ SECTIONS *(.startphase2) *(.text) *(.glue_7) + *(.glue_7t) *(.rodata) *(.data) . = ALIGN( 32 / 8 ); -- 2.39.5 From 2bfed17db25367442c6ad57a76a3c998ec84889c Mon Sep 17 00:00:00 2001 From: "henryk@ploetzli.ch" Date: Thu, 27 Aug 2009 16:07:35 +0000 Subject: [PATCH 16/16] Add a common linker script with the memory map for the complete project Use the correct physical addresses in the memory map, and instead translate the addresses during postprocessing with objcopy --- armsrc/ldscript | 22 +++++++++++++++------- armsrc/ldscript-fpga | 14 ++++++++------ bootrom/ldscript-flash | 16 ++-------------- common/Makefile.common | 10 +++++++++- common/ldscript.common | 16 ++++++++++++++++ 5 files changed, 50 insertions(+), 28 deletions(-) create mode 100644 common/ldscript.common diff --git a/armsrc/ldscript b/armsrc/ldscript index 0489cfe4..81ed4edf 100644 --- a/armsrc/ldscript +++ b/armsrc/ldscript @@ -1,13 +1,21 @@ +INCLUDE ../common/ldscript.common + ENTRY(Vector) SECTIONS { - . = 0x00010000; - .start : { obj/start.o(.text) } - .text : { *(.text) } - .rodata : { *(.rodata) } - . = 0x00200000; - .data : { *(.data) } + .start : { obj/start.o(.text) } >osimage + .text : { + *(.text) + *(.text.*) + *(.glue_7) + *(.glue_7t) + } >osimage + .rodata : { + *(.rodata) + *(.rodata*) + } >osimage + .data : { *(.data) } >ram __bss_start__ = .; - .bss : { *(.bss) } + .bss : { *(.bss) } >ram __bss_end__ = .; } diff --git a/armsrc/ldscript-fpga b/armsrc/ldscript-fpga index da8b1a21..4c926bf8 100644 --- a/armsrc/ldscript-fpga +++ b/armsrc/ldscript-fpga @@ -1,11 +1,13 @@ +INCLUDE ../common/ldscript.common + SECTIONS { - . = 0x00002000; - .text : { obj/fpgaimg.o(.text) *(.text) } - .rodata : { *(.rodata) } - . = 0x00200000; - .data : { *(.data) } + fpgaimage : { + obj/fpgaimg.o(.text) *(.text) + *(.rodata) + } >fpgaimage + .data : { *(.data) } >ram __bss_start__ = .; - .bss : { *(.bss) } + .bss : { *(.bss) } >ram __bss_end__ = .; } diff --git a/bootrom/ldscript-flash b/bootrom/ldscript-flash index 55078012..50218d68 100644 --- a/bootrom/ldscript-flash +++ b/bootrom/ldscript-flash @@ -1,18 +1,6 @@ -MEMORY -{ - /* AT91SAM7S256 has 256k Flash and 64k RAM */ - /* Important note: the correct ORIGIN for bootphase1 is 0x00100000 and for bootphase2 is 0x00100200 - However, this will confuse the currently deployed flash code which expects logical and and not - physical addresses and performs no sanity checks at all. If confronted with physical addresses, - it will happily erase everything and brick the device. So for the time being pretend these addresses - to start at 0x0 while updating all the flash code with proper sanity checks, then come back later and - fix the addresses. -- Henryk Plötz 2009-08-27 */ - bootphase1 : ORIGIN = 0x00000000, LENGTH = 0x200 /* Phase 1 bootloader: Copies real bootloader to RAM */ - bootphase2 : ORIGIN = 0x00000200, LENGTH = 0x2000 - 0x200 /* Main bootloader code, stored in Flash, executed from RAM */ - ram : ORIGIN = 0x00200000, LENGTH = 64K -} - +INCLUDE ../common/ldscript.common +ENTRY(flashstart) SECTIONS { . = 0; diff --git a/common/Makefile.common b/common/Makefile.common index eab96080..1c4738a1 100644 --- a/common/Makefile.common +++ b/common/Makefile.common @@ -66,8 +66,16 @@ $(ARMOBJ): $(OBJDIR)/%.o: %.c $(INCLUDES) $(ASMOBJ): $(OBJDIR)/%.o: %.s $(CC) $(CFLAGS) -mthumb-interwork -o $@ $< +# This objcopy call translates physical flash addresses to logical addresses +# See ldscript.common. -- Henryk Plötz 2009-08-27 $(OBJDIR)/%.s19: $(OBJDIR)/%.elf - $(OBJCOPY) -Osrec --srec-forceS3 $^ $@ + $(OBJCOPY) -Osrec --srec-forceS3 --no-change-warnings \ + --change-section-address bootphase1-0x100000 \ + --change-section-address bootphase2-0x100000 \ + --change-section-address fpgaimage-0x100000 \ + --change-section-address .start-0x100000 \ + --change-section-address .text-0x100000 \ + --change-section-address .rodata-0x100000 $^ $@ # Automatic dependency generation DEPENDENCY_FILES = $(patsubst %.c,$(OBJDIR)/%.d,$(notdir $(THUMBSRC))) \ diff --git a/common/ldscript.common b/common/ldscript.common new file mode 100644 index 00000000..4c4bd390 --- /dev/null +++ b/common/ldscript.common @@ -0,0 +1,16 @@ +/* AT91SAM7S256 has 256k Flash and 64k RAM */ +MEMORY +{ + /* Important note: this memory map has the correct origins for all the flash sections. + However, this will confuse the currently deployed flash code which expects logical and and not + physical addresses and performs no sanity checks at all. If confronted with physical addresses, + it will happily erase everything and brick the device. So for the time being translate these addresses + down in the objcopy call while updating all the flash code with proper sanity checks, then come + back later and fix the addresses. -- Henryk Plötz 2009-08-27 */ + bootphase1 : ORIGIN = 0x00100000, LENGTH = 0x200 /* Phase 1 bootloader: Copies real bootloader to RAM */ + bootphase2 : ORIGIN = 0x00100200, LENGTH = 0x2000 - 0x200 /* Main bootloader code, stored in Flash, executed from RAM */ + fpgaimage : ORIGIN = 0x00102000, LENGTH = 64k - 0x2000 /* Place where the FPGA image will end up */ + osimage : ORIGIN = 0x00110000, LENGTH = 256K - 64k /* Place where the main OS will end up */ + ram : ORIGIN = 0x00200000, LENGTH = 64K +} + -- 2.39.5