From 721173449c8bb561424a48b34998cdd1ac044c3f Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Wed, 15 Apr 2009 15:03:47 -0400 Subject: [PATCH] startup code --- Makefile | 11 ++- boot.lds | 2 +- include/maca.h | 1 + include/nvm.h | 40 +++++++++++ src/maca.c | 1 + src/start.S | 177 +++++++++++++++++++++++++++++++++++++++++++++++ tests/nvm-read.c | 15 ++-- 7 files changed, 232 insertions(+), 15 deletions(-) create mode 100644 include/nvm.h create mode 100644 src/start.S diff --git a/Makefile b/Makefile index c391d6cdc..3d4a2a3f2 100644 --- a/Makefile +++ b/Makefile @@ -58,11 +58,11 @@ ALL = $(TESTS:.c=.srec) $(TESTS:.c=.bin) $(TESTS:.c=.dis) .PRECIOUS: $(COBJS) $(TARGETS) $(TESTS:.c=.obj) -all: $(ALL) +all: src/start.o $(ALL) -tests/nvm-read.obj: src/maca.o -tests/rftest-rx.obj: src/maca.o -tests/rftest-tx.obj: src/maca.o +tests/nvm-read.obj: src/maca.o +tests/rftest-rx.obj: src/maca.o +tests/rftest-tx.obj: src/maca.o %.srec: %.obj $(OBJCOPY) ${OBJCFLAGS} -O srec $< $@ @@ -74,10 +74,9 @@ tests/rftest-tx.obj: src/maca.o $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@ %.dis: %.obj - $(OBJDUMP) -d $< > $@ + $(OBJDUMP) -D $< > $@ %.obj: $(LDSCRIPT) %.o - echo $*.o $(LD) $(LDFLAGS) $(AOBJS) \ --start-group $(PLATFORM_LIBS) --end-group \ -Map $*.map $^ -o $@ diff --git a/boot.lds b/boot.lds index c9f49a561..5b6ae7aef 100644 --- a/boot.lds +++ b/boot.lds @@ -32,7 +32,7 @@ SECTIONS . = ALIGN(4); .text : { - *(startup) + src/start.o (.text) *(.text) } diff --git a/include/maca.h b/include/maca.h index ba263de5c..4be48cc06 100644 --- a/include/maca.h +++ b/include/maca.h @@ -407,6 +407,7 @@ typedef union maca_maskirq_reg_tag void reset_maca(void); void init_phy(void); +void vreg_init(void); void ResumeMACASync(void); void radio_init(void); void set_power(uint8_t power); diff --git a/include/nvm.h b/include/nvm.h new file mode 100644 index 000000000..3b30575b1 --- /dev/null +++ b/include/nvm.h @@ -0,0 +1,40 @@ +#ifndef NVM_H +#define NVM_H + +typedef enum +{ + gNvmType_NoNvm_c, + gNvmType_SST_c, + gNvmType_ST_c, + gNvmType_ATM_c, + gNvmType_Max_c +} nvmType_t; + + +typedef enum +{ + gNvmErrNoError_c = 0, + gNvmErrInvalidInterface_c, + gNvmErrInvalidNvmType_c, + gNvmErrInvalidPointer_c, + gNvmErrWriteProtect_c, + gNvmErrVerifyError_c, + gNvmErrAddressSpaceOverflow_c, + gNvmErrBlankCheckError_c, + gNvmErrRestrictedArea_c, + gNvmErrMaxError_c +} nvmErr_t; + +typedef enum +{ + gNvmInternalInterface_c, + gNvmExternalInterface_c, + gNvmInterfaceMax_c +} nvmInterface_t; + +/* ROM code seems to be THUMB */ +/* need to be in a THUMB block before calling them */ +volatile nvmErr_t (*nvm_detect)(nvmInterface_t nvmInterface,nvmType_t* pNvmType) = 0x00006cb9; +volatile nvmErr_t (*nvm_read)(nvmInterface_t nvmInterface , nvmType_t nvmType , void *pDest, uint32_t address, uint32_t numBytes); + +#endif //NVM_H diff --git a/src/maca.c b/src/maca.c index cf711c973..d24a74ffd 100644 --- a/src/maca.c +++ b/src/maca.c @@ -1,3 +1,4 @@ +#include "embedded_types.h" #include "maca.h" #define reg(x) (*(volatile uint32_t *)(x)) diff --git a/src/start.S b/src/start.S new file mode 100644 index 000000000..23ece110e --- /dev/null +++ b/src/start.S @@ -0,0 +1,177 @@ +/* + * armboot - Startup Code for ARM720 CPU-core + * + * Copyright (c) 2001 Marius Gröger + * Copyright (c) 2002 Alex Züpke + * + * See file CREDITS for list of people who contributed to this + * project. + * + * 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 program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + + +/* + ************************************************************************* + * + * Jump vector table as in table 3.1 in [1] + * + ************************************************************************* + */ + + +.globl _start +_start: b main + ldr pc, _undefined_instruction + ldr pc, _software_interrupt + ldr pc, _prefetch_abort + ldr pc, _data_abort + ldr pc, _not_used + ldr pc, _irq + ldr pc, _fiq + +_undefined_instruction: .word undefined_instruction +_software_interrupt: .word software_interrupt +_prefetch_abort: .word prefetch_abort +_data_abort: .word data_abort +_not_used: .word not_used +_irq: .word irq +_fiq: .word fiq + + .balignl 16,0xdeadbeef + + +/* + ************************************************************************* + * + * Startup Code (reset vector) + * + * do important init only if we don't start from memory! + * relocate armboot to ram + * setup stack + * jump to second stage + * + ************************************************************************* + */ + +_TEXT_BASE: + .word TEXT_BASE + +.globl _armboot_start +_armboot_start: + .word _start + +/* + * These are defined in the board-specific linker script. + */ +.globl _bss_start +_bss_start: + .word __bss_start + +.globl _bss_end +_bss_end: + .word _end + +_start_armboot: .word main + +/* + ************************************************************************* + * + * CPU_init_critical registers + * + ************************************************************************* + */ + +cpu_init_crit: + # actually do nothing for now! + mov pc, lr + + +/* + ************************************************************************* + * + * Interrupt handling + * + ************************************************************************* + */ + +@ +@ IRQ stack frame. +@ +#define S_FRAME_SIZE 72 + +#define S_OLD_R0 68 +#define S_PSR 64 +#define S_PC 60 +#define S_LR 56 +#define S_SP 52 + +#define S_IP 48 +#define S_FP 44 +#define S_R10 40 +#define S_R9 36 +#define S_R8 32 +#define S_R7 28 +#define S_R6 24 +#define S_R5 20 +#define S_R4 16 +#define S_R3 12 +#define S_R2 8 +#define S_R1 4 +#define S_R0 0 + +#define MODE_SVC 0x13 +#define I_BIT 0x80 + + + .macro get_irq_stack @ setup IRQ stack + ldr sp, IRQ_STACK_START + .endm + + .macro get_fiq_stack @ setup FIQ stack + ldr sp, FIQ_STACK_START + .endm + +/* + * exception handlers + */ + .align 5 +undefined_instruction: + + .align 5 +software_interrupt: + + .align 5 +prefetch_abort: + nop + .align 5 +data_abort: + + .align 5 +not_used: + + + .align 5 +irq: + + .align 5 +fiq: + + .align 5 + +.globl reset_cpu +reset_cpu: + mov pc, r0 diff --git a/tests/nvm-read.c b/tests/nvm-read.c index b14677663..b06829c42 100644 --- a/tests/nvm-read.c +++ b/tests/nvm-read.c @@ -14,6 +14,7 @@ #include "embedded_types.h" #include "nvm.h" +#include "maca.h" #define reg(x) (*(volatile uint32_t *)(x)) @@ -30,8 +31,7 @@ const uint8_t hex[16]={'0','1','2','3','4','5','6','7', __attribute__ ((section ("startup"))) void main(void) { - uint8_t c; - uint32_t type; + uint32_t type=0xdeadbeef; nvmErr_t err; *(volatile uint32_t *)GPIO_PAD_DIR0 = 0x00000100; @@ -55,9 +55,9 @@ void main(void) { vreg_init(); - puts("CRM status: 0x"); - put_hex32(reg(0x80003018)); - puts("\n\r"); +// puts("CRM status: 0x"); +// put_hex32(reg(0x80003018)); +// puts("\n\r"); puts("Detecting internal nvm\n\r"); @@ -66,11 +66,10 @@ void main(void) { puts("nvm_detect returned: 0x"); put_hex(err); puts(" type is: 0x"); - put_hex(type); + put_hex32(type); puts("\n\r"); - while(1) { - }; + while(1) {continue;}; } void putc(uint8_t c) {