Skip to content

Commit 672abb1

Browse files
igoropaniukkonradybcio
authored andcommitted
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 f066304 commit 672abb1

File tree

7 files changed

+112
-4
lines changed

7 files changed

+112
-4
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 io.c qdl.c sahara.c util.c patch.c program.c read.c ufs.c usb.c ux.c oscompat.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 oscompat.c
1010
QDL_OBJS := $(QDL_SRCS:.c=.o)
1111

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

1515
KS_OUT := ks

firehose.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ static int firehose_read(struct qdl_device *qdl, int timeout_ms,
146146
gettimeofday(&now, NULL);
147147
timeradd(&now, &delta, &timeout);
148148

149+
/* In simulation mode we don't expent to read and parse any responses */
150+
if (qdl->dev_type == QDL_DEVICE_SIM)
151+
return 0;
152+
149153
do {
150154
n = qdl_read(qdl, buf, sizeof(buf), 100);
151155
if (n <= 0) {
@@ -298,7 +302,12 @@ static int firehose_configure(struct qdl_device *qdl, bool skip_storage_init, co
298302
return -1;
299303
}
300304

301-
max_payload_size = size;
305+
/*
306+
* Simulated target doesn't provide any valid payload size, so
307+
* for QDL_DEVICE_SIM dev type we keep old max_payload_size value
308+
*/
309+
if (qdl->dev_type != QDL_DEVICE_SIM)
310+
max_payload_size = size;
302311
}
303312

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

io.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ struct qdl_device *qdl_init(enum QDL_DEVICE_TYPE type)
3636
if (type == QDL_DEVICE_USB)
3737
return usb_init();
3838

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

qdl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static void print_usage(void)
107107
{
108108
extern const char *__progname;
109109
fprintf(stderr,
110-
"%s [--debug] [--version] [--allow-missing] [--storage <emmc|nand|ufs>] [--finalize-provisioning] [--include <PATH>] [--serial <NUM>] [--out-chunk-size <SIZE>] <prog.mbn> [<program> <patch> ...]\n",
110+
"%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",
111111
__progname);
112112
}
113113

@@ -140,6 +140,7 @@ int main(int argc, char **argv)
140140
{"storage", required_argument, 0, 's'},
141141
{"allow-missing", no_argument, 0, 'f'},
142142
{"allow-fusing", no_argument, 0, 'c'},
143+
{"dry-run", no_argument, 0, 'n'},
143144
{0, 0, 0, 0}
144145
};
145146

@@ -148,6 +149,9 @@ int main(int argc, char **argv)
148149
case 'd':
149150
qdl_debug = true;
150151
break;
152+
case 'n':
153+
qdl_dev_type = QDL_DEVICE_SIM;
154+
break;
151155
case 'v':
152156
print_version();
153157
return 0;

qdl.h

Lines changed: 2 additions & 0 deletions
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
@@ -40,6 +41,7 @@ int qdl_write(struct qdl_device *qdl, const void *buf, size_t len);
4041
void qdl_set_out_chunk_size(struct qdl_device *qdl, long size);
4142

4243
struct qdl_device *usb_init(void);
44+
struct qdl_device *sim_init(void);
4345

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

sahara.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,13 @@ int sahara_run(struct qdl_device *qdl, char *img_arr[], bool single_image,
469469
bool done = false;
470470
int n;
471471

472+
/*
473+
* Don't need to do anything in simulation mode with Sahara,
474+
* we care only about Firehose protocol
475+
*/
476+
if (qdl->dev_type == QDL_DEVICE_SIM)
477+
return 0;
478+
472479
while (!done) {
473480
n = qdl_read(qdl, buf, sizeof(buf), 1000);
474481
if (n < 0)

sim.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 <stdlib.h>
31+
#include <string.h>
32+
33+
#include "qdl.h"
34+
35+
struct qdl_device_sim
36+
{
37+
struct qdl_device base;
38+
};
39+
40+
static int sim_open(struct qdl_device *qdl, const char *serial)
41+
{
42+
ux_info("This is a dry-run execution of QDL. No actual flashing has been performed\n");
43+
44+
return 0;
45+
}
46+
47+
static void sim_close(struct qdl_device *qdl)
48+
{
49+
return;
50+
}
51+
52+
static int sim_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout)
53+
{
54+
return len;
55+
}
56+
57+
static int sim_write(struct qdl_device *qdl, const void *buf, size_t len)
58+
{
59+
return len;
60+
}
61+
62+
static void sim_set_out_chunk_size(struct qdl_device *qdl, long size)
63+
{
64+
return;
65+
}
66+
67+
struct qdl_device *sim_init(void)
68+
{
69+
struct qdl_device *qdl = malloc(sizeof(struct qdl_device_sim));
70+
if (!qdl)
71+
return NULL;
72+
73+
memset(qdl, 0, sizeof(struct qdl_device_sim));
74+
75+
qdl->dev_type = QDL_DEVICE_SIM;
76+
qdl->open = sim_open;
77+
qdl->read = sim_read;
78+
qdl->write = sim_write;
79+
qdl->close = sim_close;
80+
qdl->set_out_chunk_size = sim_set_out_chunk_size;
81+
82+
return qdl;
83+
}

0 commit comments

Comments
 (0)