summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-04-12 00:08:11 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2014-04-12 00:11:13 +0200
commit238be18d0331a7a87e3ea8ea0d24b78e451357cb (patch)
tree31807bf3fd533d2d0d3d4eb0421b08100cc67c25
parent910235b49a754fcd18157dbd22e125a32b482c9d (diff)
downloadrockbox-238be18d0331a7a87e3ea8ea0d24b78e451357cb.tar.gz
rockbox-238be18d0331a7a87e3ea8ea0d24b78e451357cb.zip
hwstub: add proper PP support
- drop support for PP500x: it's very different from other PP and although it would be possible to support them, I don't have one to test the code - make sure only the CPU is started - add PP descriptor to report chip ID and revision - add code in shell and lua to support pp (no register description yet) - compile for ARMv4 because PP502x is an ARM7TDMI Change-Id: I36c4e465dfc2cfdfe7433b2f65cc8f6f0720fe62
-rw-r--r--utils/hwstub/hwstub_protocol.h10
-rw-r--r--utils/hwstub/stub/pp/Makefile2
-rw-r--r--utils/hwstub/stub/pp/crt0.S31
-rw-r--r--utils/hwstub/stub/pp/target-config.h6
-rw-r--r--utils/hwstub/stub/pp/target.c65
-rw-r--r--utils/hwstub/tools/hwstub_shell.cpp23
-rw-r--r--utils/hwstub/tools/lua/load.lua2
-rw-r--r--utils/hwstub/tools/lua/pp.lua62
8 files changed, 182 insertions, 19 deletions
diff --git a/utils/hwstub/hwstub_protocol.h b/utils/hwstub/hwstub_protocol.h
index 67945cd5c0..fa692abab5 100644
--- a/utils/hwstub/hwstub_protocol.h
+++ b/utils/hwstub/hwstub_protocol.h
@@ -56,6 +56,7 @@
56#define HWSTUB_DT_LAYOUT 0x42 /* mandatory */ 56#define HWSTUB_DT_LAYOUT 0x42 /* mandatory */
57#define HWSTUB_DT_TARGET 0x43 /* mandatory */ 57#define HWSTUB_DT_TARGET 0x43 /* mandatory */
58#define HWSTUB_DT_STMP 0x44 /* optional */ 58#define HWSTUB_DT_STMP 0x44 /* optional */
59#define HWSTUB_DT_PP 0x45 /* optional */
59 60
60struct hwstub_version_desc_t 61struct hwstub_version_desc_t
61{ 62{
@@ -92,6 +93,15 @@ struct hwstub_stmp_desc_t
92 uint8_t bPackage; /* 0=169BGA for example */ 93 uint8_t bPackage; /* 0=169BGA for example */
93} __attribute__((packed)); 94} __attribute__((packed));
94 95
96struct hwstub_pp_desc_t
97{
98 uint8_t bLength;
99 uint8_t bDescriptorType;
100 /* Chip ID and revision */
101 uint16_t wChipID; /* 0x5002 for PP5002 for example */
102 uint8_t bRevision[2]; /* 'B1' for B1 for example */
103} __attribute__((packed));
104
95#define HWSTUB_TARGET_UNK ('U' | 'N' << 8 | 'K' << 16 | ' ' << 24) 105#define HWSTUB_TARGET_UNK ('U' | 'N' << 8 | 'K' << 16 | ' ' << 24)
96#define HWSTUB_TARGET_STMP ('S' | 'T' << 8 | 'M' << 16 | 'P' << 24) 106#define HWSTUB_TARGET_STMP ('S' | 'T' << 8 | 'M' << 16 | 'P' << 24)
97#define HWSTUB_TARGET_RK27 ('R' | 'K' << 8 | '2' << 16 | '7' << 24) 107#define HWSTUB_TARGET_RK27 ('R' | 'K' << 8 | '2' << 16 | '7' << 24)
diff --git a/utils/hwstub/stub/pp/Makefile b/utils/hwstub/stub/pp/Makefile
index 6e79a2b1c8..73d5838f49 100644
--- a/utils/hwstub/stub/pp/Makefile
+++ b/utils/hwstub/stub/pp/Makefile
@@ -7,7 +7,7 @@ AS=arm-elf-eabi-gcc
7OC=arm-elf-eabi-objcopy 7OC=arm-elf-eabi-objcopy
8DEFINES= 8DEFINES=
9INCLUDES=-I$(CURDIR) 9INCLUDES=-I$(CURDIR)
10GCCOPTS=-mcpu=arm926ej-s 10GCCOPTS=-mcpu=arm7tdmi
11BUILD_DIR=$(CURDIR)/build/ 11BUILD_DIR=$(CURDIR)/build/
12ROOT_DIR=$(CURDIR)/.. 12ROOT_DIR=$(CURDIR)/..
13 13
diff --git a/utils/hwstub/stub/pp/crt0.S b/utils/hwstub/stub/pp/crt0.S
index 38b6f18ac5..a128391286 100644
--- a/utils/hwstub/stub/pp/crt0.S
+++ b/utils/hwstub/stub/pp/crt0.S
@@ -5,9 +5,25 @@
5start: 5start:
6 sub r7, pc, #8 /* Copy running address */ 6 sub r7, pc, #8 /* Copy running address */
7 msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */ 7 msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */
8 /* The stub could be located at a virtual address so killing the MMU at 8
9 * this point would be mere suicide. We assume that the remap location 9 /* Get processor ID */
10 * is identically mapped and kill the MMU after the copy */ 10 ldr r0, =0x60000000 /* PROC_ID */
11 ldrb r4, [r0]
12
13 /* Halt the COP */
14 ldr r6, =0x60007004 /* COP_CTL */
15 cmp r4, #0x55 /* CPU_ID */
161:
17 ldrne r1, [r6]
18 orrne r1, #0x80000000 /* PROC_SLEEP */
19 strne r1, [r6]
20 bne 1b
21
22 /* Wait for the COP to be stopped */
231:
24 ldr r0, [r6]
25 tst r0, #0x80000000 /* PROC_SLEEP */
26 beq 1b
11 27
12 /* Relocate to right address */ 28 /* Relocate to right address */
13 mov r2, r7 29 mov r2, r7
@@ -19,16 +35,11 @@ start:
19 strhi r5, [r3], #4 35 strhi r5, [r3], #4
20 bhi 1b 36 bhi 1b
21 mov r2, #0 37 mov r2, #0
22 mcr p15, 0, r2, c7, c5, 0 @ Invalidate ICache 38 /* FIXME invalid Icache here ? */
23 /* Jump to real location */ 39 /* Jump to real location */
24 ldr pc, =remap 40 ldr pc, =remap
25remap: 41remap:
26 /* Disable MMU, disable caching and buffering; 42 /* NOTE on PP611x, we should make sure the MMU is disabled at this point */
27 * use low exception range address */
28 mrc p15, 0, r0, c1, c0, 0
29 ldr r1, =0x3005
30 bic r0, r1
31 mcr p15, 0, r0, c1, c0, 0
32 /* clear bss */ 43 /* clear bss */
33 ldr r2, =bss_start 44 ldr r2, =bss_start
34 ldr r3, =bss_end 45 ldr r3, =bss_end
diff --git a/utils/hwstub/stub/pp/target-config.h b/utils/hwstub/stub/pp/target-config.h
index 0774137277..0cd7c0ccc7 100644
--- a/utils/hwstub/stub/pp/target-config.h
+++ b/utils/hwstub/stub/pp/target-config.h
@@ -1,9 +1,7 @@
1#define CONFIG_PP 1#define CONFIG_PP
2#define IRAM_ORIG 0x40000000 2#define IRAM_ORIG 0x40000000
3#define IRAM_SIZE 0x20000 3#define IRAM_SIZE 0xc000
4#define DRAM_ORIG 0x10f00000
5#define DRAM_SIZE (MEMORYSIZE * 0x100000)
6#define CPU_ARM 4#define CPU_ARM
7#define ARM_ARCH 5 5#define ARM_ARCH 4
8#define USB_BASE 0xc5000000 6#define USB_BASE 0xc5000000
9#define USB_NUM_ENDPOINTS 2 \ No newline at end of file 7#define USB_NUM_ENDPOINTS 2 \ No newline at end of file
diff --git a/utils/hwstub/stub/pp/target.c b/utils/hwstub/stub/pp/target.c
index 14eab80080..5e3a819114 100644
--- a/utils/hwstub/stub/pp/target.c
+++ b/utils/hwstub/stub/pp/target.c
@@ -30,28 +30,85 @@
30 * 30 *
31 */ 31 */
32 32
33/* FIXME wrong for PP500x */ 33enum pp_family_t
34#define USEC_TIMER (*(volatile unsigned long *)(0x60005010)) 34{
35 UNKNOWN,
36 PP502x,
37 PP611x
38};
39
40static enum pp_family_t g_pp_family = UNKNOWN;
41
42#define USEC_TIMER (*(volatile unsigned long *)(0x60005010))
43
44// NOTE only valid for PP502x and above */
45#define PP_VER1 (*(volatile unsigned long *)(0x70000000))
46#define PP_VER2 (*(volatile unsigned long *)(0x70000004))
35 47
36struct hwstub_target_desc_t __attribute__((aligned(2))) target_descriptor = 48struct hwstub_target_desc_t __attribute__((aligned(2))) target_descriptor =
37{ 49{
38 sizeof(struct hwstub_target_desc_t), 50 sizeof(struct hwstub_target_desc_t),
39 HWSTUB_DT_TARGET, 51 HWSTUB_DT_TARGET,
40 HWSTUB_TARGET_PP, 52 HWSTUB_TARGET_PP,
41 "PP500x / PP502x / PP610x" 53 "PP502x / PP611x"
42}; 54};
43 55
56static struct hwstub_pp_desc_t __attribute__((aligned(2))) pp_descriptor =
57{
58 sizeof(struct hwstub_pp_desc_t),
59 HWSTUB_DT_PP,
60 0, {' ', ' '},
61};
62
63static uint16_t char2hex(uint8_t c)
64{
65 if(c >= '0' && c <= '9')
66 return c - '0';
67 else
68 return 0xf;
69}
70
44void target_init(void) 71void target_init(void)
45{ 72{
73 /* try to read version for PP502x */
74 if(PP_VER2 >> 16 != ('P' | 'P' << 8))
75 {
76 logf("unidentified PP family");
77 g_pp_family = UNKNOWN;
78 }
79 else
80 {
81 pp_descriptor.wChipID = char2hex((PP_VER2 >> 8) & 0xff) << 12 |
82 char2hex(PP_VER2 & 0xff) << 8 |
83 char2hex((PP_VER1 >> 24) & 0xff) << 4 |
84 char2hex((PP_VER1 >> 16) & 0xff);
85 pp_descriptor.bRevision[0] = (PP_VER1 >> 8) & 0xff;
86 pp_descriptor.bRevision[1] = PP_VER1 & 0xff;
87 if(pp_descriptor.wChipID >= 0x6110)
88 {
89 logf("identified PP611x family");
90 g_pp_family = PP611x;
91 }
92 else
93 {
94 logf("identified PP502x family");
95 g_pp_family = PP502x;
96 }
97 }
46} 98}
47 99
48void target_get_desc(int desc, void **buffer) 100void target_get_desc(int desc, void **buffer)
49{ 101{
50 *buffer = NULL; 102 if(desc == HWSTUB_DT_PP)
103 *buffer = &pp_descriptor;
104 else
105 *buffer = NULL;
51} 106}
52 107
53void target_get_config_desc(void *buffer, int *size) 108void target_get_config_desc(void *buffer, int *size)
54{ 109{
110 memcpy(buffer, &pp_descriptor, sizeof(pp_descriptor));
111 *size += sizeof(pp_descriptor);
55} 112}
56 113
57void target_udelay(int us) 114void target_udelay(int us)
diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp
index 61cb617509..cdacd81821 100644
--- a/utils/hwstub/tools/hwstub_shell.cpp
+++ b/utils/hwstub/tools/hwstub_shell.cpp
@@ -44,6 +44,7 @@ struct hwstub_version_desc_t g_hwdev_ver;
44struct hwstub_layout_desc_t g_hwdev_layout; 44struct hwstub_layout_desc_t g_hwdev_layout;
45struct hwstub_target_desc_t g_hwdev_target; 45struct hwstub_target_desc_t g_hwdev_target;
46struct hwstub_stmp_desc_t g_hwdev_stmp; 46struct hwstub_stmp_desc_t g_hwdev_stmp;
47struct hwstub_pp_desc_t g_hwdev_pp;
47lua_State *g_lua; 48lua_State *g_lua;
48 49
49/** 50/**
@@ -278,6 +279,8 @@ bool my_lua_import_hwstub()
278 lua_setfield(g_lua, -2, "UNK"); 279 lua_setfield(g_lua, -2, "UNK");
279 lua_pushinteger(g_lua, HWSTUB_TARGET_STMP); 280 lua_pushinteger(g_lua, HWSTUB_TARGET_STMP);
280 lua_setfield(g_lua, -2, "STMP"); 281 lua_setfield(g_lua, -2, "STMP");
282 lua_pushinteger(g_lua, HWSTUB_TARGET_PP);
283 lua_setfield(g_lua, -2, "PP");
281 lua_pushinteger(g_lua, HWSTUB_TARGET_RK27); 284 lua_pushinteger(g_lua, HWSTUB_TARGET_RK27);
282 lua_setfield(g_lua, -2, "RK27"); 285 lua_setfield(g_lua, -2, "RK27");
283 lua_setfield(g_lua, -2, "target"); 286 lua_setfield(g_lua, -2, "target");
@@ -293,6 +296,15 @@ bool my_lua_import_hwstub()
293 lua_setfield(g_lua, -2, "package"); 296 lua_setfield(g_lua, -2, "package");
294 lua_setfield(g_lua, -2, "stmp"); 297 lua_setfield(g_lua, -2, "stmp");
295 } 298 }
299 else if(g_hwdev_target.dID == HWSTUB_TARGET_PP)
300 {
301 lua_newtable(g_lua); // pp
302 lua_pushinteger(g_lua, g_hwdev_pp.wChipID);
303 lua_setfield(g_lua, -2, "chipid");
304 lua_pushlstring(g_lua, (const char *)g_hwdev_pp.bRevision, 2);
305 lua_setfield(g_lua, -2, "rev");
306 lua_setfield(g_lua, -2, "pp");
307 }
296 308
297 lua_pushlightuserdata(g_lua, (void *)&hw_read8); 309 lua_pushlightuserdata(g_lua, (void *)&hw_read8);
298 lua_pushcclosure(g_lua, my_lua_readn, 1); 310 lua_pushcclosure(g_lua, my_lua_readn, 1);
@@ -791,6 +803,17 @@ int main(int argc, char **argv)
791 goto Lerr; 803 goto Lerr;
792 } 804 }
793 } 805 }
806
807 // get PP specific information
808 if(g_hwdev_target.dID == HWSTUB_TARGET_PP)
809 {
810 ret = hwstub_get_desc(g_hwdev, HWSTUB_DT_PP, &g_hwdev_pp, sizeof(g_hwdev_pp));
811 if(ret != sizeof(g_hwdev_pp))
812 {
813 printf("Cannot get pp: %d\n", ret);
814 goto Lerr;
815 }
816 }
794 /** Init lua */ 817 /** Init lua */
795 818
796 // create lua state 819 // create lua state
diff --git a/utils/hwstub/tools/lua/load.lua b/utils/hwstub/tools/lua/load.lua
index 2875b74f1a..a812f92636 100644
--- a/utils/hwstub/tools/lua/load.lua
+++ b/utils/hwstub/tools/lua/load.lua
@@ -2,6 +2,8 @@ package.path = string.sub(string.gsub(debug.getinfo(1).source, "load.lua", "?.lu
2 2
3if hwstub.dev.target.id == hwstub.dev.target.STMP then 3if hwstub.dev.target.id == hwstub.dev.target.STMP then
4 require "stmp" 4 require "stmp"
5elseif hwstub.dev.target.id == hwstub.dev.target.PP then
6 require "pp"
5end 7end
6 8
7require "dumper" 9require "dumper"
diff --git a/utils/hwstub/tools/lua/pp.lua b/utils/hwstub/tools/lua/pp.lua
new file mode 100644
index 0000000000..e32a878d01
--- /dev/null
+++ b/utils/hwstub/tools/lua/pp.lua
@@ -0,0 +1,62 @@
1---
2--- Chip Identification
3---
4
5PP = { info = {} }
6
7local h = HELP:create_topic("PP")
8h:add("This table contains the abstraction of the different device blocks for the Portal Player / GoForce")
9h:add("It allows one to use higher-level primitives rather than poking at register directly.")
10h:add("Furthermore, it tries as much as possible to hide the differences between the different PP families.")
11
12local function identify(name, family, desc)
13 PP.chipid = hwstub.dev.pp.chipid
14 PP.info.chip = name
15 PP.info.revision = hwstub.dev.pp.rev
16 PP.desc = desc
17 PP.family = family
18 print("Chip identified as " .. name ..", ROM " .. PP.info.revision)
19 if not hwstub.soc:select(desc) then
20 print("Looking for soc " .. desc .. ": not found. Please load a soc by hand.")
21 end
22end
23
24local hh = h:create_topic("is_pp611x")
25hh:add("PP.is_pp611x() returns true if the chip ID reports a PP611x")
26
27function PP.is_pp611x()
28 return hwstub.dev.pp.chipid >= 0x6110
29end
30
31hh = h:create_topic("is_pp502x")
32hh:add("PP.is_pp502x() returns true if the chip ID reports a PP502x")
33
34function PP.is_pp502x()
35 return hwstub.dev.pp.chipid >= 0x5020 and hwstub.dev.pp.chipid < 0x6100
36end
37
38hh = h:create_topic("is_pp500x")
39hh:add("PP.is_pp500x() returns true if the chip ID reports a PP500x")
40
41function PP.is_pp500x()
42 return hwstub.dev.pp.chipid >= 0x5000 and hwstub.dev.pp.chipid < 0x5010
43end
44
45if PP.is_pp611x() then
46 identify("PP6110x (aka GoForce6110)", "pp6110", "pp6110")
47elseif PP.is_pp502x() then
48 identify("PP502x", "pp502x", "pp502x")
49elseif PP.is_pp500x() then
50 identify("PP500x", "pp500x", "pp500x")
51else
52 print(string.format("Unable to identify this chip as a PP: chipid=0x%x", hwstub.dev.pp.chipid));
53end
54
55hh = h:create_topic("debug")
56hh:add("PP.debug(...) prints some debug output if PP.debug_on is true and does nothing otherwise.")
57
58PP.debug_on = false
59
60function PP.debug(...)
61 if PP.debug_on then print(...) end
62end