Raef Coles | b3d343b | 2020-12-08 09:31:43 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Jianliang Shen | 5375ddb | 2022-08-28 23:32:47 +0800 | [diff] [blame] | 2 | # Copyright (c) 2021-2022, Arm Limited. All rights reserved. |
Raef Coles | b3d343b | 2020-12-08 09:31:43 +0000 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | |
| 6 | |
| 7 | set_default AXF_FILE ${BUILD_DIR}/bin/tfm_s.axf |
| 8 | set_default OBJDUMP arm-none-eabi-objdump |
| 9 | set_default GDB gdb-multiarch |
| 10 | |
| 11 | if ! test -f ${AXF_FILE} |
| 12 | then |
| 13 | error "no such file ${AXF_FILE}" |
| 14 | fi |
| 15 | |
| 16 | # Check if the ELF file specified is compatible |
| 17 | if ! file ${AXF_FILE} | grep "ELF.*32.*ARM" &>/dev/null |
| 18 | then |
| 19 | error "Incompatible file: ${AXF_FILE}" |
| 20 | fi |
| 21 | |
| 22 | #TODO clean this up, and use less regex |
| 23 | |
| 24 | # Dump all objects that have a name containing FIH_LABEL |
| 25 | ADDRESSES=$($OBJDUMP $AXF_FILE -t | grep "FIH_LABEL") |
| 26 | # strip all data except "address, label_name" |
| 27 | ADDRESSES=$(echo "$ADDRESSES" | sed "s/\([[:xdigit:]]*\).*\(FIH_LABEL_.*\)_[0-9]*_[0-9]*/0x\1, \2/g") |
| 28 | # Sort by address in ascending order |
| 29 | ADDRESSES=$(echo "$ADDRESSES" | sort) |
| 30 | # In the case that there is a START followed by another START take the first one |
| 31 | ADDRESSES=$(echo "$ADDRESSES" | sed "N;s/\(.*START.*\)\n\(.*START.*\)/\1/;P;D") |
| 32 | # Same for END except take the second one |
| 33 | ADDRESSES=$(echo "$ADDRESSES" | sed "N;s/\(.*END.*\)\n\(.*END.*\)/\2/;P;D") |
| 34 | |
| 35 | # Output in CSV format with a label |
| 36 | echo "Address, Type" > ${BUILD_DIR}/fih_manifest.csv |
Jianliang Shen | 5375ddb | 2022-08-28 23:32:47 +0800 | [diff] [blame] | 37 | |
| 38 | # Dump all objects that have a name containing FUNCTION |
| 39 | if [ -n "$FUNCTION" ];then |
| 40 | if [ -n "$(echo "$ADDRESSES" | grep "$FUNCTION")" ];then |
| 41 | IFS_OLD=$IFS |
| 42 | IFS=$'\n' |
| 43 | next_line=0 |
| 44 | for line in $ADDRESSES; |
| 45 | do |
| 46 | if [ -n "$(echo "$line" | grep "CRITICAL_POINT")" ] || [ -n "$(echo "$line" | grep "FAILURE_LOOP")" ];then |
| 47 | echo "$line" >> ${BUILD_DIR}/fih_manifest.csv |
| 48 | continue |
| 49 | fi |
| 50 | if [ -n "$(echo "$line" | grep "$FUNCTION")" ];then |
| 51 | echo "$line" >> ${BUILD_DIR}/fih_manifest.csv |
| 52 | next_line=1 |
| 53 | continue |
| 54 | fi |
| 55 | if [ $next_line -eq 1 ];then |
| 56 | echo "$line" >> ${BUILD_DIR}/fih_manifest.csv |
| 57 | next_line=0 |
| 58 | fi |
| 59 | done |
| 60 | IFS=$IFS_OLD |
| 61 | else |
| 62 | echo "Function $FUNCTION is not found in TF-M!" |
| 63 | exit |
| 64 | fi |
| 65 | else |
| 66 | echo "$ADDRESSES" >> ${BUILD_DIR}/fih_manifest.csv |
| 67 | fi |