Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usbsdmux support #402

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ config CONSOLE_VARIANT
string "Console variant"
default "qemu"
help
Select a shared storage variant from 'docker', 'qemu', 'samsung'
and 'usbf'.
Select a shared storage variant from 'docker', 'qemu', 'samsung',
'usbsdmux' and 'usbf'.
endmenu

menu "Video Settings"
Expand Down
19 changes: 17 additions & 2 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ General settings
selected with ``variant``.

* ``variant``: string [required]
Select a shared storage variant from ``docker``, ``qemu``, ``samsung``
and ``usbf``.
Select a shared storage variant from ``docker``, ``qemu``, ``samsung``,
``usbsdmux`` and ``usbf``.

* ``usb``: section [optional]
Specify how many USB ports may be controlled from this agent.
Expand Down Expand Up @@ -388,6 +388,21 @@ a SD card between the DUT and host. The following settings are supported:
Identifier of the sdmux/sdwire device to use. Use ``sd-mux-ctrl`` to list
available devices. When not specified, the first device is auto-detected.

``usbsdmux`` driver settings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``usbsdmux`` driver supports SD card switcher based on the Microchip
USB2642 card reader chip. A tool with this name is available for several
distributions and via pip. The following settings are supported:

* ``device``: string [optional]
Block device for the shared storage as seen on the host (defaults to
``/dev/sda``)

* ``control-device``: string [optional]
Control device used for talking to the switcher on the host (defaults to
``/dev/sg0``)

``usbf`` driver settings
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
1 change: 1 addition & 0 deletions meta-isar/recipes-core/images/mtda-image.bb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ IMAGE_PREINSTALL += " \
ssh \
sudo \
systemd-timesyncd \
usbsdmux \
vim \
wireless-regdb \
wireless-tools \
Expand Down
1 change: 1 addition & 0 deletions mtda.ini
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ variant=aviosys_8800
# - docker
# - qemu
# - samsung
# - usbsdmux
# - usbf
# ---------------------------------------------------------------------------
# Note: this section is ignored when connecting to a remote agent
Expand Down
2 changes: 1 addition & 1 deletion mtda/storage/qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def configure(self, conf):
self.mtda.debug(3, "storage.qemu.configure()")
self.lock.acquire()

result = None
result = True
if 'file' in conf:
self.file = os.path.realpath(conf['file'])
d = os.path.dirname(self.file)
Expand Down
114 changes: 114 additions & 0 deletions mtda/storage/usbsdmux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# ---------------------------------------------------------------------------
# Storage driver for usbsdmux on MTDA
# ---------------------------------------------------------------------------
#
# This software is a part of MTDA.
# Copyright (C) 2024 Siemens AG
#
# ---------------------------------------------------------------------------
# SPDX-License-Identifier: MIT
# ---------------------------------------------------------------------------

# System imports
import subprocess

# Local imports
import mtda.constants as CONSTS
from mtda.storage.helpers.image import Image


class UsbSdMuxStorageController(Image):

def __init__(self, mtda):
super().__init__(mtda)
self.file = "/dev/sda"
self.control_device = "/dev/sg0"

""" Configure this storage controller from the provided configuration"""
def configure(self, conf):
self.mtda.debug(3, "storage.usbsdmux.configure()")

result = True
if 'device' in conf:
self.file = conf['device']
if 'control-device' in conf:
self.control_device = conf['control-device']
self.mtda.debug(3, f"storage.usbsdmux.configure(): {str(result)}")
return result

""" Check presence of the sdmux"""
def probe(self):
self.mtda.debug(3, "storage.usbsdmux.probe()")

result = True
try:
subprocess.check_output([
"usbsdmux", self.control_device, "get"
])
except subprocess.CalledProcessError:
result = False

self.mtda.debug(3, f"storage.usbsdmux.probe(): {str(result)}")
return result

""" Attach the SD card to the host"""
def to_host(self):
self.mtda.debug(3, "storage.usbsdmux.to_host()")

result = True
try:
subprocess.check_output([
"usbsdmux", self.control_device, "host"
])
except subprocess.CalledProcessError:
result = False

self.mtda.debug(3, f"storage.usbsdmux.to_host(): {str(result)}")
return result

""" Attach the SD card to the target"""
def to_target(self):
self.mtda.debug(3, "storage.usbsdmux.to_target()")
self.lock.acquire()

result = self._close()
if result is True:
result = self._umount()
if result is True:
try:
subprocess.check_output([
"usbsdmux", self.control_device, "dut"
])
except subprocess.CalledProcessError:
result = False

self.mtda.debug(3, f"storage.usbsdmux.to_target(): {str(result)}")
self.lock.release()
return result

""" Determine where is the SD card attached"""
def _status(self):
self.mtda.debug(3, "storage.usbsdmux.status()")

try:
status = subprocess.check_output([
"usbsdmux", self.control_device, "get"
]).decode("utf-8").splitlines()
result = CONSTS.STORAGE.UNKNOWN
for s in status:
if s == "host":
result = CONSTS.STORAGE.ON_HOST
break
elif s == "dut":
result = CONSTS.STORAGE.ON_TARGET
break
except subprocess.CalledProcessError:
self.mtda.debug(1, "storage.usbsdmux.status(): usbsdmux failed!")
result = CONSTS.STORAGE.UNKNOWN

self.mtda.debug(3, f"storage.usbsdmux.status(): {str(result)}")
return result


def instantiate(mtda):
return UsbSdMuxStorageController(mtda)
Loading