diff --git a/utils/hwstub/hwstub_protocol.h b/utils/hwstub/hwstub_protocol.h index 4feab87f00..a34c65b1b5 100644 --- a/utils/hwstub/hwstub_protocol.h +++ b/utils/hwstub/hwstub_protocol.h @@ -95,6 +95,7 @@ struct hwstub_stmp_desc_t #define HWSTUB_TARGET_UNK ('U' | 'N' << 8 | 'K' << 16 | ' ' << 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_PP ('P' | 'P' << 8 | ' ' << 16 | ' ' << 24) struct hwstub_target_desc_t { diff --git a/utils/hwstub/stub/SOURCES b/utils/hwstub/stub/SOURCES index bcb782c282..9693fdd408 100644 --- a/utils/hwstub/stub/SOURCES +++ b/utils/hwstub/stub/SOURCES @@ -15,4 +15,8 @@ usb_drv_arc.c rk27xx/crt0.S rk27xx/usb_drv_rk27xx.c rk27xx/target.c +#elif defined(CONFIG_PP) +pp/crt0.S +pp/target.c +usb_drv_arc.c #endif diff --git a/utils/hwstub/stub/pp/Makefile b/utils/hwstub/stub/pp/Makefile new file mode 100644 index 0000000000..6e79a2b1c8 --- /dev/null +++ b/utils/hwstub/stub/pp/Makefile @@ -0,0 +1,14 @@ +# +# common +# +CC=arm-elf-eabi-gcc +LD=arm-elf-eabi-gcc +AS=arm-elf-eabi-gcc +OC=arm-elf-eabi-objcopy +DEFINES= +INCLUDES=-I$(CURDIR) +GCCOPTS=-mcpu=arm926ej-s +BUILD_DIR=$(CURDIR)/build/ +ROOT_DIR=$(CURDIR)/.. + +include ../hwstub.make diff --git a/utils/hwstub/stub/pp/crt0.S b/utils/hwstub/stub/pp/crt0.S new file mode 100644 index 0000000000..38b6f18ac5 --- /dev/null +++ b/utils/hwstub/stub/pp/crt0.S @@ -0,0 +1,42 @@ +.section .text,"ax",%progbits +.code 32 +.align 0x04 +.global start +start: + sub r7, pc, #8 /* Copy running address */ + 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 + * is identically mapped and kill the MMU after the copy */ + + /* Relocate to right address */ + mov r2, r7 + ldr r3, =_copystart + ldr r4, =_copyend +1: + cmp r4, r3 + ldrhi r5, [r2], #4 + strhi r5, [r3], #4 + bhi 1b + mov r2, #0 + mcr p15, 0, r2, c7, c5, 0 @ Invalidate ICache + /* Jump to real location */ + ldr pc, =remap +remap: + /* Disable MMU, disable caching and buffering; + * 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 */ + ldr r2, =bss_start + ldr r3, =bss_end + mov r4, #0 +1: + cmp r3, r2 + strhi r4, [r2], #4 + bhi 1b + /* jump to C code */ + ldr sp, =oc_stackend + b main diff --git a/utils/hwstub/stub/pp/hwstub.lds b/utils/hwstub/stub/pp/hwstub.lds new file mode 100644 index 0000000000..baf10252e1 --- /dev/null +++ b/utils/hwstub/stub/pp/hwstub.lds @@ -0,0 +1,73 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2014 by Amaury Pouly + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" + +ENTRY(start) +OUTPUT_FORMAT(elf32-littlearm) +OUTPUT_ARCH(arm) +STARTUP(pp/crt0.o) + +#define IRAM_END_ADDR (IRAM_ORIG + IRAM_SIZE) + +MEMORY +{ + OCRAM : ORIGIN = IRAM_ORIG, LENGTH = IRAM_SIZE +} + +SECTIONS +{ + .octext : + { + _copystart = .; + oc_codestart = .; + *(.text*) + *(.icode*) + *(.data*) + *(.rodata*) + _copyend = .; + } > OCRAM + + .bss (NOLOAD) : + { + bss_start = .; + *(.bss) + bss_end = .; + } > OCRAM + + .stack (NOLOAD) : + { + oc_codeend = .; + oc_stackstart = .; + . += STACK_SIZE; + oc_stackend = .; + oc_bufferstart = .; + } > OCRAM + + .ocend IRAM_END_ADDR (NOLOAD) : + { + oc_bufferend = .; + } > OCRAM + + /DISCARD/ : + { + *(.eh_frame) + } +} diff --git a/utils/hwstub/stub/pp/target-config.h b/utils/hwstub/stub/pp/target-config.h new file mode 100644 index 0000000000..0774137277 --- /dev/null +++ b/utils/hwstub/stub/pp/target-config.h @@ -0,0 +1,9 @@ +#define CONFIG_PP +#define IRAM_ORIG 0x40000000 +#define IRAM_SIZE 0x20000 +#define DRAM_ORIG 0x10f00000 +#define DRAM_SIZE (MEMORYSIZE * 0x100000) +#define CPU_ARM +#define ARM_ARCH 5 +#define USB_BASE 0xc5000000 +#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 new file mode 100644 index 0000000000..14eab80080 --- /dev/null +++ b/utils/hwstub/stub/pp/target.c @@ -0,0 +1,66 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2014 by Amaury Pouly + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "stddef.h" +#include "target.h" +#include "system.h" +#include "logf.h" +#include "memory.h" + +/** + * + * Global + * + */ + +/* FIXME wrong for PP500x */ +#define USEC_TIMER (*(volatile unsigned long *)(0x60005010)) + +struct hwstub_target_desc_t __attribute__((aligned(2))) target_descriptor = +{ + sizeof(struct hwstub_target_desc_t), + HWSTUB_DT_TARGET, + HWSTUB_TARGET_PP, + "PP500x / PP502x / PP610x" +}; + +void target_init(void) +{ +} + +void target_get_desc(int desc, void **buffer) +{ + *buffer = NULL; +} + +void target_get_config_desc(void *buffer, int *size) +{ +} + +void target_udelay(int us) +{ + uint32_t end = USEC_TIMER + us; + while(USEC_TIMER <= end); +} + +void target_mdelay(int ms) +{ + return target_udelay(ms * 1000); +}