cancel
Showing results for 
Search instead for 
Did you mean: 
8,881 Views
Registered: ‎10-15-2010

SREC is bigger than ELF so it does not fit on external Flash

Jump to solution

Hi,

 

i'm, using a PPC440 with a virtex5.

 

I did a big PPC SW (elf=27MB) cause i need to use a lot of buffer (16384*1460) for my HDMA. Even if it's big, it fits well in my external DDR2 (that is 64MB).

Now i would like to put it in my external flash (32MB), then use a bootloader to copy it from flash to DDR2 when power on my system.

 

Problem :

When i use the "program flash memory" wizard to build a SREC file from my elf, the SREC become bigger (54MB) than the elf so of course it does not fit anymore on my external Flash.

 

Question :

- Why SREC become bigger than ELF (when i tested with the "TestApp_Memory" example, the SREC became smaller than the ELF) ?

- Do you have an idea how to reduce the size of the SREC ?

- Since it's my HDMA buffer that take a lot of space, it is possible to build buffer directly inside the DDR2 after or something like this ?

 

Of course a solution is to reduce the number of buffer, but it's not possible for my application.

I did a lot of test but now i'm really confused .... help me please

 

Thank you

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Voyager
Voyager
11,586 Views
Registered: ‎05-09-2008

Re: SREC is bigger than ELF so it does not fit on external Flash

Jump to solution

This is a good starting point :

 

    /* 
     *bootloader.c 
     * 
     * 
     *Loads an ELF kernel from flash memory. 
     */  
      
    #include "bootloader.h"   
    void main(void)  
    {  
        static char *mem = (char *)FLASH_MEM0_BASEADDR;  
      
        Elf32_Ehdr *elf;            //elf file header  
        Elf32_Phdr *elf_phdr;   /* program segment header */  
        unsigned long e_entry,    
        e_phoff,  //program head offset (at file)  
        e_phnum;  //phdr number  
                        
      int i;  
          
      while(1)  
      {  
         elf = (Elf32_Ehdr *) mem;  
          
         if (elf->e_ident[0] !=0x7f ||    
            elf->e_ident[1] !='E' ||  
            elf->e_ident[2] !='L' ||  
            elf->e_ident[3] !='F' )  
         {  
            print("not an ELF file\n");  
            continue; //??flash ??  
        }  
        if (elf->e_type != ET_EXEC) {  
            print("not an ELF executable\n");  
            continue;  
        }  
      
        e_entry = elf->e_entry;  
        e_phnum = elf->e_phnum;  
        e_phoff = elf->e_phoff;  
      
      
        for (i = 0; i  e_phnum; ++i)  
        {  
            elf_phdr = (Elf32_Phdr *) (e_phoff+mem);  
              
            e_phoff += sizeof(*elf_phdr);  
      
            if (elf_phdr->p_type != PT_LOAD)  
                continue;  
      
            memcpy((void *)(elf_phdr->p_vaddr), (void*)(elf_phdr->p_offset+mem), elf_phdr->p_filesz);  
            memset((char*)(elf_phdr->p_vaddr+elf_phdr->p_filesz), 0, elf_phdr->p_memsz -elf_phdr->p_filesz);  
        }  
      
        print("starting kernel...\n");  
      
        void (*boot)();  
        boot=(void*)e_entry;    
        boot();  
        //???????????  
        #ifdef LED_BASEADDR  
        XIo_Out32(LED_BASEADDR, 0x55);  
        XIo_Out32(LED_BASEADDR, 0xaa);  
        #endif  
     }  
    }

secureasm

View solution in original post

8 Replies
Highlighted
Explorer
Explorer
8,874 Views
Registered: ‎07-14-2008

Re: SREC is bigger than ELF so it does not fit on external Flash

Jump to solution

If I remember correctly, SREC is kind of a ascii based format. If you want to reduce the size of your Flash image, you might consider to use the BIN format instead. I'm not sure if the PPC command line tools offer the same function as they do for Microblaze though. For Microblaze, there is a tool called "mb-objcopy". It converts a given ELF file into a BIN file. In case of Microblaze you need to exclude all the jump vectors, otherwise you'd get a huge file. The tool generates kind of an image of your complete address space and hence simply copies all defined memory areas (see ld script) into that file and fills the gaps with 0x00. The needed BIN bootloader then just has to copy the data from Flash into volatile memory and jump right in.

0 Kudos
Highlighted
Voyager
Voyager
8,869 Views
Registered: ‎05-09-2008

Re: SREC is bigger than ELF so it does not fit on external Flash

Jump to solution

Hi,

 

use an ELF bootloader instead of SREC bootloader.

 

The bootloader is very small and size of file is size of ELF program.

 

secureasm

0 Kudos
Highlighted
8,865 Views
Registered: ‎10-15-2010

Re: SREC is bigger than ELF so it does not fit on external Flash

Jump to solution

: Thanks for your answer, but i cannot use BIN file

 

: Great thanks !! That seems a really good solution.

Can you tell me more about it please. Where can i find a tutorial or examples. Actually i'm novice and i used the already build in SREC bootloader example.

 

Thanks everybody to take time to help me

 

0 Kudos
Highlighted
8,859 Views
Registered: ‎10-15-2010

Re: SREC is bigger than ELF so it does not fit on external Flash

Jump to solution

I cannot find any example of elf bootloader .... can you help me please.

or maybe does someone have another solution

0 Kudos
Highlighted
Voyager
Voyager
11,587 Views
Registered: ‎05-09-2008

Re: SREC is bigger than ELF so it does not fit on external Flash

Jump to solution

This is a good starting point :

 

    /* 
     *bootloader.c 
     * 
     * 
     *Loads an ELF kernel from flash memory. 
     */  
      
    #include "bootloader.h"   
    void main(void)  
    {  
        static char *mem = (char *)FLASH_MEM0_BASEADDR;  
      
        Elf32_Ehdr *elf;            //elf file header  
        Elf32_Phdr *elf_phdr;   /* program segment header */  
        unsigned long e_entry,    
        e_phoff,  //program head offset (at file)  
        e_phnum;  //phdr number  
                        
      int i;  
          
      while(1)  
      {  
         elf = (Elf32_Ehdr *) mem;  
          
         if (elf->e_ident[0] !=0x7f ||    
            elf->e_ident[1] !='E' ||  
            elf->e_ident[2] !='L' ||  
            elf->e_ident[3] !='F' )  
         {  
            print("not an ELF file\n");  
            continue; //??flash ??  
        }  
        if (elf->e_type != ET_EXEC) {  
            print("not an ELF executable\n");  
            continue;  
        }  
      
        e_entry = elf->e_entry;  
        e_phnum = elf->e_phnum;  
        e_phoff = elf->e_phoff;  
      
      
        for (i = 0; i  e_phnum; ++i)  
        {  
            elf_phdr = (Elf32_Phdr *) (e_phoff+mem);  
              
            e_phoff += sizeof(*elf_phdr);  
      
            if (elf_phdr->p_type != PT_LOAD)  
                continue;  
      
            memcpy((void *)(elf_phdr->p_vaddr), (void*)(elf_phdr->p_offset+mem), elf_phdr->p_filesz);  
            memset((char*)(elf_phdr->p_vaddr+elf_phdr->p_filesz), 0, elf_phdr->p_memsz -elf_phdr->p_filesz);  
        }  
      
        print("starting kernel...\n");  
      
        void (*boot)();  
        boot=(void*)e_entry;    
        boot();  
        //???????????  
        #ifdef LED_BASEADDR  
        XIo_Out32(LED_BASEADDR, 0x55);  
        XIo_Out32(LED_BASEADDR, 0xaa);  
        #endif  
     }  
    }

secureasm

View solution in original post

Highlighted
8,854 Views
Registered: ‎10-15-2010

Re: SREC is bigger than ELF so it does not fit on external Flash

Jump to solution

thank you very much i ll have a look at it and tell you if i can do something with

0 Kudos
Highlighted
8,848 Views
Registered: ‎10-15-2010

Re: SREC is bigger than ELF so it does not fit on external Flash

Jump to solution

man you are sooooooo great !!!

I just modified few stuff to adapt your files to my project and it works at the first time.

You cannot imagine how much you helped me.

 

Thank you so much.

 

 

0 Kudos
Highlighted
Voyager
Voyager
8,839 Views
Registered: ‎05-09-2008

Re: SREC is bigger than ELF so it does not fit on external Flash

Jump to solution

Hi,

 

when I can, no problem.

 

secureasm

0 Kudos