Example #1
0
def check_interfaces():
    ok = True

    def test_serial_port(glob, name):
        try:
            with open_serial_port(glob):
                info('%s port is OK', name)
                return True
        except Exception:
            error('%s port is not working', name)
            return False

    info('Checking interfaces...')
    ok = test_serial_port(DEBUGGER_PORT_GDB_GLOB, 'GDB') and ok
    ok = test_serial_port(DEBUGGER_PORT_CLI_GLOB, 'CLI') and ok
    try:
        init_can_iface()
        info('CAN interface is OK')
    except Exception:
        logging.debug('CAN check error', exc_info=True)
        error('CAN interface is not working')
        ok = False

    if not ok:
        fatal('Required interfaces are not available. Please check your hardware configuration. '
              'If this application is running on a virtual machine, make sure that hardware '
              'sharing is configured correctly.')
def check_interfaces():
    ok = True

    def test_serial_port(glob, name):
        try:
            with open_serial_port(DEBUGGER_PORT_GDB_GLOB):
                info("%s port is OK", name)
                return True
        except Exception:
            error("%s port is not working", name)
            return False

    info("Checking interfaces...")
    ok = test_serial_port(DEBUGGER_PORT_GDB_GLOB, "GDB") and ok
    ok = test_serial_port(DEBUGGER_PORT_CLI_GLOB, "CLI") and ok
    try:
        init_can_iface()
        info("CAN interface is OK")
    except Exception:
        logging.debug("CAN check error", exc_info=True)
        error("CAN interface is not working")
        ok = False

    if not ok:
        fatal(
            "Required interfaces are not available. Please check your hardware configuration. "
            "If this application is running on a virtual machine, make sure that hardware "
            "sharing is configured correctly."
        )
Example #3
0
 def test_serial_port(glob, name):
     try:
         with open_serial_port(glob):
             info('%s port is OK', name)
             return True
     except Exception:
         error('%s port is not working', name)
         return False
 def test_serial_port(glob, name):
     try:
         with open_serial_port(DEBUGGER_PORT_GDB_GLOB):
             info("%s port is OK", name)
             return True
     except Exception:
         error("%s port is not working", name)
         return False
Example #5
0
def load_and_start_firmware(bootloader_interface, firmware_image):
    while True:
        try:
            info('Flashing the firmware [%d bytes]...', len(firmware_image))
            bootloader_interface.unlock()
            bootloader_interface.load_firmware(firmware_image)
        except Exception as ex:
            error('Flashing failed: %r', ex)
            if not input('Try harder?', yes_no=True):
                abort('Flashing failed')
        else:
            input('Set PIO0_1 high (J4 open), then press ENTER')
            info('Starting the firmware...')
            bootloader_interface.reset()
            break
Example #6
0
def load_and_start_firmware(bootloader_interface, firmware_image):
    while True:
        try:
            info('Flashing the firmware [%d bytes]...', len(firmware_image))
            bootloader_interface.unlock()
            bootloader_interface.load_firmware(firmware_image)
        except Exception as ex:
            error('Flashing failed: %r', ex)
            if not input('Try harder?', yes_no=True):
                abort('Flashing failed')
        else:
            input('Set PIO0_1 high (J4 open), then press ENTER')
            info('Starting the firmware...')
            bootloader_interface.reset()
            break
Example #7
0
def wait_for_boot():
    def handle_serial_port_hanging():
        fatal('DRWATSON HAS DETECTED A PROBLEM WITH CONNECTED HARDWARE AND NEEDS TO TERMINATE.\n'
              'A serial port operation has timed out. This usually indicates a problem with the connected '
              'hardware or its drivers. Please disconnect all USB devices currently connected to this computer, '
              "then connect them back and restart Drwatson. If you're using a virtual machine, please reboot it.",
              use_abort=True)

    with BackgroundDelay(BOOT_TIMEOUT * 5, handle_serial_port_hanging):
        with open_serial_port(DEBUGGER_PORT_CLI_GLOB) as p:
            try:
                serial_cli = SerialCLI(p)
                boot_deadline = time.monotonic() + BOOT_TIMEOUT
                boot_notification_received = False
                failure_notification_received = False

                while boot_deadline > time.monotonic():
                    timed_out, line = serial_cli.read_line(END_OF_BOOT_LOG_TIMEOUT)

                    if not timed_out:
                        cli_logger.info(repr(line))

                        if PRODUCT_NAME.lower() in line.lower() and 'bootloader' not in line.lower():
                            info('Boot confirmed')
                            boot_notification_received = True

                        if 'error' in line.lower() or 'fail' in line.lower():
                            failure_notification_received = True
                            error('Boot error: %r', line)
                    else:
                        if failure_notification_received:
                            abort('Device failed to start up normally; see the log for details')

                        if boot_notification_received:
                            return

            except IOError:
                logging.info('Boot error', exc_info=True)
            finally:
                p.flushInput()

    abort("The device did not report to CLI with a correct boot message. Possible reasons for this error:\n"
          '1. The device could not boot properly (however it was flashed successfully).\n'
          '2. The debug connector is not soldered properly.\n'
          '3. The serial port is open by another application.\n'
          '4. Either USB-UART adapter or VM are malfunctioning. Try to re-connect the '
          'adapter (disconnect from USB and from the device!) or reboot the VM.')