Embedded ssl on bare-metal system (memory allocation)

cancel
Showing results for 
Search instead for 
Did you mean: 

Embedded ssl on bare-metal system (memory allocation)

934 Views
Contributor III

Hello everyone!

 

     I'm trying to integrate and run a ssl library (wolfSSL) using S32 Design Studio and MPC5748G as target board. I have some problems when i'm trying to use the library because i don't have an operating system and i don't know how to manage memory allocation. ( WolfSSL use malloc and realloc functions, but i don't have an available implementation in S32 Studio ). Could anyone tell me please a possible solution that can help me ?

 

Best regards,

Alex.

 

Labels (1)
9 Replies

36 Views
NXP Employee
NXP Employee

Hi Alex,

S32DS supports both functions malloc and also realloc. You can use EWL library or NewLib library. But you have to do following. At first you have to increase Heap size in mem.ld linker file. Second step is edit stack section in section.ld linker file with following code:

.stack (NOLOAD) : ALIGN(16)

    {

      __HEAP = . ;

      _end = . ;

      end = . ;

      . += __HEAP_SIZE ;

      __HEAP_END = . ;

      _stack_end = . ;

      . +=  __STACK_SIZE ;

      _stack_addr = . ;

      __SP_INIT = . ;

      . += 4;

    } > m_data

Now you should be able to use malloc and realloc functions correctly.

If you have any other questions, please feel free to write me back.

Regards,

Martin 

0 Kudos

36 Views
Contributor III

Hi Martin,

I have modified heap size and stack section as you said ( linker files path:.\S32_Power_v1.0\eclipse\configuration\org.eclipse.osgi\438\0\.cp\BaseTemplate\DataBase\derivatives\MPC5748G ). But when I include stdlib.h library and use malloc function to allocate a variable the following error occurred:

    S32DS/e200_ewl/EWL_C/src/stdlib/alloc.c undefined reference to `_end' undefined reference to `_end'

I also define EWL_BAREBOARD_MALLOC or EMBEDDED_WARRIOR_MALLOC but same problem occurred.

EWL library is already in S32 Studio ( library path: .\S32_Power_v1.0\S32DS\e200_ewl2\EWL_C ) or I need to install something else ?

Thanks,

Alex.

0 Kudos

36 Views
NXP Employee
NXP Employee

Hi Alex,

I tested malloc function and it works correct to me. I also tested on board, and memory seems to be allocated correct. Please see attached project.

About EWL and NewLib, you choose this during project creation. You do not have to install anything.

Regards,

Martin

36 Views
Contributor III

Hi Martin,

Thanks for your help! I have modified heap size, stack section and create a new project using NewLib and it's work fine for me.

Could you please tell me if I can use time.h header file that contains definitions of functions to get and manipulate date and time information? I tried to use time_t type but the following error occurred: Type 'time_t' could not be resolved .

Regards,

Alex.

0 Kudos

36 Views
NXP Employee
NXP Employee

Hi Alex,

I had used this include #include <time.h> and then I defined global variable time_t TimeVariable; and I am able to compile my program correct.

I also saw notice time_t could not be resolved before compiling, but after compilation it seems to be correct.

Please try and let me know.

Regards,

Martin

0 Kudos

36 Views
Contributor III

Hi Martin,

I had created a new project and I use  #include <time.h> and time_t variable. After compilation  the project it's look ok, no errors.

But in other project (please see attached archive) I couldn't be able to use  this header. I imported this project and to be able to use malloc function I change "Libraries support" to newlib( -specs=nosys.specs) from project properties (Tool Settings -> Target Processor) and modify heap size and stack section from Project_Settings folder . When I use time type variable I encountered these errors and warnings:

Error: Type 'time_t' could not be resolved.

Warning: C:/Freescale/S32_Power_v1.0/S32DS/e200_ewl2/EWL_C/include/ctime ignoring #pragma options align [-Wunknown-pragmas].

Thanks,

Alex.

0 Kudos

35 Views
NXP Employee
NXP Employee

Hi Alex,

I found your problem. There were remain some include paths from EWL library in your project and time.h library was referenced to EWL. But there is no time_t type in EWL time.h.

So open project settings, choose C/C++ Build -> Settings and click Includes. Delete two EWL paths. Now it will work correct.

Regards,

Martin

35 Views
Contributor III

Hi Martin,

Many thanks! I deleted the paths and now the project work correctly.

Could you please tell me how and if it possible to read/write data from or to a file using NewLib ?

Best regards,

Alex.

0 Kudos

35 Views
NXP Employee
NXP Employee

Hi Alex,

please look at the functions fprintf, fscanf, fgetc, fputc, fgets and fputs. All these functions are implemented in newlib, but unfortunately, I do not have any experience with read/write data from/to file using micro. I found some information how to read/write to file using Arduino, so I think it should be also possible using MPC5748G, but I am not able to provide any more information.

Regards,

Martin

PS: Do not forget correctly configure UART.

0 Kudos