예제 #1
0
    def flash(self, image_bundle=None, images=None, recreate_uefi_entry=True):  # pylint: disable=arguments-differ
        device = self.owner
        if not hasattr(device, 'port') or not hasattr(device, 'microsd_mount_point'):
            msg = 'Device {} does not appear to support VExpress flashing.'
            raise ConfigError(msg.format(device.name))
        with open_serial_connection(port=device.port,
                                    baudrate=device.baudrate,
                                    timeout=device.timeout,
                                    init_dtr=0) as target:
            target.sendline('usb_on')  # this will cause the MicroSD to be mounted on the host
            device.wait_for_microsd_mount_point(target)
            self.deploy_images(device, image_bundle, images)

        self.logger.debug('Resetting the device.')
        device.hard_reset()

        with open_serial_connection(port=device.port,
                                    baudrate=device.baudrate,
                                    timeout=device.timeout,
                                    init_dtr=0) as target:
            menu = UefiMenu(target)
            menu.open(timeout=300)
            if recreate_uefi_entry and menu.has_option(device.uefi_entry):
                self.logger.debug('Deleting existing device entry.')
                menu.delete_entry(device.uefi_entry)
                menu.create_entry(device.uefi_entry, device.uefi_config)
            elif not menu.has_option(device.uefi_entry):
                menu.create_entry(device.uefi_entry, device.uefi_config)
            menu.select(device.uefi_entry)
            target.expect(device.android_prompt, timeout=device.timeout)
예제 #2
0
    def flash(self, image_bundle=None, images=None, recreate_uefi_entry=True):  # pylint: disable=arguments-differ
        device = self.owner
        if not hasattr(device, 'port') or not hasattr(device,
                                                      'microsd_mount_point'):
            msg = 'Device {} does not appear to support VExpress flashing.'
            raise ConfigError(msg.format(device.name))
        with open_serial_connection(port=device.port,
                                    baudrate=device.baudrate,
                                    timeout=device.timeout,
                                    init_dtr=0) as target:
            target.sendline(
                'usb_on'
            )  # this will cause the MicroSD to be mounted on the host
            device.wait_for_microsd_mount_point(target)
            self.deploy_images(device, image_bundle, images)

        self.logger.debug('Resetting the device.')
        device.hard_reset()

        with open_serial_connection(port=device.port,
                                    baudrate=device.baudrate,
                                    timeout=device.timeout,
                                    init_dtr=0) as target:
            menu = UefiMenu(target)
            menu.open(timeout=300)
            if recreate_uefi_entry and menu.has_option(device.uefi_entry):
                self.logger.debug('Deleting existing device entry.')
                menu.delete_entry(device.uefi_entry)
                menu.create_entry(device.uefi_entry, device.uefi_config)
            elif not menu.has_option(device.uefi_entry):
                menu.create_entry(device.uefi_entry, device.uefi_config)
            menu.select(device.uefi_entry)
            target.expect(device.android_prompt, timeout=device.timeout)
예제 #3
0
    def connect(self):
        if not self._is_ready:
            if not self.adb_name:  # pylint: disable=E0203
                with open_serial_connection(timeout=self.timeout,
                                            port=self.port,
                                            baudrate=self.baudrate,
                                            init_dtr=0) as target:
                    target.sendline('')
                    self.logger.debug('Waiting for the Android prompt.')
                    target.expect(self.android_prompt)

                    self.logger.debug('Waiting for IP address...')
                    wait_start_time = time.time()
                    while True:
                        target.sendline('ip addr list eth0')
                        time.sleep(1)
                        try:
                            target.expect('inet ([1-9]\d*.\d+.\d+.\d+)', timeout=10)
                            self.adb_name = target.match.group(1) + ':5555'  # pylint: disable=W0201
                            break
                        except pexpect.TIMEOUT:
                            pass  # We have our own timeout -- see below.
                        if (time.time() - wait_start_time) > self.ready_timeout:
                            raise DeviceError('Could not acquire IP address.')

            if self.adb_name in adb_list_devices():
                adb_disconnect(self.adb_name)
            adb_connect(self.adb_name, timeout=self.timeout)
            super(Juno, self).connect()  # wait for boot to complete etc.
            self._is_ready = True
예제 #4
0
    def connect(self):
        if not self._is_ready:
            if self.config.adb_name:
                self.adb_name = self.config.adb_name  # pylint: disable=attribute-defined-outside-init
            else:
                with open_serial_connection(timeout=self.config.serial_max_timeout,
                                            port=self.config.serial_device,
                                            baudrate=self.config.serial_baud) as target:
                    # Get IP address and push the Gator and PMU logger.
                    target.sendline('su')  # as of Android v5.0.2, Linux does not boot into root shell
                    target.sendline('netcfg')
                    ipaddr_re = re.compile('eth0 +UP +(.+)/.+', re.MULTILINE)
                    target.expect(ipaddr_re)
                    output = target.after
                    match = re.search('eth0 +UP +(.+)/.+', output)
                    if not match:
                        raise DeviceError('Could not get adb IP address.')
                    ipaddr = match.group(1)

                    # Connect to device using adb.
                    target.expect(self.android_prompt)  # pylint: disable=E1101
                    self.adb_name = ipaddr + ":5555"  # pylint: disable=W0201

            if self.adb_name in adb_list_devices():
                adb_disconnect(self.adb_name)
            adb_connect(self.adb_name)
            self._is_ready = True
            self.execute("input keyevent 82", timeout=ADB_SHELL_TIMEOUT)
            self.execute("svc power stayon true", timeout=ADB_SHELL_TIMEOUT)
예제 #5
0
    def connect(self):
        if not self._is_ready:
            if not self.adb_name:  # pylint: disable=E0203
                with open_serial_connection(timeout=self.timeout,
                                            port=self.port,
                                            baudrate=self.baudrate,
                                            init_dtr=0) as target:
                    target.sendline('')
                    self.logger.debug('Waiting for the Android prompt.')
                    target.expect(self.android_prompt)

                    self.logger.debug('Waiting for IP address...')
                    wait_start_time = time.time()
                    while True:
                        target.sendline('ip addr list eth0')
                        time.sleep(1)
                        try:
                            target.expect('inet ([1-9]\d*.\d+.\d+.\d+)',
                                          timeout=10)
                            self.adb_name = target.match.group(1) + ':5555'  # pylint: disable=W0201
                            break
                        except pexpect.TIMEOUT:
                            pass  # We have our own timeout -- see below.
                        if (time.time() -
                                wait_start_time) > self.ready_timeout:
                            raise DeviceError('Could not acquire IP address.')

            if self.adb_name in adb_list_devices():
                adb_disconnect(self.adb_name)
            adb_connect(self.adb_name, timeout=self.timeout)
            super(Juno, self).connect()  # wait for boot to complete etc.
            self._is_ready = True
예제 #6
0
    def connect(self):
        if not self._is_ready:
            if self.config.adb_name:
                self.adb_name = self.config.adb_name  # pylint: disable=attribute-defined-outside-init
            else:
                with open_serial_connection(
                        timeout=self.config.serial_max_timeout,
                        port=self.config.serial_device,
                        baudrate=self.config.serial_baud) as target:
                    # Get IP address and push the Gator and PMU logger.
                    target.sendline(
                        'su'
                    )  # as of Android v5.0.2, Linux does not boot into root shell
                    target.sendline('netcfg')
                    ipaddr_re = re.compile('eth0 +UP +(.+)/.+', re.MULTILINE)
                    target.expect(ipaddr_re)
                    output = target.after
                    match = re.search('eth0 +UP +(.+)/.+', output)
                    if not match:
                        raise DeviceError('Could not get adb IP address.')
                    ipaddr = match.group(1)

                    # Connect to device using adb.
                    target.expect(self.android_prompt)  # pylint: disable=E1101
                    self.adb_name = ipaddr + ":5555"  # pylint: disable=W0201

            if self.adb_name in adb_list_devices():
                adb_disconnect(self.adb_name)
            adb_connect(self.adb_name)
            self._is_ready = True
            self.execute("input keyevent 82", timeout=ADB_SHELL_TIMEOUT)
            self.execute("svc power stayon true", timeout=ADB_SHELL_TIMEOUT)
예제 #7
0
    def boot(self, **kwargs):  # NOQA
        mode = kwargs.get('os_mode', None)
        self._is_ready = False
        self._has_booted = False

        self.mode = mode
        self.logger.debug('Booting in {} mode'.format(self.mode))

        with open_serial_connection(timeout=self.config.serial_max_timeout,
                                    port=self.config.serial_device,
                                    baudrate=self.config.serial_baud) as target:
            if self.config.boot_firmware == 'bootmon':
                self._boot_using_bootmon(target)
            elif self.config.boot_firmware == 'uefi':
                self._boot_using_uefi(target)
            else:
                message = 'Unexpected boot firmware: {}'.format(self.config.boot_firmware)
                raise ConfigError(message)

            try:
                target.sendline('')
                self.logger.debug('Waiting for the Android prompt.')
                target.expect(self.android_prompt, timeout=40)  # pylint: disable=E1101
            except pexpect.TIMEOUT:
                # Try a second time before giving up.
                self.logger.debug('Did not get Android prompt, retrying...')
                target.sendline('')
                target.expect(self.android_prompt, timeout=10)  # pylint: disable=E1101

            self.logger.debug('Waiting for OS to initialize...')
            started_waiting_time = time.time()
            time.sleep(20)  # we know it's not going to to take less time than this.
            boot_completed, got_ip_address = False, False
            while True:
                try:
                    if not boot_completed:
                        target.sendline('getprop sys.boot_completed')
                        boot_completed = target.expect(['0.*', '1.*'], timeout=10)
                    if not got_ip_address:
                        target.sendline('getprop dhcp.eth0.ipaddress')
                        # regexes  are processed in order, so ip regex has to
                        # come first (as we only want to match new line if we
                        # don't match the IP). We do a "not" make the logic
                        # consistent with boot_completed.
                        got_ip_address = not target.expect(['[1-9]\d*.\d+.\d+.\d+', '\n'], timeout=10)
                except pexpect.TIMEOUT:
                    pass  # We have our own timeout -- see below.
                if boot_completed and got_ip_address:
                    break
                time.sleep(5)
                if (time.time() - started_waiting_time) > self.config.init_timeout:
                    raise DeviceError('Timed out waiting for the device to initialize.')

        self._has_booted = True
예제 #8
0
    def boot(self, **kwargs):  # NOQA
        mode = kwargs.get('os_mode', None)
        self._is_ready = False
        self._has_booted = False

        self.mode = mode
        self.logger.debug('Booting in {} mode'.format(self.mode))

        with open_serial_connection(timeout=self.config.serial_max_timeout,
                                    port=self.config.serial_device,
                                    baudrate=self.config.serial_baud) as target:
            if self.config.boot_firmware == 'bootmon':
                self._boot_using_bootmon(target)
            elif self.config.boot_firmware == 'uefi':
                self._boot_using_uefi(target)
            else:
                message = 'Unexpected boot firmware: {}'.format(self.config.boot_firmware)
                raise ConfigError(message)

            try:
                target.sendline('')
                self.logger.debug('Waiting for the Android prompt.')
                target.expect(self.android_prompt, timeout=40)  # pylint: disable=E1101
            except pexpect.TIMEOUT:
                # Try a second time before giving up.
                self.logger.debug('Did not get Android prompt, retrying...')
                target.sendline('')
                target.expect(self.android_prompt, timeout=10)  # pylint: disable=E1101

            self.logger.debug('Waiting for OS to initialize...')
            started_waiting_time = time.time()
            time.sleep(20)  # we know it's not going to to take less time than this.
            boot_completed, got_ip_address = False, False
            while True:
                try:
                    if not boot_completed:
                        target.sendline('getprop sys.boot_completed')
                        boot_completed = target.expect(['0.*', '1.*'], timeout=10)
                    if not got_ip_address:
                        target.sendline('getprop dhcp.eth0.ipaddress')
                        # regexes  are processed in order, so ip regex has to
                        # come first (as we only want to match new line if we
                        # don't match the IP). We do a "not" make the logic
                        # consistent with boot_completed.
                        got_ip_address = not target.expect(['[1-9]\d*.\d+.\d+.\d+', '\n'], timeout=10)
                except pexpect.TIMEOUT:
                    pass  # We have our own timeout -- see below.
                if boot_completed and got_ip_address:
                    break
                time.sleep(5)
                if (time.time() - started_waiting_time) > self.config.init_timeout:
                    raise DeviceError('Timed out waiting for the device to initialize.')

        self._has_booted = True
예제 #9
0
 def _fastboot_prelude(self, device):
     with open_serial_connection(port=device.port,
                                 baudrate=device.baudrate,
                                 timeout=self.serial_timeout,
                                 init_dtr=0,
                                 get_conn=False) as target:
         device.reset()
         time.sleep(self.delay)
         target.sendline(' ')
         time.sleep(self.delay)
         target.sendline('fast')
         time.sleep(self.delay)
     self.prelude_done = True
예제 #10
0
 def _fastboot_prelude(self, device):
     with open_serial_connection(port=device.port,
                                 baudrate=device.baudrate,
                                 timeout=self.serial_timeout,
                                 init_dtr=0,
                                 get_conn=False) as target:
         device.reset()
         time.sleep(self.delay)
         target.sendline(' ')
         time.sleep(self.delay)
         target.sendline('fast')
         time.sleep(self.delay)
     self.prelude_done = True
예제 #11
0
 def _boot_via_uboot(self, **kwargs):
     if not kwargs:
         # Standard linaro configuration will proceed directly to the kernel
         return
     with open_serial_connection(port=self.port,
                                 baudrate=self.baudrate,
                                 timeout=self.timeout,
                                 init_dtr=0) as target:
         menu = UbootMenu(target)
         self.logger.debug('Waiting for U-Boot prompt...')
         menu.open(timeout=120)
         for var, value in kwargs.iteritems():
             menu.setenv(var, value)
         menu.boot()
예제 #12
0
 def _boot_via_uboot(self, **kwargs):
     if not kwargs:
         # Standard linaro configuration will proceed directly to the kernel
         return
     with open_serial_connection(port=self.port,
                                 baudrate=self.baudrate,
                                 timeout=self.timeout,
                                 init_dtr=0) as target:
         menu = UbootMenu(target)
         self.logger.debug('Waiting for U-Boot prompt...')
         menu.open(timeout=120)
         for var, value in kwargs.iteritems():
             menu.setenv(var, value)
         menu.boot()
예제 #13
0
    def hard_reset(self):
        self.disconnect()
        self.adb_name = None  # Force re-acquire IP address on reboot. pylint: disable=attribute-defined-outside-init
        with open_serial_connection(port=self.port,
                                    baudrate=self.baudrate,
                                    timeout=self.timeout,
                                    init_dtr=0,
                                    get_conn=True) as (target, conn):
            pulse_dtr(conn, state=True, duration=0.1)  # TRM specifies a pulse of >=100ms

            i = target.expect([AUTOSTART_MESSAGE, self.firmware_prompt])
            if i:
                self.logger.debug('Saw firmware prompt.')
                time.sleep(self.short_delay)
                target.sendline('reboot')
            else:
                self.logger.debug('Saw auto boot message.')
예제 #14
0
 def _boot_via_uefi(self):
     with open_serial_connection(port=self.port,
                                 baudrate=self.baudrate,
                                 timeout=self.timeout,
                                 init_dtr=0) as target:
         menu = UefiMenu(target)
         self.logger.debug('Waiting for UEFI menu...')
         menu.open(timeout=120)
         try:
             menu.select(self.uefi_entry)
         except LookupError:
             self.logger.debug('{} UEFI entry not found.'.format(self.uefi_entry))
             self.logger.debug('Attempting to create one using default flasher configuration.')
             menu.create_entry(self.uefi_entry, self.uefi_config)
             menu.select(self.uefi_entry)
         self.logger.debug('Waiting for the Android prompt.')
         target.expect(self.android_prompt, timeout=self.timeout)
예제 #15
0
    def hard_reset(self):
        self.disconnect()
        self.adb_name = None  # Force re-acquire IP address on reboot. pylint: disable=attribute-defined-outside-init
        with open_serial_connection(port=self.port,
                                    baudrate=self.baudrate,
                                    timeout=self.timeout,
                                    init_dtr=0,
                                    get_conn=True) as (target, conn):
            pulse_dtr(conn, state=True,
                      duration=0.1)  # TRM specifies a pulse of >=100ms

            i = target.expect([AUTOSTART_MESSAGE, self.firmware_prompt])
            if i:
                self.logger.debug('Saw firmware prompt.')
                time.sleep(self.short_delay)
                target.sendline('reboot')
            else:
                self.logger.debug('Saw auto boot message.')
예제 #16
0
 def _boot_via_uefi(self):
     with open_serial_connection(port=self.port,
                                 baudrate=self.baudrate,
                                 timeout=self.timeout,
                                 init_dtr=0) as target:
         menu = UefiMenu(target)
         self.logger.debug('Waiting for UEFI menu...')
         menu.open(timeout=120)
         try:
             menu.select(self.uefi_entry)
         except LookupError:
             self.logger.debug('{} UEFI entry not found.'.format(
                 self.uefi_entry))
             self.logger.debug(
                 'Attempting to create one using default flasher configuration.'
             )
             menu.create_entry(self.uefi_entry, self.uefi_config)
             menu.select(self.uefi_entry)
         self.logger.debug('Waiting for the Android prompt.')
         target.expect(self.android_prompt, timeout=self.timeout)
예제 #17
0
 def stop_active_cooling(self):
     with open_serial_connection(timeout=self.timeout,
                                 port=self.port,
                                 baudrate=self.buad) as target:
         target.sendline('motor_{}_0'.format(self.fan_pin))