加密保护的机制Datasheet上都有详细说明。
具体特定芯片的加密,需仔细阅读datasheet中Flash spec及相关保护寄存器的spec,结合下面历程灵活更改(补充了datasheet的例程)。
在做访问保护操作之前,先将永久(临时)解访问保护程序烧入IFlash.
Set (XPEN, ROMEN) @ SYSCON register as “1” Set XFLASHEN @XPERCON register as “1”
1)Write Protection, Enable Write Protection of sectors B0F4 of Bank 0 in I-Flash module. FCR0H |= 0x0100; /* Set SPR in FCR0H*/ FARL = 0xDFB4; /*Load Add of register FNVWPIR in FARL*/ FARH = 0x000E; /*Load Add of register FNVWPIR in FARH*/ FDR0L = 0xFFEF; /*Load Data in FDR0L*/ FDR0H = 0xFFFF; /*Load Data in FDR0H*/ FCR0H |= 0x8000; /* Operation start*/
2)Temporary un-write protection, B0F4 temporarily un-write protection and programmingB0F4
FCR0H |=0x0100; FARL = 0xDFB4; FARH = 0x000E; FDR0L = 0xFFFF; /*Load Data in FDR0L*/ FDR0H = 0xFFFF; FCR0H |= 0x8000;
FCR0H |=0x2080; /* Set WPG & SMOD in FCR0H*/ FARL = 0x8000; /* Load B0F4 Add into FAR*/ FARH = 0x0001; FDR0L = 0xAAAA; /* Load Data in FDR*/ FDR0H = 0xFFFF; FCR0H |=0x8000; /* Operation start*/
3)Access Protection
Temp = FNVAPR0; Temp &= 0xFFFC; /* Set DBGP, ACCP as “0” in FNVAPR0*/ FCR0H |= 0x0100; /* Set SPR in FCR0H */ FARL = 0xDFB8; /* Load Add of FNVAPR0 into FARL*/ FARH = 0x000E; /* Load Add of FNVAPR0 into FARH */ FDR0L = Temp; /* Load Data into FDR0L*/ FCR0H |= 0x8000; /* Operation start*/
Notes: 1) The Default value of FNVAPR0 is ACFF; 2) Set both DBGP and ACCP in FNVAPR0 as “0” to disable Access protection permanently.
4)Disable in a permanent way Access Protection
FCR0H |= 0x0100; FARL = 0xDFBC; /* Load FNVAPR1 Add into FAR*/ FARH = 0x000E; FDR0L = 0xFFFE; /* Load Data into FDR*/ FDR0H = 0xFFFF; FCR0H |= 0x8000;
Notes: 1) Disable access protection routines must be programmed into I-Flash before Access protection operation
5) Enable in a permanent way Access Protection FCR0H |= 0x0100; FARL = 0xDFBC; /* Load FNVAPR1 Add into FAR*/ FARH = 0x000E; FDR0L = 0xFFFE; /* Load Data into FDR*/ FDR0H = 0xFFFE; FCR0H |= 0x8000;
|