Commit 45cc3521 authored by Nicolas Dechesne's avatar Nicolas Dechesne Committed by Bjorn Andersson
Browse files

qdl: add --include to specific optional folder to look for files



Let the programmer search for files beyond the current folder. When --include is
used , the programmmer will first look for files in the specified folder, and it
will then fallback to looking at the current folder.
Signed-off-by: default avatarNicolas Dechesne <nicolas.dechesne@linaro.org>
Signed-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
parent 5d51472f
......@@ -602,7 +602,7 @@ static int firehose_reset(int fd)
return firehose_read(fd, -1, firehose_nop_parser);
}
int firehose_run(int fd)
int firehose_run(int fd, const char *incdir)
{
int bootable;
int ret;
......@@ -635,7 +635,7 @@ int firehose_run(int fd)
if (ret)
return ret;
ret = program_execute(fd, firehose_program);
ret = program_execute(fd, firehose_program, incdir);
if (ret)
return ret;
......
......@@ -135,9 +135,12 @@ int program_load(const char *program_file)
return 0;
}
int program_execute(int usbfd, int (*apply)(int usbfd, struct program *program, int fd))
int program_execute(int usbfd, int (*apply)(int usbfd, struct program *program, int fd),
const char *incdir)
{
struct program *program;
const char *filename;
char tmp[PATH_MAX];
int ret;
int fd;
......@@ -145,7 +148,15 @@ int program_execute(int usbfd, int (*apply)(int usbfd, struct program *program,
if (!program->filename)
continue;
fd = open(program->filename, O_RDONLY);
filename = program->filename;
if (incdir) {
snprintf(tmp, PATH_MAX, "%s/%s", incdir, filename);
if (access(tmp, F_OK) != -1)
filename = tmp;
}
fd = open(filename, O_RDONLY);
if (fd < 0) {
printf("Unable to open %s...ignoring\n", program->filename);
continue;
......
......@@ -19,7 +19,8 @@ struct program {
};
int program_load(const char *program_file);
int program_execute(int usbfd, int (*apply)(int usbfd, struct program *program, int fd));
int program_execute(int usbfd, int (*apply)(int usbfd, struct program *program, int fd),
const char *incdir);
int program_find_bootable_partition(void);
#endif
......@@ -220,7 +220,7 @@ static void print_usage(void)
{
extern const char *__progname;
fprintf(stderr,
"%s [--debug] [--finalize-provisioning] <prog.mbn> [<program> <patch> ...]\n",
"%s [--debug] [--finalize-provisioning] [--include <PATH>] <prog.mbn> [<program> <patch> ...]\n",
__progname);
}
......@@ -228,6 +228,7 @@ int main(int argc, char **argv)
{
struct termios tios;
char *prog_mbn;
char *incdir = NULL;
int type;
int ret;
int fd;
......@@ -237,15 +238,19 @@ int main(int argc, char **argv)
static struct option options[] = {
{"debug", no_argument, 0, 'd'},
{"include", required_argument, 0, 'i'},
{"finalize-provisioning", no_argument, 0, 'l'},
{0, 0, 0, 0}
};
while ((opt = getopt_long(argc, argv, "d", options, NULL )) != -1) {
while ((opt = getopt_long(argc, argv, "di:", options, NULL )) != -1) {
switch (opt) {
case 'd':
qdl_debug = true;
break;
case 'i':
incdir = optarg;
break;
case 'l':
qdl_finalize_provisioning = true;
break;
......@@ -298,7 +303,7 @@ int main(int argc, char **argv)
if (ret < 0)
goto out;
ret = firehose_run(fd);
ret = firehose_run(fd, incdir);
out:
ret = tcsetattr(fd, TCSANOW, &tios);
......
......@@ -6,7 +6,7 @@
#include "patch.h"
#include "program.h"
int firehose_run(int fd);
int firehose_run(int fd, const char *incdir);
int sahara_run(int fd, char *prog_mbn);
void print_hex_dump(const char *prefix, const void *buf, size_t len);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment