Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2012 by Amaury Pouly |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
Amaury Pouly | c535794 | 2013-06-13 02:02:53 +0200 | [diff] [blame] | 21 | #ifndef __HWSTUB_PROTOCOL__ |
| 22 | #define __HWSTUB_PROTOCOL__ |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 23 | |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 24 | /** |
| 25 | * HWStub protocol version |
| 26 | */ |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 27 | |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 28 | #define HWSTUB_VERSION_MAJOR 4 |
Marcin Bukat | cd04a5f | 2014-11-18 23:27:26 +0100 | [diff] [blame] | 29 | #define HWSTUB_VERSION_MINOR 1 |
Amaury Pouly | dc869e7 | 2014-05-02 00:32:41 +0200 | [diff] [blame] | 30 | |
Amaury Pouly | 29de342 | 2014-08-09 18:35:37 +0200 | [diff] [blame] | 31 | #define HWSTUB_VERSION__(maj, min) #maj"."#min |
| 32 | #define HWSTUB_VERSION_(maj, min) HWSTUB_VERSION__(maj, min) |
| 33 | #define HWSTUB_VERSION HWSTUB_VERSION_(HWSTUB_VERSION_MAJOR, HWSTUB_VERSION_MINOR) |
| 34 | |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 35 | /** |
| 36 | * A device can use any VID:PID but in case hwstub is in full control of the |
| 37 | * device, the preferred VID:PID is the following. |
| 38 | */ |
| 39 | |
Amaury Pouly | c535794 | 2013-06-13 02:02:53 +0200 | [diff] [blame] | 40 | #define HWSTUB_USB_VID 0xfee1 |
| 41 | #define HWSTUB_USB_PID 0xdead |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 42 | |
| 43 | /** |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 44 | * The device class should be per interface and the hwstub interface must use |
| 45 | * the following class, subclass and protocol. |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 46 | */ |
| 47 | |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 48 | #define HWSTUB_CLASS 0xff |
Amaury Pouly | 43ca127 | 2014-08-04 20:26:48 +0200 | [diff] [blame] | 49 | #define HWSTUB_SUBCLASS 0xde |
| 50 | #define HWSTUB_PROTOCOL 0xad |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 51 | |
| 52 | /** |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 53 | * Descriptors can be retrieved using configuration descriptor or individually |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 54 | * using the standard GetDescriptor request on the interface. |
| 55 | */ |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 56 | |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 57 | #define HWSTUB_DT_VERSION 0x41 /* mandatory */ |
| 58 | #define HWSTUB_DT_LAYOUT 0x42 /* mandatory */ |
| 59 | #define HWSTUB_DT_TARGET 0x43 /* mandatory */ |
| 60 | #define HWSTUB_DT_STMP 0x44 /* optional */ |
| 61 | #define HWSTUB_DT_PP 0x45 /* optional */ |
| 62 | #define HWSTUB_DT_DEVICE 0x46 /* optional */ |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 63 | |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 64 | struct hwstub_version_desc_t |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 65 | { |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 66 | uint8_t bLength; |
| 67 | uint8_t bDescriptorType; |
| 68 | /* full version information */ |
| 69 | uint8_t bMajor; |
| 70 | uint8_t bMinor; |
| 71 | uint8_t bRevision; |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 72 | } __attribute__((packed)); |
| 73 | |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 74 | struct hwstub_layout_desc_t |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 75 | { |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 76 | uint8_t bLength; |
| 77 | uint8_t bDescriptorType; |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 78 | /* describe the range of memory used by the running code */ |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 79 | uint32_t dCodeStart; |
| 80 | uint32_t dCodeSize; |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 81 | /* describe the range of memory used by the stack */ |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 82 | uint32_t dStackStart; |
| 83 | uint32_t dStackSize; |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 84 | /* describe the range of memory available as a buffer */ |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 85 | uint32_t dBufferStart; |
| 86 | uint32_t dBufferSize; |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 87 | } __attribute__((packed)); |
| 88 | |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 89 | struct hwstub_stmp_desc_t |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 90 | { |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 91 | uint8_t bLength; |
| 92 | uint8_t bDescriptorType; |
| 93 | /* Chip ID and revision */ |
| 94 | uint16_t wChipID; /* 0x3780 for STMP3780 for example */ |
| 95 | uint8_t bRevision; /* 0=TA1 on STMP3780 for example */ |
| 96 | uint8_t bPackage; /* 0=169BGA for example */ |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 97 | } __attribute__((packed)); |
| 98 | |
Amaury Pouly | 238be18 | 2014-04-12 00:08:11 +0200 | [diff] [blame] | 99 | struct hwstub_pp_desc_t |
| 100 | { |
| 101 | uint8_t bLength; |
| 102 | uint8_t bDescriptorType; |
| 103 | /* Chip ID and revision */ |
| 104 | uint16_t wChipID; /* 0x5002 for PP5002 for example */ |
| 105 | uint8_t bRevision[2]; /* 'B1' for B1 for example */ |
| 106 | } __attribute__((packed)); |
| 107 | |
Amaury Pouly | f617da0 | 2013-07-13 17:38:34 +0200 | [diff] [blame] | 108 | #define HWSTUB_TARGET_UNK ('U' | 'N' << 8 | 'K' << 16 | ' ' << 24) |
| 109 | #define HWSTUB_TARGET_STMP ('S' | 'T' << 8 | 'M' << 16 | 'P' << 24) |
Marcin Bukat | 8e63338 | 2013-07-18 23:55:35 +0200 | [diff] [blame] | 110 | #define HWSTUB_TARGET_RK27 ('R' | 'K' << 8 | '2' << 16 | '7' << 24) |
Amaury Pouly | ccfa518 | 2014-04-07 22:23:54 +0200 | [diff] [blame] | 111 | #define HWSTUB_TARGET_PP ('P' | 'P' << 8 | ' ' << 16 | ' ' << 24) |
Marcin Bukat | d11704f | 2014-09-23 13:30:17 +0200 | [diff] [blame] | 112 | #define HWSTUB_TARGET_ATJ ('A' | 'T' << 8 | 'J' << 16 | ' ' << 24) |
Amaury Pouly | f617da0 | 2013-07-13 17:38:34 +0200 | [diff] [blame] | 113 | |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 114 | struct hwstub_target_desc_t |
Amaury Pouly | f617da0 | 2013-07-13 17:38:34 +0200 | [diff] [blame] | 115 | { |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 116 | uint8_t bLength; |
| 117 | uint8_t bDescriptorType; |
| 118 | /* Target ID and name */ |
| 119 | uint32_t dID; |
| 120 | char bName[58]; |
| 121 | } __attribute__((packed)); |
Amaury Pouly | f617da0 | 2013-07-13 17:38:34 +0200 | [diff] [blame] | 122 | |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 123 | struct hwstub_device_desc_t |
| 124 | { |
| 125 | uint8_t bLength; |
| 126 | uint8_t bDescriptorType; |
| 127 | /* Give the bRequest value for */ |
| 128 | } __attribute__((packed)); |
| 129 | |
| 130 | /** |
| 131 | * Control commands |
| 132 | * |
| 133 | * These commands are sent to the interface, using the standard bRequest field |
| 134 | * of the SETUP packet. The wIndex contains the interface number. The wValue |
| 135 | * contains an ID which is used for requests requiring several transfers. |
| 136 | */ |
| 137 | |
| 138 | #define HWSTUB_GET_LOG 0x40 |
| 139 | #define HWSTUB_READ 0x41 |
| 140 | #define HWSTUB_READ2 0x42 |
| 141 | #define HWSTUB_WRITE 0x43 |
| 142 | #define HWSTUB_EXEC 0x44 |
Marcin Bukat | cd04a5f | 2014-11-18 23:27:26 +0100 | [diff] [blame] | 143 | #define HWSTUB_READ2_ATOMIC 0x45 |
| 144 | #define HWSTUB_WRITE_ATOMIC 0x46 |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 145 | |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 146 | /** |
Amaury Pouly | c17d30f | 2014-02-04 00:10:41 +0100 | [diff] [blame] | 147 | * HWSTUB_GET_LOG: |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 148 | * The log is returned as part of the control transfer. |
| 149 | */ |
| 150 | |
| 151 | /** |
Marcin Bukat | cd04a5f | 2014-11-18 23:27:26 +0100 | [diff] [blame] | 152 | * HWSTUB_READ and HWSTUB_READ2(_ATOMIC): |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 153 | * Read a range of memory. The request works in two steps: first the host |
| 154 | * sends HWSTUB_READ with the parameters (address, length) and then |
| 155 | * a HWSTUB_READ2 to retrieve the buffer. Both requests must use the same |
| 156 | * ID in wValue, otherwise the second request will be STALLed. |
Marcin Bukat | cd04a5f | 2014-11-18 23:27:26 +0100 | [diff] [blame] | 157 | * HWSTUB_READ2_ATOMIC behaves the same as HWSTUB_READ2 except that the read |
| 158 | * is guaranteed to be atomic (ie performed as a single memory access) and |
| 159 | * will be STALLed if atomicity can not be ensured. |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 160 | */ |
| 161 | |
| 162 | struct hwstub_read_req_t |
| 163 | { |
| 164 | uint32_t dAddress; |
| 165 | } __attribute__((packed)); |
Amaury Pouly | c535794 | 2013-06-13 02:02:53 +0200 | [diff] [blame] | 166 | |
| 167 | /** |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 168 | * HWSTUB_WRITE |
| 169 | * Write a range of memory. The payload starts with the following header, everything |
| 170 | * which follows is data. |
Marcin Bukat | cd04a5f | 2014-11-18 23:27:26 +0100 | [diff] [blame] | 171 | * HWSTUB_WRITE_ATOMIC behaves the same except it is atomic. See HWSTUB_READ2_ATOMIC. |
Amaury Pouly | 12ce7fc | 2014-05-25 16:06:31 +0200 | [diff] [blame] | 172 | */ |
| 173 | struct hwstub_write_req_t |
| 174 | { |
| 175 | uint32_t dAddress; |
| 176 | } __attribute__((packed)); |
| 177 | |
| 178 | /** |
| 179 | * HWSTUB_EXEC: |
| 180 | * Execute code at an address. Several options are available regarding ARM vs Thumb, |
| 181 | * jump vs call. |
| 182 | */ |
| 183 | |
| 184 | #define HWSTUB_EXEC_ARM (0 << 0) /* target code is ARM */ |
| 185 | #define HWSTUB_EXEC_THUMB (1 << 0) /* target code is Thumb */ |
| 186 | #define HWSTUB_EXEC_JUMP (0 << 1) /* branch, code will never turn */ |
| 187 | #define HWSTUB_EXEC_CALL (1 << 1) /* call and expect return */ |
| 188 | |
| 189 | struct hwstub_exec_req_t |
| 190 | { |
| 191 | uint32_t dAddress; |
| 192 | uint16_t bmFlags; |
Amaury Pouly | 43ca127 | 2014-08-04 20:26:48 +0200 | [diff] [blame] | 193 | } __attribute__((packed)); |
Amaury Pouly | f44d956 | 2012-11-14 12:51:51 +0100 | [diff] [blame] | 194 | |
Amaury Pouly | c535794 | 2013-06-13 02:02:53 +0200 | [diff] [blame] | 195 | #endif /* __HWSTUB_PROTOCOL__ */ |