main.c
来自「SAMSUNG S3C6410 CPU BSP for winmobile6」· C语言 代码 · 共 1,638 行 · 第 1/4 页
C
1,638 行
//
// 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 "loader.h"
#include "usb.h"
#include <XsrTypes.h>
#include <BML.h>
#include "s3c6410_ldi.h"
#include "s3c6410_display_con.h"
#include "InitialImage_rgb16_320x240.h"
// For USB Download function.
extern BOOL UbootReadData (DWORD cbData, LPBYTE pbData);
extern BOOL InitUSB ();
extern void Isr_Init();
// For USB 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);
extern UINT32 BLFlashDownload();
// End ***************************************
// Display Function
static void InitializeDisplay(void);
// Globals
//
DWORD EdbgDebugZone;
DWORD g_ImageType;
MultiBINInfo g_BINRegionInfo;
PBOOT_CFG g_pBootCfg;
UCHAR g_TOC[NAND_SECTOR_SIZE];
const PTOC g_pTOC = (PTOC)&g_TOC;
DWORD g_dwTocEntry;
BOOL g_bBootMediaExist = FALSE;
BOOL g_bDownloadImage = TRUE;
BOOLEAN g_bUSBDownload = FALSE;
// jylee
BOOLEAN g_bT32Download = FALSE;
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;
// External definitions.
//
//extern const BYTE ScreenBitmap[];
/*
@func void | SpinForever | Halts execution (used in error conditions).
@rdesc
@comm
@xref
*/
static void SpinForever(void)
{
EdbgOutputDebugString("SpinForever...\r\n");
while(1)
{
;
}
}
/*
@func void | main | Samsung bootloader C routine entry point.
@rdesc N/A.
@comm
@xref
*/
void main(void)
{
// Clear LEDs.
//
// OEMWriteDebugLED(0, 0xF);
// Common boot loader (blcommon) main routine.
//
// OALMSG(1, (TEXT("\r\n============---------------\r\n")));
volatile UINT32 uTemp;
uTemp = Inp32SYSC(0x900);
Outp32SYSC(0x900, uTemp|(1<<16)); // unmask usb signal
// OTGDEV_InitPhyCon();
// OTGDEV_SoftResetCore();
// OTGDEV_InitCore();
// OTGDEV_InitOtg(USB_HIGH);
OTGDEV_SetSoftDisconnect();
BootloaderMain();
// Should never get here.
//
SpinForever();
}
/*
@func void | SetIP | Accepts IP address from user input.
@rdesc N/A.
@comm
@xref
*/
static void SetIP(PBOOT_CFG pBootCfg)
{
CHAR szDottedD[16 + 1]; // The string used to collect the dotted decimal IP address.
USHORT cwNumChars = 0;
USHORT InChar = 0;
EdbgOutputDebugString("\r\nEnter new IP address: ");
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)
{
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);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars)
{
szDottedD[cwNumChars] = '\0';
pBootCfg->EdbgAddr.dwIP = inet_addr(szDottedD);
}
}
/*
@func void | SetMask | Accepts subnet mask from user input.
@rdesc N/A.
@comm
@xref
*/
static void SetMask(PBOOT_CFG pBootCfg)
{
CHAR szDottedD[16 + 1]; // The string used to collect the dotted masks.
USHORT cwNumChars = 0;
USHORT InChar = 0;
EdbgOutputDebugString("\r\nEnter new subnet mask: ");
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)
{
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);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars)
{
szDottedD[cwNumChars] = '\0';
pBootCfg->SubnetMask = inet_addr(szDottedD);
}
}
/*
@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 + 1];
USHORT cwNumChars = 0;
USHORT InChar = 0;
EdbgOutputDebugString("\r\nEnter maximum number of seconds to delay [1-255]: ");
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 >= '0' && InChar <= '9'))
{
if (cwNumChars < 16)
{
szCount[cwNumChars++] = (char)InChar;
OEMWriteDebugByte((BYTE)InChar);
}
}
// If it's a backspace, back up.
//
else if (InChar == 8)
{
if (cwNumChars > 0)
{
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars)
{
szCount[cwNumChars] = '\0';
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;
char InChar = 0;
// Replace the dots with NULL terminators
pszLastNum = pszDottedD;
for(cBytes = 0 ; cBytes < 6 ; cBytes++)
{
InChar = *pszDottedD;
while((InChar != '.') && (InChar != '\0'))
{
pszDottedD++;
}
InChar = *pszDottedD;
if ((InChar == '\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, 0x0 /*'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");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?