Flashing executable that has cross-compiled in ubuntu

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Flashing executable that has cross-compiled in ubuntu

608 Views
CanCan
Contributor I

Hello. I cross-compiled a .cpp file for my S32K148EVB-Q176 in my ubuntu x86_64 VM with the following command.

 

arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -o deneme-arm deneme.cpp -lstdc++ -lc

 

Then I am getting these errors:

 

/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a(lib_a-abort.o): in function `abort':
/build/newlib-pB30de/newlib-3.3.0/build/arm-none-eabi/thumb/v7e-m+fp/hard/newlib/libc/stdlib/../../../../../../../../newlib/libc/stdlib/abort.c:59: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a(lib_a-exit.o): in function `exit':
/build/newlib-pB30de/newlib-3.3.0/build/arm-none-eabi/thumb/v7e-m+fp/hard/newlib/libc/stdlib/../../../../../../../../newlib/libc/stdlib/exit.c:64: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a(lib_a-fstatr.o): in function `_fstat_r':
/build/newlib-pB30de/newlib-3.3.0/build/arm-none-eabi/thumb/v7e-m+fp/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/fstatr.c:55: undefined reference to `_fstat'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a(lib_a-openr.o): in function `_open_r':
/build/newlib-pB30de/newlib-3.3.0/build/arm-none-eabi/thumb/v7e-m+fp/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/openr.c:50: undefined reference to `_open'

 

My main goal is to build this program (which is a basic .cpp hello_world kind of file) in my linux machine for arm-32 architecture and then flash it to the board by itself using S32 Design Studio.

Beforehand I tried to compile a .c file with this command:

 

arm-linux-gnueabi-gcc hello.c -o hello-arm

 

It successfully generates an ELF arm-32 executable file. But when I try to flash it wiht S32DS to the board. I get below errors:

-Bus fault.

-Hard fault.

----------------------------------------------------------------------------------

-So my first question is this,

1) How can I cross-compile a .cpp code in my Linux terminal with using commands for S32K148EVB board.

Second question is,

2a) If I successfully compile, how can I flash the generated executable by itself using S32 Design Studio.

2b) Or suppose if I compiled an executable for the desired architecture like I showed with the second command. How can I successfully embed this executable to correct memory address in the board?

An explanation for this process would be really helpful. Thanks in advance.

0 Kudos
Reply
4 Replies

566 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

before you can execute main() function - you need to perform some startup for target device - like init memory and so on. Also linker file script is required to place code into proper memory space. 

To get better overview you can create new empty project in S32DS for your target and check what is required for minimal hello world project. 

0 Kudos
Reply

554 Views
CanCan
Contributor I

My proposal is this following,

I take the startup and necessary libraries for the board to my linux environment and wrote a main.cpp as following:

#include <iostream>

#include "S32K148.h"

//rest is my simple hello_world code

Can I cross-compile above code as a project in my linux terminal and generate a single ELF 32 executable using certain commands? If so, what are those commands?

Thanks in advance.

 

0 Kudos
Reply

515 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

yes, it is possible. Best way is examine existing project from S32DS. This is build command from S32DS:

arm-none-eabi-gcc -DCPU_S32K148 -I"C:\Users\nxf24838\workspaceS32DS.3.5.6\s32k148_empty/include" -O0 -g3 -Wall -c -fmessage-length=0 -ffunction-sections -fdata-sections -mcpu=cortex-m4 -specs=nosys.specs

For linker:

arm-none-eabi-gcc -T"C:\Users\nxf24838\workspaceS32DS.3.5.6\s32k148_empty/Project_Settings/Linker_Files/S32K148_256_flash.ld" -Wl,-Map,"s32k148_empty.map" -Xlinker --gc-sections -n -mcpu=cortex-m4 -specs=nosys.specs

 

If you are experimenting with your own settings - make sure that on address 0x400 is correct flash config value. With random data on this address there is high chance that you turn your MCU into brick  (mass erase disabled and chip secured). 

482 Views
CanCan
Contributor I

Thank you for the solution advise. I will get back to you with the result when I try this approach. 

0 Kudos
Reply