?? main.c
字號(hào):
//
// 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) 2004-2007, 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
//
// Common routines for the bootloader.
//
//-----------------------------------------------------------------------------
#include "bsp.h"
#include <ethdbg.h>
#pragma warning(push)
#pragma warning(disable: 4115)
#include <fmd.h>
#pragma warning(pop)
#include "loader.h"
//-----------------------------------------------------------------------------
// External Functions
extern BOOL NANDLoadIPL(VOID);
extern BOOL NANDLoadNK(VOID);
extern BOOL SDHCLoadNK(VOID);
extern BOOL FlashLoadBootCFG(BYTE *pBootCfg, DWORD cbBootCfgSize);
extern BOOL FlashStoreBootCFG(BYTE *pBootCfg, DWORD cbBootCfgSize);
extern void Launch(unsigned int uAddr);
extern BOOL BLMenu();
extern UINT32 OEMGetMagicNumber();
//-----------------------------------------------------------------------------
// External Variables
extern PCSP_PBC_REGS g_pPBC;
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
// Types
//-----------------------------------------------------------------------------
// Global Variables
BSP_ARGS *g_pBSPArgs;
IMAGE_TYPE g_ImageType;
IMAGE_MEMORY g_ImageMemory;
BOOT_CFG g_BootCFG;
BOOL g_DownloadImage = TRUE;
UCHAR *g_DefaultRamAddress;
BOOL g_bNandBootloader;
BOOL g_bNandExist;
BOOL g_bSDHCBootloader;
BOOL g_bSDHCExist;
// Used to save information about downloaded DIO mage
BOOT_BINDIO_CONTEXT g_BinDIO;
//-----------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
// Local Functions
//
BOOL LoadBootCFG(BOOT_CFG *BootCFG);
BOOL StoreBootCFG(BOOT_CFG *BootCFG);
void ResetDefaultBootCFG(BOOT_CFG *pBootCFG);
BOOL OEMVerifyMemory(DWORD dwStartAddr, DWORD dwLength);
BOOL OEMReportError (DWORD dwReason, DWORD dwReserved);
void OEMMultiBINNotify(const PMultiBINInfo pInfo);
//------------------------------------------------------------------------------
//
// Function: main
//
// Bootloader main routine.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void main(void)
{
// Common boot loader (blcommon) main routine.
//
BootloaderMain();
// Should never get here.
//
SpinForever();
}
//------------------------------------------------------------------------------
//
// Function: OEMDebugInit
//
// This function is the first called by the BLCOMMON framework when a boot
// loader starts. This function initializes the debug transport, usually just
// initializing the debug serial universal asynchronous receiver-transmitter
// (UART).
//
// Parameters:
// None.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//
//------------------------------------------------------------------------------
BOOL OEMDebugInit (void)
{
OEMInitDebugSerial();
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: OEMPlatformInit
//
// This function initializes the platform and is called by the BLCOMMON
// framework.
//
// Parameters:
// None.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//------------------------------------------------------------------------------
BOOL OEMPlatformInit (void)
{
PCSP_CCM_REGS pCCM;
UINT32 rcsr;
OEMBootInit ();
// Get reset status from CCM
pCCM = (PCSP_CCM_REGS) OALPAtoUA(CSP_BASE_REG_PA_CCM);
rcsr = INREG32(&pCCM->RCSR);
// Determine boot mode
switch(CSP_BITFEXT(rcsr, CCM_RCSR_BTP))
{
// BOOT[4:0] configured for NAND boot
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x10:
case 0x11:
case 0x12:
case 0x13:
g_bNandBootloader = TRUE;
KITLOutputDebugString("INFO: Bootloader launched from NAND\r\n");
break;
// Otherwise assume NOR bootloader
default:
KITLOutputDebugString("INFO: Bootloader launched from NOR\r\n");
g_bNandBootloader = FALSE;
break;
}
// Check for image reflash flag from RVD
if (CSP_BITFEXT(rcsr, CCM_RCSR_GPF) == 0xF)
{
KITLOutputDebugString("Reflash request detected!\r\n");
// Write out the image previously downloaded into SDRAM
// by RVD
OEMWriteFlash((DWORD) OALPAtoCA(IMAGE_BOOT_NORDEV_NOR_PA_START), IMAGE_BOOT_NORDEV_NOR_SIZE);
// EBOOT download is unnecessary since RVD downloaded image via JTAG
g_DownloadImage = FALSE;
// Jump to OS image
OEMLaunch(0, 0, (DWORD) OALPAtoCA(IMAGE_BOOT_NKIMAGE_NOR_PA_START), NULL);
}
// Initialize the BSP args structure.
//
g_pBSPArgs = (BSP_ARGS *) IMAGE_SHARE_ARGS_UA_START;
if ((g_pBSPArgs->header.signature != OAL_ARGS_SIGNATURE) ||
(g_pBSPArgs->header.oalVersion != OAL_ARGS_VERSION) ||
(g_pBSPArgs->header.bspVersion != BSP_ARGS_VERSION))
{
memset((LPVOID)g_pBSPArgs, 0, sizeof(BSP_ARGS));
g_pBSPArgs->header.signature = OAL_ARGS_SIGNATURE;
g_pBSPArgs->header.oalVersion = OAL_ARGS_VERSION;
g_pBSPArgs->header.bspVersion = BSP_ARGS_VERSION;
g_pBSPArgs->kitl.flags = (OAL_KITL_FLAGS_ENABLED | OAL_KITL_FLAGS_VMINI);
g_pBSPArgs->kitl.devLoc.IfcType = Internal;
g_pBSPArgs->kitl.devLoc.BusNumber = 0;
g_pBSPArgs->kitl.devLoc.LogicalLoc = BSP_BASE_REG_PA_CS8900A_IOBASE;
g_pBSPArgs->kitl.devLoc.PhysicalLoc = (PVOID)(BSP_BASE_REG_PA_CS8900A_IOBASE);
g_pBSPArgs->updateMode = FALSE;
}
// Update global BSP args struct with user switches on ADS board
OALBspArgsInit(g_pBSPArgs);
// Attempt to initialize the NAND flash driver
if (!FMD_Init(NULL, NULL, NULL))
{
KITLOutputDebugString("WARNING: OEMPlatformInit: Failed to initialize NAND flash device.\r\n");
g_bNandExist = FALSE;
}
else
{
KITLOutputDebugString("INFO: OEMPlatformInit: Initialized NAND flash device.\r\n");
g_bNandExist = TRUE;
}
// Load eboot configuration
//
if (!LoadBootCFG(&g_BootCFG))
{
// Load default bootloader configuration settings.
KITLOutputDebugString("ERROR: flash initialization failed - loading bootloader defaults...\r\n");
ResetDefaultBootCFG(&g_BootCFG);
}
// Set up optional bootloader function pointers.
//
g_pOEMMultiBINNotify = OEMMultiBINNotify;
g_pOEMVerifyMemory = OEMVerifyMemory;
g_pOEMReportError = OEMReportError;
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: OEMPreDownload
//
// This function is called by the BLCOMMON framework prior to download and can
// be customized to prompt for user feedback, such as obtaining a static IP
// address or skipping the download and jumping to a flash-resident run-time
// image.
//
// Parameters:
// None.
//
// Returns:
// Possible return values for OEMPreDownload:
//
// Value Description
// ----- -----------
// BL_DOWNLOAD = 0 Download the OS image from the host machine.
// BL_JUMP = 1 Skip the download and jump to a resident OS image.
// BL_ERROR = -1 Image download is unsuccessful.
//------------------------------------------------------------------------------
DWORD OEMPreDownload(void)
{
UINT32 rc = (DWORD)BL_ERROR;
BOOL fGotJumpImg = FALSE;
// User menu code...
//
if (!BLMenu())
{
return rc;
}
// Create device name based on Ethernet address (this is how Platform Builder identifies this device).
//
OALKitlCreateName(BSP_DEVICE_PREFIX, g_pBSPArgs->kitl.mac, (CHAR *)g_pBSPArgs->deviceId);
KITLOutputDebugString("INFO: Using device name: '%s'\n", g_pBSPArgs->deviceId);
fGotJumpImg = GetPreDownloadInfo (&g_BootCFG);
if (!g_DownloadImage || // this gets set in the BLMenu() function
fGotJumpImg) // this gets set in EbootInitEtherTransport
{
switch(g_BootCFG.autoDownloadImage)
{
case BOOT_CFG_AUTODOWNLOAD_NK_NOR:
rc = BL_JUMP;
break;
case BOOT_CFG_AUTODOWNLOAD_NK_NAND:
if (NANDLoadNK())
{
rc = BL_JUMP;
}
else
{
KITLOutputDebugString("ERROR: Failed to load OS image from NAND.\r\n");
}
break;
case BOOT_CFG_AUTODOWNLOAD_IPL_NAND:
if (NANDLoadIPL())
{
rc = BL_JUMP;
}
else
{
KITLOutputDebugString("ERROR: Failed to load IPL image from NAND.\r\n");
}
break;
}
// Set the clean boot flag so that OAL will let the kernel know that
// it needs a clean boot
//
// g_pBSPArgs->bCleanBootFlag = TRUE;
}
else if (g_DownloadImage)
{
rc = BL_DOWNLOAD;
}
return(rc);
}
//------------------------------------------------------------------------------
//
// Function: OEMLaunch
//
// This function launches the run-time image. It is the last one called by
// the BLCOMMON framework.
//
// Parameters:
// dwImageStart
// [in] Starting address of OS image.
//
// dwImageLength
// [in] Length, in bytes, of the OS image.
//
// dwLaunchAddr
// [in] First instruction of the OS image.
//
// pRomHdr
// [out] Pointer to the ROM header structure.
//
// Returns:
// None.
//------------------------------------------------------------------------------
void OEMLaunch (DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr, const ROMHDR *pRomHdr)
{
UINT32 PhysAddress;
// Remove-W4: Warning C4100 workaround
UNREFERENCED_PARAMETER(pRomHdr);
switch(g_BootCFG.autoDownloadImage)
{
case BOOT_CFG_AUTODOWNLOAD_NK_NOR:
// Set launch address for NOR OS image. OS executes-in-place from NOR.
PhysAddress = IMAGE_BOOT_NKIMAGE_NOR_PA_START;
break;
case BOOT_CFG_AUTODOWNLOAD_NK_NAND:
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -