From: Nathael Pajani Date: Tue, 10 Mar 2015 20:43:21 +0000 (+0100) Subject: Adding CRP Checking. X-Git-Tag: v1.07~4 X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=22bda851d3dcd3a1c5a731e38d60827dd4f7d4a6;p=soft%2Ftools%2Flpctools Adding CRP Checking. --- diff --git a/README b/README index 5bb8319..dbe5588 100644 --- a/README +++ b/README @@ -28,7 +28,5 @@ Allow flashing of parts with flash sectors of different sizes (LPC1764 has 16 small 4k sectors and two big 32k sectors). --> Need to change parts definition format. -Prevent unwanted writting of Code Read Protection values. - Add the definition of all LPC parts ? diff --git a/isp_utils.h b/isp_utils.h index 729c9f3..21b08ea 100644 --- a/isp_utils.h +++ b/isp_utils.h @@ -24,6 +24,15 @@ #ifndef ISP_UTILS_H #define ISP_UTILS_H + +/* ---- CRP Protection values ---------------------------------------------------*/ +#define CRP_OFFSET 0x000002FC +#define CRP_NO_ISP 0x4E697370 +#define CRP_CRP1 0x12345678 +#define CRP_CRP2 0x87654321 +#define CRP_CRP3 0x43218765 + + void isp_dump(const unsigned char* buf, unsigned int buf_size); diff --git a/prog_commands.c b/prog_commands.c index 664f0ae..cf80f8b 100644 --- a/prog_commands.c +++ b/prog_commands.c @@ -196,6 +196,7 @@ int flash_target(struct part_desc* part, char* filename, int calc_user_code) uint32_t uuencode = part->uuencode; uint32_t* v = NULL; /* Used for checksum computing */ uint32_t cksum = 0; + uint32_t crp = 0; /** Sanity checks *********************************/ /* RAM buffer address within RAM */ @@ -244,6 +245,16 @@ int flash_target(struct part_desc* part, char* filename, int calc_user_code) } printf("Checksum check OK\n"); + crp = v[(CRP_OFFSET / 4)]; + if ((crp == CRP_NO_ISP) || (crp == CRP_CRP1) || (crp == CRP_CRP2) || (crp == CRP_CRP3)) { + printf("CRP : 0x%08x\n", crp); + printf("The binary has CRP protection ativated, which violates GPLv3.\n"); + printf("Check the licence for the software you are using, and if this is allowed,\n"); + printf(" then modify this software to allow flashing of code with CRP protection\n"); + printf(" activated. (Or use another software).\n"); + return -6; + } + blocks = (size / write_size) + ((size % write_size) ? 1 : 0); /* Gonna write out of flash ? */ if ((blocks * write_size) > part->flash_size) { @@ -251,7 +262,7 @@ int flash_target(struct part_desc* part, char* filename, int calc_user_code) printf("Flash size : %d, trying to flash %d blocks of %d bytes : %d\n", part->flash_size, blocks, write_size, (blocks * write_size)); free(data); - return -6; + return -7; } printf("Flash size : %d, trying to flash %d blocks of %d bytes : %d\n", part->flash_size, blocks, write_size, (blocks * write_size));