Index: trunk/softs/tsar_boot/Makefile
===================================================================
--- trunk/softs/tsar_boot/Makefile	(revision 417)
+++ trunk/softs/tsar_boot/Makefile	(revision 425)
@@ -2,7 +2,5 @@
 -include ./build.mk
 
-ifndef MAKECMDGOALS
-  MAKECMDGOALS=none
-endif
+MAKECMDGOALS ?= none
 
 ifneq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),clean distclean clean-doc doc))
@@ -19,8 +17,4 @@
     endif
   endif
-endif
-
-ifeq ($(USE_DT), 0)
-	DTS=
 endif
 
@@ -58,7 +52,7 @@
 
 CFLAGS     := -Wall -mno-gpopt -ffreestanding -fomit-frame-pointer -mips32 \
-		      -ggdb -mlong-calls
+		      -ggdb -mlong-calls -Werror
 
-C_SRCS	   := boot_elf_loader.c boot_ioc.c boot_memcpy.c boot_tty.c exceptions.c
+C_SRCS	   := boot_elf_loader.c boot_ioc.c boot_utils.c boot_tty.c exceptions.c
 
 ifndef SOCLIB
@@ -74,13 +68,5 @@
 TARGET     := bin.soft
 
-ifndef USE_DT
-  USE_DT := 1
-else
-  USE_DT := $(USE_DT)
-endif
-
-ifdef SYSCLK_FREQ
-  DEFS += -DSYSCLK_FREQ=$(SYSCLK_FREQ)
-endif
+USE_DT 	   ?= 1
 
 all: $(TARGET)
@@ -91,15 +77,17 @@
 	$(DU) -D $@ > $@.txt
 
+ifeq ($(USE_DT), 1)
 $(BUILD_DIR)/platform.ld: $(BUILD_DIR)/platform.dtb
 	$(ECHO) "[ HEXDUMP ]     $(notdir $<)"
 	$(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@
+else
+$(BUILD_DIR)/platform.ld:
+	$(ECHO) "[  TOUCH  ]     $(notdir $@)"
+	touch $@
+endif
 
 $(BUILD_DIR)/platform.dtb: $(DTS)
-ifeq ($(USE_DT), 1)
 	$(ECHO) "[   DTC   ]     $(notdir $<)"
 	${DTC} -O dtb -o $@ $< &> /dev/null
-else
-	touch $@
-endif
 
 $(BUILD_DIR):
Index: trunk/softs/tsar_boot/README.txt
===================================================================
--- trunk/softs/tsar_boot/README.txt	(revision 417)
+++ trunk/softs/tsar_boot/README.txt	(revision 425)
@@ -17,4 +17,5 @@
              the TTY, IOC and XICU devices.
              It defines also:
+
               -> CACHE_COHERENCE
                  This constant is used by the boot_ioc_read function to know
@@ -22,12 +23,15 @@
                  must be invalidated in the dcache after the transfert has
                  finished.
-				 0 means invalidation must be made.
-
-              -> INSTRUMENTATION
-                 Set value different to 0 if some instrumentation of the
-                 bootloader is needed.
 
               -> CACHE_LINE_SIZE
+                 This constant is mandatory if CACHE_COHERENCE=0
                  This constant defines the size in bytes of a cache line.
+
+              -> BOOT_DEBUG
+                 Set value to 1 to show some debug messages during loading 
+
+              -> BOOT_DEBUG_IOC
+                 Set value to 1 to show some debug messages during loading
+                 concerning the disk accesses. 
 
               -> IRQ_PER_PROC
@@ -37,13 +41,11 @@
       --->  platform_soclib.dts:
 
-             Device tree file. It is mandatory if compiling
-             for a SOCLIB platform. If the application to execute does not use
-             a device tree file, create an empty one.
+             Device tree file. It is mandatory if compiling for a SOCLIB
+             platform and USE_DT=1.
 
       --->  platform_fpga.dts:
 
-             Device tree file. It is mandatory if compiling
-             for a FPGA platform. If the application to execute does not use
-             a device tree file, create an empty one.
+             Device tree file. It is mandatory if compiling for a FPGA platform
+             and USE_DT=1.
 
       --->  ldscript:
@@ -70,11 +72,8 @@
                    drivers
 
-             ---> SYSCLK_FREQ=<value hz>
+             ---> USE_DT=0
 
-                   If not SOCLIB platform, this flag allows us to choose the
-                   CLK frequency used in the hardware platform (i.e. FPGA).
-                   This information is used to configurate the SPI device
-                   which allow us to drive a SD card device.
+                   If a device tree file is not used, set this flag to 0. It
+                   is set by default to 1.
 
-              i.e. make PLATFORM_DIR=conf/<platform_dir> SYSCLK_FREQ=50000000
-                   make PLATFORM_DIR=conf/<platform_dir> SOCLIB=1
+              e.g. make PLATFORM_DIR=conf/<platform_dir> SOCLIB=1 USE_DT=0
Index: trunk/softs/tsar_boot/conf/platform_fpga_de2-115/defs_platform.h
===================================================================
--- trunk/softs/tsar_boot/conf/platform_fpga_de2-115/defs_platform.h	(revision 417)
+++ trunk/softs/tsar_boot/conf/platform_fpga_de2-115/defs_platform.h	(revision 425)
@@ -7,5 +7,5 @@
 #define CACHE_LINE_SIZE 64//bytes
 
-#define BOOT_DEBUG      0
+#define BOOT_DEBUG      1
 #define BOOT_DEBUG_IOC  0
 
@@ -13,2 +13,6 @@
 #define TTY_BASE        0xFC000000
 #define ICU_BASE        0xFD000000
+
+/* Mandatory argument only for FPGA platforms */ 
+
+#define SYSCLK_FREQ     25000000//Hz
Index: trunk/softs/tsar_boot/conf/platform_vgsb_xicu_mmu/defs_platform.h
===================================================================
--- trunk/softs/tsar_boot/conf/platform_vgsb_xicu_mmu/defs_platform.h	(revision 417)
+++ trunk/softs/tsar_boot/conf/platform_vgsb_xicu_mmu/defs_platform.h	(revision 425)
@@ -7,4 +7,7 @@
 #define CACHE_LINE_SIZE 16//bytes
 
+#define BOOT_DEBUG      1
+#define BOOT_DEBUG_IOC  0
+
 #define ICU_BASE        0x00F00000
 #define IOC_BASE        0x00F10000
Index: trunk/softs/tsar_boot/conf/platform_vgsb_xicu_mmu/ldscript
===================================================================
--- trunk/softs/tsar_boot/conf/platform_vgsb_xicu_mmu/ldscript	(revision 417)
+++ trunk/softs/tsar_boot/conf/platform_vgsb_xicu_mmu/ldscript	(revision 425)
@@ -7,5 +7,5 @@
 /* Definition of the base address for all segments */ 
 
-seg_stack_base    = 0x00108000;
+seg_stack_base    = 0x00018000;
 seg_boot_base     = 0xBFC00000;       /* le code de boot */
 
Index: trunk/softs/tsar_boot/include/boot_memcpy.h
===================================================================
--- trunk/softs/tsar_boot/include/boot_memcpy.h	(revision 417)
+++ 	(revision )
@@ -1,6 +1,0 @@
-#ifndef BOOT_MEMCPY_H
-#define BOOT_MEMCPY_H
-
-void * boot_memcpy(void *_dst, const void *_src, unsigned int size);
-
-#endif
Index: trunk/softs/tsar_boot/include/boot_utils.h
===================================================================
--- trunk/softs/tsar_boot/include/boot_utils.h	(revision 425)
+++ trunk/softs/tsar_boot/include/boot_utils.h	(revision 425)
@@ -0,0 +1,57 @@
+/**
+ * \file    : boot_utils.h
+ * \date    : August 2012
+ * \author  : Cesar Fuguet
+ *
+ * Definition of some miscellaneous functions used by the
+ * pre-loader
+ */
+
+#ifndef BOOT_UTILS_H
+#define BOOT_UTILS_H
+
+#include <elf-types.h>
+#include <boot_tty.h>
+
+/**
+ * memcpy( _dst, _src, size )
+ *
+ * Transfer data between to memory buffers.
+ *
+ * \param _dst   : Destination buffer base address 
+ * \param _src   : Source buffer base address
+ * \param size   : Number of bytes to transfer 
+ *
+ */
+void * memcpy(void *_dst, const void *_src, unsigned int size);
+
+/**
+ * memset( _dst, value, size )
+ *
+ * Initialize memory buffers with predefined value.
+ *
+ * \param _dst   : Destination buffer base address 
+ * \param value  : Initialization value 
+ * \param size   : Number of bytes to initialize
+ *
+ */
+void * memset(void *_dst, const int value, unsigned int size);
+
+/******************************************************************************
+ * Misc functions for the ELF 
+ *****************************************************************************/
+
+/**
+ * boot_print_elf_phdr( elf_phdr_ptr )
+ *
+ * Print some fields of a ELF program header
+ *
+ * \param elf_phdr_ptr : Pointer to the ELF program header to print
+ *
+ */
+void boot_print_elf_phdr(Elf32_Phdr * elf_phdr_ptr);
+
+#endif
+
+// vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+
Index: trunk/softs/tsar_boot/include/defs.h
===================================================================
--- trunk/softs/tsar_boot/include/defs.h	(revision 417)
+++ trunk/softs/tsar_boot/include/defs.h	(revision 425)
@@ -3,5 +3,5 @@
 #define BOOT_VERSION    0x00010001
 
-#define BOOT_STACK_SIZE 0x8000     /* 32 KB */
+#define BOOT_STACK_SIZE 0x4000     /* 16 KB */
 #define BOOT_LOADER_LBA 2
 #define PHDR_ARRAY_SIZE	16
Index: trunk/softs/tsar_boot/src/boot_elf_loader.c
===================================================================
--- trunk/softs/tsar_boot/src/boot_elf_loader.c	(revision 417)
+++ trunk/softs/tsar_boot/src/boot_elf_loader.c	(revision 425)
@@ -1,4 +1,4 @@
 /**
- * \file    : boot_loader_entry.c
+ * \file    : boot_elf_loader.c
  * \date    : August 2012
  * \author  : Cesar Fuguet
@@ -13,10 +13,20 @@
 #include <elf-types.h>
 #include <boot_tty.h>
-#include <boot_memcpy.h>
+#include <boot_utils.h>
 #include <defs.h>
+
+#if (BOOT_DEBUG == 1)
+static char* init_state_str[] = {
+    "ELF_HEADER_STATE",
+    "ELF_PROGRAM_HEADER_STATE",
+    "ELF_OFFSET_STATE",
+    "ELF_SEGMENT_STATE",
+    "ELF_END_STATE"
+};
+#endif
 
 void * boot_elf_loader(unsigned int lba)
 {
-    /**
+    /*
      * Temporary variables used by the boot loader
      */
@@ -26,6 +36,6 @@
 
     unsigned char * buffer_ptr;
-    Elf32_Ehdr    * elf_header_ptr;
-    Elf32_Phdr    * elf_pht_ptr;
+    Elf32_Ehdr    * elf_ehdr_ptr;
+    Elf32_Phdr    * elf_phdr_ptr;
 
     unsigned int nb_available;
@@ -34,12 +44,15 @@
     unsigned int nb_block;
     unsigned int offset;
+
+    unsigned char * pseg_ptr;
+    unsigned int pseg_start;
+    unsigned int pseg_end;
+    unsigned int pseg_remainder;
     unsigned int pseg;
-    unsigned int i;
-    unsigned int segment_req;
 
     /*
      * Loader state machine definition
      */
-    enum
+    typedef enum
     {
         ELF_HEADER_STATE,
@@ -48,49 +61,35 @@
         ELF_SEGMENT_STATE,
         ELF_END_STATE
-    } init_state
-#if (BOOT_DEBUG ==1)
-    , init_state_debug
-#endif
-        ;
-
-#if (BOOT_DEBUG == 1)
-    char* init_state_str[] = {
-        "ELF_HEADER_STATE",
-        "ELF_PROGRAM_HEADER_STATE",
-        "ELF_OFFSET_STATE",
-        "ELF_SEGMENT_STATE",
-        "ELF_END_STATE"
-    };
-#endif
-
+    } elf_loader_t;
+
+    elf_loader_t init_state;
+    init_state = ELF_HEADER_STATE;
+
+#if (BOOT_DEBUG == 1)
+    elf_loader_t init_state_debug;
+    init_state_debug = ELF_END_STATE;
+#endif
 
     boot_puts("Starting boot_elf_loader function...\n\r");
 
-    nb_block           = lba;
-
-    pseg               = 0;
-    nb_available       = 0;
-    nb_rest            = sizeof(Elf32_Ehdr);
-    offset             = 0;
-
-    elf_header_ptr     = (Elf32_Ehdr *) &elf_header;
-    elf_pht_ptr        = (Elf32_Phdr *) &elf_pht[0];
-
-    init_state         = ELF_HEADER_STATE;
-#if (BOOT_DEBUG == 1)
-    init_state_debug   = ELF_END_STATE;
-#endif
+    nb_block     = lba;
+    nb_available = 0;
+    nb_rest      = sizeof(Elf32_Ehdr);
+    pseg         = 0;
+    offset       = 0;
+    elf_ehdr_ptr = (Elf32_Ehdr *) &elf_header;
+    elf_phdr_ptr = (Elf32_Phdr *) &elf_pht[0];
 
     while(init_state != ELF_END_STATE)
     {
-        if (nb_available == 0)
+        if (nb_available == 0 )
         {
             buffer_ptr = &boot_elf_loader_buffer[0];
 
-            if ( boot_ioc_read(nb_block , buffer_ptr, 1) )
+            if (boot_ioc_read(nb_block , buffer_ptr, 1))
             {
                 boot_puts (
                     "ERROR: "
-                    "IOC_FAILED"
+                    "boot_ioc_read() failed"
                     "\n"
                 );
@@ -118,9 +117,9 @@
         switch(init_state)
         {
-            /**
+            /*
              * Reading ELF executable header
              */
             case ELF_HEADER_STATE:
-                boot_memcpy(elf_header_ptr, buffer_ptr, nb_read);
+                memcpy(elf_ehdr_ptr, buffer_ptr, nb_read);
 
                 nb_rest -= nb_read;
@@ -128,12 +127,13 @@
                 if(nb_rest == 0)
                 {
-                    nb_rest = elf_header_ptr->e_phnum * elf_header_ptr->e_phentsize;
-
-                    /* Verification of ELF Magic Number */
-                    if (
-                        (elf_header_ptr->e_ident[EI_MAG0] != ELFMAG0) ||
-                        (elf_header_ptr->e_ident[EI_MAG1] != ELFMAG1) ||
-                        (elf_header_ptr->e_ident[EI_MAG2] != ELFMAG2) ||
-                        (elf_header_ptr->e_ident[EI_MAG3] != ELFMAG3) )
+                    nb_rest = elf_ehdr_ptr->e_phnum * elf_ehdr_ptr->e_phentsize;
+
+                    /*
+                     * Verification of ELF Magic Number
+                     */
+                    if ( (elf_ehdr_ptr->e_ident[EI_MAG0] != ELFMAG0) ||
+                         (elf_ehdr_ptr->e_ident[EI_MAG1] != ELFMAG1) ||
+                         (elf_ehdr_ptr->e_ident[EI_MAG2] != ELFMAG2) ||
+                         (elf_ehdr_ptr->e_ident[EI_MAG3] != ELFMAG3) )
                     {
                         boot_puts(
@@ -150,11 +150,11 @@
                      * smaller than the work size allocated for the
                      * elf_pht[PHDR_ARRAY_SIZE] array
-                     **/
-                    if (elf_header_ptr->e_phnum > PHDR_ARRAY_SIZE)
+                     */
+                    if (elf_ehdr_ptr->e_phnum > PHDR_ARRAY_SIZE)
                     {
                         boot_puts(
                             "ERROR: "
-                            "ELF PHDR table size is bigger than "
-                            "the allocated work space"
+                            "ELF PHDR table size is bigger than the allocated"
+                            "work space"
                             "\n"
                         );
@@ -168,42 +168,37 @@
                 break;
 
-            /**
+            /*
              * Reading ELF program headers
              */
             case ELF_PROGRAM_HEADER_STATE:
-                boot_memcpy(elf_pht_ptr, buffer_ptr, nb_read);
-
-                elf_pht_ptr = (Elf32_Phdr *)((unsigned char *) elf_pht_ptr + nb_read);
-                nb_rest    -= nb_read;
+                memcpy(elf_phdr_ptr, buffer_ptr, nb_read);
+
+                elf_phdr_ptr = 
+                    (Elf32_Phdr *)((unsigned char *) elf_phdr_ptr + nb_read);
+
+                nb_rest -= nb_read;
 
                 if(nb_rest == 0)
                 {
-                    elf_pht_ptr = (Elf32_Phdr *) &elf_pht[0];
+                    elf_phdr_ptr = (Elf32_Phdr *) &elf_pht[0];
 
                     /*
                      * Search the first not NULL segment in the ELF file
                      */
-                    for (pseg = 0; pseg < elf_header_ptr->e_phnum; pseg++)
-                    {
-                        if(elf_pht_ptr[pseg].p_type == PT_LOAD)
+                    for (pseg = 0; pseg < elf_ehdr_ptr->e_phnum; pseg++)
+                    {
+                        if(elf_phdr_ptr[pseg].p_type == PT_LOAD)
                         {
 #if (BOOT_DEBUG == 1)
-                            boot_puts("found a loadable segment:");
-                            boot_puts("\n- type   : "); boot_putx(elf_pht_ptr[pseg].p_type);
-                            boot_puts("\n- offset : "); boot_putx(elf_pht_ptr[pseg].p_offset);
-                            boot_puts("\n- vaddr  : "); boot_putx(elf_pht_ptr[pseg].p_vaddr);
-                            boot_puts("\n- paddr  : "); boot_putx(elf_pht_ptr[pseg].p_paddr);
-                            boot_puts("\n- filesz : "); boot_putx(elf_pht_ptr[pseg].p_filesz);
-                            boot_puts("\n- memsz  : "); boot_putx(elf_pht_ptr[pseg].p_memsz);
-                            boot_puts("\n- flags  : "); boot_putx(elf_pht_ptr[pseg].p_flags);
-                            boot_puts("\n- align  : "); boot_putx(elf_pht_ptr[pseg].p_align);
-#endif
-                            if (elf_pht_ptr[pseg].p_offset < offset)
+                            boot_puts("loadable segment found:\n");
+                            boot_print_elf_phdr(&elf_phdr_ptr[pseg]);
+#endif
+                            if (elf_phdr_ptr[pseg].p_offset < offset)
                             {
                                 /* 
-                                 * Case where the segment to load includes the elf
-                                 * and program headers 
-                                 * */
-                                nb_rest = elf_pht_ptr[pseg].p_filesz - offset;
+                                 * Case where the segment to load includes the 
+                                 * elf and program headers 
+                                 */
+                                nb_rest = elf_phdr_ptr[pseg].p_filesz - offset;
                                 init_state = ELF_SEGMENT_STATE;
                             }
@@ -212,6 +207,6 @@
                                 /* 
                                  * Segment to load is further away in ELF file
-                                 * */
-                                nb_rest = elf_pht_ptr[pseg].p_offset - offset;
+                                 */
+                                nb_rest = elf_phdr_ptr[pseg].p_offset - offset;
                                 init_state = ELF_OFFSET_STATE;
                             }
@@ -220,5 +215,5 @@
                     }
 
-                    if (pseg == elf_header_ptr->e_phnum)
+                    if (pseg == elf_ehdr_ptr->e_phnum)
                     {
                         boot_puts(
@@ -234,7 +229,11 @@
                 break;
 
-            /**
+            /*
              * Go to the offset of the first not null program segment in the
              * ELF file
+             *
+             * TODO:
+             * No need to read from the disk the useless bytes. Try to compute
+             * the next usefull lba
              */
             case ELF_OFFSET_STATE:
@@ -243,5 +242,5 @@
                 if (nb_rest == 0)
                 {
-                    nb_rest    = elf_pht_ptr[pseg].p_filesz;
+                    nb_rest    = elf_phdr_ptr[pseg].p_filesz;
                     init_state = ELF_SEGMENT_STATE;
                 }
@@ -249,51 +248,77 @@
                 break;
 
-            /**
+            /*
              * Reading ELF segments
+             *
+             * TODO:
+             * Do not pass by block buffer but write directly in target memory
+             * address
              */
             case ELF_SEGMENT_STATE:
-                /**
-                 * Copying ELF segment data in memory segments using the virtual
-                 * address got from the ELF file
+                /*
+                 * Verify that loadable segment does not conflict with
+                 * pre-loader memory space 
                  */
-                segment_req = ((elf_pht_ptr[pseg].p_vaddr & 0xBFC00000) != 0xBFC00000);
-
-                if ( segment_req )
-                {
-                    boot_memcpy((unsigned char *) elf_pht_ptr[pseg].p_vaddr +
-                                (elf_pht_ptr[pseg].p_filesz - nb_rest),
-                                buffer_ptr,
-                                nb_read);
-                }
+                pseg_start = elf_phdr_ptr[pseg].p_vaddr;
+
+                pseg_end   = elf_phdr_ptr[pseg].p_vaddr +
+                             elf_phdr_ptr[pseg].p_memsz;
+
+                if ((pseg_start >= 0xBFC00000 && pseg_start <= 0xBFC10000) ||
+                    (pseg_end   >= 0xBFC00000 && pseg_end   <= 0xBFC10000) ||
+                    (pseg_start <  0xBFC00000 && pseg_end   >  0xBFC10000))
+                {
+                    boot_puts(
+                        "ERROR: "
+                        "Program segment conflits with pre-loader memory space"
+                        "\n"
+                    );
+                    boot_exit();
+                }
+
+                /*
+                 * Copy the ELF segment data in memory using the
+                 * virtual address obtained from the ELF file
+                 */
+                pseg_ptr = (unsigned char *)
+                    elf_phdr_ptr[pseg].p_vaddr  +
+                    elf_phdr_ptr[pseg].p_filesz -
+                    nb_rest;
+
+                memcpy(pseg_ptr, buffer_ptr, nb_read);
 
                 nb_rest -= nb_read;
 
-                if ( nb_rest == 0 )
-                {
-                    if ( segment_req )
-                    {
-                        boot_puts("Copied segment at address ");
-                        boot_putx(elf_pht_ptr[pseg].p_vaddr);
-                        boot_puts("\n");
-
-                        /*
-                         * Fill remaining bytes with zeros (filesz < memsz)
-                         */
-                        for ( i = 0                                                        ;
-                              i < (elf_pht_ptr[pseg].p_memsz - elf_pht_ptr[pseg].p_filesz) ;
-                              i--                                                          )
+                if (nb_rest == 0)
+                {
+                    /*
+                     * Fill remaining bytes with zeros (filesz < memsz)
+                     */
+                    pseg_remainder =
+                        elf_phdr_ptr[pseg].p_memsz  -
+                        elf_phdr_ptr[pseg].p_filesz ;
+
+                    pseg_ptr = (unsigned char *)
+                        elf_phdr_ptr[pseg].p_vaddr  +
+                        elf_phdr_ptr[pseg].p_filesz ;
+
+                    memset(pseg_ptr, 0, pseg_remainder);
+
+                    boot_puts("Copied segment at address ");
+                    boot_putx(elf_phdr_ptr[pseg].p_vaddr);
+                    boot_puts("\n");
+
+                    /*
+                     * Search the next first not NULL segment in the ELF file
+                     */
+                    for (pseg += 1; pseg < elf_ehdr_ptr->e_phnum; pseg++)
+                    {
+                        if(elf_phdr_ptr[pseg].p_type == PT_LOAD)
                         {
-                            *(unsigned char *)
-                            (elf_pht_ptr[pseg].p_vaddr + elf_pht_ptr[pseg].p_filesz + i) = 0;
-                        }
-                    }
-
-                    /*
-                     * Search the first not NULL segment in the ELF file
-                     */
-                    for ( pseg = pseg + 1; pseg < elf_header_ptr->e_phnum; pseg++) {
-                        if(elf_pht_ptr[pseg].p_type == PT_LOAD)
-                        {
-                            nb_rest = elf_pht_ptr[pseg].p_offset - offset;
+#if (BOOT_DEBUG == 1)
+                            boot_puts("loadable segment found:\n");
+                            boot_print_elf_phdr(&elf_phdr_ptr[pseg]);
+#endif
+                            nb_rest = elf_phdr_ptr[pseg].p_offset - offset;
                             break;
                         }
@@ -303,5 +328,5 @@
                      * Program loading finished
                      */
-                    if(pseg == elf_header_ptr->e_phnum)
+                    if(pseg == elf_ehdr_ptr->e_phnum)
                     {
                         init_state = ELF_END_STATE;
@@ -317,6 +342,6 @@
         }
 
-        buffer_ptr              += nb_read;
-        nb_available            -= nb_read;
+        buffer_ptr   += nb_read;
+        nb_available -= nb_read;
     }
 
@@ -325,7 +350,10 @@
         "Entry point address: "
     );
-    boot_putx(elf_header_ptr->e_entry);
+
+    boot_putx(elf_ehdr_ptr->e_entry);
     boot_puts("\n");
 
-    return ((void *) elf_header_ptr->e_entry);
+    return ((void *) elf_ehdr_ptr->e_entry);
 }
+
+// vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
Index: trunk/softs/tsar_boot/src/boot_ioc.c
===================================================================
--- trunk/softs/tsar_boot/src/boot_ioc.c	(revision 417)
+++ trunk/softs/tsar_boot/src/boot_ioc.c	(revision 425)
@@ -5,9 +5,4 @@
 static struct sdcard_dev  _sdcard_device;
 static struct spi_dev   * _spi_device   = ( struct spi_dev * )IOC_BASE;
-
-#ifndef SYSCLK_FREQ
-#warning "Using default value for SYSCLK_FREQ = 50000000"
-#define SYSCLK_FREQ 50000000U
-#endif // end ifndef SYSCLK_FREQ
 
 #endif // end ifndef SOCLIB_IOC
@@ -266,5 +261,5 @@
 
     // iterate on cache lines
-    for (i = 0; i < size; i += line_size) {
+    for (i = 0; i <= size; i += line_size) {
         asm volatile(
             " cache %0, %1"
Index: trunk/softs/tsar_boot/src/boot_memcpy.c
===================================================================
--- trunk/softs/tsar_boot/src/boot_memcpy.c	(revision 417)
+++ 	(revision )
@@ -1,21 +1,0 @@
-#include <boot_memcpy.h>
-
-void * boot_memcpy(void *_dst, const void *_src, unsigned int size)
-{
-    unsigned int *dst = _dst;
-    const unsigned int *src = _src;
-    if ( ! ((unsigned int)dst & 3) && ! ((unsigned int)src & 3) )
-        while (size > 3) {
-            *dst++ = *src++;
-            size -= 4;
-        }
-
-    unsigned char *cdst = (unsigned char*) dst;
-    unsigned char *csrc = (unsigned char*) src;
-
-    while (size--) {
-        *cdst++ = *csrc++;
-    }
-    return _dst;
-}
-
Index: trunk/softs/tsar_boot/src/boot_utils.c
===================================================================
--- trunk/softs/tsar_boot/src/boot_utils.c	(revision 425)
+++ trunk/softs/tsar_boot/src/boot_utils.c	(revision 425)
@@ -0,0 +1,99 @@
+/**
+ * \file    : boot_utils.c
+ * \date    : August 2012
+ * \author  : Cesar Fuguet
+ *
+ * Definition of some miscellaneous functions used in by the
+ * pre-loader
+ */
+
+#include <boot_utils.h>
+
+/**
+ * memcpy( _dst, _src, size )
+ *
+ * Transfer data between to memory buffers.
+ *
+ * \param _dst   : Destination buffer base address 
+ * \param _src   : Source buffer base address
+ * \param size   : Number of bytes to transfer 
+ *
+ */
+void * memcpy(void *_dst, const void *_src, unsigned int size)
+{
+    unsigned int *dst = _dst;
+    const unsigned int *src = _src;
+    if ( ! ((unsigned int)dst & 3) && ! ((unsigned int)src & 3) )
+        while (size > 3) {
+            *dst++ = *src++;
+            size -= 4;
+        }
+
+    unsigned char *cdst = (unsigned char*) dst;
+    unsigned char *csrc = (unsigned char*) src;
+
+    while (size--) {
+        *cdst++ = *csrc++;
+    }
+    return _dst;
+}
+
+/**
+ * memset( _dst, value, size )
+ *
+ * Initialize memory buffers with predefined value.
+ *
+ * \param _dst   : Destination buffer base address 
+ * \param value  : Initialization value 
+ * \param size   : Number of bytes to initialize
+ *
+ */
+void * memset(void *_dst, const int value, unsigned int size)
+{
+    char * dst = (char *) _dst;
+
+    while(size--) *dst++ = (char) value;
+
+    return _dst;
+}
+
+/*
+ * Misc functions for the ELF format
+ */
+
+/**
+ * boot_print_elf_phdr( elf_phdr_ptr )
+ *
+ * Print some fields of a ELF program header
+ *
+ * \param elf_phdr_ptr : Pointer to the ELF program header to print
+ *
+ */
+void boot_print_elf_phdr(Elf32_Phdr * elf_phdr_ptr)
+{
+    boot_puts("- type   : ");
+    boot_putx(elf_phdr_ptr->p_type);
+
+    boot_puts("\n- offset : ");
+    boot_putx(elf_phdr_ptr->p_offset);
+
+    boot_puts("\n- vaddr  : ");
+    boot_putx(elf_phdr_ptr->p_vaddr);
+
+    boot_puts("\n- paddr  : ");
+    boot_putx(elf_phdr_ptr->p_paddr);
+
+    boot_puts("\n- filesz : ");
+    boot_putx(elf_phdr_ptr->p_filesz);
+
+    boot_puts("\n- memsz  : ");
+    boot_putx(elf_phdr_ptr->p_memsz);
+
+    boot_puts("\n- flags  : ");
+    boot_putx(elf_phdr_ptr->p_flags);
+
+    boot_puts("\n- align  : ");
+    boot_putx(elf_phdr_ptr->p_align);
+}
+
+// vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
Index: trunk/softs/tsar_boot/src/reset.S
===================================================================
--- trunk/softs/tsar_boot/src/reset.S	(revision 417)
+++ trunk/softs/tsar_boot/src/reset.S	(revision 425)
@@ -34,5 +34,5 @@
     .extern boot_ioc_read
     .extern boot_elf_loader
-    .extern boot_memcpy
+    .extern memcpy
     .extern boot_puts
     .extern boot_putx
@@ -58,5 +58,5 @@
     .word   boot_ioc_read           /* 0xbfc0018 */
     .word   boot_elf_loader         /* 0xbfc001C */
-    .word   boot_memcpy             /* 0xbfc0020 */
+    .word   memcpy                  /* 0xbfc0020 */
     .word   boot_puts               /* 0xbfc0024 */
     .word   boot_putx               /* 0xbfc0028 */
