Skip to content

Commit 429331b

Browse files
committed
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 <[email protected]>
1 parent 0adbe81 commit 429331b

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

firehose.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,17 @@ static int firehose_configure_response_parser(xmlNode *node, void *data, bool *r
299299
}
300300

301301
static int firehose_send_configure(struct qdl_device *qdl, size_t payload_size,
302-
bool skip_storage_init, const char *storage,
302+
bool skip_storage_init,
303+
enum qdl_storage_type storage,
303304
size_t *max_payload_size)
304305
{
306+
static const char * const memory_names[] = {
307+
[QDL_STORAGE_EMMC] = "emmc",
308+
[QDL_STORAGE_NAND] = "nand",
309+
[QDL_STORAGE_UFS] = "ufs",
310+
[QDL_STORAGE_NVME] = "nvme",
311+
[QDL_STORAGE_SPINOR] = "spinor",
312+
};
305313
xmlNode *root;
306314
xmlNode *node;
307315
xmlDoc *doc;
@@ -311,7 +319,7 @@ static int firehose_send_configure(struct qdl_device *qdl, size_t payload_size,
311319
xmlDocSetRootElement(doc, root);
312320

313321
node = xmlNewChild(root, NULL, (xmlChar *)"configure", NULL);
314-
xml_setpropf(node, "MemoryName", storage);
322+
xml_setpropf(node, "MemoryName", memory_names[storage]);
315323
xml_setpropf(node, "MaxPayloadSizeToTargetInBytes", "%lu", payload_size);
316324
xml_setpropf(node, "verbose", "%d", 0);
317325
xml_setpropf(node, "ZLPAwareHost", "%d", 1);
@@ -324,7 +332,7 @@ static int firehose_send_configure(struct qdl_device *qdl, size_t payload_size,
324332
}
325333

326334
static int firehose_try_configure(struct qdl_device *qdl, bool skip_storage_init,
327-
const char *storage)
335+
enum qdl_storage_type storage)
328336
{
329337
size_t max_sector_size;
330338
size_t sector_sizes[] = { 512, 4096 };
@@ -359,7 +367,7 @@ static int firehose_try_configure(struct qdl_device *qdl, bool skip_storage_init
359367

360368
ux_debug("accepted max payload size: %zu\n", qdl->max_payload_size);
361369

362-
if (strcmp(storage, "nand")) {
370+
if (storage != QDL_STORAGE_NAND) {
363371
max_sector_size = sector_sizes[ARRAY_SIZE(sector_sizes) - 1];
364372
buf = malloc(max_sector_size);
365373
memset(&op, 0, sizeof(op));
@@ -560,7 +568,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
560568

561569
vip_transfer_clear_status(qdl);
562570
}
563-
n = qdl_write(qdl, buf, chunk_size * sector_size, 10000);
571+
n = qdl_write(qdl, buf, chunk_size * sector_size, 30000);
564572
if (n < 0) {
565573
ux_err("USB write failed for data chunk\n");
566574
ret = firehose_read(qdl, 30000, firehose_generic_parser, NULL);
@@ -929,7 +937,7 @@ static int firehose_reset(struct qdl_device *qdl)
929937

930938
static int firehose_detect_and_configure(struct qdl_device *qdl,
931939
bool skip_storage_init,
932-
const char *storage,
940+
enum qdl_storage_type storage,
933941
unsigned int timeout_s)
934942
{
935943
struct timeval timeout = { .tv_sec = timeout_s };
@@ -962,7 +970,7 @@ int firehose_provision(struct qdl_device *qdl)
962970
{
963971
int ret;
964972

965-
ret = firehose_detect_and_configure(qdl, true, "ufs", 5);
973+
ret = firehose_detect_and_configure(qdl, true, QDL_STORAGE_UFS, 5);
966974
if (ret)
967975
return ret;
968976

@@ -980,7 +988,7 @@ int firehose_provision(struct qdl_device *qdl)
980988

981989
}
982990

983-
int firehose_run(struct qdl_device *qdl, const char *storage)
991+
int firehose_run(struct qdl_device *qdl, enum qdl_storage_type storage)
984992
{
985993
bool multiple;
986994
int bootable;

qdl.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ static int detect_type(const char *verb)
9292
return type;
9393
}
9494

95+
static enum qdl_storage_type decode_storage(const char *storage)
96+
{
97+
98+
if (!strcmp(storage, "emmc"))
99+
return QDL_STORAGE_EMMC;
100+
if (!strcmp(storage, "nand"))
101+
return QDL_STORAGE_NAND;
102+
if (!strcmp(storage, "nvme"))
103+
return QDL_STORAGE_NVME;
104+
if (!strcmp(storage, "spinor"))
105+
return QDL_STORAGE_SPINOR;
106+
if (!strcmp(storage, "ufs"))
107+
return QDL_STORAGE_UFS;
108+
109+
fprintf(stderr, "Unknown storage type \"%s\"\n", storage);
110+
exit(1);
111+
}
112+
95113
static void print_usage(FILE *out)
96114
{
97115
extern const char *__progname;
@@ -102,7 +120,7 @@ static void print_usage(FILE *out)
102120
fprintf(out, " -v, --version\t\t\tPrint the current version and exit\n");
103121
fprintf(out, " -n, --dry-run\t\t\tDry run execution, no device reading or flashing\n");
104122
fprintf(out, " -f, --allow-missing\t\tAllow skipping of missing files during flashing\n");
105-
fprintf(out, " -s, --storage=T\t\tSet target storage type T: <emmc|nand|ufs>\n");
123+
fprintf(out, " -s, --storage=T\t\tSet target storage type T: <emmc|nand|nvme|spinor|ufs>\n");
106124
fprintf(out, " -l, --finalize-provisioning\tProvision the target storage\n");
107125
fprintf(out, " -i, --include=T\t\tSet an optional folder T to search for files\n");
108126
fprintf(out, " -S, --serial=T\t\t\tSelect target by serial number T (e.g. <0AA94EFD>)\n");
@@ -122,7 +140,8 @@ static void print_usage(FILE *out)
122140

123141
int main(int argc, char **argv)
124142
{
125-
char *prog_mbn, *storage = "ufs";
143+
enum qdl_storage_type storage = QDL_STORAGE_UFS;
144+
char *prog_mbn;
126145
char *incdir = NULL;
127146
char *serial = NULL;
128147
const char *vip_generate_dir = NULL;
@@ -186,7 +205,7 @@ int main(int argc, char **argv)
186205
out_chunk_size = strtol(optarg, NULL, 10);
187206
break;
188207
case 's':
189-
storage = optarg;
208+
storage = decode_storage(optarg);
190209
break;
191210
case 'S':
192211
serial = optarg;
@@ -253,7 +272,7 @@ int main(int argc, char **argv)
253272
errx(1, "patch_load %s failed", argv[optind]);
254273
break;
255274
case QDL_FILE_PROGRAM:
256-
ret = program_load(argv[optind], !strcmp(storage, "nand"), allow_missing, incdir);
275+
ret = program_load(argv[optind], storage == QDL_STORAGE_NAND, allow_missing, incdir);
257276
if (ret < 0)
258277
errx(1, "program_load %s failed", argv[optind]);
259278

@@ -267,7 +286,7 @@ int main(int argc, char **argv)
267286
errx(1, "read_op_load %s failed", argv[optind]);
268287
break;
269288
case QDL_FILE_UFS:
270-
if (strcmp(storage, "ufs"))
289+
if (storage != QDL_STORAGE_UFS)
271290
errx(1, "attempting to load provisioning config when storage isn't \"ufs\"");
272291

273292
ret = ufs_load(argv[optind], qdl_finalize_provisioning);

qdl.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ enum QDL_DEVICE_TYPE {
3535
QDL_DEVICE_SIM,
3636
};
3737

38+
enum qdl_storage_type {
39+
QDL_STORAGE_UNKNOWN,
40+
QDL_STORAGE_EMMC,
41+
QDL_STORAGE_NAND,
42+
QDL_STORAGE_UFS,
43+
QDL_STORAGE_NVME,
44+
QDL_STORAGE_SPINOR,
45+
};
46+
3847
struct qdl_device {
3948
enum QDL_DEVICE_TYPE dev_type;
4049
int fd;
@@ -68,7 +77,7 @@ int qdl_vip_transfer_enable(struct qdl_device *qdl, const char *vip_table_path);
6877
struct qdl_device *usb_init(void);
6978
struct qdl_device *sim_init(void);
7079

71-
int firehose_run(struct qdl_device *qdl, const char *storage);
80+
int firehose_run(struct qdl_device *qdl, enum qdl_storage_type storage);
7281
int firehose_provision(struct qdl_device *qdl);
7382
int firehose_read_buf(struct qdl_device *qdl, struct read_op *read_op, void *out_buf, size_t out_size);
7483
int sahara_run(struct qdl_device *qdl, char *img_arr[], bool single_image,

0 commit comments

Comments
 (0)