How to Ascertain Last Address of User Code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to Ascertain Last Address of User Code

1,381 Views
airbusboy
Contributor I
Hi

I have a requirement to perform a run-time CRC check on all of the user code residing in flash memory.

From the map file, it would appear that constant strings located in the rodata1section by the linker seem to be placed at or near the end of my user code. However, when looking at a memory dump at these addresses there seems to be a few bytes "tagged" on the end that i can't explain:-

00, 01, 00, A0, 80, 00, 00

My question really is how to reliably ascertain the last address of my user code so that a CRC calculation can be performed on all code up to said address.

Many thanks

Gary

Labels (1)
0 Kudos
Reply
2 Replies

493 Views
CompilerGuru
NXP Employee
NXP Employee
In addition to what YeOldeBDM already said. My guess is that you see the copy down content behind the strings. You can check in the map file, there is a special section "COPYDOWN SECTION" which shows what those bytes mean a bit more clear (but still a bit cryptic too). Also the "SECTION-ALLOCATION SECTION" part of the map file shows what some part is used for, if it does not appear in the "OBJECT LIST SORTED BY ADDRESS" which I usually would consult first, but it does not contain the copy down elements for this case. In order to get the end address of the COPY section, you could use something like this (not tested) #define __SEG_END_REF(a) __SEG_END_ ## a #define __SEG_END_DEF(a) extern const char __SEG_END_REF( a) [] __SEG_SIZE_DEF(COPY); and then __SEG_END_REF(COPY) names a linker defined object just behind the first byte no longer used by your application. But I think the use of the FILL command, as proposed by YeOldeBDM is simpler :smileyhappy:. Daniel
0 Kudos
Reply

493 Views
YeOldeBDM
Contributor III
If you are using Codewarrior, there is an easy solution. By including additional commands in the PRM file, you can have the linker fill all of unused ROM with 0xFF, compute a checksum by simple addition or a variety of CRC methods, and store that checksum in a ROM location(s) of your choice. So you don't have to keep track of where your code is located.
 
You will have to write some code to compute the checksum and compare it to the value computed and stored by the linker. I have no qualms about putting this code in the startup code file for the project.
 
I believe there is a technical note in the documentation that describes the whole process, but I can't point to it specifically.
 
 
 
0 Kudos
Reply