Skip to content

Commit e3da70f

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 <igor.opaniuk@oss.qualcomm.com>
1 parent 30ac3a8 commit e3da70f

File tree

9 files changed

+263
-33
lines changed

9 files changed

+263
-33
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ static int firehose_read(struct qdl_device *qdl, int timeout_ms,
159159
}
160160
buf[n] = '\0';
161161

162+
if (qdl->dev_type == QDL_DEVICE_SIM) {
163+
ret = 0;
164+
break;
165+
}
166+
162167
ux_debug("FIREHOSE READ: %s\n", buf);
163168

164169
node = firehose_response_parse(buf, n, &error);
@@ -409,6 +414,11 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
409414
goto out;
410415
}
411416

417+
if (qdl->dev_type == QDL_DEVICE_SIM) {
418+
ret = FIREHOSE_ACK;
419+
goto out;
420+
}
421+
412422
t0 = time(NULL);
413423

414424
lseek(fd, (off_t) program->file_offset * program->sector_size, SEEK_SET);

io.c

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

qdl.c

Lines changed: 24 additions & 9 deletions
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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,59 @@
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

13-
struct libusb_device_handle;
17+
enum QDL_DEVICE_TYPE {
18+
QDL_DEVICE_USB,
19+
QDL_DEVICE_SIM,
20+
};
1421

1522
struct qdl_device {
16-
struct libusb_device_handle *usb_handle;
23+
enum QDL_DEVICE_TYPE dev_type;
1724
int fd;
1825

26+
int (*open)(struct qdl_device *qdl, const char *serial);
27+
int (*read)(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout);
28+
int (*write) (struct qdl_device *qdl, const void *buf, size_t nbytes);
29+
void (*close)(struct qdl_device *qdl);
30+
void (*set_out_chunk_size)(struct qdl_device *qdl, long size);
31+
32+
char *mappings[MAPPING_SZ]; // array index is the id from the device
33+
};
34+
35+
struct libusb_device_handle;
36+
37+
struct qdl_device_usb {
38+
struct qdl_device base;
39+
struct libusb_device_handle *usb_handle;
40+
1941
int in_ep;
2042
int out_ep;
2143

2244
size_t in_maxpktsize;
2345
size_t out_maxpktsize;
2446
size_t out_chunk_size;
47+
};
2548

26-
char *mappings[MAPPING_SZ]; // array index is the id from the device
49+
struct qdl_device_sim {
50+
struct qdl_device base;
2751
};
2852

53+
struct qdl_device *qdl_init(enum QDL_DEVICE_TYPE type);
54+
void qdl_deinit(struct qdl_device *qdl);
2955
int qdl_open(struct qdl_device *qdl, const char *serial);
3056
void qdl_close(struct qdl_device *qdl);
3157
int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout);
3258
int qdl_write(struct qdl_device *qdl, const void *buf, size_t len);
3359
void qdl_set_out_chunk_size(struct qdl_device *qdl, long size);
3460

61+
struct qdl_device *usb_init(void);
62+
struct qdl_device *sim_init(void);
63+
3564
int firehose_run(struct qdl_device *qdl, const char *incdir, const char *storage, bool allow_missing);
3665
int sahara_run(struct qdl_device *qdl, char *img_arr[], bool single_image,
3766
const char *ramdump_path, const char *ramdump_filter);

ramdump.c

Lines changed: 5 additions & 3 deletions
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

Lines changed: 3 additions & 0 deletions
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

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

0 commit comments

Comments
 (0)