UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Observer mat01
Observer
13,995 Views
Registered: ‎05-04-2009

create a "real" image from *.elf , *.bin and *.srec don't work, a memdump does

Hi, in my Microblaze system I have an SRAM and a FLASH. I copy my code (the *.elf) with XMD to the SRAM then I start a small code in BRAM which copies the SRAM content word by word to FLASH. When booting the system the FLASH content is copied to SRAM and the system starts from the SRAM start address. (This was put up before there was the flashprogrammer tool in XPS). Now I want my system to be updated via UART but none of the above mentioned files do the trick. The only thing that worked so far was doing something similar like above : copy the *.elf to SRAM then copy with a small BRAM program to an  MMC card. Then I extract the copied portion with a HEX editor and save it to a file. If I upload this one via UART to FLASH it works. The *.bin (which looks similar) doesn't. What can I do to generate a file that works ? (for a little more comfort :-) )

Thank you,

Mat

0 Kudos
5 Replies
Adventurer
Adventurer
13,963 Views
Registered: ‎01-04-2008

Re: create a "real" image from *.elf , *.bin and *.srec don't work, a memdump does

Since the file isn't being handled by an ELF loader, the binary file must first be flattened so that all instructions and data appear at the correct addresses.  Additionally, all ELF header info (program/section headers, magic numbers, etc.) have to be removed as well.  I would recommend using mb-objcopy to produce a binary file, and then use xxd to translate this binary file into a C header file.

 

Say you have a MicroBlaze ELF called executable.elf:

 

> mb-objcopy -I elf32-microblaze -O binary executable.elf temp.bin

> xxd -i -c 4 temp.bin exec.c

 

This produces a flattened C file that preserves memory layout while also removing all ELF header info (if header info is loaded into memory it would corrupt the executable).  You can then link against this C file, and write the contents over UART, etc.

 

Also, you can compare the contents of the C file to the disassembled version of your executable by:

 

> mb-objdump -D executable.elf > disasm.txt

 

The instructions/data found in this file should correspond to those found in the array declared in the C file.

 

-Jason

Explorer
Explorer
13,947 Views
Registered: ‎01-25-2008

Re: create a "real" image from *.elf , *.bin and *.srec don't work, a memdump does

Hi,

I boot from a similar method.  Store the firmware update on SD card, at the user request copy the firmware to FLASH and then boot from FLASH to DDR using the standard methods.

 

I create a simple script to do the job:

 

 

powerpc-eabi-objcopy -O binary -j .vectors -j .text -j .init -j .fini -j .rodata -j .rodata1 -j .fw_version -j .sdata2 -j .sbss2 -j .data -j .got -j .got1 -j .got2 -j .ctors -j .dtors -j .eh_frame -j .jcr -j .gcc_except_table -j .sdata -j .sbss c:/lockie/lts2_disp1_001/release/lts2_disp1_001.elf c:/lockie/lts2_disp1_001/release/lts2_disp1_001_release.bin

 

powerpc-eabi-objcopy -O srec -j .vectors -j .text -j .init -j .fini -j .rodata -j .rodata1 -j .fw_version -j .sdata2 -j .sbss2 -j .data -j .got -j .got1 -j .got2 -j .ctors -j .dtors -j .eh_frame -j .jcr -j .gcc_except_table -j .sdata -j .sbss c:/lockie/lts2_disp1_001/release/lts2_disp1_001.elf c:/lockie/lts2_disp1_001/release/lts2_disp1_001_release.srec

 

powerpc-eabi-objdump -I .sbss2 c:/lockie/lts2_disp1_001/release/lts2_disp1_001.elf -x > c:/lockie/lts2_disp1_001/release/lts2_disp1_001_release_objdump.txt

 

The resulting .bin file can be byte-for-byte copied onto flash starting from address 0.

 

Hope this helps.

Lachlan.

 

 

Lachlan Grogan
CEO, SIL3 Pty Ltd
Melbourne, Australia
http://sil3.com.au
0 Kudos
Observer mat01
Observer
13,933 Views
Registered: ‎05-04-2009

Re: create a "real" image from *.elf , *.bin and *.srec don't work, a memdump does

Hi Jason,

 

thank you for your answer, unfortunately the xxd command is "unknown" when I try to use it in the command shell. what could I have done wrong, or could be needed ?

Mat 

0 Kudos
Observer mat01
Observer
13,932 Views
Registered: ‎05-04-2009

Re: create a "real" image from *.elf , *.bin and *.srec don't work, a memdump does

Hi Lachlan,

 

thank you for your answer, I used the first part to create the .bin file (only changed to "mb-objcopy") and I think it works ! Only... if you don't mind could you explain a little what you do there and why, I'm afraid I'm not the command-line specialist... ;-)  But I also understand if you say RTFM :-) .

 

thanks again,

Mat

 

btw: unrelated : r u from Scotland ?

 

0 Kudos
Highlighted
Explorer
Explorer
13,918 Views
Registered: ‎01-25-2008

Re: create a "real" image from *.elf , *.bin and *.srec don't work, a memdump does

Hi,

 

  1. Build your SDK project in release mode and find out where the .elf file is placed (its typically under .\release of your SDK_Project\projectxxx\ directory)
  2. Create a file called "generate_bin.sh".  The .sh file is just a text file, and really you can just keep it as .txt.
  3. By using powerpc-eabi-objcopy you get the objects out .elf given the section names as detailed by the -j command.  If you are unsure what section names you have in your .elf file then use the obj-dump command on your .elf to find out.  I dump them to a .txt file in the example given so as my VB.NET application can do a proper check for our QA system.
  4. You really don't need to do the srec dump, bit I do it for completeness and QA checking as we do other post build events to check the quality of code and boot loaders, etc.
  5. Create a batch file called go.bat and place in it:

SET CHERE_INVOKING=1 %XILINX_EDK%\bin\nt\xbash.exe -c "c:/lockie/xxxx/disp1_gen_bin_release.sh"

 Run the batch file as part of your post build flow in XPS (project properties -> build tab).

 

This way every time you build your project, it will auto-build your .bin file..

 

I spent a long time with the FAE trying to work this out.  There is no FM to R :)..

 

From Australia ;)

 

Cheers

Lachlan.

 

 


 

 

Lachlan Grogan
CEO, SIL3 Pty Ltd
Melbourne, Australia
http://sil3.com.au
0 Kudos