From 126d76a189309089c2cd4110d8cca1b68e35002c Mon Sep 17 00:00:00 2001 From: hackbard Date: Wed, 15 Aug 2007 18:27:19 +0200 Subject: [PATCH] added fwflash firmware (not yet working!) --- betty/Makefile | 13 ++- betty/fwflash.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+), 3 deletions(-) create mode 100644 betty/fwflash.c diff --git a/betty/Makefile b/betty/Makefile index 8d10030..4e07f98 100644 --- a/betty/Makefile +++ b/betty/Makefile @@ -7,7 +7,7 @@ ARMOBJCOPY = /scratch/arm-elf/bin/arm-elf-objcopy HOSTOBJECTS = lpcload fwdump -ARMOBJECTS = fwbc.hex +ARMOBJECTS = fwbc.hex fwflash.hex # all projects all: $(HOSTOBJECTS) $(ARMOBJECTS) @@ -22,8 +22,15 @@ fwbc: fwbc.hex: fwbc $(ARMOBJCOPY) -O ihex fwbc fwbc.hex +# fwflash +fwflash: + $(ARMCC) $(ARMCFLAGS) -c fwflash.c -o fwflash + +fwflash.hex: fwflash + $(ARMOBJCOPY) -O ihex fwflash fwflash.hex + clean: - rm -f lpcload fwbc.hex fwbc + rm -f lpcload fwdump arm_clean: - rm -f fwbc.hex fwbc + rm -f $(ARMOBJECTS) fwbc fwflash diff --git a/betty/fwflash.c b/betty/fwflash.c new file mode 100644 index 0000000..4462654 --- /dev/null +++ b/betty/fwflash.c @@ -0,0 +1,221 @@ +/* + * fwflash.c - handling the betty flashes + * + * author: hackbard@hackdaworld.org + * + */ + +/* + * include files + */ + +#include "lpc2xxx.h" + +/* + * defines + */ + +/* band 0/2 addr */ +#define BANK0 0x80000000 +#define BANK2 0x82000000 +#define B0HB 0x00000000 +#define B2HB 0x02000000 + +/* commands */ +#define CMD_READ 'R' +#define CMD_CHIP_ERASE 'E' + +#define BUFSIZE 16 + +/* + * type definitions + */ + +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; + +/* + * define macros + */ + +#define TX_BYTE(x) while(!(UART0_LSR&(1<<5))) continue; \ + UART0_THR=x; + +#define SEND_OK TX_BYTE('o'); TX_BYTE('k'); TX_BYTE('\n'); \ + TX_BYTE('\r'); + +/* + * function prototypes + */ + +void mmap_init(u8 memtype); +void uart0_init(void); +void uart0_send_string(char *txbuf); +void uart0_send_char(char send); + +/* + * main function + */ + +int main(void) { + + /* variables */ + + u32 i,addrlen,datalen; + u8 buf[BUFSIZE]; + u32 addr; + u16 *dptr; + u8 cmd; + u8 txrx; + + /* memory mapping of interrupt vectors to static ram */ + + //mmap_init(MMAP_RAM); + + /* uart initialization */ + + //uart0_init(); + + PINSEL0=0x05; // pin select -> tx, rx + UART0_FCR=0x07; // enable fifo + UART0_LCR=0x83; // set dlab + word length + UART0_DLL=0x10; // br: 9600 @ 10/4 mhz + UART0_DLM=0x00; + UART0_LCR=0x03; // unset dlab + + /* external memory init */ + + BCFG0=0x1000FBEF; // no boot[1:0] influence? (thnx colibri) + // BCFG2 should be fine as is + + /* begin the main loop */ + while(1) { + + /* receive cmd */ + while(1) { + + while(!(UART0_LSR&(1<<0))) + continue; + cmd=UART0_RBR; + + if(cmd==CMD_CHIP_ERASE) { +SEND_OK + addrlen=0; + datalen=1; + break; + } + + if(cmd==CMD_READ) { + addrlen=4; + datalen=1; + break; + } + } + + /* receive (only if there is) more data from uart0 */ + + addr=0; + for(i=0;i tx, rx + UART0_FCR=0x07; // enable fifo + UART0_LCR=0x83; // set dlab + word length + UART0_DLL=0x10; // br: 9600 @ 10/4 mhz + UART0_DLM=0x00; + UART0_LCR=0x03; // unset dlab +} + +void uart0_send_string(char *txbuf) { + + int i; + + i=0; + + while(txbuf[i]) + UART0_THR=txbuf[i++]; + UART0_THR='\n'; + UART0_THR='\r'; + + while(!(UART0_LSR&(1<<6))) {} +} + +void uart0_send_char(char send) { + + while(!(UART0_LSR&(1<<5))) + continue; + + UART0_THR=send; +} + -- 2.39.2