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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ethdown.c

?? 這個(gè)是嵌入式arm系列的一個(gè)bootloader程序。對需要編寫bootloader的很有參考價(jià)值
?? 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" );

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲成a人v欧美综合天堂下载| 日韩欧美一级二级三级 | 久久精品无码一区二区三区| 国产精品污www在线观看| 一区二区三区日韩| 麻豆免费精品视频| av电影一区二区| 欧美日韩国产影片| 国产偷v国产偷v亚洲高清| 一区二区三区在线视频观看58| 日本少妇一区二区| 99国内精品久久| 欧美美女一区二区在线观看| 国产日韩欧美综合一区| 亚洲国产裸拍裸体视频在线观看乱了| 麻豆91在线看| 91精品1区2区| 久久欧美一区二区| 亚洲一区二区在线免费看| 国内精品自线一区二区三区视频| 在线一区二区视频| 精品福利一区二区三区免费视频| 综合在线观看色| 久久精品国产精品亚洲精品| 日本二三区不卡| 久久人人97超碰com| 亚洲午夜久久久久| 成人av电影在线| 欧美mv日韩mv国产网站app| 一区二区三区在线免费| 国产一区999| 欧美日韩成人激情| 蜜桃av一区二区| 欧美日韩一二区| 亚洲欧美国产77777| 国产一区二区三区电影在线观看| 久久久www成人免费无遮挡大片| 亚洲日本丝袜连裤袜办公室| 韩国三级在线一区| 色综合激情五月| 国产清纯在线一区二区www| 亚瑟在线精品视频| 色狠狠色狠狠综合| 国产精品久久久久久久久晋中| 精品一区二区三区在线播放| 欧美日韩精品一区视频| 亚洲精品国产一区二区三区四区在线| 久久精品久久综合| 欧美一区二区视频在线观看| 国产精品第五页| 国产白丝精品91爽爽久久| 精品国产一区二区国模嫣然| 蜜桃一区二区三区在线观看| 欧美日韩国产片| 一卡二卡三卡日韩欧美| 91在线精品秘密一区二区| 久久久电影一区二区三区| 蜜臀久久久99精品久久久久久| 欧美少妇xxx| 一区二区三区小说| 91美女在线看| 亚洲视频中文字幕| 91在线视频免费观看| 最好看的中文字幕久久| 99久久免费国产| 中文字幕一区二区日韩精品绯色| 国产精品18久久久久| 精品国产网站在线观看| 麻豆精品在线看| 精品国产亚洲在线| 国产一区二区精品在线观看| 久久综合九色综合欧美就去吻| 久久激五月天综合精品| 欧美一区二区高清| 久久99精品久久久久婷婷| 日韩精品一区二区三区视频播放| 捆绑紧缚一区二区三区视频| 欧美成人性战久久| 激情综合五月天| 久久毛片高清国产| 成人在线视频一区| 亚洲欧美精品午睡沙发| 91美女视频网站| 午夜精品成人在线视频| 欧美一区二区三区思思人| 韩日av一区二区| 国产情人综合久久777777| 99riav一区二区三区| 亚洲精品美国一| 欧美精品第1页| 久久精品999| 亚洲国产精品99久久久久久久久| 国产91精品露脸国语对白| 亚洲三级免费观看| 欧美色倩网站大全免费| 蜜臂av日日欢夜夜爽一区| 久久精品视频网| 色综合中文字幕国产| 午夜伦欧美伦电影理论片| 日韩欧美中文一区二区| 国产精品白丝jk黑袜喷水| 成人免费小视频| 欧美区一区二区三区| 激情丁香综合五月| 18成人在线观看| 9191久久久久久久久久久| 国产麻豆一精品一av一免费| 自拍偷拍亚洲欧美日韩| 欧美日韩色一区| 国内成人精品2018免费看| 综合在线观看色| 中文字幕一区二| 欧美日韩二区三区| 国产精品香蕉一区二区三区| 一区二区激情小说| 精品国产91亚洲一区二区三区婷婷 | 亚洲乱码中文字幕综合| 欧美日韩一级大片网址| 国产一区二区三区免费播放| 国产精品久久久久四虎| 欧美日韩国产免费一区二区 | 国产日韩一级二级三级| 在线中文字幕不卡| 黄色精品一二区| 玉米视频成人免费看| 久久亚洲欧美国产精品乐播| 一本一道综合狠狠老| 美女视频网站久久| 一区二区三区四区视频精品免费 | 国产一本一道久久香蕉| 亚洲品质自拍视频| 26uuu亚洲综合色| 欧美亚洲国产一区在线观看网站 | 亚洲欧洲三级电影| 日韩视频在线你懂得| 97精品久久久午夜一区二区三区| 日本成人在线电影网| 自拍偷在线精品自拍偷无码专区| 欧美变态tickling挠脚心| 欧美制服丝袜第一页| 国产在线播放一区二区三区| 亚洲一卡二卡三卡四卡| 国产精品污www在线观看| 日韩欧美精品在线| 欧美日韩亚洲国产综合| 99麻豆久久久国产精品免费优播| 蜜桃91丨九色丨蝌蚪91桃色| 亚洲综合丁香婷婷六月香| 国产精品色婷婷| 久久综合色综合88| 欧美一区二区在线观看| 欧美自拍偷拍一区| av激情亚洲男人天堂| 国产真实乱对白精彩久久| 亚洲成人资源网| 一区二区三区高清| 国产精品私人影院| 久久精品在线免费观看| 日韩欧美成人午夜| 欧美高清性hdvideosex| 日本韩国精品在线| 99国产麻豆精品| 99精品桃花视频在线观看| 国产馆精品极品| 国模套图日韩精品一区二区| 美女国产一区二区| 奇米影视在线99精品| 婷婷开心久久网| 亚洲成人午夜电影| 亚洲第一福利一区| 亚洲国产日韩一级| 亚洲国产精品久久一线不卡| 亚洲另类一区二区| 亚洲人一二三区| 亚洲激情五月婷婷| 亚洲人精品午夜| 最新欧美精品一区二区三区| 国产精品乱人伦| 久热成人在线视频| 免费在线观看不卡| 久久se精品一区精品二区| 麻豆精品在线视频| 国产一区二区三区日韩| 国产成人丝袜美腿| 成人毛片在线观看| aa级大片欧美| 91福利区一区二区三区| 欧美在线|欧美| 欧美美女黄视频| 日韩欧美在线综合网| 久久一区二区三区四区| 久久久久国产一区二区三区四区| 精品福利在线导航| 欧美国产日韩在线观看| 亚洲人成影院在线观看| 亚洲愉拍自拍另类高清精品| 亚洲午夜精品在线| 裸体一区二区三区| 成人小视频免费观看| 99精品1区2区|