blob: 1fe982323daf4ff03a74730e7535aab83544ba6b [file] [log] [blame]
Amaury Poulyf44d9562012-11-14 12:51:51 +01001/***************************************************************************
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 Poulyc5357942013-06-13 02:02:53 +020021#ifndef __HWSTUB_PROTOCOL__
22#define __HWSTUB_PROTOCOL__
Amaury Poulyf44d9562012-11-14 12:51:51 +010023
Amaury Pouly12ce7fc2014-05-25 16:06:31 +020024/**
25 * HWStub protocol version
26 */
Amaury Poulyf44d9562012-11-14 12:51:51 +010027
Amaury Pouly12ce7fc2014-05-25 16:06:31 +020028#define HWSTUB_VERSION_MAJOR 4
Marcin Bukatcd04a5f2014-11-18 23:27:26 +010029#define HWSTUB_VERSION_MINOR 1
Amaury Poulydc869e72014-05-02 00:32:41 +020030
Amaury Pouly29de3422014-08-09 18:35:37 +020031#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 Pouly12ce7fc2014-05-25 16:06:31 +020035/**
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 Poulyc5357942013-06-13 02:02:53 +020040#define HWSTUB_USB_VID 0xfee1
41#define HWSTUB_USB_PID 0xdead
Amaury Poulyf44d9562012-11-14 12:51:51 +010042
43/**
Amaury Pouly12ce7fc2014-05-25 16:06:31 +020044 * The device class should be per interface and the hwstub interface must use
45 * the following class, subclass and protocol.
Amaury Poulyf44d9562012-11-14 12:51:51 +010046 */
47
Amaury Pouly12ce7fc2014-05-25 16:06:31 +020048#define HWSTUB_CLASS 0xff
Amaury Pouly43ca1272014-08-04 20:26:48 +020049#define HWSTUB_SUBCLASS 0xde
50#define HWSTUB_PROTOCOL 0xad
Amaury Poulyf44d9562012-11-14 12:51:51 +010051
52/**
Amaury Pouly12ce7fc2014-05-25 16:06:31 +020053 * Descriptors can be retrieved using configuration descriptor or individually
Amaury Poulyc17d30f2014-02-04 00:10:41 +010054 * using the standard GetDescriptor request on the interface.
55 */
Amaury Poulyf44d9562012-11-14 12:51:51 +010056
Amaury Pouly12ce7fc2014-05-25 16:06:31 +020057#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 Poulyf44d9562012-11-14 12:51:51 +010063
Amaury Poulyc17d30f2014-02-04 00:10:41 +010064struct hwstub_version_desc_t
Amaury Poulyf44d9562012-11-14 12:51:51 +010065{
Amaury Poulyc17d30f2014-02-04 00:10:41 +010066 uint8_t bLength;
67 uint8_t bDescriptorType;
68 /* full version information */
69 uint8_t bMajor;
70 uint8_t bMinor;
71 uint8_t bRevision;
Amaury Poulyf44d9562012-11-14 12:51:51 +010072} __attribute__((packed));
73
Amaury Poulyc17d30f2014-02-04 00:10:41 +010074struct hwstub_layout_desc_t
Amaury Poulyf44d9562012-11-14 12:51:51 +010075{
Amaury Poulyc17d30f2014-02-04 00:10:41 +010076 uint8_t bLength;
77 uint8_t bDescriptorType;
Amaury Poulyf44d9562012-11-14 12:51:51 +010078 /* describe the range of memory used by the running code */
Amaury Poulyc17d30f2014-02-04 00:10:41 +010079 uint32_t dCodeStart;
80 uint32_t dCodeSize;
Amaury Poulyf44d9562012-11-14 12:51:51 +010081 /* describe the range of memory used by the stack */
Amaury Poulyc17d30f2014-02-04 00:10:41 +010082 uint32_t dStackStart;
83 uint32_t dStackSize;
Amaury Poulyf44d9562012-11-14 12:51:51 +010084 /* describe the range of memory available as a buffer */
Amaury Poulyc17d30f2014-02-04 00:10:41 +010085 uint32_t dBufferStart;
86 uint32_t dBufferSize;
Amaury Poulyf44d9562012-11-14 12:51:51 +010087} __attribute__((packed));
88
Amaury Poulyc17d30f2014-02-04 00:10:41 +010089struct hwstub_stmp_desc_t
Amaury Poulyf44d9562012-11-14 12:51:51 +010090{
Amaury Poulyc17d30f2014-02-04 00:10:41 +010091 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 Poulyf44d9562012-11-14 12:51:51 +010097} __attribute__((packed));
98
Amaury Pouly238be182014-04-12 00:08:11 +020099struct 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 Poulyf617da02013-07-13 17:38:34 +0200108#define HWSTUB_TARGET_UNK ('U' | 'N' << 8 | 'K' << 16 | ' ' << 24)
109#define HWSTUB_TARGET_STMP ('S' | 'T' << 8 | 'M' << 16 | 'P' << 24)
Marcin Bukat8e633382013-07-18 23:55:35 +0200110#define HWSTUB_TARGET_RK27 ('R' | 'K' << 8 | '2' << 16 | '7' << 24)
Amaury Poulyccfa5182014-04-07 22:23:54 +0200111#define HWSTUB_TARGET_PP ('P' | 'P' << 8 | ' ' << 16 | ' ' << 24)
Marcin Bukatd11704f2014-09-23 13:30:17 +0200112#define HWSTUB_TARGET_ATJ ('A' | 'T' << 8 | 'J' << 16 | ' ' << 24)
Amaury Poulyf617da02013-07-13 17:38:34 +0200113
Amaury Poulyc17d30f2014-02-04 00:10:41 +0100114struct hwstub_target_desc_t
Amaury Poulyf617da02013-07-13 17:38:34 +0200115{
Amaury Poulyc17d30f2014-02-04 00:10:41 +0100116 uint8_t bLength;
117 uint8_t bDescriptorType;
118 /* Target ID and name */
119 uint32_t dID;
120 char bName[58];
121} __attribute__((packed));
Amaury Poulyf617da02013-07-13 17:38:34 +0200122
Amaury Pouly12ce7fc2014-05-25 16:06:31 +0200123struct 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 Bukatcd04a5f2014-11-18 23:27:26 +0100143#define HWSTUB_READ2_ATOMIC 0x45
144#define HWSTUB_WRITE_ATOMIC 0x46
Amaury Pouly12ce7fc2014-05-25 16:06:31 +0200145
Amaury Poulyf44d9562012-11-14 12:51:51 +0100146/**
Amaury Poulyc17d30f2014-02-04 00:10:41 +0100147 * HWSTUB_GET_LOG:
Amaury Poulyf44d9562012-11-14 12:51:51 +0100148 * The log is returned as part of the control transfer.
149 */
150
151/**
Marcin Bukatcd04a5f2014-11-18 23:27:26 +0100152 * HWSTUB_READ and HWSTUB_READ2(_ATOMIC):
Amaury Pouly12ce7fc2014-05-25 16:06:31 +0200153 * 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 Bukatcd04a5f2014-11-18 23:27:26 +0100157 * 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 Pouly12ce7fc2014-05-25 16:06:31 +0200160 */
161
162struct hwstub_read_req_t
163{
164 uint32_t dAddress;
165} __attribute__((packed));
Amaury Poulyc5357942013-06-13 02:02:53 +0200166
167/**
Amaury Pouly12ce7fc2014-05-25 16:06:31 +0200168 * HWSTUB_WRITE
169 * Write a range of memory. The payload starts with the following header, everything
170 * which follows is data.
Marcin Bukatcd04a5f2014-11-18 23:27:26 +0100171 * HWSTUB_WRITE_ATOMIC behaves the same except it is atomic. See HWSTUB_READ2_ATOMIC.
Amaury Pouly12ce7fc2014-05-25 16:06:31 +0200172 */
173struct 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
189struct hwstub_exec_req_t
190{
191 uint32_t dAddress;
192 uint16_t bmFlags;
Amaury Pouly43ca1272014-08-04 20:26:48 +0200193} __attribute__((packed));
Amaury Poulyf44d9562012-11-14 12:51:51 +0100194
Amaury Poulyc5357942013-06-13 02:02:53 +0200195#endif /* __HWSTUB_PROTOCOL__ */