Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 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 | |
| 23 | #include <common.h> |
| 24 | #include <command.h> |
| 25 | #include <malloc.h> |
| 26 | #include <dfu.h> |
| 27 | #include <asm/errno.h> |
| 28 | #include <g_dnl.h> |
| 29 | |
| 30 | static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 31 | { |
| 32 | const char *str_env; |
Albert ARIBAUD | d6d4ec8 | 2012-10-09 09:28:15 +0000 | [diff] [blame] | 33 | char *s = "dfu"; |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 34 | char *env_bkp; |
| 35 | int ret; |
| 36 | |
| 37 | if (argc < 3) |
| 38 | return CMD_RET_USAGE; |
| 39 | |
| 40 | str_env = getenv("dfu_alt_info"); |
| 41 | if (str_env == NULL) { |
| 42 | printf("%s: \"dfu_alt_info\" env variable not defined!\n", |
| 43 | __func__); |
| 44 | return CMD_RET_FAILURE; |
| 45 | } |
| 46 | |
| 47 | env_bkp = strdup(str_env); |
| 48 | ret = dfu_config_entities(env_bkp, argv[1], |
| 49 | (int)simple_strtoul(argv[2], NULL, 10)); |
| 50 | if (ret) |
| 51 | return CMD_RET_FAILURE; |
| 52 | |
Pantelis Antoniou | 14658c0 | 2012-11-30 08:01:08 +0000 | [diff] [blame] | 53 | if (argc > 3 && strcmp(argv[3], "list") == 0) { |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 54 | dfu_show_entities(); |
| 55 | goto done; |
| 56 | } |
| 57 | |
Pantelis Antoniou | 4e3aac0 | 2012-11-30 08:01:07 +0000 | [diff] [blame] | 58 | #ifdef CONFIG_TRATS |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 59 | board_usb_init(); |
Pantelis Antoniou | 4e3aac0 | 2012-11-30 08:01:07 +0000 | [diff] [blame] | 60 | #endif |
| 61 | |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 62 | g_dnl_register(s); |
| 63 | while (1) { |
| 64 | if (ctrlc()) |
| 65 | goto exit; |
| 66 | |
| 67 | usb_gadget_handle_interrupts(); |
| 68 | } |
| 69 | exit: |
| 70 | g_dnl_unregister(); |
| 71 | done: |
| 72 | dfu_free_entities(); |
| 73 | free(env_bkp); |
| 74 | |
| 75 | return CMD_RET_SUCCESS; |
| 76 | } |
| 77 | |
| 78 | U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, |
| 79 | "Device Firmware Upgrade", |
| 80 | "<interface> <dev> [list]\n" |
| 81 | " - device firmware upgrade on a device <dev>\n" |
| 82 | " attached to interface <interface>\n" |
| 83 | " [list] - list available alt settings" |
| 84 | ); |