summaryrefslogtreecommitdiff
path: root/extra/usb_serial
diff options
context:
space:
mode:
Diffstat (limited to 'extra/usb_serial')
-rw-r--r--extra/usb_serial/.gitignore12
-rw-r--r--extra/usb_serial/51-google-serial-fallback.rules6
-rw-r--r--extra/usb_serial/51-google-serial.rules33
-rw-r--r--extra/usb_serial/Makefile10
-rw-r--r--extra/usb_serial/README.md5
-rwxr-xr-xextra/usb_serial/add_usb_serial_id32
-rwxr-xr-xextra/usb_serial/console.py298
-rwxr-xr-xextra/usb_serial/install88
-rw-r--r--extra/usb_serial/raiden.c46
9 files changed, 0 insertions, 530 deletions
diff --git a/extra/usb_serial/.gitignore b/extra/usb_serial/.gitignore
deleted file mode 100644
index 77fee262b1..0000000000
--- a/extra/usb_serial/.gitignore
+++ /dev/null
@@ -1,12 +0,0 @@
-.built-in.o.cmd
-.raiden.ko.cmd
-.raiden.mod.o.cmd
-.raiden.o.cmd
-.tmp_versions/
-Module.symvers
-built-in.o
-modules.order
-raiden.ko
-raiden.mod.c
-raiden.mod.o
-raiden.o
diff --git a/extra/usb_serial/51-google-serial-fallback.rules b/extra/usb_serial/51-google-serial-fallback.rules
deleted file mode 100644
index 5f43e58e30..0000000000
--- a/extra/usb_serial/51-google-serial-fallback.rules
+++ /dev/null
@@ -1,6 +0,0 @@
-#
-# Add USB VID/PID for usb-serial compatible CCD devices. This is a fallback
-# rule that can be used if the raiden module can't be built, or used for some
-# reason.
-#
-SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTR{idVendor}=="18d1", ENV{ID_USB_INTERFACES}=="*:ff5001:*", RUN+="add_usb_serial_id $attr{idVendor} $attr{idProduct}"
diff --git a/extra/usb_serial/51-google-serial.rules b/extra/usb_serial/51-google-serial.rules
deleted file mode 100644
index 3dedac1b1f..0000000000
--- a/extra/usb_serial/51-google-serial.rules
+++ /dev/null
@@ -1,33 +0,0 @@
-#
-# Rules for Google Case Closed Debugging devices.
-#
-# The first rule matches the google VID and records the product name, USB bus
-# number and USB device path (the device path is the list of hub ports between
-# the root and the device). This becomes a unique directory name under which
-# later rules can create symlinks. If this rule doesn't match udev will skip
-# the rest of this files rules.
-#
-# This rule intentionally matches using SUBSYSTEMS and ATTRS instead of
-# SUBSYSTEM and ATTR so that the GOOGLE_CCD_NAME is available to all nodes
-# that descend from a Google USB device (this includes all USB interface nodes
-# as well as all of the TTY nodes derived from CCD USB interfaces).
-#
-SUBSYSTEMS=="usb", ATTRS{idVendor}=="18d1", ENV{GOOGLE_CCD_NAME}="$attr{product}-$attr{busnum}-$attr{devpath}"
-
-#
-# Force ModemManager to ignore all Google case closed debug devices. It would
-# be better to just ignore the case closed debug serial console interfaces, but
-# ModemManager doesn't look at the usb_interface udev node, it looks at the
-# usb_device node, so you have to mark the entire device as incompatible with
-# ModemManager.
-#
-# This node could lose the match against the usb_device DEVTYPE and still work,
-# it would just add extraneous ID_MM_DEVICE_IGNORE tags to the TTY and USB
-# interface nodes.
-#
-SUBSYSTEM=="usb", ENV{GOOGLE_CCD_NAME}!="", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:ff5001:*", ENV{ID_MM_DEVICE_IGNORE}="1"
-
-#
-# Construct a symlink to a TTY generated from a CCD USB serial interface.
-#
-SUBSYSTEM=="tty", ENV{GOOGLE_CCD_NAME}!="", ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="50", ATTRS{bInterfaceProtocol}=="01", OPTIONS+="string_escape=replace", SYMLINK+="google/$env{GOOGLE_CCD_NAME}/serial/$attr{interface}"
diff --git a/extra/usb_serial/Makefile b/extra/usb_serial/Makefile
deleted file mode 100644
index 9c478050cc..0000000000
--- a/extra/usb_serial/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-obj-m := raiden.o
-
-.PHONY: all
-
-all: modules
-
-.DEFAULT:
- $(MAKE) -C /lib/modules/$(shell uname -r)/build \
- M=$(shell pwd) \
- $(MAKECMDGOALS)
diff --git a/extra/usb_serial/README.md b/extra/usb_serial/README.md
deleted file mode 100644
index 7cc6030d0a..0000000000
--- a/extra/usb_serial/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# Case Closed Debugging Serial Consoles over USB
-
-Please see the documentation in [case_closed_debugging doc][1]
-
-[1]:https://chromium.googlesource.com/chromiumos/platform/ec/+/cr50_stab/docs/case_closed_debugging.md
diff --git a/extra/usb_serial/add_usb_serial_id b/extra/usb_serial/add_usb_serial_id
deleted file mode 100755
index ef8336afdc..0000000000
--- a/extra/usb_serial/add_usb_serial_id
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh -e
-#
-# Copyright 2016 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-#
-# Add a USB VID:PID device ID to the usbserial list of handled devices
-
-if [ $# -ne 2 ]; then
- echo ""
- echo "Usage: $0 <VID> <PID>"
- echo ""
- echo "Add a USB VID:PID device identification pair to the list of devices"
- echo "that usbserial will recognize. This script ensures that a device is"
- echo "not added more than once."
- echo ""
- exit 1
-fi
-
-#
-# Firts ensure that the usbserial module is loaded. This is required as there
-# may be no other USB serial adaptor connected yet.
-#
-modprobe usbserial
-
-device_id="$1 $2"
-file="/sys/bus/usb-serial/drivers/generic/new_id"
-
-#
-# Only add the device ID pair if it isn't already in the ID list.
-#
-grep -q "$device_id" $file || echo $device_id > $file
diff --git a/extra/usb_serial/console.py b/extra/usb_serial/console.py
deleted file mode 100755
index 7b3bacd903..0000000000
--- a/extra/usb_serial/console.py
+++ /dev/null
@@ -1,298 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2016 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-#
-# Ignore indention messages, since legacy scripts use 2 spaces instead of 4.
-# pylint: disable=bad-indentation,docstring-section-indent
-# pylint: disable=docstring-trailing-quotes
-
-"""Allow creation of uart/console interface via usb google serial endpoint."""
-
-# Note: This is a py2/3 compatible file.
-
-from __future__ import print_function
-import argparse
-import array
-import os
-import sys
-import termios
-import threading
-import time
-import traceback
-import tty
-try:
- import usb
-except:
- print("import usb failed")
- print("try running these commands:")
- print(" sudo apt-get install python-pip")
- print(" sudo pip install --pre pyusb")
- print()
- sys.exit(-1)
-
-import six
-
-
-def GetBuffer(stream):
- if six.PY3:
- return stream.buffer
- return stream
-
-
-"""Class Susb covers USB device discovery and initialization.
-
- It can find a particular endpoint by vid:pid, serial number,
- and interface number.
-"""
-
-class SusbError(Exception):
- """Class for exceptions of Susb."""
- def __init__(self, msg, value=0):
- """SusbError constructor.
-
- Args:
- msg: string, message describing error in detail
- value: integer, value of error when non-zero status returned. Default=0
- """
- super(SusbError, self).__init__(msg, value)
- self.msg = msg
- self.value = value
-
-class Susb():
- """Provide USB functionality.
-
- Instance Variables:
- _read_ep: pyUSB read endpoint for this interface
- _write_ep: pyUSB write endpoint for this interface
- """
- READ_ENDPOINT = 0x81
- WRITE_ENDPOINT = 0x1
- TIMEOUT_MS = 100
-
- def __init__(self, vendor=0x18d1,
- product=0x500f, interface=1, serialname=None):
- """Susb constructor.
-
- Discovers and connects to USB endpoints.
-
- Args:
- vendor : usb vendor id of device
- product : usb product id of device
- interface : interface number ( 1 - 8 ) of device to use
- serialname: string of device serialnumber.
-
- Raises:
- SusbError: An error accessing Susb object
- """
- # Find the device.
- dev_g = usb.core.find(idVendor=vendor, idProduct=product, find_all=True)
- dev_list = list(dev_g)
- if dev_list is None:
- raise SusbError("USB device not found")
-
- # Check if we have multiple devices.
- dev = None
- if serialname:
- for d in dev_list:
- dev_serial = "PyUSB doesn't have a stable interface"
- try:
- dev_serial = usb.util.get_string(d, 256, d.iSerialNumber)
- except:
- dev_serial = usb.util.get_string(d, d.iSerialNumber)
- if dev_serial == serialname:
- dev = d
- break
- if dev is None:
- raise SusbError("USB device(%s) not found" % (serialname,))
- else:
- try:
- dev = dev_list[0]
- except:
- try:
- dev = dev_list.next()
- except:
- raise SusbError("USB device %04x:%04x not found" % (vendor, product))
-
- # If we can't set configuration, it's already been set.
- try:
- dev.set_configuration()
- except usb.core.USBError:
- pass
-
- # Get an endpoint instance.
- cfg = dev.get_active_configuration()
- intf = usb.util.find_descriptor(cfg, bInterfaceNumber=interface)
- self._intf = intf
-
- if not intf:
- raise SusbError("Interface not found")
-
- # Detach raiden.ko if it is loaded.
- if dev.is_kernel_driver_active(intf.bInterfaceNumber) is True:
- dev.detach_kernel_driver(intf.bInterfaceNumber)
-
- read_ep_number = intf.bInterfaceNumber + self.READ_ENDPOINT
- read_ep = usb.util.find_descriptor(intf, bEndpointAddress=read_ep_number)
- self._read_ep = read_ep
-
- write_ep_number = intf.bInterfaceNumber + self.WRITE_ENDPOINT
- write_ep = usb.util.find_descriptor(intf, bEndpointAddress=write_ep_number)
- self._write_ep = write_ep
-
-
-"""Suart class implements a stream interface, to access Google's USB class.
-
- This creates a send and receive thread that monitors USB and console input
- and forwards them across. This particular class is hardcoded to stdin/out.
-"""
-
-class SuartError(Exception):
- """Class for exceptions of Suart."""
- def __init__(self, msg, value=0):
- """SuartError constructor.
-
- Args:
- msg: string, message describing error in detail
- value: integer, value of error when non-zero status returned. Default=0
- """
- super(SuartError, self).__init__(msg, value)
- self.msg = msg
- self.value = value
-
-
-class Suart():
- """Provide interface to serial usb endpoint."""
-
- def __init__(self, vendor=0x18d1, product=0x501c, interface=0,
- serialname=None):
- """Suart contstructor.
-
- Initializes USB stream interface.
-
- Args:
- vendor: usb vendor id of device
- product: usb product id of device
- interface: interface number of device to use
- serialname: Defaults to None.
-
- Raises:
- SuartError: If init fails
- """
- self._done = threading.Event()
- self._susb = Susb(vendor=vendor, product=product,
- interface=interface, serialname=serialname)
-
- def wait_until_done(self, timeout=None):
- return self._done.wait(timeout=timeout)
-
- def run_rx_thread(self):
- try:
- while True:
- try:
- r = self._susb._read_ep.read(64, self._susb.TIMEOUT_MS)
- if r:
- GetBuffer(sys.stdout).write(r.tostring())
- GetBuffer(sys.stdout).flush()
-
- except Exception as e:
- # If we miss some characters on pty disconnect, that's fine.
- # ep.read() also throws USBError on timeout, which we discard.
- if not isinstance(e, (OSError, usb.core.USBError)):
- print("rx %s" % e)
- finally:
- self._done.set()
-
- def run_tx_thread(self):
- try:
- while True:
- try:
- r = GetBuffer(sys.stdin).read(1)
- if not r or r == b"\x03":
- break
- if r:
- self._susb._write_ep.write(array.array('B', r),
- self._susb.TIMEOUT_MS)
- except Exception as e:
- print("tx %s" % e)
- finally:
- self._done.set()
-
- def run(self):
- """Creates pthreads to poll USB & PTY for data.
- """
- self._exit = False
-
- self._rx_thread = threading.Thread(target=self.run_rx_thread)
- self._rx_thread.daemon = True
- self._rx_thread.start()
-
- self._tx_thread = threading.Thread(target=self.run_tx_thread)
- self._tx_thread.daemon = True
- self._tx_thread.start()
-
-
-
-"""Command line functionality
-
- Allows specifying vid:pid, serialnumber, interface.
- Ctrl-C exits.
-"""
-
-parser = argparse.ArgumentParser(description="Open a console to a USB device")
-parser.add_argument('-d', '--device', type=str,
- help="vid:pid of target device", default="18d1:501c")
-parser.add_argument('-i', '--interface', type=int,
- help="interface number of console", default=0)
-parser.add_argument('-s', '--serialno', type=str,
- help="serial number of device", default="")
-parser.add_argument('-S', '--notty-exit-sleep', type=float, default=0.2,
- help="When stdin is *not* a TTY, wait this many seconds after EOF from "
- "stdin before exiting, to give time for receiving a reply from the USB "
- "device.")
-
-
-def runconsole():
- """Run the usb console code
-
- Starts the pty thread, and idles until a ^C is caught.
- """
- args = parser.parse_args()
-
- vidstr, pidstr = args.device.split(':')
- vid = int(vidstr, 16)
- pid = int(pidstr, 16)
-
- serialno = args.serialno
- interface = args.interface
-
- sobj = Suart(vendor=vid, product=pid, interface=interface,
- serialname=serialno)
- if sys.stdin.isatty():
- tty.setraw(sys.stdin.fileno())
- sobj.run()
- sobj.wait_until_done()
- if not sys.stdin.isatty() and args.notty_exit_sleep > 0:
- time.sleep(args.notty_exit_sleep)
-
-
-def main():
- stdin_isatty = sys.stdin.isatty()
- if stdin_isatty:
- fd = sys.stdin.fileno()
- os.system("stty -echo")
- old_settings = termios.tcgetattr(fd)
-
- try:
- runconsole()
- finally:
- if stdin_isatty:
- termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
- os.system("stty echo")
- # Avoid having the user's shell prompt start mid-line after the final output
- # from this program.
- print()
-
-
-if __name__ == '__main__':
- main()
diff --git a/extra/usb_serial/install b/extra/usb_serial/install
deleted file mode 100755
index eba1d2ac83..0000000000
--- a/extra/usb_serial/install
+++ /dev/null
@@ -1,88 +0,0 @@
-#!/bin/sh -e
-#
-# Copyright 2016 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-#
-# Build and install raiden module and udev rules
-
-bold=$(tput bold)
-normal=$(tput sgr0)
-
-error() {
- echo "${bold}Install failed${normal}"
-}
-
-trap "error $LINENO" ERR
-
-fallback=false
-
-if [ "$1" = "--fallback" ]; then
- fallback=true
- shift
-fi
-
-if [ $# -ne 0 ]; then
- echo ""
- echo "Usage: ${bold}$0${normal} [--fallback]"
- echo ""
- echo "Install Raiden kernel module and udev rules for working with Case"
- echo "Closed Debug enabled devices."
- echo ""
- echo "${bold}--fallback${normal}"
- echo " Install udev rules to use usbserial directly without installing"
- echo " the raiden module. This can be used when the raiden module fails"
- echo " to build, or can not be used for other reasons."
- echo ""
- echo " The fallback solution will generate extra /dev/ttyUSB? entries"
- echo " for the SPI and possibly other CCD bridges. These should be"
- echo " ignored by you. Flashrom is smart enough to detach the kernel"
- echo " driver from the SPI bridge, so they will not interfere with"
- echo " flashing new firmware images over CCD."
- echo ""
- exit 1
-fi
-
-if [ "$fallback" = "false" ]; then
- #
- # The normal path builds and installs the raiden module
- #
- {
- #
- # Don't build the module as root so it's easier to clean up after
- #
- make modules &&
-
- #
- # Install the new module and update dependency and alias information
- #
- sudo make modules_install &&
- sudo depmod -a
- } || {
- echo $bold
- echo "Building and/or installing the raiden module failed, you may"
- echo "want to use the --fallback option."
- echo $normal
- exit 1;
- }
-else
- #
- # The fallback path installs the fallback udev rule and its helper script.
- #
- sudo install -m644 51-google-serial-fallback.rules /etc/udev/rules.d
- sudo install add_usb_serial_id /lib/udev
-fi
-
-#
-# Install the udev rule for creating /dev/google symlinks.
-#
-sudo install -m644 51-google-serial.rules /etc/udev/rules.d
-
-#
-# Trigger udev to create the symlinks for any attached devices that have the
-# Google Vendor ID. Limiting triggering like this prevents unwanted resetting
-# of some device state, even with the change action specified.
-#
-for syspath in $(dirname $(grep -rxl --include=idVendor 18d1 /sys/devices)); do
- sudo udevadm trigger --action=change --parent-match=${syspath}
-done
diff --git a/extra/usb_serial/raiden.c b/extra/usb_serial/raiden.c
deleted file mode 100644
index e4720b4357..0000000000
--- a/extra/usb_serial/raiden.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * USB Serial module for Raiden USB debug serial console forwarding.
- * SubClass and Protocol allocated in go/usb-ids
- *
- * Copyright 2014 The Chromium OS Authors <chromium-os-dev@chromium.org>
- * Author: Anton Staaf <robotboy@chromium.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/tty.h>
-#include <linux/usb.h>
-#include <linux/usb/serial.h>
-
-MODULE_LICENSE("GPL");
-
-#define USB_VENDOR_ID_GOOGLE 0x18d1
-#define USB_SUBCLASS_GOOGLE_SERIAL 0x50
-#define USB_PROTOCOL_GOOGLE_SERIAL 0x01
-
-static struct usb_device_id const ids[] = {
- { USB_VENDOR_AND_INTERFACE_INFO(USB_VENDOR_ID_GOOGLE,
- USB_CLASS_VENDOR_SPEC,
- USB_SUBCLASS_GOOGLE_SERIAL,
- USB_PROTOCOL_GOOGLE_SERIAL) },
- { 0 }
-};
-
-MODULE_DEVICE_TABLE(usb, ids);
-
-static struct usb_serial_driver device =
-{
- .driver = { .owner = THIS_MODULE,
- .name = "Google" },
- .id_table = ids,
- .num_ports = 1,
-};
-
-static struct usb_serial_driver * const drivers[] = { &device, NULL };
-
-module_usb_serial_driver(drivers, ids);