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