cmd_dfu.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * cmd_dfu.c -- dfu command
  3. *
  4. * Copyright (C) 2012 Samsung Electronics
  5. * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
  6. * Lukasz Majewski <l.majewski@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <command.h>
  24. #include <malloc.h>
  25. #include <dfu.h>
  26. #include <asm/errno.h>
  27. #include <g_dnl.h>
  28. static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  29. {
  30. const char *str_env;
  31. char *s = "dfu";
  32. char *env_bkp;
  33. int ret;
  34. if (argc < 3)
  35. return CMD_RET_USAGE;
  36. str_env = getenv("dfu_alt_info");
  37. if (str_env == NULL) {
  38. printf("%s: \"dfu_alt_info\" env variable not defined!\n",
  39. __func__);
  40. return CMD_RET_FAILURE;
  41. }
  42. env_bkp = strdup(str_env);
  43. ret = dfu_config_entities(env_bkp, argv[1],
  44. (int)simple_strtoul(argv[2], NULL, 10));
  45. if (ret)
  46. return CMD_RET_FAILURE;
  47. if (argc > 3 && strcmp(argv[3], "list") == 0) {
  48. dfu_show_entities();
  49. goto done;
  50. }
  51. #ifdef CONFIG_TRATS
  52. board_usb_init();
  53. #endif
  54. g_dnl_register(s);
  55. while (1) {
  56. if (ctrlc())
  57. goto exit;
  58. usb_gadget_handle_interrupts();
  59. }
  60. exit:
  61. g_dnl_unregister();
  62. done:
  63. dfu_free_entities();
  64. free(env_bkp);
  65. return CMD_RET_SUCCESS;
  66. }
  67. U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
  68. "Device Firmware Upgrade",
  69. "<interface> <dev> [list]\n"
  70. " - device firmware upgrade on a device <dev>\n"
  71. " attached to interface <interface>\n"
  72. " [list] - list available alt settings"
  73. );