Loading and executing a program


2012-03-20Publicerad av Sven-Åke Andersson

Introduction


When have figured out how to program the SPI flash we are ready to load and execute an application program. We will use a simple program to turn on some of the LEDs on the board. We will put the binary code in the SPI flash starting at address 0x1c0000 and let the simple bootloader copy the program to SDRAM and start execution when we power-cycle the board.

C-program


The c-program looks like this. It will turn on four of the eight LEDs on the board.




 
 

Create a board file


We need to creata a board file for the Atlys board. We can download a template file from here and rename it to atlys.S and make the modifications needed. The only thing we will change is the board frequency to 50000000.

/*
* Define symbols to be used during startup - file is linked at compile time
*
*/
.global _board_mem_base
.global _board_mem_size
.global _board_clk_freq

_board_mem_base: .long 0x0
_board_mem_size: .long 0x800000

_board_clk_freq: .long 66666666

/* Peripheral information - Set base to 0 if not present*/
.global _board_uart_base
.global _board_uart_baud
.global _board_uart_IRQ

_board_uart_base: .long 0x90000000
_board_uart_baud: .long 115200
_board_uart_IRQ: .long 2



Compile the board file using this command: or32-elf-gcc -c atlys.S

Archive the compiled file using this commamnd: or32-elf-ar -rs libboard.a atlys.o

Copy the libboard.a to the directory "path_to_toolchain"/or32-elf/lib/boards/atlys
 



 

Compiling the program

 
Use this simple command to compile our code:

or32-elf-gcc -mnewlib -mboard=atlys LEDtest.c -o LEDtest.exe
 

Generate a bin file


Use this command to generate a bin file from the ELF file:

or32-elf-objcopy -O binary LEDtest.exe LEDtest.bin


Adding the size block


Before we can make the SPI flash image file we have to add the size block (the first four bytes) to the binary file. The bootloader reads the size header and understands how many bytes to copy. To our help we have a number of utility programs found in the utils directory:

 



We use the following command to add the size header:

bin2binsizeword LEDtest.bin LEDtest_sz.bin
 

Generate the SPI image file


By adding the bin file to the makefile found in the directory: <...../boards/xilinx/atlys/backend/par/bin> we can use a simple make command to generate the orpsoc.mcs file.

Add the following line in the makefile: BOOTLOADER_BIN ?=$(BOARD_ROOT)/sw/src/LEDtest_sz.bin

 



 


 

Executing the program


After loading the SPI image (see previous chapter) and power-cycling the board four of the LEDs light up. Here is the proof.