CHG: appmain now calls cmd_recieve as it should
CHG: flasher - removed unneeded parameter to function CHG: flasher - increased limit to fpga-files that can be loaded FIX: main client, wrong windows define fixed. CHG: device side - recieve usb command does not always get 544 bytes. usb packages can be incomplete. CHG: usb_cdc.c also got piwi's changes. CHG: uart_posix.c removed a debug value CHG: uart_win32.c clean up.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
void SendCommand(UsbCommand* txcmd);
|
||||
void ReceiveCommand(UsbCommand* rxcmd);
|
||||
void CloseProxmark();
|
||||
int OpenProxmark(size_t i);
|
||||
int OpenProxmark();
|
||||
|
||||
// FIXME: what the fuckity fuck
|
||||
unsigned int current_command = CMD_UNKNOWN;
|
||||
@@ -41,8 +41,7 @@ static const uint8_t elf_ident[] = {
|
||||
|
||||
// Turn PHDRs into flasher segments, checking for PHDR sanity and merging adjacent
|
||||
// unaligned segments if needed
|
||||
static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, int num_phdrs)
|
||||
{
|
||||
static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, int num_phdrs) {
|
||||
Elf32_Phdr *phdr = phdrs;
|
||||
flash_seg_t *seg;
|
||||
uint32_t last_end = 0;
|
||||
@@ -187,8 +186,7 @@ static int check_segs(flash_file_t *ctx, int can_write_bl) {
|
||||
}
|
||||
|
||||
// Load an ELF file and prepare it for flashing
|
||||
int flash_load(flash_file_t *ctx, const char *name, int can_write_bl)
|
||||
{
|
||||
int flash_load(flash_file_t *ctx, const char *name, int can_write_bl) {
|
||||
FILE *fd = NULL;
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr *phdrs = NULL;
|
||||
@@ -269,10 +267,8 @@ fail:
|
||||
}
|
||||
|
||||
// Get the state of the proxmark, backwards compatible
|
||||
static int get_proxmark_state(uint32_t *state)
|
||||
{
|
||||
UsbCommand c;
|
||||
c.cmd = CMD_DEVICE_INFO;
|
||||
static int get_proxmark_state(uint32_t *state) {
|
||||
UsbCommand c = {CMD_DEVICE_INFO};
|
||||
SendCommand(&c);
|
||||
UsbCommand resp;
|
||||
ReceiveCommand(&resp);
|
||||
@@ -297,13 +293,11 @@ static int get_proxmark_state(uint32_t *state)
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Enter the bootloader to be able to start flashing
|
||||
static int enter_bootloader(char *serial_port_name)
|
||||
{
|
||||
static int enter_bootloader(char *serial_port_name) {
|
||||
uint32_t state;
|
||||
|
||||
if (get_proxmark_state(&state) < 0)
|
||||
@@ -314,7 +308,7 @@ static int enter_bootloader(char *serial_port_name)
|
||||
return 0;
|
||||
|
||||
if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
|
||||
fprintf(stderr,"Entering bootloader...\n");
|
||||
fprintf(stderr, "Entering bootloader...\n");
|
||||
UsbCommand c;
|
||||
memset(&c, 0, sizeof (c));
|
||||
|
||||
@@ -324,22 +318,22 @@ static int enter_bootloader(char *serial_port_name)
|
||||
// and enter the bootrom on the next boot.
|
||||
c.cmd = CMD_START_FLASH;
|
||||
SendCommand(&c);
|
||||
fprintf(stderr,"(Press and release the button only to abort)\n");
|
||||
fprintf(stderr, "(Press and release the button only to abort)\n");
|
||||
} else {
|
||||
// Old style handover: Ask the user to press the button, then reset the board
|
||||
c.cmd = CMD_HARDWARE_RESET;
|
||||
SendCommand(&c);
|
||||
fprintf(stderr,"Press and hold down button NOW if your bootloader requires it.\n");
|
||||
fprintf(stderr, "Press and hold down button NOW if your bootloader requires it.\n");
|
||||
}
|
||||
msleep(100);
|
||||
CloseProxmark();
|
||||
|
||||
fprintf(stderr,"Waiting for Proxmark to reappear on %s",serial_port_name);
|
||||
fprintf(stderr, "Waiting for Proxmark to reappear on %s", serial_port_name);
|
||||
do {
|
||||
msleep(1000);
|
||||
fprintf(stderr, ".");
|
||||
} while (!OpenProxmark(0));
|
||||
fprintf(stderr," Found.\n");
|
||||
} while ( !OpenProxmark());
|
||||
fprintf(stderr, " Found.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -347,19 +341,17 @@ static int enter_bootloader(char *serial_port_name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int wait_for_ack(UsbCommand *ack)
|
||||
{
|
||||
static int wait_for_ack(UsbCommand *ack) {
|
||||
ReceiveCommand(ack);
|
||||
if (ack->cmd != CMD_ACK) {
|
||||
printf("Error: Unexpected reply 0x%04" PRIx64 " %s (expected ACK)\n", ack->cmd, (ack->cmd==CMD_NACK)?"NACK":"");
|
||||
printf("Error: Unexpected reply 0x%04" PRIx64 " %s (expected ACK)\n", ack->cmd, (ack->cmd == CMD_NACK) ? "NACK" : "");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Go into flashing mode
|
||||
int flash_start_flashing(int enable_bl_writes,char *serial_port_name)
|
||||
{
|
||||
int flash_start_flashing(int enable_bl_writes, char *serial_port_name) {
|
||||
uint32_t state;
|
||||
|
||||
if (enter_bootloader(serial_port_name) < 0)
|
||||
@@ -392,8 +384,7 @@ int flash_start_flashing(int enable_bl_writes,char *serial_port_name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int write_block(uint32_t address, uint8_t *data, uint32_t length)
|
||||
{
|
||||
static int write_block(uint32_t address, uint8_t *data, uint32_t length) {
|
||||
uint8_t block_buf[BLOCK_SIZE];
|
||||
memset(block_buf, 0xFF, BLOCK_SIZE);
|
||||
memcpy(block_buf, data, length);
|
||||
@@ -415,8 +406,7 @@ static int write_block(uint32_t address, uint8_t *data, uint32_t length)
|
||||
}
|
||||
|
||||
// Write a file's segments to Flash
|
||||
int flash_write(flash_file_t *ctx)
|
||||
{
|
||||
int flash_write(flash_file_t *ctx) {
|
||||
fprintf(stderr, "Writing segments for file: %s\n", ctx->filename);
|
||||
for (int i = 0; i < ctx->num_segs; i++) {
|
||||
flash_seg_t *seg = &ctx->segments[i];
|
||||
@@ -425,8 +415,7 @@ int flash_write(flash_file_t *ctx)
|
||||
uint32_t blocks = (length + BLOCK_SIZE - 1) / BLOCK_SIZE;
|
||||
uint32_t end = seg->start + length;
|
||||
|
||||
fprintf(stderr, " 0x%08x..0x%08x [0x%x / %d blocks]",
|
||||
seg->start, end - 1, length, blocks);
|
||||
fprintf(stderr, " 0x%08x..0x%08x [0x%x / %d blocks]", seg->start, end - 1, length, blocks);
|
||||
|
||||
int block = 0;
|
||||
uint8_t *data = seg->data;
|
||||
@@ -455,8 +444,7 @@ int flash_write(flash_file_t *ctx)
|
||||
}
|
||||
|
||||
// free a file context
|
||||
void flash_free(flash_file_t *ctx)
|
||||
{
|
||||
void flash_free(flash_file_t *ctx) {
|
||||
if (!ctx)
|
||||
return;
|
||||
if (ctx->segments) {
|
||||
@@ -474,4 +462,4 @@ int flash_stop_flashing(void) {
|
||||
SendCommand(&c);
|
||||
msleep(100);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "uart.h"
|
||||
#include "usb_cmd.h"
|
||||
|
||||
#define MAX_FILES 4
|
||||
|
||||
#ifdef _WIN32
|
||||
# define unlink(x)
|
||||
#else
|
||||
@@ -25,17 +27,17 @@
|
||||
static serial_port sp;
|
||||
static char* serial_port_name;
|
||||
|
||||
void cmd_debug(UsbCommand* UC) {
|
||||
void cmd_debug(UsbCommand* c) {
|
||||
// Debug
|
||||
printf("UsbCommand length[len=%zd]\n", sizeof(UsbCommand));
|
||||
printf(" cmd[len=%zd]: %016" PRIx64"\n", sizeof(UC->cmd), UC->cmd);
|
||||
printf(" arg0[len=%zd]: %016" PRIx64"\n", sizeof(UC->arg[0]), UC->arg[0]);
|
||||
printf(" arg1[len=%zd]: %016" PRIx64"\n", sizeof(UC->arg[1]), UC->arg[1]);
|
||||
printf(" arg2[len=%zd]: %016" PRIx64"\n", sizeof(UC->arg[2]), UC->arg[2]);
|
||||
printf(" data[len=%zd]: ", sizeof(UC->d.asBytes));
|
||||
printf(" cmd[len=%zd]: %016" PRIx64"\n", sizeof(c->cmd), c->cmd);
|
||||
printf(" arg0[len=%zd]: %016" PRIx64"\n", sizeof(c->arg[0]), c->arg[0]);
|
||||
printf(" arg1[len=%zd]: %016" PRIx64"\n", sizeof(c->arg[1]), c->arg[1]);
|
||||
printf(" arg2[len=%zd]: %016" PRIx64"\n", sizeof(c->arg[2]), c->arg[2]);
|
||||
printf(" data[len=%zd]: ", sizeof(c->d.asBytes));
|
||||
|
||||
for (size_t i=0; i<16; i++)
|
||||
printf("%02x", UC->d.asBytes[i]);
|
||||
printf("%02x", c->d.asBytes[i]);
|
||||
|
||||
printf("...\n");
|
||||
}
|
||||
@@ -43,7 +45,7 @@ void cmd_debug(UsbCommand* UC) {
|
||||
void SendCommand(UsbCommand* txcmd) {
|
||||
// printf("send: ");
|
||||
// cmd_debug(txcmd);
|
||||
if (!uart_send(sp,(byte_t*)txcmd, sizeof(UsbCommand))) {
|
||||
if (!uart_send(sp, (byte_t*)txcmd, sizeof(UsbCommand))) {
|
||||
printf("Sending bytes to proxmark failed\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -70,13 +72,17 @@ void CloseProxmark() {
|
||||
unlink(serial_port_name);
|
||||
}
|
||||
|
||||
int OpenProxmark(size_t i) {
|
||||
int OpenProxmark() {
|
||||
sp = uart_open(serial_port_name);
|
||||
|
||||
//poll once a second
|
||||
if (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT)
|
||||
if (sp == INVALID_SERIAL_PORT) {
|
||||
printf("ERROR: invalid serial port\n");
|
||||
return 0;
|
||||
|
||||
} else if (sp == CLAIMED_SERIAL_PORT) {
|
||||
printf("ERROR: serial port is claimed by another process\n");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -95,10 +101,7 @@ static void usage(char *argv0) {
|
||||
fprintf(stderr, " https://github.com/Proxmark/proxmark3/wiki/OSX\n\n");
|
||||
}
|
||||
|
||||
#define MAX_FILES 4
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
int can_write_bl = 0;
|
||||
int num_files = 0;
|
||||
int res;
|
||||
@@ -138,7 +141,7 @@ int main(int argc, char **argv)
|
||||
fprintf(stderr, ".");
|
||||
} while (!OpenProxmark(0));
|
||||
|
||||
fprintf(stderr," Found.\n");
|
||||
fprintf(stderr, " Found.\n");
|
||||
|
||||
res = flash_start_flashing(can_write_bl, serial_port_name);
|
||||
if (res < 0)
|
||||
|
||||
@@ -125,7 +125,6 @@ static void *uart_receiver(void *targ) {
|
||||
PrintAndLog("Sending bytes to proxmark failed");
|
||||
}
|
||||
__atomic_clear(&txcmd_pending, __ATOMIC_SEQ_CST);
|
||||
//txcmd_pending = false;
|
||||
|
||||
// set offline flag
|
||||
if ( counter_to_offline == 3 ) {
|
||||
@@ -356,7 +355,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
# if _WIN32
|
||||
# ifdef _WIN32
|
||||
InitGraphics(argc, argv, script_cmds_file, usb_present);
|
||||
MainGraphics();
|
||||
# else
|
||||
|
||||
Reference in New Issue
Block a user