init: factory_utils: add option 'tmpfs'

Mount tmpfs to /var/.  When booting from USB disk and run factory
toolkit, writing to /var/ slows down system performance dramatically.
Since there is no need to really write to stateful partition, using
option 'tmpfs' will mount tmpfs on /var, to improve performance
(especially when running tests like touchpad, touchscreen).

Also fix the path of option_file (/mnt/stateful_partition is not linked
to /usr/local/ when the function is called).

BUG=None
TEST=cros_workon-${BOARD} chromeos-test-init; build_image test

Change-Id: I9473261b26ac875bc35b370bbaae559df47bddc1
Reviewed-on: https://chromium-review.googlesource.com/1065755
Reviewed-by: Wei-Han Chen <stimim@chromium.org>
Commit-Queue: Wei-Han Chen <stimim@chromium.org>
Tested-by: Wei-Han Chen <stimim@chromium.org>
diff --git a/init/upstart/test-init/factory_utils.sh b/init/upstart/test-init/factory_utils.sh
index 308a75e..9aed5e6 100644
--- a/init/upstart/test-init/factory_utils.sh
+++ b/init/upstart/test-init/factory_utils.sh
@@ -2,10 +2,12 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+FACTORY_DIR="/mnt/stateful_partition/dev_image/factory"
+
 is_factory_test_mode() {
   # The path to factory enabled tag. If this path exists in a debug build,
   # we assume factory test mode.
-  local factory_tag_path="/mnt/stateful_partition/dev_image/factory/enabled"
+  local factory_tag_path="${FACTORY_DIR}/enabled"
   crossystem "debug_build?1" && [ -f "${factory_tag_path}" ]
 }
 
@@ -26,7 +28,7 @@
 
 # Overrides do_mount_var_and_home_chronos in chromeos_startup.
 do_mount_var_and_home_chronos() {
-  local option_file=/usr/local/factory/init/encstateful_mount_option
+  local option_file="${FACTORY_DIR}/init/encstateful_mount_option"
   local option=""
 
   if is_factory_mode; then
@@ -49,6 +51,15 @@
       # when we are confident of using unencrypted mode.
       mount_var_and_home_chronos "factory"
       ;;
+    tmpfs)
+      # Mount tmpfs to /var/.  When booting from USB disk, writing to /var/
+      # slows down system performance dramatically.  Since there is no need to
+      # really write to stateful partition, using option 'tmpfs' will mount
+      # tmpfs on /var to improve performance.  (especially when running tests
+      # like touchpad, touchscreen).
+      mount -n -t tmpfs tmpfs_var /var || return 1
+      mount -n --bind /mnt/stateful_partition/home/chronos /home/chronos
+      ;;
     *)
       mount_var_and_home_chronos
       ;;