Blame view

common/cmd_dfu.c 1.57 KB
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
1
2
3
4
5
6
7
  /*
   * cmd_dfu.c -- dfu command
   *
   * Copyright (C) 2012 Samsung Electronics
   * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
   *	    Lukasz Majewski <l.majewski@samsung.com>
   *
1a4596601   Wolfgang Denk   Add GPL-2.0+ SPDX...
8
   * SPDX-License-Identifier:	GPL-2.0+
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
9
10
11
   */
  
  #include <common.h>
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
12
  #include <dfu.h>
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
13
  #include <g_dnl.h>
16297cfb2   Mateusz Zalega   usb: new board-sp...
14
  #include <usb.h>
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
15
16
17
  
  static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  {
16297cfb2   Mateusz Zalega   usb: new board-sp...
18
19
20
21
22
23
  	if (argc < 4)
  		return CMD_RET_USAGE;
  
  	char *usb_controller = argv[1];
  	char *interface = argv[2];
  	char *devstring = argv[3];
b823fd9ba   Albert ARIBAUD   ARM: prevent misa...
24
  	char *s = "dfu";
6bed7ce56   Lukasz Majewski   dfu: Implementati...
25
  	int ret, i = 0;
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
26

16297cfb2   Mateusz Zalega   usb: new board-sp...
27
28
  	ret = dfu_init_env_entities(interface, simple_strtoul(devstring,
  							      NULL, 10));
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
29
  	if (ret)
765c5ae5b   Lukasz Majewski   dfu: Extract comm...
30
  		return ret;
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
31

16297cfb2   Mateusz Zalega   usb: new board-sp...
32
  	if (argc > 4 && strcmp(argv[4], "list") == 0) {
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
33
34
35
  		dfu_show_entities();
  		goto done;
  	}
16297cfb2   Mateusz Zalega   usb: new board-sp...
36
37
  	int controller_index = simple_strtoul(usb_controller, NULL, 0);
  	board_usb_init(controller_index, USB_INIT_DEVICE);
ea3e21226   Pantelis Antoniou   dfu: Only perform...
38

a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
39
40
  	g_dnl_register(s);
  	while (1) {
6bed7ce56   Lukasz Majewski   dfu: Implementati...
41
42
43
44
45
46
47
48
  		if (dfu_reset())
  			/*
  			 * This extra number of usb_gadget_handle_interrupts()
  			 * calls is necessary to assure correct transmission
  			 * completion with dfu-util
  			 */
  			if (++i == 10)
  				goto exit;
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
49
50
51
52
53
54
55
56
57
  		if (ctrlc())
  			goto exit;
  
  		usb_gadget_handle_interrupts();
  	}
  exit:
  	g_dnl_unregister();
  done:
  	dfu_free_entities();
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
58

6bed7ce56   Lukasz Majewski   dfu: Implementati...
59
60
  	if (dfu_reset())
  		run_command("reset", 0);
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
61
62
63
64
65
  	return CMD_RET_SUCCESS;
  }
  
  U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
  	"Device Firmware Upgrade",
16297cfb2   Mateusz Zalega   usb: new board-sp...
66
67
68
69
70
71
72
73
74
75
  	"<USB_controller> <interface> <dev> [list]
  "
  	"  - device firmware upgrade via <USB_controller>
  "
  	"    on device <dev>, attached to interface
  "
  	"    <interface>
  "
  	"    [list] - list available alt settings
  "
a006a5dea   Lukasz Majewski   dfu:cmd: Support ...
76
  );