#include "flasher.h" #include "dm644x.h" #include "uart.h" #include "util.h" #include "nor.h" extern uint32_t ret_code; extern NOR_INFO gNorInfo; void UART_Boot( void ) { UART_ACK_HEADER ackHeader; uint32_t bootCmd; UART_tryAgain: bootCmd = 0; waitloop( 1000000 ); /* FLASHER Sends 'FLASHME/0' */ if( UARTSendData( (uint8_t*)"FLASHME", TRUE ) != E_PASS ) goto UART_tryAgain; /* Get the BOOT command */ if( UARTGetCMD( &bootCmd ) != E_PASS ) goto UART_tryAgain; switch( bootCmd ) { case FLASHER_MAGIC_NOR_RESTORE: { /* Get the APP (should be u-boot) into binary form */ if( UARTSendData( (uint8_t*)"SENDAPP", TRUE ) != E_PASS ) goto UART_tryAgain; if( UARTGetHeaderAndData( &ackHeader ) != E_PASS ) goto UART_tryAgain; waitloop( 100000 ); /* Initialize the NOR Flash */ if( NOR_Init() != E_PASS ) goto UART_tryAgain; /* Erasing the Flash */ if( NOR_Erase( ackHeader.start_addr, ackHeader.size ) != E_PASS ) goto UART_tryAgain; /* Write the actual application to the flash */ if( NOR_WriteBytes( ackHeader.start_addr, ackHeader.size, ackHeader.ddr_mem ) != E_PASS ) goto UART_tryAgain; /* Now check CRC32 in NOR Flash */ { uint8_t *nor = (uint8_t *)ackHeader.start_addr; uint32_t crc32 = 0; /* Now check CRC32 in DDR2 */ if( get_crc32( &crc32, nor, (int)ackHeader.size ) != 1 ) { UARTSendData( (uint8_t *)" ECRC32", TRUE ); ret_code = 0; break; } if( crc32 != ackHeader.crc32 ) { UARTSendData( (uint8_t *)" ECRC32", TRUE ); ret_code = 0; break; } } ret_code = 1; break; } case FLASHER_MAGIC_NOR_GLOBAL_ERASE: { /* Initialize the NOR Flash */ NOR_Init(); /* Erasing the Flash */ if( NOR_GlobalErase() != E_PASS ) { UARTSendData( (uint8_t *)" EERASE", TRUE ); goto UART_tryAgain; } ret_code = 1; break; } default: goto UART_tryAgain; break; } /* end switch statement */ }