Skip to content

Commit d136299

Browse files
qdl: Add support for having up to 32 include folder when searching for files. This is particularly useful for yocto builds since binaries are generated into three folders whereas currently QDL only supports searching for files in two folders.
1 parent 8c15806 commit d136299

5 files changed

Lines changed: 34 additions & 16 deletions

File tree

program.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,14 @@ static int program_load_sparse(struct program *program, int fd)
148148
return 0;
149149
}
150150

151-
static int load_program_tag(xmlNode *node, bool is_nand, bool allow_missing, const char *incdir)
151+
static int load_program_tag(xmlNode *node, bool is_nand, bool allow_missing, const char *incdir[], int incdir_count)
152152
{
153153
struct program *program;
154154
char tmp[PATH_MAX];
155155
int errors = 0;
156156
int ret;
157157
int fd = -1;
158+
bool found = false;
158159

159160
program = calloc(1, sizeof(struct program));
160161

@@ -184,11 +185,14 @@ static int load_program_tag(xmlNode *node, bool is_nand, bool allow_missing, con
184185
}
185186

186187
if (program->filename) {
187-
if (incdir) {
188-
snprintf(tmp, PATH_MAX, "%s/%s", incdir, program->filename);
188+
for (int i = 0; i < incdir_count && incdir[i]; ++i) {
189+
snprintf(tmp, PATH_MAX, "%s/%s", incdir[i], program->filename);
189190
if (access(tmp, F_OK) != -1) {
190191
free((void *)program->filename);
191192
program->filename = strdup(tmp);
193+
if(found)
194+
ux_info("multiple files found for %s, using %s\n", program->filename, tmp);
195+
found = true;
192196
}
193197
}
194198

@@ -227,7 +231,7 @@ static int load_program_tag(xmlNode *node, bool is_nand, bool allow_missing, con
227231
return 0;
228232
}
229233

230-
int program_load(const char *program_file, bool is_nand, bool allow_missing, const char *incdir)
234+
int program_load(const char *program_file, bool is_nand, bool allow_missing, const char *incdir[], int incdir_count)
231235
{
232236
xmlNode *node;
233237
xmlNode *root;
@@ -248,7 +252,7 @@ int program_load(const char *program_file, bool is_nand, bool allow_missing, con
248252
if (!xmlStrcmp(node->name, (xmlChar *)"erase"))
249253
errors = load_erase_tag(node, is_nand);
250254
else if (!xmlStrcmp(node->name, (xmlChar *)"program"))
251-
errors = load_program_tag(node, is_nand, allow_missing, incdir);
255+
errors = load_program_tag(node, is_nand, allow_missing, incdir, incdir_count);
252256
else {
253257
ux_err("unrecognized tag \"%s\" in program-type file \"%s\"\n", node->name, program_file);
254258
errors = -EINVAL;

program.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct program {
3333

3434
struct qdl_device;
3535

36-
int program_load(const char *program_file, bool is_nand, bool allow_missing, const char *incdir);
36+
int program_load(const char *program_file, bool is_nand, bool allow_missing, const char *incdir[], int incdir_count);
3737
int program_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct program *program, int fd));
3838
int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct program *program));
3939
int program_find_bootable_partition(bool *multiple_found);

qdl.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ static int qdl_flash(int argc, char **argv)
557557
{
558558
enum qdl_storage_type storage_type = QDL_STORAGE_UFS;
559559
struct sahara_image sahara_images[MAPPING_SZ] = {};
560-
char *incdir = NULL;
560+
const char *incdir[32] = {0};
561561
char *serial = NULL;
562562
const char *vip_generate_dir = NULL;
563563
const char *vip_table_path = NULL;
@@ -571,6 +571,7 @@ static int qdl_flash(int argc, char **argv)
571571
unsigned int slot = UINT_MAX;
572572
struct qdl_device *qdl = NULL;
573573
enum QDL_DEVICE_TYPE qdl_dev_type = QDL_DEVICE_USB;
574+
int incdir_count = 0;
574575

575576
static struct option options[] = {
576577
{"debug", no_argument, 0, 'd'},
@@ -610,7 +611,12 @@ static int qdl_flash(int argc, char **argv)
610611
allow_missing = true;
611612
break;
612613
case 'i':
613-
incdir = optarg;
614+
if (incdir_count < sizeof(incdir) / sizeof(incdir[0])) {
615+
incdir[incdir_count] = optarg;
616+
incdir_count++;
617+
} else {
618+
errx(1, "maximum number of include directories exceeded");
619+
}
614620
break;
615621
case 'l':
616622
qdl_finalize_provisioning = true;
@@ -694,7 +700,7 @@ static int qdl_flash(int argc, char **argv)
694700
errx(1, "patch_load %s failed", argv[optind]);
695701
break;
696702
case QDL_FILE_PROGRAM:
697-
ret = program_load(argv[optind], storage_type == QDL_STORAGE_NAND, allow_missing, incdir);
703+
ret = program_load(argv[optind], storage_type == QDL_STORAGE_NAND, allow_missing, incdir, incdir_count);
698704
if (ret < 0)
699705
errx(1, "program_load %s failed", argv[optind]);
700706

@@ -703,7 +709,7 @@ static int qdl_flash(int argc, char **argv)
703709
" changes. Allow explicitly with --allow-fusing parameter");
704710
break;
705711
case QDL_FILE_READ:
706-
ret = read_op_load(argv[optind], incdir);
712+
ret = read_op_load(argv[optind], incdir, incdir_count);
707713
if (ret < 0)
708714
errx(1, "read_op_load %s failed", argv[optind]);
709715
break;

read.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919

2020
static struct list_head read_ops = LIST_INIT(read_ops);
2121

22-
int read_op_load(const char *read_op_file, const char *incdir)
22+
int read_op_load(const char *read_op_file, const char *incdir[], int incdir_count)
2323
{
2424
struct read_op *read_op;
2525
xmlNode *node;
2626
xmlNode *root;
2727
xmlDoc *doc;
2828
int errors;
2929
char tmp[PATH_MAX];
30+
bool found = false;
3031

3132
doc = xmlReadFile(read_op_file, NULL, 0);
3233
if (!doc) {
@@ -61,10 +62,17 @@ int read_op_load(const char *read_op_file, const char *incdir)
6162
continue;
6263
}
6364

64-
if (incdir) {
65-
snprintf(tmp, PATH_MAX, "%s/%s", incdir, read_op->filename);
66-
if (access(tmp, F_OK) != -1)
67-
read_op->filename = strdup(tmp);
65+
if (read_op->filename) {
66+
for (int i = 0; i < incdir_count && incdir[i]; ++i) {
67+
snprintf(tmp, PATH_MAX, "%s/%s", incdir[i], read_op->filename);
68+
if (access(tmp, F_OK) != -1) {
69+
free((void *)read_op->filename);
70+
read_op->filename = strdup(tmp);
71+
if(found)
72+
ux_info("multiple files found for %s, using %s\n", read_op->filename, tmp);
73+
found = true;
74+
}
75+
}
6876
}
6977

7078
list_add(&read_ops, &read_op->node);

read.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct read_op {
1919
struct list_head node;
2020
};
2121

22-
int read_op_load(const char *read_op_file, const char *incdir);
22+
int read_op_load(const char *read_op_file, const char *incdir[], int incdir_count);
2323
int read_op_execute(struct qdl_device *qdl,
2424
int (*apply)(struct qdl_device *qdl, struct read_op *read_op, int fd));
2525
int read_cmd_add(const char *source, const char *filename);

0 commit comments

Comments
 (0)