footprint.sh 2.7 KB

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