blob: e44158d1e6808dda007f3a352d8d1a3aa9cb0026 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/bin/bash
#
# Copyright 2012 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# This script can change GBB flags in system flash or a file.
# This script calls `futility gbb --set`, consider using that directly.
SCRIPT_BASE="$(dirname "$0")"
. "${SCRIPT_BASE}/gbb_flags_common.sh"
# DEFINE_string name default_value description flag
DEFINE_string file "" "Path to firmware image. Default to system firmware." "f"
DEFINE_boolean check_wp ${FLAGS_TRUE} "Check write protection states first." ""
DEFINE_string programmer "host" "Programmer to use when setting GBB flags" "p"
DEFINE_boolean servo "${FLAGS_FALSE}" "Determine programmer using servo" ""
set -e
# Check write protection
# ----------------------------------------------------------------------------
check_write_protection() {
local hw_wp="" sw_wp=""
local programmer="$1"
if [ "${programmer}" = "host" ] && ! crossystem "wpsw_cur?0"; then
hw_wp="on"
fi
# Keep 'local' declaration split from assignment so return code is checked.
local wp_states
wp_states="$(flashrom -p "${programmer}" --wp-status 2>/dev/null | grep WP)"
local wp_disabled="$(echo "${wp_states}" | grep "WP:.*is disabled.")"
local wp_zero_len="$(echo "${wp_states}" | grep "WP:.*, len=0x00000000")"
if [ -z "${wp_disabled}" -a -z "${wp_zero_len}" ]; then
sw_wp="on"
fi
if [ -n "${hw_wp}" -a -n "${sw_wp}" ]; then
return ${FLAGS_FALSE}
fi
return ${FLAGS_TRUE}
}
# Main
# ----------------------------------------------------------------------------
main() {
if [ "$#" != "1" ]; then
flags_help
exit 1
fi
echo 'NOTICE: This script has been replaced with futility functionality and will be removed.' 1>&2
echo 'NOTICE: Please try `futility gbb --set --flags=`' 1>&2
local value="$(($1))"
local args=()
if [ -n "${FLAGS_file}" ]; then
args+=("${FLAGS_file}")
elif [ "${FLAGS_servo}" = "${FLAGS_TRUE}" ]; then
args+=("--servo")
else
args+=("--flash" "--programmer=${FLAGS_programmer}")
if [ "${FLAGS_check_wp}" = "${FLAGS_TRUE}" ]; then
if ! check_write_protection "${FLAGS_programmer}"; then
echo ""
echo "WARNING: System GBB Flags are NOT changed!!!"
echo "ERROR: You must disable write protection before setting flags."
exit 1
fi
fi
fi
# Process file
# Keep 'local' declaration split from assignment so return code is checked.
local old_value
old_value="$(futility gbb --get --flags "${args[@]}" | grep "flags: ")"
printf "Setting GBB flags from %s to %#x\n" "${old_value}" "${value}"
futility gbb --set --flags="${value}" "${args[@]}"
}
# Parse command line
FLAGS "$@" || exit 1
eval set -- "$FLAGS_ARGV"
main "$@"
|