bullshit commit, sync for travel (to zn00H!) :)
[my-code/arm.git] / betty / fwbc.c
index 9682ee8..1874819 100644 (file)
 #define MMAP_RAM               0x02
 #define MMAP_EXT               0x03
 
+/* band 0/2 & bootloader addr */
+#define BANK0                  0x80000000
+#define BANK2                  0x82000000
+#define BOOTLOADER             0x7fffe000
+
 /*
  * type definitions
  */
 
 typedef unsigned char u8;
+typedef unsigned short u16;
 typedef unsigned int u32;
 
 /*
@@ -49,29 +55,89 @@ void uart0_send_char(char send);
 
 int main(void) {
 
+       /* variables */
+
+       u16 *mem=0;
+       u32 *bl=0;
+       u32 i,len;
+       u8 start;
+
        /* memory mapping of interrupt vectors to static ram */
 
        //mmap_init(MMAP_RAM);
 
        /* uart initialization */
 
-#ifdef USE_FUNCTIONS
        //uart0_init();
-#else
+
        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
-#endif
 
        /* external memory init */
 
+       BCFG0=0x1000FBEF;               // no boot[1:0] influence? (thnx colibri)
+                                       // BCFG2 should be fine as is
+
+       while(1) {
+
+       /* wait for fwdump to send transmit start character */
+       start=0x23;
        while(1) {
+               while(!(UART0_LSR&(1<<0)))
+                       continue;
+               start=UART0_RBR;
+               if(start=='0') {
+                       mem=(u16 *)BANK0;
+                       len=0x80000;
+                       break;
+               }
+               if(start=='2') {
+                       mem=(u16 *)BANK2;
+                       len=0x80000;
+                       break;
+               }
+               if(start=='b') {
+                       BCFG0=0x1000FBEF;       // 32 bit width
+                       bl=(u32 *)BOOTLOADER;
+                       len=0x800;
+                       break;
+               }
+       }
+
+       /* transmit 1 mb of data */
+       for(i=0;i<len;i++) {                    // care for endianness
+
+               while(!(UART0_LSR&(1<<5)))
+                       continue;
+               if(start=='b')
+                       UART0_THR=(*bl&0xff);
+               else
+                       UART0_THR=(*mem&0xff);
+
                while(!(UART0_LSR&(1<<5)))
                        continue;
-               UART0_THR=0x23;
+               if(start=='b')
+                       UART0_THR=((*bl&0xff00)>>8);
+               else {
+                       UART0_THR=((*mem&0xff00)>>8);
+                       mem++;
+               }
+
+               if(start=='b') {
+                       while(!(UART0_LSR&(1<<5)))
+                               continue;
+                       UART0_THR=((*bl&0xff0000)>>16);
+                       while(!(UART0_LSR&(1<<5)))
+                               continue;
+                       UART0_THR=((*bl&0xff000000)>>24);
+                       bl++;
+               }
+       }
+
        }
 
        return 0;