dfu.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 < 4)
  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 = argv[2];
  28. char *devstring = argv[3];
  29. #endif
  30. int ret = 0;
  31. #ifdef CONFIG_DFU_OVER_TFTP
  32. unsigned long addr = 0;
  33. if (!strcmp(argv[1], "tftp")) {
  34. if (argc == 5)
  35. addr = simple_strtoul(argv[4], NULL, 0);
  36. return update_tftp(addr, interface, devstring);
  37. }
  38. #endif
  39. #ifdef CONFIG_DFU_OVER_USB
  40. ret = dfu_init_env_entities(interface, devstring);
  41. if (ret)
  42. goto done;
  43. ret = CMD_RET_SUCCESS;
  44. if (argc > 4 && strcmp(argv[4], "list") == 0) {
  45. dfu_show_entities();
  46. goto done;
  47. }
  48. int controller_index = simple_strtoul(usb_controller, NULL, 0);
  49. run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
  50. done:
  51. dfu_free_entities();
  52. #endif
  53. return ret;
  54. }
  55. U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
  56. "Device Firmware Upgrade",
  57. ""
  58. #ifdef CONFIG_DFU_OVER_USB
  59. "<USB_controller> <interface> <dev> [list]\n"
  60. " - device firmware upgrade via <USB_controller>\n"
  61. " on device <dev>, attached to interface\n"
  62. " <interface>\n"
  63. " [list] - list available alt settings\n"
  64. #endif
  65. #ifdef CONFIG_DFU_OVER_TFTP
  66. #ifdef CONFIG_DFU_OVER_USB
  67. "dfu "
  68. #endif
  69. "tftp <interface> <dev> [<addr>]\n"
  70. " - device firmware upgrade via TFTP\n"
  71. " on device <dev>, attached to interface\n"
  72. " <interface>\n"
  73. " [<addr>] - address where FIT image has been stored\n"
  74. #endif
  75. );