Executing Example Code in DDRAM

Moderator: nferre

3F800000
Posts: 15
Joined: Wed Apr 25, 2018 6:36 pm

Executing Example Code in DDRAM

Sat Nov 23, 2019 10:45 pm

I have the SOM1-EK eval board trying to run the eth_lwip example provided in softpack_v2.17. Using Cygwin I can build the project giving:

eth_lwip.bin
eth_lwip.elf
bootstrap.elf
etc.

The next step is unclear to me. Looking at bootstrap.c it just seems to initialize hardware, including DDRAM, but then ends at a breakpoint. I have sam-ba handy but I'm not sure how to proceed. Perhaps the BIN files are to be written to flash? If so where? Or do I use J-Link, in which case I need to look deeper into the Segger documentation?

Thanks
blue_z
Location: USA
Posts: 2005
Joined: Thu Apr 19, 2007 10:15 pm

Re: Executing Example Code in DDRAM

Mon Nov 25, 2019 2:28 am

3F800000 wrote: I have the SOM1-EK eval board trying to run the eth_lwip example provided in softpack_v2.17.
...
The next step is unclear to me.
You could use J-Link.
The old GUI version of SAM-BA doesn't support SAMA5D2, and SAM-BA version 3.x doesn't seem to have the basic load file and execute commands.
But IMO the straight-forward method of executing such standalone programs would be from SDcard.
Before you can load a program into DRAM, the clocks and DRAM controller must be initialized.
Booting from SDcard can automate this requirement.

See SD card boot for AT91SAM SoC.

For step 5, download a tarball of the latest release of AT91Bootstrap (rather than copy the git repository).
For the defconfig file, choose either sama5d27_som1_eksd_uboot_defconfig or sama5d27_som1_eksd1_uboot_defconfig depending on which card socket (aka slot) you intend to boot from.
The SDcard socket will be hardcoded in the program, and the program will not boot using the other socket.

Before building AT91Bootstrap with the `make` command, you need to customize the build to boot your standalone program instead of U-Boot.
See SAMA5D2 xplained start application bare metal (without os) on customizing the `Image Loading Strategy`.

For step 6, install your standalone program (instead of U-Boot) with the same `Image Name` filename as specified in the `Image Loading Strategy` menu.

Regards
3F800000
Posts: 15
Joined: Wed Apr 25, 2018 6:36 pm

Re: Executing Example Code in DDRAM

Mon Nov 25, 2019 6:21 pm

OK, thanks. I'm sure I can get the bootloader going and run the example from SD card or QSPI.

Still, I'm curious what was the intention of the bootstrap. Looks like it is built automatically for the examples set to run from DDRAM. It initializes various things including getting DDRAM configured properly, but then seems to stop at a BKPT instruction. I guess at that point the idea is to load the example ELF (or BIN) file using J-Link into DDRAM and execute it. Do you know if that is the case, or where this might be documented?

(To be clear, the bootstrap in question is a different entity than AT91Boostrap with which I am quite familiar.)

Again, thanks!
blue_z
Location: USA
Posts: 2005
Joined: Thu Apr 19, 2007 10:15 pm

Re: Executing Example Code in DDRAM

Tue Nov 26, 2019 2:48 am

3F800000 wrote: Do you know if that is the case, or where this might be documented?
Your guess is reasonable, except that you would load the .bin file, which is an executable image that doesn't have any cruft.
If you have a J-Link and don't mind a manual, two-step load procedure every time you reset the board, then that is still a viable procedure.
(I haven't used a J-Link in over a decade, and cannot describe the procedure.)

As to "usage" documentation, there should be comments at the beginning of the example's main.c.
The document links are likely to be stale/broken.

The Softpack README.md file has some vague information.
With older SoCs the assumption was that you could use the SAM-BA 2.x utility, e.g. How to deploy bare metal application in internal SRAM.

Regards
pbugalski
Posts: 17
Joined: Thu Nov 29, 2018 4:28 pm

Re: Executing Example Code in DDRAM

Fri Nov 29, 2019 10:20 am

Hi 3F800000,

Usually when you use J-link or similar interface code is loaded into RAM and then executed. The problem with sama5d2 is that DDRAM is not configured yet so it cannot be used. Workaround is by using bootstrap - j-link will start bootstrap and then take control again to continue application loading and debugging.
How it works you can find in gdb scripts. First you need to open https://github.com/atmelcorp/atmel-soft ... /ddram.gdb :

Code: Select all

  init_ddr
  load_in_ddr
So next step is have a look how these procedures are implemented in https://github.com/atmelcorp/atmel-soft ... common.gdb :

Code: Select all

define init_ddr  

  reset_registers
  
  load target/bootstrap.elf
  
  # Initialize PC
  mon reg pc = 0x00200000
  mon reg pc = 0x00200000

  continue
end
"load target/bootstrap.elf" as you can guess is just loading bootstrap code into SRAM, then program counter (PC) register is set to begining of code and "continue" starts execution.
When bootstrap is executed gdb is just waiting... for a breakpoint and this is the why BKPT instruction is inside bootstrap. On breakpoint debugger gets control back and runs load_in_ddr procedure.

Code: Select all

define load_in_ddr

  reset_registers

  load
  
  # Initialize PC
  mon reg pc = 0x20000000
end
Now DDRAM is fully operational so main application can be just loaded there using "load" without parameters. PC register has to be updated and application can start.

Regards,
Piotr

Return to “SAMA5-based”

Who is online

Users browsing this forum: No registered users and 1 guest