Files
OpenCellular/tests/futility/test_sign_usbpd1.sh
Bill Richardson b5a439241f futility: add support for usbpd1 images
The USB Type-C chargers released with Samus ("Pixel (2015)") have
upgradable firmware. Those firmware images are currently signed
by some custom scripts. This adds support for those images to
futility, so that those custom scripts can be replaced.

Note that due to space considerations, the usbpd firmware images
don't have room for handy things like an FMAP or headers for the
signatures. Accordingly, all the normally variable factors (image
size, signature algorithms, etc.) are hard coded and the image
itself just looks like a bunch of random numbers. Because of
this:

1. There's no way to recognize this type of file, and nothing to
   display about it.

2. You have to give the "--type usbpd1" arg to the sign command.

3. I'm designating this file type "v1" because I hope that the
   firmware for any future adapters will be more readily
   identifiable.

BUG=chromium:231574
BRANCH=none
TEST=make runtests

This adds a new test that signs usbpd1 firmware images using
futility, and compares the result to the same files signed by the
custom scripts, ensuring that they are bitwise identical.

Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Change-Id: Idbe061db5b3c8e474ada47b40bcbe04bbecdba3a
Reviewed-on: https://chromium-review.googlesource.com/262899
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-03-31 06:30:36 +00:00

57 lines
1.4 KiB
Bash
Executable File

#!/bin/bash -eux
# Copyright 2015 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.
me=${0##*/}
TMP="$me.tmp"
# Work in scratch directory
cd "$OUTDIR"
# The signed input images are signed with dev keys. We resign the unsigned
# images with the same keypair, to make sure that we're producing identical
# binaries.
DATADIR="${SCRIPTDIR}/data"
TESTS="dingdong hoho minimuffin zinger"
set -o pipefail
count=0
for test in $TESTS; do
: $(( count++ ))
echo -n "$count " 1>&3
pemfile=${DATADIR}/${test}.pem
infile=${DATADIR}/${test}.unsigned
goodfile=${DATADIR}/${test}.signed
outfile=${TMP}.${test}.new
# Signing the whole thing with futility should produce identical results
${FUTILITY} sign --type usbpd1 --pem ${pemfile} ${infile} ${outfile}
cmp ${goodfile} ${outfile}
# Now try signing just the RW part
size=$(stat -c '%s' ${infile})
half=$(( size / 2 ))
newin=${TMP}.${test}.rw_in
dd if=${infile} bs=${half} count=1 skip=1 of=${newin}
newgood=${TMP}.${test}.rw_ok
dd if=${goodfile} bs=${half} count=1 skip=1 of=${newgood}
newout=${TMP}.${test}.rw_out
# Sign the RW part alone
${FUTILITY} sign --type usbpd1 --pem ${pemfile} \
--ro_size 0 \
${newin} ${newout}
cmp ${newgood} ${newout}
done
# cleanup
rm -rf ${TMP}*
exit 0