📄 fl_wrt.c
字号:
/***********************************************************************
* $Workfile: fl_wrt.c $
* $Revision: 1.0 $
* $Author: WellsK $
* $Date: Sep 04 2003 15:53:28 $
*
* Project: AXD flash programmer utility
*
* Description:
* This program provides the capability to detect, (re)program,
* and verify FLASH on the SDK7A400 and SDK7A404 EVBs when used
* with the ARM AXD debugger (and a RDI ICE unit).
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh7a404/bsps/sdk7a404/examples/flash_li/fl_wrt.c-arc $
*
* Rev 1.0 Sep 04 2003 15:53:28 WellsK
* Initial revision.
*
*
***********************************************************************
* SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
* OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
* AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES,
* SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
*
* SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY
* FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A
* SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
* FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
*
* COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
* CAMAS, WA
**********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "abl_types.h"
#include "sdk7a404_strataflash.h"
/***********************************************************************
* AXD flash programmer private data and types
**********************************************************************/
/* If the following define is used, single location writes will be used
to program FLASH instead of block writes. Block writes are faster */
#define USE_SINGLE_WRITE
/* Size of the FLASH devices */
static INT_32 flashsize;
/* Verify flag, 0 = do not verify after write */
static INT_32 verify;
/* Erase flag, 0 = do not erase before write */
static INT_32 erase;
/* Query flag, 0 = do not print FLASH info */
static INT_32 query;
/* FLASH device base address */
static UNS_32 flashbase;
/* FLASH programming offset from base address */
static UNS_32 flashoffset;
/* Path and filename of target file */
static CHAR filename[1024];
/***********************************************************************
* AXD flash programmer functions
**********************************************************************/
/***********************************************************************
*
* Function: showhelp
*
* Purpose: Prints FLASH program options
*
* Processing:
* Displays options used for the AXD flash.li program.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void showhelp(void)
{
printf("Options:\n");
printf(" -d Disable interactive prompts\n");
printf(" -v Enable verify after FLASH write (slower)\n");
printf(" -h Display options help (this menu)\n");
printf(" -q Display programming info\n");
printf(" -e Erase entire FLASH device\n");
printf(" -l Display a list of block addresses\n");
printf(" -b n Use n as the FLASH base address (default 0)\n");
printf(" -o n Program FLASH at offset n (default 0)\n");
printf(" (Address must be 32-bit aligned\n");
}
/***********************************************************************
*
* Function: flashgetaddroffs
*
* Purpose: Get FLASH address and offset from user
*
* Processing:
* Display messages requesting the FLASH base address and offset
* and fetch the values from the user.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void flashgetaddroffs(void)
{
printf("Enter base address of FLASH device in hex: ");
scanf("%x", &flashbase);
printf("Enter offset in FLASH for program in hex: ");
scanf("%x", &flashoffset);
}
/***********************************************************************
*
* Function: flashdetect
*
* Purpose: Get and display FLASH geometry data
*
* Processing:
* See function.
*
* Parameters: None
*
* Outputs: None
*
* Returns: 0 if the FLASH device was detected, otherwise (-1).
*
* Notes: None
*
**********************************************************************/
INT_32 flashdetect(void)
{
return cfi_detect((UNS_32 *) flashbase);
}
/***********************************************************************
*
* Function: flasherasedevice
*
* Purpose: Erase the entire FLASH device
*
* Processing:
* See function.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void flasherasedevice(void)
{
printf("Erasing entire device...\n");
cfi_erase_device();
}
/***********************************************************************
*
* Function: flashprogram
*
* Purpose: Program a FLASH device
*
* Processing:
* See function.
*
* Parameters: None
*
* Outputs: None
*
* Returns: 0 if the FLASH device was programmed, otherwise (-1).
*
* Notes: None
*
**********************************************************************/
INT_32 flashprogram(void)
{
UNS_32 data[32];
FILE *pfile;
BOOL_32 exitprog;
UNS_32 block, *blockstart, *blockend, blocksize, xfer_size;
INT_32 bytes, status = 0;
/* Because blocks need to be erased before they are programmed,
the starting address of where to program must always reside
on a block boundary. Verify that this is valid first and
determine the starting block number for the address */
block = cfi_get_block_from_address((UNS_32 *) (flashbase +
flashoffset));
blockstart = (UNS_32 *) cfi_get_block_address(block);
if ((UNS_32) blockstart == (flashbase + flashoffset))
{
/* Program address starts at a block address, continue */
/* Open file for reading */
pfile = fopen(filename, "rb");
if (pfile != NULL)
{
/* Main programming algorithm - continue until FLASH is
full or the file is empty */
exitprog = FALSE;
while (exitprog == FALSE)
{
/* Get block size and compute end of block */
blocksize = cfi_get_block_size(block);
blockend = (UNS_32 *) ((UNS_32) blockstart + blocksize);
/* Clear block lock */
cfi_clear_block_lock(block);
/* Display block number */
printf("Programming block #%d at address %08x "
"(%d bytes)\n", block, (UNS_32) blockstart, blocksize);
/* Erase block if not previously erased */
if (erase == 0)
{
cfi_erase_block(block);
}
/* Compute optimal transfer size in bytes */
xfer_size = 4 * cfi_get_wb_size();
if (cfi_get_wb_size() > sizeof(data))
{
xfer_size = sizeof(data);
}
/* Program the block */
while ((blockstart < blockend) && (exitprog == FALSE))
{
#ifdef USE_SINGLE_WRITE
/* Read data from the file */
bytes = fread(&data[0], 1, sizeof(data[0]), pfile);
if (bytes > 0)
{
/* Write data to next address */
cfi_writeword(blockstart, data[0]);
/* Next address */
blockstart++;
}
#else
/* Read data from the file */
bytes = fread(&data[0], 1, xfer_size, pfile);
if (bytes > 0)
{
blockstart = blockstart +
cfi_write_to_buffer(&data[0], blockstart,
(bytes / 4));
}
#endif
else
{
/* No more data */
exitprog = TRUE;
}
}
/* Lock block */
cfi_set_block_lock(block);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -