// ================================================ ========================================
// TITLE:
// Read the boot flash reference code of the DBAU1200 Development Board
// AUTHOR:
// Norains
// DATE:
// Saturday 31-May-2008.
// Environment:
// VS2005 + DBAU1200 BOARD + misii SDK
// ================================================ ========================================
This code is used to read the boot flash of the DBAU1200 Development Board and save it as the SREC format.
Cflashamilton is mainly used to read boot flash, this class can be obtained here: http://blog.csdn.net/norains/archive/2008/05/31/2498178.aspx
Note that the Code listed in this article is the reference code, and there are still many imperfections. For example, the size of the FLASH to be read must be an integer multiple of 16. Be careful when using it.
# Include "stdafx. H"
# Include "flashamilton. H"
# Include <vector>
# Include <string>
# Include <algorithm>
// Start address of the dbau1200 Development Board flash
# Define default_dbau1__flash_address_base 0x9c000000
// Read the offset address
# Define default_dbau0000_flash_offset_read 0x3c00000
// Read The Flash size
# Define max_size_read (1024*1024) // 1 Mbyte
Int winapi winmain (hinstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
Int nCmdShow)
{
Cflascnt flash;
Flash. SetFlashInfo (Flash: FLASH_INFO_AM29LV256M );
Flash. SetFlashAddressBase (DEFAULT_DBAU1200_FLASH_ADDRESS_BASE );
Std: vector <BYTE> vtBuf (MAX_SIZE_READ, 0 );
Flash. ReadFlash (DEFAULT_DBAU1200_FLASH_OFFSET_READ, & vtBuf [0], MAX_SIZE_READ );
// Change it to S3 type
Const DWORD dwDataPerLine = 16;
DWORD dwStoreCount = 0;
Std: string strStore;
DWORD dwChkSum = 0;
DWORD dwAddress = DEFAULT_DBAU1200_FLASH_ADDRESS_BASE + default_dbau1__flash_offset_read;
While (true)
{
If (dwStoreCount + dwDataPerLine> vtBuf. size ())
{
Break;
}
// Clear the check sum.
DwChkSum = 0;
// The type and length
Std: string strLine;
StrLine + = "S315 ";
DwChkSum + = 0x15;
// The buffer for storing the convert string
Std: vector <char> vtCnvt (9, 0 );
// The address
_ Ultoa (dwAddress, & vtCnvt [0], 16 );
StrLine + = reinterpret_cast <char *> (& vtCnvt [0]);
DwChkSum + = dwAddress> 24;
DwChkSum + = (dwAddress> 16) & 0xFF;
Dwchksum + = (dwaddress> 8) & 0xff;
Dwchksum + = dwaddress & 0xff;
Dwaddress + = dwdataperline;
// The data
For (INT I = 0; I <dwdataperline; I ++)
{
_ Ultoa (vtbuf [dwstorecount + I], & vtcnvt [0], 16 );
If (vtbuf [dwstorecount + I]> 0x0f)
{
Strline + = reinterpret_cast <char *> (& vtcnvt [0]);
}
Else
{
Strline = strline + "0" + reinterpret_cast <char *> (& vtcnvt [0]);
}
Dwchksum + = vtbuf [dwstorecount + I];
}
Dwstorecount + = dwdataperline;
// The check sum
DwChkSum = 0xFF-(dwChkSum & 0xFF );
_ Ultoa (dwChkSum, & vtCnvt [0], 16 );
If (dwChkSum> 0x0F)
{
StrLine + = reinterpret_cast <char *> (& vtCnvt [0]);
}
Else
{
StrLine = strLine + "0" + reinterpret_cast <char *> (& vtCnvt [0]);
}
StrLine + = "/r/n ";
// Store to the buffer
StrStore + = strLine;
}
// To upper
Transform (strStore. begin (), strStore. end (), strStore. begin (), toupper );
// Save the data to file
HANDLE hFile = CreateFile (TEXT ("bootsave. rec"), GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
DWORD dwWrite = 0;
WriteFile (hFile, & strStore [0], strStore. size (), & dwWrite, NULL );
CloseHandle (hFile );
Return 0;
}