Hi,
there was a very good basic introduction from Rudy posted to the list
on July 28, please check the archive.
Rudy alos provided a first stage bootloader later on. Can be found in the
archives, too.
Attached is a very crude little (Windows) program which implements a UART
boot. Requires Rudy's first stage loader. Don't view this as a real
program but more as a proof of function.
Ciao,
Peter
On Wed, 20 Dec 2006, Uday Bhide wrote:
> Hi all,
>
> I've just started working on the DaVinci EVM board
> and I'm new to this mailing list too.
> I read through a lot of mails from the mailing list but
> could not get to the basics of what I need to know now.
>
> I need to utilize the UART boot to load a file to boot
> the DSP.
>
> When I switch to the UART Boot mode and switch on
> the board, the only thing I see on the minicom console
> is "BOOTME BOOTME..." repeatedly.
>
> How do I start the UART communication? How to send
> ACK to the RBL in the first hand? And what next?
>
> Can anybody who has a fair knowledge of the procedure
> please send me the steps?
> Also, please send any scripts or applications that can do
> the necessary communication to send the UBL to the RAM.
>
>
> Thanking you in advance,
> Uday.
>
| Peter Wippich Voice: +49 30 46776411 |
| G&W Instruments GmbH fax: +49 30 46776419 |
| Gustav-Meyer-Allee 25, Geb. 12 Email: [EMAIL PROTECTED] |
| D-13355 Berlin / Germany |
//-----------------------------------------------------------------------------
// File load.c
// Load UBL to davinci over UART
// Win32 console application
// (c) 2005 G&W Instruments
//-----------------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include <time.h>
#define MAX_UBL_SIZE (14*1024)
static HANDLE DevHandle = INVALID_HANDLE_VALUE ;
//---------------------------------------------------------------------------
int OpenCom(int portnum)
{
char portname[12] ; // 10 shall do ...
const int RxQueueSize=4*1024;
const int TxQueueSize=4*1024;
int NumWritten ;
DCB dcb;
COMMTIMEOUTS ComTimeouts ;
memset(portname, 0, 12) ;
sprintf(portname,"\\\\.\\COM%d",portnum) ;
// open Port
DevHandle = CreateFile(portname,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if (DevHandle==INVALID_HANDLE_VALUE) {
printf("CreateFile for %s failed %d\n", portname, GetLastError());
return 0;
}
if (!SetupComm(DevHandle, RxQueueSize, TxQueueSize)) {
printf("SetupComm failed %d\n", GetLastError());
CloseHandle(DevHandle);
DevHandle = INVALID_HANDLE_VALUE ;
return 0;
}
memset(&dcb, 0, sizeof(dcb));
dcb.DCBlength = sizeof(DCB);
if (!GetCommState(DevHandle, &dcb)) {
printf("GetCommState failed %d\n", GetLastError());
CloseHandle(DevHandle);
DevHandle = INVALID_HANDLE_VALUE ;
return 0;
}
dcb.DCBlength = sizeof(DCB);
dcb.BaudRate = 115200; /* Baudrate */
dcb.fBinary = 1 ;
dcb.fParity = 0; /* Disable parity checking
*/
dcb.fOutxCtsFlow = 0 ; /* CTS handshaking on output
*/
dcb.fOutxDsrFlow = 0; /* no SR handshaking on
output */
dcb.fDtrControl = DTR_CONTROL_DISABLE; /* DTR off control
*/
dcb.fOutX = 0; /* Disable output X-ON/X-OFF
*/
dcb.fInX = 0; /* Disable input X-ON/X-OFF
*/
dcb.fErrorChar = 0 ; // do not replace witherror char
dcb.fNull = 0; /* Enable Null stripping
*/
dcb.fRtsControl = RTS_CONTROL_DISABLE; // RTS off
dcb.fAbortOnError = 0 ;
dcb.XonLim = 500 ;
dcb.XoffLim = RxQueueSize * 80 / 100;
dcb.Parity = NOPARITY; /* 0-4=None,Odd,Even,Mark,Space */
dcb.ByteSize = 8; /* Number of bits/byte, 4-8 */
dcb.StopBits = ONESTOPBIT; /* 0,1,2 = 1, 1.5, 2 */
dcb.XonChar = 0x11; /* Tx and Rx X-ON character */
dcb.XoffChar = 0x13; /* Tx and Rx X-OFF character */
#if 0
DWORD fDsrSensitivity:1; /* DSR Sensitivity */
DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */
WORD wReserved; /* Not currently used */
char ErrorChar; /* Error replacement char */
char EofChar; /* End of Input character */
char EvtChar; /* Received Event character */
#endif
if (!SetCommState(DevHandle, &dcb)) {
printf("SetCommState failed %d\n", GetLastError());
CloseHandle(DevHandle);
DevHandle = INVALID_HANDLE_VALUE ;
return 0;
}
ComTimeouts.ReadIntervalTimeout = 1000 ;
ComTimeouts.ReadTotalTimeoutMultiplier = 500 ;
ComTimeouts.ReadTotalTimeoutConstant = 1000 ;
ComTimeouts.WriteTotalTimeoutMultiplier = 500 ;
ComTimeouts.WriteTotalTimeoutConstant = 1000;
SetCommTimeouts(DevHandle, &ComTimeouts) ;
PurgeComm(DevHandle,PURGE_RXABORT | PURGE_RXCLEAR | PURGE_TXABORT |
PURGE_TXCLEAR);
#if 0
// Set timeouts to something which gives us not to slow response
// when waiting for events
ComTimeouts.ReadIntervalTimeout = 50 ;
ComTimeouts.ReadTotalTimeoutMultiplier = 10 ;
ComTimeouts.ReadTotalTimeoutConstant = 100 ;
ComTimeouts.WriteTotalTimeoutMultiplier = 500 ;
ComTimeouts.WriteTotalTimeoutConstant = 1000;
SetCommTimeouts(DevHandle, &ComTimeouts) ;
#endif
return 1 ;
}
//---------------------------------------------------------------------------
void CloseCom(void)
{
if(DevHandle != INVALID_HANDLE_VALUE)
{
PurgeComm(DevHandle,PURGE_RXABORT | PURGE_RXCLEAR | PURGE_TXABORT |
PURGE_TXCLEAR);
CloseHandle(DevHandle);
DevHandle = INVALID_HANDLE_VALUE ;
}
}
//---------------------------------------------------------------------------
/*---------------------------------------------------------------------------
Wait for (partial) string with timeout (in milliseconds)
----------------------------------------------------------------------------*/
int WaitFor(char * wstring, int timeout)
{
char c ;
int cmplen = strlen(wstring) ;
int nmatch = 0;
unsigned long timeout_ticks ;
int nread = 0;
clock_t stop ;
timeout_ticks = (CLOCKS_PER_SEC * (unsigned long) timeout) ;
timeout_ticks += 500 ; // round up
timeout_ticks /= 1000 ; // scale for CPS
stop = clock() + (clock_t)timeout_ticks ;
while(stop > clock())
{
if(!ReadFile(DevHandle, &c, 1, &nread, 0))
{
printf("Read Failed %d\n", GetLastError() ) ;
nread = 0 ;
}
if(nread)
{
printf("%c",c) ;
if(c == wstring[nmatch])
{
nmatch++ ;
if(nmatch == cmplen) return 1 ;
}
else
{
nmatch = 0 ;
}
}
}
return 0 ;
}
//---------------------------------------------------------------------------
static void print_usage(char *pgm)
{
printf("Usage:\n");
printf("%s [file to load] [portnum]\n", pgm) ;
}
//---------------------------------------------------------------------------
//test only
int main(int argc, char ** argv)
{
unsigned long baudrate = 115200 ;
DCB dcb;
char ch ;
FILE * file ;
unsigned char *buf, *loc ;
int numread, numwritten ;
int i ;
char txbuf[1024] ;
long uboot_size ;
if(argc =! 3) {
print_usage(argv[0]) ;
exit(1) ;
}
if( !OpenCom(atoi(argv[2])) ){
printf("failed to open com%s\n", argv[2]) ;
exit(1) ;
}
file = fopen(argv[1],"rb") ;
if(!file) {
printf("failed to open %s\n", argv[1] ) ;
CloseCom() ;
exit(1) ;
}
buf = malloc(MAX_UBL_SIZE) ;
if(!buf) {
printf("failed to allocate buffer\n") ;
fclose(file) ;
CloseCom() ;
exit(1) ;
}
numread = fread(buf, 1, MAX_UBL_SIZE, file) ;
printf("read %d bytes from %s\n", numread, argv[1]) ;
fclose(file) ;
if(!numread) {
printf("nothing read, exiting\n") ;
free(buf) ;
CloseCom() ;
exit(1) ;
}
printf("Waiting for boot message from Davinci\n") ;
while(1) {
printf(".") ;
if( WaitFor(" BOOTME\0", 5000) ) break ;
if(kbhit()) {
ch = getch() ;
if(ch == 0x1b) {
printf("aborted\n") ;
CloseCom() ;
free(buf) ;
exit(0) ;
}
}
}
printf("\nsending ACK\n") ;
memset(txbuf, 0, 8) ;
sprintf(txbuf," ACK") ;
WriteFile(DevHandle, txbuf, 8, &numwritten, 0) ;
memset(txbuf, 0, 20) ;
sprintf(txbuf,"00000000%.4x%.4x0000", numread - (8*4), 0x100) ;
WriteFile(DevHandle, txbuf, 20, &numwritten, 0) ;
printf("Waiting for begin message from Davinci\n") ;
if( ! WaitFor(" BEGIN\0", 5000) ) {
printf("timed out\n") ;
CloseCom() ;
free(buf) ;
exit(1) ;
}
printf("sending empty CRC table\n") ;
memset(txbuf, 0, 8) ;
sprintf(txbuf,"00000000") ;
for(i=0; i<256 ; i++) WriteFile(DevHandle, txbuf, 8, &numwritten, 0) ;
printf("Waiting for done message from Davinci\n") ;
if( ! WaitFor(" DONE\0", 5000) ) {
printf("timed out\n") ;
free(buf) ;
CloseCom() ;
exit(1) ;
}
printf("Sending data\n") ;
for(i=8*4 ; i<numread ; i+=4)
{
// XXXX assumes LE machine !!
unsigned long *p = (unsigned long *)&buf[i];
sprintf(txbuf,"%.8x",*p) ;
WriteFile(DevHandle, txbuf, 8, &numwritten, 0) ;
}
free(buf) ;
printf("Waiting for done message from Davinci\n") ;
if( ! WaitFor(" DONE\0", 5000) ) {
printf("timed out\n") ;
CloseCom() ;
exit(1) ;
}
printf("Waiting for UBL message from Davinci\n") ;
if( ! WaitFor("Rboot->", 5000) ) {
printf("timed out\n") ;
CloseCom() ;
exit(1) ;
}
// load uboot to ram at 0x81080000, default textbase
// see u-boot config
// XXXX : hardwired
file = fopen("u-boot_ram.bin","rb") ;
if(!file) {
printf("u-boot not found\n") ;
CloseCom() ;
exit(1) ;
}
fseek(file, 0, SEEK_END) ;
uboot_size = ftell(file) ;
printf("uboot size is %d bytes\n", uboot_size) ;
fseek(file, 0, SEEK_SET) ;
txbuf[0] = 'l' ;
txbuf[1] = 0 ;
txbuf[2] = 0 ;
txbuf[3] = 0x08 ;
txbuf[4] = 0x81 ;
txbuf[5] = uboot_size & 0xff ;
txbuf[6] = (uboot_size >> 8) & 0xff ;
txbuf[7] = (uboot_size >> 16) & 0xff ;
txbuf[8] = (uboot_size >> 24) & 0xff ;
WriteFile(DevHandle, txbuf, 9, &numwritten, 0) ;
for(i=0 ; i<uboot_size ; i+=1024)
{
printf("*") ;
numread = fread(txbuf, 1, 1024, file) ;
WriteFile(DevHandle, txbuf, numread, &numwritten, 0) ;
}
fclose(file) ;
printf("\n") ;
if( ! WaitFor("Rboot->", 5000) ) {
printf("timed out\n") ;
CloseCom() ;
exit(1) ;
}
// start uboot at 0x81080000
txbuf[0] = 'g' ;
txbuf[1] = 0 ;
txbuf[2] = 0 ;
txbuf[3] = 0x08 ;
txbuf[4] = 0x81 ;
WriteFile(DevHandle, txbuf, 5, &numwritten, 0) ;
WaitFor("autoboot:", 5000) ;
WriteFile(DevHandle, "\r", 1, &numwritten, 0) ;
CloseCom();
}
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source