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

📄 fl_wrt.c

📁 sharp的arm920t 7A400的评估板附带光盘Sharp KEVLH7A400 v0.3b Welcome to the SHARP KEV7A400 Evaluation board
💻 C
📖 第 1 页 / 共 4 页
字号:
/**********************************************************************
 *	$Workfile:   fl_wrt.c  $
 *	$Revision:   1.8  $
 *	$Author:   KovitzP  $
 *	$Date:   Jan 23 2002 10:28:16  $
 *
 *	Project: LH79520 Evaluation Board
 *
 *	Description:
 * This file currently will recognize and program the FLASH EPROMS from
 * SHARP * namely :-
 *       LH28F160S3T-L10 16 Mbit device - sectors 65536 bytes
 *       LH28F320BJE-PBTL90 32 Mbit device -  sectors 65536 bytes
 *  It was modified from source code provided by ARM. That code was
 *  Copyright (c) 1996 Advanced RISC Machines Limited.
 *
 *  This code was designed to work with the ADW 2.51 and AXD debuggers.
 *  Make a project that contains this source file only. Configure
 *  the FromELF utility to output an AIF format file (debug enabled) into
 *  a file called flash.li. Copy flash.li into the [path]\bin directory
 *  that contains the executable code for the debugger.
 *
 *  Prepare your hardware to receive code into memory. Run an obey
 *  file or startup program if necessary to set up the target hardware.
 *  Make sure you know the base address of flash memory.
 *
 *  Open a console window.
 *  Use the File>Flash Download... menu item in the debugger to
 *  start the download process.
 *
 *  Answer the prompts in the console window as they appear. There is
 *  very little error checking, so type carefully.
 *
 *	Revision History:
 *	$Log:   P:/PVCS6_6/archives/LH79531 EVB/Flash/fl_wrt.c-arc  $
 * 
 *    Rev 1.8   Jan 23 2002 10:28:16   KovitzP
 * Added support for LH28F320BFE_PBTL devices
 * 
 *    Rev 1.7   Nov 07 2001 16:39:24   KovitzP
 * Added support for flashing SyncFlash and Phoenix Flash
 * 
 *    Rev 1.6   Oct 24 2001 17:33:08   KovitzP
 * Added code for the 64Mbit top boot Phoenix Flash device. May have broken code for the BJE-type 32Mbit device. Should not have, but it is not tested yet.
 * 
 *    Rev 1.5   Aug 13 2001 17:01:28   KovitzP
 * Repaired bugs in flash erase and flash verify. Cleaned up
 * the help option
 * 
 *    Rev 1.4.1.0   Aug 13 2001 14:37:18   KovitzP
 * trying to fix -B (erase flash) option. Not done yet. Don't use this version
 * 
 *    Rev 1.4   Aug 09 2001 14:26:00   KovitzP
 * updated flash programming tool to make command writes to flash 16-bit writes instead of 8-bit writes.
 * 
 *    Rev 1.3   Aug 07 2001 15:16:22   KovitzP
 * Fixed comments on how to build and use. Verfied operation
 * integrated with ARM AXD.
 * 
 *    Rev 1.2   Aug 07 2001 13:17:44   KovitzP
 * Verified to work in debug mode.
 * 
 *	COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
 *		CAMAS, WA
 *********************************************************************/

/* Include Standard c Libraries to allow stand alone compiling and operation */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "LH7A400_sdramc.h"

/*#define EPROM_BASE              0x08000000 */
#define SYNC_BASE_ADDRESS       0x80002400
#define SYNC_FLASH_BASE_ADDRESS 0xF0000000
#define MAN_MICRON              0x002C 
//#define MICRON_MT28S4M16LC_ID   0x00D3 /* this is actual ID */
#define MICRON_MT28S4M16LC_ID   0x002C /* this is what Aruba returns */
#define MICRON_SECTOR_SIZE      (512 * 1024) /* 512Kbyte blocks */
#define MAN_SHARP               0x00B0
#define MAN_MASK                0x00FF
#define DEV_MASK                0x00FF
#define SHARP_LH28F160S_ID      0x00D0
#define SHARP_LH28F800S_ID      0x66a8
#define SHARP_LH28F320BJE_ID    0x00E3
#define SHARP_LH28F640BFE_PTTL_ID 0x00B0
#define SHARP_LH28F320BFE_PBTL_ID 0x00B5
#define SHARP_SECTOR_SIZE       65536
#define MAX_SECTOR_SIZE         MICRON_SECTOR_SIZE
#define SHARP_BOOT_PARAM_SIZE   8192
#define SHORT_HELP
#define LONG_HELP

/**********************************************************************
 *             P R E P R O C E S S O R   D E F I N E S
 **********************************************************************/

#define ISM_READY _BIT(7)
#define ISM_PROTECTED _BIT(3)

/* Local routine defines for the fl_wrt.c module */
#define MIN_NO_OF_ARGS    2
#define WORD_SHIFT_OFFS   1
#define WORD_ADD_OFFSET   2
#define STATUS_ADD_OFFSET 4


//#define FILL_PATTERN    0xffff
#define FILL_PATTERN    0xff
#define WORD_SIZE       4
#define MAX_ERRORS_ALLOWED 20

#define RESET_COM       0xff
#define READ_ARRAY_COM  0xff
#define READ_ID_COM     0x90
#define QUERY_COM       0x98
#define READ_STATUS_COM 0x70
#define CLR_STATUS_COM  0x50
#define BLK_ERASE_COM1  0x20
#define BLK_ERASE_COM2  0xd0
#define CHP_ERASE_COM1  0x30
#define CHP_ERASE_COM2  0xd0
#define WRITE_COM       0x40
#define UNLOCK_COM1     0x60
#define UNLOCK_COM2     0xd0
#define LOCK_COM1       0x60
#define LOCK_COM2       0x01
#define PARTION_COM1    0x60
#define PARTION_COM2    0x04

/* Read address bitfield for command data */
#define SDRAM16_ROW_OFFSET 9
#define SDRAM32_ROW_OFFSET 10


typedef 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__);

#define cmd_write(address, cmd) {/*printf("Writing 0x%x to 0x%lx\n", (cmd), (address));*/ (*((volatile short *)(address)) = (volatile short)(cmd));}
#define read_status(address) *((volatile char *)((address) + STATUS_ADD_OFFSET))

/* 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
 **********************************************************************/

/* Specify the host files for the flash transfer */
static FILE *image;

static unsigned long sector_size = 0;
static unsigned long boot_param_sector_size = 0;
static unsigned long no_of_sectors = -1;
static unsigned long boot_param_sectors = 0;
static bool use_sync_interface = FALSE;
static unsigned long segment_spacing = 0;
static unsigned long sectors_per_segment = 0;
static bool bottom_boot = FALSE;
static bool top_boot = FALSE;
static bool quiet = FALSE;
static bool verbose = FALSE;
static bool interactive = FALSE;
static bool sector_unlockable = FALSE;
static int manuf_code = 0, device_code = 0;
static unsigned long filesize = 0;
static 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;
#ifdef EPROM_BASE
static bool base_defined = TRUE;
#else
static bool base_defined = FALSE;
#endif
static bool file_defined = FALSE;
static bool filesize_defined = FALSE;
static bool rom_identified = FALSE;

static bool sync_base_defined = FALSE;
static SDRAMREGS * sync_base_address = (SDRAMREGS *)SYNC_BASE_ADDRESS;

#ifdef EPROM_BASE
static unsigned long base_address = EPROM_BASE;
#else
static unsigned long base_address = 0;
#endif
static unsigned long start_sector = 0;
static char filename[512];

static unsigned int sector[MAX_SECTOR_SIZE/4];
static void sync_flash_command(UNS_16 command, volatile UNS_16 *address);
static void sync_wait_for_ready(volatile UNS_16 * sector_ptr);
/**********************************************************************
 *          P R O T O T Y P E   D E C L A R A T I O N S
 **********************************************************************/
static void needBaseAddress(void);
static void needSyncBase(void);
static void needFilename(void);
static bool IdentifyChip(void);
static void FileInfo(void);
void openFile(void);
static void RomInfo(char *msg);
static void Pause(void);
int verify_sector(unsigned long start_address, int sector_size, 
                  unsigned int sector_data[]);
extern int write_sector (unsigned long base, unsigned long start_address,
                         int sector_size,
                         unsigned int sector_data[MAX_SECTOR_SIZE/sizeof(int)]);
void wait_for_ready(void);


/**********************************************************************
 *                 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.
 */
static 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] [-S width] [file]\n");
#else
    printf("Usage:\n"
           "  [-w] [-qVp] [-b addr] [-s sector] [file]\n"
           "  -v [-qvp] [-b addr] [-s sector] [file]\n"
           "  -B [-qvp] [-b addr] [-s sector]\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 sector 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%08lx)\n", base_address);
    printf("  -s n     use \'n\' as the start sector number 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"
           "  -S width Use the SDRAM interface to access the flash device\n"
           "           Specify width = 16 for 16-bit flash device.\n"
           );
    printf("\n"
           "This program is used to download a file into flash.\n");
#endif
}


static bool SetDeviceParams()
{
    switch (manuf_code)
    {
       case MAN_SHARP:
          switch (device_code)
          {
             case  SHARP_LH28F160S_ID:
                if (verbose)
                   printf ("LH28F160S recognized\n");
                sector_size = SHARP_SECTOR_SIZE;
                no_of_sectors = 32;
                rom_identified = TRUE;
                boot_param_sectors = 0;
                boot_param_sector_size = 0;
                bottom_boot = FALSE;
                top_boot = FALSE;
                sector_unlockable = FALSE;
                break;

             case  SHARP_LH28F800S_ID:
                if (verbose)
                   printf ("LH28F800S recognized\n");
                sector_size = SHARP_SECTOR_SIZE;
                no_of_sectors = 16;
                rom_identified = TRUE;
                boot_param_sectors = 0;
                boot_param_sector_size = 0;
                bottom_boot = FALSE;

⌨️ 快捷键说明

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