summaryrefslogtreecommitdiff
path: root/utils/hwstub/stmp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/hwstub/stmp')
-rw-r--r--utils/hwstub/stmp/Makefile74
-rw-r--r--utils/hwstub/stmp/config.h56
-rw-r--r--utils/hwstub/stmp/crt0.S17
-rw-r--r--utils/hwstub/stmp/format.c223
-rw-r--r--utils/hwstub/stmp/format.h29
-rw-r--r--utils/hwstub/stmp/hwstub.db31
-rw-r--r--utils/hwstub/stmp/hwstub.lds71
-rw-r--r--utils/hwstub/stmp/logf.c68
-rw-r--r--utils/hwstub/stmp/logf.h31
-rw-r--r--utils/hwstub/stmp/main.c1105
-rw-r--r--utils/hwstub/stmp/memcpy.S176
-rw-r--r--utils/hwstub/stmp/memmove.S190
-rw-r--r--utils/hwstub/stmp/memset.S98
-rw-r--r--utils/hwstub/stmp/protocol.h1
-rw-r--r--utils/hwstub/stmp/stddef.h32
-rw-r--r--utils/hwstub/stmp/stdint.h38
-rw-r--r--utils/hwstub/stmp/string.c29
-rw-r--r--utils/hwstub/stmp/string.h30
-rw-r--r--utils/hwstub/stmp/system.h118
-rw-r--r--utils/hwstub/stmp/usb_ch9.h454
20 files changed, 0 insertions, 2871 deletions
diff --git a/utils/hwstub/stmp/Makefile b/utils/hwstub/stmp/Makefile
deleted file mode 100644
index 4185dcbbc9..0000000000
--- a/utils/hwstub/stmp/Makefile
+++ /dev/null
@@ -1,74 +0,0 @@
1#
2# common
3#
4CC=arm-elf-eabi-gcc
5LD=arm-elf-eabi-gcc
6AS=arm-elf-eabi-gcc
7OC=arm-elf-eabi-objcopy
8CFLAGS=-W -Wall -Wundef -O -nostdlib -ffreestanding -Wstrict-prototypes -pipe -std=gnu99 -mcpu=arm926ej-s -fomit-frame-pointer -Wno-pointer-sign -Wno-override-init -ffunction-sections
9ASFLAGS=$(CFLAGS) -D__ASSEMBLER__
10OCFLAGS=
11LINKER_FILE=hwstub.lds
12TMP_LDS=link.lds
13TMP_MAP=hwstub.map
14LDFLAGS=-lgcc -Os -nostdlib -T$(TMP_LDS) -Wl,-Map,$(TMP_MAP)
15SRC_C=$(wildcard *.c)
16SRC_S=$(wildcard *.S)
17OBJ_C=$(SRC_C:.c=.o)
18OBJ_S=$(SRC_S:.S=.o)
19OBJ=$(OBJ_C) $(OBJ_S)
20OBJ_EXCEPT_CRT0=$(filter-out crt0.o,$(OBJ))
21DEPS=$(OBJ:.o=.d)
22EXEC_ELF=hwstub.elf
23
24#
25# image production
26#
27TOOLS=../../../tools
28SBTOOLS=../../imxtools/sbtools
29
30# sb (stmp37xx)
31EXEC_SB=hwstub.sb
32ELF2SB=$(SBTOOLS)/elftosb -d
33ELF2SB_CMD=-c hwstub.db
34ELF2SB_KEY?=-z
35
36# sb1 (stmp36xx)
37EXEC_SB1=hwstub.sb1
38ELF2SB1_CMD=-loadjump $(EXEC_ELF)
39ELF2SB1_KEY?=
40ELF2SB1=$(SBTOOLS)/elftosb1 -d
41
42EXEC=$(EXEC_ELF) $(EXEC_SB) $(EXEC_SB1)
43
44all: $(EXEC)
45
46# pull in dependency info for *existing* .o files
47-include $(DEPS)
48
49%.o: %.c
50 $(CC) $(CFLAGS) -c -o $@ $<
51 $(CC) -MM $(CFLAGS) $*.c > $*.d
52 @cp -f $*.d $*.d.tmp
53 @sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
54 sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
55 @rm -f $*.d.tmp
56
57%.o: %.S
58 $(AS) $(ASFLAGS) -c -o $@ $<
59
60$(TMP_LDS): $(LINKER_FILE)
61 $(CC) -E -x c - < $< | sed '/#/d' > $@
62
63$(EXEC_ELF): $(OBJ) $(TMP_LDS)
64 $(LD) $(LDFLAGS) -o $@ $(OBJ_EXCEPT_CRT0)
65
66$(EXEC_SB): $(EXEC_ELF)
67 $(ELF2SB) $(ELF2SB_CMD) $(ELF2SB_KEY) -o $@
68
69$(EXEC_SB1): $(EXEC_ELF)
70 $(ELF2SB1) $(ELF2SB1_CMD) $(ELF2SB1_KEY) -o $@
71
72clean:
73 rm -rf $(OBJ) $(DEPS) $(EXEC) $(TMP_LDS) $(TMP_MAP)
74
diff --git a/utils/hwstub/stmp/config.h b/utils/hwstub/stmp/config.h
deleted file mode 100644
index 9d6de07f33..0000000000
--- a/utils/hwstub/stmp/config.h
+++ /dev/null
@@ -1,56 +0,0 @@
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 ****************************************************************************/
21#ifndef __HWSTUB_CONFIG__
22#define __HWSTUB_CONFIG__
23
24#define MEMORYSIZE 0
25#define STACK_SIZE 0x1000
26#define MAX_LOGF_SIZE 128
27
28#define IRAM_ORIG 0
29#define IRAM_SIZE 0x8000
30#define DRAM_ORIG 0x40000000
31#define DRAM_SIZE (MEMORYSIZE * 0x100000)
32
33#define CPU_ARM
34#define ARM_ARCH 5
35
36#if defined(CPU_ARM) && defined(__ASSEMBLER__)
37/* ARMv4T doesn't switch the T bit when popping pc directly, we must use BX */
38.macro ldmpc cond="", order="ia", regs
39#if ARM_ARCH == 4 && defined(USE_THUMB)
40 ldm\cond\order sp!, { \regs, lr }
41 bx\cond lr
42#else
43 ldm\cond\order sp!, { \regs, pc }
44#endif
45.endm
46.macro ldrpc cond=""
47#if ARM_ARCH == 4 && defined(USE_THUMB)
48 ldr\cond lr, [sp], #4
49 bx\cond lr
50#else
51 ldr\cond pc, [sp], #4
52#endif
53.endm
54#endif
55
56#endif /* __HWSTUB_CONFIG__ */
diff --git a/utils/hwstub/stmp/crt0.S b/utils/hwstub/stmp/crt0.S
deleted file mode 100644
index e2d4742d36..0000000000
--- a/utils/hwstub/stmp/crt0.S
+++ /dev/null
@@ -1,17 +0,0 @@
1.section .text,"ax",%progbits
2.code 32
3.align 0x04
4.global start
5start:
6 msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */
7 ldr sp, =oc_stackend
8 /* clear bss */
9 ldr r2, =bss_start
10 ldr r3, =bss_end
11 mov r4, #0
121:
13 cmp r3, r2
14 strhi r4, [r2], #4
15 bhi 1b
16 /* jump to C code */
17 b main
diff --git a/utils/hwstub/stmp/format.c b/utils/hwstub/stmp/format.c
deleted file mode 100644
index f5783159c0..0000000000
--- a/utils/hwstub/stmp/format.c
+++ /dev/null
@@ -1,223 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Gary Czvitkovicz
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 ****************************************************************************/
21
22
23#include <stdarg.h>
24#include <limits.h>
25#include "stddef.h"
26#include "string.h"
27#include "format.h"
28
29static const char hexdigit[] = "0123456789ABCDEF";
30
31void vuprintf(
32 /* call 'push()' for each output letter */
33 int (*push)(void *userp, unsigned char data),
34 void *userp,
35 const char *fmt,
36 va_list ap)
37{
38 char *str;
39 char tmpbuf[12], pad;
40 int ch, width, val, sign, precision;
41 long lval, lsign;
42 unsigned int uval;
43 unsigned long ulval;
44 size_t uszval;
45 ssize_t szval, szsign;
46 bool ok = true;
47
48 tmpbuf[sizeof tmpbuf - 1] = '\0';
49
50 while ((ch = *fmt++) != '\0' && ok)
51 {
52 if (ch == '%')
53 {
54 ch = *fmt++;
55 pad = ' ';
56 if (ch == '0')
57 pad = '0';
58
59 width = 0;
60 while (ch >= '0' && ch <= '9')
61 {
62 width = 10*width + ch - '0';
63 ch = *fmt++;
64 }
65
66 precision = 0;
67 if(ch == '.')
68 {
69 ch = *fmt++;
70 while (ch >= '0' && ch <= '9')
71 {
72 precision = 10*precision + ch - '0';
73 ch = *fmt++;
74 }
75 } else {
76 precision = INT_MAX;
77 }
78
79 str = tmpbuf + sizeof tmpbuf - 1;
80 switch (ch)
81 {
82 case 'c':
83 *--str = va_arg (ap, int);
84 break;
85
86 case 's':
87 str = va_arg (ap, char*);
88 break;
89
90 case 'd':
91 val = sign = va_arg (ap, int);
92 if (val < 0)
93 val = -val;
94 do
95 {
96 *--str = (val % 10) + '0';
97 val /= 10;
98 }
99 while (val > 0);
100 if (sign < 0)
101 *--str = '-';
102 break;
103
104 case 'u':
105 uval = va_arg(ap, unsigned int);
106 do
107 {
108 *--str = (uval % 10) + '0';
109 uval /= 10;
110 }
111 while (uval > 0);
112 break;
113
114 case 'x':
115 case 'X':
116 pad='0';
117 uval = va_arg (ap, int);
118 do
119 {
120 *--str = hexdigit[uval & 0xf];
121 uval >>= 4;
122 }
123 while (uval);
124 break;
125
126 case 'l':
127 ch = *fmt++;
128 switch(ch) {
129 case 'x':
130 case 'X':
131 pad='0';
132 ulval = va_arg (ap, long);
133 do
134 {
135 *--str = hexdigit[ulval & 0xf];
136 ulval >>= 4;
137 }
138 while (ulval);
139 break;
140 case 'd':
141 lval = lsign = va_arg (ap, long);
142 if (lval < 0)
143 lval = -lval;
144 do
145 {
146 *--str = (lval % 10) + '0';
147 lval /= 10;
148 }
149 while (lval > 0);
150 if (lsign < 0)
151 *--str = '-';
152 break;
153
154 case 'u':
155 ulval = va_arg(ap, unsigned long);
156 do
157 {
158 *--str = (ulval % 10) + '0';
159 ulval /= 10;
160 }
161 while (ulval > 0);
162 break;
163
164 default:
165 *--str = 'l';
166 *--str = ch;
167 }
168
169 break;
170
171 case 'z':
172 ch = *fmt++;
173 switch(ch) {
174 case 'd':
175 szval = szsign = va_arg (ap, ssize_t);
176 if (szval < 0)
177 szval = -szval;
178 do
179 {
180 *--str = (szval % 10) + '0';
181 szval /= 10;
182 }
183 while (szval > 0);
184 if (szsign < 0)
185 *--str = '-';
186 break;
187
188 case 'u':
189 uszval = va_arg(ap, size_t);
190 do
191 {
192 *--str = (uszval % 10) + '0';
193 uszval /= 10;
194 }
195 while (uszval > 0);
196 break;
197
198 default:
199 *--str = 'z';
200 *--str = ch;
201 }
202
203 break;
204
205 default:
206 *--str = ch;
207 break;
208 }
209
210 if (width > 0)
211 {
212 width -= strlen (str);
213 while (width-- > 0 && ok)
214 ok=push(userp, pad);
215 }
216 while (*str != '\0' && ok && precision--)
217 ok=push(userp, *str++);
218 }
219 else
220 ok=push(userp, ch);
221 }
222}
223
diff --git a/utils/hwstub/stmp/format.h b/utils/hwstub/stmp/format.h
deleted file mode 100644
index 2ad4229f1e..0000000000
--- a/utils/hwstub/stmp/format.h
+++ /dev/null
@@ -1,29 +0,0 @@
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 ****************************************************************************/
21#ifndef __HWSTUB_FORMAT__
22#define __HWSTUB_FORMAT__
23
24#include <stdarg.h>
25
26void vuprintf(int (*push)(void *userp, unsigned char data),
27 void *userp, const char *fmt, va_list ap);
28
29#endif /* __HWSTUB_FORMAT__ */
diff --git a/utils/hwstub/stmp/hwstub.db b/utils/hwstub/stmp/hwstub.db
deleted file mode 100644
index 1a085da50a..0000000000
--- a/utils/hwstub/stmp/hwstub.db
+++ /dev/null
@@ -1,31 +0,0 @@
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 ****************************************************************************/
21sources
22{
23 hwstub = "hwstub.elf";
24}
25
26section(0)
27{
28 load hwstub;
29 jump hwstub(1);
30}
31
diff --git a/utils/hwstub/stmp/hwstub.lds b/utils/hwstub/stmp/hwstub.lds
deleted file mode 100644
index 61504a3e75..0000000000
--- a/utils/hwstub/stmp/hwstub.lds
+++ /dev/null
@@ -1,71 +0,0 @@
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 ****************************************************************************/
21#include "config.h"
22
23ENTRY(start)
24OUTPUT_FORMAT(elf32-littlearm)
25OUTPUT_ARCH(arm)
26STARTUP(crt0.o)
27
28#define IRAM_END_ADDR (IRAM_ORIG + IRAM_SIZE)
29
30MEMORY
31{
32 OCRAM : ORIGIN = IRAM_ORIG, LENGTH = IRAM_SIZE
33}
34
35SECTIONS
36{
37 .octext :
38 {
39 oc_codestart = .;
40 *(.text*)
41 *(.icode*)
42 *(.data*)
43 *(.rodata*)
44 } > OCRAM
45
46 .bss (NOLOAD) :
47 {
48 bss_start = .;
49 *(.bss)
50 bss_end = .;
51 } > OCRAM
52
53 .stack (NOLOAD) :
54 {
55 oc_codeend = .;
56 oc_stackstart = .;
57 . += STACK_SIZE;
58 oc_stackend = .;
59 oc_bufferstart = .;
60 } > OCRAM
61
62 .ocend IRAM_END_ADDR (NOLOAD) :
63 {
64 oc_bufferend = .;
65 } > OCRAM
66
67 /DISCARD/ :
68 {
69 *(.eh_frame)
70 }
71}
diff --git a/utils/hwstub/stmp/logf.c b/utils/hwstub/stmp/logf.c
deleted file mode 100644
index 3ccc5c5e9f..0000000000
--- a/utils/hwstub/stmp/logf.c
+++ /dev/null
@@ -1,68 +0,0 @@
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 ****************************************************************************/
21#include "config.h"
22#include "logf.h"
23#include "format.h"
24#include "string.h"
25
26static unsigned char logfbuffer[MAX_LOGF_SIZE];
27static int logfread = 0;
28static int logfwrite = 0;
29static int logfen = true;
30
31void enable_logf(bool en)
32{
33 logfen = en;
34}
35
36static int logf_push(void *userp, unsigned char c)
37{
38 (void)userp;
39
40 logfbuffer[logfwrite++] = c;
41 if(logfwrite == MAX_LOGF_SIZE)
42 logfwrite = 0;
43 return true;
44}
45
46void logf(const char *fmt, ...)
47{
48 if(!logfen) return;
49 va_list ap;
50 va_start(ap, fmt);
51 vuprintf(logf_push, NULL, fmt, ap);
52 va_end(ap);
53}
54
55size_t logf_readback(char *buf, size_t max_size)
56{
57 if(logfread == logfwrite)
58 return 0;
59 if(logfread < logfwrite)
60 max_size = MIN(max_size, (size_t)(logfwrite - logfread));
61 else
62 max_size = MIN(max_size, (size_t)(MAX_LOGF_SIZE - logfread));
63 memcpy(buf, &logfbuffer[logfread], max_size);
64 logfread += max_size;
65 if(logfread == MAX_LOGF_SIZE)
66 logfread = 0;
67 return max_size;
68}
diff --git a/utils/hwstub/stmp/logf.h b/utils/hwstub/stmp/logf.h
deleted file mode 100644
index 48c8c2c9b9..0000000000
--- a/utils/hwstub/stmp/logf.h
+++ /dev/null
@@ -1,31 +0,0 @@
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 ****************************************************************************/
21#ifndef __HWSTUB_LOGF__
22#define __HWSTUB_LOGF__
23
24#include "stddef.h"
25#include <stdarg.h>
26
27void enable_logf(bool en);
28void logf(const char *fmt, ...);
29size_t logf_readback(char *buf, size_t max_size);
30
31#endif /* __HWSTUB_LOGF__ */
diff --git a/utils/hwstub/stmp/main.c b/utils/hwstub/stmp/main.c
deleted file mode 100644
index 845f3842ea..0000000000
--- a/utils/hwstub/stmp/main.c
+++ /dev/null
@@ -1,1105 +0,0 @@
1#include "stddef.h"
2#include "protocol.h"
3#include "logf.h"
4#include "usb_ch9.h"
5
6extern unsigned char oc_codestart[];
7extern unsigned char oc_codeend[];
8extern unsigned char oc_stackstart[];
9extern unsigned char oc_stackend[];
10extern unsigned char oc_bufferstart[];
11extern unsigned char oc_bufferend[];
12
13#define oc_codesize ((size_t)(oc_codeend - oc_codestart))
14#define oc_stacksize ((size_t)(oc_stackend - oc_stackstart))
15#define oc_buffersize ((size_t)(oc_bufferend - oc_bufferstart))
16
17/**
18 *
19 * Common
20 *
21 */
22#define MIN(a,b) ((a) < (b) ? (a) : (b))
23
24#define __REG_SET(reg) (*((volatile uint32_t *)(&reg + 1)))
25#define __REG_CLR(reg) (*((volatile uint32_t *)(&reg + 2)))
26#define __REG_TOG(reg) (*((volatile uint32_t *)(&reg + 3)))
27
28#define __BLOCK_SFTRST (1 << 31)
29#define __BLOCK_CLKGATE (1 << 30)
30
31#define __XTRACT(reg, field) ((reg & reg##__##field##_BM) >> reg##__##field##_BP)
32#define __XTRACT_EX(val, field) (((val) & field##_BM) >> field##_BP)
33#define __FIELD_SET(reg, field, val) reg = (reg & ~reg##__##field##_BM) | (val << reg##__##field##_BP)
34
35/**
36 *
37 * Global
38 *
39 */
40
41enum stmp_family_t
42{
43 UNKNOWN,
44 STMP3600,
45 STMP3700,
46 STMP3770,
47 STMP3780
48};
49
50enum stmp_family_t g_stmp_family = UNKNOWN;
51
52/**
53 *
54 * USB subsystem
55 *
56 */
57
58#define USB_BASE 0x80080000
59#define USB_NUM_ENDPOINTS 2
60#define MAX_PKT_SIZE 1024
61#define MAX_PKT_SIZE_EP0 64
62
63/* USB device mode registers (Little Endian) */
64#define REG_USBCMD (*(volatile unsigned int *)(USB_BASE+0x140))
65#define REG_DEVICEADDR (*(volatile unsigned int *)(USB_BASE+0x154))
66#define REG_ENDPOINTLISTADDR (*(volatile unsigned int *)(USB_BASE+0x158))
67#define REG_PORTSC1 (*(volatile unsigned int *)(USB_BASE+0x184))
68#define REG_USBMODE (*(volatile unsigned int *)(USB_BASE+0x1a8))
69#define REG_ENDPTSETUPSTAT (*(volatile unsigned int *)(USB_BASE+0x1ac))
70#define REG_ENDPTPRIME (*(volatile unsigned int *)(USB_BASE+0x1b0))
71#define REG_ENDPTSTATUS (*(volatile unsigned int *)(USB_BASE+0x1b8))
72#define REG_ENDPTCOMPLETE (*(volatile unsigned int *)(USB_BASE+0x1bc))
73#define REG_ENDPTCTRL0 (*(volatile unsigned int *)(USB_BASE+0x1c0))
74#define REG_ENDPTCTRL1 (*(volatile unsigned int *)(USB_BASE+0x1c4))
75#define REG_ENDPTCTRL2 (*(volatile unsigned int *)(USB_BASE+0x1c8))
76#define REG_ENDPTCTRL(_x_) (*(volatile unsigned int *)(USB_BASE+0x1c0+4*(_x_)))
77
78/* USB CMD Register Bit Masks */
79#define USBCMD_RUN (0x00000001)
80#define USBCMD_CTRL_RESET (0x00000002)
81#define USBCMD_PERIODIC_SCHEDULE_EN (0x00000010)
82#define USBCMD_ASYNC_SCHEDULE_EN (0x00000020)
83#define USBCMD_INT_AA_DOORBELL (0x00000040)
84#define USBCMD_ASP (0x00000300)
85#define USBCMD_ASYNC_SCH_PARK_EN (0x00000800)
86#define USBCMD_SUTW (0x00002000)
87#define USBCMD_ATDTW (0x00004000)
88#define USBCMD_ITC (0x00FF0000)
89
90/* Device Address bit masks */
91#define USBDEVICEADDRESS_MASK (0xFE000000)
92#define USBDEVICEADDRESS_BIT_POS (25)
93
94/* Endpoint Setup Status bit masks */
95#define EPSETUP_STATUS_EP0 (0x00000001)
96
97/* PORTSCX Register Bit Masks */
98#define PORTSCX_CURRENT_CONNECT_STATUS (0x00000001)
99#define PORTSCX_CONNECT_STATUS_CHANGE (0x00000002)
100#define PORTSCX_PORT_ENABLE (0x00000004)
101#define PORTSCX_PORT_EN_DIS_CHANGE (0x00000008)
102#define PORTSCX_OVER_CURRENT_ACT (0x00000010)
103#define PORTSCX_OVER_CURRENT_CHG (0x00000020)
104#define PORTSCX_PORT_FORCE_RESUME (0x00000040)
105#define PORTSCX_PORT_SUSPEND (0x00000080)
106#define PORTSCX_PORT_RESET (0x00000100)
107#define PORTSCX_LINE_STATUS_BITS (0x00000C00)
108#define PORTSCX_PORT_POWER (0x00001000)
109#define PORTSCX_PORT_INDICTOR_CTRL (0x0000C000)
110#define PORTSCX_PORT_TEST_CTRL (0x000F0000)
111#define PORTSCX_WAKE_ON_CONNECT_EN (0x00100000)
112#define PORTSCX_WAKE_ON_CONNECT_DIS (0x00200000)
113#define PORTSCX_WAKE_ON_OVER_CURRENT (0x00400000)
114#define PORTSCX_PHY_LOW_POWER_SPD (0x00800000)
115#define PORTSCX_PORT_FORCE_FULL_SPEED (0x01000000)
116#define PORTSCX_PORT_SPEED_MASK (0x0C000000)
117#define PORTSCX_PORT_WIDTH (0x10000000)
118#define PORTSCX_PHY_TYPE_SEL (0xC0000000)
119
120/* bit 11-10 are line status */
121#define PORTSCX_LINE_STATUS_SE0 (0x00000000)
122#define PORTSCX_LINE_STATUS_JSTATE (0x00000400)
123#define PORTSCX_LINE_STATUS_KSTATE (0x00000800)
124#define PORTSCX_LINE_STATUS_UNDEF (0x00000C00)
125#define PORTSCX_LINE_STATUS_BIT_POS (10)
126
127/* bit 15-14 are port indicator control */
128#define PORTSCX_PIC_OFF (0x00000000)
129#define PORTSCX_PIC_AMBER (0x00004000)
130#define PORTSCX_PIC_GREEN (0x00008000)
131#define PORTSCX_PIC_UNDEF (0x0000C000)
132#define PORTSCX_PIC_BIT_POS (14)
133
134/* bit 19-16 are port test control */
135#define PORTSCX_PTC_DISABLE (0x00000000)
136#define PORTSCX_PTC_JSTATE (0x00010000)
137#define PORTSCX_PTC_KSTATE (0x00020000)
138#define PORTSCX_PTC_SE0NAK (0x00030000)
139#define PORTSCX_PTC_PACKET (0x00040000)
140#define PORTSCX_PTC_FORCE_EN (0x00050000)
141#define PORTSCX_PTC_BIT_POS (16)
142
143/* bit 27-26 are port speed */
144#define PORTSCX_PORT_SPEED_FULL (0x00000000)
145#define PORTSCX_PORT_SPEED_LOW (0x04000000)
146#define PORTSCX_PORT_SPEED_HIGH (0x08000000)
147#define PORTSCX_PORT_SPEED_UNDEF (0x0C000000)
148#define PORTSCX_SPEED_BIT_POS (26)
149
150/* bit 28 is parallel transceiver width for UTMI interface */
151#define PORTSCX_PTW (0x10000000)
152#define PORTSCX_PTW_8BIT (0x00000000)
153#define PORTSCX_PTW_16BIT (0x10000000)
154
155/* bit 31-30 are port transceiver select */
156#define PORTSCX_PTS_UTMI (0x00000000)
157#define PORTSCX_PTS_CLASSIC (0x40000000)
158#define PORTSCX_PTS_ULPI (0x80000000)
159#define PORTSCX_PTS_FSLS (0xC0000000)
160#define PORTSCX_PTS_BIT_POS (30)
161
162/* USB MODE Register Bit Masks */
163#define USBMODE_CTRL_MODE_IDLE (0x00000000)
164#define USBMODE_CTRL_MODE_DEVICE (0x00000002)
165#define USBMODE_CTRL_MODE_HOST (0x00000003)
166#define USBMODE_CTRL_MODE_RSV (0x00000001)
167#define USBMODE_SETUP_LOCK_OFF (0x00000008)
168#define USBMODE_STREAM_DISABLE (0x00000010)
169
170/* ENDPOINTCTRLx Register Bit Masks */
171#define EPCTRL_TX_ENABLE (0x00800000)
172#define EPCTRL_TX_DATA_TOGGLE_RST (0x00400000) /* Not EP0 */
173#define EPCTRL_TX_DATA_TOGGLE_INH (0x00200000) /* Not EP0 */
174#define EPCTRL_TX_TYPE (0x000C0000)
175#define EPCTRL_TX_DATA_SOURCE (0x00020000) /* Not EP0 */
176#define EPCTRL_TX_EP_STALL (0x00010000)
177#define EPCTRL_RX_ENABLE (0x00000080)
178#define EPCTRL_RX_DATA_TOGGLE_RST (0x00000040) /* Not EP0 */
179#define EPCTRL_RX_DATA_TOGGLE_INH (0x00000020) /* Not EP0 */
180#define EPCTRL_RX_TYPE (0x0000000C)
181#define EPCTRL_RX_DATA_SINK (0x00000002) /* Not EP0 */
182#define EPCTRL_RX_EP_STALL (0x00000001)
183
184/* bit 19-18 and 3-2 are endpoint type */
185#define EPCTRL_TX_EP_TYPE_SHIFT (18)
186#define EPCTRL_RX_EP_TYPE_SHIFT (2)
187
188#define QH_MULT_POS (30)
189#define QH_ZLT_SEL (0x20000000)
190#define QH_MAX_PKT_LEN_POS (16)
191#define QH_IOS (0x00008000)
192#define QH_NEXT_TERMINATE (0x00000001)
193#define QH_IOC (0x00008000)
194#define QH_MULTO (0x00000C00)
195#define QH_STATUS_HALT (0x00000040)
196#define QH_STATUS_ACTIVE (0x00000080)
197#define EP_QUEUE_CURRENT_OFFSET_MASK (0x00000FFF)
198#define EP_QUEUE_HEAD_NEXT_POINTER_MASK (0xFFFFFFE0)
199#define EP_QUEUE_FRINDEX_MASK (0x000007FF)
200#define EP_MAX_LENGTH_TRANSFER (0x4000)
201
202#define DTD_NEXT_TERMINATE (0x00000001)
203#define DTD_IOC (0x00008000)
204#define DTD_STATUS_ACTIVE (0x00000080)
205#define DTD_STATUS_HALTED (0x00000040)
206#define DTD_STATUS_DATA_BUFF_ERR (0x00000020)
207#define DTD_STATUS_TRANSACTION_ERR (0x00000008)
208#define DTD_RESERVED_FIELDS (0x80007300)
209#define DTD_ADDR_MASK (0xFFFFFFE0)
210#define DTD_PACKET_SIZE (0x7FFF0000)
211#define DTD_LENGTH_BIT_POS (16)
212#define DTD_ERROR_MASK (DTD_STATUS_HALTED | \
213 DTD_STATUS_DATA_BUFF_ERR | \
214 DTD_STATUS_TRANSACTION_ERR)
215/*-------------------------------------------------------------------------*/
216/* manual: 32.13.2 Endpoint Transfer Descriptor (dTD) */
217struct transfer_descriptor {
218 unsigned int next_td_ptr; /* Next TD pointer(31-5), T(0) set
219 indicate invalid */
220 unsigned int size_ioc_sts; /* Total bytes (30-16), IOC (15),
221 MultO(11-10), STS (7-0) */
222 unsigned int buff_ptr0; /* Buffer pointer Page 0 */
223 unsigned int buff_ptr1; /* Buffer pointer Page 1 */
224 unsigned int buff_ptr2; /* Buffer pointer Page 2 */
225 unsigned int buff_ptr3; /* Buffer pointer Page 3 */
226 unsigned int buff_ptr4; /* Buffer pointer Page 4 */
227 unsigned int reserved;
228} __attribute__ ((packed));
229
230static struct transfer_descriptor td_array[USB_NUM_ENDPOINTS*2]
231 __attribute__((aligned(32)));
232
233/* manual: 32.13.1 Endpoint Queue Head (dQH) */
234struct queue_head {
235 unsigned int max_pkt_length; /* Mult(31-30) , Zlt(29) , Max Pkt len
236 and IOS(15) */
237 unsigned int curr_dtd_ptr; /* Current dTD Pointer(31-5) */
238 struct transfer_descriptor dtd; /* dTD overlay */
239 unsigned int setup_buffer[2]; /* Setup data 8 bytes */
240 unsigned int reserved; /* for software use, pointer to the first TD */
241 unsigned int status; /* for software use, status of chain in progress */
242 unsigned int length; /* for software use, transfered bytes of chain in progress */
243 unsigned int wait; /* for softwate use, indicates if the transfer is blocking */
244} __attribute__((packed));
245
246static struct queue_head qh_array[USB_NUM_ENDPOINTS*2] __attribute__((aligned(2048)));
247
248static const unsigned int pipe2mask[] = {
249 0x01, 0x010000,
250 0x02, 0x020000,
251 0x04, 0x040000,
252 0x08, 0x080000,
253 0x10, 0x100000,
254};
255
256/* return transfered size if wait=true */
257static int prime_transfer(int ep_num, void *ptr, int len, bool send, bool wait)
258{
259 int pipe = ep_num * 2 + (send ? 1 : 0);
260 unsigned mask = pipe2mask[pipe];
261 struct transfer_descriptor *td = &td_array[pipe];
262 struct queue_head* qh = &qh_array[pipe];
263
264 /* prepare TD */
265 td->next_td_ptr = DTD_NEXT_TERMINATE;
266 td->size_ioc_sts = (len<< DTD_LENGTH_BIT_POS) | DTD_STATUS_ACTIVE;
267 td->buff_ptr0 = (unsigned int)ptr;
268 td->buff_ptr1 = ((unsigned int)ptr & 0xfffff000) + 0x1000;
269 td->buff_ptr2 = ((unsigned int)ptr & 0xfffff000) + 0x2000;
270 td->buff_ptr3 = ((unsigned int)ptr & 0xfffff000) + 0x3000;
271 td->buff_ptr4 = ((unsigned int)ptr & 0xfffff000) + 0x4000;
272 td->reserved = 0;
273 /* prime */
274 qh->dtd.next_td_ptr = (unsigned int)td;
275 qh->dtd.size_ioc_sts &= ~(QH_STATUS_HALT | QH_STATUS_ACTIVE);
276 REG_ENDPTPRIME |= mask;
277 /* wait for priming to be taken into account */
278 while(!(REG_ENDPTSTATUS & mask));
279 /* wait for completion */
280 if(wait)
281 {
282 while(!(REG_ENDPTCOMPLETE & mask));
283 REG_ENDPTCOMPLETE = mask;
284 /* memory barrier */
285 asm volatile("":::"memory");
286 /* return transfered size */
287 return len - (td->size_ioc_sts >> DTD_LENGTH_BIT_POS);
288 }
289 else
290 return 0;
291}
292
293void usb_drv_set_address(int address)
294{
295 REG_DEVICEADDR = address << USBDEVICEADDRESS_BIT_POS;
296}
297
298/* endpoints */
299#define EP_CONTROL 0
300
301#define DIR_OUT 0
302#define DIR_IN 1
303
304#define EP_DIR(ep) (((ep) & USB_ENDPOINT_DIR_MASK) ? DIR_IN : DIR_OUT)
305#define EP_NUM(ep) ((ep) & USB_ENDPOINT_NUMBER_MASK)
306
307static int usb_drv_send_nonblocking(int endpoint, void* ptr, int length)
308{
309 return prime_transfer(EP_NUM(endpoint), ptr, length, true, false);
310}
311
312static int usb_drv_send(int endpoint, void* ptr, int length)
313{
314 return prime_transfer(EP_NUM(endpoint), ptr, length, true, true);
315}
316
317static int usb_drv_recv(int endpoint, void* ptr, int length)
318{
319 return prime_transfer(EP_NUM(endpoint), ptr, length, false, true);
320}
321
322static int usb_drv_recv_nonblocking(int endpoint, void* ptr, int length)
323{
324 return prime_transfer(EP_NUM(endpoint), ptr, length, false, false);
325}
326
327static int usb_drv_port_speed(void)
328{
329 return (REG_PORTSC1 & 0x08000000) ? 1 : 0;
330}
331
332static void usb_drv_stall(int endpoint, bool stall, bool in)
333{
334 int ep_num = EP_NUM(endpoint);
335
336 if(in)
337 {
338 if(stall)
339 REG_ENDPTCTRL(ep_num) |= EPCTRL_TX_EP_STALL;
340 else
341 REG_ENDPTCTRL(ep_num) &= ~EPCTRL_TX_EP_STALL;
342 }
343 else
344 {
345 if (stall)
346 REG_ENDPTCTRL(ep_num) |= EPCTRL_RX_EP_STALL;
347 else
348 REG_ENDPTCTRL(ep_num) &= ~EPCTRL_RX_EP_STALL;
349 }
350}
351
352static void usb_drv_configure_endpoint(int ep_num, int type)
353{
354 REG_ENDPTCTRL(ep_num) =
355 EPCTRL_RX_DATA_TOGGLE_RST | EPCTRL_RX_ENABLE |
356 EPCTRL_TX_DATA_TOGGLE_RST | EPCTRL_TX_ENABLE |
357 (type << EPCTRL_RX_EP_TYPE_SHIFT) |
358 (type << EPCTRL_TX_EP_TYPE_SHIFT);
359}
360
361/**
362 *
363 * Clkctrl
364 *
365 */
366
367#define HW_CLKCTRL_BASE 0x80040000
368
369#define HW_CLKCTRL_PLLCTRL0 (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x0))
370#define HW_CLKCTRL_PLLCTRL0__BYPASS (1 << 17) /* STMP3600 only */
371#define HW_CLKCTRL_PLLCTRL0__POWER (1 << 16)
372#define HW_CLKCTRL_PLLCTRL0__EN_USB_CLKS (1 << 18)
373
374#define HW_CLKCTRL_PLLCTRL1 (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x10))
375#define HW_CLKCTRL_PLLCTRL1__LOCK (1 << 31)
376
377/* STMP3600 only */
378#define HW_CLKCTRL_CPUCLKCTRL (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x20))
379#define HW_CLKCTRL_CPUCLKCTRL__DIV_BP 0
380#define HW_CLKCTRL_CPUCLKCTRL__DIV_BM 0x3ff
381#define HW_CLKCTRL_CPUCLKCTRL__WAIT_PLL_LOCK (1 << 30)
382
383/* STMP3600 */
384#define HW_CLKCTRL_HBUSCLKCTRL (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x30))
385
386/* STMP3600 only */
387#define HW_CLKCTRL_XBUSCLKCTRL (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x40))
388#define HW_CLKCTRL_XBUSCLKCTRL__DIV_BP 0
389#define HW_CLKCTRL_XBUSCLKCTRL__DIV_BM 0x3ff
390
391/* STMP3600 only */
392#define HW_CLKCTRL_UTMICLKCTRL (*(volatile uint32_t *)(HW_CLKCTRL_BASE + 0x70))
393#define HW_CLKCTRL_UTMICLKCTRL__UTMI_CLK30M_GATE (1 << 30)
394#define HW_CLKCTRL_UTMICLKCTRL__UTMI_CLK120M_GATE (1 << 31)
395
396/**
397 *
398 * Digctl
399 *
400 */
401
402/* Digital control */
403#define HW_DIGCTL_BASE 0x8001C000
404#define HW_DIGCTL_CTRL (*(volatile uint32_t *)(HW_DIGCTL_BASE + 0))
405#define HW_DIGCTL_CTRL__USB_CLKGATE (1 << 2)
406
407#define HW_DIGCTL_MICROSECONDS (*(volatile uint32_t *)(HW_DIGCTL_BASE + 0xC0))
408
409#define HW_DIGCTL_CHIPID (*(volatile uint32_t *)(HW_DIGCTL_BASE + 0x310))
410#define HW_DIGCTL_CHIPID__PRODUCT_CODE_BP 16
411#define HW_DIGCTL_CHIPID__PRODUCT_CODE_BM 0xffff0000
412#define HW_DIGCTL_CHIPID__REVISION_BP 0
413#define HW_DIGCTL_CHIPID__REVISION_BM 0xff
414
415static bool imx233_us_elapsed(uint32_t ref, unsigned us_delay)
416{
417 uint32_t cur = HW_DIGCTL_MICROSECONDS;
418 if(ref + us_delay <= ref)
419 return !(cur > ref) && !(cur < (ref + us_delay));
420 else
421 return (cur < ref) || cur >= (ref + us_delay);
422}
423
424static void udelay(unsigned us)
425{
426 uint32_t ref = HW_DIGCTL_MICROSECONDS;
427 while(!imx233_us_elapsed(ref, us));
428}
429
430#define HZ 1000000
431
432/**
433 *
434 * USB PHY
435 *
436 */
437/* USB Phy */
438#define HW_USBPHY_BASE 0x8007C000
439#define HW_USBPHY_PWD (*(volatile uint32_t *)(HW_USBPHY_BASE + 0))
440
441#define HW_USBPHY_CTRL (*(volatile uint32_t *)(HW_USBPHY_BASE + 0x30))
442
443/**
444 *
445 * DCP
446 *
447 */
448#define HW_DCP_BASE 0x80028000
449
450#define HW_DCP_CTRL (*(volatile unsigned long *)(HW_DCP_BASE + 0x0))
451
452#define HW_DCP_STAT (*(volatile unsigned long *)(HW_DCP_BASE + 0x10))
453#define HW_DCP_STAT__IRQ(x) (1 << (x))
454
455#define HW_DCP_CHANNELCTRL (*(volatile unsigned long *)(HW_DCP_BASE + 0x20))
456#define HW_DCP_CHANNELCTRL__ENABLE_CHANNEL(x) (1 << (x))
457
458#define HW_DCP_CH0CMDPTR (*(volatile unsigned long *)(HW_DCP_BASE + 0x100))
459
460#define HW_DCP_CH0SEMA (*(volatile unsigned long *)(HW_DCP_BASE + 0x110))
461#define HW_DCP_CH0SEMA__INCREMENT(x) (x)
462#define HW_DCP_CH0SEMA__VALUE_BP 16
463#define HW_DCP_CH0SEMA__VALUE_BM (0xff << 16)
464#define HW_DCP_CH0STAT (*(volatile unsigned long *)(HW_DCP_BASE + 0x120))
465
466#define HW_DCP_CTRL0__INTERRUPT_ENABLE (1 << 0)
467#define HW_DCP_CTRL0__DECR_SEMAPHORE (1 << 1)
468#define HW_DCP_CTRL0__ENABLE_MEMCOPY (1 << 4)
469#define HW_DCP_CTRL0__ENABLE_CIPHER (1 << 5)
470#define HW_DCP_CTRL0__ENABLE_HASH (1 << 6)
471#define HW_DCP_CTRL0__CIPHER_ENCRYPT (1 << 8)
472#define HW_DCP_CTRL0__CIPHER_INIT (1 << 9)
473#define HW_DCP_CTRL0__OTP_KEY (1 << 10)
474#define HW_DCP_CTRL0__HASH_INIT (1 << 12)
475#define HW_DCP_CTRL0__HASH_TERM (1 << 13)
476#define HW_DCP_CTRL0__HASH_OUTPUT (1 << 15)
477
478#define HW_DCP_CTRL1__CIPHER_SELECT_BP 0
479#define HW_DCP_CTRL1__CIPHER_SELECT_BM 0xf
480#define HW_DCP_CTRL1__CIPHER_SELECT__AES128 0
481#define HW_DCP_CTRL1__CIPHER_MODE_BP 4
482#define HW_DCP_CTRL1__CIPHER_MODE_BM 0xf0
483#define HW_DCP_CTRL1__CIPHER_MODE__CBC (1 << 4)
484#define HW_DCP_CTRL1__HASH_SELECT_BP 4
485#define HW_DCP_CTRL1__HASH_SELECT_BM 0xf00
486
487struct dcp_packet_t
488{
489 unsigned long next;
490 unsigned long ctrl0;
491 unsigned long ctrl1;
492 unsigned long src_buf;
493 unsigned long dst_buf;
494 unsigned long buf_sz;
495 unsigned long payload_ptr;
496 unsigned long status;
497} __attribute__((packed));
498
499/**
500 *
501 * Misc
502 *
503 */
504
505void memcpy(void *dest, const void *src, size_t n);
506void memmove(void *dest, const void *src, size_t n);
507void memset(void *dst, int value, size_t n);
508
509/**
510 *
511 * USB stack
512 *
513 */
514
515static struct usb_device_descriptor __attribute__((aligned(2)))
516 device_descriptor=
517{
518 .bLength = sizeof(struct usb_device_descriptor),
519 .bDescriptorType = USB_DT_DEVICE,
520 .bcdUSB = 0x0200,
521 .bDeviceClass = USB_CLASS_PER_INTERFACE,
522 .bDeviceSubClass = 0,
523 .bDeviceProtocol = 0,
524 .bMaxPacketSize0 = 64,
525 .idVendor = HWSTUB_USB_VID,
526 .idProduct = HWSTUB_USB_PID,
527 .bcdDevice = HWSTUB_VERSION_MAJOR << 8 | HWSTUB_VERSION_MINOR,
528 .iManufacturer = 1,
529 .iProduct = 2,
530 .iSerialNumber = 3,
531 .bNumConfigurations = 1
532};
533
534#define USB_MAX_CURRENT 200
535
536static struct usb_config_descriptor __attribute__((aligned(2)))
537 config_descriptor =
538{
539 .bLength = sizeof(struct usb_config_descriptor),
540 .bDescriptorType = USB_DT_CONFIG,
541 .wTotalLength = 0, /* will be filled in later */
542 .bNumInterfaces = 1,
543 .bConfigurationValue = 1,
544 .iConfiguration = 0,
545 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
546 .bMaxPower = (USB_MAX_CURRENT + 1) / 2, /* In 2mA units */
547};
548
549/* main interface */
550static struct usb_interface_descriptor __attribute__((aligned(2)))
551 interface_descriptor =
552{
553 .bLength = sizeof(struct usb_interface_descriptor),
554 .bDescriptorType = USB_DT_INTERFACE,
555 .bInterfaceNumber = 0,
556 .bAlternateSetting = 0,
557 .bNumEndpoints = 3,
558 .bInterfaceClass = HWSTUB_CLASS,
559 .bInterfaceSubClass = HWSTUB_SUBCLASS,
560 .bInterfaceProtocol = HWSTUB_PROTOCOL,
561 .iInterface = 4
562};
563
564
565static struct usb_endpoint_descriptor __attribute__((aligned(2)))
566 endpoint_descriptor =
567{
568 .bLength = sizeof(struct usb_endpoint_descriptor),
569 .bDescriptorType = USB_DT_ENDPOINT,
570 .bEndpointAddress = 0,
571 .bmAttributes = USB_ENDPOINT_XFER_BULK,
572 .wMaxPacketSize = 0,
573 .bInterval = 0
574};
575
576static const struct usb_string_descriptor __attribute__((aligned(2)))
577 usb_string_iManufacturer =
578{
579 24,
580 USB_DT_STRING,
581 {'R', 'o', 'c', 'k', 'b', 'o', 'x', '.', 'o', 'r', 'g'}
582};
583
584static const struct usb_string_descriptor __attribute__((aligned(2)))
585 usb_string_iProduct =
586{
587 52,
588 USB_DT_STRING,
589 {'R', 'o', 'c', 'k', 'b', 'o', 'x', ' ',
590 'h', 'a', 'r', 'd', 'w', 'a', 'r', 'e', ' ',
591 'e', 'm', 'u', 'l', 'a', 't', 'e', 'r'}
592};
593
594static struct usb_string_descriptor __attribute__((aligned(2)))
595 usb_string_iSerial =
596{
597 84,
598 USB_DT_STRING,
599 {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
600 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
601 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
602 '0', '0', '0', '0', '0', '0', '0', '0'}
603};
604
605static struct usb_string_descriptor __attribute__((aligned(2)))
606 usb_string_iInterface =
607{
608 28,
609 USB_DT_STRING,
610 {'A', 'c', 'i', 'd', ' ',
611 '0' + (HWSTUB_VERSION_MAJOR >> 4), '0' + (HWSTUB_VERSION_MAJOR & 0xf), '.',
612 '0' + (HWSTUB_VERSION_MINOR >> 4), '0' + (HWSTUB_VERSION_MINOR & 0xf), '.',
613 '0' + (HWSTUB_VERSION_REV >> 4), '0' + (HWSTUB_VERSION_REV & 0xf) }
614};
615
616/* this is stringid #0: languages supported */
617static const struct usb_string_descriptor __attribute__((aligned(2)))
618 lang_descriptor =
619{
620 4,
621 USB_DT_STRING,
622 {0x0409} /* LANGID US English */
623};
624
625#define USB_NUM_STRINGS 5
626
627static const struct usb_string_descriptor* const usb_strings[USB_NUM_STRINGS] =
628{
629 &lang_descriptor,
630 &usb_string_iManufacturer,
631 &usb_string_iProduct,
632 &usb_string_iSerial,
633 &usb_string_iInterface
634};
635
636uint8_t *usb_buffer = oc_bufferstart;
637uint32_t usb_buffer_size = 0;
638
639#define EP_BULK 1
640#define EP_INT 2
641
642static void set_config(void)
643{
644 usb_drv_configure_endpoint(EP_BULK, USB_ENDPOINT_XFER_BULK);
645 usb_drv_configure_endpoint(EP_INT, USB_ENDPOINT_XFER_INT);
646}
647
648static void handle_std_dev_desc(struct usb_ctrlrequest *req)
649{
650 int size;
651 const void* ptr = NULL;
652 unsigned index = req->wValue & 0xff;
653
654 switch(req->wValue >> 8)
655 {
656 case USB_DT_DEVICE:
657 ptr = &device_descriptor;
658 size = sizeof(struct usb_device_descriptor);
659 break;
660 case USB_DT_OTHER_SPEED_CONFIG:
661 case USB_DT_CONFIG:
662 {
663 int max_packet_size;
664
665 /* config desc */
666 if((req->wValue >> 8) ==USB_DT_CONFIG)
667 {
668 max_packet_size = (usb_drv_port_speed() ? 512 : 64);
669 config_descriptor.bDescriptorType = USB_DT_CONFIG;
670 }
671 else
672 {
673 max_packet_size=(usb_drv_port_speed() ? 64 : 512);
674 config_descriptor.bDescriptorType = USB_DT_OTHER_SPEED_CONFIG;
675 }
676 size = sizeof(struct usb_config_descriptor);
677
678 /* interface */
679 memcpy(usb_buffer + size, (void *)&interface_descriptor,
680 sizeof(interface_descriptor));
681 size += sizeof(interface_descriptor);
682 /* endpoint 1: bulk out */
683 endpoint_descriptor.bEndpointAddress = EP_BULK | USB_DIR_OUT;
684 endpoint_descriptor.bmAttributes = USB_ENDPOINT_XFER_BULK;
685 endpoint_descriptor.wMaxPacketSize = 512;
686 memcpy(usb_buffer + size, (void *)&endpoint_descriptor,
687 sizeof(endpoint_descriptor));
688 size += sizeof(endpoint_descriptor);
689 /* endpoint 2: bulk in */
690 endpoint_descriptor.bEndpointAddress = EP_BULK | USB_DIR_IN;
691 endpoint_descriptor.bmAttributes = USB_ENDPOINT_XFER_BULK;
692 endpoint_descriptor.wMaxPacketSize = 512;
693 memcpy(usb_buffer + size, (void *)&endpoint_descriptor,
694 sizeof(endpoint_descriptor));
695 size += sizeof(endpoint_descriptor);
696 /* endpoint 3: int in */
697 endpoint_descriptor.bEndpointAddress = EP_INT | USB_DIR_IN;
698 endpoint_descriptor.bmAttributes = USB_ENDPOINT_XFER_INT;
699 endpoint_descriptor.wMaxPacketSize = 1024;
700 memcpy(usb_buffer + size, (void *)&endpoint_descriptor,
701 sizeof(endpoint_descriptor));
702 size += sizeof(endpoint_descriptor);
703
704 /* fix config descriptor */
705 config_descriptor.bNumInterfaces = 1;
706 config_descriptor.wTotalLength = size;
707 memcpy(usb_buffer, (void *)&config_descriptor, sizeof(config_descriptor));
708
709 ptr = usb_buffer;
710 break;
711 }
712 case USB_DT_STRING:
713 if(index < USB_NUM_STRINGS)
714 {
715 size = usb_strings[index]->bLength;
716 ptr = usb_strings[index];
717 }
718 else
719 usb_drv_stall(EP_CONTROL, true, true);
720 break;
721 default:
722 break;
723 }
724
725 if(ptr)
726 {
727 int length = MIN(size, req->wLength);
728
729 if(ptr != usb_buffer)
730 memcpy(usb_buffer, ptr, length);
731
732 usb_drv_send(EP_CONTROL, usb_buffer, length);
733 usb_drv_recv(EP_CONTROL, NULL, 0);
734 }
735 else
736 usb_drv_stall(EP_CONTROL, true, true);
737}
738
739static void handle_std_dev_req(struct usb_ctrlrequest *req)
740{
741 switch(req->bRequest)
742 {
743 case USB_REQ_GET_CONFIGURATION:
744 usb_buffer[0] = 1;
745 usb_drv_send(EP_CONTROL, usb_buffer, 1);
746 usb_drv_recv(EP_CONTROL, NULL, 0);
747 break;
748 case USB_REQ_SET_CONFIGURATION:
749 usb_drv_send(EP_CONTROL, NULL, 0);
750 set_config();
751 break;
752 case USB_REQ_GET_DESCRIPTOR:
753 handle_std_dev_desc(req);
754 break;
755 case USB_REQ_SET_ADDRESS:
756 usb_drv_send(EP_CONTROL, NULL, 0);
757 usb_drv_set_address(req->wValue);
758 break;
759 case USB_REQ_GET_STATUS:
760 usb_buffer[0] = 0;
761 usb_buffer[1] = 0;
762 usb_drv_send(EP_CONTROL, usb_buffer, 2);
763 usb_drv_recv(EP_CONTROL, NULL, 0);
764 break;
765 default:
766 usb_drv_stall(EP_CONTROL, true, true);
767 }
768}
769
770static void handle_std_req(struct usb_ctrlrequest *req)
771{
772 switch(req->bRequestType & USB_RECIP_MASK)
773 {
774 case USB_RECIP_DEVICE:
775 return handle_std_dev_req(req);
776 default:
777 usb_drv_stall(EP_CONTROL, true, true);
778 }
779}
780
781struct usb_resp_info_version_t g_version =
782{
783 .major = HWSTUB_VERSION_MAJOR,
784 .minor = HWSTUB_VERSION_MINOR,
785 .revision = HWSTUB_VERSION_REV
786};
787
788struct usb_resp_info_layout_t g_layout;
789
790struct usb_resp_info_stmp_t g_stmp;
791
792struct usb_resp_info_features_t g_features =
793{
794 .feature_mask = HWSTUB_FEATURE_LOG | HWSTUB_FEATURE_MEM |
795 HWSTUB_FEATURE_CALL | HWSTUB_FEATURE_JUMP | HWSTUB_FEATURE_AES_OTP
796};
797
798static void fill_layout_info(void)
799{
800 g_layout.oc_code_start = (uint32_t)oc_codestart;
801 g_layout.oc_code_size = oc_codesize;
802 g_layout.oc_stack_start = (uint32_t)oc_stackstart;
803 g_layout.oc_stack_size = oc_stacksize;
804 g_layout.oc_buffer_start = (uint32_t)oc_bufferstart;
805 g_layout.oc_buffer_size = oc_buffersize;
806}
807
808static void fill_stmp_info(void)
809{
810 g_stmp.chipid = __XTRACT(HW_DIGCTL_CHIPID, PRODUCT_CODE);
811 g_stmp.rev = __XTRACT(HW_DIGCTL_CHIPID, REVISION);
812 g_stmp.is_supported = g_stmp.chipid == 0x3780 || g_stmp.chipid == 0x3700 ||
813 g_stmp.chipid == 0x3b00;
814}
815
816static void handle_get_info(struct usb_ctrlrequest *req)
817{
818 void *ptr = NULL;
819 int size = 0;
820 switch(req->wIndex)
821 {
822 case HWSTUB_INFO_VERSION:
823 ptr = &g_version;
824 size = sizeof(g_version);
825 break;
826 case HWSTUB_INFO_LAYOUT:
827 fill_layout_info();
828 ptr = &g_layout;
829 size = sizeof(g_layout);
830 break;
831 case HWSTUB_INFO_STMP:
832 fill_stmp_info();
833 ptr = &g_stmp;
834 size = sizeof(g_stmp);
835 break;
836 case HWSTUB_INFO_FEATURES:
837 ptr = &g_features;
838 size = sizeof(g_features);
839 break;
840 default:
841 usb_drv_stall(EP_CONTROL, true, true);
842 }
843
844 if(ptr)
845 {
846 int length = MIN(size, req->wLength);
847
848 if(ptr != usb_buffer)
849 memcpy(usb_buffer, ptr, length);
850 usb_drv_send(EP_CONTROL, usb_buffer, length);
851 usb_drv_recv(EP_CONTROL, NULL, 0);
852 }
853}
854
855static void handle_get_log(struct usb_ctrlrequest *req)
856{
857 enable_logf(false);
858 int length = logf_readback(usb_buffer, MIN(req->wLength, usb_buffer_size));
859 usb_drv_send(EP_CONTROL, usb_buffer, length);
860 usb_drv_recv(EP_CONTROL, NULL, 0);
861 enable_logf(true);
862}
863
864static void handle_rw_mem(struct usb_ctrlrequest *req)
865{
866 uint32_t addr = req->wValue | req->wIndex << 16;
867 uint16_t length = req->wLength;
868
869 if(req->bRequestType & USB_DIR_IN)
870 {
871 memcpy(usb_buffer, (void *)addr, length);
872 asm volatile("nop" : : : "memory");
873 usb_drv_send(EP_CONTROL, usb_buffer, length);
874 usb_drv_recv(EP_CONTROL, NULL, 0);
875 }
876 else
877 {
878 int size = usb_drv_recv(EP_CONTROL, usb_buffer, length);
879 asm volatile("nop" : : : "memory");
880 if(size != length)
881 usb_drv_stall(EP_CONTROL, true, true);
882 else
883 {
884 memcpy((void *)addr, usb_buffer, length);
885 usb_drv_send(EP_CONTROL, NULL, 0);
886 }
887 }
888}
889
890static void handle_call_jump(struct usb_ctrlrequest *req)
891{
892 uint32_t addr = req->wValue | req->wIndex << 16;
893
894 if(req->bRequest == HWSTUB_CALL)
895 ((void (*)(void))addr)();
896 else
897 {
898 /* disconnect to make sure usb/dma won't interfere */
899 REG_USBCMD &= ~USBCMD_RUN;
900 REG_USBCMD |= USBCMD_CTRL_RESET;
901 asm volatile("bx %0\n" : : "r" (addr) : "memory");
902 }
903}
904
905static void do_aes_otp(void *buffer, unsigned length, unsigned params)
906{
907 static struct dcp_packet_t dcp_packet;
908
909 bool encrypt = !!(params & HWSTUB_AES_OTP_ENCRYPT);
910 /* reset DCP */
911 __REG_SET(HW_DCP_CTRL) = 0x80000000;
912 /* clear clock gate */
913 __REG_CLR(HW_DCP_CTRL) = 0xc0000000;
914 /* enable dma for channel 0 */
915 __REG_SET(HW_DCP_CHANNELCTRL) = HW_DCP_CHANNELCTRL__ENABLE_CHANNEL(0);
916 /* prepare packet */
917 dcp_packet.next = 0;
918
919 dcp_packet.ctrl0 = HW_DCP_CTRL0__INTERRUPT_ENABLE |
920 HW_DCP_CTRL0__DECR_SEMAPHORE | HW_DCP_CTRL0__CIPHER_INIT |
921 HW_DCP_CTRL0__ENABLE_CIPHER | HW_DCP_CTRL0__OTP_KEY |
922 (encrypt ? HW_DCP_CTRL0__CIPHER_ENCRYPT : 0);
923 dcp_packet.ctrl1 = HW_DCP_CTRL1__CIPHER_SELECT__AES128 |
924 HW_DCP_CTRL1__CIPHER_MODE__CBC;
925 dcp_packet.src_buf = (unsigned long)buffer + 16;
926 dcp_packet.dst_buf = (unsigned long)buffer + 16;
927 dcp_packet.buf_sz = length - 16;
928 dcp_packet.payload_ptr = (unsigned long)buffer;
929 dcp_packet.status = 0;
930
931 asm volatile("":::"memory");
932 /* kick */
933 HW_DCP_CH0CMDPTR = (unsigned long)&dcp_packet;
934 HW_DCP_CH0SEMA = HW_DCP_CH0SEMA__INCREMENT(1);
935 /* wait */
936 while(!(HW_DCP_STAT & HW_DCP_STAT__IRQ(0)));
937
938 usb_drv_send_nonblocking(EP_INT, buffer, length);
939}
940
941static void handle_aes_otp(struct usb_ctrlrequest *req)
942{
943 uint16_t length = req->wLength;
944
945 int size = usb_drv_recv(EP_CONTROL, usb_buffer, length);
946 if(size != length)
947 usb_drv_stall(EP_CONTROL, true, true);
948 else
949 usb_drv_send(EP_CONTROL, NULL, 0);
950 do_aes_otp(usb_buffer, length, req->wValue);
951}
952
953static void handle_class_dev_req(struct usb_ctrlrequest *req)
954{
955 switch(req->bRequest)
956 {
957 case HWSTUB_GET_INFO:
958 handle_get_info(req);
959 break;
960 case HWSTUB_GET_LOG:
961 handle_get_log(req);
962 break;
963 case HWSTUB_RW_MEM:
964 handle_rw_mem(req);
965 break;
966 case HWSTUB_CALL:
967 case HWSTUB_JUMP:
968 handle_call_jump(req);
969 break;
970 case HWSTUB_AES_OTP:
971 handle_aes_otp(req);
972 break;
973 default:
974 usb_drv_stall(EP_CONTROL, true, true);
975 }
976}
977
978static void handle_class_req(struct usb_ctrlrequest *req)
979{
980 switch(req->bRequestType & USB_RECIP_MASK)
981 {
982 case USB_RECIP_DEVICE:
983 return handle_class_dev_req(req);
984 default:
985 usb_drv_stall(EP_CONTROL, true, true);
986 }
987}
988
989/**
990 *
991 * Main
992 *
993 */
994
995void main(uint32_t arg)
996{
997 usb_buffer_size = oc_buffersize;
998
999 logf("hwstub %d.%d.%d\n", HWSTUB_VERSION_MAJOR, HWSTUB_VERSION_MINOR,
1000 HWSTUB_VERSION_REV);
1001 logf("argument: 0x%08x\n", arg);
1002
1003 /* detect family */
1004 uint16_t product_code = __XTRACT(HW_DIGCTL_CHIPID, PRODUCT_CODE);
1005 if(product_code >= 0x3600 && product_code < 0x3700)
1006 {
1007 logf("identified STMP3600 family\n");
1008 g_stmp_family = STMP3600;
1009 }
1010 else if(product_code == 0x3700)
1011 {
1012 logf("identified STMP3700 family\n");
1013 g_stmp_family = STMP3700;
1014 }
1015 else if(product_code == 0x37b0)
1016 {
1017 logf("identified STMP3770 family\n");
1018 g_stmp_family = STMP3770;
1019 }
1020 else if(product_code == 0x3780)
1021 {
1022 logf("identified STMP3780 family\n");
1023 g_stmp_family = STMP3780;
1024 }
1025 else
1026 logf("cannot identify family: 0x%x\n", product_code);
1027
1028 /* we don't know if USB was connected or not. In USB recovery mode it will
1029 * but in other cases it might not be. In doubt, disconnect */
1030 REG_USBCMD &= ~USBCMD_RUN;
1031 if(g_stmp_family == STMP3600)
1032 {
1033 /* CPU clock is always derived from PLL, if we switch to PLL, cpu will
1034 * run at 480 MHz unprepared ! That's bad so prepare to run at slow sleed
1035 * (1.2MHz) for a safe transition */
1036 HW_CLKCTRL_CPUCLKCTRL = HW_CLKCTRL_CPUCLKCTRL__WAIT_PLL_LOCK | 400;
1037 /* We need to ensure that XBUS < HBUS but HBUS will be 1.2 MHz after the
1038 * switch so lower XBUS too */
1039 HW_CLKCTRL_XBUSCLKCTRL = 20;
1040 /* Power PLL */
1041 __REG_SET(HW_CLKCTRL_PLLCTRL0) = HW_CLKCTRL_PLLCTRL0__POWER;
1042 HW_CLKCTRL_PLLCTRL0 = (HW_CLKCTRL_PLLCTRL0 & ~0x3ff) | 480;
1043 /* Wait lock */
1044 while(!(HW_CLKCTRL_PLLCTRL1 & HW_CLKCTRL_PLLCTRL1__LOCK));
1045 /* Switch to PLL source */
1046 __REG_CLR(HW_CLKCTRL_PLLCTRL0) = HW_CLKCTRL_PLLCTRL0__BYPASS;
1047 /* Get back XBUS = 24 MHz and CPU = HBUS = 64MHz */
1048 HW_CLKCTRL_CPUCLKCTRL = 7;
1049 HW_CLKCTRL_HBUSCLKCTRL = 7;
1050 HW_CLKCTRL_XBUSCLKCTRL = 1;
1051 __REG_CLR(HW_CLKCTRL_UTMICLKCTRL) = HW_CLKCTRL_UTMICLKCTRL__UTMI_CLK120M_GATE;
1052 __REG_CLR(HW_CLKCTRL_UTMICLKCTRL) = HW_CLKCTRL_UTMICLKCTRL__UTMI_CLK30M_GATE;
1053 }
1054 else
1055 __REG_SET(HW_CLKCTRL_PLLCTRL0) = HW_CLKCTRL_PLLCTRL0__POWER;
1056 /* enable USB PHY PLL */
1057 __REG_SET(HW_CLKCTRL_PLLCTRL0) = HW_CLKCTRL_PLLCTRL0__EN_USB_CLKS;
1058 /* power up USB PHY */
1059 __REG_CLR(HW_USBPHY_CTRL) = __BLOCK_CLKGATE | __BLOCK_SFTRST;
1060 HW_USBPHY_PWD = 0;
1061 /* enable USB controller */
1062 __REG_CLR(HW_DIGCTL_CTRL) = HW_DIGCTL_CTRL__USB_CLKGATE;
1063 /* reset the controller */
1064 REG_USBCMD |= USBCMD_CTRL_RESET;
1065 while (REG_USBCMD & USBCMD_CTRL_RESET);
1066 /* put it in device mode */
1067 REG_USBMODE = USBMODE_CTRL_MODE_DEVICE;
1068 /* reset address */
1069 REG_DEVICEADDR = 0;
1070 /* prepare qh array */
1071 qh_array[0].max_pkt_length = 1 << 29 | MAX_PKT_SIZE_EP0 << 16;
1072 qh_array[1].max_pkt_length = 1 << 29 | MAX_PKT_SIZE_EP0 << 16;
1073 qh_array[2].max_pkt_length = 1 << 29 | MAX_PKT_SIZE << 16;
1074 qh_array[3].max_pkt_length = 1 << 29 | MAX_PKT_SIZE << 16;
1075 /* setup qh */
1076 REG_ENDPOINTLISTADDR = (unsigned int)qh_array;
1077 /* clear setup status */
1078 REG_ENDPTSETUPSTAT = EPSETUP_STATUS_EP0;
1079 /* run! */
1080 REG_USBCMD |= USBCMD_RUN;
1081
1082 while(1)
1083 {
1084 /* wait for setup */
1085 while(!(REG_ENDPTSETUPSTAT & EPSETUP_STATUS_EP0))
1086 ;
1087 /* clear setup status */
1088 REG_ENDPTSETUPSTAT = EPSETUP_STATUS_EP0;
1089 /* check request */
1090 asm volatile("":::"memory");
1091 struct usb_ctrlrequest *req = (void *)&qh_array[0].setup_buffer[0];
1092
1093 switch(req->bRequestType & USB_TYPE_MASK)
1094 {
1095 case USB_TYPE_STANDARD:
1096 handle_std_req(req);
1097 break;
1098 case USB_TYPE_CLASS:
1099 handle_class_req(req);
1100 break;
1101 default:
1102 usb_drv_stall(EP_CONTROL, true, true);
1103 }
1104 }
1105}
diff --git a/utils/hwstub/stmp/memcpy.S b/utils/hwstub/stmp/memcpy.S
deleted file mode 100644
index 2a55fb5656..0000000000
--- a/utils/hwstub/stmp/memcpy.S
+++ /dev/null
@@ -1,176 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Free Software Foundation, Inc.
11 * This file was originally part of the GNU C Library
12 * Contributed to glibc by MontaVista Software, Inc. (written by Nicolas Pitre)
13 * Adapted for Rockbox by Daniel Ankers
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24
25#include "config.h"
26
27/*
28 * Endian independent macros for shifting bytes within registers.
29 */
30#ifndef __ARMEB__
31#define pull lsr
32#define push lsl
33#else
34#define pull lsl
35#define push lsr
36#endif
37
38/* Prototype: void *memcpy(void *dest, const void *src, size_t n); */
39
40 .section .icode,"ax",%progbits
41
42 .align 2
43 .global memcpy
44 .type memcpy,%function
45
46memcpy:
47 stmfd sp!, {r0, r4, lr}
48
49 subs r2, r2, #4
50 blt 8f
51 ands ip, r0, #3
52 bne 9f
53 ands ip, r1, #3
54 bne 10f
55
561: subs r2, r2, #(28)
57 stmfd sp!, {r5 - r8}
58 blt 5f
59
602:
613:
624: ldmia r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
63 subs r2, r2, #32
64 stmia r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
65 bge 3b
66
675: ands ip, r2, #28
68 rsb ip, ip, #32
69 addne pc, pc, ip @ C is always clear here
70 b 7f
716: nop
72 ldr r3, [r1], #4
73 ldr r4, [r1], #4
74 ldr r5, [r1], #4
75 ldr r6, [r1], #4
76 ldr r7, [r1], #4
77 ldr r8, [r1], #4
78 ldr lr, [r1], #4
79
80 add pc, pc, ip
81 nop
82 nop
83 str r3, [r0], #4
84 str r4, [r0], #4
85 str r5, [r0], #4
86 str r6, [r0], #4
87 str r7, [r0], #4
88 str r8, [r0], #4
89 str lr, [r0], #4
90
917: ldmfd sp!, {r5 - r8}
92
938: movs r2, r2, lsl #31
94 ldrneb r3, [r1], #1
95 ldrcsb r4, [r1], #1
96 ldrcsb ip, [r1]
97 strneb r3, [r0], #1
98 strcsb r4, [r0], #1
99 strcsb ip, [r0]
100
101 ldmpc regs="r0, r4"
102
1039: rsb ip, ip, #4
104 cmp ip, #2
105 ldrgtb r3, [r1], #1
106 ldrgeb r4, [r1], #1
107 ldrb lr, [r1], #1
108 strgtb r3, [r0], #1
109 strgeb r4, [r0], #1
110 subs r2, r2, ip
111 strb lr, [r0], #1
112 blt 8b
113 ands ip, r1, #3
114 beq 1b
115
11610: bic r1, r1, #3
117 cmp ip, #2
118 ldr lr, [r1], #4
119 beq 17f
120 bgt 18f
121
122
123 .macro forward_copy_shift pull push
124
125 subs r2, r2, #28
126 blt 14f
127
12811: stmfd sp!, {r5 - r9}
129
13012:
13113: ldmia r1!, {r4, r5, r6, r7}
132 mov r3, lr, pull #\pull
133 subs r2, r2, #32
134 ldmia r1!, {r8, r9, ip, lr}
135 orr r3, r3, r4, push #\push
136 mov r4, r4, pull #\pull
137 orr r4, r4, r5, push #\push
138 mov r5, r5, pull #\pull
139 orr r5, r5, r6, push #\push
140 mov r6, r6, pull #\pull
141 orr r6, r6, r7, push #\push
142 mov r7, r7, pull #\pull
143 orr r7, r7, r8, push #\push
144 mov r8, r8, pull #\pull
145 orr r8, r8, r9, push #\push
146 mov r9, r9, pull #\pull
147 orr r9, r9, ip, push #\push
148 mov ip, ip, pull #\pull
149 orr ip, ip, lr, push #\push
150 stmia r0!, {r3, r4, r5, r6, r7, r8, r9, ip}
151 bge 12b
152
153 ldmfd sp!, {r5 - r9}
154
15514: ands ip, r2, #28
156 beq 16f
157
15815: mov r3, lr, pull #\pull
159 ldr lr, [r1], #4
160 subs ip, ip, #4
161 orr r3, r3, lr, push #\push
162 str r3, [r0], #4
163 bgt 15b
164
16516: sub r1, r1, #(\push / 8)
166 b 8b
167
168 .endm
169
170
171 forward_copy_shift pull=8 push=24
172
17317: forward_copy_shift pull=16 push=16
174
17518: forward_copy_shift pull=24 push=8
176
diff --git a/utils/hwstub/stmp/memmove.S b/utils/hwstub/stmp/memmove.S
deleted file mode 100644
index d8cab048be..0000000000
--- a/utils/hwstub/stmp/memmove.S
+++ /dev/null
@@ -1,190 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Free Software Foundation, Inc.
11 * This file was originally part of the GNU C Library
12 * Contributed to glibc by MontaVista Software, Inc. (written by Nicolas Pitre)
13 * Adapted for Rockbox by Daniel Ankers
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24
25#include "config.h"
26
27/*
28 * Endian independent macros for shifting bytes within registers.
29 */
30#ifndef __ARMEB__
31#define pull lsr
32#define push lsl
33#else
34#define pull lsl
35#define push lsr
36#endif
37
38 .text
39
40/*
41 * Prototype: void *memmove(void *dest, const void *src, size_t n);
42 *
43 * Note:
44 *
45 * If the memory regions don't overlap, we simply branch to memcpy which is
46 * normally a bit faster. Otherwise the copy is done going downwards.
47 */
48
49 .section .icode,"ax",%progbits
50
51 .align 2
52 .global memmove
53 .type memmove,%function
54
55memmove:
56
57 subs ip, r0, r1
58 cmphi r2, ip
59 bls memcpy
60
61 stmfd sp!, {r0, r4, lr}
62 add r1, r1, r2
63 add r0, r0, r2
64 subs r2, r2, #4
65 blt 8f
66 ands ip, r0, #3
67 bne 9f
68 ands ip, r1, #3
69 bne 10f
70
711: subs r2, r2, #(28)
72 stmfd sp!, {r5 - r8}
73 blt 5f
74
752:
763:
774: ldmdb r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
78 subs r2, r2, #32
79 stmdb r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
80 bge 3b
81
825: ands ip, r2, #28
83 rsb ip, ip, #32
84 addne pc, pc, ip @ C is always clear here
85 b 7f
866: nop
87 ldr r3, [r1, #-4]!
88 ldr r4, [r1, #-4]!
89 ldr r5, [r1, #-4]!
90 ldr r6, [r1, #-4]!
91 ldr r7, [r1, #-4]!
92 ldr r8, [r1, #-4]!
93 ldr lr, [r1, #-4]!
94
95 add pc, pc, ip
96 nop
97 nop
98 str r3, [r0, #-4]!
99 str r4, [r0, #-4]!
100 str r5, [r0, #-4]!
101 str r6, [r0, #-4]!
102 str r7, [r0, #-4]!
103 str r8, [r0, #-4]!
104 str lr, [r0, #-4]!
105
1067: ldmfd sp!, {r5 - r8}
107
1088: movs r2, r2, lsl #31
109 ldrneb r3, [r1, #-1]!
110 ldrcsb r4, [r1, #-1]!
111 ldrcsb ip, [r1, #-1]
112 strneb r3, [r0, #-1]!
113 strcsb r4, [r0, #-1]!
114 strcsb ip, [r0, #-1]
115 ldmpc regs="r0, r4"
116
1179: cmp ip, #2
118 ldrgtb r3, [r1, #-1]!
119 ldrgeb r4, [r1, #-1]!
120 ldrb lr, [r1, #-1]!
121 strgtb r3, [r0, #-1]!
122 strgeb r4, [r0, #-1]!
123 subs r2, r2, ip
124 strb lr, [r0, #-1]!
125 blt 8b
126 ands ip, r1, #3
127 beq 1b
128
12910: bic r1, r1, #3
130 cmp ip, #2
131 ldr r3, [r1, #0]
132 beq 17f
133 blt 18f
134
135
136 .macro backward_copy_shift push pull
137
138 subs r2, r2, #28
139 blt 14f
140
14111: stmfd sp!, {r5 - r9}
142
14312:
14413: ldmdb r1!, {r7, r8, r9, ip}
145 mov lr, r3, push #\push
146 subs r2, r2, #32
147 ldmdb r1!, {r3, r4, r5, r6}
148 orr lr, lr, ip, pull #\pull
149 mov ip, ip, push #\push
150 orr ip, ip, r9, pull #\pull
151 mov r9, r9, push #\push
152 orr r9, r9, r8, pull #\pull
153 mov r8, r8, push #\push
154 orr r8, r8, r7, pull #\pull
155 mov r7, r7, push #\push
156 orr r7, r7, r6, pull #\pull
157 mov r6, r6, push #\push
158 orr r6, r6, r5, pull #\pull
159 mov r5, r5, push #\push
160 orr r5, r5, r4, pull #\pull
161 mov r4, r4, push #\push
162 orr r4, r4, r3, pull #\pull
163 stmdb r0!, {r4 - r9, ip, lr}
164 bge 12b
165
166 ldmfd sp!, {r5 - r9}
167
16814: ands ip, r2, #28
169 beq 16f
170
17115: mov lr, r3, push #\push
172 ldr r3, [r1, #-4]!
173 subs ip, ip, #4
174 orr lr, lr, r3, pull #\pull
175 str lr, [r0, #-4]!
176 bgt 15b
177
17816: add r1, r1, #(\pull / 8)
179 b 8b
180
181 .endm
182
183
184 backward_copy_shift push=8 pull=24
185
18617: backward_copy_shift push=16 pull=16
187
18818: backward_copy_shift push=24 pull=8
189
190
diff --git a/utils/hwstub/stmp/memset.S b/utils/hwstub/stmp/memset.S
deleted file mode 100644
index 682da874ce..0000000000
--- a/utils/hwstub/stmp/memset.S
+++ /dev/null
@@ -1,98 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Thom Johansen
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 ****************************************************************************/
21#include "config.h"
22
23 .section .icode,"ax",%progbits
24
25 .align 2
26
27/* The following code is based on code found in Linux kernel version 2.6.15.3
28 * linux/arch/arm/lib/memset.S
29 *
30 * Copyright (C) 1995-2000 Russell King
31 */
32
33/* This code will align a pointer for memset, if needed */
341: cmp r2, #4 @ 1 do we have enough
35 blt 5f @ 1 bytes to align with?
36 cmp r3, #2 @ 1
37 strgtb r1, [r0, #-1]! @ 1
38 strgeb r1, [r0, #-1]! @ 1
39 strb r1, [r0, #-1]! @ 1
40 sub r2, r2, r3 @ 1 r2 = r2 - r3
41 b 2f
42
43 .global memset
44 .type memset,%function
45memset:
46 add r0, r0, r2 @ we'll write backwards in memory
47 ands r3, r0, #3 @ 1 unaligned?
48 bne 1b @ 1
492:
50/*
51 * we know that the pointer in r0 is aligned to a word boundary.
52 */
53 orr r1, r1, r1, lsl #8
54 orr r1, r1, r1, lsl #16
55 mov r3, r1
56 cmp r2, #16
57 blt 5f
58/*
59 * We need an extra register for this loop - save the return address and
60 * use the LR
61 */
62 str lr, [sp, #-4]!
63 mov ip, r1
64 mov lr, r1
65
663: subs r2, r2, #64
67 stmgedb r0!, {r1, r3, ip, lr} @ 64 bytes at a time.
68 stmgedb r0!, {r1, r3, ip, lr}
69 stmgedb r0!, {r1, r3, ip, lr}
70 stmgedb r0!, {r1, r3, ip, lr}
71 bgt 3b
72 ldrpc cond=eq @ Now <64 bytes to go.
73/*
74 * No need to correct the count; we're only testing bits from now on
75 */
76 tst r2, #32
77 stmnedb r0!, {r1, r3, ip, lr}
78 stmnedb r0!, {r1, r3, ip, lr}
79 tst r2, #16
80 stmnedb r0!, {r1, r3, ip, lr}
81 ldr lr, [sp], #4
82
835: tst r2, #8
84 stmnedb r0!, {r1, r3}
85 tst r2, #4
86 strne r1, [r0, #-4]!
87/*
88 * When we get here, we've got less than 4 bytes to zero. We
89 * may have an unaligned pointer as well.
90 */
916: tst r2, #2
92 strneb r1, [r0, #-1]!
93 strneb r1, [r0, #-1]!
94 tst r2, #1
95 strneb r1, [r0, #-1]!
96 bx lr
97.end:
98 .size memset,.end-memset
diff --git a/utils/hwstub/stmp/protocol.h b/utils/hwstub/stmp/protocol.h
deleted file mode 100644
index 35510fa9b2..0000000000
--- a/utils/hwstub/stmp/protocol.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../hwstub_protocol.h"
diff --git a/utils/hwstub/stmp/stddef.h b/utils/hwstub/stmp/stddef.h
deleted file mode 100644
index 9bfd767750..0000000000
--- a/utils/hwstub/stmp/stddef.h
+++ /dev/null
@@ -1,32 +0,0 @@
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 ****************************************************************************/
21#ifndef __HWSTUB_STDDEF__
22#define __HWSTUB_STDDEF__
23
24#include "stdint.h"
25
26typedef uint32_t size_t;
27typedef int32_t ssize_t;
28
29#define MIN(a, b) ((a) < (b) ? (a) : (b))
30#define MAX(a, b) ((a) > (b) ? (a) : (b))
31
32#endif /* __HWSTUB_STDDEF__ */
diff --git a/utils/hwstub/stmp/stdint.h b/utils/hwstub/stmp/stdint.h
deleted file mode 100644
index 4fe3702c86..0000000000
--- a/utils/hwstub/stmp/stdint.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Dave Chapman
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 ****************************************************************************/
21
22#ifndef __STDINT_H__
23#define __STDINT_H__
24
25typedef signed char int8_t;
26typedef unsigned char uint8_t;
27typedef short int16_t;
28typedef unsigned short uint16_t;
29typedef long int32_t;
30typedef unsigned long uint32_t;
31typedef char bool;
32
33#define true 1
34#define false 0
35
36#define NULL (void *)0
37
38#endif /* __STDINT_H__ */
diff --git a/utils/hwstub/stmp/string.c b/utils/hwstub/stmp/string.c
deleted file mode 100644
index 1f8c415a99..0000000000
--- a/utils/hwstub/stmp/string.c
+++ /dev/null
@@ -1,29 +0,0 @@
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 ****************************************************************************/
21#include "string.h"
22
23size_t strlen(const char *s)
24{
25 size_t len = 0;
26 while(*s++)
27 len++;
28 return len;
29}
diff --git a/utils/hwstub/stmp/string.h b/utils/hwstub/stmp/string.h
deleted file mode 100644
index 184144e525..0000000000
--- a/utils/hwstub/stmp/string.h
+++ /dev/null
@@ -1,30 +0,0 @@
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 ****************************************************************************/
21#ifndef __HWSTUB_STRING__
22#define __HWSTUB_STRING__
23
24#include "stddef.h"
25
26void memset(void *dst, int c, size_t n);
27void memcpy(void *dst, const void *src, size_t n);
28size_t strlen(const char *s);
29
30#endif /* __HWSTUB_STRING__ */
diff --git a/utils/hwstub/stmp/system.h b/utils/hwstub/stmp/system.h
deleted file mode 100644
index e5aea12051..0000000000
--- a/utils/hwstub/stmp/system.h
+++ /dev/null
@@ -1,118 +0,0 @@
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 ****************************************************************************/
21#ifndef __HWSTUB_SYSTEM__
22#define __HWSTUB_SYSTEM__
23
24#define IRQ_ENABLED 0x00
25#define IRQ_DISABLED 0x80
26#define IRQ_STATUS 0x80
27#define FIQ_ENABLED 0x00
28#define FIQ_DISABLED 0x40
29#define FIQ_STATUS 0x40
30#define IRQ_FIQ_ENABLED 0x00
31#define IRQ_FIQ_DISABLED 0xc0
32#define IRQ_FIQ_STATUS 0xc0
33#define HIGHEST_IRQ_LEVEL IRQ_DISABLED
34
35#define set_irq_level(status) \
36 set_interrupt_status((status), IRQ_STATUS)
37#define set_fiq_status(status) \
38 set_interrupt_status((status), FIQ_STATUS)
39
40#define disable_irq_save() \
41 disable_interrupt_save(IRQ_STATUS)
42#define disable_fiq_save() \
43 disable_interrupt_save(FIQ_STATUS)
44
45#define restore_irq(cpsr) \
46 restore_interrupt(cpsr)
47#define restore_fiq(cpsr) \
48 restore_interrupt(cpsr)
49
50#define disable_irq() \
51 disable_interrupt(IRQ_STATUS)
52#define enable_irq() \
53 enable_interrupt(IRQ_STATUS)
54#define disable_fiq() \
55 disable_interrupt(FIQ_STATUS)
56#define enable_fiq() \
57 enable_interrupt(FIQ_STATUS)
58
59static inline int set_interrupt_status(int status, int mask)
60{
61 unsigned long cpsr;
62 int oldstatus;
63 /* Read the old levels and set the new ones */
64 asm volatile (
65 "mrs %1, cpsr \n"
66 "bic %0, %1, %[mask] \n"
67 "orr %0, %0, %2 \n"
68 "msr cpsr_c, %0 \n"
69 : "=&r,r"(cpsr), "=&r,r"(oldstatus)
70 : "r,i"(status & mask), [mask]"i,i"(mask));
71
72 return oldstatus;
73}
74
75static inline void restore_interrupt(int cpsr)
76{
77 /* Set cpsr_c from value returned by disable_interrupt_save
78 * or set_interrupt_status */
79 asm volatile ("msr cpsr_c, %0" : : "r"(cpsr));
80}
81
82static inline void enable_interrupt(int mask)
83{
84 /* Clear I and/or F disable bit */
85 int tmp;
86 asm volatile (
87 "mrs %0, cpsr \n"
88 "bic %0, %0, %1 \n"
89 "msr cpsr_c, %0 \n"
90 : "=&r"(tmp) : "i"(mask));
91}
92
93static inline void disable_interrupt(int mask)
94{
95 /* Set I and/or F disable bit */
96 int tmp;
97 asm volatile (
98 "mrs %0, cpsr \n"
99 "orr %0, %0, %1 \n"
100 "msr cpsr_c, %0 \n"
101 : "=&r"(tmp) : "i"(mask));
102}
103
104static inline int disable_interrupt_save(int mask)
105{
106 /* Set I and/or F disable bit and return old cpsr value */
107 int cpsr, tmp;
108 asm volatile (
109 "mrs %1, cpsr \n"
110 "orr %0, %1, %2 \n"
111 "msr cpsr_c, %0 \n"
112 : "=&r"(tmp), "=&r"(cpsr)
113 : "i"(mask));
114 return cpsr;
115}
116
117#endif /* __HWSTUB_SYSTEM__ */
118
diff --git a/utils/hwstub/stmp/usb_ch9.h b/utils/hwstub/stmp/usb_ch9.h
deleted file mode 100644
index 09141b93bd..0000000000
--- a/utils/hwstub/stmp/usb_ch9.h
+++ /dev/null
@@ -1,454 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) by Linux Kernel Developers
11 *
12 * Based on code from the Linux Kernel
13 * available at http://www.kernel.org
14 * Original file: <kernel>/include/linux/usb/ch9.h
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
20 *
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
23 *
24 ****************************************************************************/
25
26/*
27 * This file holds USB constants and structures that are needed for
28 * USB device APIs. These are used by the USB device model, which is
29 * defined in chapter 9 of the USB 2.0 specification and in the
30 * Wireless USB 1.0 (spread around). Linux has several APIs in C that
31 * need these:
32 *
33 * - the master/host side Linux-USB kernel driver API;
34 * - the "usbfs" user space API; and
35 * - the Linux "gadget" slave/device/peripheral side driver API.
36 *
37 * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems
38 * act either as a USB master/host or as a USB slave/device. That means
39 * the master and slave side APIs benefit from working well together.
40 *
41 * There's also "Wireless USB", using low power short range radios for
42 * peripheral interconnection but otherwise building on the USB framework.
43 *
44 * Note all descriptors are declared '__attribute__((packed))' so that:
45 *
46 * [a] they never get padded, either internally (USB spec writers
47 * probably handled that) or externally;
48 *
49 * [b] so that accessing bigger-than-a-bytes fields will never
50 * generate bus errors on any platform, even when the location of
51 * its descriptor inside a bundle isn't "naturally aligned", and
52 *
53 * [c] for consistency, removing all doubt even when it appears to
54 * someone that the two other points are non-issues for that
55 * particular descriptor type.
56 */
57
58#ifndef _CH9_H_
59#define _CH9_H_
60
61#include "stdint.h"
62
63/*-------------------------------------------------------------------------*/
64
65/* CONTROL REQUEST SUPPORT */
66
67/*
68 * USB directions
69 *
70 * This bit flag is used in endpoint descriptors' bEndpointAddress field.
71 * It's also one of three fields in control requests bRequestType.
72 */
73#define USB_DIR_OUT 0 /* to device */
74#define USB_DIR_IN 0x80 /* to host */
75
76/*
77 * USB types, the second of three bRequestType fields
78 */
79#define USB_TYPE_MASK (0x03 << 5)
80#define USB_TYPE_STANDARD (0x00 << 5)
81#define USB_TYPE_CLASS (0x01 << 5)
82#define USB_TYPE_VENDOR (0x02 << 5)
83#define USB_TYPE_RESERVED (0x03 << 5)
84
85/*
86 * USB recipients, the third of three bRequestType fields
87 */
88#define USB_RECIP_MASK 0x1f
89#define USB_RECIP_DEVICE 0x00
90#define USB_RECIP_INTERFACE 0x01
91#define USB_RECIP_ENDPOINT 0x02
92#define USB_RECIP_OTHER 0x03
93
94/*
95 * Standard requests, for the bRequest field of a SETUP packet.
96 *
97 * These are qualified by the bRequestType field, so that for example
98 * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved
99 * by a GET_STATUS request.
100 */
101#define USB_REQ_GET_STATUS 0x00
102#define USB_REQ_CLEAR_FEATURE 0x01
103#define USB_REQ_SET_FEATURE 0x03
104#define USB_REQ_SET_ADDRESS 0x05
105#define USB_REQ_GET_DESCRIPTOR 0x06
106#define USB_REQ_SET_DESCRIPTOR 0x07
107#define USB_REQ_GET_CONFIGURATION 0x08
108#define USB_REQ_SET_CONFIGURATION 0x09
109#define USB_REQ_GET_INTERFACE 0x0A
110#define USB_REQ_SET_INTERFACE 0x0B
111#define USB_REQ_SYNCH_FRAME 0x0C
112/*
113 * USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and
114 * are read as a bit array returned by USB_REQ_GET_STATUS. (So there
115 * are at most sixteen features of each type.) Hubs may also support a
116 * new USB_REQ_TEST_AND_SET_FEATURE to put ports into L1 suspend.
117 */
118#define USB_DEVICE_SELF_POWERED 0 /* (read only) */
119#define USB_DEVICE_REMOTE_WAKEUP 1 /* dev may initiate wakeup */
120#define USB_DEVICE_TEST_MODE 2 /* (wired high speed only) */
121#define USB_DEVICE_BATTERY 2 /* (wireless) */
122#define USB_DEVICE_B_HNP_ENABLE 3 /* (otg) dev may initiate HNP */
123#define USB_DEVICE_WUSB_DEVICE 3 /* (wireless)*/
124#define USB_DEVICE_A_HNP_SUPPORT 4 /* (otg) RH port supports HNP */
125#define USB_DEVICE_A_ALT_HNP_SUPPORT 5 /* (otg) other RH port does */
126#define USB_DEVICE_DEBUG_MODE 6 /* (special devices only) */
127
128#define USB_ENDPOINT_HALT 0 /* IN/OUT will STALL */
129
130
131/**
132 * struct usb_ctrlrequest - SETUP data for a USB device control request
133 * @bRequestType: matches the USB bmRequestType field
134 * @bRequest: matches the USB bRequest field
135 * @wValue: matches the USB wValue field (le16 byte order)
136 * @wIndex: matches the USB wIndex field (le16 byte order)
137 * @wLength: matches the USB wLength field (le16 byte order)
138 *
139 * This structure is used to send control requests to a USB device. It matches
140 * the different fields of the USB 2.0 Spec section 9.3, table 9-2. See the
141 * USB spec for a fuller description of the different fields, and what they are
142 * used for.
143 *
144 * Note that the driver for any interface can issue control requests.
145 * For most devices, interfaces don't coordinate with each other, so
146 * such requests may be made at any time.
147 */
148struct usb_ctrlrequest {
149 uint8_t bRequestType;
150 uint8_t bRequest;
151 uint16_t wValue;
152 uint16_t wIndex;
153 uint16_t wLength;
154} __attribute__ ((packed));
155
156/*-------------------------------------------------------------------------*/
157
158/*
159 * STANDARD DESCRIPTORS ... as returned by GET_DESCRIPTOR, or
160 * (rarely) accepted by SET_DESCRIPTOR.
161 *
162 * Note that all multi-byte values here are encoded in little endian
163 * byte order "on the wire". But when exposed through Linux-USB APIs,
164 * they've been converted to cpu byte order.
165 */
166
167/*
168 * Descriptor types ... USB 2.0 spec table 9.5
169 */
170#define USB_DT_DEVICE 0x01
171#define USB_DT_CONFIG 0x02
172#define USB_DT_STRING 0x03
173#define USB_DT_INTERFACE 0x04
174#define USB_DT_ENDPOINT 0x05
175#define USB_DT_DEVICE_QUALIFIER 0x06
176#define USB_DT_OTHER_SPEED_CONFIG 0x07
177#define USB_DT_INTERFACE_POWER 0x08
178/* these are from a minor usb 2.0 revision (ECN) */
179#define USB_DT_OTG 0x09
180#define USB_DT_DEBUG 0x0a
181#define USB_DT_INTERFACE_ASSOCIATION 0x0b
182/* these are from the Wireless USB spec */
183#define USB_DT_SECURITY 0x0c
184#define USB_DT_KEY 0x0d
185#define USB_DT_ENCRYPTION_TYPE 0x0e
186#define USB_DT_BOS 0x0f
187#define USB_DT_DEVICE_CAPABILITY 0x10
188#define USB_DT_WIRELESS_ENDPOINT_COMP 0x11
189#define USB_DT_WIRE_ADAPTER 0x21
190#define USB_DT_RPIPE 0x22
191#define USB_DT_CS_RADIO_CONTROL 0x23
192
193/* Conventional codes for class-specific descriptors. The convention is
194 * defined in the USB "Common Class" Spec (3.11). Individual class specs
195 * are authoritative for their usage, not the "common class" writeup.
196 */
197#define USB_DT_CS_DEVICE (USB_TYPE_CLASS | USB_DT_DEVICE)
198#define USB_DT_CS_CONFIG (USB_TYPE_CLASS | USB_DT_CONFIG)
199#define USB_DT_CS_STRING (USB_TYPE_CLASS | USB_DT_STRING)
200#define USB_DT_CS_INTERFACE (USB_TYPE_CLASS | USB_DT_INTERFACE)
201#define USB_DT_CS_ENDPOINT (USB_TYPE_CLASS | USB_DT_ENDPOINT)
202
203/* All standard descriptors have these 2 fields at the beginning */
204struct usb_descriptor_header {
205 uint8_t bLength;
206 uint8_t bDescriptorType;
207} __attribute__ ((packed));
208
209
210/*-------------------------------------------------------------------------*/
211
212/* USB_DT_DEVICE: Device descriptor */
213struct usb_device_descriptor {
214 uint8_t bLength;
215 uint8_t bDescriptorType;
216
217 uint16_t bcdUSB;
218 uint8_t bDeviceClass;
219 uint8_t bDeviceSubClass;
220 uint8_t bDeviceProtocol;
221 uint8_t bMaxPacketSize0;
222 uint16_t idVendor;
223 uint16_t idProduct;
224 uint16_t bcdDevice;
225 uint8_t iManufacturer;
226 uint8_t iProduct;
227 uint8_t iSerialNumber;
228 uint8_t bNumConfigurations;
229} __attribute__ ((packed));
230
231#define USB_DT_DEVICE_SIZE 18
232
233
234/*
235 * Device and/or Interface Class codes
236 * as found in bDeviceClass or bInterfaceClass
237 * and defined by www.usb.org documents
238 */
239#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
240#define USB_CLASS_AUDIO 1
241#define USB_CLASS_COMM 2
242#define USB_CLASS_HID 3
243#define USB_CLASS_PHYSICAL 5
244#define USB_CLASS_STILL_IMAGE 6
245#define USB_CLASS_PRINTER 7
246#define USB_CLASS_MASS_STORAGE 8
247#define USB_CLASS_HUB 9
248#define USB_CLASS_CDC_DATA 0x0a
249#define USB_CLASS_CSCID 0x0b /* chip+ smart card */
250#define USB_CLASS_CONTENT_SEC 0x0d /* content security */
251#define USB_CLASS_VIDEO 0x0e
252#define USB_CLASS_WIRELESS_CONTROLLER 0xe0
253#define USB_CLASS_MISC 0xef
254#define USB_CLASS_APP_SPEC 0xfe
255#define USB_CLASS_VENDOR_SPEC 0xff
256
257/*-------------------------------------------------------------------------*/
258
259/* USB_DT_CONFIG: Configuration descriptor information.
260 *
261 * USB_DT_OTHER_SPEED_CONFIG is the same descriptor, except that the
262 * descriptor type is different. Highspeed-capable devices can look
263 * different depending on what speed they're currently running. Only
264 * devices with a USB_DT_DEVICE_QUALIFIER have any OTHER_SPEED_CONFIG
265 * descriptors.
266 */
267struct usb_config_descriptor {
268 uint8_t bLength;
269 uint8_t bDescriptorType;
270
271 uint16_t wTotalLength;
272 uint8_t bNumInterfaces;
273 uint8_t bConfigurationValue;
274 uint8_t iConfiguration;
275 uint8_t bmAttributes;
276 uint8_t bMaxPower;
277} __attribute__ ((packed));
278
279#define USB_DT_CONFIG_SIZE 9
280
281/* from config descriptor bmAttributes */
282#define USB_CONFIG_ATT_ONE (1 << 7) /* must be set */
283#define USB_CONFIG_ATT_SELFPOWER (1 << 6) /* self powered */
284#define USB_CONFIG_ATT_WAKEUP (1 << 5) /* can wakeup */
285#define USB_CONFIG_ATT_BATTERY (1 << 4) /* battery powered */
286
287/*-------------------------------------------------------------------------*/
288
289/* USB_DT_STRING: String descriptor */
290struct usb_string_descriptor {
291 uint8_t bLength;
292 uint8_t bDescriptorType;
293
294 uint16_t wString[]; /* UTF-16LE encoded */
295} __attribute__ ((packed));
296
297/* note that "string" zero is special, it holds language codes that
298 * the device supports, not Unicode characters.
299 */
300
301/*-------------------------------------------------------------------------*/
302
303/* USB_DT_INTERFACE: Interface descriptor */
304struct usb_interface_descriptor {
305 uint8_t bLength;
306 uint8_t bDescriptorType;
307
308 uint8_t bInterfaceNumber;
309 uint8_t bAlternateSetting;
310 uint8_t bNumEndpoints;
311 uint8_t bInterfaceClass;
312 uint8_t bInterfaceSubClass;
313 uint8_t bInterfaceProtocol;
314 uint8_t iInterface;
315} __attribute__ ((packed));
316
317#define USB_DT_INTERFACE_SIZE 9
318
319/*-------------------------------------------------------------------------*/
320
321/* USB_DT_ENDPOINT: Endpoint descriptor */
322struct usb_endpoint_descriptor {
323 uint8_t bLength;
324 uint8_t bDescriptorType;
325
326 uint8_t bEndpointAddress;
327 uint8_t bmAttributes;
328 uint16_t wMaxPacketSize;
329 uint8_t bInterval;
330} __attribute__ ((packed));
331
332#define USB_DT_ENDPOINT_SIZE 7
333#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
334
335
336/*
337 * Endpoints
338 */
339#define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
340#define USB_ENDPOINT_DIR_MASK 0x80
341
342#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
343#define USB_ENDPOINT_XFER_CONTROL 0
344#define USB_ENDPOINT_XFER_ISOC 1
345#define USB_ENDPOINT_XFER_BULK 2
346#define USB_ENDPOINT_XFER_INT 3
347#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
348
349
350/*-------------------------------------------------------------------------*/
351
352/* USB_DT_DEVICE_QUALIFIER: Device Qualifier descriptor */
353struct usb_qualifier_descriptor {
354 uint8_t bLength;
355 uint8_t bDescriptorType;
356
357 uint16_t bcdUSB;
358 uint8_t bDeviceClass;
359 uint8_t bDeviceSubClass;
360 uint8_t bDeviceProtocol;
361 uint8_t bMaxPacketSize0;
362 uint8_t bNumConfigurations;
363 uint8_t bRESERVED;
364} __attribute__ ((packed));
365
366
367/*-------------------------------------------------------------------------*/
368
369/* USB_DT_OTG (from OTG 1.0a supplement) */
370struct usb_otg_descriptor {
371 uint8_t bLength;
372 uint8_t bDescriptorType;
373
374 uint8_t bmAttributes; /* support for HNP, SRP, etc */
375} __attribute__ ((packed));
376
377/* from usb_otg_descriptor.bmAttributes */
378#define USB_OTG_SRP (1 << 0)
379#define USB_OTG_HNP (1 << 1) /* swap host/device roles */
380
381/*-------------------------------------------------------------------------*/
382
383/* USB_DT_DEBUG: for special highspeed devices, replacing serial console */
384struct usb_debug_descriptor {
385 uint8_t bLength;
386 uint8_t bDescriptorType;
387
388 /* bulk endpoints with 8 byte maxpacket */
389 uint8_t bDebugInEndpoint;
390 uint8_t bDebugOutEndpoint;
391} __attribute__((packed));
392
393/*-------------------------------------------------------------------------*/
394/* USB 2.0 defines three speeds, here's how Linux identifies them */
395
396enum usb_device_speed {
397 USB_SPEED_UNKNOWN = 0, /* enumerating */
398 USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
399 USB_SPEED_HIGH, /* usb 2.0 */
400 USB_SPEED_VARIABLE, /* wireless (usb 2.5) */
401};
402
403enum usb_device_state {
404 /* NOTATTACHED isn't in the USB spec, and this state acts
405 * the same as ATTACHED ... but it's clearer this way.
406 */
407 USB_STATE_NOTATTACHED = 0,
408
409 /* chapter 9 and authentication (wireless) device states */
410 USB_STATE_ATTACHED,
411 USB_STATE_POWERED, /* wired */
412 USB_STATE_UNAUTHENTICATED, /* auth */
413 USB_STATE_RECONNECTING, /* auth */
414 USB_STATE_DEFAULT, /* limited function */
415 USB_STATE_ADDRESS,
416 USB_STATE_CONFIGURED, /* most functions */
417
418 USB_STATE_SUSPENDED
419
420 /* NOTE: there are actually four different SUSPENDED
421 * states, returning to POWERED, DEFAULT, ADDRESS, or
422 * CONFIGURED respectively when SOF tokens flow again.
423 * At this level there's no difference between L1 and L2
424 * suspend states. (L2 being original USB 1.1 suspend.)
425 */
426};
427
428/**
429 * struct usb_string - wraps a C string and its USB id
430 * @id:the (nonzero) ID for this string
431 * @s:the string, in UTF-8 encoding
432 *
433 * If you're using usb_gadget_get_string(), use this to wrap a string
434 * together with its ID.
435 */
436struct usb_string {
437 uint8_t id;
438 const char* s;
439};
440
441/**
442 * struct usb_gadget_strings - a set of USB strings in a given language
443 * @language:identifies the strings' language (0x0409 for en-us)
444 * @strings:array of strings with their ids
445 *
446 * If you're using usb_gadget_get_string(), use this to wrap all the
447 * strings for a given language.
448 */
449struct usb_gadget_strings {
450 uint16_t language; /* 0x0409 for en-us */
451 struct usb_string* strings;
452};
453
454#endif /*_CH9_H_*/