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

📄 fl_wrt.c

📁 AT91所有开发板的资料 AT91所有开发板的资料
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  $Revision: 1.3 $ *    $Author: mechavar $ *      $Date: 2000/06/19 18:53:18 $ * *  Copyright (c) 1996 Advanced RISC Machines Limited *  All rights reserved * * *	This file contains the hardware independent portion of the ARM flash  * downloader. This version does not support placing ethernet cookies in the  * flash. * *//* Include Standard c Libraries to allow stand alone compiling and operation */#include <stdio.h>#include <stdlib.h>#include <time.h>#include <string.h>/* Include the specific files for the flash memory system */#include "mem.h"#include "fl_sst.h"/********************************************************************** *             P R E P R O C E S S O R   D E F I N E S **********************************************************************//* Local routine defines for the flashwrt.c module */#define MIN_NO_OF_ARGS   2#define BYTE_MSBIT_MASK  0x80#define BYTE_ADD_OFFSET  1#define WORD_ADD_OFFSET  2#define WORD_SHIFT_OFFS  1#define FILL_PATTERN     0x5a#define WORD_SIZE        4#define WORD_TRUE         1typedef int bool;#ifndef TRUE#define TRUE (bool)1#endif#ifndef FALSE#define FALSE (bool)0#endif#define ASSERT(cond)   if (!cond) fprintf(stderr, "Assertion failed line %d\n", __LINE__);/* perform x/y, rounding upwards (i.e. 3/4 is 1, 5/2 is 3) */#define divroundup(x, y)   ((unsigned long)((x) + ((y)-1)) / (unsigned long)(y))/********************************************************************** *                    P R O G R A M   D A T A **********************************************************************/extern unsigned long base_address;/* Specify the host files for the flash transfer */FILE *image;unsigned long sector_size = 0;unsigned long no_of_sectors = -1;bool quiet = FALSE;bool verbose = FALSE;static bool interactive = FALSE;int manuf_code, device_code;unsigned long filesize = 0;unsigned long romsize = 0;static enum operations{    op_writerom, op_verify,    op_blank, op_help, op_identify } mode = op_writerom;static bool start_defined = FALSE;bool base_defined = TRUE;bool file_defined = FALSE;bool filesize_defined = FALSE;bool rom_identified = FALSE;unsigned long start_offset = 0;static char filename[512];extern unsigned int sector[MAX_SECTOR_SIZE];/********************************************************************** *          P R O T O T Y P E   D E C L A R A T I O N S **********************************************************************/extern bool IdentifyChip(void);extern bool SetDeviceParams( void );extern int write_sector (unsigned long, unsigned long, int, unsigned int []);extern bool checkFileSize(char *action);extern void DownloadFileToFlash( void );extern void BlankFlash( void );void needBaseAddress(void);void needFilename(void);void FileInfo(void);void openFile(void);void RomInfo(char *msg);static void Pause(void);int verify_sector(unsigned long start_address, int sector_size,                   unsigned int sector_data[]);/********************************************************************** *                 L O C A L   F U N C T I O N S **********************************************************************//* *       Function: getYesOrNo *        Purpose: Print out the given message and wait for the user to enter 'y' or 'n'.. * *  PreConditions: none. *  *         Params: msg - prompt to write out *                 def - default value if just a carriage return entered. * *        Returns: none *  * PostConditions: none. */bool getYesOrNo(char *msg, bool def){    bool ans = def;    int c;    printf(msg);    while((c = getchar()) != EOF)    {        if (c == 'y' || c == 'Y')        {            ans = 1;            break;        }        else if (c == 'n' || c == 'N')        {            ans = 0;            break;        }        else if (c == '\n')        {            ans = def;            break;        }        else            printf(msg);    }    /* Now consume the rest of the line (as we don't unset line editing     * mode, the only way we get any char is if the user enters a whole line.     */    while( c != '\n' && (c = getchar()) != EOF)        continue;        return ans;}/* *       Function: getLong *        Purpose: Print out the given message and wait for the user to enter a valid number * *  PreConditions: none. *  *         Params: msg - prompt to write out (should include a %ld for the default) *                 def - default value if just a carriage return entered. * *        Returns: none *  * PostConditions: none. */static unsigned long getLong(char *msg, unsigned long def){    unsigned long ans;    char instring[32];        while (TRUE)    {        printf(msg, def);        fgets(instring,sizeof(instring),stdin);                if (instring[0] == '\n')        {            ans = def;            break;        }        else            if (sscanf(instring,"%lx",&ans) == 1)                break;    }    return ans;}/* *       Function: getString *        Purpose: Print out the given message and wait for the user to enter a string * *  PreConditions: none. *  *         Params: msg - prompt to write out (should include a %s for the default) *                 def - default value if just a carriage return entered. * *        Returns: char * - a pointer to the string retrieved. *  * PostConditions: none. */static char *getString(char *msg, char *def){    static char instring[512];    char *p;        printf(msg, def);    fgets(instring,sizeof(instring),stdin);        if (instring[0] == '\n')        strcpy(instring, def);    else if ((p = strchr(instring, '\n')) != NULL)        *p = '\0';        return instring;}/* *       Function: DisplayHelp *        Purpose: Print out the usage message. * *  PreConditions: none. *  *         Params: none. * *        Returns: none *  * PostConditions: none. */static void DisplayHelp(void){#ifdef SHORT_HELP    printf("usage: flash [-w|-v|-B|-h|-I] [-qvp] [-b addr] [-s sector] [file]\n");#else    printf("Usage:\n"           "  [-w] [-qvp] [-b addr] [-s offset] [file]\n"           "  -v [-qvp] [-b addr] [-s offset] [file]\n"           "  -B [-qvp] [-b addr] [-s offset]\n"           "  -h\n"           "  -I\n");#endif#ifdef  LONG_HELP    printf("\n"           " Modes:\n"           "  -w       write and verify named file to ROM (default mode,\n"           "           the \'-w\' is optional if a filename is specified)\n"           "  -v       verify named file matches ROM contents.\n"           "  -B       blank the ROM from the start offset to the end.\n"           "  -h       print the usage message and exit\n"           "  -I       identify the ROM type and exit\n"           "\n");    printf(" Options:\n"           "  -b n     use \'n\' as the Flash ROM base address (default 0x%x)\n", EPROM_BASE);    printf("  -s n     use \'n\' as the start offset address for program/verify\n"           "  -q       quiet; don\'t print status or progress messages\n"           "  -V       verbose; print lots of info on what\'s happening\n"           "  -p       force interactive; even if required info specified, prompt\n"           "           for it (with defaults)\n");#endif}/* *       Function: Pause *        Purpose: Pause for at least 10 ms. In fact, this will pause *                 for 1 second (definition of time()) as this is (currently) *                 the best that can be done. * *  PreConditions:  *  *         Params: none. * *        Returns: none. *  * PostConditions: */static void Pause(void){    time_t t = time(NULL);      while(time(NULL)-t < 1)        continue;}/* *       Function: needStartOffset *        Purpose: if the sector start is not currently defined (as indicated by *                 'start_defined' or interactive mode is enabled then prompt *                 the user for a starting sector, indicating the current value. * *  PreConditions:  *  *         Params: *            Input: start_defined - global indicating if the filename is set *                   interactive - global indicating if info should be prompted *                                 for even if set on the command line. * *        Returns: none. *  * PostConditions: global startsector and start_defined set */void needStartOffset( void ){    if (start_defined == FALSE || interactive == TRUE)    {        start_offset = getLong("Starting address offset [in hex, default %lx]: ", start_offset);        start_defined = TRUE;    }}/* *       Function: needBaseAddress *        Purpose: if the ROM base is not currently defined (as indicated by *                 'base_defined' or interactive mode is enabled then prompt *                 the user for a base address, indicating the current value. * *  PreConditions:  *  *         Params: *            Input: start_defined - global indicating if the filename is set *                   interactive - global indicating if info should be prompted *                                 for even if set on the command line. * *        Returns: none. *  * PostConditions: global startsector and start_defined set */void needBaseAddress(void){    if (base_defined == FALSE || interactive == TRUE)    {        base_address = getLong("Base Address [in hex, default %lx]: ", base_address);        base_defined = TRUE;    }}/* *       Function: needFilename *        Purpose: if the filename is not currently defined (as indicated by *                 'file_defined' or interactive mode is enabled then prompt *                 the user for a filename, indicating the current value. * *  PreConditions:  *  *         Params: *            Input: file_defined - global indicating if the filename is set *                   interactive - global indicating if info should be prompted *                                 for even if set on the command line. * *        Returns: none. *  * PostConditions: global filename and file_defined set */void needFilename(void){    if (file_defined == FALSE || interactive == TRUE)    {        strcpy(filename, getString("Filename [default \"%s\"]: ", filename));        file_defined = TRUE;    }}

⌨️ 快捷键说明

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