blob: dd6b36f73546efd231e69cb5c0c7a803f816bdc7 [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.
#
# This script processes exit values of the gsctool utility ran by
# cr50-update.conf. See it for details of exit code values.
description "Startup file to process cr50 firmware updater exit status"
author "chromium-os-dev@chromium.org"
start on stopped cr50-update
script
logit() {
logger -t ${UPSTART_JOB} "$*"
}
. /usr/share/misc/chromeos-common.sh
. /usr/sbin/write_gpt.sh
exit_status=0
# Check the device state with cr50-set-board-id to determine if board id
# should be set this boot. Only set board id when check_result runs
# successfully.
device_status="$(/usr/share/cros/cr50-set-board-id.sh 'check_device')" ||
exit_status="$?"
if [ "${exit_status}" = "0" ]; then
logit "Will check Board ID settings"
# Set flag to 'unknown' if board ID hasn't been set.
# Note that this flag should normally be set in the factory flow.
logit "$(/usr/share/cros/cr50-set-board-id.sh 'unknown')"
else
logit "skip setting board id: ${device_status}"
# If cr50-set-board-id exited with a status of 4, something is wrong with
# the device and cr50-result should skip the update reboot.
if [ "${exit_status}" = "4" ]; then
logit "skip reboot."
exit "{exit_status}"
fi
fi
# Check if rootfs is mounted on a removable device.
rootdev_removable() {
load_base_vars
local dst_drive="$(get_fixed_dst_drive)"
local root_drive="$(rootdev -s -d)"
if [ -z "${dst_drive}" ]; then
logit "no known device"
elif [ "${dst_drive}" != "${root_drive}" ]; then
logit "running on removable device ${dst_drive}, not ${root_drive}"
return 0
else
logit "running on disk ${root_drive}"
fi
return 1
}
case ${EXIT_STATUS} in
(0)
;;
(10[12])
if rootdev_removable; then
logit "rootfs on removable device, not rebooting"
else
logit "reboot required ${EXIT_STATUS}"
reboot
# Make sure this script does not continue running.
sleep 60
fi
;;
(*)
logit "unexpected cr50-update exit code ${EXIT_STATUS}"
;;
esac
end script