Hi Youdong,
I suppose that you mean global address 0x700000 instead 0x70000. Such address is quite inconvenient since you should access it through paged access and you should allocate whole 1kB P-Flash sector just for this key (you must erase sector prior any writing). I suppose that EEPROM, D-Flash or potentially also RAM may be used rather than P-Flash.
The RAM content is unaffected by a system reset, but its value is also random after power-up. So, there is still tiny chance that random value may fit our key. For that case, we should combine it with testing PORF flag followed by clearing this flag. The code will jump into bootloader only when Bootloader key will fit and PORF flag is 0 OR when the application is not loaded yet (=erased AppResetVect).
You may use similar code as code for check whether AppResetVect is already written. Here I used BootloaderKey at EEPROM address 0x0C00 with valid value 0x5AA5
BootloaderKey: equ $0C00; here is stored key for enter into bootloader. 0x0C00 points to EEPROM.
ldd BootloaderKey
cpd #$5AA5 ; compare the content of accumulator D with a 16-bit Bootloader key value
beq GoBoot ; if the BootloaderKey fits
; then start the bootloader
ldd AppResetVect
cpd #$ffff
beq GoBoot ; if the application reset vector is not available
; then start the bootloader
ldx AppResetVect
jmp 0,x ; jump to the application
Note: I didn’t test this code – it is rather a just idea.
About your second question)
You may edit bootloader prm linker file and modify RAM_CODE_SEG, ROM_F000 segment ranges.
When you increase the size of RAM_CODE_SEG segment, you should also move down higher RAM segment border.
For example:
RAM = READ_WRITE 0x3700 TO 0x3AFF;
RAM_CODE_SEG = READ_ONLY 0xFB00 TO 0xFEFF RELOCATE_TO 0x3B00;
ROM_E000 = READ_ONLY 0xE000 TO 0xFAFF;
//…
NON_BANKED INTO ROM_E000;
Since we increased RAM_CODE_SEG segment size, we have to edit also address in RAM where we copy this code. Unfortunately, the address is not in macro, but directly hard coded in CopyCodeToRAM() function. Please edit:
// Dst = (UINT8 *)0x3D00;
Dst = (UINT8 *)0x3B00;
Since the original area 0xEFE0~0xEFFF is used for application reset vector, we should move it to somewhere else – the optimal area is between application and bootloader area – for example into 0xDFE0~0xDFFF.
In that case, we should edit main.c:
//#define RESET_VEC_DST 0x7FEFF8
#define RESET_VEC_DST 0x7FDFF8
And Start12X.s:
AppResetVect: equ $dffe ; here is stored reset vector of user application
And finally, the prm linker file in the application project must be updated accordingly. For example:
ROM_C000 = READ_ONLY DATA_NEAR IBCC_NEAR 0xC000 TO 0xDFDF;
Note: Again, I didn’t test this code – it is rather a just idea.
I hope it helps you.
Have a great day,
Radek
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------