Skip to content

Commit

Permalink
driver/usbloader: Add a loader for samsung
Browse files Browse the repository at this point in the history
Add a USB loader for samsung, supporting BL1, SPL and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>
  • Loading branch information
sjg20 committed Aug 22, 2024
1 parent 2dcbcfb commit 1678bad
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 0 deletions.
64 changes: 64 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,24 @@ Arguments:
Used by:
- `RKUSBDriver`_

SamsungUSBLoader
~~~~~~~~~~~~~~~~
A :any:`SamsungUSBLoader` resource describes a USB device in the *Samsung
loader state*.

.. code-block:: yaml
SamsungUSBLoader:
## hub d4
match:
ID_PATH: pci-0000:03:00.2-usb-0:4.2.4
Arguments:
- match (dict): key and value pairs for a udev match, see `udev Matching`_

Used by:
- `SamsungUSBDriver`_

SunxiUSBLoader
~~~~~~~~~~~~~~
A :any:`SunxiUSBLoader` resource describes a USB device in the *Allwinner
Expand Down Expand Up @@ -767,6 +785,11 @@ NetworkRKUSBLoader
A :any:`NetworkRKUSBLoader` describes an `RKUSBLoader`_ available on a remote
computer.

NetworkSamsungUSBLoader
~~~~~~~~~~~~~~~~~~~~~~~
A :any:`NetworkSamsungUSBLoader` describes a `SamsungUSBLoader`_ available on a
remote computer.

NetworkSunxiUSBLoader
~~~~~~~~~~~~~~~~~~~~~
A :any:`NetworkSunxiUSBLoader` describes a `SunxiUSBLoader`_ available on a
Expand Down Expand Up @@ -2563,6 +2586,47 @@ Arguments:
Tools:
- sunxi-fel: Path to the 'sunxi-fel' tool (default is 'sunxi-fel')

SamsungUSBDriver
~~~~~~~~~~~~~~~~
A :any:`SamsungUSBDriver` is used to upload an image into a device in the
*Samsung loader state*. This is useful to bootstrap a bootloader onto a device.

The load happens in three stages: BL1, SPL and U-Boot proper.

Binds to:
loader:
- `SamsungUSBLoader`_
- `NetworkSamsungUSBLoader`_

Implements:
- :any:`BootstrapProtocol`

.. code-block:: yaml
targets:
main:
drivers:
SamsungUSBDriver:
bl1: '/home/dev/exynos/snow/u-boot.bl1.bin'
bl1_loadaddr: 0x02021400
spl_loadaddr: 0x02023400
loadaddr: 0x43e00000
tools:
smdk-usbdl: '/home/dev/bin/smdk-usbdl'
Arguments:
- bl1 (str): Filename of the BL1 file which sets up the SoC
- bl1_loadaddr (int): Load address of the BL1 file. This depends on the SoC
spl_load_addr (int): Load address of SPL. The easiest way to find this value
is to check the *CONFIG_SPL_TEXT_BASE* value in U-Boot
- loadaddr (int): address to use when loading U-Boot. This depends on the
SoC being used. The easiest way to find this value is to check the
*CONFIG_TEXT_BASE* value in U-Boot
- image (str): Optional image filename

Tools:
- smdk-usbdl: Path to the 'smdk-usbdl' tool (default is 'smdk-usbdl')

TegraUSBDriver
~~~~~~~~~~~~~~
A :any:`TegraUSBDriver` is used to upload an image into a device in the
Expand Down
64 changes: 64 additions & 0 deletions labgrid/driver/usbloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,67 @@ def load(self, filename=None, phase=None):
@step()
def execute(self):
pass


@target_factory.reg_driver
@attr.s(eq=False)
class SamsungUSBDriver(Driver, BootstrapProtocol):
bindings = {
'loader': {'SamsungUSBLoader', 'NetworkSamsungUSBLoader'},
}

bl1 = attr.ib(validator=attr.validators.instance_of(str))
bl1_loadaddr = attr.ib(validator=attr.validators.instance_of(int))
spl_loadaddr = attr.ib(validator=attr.validators.instance_of(int))
loadaddr = attr.ib(validator=attr.validators.instance_of(int))
image = attr.ib(default=None)

def __attrs_post_init__(self):
super().__attrs_post_init__()
# FIXME make sure we always have an environment or config
if self.target.env:
self.tool = self.target.env.config.get_tool('smdk-usbdl')
else:
self.tool = 'smdk-usbdl'

def on_activate(self):
pass

def on_deactivate(self):
pass

@Driver.check_active
@step(args=['filename'])
def load(self, filename=None, phase=None):
if filename is None and phase == 'bl1':
filename = self.bl1
if filename is None and self.image is not None:
filename = self.target.env.config.get_image_path(self.image)
mf = ManagedFile(filename, self.loader)
mf.sync_to_resource()

if phase == 'bl1':
addr = self.bl1_loadaddr
elif phase == 'spl':
addr = self.spl_loadaddr
elif phase in (None, 'u-boot'):
addr = self.loadaddr
else:
raise ValueError(f"Unknown phase '{phase}'")
pathname = mf.get_remote_path()
#time.sleep(0.5)

args = [self.tool, '-a', f'{addr:x}',
'-b', f'{self.loader.busnum:03d}',
'-d', f'{self.loader.devnum:03d}',
'-f', pathname]

processwrapper.check_output(
self.loader.command_prefix + args,
#print_on_silent_log=True
)

@Driver.check_active
@step()
def execute(self):
pass
1 change: 1 addition & 0 deletions labgrid/remote/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ def __attrs_post_init__(self):
exports["IMXUSBLoader"] = USBGenericExport
exports["MXSUSBLoader"] = USBGenericExport
exports["RKUSBLoader"] = USBGenericExport
exports["SamsungUSBLoader"] = USBGenericExport
exports["SunxiUSBLoader"] = USBGenericExport
exports["TegraUSBLoader"] = USBGenericExport
exports["AlteraUSBBlaster"] = USBGenericExport
Expand Down
1 change: 1 addition & 0 deletions labgrid/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
MatchedSysfsGPIO,
MXSUSBLoader,
RKUSBLoader,
SamsungUSBLoader,
SunxiUSBLoader,
TegraUSBLoader,
SiSPMPowerPort,
Expand Down
8 changes: 8 additions & 0 deletions labgrid/resource/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ def __attrs_post_init__(self):
super().__attrs_post_init__()


@target_factory.reg_resource
@attr.s(eq=False)
class NetworkSamsungUSBLoader(RemoteUSBResource):
def __attrs_post_init__(self):
self.timeout = 10.0
super().__attrs_post_init__()


@target_factory.reg_resource
@attr.s(eq=False)
class NetworkSunxiUSBLoader(RemoteUSBResource):
Expand Down
2 changes: 2 additions & 0 deletions labgrid/resource/suggest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
USBSDWireDevice,
AlteraUSBBlaster,
RKUSBLoader,
SamsungUSBLoader,
SunxiUSBLoader,
TegraUSBLoader,
USBNetworkInterface,
Expand Down Expand Up @@ -52,6 +53,7 @@ def __init__(self, args):
self.resources.append(USBSDWireDevice(**args))
self.resources.append(AlteraUSBBlaster(**args))
self.resources.append(RKUSBLoader(**args))
self.resources.append(SamsungUSBLoader(**args))
self.resources.append(SunxiUSBLoader(**args))
self.resources.append(TegraUSBLoader(**args))
self.resources.append(USBNetworkInterface(**args))
Expand Down
11 changes: 11 additions & 0 deletions labgrid/resource/udev.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,17 @@ def filter_match(self, device):

return super().filter_match(device)

@target_factory.reg_resource
@attr.s(eq=False)
class SamsungUSBLoader(USBResource):
def filter_match(self, device):
match = (device.properties.get('ID_VENDOR_ID'), device.properties.get('ID_MODEL_ID'))

if match not in [("04e8", "1234")]:
return False

return super().filter_match(device)

@target_factory.reg_resource
@attr.s(eq=False)
class SunxiUSBLoader(USBResource):
Expand Down
4 changes: 4 additions & 0 deletions man/labgrid-device-config.5
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ See: \fI\%https://git.tizen.org/cgit/tools/testlab/sd\-mux/\fP
Path to the sispmctl binary, used by the SiSPMPowerDriver.
See: \fI\%https://sispmctl.sourceforge.net/\fP
.TP
.B \fBsmdk\-usbdl\fP
Path to the smdk\-usbdl binary, used by the SamsungUSBDriver.
See: \fI\%http://www.fluff.org/ben/smdk/tools\fP
.TP
.B \fBsunxi\-fel\fP
Path to the sunxi\-fel binary, used by the SunxiUSBDriver.
See: \fI\%https://linux\-sunxi.org/FEL\fP
Expand Down
4 changes: 4 additions & 0 deletions man/labgrid-device-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ TOOLS KEYS
Path to the sispmctl binary, used by the SiSPMPowerDriver.
See: https://sispmctl.sourceforge.net/

``smdk-usbdl``
Path to the smdk-usbdl binary, used by the SamsungUSBDriver.
See: http://www.fluff.org/ben/smdk/tools

``sunxi-fel``
Path to the sunxi-fel binary, used by the SunxiUSBDriver.
See: https://linux-sunxi.org/FEL
Expand Down

0 comments on commit 1678bad

Please sign in to comment.