holidays ...
authorhackbard <hackbard@hackdaworld.org>
Tue, 28 Aug 2007 17:20:01 +0000 (19:20 +0200)
committerhackbard <hackbard@hackdaworld.org>
Tue, 28 Aug 2007 17:20:01 +0000 (19:20 +0200)
betty/Makefile
betty/fwflash.c

index 4e07f98..8925b22 100644 (file)
@@ -1,13 +1,16 @@
+# 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)
index 8d837e7..e2f78d9 100644 (file)
@@ -9,16 +9,24 @@
  * 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'
@@ -38,10 +46,14 @@ typedef unsigned int u32;
  */
 
 #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
@@ -53,6 +65,12 @@ void uart0_send_string(char *txbuf);
 void uart0_send_char(char send);
 
 /*
+ * global variables
+ */
+
+int scnt;
+
+/*
  * main function
  */
 
@@ -84,8 +102,7 @@ int main(void) {
 
        /* 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) {
@@ -98,7 +115,6 @@ int main(void) {
                cmd=UART0_RBR;
 
                if(cmd==CMD_CHIP_ERASE) {
-SEND_OK
                        addrlen=0;
                        datalen=1;
                        break;
@@ -115,19 +131,20 @@ SEND_OK
 
        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 */
 
@@ -140,29 +157,22 @@ SEND_OK
                        }
                        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;