]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - bootrom/bootrom.c
Make the bootrom correctly nack in case of flash write error (e.g. due to lock bits)
[proxmark3-svn] / bootrom / bootrom.c
index 7b29ad97955cd1d5342b6151764ad2034f7b9ff4..83794d9f8c65fb1163f683bf99b24f7c104afc3c 100644 (file)
@@ -83,9 +83,9 @@ void UsbPacketReceived(BYTE *packet, int len)
         case CMD_DEVICE_INFO:\r
             dont_ack = 1;\r
             c->cmd = CMD_DEVICE_INFO;\r
-            c->ext1 = DEVICE_INFO_FLAG_BOOTROM_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM |\r
+            c->arg[0] = DEVICE_INFO_FLAG_BOOTROM_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM |\r
                 DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH;\r
-            if(common_area.flags.osimage_present) c->ext1 |= DEVICE_INFO_FLAG_OSIMAGE_PRESENT;\r
+            if(common_area.flags.osimage_present) c->arg[0] |= DEVICE_INFO_FLAG_OSIMAGE_PRESENT;\r
             UsbSendPacket(packet, len);\r
             break;\r
 \r
@@ -95,7 +95,7 @@ void UsbPacketReceived(BYTE *packet, int len)
              */\r
             p = (volatile DWORD *)&_flash_start;\r
             for(i = 0; i < 12; i++) {\r
-                p[i+c->ext1] = c->d.asDwords[i];\r
+                p[i+c->arg[0]] = c->d.asDwords[i];\r
             }\r
             break;\r
 \r
@@ -106,7 +106,7 @@ void UsbPacketReceived(BYTE *packet, int len)
             }\r
 \r
             /* Check that the address that we are supposed to write to is within our allowed region */\r
-            if( ((c->ext1+AT91C_IFLASH_PAGE_SIZE-1) >= end_addr) || (c->ext1 < start_addr) ) {\r
+            if( ((c->arg[0]+AT91C_IFLASH_PAGE_SIZE-1) >= end_addr) || (c->arg[0] < start_addr) ) {\r
                 /* Disallow write */\r
                 dont_ack = 1;\r
                 c->cmd = CMD_NACK;\r
@@ -114,11 +114,19 @@ void UsbPacketReceived(BYTE *packet, int len)
             } else {\r
                 /* Translate address to flash page and do flash, update here for the 512k part */\r
                 AT91C_BASE_EFC0->EFC_FCR = MC_FLASH_COMMAND_KEY |\r
-                    MC_FLASH_COMMAND_PAGEN((c->ext1-(int)&_flash_start)/AT91C_IFLASH_PAGE_SIZE) |\r
+                    MC_FLASH_COMMAND_PAGEN((c->arg[0]-(int)&_flash_start)/AT91C_IFLASH_PAGE_SIZE) |\r
                     AT91C_MC_FCMD_START_PROG;\r
             }\r
-            while(!(AT91C_BASE_EFC0->EFC_FSR & MC_FLASH_STATUS_READY))\r
+            \r
+            uint32_t sr;\r
+            \r
+            while(!((sr = AT91C_BASE_EFC0->EFC_FSR) & MC_FLASH_STATUS_READY))\r
                 ;\r
+            if(sr & (MC_FLASH_STATUS_LOCKE | MC_FLASH_STATUS_PROGE)) { \r
+                   dont_ack = 1;\r
+                    c->cmd = CMD_NACK;\r
+                    UsbSendPacket(packet, len);\r
+            }\r
             break;\r
 \r
         case CMD_HARDWARE_RESET:\r
@@ -127,15 +135,15 @@ void UsbPacketReceived(BYTE *packet, int len)
             break;\r
 \r
         case CMD_START_FLASH:\r
-            if(c->ext3 == START_FLASH_MAGIC) bootrom_unlocked = 1;\r
+            if(c->arg[2] == START_FLASH_MAGIC) bootrom_unlocked = 1;\r
             else bootrom_unlocked = 0;\r
             {\r
                 int prot_start = (int)&_bootrom_start;\r
                 int prot_end = (int)&_bootrom_end;\r
                 int allow_start = (int)&_flash_start;\r
                 int allow_end = (int)&_flash_end;\r
-                int cmd_start = c->ext1;\r
-                int cmd_end = c->ext2;\r
+                int cmd_start = c->arg[0];\r
+                int cmd_end = c->arg[1];\r
 \r
                 /* Only allow command if the bootrom is unlocked, or the parameters are outside of the protected\r
                  * bootrom area. In any case they must be within the flash area.\r
Impressum, Datenschutz