71 Commits

Author SHA1 Message Date
Igor Opaniuk
d192ab7e1a qdl: fix resource leaks in programmer image decoding
On error, decode_programmer_archive() and decode_sahara_config() leak
both the input blob and any images partially loaded before the failure.

Fix by extending their error paths to call sahara_images_free() and
free the blob, mirroring the cleanup already done on success. Also
introduce sahara_images_free() to consolidate teardown, drop the
misleading 'const' from sahara_image.name, and release sahara_images
in qdl_flash() on all exit paths.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
2026-02-24 11:31:41 +01:00
Bjorn Andersson
7fd466c95e qdl: Propagate the success of decode_sahara_config()
Commit '44e7be00aca0 ("sahara: Drop "single image" concept")' cleaned up
the handling of programmer selection, but in the new flow failed to
propagate the successful decoding of the sahara_config.

Fixes: 44e7be00ac ("sahara: Drop "single image" concept")
Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2026-02-04 14:37:38 -06:00
Bjorn Andersson
f60f2bde70 qdl: Refactor main()
Rather than mixing subcommands and the default "flash" operation, split
the flashing mechanism out into its own subcommand function to clean up
the main function.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2026-02-02 12:23:24 -06:00
Bjorn Andersson
156d9673a2 ramdump: Provide some user feedback
Dumping all the DDR takes significant time and there's currently no
user-visible feedback provided to indicate that even the process has
started.

Solve this by wiring up the ux module and provide a progress bar while
dumping segments, as well as information as the segments are skipped or
dumped.

Add missing ux_init() to the ramdump setup, and make sure to clamp value
to max in the progress calculation, to avoid funky issues when progress
is made beyond the size of the chunk.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2026-02-02 12:23:24 -06:00
Bjorn Andersson
ff1a3bb1d3 ramdump: Make ramdump a qdl subcommand
Providing qdl-ramdump as a separate executable has resulted in it not
being part of several of the distributions that include qdl. Also, users
that knows that qdl supports ramdumps are looking for it "in" qdl, not a
related tool.

Make "ramdump" a subcommand, just like "qdl list", to improve the
ergonomics of the tool.

The implementation is a (almost) verbatim copy of ramdump.c. The
existing executable is kept in order to not break those distributions
that explicitly do package said executable.
At some point we should figure out how to drop this.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2026-02-02 12:23:24 -06:00
Bjorn Andersson
44e7be00ac sahara: Drop "single image" concept
The Sahara implementation was written without understanding of the
special meaning of image id #13. As the implementation grew support for
multiple images the special casing of "single image" was introduced, and
this spread to the calling bodies.

Prior to the introduction of multi-programmer platforms this didn't
matter, the logic was fairly simple and usage was straight forward.

But when a single programmer image is provided on a multi-programmer
target "single_image" is true and hence the image id is ignored on the
first read, the one provided file is loaded. The typical outcome is that
the following SAHARA_END_OF_IMAGE_CMD fails with a message stating
"non-successful end-of-image result".

Few users draws the conclusion that this is because they didn't provide
the appropriate programmers.

But 13 is the image id for the programmer, so it should be fine to drop
the special logic. This results in a (somewhat) more helpful error
message telling the user that an invalid image is being requested.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2026-02-02 09:44:25 -06:00
lucarin91
f32f5ebe9f usb: add support for listing devices
When working with multiple devices and the --serial argument, the serial
numbers must be known.

Add a new command "qdl list" to list the connected devices in EDL mode
and their serial number.

Signed-off-by: lucarin91 <lucarin@protonmail.com>
[bjorn: Replaced --list with list, changed output to only print serial, some stylistic changes]
Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2026-02-02 09:02:58 -06:00
Bjorn Andersson
aa77dfc23e qdl: Allow absolute paths in Windows again
Commit '5b768d8be070 ("qdl: Allow multiple Sahara images")' introduced
support for specifying multiple programmer images, by splitting the
requested programmer on ':'-character and use the pair as id and
filename specifiers. This obviously breaks absolute paths in Windows.

Reorder the programmer decoder such that if the specifier starts with an
id followed by a ':', then the specifier must be a comma-separated list
of id:filename (where ',' is not allowed in the filename).

In all other cases consider the whole specifier the one file to use as
programmer, programmer archive, or programmer specifier XML. This brings
back the ability to specify programmer by absolute path in Windows.

The parsing of the programmer specifier is also altered to not tokenize
on ':' but instead only find the first one and then treat the rest as
the filename. This makes it possible use absolute paths here as well.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2026-01-27 13:34:34 -06:00
Jacob Creedon
a3ec7fd90b firehose: Add slot flag
For SoCs that support multiple UFS devices, firehose allows the slot property. This adds a flag to set the slot parameter.

Signed-off-by: Jacob Creedon <jcreedon@gmail.com>
2025-11-26 11:03:19 -08:00
Bjorn Andersson
406ede8e14 qdl: Also support Sahara config XML documents
Flattened METAs contains the relevant programmer files, as well as a
special "sahara_config" XML file, which specifies the Sahara images and
their image ids.

Support populating the Sahara images array from this XML file as well,
to make it easy to flash this type of builds.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2025-11-18 15:10:03 -06:00
Bjorn Andersson
4bdcaaec1a qdl: Support for "programmer archives"
Providing a long list of Sahara image ids and their respective payload
filename is cumbersome and error prone.

Introduce support for loading a "programmer archive", a CPIO archive
containing the list of Sahara images. The Sahara image id is read from
the filename of each file in the archive, and should be provided in the
form "<id>[:<filename>]".

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2025-11-18 15:10:03 -06:00
Bjorn Andersson
5b768d8be0 qdl: Allow multiple Sahara images
Some newer targets, such as Kaanapali, is requesting multiple images
from Sahara on the path to reach Firehose mode.

Extend the handling of the "programmer" argument to allow specifying a
comma-separated, colon-separated list of "<id>:<filename>" entries, to
specify the filenames for each of the image ids to be provided.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2025-11-18 14:49:58 -06:00
Bjorn Andersson
ff260604e7 sahara: Load programmer at parse time
Lugging around the filename of the to-be-loaded Sahara image(s) prevents
us from (in a later patch) load the programmer payload from an archive.

So move the loading of the specified programmer image(s) to parse time
and hold each one in memory instead.

While doing this, move the "mappings" array (i.e. the list of Sahara
images) to the stack instead, as it was already being passed as a
parameter to the relevant function(s).

sahara_run() is also extended to provide debug information about which
images are being presented to the device.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2025-11-18 14:49:54 -06:00
Bjorn Andersson
57910d9696 qdl: Be explicit about storage types
Rather than accepting an arbitrary string for "storage type", pass this
through a variety of strcmp() and then passing it verbatim to
<configure>, define the supported storage types, decode the passed
value, and clean up the various checks.

While doing so, extend the help text to document that we do support both
"nand" and "spinor" (the latter with some trouble).

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2025-11-11 09:09:38 -06:00
Bjorn Andersson
5449037f1c ufs: Extract provisioning from firehose_run()
firehose_run() is clearly sequential, except if UFS provisioning is
taken place, then it's a completely different sequence and an early
return - almost like it's two separate functions crammed into one.

Split firehose_provision() from firehose_run() and make the decision in
qdl.c instead.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2025-09-17 09:24:55 -05:00
Bjorn Andersson
ccc1b6835b qdl: Fail fast when programmer is unavailable
Having the tool fail due to missing images before we establish the USB
connection turns out to be rather nice, so let's do the same thing with
the flash programmer.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2025-09-12 10:36:09 -05:00
Bjorn Andersson
3eb702d950 Move check for missing files to load time
Rather than letting the flash process get halfway through before
aborting for missing files, check that files are available while loading
the program xml files, before we start talking to the device.

In addition to a better user experience, this helps cleaning up the
upcoming change where sparse files are parsed at load time as well.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2025-09-12 10:36:09 -05:00
Bjorn Andersson
35b46a0e5e Resolve include dir at load time
Rather than waiting until program and read time to resolve the include
path, adjust the filename paths while we're parsing the XML tags.

This simplifies the execution step slightly, but more importantly it
allow us to also apply the missing-files check at load time in an
upcoming commit.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2025-09-12 10:36:09 -05:00
Bjorn Andersson
dad8b4802d qdl: Document the newly introduced read and write commands
Add documentation and usage for the newly introduced read and write
commands.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2025-09-09 16:18:12 -05:00
Bjorn Andersson
dff2ed7a72 qdl: Add "read" and "write" commands
There are a number of scenarios where one just want to write a binary
file directly to some specific location on the target, such as writing a
full disk image to LUN 0. Similarily (although not as frequent) one just
want to dump a few sectors of data for inspection.

So far the recommended way to do this has been to craft a program.xml
or a read.xml file and feed to QDL, but this is annoying.

Add support for writing/reading binary data straight to/from the device
by the means of just specifying the "write" or "read" commands on the
QDL commandline, e.g.:

  qdl prog_firehose.elf write 0 debian.img

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2025-09-09 16:18:12 -05:00
Igor Opaniuk
a691179284 qdl: improve usage output
Prettify usage details and introduce explicit -h param:

Usage: qdl [options] <prog.mbn> [<program> <patch> ...]
 -d, --debug			Print detailed debug info
 -v, --version			Print the current version and exit
 -n, --dry-run			Dry run execution, no device reading or flashing
 -f, --allow-missing		Allow skipping of missing files during flashing
 -s, --storage=T		Set target storage type T: <emmc|nand|ufs>
 -l, --finalize-provisioning	Provision the target storage
 -i, --include=T		Set an optional folder T to search for files
 -S, --serial=T			Select target by serial number T (e.g. <0AA94EFD>)
 -u, --out-chunk-size=T		Override chunk size for transaction with T
 -t, --create-digests=T		Generate table of digests in the T folder
 -D, --vip-table-path=T		Use digest tables in the T folder for VIP
 -h, --help			Print this usage info

Example: qdl prog_firehose_ddr.elf rawprogram*.xml patch*.xml

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
2025-06-24 14:26:14 +02:00
Igor Opaniuk
c70255e3e8 qdl: fix provided options to getopt_long
Fix list of provided command-line options to getopt_long() for parsing.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
2025-06-24 14:26:14 +02:00
Igor Opaniuk
7a8b6f3115 qdl: drop enum for chunk size param
Drop enum definition for chunk size parameter.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
2025-06-24 14:26:14 +02:00
Igor Opaniuk
8818b98e85 firehose: support VIP extension
This extends the Firehose protocol implementation to support the VIP
extension. It implements a state machine that counts the number of
packets sent, then injects the VIP table as the next RAW packet when
the Firehose programmer runs out of provided digests and needs a new table
of digests to validate the next packets. For example:

Packet 0: DigestsTableToSign.bin.mbn (53 digest + 1 digest of next table)
Packet 1: <configure>
Packet 2: <program>
Packet 3: ...
...
Packet 54: ChainedTableOfDigests0.bin (255 digests + digest of next table)
Packet 55: <program>
...
Packet 309: ChainedTableOfDigests1.bin

To enable VIP extension provide a path where previously generated VIP
tables are stored using "--vip-table-path" param:

$ qdl --vip-table-path "<vip-table-path>" prog_firehose_ddr.elf \
  rawprogram*.xml patch*.xml

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
2025-06-24 14:26:14 +02:00
Igor Opaniuk
cdcdc51a3d checkpatch: address all obvious issues
Address all obvious coding style issues caught by checkpatch.pl tool.
sha2.c and sha2.h were kept as there are.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
2025-06-21 21:32:25 +02:00