亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ethdown.c

?? 這個是嵌入式arm系列的一個bootloader程序。對需要編寫bootloader的很有參考價值
?? C
?? 第 1 頁 / 共 2 頁
字號:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:  
    ethdown.c

Abstract:  
    This contains an example of a registered TFTP server 
 	process.  It is the EthDown() routine that handles the download
	of .BIN files to RAM.  

Functions:


Notes: 
--*/
#include <windows.h>
#include <halether.h>
#include <pehdr.h>
#include <romldr.h>

#include "loader.h"
#include "ethdown.h"
#include "xsc1bd.h"


extern void DumpDwords(PDWORD pdw, int len);
extern void OEMWriteDebugByte(unsigned char c);

#define BIN_FILE_TYPE	1
#define NB0_FILE_TYPE	2
#define BOOTLOADER		4
#define NKBIN			8
#define FLASHTARGET		16
DWORD dwPhysStart;		// image physical starting address
DWORD dwPhysLen;		// image physical length
DWORD dwOffset;
DWORD dwLaunchAddr;
DWORD v_FlashBlock;
BOOL bFirst=TRUE;
LPDWORD pdwRecStart=0, pdwRecNext=0;	// saved record address, length and checksum pointers
DWORD v_PacketNum=0;
DWORD v_FlashBlock;
DWORD fileType=0;
DWORD dwEBOOT_OFFSET;
int offset = 0;

#if defined ( ORGEBOOT_FLAG )
#define RAM_IMAGE_START 0x8008D000
#else
#define RAM_IMAGE_START 0x800C0000
#endif

#define FLASH_START		BOOT_FLASH_BASE_U_VIRTUAL   

DWORD VerifyCheckSum(void) {
	DWORD dwRecordLen;					// Total length of the record being processed
	DWORD dwRecordAddr;					// starting address of the record
	DWORD dwPerfectCRC;					// Theoretical CRC over the record being processed
	DWORD dwPartialCRC;					// Running CRC over the record being processed
	DWORD dwCurDataWord;				// Usually, this is the data word at the current position within the
	BYTE *pbCRC;						// Pointer used to run through memory to calculate CRC
	DWORD i;
	if (!pdwRecNext)
		return 0;
	EdbgOutputDebugString( "Verify checksums...\r\n");
	*pdwRecNext++=0;
	*pdwRecNext++=0;
	*pdwRecNext++=0;
	pdwRecNext=pdwRecStart;
	do 
	{
		dwRecordAddr=dwCurDataWord=*pdwRecNext++;
		dwRecordLen=*pdwRecNext++;
		dwPerfectCRC=*pdwRecNext++;
		if (dwRecordAddr && dwPerfectCRC) 
		{
			dwCurDataWord-= dwOffset;
			pbCRC = (BYTE *)dwCurDataWord;

			// Check the CRC
			dwPartialCRC = 0;
			for( i = 0; i < dwRecordLen; i++ )
				dwPartialCRC += *pbCRC++;
			if (dwPartialCRC != dwPerfectCRC) 
			{
				EdbgOutputDebugString( "Checksum Error Addr %Xh Len %Xh Expected %Xh Calculated %Xh\r\n",
					dwRecordAddr, dwRecordLen, dwPerfectCRC, dwPartialCRC);
				return 1;
			}
		}
	} while (dwRecordAddr && dwPerfectCRC);
	EdbgOutputDebugString( "Checksums verified correct.\r\n");
	return 0;
}

UINT16 EthDown( char *pszFileName, TFtpdCallBackOps Operation, BYTE *pbData, UINT16 *cwLength, char **ppszErrorMsg ) {

	volatile DWORD *pdwFlashCache;
	static BINFileParseStates BINFileParseState;
	// Because the signature of the BIN file is 7 bytes long and the length of a TFTP data packet
	//  is typically 512 bytes long, it is very probable that the last 4 byte DWORD will be broken
	//  across two TFTP packets.  I use these two variables to store the broken DWORD.
	static DWORD dwDataTailFromLastPacket;	// The beginning of the broken DWORD that has been
											//  retained from the last packet.
	static BYTE bNumBytesInDataTail;		// The number of bytes that have been carried over from
											//  the last packet.  Note that these are numbered starting
											//  from low byte to high byte because this is little endian.
											// DANGER - This may not be true on all processors.
	DWORD UNALIGNED *pdwBuffer;			// Pointer to current data position within the current TFTP packet
	int iBufferPos;				// Position of processing within the pbData packet buffer
	DWORD dwCurDataWord;		// Usually, this is the data word at the current position within the
								//  TFTP packet.  However, in order to compensate for the 7 byte preamble
								//  misalignment, this word may be "doctored" at the beginning of parsing
								//  a packet in order to include carry over byte(s) from the last packet.
	static DWORD UNALIGNED *pdwDest;		// Pointer to the address that the data is to be written too.
	static DWORD dwRecordLen;	// Total length of the record being processed
	static DWORD dwRecordPos;	// Position of processing within the record being processed
	static DWORD dwRecordAddr;	// starting address of the record
	static DWORD dwPerfectCRC;	// Theoretical CRC over the record being processed
	static BYTE *pbCRC;			// Pointer used to run through memory to calculate CRC
	DWORD i;

#if defined ( PLAT_LUBBOCK )
    //volatile BLR_REGS *BLR = (BLR_REGS *)FPGA_REGS_BASE_U_VIRTUAL;
	static int prev_percentComplete = -1;
	int percentComplete;
	int x,y,z;
#endif

	switch( Operation ) 
	{

		case TFTPD_OPEN:
			EdbgOutputDebugString( "EthDown::TFTPD_OPEN::%s\r\n", pszFileName );
			dwPhysLen = 0;
			break;

		case TFTPD_READ:
			*cwLength = 0;
			EdbgOutputDebugString( "EthDown::TFTPD_READ::%s returning %u bytes\r\n", pszFileName, *cwLength );
			break;

		case TFTPD_WRITE:
			// EdbgOutputDebugString( "EthDown::TFTPD_WRITE::%s with %u bytes\r\n", pszFileName, *cwLength );
 			// If it's the first packet, check the file type to determine 
  			// if this is a .BIN file or something else.  We assume that if 
  			// it's not in .BIN format, then it's the NB0 format.
  			if (v_PacketNum == 0)
  			{
  				if (memcmp( pbData, "B000FF\x0A", 7) == 0)
  				{
  					EdbgOutputDebugString( "Downloading .BIN file\r\n");
  					fileType |= BIN_FILE_TYPE;
  				}
  				else
  				{
  					EdbgOutputDebugString( "Downloading .NB0 file\r\n");
  					fileType |= (NB0_FILE_TYPE | FLASHTARGET);
  				}
  			}
  
  			if (fileType & NB0_FILE_TYPE)
  			{
  				pdwFlashCache =	(volatile DWORD *)RAM_IMAGE_START;
				
				// Copy data packet into SDRAM and increment index by 512 bytes (128 DWORDS)
  				memcpy((LPVOID)(pdwFlashCache+(v_PacketNum*128)), (LPVOID)pbData, 512); 
  				if (v_PacketNum % 100 == 0)
				{
  					EdbgOutputDebugString( "X" );
  				}
  				v_PacketNum++;

				// Write this image in place of the boot loader, so there is no offset.
#if defined ( RTECH_FLAG )
				fileType |= BOOTLOADER;
#endif
				dwEBOOT_OFFSET = 0x00000000;
 				break;
 			}
    
			iBufferPos = 0;
			pdwBuffer = (DWORD *)pbData;
			
			// If this is the beginning of the file
			if (dwPhysLen == 0) 
			{
				// I need to DWORD align the rest of the data so that the DWORD accesses won't cause
				//  processor exceptions
				*cwLength -= 7;
				pdwBuffer = (DWORD UNALIGNED *) (pbData + 7); // memmove( pbData, pbData + 7, *cwLength );

				dwPhysStart = *pdwBuffer++;
				dwOffset=0;
				dwPhysLen = *pdwBuffer++;
				iBufferPos = 8;

				// Normal NK.BIN RAM images will be located at RAM_IMAGE_START.
				// NK.BIN FLASH images and EBOOT.BIN FLASH images must be cached into RAM before flashing.  
				// We'll cache the data at RAM_IMAGE_START.
				// We'll calculate an offset to be added to dwPhysStart in order to cache each image at the same location.
				offset = RAM_IMAGE_START - dwPhysStart; 

				if (offset > 0) // downloading eboot.bin
				{
					EdbgOutputDebugString("\r\nDownloading bootloader image.\r\n");
					// Write this image in place of the bootloader.  
					// Therefore, there is no offset.
					dwEBOOT_OFFSET = 0x00000000;
					fileType |= (BOOTLOADER | FLASHTARGET);
				} else if (offset < 0) // downloading nk.bin (IMGFLASH=1)
				{
					EdbgOutputDebugString("\r\nDownloading operating system image for flash target.\r\n");
					// Write this image above the boot loader and configuration block.
					dwEBOOT_OFFSET = 0x00080000;
					fileType |= (NKBIN | FLASHTARGET);
				} else // downloading nk.bin (IMGFLASH=<not set>)
				{
					EdbgOutputDebugString("\r\nDownloading operating system image for SDRAM target.\r\n");
					fileType |= (NKBIN);
				}

				EdbgOutputDebugString("\r\nImage start: 0x%X length: 0x%X cache location: 0x%X\r\n", dwPhysStart, dwPhysLen, dwPhysStart + offset );
				
				// Go ahead and apply the offset to the image start address.
				dwPhysStart += offset;

				bNumBytesInDataTail = 0;
				BINFileParseState = BIN_PHYSADDR;

				pdwRecStart=pdwRecNext=(LPDWORD)(dwPhysStart+dwPhysLen-dwOffset);
			}
			// Check to see if this is the last packet and it's empty
			else if (*cwLength == 0)
				return 0;

			v_PacketNum++;

			// Pull the rest of the 32-bit data word that was started in the last packet
			if (bNumBytesInDataTail) {
				dwCurDataWord = 0;
				for( i = 0; i < 4UL-bNumBytesInDataTail; i++ )
					dwCurDataWord |= pbData[i] << ((i+bNumBytesInDataTail) * 8);
				dwCurDataWord |= dwDataTailFromLastPacket;

				// DWORD align the buffer
				*cwLength -= 4 - bNumBytesInDataTail;
				pdwBuffer = (DWORD UNALIGNED *) (pbData + (4-bNumBytesInDataTail)); //memmove( pbData, pbData + (4-bNumBytesInDataTail), *cwLength );
				iBufferPos = -4;
			}
			else
				dwCurDataWord = *pdwBuffer++;

#if defined ( PLAT_LUBBOCK )			
			percentComplete = (((v_PacketNum+1) * 512 * 100) / dwPhysLen);
			// Update the display only when the percent complete changes
			if (percentComplete != prev_percentComplete)
			{
				// Display percentage in decimal on the hex display
				x = percentComplete / 100;
				y = (percentComplete % 100) / 10;
				z = ((percentComplete % 100) % 10);
				//BLR->hex_led = ((x << 8) | (y << 4) | (z));
				prev_percentComplete = percentComplete;
			}
#endif
			// I'll keep looping until I get almost to the end of the packet buffer
			while( iBufferPos + 4 <= *cwLength ) 
			{
				switch( BINFileParseState ) 
				{
					case BIN_PHYSADDR:
						dwRecordAddr= dwCurDataWord;

						if (dwRecordAddr != 0)
							dwRecordAddr += offset;
						if (offset && dwRecordAddr)
							EdbgOutputDebugString("\r\nAddress fixup was 0x%X now 0x%X\r\n", dwCurDataWord, dwRecordAddr );

#ifdef ARM
						dwCurDataWord-= dwOffset;
#endif
						pdwDest = (DWORD UNALIGNED *)dwRecordAddr;
						pbCRC = (BYTE *)dwRecordAddr;

						BINFileParseState = BIN_PHYSLEN;
						break;
					case BIN_PHYSLEN:
						dwRecordLen = dwCurDataWord;
						BINFileParseState = BIN_CHECKSUM;
						break;
					case BIN_CHECKSUM:
						if (pdwDest == 0 && dwCurDataWord == 0) 
						{
							dwLaunchAddr = dwRecordLen;
#if defined ( PLAT_LUBBOCK )			
							// Display 100% on the display
							//BLR->hex_led = 0x100;
#endif
						}
						dwPerfectCRC = dwCurDataWord;
						dwRecordPos = 0;
						BINFileParseState = BIN_DATA;
						*pdwRecNext++=dwRecordAddr;
						*pdwRecNext++=dwRecordLen;
						*pdwRecNext++=dwPerfectCRC;
						break;
					case BIN_DATA:
						// If we aren't at the end of the record yet read another DWORD.  Note that the number of
						//  bytes in a record is guaranteed to always be DWORD aligned, so we can assume that there
						//  won't be a partial DWORD at the end of a record.
						*pdwDest++ = dwCurDataWord;
						dwRecordPos += 4;
						if (dwRecordPos < dwRecordLen)
							BINFileParseState = BIN_DATA;
						// If we have reached the end of the record
						else {
							BINFileParseState = BIN_PHYSADDR;
						}
						break;
				} // switch(BINFileParseState)
				dwCurDataWord = *pdwBuffer++;
				iBufferPos += 4;
			} // while not at end of buffer

			// Store the fragmented DWORD until we get the next packet
			bNumBytesInDataTail = (BYTE)(*cwLength - iBufferPos);
			dwDataTailFromLastPacket = dwCurDataWord;

			// Mask off the garbage that was picked up from the end of the packet buffer 
			switch( bNumBytesInDataTail ) {
				case 1:
					dwDataTailFromLastPacket &= 0x000000FFUL;
					break;
				case 2:
					dwDataTailFromLastPacket &= 0x0000FFFFUL;
					break;
				case 3:
					dwDataTailFromLastPacket &= 0x00FFFFFFUL;
					break;
			}

			break;

		case TFTPD_DESTROY:
			EdbgOutputDebugString( "EthDown::TFTPD_DESTROY::%s with %u bytes\r\n", pszFileName, *cwLength );
			for( i = 0; i < *cwLength; i++ ) {
				if (i > 0 && i % 8 == 0)
					EdbgOutputDebugString( "    " );
				if (i > 0 && i % 16 == 0)
					EdbgOutputDebugString( "\r\n" );

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区福利视频| 亚洲免费av在线| 国产精品久久午夜| 日本欧美韩国一区三区| 91一区二区三区在线观看| 日韩欧美国产成人一区二区| 亚洲欧美激情插| 国产精品123区| 日韩免费观看高清完整版| 亚洲精品国产一区二区三区四区在线| 狠狠色伊人亚洲综合成人| 欧美午夜宅男影院| 国产精品久久久爽爽爽麻豆色哟哟 | 日本一区二区三区电影| 天堂在线一区二区| 在线观看视频一区二区| 亚洲欧洲99久久| av在线播放不卡| 欧美激情一区二区三区在线| 狠狠色丁香久久婷婷综| 欧美一级精品在线| 蜜臀av一区二区在线免费观看| 欧亚洲嫩模精品一区三区| 亚洲精品美国一| 在线免费不卡电影| 亚洲一区二区美女| 欧美网站大全在线观看| 亚洲第一成年网| 欧美另类变人与禽xxxxx| 亚洲成精国产精品女| 欧美日韩国产高清一区二区三区 | 香蕉久久一区二区不卡无毒影院 | 国产成人精品aa毛片| 久久亚洲综合av| 国产在线播精品第三| 日韩欧美一区二区免费| 久久99精品国产麻豆不卡| 精品美女一区二区| 国产99久久久国产精品潘金网站| 国产亚洲精品精华液| 99r精品视频| 日韩中文字幕1| 日韩精品一区二区在线| 成人小视频在线| 亚洲精选免费视频| 91精品国产一区二区| 久久99国产精品麻豆| 国产欧美精品区一区二区三区| 欧美日韩三级一区二区| 免费成人小视频| 国产欧美日韩久久| 日本大香伊一区二区三区| 日韩avvvv在线播放| 久久影音资源网| 色呦呦国产精品| 麻豆精品在线播放| 国产精品久久久久久亚洲毛片 | 欧美一区二区三区免费视频| 国内精品视频666| 国产精品国产三级国产aⅴ中文| 一道本成人在线| 久久精品av麻豆的观看方式| 国产精品素人视频| 欧美日本国产一区| 国产91富婆露脸刺激对白| 亚洲一区二区黄色| 亚洲第一av色| 日本一区二区三区在线观看| 欧美唯美清纯偷拍| 国产盗摄一区二区| 五月婷婷激情综合网| 欧美国产日韩在线观看| 3d成人h动漫网站入口| 不卡欧美aaaaa| 老色鬼精品视频在线观看播放| 国产精品国产a| 欧美电视剧在线看免费| 欧洲一区二区三区在线| 成人午夜又粗又硬又大| 日本不卡在线视频| 亚洲精品国久久99热| 久久久久久**毛片大全| 在线91免费看| 91免费视频观看| 国产成人h网站| 极品少妇一区二区| 五月婷婷综合在线| 日本成人在线一区| 亚洲成人激情自拍| 亚洲视频在线观看三级| 欧美国产禁国产网站cc| 精品99999| 日韩免费视频一区二区| 在线成人免费观看| 欧美日韩中文另类| 在线免费不卡电影| 在线观看视频一区二区欧美日韩 | 看电视剧不卡顿的网站| 亚洲影视在线播放| 亚洲图片有声小说| 亚洲午夜av在线| 亚洲在线视频一区| 一区二区三区欧美| 一卡二卡欧美日韩| 一区二区高清免费观看影视大全| 国产精品久久久久久妇女6080| 国产欧美日韩另类一区| 国产精品视频yy9299一区| 亚洲摸摸操操av| 一区二区三区四区不卡在线| 1000部国产精品成人观看| 国产精品久久久久久亚洲伦| 1000精品久久久久久久久| 一区精品在线播放| 玉足女爽爽91| 丝袜脚交一区二区| 日本中文字幕一区二区有限公司| 日韩精品欧美精品| 国产在线精品不卡| 国产精品99久久久久久久女警| 国产成人啪免费观看软件| 成人免费视频caoporn| 91丨porny丨国产| 欧美丝袜自拍制服另类| 91精品中文字幕一区二区三区| 欧美一级精品大片| 国产女同性恋一区二区| 亚洲视频一区二区免费在线观看| 一区二区三区中文在线| 五月天激情小说综合| 丁香天五香天堂综合| 成人动漫在线一区| 精品污污网站免费看| 欧美一区二区三区四区久久| 久久综合色一综合色88| 国产精品福利一区二区三区| 亚洲精品视频在线观看网站| 肉肉av福利一精品导航| 国产成人免费视频一区| 色欲综合视频天天天| 91精品国产综合久久蜜臀| 精品1区2区在线观看| 中文字幕日韩一区| 美美哒免费高清在线观看视频一区二区| 国内精品嫩模私拍在线| 色久优优欧美色久优优| 日韩欧美区一区二| 亚洲免费观看高清在线观看| 秋霞影院一区二区| aa级大片欧美| 日韩欧美精品三级| 亚洲精品网站在线观看| 久久成人综合网| 在线亚洲精品福利网址导航| 亚洲午夜久久久久久久久久久 | 色综合久久88色综合天天免费| 91精品国产欧美一区二区成人| 国产欧美精品一区二区三区四区| 亚洲一区二区三区四区在线 | 欧美性欧美巨大黑白大战| 久久久久久久久久美女| 午夜视频一区二区| 成人av在线一区二区| 精品国产伦一区二区三区观看方式| 一区二区三区产品免费精品久久75| 麻豆国产欧美日韩综合精品二区| 99精品久久只有精品| 欧美成va人片在线观看| 亚洲一区二区三区自拍| 成人av电影在线播放| 久久久久久日产精品| 日韩影院精彩在线| 日本精品一级二级| 亚洲午夜三级在线| 色美美综合视频| 亚洲国产精品高清| 国产尤物一区二区在线| 欧美一级片在线| 午夜精品免费在线| 在线一区二区三区四区五区| 国产精品私人影院| 国产成人av电影在线播放| 精品日韩成人av| 久久精工是国产品牌吗| 91精品国产乱码久久蜜臀| 亚洲电影一区二区三区| 在线欧美一区二区| 一区二区三区四区乱视频| 91丨九色丨蝌蚪丨老版| 亚洲人成网站色在线观看| 成人av免费网站| 国产精品福利一区二区| 成人国产视频在线观看| 国产精品久久久久天堂| 91原创在线视频| 亚洲女同一区二区| 在线精品视频免费播放| 亚洲国产欧美日韩另类综合| 欧美日韩免费高清一区色橹橹 | 久久精品噜噜噜成人88aⅴ|