mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
CHG: a bit code clean up,
FIX: a comparison with signed vs unsigned was solved. I'm reluctant to change this code since it is a vital piece.
This commit is contained in:
parent
ff4ff94b25
commit
cf69eca0ff
1 changed files with 124 additions and 125 deletions
|
@ -9,13 +9,12 @@
|
|||
#include <proxmark3.h>
|
||||
#include "usb_cdc.h"
|
||||
#include "cmd.h"
|
||||
//#include "usb_hid.h"
|
||||
|
||||
void DbpString(char *str) {
|
||||
byte_t len = 0;
|
||||
while (str[len] != 0x00) {
|
||||
len++;
|
||||
}
|
||||
while (str[len] != 0x00)
|
||||
++len;
|
||||
|
||||
cmd_send(CMD_DEBUG_PRINT_STRING,len,0,0,(byte_t*)str,len);
|
||||
}
|
||||
|
||||
|
@ -84,8 +83,7 @@ static void ConfigClocks(void)
|
|||
;
|
||||
}
|
||||
|
||||
static void Fatal(void)
|
||||
{
|
||||
static void Fatal(void) {
|
||||
for(;;);
|
||||
}
|
||||
|
||||
|
@ -94,9 +92,7 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
|||
UsbCommand* c = (UsbCommand *)packet;
|
||||
volatile uint32_t *p;
|
||||
|
||||
if(len != sizeof(UsbCommand)) {
|
||||
Fatal();
|
||||
}
|
||||
if(len != sizeof(UsbCommand)) Fatal();
|
||||
|
||||
uint32_t arg0 = (uint32_t)c->arg[0];
|
||||
|
||||
|
@ -105,9 +101,9 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
|||
dont_ack = 1;
|
||||
arg0 = DEVICE_INFO_FLAG_BOOTROM_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM |
|
||||
DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH;
|
||||
if(common_area.flags.osimage_present) {
|
||||
if(common_area.flags.osimage_present)
|
||||
arg0 |= DEVICE_INFO_FLAG_OSIMAGE_PRESENT;
|
||||
}
|
||||
|
||||
cmd_send(CMD_DEVICE_INFO,arg0,1,2,0,0);
|
||||
} break;
|
||||
|
||||
|
@ -116,14 +112,13 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
|||
* whole memory region, only the last 8 bits are decoded.
|
||||
*/
|
||||
p = (volatile uint32_t *)&_flash_start;
|
||||
for(i = 0; i < 12; i++) {
|
||||
for(i = 0; i < 12; i++)
|
||||
p[i+arg0] = c->d.asDwords[i];
|
||||
}
|
||||
} break;
|
||||
|
||||
case CMD_FINISH_WRITE: {
|
||||
uint32_t* flash_mem = (uint32_t*)(&_flash_start);
|
||||
for (size_t j=0; j<2; j++) {
|
||||
for ( int j=0; j<2; j++) {
|
||||
for(i = 0+(64*j); i < 64+(64*j); i++) {
|
||||
flash_mem[i] = c->d.asDwords[i];
|
||||
}
|
||||
|
@ -159,9 +154,11 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
|||
} break;
|
||||
|
||||
case CMD_START_FLASH: {
|
||||
if(c->arg[2] == START_FLASH_MAGIC) bootrom_unlocked = 1;
|
||||
else bootrom_unlocked = 0;
|
||||
{
|
||||
if(c->arg[2] == START_FLASH_MAGIC)
|
||||
bootrom_unlocked = 1;
|
||||
else
|
||||
bootrom_unlocked = 0;
|
||||
|
||||
int prot_start = (int)&_bootrom_start;
|
||||
int prot_end = (int)&_bootrom_end;
|
||||
int allow_start = (int)&_flash_start;
|
||||
|
@ -172,8 +169,9 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
|||
/* Only allow command if the bootrom is unlocked, or the parameters are outside of the protected
|
||||
* bootrom area. In any case they must be within the flash area.
|
||||
*/
|
||||
if( (bootrom_unlocked || ((cmd_start >= prot_end) || (cmd_end < prot_start)))
|
||||
&& (cmd_start >= allow_start) && (cmd_end <= allow_end) ) {
|
||||
if( (bootrom_unlocked || ((cmd_start >= prot_end) || (cmd_end < prot_start))) &&
|
||||
(cmd_start >= allow_start) &&
|
||||
(cmd_end <= allow_end) ) {
|
||||
start_addr = cmd_start;
|
||||
end_addr = cmd_end;
|
||||
} else {
|
||||
|
@ -181,7 +179,6 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
|||
dont_ack = 1;
|
||||
cmd_send(CMD_NACK,0,0,0,0,0);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
default: {
|
||||
|
@ -189,10 +186,9 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
|||
} break;
|
||||
}
|
||||
|
||||
if(!dont_ack) {
|
||||
if(!dont_ack)
|
||||
cmd_send(CMD_ACK,arg0,0,0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
static void flash_mode(int externally_entered)
|
||||
{
|
||||
|
@ -203,16 +199,16 @@ static void flash_mode(int externally_entered)
|
|||
size_t rx_len;
|
||||
|
||||
usb_enable();
|
||||
for (volatile size_t i=0; i<0x100000; i++);
|
||||
for (volatile size_t i=0; i<0x100000; i++)
|
||||
;
|
||||
|
||||
for(;;) {
|
||||
WDT_HIT();
|
||||
|
||||
if (usb_poll()) {
|
||||
rx_len = usb_read(rx,sizeof(UsbCommand));
|
||||
if (rx_len) {
|
||||
if (rx_len)
|
||||
UsbPacketReceived(rx,rx_len);
|
||||
}
|
||||
}
|
||||
|
||||
if(!externally_entered && !BUTTON_PRESS()) {
|
||||
|
@ -220,7 +216,8 @@ static void flash_mode(int externally_entered)
|
|||
usb_disable();
|
||||
LED_B_ON();
|
||||
AT91C_BASE_RSTC->RSTC_RCR = RST_CONTROL_KEY | AT91C_RSTC_PROCRST;
|
||||
for(;;);
|
||||
for(;;)
|
||||
;
|
||||
}
|
||||
if(externally_entered && BUTTON_PRESS()) {
|
||||
/* Let the user's button press override the automatic leave */
|
||||
|
@ -305,9 +302,11 @@ void BootROM(void)
|
|||
|
||||
if(!common_area_present){
|
||||
/* Common area not ok, initialize it */
|
||||
int i; for(i=0; i<sizeof(common_area); i++) { /* Makeshift memset, no need to drag util.c into this */
|
||||
int i;
|
||||
/* Makeshift memset, no need to drag util.c into this */
|
||||
for(i=0; i<sizeof(common_area); i++)
|
||||
((char*)&common_area)[i] = 0;
|
||||
}
|
||||
|
||||
common_area.magic = COMMON_AREA_MAGIC;
|
||||
common_area.version = 1;
|
||||
common_area.flags.bootrom_present = 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue