1 From 225b899f1e904128ed4794041dc625751c08fc3f Mon Sep 17 00:00:00 2001
2 From: Martin Meloun <meloumar@cmp.felk.cvut.cz>
3 Date: Mon, 26 Aug 2013 11:23:24 +0200
4 Subject: [PATCH] Implement USB_VENDOR_CALL feature in usb_sendhex
6 USB_VENDOR_CALL feature sends a command with a argument
7 (both 16bit) and expects 16bit return value. It is used
8 for calling functions on the target. If mixed with other
9 arguments, it is executed right before GOTO.
11 Signed-off-by: Martin Meloun <meloumar@cmp.felk.cvut.cz>
13 app-host/usb_sendhex/usb_sendhex.c | 57 ++++++++++++++++++++++++++++++++++----
14 1 file changed, 52 insertions(+), 5 deletions(-)
16 diff --git a/app-host/usb_sendhex/usb_sendhex.c b/app-host/usb_sendhex/usb_sendhex.c
17 index 16f4907..c297822 100644
18 --- a/app-host/usb_sendhex/usb_sendhex.c
19 +++ b/app-host/usb_sendhex/usb_sendhex.c
22 * Based on 'ul_sendhex'
24 - * Version 1.0 - 2004/02/03
25 + * Version 1.1 - 2013/08/26
29 @@ -52,6 +52,9 @@ unsigned long mem_length = 0xff00;
30 unsigned long max_block = 1024;
31 unsigned long go_addr = 3;
39 @@ -579,6 +582,33 @@ int download_file(char *file_name, char *format)
43 +int send_cmd_call(int cmd, int val)
46 + usb_dev_handle *hdev;
49 + hdev = usb_open_device(vid, pid);
53 + perror("send_cmd_call : USB open failed");
57 + ret = usb_control_msg(hdev, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
58 + USB_VENDOR_CALL, val & 0xffff, cmd & 0xffff, resp, sizeof(resp), USB_TIMEOUT);
59 + resp_val = usb_swab16(*((uint16_t *)(resp)));
62 + printf("Call %4X (%4X) ERROR %d: %s\n", (uint16_t)(cmd & 0xffff), (uint16_t)(val & 0xffff), ret, usb_strerror());
64 + printf("Call %4X (%4X): %4X\n", (uint16_t)(cmd & 0xffff), (uint16_t)(val & 0xffff), resp_val);
66 + usb_close_device(hdev);
70 int send_cmd_go(unsigned long addr)
73 @@ -893,6 +923,8 @@ usage(void)
74 printf(" -s, --start <addr> start address of transfer\n");
75 printf(" -l, --length <num> length of upload block\n");
76 printf(" -b, --block <num> maximal block length\n");
77 + printf(" -c, --call <num> vendor custom call\n");
78 + printf(" -a, --argument <num> argument for vendor custom call\n");
79 printf(" -g, --go <addr> start program from address\n");
80 printf(" -r, --reset reset before download\n");
81 printf(" -E, --mass-erase <mode> full device erase\n");
82 @@ -917,6 +949,8 @@ int main(int argc, char *argv[])
83 { "start", 1, 0, 's' },
84 { "length", 1, 0, 'l' },
85 { "block", 1, 0, 'b' },
86 + { "call", 1, 0, 'c' },
87 + { "argument", 1, 0, 'a' },
89 { "reset", 0, 0, 'r' },
90 { "mass-erase", 1, 0, 'E' },
91 @@ -934,9 +968,9 @@ int main(int argc, char *argv[])
94 #ifndef HAS_GETOPT_LONG
95 - while ((opt = getopt(argc, argv, "d:i:t:s:l:b:g:rE:euwf:pvVhD:")) != EOF)
96 + while ((opt = getopt(argc, argv, "d:i:t:s:l:b:c:a::g:rE:euwf:pvVhD:")) != EOF)
98 - while ((opt = getopt_long(argc, argv, "d:i:t:s:l:b:g:rE:euwf:pvVh", &long_opts[0], NULL)) != EOF)
99 + while ((opt = getopt_long(argc, argv, "d:i:t:s:l:b:c:a:g:rE:euwf:pvVh", &long_opts[0], NULL)) != EOF)
103 @@ -979,6 +1013,13 @@ int main(int argc, char *argv[])
105 max_block = strtoul(optarg, NULL, 0);
108 + call = strtoul(optarg, NULL, 0);
112 + arg = strtoul(optarg, NULL, 0);
115 go_addr = strtoul(optarg, NULL, 0);
117 @@ -1013,7 +1054,7 @@ int main(int argc, char *argv[])
121 - fputs("USB sendhex v.1.0\n", stdout);
122 + fputs("USB sendhex v.1.1\n", stdout);
126 @@ -1021,7 +1062,7 @@ int main(int argc, char *argv[])
127 exit(opt == 'h' ? 0 : 1);
130 - if ((optind >= argc) && !go_flg && !prt_modules && !debugk_flg
131 + if ((optind >= argc) && !go_flg && !call_flg && !prt_modules && !debugk_flg
132 && !masserase_flg && !regerase_flg && !reset_flg)
135 @@ -1062,6 +1103,12 @@ int main(int argc, char *argv[])
141 + if (send_cmd_call(call, arg) < 0)
147 if (send_cmd_go(go_addr) < 0)