footprint.sh 4.2 KB

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