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

📄 atlasmgr2dlg.cpp

📁 cell phone source code
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		if(!GetNorCMD(szNorflashType))
		{
			JTAG_ErrMsg("Read the nor flash commond error");

		fclose(fp);
		return false;
		}
		//Init NorFlash
		NOR_Init();

		//Read NorFlash ID
		id = NOR_ReadID(g_8BitsNor);
		g_NorID = id;
		szDevInfo.Format("FLASH_ID: 0x%x. Download 150KB files maybe need 16 mins.", id);
		GetDlgItem(IDC_DEV_INFO)->SetWindowText(szDevInfo);
		
		//Check ID
		bValidID = NOR_ValidID(id);
		/*
		BOOL bread = TRUE;
		unsigned char data;
		int i = 0;
		while(bread)
		{
			data = NorFlash_RByte(i++);
		}
		// */
		/*
		unsigned char data[152*1024];
		unsigned short WordToWrite;
		for(int k=0;k<152*1024;k++)
		{
			//fread(&WordToWrite, 2, 1, fp);
			data[k]=NorFlash_RByte(k);
		}
		CFile file;
		file.Open("c:\\aa.txt", CFile::modeWrite|CFile::modeCreate);
		file.Write(data, 152*1024);
		file.Close();
		// */
	}


	if(!bValidID)
	{
    JTAG_ErrMsg("Read Flash ID Error! Please check follow items:\n \
                 1. Please make sure the Chip and FlashType settings are correct. \n \
                 2. If your flash enabled the write-protection function default, \n \
                 please make sure your Disable NF-WP settings are correct. \n \
                 3. Please check your flash type: \n \
                 for Nand Flash, we only support: SAMSUNG, Toshiba, Micron, Intel, ST, Spectek & HYNIX \n \
                 for Nor Flash, please check the manufacture Id");
    

		fclose(fp);
		return false;
	}

	if(ATLAS_FLASHTYPE_NAND == m_nFlashType)
	{
		NF_TypeInfo nfti = NF_GetType(id);

		if(nfti.id == 0)
		{
			JTAG_ErrMsg("Invalid nand flash ID!");
			return false;
		}

		long programSize  = 0;
		long curBlockSize = 0;
		long blockSize	  = nfti.blockSize;
		long blockIndex   = 0;
		long pageIndex	  = 0;
		long pageSize     = 512;
		unsigned char blockBuf[2048*64];
		unsigned char spareBuf[64];
		unsigned char* pagePtr;
		int	 numRead = 0;
		unsigned char page[2048];

		if(nfti.block == NF_BLOCK_LARGE)
		{
			pageSize = 2048;
		}

		//Initialize spare buffer
		//NBoot Bad Block mark 0xfc
		int j;
		for(j = 0; j < 64; j++)
		{
			spareBuf[j] = 0xff;
		}

#if 0
		if(nfti.bits == NF_BITS_X08)
		{
			spareBuf[nfti.badmarkIndex - nfti.pageSize] = 0xfc;
		}
		else
		{
			spareBuf[nfti.badmarkIndex - nfti.pageSize] = 0xfc;
			spareBuf[nfti.badmarkIndex - nfti.pageSize+1] = 0xfc;
		}
#else
		spareBuf[4] = 0xfc;
		spareBuf[5] = 0x0;
#endif

		//ProgressBar
		CProgressDlg progress;
		progress.Create(this);
		progress.SetWindowText(szFile);
		progress.SetStep(1);	
		progress.SetRange(0, (imageSize + pageSize-1) / pageSize);

		progress.StepIt();
		
		while(programSize < imageSize)
		{
			//Read one Block from File
			if( (programSize + blockSize) <= imageSize)
			{
				curBlockSize = blockSize;
			}
			else
			{
				curBlockSize = imageSize - programSize;
			}
			
			programSize += curBlockSize;

			//Read Data from file
			//ReadBlock(blockBuf, blockSize,fp);
			numRead = fread(blockBuf, 1, curBlockSize, fp);

			int cnt=0;
			int TRY_TIMES=2;

			for(cnt=0; cnt<TRY_TIMES; cnt++ )
			{
				//Erase Block
				while( !NF_EraseBlock(blockIndex, nfti) )
				{
					JTAG_ErrMsg("Erase Block Failed!");
					if (0 == cnt) 
					{
						blockIndex++;
					}			
				}

				//Check Erase 
				NF_ReadPage(0, 0, page, 0, nfti);
				long i;

				for(i = 0; i < pageSize; i++)
				{
					if(page[i] != 0xff)
					{
						if((cnt+1) >= TRY_TIMES)
						{
							JTAG_ErrMsg("Check Erase Failed!");
							fclose(fp);
							return false;
						}
						else
						{
							//szDevInfo.Format("Erase Fail times: %d", cnt);
							//GetDlgItem(IDC_DEV_INFO)->SetWindowText(szDevInfo);
							//blockIndex = 0;
							break;
						}

					}
					else
					{
						cnt = TRY_TIMES;
						break;
					}
				}
			}


			//Write Pages of current block
			pageIndex = 0;

			int ret = 1;
			while(curBlockSize > 0)
			{
				pagePtr = blockBuf + pageSize * pageIndex;
				if(pageIndex == 0)
				{
					ret = NF_WritePage(blockIndex, pageIndex, pagePtr, spareBuf, nfti);
				}
				else
				{
					ret = NF_WritePage(blockIndex, pageIndex, pagePtr, 0, nfti);
				}

				curBlockSize -= pageSize;
				pageIndex++;

				if ((!ret) || (progress.CheckCancelButton() == TRUE))
				{
					fclose(fp);
					return false;
				}

				progress.StepIt();
			}

			blockIndex++;
		}//while
	}
	else //ATLAS_FLASHTYPE_NOR
	{
		unsigned long TARGET_ADDR;
		unsigned long ADDROFFSET;

		//////////////////////////////////////////////////////////////////////////
		//SST NorFlash
		TARGET_ADDR = 0;
		ADDROFFSET = 0;
		//////////////////////////////////////////////////////////////////////////
		
		long programSize  = 0;
		int	 numRead = 0;
		
		long SectorSize	  = 0xfff;
		long StepSize     = SectorSize;

		unsigned long AddToWrite=0;
		unsigned char ByteToWrite;
		unsigned short WordToWrite;
		int WritedBytesInSector = 0;

		//ProgressBar
		CProgressDlg progress;
		progress.Create(this);
		progress.SetWindowText(szFile);
		progress.SetStep(1);	
		progress.SetRange(0, (imageSize + StepSize-1) / StepSize);

		AddToWrite = TARGET_ADDR + ADDROFFSET;

		//erase chip
		NorFlash_EChip();
		//szDevInfo.Format("Chip Erase Successed!");
		//GetDlgItem(IDC_DEV_INFO)->SetWindowText(szDevInfo);
		
		progress.StepIt();
		//NorFlash_EnterBypass();
		while(programSize < imageSize)
		{
			bool ret = true;
			if(8 == g_8BitsNor)
			{
				programSize++;
				//Read one byte from file
				numRead = fread(&ByteToWrite, 1, 1, fp);
				
				
				ret = NorFlash_WByte(AddToWrite,ByteToWrite);
				WritedBytesInSector++;
			}
			else
			{
				programSize+=2;
				//numRead = fread(&ByteToWrite, 1, 1, fp);
				numRead = fread(&WordToWrite, 2, 1, fp);
				//WordToWrite = (WordToWrite<<8) | ByteToWrite;
				ret = NorFlash_WWord(AddToWrite, WordToWrite);
				
				WritedBytesInSector+=2;
			}

			if ((!ret) || (progress.CheckCancelButton() == TRUE))
			{
				fclose(fp);
				return false;
			}	

			
			if (WritedBytesInSector >= StepSize) 
			{
				progress.StepIt();
				WritedBytesInSector = 0;
			}

			AddToWrite++;
		}
	}
	//NorFlash_ExitBypass();
	//Close file
	fclose(fp);

	return true;
}


void CAtlasMgr2Dlg::OnDumpNboot() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	if(!AtlasSetNandCS(m_nCs))
	{
		return;
	}	
	AtlasGetNfInfo(m_nCs);
	
	dwBytesPerSector=1<<g_DumpNFInfo.ucSectorSizeBits;
	dwSectorsPerBlock=1<<g_DumpNFInfo.ucSectorsPerBlockBits;
	dwBlocks=g_DumpNFInfo.dwTotalSize/(1<<g_DumpNFInfo.ucBlockSizeBits);
	dwDataWidth=(DWORD)g_DumpNFInfo.ucDataWidth;
	dwSpareDataLength=(DWORD)g_DumpNFInfo.dwSpareDataLength;

	if(!AtlasDumpNandFlashBlocks(this,m_nCs, 0, 1,FALSE))
	{
		AfxMessageBox("Dump NBOOT failed!");
		return;
	}
	//AfxMessageBox("Not supported at this time!");
}

void CAtlasMgr2Dlg::OnDumpEboot() 
{
	// TODO: Add your control notification handler code here
	DWORD dwEbootStart;
	DWORD dwEbootBlockCount;
	UpdateData(TRUE);
	if(ATLAS_FLASHTYPE_NAND == m_nFlashType)
	{
		if(!AtlasSetNandCS(m_nCs))
		{
			return;
		}	
		AtlasGetNfInfo(m_nCs);
		
		dwBytesPerSector=1<<g_DumpNFInfo.ucSectorSizeBits;
		dwSectorsPerBlock=1<<g_DumpNFInfo.ucSectorsPerBlockBits;
		dwBlocks=g_DumpNFInfo.dwTotalSize/(1<<g_DumpNFInfo.ucBlockSizeBits);
		dwDataWidth=(DWORD)g_DumpNFInfo.ucDataWidth;
		dwSpareDataLength=(DWORD)g_DumpNFInfo.dwSpareDataLength;
		
		if(AtlasGetEBOOTPositon(m_nCs,&dwEbootStart,&dwEbootBlockCount))
		{
			AtlasDumpNandFlashBlocks(this,m_nCs,dwEbootStart,dwEbootBlockCount,TRUE);
		}
	}
	else
	{
	}
	//AfxMessageBox("Not supported at this time!");
}
void CAtlasMgr2Dlg::OnDumpBlocks() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	DWORD dwStartBlock,dwReadBlockCount;
	
	if(!AtlasSetNandCS(m_nCs))
	{
		return;
	}	
	AtlasGetNfInfo(m_nCs);
	
	dwBytesPerSector=1<<g_DumpNFInfo.ucSectorSizeBits;
	dwSectorsPerBlock=1<<g_DumpNFInfo.ucSectorsPerBlockBits;
	dwBlocks=g_DumpNFInfo.dwTotalSize/(1<<g_DumpNFInfo.ucBlockSizeBits);
	dwDataWidth=(DWORD)g_DumpNFInfo.ucDataWidth;
	dwSpareDataLength=(DWORD)g_DumpNFInfo.dwSpareDataLength;
	
	if(m_nDumpNFStart>m_nDumpNFEnd)
	{
		AfxMessageBox("Start block index can't overrun end block index!");
		return;
	}
	if(m_wholechip)
	{
		dwStartBlock=m_nDumpNFStart;
		dwReadBlockCount=m_nDumpNFEnd-m_nDumpNFStart+1;
	}
	else
	{//WholeChip
		dwStartBlock=0;
		dwReadBlockCount=dwBlocks;
	}
	if((dwReadBlockCount+dwStartBlock)>dwBlocks)
	{
		AfxMessageBox("The read blocks can't overrun last block!");
		return;
	}
	if(!AtlasDumpNandFlashBlocks(this,m_nCs, dwStartBlock, dwReadBlockCount,FALSE))
	{
		AfxMessageBox("Dump NF failed!");
		return;
	}

}































































⌨️ 快捷键说明

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