This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

wolfSSL and StellarisWare examples

Hi,

I want to use the freertos_demo that is part of StellarisWare /TivaWare in combination with wolfSSL library but I find it difficult to read the Makefile (actually the makedefs files).

I downloaded and compiled wolfSSL according to the manual. Now in /usr/local/lib there are the following files:

/usr/local/lib//libwolfssl.la

/usr/local/lib//libwolfssl.so

/usr/local/lib//libwolfssl.so.3

/usr/local/lib//libwolfssl.so.3.1.0

Now I open makedefs from the StellarisWare root directory and added the folling code to line 160: 

LIBS=-lwolfssl

Further, I modified lines 246 and 252 which now state the following (both lines are identical; basically I only added  '${LIBS}' ):

'${LIBM}' '${LIBC}' '${LIBGCC}' '${LIBS}';

However, when I go to the blinky sub-directory and perform a "make clean; make", I get the following error:

arm-none-eabi-ld: cannot find -lwolfssl

What am I missing?

Best

  • Hi Richard,

    I've moved this to the TM4C forum. They are more familiar with the TivaWare makefiles and can answer your question.

    Todd
  • Hello Richard

    Instead of libwolfssl.la can you rename the file as libwolfssl.a and then retry?

    Regards
    Amit
  • Hi Amit,

    first, the name changes did not yield any positive results.

    However, I created a stand alone file to see whether the library would be loaded correctly at all. I figured that *.so and *.la files must reside in /usr/lib/. Thus, I re-compiled wolfSSL with prefix set to /usr/. Now, this code works well:

    #include <stdio.h>
    #include <stdlib.h>
    #include <wolfssl/wolfcrypt/sha.h>
    
    main() {
    
    	byte shaSum[SHA_DIGEST_SIZE];
    	byte buff[1024];
    	Sha sha;
    	wc_InitSha(&sha);
    	wc_ShaUpdate(&sha, buff, sizeof(buffy));
    	wc_ShaFinal(&sha, shaSum);
    	printf("%x\n", buff);
    
    	return 0;
    }

    I compile it with: gcc main.c -lwolfssl

    Thus, the next step is to include  -lwolfssl into the makedefs/ Makefile of the StellarisWare examples. I am still running into the following error while running make:

    blinky.c:26:34: fatal error: wolfssl/wolfcrypt/sha.h: No such file or directory

    Thus, I guess I included -lwolfssl at the wrong position. If I can locate the correct position to specify -lwolfssl, it should be working.

  • Hello Richard

    That seems to be a compilation error and not a linker error. Can you check the path of the header file?

    Regards
    Amit
  • Dear Amit,

    the header files are in place:

    $ ls -lsa /usr/include/wolfssl/wolfcrypt/sha.h
    4 -rw-r--r-- 1 root root 2279 Jan 12 11:04 /usr/include/wolfssl/wolfcrypt/sha.h

    Also the stand-alone project uses the same include command and it works. I think it is because I am using -lwolfssl at a wrong position in the makedefs file. Where exactly would you insert any -lXXXX command to tell gcc to use a library?

  • Hello Richard,

    The path is included before the -l option in my Linaro GCC compiler setup

    Regards
    Amit
  • Those are the relevant files for using make inside one of the stellaris example projects.


    First the Makefile within the blinky project folder:

    #
    # Defines the part type that this project uses.
    #
    PART=LM4F120H5QR
    
    #
    # Set the processor variant.
    #
    VARIANT=cm4f
    
    #
    # The base directory for StellarisWare.
    #
    ROOT=../../..
    
    #
    # Include the common make definitions.
    #
    include ${ROOT}/makedefs
    
    #
    # Where to find header files that do not live in the source directory.
    #
    IPATH=../../..
    
    #
    # The default rule, which causes the blinky example to be built.
    #
    all: ${COMPILER}
    all: ${COMPILER}/blinky.axf
    
    #
    # The rule to clean out all the build products.
    #
    clean:
    	@rm -rf ${COMPILER} ${wildcard *~}
    
    #
    # The rule to create the target directory.
    #
    ${COMPILER}:
    	@mkdir -p ${COMPILER}
    
    #
    # Rules for building the blinky example.
    #
    ${COMPILER}/blinky.axf: ${COMPILER}/blinky.o
    ${COMPILER}/blinky.axf: ${COMPILER}/startup_${COMPILER}.o
    ${COMPILER}/blinky.axf: blinky.ld
    SCATTERgcc_blinky=blinky.ld
    ENTRY_blinky=ResetISR
    
    #
    # Include the automatically generated dependency files.
    #
    ifneq (${MAKECMDGOALS},clean)
    -include ${wildcard ${COMPILER}/*.d} __dummy__
    endif


    Secondly, the makedefs file that is located three hierarchy level above:

    #******************************************************************************
    #
    # makedefs - Definitions common to all makefiles.
    #
    # Copyright (c) 2005-2012 Texas Instruments Incorporated.  All rights reserved.
    # Software License Agreement
    # 
    #   Redistribution and use in source and binary forms, with or without
    #   modification, are permitted provided that the following conditions
    #   are met:
    # 
    #   Redistributions of source code must retain the above copyright
    #   notice, this list of conditions and the following disclaimer.
    # 
    #   Redistributions in binary form must reproduce the above copyright
    #   notice, this list of conditions and the following disclaimer in the
    #   documentation and/or other materials provided with the  
    #   distribution.
    # 
    #   Neither the name of Texas Instruments Incorporated nor the names of
    #   its contributors may be used to endorse or promote products derived
    #   from this software without specific prior written permission.
    # 
    # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    # 
    # This is part of revision 9453 of the Stellaris Firmware Development Package.
    #
    #******************************************************************************
    
    #******************************************************************************
    #
    # Get the operating system name.  If this is Cygwin, the .d files will be
    # munged to convert c: into /cygdrive/c so that "make" will be happy with the
    # auto-generated dependencies.
    #
    #******************************************************************************
    os:=${shell uname -s}
    
    #******************************************************************************
    #
    # The compiler to be used.
    #
    #******************************************************************************
    ifndef COMPILER
    COMPILER=gcc
    endif
    
    #******************************************************************************
    #
    # Definitions for using GCC.
    #
    #******************************************************************************
    ifeq (${COMPILER}, gcc)
    
    #
    # Get the prefix for the tools to use.  Use arm-stellaris-eabi if it exists,
    # otherwise fall back to arm-none-eabi.
    #
    PREFIX=${shell type arm-stellaris-eabi-gcc > /dev/null 2>&1 && \
             echo arm-stellaris-eabi || echo arm-none-eabi}
    
    #
    # The command for calling the compiler.
    #
    CC=${PREFIX}-gcc
    
    #
    # The location of the C compiler
    # ARMGCC_ROOT is used by some makefiles that need to know where the compiler
    # is installed.  It is not used further for normal stellarisware apps
    #
    ARMGCC_ROOT:=${shell dirname '${shell sh -c "which ${CC}"}'}/..
    
    #
    # Determine the compiler CPU/FPU options based on the processor variant.
    #
    ifndef VARIANT
    CPU=-mcpu=cortex-m3
    FPU=
    else
    ifeq (${VARIANT}, cm3)
    CPU=-mcpu=cortex-m3
    FPU=
    else
    ifeq (${VARIANT}, cm4f)
    CPU=-mcpu=cortex-m4
    FPU=-mfpu=fpv4-sp-d16 -mfloat-abi=softfp
    else
    $(error Unknown processor variant ${VARIANT}!)
    endif
    endif
    endif
    
    #
    # The flags passed to the assembler.
    #
    AFLAGS=-mthumb \
           ${CPU}  \
           ${FPU}  \
           -MD          
           
    
    #
    # The flags passed to the compiler.
    #
    CFLAGS=-mthumb             \
           ${CPU}              \
           ${FPU}              \
           -Os                 \
           -ffunction-sections \
           -fdata-sections     \
           -MD                 \
           -std=c99            \
           -Wall               \
           -Wno-unused-variable   \
           -pedantic           \
           -DPART_${PART}      \
           -c           	\      
           
    
    #
    # The command for calling the library archiver.
    #
    AR=${PREFIX}-ar
    
    #
    # The command for calling the linker.
    #
    LD=${PREFIX}-ld
    
    #
    # The flags passed to the linker.
    #
    LDFLAGS=--gc-sections -Map gcc/output.map
    
    #
    # Get the location of libgcc.a from the GCC front-end.
    #
    LIBGCC=${shell ${CC} ${CFLAGS} -print-libgcc-file-name}
    
    #
    # Get the location of libc.a from the GCC front-end.
    #
    LIBC=${shell ${CC} ${CFLAGS} -print-file-name=libc.a}
    
    #
    # Get the location of libm.a from the GCC front-end.
    #
    LIBM=${shell ${CC} ${CFLAGS} -print-file-name=libm.a}
    
    #
    # The command for extracting images from the linked executables.
    #
    OBJCOPY=${PREFIX}-objcopy
    
    #
    # Tell the compiler to include debugging information if the DEBUG environment
    # variable is set.
    #
    ifdef DEBUG
    CFLAGS+= -D DEBUG
    endif
    
    #
    # Add the tool specific CFLAGS.
    #
    CFLAGS+=${CFLAGSgcc}
    
    #
    # Add the include file paths to AFLAGS and CFLAGS.
    #
    AFLAGS+=${patsubst %,-I%,${subst :, ,${IPATH}}}
    CFLAGS+=${patsubst %,-I%,${subst :, ,${IPATH}}}
    
    #
    # The rule for building the object file from each C source file.
    #
    ${COMPILER}${SUFFIX}/%.o: %.c
    	@if [ 'x${VERBOSE}' = x ];                            \
    	 then                                                 \
    	     echo "  CC    ${<}";                             \
    	 else                                                 \
    	     echo ${CC} ${CFLAGS} -D${COMPILER} -o ${@} ${<}; \
    	 fi
    	@${CC} ${CFLAGS} -D${COMPILER} -o ${@} ${<}
    ifneq ($(findstring CYGWIN, ${os}), )
    	@sed -i -r 's/ ([A-Za-z]):/ \/cygdrive\/\1/g' ${@:.o=.d}
    endif
    
    #
    # The rule for building the object file from each assembly source file.
    #
    ${COMPILER}${SUFFIX}/%.o: %.S
    	@if [ 'x${VERBOSE}' = x ];                               \
    	 then                                                    \
    	     echo "  AS    ${<}";                                \
    	 else                                                    \
    	     echo ${CC} ${AFLAGS} -D${COMPILER} -o ${@} -c ${<}; \
    	 fi
    	@${CC} ${AFLAGS} -D${COMPILER} -o ${@} -c ${<}
    ifneq ($(findstring CYGWIN, ${os}), )
    	@sed -i -r 's/ ([A-Za-z]):/ \/cygdrive\/\1/g' ${@:.o=.d}
    endif
    
    #
    # The rule for creating an object library.
    #
    ${COMPILER}${SUFFIX}/%.a:
    	@if [ 'x${VERBOSE}' = x ];     \
    	 then                          \
    	     echo "  AR    ${@}";      \
    	 else                          \
    	     echo ${AR} -cr ${@} ${^}; \
    	 fi
    	@${AR} -cr ${@} ${^}
    
    #
    # The rule for linking the application.
    #
    ${COMPILER}${SUFFIX}/%.axf:
    	@if [ 'x${SCATTERgcc_${notdir ${@:.axf=}}}' = x ];                    \
    	 then                                                                 \
    	     ldname="${ROOT}/gcc/standalone.ld";                              \
    	 else                                                                 \
    	     ldname="${SCATTERgcc_${notdir ${@:.axf=}}}";                     \
    	 fi;                                                                  \
    	 if [ 'x${VERBOSE}' = x ];                                            \
    	 then                                                                 \
    	     echo "  LD    ${@} ${LNK_SCP}";                                  \
    	 else                                                                 \
    	     echo ${LD} -T $${ldname}                                         \
    	          --entry ${ENTRY_${notdir ${@:.axf=}}}                       \
    	          ${LDFLAGSgcc_${notdir ${@:.axf=}}}                          \
    	          ${LDFLAGS} -o ${@} $(filter %.o %.a, ${^})                  \
    	          '${LIBM}' '${LIBC}' '${LIBGCC}' -lwolfssl;                            \
    	 fi;                                                                  \
    	${LD} -T $${ldname}                                                   \
    	      --entry ${ENTRY_${notdir ${@:.axf=}}}                           \
    	      ${LDFLAGSgcc_${notdir ${@:.axf=}}}                              \
    	      ${LDFLAGS} -o ${@} $(filter %.o %.a, ${^})                      \
    	      '${LIBM}' '${LIBC}' '${LIBGCC} -lwolfssl'
    	@${OBJCOPY} -O binary ${@} ${@:.axf=.bin}
    endif
    
    

    Given both files, my guess is that the correct place to add -lwolfssl would be the CFLAGS command, right after the -c. However I added it at this place without success, although the header files are in the correct place. It seems like a pretty easy problem but I just can't find the reason for it.

    Best

  • Hello Richard

    I have asked one of co workers to check the same and provide you with a resolution

    Regards
    Amit
  • Thanks a bunch Amit. I highly appreciate your efforts.

    P.S.: Some more things I noticed. I created a stand-alone file outside the stellarisware that calls some wolfSSL functions using the library. It works pretty fine when compiled with gcc:

    gcc -o aead main_aead.c -lwolfssl;

    However, when cross-compiled it says it can't find the header files:

    $ arm-none-eabi-gcc -o aead main_aead.c -lwolfssl;

    main_aead.c:1:35: fatal error: wolfssl/wolfcrypt/aes.h: No such file or directory


    Thus, I added some information about where to find wolfSSL:

    $ arm-none-eabi-gcc -o aead main_aead.c printhex.c -I /usr/include/ -lwolfssl;
    cc1: warning: include location "/usr/include/" is unsafe for cross-compilation
    In file included from /usr/include/pthread.h:21:0,
                     from /usr/include/wolfssl/wolfcrypt/wc_port.h:78,
                     from /usr/include/wolfssl/wolfcrypt/types.h:27,
                     from /usr/include/wolfssl/wolfcrypt/aes.h:25,
                     from main_aead.c:1:
    /usr/include/features.h:388:23: fatal error: gnu/stubs.h: No such file or directory
    compilation terminated.

    Obviously, those are the wrong header files. Thus, I located the arm-none-eabi- header files in /usr/lib/gcc/arm-none-eabi/4.9.3/include/ and created a symbolic link there to /usr/include/wolfssl/. Now I get the following error:

    $ arm-none-eabi-gcc -o aead main_aead.c printhex.c -I /usr/lib/gcc/arm-none-eabi/4.9.3/include/ -lwolfssl;
    In file included from /usr/lib/gcc/arm-none-eabi/4.9.3/include/wolfssl/wolfcrypt/types.h:27:0,
                     from /usr/lib/gcc/arm-none-eabi/4.9.3/include/wolfssl/wolfcrypt/aes.h:25,
                     from main_aead.c:1:
    /usr/lib/gcc/arm-none-eabi/4.9.3/include/wolfssl/wolfcrypt/wc_port.h:104:33: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'wolfSSL_Mutex'
    /usr/lib/gcc/arm-none-eabi/4.9.3/include/wolfssl/wolfcrypt/wc_port.h:167:42: error: expected ')' before '*' token
    /usr/lib/gcc/arm-none-eabi/4.9.3/include/wolfssl/wolfcrypt/wc_port.h:168:42: error: expected ')' before '*' token
    /usr/lib/gcc/arm-none-eabi/4.9.3/include/wolfssl/wolfcrypt/wc_port.h:169:42: error: expected ')' before '*' token
    /usr/lib/gcc/arm-none-eabi/4.9.3/include/wolfssl/wolfcrypt/wc_port.h:170:44: error: expected ')' before '*' token
    main_aead.c: In function 'main':
    main_aead.c:56:2: warning: passing argument 1 of 'printhex' discards qualifiers from pointer target type
    main_aead.c:7:6: note: expected 'unsigned char *' but argument is of type 'const byte *'
    main_aead.c:71:2: warning: passing argument 1 of 'printhex' discards qualifiers from pointer target type
    main_aead.c:7:6: note: expected 'unsigned char *' but argument is of type 'const byte *

  • Hello Richard,

    I believe the library has to be added to the LDFLAGS as the library is required during the linking stage. It is better to not modify the makedefs file in TivaWare root folder. Instead the library can be passed to the linker by using the following line in the Makefile inside the project folder.

    LDFLAGS+=-l:<wolfSSL_Library_Path>/libwolfssl.la

    Hopefully this works!

    Thanks,

    Sai

     

  • Hi Sai,

    I added

    LDFLAGS+=-l:/usr/lib/libwolfssl.la

    to the Makefile beneath the IPATH command. However, the resulting error is the same:

    $ make clean; make
      CC    blinky.c
    In file included from /home/andre/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/arm-none-eabi/4.5.2/../../../../arm-none-eabi/include/wolfssl/wolfcrypt/types.h:27:0,
                     from /home/andre/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/arm-none-eabi/4.5.2/../../../../arm-none-eabi/include/wolfssl/wolfcrypt/sha256.h:27,
                     from blinky.c:26:
    /home/andre/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/arm-none-eabi/4.5.2/../../../../arm-none-eabi/include/wolfssl/wolfcrypt/wc_port.h:104:33: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'wolfSSL_Mutex'
    /home/andre/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/arm-none-eabi/4.5.2/../../../../arm-none-eabi/include/wolfssl/wolfcrypt/wc_port.h:167:42: error: expected ')' before '*' token
    /home/andre/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/arm-none-eabi/4.5.2/../../../../arm-none-eabi/include/wolfssl/wolfcrypt/wc_port.h:168:42: error: expected ')' before '*' token
    /home/andre/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/arm-none-eabi/4.5.2/../../../../arm-none-eabi/include/wolfssl/wolfcrypt/wc_port.h:169:42: error: expected ')' before '*' token
    /home/andre/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/arm-none-eabi/4.5.2/../../../../arm-none-eabi/include/wolfssl/wolfcrypt/wc_port.h:170:44: error: expected ')' before '*' token
    blinky.c: In function 'main':
    blinky.c:73:9: error: 'Sha' undeclared (first use in this function)
    blinky.c:73:9: note: each undeclared identifier is reported only once for each function it appears in
    blinky.c:73:13: error: expected ';' before 'sha'
    blinky.c:74:9: warning: implicit declaration of function 'wc_InitSha'
    blinky.c:74:21: error: 'sha' undeclared (first use in this function)
    blinky.c:75:9: warning: implicit declaration of function 'wc_ShaUpdate'
    blinky.c:76:9: warning: implicit declaration of function 'wc_ShaFinal'
    ../../../makedefs:189: recipe for target 'gcc/blinky.o' failed
    make: *** [gcc/blinky.o] Error 1
    

  • Hello Richard,

    Based on this error log, it looks like the correct library file is being picked up. So the initial error of not picking the correct library file is resolved.

    The errors from the log seem to suggest that the wolfSSL is not configured correctly. This could be due to incompatible combination of the define labels being selected. According to wolfSSL manual, the necessary define to configure wolfSSL for an RTOS and TCP/IP stack are located in the file "./wolfssl/wolfcrypt/settings.h". Please refer wolfSSL's manual for more details.

    Thanks,
    Sai