?? main.c
字號:
//
// 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.
//
//
//
// 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.
//
#include <windows.h>
#include <bsp.h>
#include <ethdbg.h>
#include <fmd.h>
#include <pcireg.h>
#include <oal_blserial.h>
#include <usbdbgser.h>
#include <usbdbgrndis.h>
#include "loader.h"
#include "usb.h"
#include "fmd_lb.h"
#include "fmd_sb.h"
#include "s3c6410_ldi.h"
#include "s3c6410_display_con.h"
#include "InitialImage_rgb16_320x240.h"
// For USB Download function
extern BOOL InitializeUSB();
extern void InitializeInterrupt();
extern BOOL UbootReadData(DWORD cbData, LPBYTE pbData);
extern void OTGDEV_SetSoftDisconnect();
static void InitializeOTGCLK(void);
// To change Voltage for higher clock.
extern void LTC3714_Init();
extern void LTC3714_VoltageSet(UINT32,UINT32,UINT32);
// For Ethernet Download function.
char *inet_ntoa(DWORD dwIP);
DWORD inet_addr( char *pszDottedD );
BOOL EbootInitEtherTransport(EDBG_ADDR *pEdbgAddr, LPDWORD pdwSubnetMask,
BOOL *pfJumpImg,
DWORD *pdwDHCPLeaseTime,
UCHAR VersionMajor, UCHAR VersionMinor,
char *szPlatformString, char *szDeviceName,
UCHAR CPUId, DWORD dwBootFlags);
BOOL EbootEtherReadData(DWORD cbData, LPBYTE pbData);
EDBG_OS_CONFIG_DATA *EbootWaitForHostConnect (EDBG_ADDR *pDevAddr, EDBG_ADDR *pHostAddr);
void SaveEthernetAddress();
// Eboot Internal static function
static void InitializeDisplay(void);
static void InitializeRTC(void);
static void SpinForever(void);
static USHORT GetIPString(char *);
static USHORT InputNumericalString(CHAR *szCount, UINT32 length);
// Globals
//
DWORD g_ImageType;
DWORD g_dwMinImageStart; // For MultiBin, we will use lowest regions as XIPKERNEL
MultiBINInfo g_BINRegionInfo;
PBOOT_CFG g_pBootCfg;
UCHAR g_TOC[LB_PAGE_SIZE];
const PTOC g_pTOC = (PTOC)&g_TOC;
DWORD g_dwTocEntry;
BOOL g_bBootMediaExist = FALSE;
BOOL g_bDownloadImage = TRUE;
BOOL g_bWaitForConnect = TRUE;
BOOL * g_bCleanBootFlag;
BOOL * g_bHiveCleanFlag;
BOOL * g_bFormatPartitionFlag;
DWORD g_DefaultBootDevice = BOOT_DEVICE_USB_DNW;
//for KITL Configuration Of Args
OAL_KITL_ARGS *g_KITLConfig;
//for Device ID Of Args
UCHAR *g_DevID;
EDBG_ADDR g_DeviceAddr; // NOTE: global used so it remains in scope throughout download process
// since eboot library code keeps a global pointer to the variable provided.
DWORD wNUM_BLOCKS;
void main(void)
{
//GPIOTest_Function();
OTGDEV_SetSoftDisconnect();
BootloaderMain();
// Should never get here.
//
SpinForever();
}
static void Delay(UINT32 count)
{
volatile int i, j = 0;
volatile static int loop = S3C6410_ACLK/100000;
for(;count > 0;count--)
for(i=0;i < loop; i++) { j++; }
}
static USHORT GetIPString(char *szDottedD)
{
USHORT InChar = 0;
USHORT cwNumChars = 0;
while(!((InChar == 0x0d) || (InChar == 0x0a)))
{
InChar = OEMReadDebugByte();
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
// If it's a number or a period, add it to the string.
//
if (InChar == '.' || (InChar >= '0' && InChar <= '9'))
{
if (cwNumChars < 16) // IP string cannot over 15. xxx.xxx.xxx.xxx
{
szDottedD[cwNumChars++] = (char)InChar;
OEMWriteDebugByte((BYTE)InChar);
}
}
// If it's a backspace, back up.
//
else if (InChar == 8)
{
if (cwNumChars > 0)
{
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
return cwNumChars;
}
/*
@func void | SetIP | Accepts IP address from user input.
@rdesc N/A.
@comm
@xref
*/
static void SetIP(PBOOT_CFG pBootCfg)
{
CHAR szDottedD[16]; // The string used to collect the dotted decimal IP address.
USHORT cwNumChars = 0;
//USHORT InChar = 0;
EdbgOutputDebugString("\r\nEnter new IP address: ");
cwNumChars = GetIPString(szDottedD);
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars && cwNumChars < 16)
{
szDottedD[cwNumChars] = '\0';
pBootCfg->EdbgAddr.dwIP = inet_addr(szDottedD);
}
else
{
EdbgOutputDebugString("\r\nIncorrect String");
}
}
/*
@func void | SetMask | Accepts subnet mask from user input.
@rdesc N/A.
@comm
@xref
*/
static void SetMask(PBOOT_CFG pBootCfg)
{
CHAR szDottedD[16]; // The string used to collect the dotted masks.
USHORT cwNumChars = 0;
//USHORT InChar = 0;
EdbgOutputDebugString("\r\nEnter new subnet mask: ");
cwNumChars = GetIPString(szDottedD);
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars && cwNumChars < 16)
{
szDottedD[cwNumChars] = '\0';
pBootCfg->SubnetMask = inet_addr(szDottedD);
}
else
{
EdbgOutputDebugString("\r\nIncorrect String");
}
}
/*
@func void | SetDelay | Accepts an autoboot delay value from user input.
@rdesc N/A.
@comm
@xref
*/
static void SetDelay(PBOOT_CFG pBootCfg)
{
CHAR szCount[16];
USHORT cwNumChars = 0;
USHORT InChar = 0;
EdbgOutputDebugString("\r\nEnter maximum number of seconds to delay [1-255]: ");
cwNumChars = InputNumericalString(szCount, 16);
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars)
{
pBootCfg->BootDelay = atoi(szCount);
if (pBootCfg->BootDelay > 255)
{
pBootCfg->BootDelay = 255;
}
else if (pBootCfg->BootDelay < 1)
{
pBootCfg->BootDelay = 1;
}
}
}
static ULONG mystrtoul(PUCHAR pStr, UCHAR nBase)
{
UCHAR nPos=0;
BYTE c;
ULONG nVal = 0;
UCHAR nCnt=0;
ULONG n=0;
// fulllibc doesn't implement isctype or iswctype, which are needed by
// strtoul, rather than including coredll code, here's our own simple strtoul.
if (pStr == NULL)
return(0);
for (nPos=0 ; nPos < strlen(pStr) ; nPos++)
{
c = tolower(*(pStr + strlen(pStr) - 1 - nPos));
if (c >= '0' && c <= '9')
c -= '0';
else if (c >= 'a' && c <= 'f')
{
c -= 'a';
c = (0xa + c);
}
for (nCnt = 0, n = 1 ; nCnt < nPos ; nCnt++)
{
n *= nBase;
}
nVal += (n * c);
}
return(nVal);
}
static void CvtMAC(USHORT MacAddr[3], char *pszDottedD )
{
DWORD cBytes;
char *pszLastNum;
int atoi (const char *s);
int i=0;
BYTE *p = (BYTE *)MacAddr;
// Replace the dots with NULL terminators
pszLastNum = pszDottedD;
for(cBytes = 0 ; cBytes < 6 ; cBytes++)
{
while(*pszDottedD != '.' && *pszDottedD != '\0')
{
pszDottedD++;
}
if (pszDottedD == '\0' && cBytes != 5)
{
// zero out the rest of MAC address
while(i++ < 6)
{
*p++ = 0;
}
break;
}
*pszDottedD = '\0';
*p++ = (BYTE)(mystrtoul(pszLastNum, 16) & 0xFF);
i++;
pszLastNum = ++pszDottedD;
}
}
static void SetCS8900MACAddress(PBOOT_CFG pBootCfg)
{
CHAR szDottedD[24];
USHORT cwNumChars = 0;
USHORT InChar = 0;
memset(szDottedD, '0', 24);
EdbgOutputDebugString ( "\r\nEnter new MAC address in hexadecimal (hh.hh.hh.hh.hh.hh): ");
while(!((InChar == 0x0d) || (InChar == 0x0a)))
{
InChar = OEMReadDebugByte();
InChar = tolower(InChar);
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
// If it's a hex number or a period, add it to the string.
//
if (InChar == '.' || (InChar >= '0' && InChar <= '9') || (InChar >= 'a' && InChar <= 'f'))
{
if (cwNumChars < 17)
{
szDottedD[cwNumChars++] = (char)InChar;
OEMWriteDebugByte((BYTE)InChar);
}
}
else if (InChar == 8) // If it's a backspace, back up.
{
if (cwNumChars > 0)
{
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
EdbgOutputDebugString ( "\r\n");
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars)
{
szDottedD[cwNumChars] = '\0';
CvtMAC(pBootCfg->EdbgAddr.wMAC, szDottedD);
EdbgOutputDebugString("INFO: MAC address set to: %x:%x:%x:%x:%x:%x\r\n",
pBootCfg->EdbgAddr.wMAC[0] & 0x00FF, pBootCfg->EdbgAddr.wMAC[0] >> 8,
pBootCfg->EdbgAddr.wMAC[1] & 0x00FF, pBootCfg->EdbgAddr.wMAC[1] >> 8,
pBootCfg->EdbgAddr.wMAC[2] & 0x00FF, pBootCfg->EdbgAddr.wMAC[2] >> 8);
}
else
{
EdbgOutputDebugString("WARNING: SetCS8900MACAddress: Invalid MAC address.\r\n");
}
}
static void MarkReservedBlockWithBadBlock()
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -