Pass 2; commit 2;

This commit is contained in:
Colin J. Brigato 2018-09-06 05:24:50 +02:00
parent 368fe11df0
commit c74dbb63b8
6 changed files with 77 additions and 34 deletions

View file

@ -12,13 +12,36 @@
#include "rsa.h" #include "rsa.h"
#include "sha1.h" #include "sha1.h"
#define MCK 48000000
//#define FLASH_BAUD 24000000
#define FLASH_MINFAST 24000000 //33000000
#define FLASH_BAUD MCK/2
#define FLASH_FASTBAUD MCK
#define FLASH_MINBAUD FLASH_FASTBAUD
#define FASTFLASH (FLASHMEM_SPIBAUDRATE > FLASH_MINFAST)
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
int usage_flashmem_spibaud(void){
PrintAndLogEx(NORMAL, "Usage: mem spibaud [h] <baudrate>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h this help");
PrintAndLogEx(NORMAL, " <baudrate> SPI baudrate in MHz [24|48]");
PrintAndLogEx(NORMAL, " ");
PrintAndLogEx(NORMAL, " If >= 24Mhz, FASTREADS instead of READS instruction will be used.");
PrintAndLogEx(NORMAL, " Reading Flash ID will virtually always fail under 48Mhz setting");
PrintAndLogEx(NORMAL, " Unless you know what you are doing, please stay at 24Mhz");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " mem spibaud 48");
return 0;
}
int usage_flashmem_read(void){ int usage_flashmem_read(void){
PrintAndLogEx(NORMAL, "Read flash memory on device"); PrintAndLogEx(NORMAL, "Read flash memory on device");
PrintAndLogEx(NORMAL, "Usage: mem read o <offset> l <len> [f]"); PrintAndLogEx(NORMAL, "Usage: mem read o <offset> l <len>");
PrintAndLogEx(NORMAL, " o <offset> : offset in memory"); PrintAndLogEx(NORMAL, " o <offset> : offset in memory");
PrintAndLogEx(NORMAL, " l <len> : length"); PrintAndLogEx(NORMAL, " l <len> : length");
PrintAndLogEx(NORMAL, " f : fastRead mode");
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " mem read o 0 l 32"); // read 32 bytes starting at offset 0 PrintAndLogEx(NORMAL, " mem read o 0 l 32"); // read 32 bytes starting at offset 0
@ -42,7 +65,6 @@ int usage_flashmem_save(void){
PrintAndLogEx(NORMAL, " o <offset> : offset in memory"); PrintAndLogEx(NORMAL, " o <offset> : offset in memory");
PrintAndLogEx(NORMAL, " l <length> : length"); PrintAndLogEx(NORMAL, " l <length> : length");
PrintAndLogEx(NORMAL, " f <filename> : file name"); PrintAndLogEx(NORMAL, " f <filename> : file name");
PrintAndLogEx(NORMAL, " + : fast read mode");
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " mem save f myfile"); // download whole flashmem to file myfile PrintAndLogEx(NORMAL, " mem save f myfile"); // download whole flashmem to file myfile
@ -81,14 +103,9 @@ int CmdFlashMemRead(const char *Cmd) {
uint8_t cmdp = 0; uint8_t cmdp = 0;
bool errors = false; bool errors = false;
uint32_t start_index = 0, len = 0; uint32_t start_index = 0, len = 0;
uint8_t fast = 0;
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch (tolower(param_getchar(Cmd, cmdp))) { switch (tolower(param_getchar(Cmd, cmdp))) {
case 'f':
fast = 1;
cmdp += 1;
break;
case 'o': case 'o':
start_index = param_get32ex(Cmd, cmdp+1, 0, 10); start_index = param_get32ex(Cmd, cmdp+1, 0, 10);
cmdp += 2; cmdp += 2;
@ -114,11 +131,24 @@ int CmdFlashMemRead(const char *Cmd) {
return 1; return 1;
} }
UsbCommand c = {CMD_READ_FLASH_MEM, {start_index, len, fast}}; UsbCommand c = {CMD_FLASHMEM_READ, {start_index, len, 0}};
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
return 0; return 0;
} }
int CmdFlashmemSpiBaudrate(const char *Cmd) {
char ctmp = param_getchar(Cmd, 0);
if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') return usage_flashmem_spibaud();
uint32_t baudrate = param_get32ex(Cmd, 0, 0, 10);
baudrate = baudrate*1000000;
if (baudrate != FLASH_BAUD && baudrate != FLASH_MINBAUD ) return usage_flashmem_spibaud();
UsbCommand c = {CMD_FLASHMEM_SET_SPIBAUDRATE, {baudrate, 0, 0}};
SendCommand(&c);
return 0;
}
int CmdFlashMemLoad(const char *Cmd){ int CmdFlashMemLoad(const char *Cmd){
FILE *f; FILE *f;
@ -196,7 +226,7 @@ int CmdFlashMemLoad(const char *Cmd){
while (bytes_remaining > 0){ while (bytes_remaining > 0){
uint32_t bytes_in_packet = MIN(FLASH_MEM_BLOCK_SIZE, bytes_remaining); uint32_t bytes_in_packet = MIN(FLASH_MEM_BLOCK_SIZE, bytes_remaining);
UsbCommand c = {CMD_WRITE_FLASH_MEM, {start_index + bytes_sent, bytes_in_packet, 0}}; UsbCommand c = {CMD_FLASHMEM_WRITE, {start_index + bytes_sent, bytes_in_packet, 0}};
memcpy(c.d.asBytes, dump + bytes_sent, bytes_in_packet); memcpy(c.d.asBytes, dump + bytes_sent, bytes_in_packet);
clearCommandBuffer(); clearCommandBuffer();
@ -228,7 +258,6 @@ int CmdFlashMemSave(const char *Cmd){
uint8_t cmdp = 0; uint8_t cmdp = 0;
bool errors = false; bool errors = false;
uint32_t start_index = 0, len = FLASH_MEM_MAX_SIZE; uint32_t start_index = 0, len = FLASH_MEM_MAX_SIZE;
uint8_t fast = 0;
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch (tolower(param_getchar(Cmd, cmdp))) { switch (tolower(param_getchar(Cmd, cmdp))) {
@ -241,10 +270,6 @@ int CmdFlashMemSave(const char *Cmd){
start_index = param_get32ex(Cmd, cmdp+1, 0, 10); start_index = param_get32ex(Cmd, cmdp+1, 0, 10);
cmdp += 2; cmdp += 2;
break; break;
case '+':
fast = 1;
cmdp += 1;
break;
case 'f': case 'f':
//File handling //File handling
if ( param_getstr(Cmd, cmdp+1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE ) { if ( param_getstr(Cmd, cmdp+1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE ) {
@ -314,7 +339,7 @@ int CmdFlashMemWipe(const char *Cmd){
//Validations //Validations
if (errors || cmdp == 0 ) return usage_flashmem_wipe(); if (errors || cmdp == 0 ) return usage_flashmem_wipe();
UsbCommand c = {CMD_WIPE_FLASH_MEM, {page, initalwipe, 0}}; UsbCommand c = {CMD_FLASHMEM_WIPE, {page, initalwipe, 0}};
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
UsbCommand resp; UsbCommand resp;
@ -359,7 +384,7 @@ int CmdFlashMemInfo(const char *Cmd){
//Validations //Validations
if (errors ) return usage_flashmem_info(); if (errors ) return usage_flashmem_info();
UsbCommand c = {CMD_INFO_FLASH_MEM, {0, 0, 0}}; UsbCommand c = {CMD_FLASHMEM_INFO, {0, 0, 0}};
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
UsbCommand resp; UsbCommand resp;
@ -488,7 +513,7 @@ int CmdFlashMemInfo(const char *Cmd){
if (shall_write) { if (shall_write) {
// save to mem // save to mem
c = (UsbCommand){CMD_WRITE_FLASH_MEM, {FLASH_MEM_SIGNATURE_OFFSET, FLASH_MEM_SIGNATURE_LEN, 0}}; c = (UsbCommand){CMD_FLASHMEM_WRITE, {FLASH_MEM_SIGNATURE_OFFSET, FLASH_MEM_SIGNATURE_LEN, 0}};
memcpy(c.d.asBytes, sign, sizeof(sign)); memcpy(c.d.asBytes, sign, sizeof(sign));
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
@ -520,6 +545,7 @@ int CmdFlashMemInfo(const char *Cmd){
static command_t CommandTable[] = { static command_t CommandTable[] = {
{"help", CmdHelp, 1, "This help"}, {"help", CmdHelp, 1, "This help"},
{"spibaud", CmdFlashmemSpiBaudrate, 1, "Set Flash memory Spi baudrate [rdv40]"},
{"read", CmdFlashMemRead, 1, "Read Flash memory [rdv40]"}, {"read", CmdFlashMemRead, 1, "Read Flash memory [rdv40]"},
{"info", CmdFlashMemInfo, 1, "Flash memory information [rdv40]"}, {"info", CmdFlashMemInfo, 1, "Flash memory information [rdv40]"},
{"load", CmdFlashMemLoad, 1, "Load data into flash memory [rdv40]"}, {"load", CmdFlashMemLoad, 1, "Load data into flash memory [rdv40]"},

View file

@ -298,9 +298,9 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_EML_BIGBUF); return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_EML_BIGBUF);
} }
case FLASH_MEM: { case FLASH_MEM: {
UsbCommand c = {CMD_DOWNLOAND_FLASH_MEM, {start_index, bytes, 0}}; UsbCommand c = {CMD_FLASHMEM_DOWNLOAD, {start_index, bytes, 0}};
SendCommand(&c); SendCommand(&c);
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_FLASHMEM); return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_FLASHMEM_DOWNLOADED);
} }
case SIM_MEM: { case SIM_MEM: {
//UsbCommand c = {CMD_DOWNLOAND_SIM_MEM, {start_index, bytes, 0}}; //UsbCommand c = {CMD_DOWNLOAND_SIM_MEM, {start_index, bytes, 0}};

View file

@ -57,12 +57,12 @@ typedef struct {
#define CMD_DOWNLOADED_EML_BIGBUF 0x0111 #define CMD_DOWNLOADED_EML_BIGBUF 0x0111
// RDV40, Flash memory operations // RDV40, Flash memory operations
#define CMD_READ_FLASH_MEM 0x0120 #define CMD_FLASHMEM_READ 0x0120
#define CMD_WRITE_FLASH_MEM 0x0121 #define CMD_FLASHMEM_WRITE 0x0121
#define CMD_WIPE_FLASH_MEM 0x0122 #define CMD_FLASHMEM_WIPE 0x0122
#define CMD_DOWNLOAND_FLASH_MEM 0x0123 #define CMD_FLASHMEM_DOWNLOAD 0x0123
#define CMD_DOWNLOADED_FLASHMEM 0x0124 #define CMD_FLASHMEM_DOWNLOADED 0x0124
#define CMD_INFO_FLASH_MEM 0x0125 #define CMD_FLASHMEM_INFO 0x0125
// For low-frequency tags // For low-frequency tags
#define CMD_READ_TI_TYPE 0x0202 #define CMD_READ_TI_TYPE 0x0202

View file

@ -30,6 +30,9 @@ typedef unsigned char byte_t;
#define MF_DBG_EXTENDED 4 #define MF_DBG_EXTENDED 4
extern int MF_DBGLEVEL; extern int MF_DBGLEVEL;
// Flashmem spi baudrate
extern uint32_t FLASHMEM_SPIBAUDRATE;
// reader voltage field detector // reader voltage field detector
#define MF_MINFIELDV 4000 #define MF_MINFIELDV 4000

View file

@ -67,13 +67,17 @@ typedef struct{
#define CMD_DOWNLOAD_EML_BIGBUF 0x0110 #define CMD_DOWNLOAD_EML_BIGBUF 0x0110
#define CMD_DOWNLOADED_EML_BIGBUF 0x0111 #define CMD_DOWNLOADED_EML_BIGBUF 0x0111
// RDV40, Flash memory operations // RDV40, Flash memory operations
#define CMD_READ_FLASH_MEM 0x0120 #define CMD_FLASHMEM_READ 0x0120
#define CMD_WRITE_FLASH_MEM 0x0121 #define CMD_FLASHMEM_WRITE 0x0121
#define CMD_WIPE_FLASH_MEM 0x0122 #define CMD_FLASHMEM_WIPE 0x0122
#define CMD_DOWNLOAND_FLASH_MEM 0x0123 #define CMD_FLASHMEM_DOWNLOAD 0x0123
#define CMD_DOWNLOADED_FLASHMEM 0x0124 #define CMD_FLASHMEM_DOWNLOADED 0x0124
#define CMD_INFO_FLASH_MEM 0x0125 #define CMD_FLASHMEM_INFO 0x0125
#define CMD_FLASHMEM_SET_SPIBAUDRATE 0x0126
// RDV40, Smart card operations // RDV40, Smart card operations
#define CMD_SMART_RAW 0x0140 #define CMD_SMART_RAW 0x0140

View file

@ -18,13 +18,23 @@ my $fullgitinfo = 'iceman';
my $ctime; my $ctime;
# GIT status 0 = dirty, 1 = clean , 2 = undecided # GIT status 0 = dirty, 1 = clean , 2 = undecided
my $clean = 2; my $clean = 2;
# Do we have acces to git command? # Do we have acces to git command?
my $commandGIT = `bash which git`; #######
# solves some bug on macos i.e:
##
# perl ../tools/mkversion.pl .. > version.c || cp ../common/default_version.c version.c
# /usr/bin/which: /usr/bin/which: cannot execute binary file
# fatal: No names found, cannot describe anything.
##
# anyway forcing any kind of shell is at least useless, at worst fatal.
my $commandGIT = "env -S which git";
if ( defined($commandGIT) ) { if ( defined($commandGIT) ) {
my $githistory = `git fetch --all`; my $githistory = `git fetch --all`;
my $gitversion = `git describe --dirty`; # now avoiding the "fatal: No names found, cannot describe anything." error by fallbacking to abbrev hash in such case
my $gitversion = `git describe --dirty --always`;
my $gitbranch = `git rev-parse --abbrev-ref HEAD`; my $gitbranch = `git rev-parse --abbrev-ref HEAD`;
$clean = $gitversion =~ '-dirty' ? 0 : 1; $clean = $gitversion =~ '-dirty' ? 0 : 1;