CHERRYPICK: Battery cut-off should be executed after factory wipe/reset.
BUG=chrome-os-partner:25935
TEST=Factory wipe and check the battery is cut-off.
Factory reset and check the battery is cut-off
Original Change-Id: I760e08dc8320675757b9bbac88846697968816e3
Original Reviewed-on: https://chromium-review.googlesource.com/186948
Original Reviewed-by: Bernie Thompson <bhthompson@chromium.org>
Original Commit-Queue: Bowgo Tsai <bowgotsai@chromium.org>
Original Tested-by: Bowgo Tsai <bowgotsai@chromium.org>
Original Change-Id: If9784e92ee49414ffd30f974143abf7f2dc6d44d
Change-Id: Id66c0f4599a561bb61dfc319c71e06e4f6746d7f
Reviewed-on: https://chromium-review.googlesource.com/190408
Reviewed-by: Bowgo Tsai <bowgotsai@chromium.org>
Commit-Queue: Kevin Cheng <kevin.cheng@intel.com>
Tested-by: Kevin Cheng <kevin.cheng@intel.com>
diff --git a/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/chromeos-bsp-glimmer-0.0.1-r3.ebuild b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/chromeos-bsp-glimmer-0.0.1-r4.ebuild
similarity index 100%
rename from overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/chromeos-bsp-glimmer-0.0.1-r3.ebuild
rename to overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/chromeos-bsp-glimmer-0.0.1-r4.ebuild
diff --git a/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/chromeos-bsp-glimmer-0.0.1.ebuild b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/chromeos-bsp-glimmer-0.0.1.ebuild
index 02e84a7..9444521 100644
--- a/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/chromeos-bsp-glimmer-0.0.1.ebuild
+++ b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/chromeos-bsp-glimmer-0.0.1.ebuild
@@ -17,6 +17,7 @@
chromeos-base/ec-utils
pcserial? ( chromeos-base/serial-tty )
sys-kernel/linux-firmware
+ media-gfx/ply-image
"
DEPEND="${RDEPEND}"
@@ -24,4 +25,17 @@
src_install() {
doappid "{D0DBB0D9-6EEB-B148-F8AF-AE8AF86ECE5B}"
+
+ # 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"
+
+ 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"
}
diff --git a/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/battery_cut_off.sh b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/battery_cut_off.sh
new file mode 100755
index 0000000..3079dcf
--- /dev/null
+++ b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/battery_cut_off.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+#
+# Copyright (c) 2014 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"
+
+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
+ 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
+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
+
+sleep 1d
+exit 1
diff --git a/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/board_charge_battery.sh b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/board_charge_battery.sh
new file mode 100755
index 0000000..d6edd5a
--- /dev/null
+++ b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/board_charge_battery.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# Copyright (c) 2014 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 checks the battery level is high enough for shipping. If not,
+# it asks for AC power and waits for the battery to charge.
+#
+
+IMG_PATH="/usr/share/factory/images"
+MIN_LEVEL=40
+TTY="/dev/tty1"
+
+get_percentage() {
+ power_supply_info 2>/dev/null \
+ | awk '/percentage/ && !/display/ {print int($2)}'
+}
+
+mkdir -p /var/lib/power_manager
+
+if [[ $(get_percentage) -le $MIN_LEVEL ]]; then
+ # Ask for AC power
+ if [ -z "$(ectool battery | grep -q AC_PRESENT)" ]; then
+ ply-image --clear 0x000000 "${IMG_PATH}/connect_ac.png"
+ while [ -z "$(ectool battery | grep -q 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"
+ sleep 1
+ done
+fi
diff --git a/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/board_factory_reset.sh b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/board_factory_reset.sh
new file mode 100644
index 0000000..8e87f27
--- /dev/null
+++ b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/board_factory_reset.sh
@@ -0,0 +1,24 @@
+#!/bin/sh -e
+#
+# Copyright (c) 2014 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.
+#
+
+/usr/sbin/activate_date --clean
+# remove the cached vpd log file so that the next reboot will re-generate it
+# in /etc/init/vpd-log.conf.
+VPD_2_0="/var/log/vpd_2.0.txt"
+rm -f $VPD_2_0
+sync
+sleep 3
+
+/usr/sbin/board_charge_battery.sh
+
+/usr/sbin/battery_cut_off.sh
+
+# Battery cut-off is failed if it returns with 1.
+if [ $? -eq 1 ]; then
+ echo "Battery cut-off is failed."
+fi
+exit 1
diff --git a/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/board_factory_wipe.sh b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/board_factory_wipe.sh
new file mode 100644
index 0000000..79a0fc1
--- /dev/null
+++ b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/board_factory_wipe.sh
@@ -0,0 +1,25 @@
+#!/bin/sh -e
+#
+# Copyright (c) 2014 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.
+#
+
+/usr/sbin/activate_date --clean
+# make sure the cached vpd log file has been removed so that the the next reboot
+# will re-generate it in /etc/init/vpd-log.conf.
+VPD_2_0="/var/log/vpd_2.0.txt"
+rm -f $VPD_2_0
+sync
+sleep 3
+
+# this script is called by clobber-state
+/usr/sbin/battery_cut_off.sh
+
+# Battery cut-off is failed if it returns with 1.
+if [ $? -eq 1 ]; then
+ echo "Battery cut-off is failed."
+fi
+exit 1
+
+# reboot after return to clobber-state(default)
diff --git a/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/charging.png b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/charging.png
new file mode 100644
index 0000000..e5d5aa7
--- /dev/null
+++ b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/charging.png
Binary files differ
diff --git a/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/connect_ac.png b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/connect_ac.png
new file mode 100644
index 0000000..a62f555
--- /dev/null
+++ b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/connect_ac.png
Binary files differ
diff --git a/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/cutoff_failed.png b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/cutoff_failed.png
new file mode 100644
index 0000000..15386c1
--- /dev/null
+++ b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/cutoff_failed.png
Binary files differ
diff --git a/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/cutting_off.png b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/cutting_off.png
new file mode 100644
index 0000000..cd2e09c
--- /dev/null
+++ b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/cutting_off.png
Binary files differ
diff --git a/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/images.yaml b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/images.yaml
new file mode 100644
index 0000000..d92d82f
--- /dev/null
+++ b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/images.yaml
@@ -0,0 +1,20 @@
+- 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-glimmer/chromeos-base/chromeos-bsp-glimmer/files/remove_ac.png b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/remove_ac.png
new file mode 100644
index 0000000..18ba4ea
--- /dev/null
+++ b/overlay-glimmer/chromeos-base/chromeos-bsp-glimmer/files/remove_ac.png
Binary files differ