/_build
/_compiled
+/config.target
/config.omk
/config.omk-default
+cscope.files
+cscope.out
+sources.txt
+TAGS
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
#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)
{
}
- 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);
}
{
__u8 *p;
- _setup_board();
+ _setup_board(); /* Provided in bspbase library of each board */
p=(__u8*)&deb_wr_hex;
if(p>=IRAM_START) p=" IRAM";
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
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 */
while (1) {
i = (i + 1) & 7;
deb_led_out(i);
- FlWait(1*100000);
+ wait(1*100000);
}
};
*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()
{
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);
}
}
#include <unistd.h>
#include <fcntl.h>
#include "tohit_fn.h"
+#include <boot_fn.h>
#define DEBUG 0
#define DEBUG_COUNT 0
[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)
{
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;
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)
{
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;
}
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;
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;
}
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;
}
}
".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"
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*/
}
*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)
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)){
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;
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;
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); */
}
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;
}
}
*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)
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);
/* 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;
#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();