]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/appmain.c
Change section_start pointer to char** to prevent aliasing warnings on old toolchain
[proxmark3-svn] / armsrc / appmain.c
index 59cc6dead3bf6a5bbbf99ad96c15dfae2cc640f7..78ab86912c779eb5b4b2db6cc182f3a4a439fea0 100644 (file)
@@ -13,7 +13,6 @@
 #include "LCD.h"
 #endif
 
 #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
 //=============================================================================
 // 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;
 BYTE ToSend[256];
 int ToSendMax;
 static int ToSendBit;
+struct common_area common_area __attribute__((section(".commonarea")));
 
 void BufferClear(void)
 {
 
 void BufferClear(void)
 {
@@ -238,17 +238,19 @@ void ReadMem(int addr)
 
 /* osimage version information is linked in */
 extern struct version_information version_information;
 
 /* 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");
        
 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. For the time being, expect
-        * to find a pointer at address 0x1001fc, perform slight sanity checks on 
-        * the pointer, then use it.
+       /* 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.
         */
         */
-       void *bootrom_version = *(void**)0x1001fc;
-       if( bootrom_version < (void*)0x100000 || bootrom_version > (void*)0x101000 ) {
+       void *bootrom_version = *(void**)&_bootphase1_version_pointer;
+       if( bootrom_version < (void*)&_flash_start || bootrom_version >= (void*)&_flash_end ) {
                DbpString("bootrom version information appears invalid");
        } else {
                FormatVersionInformation(temp, sizeof(temp), "bootrom: ", bootrom_version);
                DbpString("bootrom version information appears invalid");
        } else {
                FormatVersionInformation(temp, sizeof(temp), "bootrom: ", bootrom_version);
@@ -667,7 +669,23 @@ void UsbPacketReceived(BYTE *packet, int len)
                                // We're going to reset, and the bootrom will take control.
                        }
                        break;
                                // 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;
                default:
                        DbpString("unknown command");
                        break;
@@ -678,6 +696,14 @@ void AppMain(void)
 {
        memset(BigBuf,0,sizeof(BigBuf));
        SpinDelay(100);
 {
        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();
 
        LED_D_OFF();
        LED_C_OFF();
Impressum, Datenschutz