From 0384359aa4fb2b8a2fa12658cde8714177319533 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 21 Aug 2021 23:52:15 +0200 Subject: [PATCH] icopyx bootloader safeguard --- Makefile | 3 ++- bootrom/bootrom.c | 6 ++++++ client/Makefile | 11 +++++++++++ client/src/flash.c | 4 ++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d8fd3092d..afa30c0f8 100644 --- a/Makefile +++ b/Makefile @@ -132,7 +132,7 @@ bootrom/%: FORCE cleanifplatformchanged armsrc/%: FORCE cleanifplatformchanged fpga_compress/% $(info [*] MAKE $@) $(Q)$(MAKE) --no-print-directory -C armsrc $(patsubst armsrc/%,%,$@) DESTDIR=$(MYDESTDIR) -client/%: FORCE +client/%: FORCE cleanifplatformchanged $(info [*] MAKE $@) $(Q)$(MAKE) --no-print-directory -C client $(patsubst client/%,%,$@) DESTDIR=$(MYDESTDIR) recovery/all: bootrom/all armsrc/all @@ -222,6 +222,7 @@ ifeq ($(PLATFORM_CHANGED),true) $(Q)$(MAKE) --no-print-directory -C bootrom clean $(Q)$(MAKE) --no-print-directory -C armsrc clean $(Q)$(MAKE) --no-print-directory -C recovery clean + $(Q)$(MAKE) --no-print-directory -C client clean $(Q)$(MAKE) --no-print-directory -C tools/fpga_compress clean $(Q)echo CACHED_PLATFORM=$(PLATFORM) > .Makefile.options.cache $(Q)echo CACHED_PLATFORM_EXTRAS=$(PLATFORM_EXTRAS) >> .Makefile.options.cache diff --git a/bootrom/bootrom.c b/bootrom/bootrom.c index 934ee2a5c..0ebfa86df 100644 --- a/bootrom/bootrom.c +++ b/bootrom/bootrom.c @@ -112,6 +112,9 @@ static void UsbPacketReceived(uint8_t *packet) { break; case CMD_FINISH_WRITE: { +#if defined ICOPYX + if (c->arg[1] == 0xff && c->arg[2] == 0x1fd) { +#endif for (int j = 0; j < 2; j++) { uint32_t flash_address = arg0 + (0x100 * j); AT91PS_EFC efc_bank = AT91C_BASE_EFC0; @@ -147,6 +150,9 @@ static void UsbPacketReceived(uint8_t *packet) { reply_old(CMD_NACK, sr, 0, 0, 0, 0); } } +#if defined ICOPYX + } +#endif } break; diff --git a/client/Makefile b/client/Makefile index 88b0f78de..57c1ea129 100644 --- a/client/Makefile +++ b/client/Makefile @@ -5,6 +5,17 @@ #----------------------------------------------------------------------------- include ../Makefile.defs +ifeq ($(PLTNAME),) + -include ../Makefile.platform + -include ../.Makefile.options.cache + ifneq ($(PLATFORM), $(CACHED_PLATFORM)) + $(error platform definitions have been changed, please "make clean" at the root of the project) + endif +endif + +ifeq ($(PLATFORM),PM3ICOPYX) + INCLUDES += -DICOPYX +endif INSTALLBIN = proxmark3 INSTALLSHARE = cmdscripts lualibs luascripts pyscripts resources dictionaries diff --git a/client/src/flash.c b/client/src/flash.c index 6a2cb0787..6c3f9a689 100644 --- a/client/src/flash.c +++ b/client/src/flash.c @@ -522,7 +522,11 @@ static int write_block(uint32_t address, uint8_t *data, uint32_t length) { memset(block_buf, 0xFF, BLOCK_SIZE); memcpy(block_buf, data, length); PacketResponseNG resp; +#if defined ICOPYX + SendCommandBL(CMD_FINISH_WRITE, address, 0xff, 0x1fd, block_buf, length); +#else SendCommandBL(CMD_FINISH_WRITE, address, 0, 0, block_buf, length); +#endif int ret = wait_for_ack(&resp); if (ret && resp.oldarg[0]) { uint32_t lock_bits = resp.oldarg[0] >> 16;