Reducing Contiki OS' Firmware Size
From ContikiWiki
TODO: This file needs many more additions. Feel free to add and edit.
Contents |
[edit] Optimised Makefile
The easiest way of reducing the firmware size is by adding compiler flags that squeeze the last couple of bytes out of the firmware. Add the following to your Makefile:
CFLAGS += -ffunction-sections LDFLAGS += -Wl,--gc-sections,--undefined=_reset_vector__,--undefined=InterruptVectors,--undefined=_copy_data_init__,--undefined=_clear_bss_init__,--undefined=_end_of_init__
The objdump tool will show the size of the initialized RAM in the .data section, and the zeroed RAM variables in the .bss section. Toolchains may have their own tool, e.g. avr-objdump.
$ objdump -t --section=.data udp-client.micaz 00800100 l d .data 00000000 .data 008001d0 l O .data 00000008 packet_memb 008001d8 l O .data 00000008 metadata_memb 008001c8 l O .data 00000008 neighbor_memb ...
The variable s below takes 34 bytes, does it really need to be static? Examine the map file to see where it is used; grepping only works for distinctive variable names!
$ avr-objdump -t --section=.bss udp-client.micaz ... 008002ce l O .bss 00000002 outputfunc 008002a3 l O .bss 00000001 i.3761 008002ac l O .bss 00000022 s 008002a4 l O .bss 00000008 periodic ...
[edit] Reducing the Size of Contiki
There are many features within Contiki that can easily be excluded or reduced in size by setting the correct flags in the project-conf.h file that you should create in your application directory.
- Processes headers contain pointers to ASCII strings that are used only for informational printing. #define PROCESS_CONF_NO_PROCESS_NAMES 1 to disable these. This reduces both flash and RAM usage by the combined length of the strings and pointers, a hundred bytes being typical.
[edit] Reducing uIP/IPv6 Stack Size
- TCP and UDP can be separately enabled or disabled with #define UIP_CONF_TCP [0,1] and #define UIP_CONF_UDP [0,1]. Disabling TCP eliminates a MSS-sized buffer. Note the TCP process needed for RPL-ROLL meshing works whether or not TCP is enabled.
[edit] Changing the radio duty cycling protocol
The RDC protocols require additional program and RAM to store neighbor information. Reduce the sequence number arrray size used for duplicate packet detection. Turn off phase optimization in contikimac to eliminate the neighbor wake time table. Use #define NETSTACK_CONF_RDC nullrdc_driver for the smallest size.
[edit] Excluding the uIP/IPv6 Stack
- CONTIKI_NO_NET=1 in the makefile excludes all the networking code. You can then add individual files or routines (e.g. checksum calculations) as needed. See /examples/ravenusb/Makefile.ravenusbstick and /fakeuip.c for an example; by default the usb stick is just a network bridge with no uIP stack of its own, although the stack can be enabled to support an internal webserver.