Skip to content

Commit c7cc2cb

Browse files
committed
driver/usbloader: Add a loader for samsung
Add a USB loader for samsung, supporting BL1, SPL and U-Boot. Signed-off-by: Simon Glass <sjg@chromium.org>
1 parent 1729894 commit c7cc2cb

7 files changed

Lines changed: 151 additions & 0 deletions

File tree

doc/configuration.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,24 @@ Arguments:
715715
Used by:
716716
- `RKUSBDriver`_
717717

718+
SamsungUSBLoader
719+
~~~~~~~~~~~~~~~~
720+
A :any:`SamsungUSBLoader` resource describes a USB device in the *Samsung
721+
loader state*.
722+
723+
.. code-block:: yaml
724+
725+
SamsungUSBLoader:
726+
## hub d4
727+
match:
728+
ID_PATH: pci-0000:03:00.2-usb-0:4.2.4
729+
730+
Arguments:
731+
- match (dict): key and value pairs for a udev match, see `udev Matching`_
732+
733+
Used by:
734+
- `SamsungUSBDriver`_
735+
718736
SunxiUSBLoader
719737
~~~~~~~~~~~~~~
720738
A :any:`SunxiUSBLoader` resource describes a USB device in the *Allwinner
@@ -767,6 +785,11 @@ NetworkRKUSBLoader
767785
A :any:`NetworkRKUSBLoader` describes an `RKUSBLoader`_ available on a remote
768786
computer.
769787

788+
NetworkSamsungUSBLoader
789+
~~~~~~~~~~~~~~~~~~~~~~~
790+
A :any:`NetworkSamsungUSBLoader` describes a `SamsungUSBLoader`_ available on a
791+
remote computer.
792+
770793
NetworkSunxiUSBLoader
771794
~~~~~~~~~~~~~~~~~~~~~
772795
A :any:`NetworkSunxiUSBLoader` describes a `SunxiUSBLoader`_ available on a
@@ -2563,6 +2586,47 @@ Arguments:
25632586
Tools:
25642587
- sunxi-fel: Path to the 'sunxi-fel' tool (default is 'sunxi-fel')
25652588

2589+
SamsungUSBDriver
2590+
~~~~~~~~~~~~~~~~
2591+
A :any:`SamsungUSBDriver` is used to upload an image into a device in the
2592+
*Samsung loader state*. This is useful to bootstrap a bootloader onto a device.
2593+
2594+
The load happens in three stages: BL1, SPL and U-Boot proper.
2595+
2596+
Binds to:
2597+
loader:
2598+
- `SamsungUSBLoader`_
2599+
- `NetworkSamsungUSBLoader`_
2600+
2601+
Implements:
2602+
- :any:`BootstrapProtocol`
2603+
2604+
.. code-block:: yaml
2605+
2606+
targets:
2607+
main:
2608+
drivers:
2609+
SamsungUSBDriver:
2610+
bl1: '/home/dev/exynos/snow/u-boot.bl1.bin'
2611+
bl1_loadaddr: 0x02021400
2612+
spl_loadaddr: 0x02023400
2613+
loadaddr: 0x43e00000
2614+
tools:
2615+
smdk-usbdl: '/home/dev/bin/smdk-usbdl'
2616+
2617+
Arguments:
2618+
- bl1 (str): Filename of the BL1 file which sets up the SoC
2619+
- bl1_loadaddr (int): Load address of the BL1 file. This depends on the SoC
2620+
spl_load_addr (int): Load address of SPL. The easiest way to find this value
2621+
is to check the *CONFIG_SPL_TEXT_BASE* value in U-Boot
2622+
- loadaddr (int): address to use when loading U-Boot. This depends on the
2623+
SoC being used. The easiest way to find this value is to check the
2624+
*CONFIG_TEXT_BASE* value in U-Boot
2625+
- image (str): Optional image filename
2626+
2627+
Tools:
2628+
- smdk-usbdl: Path to the 'smdk-usbdl' tool (default is 'smdk-usbdl')
2629+
25662630
TegraUSBDriver
25672631
~~~~~~~~~~~~~~
25682632
A :any:`TegraUSBDriver` is used to upload an image into a device in the

labgrid/driver/usbloader.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,67 @@ def load(self, filename=None, phase=None):
337337
@step()
338338
def execute(self):
339339
pass
340+
341+
342+
@target_factory.reg_driver
343+
@attr.s(eq=False)
344+
class SamsungUSBDriver(Driver, BootstrapProtocol):
345+
bindings = {
346+
'loader': {'SamsungUSBLoader', 'NetworkSamsungUSBLoader'},
347+
}
348+
349+
bl1 = attr.ib(validator=attr.validators.instance_of(str))
350+
bl1_loadaddr = attr.ib(validator=attr.validators.instance_of(int))
351+
spl_loadaddr = attr.ib(validator=attr.validators.instance_of(int))
352+
loadaddr = attr.ib(validator=attr.validators.instance_of(int))
353+
image = attr.ib(default=None)
354+
355+
def __attrs_post_init__(self):
356+
super().__attrs_post_init__()
357+
# FIXME make sure we always have an environment or config
358+
if self.target.env:
359+
self.tool = self.target.env.config.get_tool('smdk-usbdl')
360+
else:
361+
self.tool = 'smdk-usbdl'
362+
363+
def on_activate(self):
364+
pass
365+
366+
def on_deactivate(self):
367+
pass
368+
369+
@Driver.check_active
370+
@step(args=['filename'])
371+
def load(self, filename=None, phase=None):
372+
if filename is None and phase == 'bl1':
373+
filename = self.bl1
374+
if filename is None and self.image is not None:
375+
filename = self.target.env.config.get_image_path(self.image)
376+
mf = ManagedFile(filename, self.loader)
377+
mf.sync_to_resource()
378+
379+
if phase == 'bl1':
380+
addr = self.bl1_loadaddr
381+
elif phase == 'spl':
382+
addr = self.spl_loadaddr
383+
elif phase in (None, 'u-boot'):
384+
addr = self.loadaddr
385+
else:
386+
raise ValueError(f"Unknown phase '{phase}'")
387+
pathname = mf.get_remote_path()
388+
#time.sleep(0.5)
389+
390+
args = [self.tool, '-a', f'{addr:x}',
391+
'-b', f'{self.loader.busnum:03d}',
392+
'-d', f'{self.loader.devnum:03d}',
393+
'-f', pathname]
394+
395+
processwrapper.check_output(
396+
self.loader.command_prefix + args,
397+
#print_on_silent_log=True
398+
)
399+
400+
@Driver.check_active
401+
@step()
402+
def execute(self):
403+
pass

labgrid/remote/exporter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ def __attrs_post_init__(self):
543543
exports["IMXUSBLoader"] = USBGenericExport
544544
exports["MXSUSBLoader"] = USBGenericExport
545545
exports["RKUSBLoader"] = USBGenericExport
546+
exports["SamsungUSBLoader"] = USBGenericExport
546547
exports["SunxiUSBLoader"] = USBGenericExport
547548
exports["TegraUSBLoader"] = USBGenericExport
548549
exports["AlteraUSBBlaster"] = USBGenericExport

labgrid/resource/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
MatchedSysfsGPIO,
1919
MXSUSBLoader,
2020
RKUSBLoader,
21+
SamsungUSBLoader,
2122
SunxiUSBLoader,
2223
TegraUSBLoader,
2324
SiSPMPowerPort,

labgrid/resource/remote.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ def __attrs_post_init__(self):
166166
super().__attrs_post_init__()
167167

168168

169+
@target_factory.reg_resource
170+
@attr.s(eq=False)
171+
class NetworkSamsungUSBLoader(RemoteUSBResource):
172+
def __attrs_post_init__(self):
173+
self.timeout = 10.0
174+
super().__attrs_post_init__()
175+
176+
169177
@target_factory.reg_resource
170178
@attr.s(eq=False)
171179
class NetworkSunxiUSBLoader(RemoteUSBResource):

labgrid/resource/suggest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
USBSDWireDevice,
1717
AlteraUSBBlaster,
1818
RKUSBLoader,
19+
SamsungUSBLoader,
1920
SunxiUSBLoader,
2021
TegraUSBLoader,
2122
USBNetworkInterface,
@@ -52,6 +53,7 @@ def __init__(self, args):
5253
self.resources.append(USBSDWireDevice(**args))
5354
self.resources.append(AlteraUSBBlaster(**args))
5455
self.resources.append(RKUSBLoader(**args))
56+
self.resources.append(SamsungUSBLoader(**args))
5557
self.resources.append(SunxiUSBLoader(**args))
5658
self.resources.append(TegraUSBLoader(**args))
5759
self.resources.append(USBNetworkInterface(**args))

labgrid/resource/udev.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,17 @@ def filter_match(self, device):
317317

318318
return super().filter_match(device)
319319

320+
@target_factory.reg_resource
321+
@attr.s(eq=False)
322+
class SamsungUSBLoader(USBResource):
323+
def filter_match(self, device):
324+
match = (device.properties.get('ID_VENDOR_ID'), device.properties.get('ID_MODEL_ID'))
325+
326+
if match not in [("04e8", "1234")]:
327+
return False
328+
329+
return super().filter_match(device)
330+
320331
@target_factory.reg_resource
321332
@attr.s(eq=False)
322333
class SunxiUSBLoader(USBResource):

0 commit comments

Comments
 (0)