Skip to content

Commit f07a2d3

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 6050e51 commit f07a2d3

File tree

7 files changed

+111
-4
lines changed

7 files changed

+111
-4
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 io.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 io.c usb.c util.c ux.c
12+
RAMDUMP_SRCS := ramdump.c sahara.c io.c sim.c usb.c util.c ux.c
1313
RAMDUMP_OBJS := $(RAMDUMP_SRCS:.c=.o)
1414

1515
KS_OUT := ks

firehose.c

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

151+
/* In simulation mode we don't expent to read and parse any responses */
152+
if (qdl->dev_type == QDL_DEVICE_SIM)
153+
return 0;
154+
151155
do {
152156
n = qdl_read(qdl, buf, sizeof(buf), 100);
153157
if (n < 0) {
@@ -300,7 +304,12 @@ static int firehose_configure(struct qdl_device *qdl, bool skip_storage_init, co
300304
return -1;
301305
}
302306

303-
max_payload_size = size;
307+
/*
308+
* Simulated target doesn't provide any valid payload size, so
309+
* for QDL_DEVICE_SIM dev type we keep old max_payload_size value
310+
*/
311+
if (qdl->dev_type != QDL_DEVICE_SIM)
312+
max_payload_size = size;
304313
}
305314

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

io.c

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ struct qdl_device *qdl_init(enum QDL_DEVICE_TYPE type)
3535
if (type == QDL_DEVICE_USB)
3636
return usb_init();
3737

38+
if (type == QDL_DEVICE_SIM)
39+
return sim_init();
40+
3841
return NULL;
3942
}
4043

qdl.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static void print_usage(void)
102102
{
103103
extern const char *__progname;
104104
fprintf(stderr,
105-
"%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",
106106
__progname);
107107
}
108108

@@ -133,6 +133,7 @@ int main(int argc, char **argv)
133133
{"serial", required_argument, 0, 'S'},
134134
{"storage", required_argument, 0, 's'},
135135
{"allow-missing", no_argument, 0, 'f'},
136+
{"dry-run", no_argument, 0, 'n'},
136137
{0, 0, 0, 0}
137138
};
138139

@@ -141,6 +142,9 @@ int main(int argc, char **argv)
141142
case 'd':
142143
qdl_debug = true;
143144
break;
145+
case 'n':
146+
qdl_dev_type = QDL_DEVICE_SIM;
147+
break;
144148
case 'v':
145149
print_version();
146150
return 0;

qdl.h

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
enum QDL_DEVICE_TYPE
1414
{
1515
QDL_DEVICE_USB,
16+
QDL_DEVICE_SIM,
1617
};
1718

1819
struct qdl_device
@@ -44,6 +45,11 @@ struct qdl_device_usb
4445
size_t out_chunk_size;
4546
};
4647

48+
struct qdl_device_sim
49+
{
50+
struct qdl_device base;
51+
};
52+
4753
struct qdl_device *qdl_init(enum QDL_DEVICE_TYPE type);
4854
void qdl_deinit(struct qdl_device *qdl);
4955
int qdl_open(struct qdl_device *qdl, const char *serial);
@@ -53,6 +59,7 @@ int qdl_write(struct qdl_device *qdl, const void *buf, size_t len);
5359
void qdl_set_out_chunk_size(struct qdl_device *qdl, long size);
5460

5561
struct qdl_device *usb_init(void);
62+
struct qdl_device *sim_init(void);
5663

5764
int firehose_run(struct qdl_device *qdl, const char *incdir, const char *storage, bool allow_missing);
5865
int sahara_run(struct qdl_device *qdl, char *img_arr[], bool single_image,

sahara.c

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

441+
/*
442+
* Don't need to do anything in simulation mode with Sahara,
443+
* we care only about Firehose protocol
444+
*/
445+
if (qdl->dev_type == QDL_DEVICE_SIM)
446+
return 0;
447+
441448
if (ramdump_path) {
442449
ramdump_dir = open(ramdump_path, O_DIRECTORY);
443450
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)