Adding CRP Checking.
authorNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 10 Mar 2015 20:43:21 +0000 (21:43 +0100)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 10 Mar 2015 20:43:21 +0000 (21:43 +0100)
README
isp_utils.h
prog_commands.c

diff --git a/README b/README
index 5bb8319..dbe5588 100644 (file)
--- 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 ?
 
index 729c9f3..21b08ea 100644 (file)
 #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);
 
 
index 664f0ae..cf80f8b 100644 (file)
@@ -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));