blob: cdbc178e846cbfa43531151995370bbcadc38aff [file] [log] [blame]
# Copyright 2018 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.
#
# This script gathers information about Cr50 Board ID and flags and reports it
# appropriately.
start on started trunksd
script
status=0
# 'cros_config / brand-code' generates a 4 ASCII symbols RLZ brand code.
ascii_rlz="$(cros_config / brand-code)" || status="$?"
if [ "${status}" != 0 ] || [ "${#ascii_rlz}" != 4 ]; then
logger -t "${UPSTART_JOB}" \
"Error: cros_config returned ${status}."
exit 1
fi
# gsctool '-i' option generates output of the following format:
# Board ID space: <hex bid>:<inverted hex bid>:<hex flags>
bid_all="$(gsctool -a -i 2>&1)" || status="$?"
if [ "${status}" != 0 ]; then
logger -t "${UPSTART_JOB}" \
"Error: gsctool status $status, output \"${bid_all}\""
exit 1
fi
# Hex representation of values of interest.
rlz="$(printf "${ascii_rlz}" |
od -tx4 -An --endian=big | awk '{printf "0x"$1}')"
bid="$(printf "${bid_all}" | awk -F': *' '{print "0x"$2}')"
flags="$(printf "${bid_all}" | awk -F: '{printf "0x"$4}')"
# Always report the Cr50 board id type and flags.
metrics_client -s "Platform.Cr50.BoardIdFlags" "${flags}"
metrics_client -s "Platform.Cr50.BoardIdType" "${bid}"
if [ "${bid}" != "${rlz}" ]; then
# Misprogrammed Board ID/RLZ
metrics_client -s "Platform.Cr50.BoardIdOfRlzMismatch" "${bid}"
metrics_client -s "Platform.Cr50.RlzOfBoardIdMismatch" "${rlz}"
else
metrics_client -s "Platform.Cr50.MatchingBoardId" "${bid}"
fi
# Run the script to set up flash log time base and collect recent log
# entries, if any. This could fail if the currently running Cr50 version
# does not support flash log. Not a big deal, the message will be logged, we
# just ignore the issue here.
/usr/share/cros/cr50-flash-log.sh || true
logger -t "${UPSTART_JOB}" "Finished, flags ${flags}, RLZ ${rlz}, bid ${bid}"
end script