summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@google.com>2021-11-22 18:46:01 -0800
committerCommit Bot <commit-bot@chromium.org>2021-12-22 03:00:56 +0000
commit6c404e61aec45ed053da8ce5b44dc2c13eff00a3 (patch)
tree07dab52be457d4cddc91b7bfb57ebb92bfcb0ce2
parent9865030f6d32bcf86310d50592f7ab1b36395817 (diff)
downloadchrome-ec-6c404e61aec45ed053da8ce5b44dc2c13eff00a3.tar.gz
bcmp.sh: script for comparing Cr50 code branches
The script builds a Cr50 image from scratch, then by examining the contents of builed/cr50/RW the script figures out the source files which were used to build the image and then compares all source files with a different git branch. The branch to compare with by default is cros/firmware-cr50-stab-14294.B, if the user wants to compare to a different branch, the name of the branch can be passed as command line parameter. The Cr50 tree branch names in firmware branches are modified by addition of the '-cr50_stab' suffix, the script tries adding the suffix if the branch to compare to does not exist in the Cr50 tree. Two git trees are examined, Cr50 and tpm2. If the other branch does not exist in either of the trees or building Cr50 image fails, the script reports error and exits. The result of running the script is a set of git diffs for files which are different between branches. BUG=b:200823466 TEST=ran the script to compare ToT and pre-pvt Cr50 branches, observed sensible results. Signed-off-by: Vadim Bendebury <vbendeb@google.com> Change-Id: Ic044c2d23758eed1a5573385e903e59ed4328635 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3297446 Tested-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
-rwxr-xr-xutil/bcmp.sh122
1 files changed, 122 insertions, 0 deletions
diff --git a/util/bcmp.sh b/util/bcmp.sh
new file mode 100755
index 0000000000..81dede5582
--- /dev/null
+++ b/util/bcmp.sh
@@ -0,0 +1,122 @@
+#!/bin/bash
+#
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# 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.
+
+tmpf="/tmp/bcmp.$$"
+trap '{ rm -f "${tmpf}" ; }' EXIT
+default_compare_to="cros/firmware-cr50-stab-14294.B"
+
+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}"; then
+ echo "Branch ${compare_to} not found in ${tpm2_dir}" >&2
+ exit 1
+fi
+
+cr50_compare_to="${compare_to}"
+if ! branch_exists "${cr50_dir}" "${cr50_compare_to}"; then
+ # This could be a new branch with mangled name.
+ cr50_compare_to="${cr50_compare_to}-cr50_stab"
+ if ! branch_exists "${cr50_dir}" "${cr50_compare_to}"; then
+ echo "Branch ${compare_to} not found in ${cr50_dir}" >&2
+ exit 1
+ fi
+fi
+
+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="${cr50_compare_to}"
+ else
+ branch="${compare_to}"
+ # 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