Difference between revisions of "The IGEP X-loader"

From IGEP - ISEE Wiki

Jump to: navigation, search
Line 233: Line 233:
  
 
</pre>  
 
</pre>  
It's important take a lool to the call assembly function cpu_init_crit (you can see the code below) this is resposable to call the board initialization defined in [http://git.igep.es/?p=pub/scm/igep-x-loader.git;a=blob;f=board/igep0020/platform.S platform.S] file.<br>  
+
It's important take a lool to the call assembly function cpu_init_crit (you can see the code below) this is resposable to call the board initialization defined in [http://git.igep.es/?p=pub/scm/igep-x-loader.git;a=blob;f=board/igep0020/platform.S platform.S] file. Check the call to lowlevel_init:<br>  
 
<pre> 175 cpu_init_crit:
 
<pre> 175 cpu_init_crit:
 
  176        /*
 
  176        /*
Line 316: Line 316:
  
 
</pre>  
 
</pre>  
<br>  
+
Lowlevel_init it's responsable to set the stack settings and call the lowlevel board initialization called s_init "C" code defined in [http://git.igep.es/?p=pub/scm/igep-x-loader.git;a=blob;f=board/igep0020/igep0020.c here]<br>  
 +
<pre> 171 .globl lowlevel_init
 +
172 lowlevel_init:
  
it do a basic initialization and at end jump to the C initial function called [http://git.igep.es/?p=pub/scm/igep-x-loader.git;a=blob;f=lib/board.c start_armboot] defined in the file lib/board.c.<br>
+
173        ldr    sp,    SRAM_STACK
 +
 
 +
174        str    ip,    [sp]    /* stash old link register */
 +
 
 +
175        mov    ip,    lr      /* save link reg across call */
 +
 
 +
176        bl      s_init          /* go setup pll,mux,memory */
 +
 
 +
177        ldr    ip,    [sp]    /* restore save ip */
 +
 
 +
178        mov    lr,    ip      /* restore link reg */
 +
 
 +
179
 +
 
 +
180        /* back to arch calling code */
 +
 
 +
181        mov    pc,    lr
 +
 
 +
 
 +
 
 +
</pre>
 +
At the end and after the s_init call the code jump to initial C function called [http://git.igep.es/?p=pub/scm/igep-x-loader.git;a=blob;f=lib/board.c start_armboot] defined in the file lib/board.c.<br>
  
 
== C Execution Flow<br>  ==
 
== C Execution Flow<br>  ==

Revision as of 23:15, 26 February 2011

Summary

X-Loader, an initial program loader for Embedded boards based on OMAP processors.

Features and Limitations

Improvements & Modifications

  • Malloc/free functionality.
  • Mtd framework and onenand support, removed the old onenand drivers.
  • Jffs2 support using mtd & onenand support (Read Only).
  • Crc32 and zlib.
  • Jffs2 zlib compression support (Read Only).
  • Dual boot mmc & onenand with mmc highest priority.
  • Linux kernel boot directly (Support for 2.6.22 and highest version kernels)
  • Linux kernel supported images: vmlinuz, bzImage and zImage.
  • Support for loading Linux Ram disk (EXPERIMENTAL)
  • "ini" files parser.
  • The configuration resides in a plain txt (ini format file).
  • Support Windows & Linux formating ini files.
  • Boot from mmc, onenand, or mix with mmc highest priority.
  • Codeblocks project and compilation rules.
  • Support for gcc 4.5.1.

Limitations

  • The ini configuration file it's limited to max size: 16 KiB
  • Kernel Command line parameters it's limited to: 4 KiB
  • Malloc it's limited to 32 MiB.
  • Cannot write comments in lines with tag=value

TODO

  • Support for IGEP0030 - Family boards.
  • Support for other OMAP/DM/AM processor boards.
  • Remove compilation warnings.
  • Comments in tag lines

STATUS

  • Support IGEP0020 Revision B & C family boards.
  • Tested with IGEPv2 (DM3730@1Ghz and 512/512 MB Ram/Onenand)
  • Tested with IGEPv2 (AM3703@1Ghz and 512/512 MB Ram/Onenand)
  • Tested with IGEPv2 (OMAP3530@720Mhz and 512/512 MB Ram/Onenand)

Build Procedure

Build with Ubuntu Cross Compiler gcc 4.5.1

EnviromentUbuntu 10.10

Install the cross compiler if you not do it before.

apt-get install cpp-4.5-arm-linux-gnueabi g++-4.5-arm-linux-gnueabi

Setup the board settings

make igep0020-sdcard_config

Build

make

Sign the binary x-loader

You should execute contrib/signGP for sign the xloader.

contrib/signGP x-load.bin
The signed x-loader it's named: x-load.bin.ift

Build with IGEP SDK

Setup the Enviroment

source /usr/local/poky/eabi-glibc/environment-setup-arm-none-linux-gnueabi

Setup the board settings

make igep0020-sdcard_config

Build

make CROSS_COMPILE=arm-none-linux-gnueabi-

Sign the binary x-loader

You should execute contrib/signGP for sign the xloader.

contrib/signGP x-load.bin
The signed x-loader it's named: x-load.bin.ift

Build Native

Configure the board settings

make igep0020-sdcard_config
Edit the variable CFLAGS and add the option: -fno-stack-protector
CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -fno-stack-protector

Build

make CROSS_COMPILE=arm-none-linux-gnueabi-

Sign the binary x-loader

You should execute contrib/signGP for sign the xloader.

contrib/signGP x-load.bin
The signed x-loader it's named: x-load.bin.ift

BOOT

The IGEP X-Loader must reside in the microSD card or in the OneNand.

Low Level Initialization

The OMAP Processor loads the XLoader directly from the mmc or the OneNand and copy the binary into the internal processor RAM (0x40200000) and jump to this place, this internal memory it's limited to 64K divided as: Interrupts, code, data and stack. Initialization code can be found using this link: start.S 

  96 reset:
 
  97         /*

  98          * set the cpu to SVC32 mode

  99          */

 100         mrs     r0,cpsr

 101         bic     r0,r0,#0x1f

 102         orr     r0,r0,#0xd3

 103         msr     cpsr,r0

 104 

 105         /* Copy vectors to mask ROM indirect addr */ 

 106         adr     r0, _start              /* r0 <- current position of code   */

 107         add     r0, r0, #4                              /* skip reset vector                    */

 108         mov     r2, #64                 /* r2 <- size to copy  */

 109         add     r2, r0, r2              /* r2 <- source end address         */

 110         mov     r1, #SRAM_OFFSET0         /* build vect addr */

 111         mov     r3, #SRAM_OFFSET1

 112         add     r1, r1, r3

 113         mov     r3, #SRAM_OFFSET2

 114         add     r1, r1, r3

 115 next:

 116         ldmia   r0!, {r3-r10}           /* copy from source address [r0]    */

 117         stmia   r1!, {r3-r10}           /* copy to   target address [r1]    */

 118         cmp     r0, r2                  /* until source end address [r2]    */

 119         bne     next                    /* loop until equal */

 120 

 121         bl      cpy_clk_code            /* put dpll adjust code behind vectors */

 122  

 123         /* the mask ROM code should have PLL and others stable */

 124         bl cpu_init_crit 

 125 

 126 relocate:                               /* relocate U-Boot to RAM           */

 127         adr     r0, _start              /* r0 <- current position of code   */

 128         ldr     r1, _TEXT_BASE          /* test if we run from flash or RAM */

 129         cmp r0, r1                      /* no need to relocate if XIP       */

 130         beq stack_setup                 /* skip txt cpy if XIP(SRAM, SDRAM) */ 

 131 

 132         ldr     r2, _armboot_start

 133         ldr     r3, _bss_start

 134         sub     r2, r3, r2              /* r2 <- size of armboot            */

 135         add     r2, r0, r2              /* r2 <- source end address         */

 136 

 137 copy_loop:

 138         ldmia   r0!, {r3-r10}           /* copy from source address [r0]    */

 139         stmia   r1!, {r3-r10}           /* copy to   target address [r1]    */

 140         cmp     r0, r2                  /* until source end addreee [r2]    */

 141         ble     copy_loop

 142 

 143         /* Set up the stack                                                 */

 144 stack_setup:

 145         ldr     r0, _TEXT_BASE          /* upper 128 KiB: relocated uboot   */

 146         sub     sp, r0, #128            /* leave 32 words for abort-stack   */

 147         and     sp, sp, #~7             /* 8 byte alinged for (ldr/str)d    */

 148 

 149         /* Clear BSS (if any).  Is below tx (watch load addr - need space)  */

 150 clear_bss:

 151         ldr     r0, _bss_start          /* find start of bss segment        */

 152         ldr     r1, _bss_end            /* stop here                        */

 153         mov     r2, #0x00000000         /* clear value                      */

 154 clbss_l:

 155         str     r2, [r0]                /* clear BSS location               */

 156         cmp     r0, r1                  /* are we at the end yet            */

 157         add     r0, r0, #4              /* increment clear index pointer    */

 158         bne     clbss_l                 /* keep clearing till at end        */

 159 

 160         ldr     pc, _start_armboot      /* jump to C code                   */

 161 

 162 _start_armboot: .word start_armboot

It's important take a lool to the call assembly function cpu_init_crit (you can see the code below) this is resposable to call the board initialization defined in platform.S file. Check the call to lowlevel_init:

 175 cpu_init_crit:
 176         /*

 177          * Invalidate L1 I/D

 178          */

 179         mov     r0, #0                 /* set up for MCR */

 180         mcr     p15, 0, r0, c8, c7, 0  /* invalidate TLBs */

 181         mcr     p15, 0, r0, c7, c5, 1  /* invalidate icache */

 182 

 183         /* Invalide L2 cache (gp device call point) 

 184          * - warning, this may have issues on EMU/HS devices

 185          * this call can corrupt r0-r5

 186          */

 187         mov r12, #0x1           @ set up to invalide L2 

 188 smi:    .word 0xE1600070        @ Call SMI monitor

 189 

 190         /*

 191          * disable MMU stuff and caches

 192          */

 193         mrc     p15, 0, r0, c1, c0, 0

 194         bic     r0, r0, #0x00002000     @ clear bits 13 (--V-)

 195         bic     r0, r0, #0x00000007     @ clear bits 2:0 (-CAM)

 196         orr     r0, r0, #0x00000002     @ set bit 1 (--A-) Align

 197 #ifndef CONFIG_ICACHE_OFF

 198         orr     r0, r0, #0x00001800     @ set bit 11,12 (---I Z---) BTB,I-Cache

 199 #endif

 200         mcr     p15, 0, r0, c1, c0, 0

 201 

 202         /*

 203          * Jump to board specific initialization... The Mask ROM will have already initialized

 204          * basic memory.  Go here to bump up clock rate and handle wake up conditions.

 205          */

 206         adr     r0, _start              /* r0 <- current position of code   */

 207         ldr     r1, _TEXT_BASE          /* test if we run from flash or RAM */

 208         cmp     r0, r1                  /* pass on info about skipping some init portions */

 209         moveq   r0,#0x1                 /* flag to skip prcm and sdrc setup */

 210         movne   r0,#0x0

 211 

 212         mov     ip, lr          /* persevere link reg across call */

 213         bl      lowlevel_init   /* go setup pll,mux,memory */

 214         mov     lr, ip          /* restore link */

 215         mov     pc, lr          /* back to my caller */

Lowlevel_init it's responsable to set the stack settings and call the lowlevel board initialization called s_init "C" code defined in here

 171 .globl lowlevel_init
 172 lowlevel_init:

 173         ldr     sp,     SRAM_STACK

 174         str     ip,     [sp]    /* stash old link register */

 175         mov     ip,     lr      /* save link reg across call */

 176         bl      s_init          /* go setup pll,mux,memory */

 177         ldr     ip,     [sp]    /* restore save ip */

 178         mov     lr,     ip      /* restore link reg */

 179 

 180         /* back to arch calling code */

 181         mov     pc,     lr



At the end and after the s_init call the code jump to initial C function called start_armboot defined in the file lib/board.c.

C Execution Flow

cpu_init

Function: cpu_init

This function it's the responsable to do the CPU generic initialization and it's the first function called.

board_init

Function: board_init

This function it's defined per board and it's the responsable to initialize the board,



4 Settings & Configuration:

================

4.1 MMC Boot
------------
Get a new mmc and create two partitions, the first one must be fat (you can follow
this howto: http://code.google.com/p/beagleboard/wiki/LinuxBootDiskFormat)
In this first partition (boot partition) you should copy:

  • x-loader.bin.ift (you must rename this file to MLO) / This is a signed image using contrib/signGP tool
    * igep.ini
    * Your desired kernel image.

Don't use a uImage kernel format (from uboot), only kernel formats be supported.

Compilation Example:
$make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- zImage modules

Read the kernel documentation about kernel images.

4.2 Setup igep.ini file
------------------------
# Note this format permits use the characters
# '#' and ';' as comment check file size restrictions

[kernel]
kaddress=0x80008000
;rdaddress=0x84000000
serial.low=00000001
serial.high=00000000
revision=0001
;kImageName=
;kRdImageName=

[kparams]
console=ttyS2,115200n8
;earlyprintk=serial,ttyS2,115200
mem=512M
boot_delay=0
;mpurate=800
;loglevel=7
omapfb.mode=dvi:1024x768MR-16@60
smsc911x.mac=0xb2,0xb0,0x14,0xb5,0xcd,0xde
;ubi.mtd=2
;root=ubi0:igep0020-rootfs
;rootfstype=ubifs
root=/dev/mmcblk0p2 rw rootwait


Tags Supported
---------------


[kernel] ----
* kaddress=0x80008000

Kernel copy address, you should use the same address used in kernel image
configuration. If you don't know what it means maybe it's better don't change it.

  • rdaddress=0x84000000
    Kernel RAM disk copy address.
    If you don't know what it means maybe it's better don't change it.
  • serial.low=00000001
    * serial.high=00000000
    Board serial Number, you can read this information using /proc/cpuinfo
  • revision=0001
    Board Revision ID, you can read this information using /proc/cpuinfo
  • kImageName=zImage
    Kernel file name, if you don't provide this tag it try to load these others:
    // DEFAULT IMAGES
    "zImage"
    "zimage"
    "vmlinuz"
    "bzImage"
    "bzimage"
  • kRdImageName=rdimage
    Kernel RAM Disk file, if you don't provide this tag it try to load these others:
    // DEFAULT IMAGES
    "initrd"

[kparams] ----
Kernel parameters, all these parameters are passed directly to the kernel using the
kernel command line.

kernel parameters documentation:
http://www.kernel.org/doc/Documentation/kernel-parameters.txt
http://www.kernel.org/pub/linux/kernel/people/gregkh/lkn/lkn_pdf/ch09.pdf

4.3 Boot Priority
-----------------
First try mmc and if it fails then try from OneNand.

Examples:
a) MLO (x-loader), igep.ini, zImage from MMC
If all it's present in the mmc it don't try to boot from Onenand.

b) MLO (x-loader) in MMC, igep.ini and zImage in Onenand.
If only MLO it's provided this one try to load the other information from
the Onenand.

4.4 OneNand Partition settings
-------------------------------
We suggest use minimum 3 partitions on the OneNand.

Creating 3 MTD partitions on "omap2-onenand":
0x000000000000-0x000000080000 : "X-Loader"
0x000000080000-0x000000c80000 : "Boot"
0x000000c80000-0x000020000000 : "File System"

4.4.1) Xloader partition
* Not fs formated (raw)
* Suggested size: 0x80000 (512 KiB)
* The xloader must be signed before copy it in the flash memory.

You should copy the x-loader in the firsts 4 blocks (first 512 KiB), this is not a
formated partition due the ROM not permits boot from there, you should use tools:
flash_eraseall and nandwrite for copy x-loader in the first blocks.

Suggested procedure:

nand_eraseall /dev/mtd0
nandwrite -p /dev/mtd0 <x-loader>

  • Sign x-loader
    You should execute contrib/signGP for sign the xloader that resides inside the flash memory.

contrib/signGP x-load.bin
The signed x-loader it's named: x-load.bin.ift

Due the Onenand 512 MiB has two dies it's necessary split the x-loader and convert it to a 1 die binary.
This is a know OMAP/DM/AM OneNand/Nand boot limitation.

This is the procedure for create the x-loader OneNand binary:
You should execute: (You can use copy paste in your console)

split -b 2K x-load.bin.ift split-
for file in `ls split-a?`; do cat $file >> x-load-ddp.bin.ift; cat $file >> x-load-ddp.bin.ift; done

This last command generate a file named x-load-ddp.bin.ift this is the x-loader for copy it in the OneNand.

4.4.2 Boot Partition
--------------------
* fs used jffs2 zlib compressed filesystem.
* Suggested size: 0xC00000 (12 MiB)

First time creation:
a) Use the same procedure described in point 4.2.1. Copy your jffs2 compressed image in the
partition, it can be a empty file.

b) Erase the partition and mount it as jffs2 filesystem then you can copy with cp command.

Next Times:
Copy the files using cp command, or edit directly.

when kernel boots you can enable mount this partition over /boot directory for access all boot content.

4.4.3 Rootfs
------------
* fs (your prefered fs supported by linux, maybe a good choice it should be ubifs)
* Size, all or you can create more partitions if you wish ... emoticon


5 Build procedure
=================

5.1 Build with Ubuntu Cross Compiler gcc 4.5.1

  • This is tested with Ubuntu 10.10

a) Install the cross compiler:
apt-get install cpp-4.5-arm-linux-gnueabi g++-4.5-arm-linux-gnueabi

b) Configure the board
make igep0020-sdcard_config

c) Build
make

d) Sign x-loader
You should execute contrib/signGP for sign the xloader that resides inside the flash memory.
contrib/signGP x-load.bin
The signed x-loader it's named: x-load.bin.ift


5.2 Build with IGEP SDK

a) Source the enviroment
source /usr/local/poky/eabi-glibc/environment-setup-arm-none-linux-gnueabi

b) Edit the file Makefile
Find the define:

And Set the variable as:
CROSS_COMPILE = arm-none-linux-gnueabi-

b) Configure the board
make igep0020-sdcard_config

c) build
make

d) Sign x-loader
You should execute contrib/signGP for sign the xloader that resides inside the flash memory.
contrib/signGP x-load.bin
The signed x-loader it's named: x-load.bin.ift


5.3 Build Native

a) Configure the board
make igep0020-sdcard_config

b) Modify the config.mk file
Edit the variable CFLAGS and add the option: -fno-stack-protector

CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -fno-stack-protector

c) build
make CROSS_COMPILE=""

d) Sign x-loader
You should execute contrib/signGP for sign the xloader that resides inside the flash memory.
contrib/signGP x-load.bin
The signed x-loader it's named: x-load.bin.ift


6 Contribution & Support & Report Bugs
======================================
Contributions to this project be welcome and you can send your patches to support@iseebcn.com
or you can use the igep forum for it.
You can access to IGEP-x-Loader repository using our git at git.igep.es
IGEP IRC Channel: http://webchat.freenode.net/?channels=igep