]> rtime.felk.cvut.cz Git - sysless.git/commitdiff
Merge branch 'master' of pisa@rtime.felk.cvut.cz:/var/git/sysless-h8300
authorPavel Pisa <pisa@cmp.felk.cvut.cz>
Sun, 26 Apr 2009 22:08:23 +0000 (00:08 +0200)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Sun, 26 Apr 2009 22:08:23 +0000 (00:08 +0200)
.gitignore
app/bloader/Makefile.omk
app/bloader/bloader.c
app/ledblink/Makefile.omk
app/ledblink/ledblink.c
app/ledblink/ledtimer.c
app/tohit/tohit_fn.c
arch/h8300/generic/libs/boot/boot_fn.c
arch/h8300/generic/libs/boot/boot_fn.h

index 2f91861f0561248c6b521fa49909fce01af511d2..c3d05137c42fbbbb9d4812e458fe0a7abb96d534 100644 (file)
@@ -1,4 +1,9 @@
 /_build
 /_compiled
+/config.target
 /config.omk
 /config.omk-default
+cscope.files
+cscope.out
+sources.txt
+TAGS
index 3d387cf9f19280cb13d297463655233645aa243d..b8ef37878dd7fd846ba0d9b113d8cd071608f176 100644 (file)
@@ -6,7 +6,7 @@ bloader_SOURCES = bloader.c
 bloader_LIBS = boot_fn bspbase
 #bloader_MOREOBJS = boot_fn.o
 
-link_VARIANTS = boot ram bload flash
+link_VARIANTS = boot bload
 
 bootstrap: TOHIT=$(USER_COMPILED_DIR_NAME)/bin-utils/tohit -d $(HIT_DEV)
 bootstrap: HIT_BAUD=19200
index 35d6e1cfaf2eb401dae2eb33cec0d5970bc563f3..0d2aa45a423eb1a84ea5e54edd001a13f0811034 100644 (file)
@@ -79,8 +79,9 @@ static void deb_led_out(char val)
 
 #include <boot_fn.h>
 
-char __boot_fn_start;
-char __boot_fn_end;
+/* Provided by linker script */
+extern char __boot_fn_start;
+extern char __boot_fn_end;
 
 void RelocatedProgMode(unsigned long where, unsigned baud)
 { 
@@ -123,8 +124,11 @@ void boot_test()
   }
 
  
-  if((__u8*)&__boot_fn_start<(__u8*)0xffb000)
-    RelocatedProgMode(0xffb000,HIT_LOAD_BAUD);
+  if((__u8*)&__boot_fn_start<(__u8*)0xffb000) {
+         /* If we are not in the internal RAM, copy and run us from
+          * there */
+         RelocatedProgMode(0xffb000,HIT_LOAD_BAUD);
+  }
    else
     ProgMode(HIT_LOAD_BAUD);
 }
@@ -157,7 +161,7 @@ int main()
 {
   __u8 *p;
 
-  _setup_board();
+  _setup_board(); /* Provided in bspbase library of each board */
 
   p=(__u8*)&deb_wr_hex;
   if(p>=IRAM_START) p=" IRAM";
index 92cb6fa760a9c46f71cafa0dd7beeeafd163e833..c324ee564f32acf8f3ac9149c2325fc6205f43d3 100644 (file)
@@ -3,11 +3,7 @@
 bin_PROGRAMS  = ledtimer ledblink
 
 ledblink_SOURCES = ledblink.c 
-ledblink_LIBS = boot_fn
 
 ledtimer_SOURCES = ledtimer.c 
-ledtimer_LIBS = boot_fn excptvec
+ledtimer_LIBS = excptvec
 
-ledblink_LIBS = boot_fn excptvec
-
-link_VARIANTS = ram flash
index dc04707a516bc2477d243f9258c000be3d13af72..507d95d0cb8e1ac3d853350e7e3b9a8858e82e88 100644 (file)
@@ -26,6 +26,16 @@ static void deb_led_out(char val)
     DEB_LED_OFF(3);
 }
 
+void wait(long n)
+{
+  long i=0;
+  volatile long x;
+  while (i<n*2){
+    i++;
+    x+=i;
+  }    
+}
+
 int main()
 {
     DEB_LED_INIT(); /* Init port with LEDs */
@@ -33,6 +43,6 @@ int main()
     while (1) {
         i = (i + 1) & 7;
         deb_led_out(i);
-        FlWait(1*100000);
+        wait(1*100000);
     }
 };
index 61f447d590a883e5262b65c44ede210f8eea5e35..22dbc46af5709693951fde1d0e2c0f4f03ce5419 100644 (file)
@@ -61,6 +61,15 @@ void init_timer1()
     *TPU_TSTR |=TSTR_CST1m;     //start timer
 }
 
+void wait(long n)
+{
+  long i=0;
+  volatile long x;
+  while (i<n*2){
+    i++;
+    x+=i;
+  }    
+}
 
 int main()
 {
@@ -80,12 +89,12 @@ int main()
     init_timer1();
     sti();
 
-    FlWait(1*400000);
+    wait(1*400000);
   
     while (1){
         DEB_LED_ON(0);  // leds blink to show that the main program is still running
-        FlWait(100000);
+        wait(100000);
         DEB_LED_OFF(0);
-        FlWait(100000);
+        wait(100000);
     }
 }
index aefb959ff03d1ed70c9b8e5e139827ad4724af42..1083497d5827522d9d121521489253ab23928088 100644 (file)
@@ -8,6 +8,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include "tohit_fn.h"
+#include <boot_fn.h>
 
 #define DEBUG 0
 #define DEBUG_COUNT 0
@@ -341,6 +342,22 @@ const char *cmd_name[] = {
        [1+TOHIT_RESET] = "RESET"
 };
 
+const char *boot_err[] = {
+       [EBOOT_PROG_FAILURE] = "Flash programming failure (damaged flash?)",
+       [EBOOT_EXT_FLASH_VERIFY] = "External flash verify failed",
+       [EBOOT_FLASH_VERIFY] = "Flash verify failed",
+       [EBOOT_ROW_NOT_ERASED] = "Flash row was not erased",
+       [EBOOT_NO_FWE] = "Flash write not enabled (FWE pin)",
+       [EBOOT_ROW_BEGIN] = "Programming starts in the middle of a row",
+       [EBOOT_BLOCKADDR] = "Wrong flash block start/end address",
+       [EBOOT_BLNUM_HIGH] = "Flash block number to high",
+       [EBOOT_BLNUM_LOW] = "Flash block number to low (negative)",
+       [EBOOT_FLASH_ERROR] = "Flash error indicated",
+       [EBOOT_ERASE_FAILURE] = "Flash erase failure"
+};
+
+#define ARR_SIZE(x) (sizeof(x)/sizeof(x[0]))
+
 
 int tohit_open4cmd(char *sdev, int baud, int cmd)
 {
@@ -390,7 +407,10 @@ int tohit_cmdrepchk(int fd)
     return -6;
   }    
   if (res!=0xAA && res!=0x5a) {
-    printf("Error in end reply (0x%02X)\n",res);
+         int err = (int)(signed char)res;
+         printf("Error in end reply - received 0x%02X == %d (%s)\n",
+                res, err,
+                (err < 0 && -err < ARR_SIZE(boot_err)) ? boot_err[-err] : NULL);
     return -6;
   }
   return 0;
@@ -423,6 +443,12 @@ int tohit_goto(unsigned long adr)
   return 1;
 }
 
+void print_flash_error(int err)
+{
+  printf("Flash error: %s\n",
+        (err >= 0 && err < ARR_SIZE(boot_err)) ? boot_err[err] : "unknown error");
+}
+
 int tohit_writemem(int cmd, const unsigned char *buf, 
                   unsigned long adr, unsigned long size, int blockmode)
 {
@@ -473,7 +499,11 @@ int tohit_writemem(int cmd, const unsigned char *buf,
       rs232_test(fd,500000);
       c=rs232_recch(fd);
       if (c!=buf[i]) {
-       printf("Error in data reply\n");
+       if (i % FLASH_ROW == FLASH_ROW-1) {
+         print_flash_error(rbuf[i]);
+       } else {
+         printf("Error in data reply (expected 0x%02x, received 0x%02x)\n", buf[i], c);
+       }
         close(fd);
        return -5;
       }        
@@ -499,6 +529,7 @@ int tohit_writemem(int cmd, const unsigned char *buf,
         k=write(fd, buf+i+j, count-j);
        j+=k;
        if((k<=0)||(j>count)){
+         perror("write");
           printf("Error in blk write (%d,%d)\n",j,k);
           close(fd);
          return -2;
@@ -508,11 +539,17 @@ int tohit_writemem(int cmd, const unsigned char *buf,
       verbose(3, " reading %d bytes\n",count);
       j=0;
       do{
-       rs232_test(fd,500000);
+       if ((i+j) % FLASH_ROW == FLASH_ROW - 1) {
+         verbose(3, " waiting for flashing a row\n");
+         rs232_test(fd,2/*sec*/*1000000);
+       } else {
+         rs232_test(fd,500000);
+       }
        k=read(fd, rbuf+j, count-j);
-       if(k>=0) j+=k;
-       if(k<0)
-       {
+       if(k>=0) {
+         j+=k;
+       } else {
+         perror("read");
           printf("Error in blk write - no reply (%d,%d)\n",j,k);
           close(fd);
          return -2;
@@ -524,16 +561,20 @@ int tohit_writemem(int cmd, const unsigned char *buf,
       }
       for(j=0;j<count;j++){
        if (rbuf[j]!=buf[i+j]) {
-          printf("Error in data reply at position %d\n", j);
-
-         printf("Sent:    ");
-         for (k=j; k < count && k < j+8; k++)
-                 printf(" 0x%02x", rbuf[j+k]);
-         printf("\nReceived:");
-         for (k=j; k < count && k < j+8; k++)
-                 printf(" 0x%02x", buf[i+j+k]);
-         printf("\n");
-          close(fd);
+         if (i+j % FLASH_ROW == FLASH_ROW-1) {
+           print_flash_error(rbuf[j]);
+         } else {
+           printf("Error in data reply at position %d\n", j);
+
+           printf("Sent:    ");
+           for (k=j; k < count && k < j+8; k++)
+             printf(" 0x%02x", rbuf[j+k]);
+           printf("\nReceived:");
+           for (k=j; k < count && k < j+8; k++)
+             printf(" 0x%02x", buf[i+j+k]);
+           printf("\n");
+         }
+         close(fd);
          return -5;
        }       
       }
index 71507f1c9c320c90f13f02628cc753e66fc434cd..3127f98072811541cef7602086ec2410353edc88 100644 (file)
@@ -91,7 +91,7 @@ __asm__ (
 ".global _FlWait\n"
 "_FlWait:\n"
 #if (CPU_SYS_HZ>16000000)
-"      shll.l  er0"
+"      shll.l  er0\n"
 #endif
 "      mov.w   #1,r1\n"
 "      bra     2f:8\n"
@@ -148,12 +148,12 @@ int FlTest(int bl)
 int FlErase(int bl)
 {
   int n=100; /*N*/
-  if(bl>=flash_block_count) return -4;
-  if(bl<0) return -5;
+  if(bl>=flash_block_count) return -EBOOT_BLNUM_HIGH;
+  if(bl<0) return -EBOOT_BLNUM_LOW;
 
   if(FlTest(bl)==0) return 0;
 
-  if((*FLM_FLMCR1 & FLMCR1_FWEm)==0) return -1;
+  if((*FLM_FLMCR1 & FLMCR1_FWEm)==0) return -EBOOT_NO_FWE;
 
   *FLM_FLMCR1=FLMCR1_SWE1m;
   FlWait(1);           /*x*/
@@ -191,11 +191,11 @@ int FlErase(int bl)
   }
   *FLM_FLMCR1=0;
   FlWait(100);                 /*x1*/
-  return -2;
+  return -EBOOT_ERASE_FAILURE;
   
  fls_error:
   *FLM_FLMCR1=0;
-  return -3;
+  return -EBOOT_FLASH_ERROR;
 }
 
 void FlProgPulse(int time_zx)
@@ -221,8 +221,8 @@ int FlProgRow(__u8 *adr, __u8 *data)
   int n;
   __u8 *x;
   __u8 c,d;
-  if((unsigned long)adr & (FLASH_ROW-1)) return -6;
-  if((*FLM_FLMCR1 & FLMCR1_FWEm)==0 ) return -5;
+  if((unsigned long)adr & (FLASH_ROW-1)) return -EBOOT_ROW_BEGIN;
+  if((*FLM_FLMCR1 & FLMCR1_FWEm)==0 ) return -EBOOT_NO_FWE;
  #ifdef WITH_EXTERNAL_FLASH
   if(((__u32)adr>=EXTERNAL_FLASH_START)&&
      ((__u32)adr<=EXTERNAL_FLASH_END)){
@@ -232,7 +232,7 @@ int FlProgRow(__u8 *adr, __u8 *data)
 
   x=adr;
   for(i=FLASH_ROW;i--;x++){
-    if(*x!=0xff) return -4;
+    if(*x!=0xff) return -EBOOT_ROW_NOT_ERASED;
   }
   x=data;
   for(i=0;i<FLASH_ROW;i++,x++) prog_data[i]=*x;
@@ -250,6 +250,7 @@ int FlProgRow(__u8 *adr, __u8 *data)
     
     FlProgPulse(n>6?150:25);   /*z0<30 or z2<200 if n>N1*/
 
+    /* Program-Verify Mode */
     *FLM_FLMCR1|=FLMCR1_PV1m;
     FlWait(4);                 /*gamma*/
     i=0;
@@ -268,7 +269,7 @@ int FlProgRow(__u8 *adr, __u8 *data)
        d=data[i];
        if((~c&d)&0xff) goto fls_error;
        if(c!=d) {
-         m=1;
+         m=1;       /* Reprogram needed */
           /* DEB_BLOG(0xEE000000+(long)x); */
           /* DEB_BLOG(0xEF000000+(__u16)(c<<8)+(__u8)d); */
        }
@@ -282,7 +283,7 @@ int FlProgRow(__u8 *adr, __u8 *data)
       for(i=0;i<FLASH_ROW;i++){
         c=prog_data[i]; 
        d=data[i];
-       if(c!=d) m=1;
+       if(c!=d) m=1; /* Reprogram needed */
        if((~c&d)&0xff) goto fls_error;
        prog_data[i]=d|~c;
       }
@@ -296,11 +297,11 @@ int FlProgRow(__u8 *adr, __u8 *data)
   }
   *FLM_FLMCR1=0;
   FlWait(100);                 /*x1*/
-  return -1;
+  return -EBOOT_PROG_FAILURE;
 
  fls_error:
   *FLM_FLMCR1=0;
-  return -3;
+  return -EBOOT_FLASH_VERIFY;
 }
 
 int FlPrepBlk(unsigned long badr, unsigned long len)
@@ -308,7 +309,7 @@ int FlPrepBlk(unsigned long badr, unsigned long len)
   int bl, blend, res;
   bl=FlAdr2Blk(badr);
   blend=FlAdr2Blk(badr+len-1);
-  if((bl<0)||(blend<0)) return -8;
+  if((bl<0)||(blend<0)) return -EBOOT_BLOCKADDR;
   for(;bl<=blend;bl++){
     if(FlTest(bl)){
       res=FlErase(bl);
@@ -521,7 +522,7 @@ int ExtFlProgRow(__u8 *addr, __u8 *data)
     /* reset */
     FLASH_WR16(a,EXTFL_cmd_reset);
     FlWait(2);
-    if(FLASH_RD16(addr)!=val) return -3;
+    if(FLASH_RD16(addr)!=val) return -EBOOT_EXT_FLASH_VERIFY;
     ((__u16*)addr)++;
   }
   return 0;
index 1f1949d02ded0869554d648430e42c755068f4f7..036d066c50259c6fa075945a04bdf7e6fb82f56f 100644 (file)
@@ -1,8 +1,24 @@
 #ifndef _boot_fn_H
 #define _boot_fn_H
 
+#include <types.h>
+
+/* Size of a flash row */
 #define FLASH_ROW 128
 
+/* Error codes (returned as negative numbers) */
+#define EBOOT_PROG_FAILURE     1
+#define EBOOT_EXT_FLASH_VERIFY 2
+#define EBOOT_FLASH_VERIFY     3
+#define EBOOT_ROW_NOT_ERASED   4
+#define EBOOT_NO_FWE           5
+#define EBOOT_ROW_BEGIN                6
+#define EBOOT_BLOCKADDR                8
+#define EBOOT_BLNUM_HIGH       9
+#define EBOOT_BLNUM_LOW                10
+#define EBOOT_FLASH_ERROR      11
+#define EBOOT_ERASE_FAILURE    12
+
 volatile void FlWait(long n);
 void wdg_enable(int psel);
 void wdg_disable();