Skip to content

Commit 414c88d

Browse files
authored
Merge pull request #959 from alegsan/topic/ok/android-net-fastboot
driver: fastbootdriver: support fastboot over network
2 parents f30264b + 8888926 commit 414c88d

File tree

9 files changed

+113
-26
lines changed

9 files changed

+113
-26
lines changed

doc/configuration.rst

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,15 @@ NetworkRKUSBLoader
605605
~~~~~~~~~~~~~~~~~~~
606606
A NetworkRKUSBLoader describes an `RKUSBLoader`_ available on a remote computer.
607607

608-
AndroidFastboot
609-
~~~~~~~~~~~~~~~
610-
An AndroidFastboot resource describes a USB device in the fastboot state.
608+
AndroidUSBFastboot
609+
~~~~~~~~~~~~~~~~~~
610+
An AndroidUSBFastboot resource describes a USB device in the fastboot state.
611+
Previously, this resource was named AndroidFastboot and this name still
612+
supported for backwards compatibility.
611613

612614
.. code-block:: yaml
613615
614-
AndroidFastboot:
616+
AndroidUSBFastboot:
615617
match:
616618
ID_PATH: pci-0000:06:00.0-usb-0:1.3.2:1.0
617619
@@ -625,6 +627,25 @@ Arguments:
625627
Used by:
626628
- `AndroidFastbootDriver`_
627629

630+
AndroidNetFastboot
631+
~~~~~~~~~~~~~~~~~~
632+
An AndroidNetFastboot resource describes a network device in fastboot state.
633+
634+
.. code-block:: yaml
635+
636+
AndroidNetFastboot:
637+
address: "192.168.23.42"
638+
639+
Arguments:
640+
- address (str): ip address of the fastboot device
641+
- port (int, default=5554): udp/tcp fastboot port that is used in the
642+
device. (e.g. Barebox uses port 5554)
643+
- protocol (str, default="udp"): which protocol should be used when issuing
644+
fastboot commands. (Barebox supports currently only the udp protocol)
645+
646+
Used by:
647+
- `AndroidFastbootDriver`_
648+
628649
DFUDevice
629650
~~~~~~~~~
630651
A DFUDevice resource describes a USB device in DFU (Device Firmware Upgrade)
@@ -1159,7 +1180,7 @@ The initial matching and monitoring for udev events is handled by the
11591180
:any:`UdevManager` class.
11601181
This manager is automatically created when a resource derived from
11611182
:any:`USBResource` (such as :any:`USBSerialPort`, :any:`IMXUSBLoader` or
1162-
:any:`AndroidFastboot`) is instantiated.
1183+
:any:`AndroidUSBFastboot`) is instantiated.
11631184

11641185
To identify the kernel device which corresponds to a configured `USBResource`,
11651186
each existing (and subsequently added) kernel device is matched against the
@@ -1205,15 +1226,15 @@ device's parents instead of directly to itself.
12051226
This is necessary for the `USBSerialPort` because we actually want to find the
12061227
``ttyUSB?`` device below the USB serial converter device.
12071228

1208-
Matching an Android Fastboot Device
1209-
+++++++++++++++++++++++++++++++++++
1229+
Matching an Android USB Fastboot Device
1230+
+++++++++++++++++++++++++++++++++++++++
12101231

12111232
In this case, we want to match the USB device on that port directly, so we
12121233
don't use a parent match.
12131234

12141235
.. code-block:: yaml
12151236
1216-
AndroidFastboot:
1237+
AndroidUSBFastboot:
12171238
match:
12181239
sys_name: '1-1.2.3'
12191240
@@ -1548,12 +1569,13 @@ Arguments:
15481569

15491570
AndroidFastbootDriver
15501571
~~~~~~~~~~~~~~~~~~~~~
1551-
An AndroidFastbootDriver allows the upload of images to a device in the USB
1552-
fastboot state.
1572+
An AndroidFastbootDriver allows the upload of images to a device in the USB or
1573+
network fastboot state.
15531574

15541575
Binds to:
15551576
fastboot:
1556-
- `AndroidFastboot`_
1577+
- `AndroidUSBFastboot`_
1578+
- `AndroidNetFastboot`_
15571579

15581580
Implements:
15591581
- None (yet)

doc/overview.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Resources
3333
`Resources` are passive and only store the information to access the
3434
corresponding part of the `Target`.
3535
Typical examples of resources are :any:`RawSerialPort`, :any:`NetworkPowerPort`
36-
and :any:`AndroidFastboot`.
36+
and :any:`AndroidUSBFastboot`.
3737

3838
An important type of `Resources` are :any:`ManagedResources <ManagedResource>`.
3939
While normal `Resources` are always considered available for use and have fixed
@@ -44,7 +44,7 @@ They can appear/disappear at runtime and have different properties each time
4444
they are discovered.
4545
The most common examples of `ManagedResources` are the various USB resources
4646
discovered using udev, such as :any:`USBSerialPort`, :any:`IMXUSBLoader` or
47-
:any:`AndroidFastboot`.
47+
:any:`AndroidUSBFastboot`.
4848

4949
Drivers and Protocols
5050
~~~~~~~~~~~~~~~~~~~~~
@@ -112,7 +112,7 @@ A realistic sequence of activation might look like this:
112112
:any:`IMXUSBLoader` resource to be available)
113113
- load the bootloader (:any:`BootstrapProtocol.load`)
114114
- activate the :any:`AndroidFastbootDriver` driver on the target (this will
115-
wait for the :any:`AndroidFastboot` resource to be available)
115+
wait for the :any:`AndroidUSBFastboot` resource to be available)
116116
- boot the kernel (:any:`AndroidFastbootDriver.boot`)
117117
- activate the :any:`ShellDriver` driver on the target (this will wait for the
118118
:any:`USBSerialPort` resource to be available and log in)
@@ -347,7 +347,7 @@ For resource types which do not have an existing, network-transparent protocol
347347
the mapping done by the exporter.
348348

349349
For generic USB resources, the exporter for example maps a
350-
:any:`AndroidFastboot` resource to a :any:`NetworkAndroidFastboot` resource and
350+
:any:`AndroidUSBFastboot` resource to a :any:`RemoteAndroidUSBFastboot` resource and
351351
adds a hostname property which needs to be used by the client to connect to the
352352
exporter.
353353
To avoid the need for additional remote access protocols and authentication,

labgrid/driver/fastbootdriver.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
from ..exceptions import InvalidConfigError
88
from ..util.managedfile import ManagedFile
99
from ..util.helper import processwrapper
10+
from ..resource.udev import AndroidUSBFastboot
11+
from ..resource.fastboot import AndroidNetFastboot
12+
from ..resource.remote import RemoteAndroidUSBFastboot, RemoteAndroidNetFastboot
1013

1114

1215
@target_factory.reg_driver
1316
@attr.s(eq=False)
1417
class AndroidFastbootDriver(Driver):
1518
bindings = {
16-
"fastboot": {"AndroidFastboot", "NetworkAndroidFastboot"},
19+
"fastboot": {AndroidUSBFastboot, RemoteAndroidUSBFastboot,
20+
AndroidNetFastboot, RemoteAndroidNetFastboot},
1721
}
1822

1923
boot_image = attr.ib(
@@ -38,10 +42,12 @@ def __attrs_post_init__(self):
3842
self.tool = 'fastboot'
3943

4044
def _get_fastboot_prefix(self):
41-
prefix = self.fastboot.command_prefix+[
42-
self.tool,
43-
"-s", f"usb:{self.fastboot.path}",
44-
]
45+
if isinstance(self.fastboot, (AndroidUSBFastboot, RemoteAndroidUSBFastboot)):
46+
option = f"usb:{self.fastboot.path}"
47+
else:
48+
option = f"{self.fastboot.protocol}:{self.fastboot.address}:{self.fastboot.port}"
49+
50+
prefix = self.fastboot.command_prefix + [ self.tool, "-s", option ]
4551

4652
if self.sparse_size is not None:
4753
prefix += ["-S", self.sparse_size]

labgrid/remote/exporter.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,14 @@ def _get_params(self):
491491
p['devnode'] = self.local.devnode
492492
return p
493493

494+
@attr.s(eq=False)
495+
class USBGenericRemoteExport(USBGenericExport):
496+
def __attrs_post_init__(self):
497+
super().__attrs_post_init__()
498+
self.data['cls'] = f"Remote{self.cls}".replace("Network", "")
499+
494500
exports["AndroidFastboot"] = USBGenericExport
501+
exports["AndroidUSBFastboot"] = USBGenericRemoteExport
495502
exports["DFUDevice"] = USBGenericExport
496503
exports["IMXUSBLoader"] = USBGenericExport
497504
exports["MXSUSBLoader"] = USBGenericExport
@@ -669,6 +676,21 @@ def _get_params(self):
669676

670677
exports["LXAIOBusPIO"] = LXAIOBusNodeExport
671678

679+
@attr.s(eq=False)
680+
class AndroidNetFastbootExport(ResourceExport):
681+
def __attrs_post_init__(self):
682+
super().__attrs_post_init__()
683+
local_cls_name = self.cls
684+
self.data['cls'] = f"Remote{self.cls}"
685+
from ..resource import fastboot
686+
local_cls = getattr(fastboot, local_cls_name)
687+
self.local = local_cls(target=None, name=None, **self.local_params)
688+
689+
def _get_params(self):
690+
"""Helper function to return parameters"""
691+
return {'host' : self.host, **self.local_params}
692+
693+
exports["AndroidNetFastboot"] = AndroidNetFastbootExport
672694

673695
class ExporterSession(ApplicationSession):
674696
def onConnect(self):

labgrid/resource/fastboot.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import attr
2+
3+
from ..factory import target_factory
4+
from .common import Resource
5+
6+
@target_factory.reg_resource
7+
@attr.s(eq=False)
8+
class AndroidNetFastboot(Resource):
9+
address = attr.ib(validator=attr.validators.instance_of(str))
10+
port = attr.ib(default=5554, validator=attr.validators.instance_of(int))
11+
protocol = attr.ib(default="udp", validator=attr.validators.instance_of(str))

labgrid/resource/remote.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,30 @@ class RemoteUSBResource(NetworkResource, ManagedResource):
113113

114114
@target_factory.reg_resource
115115
@attr.s(eq=False)
116-
class NetworkAndroidFastboot(RemoteUSBResource):
116+
class RemoteAndroidUSBFastboot(RemoteUSBResource):
117117
def __attrs_post_init__(self):
118118
self.timeout = 10.0
119119
super().__attrs_post_init__()
120120

121121

122+
@target_factory.reg_resource
123+
@attr.s(eq=False)
124+
class NetworkAndroidFastboot(RemoteAndroidUSBFastboot):
125+
def __attrs_post_init__(self):
126+
import warnings
127+
warnings.warn("NetworkAndroidFastboot is deprecated, use RemoteAndroidUSBFastboot instead",
128+
DeprecationWarning)
129+
super().__attrs_post_init__()
130+
131+
132+
@target_factory.reg_resource
133+
@attr.s(eq=False)
134+
class RemoteAndroidNetFastboot(NetworkResource):
135+
address = attr.ib(validator=attr.validators.instance_of(str))
136+
port = attr.ib(default=5554, validator=attr.validators.instance_of(int))
137+
protocol = attr.ib(default="udp", validator=attr.validators.instance_of(str))
138+
139+
122140
@target_factory.reg_resource
123141
@attr.s(eq=False)
124142
class NetworkDFUDevice(RemoteUSBResource):

labgrid/resource/suggest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
USBTMC,
1111
USBVideo,
1212
IMXUSBLoader,
13-
AndroidFastboot,
13+
AndroidUSBFastboot,
1414
DFUDevice,
1515
USBSDMuxDevice,
1616
USBSDWireDevice,
@@ -42,7 +42,7 @@ def __init__(self, args):
4242
self.resources.append(USBTMC(**args))
4343
self.resources.append(USBVideo(**args))
4444
self.resources.append(IMXUSBLoader(**args))
45-
self.resources.append(AndroidFastboot(**args))
45+
self.resources.append(AndroidUSBFastboot(**args))
4646
self.resources.append(DFUDevice(**args))
4747
self.resources.append(USBMassStorage(**args))
4848
self.resources.append(USBSDMuxDevice(**args))

labgrid/resource/udev.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def filter_match(self, device):
312312

313313
@target_factory.reg_resource
314314
@attr.s(eq=False)
315-
class AndroidFastboot(USBResource):
315+
class AndroidUSBFastboot(USBResource):
316316
usb_vendor_id = attr.ib(default='1d6b', validator=attr.validators.instance_of(str))
317317
usb_product_id = attr.ib(default='0104', validator=attr.validators.instance_of(str))
318318
def filter_match(self, device):
@@ -322,6 +322,14 @@ def filter_match(self, device):
322322
return False
323323
return super().filter_match(device)
324324

325+
@target_factory.reg_resource
326+
@attr.s(eq=False)
327+
class AndroidFastboot(AndroidUSBFastboot):
328+
def __attrs_post_init__(self):
329+
warnings.warn("AndroidFastboot is deprecated, use AndroidUSBFastboot instead",
330+
DeprecationWarning)
331+
super().__attrs_post_init__()
332+
325333
@target_factory.reg_resource
326334
@attr.s(eq=False)
327335
class DFUDevice(USBResource):

tests/test_environment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_create_named_resources(self, tmpdir):
8888
targets:
8989
test1:
9090
resources:
91-
- AndroidFastboot:
91+
- AndroidUSBFastboot:
9292
name: "fastboot"
9393
match: {}
9494
- RawSerialPort:
@@ -106,7 +106,7 @@ def test_create_named_drivers(self, tmpdir):
106106
targets:
107107
test1:
108108
resources:
109-
- AndroidFastboot:
109+
- AndroidUSBFastboot:
110110
name: "fastboot"
111111
match: {}
112112
- RawSerialPort:

0 commit comments

Comments
 (0)