* [PATCH 1/3] usb: dfu: Fix spelling of flag name
@ 2014-02-26 14:35 Sascha Hauer
2014-02-26 14:35 ` [PATCH 2/3] usb: dfu: Add create flag Sascha Hauer
2014-02-26 14:35 ` [PATCH 3/3] defaultenv: Add boot option for DFU Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2014-02-26 14:35 UTC (permalink / raw)
To: barebox
DFU_FLAG_SAVE should really be named DFU_FLAG_SAFE.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/dfu.c | 2 +-
drivers/usb/gadget/dfu.c | 4 ++--
include/usb/dfu.h | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/commands/dfu.c b/commands/dfu.c
index ec1197a..b310585 100644
--- a/commands/dfu.c
+++ b/commands/dfu.c
@@ -60,7 +60,7 @@ static int dfu_do_parse_one(char *partstr, char **endstr, struct usb_dfu_dev *df
case PARSE_FLAGS:
switch (*partstr) {
case 's':
- dfu->flags |= DFU_FLAG_SAVE;
+ dfu->flags |= DFU_FLAG_SAFE;
break;
case 'r':
dfu->flags |= DFU_FLAG_READBACK;
diff --git a/drivers/usb/gadget/dfu.c b/drivers/usb/gadget/dfu.c
index e15fc41..6002ff0 100644
--- a/drivers/usb/gadget/dfu.c
+++ b/drivers/usb/gadget/dfu.c
@@ -244,7 +244,7 @@ static int handle_dnload(struct usb_function *f, const struct usb_ctrlrequest *c
if (w_length == 0) {
dfu->dfu_state = DFU_STATE_dfuIDLE;
- if (dfu_devs[dfualt].flags & DFU_FLAG_SAVE) {
+ if (dfu_devs[dfualt].flags & DFU_FLAG_SAFE) {
int fd;
fd = open(dfu_devs[dfualt].dev, O_WRONLY);
@@ -376,7 +376,7 @@ 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_SAVE)
+ 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);
diff --git a/include/usb/dfu.h b/include/usb/dfu.h
index 698ba9d..00031e7 100644
--- a/include/usb/dfu.h
+++ b/include/usb/dfu.h
@@ -22,7 +22,7 @@
#include <linux/types.h>
-#define DFU_FLAG_SAVE (1 << 0)
+#define DFU_FLAG_SAFE (1 << 0)
#define DFU_FLAG_READBACK (1 << 1)
struct usb_dfu_dev {
--
1.8.5.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/3] usb: dfu: Add create flag
2014-02-26 14:35 [PATCH 1/3] usb: dfu: Fix spelling of flag name Sascha Hauer
@ 2014-02-26 14:35 ` Sascha Hauer
2014-02-26 14:35 ` [PATCH 3/3] defaultenv: Add boot option for DFU Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2014-02-26 14:35 UTC (permalink / raw)
To: barebox
With the create flag DFU can upload to regular, previously non existing
files.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/dfu.c | 8 ++++++--
drivers/usb/gadget/dfu.c | 18 ++++++++++++++----
include/usb/dfu.h | 1 +
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/commands/dfu.c b/commands/dfu.c
index b310585..3c00e7e 100644
--- a/commands/dfu.c
+++ b/commands/dfu.c
@@ -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
/**
diff --git a/drivers/usb/gadget/dfu.c b/drivers/usb/gadget/dfu.c
index 6002ff0..c3a4e61 100644
--- a/drivers/usb/gadget/dfu.c
+++ b/drivers/usb/gadget/dfu.c
@@ -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;
diff --git a/include/usb/dfu.h b/include/usb/dfu.h
index 00031e7..df4f2fd 100644
--- a/include/usb/dfu.h
+++ b/include/usb/dfu.h
@@ -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;
--
1.8.5.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 3/3] defaultenv: Add boot option for DFU
2014-02-26 14:35 [PATCH 1/3] usb: dfu: Fix spelling of flag name Sascha Hauer
2014-02-26 14:35 ` [PATCH 2/3] usb: dfu: Add create flag Sascha Hauer
@ 2014-02-26 14:35 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2014-02-26 14:35 UTC (permalink / raw)
To: barebox
DFU is for device firmware upgrade, but for development purposes it's
sometmes useful to just start a kernel vie DFU. This adds a boot option
for doing this and also the corresponding counterpart on the host. With
this it's possible to boot a system with:
scripts/dfuboot.sh -k linuximage -d dtb -c "root=ubi0:root ubi.mtd=ubi rootfstype=ubifs ignore_loglevel"
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/Kconfig | 6 ++++
defaultenv/Makefile | 1 +
defaultenv/defaultenv-2-dfu/boot/dfu | 39 +++++++++++++++++++++
defaultenv/defaultenv.c | 2 ++
scripts/dfuboot.sh | 68 ++++++++++++++++++++++++++++++++++++
5 files changed, 116 insertions(+)
create mode 100644 defaultenv/defaultenv-2-dfu/boot/dfu
create mode 100755 scripts/dfuboot.sh
diff --git a/common/Kconfig b/common/Kconfig
index d862c05..b9cbe19 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -593,6 +593,12 @@ config DEFAULT_ENVIRONMENT_GENERIC_NEW_MENU
depends on CONFIG_CMD_MENU_MANAGEMENT
default y
+config DEFAULT_ENVIRONMENT_GENERIC_NEW_DFU
+ bool
+ depends on DEFAULT_ENVIRONMENT_GENERIC_NEW
+ depends on USB_GADGET_DFU
+ default y
+
config DEFAULT_ENVIRONMENT_GENERIC
bool
depends on !HAVE_DEFAULT_ENVIRONMENT_NEW
diff --git a/defaultenv/Makefile b/defaultenv/Makefile
index d449e02..fc679eb 100644
--- a/defaultenv/Makefile
+++ b/defaultenv/Makefile
@@ -1,5 +1,6 @@
bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW) += defaultenv-2-base
bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_MENU) += defaultenv-2-menu
+bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_DFU) += defaultenv-2-dfu
bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC) += defaultenv-1
obj-$(CONFIG_DEFAULT_ENVIRONMENT) += defaultenv.o
extra-y += barebox_default_env barebox_default_env.h barebox_default_env$(DEFAULT_COMPRESSION_SUFFIX)
diff --git a/defaultenv/defaultenv-2-dfu/boot/dfu b/defaultenv/defaultenv-2-dfu/boot/dfu
new file mode 100644
index 0000000..c9463b6
--- /dev/null
+++ b/defaultenv/defaultenv-2-dfu/boot/dfu
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+if [ "$1" = menu ]; then
+ boot-menu-add-entry "$0" "Device Firmware upgrade (DFU)"
+ exit
+fi
+
+if [ -d /dfutmp ]; then
+ rm -r /dfutmp
+fi
+
+mkdir -p /dfutmp
+
+kernel="/dfutmp/kernel"
+dtb="/dfutmp/dtb"
+cmdline="/dfutmp/cmdline"
+
+global.bootm.image="$kernel"
+
+dfu $kernel(kernel)c,$dtb(dtb)c,$cmdline(cmdline)c
+if [ $? != 0 ]; then
+ exit 1
+fi
+
+if [ ! -f "$kernel" ]; then
+ echo "No kernel uploaded. Aborting"
+ exit 1
+fi
+
+if [ -f "$cmdline" ]; then
+ global linux.bootargs.dyn.dfu
+ readf $cmdline global.linux.bootargs.dyn.dfu
+fi
+
+if [ -f "$dtb" ]; then
+ global.bootm.oftree="$dtb"
+fi
+
+true
diff --git a/defaultenv/defaultenv.c b/defaultenv/defaultenv.c
index cb20e9e..ee73a49 100644
--- a/defaultenv/defaultenv.c
+++ b/defaultenv/defaultenv.c
@@ -46,6 +46,8 @@ static void defaultenv_add_base(void)
defaultenv_append_directory(defaultenv_2_base);
if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_MENU))
defaultenv_append_directory(defaultenv_2_menu);
+ if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_DFU))
+ defaultenv_append_directory(defaultenv_2_dfu);
if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC))
defaultenv_append_directory(defaultenv_1);
diff --git a/scripts/dfuboot.sh b/scripts/dfuboot.sh
new file mode 100755
index 0000000..524113b
--- /dev/null
+++ b/scripts/dfuboot.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+DEVICETREE=
+KERNEL=
+CMDLINE=
+
+usage() {
+ echo "usage: $0 [OPTIONS]"
+ echo "This script uploads a kernel and optionally a devicetree"
+ echo "and a kernel commandline to barebox via DFU running the"
+ echo "'boot dfu' command."
+ echo "OPTIONS:"
+ echo " -k <kernel> kernelimage to upload"
+ echo " -d <dtb> devicetree binary blob to upload"
+ echo " -c \"cmdline\" kernel commandline"
+ echo " -h This help text"
+
+ exit 0
+}
+
+while getopts "k:d:c:h" opt
+do
+ case "$opt" in
+ h)
+ usage
+ ;;
+ d)
+ DEVICETREE="$OPTARG"
+ ;;
+ k)
+ KERNEL="$OPTARG"
+ ;;
+ c)
+ CMDLINE="$OPTARG"
+ ;;
+ esac
+done
+
+dfu-util -D "${KERNEL}" -a kernel
+if [ $? != 0 ]; then
+ echo "Failed to upload kernel"
+ exit 1
+fi
+
+if [ -n "$DEVICETREE" ]; then
+ dfu-util -D "${DEVICETREE}" -a dtb
+ if [ $? != 0 ]; then
+ echo "Failed to upload devicetree"
+ exit 1
+ fi
+fi
+
+if [ -n "$CMDLINE" ]; then
+ cmdlinefile=$(mktemp)
+
+ echo -e "$CMDLINE" > "${cmdlinefile}"
+
+ dfu-util -D "${cmdlinefile}" -a cmdline -R
+ result=$?
+
+ rm -f "${cmdlinefile}"
+
+ if [ $result != 0 ]; then
+ echo "Failed to upload cmdline"
+ exit 1
+ fi
+
+fi
--
1.8.5.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-02-26 14:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-26 14:35 [PATCH 1/3] usb: dfu: Fix spelling of flag name Sascha Hauer
2014-02-26 14:35 ` [PATCH 2/3] usb: dfu: Add create flag Sascha Hauer
2014-02-26 14:35 ` [PATCH 3/3] defaultenv: Add boot option for DFU Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox