+# native builds
CC = gcc
CFLAGS = -Wall
-ARMCC = /scratch/arm-elf/bin/arm-elf-gcc
-ARMCFLAGS = -Wall -mcpu=arm7tdmi-s -nostartfiles -nostdlib
-ARMOBJCOPY = /scratch/arm-elf/bin/arm-elf-objcopy
+# cross build
+ARCH = arm-elf
+CROSS_CC = $(ARCH)-gcc
+CROSS_OBJCOPY = $(ARCH)-objcopy
+CROSS_CFLAGS = -Wall -Os -mcpu=arm7tdmi-s -nostartfiles -nostdlib
-HOSTOBJECTS = lpcload fwdump
-
-ARMOBJECTS = fwbc.hex fwflash.hex
+# build objects
+HOST_TARGET = lpcload fwdump
+CROSS_TARGET = fwbc.hex fwflash.hex
# all projects
all: $(HOSTOBJECTS) $(ARMOBJECTS)
* include files
*/
+#include <stdio.h>
+
#include "lpc2xxx.h"
/*
* defines
*/
-/* band 0/2 addr */
+/* bank 0/2 addr */
#define BANK0 0x80000000
#define BANK2 0x82000000
+/* flash cmd addresses */
+#define B0F555 (*((volatile unsigned long *)(BANK0|0x555)))
+#define B0F2AA (*((volatile unsigned long *)(BANK0|0x2aa)))
+#define B2F555 (*((volatile unsigned long *)(BANK2|0x555)))
+#define B2F2AA (*((volatile unsigned long *)(BANK2|0x2aa)))
+
/* commands */
#define CMD_READ 'R'
#define CMD_CHIP_ERASE 'E'
*/
#define TX_BYTE(x) while(!(UART0_LSR&(1<<5))) continue; \
- UART0_THR=x;
+ UART0_THR=x
+
+#define TX_NL TX_BYTE('\n'); TX_BYTE('\r')
-#define SEND_OK TX_BYTE('o'); TX_BYTE('k'); TX_BYTE('\n'); \
- TX_BYTE('\r');
+#define TX_STRING(x,len) for(scnt=0;scnt<len;scnt++) { \
+ TX_BYTE(x[scnt]); \
+ } \
+ TX_NL
/*
* function prototypes
void uart0_send_string(char *txbuf);
void uart0_send_char(char send);
+/*
+ * global variables
+ */
+
+int scnt;
+
/*
* main function
*/
/* external memory init */
- BCFG0=0x1000FBEF; // no boot[1:0] influence? (thnx colibri)
- // BCFG2 should be fine as is
+ BCFG0=0x1000FBEF; // BCFG2 should be fine as is
/* begin the main loop */
while(1) {
cmd=UART0_RBR;
if(cmd==CMD_CHIP_ERASE) {
-SEND_OK
addrlen=0;
datalen=1;
break;
addr=0;
for(i=0;i<addrlen;i++) {
+ //TX_STRING("got addr",8);
while(!(UART0_LSR&(1<<0)))
continue;
txrx=UART0_RBR;
- addr|=(txrx<<(i*4));
+ //addr|=(txrx<<((addrlen-i-1)*4));
+ addr=0x80000000;
}
-SEND_OK
for(i=0;i<datalen;i++) {
+ //TX_STRING("got data",8);
while(!(UART0_LSR&(1<<0)))
continue;
- buf[i++]=UART0_RBR;
+ buf[i]=UART0_RBR;
}
-SEND_OK
/* process the cmd */
}
break;
case CMD_CHIP_ERASE:
- if(buf[0]=='0')
- addr=BANK0;
- else if(buf[0]=='2')
- addr=BANK2;
- else
- break;
- // cycle 1
- dptr=(u16 *)(addr|0x555);
- *dptr=0xaa;
- // cycle 2
- dptr=(u16 *)(addr|0x2aa);
- *dptr=0x55;
- // cycle 3+4
- dptr=(u16 *)(addr|0x555);
- *dptr=0x80;
- *dptr=0xaa;
- // cycle 5
- dptr=(u16 *)(addr|0x2aa);
- *dptr=0x55;
- // cycle 6
- dptr=(u16 *)(addr|0x555);
- *dptr=0x10;
-SEND_OK
+ if(buf[0]=='0') {
+ B0F555=0xaa;
+ B0F2AA=0x55;
+ B0F555=0x80;
+ B0F555=0xaa;
+ B0F2AA=0x55;
+ B0F555=0x10;
+ }
+ else if(buf[0]=='2') {
+ B2F555=0xaa;
+ B2F2AA=0x55;
+ B2F555=0x80;
+ B2F555=0xaa;
+ B2F2AA=0x55;
+ B2F555=0x10;
+ }
break;
default:
break;