48 Commits

Author SHA1 Message Date
Neil Armstrong
30c30ce84c Merge pull request #86 from lumag/laurent-usb
laurent: add support for controlling USB power
2025-03-18 09:32:35 +01:00
Dmitry Baryshkov
bad935cbf2 device: support PPPS in parallel with the driver's USB control
Don't make PPPS path exclusive to the driver USB control. Allow both to
be used at the same time in case the setup uses both PPPS-hubs and
driver-specific control.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2025-02-21 19:17:01 +02:00
Stephan Gerhold
3922dc793a cdba: Add keys to remotely press power or fastboot key
Add special keys to allow triggering power and fastboot key presses from
the cdba client. There is an option to send a short key "pulse" (press
followed by release after 100ms) or to press/release keys separately:

 - ctrl+a -> o: Send power key pulse
 - ctrl+a -> O: Toggle power key (first use: press, next use: release)
 - ctrl+a -> f: Send fastboot key pulse
 - ctrl+a -> F: Toggle fastboot key (first use: press, next use: release)

In most cases you want to send the "pulse" (short key press), so it's
helpful to have this mapped to a single key. This avoids forgetting to
release the key again after pressing it.

The protocol between CDBA client and server is:

 (MSG_KEY_PRESS <key:u8, state:u8>)

where key is either DEVICE_KEY_FASTBOOT (0) or DEVICE_KEY_POWER (1)
and state is either KEY_PRESS_RELEASE (0), KEY_PRESS_PRESS (1) or
KEY_PRESS_PULSE (2).

The reason for implementing the "pulse" on the server side is that it's
hard to guarantee the timing on the client side. We don't know exactly when
the packets will arrive on the server. Also, "state" is a full byte anyway,
so might as well use some of the extra bits. :-)
2025-02-14 10:35:27 +01:00
Dmitry Baryshkov
5db3df360a device: loop around flock/warn
Loop around the flock(), sleeping in the middle. This allows CDBA to
break early if user closes the terminal (by killing SSH or by Ctrl-A-Q
sequence).

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2024-05-31 16:57:14 +03:00
Dmitry Baryshkov
ca5f95d6cd cdba-power: add power-on/-off tool
Add simple tool reusing CDBA code to power boards on and off.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2024-03-30 18:06:19 +02:00
Dmitry Baryshkov
762879fd0c device: add support for leaving device powered
For some devices it might be desirable to leave device powered on after
the cdba exits (e.g. to run some long-running tests). Add the
'power_always_on' option that tells cdba server to leave device powered
on after exiting and to toggle power (to reset the device) when
connecting.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2024-03-30 18:06:19 +02:00
Dmitry Baryshkov
62dc594cb1 device: split fastboot_open from device_open
Create new function calling fastboot_open so that device_open doesn't
have dependency on the fastboot_ops or udev.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2024-03-30 18:06:19 +02:00
Dmitry Baryshkov
f6bd2d01d7 watch: split implementation to aseparate file
Split CDBA's watching code to a separate file.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2024-03-30 18:06:19 +02:00
Dmitry Baryshkov
bde90b4a15 cdba: replace licence headers with SPDX identifiers
Replace all license headers with the SPDX-License-Identitier headers to
follow the current recommendations.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2024-03-30 18:06:19 +02:00
Bryan O'Donoghue
30e6838a12 cdba-server: Implement fastboot continue
Add cdba-server side support for "fastboot continue" which allows
fastboot to continue its default boot process.

I find it useful to setup my boards with an additional SD card which I
frequently use the default image on eMMC to chroot to and populate
modules, rebooting into fastboot and subsequently booting via fastboot
a rootfs on the SD card.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
2024-01-17 02:08:44 +00:00
Dmitry Baryshkov
43ed93357d cdba-server: add syslog support
Log messages to the syslog when the user opens a board.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-11-29 15:22:26 +02:00
Bjorn Andersson
cc91b34f3a device: Disable USB on boot
Leaving USB connected might cause hickups on the USB bus, and causes
power measurements to report incorrect data. Turn it off once the image
has been downloaded.

Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
2023-11-27 21:19:57 -06:00
Bjorn Andersson
81e46878ed cdba-server: Allow external status command
While the CDB Assist and QcomLT Debugboard is measuring voltage and
current on the DC jack directly in the backend, other backends and
further measurements can be performed using custom tooling.

Introduce support for invoking an external "status-cmd" to produce such
status updates.

The status command should on its stdout produce json-formatted status
updates following the same format as the cdba-server:

  {"ts":%d.%03d, "name": {["mv"|"ma"]: %u}(, "name2": {["mv"|"ma"]: %u})*}

with the ts aquired using clock_gettime(CLOCK_MONOTONIC) and provided in
seconds and milliseconds since the first measurement.

Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
2023-11-27 21:19:57 -06:00
Bjorn Andersson
0a3d51e9c8 cdba-server: Repurpose status update request
The MSG_STATUS_UPDATE message when sent from the client to the server,
has until now indicated a request for a single status update. This was
suitable when the update was for human consumption on occasional basis.

But with the transition to producing status messages for programatical
consumption it makes more sense to just keep the stream on, without the
client having to poll the server for updates. This can in particular
keep the external "status command" mechanism simpler.

Just enabling the stream of status updates would spam the console with
status updates for those users that hasn't updated their clients, so the
client needs to opt-in to the status stream.

Repurpose the status update message (sent from the client) to indicate
that the streaming of status updates should be enabled.

Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
2023-11-27 21:19:54 -06:00
Dmitry Baryshkov
3b089f313e device: separate backend operations
Separate backend operations into control and console operations. Main
idea is that each device has single set of console ops (conmux or
console) and at most one way to control it. Each backend driver exports
a structure with the set of callbacks.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-10-02 17:33:10 +03:00
Dmitry Baryshkov
fb23cabbc4 device: change device_usb logic
Allow PPPS function even if there is no device->usb callback. PPPS is
useable even with no control interface.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-10-02 17:32:13 +03:00
Dmitry Baryshkov
771910e186 cdba-server: extract message-sending helper
Instad of hand-coding message sending, create a single wrapper that
sends messages to the client.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-09-29 00:45:25 +03:00
Caleb Connolly
d36097392e device: add fcntl.h for musl
Musl requires that this header be explicitly included for O_CREAT,
O_CLOEXEC, etc.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
2023-09-28 11:09:46 +01:00
Caleb Connolly
91daddcb7c support ppps usb control
Since Linux kernel 6.0, PPPS capable USB hubs expose a simple sysfs
attribute for power control. Allow overwriting the usb control callback
to use PPPS hub control instead.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
2023-09-28 11:09:46 +01:00
Dmitry Baryshkov
3ea8df6c70 device: implement access control to the boards
Limit access control to the boards according to the passed username. If
the user has no access, the board becoms completely invisible: it is not
listed, it is not possible to fetch board description, etc.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-09-23 16:50:11 +03:00
Dmitry Baryshkov
327da0b5b5 device: support specifying active slot
For different reasons it might be desirable to keep slot 'b' as an
active slot. Add support for specifying the active slot in the config
file. The default is still slot 'a'.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-09-21 13:35:04 +03:00
Krzysztof Kozlowski
044be470d2 device: fix -Wsign-compare
Code should avoid comparing signed and unsigned integers, because of
implicit case.  Explicit casts are safe because 'lock' size is PATH_MAX.

  device.c: In function ‘device_lock’:
  device.c:64:15: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
     64 |         if (n >= sizeof(lock))
        |               ^~

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
2023-05-08 15:02:37 -05:00
Dmitry Baryshkov
961792677a device: notify before booting the board
Transfering the image to cdba server takes time (especially when working
with over the network). Notify users before actually booting the board
to ease detecting early boot issues.

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
2022-02-08 09:09:13 -08:00
Bjorn Andersson
6fbc50ca58 device: Hack around EPERM issue
Opening the lock files fails on one of my boards if the files exists and
are owned by someone else, if O_CREAT is set. This doesn't make sense,
but hack around it for now by first creating the file if it's not there,
ignoring any errors and then just opening it O_RDONLY.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-10-05 10:41:48 -07:00
Bjorn Andersson
3004fdf68d device: Reintroduce the alpaca "keep-usb-on" feature
For some reason the SC8180x Primus often fails to detect the attached
USB stick if USB is toggled as part of a power cycle, so let's continue
to support the property of not toggling it.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-02-22 11:02:57 -06:00