• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# Copyright 2019 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7set -e
8
9. $(dirname "$(readlink -f "${0}")")/common.sh
10
11test_read_from_flash_in_bootloader_mode_without_modifying_RDP_level() {
12  local file_read_from_flash="test.bin"
13  local original_fw_file="$1"
14
15  # Given:
16  #   * Hardware write protect is disabled
17  #   * Software write protect is disabled
18  #   * RDP is at level 0
19  #
20  # Then:
21  #   * Reading from flash without changing the RDP level should succeed
22  #     (we're already at level 0). Thus we should be able to read the entire
23  #     firmware out of flash and it should exactly match the firmware that we
24  #     flashed for testing.
25  echo "Reading firmware without modifying RDP level"
26  read_from_flash_in_bootloader_mode_without_modifying_RDP_level \
27    "${file_read_from_flash}"
28  if [[ $? -ne 0 ]]; then
29    echo "Failed to read firmware"
30    exit 1
31  fi
32
33  echo "Checking that value read matches the flashed version"
34  check_files_match "${file_read_from_flash}" "${original_fw_file}"
35
36  echo "Checking that firmware is still functional"
37  check_firmware_is_functional
38
39  rm -rf "${file_read_from_flash}"
40}
41
42test_read_from_flash_in_bootloader_mode_while_setting_RDP_to_level_0() {
43  local file_read_from_flash="test.bin"
44  local original_fw_file="$1"
45
46  # Given:
47  #   * Hardware write protect is disabled
48  #   * Software write protect is disabled
49  #   * RDP is at level 0
50  #
51  # Then:
52  #   * Changing the RDP level to 0 should have no effect (we're already at
53  #     level 0). Thus we should be able to read the entire firmware out of
54  #     flash and it should exactly match the firmware that we flashed for
55  #     testing.
56  echo "Reading firmware while setting RDP to level 0"
57  read_from_flash_in_bootloader_mode_while_setting_RDP_to_level_0 \
58    "${file_read_from_flash}"
59  if [[ $? -ne 0 ]]; then
60    echo "Failed to read firmware"
61    exit 1
62  fi
63
64  echo "Checking that value read matches the flashed version"
65  check_files_match "${file_read_from_flash}" "${original_fw_file}"
66
67  echo "Checking that firmware is still functional"
68  check_firmware_is_functional
69
70  rm -rf "${file_read_from_flash}"
71}
72
73echo "Running test to validate that we can read when RDP is set to level 0"
74
75readonly ORIGINAL_FW_FILE="$1"
76
77check_file_exists "${ORIGINAL_FW_FILE}"
78
79echo "Making sure all write protect is disabled"
80check_hw_and_sw_write_protect_disabled
81
82echo "Validating initial state"
83check_has_mp_rw_firmware
84check_has_mp_ro_firmware
85check_running_rw_firmware
86check_rollback_is_unset
87
88echo "Checking that firmware is functional"
89check_firmware_is_functional
90
91test_read_from_flash_in_bootloader_mode_without_modifying_RDP_level \
92  "${ORIGINAL_FW_FILE}"
93
94
95test_read_from_flash_in_bootloader_mode_while_setting_RDP_to_level_0 \
96  "${ORIGINAL_FW_FILE}"
97