footprint.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/sh
  2. #
  3. # Copyright The Mbed TLS Contributors
  4. # SPDX-License-Identifier: Apache-2.0
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  7. # not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. # Purpose
  19. #
  20. # This script determines ROM size (or code size) for the standard mbed TLS
  21. # configurations, when built for a Cortex M3/M4 target.
  22. #
  23. # Configurations included:
  24. # default include/mbedtls/config.h
  25. # thread configs/config-thread.h
  26. # suite-b configs/config-suite-b.h
  27. # psk configs/config-ccm-psk-tls1_2.h
  28. #
  29. # Usage: footprint.sh
  30. #
  31. set -eu
  32. CONFIG_H='include/mbedtls/config.h'
  33. if [ -r $CONFIG_H ]; then :; else
  34. echo "$CONFIG_H not found" >&2
  35. echo "This script needs to be run from the root of" >&2
  36. echo "a git checkout or uncompressed tarball" >&2
  37. exit 1
  38. fi
  39. if grep -i cmake Makefile >/dev/null; then
  40. echo "Not compatible with CMake" >&2
  41. exit 1
  42. fi
  43. if which arm-none-eabi-gcc >/dev/null 2>&1; then :; else
  44. echo "You need the ARM-GCC toolchain in your path" >&2
  45. echo "See https://launchpad.net/gcc-arm-embedded/" >&2
  46. exit 1
  47. fi
  48. ARMGCC_FLAGS='-Os -march=armv7-m -mthumb'
  49. OUTFILE='00-footprint-summary.txt'
  50. log()
  51. {
  52. echo "$@"
  53. echo "$@" >> "$OUTFILE"
  54. }
  55. doit()
  56. {
  57. NAME="$1"
  58. FILE="$2"
  59. log ""
  60. log "$NAME ($FILE):"
  61. cp $CONFIG_H ${CONFIG_H}.bak
  62. if [ "$FILE" != $CONFIG_H ]; then
  63. cp "$FILE" $CONFIG_H
  64. fi
  65. {
  66. scripts/config.py unset MBEDTLS_NET_C || true
  67. scripts/config.py unset MBEDTLS_TIMING_C || true
  68. scripts/config.py unset MBEDTLS_FS_IO || true
  69. scripts/config.py --force set MBEDTLS_NO_PLATFORM_ENTROPY || true
  70. } >/dev/null 2>&1
  71. make clean >/dev/null
  72. CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld \
  73. CFLAGS="$ARMGCC_FLAGS" make lib >/dev/null
  74. OUT="size-${NAME}.txt"
  75. arm-none-eabi-size -t library/libmbed*.a > "$OUT"
  76. log "$( head -n1 "$OUT" )"
  77. log "$( tail -n1 "$OUT" )"
  78. cp ${CONFIG_H}.bak $CONFIG_H
  79. }
  80. # truncate the file just this time
  81. echo "(generated by $0)" > "$OUTFILE"
  82. echo "" >> "$OUTFILE"
  83. log "Footprint of standard configurations (minus net_sockets.c, timing.c, fs_io)"
  84. log "for bare-metal ARM Cortex-M3/M4 microcontrollers."
  85. VERSION_H="include/mbedtls/version.h"
  86. MBEDTLS_VERSION=$( sed -n 's/.*VERSION_STRING *"\(.*\)"/\1/p' $VERSION_H )
  87. if git rev-parse HEAD >/dev/null; then
  88. GIT_HEAD=$( git rev-parse HEAD | head -c 10 )
  89. GIT_VERSION=" (git head: $GIT_HEAD)"
  90. else
  91. GIT_VERSION=""
  92. fi
  93. log ""
  94. log "mbed TLS $MBEDTLS_VERSION$GIT_VERSION"
  95. log "$( arm-none-eabi-gcc --version | head -n1 )"
  96. log "CFLAGS=$ARMGCC_FLAGS"
  97. doit default include/mbedtls/config.h
  98. doit thread configs/config-thread.h
  99. doit suite-b configs/config-suite-b.h
  100. doit psk configs/config-ccm-psk-tls1_2.h
  101. zip mbedtls-footprint.zip "$OUTFILE" size-*.txt >/dev/null