blob: 6727160f761d6f532b24887cad666a07ecf06979 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
#!/bin/bash
#
# Copyright 2021 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# compare local tree Cr50 source files with a different git branch.
#
# This script is supposed to run in a Cr50 source tree. The script will remove
# and rebuild Cr50 image, then scan the .o and .d files in the build directory
# to figure out all *.[cSh] files used to build the image.
#
# Once the list of files is created, all files' contents are compared with a
# different git branch. By default the other branch is
# cros/firmware-cr50-9308.B, it can be changed as a command line argument
# passed to this script.
#
# Usage
# ./bcmp.sh [mp|prepvt|tot]
tmpf="/tmp/bcmp.$$"
trap '{ rm -f "${tmpf}" ; }' EXIT
branch_name="${1}"
if [ "${branch_name}" == "mp" ] ; then
compare_to_tpm2="cros/firmware-cr50-stab-mp-14300.B"
compare_to_cr50="${compare_to_tpm2}-cr50_stab"
elif [ "${branch_name}" == "prepvt" ] ; then
compare_to_tpm2="cros/firmware-cr50-stab-14294.B"
compare_to_cr50="${compare_to_tpm2}-cr50_stab"
elif [ "${branch_name}" == "tot" ] ; then
compare_to_tpm2="cros/main"
compare_to_cr50="cros/cr50_stab"
else
echo "specify tot, mp, or prepvt branch"
exit 1
fi
find_src_file() {
local f="$1"
local log="$2"
if [[ -f ${f} ]]; then
echo "${cr50_dir} ${f}" >> "${log}"
return
fi
g="${f/\.c/.S}"
if [[ "${g}" != "${f}" ]]; then
# Could be an assembler source file.
if [[ -f ${g} ]]; then
echo "${cr50_dir} ${g}" >> "${log}"
return
fi
fi
g="${f#board/cr50/}"
if [[ -f ${tpm2_dir}/${g} ]]; then
echo "${tpm2_dir} ${f}" >> "${log}"
return
fi
case "${f}" in
(*dcrypto/fips_module* | *linkedtpm2*) ;;
(*) echo "neither ${f} nor ${g} found in the trees" >&2
esac
}
branch_exists() {
local tree="$1"
local branch="$2"
git -C "${tree}" show-branch "${branch}" > /dev/null 2>&1
}
if [[ ! -f Makefile.rules || ! -f board/cr50/board.h ]]; then
echo "this script must run in the root ec directory" >&2
exit 1
fi
if [[ "$#" != 0 ]]; then
compare_to="$1"
else
compare_to="${default_compare_to}"
fi
cr50_dir="$(pwd)"
tpm2_dir="$(readlink -f ../../third_party/tpm2/)"
if ! branch_exists "${tpm2_dir}" "${compare_to_tpm2}"; then
echo "Branch ${compare_to_tpm2} not found in ${tpm2_dir}" >&2
exit 1
fi
if ! branch_exists "${cr50_dir}" "${compare_to_cr50}"; then
echo "Branch ${compare_to_cr50} not found in platform/cr50" >&2
exit 1
fi
echo "cr50_branch: ${compare_to_cr50}"
echo "tpm2_branch: ${compare_to_tpm2}"
echo "Will rebuild CR50"
if ! make BOARD=cr50 -j > /dev/null ; then
echo "building cr50 failed" >&2
exit 1
fi
echo "Now checking .c and .S files"
for f in $(find build/cr50/RW/ -name '*.o' |
sed 's|build/cr50/RW/||;s/\.o/.c/'); do
find_src_file "${f}" "${tmpf}"
done
echo "Now checking .h files"
for f in $(find build/cr50/RW/ -name '*.d' -exec cat {} + |
sed 's/ /\n/g' |
sed 's^/mnt/host/source/src/platform/\(ec\|cr50\)/^^' |
sed 's^/mnt/host/source/src/third_party/tpm2/^^' |
sed 's/:$//'|
sort -u |
grep '\.h$' ); do
find_src_file "${f}" "${tmpf}"
done
sort "${tmpf}" | while read -r dir file; do
if [[ ${dir} == */cr50 ]]; then
branch="${compare_to_cr50}"
else
branch="${compare_to_tpm2}"
# TPM2 .o files are placed in board/cr50 in the build directory. Strip the
# prefix so that the matching .c file can be found in the TPM2 root.
file="${file#board/cr50/}"
fi
if ! git -C "${dir}" diff "${branch}" "${file}" 2>/dev/null; then
echo "Problems comparing ${file}, does it exist in ${branch} in ${dir}?" >&2
fi
done
|