main.c
来自「该BSP是基于PXA270+WINCE的BSP」· C语言 代码 · 共 263 行
C
263 行
//
// 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.
//
#include <windows.h>
#include <iplcommon.h>
#include <bootpart.h> // Needed for partition types...
#include <bsp.h>
#include <dbgserial.h>
// Base address of the image flash part.
//
// NOTE: The first three blocks are occupied by the Ethernet bootloader,
// Ethernet bootloader settings, and IPL (in order). When we
// initialize the bootpart interface, we'll have to subtract these
// blocks from the overall flash picture.
//
#define FLASH_BYTE_MBR_OFFSET IMAGE_OSIMAGE_FLASH_OFFSET
#define FLASH_BASE_PHYSICAL (0 + FLASH_BYTE_MBR_OFFSET)
#define FLASH_LENGTH_BYTES (MAINSTONEII_SIZE_BOOT_FLASH - FLASH_BYTE_MBR_OFFSET)
// Virtual address of bootpart work buffer.
//
#define BPART_BUFFER_PHYSICAL 0xA0060000
#define BPART_BUFFER_LENGTH_BYTES 0x00080000
// Global variables.
//
// --- These are used by iplcommon (start) ---
UINT32 g_ulFlashBase = FLASH_BASE_PHYSICAL; // Flash start and length.
UINT32 g_ulFlashLengthBytes = FLASH_LENGTH_BYTES;
UINT32 g_ulBPartBase = BPART_BUFFER_PHYSICAL; // BootPart work buffer start and length.
UINT32 g_ulBPartLengthBytes = BPART_BUFFER_LENGTH_BYTES;
// --- Holds the current logging zone mask. ---
UINT32 g_oalLogMask = (1<<OAL_LOG_ERROR)|(1<<OAL_LOG_WARN)|(1<<OAL_LOG_INFO);
// --- These are used by iplcommon (end) ---
// External variables.
//
extern PFN_MessageHandler g_pfnMessageHandler;
// Function prototypes.
//
void OEMWriteDebugString(unsigned short *str);
static void OEMWriteHexLED(UINT32 ulPattern)
{
//----------------------------------------------
volatile MAINSTONEII_BLR_REGS *pBLRegs = (volatile MAINSTONEII_BLR_REGS *)(MAINSTONEII_BASE_REG_PA_FPGA);
pBLRegs->hex_led = ulPattern;
//----------------------------------------------
}
static void OEMMessageHandler(IPL_MESSAGE_CODE MessageCode, LPWSTR pMessageString)
{
// Write debug message string.
//
OEMWriteDebugString(pMessageString);
}
static UINT32 HWSwitchOn(DWORD mask)
{
volatile MAINSTONEII_BLR_REGS *pBLRegs = (volatile MAINSTONEII_BLR_REGS *) (MAINSTONEII_BASE_REG_PA_FPGA);
return (pBLRegs->gpsw & mask);
}
//------------------------------------------------------------------------------
//
void main(void)
{
// Call into the IPLcommon main routine.
//
IPLmain();
}
///////////////////////////////////////////////////////////////////////////////
// Required OEM IPL routines.
///////////////////////////////////////////////////////////////////////////////
// --- These are used by iplcommon (start) ---
BOOLEAN OEMIPLInit(void)
{
//----------------------------------------------------------------
// Check and initialize BSP Args area
//
OALArgsInit((BSP_ARGS *) IMAGE_SHARE_ARGS_PA_START);
// Initialize serial UART (use the BT UART on the mainboard).
//
InitDebugSerial(BULVERDE_BASE_REG_PA_BTUART, TRUE);
OALLog(L"\r\nMicrosoft Windows CE IPL for Intel Mainstone III development platform\r\n");
// Check for HW switch settings
{
UINT32 settings = HWSwitchOn(FORMAT_PART_FLAG | CLEAN_BOOT_FLAG | HIVE_CLEAN_FLAG | UPDATE_MODE_FLAG);
if(settings)
{
if(settings & UPDATE_MODE_FLAG)
{
BOOL *flag = (BOOL*)OALArgsQuery(OAL_ARGS_QUERY_UPDATEMODE);
*flag = TRUE;
OALLog(L"Update Mode flag set\r\n");
}
if(settings & CLEAN_BOOT_FLAG)
{
BOOL *flag = (BOOL*)OALArgsQuery(BSP_ARGS_QUERY_CLEANBOOT);
*flag = TRUE;
OALLog(L"Clean Boot flag set\r\n");
}
if(settings & HIVE_CLEAN_FLAG)
{
BOOL *flag = (BOOL*)OALArgsQuery(BSP_ARGS_QUERY_HIVECLEAN);
*flag = TRUE;
OALLog(L"Hive Clean flag set\r\n");
}
if(settings & FORMAT_PART_FLAG)
{
BOOL *flag = (BOOL*)OALArgsQuery(BSP_ARGS_QUERY_FORMATPART);
*flag = TRUE;
OALLog(L"Format Partition flag set\r\n");
}
}
}
// Messaging handler callback.
//
g_pfnMessageHandler = OEMMessageHandler;
OEMWriteDebugString(L"OEMIPLInit - Success\r\n");
OEMWriteDebugString(L"-----------------------------------\r\n");
//----------------------------------------------------------------
return(TRUE);
}
BOOLEAN OEMGetUpdateMode(void)
{
BOOL fUpdateMode = FALSE;
BSP_ARGS *pArgs = (BSP_ARGS *)IMAGE_SHARE_ARGS_PA_START;
// first, check the RAM flag
if (!pArgs)
{
OEMWriteDebugString(L"OEMGetUpdateMode pArgs NULL.\r\n");
return(FALSE);
}
fUpdateMode = pArgs->bUpdateMode;
if (fUpdateMode)
{
OEMWriteDebugString(L"Update Mode RAM flag is set.\r\n");
}
else
{
// RAM flag is not set - are we recovering from power failure?
if (!BP_GetUpdateModeFlag(&fUpdateMode))
{
OEMWriteDebugString(L"Error in BP_GetUpdateModeFlag.\r\n");
}
if (fUpdateMode)
{
OEMWriteDebugString(L"Update Mode Persistent flag is set.\r\n");
}
}
if (fUpdateMode)
{
OEMWriteDebugString(L"Launching the Update Loader...\r\n");
}
else
{
OEMWriteDebugString(L"Launching the ROM image...\r\n");
}
return(fUpdateMode);
}
BOOLEAN OEMTranslateBaseAddress(UINT32 ulPartType, UINT32 ulAddr, UINT32 *pulTransAddr)
{
UINT32 FlashBaseVirtual = (UINT32) OALPAtoVA(MAINSTONEII_BASE_PA_BOOT_FLASH, TRUE);
if (pulTransAddr == NULL)
{
OEMWriteDebugString(L"OEMTranslateBaseAddress failed \r\n");
return(FALSE);
}
switch(ulPartType)
{
case PART_BOOTSECTION:
OEMWriteDebugString(L"PART_BOOTSECTION\r\n");
// Assume update loader partition contains an uncompressed RAM-based image.
// 0x8000.0000 virtual == 0xA000.0000 physical (used by IPL).
*pulTransAddr = (ulAddr + 0x20000000);
break;
case PART_XIP:
default:
// Flash or RAM address?
//
ulAddr &= ~0x20000000;
if (ulAddr >= FlashBaseVirtual && (ulAddr < (FlashBaseVirtual + MAINSTONEII_SIZE_BOOT_FLASH)))
{
// FLASH: 0x9AA0.0000 virtual == 0x0000.0000 physical (flash).
*pulTransAddr = (ulAddr - FlashBaseVirtual);
}
else
{
// RAM: 0x8000.0000 virtual == 0xA000.0000 physical (used by IPL).
*pulTransAddr = (ulAddr + 0x20000000);
}
break;
}
return(TRUE);
}
void OEMLaunchImage(UINT32 ulLaunchAddr)
{
typedef void (*PFN_LAUNCH)();
OEMWriteDebugString(L"Starting kernel (NK)\r\n");
// Since the MMU is off, we just need to jump to the address provided (it was translated by OEMTranslateBaseAddress).
//
((PFN_LAUNCH)(ulLaunchAddr))();
}
// --- These are used by iplcommon (end) ---
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?