blob: 8e3fcc21d14dd4a21372471d9a3041655ff06959 [file] [log] [blame]
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +02001#!/bin/sh
SimonBba9dd1e2016-04-03 15:06:52 +01002#
SimonBba9dd1e2016-04-03 15:06:52 +01003# Copyright (c) 2015-2016, ARM Limited, All Rights Reserved
Bence Szépkúti51b41d52020-05-26 01:54:15 +02004# 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# This file is part of Mbed TLS (https://tls.mbed.org)
SimonBba9dd1e2016-04-03 15:06:52 +010019#
20# Purpose
21#
22# This script determines ROM size (or code size) for the standard mbed TLS
23# configurations, when built for a Cortex M3/M4 target.
24#
25# Configurations included:
26# default include/mbedtls/config.h
SimonBba9dd1e2016-04-03 15:06:52 +010027# thread configs/config-thread.h
28# suite-b configs/config-suite-b.h
29# psk configs/config-ccm-psk-tls1_2.h
30#
31# Usage: footprint.sh
32#
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020033set -eu
34
35CONFIG_H='include/mbedtls/config.h'
36
37if [ -r $CONFIG_H ]; then :; else
38 echo "$CONFIG_H not found" >&2
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000039 echo "This script needs to be run from the root of" >&2
40 echo "a git checkout or uncompressed tarball" >&2
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020041 exit 1
42fi
43
44if grep -i cmake Makefile >/dev/null; then
45 echo "Not compatible with CMake" >&2
46 exit 1
47fi
48
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000049if which arm-none-eabi-gcc >/dev/null 2>&1; then :; else
50 echo "You need the ARM-GCC toolchain in your path" >&2
51 echo "See https://launchpad.net/gcc-arm-embedded/" >&2
52 exit 1
53fi
54
55ARMGCC_FLAGS='-Os -march=armv7-m -mthumb'
56OUTFILE='00-footprint-summary.txt'
57
58log()
59{
60 echo "$@"
61 echo "$@" >> "$OUTFILE"
62}
63
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020064doit()
65{
66 NAME="$1"
67 FILE="$2"
68
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000069 log ""
70 log "$NAME ($FILE):"
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020071
72 cp $CONFIG_H ${CONFIG_H}.bak
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000073 if [ "$FILE" != $CONFIG_H ]; then
74 cp "$FILE" $CONFIG_H
75 fi
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020076
77 {
78 scripts/config.pl unset MBEDTLS_NET_C || true
79 scripts/config.pl unset MBEDTLS_TIMING_C || true
80 scripts/config.pl unset MBEDTLS_FS_IO || true
SimonBba9dd1e2016-04-03 15:06:52 +010081 scripts/config.pl --force set MBEDTLS_NO_PLATFORM_ENTROPY || true
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020082 } >/dev/null 2>&1
83
Andres Amaya Garcia9a5398f2016-09-06 17:15:54 +010084 make clean >/dev/null
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020085 CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld \
Andres Amaya Garcia9a5398f2016-09-06 17:15:54 +010086 CFLAGS="$ARMGCC_FLAGS" make lib >/dev/null
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020087
88 OUT="size-${NAME}.txt"
89 arm-none-eabi-size -t library/libmbed*.a > "$OUT"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000090 log "$( head -n1 "$OUT" )"
91 log "$( tail -n1 "$OUT" )"
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020092
93 cp ${CONFIG_H}.bak $CONFIG_H
94}
95
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000096# truncate the file just this time
97echo "(generated by $0)" > "$OUTFILE"
98echo "" >> "$OUTFILE"
99
Andres AG788aa4a2016-09-14 14:32:09 +0100100log "Footprint of standard configurations (minus net_sockets.c, timing.c, fs_io)"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000101log "for bare-metal ARM Cortex-M3/M4 microcontrollers."
102
103VERSION_H="include/mbedtls/version.h"
104MBEDTLS_VERSION=$( sed -n 's/.*VERSION_STRING *"\(.*\)"/\1/p' $VERSION_H )
105if git rev-parse HEAD >/dev/null; then
106 GIT_HEAD=$( git rev-parse HEAD | head -c 10 )
Manuel Pégourié-Gonnard3134ef02015-11-25 10:50:27 +0000107 GIT_VERSION=" (git head: $GIT_HEAD)"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000108else
109 GIT_VERSION=""
110fi
111
112log ""
113log "mbed TLS $MBEDTLS_VERSION$GIT_VERSION"
114log "$( arm-none-eabi-gcc --version | head -n1 )"
115log "CFLAGS=$ARMGCC_FLAGS"
116
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000117doit default include/mbedtls/config.h
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +0200118doit thread configs/config-thread.h
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000119doit suite-b configs/config-suite-b.h
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +0200120doit psk configs/config-ccm-psk-tls1_2.h
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000121
122zip mbedtls-footprint.zip "$OUTFILE" size-*.txt >/dev/null