~dpigott/lava-dispatcher/add-sdmux-support

« back to all changes in this revision

Viewing changes to lava_dispatcher/device/sdmux.py

  • Committer: Dave Pigott
  • Date: 2013-08-05 08:37:04 UTC
  • Revision ID: dave.pigott@linaro.org-20130805083704-bw8y9c9a4i0hakww
switch to dd

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2012-2013 Linaro Limited
2
2
#
3
3
# Author: Andy Doan <andy.doan@linaro.org>
4
 
#         Dave Pigott ,dave.pigott@linaro.org
 
4
#         Dave Pigott <dave.pigott@linaro.org>
5
5
#
6
6
# This file is part of LAVA Dispatcher.
7
7
#
48
48
from lava_dispatcher.actions.lava_lmp import (
49
49
    LAVALmpSDMux,
50
50
)
51
 
 
 
51
import subprocess
52
52
 
53
53
def _flush_files(mntdir):
54
54
    """
86
86
        if config.pre_connect_command:
87
87
            self.context.run_command(config.pre_connect_command)
88
88
 
89
 
    def deploy_linaro(self, hwpack=None, rootfs=None):
 
89
    def deploy_linaro(self, hwpack=None, rootfs=None, bootloader=None):
90
90
        img = generate_image(self, hwpack, rootfs, self.scratch_dir)
91
91
        self._customize_linux(img)
92
92
        self._write_image(img)
126
126
            fd.close()
127
127
 
128
128
    def _write_image(self, image):
 
129
 
 
130
        sdmux = LAVALmpSDMux(self.config.sdmux_id)
 
131
 
 
132
        sdmux.dutDisconnect()
 
133
        sdmux.hostuSDA()
 
134
 
129
135
        with self.mux_device() as device:
130
 
            chunk_size = 4 << 20
131
 
            update_freq = chunk_size
132
136
            logging.info("dd'ing image to device (%s)", device)
133
 
            with open(device, 'wb', 0) as of:
134
 
                written = 0
135
 
                size = os.path.getsize(image)
136
 
                # 4M chunks work well for SD cards
137
 
                for chunk in self._as_chunks(image, chunk_size):
138
 
                    of.write(chunk)
139
 
#                    of.flush()
140
 
                    written += len(chunk)
141
 
                    if written % update_freq == 0:
142
 
                        logging.info("wrote %dM of %dM bytes", written/(1024*1024), size/(1024*1024))
143
 
                logging.info('closing %s, could take a while...', device)
144
 
                os.fsync(of.fileno())
145
 
                of.close()
 
137
            result = os.system("dd if=%s of=%s conv=fsync" % (image, device))
 
138
        sdmux = LAVALmpSDMux(self.config.sdmux_id)
 
139
 
 
140
        sdmux.hostDisconnect()
 
141
        sdmux.close()
 
142
 
 
143
        if result != 0:
 
144
            raise CriticalError("Failed to dd to device (%d)" % result)
146
145
 
147
146
    @contextlib.contextmanager
148
147
    def mux_device(self):
157
156
        the USB device connect to the sdmux will be powered off so that the
158
157
        target will be able to safely access it.
159
158
        """
160
 
        sdmux = LAVALmpSDMux(self.config.sdmux_id)
161
 
 
162
 
        sdmux.dutDisconnect()
163
 
        sdmux.hostuSDA()
164
 
        time.sleep(10)
165
 
        sdmux.close()
166
 
        time.sleep(10)
167
159
 
168
160
        self.proc = None
169
161