📄 fl_amphilips.c
字号:
rom_identified = TRUE; break; case AM29D800_ID: if (verbose) printf ("AM29D800 recognised\n"); sector_size = SECTOR_SIZE; no_of_sectors = NUM_SECTORS_800; /********************************/ FL_RESET = 0x00F000F0; /* Generic command bus cycle addresses */ FL_SEQ_ADD_1 = 0x5555; FL_SEQ_ADD_2 = 0x2AAA; FL_SEQ_ADD_3 = 0x5555; /* Generic command bus cycle data */ FL_WORD_COM_1 = 0xAAAAAAAA; FL_WORD_COM_2 = 0x55555555; /* Command specific data for cycle 3 */ FL_AUTO_SELECT = 0x00900090; FL_PROGRAM = 0x00A000A0; /* Erase function addresses and data */ FL_ERASE_ADD_4 = 0x5555; FL_ERASE_ADD_5 = 0x2AAA; FL_CHIP_ERASE_ADD_6 = 0x5555; /* Erase function addresses and data */ FL_ERASE_3 = 0x00800080; FL_ERASE_4 = 0x00AA00AA; FL_ERASE_5 = 0x00550055; FL_SECTOR_ERASE_6 = 0x00300030; FL_BLOCK_ERASE_6 = 0x00500050; FL_CHIP_ERASE_6 = 0x00100010; /********************************/ rom_identified = TRUE; break; case SST_SST39VF160_ID: if (verbose) printf ("SST39VF160 recognised\n"); sector_size = SECTOR_SIZE; no_of_sectors = NUM_SECTORS_160; /********************************/ FL_RESET = 0x00F000F0; /* Generic command bus cycle addresses */ FL_SEQ_ADD_1 = 0x5555; FL_SEQ_ADD_2 = 0x2AAA; FL_SEQ_ADD_3 = 0x5555; /* Generic command bus cycle data */ FL_WORD_COM_1 = 0xAAAAAAAA; FL_WORD_COM_2 = 0x55555555; /* Command specific data for cycle 3 */ FL_AUTO_SELECT = 0x00900090; FL_PROGRAM = 0x00A000A0; /* Erase function addresses and data */ FL_ERASE_ADD_4 = 0x5555; FL_ERASE_ADD_5 = 0x2AAA; FL_CHIP_ERASE_ADD_6 = 0x5555; /* Erase function addresses and data */ FL_ERASE_3 = 0x00800080; FL_ERASE_4 = 0x00AA00AA; FL_ERASE_5 = 0x00550055; FL_SECTOR_ERASE_6 = 0x00300030; FL_BLOCK_ERASE_6 = 0x00500050; FL_CHIP_ERASE_6 = 0x00100010; /********************************/ rom_identified = TRUE; break; default : printf ( "Error: Unrecognised device %04x at address %08lx\n", device_code, base_address); rom_identified = FALSE; return FALSE; } return TRUE;}/* 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: */bool IdentifyChip( void ){ needBaseAddress(); if (rom_identified) return TRUE; /* Read Manufacturer and device code from the device */ manuf_code = flash_get_manuf_code(); device_code = flash_get_device_id(); /* Check the Manufacturer - Fail if not supported */ /* if (manuf_code != MAN_AMD ) { printf ( "Error: Unexpected Manufaturer %02x (expected AMD=%2x)\n", manuf_code, MAN_AMD ); return FALSE; }*/ //deleted by barry xu return SetDeviceParams();}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; } } /* fall through from above if user decides *not* to abort */ { if ( filesize + start_offset > romsize ) { printf("Warning: this ROM cannot contain the file image from this offset.\n"); if (getYesOrNo("Abort? [y/n]", TRUE)) { fclose(image); return FALSE; } } /* end if image would extend off the end of the flash */ } return TRUE;}/* * Function: DownloadFileToFlash * Purpose: Write the named file to flash ROM * * PreConditions: * * Params: * Input: filename - the pathname in host form containing the PROM image * * Returns: none. * * PostConditions: */void DownloadFileToFlash( void ){ int erc, errors=0; unsigned start_addr, end_addr; unsigned first_block, last_block, extent, idx; if (file_defined) openFile(); RomInfo("Programming Flash ROM\n"); needStartOffset(); if (!file_defined) { needFilename(); openFile(); FileInfo(); } romsize = GET_ROM_SIZE(); if (!checkFileSize("written")) return; start_addr = start_offset + base_address; end_addr = start_addr + filesize; /* Handle possible erasing of flash prior to write, which is structured in terms of sectors or blocks */ if ( 0 != checkEraseReq( (char *)start_addr, filesize) ) { erc = flashAccessDenied( start_addr, end_addr ); if ( 0 != erc ) { if ( ADDR_PROTECTED == erc ) { printf( "--- Warning: This command will overwrite system area.\n" ); if ( getYesOrNo( "abort? [y/n]", TRUE ) ) { fclose(image); return; } } if (ADDR_TOO_HI == erc ) { printf( " Error: Blank Flash terminated, attempt to erase beyond flash limit.\n" ); fclose(image); return; } if ( ADDR_TOO_LOW == erc ) { printf( " Error: Blank Flash terminated, attempt to erase below flash start.\n" ); fclose(image); return; } } printf("Warning: this write requires a preliminary flash erase.\n"); if (getYesOrNo("Abort? [y/n]", TRUE)) { fclose(image); return; } /* Start erasing sectors, treating the first and last as a special case because of the need to preserve the contents of these blocks not targeted in the write */ first_block = GET_SECTOR_START( start_addr ); last_block = GET_SECTOR_START( end_addr ); extent = ( first_block == last_block ? filesize: (first_block + AM_SECTOR_SIZE ) - start_addr ); if ( 0 != checkEraseReq( (char *)start_addr, extent) ) { memcpy( (char *)sector, (char *)first_block, AM_SECTOR_SIZE ); Erase_Sector( first_block ); /* Resore data */ if ( start_addr != first_block ) { extent = start_addr - first_block; flash_write( (char *)first_block, (char *)sector, extent ); } if ( first_block == last_block ) { idx = end_addr - last_block; /* into sector[] */ extent = (last_block + AM_SECTOR_SIZE) - end_addr; flash_write( (char *)end_addr, ((char *)sector) + idx, (last_block + AM_SECTOR_SIZE) - end_addr ); } /* end if erased only one block */ } /* end if need to erase first sector */ if ( first_block != last_block ) { extent = (last_block + AM_SECTOR_SIZE) - end_addr; idx = end_addr - last_block; if ( 0 != checkEraseReq( (char *)last_block, idx ) ) { extent = (last_block + AM_SECTOR_SIZE) - end_addr; memcpy( ((char *)sector) + idx, (char *)end_addr, extent ); Erase_Sector( last_block ); flash_write( (char *)end_addr, ((char *)sector) + idx, extent ); } /* end if last block needs to be erased */ } /* end if the last block needs testing */ first_block += AM_SECTOR_SIZE; while ( first_block < last_block ) { if ( 0 != checkEraseReq( (char *)first_block, AM_SECTOR_SIZE ) ) { Erase_Sector( first_block ); } first_block += AM_SECTOR_SIZE; } /* end while rest of the effected sectors are erased as needed */ } /* end if erasing is needed */ /* Write the Image file to the FLASH Device in designated chunk sizes */ { int ret; unsigned buffer_size; unsigned chunk_size = 1024;//512; unsigned chunks_done = 0; char *pFlashData = (char *)( base_address + start_offset); char *pFlashDataEnd = (char *)( base_address + start_offset + filesize ); if (!quiet) printf("Now programming flash from address 0x%lx in chunks of %d bytes - please wait\n", base_address + start_offset, chunk_size); while ( ( pFlashData < pFlashDataEnd ) ) { buffer_size = (unsigned)(pFlashDataEnd - pFlashData); if ( buffer_size > chunk_size ) { buffer_size = chunk_size; } ret = fread((char *)sector, 1, buffer_size, image); if ( ret != buffer_size ) { printf("\nErorr reading file data, error code %X\n", ferror( image ) ); errors = ~0; break; } ret = flash_write( pFlashData, (char *)sector, buffer_size); if ( ret != buffer_size ) { printf("\nErorr writing flash data, expected %d wrote %d\n", buffer_size, ret ); errors = ~0; break; } pFlashData += buffer_size; chunks_done++; ShowProgress( chunks_done ); } /* end while more data to write */ } /* end write flash block */ /* Close the external file and return */ fclose(image); if (errors==0) printf("\nFlash written successfully\n"); else printf("\nFlash write aborted: too many errors.\n");}/* * Function: BlankFlash * Purpose: Erase Flash * * PreConditions: * * Params: * Input: * * Returns: none. * * PostConditions: */void BlankFlash( void ){ int romsize = 0; unsigned erc; unsigned start_addr; RomInfo("Blanking Flash ROM\n"); needStartOffset(); romsize = no_of_sectors * sector_size; start_addr = base_address + start_offset; erc = flashAccessDenied( start_addr, base_address + romsize ); if ( 0 != erc ) { if ( ADDR_PROTECTED == erc ) { printf( " Warning: Blank Flash command will erase system area.\n" ); if ( getYesOrNo( "abort? [y/n]\n", TRUE ) ) { return; } } if (ADDR_TOO_HI == erc ) { printf( " Error: Blank Flash terminated, attempt to erase beyond flash limit.\n" ); return; } if ( ADDR_TOO_LOW == erc ) { printf( " Error: Blank Flash terminated, attempt to erase below flash start.\n" ); return; } } if (!quiet) printf("Now blanking flash from offset 0x%lx - please wait\n", start_offset); if ( start_addr != GET_SECTOR_START( start_addr ) ) { memcpy( (char *)sector, (char *)GET_SECTOR_START( start_addr ), start_addr - GET_SECTOR_START( start_addr ) ); } /* end if need to preserve part of the first erased sector */ /* blank out Flash from offset */ // FlashErase( start_addr, base_address + romsize ); flash_command( FLASH_CERASE, 0, 0, 0 ); if ( start_addr != GET_SECTOR_START( start_addr ) ) { flash_write( (char *)GET_SECTOR_START( start_addr ), (char *)sector, start_addr - GET_SECTOR_START( start_addr ) ); } /* end if need to preserve part of the first erased sector */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -