Gnawty+: Modify the way to show messages during wiping
Add some scripts to show messages when finishing finalization.
BUG=chrome-os-partner:47089
TEST=Factory wipe and battery cutoff, check the output messages.
Change-Id: I277ee6954c58607f6da38f062031f6c025e72f11
Reviewed-on: https://chromium-review.googlesource.com/310256
Commit-Ready: Ra Chang <Raya.Chang@quantatw.com>
Tested-by: Ra Chang <Raya.Chang@quantatw.com>
Reviewed-by: Bowgo Tsai <bowgotsai@chromium.org>
(cherry picked from commit 0d95f7797128bee39636d9b49c603b2f58b6f824)
Reviewed-on: https://chromium-review.googlesource.com/310604
Tested-by: Bowgo Tsai <bowgotsai@chromium.org>
Reviewed-by: Bernie Thompson <bhthompson@chromium.org>
Commit-Queue: Bernie Thompson <bhthompson@chromium.org>
diff --git a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/chromeos-bsp-gnawty-0.0.1-r8.ebuild b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/chromeos-bsp-gnawty-0.0.1-r9.ebuild
similarity index 100%
rename from overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/chromeos-bsp-gnawty-0.0.1-r8.ebuild
rename to overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/chromeos-bsp-gnawty-0.0.1-r9.ebuild
diff --git a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/chromeos-bsp-gnawty-0.0.1.ebuild b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/chromeos-bsp-gnawty-0.0.1.ebuild
index 3e26ec4..cd625e9 100644
--- a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/chromeos-bsp-gnawty-0.0.1.ebuild
+++ b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/chromeos-bsp-gnawty-0.0.1.ebuild
@@ -16,7 +16,6 @@
RDEPEND="
chromeos-base/ec-utils
sys-kernel/linux-firmware
- media-gfx/ply-image
"
DEPEND="${RDEPEND}"
@@ -32,13 +31,7 @@
dosbin "${FILESDIR}/board_factory_wipe.sh"
dosbin "${FILESDIR}/board_factory_reset.sh"
dosbin "${FILESDIR}/board_charge_battery.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"
+ dosbin "${FILESDIR}/display_wipe_message.sh"
# Install Bluetooth ID override.
insinto "/etc/bluetooth"
diff --git a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/battery_cut_off.sh b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/battery_cut_off.sh
index 3079dcf..780d140 100755
--- a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/battery_cut_off.sh
+++ b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/battery_cut_off.sh
@@ -1,49 +1,28 @@
#!/bin/bash
#
-# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+# 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 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
fi
-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-gnawty/chromeos-base/chromeos-bsp-gnawty/files/board_charge_battery.sh b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/board_charge_battery.sh
index e50979a..e2c0890 100755
--- a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/board_charge_battery.sh
+++ b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/board_charge_battery.sh
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+# 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.
#
@@ -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-gnawty/chromeos-base/chromeos-bsp-gnawty/files/charging.png b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/charging.png
deleted file mode 100644
index e5d5aa7..0000000
--- a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/charging.png
+++ /dev/null
Binary files differ
diff --git a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/connect_ac.png b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/connect_ac.png
deleted file mode 100644
index a62f555..0000000
--- a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/connect_ac.png
+++ /dev/null
Binary files differ
diff --git a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/cutoff_failed.png b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/cutoff_failed.png
deleted file mode 100644
index 15386c1..0000000
--- a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/cutoff_failed.png
+++ /dev/null
Binary files differ
diff --git a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/cutting_off.png b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/cutting_off.png
deleted file mode 100644
index cd2e09c..0000000
--- a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/cutting_off.png
+++ /dev/null
Binary files differ
diff --git a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/display_wipe_message.sh b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/display_wipe_message.sh
new file mode 100755
index 0000000..74774fe
--- /dev/null
+++ b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/display_wipe_message.sh
@@ -0,0 +1,111 @@
+#!/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.
+
+ 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_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" | "cutting_off" | "cutoff_failed" )
+ mode_"${mode}" "$@"
+ ;;
+ * )
+ usage_help
+ exit 1
+ ;;
+ esac
+}
+
+trap on_exit EXIT
+main "$@"
diff --git a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/images.yaml b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/images.yaml
deleted file mode 100644
index d92d82f..0000000
--- a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/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-gnawty/chromeos-base/chromeos-bsp-gnawty/files/remove_ac.png b/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/remove_ac.png
deleted file mode 100644
index 18ba4ea..0000000
--- a/overlay-gnawty/chromeos-base/chromeos-bsp-gnawty/files/remove_ac.png
+++ /dev/null
Binary files differ