footprint.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/sh
  2. #
  3. # This file is part of mbed TLS (https://tls.mbed.org)
  4. #
  5. # Copyright (c) 2015-2016, ARM Limited, All Rights Reserved
  6. #
  7. # Purpose
  8. #
  9. # This script determines ROM size (or code size) for the standard mbed TLS
  10. # configurations, when built for a Cortex M3/M4 target.
  11. #
  12. # Configurations included:
  13. # default include/mbedtls/config.h
  14. # yotta yotta/module/mbedtls/config.h
  15. # thread configs/config-thread.h
  16. # suite-b configs/config-suite-b.h
  17. # psk configs/config-ccm-psk-tls1_2.h
  18. #
  19. # Usage: footprint.sh
  20. #
  21. set -eu
  22. CONFIG_H='include/mbedtls/config.h'
  23. if [ -r $CONFIG_H ]; then :; else
  24. echo "$CONFIG_H not found" >&2
  25. echo "This script needs to be run from the root of" >&2
  26. echo "a git checkout or uncompressed tarball" >&2
  27. exit 1
  28. fi
  29. if grep -i cmake Makefile >/dev/null; then
  30. echo "Not compatible with CMake" >&2
  31. exit 1
  32. fi
  33. if which arm-none-eabi-gcc >/dev/null 2>&1; then :; else
  34. echo "You need the ARM-GCC toolchain in your path" >&2
  35. echo "See https://launchpad.net/gcc-arm-embedded/" >&2
  36. exit 1
  37. fi
  38. ARMGCC_FLAGS='-Os -march=armv7-m -mthumb'
  39. OUTFILE='00-footprint-summary.txt'
  40. log()
  41. {
  42. echo "$@"
  43. echo "$@" >> "$OUTFILE"
  44. }
  45. doit()
  46. {
  47. NAME="$1"
  48. FILE="$2"
  49. log ""
  50. log "$NAME ($FILE):"
  51. cp $CONFIG_H ${CONFIG_H}.bak
  52. if [ "$FILE" != $CONFIG_H ]; then
  53. cp "$FILE" $CONFIG_H
  54. fi
  55. {
  56. scripts/config.pl unset MBEDTLS_NET_C || true
  57. scripts/config.pl unset MBEDTLS_TIMING_C || true
  58. scripts/config.pl unset MBEDTLS_FS_IO || true
  59. scripts/config.pl --force set MBEDTLS_NO_PLATFORM_ENTROPY || true
  60. } >/dev/null 2>&1
  61. make clean >/dev/null
  62. CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld \
  63. CFLAGS="$ARMGCC_FLAGS" make lib >/dev/null
  64. OUT="size-${NAME}.txt"
  65. arm-none-eabi-size -t library/libmbed*.a > "$OUT"
  66. log "$( head -n1 "$OUT" )"
  67. log "$( tail -n1 "$OUT" )"
  68. cp ${CONFIG_H}.bak $CONFIG_H
  69. }
  70. # truncate the file just this time
  71. echo "(generated by $0)" > "$OUTFILE"
  72. echo "" >> "$OUTFILE"
  73. log "Footprint of standard configurations (minus net_sockets.c, timing.c, fs_io)"
  74. log "for bare-metal ARM Cortex-M3/M4 microcontrollers."
  75. VERSION_H="include/mbedtls/version.h"
  76. MBEDTLS_VERSION=$( sed -n 's/.*VERSION_STRING *"\(.*\)"/\1/p' $VERSION_H )
  77. if git rev-parse HEAD >/dev/null; then
  78. GIT_HEAD=$( git rev-parse HEAD | head -c 10 )
  79. GIT_VERSION=" (git head: $GIT_HEAD)"
  80. else
  81. GIT_VERSION=""
  82. fi
  83. log ""
  84. log "mbed TLS $MBEDTLS_VERSION$GIT_VERSION"
  85. log "$( arm-none-eabi-gcc --version | head -n1 )"
  86. log "CFLAGS=$ARMGCC_FLAGS"
  87. # creates the yotta config
  88. yotta/create-module.sh >/dev/null
  89. doit default include/mbedtls/config.h
  90. doit yotta yotta/module/mbedtls/config.h
  91. doit thread configs/config-thread.h
  92. doit suite-b configs/config-suite-b.h
  93. doit psk configs/config-ccm-psk-tls1_2.h
  94. zip mbedtls-footprint.zip "$OUTFILE" size-*.txt >/dev/null