blob: 910afbc482345536e88882584c39298b56c52b71 [file] [log] [blame]
# Copyright 2016 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.
description "Report boot mode metrics"
author "chromium-os-dev@chromium.org"
start on started system-services
script
# Reads a boolean crossystem parameter and outputs a status value:
# 0: parameter value is false
# 1: parameter value is true
# 2: failed to determine value
get_crossystem_sample() {
local param="$1"
local value="$(crossystem "${param}")"
case "${value}" in
0|1)
echo "${value}"
;;
*)
echo "2"
;;
esac
}
# Report firmware write protect status.
metrics_client -e Platform.BootMode.WriteProtectSwitch \
$(get_crossystem_sample "wpsw_cur") 2
# Report dev switch status.
metrics_client -e Platform.BootMode.DevSwitch \
$(get_crossystem_sample "devsw_boot") 2
# Prints write protect status from flashrom to stdout:
# 0: write protect is disabled
# 1: write protect is enabled and range looks good
# 2: write protect is enabled but range looks bad
# 3: failed to determine status
get_wp_status_sample() {
local target="$1"
local flashrom_output="$(flashrom --wp-status -p "${target}")"
case "${flashrom_output}" in
*"WP: write protect is disabled"*)
echo "0"
;;
*"WP: write protect is enabled"*)
local range_len="$(echo "${flashrom_output}" |
grep "WP: write protect range:" |
grep -o "len=0x[[:xdigit:]]\+")"
if [ "$((${range_len#len=}))" -gt "0" ]; then
echo "1"
else
echo "2"
fi
;;
*)
echo "3"
;;
esac
}
# Report main firmware write protect status.
metrics_client -e Platform.BootMode.FirmwareWriteProtect.Main \
$(get_wp_status_sample "host") 3
# Report EC firmware write protect status.
metrics_client -e Platform.BootMode.FirmwareWriteProtect.EC \
$(get_wp_status_sample "ec") 3
# Report PD firmware write protect status.
metrics_client -e Platform.BootMode.FirmwareWriteProtect.PD \
$(get_wp_status_sample "ec:type=pd") 3
end script