X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/ba8a80b30c4da36ef10854b53b06d9ff9acaca44..1b2c8936326aa0f31912da76dff96a24102a2711:/armsrc/appmain.c diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 551ee694..23046b4d 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -13,7 +13,6 @@ #include "LCD.h" #endif - //============================================================================= // A buffer where we can queue things up to be sent through the FPGA, for // any purpose (fake tag, as reader, whatever). We go MSB first, since that @@ -23,6 +22,7 @@ BYTE ToSend[256]; int ToSendMax; static int ToSendBit; +struct common_area common_area __attribute__((section(".commonarea"))); void BufferClear(void) { @@ -236,10 +236,30 @@ void ReadMem(int addr) DbpIntegers(0, data[i], data[i+1]); } +/* osimage version information is linked in */ +extern struct version_information version_information; +/* bootrom version information is pointed to from _bootphase1_version_pointer */ +extern char *_bootphase1_version_pointer, _flash_start, _flash_end; void SendVersion(void) { char temp[48]; /* Limited data payload in USB packets */ DbpString("Prox/RFID mark3 RFID instrument"); + + /* Try to find the bootrom version information. Expect to find a pointer at + * symbol _bootphase1_version_pointer, perform slight sanity checks on the + * pointer, then use it. + */ + char *bootrom_version = *(char**)&_bootphase1_version_pointer; + if( bootrom_version < &_flash_start || bootrom_version >= &_flash_end ) { + DbpString("bootrom version information appears invalid"); + } else { + FormatVersionInformation(temp, sizeof(temp), "bootrom: ", bootrom_version); + DbpString(temp); + } + + FormatVersionInformation(temp, sizeof(temp), "os: ", &version_information); + DbpString(temp); + FpgaGatherVersion(temp, sizeof(temp)); DbpString(temp); } @@ -627,6 +647,9 @@ void UsbPacketReceived(BYTE *packet, int len) case CMD_VERSION: SendVersion(); break; + case CMD_LF_SIMULATE_BIDIR: + SimulateTagLowFrequencyBidir(c->ext1, c->ext2); + break; #ifdef WITH_LCD case CMD_LCD_RESET: LCDReset(); @@ -646,17 +669,40 @@ void UsbPacketReceived(BYTE *packet, int len) // We're going to reset, and the bootrom will take control. } break; - + case CMD_START_FLASH: + if(common_area.flags.bootrom_present) { + common_area.command = COMMON_AREA_COMMAND_ENTER_FLASH_MODE; + } + USB_D_PLUS_PULLUP_OFF(); + RSTC_CONTROL = RST_CONTROL_KEY | RST_CONTROL_PROCESSOR_RESET; + for(;;); + break; + + case CMD_DEVICE_INFO: { + UsbCommand c; + c.cmd = CMD_DEVICE_INFO; + c.ext1 = DEVICE_INFO_FLAG_OSIMAGE_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_OS; + if(common_area.flags.bootrom_present) c.ext1 |= DEVICE_INFO_FLAG_BOOTROM_PRESENT; + UsbSendPacket((BYTE*)&c, sizeof(c)); + } + break; default: DbpString("unknown command"); break; } } -void AppMain(void) +void __attribute__((noreturn)) AppMain(void) { - memset(BigBuf,0,sizeof(BigBuf)); SpinDelay(100); + + if(common_area.magic != COMMON_AREA_MAGIC || common_area.version != 1) { + /* Initialize common area */ + memset(&common_area, 0, sizeof(common_area)); + common_area.magic = COMMON_AREA_MAGIC; + common_area.version = 1; + } + common_area.flags.osimage_present = 1; LED_D_OFF(); LED_C_OFF(); @@ -687,14 +733,14 @@ void AppMain(void) LCDInit(); // test text on different colored backgrounds - LCDString(" The quick brown fox ", &FONT6x8,1,1+8*0,WHITE ,BLACK ); - LCDString(" jumped over the ", &FONT6x8,1,1+8*1,BLACK ,WHITE ); - LCDString(" lazy dog. ", &FONT6x8,1,1+8*2,YELLOW ,RED ); - LCDString(" AaBbCcDdEeFfGgHhIiJj ", &FONT6x8,1,1+8*3,RED ,GREEN ); - LCDString(" KkLlMmNnOoPpQqRrSsTt ", &FONT6x8,1,1+8*4,MAGENTA,BLUE ); - LCDString("UuVvWwXxYyZz0123456789", &FONT6x8,1,1+8*5,BLUE ,YELLOW); - LCDString("`-=[]_;',./~!@#$%^&*()", &FONT6x8,1,1+8*6,BLACK ,CYAN ); - LCDString(" _+{}|:\\\"<>? ",&FONT6x8,1,1+8*7,BLUE ,MAGENTA); + LCDString(" The quick brown fox ", (char *)&FONT6x8,1,1+8*0,WHITE ,BLACK ); + LCDString(" jumped over the ", (char *)&FONT6x8,1,1+8*1,BLACK ,WHITE ); + LCDString(" lazy dog. ", (char *)&FONT6x8,1,1+8*2,YELLOW ,RED ); + LCDString(" AaBbCcDdEeFfGgHhIiJj ", (char *)&FONT6x8,1,1+8*3,RED ,GREEN ); + LCDString(" KkLlMmNnOoPpQqRrSsTt ", (char *)&FONT6x8,1,1+8*4,MAGENTA,BLUE ); + LCDString("UuVvWwXxYyZz0123456789", (char *)&FONT6x8,1,1+8*5,BLUE ,YELLOW); + LCDString("`-=[]_;',./~!@#$%^&*()", (char *)&FONT6x8,1,1+8*6,BLACK ,CYAN ); + LCDString(" _+{}|:\\\"<>? ",(char *)&FONT6x8,1,1+8*7,BLUE ,MAGENTA); // color bands LCDFill(0, 1+8* 8, 132, 8, BLACK);