2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-08-06 12:41:09 +00:00
|
|
|
/*
|
|
|
|
* cmd_dfu.c -- dfu command
|
|
|
|
*
|
2015-08-23 22:21:48 +00:00
|
|
|
* Copyright (C) 2015
|
|
|
|
* Lukasz Majewski <l.majewski@majess.pl>
|
|
|
|
*
|
2012-08-06 12:41:09 +00:00
|
|
|
* Copyright (C) 2012 Samsung Electronics
|
|
|
|
* authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
|
|
|
|
* Lukasz Majewski <l.majewski@samsung.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
2015-04-14 07:53:13 +00:00
|
|
|
#include <watchdog.h>
|
2012-08-06 12:41:09 +00:00
|
|
|
#include <dfu.h>
|
2015-11-09 06:47:45 +00:00
|
|
|
#include <console.h>
|
2012-08-06 12:41:09 +00:00
|
|
|
#include <g_dnl.h>
|
2013-10-04 17:22:26 +00:00
|
|
|
#include <usb.h>
|
2015-08-23 22:21:48 +00:00
|
|
|
#include <net.h>
|
2012-08-06 12:41:09 +00:00
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
2012-08-06 12:41:09 +00:00
|
|
|
{
|
2014-08-25 09:07:28 +00:00
|
|
|
|
dfu: allow to manage DFU on several devices
Add support of DFU for several interface/device
with one command.
The format for "dfu_alt_info" in this case is :
- <interface> <dev>'='alternate list (';' separated)
- each interface is separated by '&'
The previous behavior is always supported.
One example for NOR (bootloaders) + NAND (rootfs in UBI):
U-Boot> env set dfu_alt_info \
"sf 0:0:10000000:0=spl part 0 1;u-boot part 0 2; \
u-boot-env part 0 3&nand 0=UBI partubi 0,3"
U-Boot> dfu 0 list
DFU alt settings list:
dev: SF alt: 0 name: spl layout: RAW_ADDR
dev: SF alt: 1 name: ssbl layout: RAW_ADDR
dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR
dev: NAND alt: 3 name: UBI layout: RAW_ADDR
U-Boot> dfu 0
$> dfu-util -l
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=3, name="UBI", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=2, name="u-boot-env", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=1, name="u-boot", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=0, name="spl", serial="002700333338511934383330"
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2019-10-14 07:28:02 +00:00
|
|
|
if (argc < 2)
|
2013-10-04 17:22:26 +00:00
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
2018-02-16 15:41:18 +00:00
|
|
|
#ifdef CONFIG_DFU_OVER_USB
|
2013-10-04 17:22:26 +00:00
|
|
|
char *usb_controller = argv[1];
|
2018-02-16 15:41:17 +00:00
|
|
|
#endif
|
dfu: Avoid declaring unused variables and absent parameters
The compiler is not happy when neither USB nor TFTP transport for DFU defined:
cmd/dfu.c: In function ‘do_dfu’:
cmd/dfu.c:31:8: warning: unused variable ‘devstring’ [-Wunused-variable]
char *devstring = argv[3];
^~~~~~~~~
cmd/dfu.c:30:8: warning: unused variable ‘interface’ [-Wunused-variable]
char *interface = argv[2];
^~~~~~~~~
Surround those variables by #ifdef expression.
More serious, that comes under same circumstances, is a compilation error due
to absence of macro parameter:
In file included from include/image.h:45,
from include/common.h:35,
from cmd/dfu.c:13:
include/command.h:207:24: error: expected expression before ‘,’ token
# define _CMD_HELP(x) x,
^
include/command.h:286:18: note: in expansion of macro ‘_CMD_HELP’
_cmd, _usage, _CMD_HELP(_help) _CMD_COMPLETE(_comp) }
^~~~~~~~~
include/command.h:290:3: note: in expansion of macro ‘U_BOOT_CMD_MKENT_COMPLETE’
U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
^~~~~~~~~~~~~~~~~~~~~~~~~
include/command.h:332:2: note: in expansion of macro ‘U_BOOT_CMD_COMPLETE’
U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, NULL)
^~~~~~~~~~~~~~~~~~~
cmd/dfu.c:70:1: note: in expansion of macro ‘U_BOOT_CMD’
U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
^~~~~~~~~~
make[1]: *** [scripts/Makefile.build:279: cmd/dfu.o] Error 1
make: *** [Makefile:1518: cmd] Error 2
Put empty string unconditionally to have macro parameter present.
Fixes: 0f44d33536a5 ("dfu: Fix up the Kconfig mess")
Cc: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Lukasz Majewski <lukma@denx.de>
2019-03-04 14:04:44 +00:00
|
|
|
#if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP)
|
dfu: allow to manage DFU on several devices
Add support of DFU for several interface/device
with one command.
The format for "dfu_alt_info" in this case is :
- <interface> <dev>'='alternate list (';' separated)
- each interface is separated by '&'
The previous behavior is always supported.
One example for NOR (bootloaders) + NAND (rootfs in UBI):
U-Boot> env set dfu_alt_info \
"sf 0:0:10000000:0=spl part 0 1;u-boot part 0 2; \
u-boot-env part 0 3&nand 0=UBI partubi 0,3"
U-Boot> dfu 0 list
DFU alt settings list:
dev: SF alt: 0 name: spl layout: RAW_ADDR
dev: SF alt: 1 name: ssbl layout: RAW_ADDR
dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR
dev: NAND alt: 3 name: UBI layout: RAW_ADDR
U-Boot> dfu 0
$> dfu-util -l
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=3, name="UBI", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=2, name="u-boot-env", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=1, name="u-boot", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=0, name="spl", serial="002700333338511934383330"
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2019-10-14 07:28:02 +00:00
|
|
|
char *interface = NULL;
|
|
|
|
char *devstring = NULL;
|
2019-11-27 16:12:15 +00:00
|
|
|
#if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
|
2019-11-27 16:12:14 +00:00
|
|
|
unsigned long value = 0;
|
|
|
|
#endif
|
dfu: allow to manage DFU on several devices
Add support of DFU for several interface/device
with one command.
The format for "dfu_alt_info" in this case is :
- <interface> <dev>'='alternate list (';' separated)
- each interface is separated by '&'
The previous behavior is always supported.
One example for NOR (bootloaders) + NAND (rootfs in UBI):
U-Boot> env set dfu_alt_info \
"sf 0:0:10000000:0=spl part 0 1;u-boot part 0 2; \
u-boot-env part 0 3&nand 0=UBI partubi 0,3"
U-Boot> dfu 0 list
DFU alt settings list:
dev: SF alt: 0 name: spl layout: RAW_ADDR
dev: SF alt: 1 name: ssbl layout: RAW_ADDR
dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR
dev: NAND alt: 3 name: UBI layout: RAW_ADDR
U-Boot> dfu 0
$> dfu-util -l
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=3, name="UBI", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=2, name="u-boot-env", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=1, name="u-boot", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=0, name="spl", serial="002700333338511934383330"
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2019-10-14 07:28:02 +00:00
|
|
|
|
|
|
|
if (argc >= 4) {
|
|
|
|
interface = argv[2];
|
|
|
|
devstring = argv[3];
|
|
|
|
}
|
2019-11-27 16:12:14 +00:00
|
|
|
|
2019-11-27 16:12:15 +00:00
|
|
|
#if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
|
2019-11-27 16:12:14 +00:00
|
|
|
if (argc == 5 || argc == 3)
|
|
|
|
value = simple_strtoul(argv[argc - 1], NULL, 0);
|
|
|
|
#endif
|
dfu: Avoid declaring unused variables and absent parameters
The compiler is not happy when neither USB nor TFTP transport for DFU defined:
cmd/dfu.c: In function ‘do_dfu’:
cmd/dfu.c:31:8: warning: unused variable ‘devstring’ [-Wunused-variable]
char *devstring = argv[3];
^~~~~~~~~
cmd/dfu.c:30:8: warning: unused variable ‘interface’ [-Wunused-variable]
char *interface = argv[2];
^~~~~~~~~
Surround those variables by #ifdef expression.
More serious, that comes under same circumstances, is a compilation error due
to absence of macro parameter:
In file included from include/image.h:45,
from include/common.h:35,
from cmd/dfu.c:13:
include/command.h:207:24: error: expected expression before ‘,’ token
# define _CMD_HELP(x) x,
^
include/command.h:286:18: note: in expansion of macro ‘_CMD_HELP’
_cmd, _usage, _CMD_HELP(_help) _CMD_COMPLETE(_comp) }
^~~~~~~~~
include/command.h:290:3: note: in expansion of macro ‘U_BOOT_CMD_MKENT_COMPLETE’
U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
^~~~~~~~~~~~~~~~~~~~~~~~~
include/command.h:332:2: note: in expansion of macro ‘U_BOOT_CMD_COMPLETE’
U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, NULL)
^~~~~~~~~~~~~~~~~~~
cmd/dfu.c:70:1: note: in expansion of macro ‘U_BOOT_CMD’
U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
^~~~~~~~~~
make[1]: *** [scripts/Makefile.build:279: cmd/dfu.o] Error 1
make: *** [Makefile:1518: cmd] Error 2
Put empty string unconditionally to have macro parameter present.
Fixes: 0f44d33536a5 ("dfu: Fix up the Kconfig mess")
Cc: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Lukasz Majewski <lukma@denx.de>
2019-03-04 14:04:44 +00:00
|
|
|
#endif
|
2013-10-04 17:22:26 +00:00
|
|
|
|
2018-02-16 15:41:17 +00:00
|
|
|
int ret = 0;
|
2018-02-16 15:41:18 +00:00
|
|
|
#ifdef CONFIG_DFU_OVER_TFTP
|
2019-11-27 16:12:14 +00:00
|
|
|
if (!strcmp(argv[1], "tftp"))
|
|
|
|
return update_tftp(value, interface, devstring);
|
2015-08-23 22:21:48 +00:00
|
|
|
#endif
|
2018-02-16 15:41:18 +00:00
|
|
|
#ifdef CONFIG_DFU_OVER_USB
|
2014-06-11 22:03:33 +00:00
|
|
|
ret = dfu_init_env_entities(interface, devstring);
|
2012-08-06 12:41:09 +00:00
|
|
|
if (ret)
|
2014-06-10 16:06:41 +00:00
|
|
|
goto done;
|
2012-08-06 12:41:09 +00:00
|
|
|
|
2019-11-27 16:12:15 +00:00
|
|
|
#ifdef CONFIG_DFU_TIMEOUT
|
|
|
|
dfu_set_timeout(value * 1000);
|
|
|
|
#endif
|
|
|
|
|
2014-06-10 16:06:41 +00:00
|
|
|
ret = CMD_RET_SUCCESS;
|
dfu: allow to manage DFU on several devices
Add support of DFU for several interface/device
with one command.
The format for "dfu_alt_info" in this case is :
- <interface> <dev>'='alternate list (';' separated)
- each interface is separated by '&'
The previous behavior is always supported.
One example for NOR (bootloaders) + NAND (rootfs in UBI):
U-Boot> env set dfu_alt_info \
"sf 0:0:10000000:0=spl part 0 1;u-boot part 0 2; \
u-boot-env part 0 3&nand 0=UBI partubi 0,3"
U-Boot> dfu 0 list
DFU alt settings list:
dev: SF alt: 0 name: spl layout: RAW_ADDR
dev: SF alt: 1 name: ssbl layout: RAW_ADDR
dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR
dev: NAND alt: 3 name: UBI layout: RAW_ADDR
U-Boot> dfu 0
$> dfu-util -l
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=3, name="UBI", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=2, name="u-boot-env", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=1, name="u-boot", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=0, name="spl", serial="002700333338511934383330"
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2019-10-14 07:28:02 +00:00
|
|
|
if (strcmp(argv[argc - 1], "list") == 0) {
|
2012-08-06 12:41:09 +00:00
|
|
|
dfu_show_entities();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2013-10-04 17:22:26 +00:00
|
|
|
int controller_index = simple_strtoul(usb_controller, NULL, 0);
|
2014-08-25 09:07:28 +00:00
|
|
|
|
2016-07-28 12:09:15 +00:00
|
|
|
run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
|
2013-07-18 11:19:14 +00:00
|
|
|
|
2012-08-06 12:41:09 +00:00
|
|
|
done:
|
|
|
|
dfu_free_entities();
|
2018-02-16 15:41:17 +00:00
|
|
|
#endif
|
2014-06-10 16:06:41 +00:00
|
|
|
return ret;
|
2012-08-06 12:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
|
|
|
|
"Device Firmware Upgrade",
|
dfu: Avoid declaring unused variables and absent parameters
The compiler is not happy when neither USB nor TFTP transport for DFU defined:
cmd/dfu.c: In function ‘do_dfu’:
cmd/dfu.c:31:8: warning: unused variable ‘devstring’ [-Wunused-variable]
char *devstring = argv[3];
^~~~~~~~~
cmd/dfu.c:30:8: warning: unused variable ‘interface’ [-Wunused-variable]
char *interface = argv[2];
^~~~~~~~~
Surround those variables by #ifdef expression.
More serious, that comes under same circumstances, is a compilation error due
to absence of macro parameter:
In file included from include/image.h:45,
from include/common.h:35,
from cmd/dfu.c:13:
include/command.h:207:24: error: expected expression before ‘,’ token
# define _CMD_HELP(x) x,
^
include/command.h:286:18: note: in expansion of macro ‘_CMD_HELP’
_cmd, _usage, _CMD_HELP(_help) _CMD_COMPLETE(_comp) }
^~~~~~~~~
include/command.h:290:3: note: in expansion of macro ‘U_BOOT_CMD_MKENT_COMPLETE’
U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
^~~~~~~~~~~~~~~~~~~~~~~~~
include/command.h:332:2: note: in expansion of macro ‘U_BOOT_CMD_COMPLETE’
U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, NULL)
^~~~~~~~~~~~~~~~~~~
cmd/dfu.c:70:1: note: in expansion of macro ‘U_BOOT_CMD’
U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
^~~~~~~~~~
make[1]: *** [scripts/Makefile.build:279: cmd/dfu.o] Error 1
make: *** [Makefile:1518: cmd] Error 2
Put empty string unconditionally to have macro parameter present.
Fixes: 0f44d33536a5 ("dfu: Fix up the Kconfig mess")
Cc: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Lukasz Majewski <lukma@denx.de>
2019-03-04 14:04:44 +00:00
|
|
|
""
|
2018-02-16 15:41:18 +00:00
|
|
|
#ifdef CONFIG_DFU_OVER_USB
|
2019-11-27 16:12:15 +00:00
|
|
|
#ifdef CONFIG_DFU_TIMEOUT
|
|
|
|
"<USB_controller> [<interface> <dev>] [<timeout>] [list]\n"
|
|
|
|
#else
|
dfu: allow to manage DFU on several devices
Add support of DFU for several interface/device
with one command.
The format for "dfu_alt_info" in this case is :
- <interface> <dev>'='alternate list (';' separated)
- each interface is separated by '&'
The previous behavior is always supported.
One example for NOR (bootloaders) + NAND (rootfs in UBI):
U-Boot> env set dfu_alt_info \
"sf 0:0:10000000:0=spl part 0 1;u-boot part 0 2; \
u-boot-env part 0 3&nand 0=UBI partubi 0,3"
U-Boot> dfu 0 list
DFU alt settings list:
dev: SF alt: 0 name: spl layout: RAW_ADDR
dev: SF alt: 1 name: ssbl layout: RAW_ADDR
dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR
dev: NAND alt: 3 name: UBI layout: RAW_ADDR
U-Boot> dfu 0
$> dfu-util -l
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=3, name="UBI", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=2, name="u-boot-env", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=1, name="u-boot", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=0, name="spl", serial="002700333338511934383330"
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2019-10-14 07:28:02 +00:00
|
|
|
"<USB_controller> [<interface> <dev>] [list]\n"
|
2019-11-27 16:12:15 +00:00
|
|
|
#endif
|
2013-10-04 17:22:26 +00:00
|
|
|
" - device firmware upgrade via <USB_controller>\n"
|
|
|
|
" on device <dev>, attached to interface\n"
|
|
|
|
" <interface>\n"
|
2019-11-27 16:12:15 +00:00
|
|
|
#ifdef CONFIG_DFU_TIMEOUT
|
|
|
|
" [<timeout>] - specify inactivity timeout in seconds\n"
|
|
|
|
#endif
|
2013-10-04 17:22:26 +00:00
|
|
|
" [list] - list available alt settings\n"
|
2018-02-16 15:41:17 +00:00
|
|
|
#endif
|
2018-02-16 15:41:18 +00:00
|
|
|
#ifdef CONFIG_DFU_OVER_TFTP
|
|
|
|
#ifdef CONFIG_DFU_OVER_USB
|
2018-02-16 15:41:17 +00:00
|
|
|
"dfu "
|
|
|
|
#endif
|
dfu: allow to manage DFU on several devices
Add support of DFU for several interface/device
with one command.
The format for "dfu_alt_info" in this case is :
- <interface> <dev>'='alternate list (';' separated)
- each interface is separated by '&'
The previous behavior is always supported.
One example for NOR (bootloaders) + NAND (rootfs in UBI):
U-Boot> env set dfu_alt_info \
"sf 0:0:10000000:0=spl part 0 1;u-boot part 0 2; \
u-boot-env part 0 3&nand 0=UBI partubi 0,3"
U-Boot> dfu 0 list
DFU alt settings list:
dev: SF alt: 0 name: spl layout: RAW_ADDR
dev: SF alt: 1 name: ssbl layout: RAW_ADDR
dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR
dev: NAND alt: 3 name: UBI layout: RAW_ADDR
U-Boot> dfu 0
$> dfu-util -l
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=3, name="UBI", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=2, name="u-boot-env", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=1, name="u-boot", serial="002700333338511934383330"
Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
intf=0, alt=0, name="spl", serial="002700333338511934383330"
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2019-10-14 07:28:02 +00:00
|
|
|
"tftp [<interface> <dev>] [<addr>]\n"
|
2015-08-23 22:21:48 +00:00
|
|
|
" - device firmware upgrade via TFTP\n"
|
|
|
|
" on device <dev>, attached to interface\n"
|
|
|
|
" <interface>\n"
|
|
|
|
" [<addr>] - address where FIT image has been stored\n"
|
|
|
|
#endif
|
2012-08-06 12:41:09 +00:00
|
|
|
);
|