CHERRY-PICK: overlay-sentry: add initial overlay files for sentry

BUG=chrome-os-partner:48942
TEST=`setup_board --board=sentry and emerge-sentry chromeos-bsp-sentry`

Change-Id: Idab5ebd3b6218eef8a3619cdf87e6f9b2e47aa29
Signed-off-by: Grace Kao <grace.kao@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/320152
Reviewed-by: Kaiwen Gu <kaiwengu@chromium.org>
(cherry picked from commit 2a1f71214a74bb864f2261133757604208f87ab4)
Reviewed-on: https://chromium-review.googlesource.com/321918
Reviewed-by: Bowgo Tsai <bowgotsai@chromium.org>
Commit-Queue: Kitty Liu <kitty.liu@intel.com>
Tested-by: Kitty Liu <kitty.liu@intel.com>
diff --git a/overlay-sentry/chromeos-base/chromeos-bsp-sentry/chromeos-bsp-sentry-0.0.1-r1.ebuild b/overlay-sentry/chromeos-base/chromeos-bsp-sentry/chromeos-bsp-sentry-0.0.1-r1.ebuild
new file mode 120000
index 0000000..a2a64d0
--- /dev/null
+++ b/overlay-sentry/chromeos-base/chromeos-bsp-sentry/chromeos-bsp-sentry-0.0.1-r1.ebuild
@@ -0,0 +1 @@
+chromeos-bsp-sentry-0.0.1.ebuild
\ No newline at end of file
diff --git a/overlay-sentry/chromeos-base/chromeos-bsp-sentry/chromeos-bsp-sentry-0.0.1.ebuild b/overlay-sentry/chromeos-base/chromeos-bsp-sentry/chromeos-bsp-sentry-0.0.1.ebuild
new file mode 100644
index 0000000..a40138a
--- /dev/null
+++ b/overlay-sentry/chromeos-base/chromeos-bsp-sentry/chromeos-bsp-sentry-0.0.1.ebuild
@@ -0,0 +1,35 @@
+# Copyright 2015 The Chromium OS Authors. All rights reserved.
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=4
+
+inherit appid
+
+DESCRIPTION="Ebuild which pulls in any necessary ebuilds as dependencies
+or portage actions."
+
+LICENSE="BSD-Google"
+SLOT="0"
+KEYWORDS="-* amd64 x86"
+IUSE=""
+S="${WORKDIR}"
+
+# Add dependencies on other ebuilds from within this board overlay
+RDEPEND="
+	chromeos-base/chromeos-bsp-baseboard-kunimitsu
+	chromeos-base/ec-utils
+	sys-kernel/linux-firmware
+	media-gfx/ply-image
+"
+DEPEND="${RDEPEND}"
+
+src_install() {
+	doappid "{E020B8D4-CA96-4599-84DA-5017455418AE}" "CHROMEBOOK"
+
+	# Install platform specific config files for power_manager.
+	insinto "/usr/share/power_manager/board_specific"
+	doins "${FILESDIR}"/powerd_prefs/*
+
+	# Battery cut off and Wiping scripts.
+	dosbin "${FILESDIR}"/sbin/*.sh
+}
diff --git a/overlay-sentry/chromeos-base/chromeos-bsp-sentry/files/powerd_prefs/low_battery_shutdown_percent b/overlay-sentry/chromeos-base/chromeos-bsp-sentry/files/powerd_prefs/low_battery_shutdown_percent
new file mode 100644
index 0000000..5186d07
--- /dev/null
+++ b/overlay-sentry/chromeos-base/chromeos-bsp-sentry/files/powerd_prefs/low_battery_shutdown_percent
@@ -0,0 +1 @@
+4.0
diff --git a/overlay-sentry/chromeos-base/chromeos-bsp-sentry/files/sbin/battery_cut_off.sh b/overlay-sentry/chromeos-base/chromeos-bsp-sentry/files/sbin/battery_cut_off.sh
new file mode 100755
index 0000000..fe7a0f4
--- /dev/null
+++ b/overlay-sentry/chromeos-base/chromeos-bsp-sentry/files/sbin/battery_cut_off.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+# 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.
+#
+
+DISPLAY_MESSAGE="/usr/sbin/display_wipe_message.sh"
+modprobe i2c_dev
+
+if (ectool battery | grep -q AC_PRESENT); then
+  "${DISPLAY_MESSAGE}" "remove_ac"
+  while (ectool battery | grep -q AC_PRESENT) ; do
+    sleep 0.5;
+  done
+fi
+
+"${DISPLAY_MESSAGE}" "cutting_off"
+
+ectool batterycutoff at-shutdown
+shutdown -h now
+sleep 15
+
+"${DISPLAY_MESSAGE}" "cutoff_failed"
+
+sleep 1d
+exit 1
diff --git a/overlay-sentry/chromeos-base/chromeos-bsp-sentry/files/sbin/board_factory_wipe.sh b/overlay-sentry/chromeos-base/chromeos-bsp-sentry/files/sbin/board_factory_wipe.sh
new file mode 100644
index 0000000..139589d
--- /dev/null
+++ b/overlay-sentry/chromeos-base/chromeos-bsp-sentry/files/sbin/board_factory_wipe.sh
@@ -0,0 +1,36 @@
+#!/bin/sh -e
+#
+# 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.
+#
+
+/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
+for WIPE_OPTION in "$@"; do
+  if [ "$WIPE_OPTION" = "battery_cut_off" ]; then
+    # battery cut-off after factory wipe-out
+    /usr/sbin/battery_cut_off.sh
+  elif [ "$WIPE_OPTION" = "shutdown" ]; then
+    # shutdown after factory wipe-out
+    /sbin/shutdown -h now
+  elif [ "$WIPE_OPTION" = "reboot" ]; then
+    # reboot after factory wipe-out
+    /sbin/reboot
+  fi
+done
+
+# Board wiping is failed if it returns with 1.
+if [ $? -eq 1 ]; then
+    echo "Board wiping is failed."
+fi
+exit 1
+
+# reboot after return to clobber-state(default)
diff --git a/overlay-sentry/chromeos-base/chromeos-bsp-sentry/files/sbin/display_wipe_message.sh b/overlay-sentry/chromeos-base/chromeos-bsp-sentry/files/sbin/display_wipe_message.sh
new file mode 100755
index 0000000..74774fe
--- /dev/null
+++ b/overlay-sentry/chromeos-base/chromeos-bsp-sentry/files/sbin/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-sentry/make.conf b/overlay-sentry/make.conf
new file mode 100644
index 0000000..81f2eab
--- /dev/null
+++ b/overlay-sentry/make.conf
@@ -0,0 +1,14 @@
+# 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.
+
+USE="${USE} sentry"
+USE="${USE} cros_ec pd_sync"
+
+# All firmwares to build from the EC code base
+EC_FIRMWARE="sentry"
+EC_FIRMWARE_EXTRA="sentry_pd"
+PD_FIRMWARE="sentry_pd"
+
+# Uncomment this line to activate the serial port.
+#TTY_CONSOLE="${TTY_CONSOLE} ttyS0"
diff --git a/overlay-sentry/metadata/layout.conf b/overlay-sentry/metadata/layout.conf
new file mode 100644
index 0000000..49e82ca
--- /dev/null
+++ b/overlay-sentry/metadata/layout.conf
@@ -0,0 +1,6 @@
+masters = portage-stable chromiumos eclass-overlay baseboard-kunimitsu freon
+profile-formats = portage-2 profile-default-eapi
+profile_eapi_when_unspecified = 5-progress
+repo-name = sentry
+thin-manifests = true
+use-manifests = strict
diff --git a/overlay-sentry/profiles/base/parent b/overlay-sentry/profiles/base/parent
new file mode 100644
index 0000000..46619be
--- /dev/null
+++ b/overlay-sentry/profiles/base/parent
@@ -0,0 +1,3 @@
+chromiumos:default/linux/amd64/10.0/chromeos
+baseboard-kunimitsu:base
+freon:base/amd64
diff --git a/overlay-sentry/toolchain.conf b/overlay-sentry/toolchain.conf
new file mode 100644
index 0000000..6fc54f6
--- /dev/null
+++ b/overlay-sentry/toolchain.conf
@@ -0,0 +1,7 @@
+x86_64-cros-linux-gnu
+
+# This is needed to build the target firmware
+i686-pc-linux-gnu
+
+# This is needed to build the EC firmware
+arm-none-eabi
diff --git a/overlay-sentry/virtual/chromeos-bsp/chromeos-bsp-2.ebuild b/overlay-sentry/virtual/chromeos-bsp/chromeos-bsp-2.ebuild
new file mode 100644
index 0000000..20fbf17
--- /dev/null
+++ b/overlay-sentry/virtual/chromeos-bsp/chromeos-bsp-2.ebuild
@@ -0,0 +1,13 @@
+# Copyright 2015 The Chromium OS Authors. All rights reserved.
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=4
+
+DESCRIPTION="Chrome OS BSP virtual package"
+HOMEPAGE="http://src.chromium.org"
+
+LICENSE="BSD-Google"
+SLOT="0"
+KEYWORDS="-* amd64 x86"
+
+RDEPEND="chromeos-base/chromeos-bsp-sentry"