For my boot loaders I need the functionality that I can keep memory ranges from being erased while downloading the rest of the application. P&E provides a GDB server which interfaces with their probes (P&E Universal Multilinks, Tracelinks, …) and as well with the OpenSDA present on many of the Freescale evaluation boards. In CodeWarrior there is an option for ‘Advanced Programming Options’ which allows to preserve memory of the microcontroller FLASH (see “Programming part of flash“). However, that option or button is not present in the Eclipse version of the P&E GDB server (e.g. in Kinetis Design Studio). So how can I preserve some areas of FLASH in Eclipse with GDB?
UPDATE: Preserving Memory Ranges with P&E
With the most recent P&E Plugins (as of 9-May-2016), presevering memory ranges is now possible :-). Inside the debugger launch configuration, there is an Additional Options section with an Advanced Options button:
Behind this button, I can preserve memory ranges:
First Try: Launch Configuration Files
First, I was checking where the settings for memory preservation are saved. The debug connection stores its settings in a launch (.launch) configuration file. So I configured a connection to preserve memory areas. Comparing the .launch file before and afterwards shows the values in the .launch file:
So there are three different attributes involved:
- PRESERVE<number>_ACTIVE set to “1” (enabled) or “0” (disabled).
- PRESERVE<number>_START is the start address in decimal format.
- PRESERVE<number>_END is the end address in decimal format.
With this knowledge, I thought that I can apply the same entries to the .launch files used by P&E for their GDB server implementation:
- Enable sharing of the launch configuration, see “Sharing Debug Configuration with Eclipse“.
- Open the launch configuration file with a text editor and add the needed string attributes to it:
Well, things came to a screeching stop at this point. Unfortunately the settings the P&E GDB Server .launch files were kind of similar to the ones in their CodeWarrior implementation. But different. I tried guessing and poking around the different string attributes, but….. I had to gave up :-(. Ahhhhhhrggggg!
Well, my wife could tell you that I can get really grumpy if I know that something ‘has to be possible somehow’, but it does not work. I don’t like to give up (anyone does?)!
So I did another round of poking and googling, and stumbled over a P&E application note from 2008: “New Programming Feature For Non-Volatile Memory – Preserve Range”. And that article opened the door to do what I need :-).
Basically, that article describes that PRESERVE_ENTRIES can be added to the flash programming applet files. But it does not find where these files are. So here we go…
Locating Flash Applet File
When I do debugging, the P&E GDB debugger writes messages to a debug console. Switch to that console with the small menu behind the triangle:
This console shows where the GDB Server executable and files are located inside the Eclipse\plugins directory:
Browse to that folder on your disk (I can copy paste the path/text from the console output). In that folder, there is a ‘gdi’ and one level down a ‘P&E’ folder. For Windows it is inside ‘Win32’, on Linux it is inside the ‘lin’ folder:
Inside that folder, search for the microcontroller you are dealing with. In this example I’m working with the KL25Z:
The flash programming files are the *.arp files, and they are simple text files. I’m using the KL25Z128. So it must be either the
Both Files are similar:
So which one is used? For this I have a look at the console output
So with this I know which flash programming file is used :-).
I open that file in a text editor and search the line with NO_BASE_ADDRESS.
💡 In any case, I recommend to make a backup of the file before doing any change.
After that line I add a PRESERVE_RANGE line:
Do *not* change the NO_BASE_ADDRESS line. Multiple PRESERVE_RANGE lines can be added. The PRESERVE_RANGE line states as first number the start address offset (from NO_BASE_ADDRESS), and the second number is the end address offset (again from NO_BASE_ADDRESS).
💡 See details in “New Programming Feature For Non-Volatile Memory – Preserve Range” about the address calculation.
With this change, I should now see that this memory range is preserved:
💡 Notice the warning about the modified CRC16. This makes sense, as I have modified the file. I think the last two bytes in the file are the checksum.
To disable the change, I can either restore my backup file, or comment the change in the file.
Preserving memory ranges in Eclipse with P&E GDB is not that simple with a dialog as in CodeWarrior. But very powerful for me after I have understood what needs to be done. It would be nice to have this in a dialog as in CodeWarrior, but until then, I have a way to make it happen.
Happy Preserving 🙂