Creating, building, loading and executing RedBoot binaries

Information of device properties, device configuration, internal register modification, memory mapping.
Creating, building, loading and executing binary images form RedBoot, including Linux kernel.
Creating, building, loading and executing binary files from Linux user and kernel space.

Creating, building, loading and executing RedBoot binaries

Postby kakanakov » Fri May 14, 2010 4:51 pm

To demonstrate the process of creating, building, loading, and executing of binaries from a RedBoot environment a sample program for turning on and off of EP9302 board's green and red LEDs will be used. This program, nor all the steps described below pretend to be a complete reference for building and executing RedBoot (or eCos) binaries.

First, we need to know the exact physical addresses of both LEDs. From EP93xx User's Guide we see that both LEDs are connected to PortE bits 1 and 0 (pp. 28-9 - 28-10). PortE Data Register is mapped to 0x80840020 and PortE Data Direction Register to 0x80840024 respectively. Now we are ready to write a really simple program that toggles the two LEDs continuously:
Code: Select all
int main() {
   unsigned char *portE_DDR;
   unsigned char *portE_DR;
   unsigned long delay = 1000000L;
   unsigned long i;
   int x = 0;
      
   portE_DDR = (unsigned char *) 0x80840024;
   portE_DR = (unsigned char *)0x80840020;
   
   //printf("address is -> %0X",portE_DDR);
   //return 1;

   *portE_DDR |= 0x03;
   *portE_DR = 0x03;
   
   for(;;) {
      for(i=0; i<delay; i++) { x = 123 + 542 * 123; };
      *portE_DR = 0x02;
      for(i=0; i<delay; i++) { x = 123 + 542 * 123; };
      *portE_DR = 0x01;
   }
   return 0;
}


To build the program above we will use GNUARM toolchain. The exact commands used to compile and link the binary are given bellow:
Code: Select all
# arm-elf-gcc -O0 -c leds.c
# arm-elf-ld -e main -o leds.elf leds.o


This will produce leds.elf executable with the following file type:
Code: Select all
# file leds.elf
leds.exe: ELF 32-bit LSB executable, ARM, version 1, statically linked, not stripped


Now we are ready to load and execute the binary on the EP9302 board. To do this we will use the capabilities of the RedBoot to load network files (using FTP, TFTP, or HTTP). Once we have an open RedBoot shell with correct TCP/IP configurations all we need to do is to execute the following commands (assuming that leds.elf binary file is available through URL: http://dsnet.tu-plovdiv.bg/leds.elf).
Code: Select all
RedBoot> load -h 192.168.32.51 -m http -b 0x00800000 /leds.elf
RedBoot> go 0x00800000


That's it. You should now see how both LEDs sequentially changes their state from on to off.

TODO: How to build binaries that returns control to RedBoot when finished.
User avatar
kakanakov
 
Posts: 28
Joined: Fri Mar 06, 2009 4:36 pm
Location: Lab 2204a, campus 2, TU - Plovdiv

Re: Creating, building, loading and executing RedBoot binaries

Postby kakanakov » Sat May 15, 2010 5:07 pm

Code: Select all
# /usr/local/gnuarm/bin/arm-elf-readelf -a leds.elf
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            ARM
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x8000
  Start of program headers:          52 (bytes into file)
  Start of section headers:          33084 (bytes into file)
  Flags:                             0x200, GNU EABI, software FP
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         1
  Size of section headers:           40 (bytes)
  Number of section headers:         7
  Section header string table index: 4

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00008000 008000 0000e0 00  AX  0   0  4
  [ 2] .comment          PROGBITS        00000000 0080e0 000012 00      0   0  1
  [ 3] .ARM.attributes   ARM_ATTRIBUTES  00000000 0080f2 000010 00      0   0  1
  [ 4] .shstrtab         STRTAB          00000000 008102 00003a 00      0   0  1
  [ 5] .symtab           SYMTAB          00000000 008254 000130 10      6   7  4
  [ 6] .strtab           STRTAB          00000000 008384 000086 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

There are no section groups in this file.

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x008000 0x00008000 0x00008000 0x000e0 0x000e0 R E 0x8000

 Section to Segment mapping:
  Segment Sections...
   00     .text

There is no dynamic section in this file.

There are no relocations in this file.

There are no unwind sections in this file.

Symbol table '.symtab' contains 19 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00008000     0 SECTION LOCAL  DEFAULT    1
     2: 00000000     0 SECTION LOCAL  DEFAULT    2
     3: 00000000     0 SECTION LOCAL  DEFAULT    3
     4: 00000000     0 FILE    LOCAL  DEFAULT  ABS leds.c
     5: 00008000     0 NOTYPE  LOCAL  DEFAULT    1 $a
     6: 000080d0     0 NOTYPE  LOCAL  DEFAULT    1 $d
     7: 000080e0     0 NOTYPE  GLOBAL DEFAULT  ABS __exidx_end
     8: 000100e0     0 NOTYPE  GLOBAL DEFAULT  ABS _bss_end__
     9: 000100e0     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start__
    10: 000080e0     0 NOTYPE  GLOBAL DEFAULT  ABS __exidx_start
    11: 000100e0     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_end__
    12: 000100e0     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start
    13: 00008000   224 FUNC    GLOBAL DEFAULT    1 main
    14: 000100e0     0 NOTYPE  GLOBAL DEFAULT  ABS __end__
    15: 000100e0     0 NOTYPE  GLOBAL DEFAULT  ABS _edata
    16: 000100e0     0 NOTYPE  GLOBAL DEFAULT  ABS _end
    17: 00080000     0 NOTYPE  GLOBAL DEFAULT    3 _stack
    18: 000100e0     0 NOTYPE  GLOBAL DEFAULT    1 __data_start

No version information found in this file.
Attribute Section: aeabi
File Attributes
User avatar
kakanakov
 
Posts: 28
Joined: Fri Mar 06, 2009 4:36 pm
Location: Lab 2204a, campus 2, TU - Plovdiv


Return to EP9302_Linux

Who is online

Users browsing this forum: No registered users and 3 guests

cron