J-Link memory maps

From SEGGER Wiki
Jump to: navigation, search

During debug, sometimes certain memory needs to be accessed differently than normal (stack, global variables, ...)
or under special circumstances debugger accesses to that memory would need to be suppressed completely.

Overview

On some devices for example the DDR RAM may not be accessed before it has been initialized because otherwise the bus access never finishes and the whole bus (and sooner or later the whole device + application) hangs.
Be it a bug in the chip or just a known precaution mentioned by the reference manual of the device, fact is that such accesses must be avoided.
A common case is to have a memory window or a watch window (global variables) open and they point to locations in DDR RAM.
When opening such a window during debug, there is usually no problem, but what if now the debug session is ended and restarted?
At the next debug session start, the IDE may want to update the memory window before main() is reached and before DDR RAM init etc. took place.
Now your debug session would be broken and you have no clue why.
For handling such cases, J-Link supports a memory map for before startup completion.
As at some point (usually before reaching main() as part of the low-level startup code that also initializes the clocks etc.) the DDR RAM becomes valid and must be accessible,
J-Link may not block such memory accesses forever.
For handling such cases, J-Link supports a memory map for after startup completion.

Before startup completion point

This describes the period in an application from reset, until main() is reached, so the period where MMU, caches, DDR RAM etc. may not be initialized yet.
The memory map before startup completion for example allows the user to define exclude regions, so addresses that when the debugger tries to access them,
will just be ignored by J-Link and not forwarded to the target for reading and writing.

This memory map may be viewed and modified via the J-Link control panel on the "MemMap".
All changes done to this map are remembered in the J-Link settings file and loaded from it on the next debug session start.

JLinkMemMap BeforeStartupCompletion.png


JLinkMemMap Add.png

Note:
The "before startup completion point" memory map is supported since J-Link software V7.92d

After startup completion point

This describes the period in an application after main() has been reached, so when MMU, caches, DDR RAM etc. can be assumed as being initialized and accessible.
In this map, it is also possible to specify exclude regions, e.g. for cases
where the target MCU does not provide an MPU / MMU but still has sensitive memory (e.g. a DDR RAM area that is not used because there is no DDR RAM connected to the MCU).
For such cases, a region needs to be added to both memory maps, before and after startup completion because such areas must not be accessed, any time during a debug session.

Note:
The "after startup completion point" memory map is supported since J-Link software V7.92d

Memory access map

J-Link can be configured to use different methods of accessing memory depending on the address range and if the core is halted or running.
The memory access map to be used by J-Link can be set by passing the path to an .xml file using the following J-Link command string:

JLinkMemAccMapXMLPath = <PathToFile>

Note: When passing a file path, be sure to encapsulate it in quotation marks (") if the path contains one ore more spaces.

The XML file is expected to have the following structure:

 <MemMap>
   <CoreRunning>
     <Range Start=... Size=... Zone=... />
     <!-- [...] -->
   </CoreRunning>
   <CoreHalted>
     <Range Start=... Size=... Zone=... />
     <!-- [...] -->
   </CoreHalted>
 </MemMap>

Between the <CoreRunning> tags, ranges can be defined that determine the memory access method J-Link should use when the core is running.
Ranges inbetween the <CoreHalted> tags determine the memory access method J-Link should use when the core is halted.

Each range consists of a <Range> tag with the attributes Start, Size and Zone.

  • Start defines the start address of the memory range (e.g "0x1FFF0000")
  • Size defines the size of the memory range in bytes (e.g. "0x400")
  • Zone defines the memory access method J-Link shoud use for that range (e.g. "AHB-AP (AP0)")

For more information regarding AHB-AP, refer to DAP.

Example:

 <MemMap>
   <!-- Target core: Cortex R4 -->
   <!-- When using AHB-AP accesses it is like a DMA accesses the memory. -->
   <!-- This means that this bypasses any MMU settings and will access the physical address, -->
   <!-- while "Default" goes through the CPU and sees the same as the core -->
   <CoreRunning>
     <Range Start="0x00000000" Size="0x100" Zone="AHB-AP (AP0)"/>
     <Range Start="0x00000100" Size="0x300" Zone="Default"/>
   </CoreRunning>
   <CoreHalted>
     <Range Start="0x00000000" Size="0x400" Zone="AHB-AP (AP0)"/>
   </CoreHalted>
 </MemMap>