Commit Graph
53 Commits
Author SHA1 Message Date
Bjorn Andersson 23688db35a doc: document the nbdkit plugin
The nbdkit plugin is undiscoverable without documentation. Describe how to
build it with meson (including the nbdkit development dependency) and walk
through serving a LUN end to end: starting nbdkit, confirming the export
with nbdinfo, attaching it to /dev/nbdN with nbd-client, and reading it,
plus a warning that writes go straight to the device's flash.

The walkthrough lives in docs/nbd.md to keep the ever growing README lean;
the README gets a short section pointing to it, and the markdown-lint
wrapper now lints everything under docs/ so future documents are covered
automatically.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
2026-07-17 09:42:05 +02:00
Bjorn Andersson 16ca90ba9a nbdkit: add qdl plugin exposing a LUN as a block device
Inspecting or editing a device's flash previously meant dumping partitions
to files and reflashing them; there was no way to treat the live storage as
a random-access block device. Exposing a LUN over nbdkit lets ordinary host
tools - parted, mount, dd, imaging tools - operate on it directly.

Add an nbdkit plugin that uploads the firehose programmer and serves a
physical partition (LUN) as a read/write block device:

$ modprobe nbd
$ nbdkit -fv ./nbdkit-qdl-plugin.so programmer=prog_firehose_ddr.elf lun=0

meson builds it only when the nbdkit dependency is present (pass
-Dnbdkit=enabled to require it), producing nbdkit-qdl-plugin.so from the
shared qdl sources; the qdl binary is unaffected.

An EDL device can only be programmed once per session - uploading the
programmer is a one-shot transition and a reset reboots it out of firehose
- but nbdkit calls .open/.close several times per client (NBD_OPT_INFO to
probe, then NBD_OPT_GO to transfer). Programming per open and resetting per
close therefore made the first close reboot the board and every later open
time out. To solve this the plugin sets the device up once, on the first
open, keeps it configured across connections, and resets it only when the
plugin unloads.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
2026-07-17 09:36:28 +02:00
Bjorn Andersson a8f21545f0 firehose: add block-level read/write/size interface
The firehose layer only drives file-oriented flashing: <program>/<read>
operations described by XML and executed as an op list. Nothing let an
in-process consumer configure the programmer on its own, learn how large a
LUN is, or read and write arbitrary sector ranges to and from memory
buffers.

The upcoming nbdkit plugin needs exactly that - random-access block I/O
against a live device - so add the missing primitives:

  - firehose_open()    configure the programmer without running any ops
  - firehose_getsize() report a LUN's sector size and count, parsed from
                       the <getstorageinfo> JSON response
  - firehose_pread()   read a sector range into a buffer, reusing the
                       chunked read path
  - firehose_pwrite()  write a buffer to a sector range, streaming it in
                       max_payload_size chunks
  - firehose_reset()   made non-static, out-of-tree callers can reuse it

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
2026-07-17 09:34:14 +02:00
Bjorn Andersson 0fcf944ab5 makefile: Use pkg-config instead of xml2-config
Per user request, use pkg-config instead of xml2-config when generating
cflags and ldflags.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-11-10 09:44:50 -06:00
Bjorn Andersson 13681fcb35 firehose: Make "start_sector" a string again
Assumed to be a remnant of early development lead to a recent transition
of "start_sector" from being represented as a string to an integer. But
it turns out that "start_sector" might be an expression, e.g. to write
something at the end of the disk.

So transition back to carry "start_sector" as a string.

Fixes: b6e0ea31d7 ("program: Make start_sector unsigned in")
Reported-by: Julien Robin
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-04-29 10:25:55 -05:00
Bjorn Andersson 650b477ca5 firehose: Drain logs on write timeout
On db410c writes sometimes fails becasue the device had more log entries
to read after the <response> and refuses writes until these are drained.

Deal with this by attempting a read when write fails with a timeout.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-04-15 21:52:00 -05:00
Bjorn Andersson 00d93b29f5 firehose: Rework firehose_read
WIth the transition from qcserial to USBFS we no longer receive multiple
messages in a single read, so we can remove the code that decode the
buffer piecemeal.

While reworking this, also introduce a mechanism so that the parsers can
pass values back to the caller of the read.

And modify the timeout handling so that the caller always has to pass a
timeout, and bump the timeouts slightly, as they are all fatal anyways.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-04-15 21:49:16 -05:00
Bjorn Andersson 7f75f17c53 fixup! program: Make start_sector unsigned in 2021-04-15 21:15:36 -05:00
Bjorn Andersson 40df480740 usb: Drop ununsed eot argument to qdl_write
qdl_write() is always called with eot=true, so drop the parameter.

As a length of 0 means we're not entering the loop and we're now always
entering the conditonal block at the end we can remove the first chunk.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-04-15 17:42:06 -05:00
Bjorn Andersson 91e609b611 usb: Drop unwanted debug print
A stray print can sometimes be seen from the udev code, drop it.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-04-15 14:23:49 -05:00
Bjorn Andersson da8dd7139a program: Introduce erase tag support
NAND based devices comes with a few minor tweaks to the program tag and
an additional erase tag, split the program code and add the handling of
the erase tag.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-04-15 14:22:15 -05:00
Bjorn Andersson b6e0ea31d7 program: Make start_sector unsigned in
For unknown reasons start_sector was a staring, turn it into an unsigned
integer instead.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-04-15 14:20:41 -05:00
Bjorn Andersson 56076936a6 firehose: Revamp read timeout handling
Remove the dummy sleep and reliance on USB read timeout while waiting
for the firehose payload to launch by rolling our own timeout handling
in firehose_read. While at it extend the firehose program timeouts, to
avoid issues seen when these operations for some reason takes a little
bit longer to return.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-04-15 14:15:43 -05:00
Bjorn Andersson bead963d33 usb: Recognize SDX55
The SDX55 shows up with bInterfaceProtocol of 17, so allow this to get
past the USB filtering routine.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-04-15 12:00:44 -05:00
Bjorn Andersson 7623ff5e1e firehose: Wait 3 seconds for payload to boot
The downstream tool has a 3 second delay to allow the firehose payload
to boot. Adding the same makes db820c successfully enter firehose mode.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-04-30 11:27:17 -07:00
Bjorn Andersson fd48f7ce18 firehose: Lower the initial read timeout
Upon booting the firehose payload some platforms will issue log messages
others won't. Rather than waiting for 10 seconds on the ones that
doesn't wait only for a second.

Hopefully this is long enough, but the firmware synchronization and
handling of incoming log messages should be reviewed further.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-02-27 15:25:34 -08:00
Bjorn Andersson 90d3a6fee6 firehose: Remove unused firehose_nop()
We don't send any NOP requests, so remove this function for now.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-02-27 15:17:52 -08:00
Bjorn Andersson 1c958b2bc2 usb: Silence usb helpers
It's perfectly normal to "poll" for incoming messages, so silence the
warning printout in the usb accessor functions.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-02-27 15:08:02 -08:00
Bjorn Andersson 5ec4f210a0 firehose: Continue reading log entries after response
On db410c the target sends log entries after the response and refuse to
serve any subsequent requests until these are consumed, so continue
reading log entries until we get a timeout.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-02-27 15:06:32 -08:00
Bjorn Andersson 8456cb2cf5 program: Correct a/b XBL match
A full build will contain both xbl_a and xbl_b, so matching on the
prefix of "xbl" will find two entries which we consider invalid.
Explicitly search for "xbl_a" instead.

Fixes: 5ea1e20c01 ("program: Match xbl in a/b scenarios")
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-02-27 09:10:12 -08:00
Bjorn Andersson 8589513f65 qdl: Wait for missing EDL device
Add support back for waiting for an EDL device to appear. This is useful
when paired with some automation scripts that introduces "arbitrary"
delays in the process of entering EDL mode.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-01-07 21:20:25 -08:00
Bjorn Andersson ba86b03391 qdl: Remove debug print for claim return code
The USB claim return code was printed to the console for debug purposes,
remove this.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-01-07 21:05:47 -08:00
Bjorn Andersson 59717efcd4 firehose: Remove unnecessary nop request
The nop was added to mitigate the fact that there's a rather long delay
in the response when sending out the first command. Increasing the write
timeout removes this problem and it's possible to just send the
configure as the first command without issues.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-01-07 21:00:42 -08:00
Bjorn Andersson 5ea1e20c01 program: Match xbl in a/b scenarios
On devices implementing a/b updates the xbl partiiton will be named
xbl_a and xbl_b, extend the match for finding the bootable partition to
support this.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-01-07 16:41:39 -08:00
Bjorn Andersson 826a5cd4fd firehose: Send ZLP after each chunk
It was assumed that we should send all the data following a "program"
request to the device, before sending a ZLP. But on SDM845 it's seen
that not sending a ZLP after each chunk sometimes causes the
communication to stall.

Given that the "program" request already carries the information about
how much data will be transferred there should be no issues with sending
additional ZLPs, so do this.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-01-07 16:36:54 -08:00
Bjorn Andersson 8f7987f756 qdl: Communicate using USBFS instead of qcserial
On some newer platforms the device ignore the configure request to
disable ZLP, causing the Firehose program request to stall, when the
device is waiting for a ZLP to end a transfer.

Mitigate this by circumventing the qcserial driver and drive the USB
traffic directly using USBFS. The tool will attempt to detach qcserial
from the device, in case it's already attached, so no changes are needed
in the kernel or system configuration.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-01-07 16:36:50 -08:00
Bjorn Andersson 44a80b1266 qdl: Remove possibility for uninitialized variable
In the case that we find a "data" tag, but not a "program" or "ufs"
child node type might have been left unitialized. Fix this by
initializing type.

Also fix up the styling of the multiline blocks.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-02-21 22:36:03 -08:00
Bjorn Andersson 0251833b4d program: Skip entries without a valid filename
Follow the behavior of the other flash tools and skip partitions with no
filename, instead of filling them with zeros. This reduces the flash
time considerably for some set of xml files.

Also clean up firehose_program() as we no longer need to support calling
this function with an invalid fd.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-11-29 21:13:10 -08:00
Bjorn Andersson febbbcc32e firehose: Negotiate max payload size
When the host propose a larger payload size than the device accepts the
device will respond with a NACK, containing the maximum payload size.
Similarily the ACK will contain the supported max if the host requests a
lower value than the device supports.

In both cases we pick the largest possible value and send a second
configure message to select this payload size.

Reported-by: Kirill Kapranov <c_kkapra@qti.qualcomm.com>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-11-29 13:24:29 -08:00
Bjorn Andersson 4a72fc8723 firehose: Read back max payload size
The max payload size is negotiated through the configure and configure
response messages. Update the max payload size based on the
configuration response value, if present.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-11-28 20:33:45 -08:00
Bjorn Andersson 4c2ea2c10c firehose: Don't pad partitions with zeros
During program it's recommended to reduce the num_sectors to only cover
the sectors containing data to be written and not write zero-block in
the rest. This reduce the time spent sending unnecessary blocks of
zeros.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-11-28 19:06:51 -08:00
Bjorn Andersson 4922fdffbf firehose: Write max_payload_size chunks at a time
Reduce the number of write operations by batching up sectors in a
max_payload_size sized buffer and write them in one chunk. Using the
qcserial driver will still chop up the USB traffic in 4kB chunks, so no
measurable perfomance improvement is seen.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-11-28 18:58:42 -08:00
Bjorn Andersson 34a47b4d29 firehose: Bump max payload size config parameter
The MaxPayloadSizeToTargetInBytes parameter of the configure command is
supposed to set the maximum size of the transfer unit. This size is
however limited by the use of the in-kernel qcserial driver and the use
of sector-sized writes. Yet increasing it, drastically bumps the
transfer speed, so leave it high.

NB. The max payload size supported by the device is part of the
configure response, if the device supports a value less than the
requested size - which we just ignore today.

Suggested-by: Kirill Kapranov <c_kkapra@qti.qualcomm.com>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-11-28 17:40:24 -08:00
Bjorn Andersson c4852c48bf firehose: Inform about flash speed
To aid fixing performance problems, calculate and print out the program
rate.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-11-28 17:40:24 -08:00
Bjorn Andersson 0793d016cd firehose: Set bootable device based on xbl/sbl1
This bootable device is not always partition number 1. Search the
program entries for an entry that has the label xbl or sbl1 and use the
partition number to mark the boot partition bootable.

Reported-by: Kirill Kapranov <kkapra@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-11-06 23:25:33 -08:00
Bjorn Andersson 25157ae50d sahara: Ignore DONE response code
The DONE message contains a return code denoting if the firmware is done
(1) requesting files from the host, or if there are more requests to
come (0). Unfortunately on some platforms the ROM code sends 0
regardless, so we just have to assume that we're done.

This assumes that there is only ever one image to transfer.

Reported-by: Kirill Kapranov <kkapra@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-11-06 23:05:10 -08:00
Bjorn Andersson 6edc9372f0 Makefile: implement GNU Coding Standard for Makefiles
GNU coding standards notably specifies:
 * install files with the $(DESTDIR) to the target system image
 * install files with the $(prefix), not $(PREFIX)
 * the default value of $(prefix) should be /usr/local

as per
https://www.gnu.org/prep/standards/html_node/Directory-Variables.html.

Suggested-by: Kirill Kapranov <kkapra@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-11-06 22:55:11 -08:00
Bjorn Andersson 02659d718f Add LICENSE file
Merge license headers into the LICENSE file.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-10-04 19:33:09 -07:00
Bjorn Andersson 4c4dbd0317 qdl: Increase tty path buffer size
Rename "buf" to "path" to clarify things and increase the size to
PATH_MAX in order to silence a compile time warning the snprintf() in
find_qdl_tty() might be truncated.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-08-24 21:04:49 -07:00
Bjorn Andersson 2944120b10 sahara: Compare, don't assign in assert
Two assert incorrectly assigned the desired values rather than verify
that they where correct, fix this.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-08-24 14:36:00 -07:00
Bjorn Andersson 8f36c1e659 qdl: Remove unused functions
Remove some left over functions from development, they can be added back
as needed in the future.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-08-24 14:34:35 -07:00
Bjorn Andersson 4081f059c1 program: Drop readback from parser
Not all program XML tags contain the readback attribute and as we don't
care about the value at this point lets just stop caring about it for
now.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-08-24 14:32:14 -07:00
Bjorn Andersson 0bb387615b qdl: Update README and add license header
This adds a license header to all files and updates the README with
information on building the project.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-07-24 23:46:13 -07:00
Bjorn Andersson c93907cfae qdl: Support multi-xml responses
Unsolicited log messages are put in the device buffer as independant xml
documents and upon reading the response packet we might get a multiple
of xml documents in one go; we must feed them to the parser one by one.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2016-09-23 15:11:14 -07:00
Bjorn Andersson a29f44cc07 qdl: Make failed program or patch operation stop execution
Failures to apply program or patch operations are silently ignored,
forcing the user to inspect the logs to conclude if the flashing
succeded. Instead make the operations halt execution.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2016-09-21 11:55:16 -07:00
Bjorn Andersson 63f64d0bbf qdl: Print error message on firehose_write errors
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2016-09-21 11:48:44 -07:00
Bjorn Andersson 1611c78335 qdl: Add --debug for dumping firehose traffic
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2016-07-27 13:09:16 -07:00
Bjorn Andersson 0a0580cff5 qdl: Correct spelling of "data" and add "contents"
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2016-07-08 16:08:46 -07:00
Bjorn Andersson 1a0e6a51d9 qdl: Add README
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2016-07-08 11:51:45 -07:00
Bjorn Andersson 4c8ba17cbc qdl: Detect xml file type and simplify usage
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2016-07-08 11:47:58 -07:00
Bjorn Andersson e72a9a1135 qdl: Add gitignore
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2016-07-08 11:27:19 -07:00
Bjorn Andersson da68b4add8 qdl: Support for program and patch
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2016-07-08 11:26:26 -07:00
Bjorn Andersson 3d3b9645de Initial commit 2016-02-25 14:00:08 -08:00