Debug Bootloader and Application in same Ozone project

From SEGGER Wiki
Jump to: navigation, search

Whenever a new project is created with Ozone, Ozone will assume that the .elf file you opened also points to the starting point of your application. This is usually the case. However should you want to e.g. debug a bootloader first the Ozone project must be edited accordingly.

How to debug bootloader and application

Each Ozone project is saved as a .jdebug file. The Ozone project itself is written in a C-like scripting language and can be edited if needed. Per default the function OnProjectLoad() will be populated and load your main application:

void OnProjectLoad (void) {
  [...]
  File.Open ("mainapplication.elf");
  [...]
} 

Now if you want to debug another application e.g. a bootloader first you need to load that file first and then load your application file later by e.g. using the AfterTargetHalt() function. This setup requires the target to be halted after bootloader execution before branching into your main application.

void AfterTargetHalt() {

  unsigned int PC;
  unsigned int SP;

  PC = Target.GetReg("PC");
  if (PC == <BOOTLOADER_END_PC>) {
    File.Load("mainapplication.elf", 0);
    PC = <MAIN_IMAGE_ENTRY_PC>;
    SP = <MAIN_IMAGE_ENTRY_SP>;
    Target.SetReg("PC", PC);
    Target.SetReg("SP", SP);
  }
} 

<BOOTLOADER_END_PC> is typically the address of the last instruction in your boot loader where you should be halted at before doing the switch as explained above.

OnProjectLoad() would then look as follows:

void OnProjectLoad (void) {
  [...]
  File.Open ("bootloader.elf");
  [...]
} 

How to only download bootloader and debug application

In case only the application should be debugged but you want to make sure the e.g. bootloader that runs prior to the application is downloaded function BeforeTargetDownload() can be used as follows:

void BeforeTargetDownload (void) {                                  
  Exec.Download("./bootloaderimage.hex");
}