blob: d8d79cb2584a276d3d89a4e0b9e1bf607694f727 [file] [log] [blame]
# Copyright 2017 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 "Hammer firmware updater task"
author "chromium-os-dev@chromium.org"
# When the hammer device is plugged, udev emits hammer-device-added signal.
# The example rule file: hammerd/udev/99-hammerd.rules.example
start on hammer-device-added
# If the device pairs correctly, expose hammer's sysfs path for other
# applications to use.
env WRITE_SYSFS_PATH="/run/hammer_sysfs_path"
# Arguments should be empty here and overridden at `hammerd.override`.
env EC_IMAGE_PATH=
env TOUCHPAD_IMAGE_PATH=
env VENDOR_ID=
env PRODUCT_ID=
env USB_BUS=
env USB_PORT=
env AUTOSUSPEND_DELAY_MS="-1"
# Set the argument to True when triggering at boot.
env AT_BOOT="false"
# The argument to determine the update condition.
# Valid values are "never", "mismatch", and "always".
env UPDATE_IF="never"
task
pre-start script
# Because the upstart job `boot-update-firmware` will force invoking hammerd
# once before UI is started, we need to make sure hammerd isn't invoked by
# udev before boot-update-firmware gets to run.
if [ "${UPSTART_EVENTS}" = 'hammer-device-added' ] && \
! initctl status boot-update-firmware | grep -q "start/running"; then
logger -t hammerd "boot-update-firmware hasn't started yet, ignore."
stop
fi
end script
# Trigger hammerd process.
# Note: minijail0 "-N" argument (cgroup namespace) is only supported on
# kernel >= 3.14. Remove if the hammerd runs on kernel < 3.14.
script
exit_status=0
/sbin/minijail0 -e -N -p -l -u hammerd -g hammerd -c 0002 \
/usr/bin/hammerd --ec_image_path="${EC_IMAGE_PATH}" \
--touchpad_image_path="${TOUCHPAD_IMAGE_PATH}" \
--vendor_id="${VENDOR_ID}" \
--product_id="${PRODUCT_ID}" \
--usb_bus="${USB_BUS}" \
--usb_port="${USB_PORT}" \
--autosuspend_delay_ms="${AUTOSUSPEND_DELAY_MS}" \
--at_boot="${AT_BOOT}" \
--update_if="${UPDATE_IF}" || exit_status="$?"
if [ "${exit_status}" -eq 0 ]; then
usb_device_path="/sys/bus/usb/devices/${USB_BUS}-${USB_PORT}"
if ! echo "${usb_device_path}" > "${WRITE_SYSFS_PATH}"; then
logger -t ${UPSTART_JOB} \
"FAILED to write into sysfs tag file: ${WRITE_SYSFS_PATH}"
exit 1 # Exit status for "unknown error" in hammerd.
fi
else
rm "${WRITE_SYSFS_PATH}" || true
fi
exit "${exit_status}"
end script