Candy: remove 'ply-image' and use 'display_message' for Freon
'ply-image' is no longer supported in Freon-based images.
Switch to 'display_message' to display wiping message
BUG=chrome-os-partner: 42066
TEST=Factory wipe and battery cutoff, check the output message.
Change-Id: Ic26e867af7f24aa8dafa6dbfddd9740885f02885
Reviewed-on: https://chromium-review.googlesource.com/289432
Reviewed-by: Bowgo Tsai <bowgotsai@chromium.org>
Commit-Queue: Nicole Li <nicole.li@intel.com>
Tested-by: Nicole Li <nicole.li@intel.com>
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/chromeos-bsp-candy-0.0.1-r9.ebuild b/overlay-candy/chromeos-base/chromeos-bsp-candy/chromeos-bsp-candy-0.0.1-r9.ebuild
new file mode 120000
index 0000000..ba96521
--- /dev/null
+++ b/overlay-candy/chromeos-base/chromeos-bsp-candy/chromeos-bsp-candy-0.0.1-r9.ebuild
@@ -0,0 +1 @@
+chromeos-bsp-candy-0.0.1.ebuild
\ No newline at end of file
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/chromeos-bsp-candy-0.0.1.ebuild b/overlay-candy/chromeos-base/chromeos-bsp-candy/chromeos-bsp-candy-0.0.1.ebuild
index 8ffa262..68fda3e 100644
--- a/overlay-candy/chromeos-base/chromeos-bsp-candy/chromeos-bsp-candy-0.0.1.ebuild
+++ b/overlay-candy/chromeos-base/chromeos-bsp-candy/chromeos-bsp-candy-0.0.1.ebuild
@@ -16,7 +16,6 @@
RDEPEND="
chromeos-base/ec-utils
sys-kernel/linux-firmware
- media-gfx/ply-image
"
DEPEND="${RDEPEND}"
S="${WORKDIR}"
@@ -29,20 +28,7 @@
doins "${FILESDIR}"/powerd_prefs/*
# Battery cut-off
- dosbin "${FILESDIR}/battery_cut_off.sh"
- dosbin "${FILESDIR}/board_factory_wipe.sh"
- dosbin "${FILESDIR}/board_factory_reset.sh"
- dosbin "${FILESDIR}/board_charge_battery.sh"
- dosbin "${FILESDIR}/board_discharge_battery.sh"
- dosbin "${FILESDIR}/rma_battery_cut_off.sh"
-
- insinto "/usr/share/factory/images"
- doins "${FILESDIR}/remove_ac.png"
- doins "${FILESDIR}/cutting_off.png"
- doins "${FILESDIR}/cutoff_failed.png"
- doins "${FILESDIR}/charging.png"
- doins "${FILESDIR}/connect_ac.png"
- doins "${FILESDIR}/discharging.png"
+ dosbin "${FILESDIR}"/*.sh
# Install Bluetooth ID override.
insinto "/etc/bluetooth"
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/battery_cut_off.sh b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/battery_cut_off.sh
index fb1ab2a..a5c5dc9 100755
--- a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/battery_cut_off.sh
+++ b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/battery_cut_off.sh
@@ -7,19 +7,12 @@
# This script uses ectool to send command to EC to cut off the battery power.
#
-IMG_PATH="/usr/share/factory/images"
-TTY="/dev/tty1"
+DISPLAY_MESSAGE="/usr/sbin/display_wipe_message.sh"
modprobe i2c_dev
if (ectool battery | grep -q AC_PRESENT); then
- if [ -e "${IMG_PATH}/remove_ac.png" ]; then
- ply-image --clear 0x000000 "${IMG_PATH}/remove_ac.png"
- else
- echo "============================================" >"$TTY"
- echo "========== Unplug AC adapter now. ==========" >"$TTY"
- echo "============================================" >"$TTY"
- echo "" >"$TTY"
- fi
+ "${DISPLAY_MESSAGE}" "remove_ac"
+
while (ectool battery | grep -q AC_PRESENT) ; do
sleep 0.5;
done
@@ -28,25 +21,11 @@
# Discharge battery to ensure battery capacity in desired range
/usr/sbin/board_discharge_battery.sh
-if [ -e "${IMG_PATH}/cutting_off.png" ]; then
- ply-image --clear 0x000000 "${IMG_PATH}/cutting_off.png"
-else
- echo "===============================================" >"$TTY"
- echo "==== Cutting off battery. Wait 10 seconds. ====" >"$TTY"
- echo "===============================================" >"$TTY"
-fi
+"${DISPLAY_MESSAGE}" "cutting_off"
ectool batterycutoff
sleep 15
-# Couldn't have reached here
-if [ -e "${IMG_PATH}/cutoff_failed.png" ]; then
- ply-image --clear 0x000000 "${IMG_PATH}/cutoff_failed.png"
-else
- echo "======================================" >"$TTY"
- echo "========== Cut off failed!! ==========" >"$TTY"
- echo "======================================" >"$TTY"
- echo "" >"$TTY"
-fi
+"${DISPLAY_MESSAGE}" "cutoff_failed"
sleep 1d
exit 1
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/board_charge_battery.sh b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/board_charge_battery.sh
index e50979a..76e8eb0 100755
--- a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/board_charge_battery.sh
+++ b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/board_charge_battery.sh
@@ -8,9 +8,8 @@
# it asks for AC power and waits for the battery to charge.
#
-IMG_PATH="/usr/share/factory/images"
MIN_LEVEL=40
-TTY="/dev/tty1"
+DISPLAY_MESSAGE="/usr/sbin/display_wipe_message.sh"
get_percentage() {
power_supply_info 2>/dev/null \
@@ -22,17 +21,15 @@
if [[ $(get_percentage) -le $MIN_LEVEL ]]; then
# Ask for AC power
if [ -z "$(ectool battery | grep AC_PRESENT)" ]; then
- ply-image --clear 0x000000 "${IMG_PATH}/connect_ac.png"
+ "${DISPLAY_MESSAGE}" "connect_ac"
while [ -z "$(ectool battery | grep AC_PRESENT)" ]; do
sleep 0.5;
done
fi
# Wait for battery to charge to MIN_LEVEL
- ply-image --clear 0x000000 "${IMG_PATH}/charging.png"
while [[ $(get_percentage) -le $MIN_LEVEL ]]; do
- printf "\033[0;0H\033[K" >"$TTY"
- echo -n "Current Battery Level: $(get_percentage)%" >"$TTY"
+ "${DISPLAY_MESSAGE}" "charging" "$(get_percentage)" "${MIN_LEVEL}"
sleep 1
done
fi
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/board_discharge_battery.sh b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/board_discharge_battery.sh
index e9ab840..b9bae48 100755
--- a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/board_discharge_battery.sh
+++ b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/board_discharge_battery.sh
@@ -8,9 +8,8 @@
# it asks for AC power and waits for the battery to charge.
#
-IMG_PATH="/usr/share/factory/images"
MAX_LEVEL=60
-TTY="/dev/tty1"
+DISPLAY_MESSAGE="/usr/sbin/display_wipe_message.sh"
get_percentage() {
power_supply_info 2>/dev/null \
@@ -24,14 +23,7 @@
if (ectool battery | grep -q AC_PRESENT); then
# If WP enabled, unplugging AC is the only way to discharge.
if (crossystem sw_wpsw_boot?1 wpsw_boot?1); then
- if [ -e "${IMG_PATH}/remove_ac.png" ]; then
- ply-image --clear 0x000000 "${IMG_PATH}/remove_ac.png"
- else
- echo "============================================" >"$TTY"
- echo "========== Unplug AC adapter now. ==========" >"$TTY"
- echo "============================================" >"$TTY"
- echo "" >"$TTY"
- fi
+ "${DISPLAY_MESSAGE}" "remove_ac"
while (ectool battery | grep -q AC_PRESENT) ; do
sleep 0.5;
done
@@ -40,19 +32,9 @@
fi
fi
- if [ -e "${IMG_PATH}/discharging.png" ]; then
- ply-image --clear 0x000000 "${IMG_PATH}/discharging.png"
- else
- echo "============================================" >"$TTY"
- echo "================ Discharging ===============" >"$TTY"
- echo "============================================" >"$TTY"
- echo "" >"$TTY"
- fi
-
# Wait for battery to discharge to MAX_LEVEL.
while [[ $(get_percentage) -gt $MAX_LEVEL ]]; do
- printf "\033[0;0H\033[K" >"$TTY"
- echo -n "Current Battery Level: $(get_percentage)%" >"$TTY"
+ "${DISPLAY_MESSAGE}" "discharging" "$(get_percentage)" "${MAX_LEVEL}"
sleep 1
done
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/charging.png b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/charging.png
deleted file mode 100644
index e5d5aa7..0000000
--- a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/charging.png
+++ /dev/null
Binary files differ
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/connect_ac.png b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/connect_ac.png
deleted file mode 100644
index a62f555..0000000
--- a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/connect_ac.png
+++ /dev/null
Binary files differ
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/cutoff_failed.png b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/cutoff_failed.png
deleted file mode 100644
index 15386c1..0000000
--- a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/cutoff_failed.png
+++ /dev/null
Binary files differ
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/cutting_off.png b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/cutting_off.png
deleted file mode 100644
index cd2e09c..0000000
--- a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/cutting_off.png
+++ /dev/null
Binary files differ
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/discharging.png b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/discharging.png
deleted file mode 100644
index 5969704..0000000
--- a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/discharging.png
+++ /dev/null
Binary files differ
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/display_wipe_message.sh b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/display_wipe_message.sh
new file mode 100755
index 0000000..198b01d
--- /dev/null
+++ b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/display_wipe_message.sh
@@ -0,0 +1,125 @@
+#!/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)"
+
+on_exit() {
+ rm -f "${MESSAGE_FILE}"
+}
+
+# Prints usage help for commands usage.
+usage_help() {
+ echo "Usage: $0 mode [arg ...]
+
+ connect_ac: Message for connecting AC.
+
+ remove_ac: Message for removing AC.
+
+ charging: Message when charging battery.
+ Arg #1: the current battery level.
+ Arg #2: the minimum battery level to charge.
+
+ discharging: Message when discharging battery.
+ Arg #1: the current battery level.
+ Arg #2: the maximum battery level to discharge.
+
+ cutting_off: Message when running cut off commands.
+
+ cutoff_failed: Message when cut off 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>"
+}
+
+display_message() {
+ prepare_message "$@" >"${MESSAGE_FILE}"
+ display_boot_message "show_file" "${MESSAGE_FILE}"
+}
+
+mode_connect_ac() {
+ (FONT_COLOR="Red" && display_message "Battery level too low" \
+ "Please connect AC power" \
+ "电池电量过低" \
+ "请连接AC电源")
+}
+
+mode_remove_ac() {
+ (FONT_COLOR="Red" && display_message "Please remove AC power" \
+ "请移除AC电源")
+}
+
+mode_charging() {
+ local current_level="$1"
+ local min_level="$2"
+
+ display_message "Charging battery to ${min_level}%%..." \
+ "Current level: ${current_level}%%" \
+ "正在充电至${min_level}%%..." \
+ "当前电量:${current_level}%%"
+}
+
+mode_discharging() {
+ local current_level="$1"
+ local max_level="$2"
+
+ display_message "Discharging battery to ${max_level}%%..." \
+ "Current level: ${current_level}%%" \
+ "正在放电至${max_level}%%..." \
+ "当前电量:${current_level}%%"
+}
+
+mode_cutting_off() {
+ display_message "Cutting off battery" \
+ "Please wait..." \
+ "切断电池电源中" \
+ "请稍候..."
+}
+
+mode_cutoff_failed() {
+ (FONT_COLOR="Red" && display_message "Battery cut-off failed" \
+ "Please contact factory team" \
+ "无法切断电池电源" \
+ "请联络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" )
+ mode_"${mode}" "$@"
+ ;;
+ * )
+ usage_help
+ exit 1
+ ;;
+ esac
+}
+
+trap on_exit EXIT
+main "$@"
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/images.yaml b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/images.yaml
deleted file mode 100644
index d92d82f..0000000
--- a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/images.yaml
+++ /dev/null
@@ -1,20 +0,0 @@
-- image: cutoff_failed.png
- text: Battery cut-off failed\nContact factory team\n无法切断电池电源\n请联络RD
- fg_color: '#ff0000'
- font_size: 60
-- image: cutting_off.png
- text: Cutting off battery.\nPlease wait...\n切断电池电源中\n请稍候...
- fg_color: '#ffffff'
- font_size: 60
-- image: remove_ac.png
- text: Please remove AC power\nfor battery cut-off\n请移除AC电源
- fg_color: '#ffff00'
- font_size: 60
-- image: connect_ac.png
- text: Battery level too low.\nPlease connect AC power.\n电池电量过低\n请连接AC电源
- fg_color: '#ffff00'
- font_size: 60
-- image: charging.png
- text: Charging battery to 40%...\n正在充电...(目标40%)
- fg_color: '#ffffff'
- font_size: 60
diff --git a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/remove_ac.png b/overlay-candy/chromeos-base/chromeos-bsp-candy/files/remove_ac.png
deleted file mode 100644
index 18ba4ea..0000000
--- a/overlay-candy/chromeos-base/chromeos-bsp-candy/files/remove_ac.png
+++ /dev/null
Binary files differ