diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 40f8c0ad1..a3d5c3d2f 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -244,8 +244,7 @@ void ReadMem(int addr) { Dbprintf("%x: %02x %02x %02x %02x %02x %02x %02x %02x", addr, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]); } -/* osimage version information is linked in */ -extern struct version_information version_information; +/* osimage version information is linked in, cf commonutil.h */ /* bootrom version information is pointed to from _bootphase1_version_pointer */ extern char *_bootphase1_version_pointer, _flash_start, _flash_end, __data_src_start__; static void SendVersion(void) { @@ -265,10 +264,12 @@ static void SendVersion(void) { } else { FormatVersionInformation(temp, sizeof(temp), " bootrom: ", bootrom_version); strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1); + strncat(VersionString, "\n", sizeof(VersionString) - strlen(VersionString) - 1); } FormatVersionInformation(temp, sizeof(temp), " os: ", &version_information); strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1); + strncat(VersionString, "\n", sizeof(VersionString) - strlen(VersionString) - 1); #if defined(__clang__) strncat(VersionString, " compiled with Clang/LLVM "__VERSION__"\n", sizeof(VersionString) - strlen(VersionString) - 1); diff --git a/armsrc/util.c b/armsrc/util.c index ccff567eb..443c9e5f4 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -289,40 +289,6 @@ int BUTTON_HELD(int ms) { return BUTTON_ERROR; } -/* Similar to FpgaGatherVersion this formats stored version information - * into a string representation. It takes a pointer to the struct version_information, - * verifies the magic properties, then stores a formatted string, prefixed by - * prefix in dst. - */ -void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information) { - struct version_information *v = (struct version_information *)version_information; - dst[0] = 0; - strncat(dst, prefix, len - 1); - if (v->magic != VERSION_INFORMATION_MAGIC) { - strncat(dst, "Missing/Invalid version information\n", len - strlen(dst) - 1); - return; - } - if (v->versionversion != 1) { - strncat(dst, "Version information not understood\n", len - strlen(dst) - 1); - return; - } - if (!v->present) { - strncat(dst, "Version information not available\n", len - strlen(dst) - 1); - return; - } - - strncat(dst, v->gitversion, len - strlen(dst) - 1); - if (v->clean == 0) { - strncat(dst, "-unclean", len - strlen(dst) - 1); - } else if (v->clean == 2) { - strncat(dst, "-suspect", len - strlen(dst) - 1); - } - - strncat(dst, " ", len - strlen(dst) - 1); - strncat(dst, v->buildtime, len - strlen(dst) - 1); - strncat(dst, "\n", len - strlen(dst) - 1); -} - bool data_available(void) { #ifdef WITH_FPC_USART_HOST return usb_poll_validate_length() || (usart_rxdata_available() > 0); diff --git a/armsrc/util.h b/armsrc/util.h index 06c4e024e..c6523a813 100644 --- a/armsrc/util.h +++ b/armsrc/util.h @@ -91,7 +91,6 @@ void SpinUp(uint32_t speed); int BUTTON_CLICKED(int ms); int BUTTON_HELD(int ms); -void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information); bool data_available(void); #endif diff --git a/client/Makefile b/client/Makefile index ad2f5aa75..59685656b 100644 --- a/client/Makefile +++ b/client/Makefile @@ -179,7 +179,8 @@ CORESRCS = uart/uart_posix.c \ scandir.c \ crc16.c \ crc32.c \ - comms.c + comms.c \ + version.c CMDSRCS = crapto1/crapto1.c \ crapto1/crypto1.c \ @@ -308,7 +309,7 @@ CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o) OBJCOBJS = $(OBJCSRCS:%.m=$(OBJDIR)/%.o) BINS = proxmark3 -CLEAN = $(BINS) src/*.moc.cpp src/ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua +CLEAN = $(BINS) src/version.c src/*.moc.cpp src/ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua # transition: cleaning also old path stuff CLEAN += flasher *.moc.cpp ui/ui_overlays.h @@ -426,6 +427,11 @@ zlib: .PHONY: all clean install uninstall tarbin liblua jansson tinycbor reveng hardnested amiibo cliparser whereami mbedtls zlib +# version.c should be remade on every compilation +src/version.c: default_version.c + $(info [=] GEN $@) + $(Q)sh ../tools/mkversion.sh > $@ || perl ../tools/mkversion.pl > $@ || $(CP) $^ $@ + # easy printing of MAKE VARIABLES print-%: ; @echo $* = $($*) diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index 3b452b492..45e56ba49 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -20,6 +20,7 @@ #include "ui.h" #include "cmdhw.h" #include "cmddata.h" +#include "commonutil.h" static int CmdHelp(const char *Cmd); @@ -688,7 +689,9 @@ void pm3_version(bool verbose, bool oneliner) { if (oneliner) { // For "proxmark3 -v", simple printf, avoid logging - printf("Client: RRG/Iceman compiled with " PM3CLIENTCOMPILER __VERSION__ PM3HOSTOS PM3HOSTARCH "\n"); + char temp[PM3_CMD_DATA_SIZE - 12]; // same limit as for ARM image + FormatVersionInformation(temp, sizeof(temp), "Client: ", &version_information); + printf("%s compiled with " PM3CLIENTCOMPILER __VERSION__ PM3HOSTOS PM3HOSTARCH "\n", temp); return; } @@ -701,9 +704,11 @@ void pm3_version(bool verbose, bool oneliner) { SendCommandNG(CMD_VERSION, NULL, 0); if (WaitForResponseTimeout(CMD_VERSION, &resp, 1000)) { + char temp[PM3_CMD_DATA_SIZE - 12]; // same limit as for ARM image PrintAndLogEx(NORMAL, "\n " _YELLOW_("[ Proxmark3 RFID instrument ]")); PrintAndLogEx(NORMAL, "\n " _YELLOW_("[ CLIENT ]")); - PrintAndLogEx(NORMAL, " client: RRG/Iceman"); // TODO version info? + FormatVersionInformation(temp, sizeof(temp), " client: ", &version_information); + PrintAndLogEx(NORMAL, "%s", temp); PrintAndLogEx(NORMAL, " compiled with " PM3CLIENTCOMPILER __VERSION__ PM3HOSTOS PM3HOSTARCH); if (IfPm3Flash() == false && IfPm3Smartcard() == false && IfPm3FpcUsartHost() == false) { diff --git a/common/commonutil.c b/common/commonutil.c index f831d744d..14f2d58e5 100644 --- a/common/commonutil.c +++ b/common/commonutil.c @@ -8,6 +8,40 @@ // Utility functions used in many places, not specific to any piece of code. //----------------------------------------------------------------------------- #include "commonutil.h" +#include + +/* Similar to FpgaGatherVersion this formats stored version information + * into a string representation. It takes a pointer to the struct version_information, + * verifies the magic properties, then stores a formatted string, prefixed by + * prefix in dst. + */ +void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_info) { + struct version_information *v = (struct version_information *)version_info; + dst[0] = 0; + strncat(dst, prefix, len - 1); + if (v->magic != VERSION_INFORMATION_MAGIC) { + strncat(dst, "Missing/Invalid version information", len - strlen(dst) - 1); + return; + } + if (v->versionversion != 1) { + strncat(dst, "Version information not understood", len - strlen(dst) - 1); + return; + } + if (!v->present) { + strncat(dst, "Version information not available", len - strlen(dst) - 1); + return; + } + + strncat(dst, v->gitversion, len - strlen(dst) - 1); + if (v->clean == 0) { + strncat(dst, "-unclean", len - strlen(dst) - 1); + } else if (v->clean == 2) { + strncat(dst, "-suspect", len - strlen(dst) - 1); + } + + strncat(dst, " ", len - strlen(dst) - 1); + strncat(dst, v->buildtime, len - strlen(dst) - 1); +} /* ref http://www.csm.ornl.gov/~dunigan/crc.html diff --git a/common/commonutil.h b/common/commonutil.h index 0f3dc0065..fdd2ac065 100644 --- a/common/commonutil.h +++ b/common/commonutil.h @@ -41,6 +41,9 @@ # define NTIME(n) for (int _index = 0; _index < n; _index++) #endif +extern struct version_information version_information; +void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_info); + uint32_t reflect(uint32_t v, int b); // used in crc.c ... uint8_t reflect8(uint8_t b); // dedicated 8bit reversal uint16_t reflect16(uint16_t b); // dedicated 16bit reversal diff --git a/common_arm/default_version.c b/common/default_version.c similarity index 93% rename from common_arm/default_version.c rename to common/default_version.c index b4b8ae17d..e04c88d2a 100644 --- a/common_arm/default_version.c +++ b/common/default_version.c @@ -1,4 +1,4 @@ -#include "proxmark3_arm.h" +#include "common.h" /* This is the default version.c file that Makefile.common falls back to if neither sh nor perl are available */ const struct version_information __attribute__((section(".version_information"))) version_information = { VERSION_INFORMATION_MAGIC, diff --git a/include/common.h b/include/common.h index e7d6bba90..d52e40f10 100644 --- a/include/common.h +++ b/include/common.h @@ -36,6 +36,16 @@ #define PACKED __attribute__((packed)) +#define VERSION_INFORMATION_MAGIC 0x56334d50 // "PM3V" +struct version_information { + int magic; /* Magic sequence to identify this as a correct version information structure. Must be VERSION_INFORMATION_MAGIC */ + char versionversion; /* Must be 1 */ + char present; /* 1 if the version information could be created at compile time, otherwise 0 and the remaining fields (except for magic) are empty */ + char clean; /* 1: Tree was clean, no local changes. 0: Tree was unclean. 2: Couldn't be determined */ + char gitversion[50]; /* String with the git revision */ + char buildtime[30]; /* string with the build time */ +} PACKED; + // debug #define DBG_NONE 0 // no messages #define DBG_ERROR 1 // errors only diff --git a/include/proxmark3_arm.h b/include/proxmark3_arm.h index 3ea80da9d..de3ae9caa 100644 --- a/include/proxmark3_arm.h +++ b/include/proxmark3_arm.h @@ -115,15 +115,7 @@ //NVDD goes LOW when USB is attached. #define USB_ATTACHED() !((AT91C_BASE_PIOA->PIO_PDSR & GPIO_NVDD_ON) == GPIO_NVDD_ON) -#define VERSION_INFORMATION_MAGIC 0x56334d50 // "PM3V" -struct version_information { - int magic; /* Magic sequence to identify this as a correct version information structure. Must be VERSION_INFORMATION_MAGIC */ - char versionversion; /* Must be 1 */ - char present; /* 1 if the version information could be created at compile time, otherwise 0 and the remaining fields (except for magic) are empty */ - char clean; /* 1: Tree was clean, no local changes. 0: Tree was unclean. 2: Couldn't be determined */ - char gitversion[50]; /* String with the git revision */ - char buildtime[30]; /* string with the build time */ -} PACKED; +// VERSION_INFORMATION is now in common.h #define COMMON_AREA_MAGIC 0x43334d50 // "PM3C" #define COMMON_AREA_COMMAND_NONE 0 diff --git a/tools/mkversion.pl b/tools/mkversion.pl index 95a794697..eecacbd72 100644 --- a/tools/mkversion.pl +++ b/tools/mkversion.pl @@ -64,7 +64,7 @@ $fullgitinfo =~ s/(\s)//g; $fullgitinfo = substr $fullgitinfo, 0, 49; print <