[Icc-avr] CRC Check of Program Memory

Roman Rohde rohde at aragon-interactive.de
Tue Oct 16 04:28:22 PDT 2007


> 1.	How do I loop through the program memory?
// Project -> Options... -> Target -> Other Options:
// -bbootsect:0x07000.0x08000    for  BOOTSIZE 2048words @ 0x3800 *
// -bbootsect:0x07800.0x08000    for  BOOTSIZE 1024words @ 0x3C00
// -bbootsect:0x07C00.0x08000    for  BOOTSIZE  512words @ 0x3E00
// -bbootsect:0x07E00.0x08000    for  BOOTSIZE  256words @ 0x3F00
#pragma text:bootsect(abs)
void boot(void) {
	const unsigned int * root;
	register unsigned int sum;
	register unsigned int tmp;
	
	asm(".include \"aiom32.s\"");
	asm("wdr");
	asm("cli");

	// init PORTs
	PORTD = 0x9F;
	DDRD  = 0xFB;
     PORTB = DDRB = PORTC = DDRC = PORTA = DDRA = 0xFF;
	SFIOR = 0x00; // SFIOR &= ~(1<<PUD);		// ensure bit 4 is written to  
zero!!!

	asm("ldi r16,>RAMEND");
	asm("out SPH,r16");
	asm("ldi r16,<RAMEND");
	asm("out SPL,r16");

	root = (unsigned int *)0x0000;
	sum = 0;

	if(*root != 0x940C) {		// if no application is present
		bootload();
		WDTCR = (1<<WDE);	// enable WatchDog to generate a reset
		while(1);
	}

// **********************************************************************
// **********************************************************************
// HERE IS THE LOOP
// **********************************************************************
// **********************************************************************

	while(root < (unsigned int *)(0x43FE)) {
		tmp = *root;
		root++;
		sum = do_crc_calc(sum);
	}

// **********************************************************************
// **********************************************************************

	if(sum ^ *root) {							// if no application is present
		bootload();
		WDTCR = (1<<WDE);						// enable WatchDog to generate a reset
		while(1);
	}


	// Move Interrupts to Application-Section
	GICR = (1<<IVCE);
	GICR = (0<<IVSEL)|(0<<IVCE);
	// Run the Application
	asm("jmp $0");
}


> 2.	How do I store the correct CRC at the end of the Flash memory?

// Project -> Options... -> Target -> Other Options:
// -bchecksum:0x04FFE.0x05000    for  2 Byte checksum
#pragma text:checksum(abs)
	asm(".word 0x753A");
#pragma text:text



More information about the Icc-avr mailing list