Sign In

Don't have a Xilinx account yet?

  • Choose to receive important news and product information
  • Gain access to special content
  • Personalize your web experience on Xilinx.com

Create Account

Username

Password

Forgot your password?
XClose Panel
Xilinx Home
Reply
Visitor
ch4ron
Posts: 14
Registered: ‎10-30-2010
0

Loading an image (picture) file with a software application in SDK

I have a software application that uses an image file (picture) which is currently in the src directory of my project in SDK.  I'm trying to load the picture to a specific section of DDR memory during FPGA programming along with my application, then access it later during software runtime via C pointers.  From what I gather this can be done with the linker script, but I'm having trouble determining exactly how to do it inside SDK.  I can create a new memory section within the DDR address range, but how do I specify that I want to load the file to this memory?

 

Thanks in advance.

Xilinx Employee
austin
Posts: 3,663
Registered: ‎02-27-2008
0

Re: Loading an image (picture) file with a software application in SDK

[ Edited ]

c,

The design has to be running to read and write the DDR memory. So, it isn't going to be able to load it to this memory in the same way you load the bitstream Instead, you will have to bring up the entire design, and then have the design "get" the file to be processed. How you do that is up to you. The design could request the data over a serial port, from a multi-gigabit transceiver, or use the LWIP ethernet interface. Depends on what logic and interfaces you have on your board. A bit clunky, but would work, is to put the image in the same flash memory after the configuration file (if it will fit).  Then you need a way to reade the picture out of the flash, and place it in the DDR memory...

Austin Lesea
Principal Engineer
Xilinx San Jose
Super Contributor
pcurt
Posts: 188
Registered: ‎04-09-2008
0

Re: Loading an image (picture) file with a software application in SDK

You could write a program (I would use MATLAB, personally) to read your image and write it out as a (gigantic) hexadecimal plain-text array in a .c file. Basically tack on a "char img[] = {" before and "};" afterward, and put commas in between. By initializing that global array, the linker should include it in the .data section. Be prepared for a very long download time when you run "dow main.elf" in xmd.

Make sure you adjust the linker script in the SDK to run your program from external memory, otherwise elfcheck will fail.

There may be a more elegant way to do this automatically using a Makefile and the linker.
Senior Engineer
EM Photonics, Inc.
Visitor
ch4ron
Posts: 14
Registered: ‎10-30-2010
0

Re: Loading an image (picture) file with a software application in SDK

Thanks for both of the replies.

 

I considered both methods, and was originally using the script version to convert the image to a char array.  I didn't really like that method, mainly because if I wanted to open the array file for any reason, it bogged down SDK to where it was unusable.  I did find another method to get the image data into DDR.  It was a little convoluted, so I'll describe it here in case anyone else wants the information.

 

Using mb-objcopy (MicroBlaze version of the objcopy utility), I converted the image (lena.pnm) to an object file (lena.o).  The command I used follows:

 

mb-objcopy -I binary -O elf32-microblazele -B microblaze lena.pnm lena.o

I used elf32-microblazele (as opposed to elf32-microblaze) so the object file would be compatible with the little endian AXI bus.  I linked the object file into the software application in SDK which effectively embedded the data into the elf file, and my linker script wrote the elf sections to the DDR.  The data then was accessible using the variables _binary_lena_pnm_start (starting address of the data),  _binary_lena_pnm_size (size of the data), and _binary_lena_pnm_end (ending address of the data).  Casting the start address to a char * allowed me to access the individual characters in the image data.

 

I don't know if there is any real benefit to the object file method instead of the char array method, save not having to write a script, but I thought it might be useful to have a couple different ways to accomplish the task.