cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
mathmaxsean
Explorer
Explorer
3,007 Views
Registered: ‎05-23-2017

How to port the C code from the server to petalinux

Hi,

I am new with the petalinux. Currently I am working on a algorithm and I have the C implementation of the code and it runs well. The code includes many files and several dependencies.  My question is how could I port all the code to the petalinux and run on the ARM core?

 

Thanks in advance.

BR,

0 Kudos
3 Replies
ubenevides
Adventurer
Adventurer
2,936 Views
Registered: ‎09-22-2016

You could potentially configure petalinux with build tools and compile/run natively on your target machine but that is very unusual.

 

What you gotta do is to build your application ELF on windows or linux (assumed x86) using a cross-compiler (arm-none-eabi-gcc). Typically this is done inside the Vivado SDK. 

 

After you created your ELF, you would want to either embed it inside your image file(s) or push to your target machine using SSH or similar in realtime.

 

 

sdk.PNG
0 Kudos
mathmaxsean
Explorer
Explorer
2,901 Views
Registered: ‎05-23-2017

Hi @ubenevides

Thanks very much I am trying to generate the application ELF file.

Since my application depends a library fftw3 :https://github.com/FFTW/fftw3.

On the Server I need to install the library first and then to use it.

 

However I don't know how to install it on the SDK. 

I followed an instruction : https://www.xilinx.com/html_docs/xilinx2017_1/SDK_Doc/index.html?q=/html_docs/xilinx2017_1/SDK_Doc/SDK_tasks/sdk_t_create_new_libproj.html to build the library.

 

What I did is I added the whole folder of "fftw3" and then built it.  And it not worked.

I past the message from the console:  

2017-06-04 14:02:26
Extracting devices & boards... 
Loading repos summaries...
Parsing cached content file "/home/vivado_project/arm_core_with_library_01/Packages/.cache/.content_www_keil_com_pack.xml"...
File does not exist, ignored.
Parsing cached content file "/home/vivado_project/arm_core_with_library_01/Packages/.cache/.content_gnuarmeclipse_sourceforge_net_packages.xml"...
File does not exist, ignored.
Identifying installed packages...
Found no installed packages.
Completed in 4ms.
No installed packages.
Completed in 8ms.

fftw_library.JPG

SDK mentioned 

Identifying installed packages...
Found no installed packages.

 

How did I installed it on SDK?

 

Thanks in advance.

0 Kudos
ubenevides
Adventurer
Adventurer
2,882 Views
Registered: ‎09-22-2016

I tried to get you a full run but got stuck at some point. Here's what I would do:

 

1. install MSYS2 (shell for windows) 

 

http://www.msys2.org/

 

2. install build essentials

 

https://wiki.qt.io/MSYS2

 

3. download fftw

 

#!/bin/bash -x

# fill these
FFTW_VER=3.3.6-pl2
XILINX_SDK=/d/xilinx/Windows/SDK/2016.4/

 

# set environment
export PATH=$PATH:$XILINX_SDK/gnu/arm/nt/bin/

CFLAGS="-O2 -fmessage-length=0 -mcpu=cortex-a9 -mfloat-abi=softfp"
CC="arm-xilinx-eabi-gcc"

 

# download and untar
wget http://www.fftw.org/fftw-$FFTW_VER.tar.gz
rm -rf fftw-$FFTW_VER
tar xzf fftw-$FFTW_VER.tar.gz

 

# configure and compile
cd fftw-$FFTW_VER
./configure --with-slow-timer --enable-float --host=arm-xilinx-eabi --enable-single --enable-neon --disable-fortran "CC=$CC $CFLAGS"
make -j5

 

 

The glitch is building libbench2 which are benchmarks for fftw. FFTW uses some sort of dynamic optimization, ie it tries several options and checks what is the best. The problem is that it needs a cycle counter or, if you use --with-slow-timer, it will  default to gettimeofday().  However it is somehow creating a link error in the end in 

 

timer.c:89:2: error: #error "timer not defined"

 

 

The problem is, on baremetal there is no such thing as gettimeofday() since it will need not only a cycle counter but also the entire GLIB. it should be available on FreeRTOS or Linux though. if that is the case then you have to set up the SDK tools to reflect that you are using that OS. 

 

Another option would be to hack into libbench2/timer.c and patch it with your own code (eg AXITimer).