2009-04-09 14:43:20 +08:00
|
|
|
#include <usb.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2009-12-22 20:35:36 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2009-04-09 14:43:20 +08:00
|
|
|
#include <strings.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2009-12-22 20:11:15 +08:00
|
|
|
#include "prox.h"
|
2009-04-09 14:43:20 +08:00
|
|
|
#include "proxmark3.h"
|
2010-01-04 13:11:08 +08:00
|
|
|
#include "flash.h"
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2009-12-22 20:46:04 +08:00
|
|
|
unsigned int current_command = CMD_UNKNOWN;
|
|
|
|
|
2010-01-04 13:11:08 +08:00
|
|
|
extern struct partition partitions[];
|
2009-09-01 22:35:13 +08:00
|
|
|
|
|
|
|
static void usage(char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
fprintf(stderr, "Usage: %s areas image [image [image]]\n", argv[0]);
|
|
|
|
fprintf(stderr, " areas is a comma-separated list of areas to flash, with no spaces\n");
|
|
|
|
fprintf(stderr, " Known areas are:");
|
2010-01-04 13:11:08 +08:00
|
|
|
|
|
|
|
for(i=0; partitions[i].name != NULL; i++) {
|
2009-09-01 22:35:13 +08:00
|
|
|
fprintf(stderr, " %s", partitions[i].name);
|
2009-07-24 10:30:08 +08:00
|
|
|
}
|
2010-01-04 13:11:08 +08:00
|
|
|
|
2009-09-01 22:35:13 +08:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fprintf(stderr, " image is the path to the corresponding image\n\n");
|
2010-01-05 08:02:12 +08:00
|
|
|
fprintf(stderr, "Example: %s os,fpga path/to/osimage.elf path/to/fpgaimage.elf\n", argv[0]);
|
2009-09-01 22:35:13 +08:00
|
|
|
}
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2009-09-01 22:35:13 +08:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
if(argc < 2) {
|
|
|
|
usage(argv);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Count area arguments */
|
|
|
|
int areas = 0, offset=-1, length=0;
|
|
|
|
while(find_next_area(argv[1], &offset, &length)) areas++;
|
|
|
|
|
|
|
|
if(areas != argc - 2) {
|
|
|
|
usage(argv);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
usb_init();
|
|
|
|
|
|
|
|
fprintf(stderr,"Waiting for Proxmark to appear on USB... ");
|
|
|
|
while(!(devh=OpenProxmark(0))) { sleep(1); }
|
|
|
|
fprintf(stderr,"Found.\n");
|
|
|
|
|
2010-01-04 13:11:08 +08:00
|
|
|
do_flash(argv);
|
2009-09-01 22:35:13 +08:00
|
|
|
|
2010-01-04 13:11:08 +08:00
|
|
|
UsbCommand c = {CMD_HARDWARE_RESET};
|
2009-12-22 20:46:04 +08:00
|
|
|
SendCommand(&c);
|
2009-04-09 14:43:20 +08:00
|
|
|
|
|
|
|
CloseProxmark();
|
|
|
|
|
|
|
|
fprintf(stderr,"Have a nice day!\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|