www.pudn.com > iMx31_WCE600.rar > 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. 
// 
//------------------------------------------------------------------------------ 
// 
// Copyright (C) 2006, Freescale Semiconductor, Inc. All Rights Reserved. 
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS 
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT 
// 
//------------------------------------------------------------------------------ 
// 
// File: main.c 
// 
// OEM IPL routines for Freescale MX31 ADS hardware platform. 
// 
//------------------------------------------------------------------------------ 
#include  
#include  
#include    // Needed for partition types... 
#include  
#include "bsp.h" 
#include "keys.h" 
 
//----------------------------------------------------------------------------- 
// External Functions 
extern void Launch(UINT32 ulLaunchAddr); 
 
//----------------------------------------------------------------------------- 
// External Variables 
 
//----------------------------------------------------------------------------- 
// Defines 
// Version number 
#define IPL_VERSION_MAJOR   1 
#define IPL_VERSION_MINOR   0 
 
//----------------------------------------------------------------------------- 
// Types 
 
//----------------------------------------------------------------------------- 
// Global Variables 
// 
// These four variables below are used by iplcommon 
// 
// Flash start and length. They are used for NOR IPL. 
// We only support NAND IPL so just set them 0. 
UINT32 g_ulFlashBase = 0; 
UINT32 g_ulFlashLengthBytes = 0; 
 
// BootPart work buffer start and length that will  
// be set in OEMIPLInit. 
UINT32 g_ulBPartBase; 
UINT32 g_ulBPartLengthBytes; 
 
//----------------------------------------------------------------------------- 
// Local Variables 
 
//----------------------------------------------------------------------------- 
// Local Functions 
 
//------------------------------------------------------------------------------ 
// 
// Function: main 
// 
// This function is the IPL main entry. 
// 
// Parameters: 
//      None. 
// 
// Returns: 
//      None. 
// 
//------------------------------------------------------------------------------ 
void main(void) 
{ 
    // Call into the IPLcommon main routine. 
    IPLmain(); 
} 
 
//------------------------------------------------------------------------------ 
// 
// Function: OEMMessageHandler 
// 
// This function is the OEM message handler. 
// 
// Parameters: 
//      MessageCode 
//          [in] IPL message code. 
// 
//      pMessageString 
//          [in] The message to output. 
// 
// Returns: 
//      None. 
// 
//------------------------------------------------------------------------------ 
static void OEMMessageHandler(IPL_MESSAGE_CODE MessageCode,  
    LPWSTR pMessageString) 
{ 
    OEMWriteDebugString((UINT16 *)pMessageString); 
} 
 
//------------------------------------------------------------------------------ 
// 
// Function: OEMIPLInit 
// 
// This function performs OEM initializaiton for IPL. 
// 
// Parameters: 
//      None. 
// 
// Returns: 
//      TRUE indicates success. FALSE indicates failure. 
// 
//------------------------------------------------------------------------------ 
BOOLEAN OEMIPLInit(void) 
{ 
    // Initialize the UART. 
    OEMInitDebugSerial(); 
 
    KITLOutputDebugString("Microsoft Windows CE IPL %d.%d for MX31 ADS (%s %s)\r\n", 
                         IPL_VERSION_MAJOR, IPL_VERSION_MINOR, __DATE__, __TIME__); 
 
    // Set BootPart work buffer start and length 
    g_ulBPartBase = (UINT32)OALPAtoUA(IMAGE_BOOT_NANDCACHE_RAM_START); 
    g_ulBPartLengthBytes = IMAGE_BOOT_NANDCACHE_RAM_SIZE; 
 
    // Messaging handler callback. 
    g_pfnMessageHandler = OEMMessageHandler; 
 
    // Initialize Keypad for ULDR forcing key read 
    KeypadInit(); 
 
    return(TRUE); 
} 
 
//------------------------------------------------------------------------------ 
// 
// Function: OEMGetUpdateMode 
// 
// This function determines whether the device is in update mode or  
// normal boot mode. It also implements the IPLCOMMON helper routines.  
// 
// Parameters: 
//      None. 
// 
// Returns: 
//      TRUE indicates success. FALSE indicates failure. 
// 
//------------------------------------------------------------------------------ 
BOOLEAN OEMGetUpdateMode(void) 
{ 
    BOOL fUpdateMode = FALSE; 
 
    // Check the left softkey for forcing ULDR 
    if (KeypadRead() & KEY_TSOFT1) 
    { 
        fUpdateMode = TRUE; 
        KITLOutputDebugString("IPL: Forcing ULDR soft key 1 is down\r\n"); 
    } 
 
    // Check the RAM flag 
    if (!fUpdateMode) 
    { 
        BOOL *pfUpdateMode = OALArgsQuery(OAL_ARGS_QUERY_UPDATEMODE); 
        if (pfUpdateMode != NULL) 
        { 
            fUpdateMode = *pfUpdateMode; 
            // Tell us when update flag is set 
            if (fUpdateMode) 
                KITLOutputDebugString("IPL: RAM Update Flag is set\r\n"); 
        } 
        else 
        { 
            KITLOutputDebugString("IPL: RAM Update is not available!!\r\n"); 
        } 
    } 
 
    // When RAM flag isn't set check persistent one 
    if (!fUpdateMode) 
    { 
        // Get persistent flag 
        if (!BP_GetUpdateModeFlag(&fUpdateMode)) 
            KITLOutputDebugString("IPL: Failed to get Persistent Update Flag\r\n"); 
 
        if (fUpdateMode) 
            KITLOutputDebugString("IPL: Persistent Update Flag is set\r\n"); 
    } 
 
    if (fUpdateMode) 
        KITLOutputDebugString("IPL: Launching the Update Loader\r\n"); 
    else 
        KITLOutputDebugString("IPL: Launching the OS image\r\n"); 
 
    return(fUpdateMode); 
} 
 
//------------------------------------------------------------------------------ 
// 
// Function: OEMTranslateBaseAddress 
// 
// This function converts an image virtual address into an  
// IPL-compatible address. 
// 
// Parameters: 
//      ulPartType  
//          [in] Specifies the partition type. 
// 
//      ulAddr  
//          [in] Starting virtual address of the specified partition.  
// 
//      pulTransAddr  
//          [out] Pointer to the translated IPL-compatible address. 
// 
// Returns: 
//      TRUE indicates success. FALSE indicates failure. 
// 
//------------------------------------------------------------------------------ 
BOOLEAN OEMTranslateBaseAddress(UINT32 ulPartType, UINT32 ulAddr,  
    UINT32 *pulTransAddr) 
{ 
    if (pulTransAddr == NULL) 
    { 
        return(FALSE); 
    } 
 
    // No translation required since IPL is operating in Virtual space. 
    switch(ulPartType) 
    { 
    case PART_BOOTSECTION: 
    case PART_XIP: 
    default: 
        *pulTransAddr = ulAddr; 
    } 
 
    return(TRUE); 
} 
 
//------------------------------------------------------------------------------ 
// 
// Function: OEMLaunchImage 
// 
// This function launches the loaded image. 
 
// 
// Parameters: 
//      ulLaunchAddr  
//          [in] Jump address of the image to launch.  
// 
// Returns: 
//      None. 
// 
//------------------------------------------------------------------------------ 
void OEMLaunchImage(UINT32 ulLaunchAddr) 
{ 
    UINT32 ulPhysicalJump = 0; 
 
    // The IPL is running with the MMU on - before we jump to the loaded image, we need to convert 
    // the launch address to a physical address and turn off the MMU. 
 
    // Convert jump address to a physical address. 
    ulPhysicalJump = OALVAtoPA((void *)ulLaunchAddr); 
 
    KITLOutputDebugString("Jumping to VA 0x%x PA 0x%x...\r\n", ulLaunchAddr, ulPhysicalJump); 
 
    // Jump... 
    Launch(ulPhysicalJump); 
}