WolfSSL optimisation (how to get more usable memory)

Hi all,
Yesterday I finally got the WolfSSL client (ported my @cermak) connected to AWS IoT. It’s not a stable connection yet, but I’ll post the file back to Rob’s repository as soon as it’s working as it should. My biggest hurdle right now is finding space to run any kind of application. Thanks to @peekay123 I now know exactly how much memory I have available on Photon/P1 and it’s not a lot given that WolfSSL takes up 118Kb.

I’m compiling locally and I’m now inspecting my .map file for ideas of how to free more memory to make this useful. Looking at the .map file there are several classes related to float handling that I don’t think I need.

For example - libgcc links “arm_addsubdf3.o” with methods named “floatdidf”,“aeabi_ui2d”, “floatunsidf” and a host of other large items. I presume this is for handling addition, subtraction but several of them seem to involve specific routines for Floats and I’m pretty sure that I can survive without that. How would I go about removing it? Are there any flags I can set to save memory?

J

1 Like

@jenschr, if you are willing to not use OTA, you may be able to get more space byt compiling a monolithic image (like the old Core). You will need to flash via DFU and it is assumed you are compiling locally. The make is in the lines of this:

cd firmware/main
make clean all PLATFORM=photon MODULAR=n 

This is unknown territory so YMMV as to the size of image you can get on the device.

Yeah, I know. OTA is key for most of these boxes though, so it’s not an option :-/

I’m up and running with two very stable project builds yielding excellent connection reliability to AWS IoT. I’m running the WolfSSL v0.0.2 port by @cermak “out of the box”, and even with all my app specific code, I’m still able to fit with some spare.

One app is doing some high speed analog sample/capture with analytics that packages up the results into JSON payloads, and the other is an edge device monitoring a mesh network of endpoints that also frames up database snapshots into JSON. They’re what I’d categorize as mid-weight operations doing some involved processing, and my worst case usages are as follows:

Memory use:
   text    data     bss     dec     hex filename
 121244     288    5024  126556   1ee5c /workspace/target/workspace.elf

Longer term for me, OTA is not necessary as these things will be mature enought for standalone operation. The bigger question will be provisioning at scale and if Photons are the right fit.

2 Likes

This is hard to read. If you have the library working and you just want to focus on your code, you can turn off the error strings: NO_ERROR_STRINGS. That will give you 11k. I don’t remember if the server code is turned on, if so, turning that off saves 6k.

Reference	
DEFINE	Firmware size	Difference
		
NO_RABBIT	89224	100
NO_WOLFSSL_SERVER	89324	6112
NO_ERROR_STRINGS	95436	11152
NO_SHA512	106588	0
NO_DSA	106588	144
NO_HC128	106732	48
NO_RC4	106780	1232
NO_MD4	108012	0
NO_MD5	108012	2320
NO_DES3	110332	4128
FULL	114460	
wolfssl@0.0.1/wolfiot	90220	
HAVE_TLS_EXTENSIONS	90716	496
HAVE_SNI	91068	352
HAVE_ECC	105884	14816
1 Like

@jimini I’m curious - what extra code did you add to connect to AWS IoT? We’ve made a wrapper class that adds the standard PubSub client and with that in place we’re spending 118Kb without having any app in there.

@cermak that one I’ll try for sure! Great tip!

J

@jenschr, I didn’t add anything in the way of code… I did add all my endpoint specifics and cert/key instances. The client is working out of the box, and all I have done is cleanup and modularization of the example code in the project.ino as repo’d in the GitHub example.

I’ve yet to go disable these other pieces of WolfSSL, nor have I had to consider doing so thus far. Where are these located @cermak?

Aha. So you don’t have an MQTT client, but talk directly via TCP/TLS? I thought AWS IoT only supported HTTP or MQTT?

Yes, TLS v1.2 for SSL handling. Using HTTP POST with JSON payloads.

1 Like

Right. So you’re parsing the JSON directly as char arrays for just simple return values then?

Yes… creating payloads for direct consumption in AWS IoT