dfu.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * cmd_dfu.c -- dfu command
  4. *
  5. * Copyright (C) 2015
  6. * Lukasz Majewski <l.majewski@majess.pl>
  7. *
  8. * Copyright (C) 2012 Samsung Electronics
  9. * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
  10. * Lukasz Majewski <l.majewski@samsung.com>
  11. */
  12. #include <common.h>
  13. #include <watchdog.h>
  14. #include <dfu.h>
  15. #include <console.h>
  16. #include <g_dnl.h>
  17. #include <usb.h>
  18. #include <net.h>
  19. static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  20. {
  21. if (argc < 2)
  22. return CMD_RET_USAGE;
  23. #ifdef CONFIG_DFU_OVER_USB
  24. char *usb_controller = argv[1];
  25. #endif
  26. #if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP)
  27. char *interface = NULL;
  28. char *devstring = NULL;
  29. #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
  30. unsigned long value = 0;
  31. #endif
  32. if (argc >= 4) {
  33. interface = argv[2];
  34. devstring = argv[3];
  35. }
  36. #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
  37. if (argc == 5 || argc == 3)
  38. value = simple_strtoul(argv[argc - 1], NULL, 0);
  39. #endif
  40. #endif
  41. int ret = 0;
  42. #ifdef CONFIG_DFU_OVER_TFTP
  43. if (!strcmp(argv[1], "tftp"))
  44. return update_tftp(value, interface, devstring);
  45. #endif
  46. #ifdef CONFIG_DFU_OVER_USB
  47. ret = dfu_init_env_entities(interface, devstring);
  48. if (ret)
  49. goto done;
  50. #ifdef CONFIG_DFU_TIMEOUT
  51. dfu_set_timeout(value * 1000);
  52. #endif
  53. ret = CMD_RET_SUCCESS;
  54. if (strcmp(argv[argc - 1], "list") == 0) {
  55. dfu_show_entities();
  56. goto done;
  57. }
  58. int controller_index = simple_strtoul(usb_controller, NULL, 0);
  59. run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
  60. done:
  61. dfu_free_entities();
  62. #endif
  63. return ret;
  64. }
  65. U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
  66. "Device Firmware Upgrade",
  67. ""
  68. #ifdef CONFIG_DFU_OVER_USB
  69. #ifdef CONFIG_DFU_TIMEOUT
  70. "<USB_controller> [<interface> <dev>] [<timeout>] [list]\n"
  71. #else
  72. "<USB_controller> [<interface> <dev>] [list]\n"
  73. #endif
  74. " - device firmware upgrade via <USB_controller>\n"
  75. " on device <dev>, attached to interface\n"
  76. " <interface>\n"
  77. #ifdef CONFIG_DFU_TIMEOUT
  78. " [<timeout>] - specify inactivity timeout in seconds\n"
  79. #endif
  80. " [list] - list available alt settings\n"
  81. #endif
  82. #ifdef CONFIG_DFU_OVER_TFTP
  83. #ifdef CONFIG_DFU_OVER_USB
  84. "dfu "
  85. #endif
  86. "tftp [<interface> <dev>] [<addr>]\n"
  87. " - device firmware upgrade via TFTP\n"
  88. " on device <dev>, attached to interface\n"
  89. " <interface>\n"
  90. " [<addr>] - address where FIT image has been stored\n"
  91. #endif
  92. );