1#!/bin/bash 2# 3# Copyright 2024 The ChromiumOS Authors 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6# 7# Tests for swap_ec_rw. 8 9# Load common constants and variables. 10. "$(dirname "$0")/common.sh" 11 12set -e 13 14ME=${0##*/} 15TMPD="${TEST_DIR}/${ME}" 16mkdir -p "${TMPD}" 17TMP="${TMPD}/image.bin" 18 19SWAP="${SRCDIR:?}/scripts/image_signing/swap_ec_rw" 20DATA="${SRCDIR:?}/tests/swap_ec_rw_data" 21 22# Intentionally use AP and EC images from different boards 23AP_IMAGE="${DATA}/bios_geralt.bin" 24EC_IMAGE="${DATA}/ec_krabby.bin" 25 26echo "Testing swap_ec_rw..." 27 28# Missing -e or --ec 29cp -f "${AP_IMAGE}" "${TMP}" 30if "${SWAP}" -i "${TMP}"; then false; fi 31 32# Good case: no ecrw.version 33cp -f "${AP_IMAGE}" "${TMP}" 34"${SWAP}" -i "${TMP}" -e "${EC_IMAGE}" 35cmp "${TMP}" "${DATA}/bios.expect.bin" 36 37# Good case: swap ecrw.version 38cp -f "${AP_IMAGE}" "${TMP}" 39cbfstool "${TMP}" extract -r "FW_MAIN_A" -n ecrw.version -f "${TMPD}/v.old" 40"${SWAP}" -i "${TMP}" -e "${EC_IMAGE}" 41cbfstool "${TMP}" extract -r "FW_MAIN_A" -n ecrw.version -f "${TMPD}/v.new" 42cmp -s "${TMPD}/v.old" "${TMPD}/v.new" && error "ecrw.version was not modified" 43 44# Cleanup 45rm -rf "${TMPD}" 46exit 0 47