View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 345
|
pcd_bootloader |
Posted: Sun Feb 25, 2018 7:44 am |
|
|
Hello All,
In connection with this topic http://www.ccsinfo.com/forum/viewtopic.php?p=216057 I have successful run Modbus TCP/IP server, Modbus RTU and double floats on DsPic33EP512MU810. For now every things are OK!
Also successful run ccs "ex_pcd_aux_bootloader" but when load wrong hex file bootloader crashes and I have to load bootloader img. again with ICD U64 programmer.
I tried to use #fuse AWRT,APROTECT but serial bootloader does't start.
Thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Sun Feb 25, 2018 12:49 pm |
|
|
Your chip does not support boot segment protection.
Just modify the bootloader, so it won't write to the memory area where your bootloader sits. Just check the address when received and if this falls into the area where the bootloader sits, don't load the data. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Sun Feb 25, 2018 3:43 pm |
|
|
Hello Mr. Ttelmah,
In the datasheet of the dsPic33EP512MU810 on a page 479 is said :
APL FAS(2) Immediate Auxiliary Segment Code-Protect bit
1 = Auxiliary program memory is not code-protected
0 = Auxiliary program memory is code-protected
AWRP FAS(2) Immediate Auxiliary Segment Write-Protect bit
1 = Auxiliary program memory is not write-protected
0 = Auxiliary program memory is write-protected
In this sense how to lock boot segment if it is located in Auxiliary program memory?
Also pcd_aux_bootloader define this memory region:
Code: |
#define APPLICATION_START 0
#define APPLICATION_END getenv("PROGRAM_MEMORY")
|
which is not in aux.memory region (0x7FC000-0x7FFFF8). |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Mon Feb 26, 2018 3:20 am |
|
|
Are you compiling your runtime code to work with the auxiliary bootloader?. As in the example ex_pcd_aux_bootload.c. Otherwise your code will be written to work in the primary memory, and not boot 'through' the auxiliary memory.
Then key is that it is the bootloader that needs to be written with the fuses set to protect itself, not the code you load. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Mon Feb 26, 2018 3:59 am |
|
|
Hi,
Quote: | Are you compiling your runtime code to work with the auxiliary bootloader?. |
Yes, I have added in my application code:
Code: |
//This is a necessary include file. It reserves space so that the
//bootloader is not overwritten.
#include <pcd_bootloader.h>
|
But the main problem is that bootloader crashes when load incorrect hex file and how to protect bootloader code space from read/write, unless it is erased!
Part of aux_bootloader.c
Code: |
#include <33EP512MU810.h>
#device ICSP=1
//#fuses AWRT,APROTECT // does't work (bootloader doesn't start)
#fuses NOJTAG,NOWDT,RESET_AUX //The RESET_AUX fuse causes PIC to reset into Auxiliary Memory
#build (AUX_MEMORY) //Build code for Auxiliary Memory
#use delay(clock=120MHz, crystal=8MHz)
#pin_select U1TX = PIN_F5
#pin_select U1RX = PIN_F4
#use rs232(Baud=38400,UART1,errors)
#define PUSH_BUTTON PIN_E8
#define LED1 PIN_A0
#define LED2 PIN_G9
//The following defines are necessary to use PCD's serial bootloader, loader_pcd.c.
#define _bootloader
#define LOADER_SIZE 0
#define APPLICATION_START 0
#define APPLICATION_END getenv("PROGRAM_MEMORY")
//Include PCD's serial bootloader
#include <loader_pcd.c> |
Thanks, |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Mon Feb 26, 2018 4:30 am |
|
|
OK. The problem setting these:
Code: |
#fuses AWRT,APROTECT // does't work (bootloader doesn't start)
|
Without also setting APLK.
If I remember correctly (another device), unless the APLK bits match the AWRT/APROTECT bits, it security locks the device. Only a bulk erase can then re-program it.
So:
Code: |
#fuses AWRT,APROTECT, APLK
|
Which then protects the auxiliary segment, without enabling the device lock.
I hope this is the same on the device you have. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Mon Feb 26, 2018 5:00 am |
|
|
With this fuse settings still no success:
Code: |
#fuses NOJTAG,NOWDT,RESET_AUX,AWRT,APROTECT,APLK
|
Bootloader does not start.
CCS C Compiller ver. 5.061 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Mon Feb 26, 2018 5:14 am |
|
|
I suggest you talk to CCS.
My guess is that the problem is the jump from general segment to auxiliary. This is only allowed to go to the last 32 instructions of the segment, when you are in high security mode (which is what you are enabling for this segment). You are probably going to have to force the bootloader vector to be in this area, rather than it's default location. A jump to anywhere else will cause a GPF, so the code won't run.... |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Mon Feb 26, 2018 7:27 am |
|
|
Okay,
I sent mail to CCS Support.
Thanks Mr.Ttelmah! |
|
|
|