Skip to content

Commit 9ecd150

Browse files
committed
qdl: add support for dry run execution
This mode assists in validating the `rawprogram_.xml` and `patch_.xml` files, as well as the Firehose commands that are expected to be sent to the Firehose programmer. Dry run implementation is also expected to be extended for the Digests Table generation required for Firehose Validated Image Programming (VIP). Example of usage: $ qdl --dry-run --serial=0AA94EFD --debug prog_firehose_ddr.elf rawprogram*.xml patch*.xml qdl version v2.1-24-g30ac3a8-dirty This is a dry-run execution of QDL. No actual flashing has been performed waiting for programmer... FIREHOSE WRITE: <?xml version="1.0"?> <data><configure MemoryName="ufs" MaxPayloadSizeToTargetInBytes="1048576" verbose="0" ZLPAwareHost="1" SkipStorageInit="0"/></data> FIREHOSE WRITE: <?xml version="1.0"?> <data><configure MemoryName="ufs" MaxPayloadSizeToTargetInBytes="0" verbose="0" ZLPAwareHost="1" SkipStorageInit="0"/></data> accepted max payload size: 0 FIREHOSE WRITE: <?xml version="1.0"?> <data><program SECTOR_SIZE_IN_BYTES="4096" num_partition_sectors="131072" physical_partition_number="0" start_sector="6" filename="efi.bin"/></data> Signed-off-by: Igor Opaniuk <[email protected]>
1 parent 30ac3a8 commit 9ecd150

File tree

9 files changed

+270
-40
lines changed

9 files changed

+270
-40
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ CFLAGS += -O2 -Wall -g `pkg-config --cflags libxml-2.0 libusb-1.0`
66
LDFLAGS += `pkg-config --libs libxml-2.0 libusb-1.0`
77
prefix := /usr/local
88

9-
QDL_SRCS := firehose.c qdl.c sahara.c util.c patch.c program.c read.c ufs.c usb.c ux.c
9+
QDL_SRCS := firehose.c io.c qdl.c sahara.c util.c patch.c program.c read.c sim.c ufs.c usb.c ux.c
1010
QDL_OBJS := $(QDL_SRCS:.c=.o)
1111

12-
RAMDUMP_SRCS := ramdump.c sahara.c usb.c util.c ux.c
12+
RAMDUMP_SRCS := ramdump.c sahara.c io.c usb.c sim.c util.c ux.c
1313
RAMDUMP_OBJS := $(RAMDUMP_SRCS:.c=.o)
1414

1515
KS_OUT := ks

firehose.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ static int firehose_read(struct qdl_device *qdl, int timeout_ms,
148148
gettimeofday(&now, NULL);
149149
timeradd(&now, &delta, &timeout);
150150

151+
if (qdl->dev_type == QDL_DEVICE_SIM)
152+
return 0;
153+
151154
do {
152155
n = qdl_read(qdl, buf, sizeof(buf), 100);
153156
if (n < 0) {
@@ -300,7 +303,8 @@ static int firehose_configure(struct qdl_device *qdl, bool skip_storage_init, co
300303
return -1;
301304
}
302305

303-
max_payload_size = size;
306+
if (qdl->dev_type == QDL_DEVICE_USB)
307+
max_payload_size = size;
304308
}
305309

306310
ux_debug("accepted max payload size: %zu\n", max_payload_size);

io.c

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2025, Qualcomm Innovation Center, Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
*
7+
* 1. Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimer.
9+
*
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
*
14+
* 3. Neither the name of the copyright holder nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include "qdl.h"
32+
33+
struct qdl_device *qdl_init(enum QDL_DEVICE_TYPE type)
34+
{
35+
if (type == QDL_DEVICE_USB)
36+
return usb_init();
37+
38+
if (type == QDL_DEVICE_SIM)
39+
return sim_init();
40+
41+
return NULL;
42+
}
43+
44+
void qdl_deinit(struct qdl_device *qdl)
45+
{
46+
if (qdl)
47+
free(qdl);
48+
}
49+
50+
void qdl_set_out_chunk_size(struct qdl_device *qdl, long size)
51+
{
52+
qdl->set_out_chunk_size(qdl, size);
53+
}
54+
55+
int qdl_open(struct qdl_device *qdl, const char *serial)
56+
{
57+
return qdl->open(qdl, serial);
58+
}
59+
60+
void qdl_close(struct qdl_device *qdl)
61+
{
62+
qdl->close(qdl);
63+
}
64+
65+
int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout)
66+
{
67+
return qdl->read(qdl, buf, len, timeout);
68+
}
69+
70+
int qdl_write(struct qdl_device *qdl, const void *buf, size_t len)
71+
{
72+
return qdl->write(qdl, buf, len);
73+
}

qdl.c

+24-9
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ enum {
5555
};
5656

5757
bool qdl_debug;
58-
static struct qdl_device qdl;
5958

6059
static int detect_type(const char *xml_file)
6160
{
@@ -103,7 +102,7 @@ static void print_usage(void)
103102
{
104103
extern const char *__progname;
105104
fprintf(stderr,
106-
"%s [--debug] [--version] [--allow-missing] [--storage <emmc|nand|ufs>] [--finalize-provisioning] [--include <PATH>] [--serial <NUM>] [--out-chunk-size <SIZE>] <prog.mbn> [<program> <patch> ...]\n",
105+
"%s [--debug] [--dry-run] [--version] [--allow-missing] [--storage <emmc|nand|ufs>] [--finalize-provisioning] [--include <PATH>] [--serial <NUM>] [--out-chunk-size <SIZE>] <prog.mbn> [<program> <patch> ...]\n",
107106
__progname);
108107
}
109108

@@ -121,7 +120,9 @@ int main(int argc, char **argv)
121120
int opt;
122121
bool qdl_finalize_provisioning = false;
123122
bool allow_missing = false;
124-
long out_chunk_size;
123+
long out_chunk_size = 0;
124+
struct qdl_device *qdl = NULL;
125+
enum QDL_DEVICE_TYPE qdl_dev_type = QDL_DEVICE_USB;
125126

126127
static struct option options[] = {
127128
{"debug", no_argument, 0, 'd'},
@@ -132,6 +133,7 @@ int main(int argc, char **argv)
132133
{"serial", required_argument, 0, 'S'},
133134
{"storage", required_argument, 0, 's'},
134135
{"allow-missing", no_argument, 0, 'f'},
136+
{"dry-run", no_argument, 0, 'n'},
135137
{0, 0, 0, 0}
136138
};
137139

@@ -140,6 +142,9 @@ int main(int argc, char **argv)
140142
case 'd':
141143
qdl_debug = true;
142144
break;
145+
case 'n':
146+
qdl_dev_type = QDL_DEVICE_SIM;
147+
break;
143148
case 'v':
144149
print_version();
145150
return 0;
@@ -154,7 +159,6 @@ int main(int argc, char **argv)
154159
break;
155160
case OPT_OUT_CHUNK_SIZE:
156161
out_chunk_size = strtol(optarg, NULL, 10);
157-
qdl_set_out_chunk_size(&qdl, out_chunk_size);
158162
break;
159163
case 's':
160164
storage = optarg;
@@ -174,6 +178,15 @@ int main(int argc, char **argv)
174178
return 1;
175179
}
176180

181+
qdl = qdl_init(qdl_dev_type);
182+
if (!qdl) {
183+
ret = -1;
184+
goto out_cleanup;
185+
}
186+
187+
if (out_chunk_size)
188+
qdl_set_out_chunk_size(qdl, out_chunk_size);
189+
177190
ux_init();
178191

179192
if (qdl_debug)
@@ -213,23 +226,25 @@ int main(int argc, char **argv)
213226
}
214227
} while (++optind < argc);
215228

216-
ret = qdl_open(&qdl, serial);
229+
ret = qdl_open(qdl, serial);
217230
if (ret)
218231
goto out_cleanup;
219232

220-
qdl.mappings[0] = prog_mbn;
221-
ret = sahara_run(&qdl, qdl.mappings, true, NULL, NULL);
233+
qdl->mappings[0] = prog_mbn;
234+
ret = sahara_run(qdl, qdl->mappings, true, NULL, NULL);
222235
if (ret < 0)
223236
goto out_cleanup;
224237

225-
ret = firehose_run(&qdl, incdir, storage, allow_missing);
238+
ret = firehose_run(qdl, incdir, storage, allow_missing);
226239
if (ret < 0)
227240
goto out_cleanup;
228241

229242
out_cleanup:
230-
qdl_close(&qdl);
243+
qdl_close(qdl);
231244
free_programs();
232245
free_patches();
233246

247+
qdl_deinit(qdl);
248+
234249
return !!ret;
235250
}

qdl.h

+42-9
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,63 @@
88
#include "read.h"
99
#include <libxml/tree.h>
1010

11+
#define container_of(ptr, typecast, member) ({ \
12+
void *_ptr = (void *)(ptr); \
13+
((typecast *)(_ptr - offsetof(typecast, member))); })
14+
1115
#define MAPPING_SZ 64
1216

17+
enum QDL_DEVICE_TYPE
18+
{
19+
QDL_DEVICE_USB,
20+
QDL_DEVICE_SIM,
21+
};
22+
23+
struct qdl_device
24+
{
25+
enum QDL_DEVICE_TYPE dev_type;
26+
int fd;
27+
28+
int (*open)(struct qdl_device *qdl, const char *serial);
29+
int (*read)(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout);
30+
int (*write)(struct qdl_device *qdl, const void *buf, size_t nbytes);
31+
void (*close)(struct qdl_device *qdl);
32+
void (*set_out_chunk_size)(struct qdl_device *qdl, long size);
33+
34+
char *mappings[MAPPING_SZ]; // array index is the id from the device
35+
};
36+
1337
struct libusb_device_handle;
1438

15-
struct qdl_device {
16-
struct libusb_device_handle *usb_handle;
17-
int fd;
39+
struct qdl_device_usb
40+
{
41+
struct qdl_device base;
42+
struct libusb_device_handle *usb_handle;
1843

19-
int in_ep;
20-
int out_ep;
44+
int in_ep;
45+
int out_ep;
2146

22-
size_t in_maxpktsize;
23-
size_t out_maxpktsize;
24-
size_t out_chunk_size;
47+
size_t in_maxpktsize;
48+
size_t out_maxpktsize;
49+
size_t out_chunk_size;
50+
};
2551

26-
char *mappings[MAPPING_SZ]; // array index is the id from the device
52+
struct qdl_device_sim
53+
{
54+
struct qdl_device base;
2755
};
2856

57+
struct qdl_device *qdl_init(enum QDL_DEVICE_TYPE type);
58+
void qdl_deinit(struct qdl_device *qdl);
2959
int qdl_open(struct qdl_device *qdl, const char *serial);
3060
void qdl_close(struct qdl_device *qdl);
3161
int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout);
3262
int qdl_write(struct qdl_device *qdl, const void *buf, size_t len);
3363
void qdl_set_out_chunk_size(struct qdl_device *qdl, long size);
3464

65+
struct qdl_device *usb_init(void);
66+
struct qdl_device *sim_init(void);
67+
3568
int firehose_run(struct qdl_device *qdl, const char *incdir, const char *storage, bool allow_missing);
3669
int sahara_run(struct qdl_device *qdl, char *img_arr[], bool single_image,
3770
const char *ramdump_path, const char *ramdump_filter);

ramdump.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ static void print_usage(void)
1818

1919
int main(int argc, char **argv)
2020
{
21-
struct qdl_device qdl;
21+
struct qdl_device_usb qdl;
22+
qdl.base.dev_type = QDL_DEVICE_USB;
23+
2224
char *ramdump_path = ".";
2325
char *filter = NULL;
2426
char *serial = NULL;
@@ -61,11 +63,11 @@ int main(int argc, char **argv)
6163
if (qdl_debug)
6264
print_version();
6365

64-
ret = qdl_open(&qdl, serial);
66+
ret = qdl_open(&qdl.base, serial);
6567
if (ret)
6668
return 1;
6769

68-
ret = sahara_run(&qdl, NULL, true, ramdump_path, filter);
70+
ret = sahara_run(&qdl.base, NULL, true, ramdump_path, filter);
6971
if (ret < 0)
7072
return 1;
7173

sahara.c

+3
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ int sahara_run(struct qdl_device *qdl, char *img_arr[], bool single_image,
438438
bool done = false;
439439
int n;
440440

441+
if (qdl->dev_type == QDL_DEVICE_SIM)
442+
return 0;
443+
441444
if (ramdump_path) {
442445
ramdump_dir = open(ramdump_path, O_DIRECTORY);
443446
if (ramdump_dir < 0)

sim.c

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2025, Qualcomm Innovation Center, Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
*
7+
* 1. Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimer.
9+
*
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
*
14+
* 3. Neither the name of the copyright holder nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
#include <string.h>
31+
32+
#include "qdl.h"
33+
34+
static int sim_open(struct qdl_device *qdl, const char *serial)
35+
{
36+
ux_info("This is a dry-run execution of QDL. No actual flashing has been performed\n");
37+
38+
return 0;
39+
}
40+
41+
static void sim_close(struct qdl_device *qdl)
42+
{
43+
return;
44+
}
45+
46+
static int sim_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout)
47+
{
48+
return len;
49+
}
50+
51+
static int sim_write(struct qdl_device *qdl, const void *buf, size_t len)
52+
{
53+
return len;
54+
}
55+
56+
static void sim_set_out_chunk_size(struct qdl_device *qdl, long size)
57+
{
58+
return;
59+
}
60+
61+
struct qdl_device *sim_init(void)
62+
{
63+
struct qdl_device *qdl = malloc(sizeof(struct qdl_device_sim));
64+
if (!qdl)
65+
return NULL;
66+
67+
memset(qdl, 0, sizeof(struct qdl_device_sim));
68+
69+
qdl->dev_type = QDL_DEVICE_SIM;
70+
qdl->open = sim_open;
71+
qdl->read = sim_read;
72+
qdl->write = sim_write;
73+
qdl->close = sim_close;
74+
qdl->set_out_chunk_size = sim_set_out_chunk_size;
75+
76+
return qdl;
77+
}

0 commit comments

Comments
 (0)