SAMA5D2 xplained start application bare metal (without os)

Moderator: nferre

JR9020
Posts: 4
Joined: Tue Oct 17, 2017 11:06 am

SAMA5D2 xplained start application bare metal (without os)

Tue Oct 17, 2017 4:38 pm

Hello,

I have the ATMEL sama5d27 xplained ultra board and i want to develop applications which should run "directly" on the board without an operating system (no linux4sam). Therefore I have downloaded the atmel software package https://github.com/atmelcorp/atmel-software-package. As first example I want to run the "getting-started". I think that I also need the AT91Bootstrap second level bootloader to load the main application from boot media to main memory? (But I am not sure) Link: https://github.com/linux4sam/at91bootstrap. In order to flash the AT91Bootstrap bootloader to the board I have downloaded the sam-ba tool. Link: https://github.com/atmelcorp/sam-ba/releases

So i have done the following (maybe it is wrong but that is why I am asking):

1. Build AT91Bootstrap
I have build the AT91Bootstrap as explained here: linux4sam/bin/view/Linux4SAM/Sama5d2Xpl ... om_sources

Code: Select all

git clone git://github.com/linux4sam/at91bootstrap.git

Code: Select all

cd at91bootstrap/

Code: Select all

make mrproper

Code: Select all

make sama5d2_xplaineddf_uboot_defconfig

Code: Select all

make menuconfig

Code: Select all

make
2. Flash AT91Bootstrap
I have flashed the AT91Bootstrap as explained here: linux4sam/bin/view/Linux4SAM/Sama5d2Xpl ... rap_binary
I got the binary (.bin file) from the previous step and flashed it in serialflash.

Code: Select all

sam-ba -p serial -b sama5d2-xplained -a serialflash -c erase::0x3000 -c writeboot:at91bootstrap-sama5d2_xplained.bin
3. Build application
First I installed the GCC ARM Embedded:

Code: Select all

sudo apt-get install gcc-arm-embedded
Then I have build the getting started example as follows:

Code: Select all

git clone git://github.com/atmelcorp/atmel-software-package.git

Code: Select all

cd atmel-software-package/examples/getting_started/

Code: Select all

make TARGET=sama5d2-xplained
4. Flash application
I have flashed the (in the previous step generated) binary at the address where the u-boot should be. I am not sure if this is the correct way to get the application running. Link: linux4sam/bin/view/Linux4SAM/Sama5d2Xpl ... oot_binary

Code: Select all

sam-ba -p serial -b sama5d2-xplained -a serialflash -c erase:0x8000:0x70000 -c write:getting-started.bin:0x8000
Problem:
After rebooting the board i get the following output:

Code: Select all

AT91Bootstrap 3.8.9-rc6-00013-gf25feef (Mon Okt 16 15:48:34 CEST 2017)

EEPROM: Loading AT24xx information ...
EEPROM: BoardName | [Revid] | VendorName
  #0  SAMA5D2-XULT [AA1]      ATMEL-RF0

EEPROM: Board sn: 0xd300000 revision: 0x200000

SF: Got Manufacturer and Device ID: 0x1f 0x47 0x1 0x0 0x0
SF: Copy 0xa0000 bytes from 0x8000 to 0x26f00000
SF: Done to load image
The AT91Bootstrap bootloader is started and it copies bytes from 0x8000 (thats where the application is stored). I have chacked that the application is not bigger than 0xa0000, so the whole programm must be copied. BUT nothing happens after the last output of the AT91Bootstrap. If i flash the (expected) u-boot.bin to 0x8000 the u-boot binary is executed and i get the u-boot output.

What am I doing wrong?

I have also tried the IAR Embedded Workbench with the segger j-link plus and with these tools I am able to flash and run the app. BUT i am not able to automatically run the app after powering the board (without using the IAR Embedded Workbench). And I also do not want to buy the IAR Embedded Workbench.

So my question is:
How to build and flash the getting-started example that the board executes the application after powering.

I hope anybody can help me.
BR JR
blue_z
Location: USA
Posts: 1692
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D2 xplained start application bare metal (without os)

Tue Oct 17, 2017 10:19 pm

JR9020 wrote:What am I doing wrong?
The clue that you incompletely scrutinized is
JR9020 wrote:

Code: Select all

SF: Copy 0xa0000 bytes from 0x8000 to 0x26f00000
You were concerned about (but verified) the length of the transfer and the source address, but failed to question the target address.
The 0x26f00000 target address in use is the default load address for U-Boot, which is why u-boot.bin successfully executes.
The DRAM Softpack example that you built and want to execute has a load address of 0x20000000.
These binary images are non-relocateable code. They must be loaded to memory at the address specified when they were built (i.e. linked).
Study the output of the linker (e.g. the symbol map file) to confirm.

The proper correction is in your step 1 when you build AT91Bootstrap.
The default configurations provided are only for booting U-Boot. You need to reconfigure the build to boot an alternate program. Use the `make menuconfig` command to perform the needed changes.
Under `Image Loading Strategy` select one of the `Load x MB into start of SDRAM` choices that you deem adequate.
Under `Demo Application Image Storage Setup` configure the entries appropriate to your application, especially the `External Ram Address`, which represents the load address.
For the `Image Name` use an appropriate name such as "softpack.bin".

JR9020 wrote:As first example I want to run the "getting-started". I think that I also need the AT91Bootstrap second level bootloader to load the main application from boot media to main memory?
There's more than one memory on the board. See this post.
There are two versions of the "getting-started" example program, one for each type of memory.
To execute the DRAM version, yes, you would need an intermediate program to initialize dynamic RAM prior to loading.

JR9020 wrote:How to build and flash the getting-started example that the board executes the application after powering.
Seems like you're almost there, except for the missing re-configuration of AT91Bootstrap.
Note that there are alternate boot schemes, such as using U-Boot as a third-level boot program. U-Boot can (when properly configured) load binary images from different media (e.g. SDcard) and over a network (e.g. using TFTP), and then execute them (using a `go` command) or store them. These commands can be entered interactively or stored for automatic execution on boot. In the long run IMO, experience with U-Boot will be more valuable than proficiency with the Atmel SAM-BA utility.

Regards
JR9020
Posts: 4
Joined: Tue Oct 17, 2017 11:06 am

Re: SAMA5D2 xplained start application bare metal (without os)

Wed Oct 18, 2017 2:56 pm

Hello,

thank you for your answer. I configured the at91bootstrap as you suggested and now it works.
Thanks a lot.

BR JR
Oleksandr
Posts: 8
Joined: Thu Nov 02, 2017 10:30 pm

Re: SAMA5D2 xplained start application bare metal (without os)

Fri Nov 03, 2017 12:03 am

Hi guys.

I did everything according to the above instructions and have the following situation: "getting-started.bin" with SPIFlash is copied into DDRAM (at 0x20000000) but does not want to be executed.

So, if I load "getting-started.bin" from the IAR into DDRAM then it works, but if the same "getting-started.bin" is loaded into DDRAM using bootstrap then it does not works.

"Get-started.bin" is actually loaded into DDRAM, because I can see its code after Power-On using the "Debud without downloading" mode in IAR over j-link adapter.

Where can I do wrong?

Help me please!
blue_z
Location: USA
Posts: 1692
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D2 xplained start application bare metal (without os)

Fri Nov 03, 2017 10:31 pm

Oleksandr wrote:I did everything according to the above instructions ...
But apparently you have a different built environment, i.e. you mention IAR whereas the OP used a GNU toolchain.

Oleksandr wrote:... but does not want to be executed.
That's not an observable fact, but rather your conjecture about a personified object. This first sentence makes all your claims suspect.

Since you have a "j-link adapter", debug the code when AT91Bootstrap jumps to 0x20000000.

Regards
Oleksandr
Posts: 8
Joined: Thu Nov 02, 2017 10:30 pm

Re: SAMA5D2 xplained start application bare metal (without os)

Sun Nov 05, 2017 12:54 pm

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

Re: SAMA5D2 xplained start application bare metal (without os)

Mon Nov 06, 2017 11:53 pm

Oleksandr wrote:Look, please, where I'm wrong
If all you provide are vague descriptions and a list of instructions, then do not expect a positive resolution to your problem.
If you study the OP's post, you should notice that there's a detailed description of steps performed and then the results of executing the program. There is information sufficient to pinpoint the problem and offer the solution.
You on the other hand, have only provided vague summations.
Nobody has the time and imagination to think of all the ways that you could make mistakes.

Regards
Oleksandr
Posts: 8
Joined: Thu Nov 02, 2017 10:30 pm

Re: SAMA5D2 xplained start application bare metal (without os)

Tue Nov 07, 2017 7:54 am

What kind of vague description are you talking about? This is a clear list of steps that I personally carried out and documented.
blue_z
Location: USA
Posts: 1692
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D2 xplained start application bare metal (without os)

Thu Nov 09, 2017 1:35 am

Why not focus on providing detailed descriptions of the results of what you did instead of complaining?
Oleksandr
Posts: 8
Joined: Thu Nov 02, 2017 10:30 pm

Re: SAMA5D2 xplained start application bare metal (without os)

Thu Nov 09, 2017 10:25 am

Hi, blue_z.

Firstly, you named the work that I performed as "an vague description"

Secondly, carefully read this: blue_z is a valuable contributor to at91 forum and has quite a track record of good answers. (c) nferre
You are a "valuable contributor", not me, not others, but you. Therefore, I appeal to you for help. If I were such a cool guy, I would not ask for help here.

Thirdly, I'm new to Linux and Atmel. All time I worked with 8051 and stm32. In quality IDE used Keil uVision 5 under Windows. And here everything is new - the compiler, the processor, the operating system.
I came to the forum for help but something went wrong. :-)
I also do not speak English well.

Okay, forget it all.

Now let's go back to the question: what's wrong with the description? Why do not you want to read it? I tried, made out, took screenshots.
blue_z
Location: USA
Posts: 1692
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D2 xplained start application bare metal (without os)

Thu Nov 09, 2017 10:44 pm

For whatever reason, there was only one page viewable the first time I looked at your document.
I still cannot determine what toolchain version you used to build AT91Bootstrap.
Try the advice from this post on using a proven toolchain. Note that the download command is for a 32-bit toolchain, whereas the Linux4SAM webpage is for a 64-bit toolchain.

Regards
JR9020
Posts: 4
Joined: Tue Oct 17, 2017 11:06 am

Re: SAMA5D2 xplained start application bare metal (without os)

Mon Mar 05, 2018 5:50 pm

Hi,

again I have a problem and I hope you can help me....

Until now I have compiled my atmel-software-package examples as follows:

Code: Select all

export TARGET=sama5d2-xplained
export VARIANT=ddram
make
The output when i have at91bootstrap and app build for DDRAM:

Code: Select all

AT91Bootstrap 3.8.9-rc6-00013-gf25feef (Mit Okt 18 15:38:33 CEST 2017)

EEPROM: Loading AT24xx information ...
EEPROM: BoardName | [Revid] | VendorName
  #0  SAMA5D2-XULT [AA1]      ATMEL-RF0

EEPROM: Board sn: 0xd300000 revision: 0x200000

SF: Got Manufacturer and Device ID: 0x1f 0x47 0x1 0x0 0x0
SF: Copy 0x4000000 bytes from 0x8000 to 0x20000000
SF: Done to load image
-D- ../../drivers/power/act8945a.c:455 Charge Level: 450mA
-- Getting Started Example --
...
In the getting-started.map file it says where to flash the binary file:

Code: Select all

Memory Configuration

Name                    Origin                                                Length
sram                     0x0000000000200000                    0x0000000000020000 
ddr                        0x0000000020000000                    0x0000000004000000
ddr_nocache       0x0000000024000000                    0x0000000001000000
*default*             0x0000000000000000                    0xffffffffffffffff
I also build the at91bootstrap with the corresponding settings:

Code: Select all

Image Loading Strategy (Load 1 MB into start of SDRAM)
(0x00008000) Flash Offset for Demo-App
 (0x04000000) Demo-App Image Size
 (0x20000000) The External Ram Address to Load Demo-App Image
BUT:
When I build the app for SRAM (without: export VARIANT=ddram) and adjust the at91bootstrap accordingly, the app is not loaded and executed:

Code: Select all

AT91Bootstrap 3.8.10-rc1 (Mon Mär  5 15:50:25 CET 2018)

EEPROM: Loading AT24xx information ...
EEPROM: BoardName | [Revid] | VendorName
  #0  SAMA5D2-XULT [AA1]      ATMEL-RF0

EEPROM: Board sn: 0xd300000 revision: 0x200000

SF: Got Manufacturer and Device ID: 0x1f 0x47 0x1 0x0 0x0
SF: Copy 0x20000 bytes from 0x8000 to 0x200000
What do I wrong when building the at91bootstrap and the app for SRAM? The program is not loaded and executed.

Thank you for your help.

BR, JR9020
blue_z
Location: USA
Posts: 1692
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D2 xplained start application bare metal (without os)

Mon Mar 05, 2018 10:17 pm

JR9020 wrote:In the getting-started.map file it says where to flash the binary file:
That is a memory map.
There's no information whatsoever about "where to flash" anything.
The map information is for where an image from flash should be loaded in memory, i.e. SRAM or DRAM.

Where things go in NAND flash is up to you.
The general rule is that images should be aligned with erase pages.
The AT91Bootstrap image (with the PMECC header) has to be at NAND location zero to comply with SoC boot requirements.
Locations for other images are under software control.

JR9020 wrote:When I build the app for SRAM (without: export VARIANT=ddram) and adjust the at91bootstrap accordingly, the app is not loaded and executed:
Exactly what did you "adjust" in AT91Bootstrap?
There is no load into SRAM option in AT91Bootstrap.

Are you getting confused with acronyms SRAM versus SDRAM?
SRAM is static RAM (which in this case is internal to the SoC).
SDRAM is synchronous dynamic RAM, i.e. DRAM (which in this case is external to the SoC).
DDRAM is a contraction for double-data-rate dynamic RAM, i.e. DRAM (which in this case is external to the SoC).


JR9020 wrote:What do I wrong when building the at91bootstrap and the app for SRAM? The program is not loaded and executed.
AT91Bootstrap is loaded and executing out of the internal SRAM.
You cannot load another program into the same address space of SRAM while that boot program is executing.
Perhaps instead of just words on page, you need to graphically draw this on paper.

Refer to the Linux4SAM web page on the conventional Atmel AT91SAM Boot Sequence for Linux.
Image
The left side lists the execution order of boot programs (you're only concerned with #1 and #2, and your app would be #3).
The right side describes the physical memories involved and the transfer of code & data.


If you insist on building an app to execute in SRAM, then it would have to replace AT91Bootstrap.
OR boot into U-Boot, and use it capabilities to execute apps in SRAM or DRAM.

Regards
JR9020
Posts: 4
Joined: Tue Oct 17, 2017 11:06 am

Re: SAMA5D2 xplained start application bare metal (without os)

Tue Mar 06, 2018 12:22 pm

Hi,

first, thank you blue_z for always responding so fast.
second, thank you for your answer and now the whole stuff is more clear to me.

The following works for me:
I build the getting-started example from the atmel-software-package for the SRAM as follows:

Code: Select all

export TARGET=sama5d2-xplained
make
When I flash the getting-started-sram.bin binary to address 0x0, the application starts after power up the board:

Code: Select all

sam-ba -p serial -b sama5d2-xplained -a serialflash -c erase::0xf000 -c writeboot:getting-started-sram.bin
The following also works for me:
I build the getting-started example from the atmel-software-package for the DDRAM as follows:

Code: Select all

export TARGET=sama5d2-xplained
export VARIANT=ddram
make
Now i need the at91bootstrap. I configured the at91bootstrap with make menuconfig as you suggested:

Code: Select all

Under 'Image Loading Strategy' I selected 'Load 1 MB into start of SDRAM'
Under 'Demo Application Image Storage Setup' i set:
(0x00008000) Flash Offset for Demo-App
(0x000a0000) Demo-App Image Size
(0x20000000) The External Ram Address to Load Demo-App Image
When I flash the at91bootstrap.bin to address 0x0 and the application to address 0x8000 (as the offset says in the at91bootstrap configuration)...

Code: Select all

sam-ba -p serial -b sama5d2-xplained -a serialflash -c erase::0xf000 -c writeboot:at91bootstrap.bin
sam-ba -p serial -b sama5d2-xplained -a serialflash -c erase:0x8000:0x70000 -c write:getting-started-ddram.bin:0x8000
... first the at91bootstrap.bin is booted and then the application is loaded after power up the board.

Output:

Code: Select all

AT91Bootstrap 3.8.10-rc1

EEPROM: Loading AT24xx information ...
EEPROM: BoardName | [Revid] | VendorName
  #0  SAMA5D2-XULT [AA1]      ATMEL-RF0

EEPROM: Board sn: 0xd300000 revision: 0x200000

SF: Got Manufacturer and Device ID: 0x1f 0x47 0x1 0x0 0x0
SF: Copy 0xa0000 bytes from 0x8000 to 0x20000000
SF: Done to load image
-D- ../../drivers/power/act8945a.c:455 Charge Level: 450mA
-- Getting Started Example --
Softpack v2.8
Built for sama5d2-xult
Processor: SAMA5D27-CN
Processor clock: 498 MHz
Master clock: 166 MHz
MMU is enabled
I-Cache is enabled
D-Cache is enabled
L2-Cache is disabled

Initializing console interrupts
Configure buttons with debouncing.
Use push buttons or console key 0 to 2.
Press the number of the led to make it start or stop blinking.
LED 0 uses softpack timer functions
LEDs 1-2 use a TC
Press 's' to stop the TC and 'b' to start it
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BUT, the following does not work for me:
I have received a software library (under NDA) from Atmel and I build it like the examples from the atmel-software-package (that works) but the definition of the environment variable VARIANT has no influence on the build. So I do not know whether it is build for SRAM or for SDRAM/DDRAM. I tried with and without the at91bootstrap (as explained above), but i could not manage to run the example demo of the software library which i reveived from Atmel.

When I try with the at91bootstrap and flash the .bin to address 0x8000 it does not load the application and stops after 'Done to load image':

Code: Select all

AT91Bootstrap 3.8.10-rc1 (Die Mär  6 09:25:31 CET 2018)

EEPROM: Loading AT24xx information ...
EEPROM: BoardName | [Revid] | VendorName
  #0  SAMA5D2-XULT [AA1]      ATMEL-RF0

EEPROM: Board sn: 0xd300000 revision: 0x200000

SF: Got Manufacturer and Device ID: 0x1f 0x47 0x1 0x0 0x0
SF: Copy 0xa0000 bytes from 0x8000 to 0x20000000
SF: Done to load image
When I try without the at91bootstrap and flash the .bin to address 0x0 it gives me some 'strange' output:

Code: Select all

<<`?▒▒▒▒▒x▒̞▒x▒▒▒f000x?▒x0▒x3▒0`030~0f<▒f<?<`?▒▒▒▒▒x▒̞▒x▒▒▒f000x?▒x0▒x3▒0`0303f<▒▒x3f<?▒▒x<▒▒<<`?▒▒▒▒▒x▒̞▒x▒▒▒▒▒▒▒▒▒▒x3▒▒`0x0▒f<▒▒▒?x▒▒▒▒▒▒▒憘▒▒▒f▒▒▒▒▒▒▒`ff▒
(this are only the last few lines of the output)

What do I have to do in order to run the application correctly on the sama5d2-xplained. I would prefer to use the at91bootstrap and load the app in DDRAM.

Thank you for your help.

BR, JR9020
blue_z
Location: USA
Posts: 1692
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D2 xplained start application bare metal (without os)

Wed Mar 07, 2018 12:29 am

JR9020 wrote:I have received a software library (under NDA) from Atmel and I build it like the examples from the atmel-software-package (that works) but the definition of the environment variable VARIANT has no influence on the build.
Technically a library would only consist of procedures that are callable, and you would have to write a main program to invoke these procedures from the library.
You seem to imply that there is an included program (and makefile) that can be built.

It would be a rare program that used such a VARIANT variable.
Such a memory specifier actually translates to a specific memory address and region, which are salient parameters when linking standalone programs.
IOW internal SRAM maps to 0x00200000, and external DRAM maps to 0x20000000 (i.e. their respective first addresses).

JR9020 wrote:So I do not know whether it is build for SRAM or for SDRAM/DDRAM.
Inspection of the .map file should indicate what you have built.
The value of .textEntry should indicate where the program is located.
The value of .stack should indicate where the top of the stack is located.
Inspect the SRAM and DRAM versions of getting-started-*.map for comparison.

JR9020 wrote:What do I have to do in order to run the application correctly on the sama5d2-xplained. I would prefer to use the at91bootstrap and load the app in DDRAM.
That should be under your control since the program's start address would be specified in the Makefile and/or .ld linker file.
I don't know what library you have, so I cannot give precise advice; I haven't signed any NDAs.
You're going to have to evaluate the files and code in this library, and learn how to use it.
If it's related to Secure Boot, then maybe it should be part of (or replaces) the second-stage bootloader (i.e. AT91Bootstrap)?
Or is it a library that expects/requires a Linux environment?


Regards

Return to “SAMA5-based”

Who is online

Users browsing this forum: No registered users and 2 guests