Any mbed TLS efforts yet?

I cross compiled mbedtls for the particle. I never finished getting an HTTPS client, but this post offers some details, after you follow my instructions:
https://tls.mbed.org/discussions/generic/mbedtls-build-for-arm (see Nov 11 2015 entry)

This is what I did (as best remembered from memory):

  • Get mbedtls : https://github.com/ARMmbed/mbedtls

  • Get the spark firmware: https://github.com/spark/firmware

  • Compile Spark’s firmware locally: https://github.com/spark/firmware/blob/develop/docs/gettingstarted.md

  • Create your application directory: APPDIR. I kept APPDIR our of the Spark firmware hierarchy because I like don’t want to accidentally erase or mess-up one code archive

    • Create a directory for it {APPDIR}
    • Create a src dir {APPDIR}/src
    • place your source code in the src directory
    • Create a mbedtlsinc directory {APPDIR}/mbedtlsinc
    • link your source to the {SPARKCODE}/firmware/main directory
      ln -s {APPNAME}/src {SPARKCODE}/firmware/main/{APPNAME}
  • Cross compile mbedtls’s libraries:

    • Create a config-photon.h header in {APPDIR}/mbedtlsinc. The config-photon.h is the “mbedtls/configs/config-mini-tls1_1.h” file, with three lines commented out: MBEDTLS_ENTROPY_C, MBEDTLS_NET_C, MBEDTLS_FS_IO.
    • Run the command:
      make CFLAGS="-I/{ROOT_MBEDTLSINC}/ -DMBEDTLS_CONFIG_FILE='<mbedtlsinc/config-photon.h>'" CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld lib
      • NOTE: on copy and past, make sure the hyphen is next to “DMBEDTLS_CONFIG_FILE”
      • This uses the modified config-photon.h header to cut out much of mbedtls’s functionality. Also, it switches the compiler, linker and archiver to arm’s.
  • Prepare to compile our project by adding additional compile instructions

    • append this instruction to the build process in {SPARKCODE}/firmware/main/makefile:
      include ./applications/$(APP)/include.mk
    • create {APPDIR}/src/include.mk with the following data (so it includes mbedtls’s libraries)
      CFLAGS += -I{mbedtls}/include LIB_DIRS += {mbedtls}/library LIBS += mbedcrypto mbedtls mbedx509
  • Compile your project.
    cd {SPARKCODE}/firmware/main ; make all APP={APPNAME} PLATFORM={photon|electron}

  • flash to photon|electron

    • The binary is in {SPARK}/firmware/build/target/user-part/platform-{6|10}-m/{APPNAME}.bin
    • Put device into accept mode: press setup/reset. release reset. wait for yellow. release setup.
    • flash --usb {SPARK}/firmware/build/target/user-part/platform-{6|10}-m/{APPNAME}.bin

Hope that helps someone. Let me know if I mixed up a command or two.