📄 fl_wrt.c
字号:
top_boot = FALSE;
sector_unlockable = FALSE;
break;
case SHARP_LH28F320BJE_ID:
if (verbose)
printf ("LH28F320BJE recognized\n");
sector_size = SHARP_SECTOR_SIZE;
no_of_sectors = 64; /* number of 64 KB areas; boot & parameter blocks treated as one main sector */
rom_identified = TRUE;
boot_param_sectors = SHARP_SECTOR_SIZE / SHARP_BOOT_PARAM_SIZE;
boot_param_sector_size = SHARP_BOOT_PARAM_SIZE;
bottom_boot = TRUE;
top_boot = FALSE;
sector_unlockable = FALSE;
break;
case SHARP_LH28F640BFE_PTTL_ID:
if (verbose)
printf ("LH28F640BFE_PTTL recognized\n");
sector_size = SHARP_SECTOR_SIZE;
no_of_sectors = 128; /* number of 64 KB areas; boot & parameter blocks treated as one main sector */
rom_identified = TRUE;
boot_param_sectors = SHARP_SECTOR_SIZE / SHARP_BOOT_PARAM_SIZE;
boot_param_sector_size = SHARP_BOOT_PARAM_SIZE;
bottom_boot = FALSE;
top_boot = TRUE;
sector_unlockable = TRUE;
/* force entire flash to be in one big partition */
cmd_write(base_address,PARTION_COM1);
cmd_write(base_address,PARTION_COM2);
break;
case SHARP_LH28F320BFE_PBTL_ID:
if (verbose)
printf ("LH28F320BFE_PBTL recognized\n");
sector_size = SHARP_SECTOR_SIZE;
no_of_sectors = 64; /* number of 64 KB areas; boot & parameter blocks treated as one main sector */
rom_identified = TRUE;
boot_param_sectors = SHARP_SECTOR_SIZE / SHARP_BOOT_PARAM_SIZE;
boot_param_sector_size = SHARP_BOOT_PARAM_SIZE;
bottom_boot = TRUE;
top_boot = FALSE;
sector_unlockable = TRUE;
/* force entire flash to be in one big partition */
cmd_write(base_address,PARTION_COM1);
cmd_write(base_address,PARTION_COM2);
break;
default :
printf ( "Error: Unrecognized device id %x at address %08lx\n",
device_code, base_address);
rom_identified = FALSE;
return FALSE;
break;
}
break;
case MAN_MICRON:
switch (device_code)
{
case MICRON_MT28S4M16LC_ID:
if (verbose)
printf ("MICRON MT28S4M16LC ID recognized\n");
sector_size = MICRON_SECTOR_SIZE;
no_of_sectors = 16;
rom_identified = TRUE;
boot_param_sectors = 0;
boot_param_sector_size = 0;
bottom_boot = FALSE;
top_boot = FALSE;
sector_unlockable = FALSE;
segment_spacing = _BIT(26);
sectors_per_segment = 4;
break;
default :
printf ( "Error: Unrecognized device id %x at address %08lx\n",
device_code, base_address);
rom_identified = FALSE;
return FALSE;
break;
}
break;
default:
printf ( "Error: Unrecognized manufacturer code %x at address %08lx\n",
manuf_code, base_address);
rom_identified = FALSE;
return FALSE;
break;
}
return TRUE;
}
/*
Issue a SyncFlash command.
*/
void sync_flash_command(UNS_16 command, volatile UNS_16 *address)
{
volatile UNS_16 dummy_val;
volatile UNS_32 mask = MICRON_SECTOR_SIZE - 1;
sync_base_address->global = SDRAM_GLOBAL_CKE |
SDRAM_GLOBAL_ENACMD;
dummy_val = *((volatile UNS_16 *)
(
((UNS_32)address & ~mask) |
_SBF(SDRAM16_ROW_OFFSET, command)
));
sync_base_address->global = SDRAM_GLOBAL_CKE |
SDRAM_GLOBAL_NORMAL;
}
/*
* Function: IdentifyChip
* Purpose: Attempt to identify what sort of Flash ROM is in memory at the
* given base address. Return the manufacturer and device codes for it
* in globals, and a bool to indicate successful identification
*
* PreConditions:
*
* Params:
* Input:
* base - the base address of the Flash PROM in memory
*
* Returns: bool - TRUE if identified correctly, FALSE otherwise..
*
* PostConditions:
*/
static bool IdentifyChip()
{
int lowest_word, lowest_word_after;
int entered_read_identifier_codes_mode=0;
if (rom_identified)
return TRUE;
needBaseAddress();
if (use_sync_interface)
{
needSyncBase();
/* read the manufacturer code */
sync_flash_command(READ_ID_COM, (volatile UNS_16 *)base_address);
manuf_code = *((volatile UNS_16 *)base_address);
/* read the Device ID */
sync_flash_command(READ_ID_COM, (volatile UNS_16 *)base_address);
device_code = *((UNS_16 *)(base_address + 2));
return SetDeviceParams();
}
cmd_write(base_address,RESET_COM);
Pause();
lowest_word = *((volatile int *)base_address);
/* Enter Software Read Identifier Codes Mode */
cmd_write(base_address,READ_ID_COM);
/* Wait 10 ms for the device to change state (Necessary?)*/
Pause();
/* if the base address of the chip contains the real, current data,
we did not get into Read Identifier Codes Mode */
lowest_word_after = *((volatile int *)base_address);
if (lowest_word_after != lowest_word)
{
/* Read Manufacturer and device code from the device */
entered_read_identifier_codes_mode = 1;
manuf_code = *((volatile short *) base_address) & MAN_MASK;
device_code = *((volatile short *) (base_address + WORD_ADD_OFFSET)) & DEV_MASK;
}
if (!entered_read_identifier_codes_mode)
{
printf("Error: Failed to read the Flash ID "
"(did not enter product ID mode)\n");
return FALSE;
}
/* Exit Read Identifier Codes Mode */
cmd_write(base_address, RESET_COM);
/* Wait 10 ms */
Pause();
/* Check the Manufacturer - Fail if not known */
if (manuf_code != MAN_SHARP)
{
printf ( "Error: Unexpected Manufacturer %02x (expected SHARP=%2x)\n",
manuf_code, MAN_SHARP );
return FALSE;
}
return SetDeviceParams();
}
/*
* 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: needStartSector
* 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
*/
static void needStartSector()
{
if (start_defined == FALSE || interactive == TRUE)
{
start_sector = getLong("Starting Sector [in hex, default %lx]: ",
start_sector);
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
*/
static void needBaseAddress(void)
{
if (base_defined == FALSE || interactive == TRUE)
{
base_address = getLong("Base Address [in hex, default 0x%08lx]: ",
base_address);
base_defined = TRUE;
}
}
/*
* Function: needSyncBase
* 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
*/
static void needSyncBase(void)
{
if (sync_base_defined == FALSE || interactive == TRUE)
{
sync_base_address = (SDRAMREGS *)getLong("Base Address of Sync Mem Controller [in hex, default 0x%08lx]: ",
(UNS_32)sync_base_address);
sync_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
*/
static void needFilename(void)
{
if (file_defined == FALSE || interactive == TRUE)
{
strcpy(filename, getString("Filename [default \"%s\"]: ", filename));
file_defined = TRUE;
}
}
/*
* Function: RomInfo
* Purpose: Print standard info about the ROM to stdout, if not
* in "quiet" mode.
*
* PreConditions:
*
* Params:
* Input: filename - the pathname in host form containing the
* PROM image
* base - the base address of the Flash PROM in memory
* sector - the sector to start at; a sector is a block
* (e.g. of 65536 bytes) in the PROM
*
* Returns: none.
*
* PostConditions:
*/
static void RomInfo(char *msg)
{
if (!IdentifyChip())
exit(1);
if (!quiet)
{
printf(msg);
if (file_defined)
FileInfo();
printf("ROM Sector size : 0x%lx\n", sector_size);
printf("ROM Length : %ldKb (%ld sectors)\n",
divroundup((no_of_sectors * sector_size), 1024), no_of_sectors);
if (boot_param_sectors != 0)
printf("Boot Sector Length : %ldKb (%ld sectors)\n",
divroundup((boot_param_sectors * boot_param_sector_size), 1024), boot_param_sectors);
if (start_defined)
printf("Start Sector : 0x%lx\n", start_sector);
if (base_defined)
printf("Base Address : 0x%lx\n", base_address);
}
}
/*
* Function: FileInfo
* Purpose: Print the filename and file size in Kb and sectros
* if not quiet mode.
*
* PreConditions: file_defined TRUE, openFile called, sector_size set.
*
* Params:
* Input: filename - global containing a pointer to the filename.
* filesize - global containing the file size in bytes.
*
* Returns: none.
*
* PostConditions:
*/
static void FileInfo(void)
{
if (!quiet)
{
printf("Input File : \"%s\"\n", filename);
printf("File size : %luKb (%lu sectors)\n",
divroundup(filesize, 1024),
divroundup(filesize, sector_size));
}
}
void openFile(void)
{
/* open the external FLASH Image file - any failure then exit */
if ((image = fopen(filename,"rb")) == NULL)
{
printf("Error: Cannot open file \"%s\"\n", filename);
exit(1);
}
if (fseek(image, 0, SEEK_END) == 0)
{
filesize = ftell(image);
fseek(image, 0, SEEK_SET);
filesize_defined = TRUE;
}
}
static bool checkFileSize(char *action)
{
ASSERT(filesize_defined);
if (romsize < filesize)
{
printf("Warning: this ROM is too small to contain the file image.\n");
if (getYesOrNo("Abort? [y/n]", TRUE))
{
fclose(image);
return FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -