usb: dfu: Add create flag
With the create flag DFU can upload to regular, previously non existing files. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
9b731118f9
commit
991a12da04
|
@ -65,6 +65,9 @@ static int dfu_do_parse_one(char *partstr, char **endstr, struct usb_dfu_dev *df
|
|||
case 'r':
|
||||
dfu->flags |= DFU_FLAG_READBACK;
|
||||
break;
|
||||
case 'c':
|
||||
dfu->flags |= DFU_FLAG_CREATE;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -167,9 +170,10 @@ BAREBOX_CMD_HELP_OPT ("-p <str>", "product string\n")
|
|||
BAREBOX_CMD_HELP_OPT ("-V <id>", "vendor id\n")
|
||||
BAREBOX_CMD_HELP_OPT ("-P <id>", "product id\n")
|
||||
BAREBOX_CMD_HELP_OPT ("<description>",
|
||||
"device1(name1)[sr],device2(name2)[sr]\n"
|
||||
"device1(name1)[sr],device2(name2)[src]\n"
|
||||
"'s' means 'safe mode' (download the complete image before flashing) and\n"
|
||||
"'r' that readback of the firmware is allowed.\n")
|
||||
"'r' that readback of the firmware is allowed.\n"
|
||||
"'c' if given, the file will be created (for use with regular files)\n")
|
||||
BAREBOX_CMD_HELP_END
|
||||
|
||||
/**
|
||||
|
|
|
@ -246,8 +246,12 @@ static int handle_dnload(struct usb_function *f, const struct usb_ctrlrequest *c
|
|||
dfu->dfu_state = DFU_STATE_dfuIDLE;
|
||||
if (dfu_devs[dfualt].flags & DFU_FLAG_SAFE) {
|
||||
int fd;
|
||||
unsigned flags = O_WRONLY;
|
||||
|
||||
fd = open(dfu_devs[dfualt].dev, O_WRONLY);
|
||||
if (dfu_devs[dfualt].flags & DFU_FLAG_CREATE)
|
||||
flags |= O_CREAT | O_TRUNC;
|
||||
|
||||
fd = open(dfu_devs[dfualt].dev, flags);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
ret = -EINVAL;
|
||||
|
@ -376,10 +380,16 @@ static int dfu_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
|
|||
goto out;
|
||||
}
|
||||
debug("dfu: starting download to %s\n", dfu_devs[dfualt].dev);
|
||||
if (dfu_devs[dfualt].flags & DFU_FLAG_SAFE)
|
||||
if (dfu_devs[dfualt].flags & DFU_FLAG_SAFE) {
|
||||
dfufd = open(DFU_TEMPFILE, O_WRONLY | O_CREAT);
|
||||
else
|
||||
dfufd = open(dfu_devs[dfualt].dev, O_WRONLY);
|
||||
} else {
|
||||
unsigned flags = O_WRONLY;
|
||||
|
||||
if (dfu_devs[dfualt].flags & DFU_FLAG_CREATE)
|
||||
flags |= O_CREAT | O_TRUNC;
|
||||
|
||||
dfufd = open(dfu_devs[dfualt].dev, flags);
|
||||
}
|
||||
|
||||
if (dfufd < 0) {
|
||||
dfu->dfu_state = DFU_STATE_dfuERROR;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#define DFU_FLAG_SAFE (1 << 0)
|
||||
#define DFU_FLAG_READBACK (1 << 1)
|
||||
#define DFU_FLAG_CREATE (1 << 2)
|
||||
|
||||
struct usb_dfu_dev {
|
||||
char *name;
|
||||
|
|
Loading…
Reference in New Issue