xref: /aosp_15_r20/external/vboot_reference/tests/futility/test_load_fmap.sh (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1#!/bin/bash -eux
2# Copyright 2014 The ChromiumOS Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6me=${0##*/}
7TMP="$me.tmp"
8
9# Work in scratch directory
10cd "$OUTDIR"
11
12
13IN="${SCRIPT_DIR}/futility/data/bios_link_mp.bin"
14BIOS="${TMP}.bios.bin"
15
16cp "${IN}" "${BIOS}"
17
18AREAS=(RW_SECTION_A VBLOCK_B BOOT_STUB)
19set -x
20# Extract good blobs first
21"${FUTILITY}" dump_fmap -x "${BIOS}" "${AREAS[@]}"
22
23# Save the good blobs, make same-size random blobs, create command
24CMDS=( )
25for a in "${AREAS[@]}"; do
26  size=$(stat -c '%s' "$a")
27  mv "$a" "$a.good"
28  dd if=/dev/urandom of="$a.rand" bs="$size" count=1
29  CMDS+=("$a:$a.rand")
30done
31
32# Poke the new blobs in
33"${FUTILITY}" load_fmap "${BIOS}" "${CMDS[@]}"
34
35# Pull them back out and see if they match
36"${FUTILITY}" dump_fmap -x "${BIOS}" "${AREAS[@]}"
37for a in "${AREAS[@]}"; do
38  cmp "$a" "$a.rand"
39done
40
41# File size smaller than area size
42cp -f "${IN}" "${BIOS}"
43"${FUTILITY}" dump_fmap -x "${BIOS}" VBLOCK_A
44cp -f VBLOCK_A VBLOCK_A.truncated
45truncate --size=-5 VBLOCK_A.truncated
46cp -f VBLOCK_A.truncated VBLOCK_A.new
47printf '\xFF%.s' {1..5} >> VBLOCK_A.new
48cmp -s VBLOCK_A.new VBLOCK_A && error "VBLOCK_A.new is the same as VBLOCK_A"
49"${FUTILITY}" load_fmap "${BIOS}" VBLOCK_A:VBLOCK_A.truncated
50"${FUTILITY}" dump_fmap -x "${BIOS}" VBLOCK_A:VBLOCK_A.readback
51cmp VBLOCK_A.readback VBLOCK_A.new
52
53# cleanup
54rm -f "${TMP}"* "${AREAS[@]}" ./*.rand ./*.good
55exit 0
56