⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 download.c

📁 AT91所有开发板的资料 AT91所有开发板的资料
💻 C
字号:
/* -*-C-*- * * $Revision: 1.2 $ *   $Author: mechavar $ *     $Date: 2000/05/01 19:37:08 $ * * Copyright (c) 2000 ARM, INC. * All Rights Reserved. * *   Project: BootStrap Loader * *   Flash C level routines */#include <string.h>#include "swis.h"#include "commands.h"#include "gdata.h"#include "lib.h"#include "errors.h"#include "bsl_platform.h"#define BEGIN "begin"#define END   "end"int download(unsigned address){    char *buffer = (char *)address;    char *s;    int errs = 0;    int i;    unsigned c, w;    int offset = 0;    int len;    unsigned led_status = 3;    PrettyPrint("Ready to download. Use 'transmit' option on terminal emulator to download file.");    s = command_line;    do {	if (ReadLineZ(s, sizeof(command_line)-1) == -1)	    return -1;    } while (!cistreq(s, BEGIN, ' '));    s = nextword(s);    s = nextword(s);    strcpy(gpbuff, s);    do {	s = command_line;	len = ReadLineZ(s, sizeof(command_line)-1);	led_status ^= 0x04;	SetLEDs(led_status);	if (len == -1 || cistreq(s, END, ' '))	    break;	c = *s++;	if (!c) continue;	len = c - 0x20;	if (len == 0) continue;	if (len > 45) { errs++; continue; }	i = 0;	while (1) {	    c = *s;	    if (c) {		c -= 0x20;		if (c >= 0x40) { errs++; break; }		s++;	    }	    w = (w << 6) + c;	    if ((++i & 3) == 0) {		buffer[offset++] = w >> 16;		if (--len == 0) break;		buffer[offset++] = w >> 8;		if (--len == 0) break;		buffer[offset++] = w;		if (--len == 0) break;	    }	}    } while (1);    SetLEDs(3);    if (errs)	PrettyPrint("Error: %d errors encountered during download.", errs);    PrettyPrint("Loaded file %s at address %x, size = %d", gpbuff, buffer, offset);    return offset;}CallBack DownLoadCommand(char *tail){    ServiceBlock sb;    CallBack cb;    unsigned tmp, base;    int size;    base = 0x8000;    if (*tail) {	cb = read_args_hex(tail, 1, &tmp);	if (cb) return cb;	base = tmp;    }    sb = ServiceCall(Service_AppSpace);		/* Claim the application space */    if (sb.r0) return sb.r0;			/* Someone objected, return */    size = download(base);    if (size == -1)	return ReportOK();    current_pc = base;    sb = ServiceCall(Service_AppLoaded, base);    return sb.r0;}CallBack FlashWriteCommand(char *tail){    CallBack cb;    unsigned args[3];    cb = read_args_hex(tail, 3, args);    if (cb) return cb;    FlashWrite(args[0], args[0] + args[2], (char *)args[1]);    return ReportOK();}#define	ADDR_TOO_LOW	(1)#define	ADDR_TOO_HI	(2)#define	ADDR_PROTECTED	(3)int flashAccessDenied( unsigned addr, unsigned extent ){   if ( addr < ROM_BASE )   {      return( ADDR_TOO_LOW );   }   if ( ROM_LIMIT < addr + extent )   {      return( ADDR_TOO_HI );   }   if ( addr < ROM_PROTECT_LIMIT )   {      return( ADDR_PROTECTED );   }   return( 0 );}CallBack FlashEraseCommand(char *tail){    CallBack cb;    unsigned args[2];    unsigned erc;    cb = read_args_hex(tail, 2, args);    if (cb) return cb;    erc = flashAccessDenied( args[0], args[1] );    if ( 0 != erc )    {       if ( ADDR_PROTECTED == erc )       {	  return ReportError( EINVAL, "Erase command terminated, attempt to erase system area." );       }       if (ADDR_TOO_HI == erc )       {	  return ReportError( EINVAL, "Erase command terminated, attempt to erase beyond flash limit." );       }       if ( ADDR_TOO_LOW == erc )       {	  return ReportError( EINVAL, "Erase command terminated, attempt to erase below flash start." );       }    }    FlashErase(args[0], args[0] + args[1]);    return ReportOK();}CallBack FlashLoadCommand(char *tail){    ServiceBlock sb;    CallBack cb;    unsigned args;    unsigned address;    unsigned erc;    int size;    cb = read_args_hex(tail, 1, &args);    if (cb) return cb;    sb = ServiceCall(Service_AppSpace);		/* Claim the application space */    if (sb.r0) return sb.r0;			/* Someone objected, return */    address = args;    size = download(0x8000);    if (size == -1)	return ReportError(EBADF, "Errors during download, flash not written");    erc = flashAccessDenied( address, size );    if ( 0 != erc )    {       if ( ADDR_PROTECTED == erc )       {	  return ReportError( EINVAL, "FlashLoad command terminated, attempt to overwrite system area." );       }       if (ADDR_TOO_HI == erc )       {	  return ReportError( EINVAL, "FlashLoad command terminated, attempt to write beyond flash limit." );       }       if ( ADDR_TOO_LOW == erc )       {	  return ReportError( EINVAL, "FlashLoad command terminated, attempt to write below flash start." );       }    }    FlashWrite(address, address + size, (char *)0x8000);    return ReportOK();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -