Remove battery_cutoff scripts.
The battery cutoff scripts have been moved to src/platform/factory/sh/cutoff.
BUG=chromium:577601
TEST=build_packages --board link; build_image factory_install --board link
Change-Id: Icbd8c35c97e271e043a5969eaffafcd62b9a0bbe
Reviewed-on: https://chromium-review.googlesource.com/410462
Commit-Ready: Hung-Te Lin <hungte@chromium.org>
Tested-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
diff --git a/battery_cutoff/battery_cutoff.sh b/battery_cutoff/battery_cutoff.sh
deleted file mode 100755
index e37f28d..0000000
--- a/battery_cutoff/battery_cutoff.sh
+++ /dev/null
@@ -1,227 +0,0 @@
-#!/bin/sh
-
-# Copyright 2015 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 controls battery power level and performs required battery
-# cutoff protection by sending commands to EC with ectool.
-
-SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
-
-DISPLAY_MESSAGE="${SCRIPT_DIR}/display_wipe_message.sh"
-
-# After calling display_wipe_message.sh to draw image with frecon, we must
-# redirect text output to tty1 to display information on the screen.
-TTY=/dev/tty1
-
-usage_help() {
- echo "Usage: $0
- [--method shutdown|reboot|battery_cutoff]
- [--check-ac connect_ac|remove_ac]
- [--min-battery-percent <minimum battery percentage>]
- [--max-battery-percent <maximum battery percentage>]
- [--min-battery-voltage <minimum battery voltage>]
- [--max-battery-voltage <maximum battery voltage>]"
-}
-
-reset_activate_date() {
- /usr/sbin/activate_date --clean
-}
-
-has_battery() {
- ( type ectool && ectool battery ) >/dev/null 2>&1
-}
-
-get_battery_percentage() {
- local full="" current=""
- full="$(ectool battery 2>/dev/null |
- awk '/Last full charge/ {print int($4)}')"
- current="$(ectool battery 2>/dev/null |
- awk '/Remaining capacity/ {print int($3)}')"
- echo $((current * 100 / full))
-}
-
-get_battery_voltage() {
- ectool battery 2>/dev/null | awk '/Present voltage/ {print int($3)}'
-}
-
-is_ac_present() {
- ectool battery | grep -q AC_PRESENT
-}
-
-require_ac() {
- if ! is_ac_present; then
- "${DISPLAY_MESSAGE}" "connect_ac"
- while ! is_ac_present; do
- sleep 0.5
- done
- fi
-}
-
-require_remove_ac() {
- if is_ac_present; then
- "${DISPLAY_MESSAGE}" "remove_ac"
- while is_ac_present; do
- sleep 0.5
- done
- fi
-}
-
-check_battery_value() {
- local min_battery_value="$1" max_battery_value="$2"
- local get_value_cmd="$3"
- local battery_value=""
- local prev_battery_value=""
-
- battery_value="$(${get_value_cmd})"
-
- if [ -n "$min_battery_value" ] &&
- [ "$battery_value" -lt "$min_battery_value" ]; then
- require_ac
- ${DISPLAY_MESSAGE} "charging"
-
- # Wait for battery to charge to min_battery_value
- prev_battery_value="-1"
- # Print a new line before and after showing battery info.
- echo ""
- while [ "$battery_value" -lt "$min_battery_value" ]; do
- # Only print battery info when it changes.
- if [ "$battery_value" -ne "$prev_battery_value" ]; then
- # Keep printing battery information in the same line.
- printf '\rcurrent: %s, target: %s' \
- "$battery_value" "$min_battery_value" >"${TTY}"
- prev_battery_value="$battery_value"
- fi
- sleep 1
- battery_value="$(${get_value_cmd})"
- done
- echo ""
- fi
-
- if [ -n "$max_battery_value" ] &&
- [ "$battery_value" -gt "$max_battery_value" ]; then
- require_remove_ac
- ${DISPLAY_MESSAGE} "discharging"
-
- # Wait for battery to discharge to max_battery_value
- prev_battery_value="-1"
- # Print a new line before and after showing battery info.
- echo ""
- while [ "$battery_value" -gt "$max_battery_value" ]; do
- # Only print battery info when it changes.
- if [ "$battery_value" -ne "$prev_battery_value" ]; then
- # Keep printing battery information in the same line.
- printf '\rcurrent: %s, target: %s' \
- "$battery_value" "$max_battery_value" >"${TTY}"
- prev_battery_value="$battery_value"
- fi
- sleep 1
- battery_value="$(${get_value_cmd})"
- done
- echo ""
- fi
-}
-
-check_ac_state() {
- local cutoff_ac_state="$1"
- if [ "$cutoff_ac_state" = "connect_ac" ]; then
- require_ac
- elif [ "$cutoff_ac_state" = "remove_ac" ]; then
- require_remove_ac
- fi
-}
-
-main() {
- local cutoff_method=""
- local cutoff_ac_state=""
- local min_battery_percent="" max_battery_percent=""
- local min_battery_voltage="" max_battery_voltage=""
-
- local key
- while [ $# -ge 1 ]
- do
- key="$1"
- case "$key" in
- "--method" )
- cutoff_method="$2"
- shift 2
- ;;
- "--check-ac" )
- cutoff_ac_state="$2"
- shift 2
- ;;
- "--min-battery-percent" )
- min_battery_percent="$2"
- shift 2
- ;;
- "--max-battery-percent" )
- max_battery_percent="$2"
- shift 2
- ;;
- "--min-battery-voltage" )
- min_battery_voltage="$2"
- shift 2
- ;;
- "--max-battery-voltage" )
- max_battery_voltage="$2"
- shift 2
- ;;
- * )
- usage_help
- exit 1
- ;;
- esac
- done
-
- reset_activate_date
-
- if has_battery; then
- # Needed by 'ectool battery'.
- mkdir -p /var/lib/power_manager
- modprobe i2c_dev
- if [ -n "$min_battery_percent" ] || [ -n "$max_battery_percent" ]; then
- check_battery_value "$min_battery_percent" "$max_battery_percent" \
- "get_battery_percentage"
- fi
- if [ -n "$min_battery_voltage" ] || [ -n "$max_battery_voltage" ]; then
- check_battery_value "$min_battery_voltage" "$max_battery_voltage" \
- "get_battery_voltage"
- fi
- fi
-
- # Ask operator to plug or unplug AC before doing cut off.
- check_ac_state "$cutoff_ac_state"
-
- $DISPLAY_MESSAGE "cutting_off"
-
- # TODO (shunhsingou): In bug
- # https://bugs.chromium.org/p/chromium/issues/detail?id=589677, small amount
- # of devices fail to do cut off in factory. This may be caused by unstable
- # ectool, or shutdown fail in the tmpfs. Here we add more retries for
- # solving this problem. Remove the retry when finding the root cause.
- for i in $(seq 5)
- do
- case "$cutoff_method" in
- "shutdown" )
- shutdown -h now
- ;;
- "reboot" )
- reboot
- ;;
- "battery_cutoff" )
- crossystem battery_cutoff_request=1 && sleep 3 && reboot
- ;;
- * )
- # By default we shutdown the device without doing anything.
- shutdown -h now
- esac
- sleep 15
- done
-
- $DISPLAY_MESSAGE "cutoff_failed"
- sleep 1d
- exit 1
-}
-
-main "$@"
diff --git a/battery_cutoff/display_wipe_message.sh b/battery_cutoff/display_wipe_message.sh
deleted file mode 100755
index 1c5449f..0000000
--- a/battery_cutoff/display_wipe_message.sh
+++ /dev/null
@@ -1,178 +0,0 @@
-#!/bin/sh
-
-# Copyright 2015 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.
-
-# Script used to show boot message.
-
-
-FONT_SIZE="60"
-FONT_COLOR="Green"
-
-# Temp message file for display_boot_message.
-MESSAGE_FILE="$(mktemp --tmpdir)"
-
-TTY=/dev/tty1
-
-on_exit() {
- rm -f "${MESSAGE_FILE}"
-}
-
-# Prints usage help for commands usage.
-usage_help() {
- echo "Usage: $0 mode
-
- connect_ac: Message for connecting AC.
-
- remove_ac: Message for removing AC.
-
- charging: Message when charging battery.
-
- discharging: Message when discharging battery.
-
- cutting_off: Message when running cut off commands.
-
- wipe: Message when wiping.
-
- wipe_failed: Message when wipe failed.
-
- cutoff_failed: Message when cut off failed.
-
- inform_shopfloor: Message when inform shopfloor.
-
- inform_shopfloor_failed: Message when inform shopfloor failed.
-"
-}
-
-prepare_message() {
- local message="
- <span font=\"Noto Sans UI ${FONT_SIZE}\"
- foreground=\"${FONT_COLOR}\">"
-
- printf "${message}\n"
- # Append messages with newline.
- for message in "$@"; do
- printf "${message}\n"
- done
- printf "</span>"
-}
-
-has_bin() {
- type "$1" >/dev/null 2>&1
-}
-
-display_message() {
- local short_message="$1"
- shift
-
- if has_bin frecon || has_bin ply-image && has_bin pango-view; then
- prepare_message "$@" >"${MESSAGE_FILE}"
- if [ "${SHOW_SPINNER}" = "true" ]; then
- SPINNER_INTERVAL=25 display_boot_message "show_spinner" "${MESSAGE_FILE}"
- else
- display_boot_message "show_file" "${MESSAGE_FILE}"
- fi
- elif has_bin figlet; then
- figlet "$short_message"
- else
- echo "$short_message"
- fi
-}
-
-mode_connect_ac() {
- (FONT_COLOR="Red" display_message "Connect AC" \
- "Please Connect AC Power" \
- "请连接AC电源")
-}
-
-mode_remove_ac() {
- (FONT_COLOR="Red" display_message "Remove AC" \
- "Please Remove AC Power" \
- "请移除AC电源")
-}
-
-mode_charging() {
- (SHOW_SPINNER="true" display_message "Charging" \
- "Charging Battery..." \
- "正在充电...")
-}
-
-mode_discharging() {
- (SHOW_SPINNER="true" display_message "Discharging" \
- "Discharging Battery..." \
- "正在放电...")
-}
-
-mode_cutting_off() {
- (SHOW_SPINNER="true" display_message "Cutting Off" \
- "Cutting Off Battery" \
- "Please wait..." \
- "切断电池电源中" \
- "请稍候...")
-}
-
-mode_cutoff_failed() {
- (FONT_COLOR="Red" && display_message "Cutoff Failed" \
- "Battery Cut-off Failed" \
- "Please contact factory team" \
- "无法切断电池电源" \
- "请联络RD")
-}
-
-mode_wipe() {
- (SHOW_SPINNER="true" display_message "Wiping" \
- "Factory Wiping In Progress" \
- "正在进行工厂清除程序")
-}
-
-mode_wipe_failed() {
- (FONT_COLOR="Red" display_message "Wiping Failed" \
- "Factory Wiping Failed" \
- "无法进行工厂清除程序" \
- "请联络RD")
-}
-
-mode_inform_shopfloor() {
- (SHOW_SPINNER="true" display_message "Inform Shopfloor" \
- "Inform Shopfloor In Progress" \
- "传送资料至Shopfloor")
-}
-
-mode_inform_shopfloor_failed() {
- (FONT_COLOR="Red" display_message "Inform Shopfloor Failed" \
- "无法传送资料至Shopfloor" \
- "请联络RD")
-}
-
-main() {
- if [ $# -lt 1 ]; then
- usage_help
- exit 1
- fi
- local mode="$1"
- shift
-
- case "${mode}" in
- "connect_ac" | "remove_ac" | "charging" | "discharging" | \
- "cutting_off" | "cutoff_failed" | "wipe" | "wipe_failed" | \
- "inform_shopfloor" | "inform_shopfloor_failed" )
- mode_"${mode}" "$@"
-
- # Light up the screen if possible.
- backlight_tool --set_brightness_percent=100 2>/dev/null || true
-
- # Hides cursor and prevents console from blanking after long inactivity.
- setterm -cursor off -blank 0 -powersave off -powerdown 0 2>/dev/null \
- >>"${TTY}" || true
-
- ;;
- * )
- usage_help
- exit 1
- ;;
- esac
-}
-
-trap on_exit EXIT
-main "$@"
diff --git a/battery_cutoff/generate_finalize_request.sh b/battery_cutoff/generate_finalize_request.sh
deleted file mode 100755
index 4f774d4..0000000
--- a/battery_cutoff/generate_finalize_request.sh
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/bin/sh
-
-# Copyright 2015 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 is used to generate the default XML/RPC request to be sent to
-# shopfloor server. It can be used after factory wiping (in-place wiping tmpfs)
-# or after factory reset (in factory reset shim) to inform shopfloor
-# the operation is completed.
-
-usage() {
- echo "Usage: $0 [factory_wipe|factory_reset]"
-}
-
-print_post_content() {
- echo "<?xml version='1.0'?>"
- echo "<methodCall>"
- echo "<methodName>$1</methodName>"
- echo "<params>"
-
- shift 1
-
- local var=""
- for var in "$@"
- do
- echo "<param><value><string>${var}</string></value></param>"
- done
-
- echo "</params>"
- echo "</methodCall>"
-}
-
-die_with_error_message() {
- echo "$@" >&2
- exit 1
-}
-
-main() {
- if [ "$#" -lt 1 ]; then
- usage
- exit 1
- fi
-
- local sn=""
- local method=""
-
- local post_type="$1"
- case "${post_type}" in
- factory_reset )
- method="FinalizeFQC"
- ;;
- factory_wipe )
- method="Finalize"
- ;;
- *)
- usage
- exit 1
- esac
-
- sn="$(vpd -g serial_number)"
- if [ -z "${sn}" ];then
- die_with_error_message "serial_number is not in ro vpd"
- fi
-
- print_post_content "${method}" "${sn}"
-}
-
-main "$@"
diff --git a/battery_cutoff/inform_shopfloor.sh b/battery_cutoff/inform_shopfloor.sh
deleted file mode 100755
index 0f0409a..0000000
--- a/battery_cutoff/inform_shopfloor.sh
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/bin/sh
-#
-# Copyright 2015 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 makes shopfloor call to inform shopfloor server. It can be used
-# after factory wiping (in-place wiping tmpfs) or after factory reset
-# (in factory reset shim) to inform shopfloor the operation is completed.
-
-SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
-DISPLAY_MESSAGE="${SCRIPT_DIR}/display_wipe_message.sh"
-
-# After calling display_wipe_message.sh to draw image with frecon, we must
-# redirect text output to tty1 to display information on the screen.
-TTY="/dev/tty1"
-
-GENERATE_FINALIZE_REQUEST="${SCRIPT_DIR}/generate_finalize_request.sh"
-
-POST_FILE="$(mktemp --tmpdir)"
-
-on_exit() {
- rm -f "${POST_FILE}"
-}
-
-die_with_error_message() {
- "${DISPLAY_MESSAGE}" "inform_shopfloor_failed"
-
- # In factory install shim, we need to reset tty1 to show message in currect
- # way.
- stty -F "${TTY}" sane
- echo "$@" > "${TTY}"
- # Stop here to show error message on the screen.
- read
-}
-
-usage_help() {
- echo "Usage: $0 SHOPFLOOR_URL <POST_FILE | factory_reset | factory_wipe>"
-}
-
-post_to_shopfloor() {
- local shopfloor_url="$1"
- local post_file="$2"
- local response=""
-
- while true; do
- echo "Sending data to shopfloor..." >"${TTY}"
- if response=$(wget -T 30 --tries 1 -q --header='Content-Type: text/xml' \
- --post-file="${post_file}" -O - "${shopfloor_url}"); then
- if ! echo "${response}" | grep -q "fault"; then
- return
- else
- echo "Shopfloor call failed with response ${response}" >"${TTY}"
- fi
- else
- echo "Cannot connect to server ${shopfloor_url}." >"${TTY}"
- fi
- echo "Retry in 10s..." >"${TTY}"
- sleep 10
- # Clear screen.
- printf "\033c" >"${TTY}"
- done
-}
-
-main() {
- if [ $# -ne 2 ]; then
- usage_help
- exit 1
- fi
-
- local shopfloor_url="$1"
-
- "${DISPLAY_MESSAGE}" "inform_shopfloor"
-
- case "$2" in
- factory_reset|factory_wipe )
- if ! "${GENERATE_FINALIZE_REQUEST}" "$2" >"${POST_FILE}"; then
- local err=""
- err="$(cat ${POST_FILE})"
- die_with_error_message "Failed to generate request: ${err}"
- fi
- post_to_shopfloor "${shopfloor_url}" "${POST_FILE}"
- ;;
- * )
- if [ -f "$2" ]; then
- wait_for_ethernet
- post_to_shopfloor "${shopfloor_url}" "$2"
- else
- usage_help
- exit 1
- fi
- ;;
- esac
-}
-
-trap on_exit EXIT
-main "$@"