Esempio n. 1
0
int main( void )
{
	volatile unsigned long ul;

	// Initialize address and notify host
  	pCurrent = (u08*)vStart;
  	u32 kopycounter=0;

	prvSetupHardware( );

    // Version Controll
    debug_msg( "NowBoot V1.2; Compiled at: "__DATE__" "__TIME__"\r");
	wait_ms(1000);
    debug_msg("NowBoot: Running drives and filesystem.");
    StorageInit();
	wait_ms(100);
    debug_msg("NowBoot: Checking for new firmware...");
    //f_rename ( "1:fmw/fmw_n.old", "fmw/fmw_n.bin" );	//For tests only
	res = f_open(&firmwarefile, "1:fmw/fmw_n.bin", FA_OPEN_EXISTING | FA_READ);
	if(res != FR_OK){
		f_close(&firmwarefile);
    	debug_msg("NowBoot: Can`t find new firmware.");
        debug_msg("NowBoot: Checking for in-flash firmware");
        if((*((u08*)vStart+4)==0xFF)&&(*((u08*)(vStart+5))==0xff)){
        	debug_msg("NowBoot: Flash is empty!");
        	debug_msg("NowBoot: Opening default firmware!");
        	res = f_open(&firmwarefile, "1:fmw/fmw_0.bin", FA_OPEN_EXISTING | FA_READ);
        	if(res != FR_OK){
        		f_close(&firmwarefile);
            	debug_msg("NowBoot: Can`t find any firmware file... Nothing to do.");
            	for(;;)AT91C_BASE_SYS->WDTC_WDCR = 0xA5000001;	//endless loop
        	}
        	goto fmw_prog;
        }
        else{
        	debug_msg("NowBoot: Flash contain firmware.");
        	goto app_now;
        }
	}else{
    	debug_msg("NowBoot: Found new firmware.");
    	fmw_prog:
    	debug_msg("NowBoot: Start programming...");
		wait_ms(300);
		debug_txt("\rCopying page: ");
		for (;;) {
			debug_txt("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bKopiuje strone: "); debug32_tdec(kopycounter++);
        	res = f_read(&firmwarefile, page, sizeof(page), &br);    /* Read a chunk of src file */
        	if (res || br == 0) {
        		wait_ms(100);
        		debug_msg("NowBoot: Copying finshed.");
        		break; /* error or eof */
        	}
        	//memset(page,0xff,sizeof(page));		//for tests only
        	flash_write(pCurrent , (void *) page );
        	pCurrent+= MEMORY_PAGE_SIZE;
    	}

	}
	f_close(&firmwarefile);

/*
    TO DO:
		MD5 verification
*/


    wait_ms(300);
    debug_msg("NowBoot: Firmware upgrade successful.");
    debug_msg("NowBoot: Removing firmware file.");
    f_unlink ( "1:fmw/fmw_n.old" );	//removeing old firmware
    f_rename ( "1:fmw/fmw_n.bin", "fmw/fmw_n.old" );

app_now:
	wait_ms(100);
    debug_msg("NowBoot: End of Boot.");
    spiInit();
    wait_ms(1000);
    AT91C_BASE_SYS->WDTC_WDCR = 0xA5000001;	//WDT restart
    asm volatile(
    	"LDR pc, =0x00108000"		//Jump to firmware start
    );
    debug_msg("NowBoot: Something bad happened! I should never be here.");
    wait_ms(100);
	vPortSoftReset();

  	return 0;
}
Esempio n. 2
0
//prints text starting at str
//adds new line first
void debug_msg(char *str)
{
	debug_chr('\r');
	debug_chr('\n');
	debug_txt(str);
}