From: hackbard Date: Sat, 1 Sep 2007 16:30:17 +0000 (+0200) Subject: testing commit X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=5599fd4317d682de1c1268422bff0f474f22d65e;p=my-code%2Farm.git testing commit --- diff --git a/betty/fwflash.c b/betty/fwflash.c index 3023789..b6d48a6 100644 --- a/betty/fwflash.c +++ b/betty/fwflash.c @@ -25,14 +25,21 @@ #define BL_SIZE 0x00002000 /* flash cmd addresses - flash[0-18] <--> arm[1-19]*/ -#define B0F555 (*((volatile unsigned long *)(BANK0|0xaaa))) // 0x555 -#define B0F2AA (*((volatile unsigned long *)(BANK0|0x554))) // 0x2aa -#define B2F555 (*((volatile unsigned long *)(BANK2|0xaaa))) // 0x555 -#define B2F2AA (*((volatile unsigned long *)(BANK2|0x554))) // 0x2aa +#define B0F555 (*((volatile unsigned short *)(BANK0|0xaaa))) // 0x555 +#define B0F2AA (*((volatile unsigned short *)(BANK0|0x554))) // 0x2aa +#define B0F (*((volatile unsigned short *)(BANK0))) +#define B2F555 (*((volatile unsigned short *)(BANK2|0xaaa))) // 0x555 +#define B2F2AA (*((volatile unsigned short *)(BANK2|0x554))) // 0x2aa +#define B2F (*((volatile unsigned short *)(BANK2))) + +#define FLASH0_555 (*((volatile unsigned short *) 0x80000AAA)) +#define FLASH0_2AA (*((volatile unsigned short *) 0x80000554)) +#define FLASH0 (*((volatile unsigned short *) 0x80000000)) /* commands */ #define CMD_READ 'R' #define CMD_CHIP_ERASE 'E' +#define CMD_SECTOR_ERASE 'S' #define CMD_CHIP_ID 'I' #define BUFSIZE 16 @@ -45,6 +52,21 @@ typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; +/* + * sector addresses + */ + +unsigned long sector_address[19]={ + 0x00000,0x02000,0x03000,0x04000,0x08000, + 0x10000,0x18000, + 0x20000,0x28000, + 0x30000,0x38000, + 0x40000,0x48000, + 0x50000,0x58000, + 0x60000,0x68000, + 0x70000,0x78000 +}; + /* * functions */ @@ -57,8 +79,8 @@ void mmap_init(u8 memtype) { void pll_init(void) { /* configuration */ - PLLCFG=0x02; // multiplier = 2 - PLLCON=0x03; // enable and set as clk source for the lpc + PLLCFG=0x42; // multiplier = 3 (for cclk), dividor = 4 (for f_cco) + PLLCON=0x03; // enable and set as clk source for the lpc /* feed sequence */ PLLFEED=0xaa; PLLFEED=0x55; @@ -67,6 +89,65 @@ void pll_init(void) { continue; } +int flash_sector_erase(u8 flash,u8 sector) { + + u32 a18_12; + u32 base; + + if(sector>18) + return -1; + a18_12=sector_address[sector]<<1; + + if((flash!='0')|(flash!='2')) + return -1; + + switch(flash) { + case '0': + base=0x80000000; + B0F555=0xaa; + B0F2AA=0x55; + B0F555=0x80; + B0F555=0xaa; + B0F2AA=0x55; + *((volatile u16 *)(base|a18_12))=0x30; + break; + case '2': + base=0x82000000; + B2F555=0xaa; + B2F2AA=0x55; + B2F555=0x80; + B2F555=0xaa; + B2F2AA=0x55; + *((volatile u16 *)(base|a18_12))=0x30; + break; + default: + return -1; + } + + return 0; +} + +void flash_sector0_erase(void) { + B0F555=0xaa; + B0F2AA=0x55; + B0F555=0x80; + B0F555=0xaa; + B0F2AA=0x55; + *((volatile u16 *)(0x80000000))=0x30; +} + +void flash_chip_erase(void) { + + /* test, erase flash at bank0 */ + + B0F555=0xaa; + B0F2AA=0x55; + B0F555=0x80; + B0F555=0xaa; + B0F2AA=0x55; + B0F555=0x10; +} + void uart0_init(void) { PINSEL0=0x05; // pin select -> tx, rx @@ -181,7 +262,15 @@ int main(void) { uart0_init(); /* external memory init */ - BCFG0=0x1000FBEF; // BCFG2 should be fine as is + BCFG0=0x10000420; + BCFG2=0x10000420; + +FLASH0_555 = 0xAA; +FLASH0_2AA = 0x55; +FLASH0_555 = 0x80; +FLASH0_555 = 0xAA; +FLASH0_2AA = 0x55; +FLASH0 = 0x30; /* begin the main loop */ while(1) { @@ -196,6 +285,10 @@ int main(void) { addrlen=0; datalen=1; break; + case CMD_SECTOR_ERASE: + addrlen=1; + datalen=0; + break; case CMD_READ: addrlen=4; datalen=4; @@ -225,10 +318,15 @@ int main(void) { /* process the cmd */ switch(cmd) { + case CMD_SECTOR_ERASE: + flash_sector0_erase(); + break; case CMD_READ: /* data length to read */ datalen=buf[0]<<24|buf[1]<<16|buf[2]<<8|buf[3]; /* check addr and datalen */ +datalen=0x40; +addr=0x80000000; if((addr>=BANK0)&(addr+datalen<=BANK0+BANK_SIZE)) uart0_send_buf16((u16 *)addr,datalen); if((addr>=BANK2)&(addr+datalen<=BANK2+BANK_SIZE)) @@ -238,12 +336,7 @@ int main(void) { break; case CMD_CHIP_ERASE: if(buf[0]=='0') { - B0F555=0xaa; - B0F2AA=0x55; - B0F555=0x80; - B0F555=0xaa; - B0F2AA=0x55; - B0F555=0x10; + flash_chip_erase(); } else if(buf[0]=='2') { B2F555=0xaa;