1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Amaury Pouly 2014-04-12 00:08:11 +02:00
parent 910235b49a
commit 238be18d03
8 changed files with 182 additions and 19 deletions

View file

@ -56,6 +56,7 @@
#define HWSTUB_DT_LAYOUT 0x42 /* mandatory */ #define HWSTUB_DT_LAYOUT 0x42 /* mandatory */
#define HWSTUB_DT_TARGET 0x43 /* mandatory */ #define HWSTUB_DT_TARGET 0x43 /* mandatory */
#define HWSTUB_DT_STMP 0x44 /* optional */ #define HWSTUB_DT_STMP 0x44 /* optional */
#define HWSTUB_DT_PP 0x45 /* optional */
struct hwstub_version_desc_t struct hwstub_version_desc_t
{ {
@ -92,6 +93,15 @@ struct hwstub_stmp_desc_t
uint8_t bPackage; /* 0=169BGA for example */ uint8_t bPackage; /* 0=169BGA for example */
} __attribute__((packed)); } __attribute__((packed));
struct hwstub_pp_desc_t
{
uint8_t bLength;
uint8_t bDescriptorType;
/* Chip ID and revision */
uint16_t wChipID; /* 0x5002 for PP5002 for example */
uint8_t bRevision[2]; /* 'B1' for B1 for example */
} __attribute__((packed));
#define HWSTUB_TARGET_UNK ('U' | 'N' << 8 | 'K' << 16 | ' ' << 24) #define HWSTUB_TARGET_UNK ('U' | 'N' << 8 | 'K' << 16 | ' ' << 24)
#define HWSTUB_TARGET_STMP ('S' | 'T' << 8 | 'M' << 16 | 'P' << 24) #define HWSTUB_TARGET_STMP ('S' | 'T' << 8 | 'M' << 16 | 'P' << 24)
#define HWSTUB_TARGET_RK27 ('R' | 'K' << 8 | '2' << 16 | '7' << 24) #define HWSTUB_TARGET_RK27 ('R' | 'K' << 8 | '2' << 16 | '7' << 24)

View file

@ -7,7 +7,7 @@ AS=arm-elf-eabi-gcc
OC=arm-elf-eabi-objcopy OC=arm-elf-eabi-objcopy
DEFINES= DEFINES=
INCLUDES=-I$(CURDIR) INCLUDES=-I$(CURDIR)
GCCOPTS=-mcpu=arm926ej-s GCCOPTS=-mcpu=arm7tdmi
BUILD_DIR=$(CURDIR)/build/ BUILD_DIR=$(CURDIR)/build/
ROOT_DIR=$(CURDIR)/.. ROOT_DIR=$(CURDIR)/..

View file

@ -5,9 +5,25 @@
start: start:
sub r7, pc, #8 /* Copy running address */ sub r7, pc, #8 /* Copy running address */
msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */ msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */
/* The stub could be located at a virtual address so killing the MMU at
* this point would be mere suicide. We assume that the remap location /* Get processor ID */
* is identically mapped and kill the MMU after the copy */ ldr r0, =0x60000000 /* PROC_ID */
ldrb r4, [r0]
/* Halt the COP */
ldr r6, =0x60007004 /* COP_CTL */
cmp r4, #0x55 /* CPU_ID */
1:
ldrne r1, [r6]
orrne r1, #0x80000000 /* PROC_SLEEP */
strne r1, [r6]
bne 1b
/* Wait for the COP to be stopped */
1:
ldr r0, [r6]
tst r0, #0x80000000 /* PROC_SLEEP */
beq 1b
/* Relocate to right address */ /* Relocate to right address */
mov r2, r7 mov r2, r7
@ -19,16 +35,11 @@ start:
strhi r5, [r3], #4 strhi r5, [r3], #4
bhi 1b bhi 1b
mov r2, #0 mov r2, #0
mcr p15, 0, r2, c7, c5, 0 @ Invalidate ICache /* FIXME invalid Icache here ? */
/* Jump to real location */ /* Jump to real location */
ldr pc, =remap ldr pc, =remap
remap: remap:
/* Disable MMU, disable caching and buffering; /* NOTE on PP611x, we should make sure the MMU is disabled at this point */
* use low exception range address */
mrc p15, 0, r0, c1, c0, 0
ldr r1, =0x3005
bic r0, r1
mcr p15, 0, r0, c1, c0, 0
/* clear bss */ /* clear bss */
ldr r2, =bss_start ldr r2, =bss_start
ldr r3, =bss_end ldr r3, =bss_end

View file

@ -1,9 +1,7 @@
#define CONFIG_PP #define CONFIG_PP
#define IRAM_ORIG 0x40000000 #define IRAM_ORIG 0x40000000
#define IRAM_SIZE 0x20000 #define IRAM_SIZE 0xc000
#define DRAM_ORIG 0x10f00000
#define DRAM_SIZE (MEMORYSIZE * 0x100000)
#define CPU_ARM #define CPU_ARM
#define ARM_ARCH 5 #define ARM_ARCH 4
#define USB_BASE 0xc5000000 #define USB_BASE 0xc5000000
#define USB_NUM_ENDPOINTS 2 #define USB_NUM_ENDPOINTS 2

View file

@ -30,28 +30,85 @@
* *
*/ */
/* FIXME wrong for PP500x */ enum pp_family_t
#define USEC_TIMER (*(volatile unsigned long *)(0x60005010)) {
UNKNOWN,
PP502x,
PP611x
};
static enum pp_family_t g_pp_family = UNKNOWN;
#define USEC_TIMER (*(volatile unsigned long *)(0x60005010))
// NOTE only valid for PP502x and above */
#define PP_VER1 (*(volatile unsigned long *)(0x70000000))
#define PP_VER2 (*(volatile unsigned long *)(0x70000004))
struct hwstub_target_desc_t __attribute__((aligned(2))) target_descriptor = struct hwstub_target_desc_t __attribute__((aligned(2))) target_descriptor =
{ {
sizeof(struct hwstub_target_desc_t), sizeof(struct hwstub_target_desc_t),
HWSTUB_DT_TARGET, HWSTUB_DT_TARGET,
HWSTUB_TARGET_PP, HWSTUB_TARGET_PP,
"PP500x / PP502x / PP610x" "PP502x / PP611x"
}; };
static struct hwstub_pp_desc_t __attribute__((aligned(2))) pp_descriptor =
{
sizeof(struct hwstub_pp_desc_t),
HWSTUB_DT_PP,
0, {' ', ' '},
};
static uint16_t char2hex(uint8_t c)
{
if(c >= '0' && c <= '9')
return c - '0';
else
return 0xf;
}
void target_init(void) void target_init(void)
{ {
/* try to read version for PP502x */
if(PP_VER2 >> 16 != ('P' | 'P' << 8))
{
logf("unidentified PP family");
g_pp_family = UNKNOWN;
}
else
{
pp_descriptor.wChipID = char2hex((PP_VER2 >> 8) & 0xff) << 12 |
char2hex(PP_VER2 & 0xff) << 8 |
char2hex((PP_VER1 >> 24) & 0xff) << 4 |
char2hex((PP_VER1 >> 16) & 0xff);
pp_descriptor.bRevision[0] = (PP_VER1 >> 8) & 0xff;
pp_descriptor.bRevision[1] = PP_VER1 & 0xff;
if(pp_descriptor.wChipID >= 0x6110)
{
logf("identified PP611x family");
g_pp_family = PP611x;
}
else
{
logf("identified PP502x family");
g_pp_family = PP502x;
}
}
} }
void target_get_desc(int desc, void **buffer) void target_get_desc(int desc, void **buffer)
{ {
*buffer = NULL; if(desc == HWSTUB_DT_PP)
*buffer = &pp_descriptor;
else
*buffer = NULL;
} }
void target_get_config_desc(void *buffer, int *size) void target_get_config_desc(void *buffer, int *size)
{ {
memcpy(buffer, &pp_descriptor, sizeof(pp_descriptor));
*size += sizeof(pp_descriptor);
} }
void target_udelay(int us) void target_udelay(int us)

View file

@ -44,6 +44,7 @@ struct hwstub_version_desc_t g_hwdev_ver;
struct hwstub_layout_desc_t g_hwdev_layout; struct hwstub_layout_desc_t g_hwdev_layout;
struct hwstub_target_desc_t g_hwdev_target; struct hwstub_target_desc_t g_hwdev_target;
struct hwstub_stmp_desc_t g_hwdev_stmp; struct hwstub_stmp_desc_t g_hwdev_stmp;
struct hwstub_pp_desc_t g_hwdev_pp;
lua_State *g_lua; lua_State *g_lua;
/** /**
@ -278,6 +279,8 @@ bool my_lua_import_hwstub()
lua_setfield(g_lua, -2, "UNK"); lua_setfield(g_lua, -2, "UNK");
lua_pushinteger(g_lua, HWSTUB_TARGET_STMP); lua_pushinteger(g_lua, HWSTUB_TARGET_STMP);
lua_setfield(g_lua, -2, "STMP"); lua_setfield(g_lua, -2, "STMP");
lua_pushinteger(g_lua, HWSTUB_TARGET_PP);
lua_setfield(g_lua, -2, "PP");
lua_pushinteger(g_lua, HWSTUB_TARGET_RK27); lua_pushinteger(g_lua, HWSTUB_TARGET_RK27);
lua_setfield(g_lua, -2, "RK27"); lua_setfield(g_lua, -2, "RK27");
lua_setfield(g_lua, -2, "target"); lua_setfield(g_lua, -2, "target");
@ -293,6 +296,15 @@ bool my_lua_import_hwstub()
lua_setfield(g_lua, -2, "package"); lua_setfield(g_lua, -2, "package");
lua_setfield(g_lua, -2, "stmp"); lua_setfield(g_lua, -2, "stmp");
} }
else if(g_hwdev_target.dID == HWSTUB_TARGET_PP)
{
lua_newtable(g_lua); // pp
lua_pushinteger(g_lua, g_hwdev_pp.wChipID);
lua_setfield(g_lua, -2, "chipid");
lua_pushlstring(g_lua, (const char *)g_hwdev_pp.bRevision, 2);
lua_setfield(g_lua, -2, "rev");
lua_setfield(g_lua, -2, "pp");
}
lua_pushlightuserdata(g_lua, (void *)&hw_read8); lua_pushlightuserdata(g_lua, (void *)&hw_read8);
lua_pushcclosure(g_lua, my_lua_readn, 1); lua_pushcclosure(g_lua, my_lua_readn, 1);
@ -791,6 +803,17 @@ int main(int argc, char **argv)
goto Lerr; goto Lerr;
} }
} }
// get PP specific information
if(g_hwdev_target.dID == HWSTUB_TARGET_PP)
{
ret = hwstub_get_desc(g_hwdev, HWSTUB_DT_PP, &g_hwdev_pp, sizeof(g_hwdev_pp));
if(ret != sizeof(g_hwdev_pp))
{
printf("Cannot get pp: %d\n", ret);
goto Lerr;
}
}
/** Init lua */ /** Init lua */
// create lua state // create lua state

View file

@ -2,6 +2,8 @@ package.path = string.sub(string.gsub(debug.getinfo(1).source, "load.lua", "?.lu
if hwstub.dev.target.id == hwstub.dev.target.STMP then if hwstub.dev.target.id == hwstub.dev.target.STMP then
require "stmp" require "stmp"
elseif hwstub.dev.target.id == hwstub.dev.target.PP then
require "pp"
end end
require "dumper" require "dumper"

View file

@ -0,0 +1,62 @@
---
--- Chip Identification
---
PP = { info = {} }
local h = HELP:create_topic("PP")
h:add("This table contains the abstraction of the different device blocks for the Portal Player / GoForce")
h:add("It allows one to use higher-level primitives rather than poking at register directly.")
h:add("Furthermore, it tries as much as possible to hide the differences between the different PP families.")
local function identify(name, family, desc)
PP.chipid = hwstub.dev.pp.chipid
PP.info.chip = name
PP.info.revision = hwstub.dev.pp.rev
PP.desc = desc
PP.family = family
print("Chip identified as " .. name ..", ROM " .. PP.info.revision)
if not hwstub.soc:select(desc) then
print("Looking for soc " .. desc .. ": not found. Please load a soc by hand.")
end
end
local hh = h:create_topic("is_pp611x")
hh:add("PP.is_pp611x() returns true if the chip ID reports a PP611x")
function PP.is_pp611x()
return hwstub.dev.pp.chipid >= 0x6110
end
hh = h:create_topic("is_pp502x")
hh:add("PP.is_pp502x() returns true if the chip ID reports a PP502x")
function PP.is_pp502x()
return hwstub.dev.pp.chipid >= 0x5020 and hwstub.dev.pp.chipid < 0x6100
end
hh = h:create_topic("is_pp500x")
hh:add("PP.is_pp500x() returns true if the chip ID reports a PP500x")
function PP.is_pp500x()
return hwstub.dev.pp.chipid >= 0x5000 and hwstub.dev.pp.chipid < 0x5010
end
if PP.is_pp611x() then
identify("PP6110x (aka GoForce6110)", "pp6110", "pp6110")
elseif PP.is_pp502x() then
identify("PP502x", "pp502x", "pp502x")
elseif PP.is_pp500x() then
identify("PP500x", "pp500x", "pp500x")
else
print(string.format("Unable to identify this chip as a PP: chipid=0x%x", hwstub.dev.pp.chipid));
end
hh = h:create_topic("debug")
hh:add("PP.debug(...) prints some debug output if PP.debug_on is true and does nothing otherwise.")
PP.debug_on = false
function PP.debug(...)
if PP.debug_on then print(...) end
end