blob: 4a769afac562f1d69c112cb87993b22153204738 [file] [log] [blame]
Wei-Han Chene97d3532016-03-31 19:22:01 +08001#!/usr/bin/env python
2# -*- coding: UTF-8 -*-
3# Copyright 2016 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
Joel Kitching679a00b2016-08-03 11:42:58 +08007"""Transition to release state directly without reboot."""
Wei-Han Chene97d3532016-03-31 19:22:01 +08008
Wei-Han Chenbe1355a2016-04-24 19:31:03 +08009import json
Wei-Han Chene97d3532016-03-31 19:22:01 +080010import logging
Wei-Han Chene97d3532016-03-31 19:22:01 +080011import os
Shun-Hsing Oub5724832016-07-21 11:45:58 +080012import re
Wei-Han Chene97d3532016-03-31 19:22:01 +080013import resource
14import shutil
15import signal
Wei-Han Chenbe1355a2016-04-24 19:31:03 +080016import socket
Wei-Han Chene97d3532016-03-31 19:22:01 +080017import tempfile
18import textwrap
19import time
20
21import factory_common # pylint: disable=unused-import
22from cros.factory.gooftool import chroot
Wei-Han Chen0a3320e2016-04-23 01:32:07 +080023from cros.factory.gooftool.common import ExecFactoryPar
Wei-Han Chen9adf9de2016-04-01 19:35:41 +080024from cros.factory.gooftool.common import Util
Wei-Han Chen0a3320e2016-04-23 01:32:07 +080025from cros.factory.test.env import paths
Wei-Han Chene97d3532016-03-31 19:22:01 +080026from cros.factory.utils import process_utils
27from cros.factory.utils import sync_utils
28from cros.factory.utils import sys_utils
29
30
Hung-Te Lina3195462016-10-14 15:48:29 +080031"""Directory of scripts for device cut-off"""
32CUTOFF_SCRIPT_DIR = '/usr/local/factory/sh/cutoff'
Wei-Han Chen9adf9de2016-04-01 19:35:41 +080033
Wei-Han Chenbe1355a2016-04-24 19:31:03 +080034WIPE_IN_TMPFS_LOG = 'wipe_in_tmpfs.log'
Wei-Han Chene97d3532016-03-31 19:22:01 +080035
Joel Kitching679a00b2016-08-03 11:42:58 +080036
Wei-Han Chenbe1355a2016-04-24 19:31:03 +080037def _CopyLogFileToStateDev(state_dev, logfile):
Wei-Han Chene97d3532016-03-31 19:22:01 +080038 with sys_utils.MountPartition(state_dev,
39 rw=True,
40 fstype='ext4') as mount_point:
41 shutil.copyfile(logfile,
42 os.path.join(mount_point, os.path.basename(logfile)))
43
44
Wei-Han Chenbe1355a2016-04-24 19:31:03 +080045def _OnError(ip, port, token, state_dev, wipe_in_tmpfs_log=None,
46 wipe_init_log=None):
47 if wipe_in_tmpfs_log:
48 _CopyLogFileToStateDev(state_dev, wipe_in_tmpfs_log)
49 if wipe_init_log:
50 _CopyLogFileToStateDev(state_dev, wipe_init_log)
51 _InformStation(ip, port, token,
52 wipe_in_tmpfs_log=wipe_in_tmpfs_log,
53 wipe_init_log=wipe_init_log,
54 success=False)
55
56
Wei-Han Chene97d3532016-03-31 19:22:01 +080057def Daemonize(logfile=None):
58 """Starts a daemon process and terminates current process.
59
60 A daemon process will be started, and continue excuting the following codes.
61 The original process that calls this function will be terminated.
62
63 Example::
64
65 def DaemonFunc():
66 Daemonize()
67 # the process calling DaemonFunc is terminated.
68 # the following codes will be executed in a daemon process
69 ...
70
71 If you would like to keep the original process alive, you could fork a child
72 process and let child process start the daemon.
73 """
74 # fork from parent process
75 if os.fork():
76 # stop parent process
77 os._exit(0) # pylint: disable=protected-access
78
79 # decouple from parent process
80 os.chdir('/')
81 os.umask(0)
82 os.setsid()
83
84 # fork again
85 if os.fork():
86 os._exit(0) # pylint: disable=protected-access
87
88 maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
89 if maxfd == resource.RLIM_INFINITY:
90 maxfd = 1024
91
92 for fd in xrange(maxfd):
93 try:
94 os.close(fd)
95 except OSError:
96 pass
97
98 # Reopen fd 0 (stdin), 1 (stdout), 2 (stderr) to prevent errors from reading
99 # or writing to these files.
100 # Since we have closed all file descriptors, os.open should open a file with
101 # file descriptor equals to 0
102 os.open('/dev/null', os.O_RDWR)
103 if logfile is None:
104 os.dup2(0, 1) # stdout
105 os.dup2(0, 2) # stderr
106 else:
107 os.open(logfile, os.O_RDWR | os.O_CREAT)
108 os.dup2(1, 2) # stderr
109
110
111def ResetLog(logfile=None):
112 if len(logging.getLogger().handlers) > 0:
113 for handler in logging.getLogger().handlers:
114 logging.getLogger().removeHandler(handler)
115 logging.basicConfig(filename=logfile, level=logging.NOTSET)
116
117
Hung-Te Lin7b27f0c2016-10-18 18:41:29 +0800118def WipeInTmpFs(is_fast=None, shopfloor_url=None, station_ip=None,
119 station_port=None, wipe_finish_token=None):
Wei-Han Chene97d3532016-03-31 19:22:01 +0800120 """prepare to wipe by pivot root to tmpfs and unmount statefull partition.
121
122 Args:
123 is_fast: whether or not to apply fast wipe.
Wei-Han Chene97d3532016-03-31 19:22:01 +0800124 shopfloor_url: for inform_shopfloor.sh
125 """
126
Wei-Han Chene97d3532016-03-31 19:22:01 +0800127 Daemonize()
128
Shun-Hsing Oub5724832016-07-21 11:45:58 +0800129 # Set the defual umask.
130 os.umask(0022)
131
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800132 logfile = os.path.join('/tmp', WIPE_IN_TMPFS_LOG)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800133 ResetLog(logfile)
134
Wei-Han Chen0a3320e2016-04-23 01:32:07 +0800135 factory_par = paths.GetFactoryPythonArchivePath()
Wei-Han Chene97d3532016-03-31 19:22:01 +0800136
137 new_root = tempfile.mkdtemp(prefix='tmpfs.')
138 binary_deps = [
139 'activate_date', 'backlight_tool', 'busybox', 'cgpt', 'cgpt.bin',
140 'clobber-log', 'clobber-state', 'coreutils', 'crossystem', 'dd',
141 'display_boot_message', 'dumpe2fs', 'ectool', 'flashrom', 'halt',
142 'initctl', 'mkfs.ext4', 'mktemp', 'mosys', 'mount', 'mount-encrypted',
143 'od', 'pango-view', 'pkill', 'pv', 'python', 'reboot', 'setterm', 'sh',
Hung-Te Lin0ce13392016-12-30 12:36:29 +0800144 'shutdown', 'stop', 'umount', 'vpd', 'wget', 'lsof', 'jq']
Wei-Han Chene97d3532016-03-31 19:22:01 +0800145 if os.path.exists('/sbin/frecon'):
146 binary_deps.append('/sbin/frecon')
147 else:
148 binary_deps.append('/usr/bin/ply-image')
149
150 etc_issue = textwrap.dedent("""
151 You are now in tmp file system created for in-place wiping.
152
153 For debugging wiping fails, see log files under
154 /tmp
155 /mnt/stateful_partition/unencrypted
156
157 The log file name should be
158 - wipe_in_tmpfs.log
159 - wipe_init.log
160
161 You can also run scripts under /usr/local/factory/sh for wiping process.
162 """)
163
Wei-Han Chen0a3320e2016-04-23 01:32:07 +0800164 util = Util()
165
166 root_disk = util.GetPrimaryDevicePath()
167 release_rootfs = util.GetReleaseRootPartitionPath()
168 state_dev = util.GetPrimaryDevicePath(1)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800169 wipe_args = 'factory' + (' fast' if is_fast else '')
170
171 logging.debug('state_dev: %s', state_dev)
172 logging.debug('factory_par: %s', factory_par)
173
174 old_root = 'old_root'
175
176 try:
Shun-Hsing Oub5724832016-07-21 11:45:58 +0800177 # pango load library module dynamically. Therefore we need to query it
178 # first.
179 pango_query_output = process_utils.SpawnOutput(
180 ['pango-querymodules', '--system'])
181 m = re.search(r'^# ModulesPath = (.+)$', pango_query_output, re.M)
182 assert m != None, 'Failed to find pango module path.'
183 pango_module = m.group(1)
184
Wei-Han Chene97d3532016-03-31 19:22:01 +0800185 with chroot.TmpChroot(
186 new_root,
187 file_dir_list=[
Shun-Hsing Oub5724832016-07-21 11:45:58 +0800188 # Basic rootfs.
Wei-Ning Huang71f94e12016-07-17 23:21:41 +0800189 '/bin', '/etc', '/lib', '/lib64', '/root', '/sbin',
Shun-Hsing Oub5724832016-07-21 11:45:58 +0800190 # Factory related scripts.
191 factory_par,
192 '/usr/local/factory/sh',
193 # Fonts and assets required for showing message.
194 pango_module,
Wei-Han Chene97d3532016-03-31 19:22:01 +0800195 '/usr/share/fonts/notocjk',
196 '/usr/share/cache/fontconfig',
197 '/usr/share/chromeos-assets/images',
198 '/usr/share/chromeos-assets/text/boot_messages',
199 '/usr/share/misc/chromeos-common.sh',
Shun-Hsing Oub5724832016-07-21 11:45:58 +0800200 # File required for enable ssh connection.
201 '/mnt/stateful_partition/etc/ssh',
202 '/root/.ssh',
203 '/usr/share/chromeos-ssh-config',
204 # /var/empty is required by openssh server.
205 '/var/empty'],
Wei-Han Chene97d3532016-03-31 19:22:01 +0800206 binary_list=binary_deps, etc_issue=etc_issue).PivotRoot(old_root):
207 logging.debug(
208 'lsof: %s',
209 process_utils.SpawnOutput('lsof -p %d' % os.getpid(), shell=True))
210
Wei-Han Chene97d3532016-03-31 19:22:01 +0800211 process_utils.Spawn(['sync'], call=True)
212 time.sleep(3)
213
214 # Restart gooftool under new root. Since current gooftool might be using
215 # some resource under stateful partition, restarting gooftool ensures that
216 # everything new gooftool is using comes from tmpfs and we can safely
217 # unmount stateful partition.
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800218 args = []
219 if wipe_args:
220 args += ['--wipe_args', wipe_args]
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800221 if shopfloor_url:
222 args += ['--shopfloor_url', shopfloor_url]
223 if station_ip:
224 args += ['--station_ip', station_ip]
225 if station_port:
226 args += ['--station_port', station_port]
227 if wipe_finish_token:
228 args += ['--wipe_finish_token', wipe_finish_token]
229 args += ['--state_dev', state_dev]
230 args += ['--release_rootfs', release_rootfs]
231 args += ['--root_disk', root_disk]
232 args += ['--old_root', old_root]
233
234 ExecFactoryPar('gooftool', 'wipe_init', *args)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800235 raise RuntimeError('Should not reach here')
236 except: # pylint: disable=bare-except
237 logging.exception('wipe_in_place failed')
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800238 _OnError(station_ip, station_port, wipe_finish_token, state_dev,
239 wipe_in_tmpfs_log=logfile, wipe_init_log=None)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800240 raise
241
242
243def _StopAllUpstartJobs(exclude_list=None):
244 logging.debug('stopping upstart jobs')
245
246 # Try three times to stop running services because some service will respawn
247 # one time after being stopped, e.g. shill_respawn. Two times should be enough
248 # to stop shill. Adding one more try for safety.
249
250 if exclude_list is None:
251 exclude_list = []
252
253 for unused_tries in xrange(3):
254 service_list = process_utils.SpawnOutput(['initctl', 'list']).splitlines()
255 service_list = [
256 line.split()[0] for line in service_list if 'start/running' in line]
257 for service in service_list:
Wei-Han Chenc8f24562016-04-23 19:42:42 +0800258 if service in exclude_list or service.startswith('console-'):
Wei-Han Chene97d3532016-03-31 19:22:01 +0800259 continue
Wei-Han Chenc8f24562016-04-23 19:42:42 +0800260 process_utils.Spawn(['stop', service], call=True, log=True)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800261
262
Wei-Han Chenc8f24562016-04-23 19:42:42 +0800263def _UnmountStatefulPartition(root, state_dev):
Wei-Han Chene97d3532016-03-31 19:22:01 +0800264 logging.debug('unmount stateful partition')
Wei-Han Chene97d3532016-03-31 19:22:01 +0800265 # mount points that need chromeos_shutdown to umount
266
267 # 1. find mount points on stateful partition
Wei-Han Chenc8f24562016-04-23 19:42:42 +0800268 mount_output = process_utils.SpawnOutput(['mount'], log=True)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800269
Wei-Han Chenc8f24562016-04-23 19:42:42 +0800270 mount_point_list = []
271 for line in mount_output.splitlines():
272 fields = line.split()
273 if fields[0] == state_dev:
274 mount_point_list.append(fields[2])
275
276 logging.debug('stateful partitions mounted on: %s', mount_point_list)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800277 # 2. find processes that are using stateful partitions
278
Wei-Han Chen0a3320e2016-04-23 01:32:07 +0800279 def _ListProcOpening(path_list):
280 lsof_cmd = ['lsof', '-t'] + path_list
Wei-Han Chene97d3532016-03-31 19:22:01 +0800281 return [int(line)
282 for line in process_utils.SpawnOutput(lsof_cmd).splitlines()]
283
284 proc_list = _ListProcOpening(mount_point_list)
285
Wei-Han Chenc8f24562016-04-23 19:42:42 +0800286 if os.getpid() in proc_list:
Wei-Han Chene97d3532016-03-31 19:22:01 +0800287 logging.error('wipe_init itself is using stateful partition')
288 logging.error(
289 'lsof: %s',
290 process_utils.SpawnOutput('lsof -p %d' % os.getpid(), shell=True))
291 raise RuntimeError('using stateful partition')
292
293 def _KillOpeningBySignal(sig):
294 proc_list = _ListProcOpening(mount_point_list)
295 if not proc_list:
296 return True # we are done
297 for pid in proc_list:
Wei-Han Chenc8f24562016-04-23 19:42:42 +0800298 try:
299 os.kill(pid, sig)
300 except: # pylint: disable=bare-except
301 logging.exception('killing process %d failed', pid)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800302 return False # need to check again
303
304 sync_utils.Retry(10, 0.1, None, _KillOpeningBySignal, signal.SIGTERM)
305 sync_utils.Retry(10, 0.1, None, _KillOpeningBySignal, signal.SIGKILL)
306
307 proc_list = _ListProcOpening(mount_point_list)
308 assert not proc_list, "processes using stateful partition: %s" % proc_list
309
310 os.unlink(os.path.join(root, 'var', 'run'))
311 os.unlink(os.path.join(root, 'var', 'lock'))
312
You-Cheng Syu2ea26dd2016-12-06 20:50:05 +0800313 def _Unmount(mount_point, critical):
314 logging.info('try to unmount %s' % mount_point)
315 for unused_i in xrange(10):
316 output = process_utils.Spawn(['umount', '-n', '-R', mount_point],
317 read_stderr=True, log=True).stderr_data
318 # some mount points need to be unmounted multiple times.
319 if (output.endswith(': not mounted\n') or
320 output.endswith(': not found\n')):
321 return
322 time.sleep(0.5)
323 logging.error('failed to unmount %s' % mount_point)
324 if critical:
325 raise RuntimeError('Unmounting %s is critical. Stop.')
326
Wei-Han Chene97d3532016-03-31 19:22:01 +0800327 if os.path.exists(os.path.join(root, 'dev', 'mapper', 'encstateful')):
You-Cheng Syuf0990462016-09-07 14:56:19 +0800328 # Doing what 'mount-encrypted umount' should do.
329 for mount_point in mount_point_list:
You-Cheng Syu2ea26dd2016-12-06 20:50:05 +0800330 _Unmount(mount_point, False)
331 _Unmount(os.path.join(root, 'var'), True)
You-Cheng Syuf0990462016-09-07 14:56:19 +0800332 process_utils.Spawn(['dmsetup', 'remove', 'encstateful'], check_call=True)
333 process_utils.Spawn(['losetup', '-D'], check_call=True)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800334
335 for mount_point in mount_point_list:
You-Cheng Syu2ea26dd2016-12-06 20:50:05 +0800336 _Unmount(mount_point, True)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800337 process_utils.Spawn(['sync'], call=True)
338
You-Cheng Syuf0990462016-09-07 14:56:19 +0800339 # Check if the stateful partition is unmounted successfully.
340 process_utils.Spawn(r'mount | grep -c "^\S*stateful" | grep -q ^0$',
341 shell=True, check_call=True)
342
Wei-Han Chene97d3532016-03-31 19:22:01 +0800343
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800344def _InformStation(ip, port, token, wipe_init_log=None,
345 wipe_in_tmpfs_log=None, success=True):
346 if not ip:
347 return
348 port = int(port)
349
350 logging.debug('inform station %s:%d', ip, port)
351
352 try:
353 sync_utils.WaitFor(
354 lambda: 0 == process_utils.Spawn(['ping', '-w1', '-c1', ip],
355 call=True).returncode,
356 timeout_secs=180, poll_interval=1)
357 except: # pylint: disable=bare-except
358 logging.exception('cannot get network connection...')
359 else:
360 sock = socket.socket()
361 sock.connect((ip, port))
362
363 response = dict(token=token, success=success)
364
365 if wipe_init_log:
366 with open(wipe_init_log) as f:
367 response['wipe_init_log'] = f.read()
368
369 if wipe_in_tmpfs_log:
370 with open(wipe_in_tmpfs_log) as f:
371 response['wipe_in_tmpfs_log'] = f.read()
372
373 sock.sendall(json.dumps(response) + '\n')
374 sock.close()
375
376
377def _WipeStateDev(release_rootfs, root_disk, wipe_args):
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800378 stateful_partition_path = '/mnt/stateful_partition'
379
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800380 clobber_state_env = os.environ.copy()
Wei-Han Chen0a3320e2016-04-23 01:32:07 +0800381 clobber_state_env.update(ROOT_DEV=release_rootfs,
Earl Oueeb289d2016-11-04 14:36:40 +0800382 ROOT_DISK=root_disk)
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800383 logging.debug('clobber-state: root_dev=%s, root_disk=%s',
Wei-Han Chen0a3320e2016-04-23 01:32:07 +0800384 release_rootfs, root_disk)
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800385 process_utils.Spawn(['clobber-state', wipe_args], env=clobber_state_env,
386 call=True)
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800387 # remove developer flag, which is created by clobber-state after wiping.
388 try:
Wei-Han Chene5b19f42016-10-21 14:45:10 +0800389 os.unlink(os.path.join(stateful_partition_path, '.developer_mode'))
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800390 except OSError:
391 pass
Wei-Han Chene5b19f42016-10-21 14:45:10 +0800392 # make sure that everything is synced
393 for unused_i in xrange(3):
394 process_utils.Spawn(['sync'], call=True)
395 time.sleep(1)
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800396
Joel Kitching679a00b2016-08-03 11:42:58 +0800397
Earl Ou564a7872016-10-05 10:22:00 +0800398def EnableReleasePartition(release_rootfs):
399 """Enables a release image partition on disk."""
Wei-Han Chen0a3320e2016-04-23 01:32:07 +0800400 logging.debug('enable release partition: %s', release_rootfs)
401 Util().EnableReleasePartition(release_rootfs)
Earl Ou564a7872016-10-05 10:22:00 +0800402 logging.debug('Device will boot from %s after reboot.', release_rootfs)
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800403
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800404
405def _InformShopfloor(shopfloor_url):
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800406 if shopfloor_url:
407 logging.debug('inform shopfloor %s', shopfloor_url)
Hung-Te Lina3195462016-10-14 15:48:29 +0800408 proc = process_utils.Spawn(
409 [os.path.join(CUTOFF_SCRIPT_DIR, 'inform_shopfloor.sh'), shopfloor_url,
410 'factory_wipe'], check_call=True)
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800411 logging.debug('stdout: %s', proc.stdout_data)
412 logging.debug('stderr: %s', proc.stderr_data)
413
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800414
Hung-Te Lin7b27f0c2016-10-18 18:41:29 +0800415def _Cutoff():
416 logging.debug('cutoff')
Hung-Te Lina3195462016-10-14 15:48:29 +0800417 cutoff_script = os.path.join(CUTOFF_SCRIPT_DIR, 'cutoff.sh')
Hung-Te Lin7b27f0c2016-10-18 18:41:29 +0800418 process_utils.Spawn('%s' % (cutoff_script), shell=True, check_call=True)
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800419
420
Hung-Te Lin7b27f0c2016-10-18 18:41:29 +0800421def WipeInit(wipe_args, shopfloor_url, state_dev, release_rootfs,
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800422 root_disk, old_root, station_ip, station_port, finish_token):
Wei-Han Chenc8f24562016-04-23 19:42:42 +0800423 Daemonize()
Wei-Han Chene97d3532016-03-31 19:22:01 +0800424 logfile = '/tmp/wipe_init.log'
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800425 wipe_in_tmpfs_log = os.path.join(old_root, 'tmp', WIPE_IN_TMPFS_LOG)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800426 ResetLog(logfile)
427
Wei-Han Chen0a3320e2016-04-23 01:32:07 +0800428 logging.debug('wipe_args: %s', wipe_args)
Wei-Han Chen0a3320e2016-04-23 01:32:07 +0800429 logging.debug('shopfloor_url: %s', shopfloor_url)
430 logging.debug('state_dev: %s', state_dev)
431 logging.debug('release_rootfs: %s', release_rootfs)
432 logging.debug('root_disk: %s', root_disk)
433 logging.debug('old_root: %s', old_root)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800434
Wei-Han Chene97d3532016-03-31 19:22:01 +0800435 try:
Shun-Hsing Oub5724832016-07-21 11:45:58 +0800436 _StopAllUpstartJobs(exclude_list=[
437 # Milestone marker that use to determine the running of other services.
438 'boot-services',
439 'system-services',
440 'failsafe',
441 # Keep dbus to make sure we can shutdown the device.
442 'dbus',
443 # Keep shill for connecting to shopfloor or stations.
444 'shill',
445 # Keep openssh-server for debugging purpose.
446 'openssh-server',
447 # sslh is a service in ARC++ for muxing between ssh and adb.
448 'sslh'
449 ])
Wei-Han Chenc8f24562016-04-23 19:42:42 +0800450 _UnmountStatefulPartition(old_root, state_dev)
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800451
Hung-Te Lina3195462016-10-14 15:48:29 +0800452 process_utils.Spawn(
453 [os.path.join(CUTOFF_SCRIPT_DIR, 'display_wipe_message.sh'), 'wipe'],
454 call=True)
Wei-Han Chen9adf9de2016-04-01 19:35:41 +0800455
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800456 _WipeStateDev(release_rootfs, root_disk, wipe_args)
457
Earl Ou564a7872016-10-05 10:22:00 +0800458 EnableReleasePartition(release_rootfs)
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800459
460 _InformShopfloor(shopfloor_url)
461
462 _InformStation(station_ip, station_port, finish_token,
463 wipe_init_log=logfile,
464 wipe_in_tmpfs_log=wipe_in_tmpfs_log,
465 success=True)
466
Hung-Te Lin7b27f0c2016-10-18 18:41:29 +0800467 _Cutoff()
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800468
469 # should not reach here
470 time.sleep(1e8)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800471 except: # pylint: disable=bare-except
472 logging.exception('wipe_init failed')
Wei-Han Chenbe1355a2016-04-24 19:31:03 +0800473 _OnError(station_ip, station_port, finish_token, state_dev,
474 wipe_in_tmpfs_log=wipe_in_tmpfs_log, wipe_init_log=logfile)
Wei-Han Chene97d3532016-03-31 19:22:01 +0800475 raise