⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 WinCE5.0BSP for Renesas SH7770
💻 C
📖 第 1 页 / 共 3 页
字号:
//
//  Copyright(C) Renesas Technology Corp. 2005. All rights reserved.
//
//  Ethernet Boot Loader for ITS-DS7
//
//  FILE      : main.c
//  CREATED   : 2005.08.01
//  MODIFIED  : 2005.11.14
//  AUTHOR    : Renesas Technology Corp.
//  HARDWARE  : RENESAS ITS-DS7
//  HISTORY   : 
//              2005.08.01
//              - Created release code.
//                (based on EBOOT for ASPEN for WCE5.0)
//              2005.11.14
//              - Changed debugserial routine of oal to debug serial common routines.
//              - Modified if start from flash, set KitlTransport is KTS_PASSIVE_MODE.

//
// 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.
//
//------------------------------------------------------------------------------
//
//  Module: main.c
//
//  Bootloader main entry point.
//
//------------------------------------------------------------------------------

// Include Files 

#include <windows.h>
#include "boot.h"
#include <ethdbg.h>
#include <nkintr.h>
#include <pehdr.h>
#include <romldr.h>
#include <oemfw.h>
#include "shx.h"
#include "sh7770.h"
#include "platform.h"
#include "drv_glob.h"
#include "loader.h"
#include <blcommon.h>
#include "rev.h"
 
// External Functions
extern UINT32 BLFlashDownload(LPDWORD pdwImageStart, LPDWORD pdwImageLength, LPDWORD pdwLaunchAddr);
extern UINT16 IsFlash( DWORD dwPhysStart, DWORD dwPhysLen );

// External Variables 
extern ROMHDR *const volatile pTOC;
extern DWORD gdwSavedPhysStart; // keep actual start address while SDRAM image is written to flash
extern DWORD gdwSaveLaunchAddr;

// Global Variables 
BOOL gbStoreSDRAMImageToFlash = FALSE;
BOOL gbJumpToFlash = FALSE;
BOOL gbGotIP = FALSE;

// Defines 
#define pDriverGlobals ((PDRIVER_GLOBALS) DRIVER_GLOBALS_PHYSICAL_MEMORY_START)

#define BACKSPACE       (8)
#define IPADDR_MAX      (15)            // strlen ("xxx.xxx.xxx.xxx") = 15

// Types
 
// Local Variables 

// Can be used to turn on debug zones in eboot.lib and smc9000.lib functions

DWORD EdbgDebugZone;
// Multi-XIP
#define FLASH_BIN_START 0  // FLASH Offset.
MultiBINInfo g_BINRegionInfo;
DWORD g_dwMinImageStart;
 
// Local Functions 
void JumpToOS( DWORD dwLaunchAddr );

// Function pointers for transports (pre-download, read-data, and launch)

VOID    SpinForever         ( VOID );
DWORD   (* pfnPreDownload)  ( VOID );
BOOL    (* pfnReadData)     ( DWORD cbData, LPBYTE pbData);
void    (* pfnLaunch)       ( DWORD dwImageStart, 
                              DWORD dwImageLength, 
                              DWORD dwLaunchAddr, 
                              const ROMHDR *pRomHdr);
BOOL    ReadEEPROMData      ( DWORD *pdwIP, DWORD *pdwSubnetMask);
BOOL    UpdateEEPROMData    ( DWORD dwIP, DWORD dwSubnetMask);
void    InitDebugSerial();

// Private Functions

static  BOOL    OEMVerifyMemory ( DWORD dwStartAddr, DWORD dwLength );
static void OEMMultiBINNotify(const PMultiBINInfo pInfo);
static BOOL OEMCheckSignature(DWORD dwImageStart, DWORD dwROMOffset, DWORD dwLaunchAddr, BOOL bDownloaded);
static  void    DisplayLED      ( CHAR *data );
static  void    DisplayNumLED   ( DWORD data );
static  BOOL    ReadIPLine      ( char *pbuf, DWORD dwTimeout );

static void DUMPREG_PMSR();
static void DUMPREG_GPIO();
static void DUMPREG_FRQCR();
static void DUMPREG_FRQCR();
static void DUMPREG_BUSBRIDGE();
static void DUMPREG_BUSBRIDGE_BSC();

//------------------------------------------------------------------------------
//  Function:  main
//
//  Main bootloader entry point. This function does not return.
//

void main( void )
{
    // Common boot loader (blcommon) main routine.
    //
    BootloaderMain();

    // Should never get here.
    //
    SpinForever();
}

//------------------------------------------------------------------------------
//  Function:  OEMPlatformInit
//
//  Platform initialization. If DIP switch S1-4 is set jump to programmed 
//  image.
//

BOOL OEMPlatformInit (void)
{
    DWORD       dwDIPs;
    SYSTEMTIME  st;
	SYSTEMTIME defst = {2000,1,0,1,0,0,0,0};	// RTC default

    EdbgOutputDebugString( "+OEMPlatformInit\r\n" );

	// check DIP switch SW2 bit 8 to select boot mode

    dwDIPs = READ_REGISTER_USHORT(SF_DIPSWMR) & 0x00FF;

#if (ITS_DS7_SETTING == ITS_DS7_COREFUNCTION)
#if (ENABLE_HSSI == 1) && (ENABLE_HAC == 0)
		EdbgOutputDebugString("ITS_DS7_SETTING : COREFUNCTION(HSSI)\r\n");
#elif (ENABLE_HAC == 1)
		EdbgOutputDebugString("ITS_DS7_SETTING : COREFUNCTION(HAC)\r\n");
#else
		EdbgOutputDebugString("ITS_DS7_SETTING : COREFUNCTION\r\n");
#endif
#else
		EdbgOutputDebugString("ITS_DS7_SETTING : COREONLY\r\n");
#endif

	if (dwDIPs & 0x00000080) {
		// SW2-8 : ON
#if (ITS_DS7_SETTING == ITS_DS7_COREFUNCTION)
    		EdbgOutputDebugString("Boot mode illegal !!\r\n");
    		EdbgOutputDebugString("H/W setting is COREONLY (SW2-8:ON)\r\n");
    		EdbgOutputDebugString("Please Power Off!!\r\n");
			PrintLED("FAIL    ");
			SpinForever();
#endif
	}
	else {
		// SW2-8 : OFF
#if (ITS_DS7_SETTING == ITS_DS7_COREONLY)
    		EdbgOutputDebugString("Boot mode illegal !! \r\n");
    		EdbgOutputDebugString("H/W setting is COREFUNCTION (SW2-8:OFF)\r\n");
    		EdbgOutputDebugString("Please Power Off!!\r\n");
			PrintLED("FAIL    ");
			SpinForever();
#endif
	}

    DisplayLED("EBOOT GO");
    EdbgOutputDebugString("Microsoft Windows CE Ethernet Bootloader %d.%d for Renesas ITS-DS7 (%s)\n",
                          EBOOT_VERSION_MAJOR,EBOOT_VERSION_MINOR, __DATE__);

    EdbgOutputDebugString("Stack=%Xh & DipSwith =0x%x \r\n",&dwDIPs,dwDIPs);

    // Initialize driver globals area, so kernel knows we are present
    memset((LPVOID)&pDriverGlobals->eth,0,DBG_ETH_GLOBALS_SIZE);
	pDriverGlobals->eth.EbootMagicNum = EBOOT_MAGIC_NUM;

	DUMPREG_PMSR();
//	DUMPREG_GPIO();
//	DUMPREG_FRQCR();
//	DUMPREG_BUSBRIDGE();
//	DUMPREG_BUSBRIDGE_BSC();

    // At this time, the CPU has been initialized

    if( !PowerOnSelfTest() )
    {
        EdbgOutputDebugString( "ERROR: OEMPlatformInit: Power On Self test failed\r\n" );
        SpinForever();
    }

	// TMU1 setup for OEMEthGetSecs
	WRITE_REGISTER_UCHAR(TMU_TSTR0, READ_REGISTER_UCHAR(TMU_TSTR0) & ~TMU_TSTR0_STR1);		// make sure timer1 is stopped
	WRITE_REGISTER_USHORT(TMU_TCR1, TMU_TCR_TPSC_D4);										// interrupt disable, divide by 4
	WRITE_REGISTER_ULONG(TMU_TCOR1, 0xffffffff);										// set timer constant register
	WRITE_REGISTER_ULONG(TMU_TCNT1, 0xffffffff);										// initialize the counter
	WRITE_REGISTER_UCHAR(TMU_TSTR0, READ_REGISTER_UCHAR(TMU_TSTR0) | TMU_TSTR0_STR1);		// startup timer1

    // Check real time clock, initialize if necessary (used for polling in net routines)
	OEMGetRealTime(&st);
	if ((st.wYear < 2000) ||
		(st.wYear > 2099) ||
		(st.wMonth < 1) ||
		(st.wMonth > 12) ||
		(st.wDay < 1) ||
		(st.wDay > 31) ||
		(st.wHour < 0) ||
		(st.wHour > 23) ||
		(st.wMinute < 0) ||
		(st.wMinute > 59) ||
		(st.wSecond < 0) ||
		(st.wSecond > 59)) {

        EdbgOutputDebugString("Invalid time returned from OEMGetRealTime: Year: %u, Month: %u, Day: %u, Hour: %u, Minute: %u, second: %u\n",
                           st.wYear, st.wMonth,st.wDay, st.wHour, st.wMinute,st.wSecond);
        EdbgOutputDebugString("Resetting real time clock to default date\n");
		OEMSetRealTime(&defst);
    }
	else if ((st.wYear == defst.wYear) &&
			(st.wMonth == defst.wMonth) &&
			(st.wDay == defst.wDay) &&
			(st.wHour == defst.wHour) &&
			(st.wMinute == defst.wMinute) &&
			(st.wSecond == defst.wSecond)){
        EdbgOutputDebugString("Initialize real time clock\n");
		OEMSetRealTime(&st);
	}

	// check DIP switch SW2 bit0 - 3 to select boot mode
    dwDIPs = READ_REGISTER_USHORT(SF_DIPSWMR) & 0x00FF;

    EdbgOutputDebugString("Read DIP switch SW2 : 0x%X\r\n",dwDIPs);

    // Normal Mode SW-2-1,2,3 OFF, OFF, OFF

    // If DIP switch SW2-1 is ON, jump straight to the programmed image.
	if (dwDIPs & 0x00000001) {	// ON
		gbJumpToFlash = TRUE;
	}
	else {
		gbJumpToFlash = FALSE;
	}
    // If DIP switch SW2-2 is ON, use already IP address.
	if (dwDIPs & 0x00000002) {	// ON
		gbGotIP = TRUE;
	}
	else {
		gbGotIP = FALSE;
	}
    // Currently this loader uses SW2-3 as flash write/restore mode selection.
    if (dwDIPs & 0x00000004) {	// ON
        // write/restore SDRAM image to/from flash memory
        EdbgOutputDebugString("Switch SW2-3 is ON, SDRAM image uses flash memory.\r\n");
        gbStoreSDRAMImageToFlash = 1;
    }
    else {
        // normal operation
        EdbgOutputDebugString("Switch SW2-3 is OFF, FLASH image uses flash memory.\r\n");
        gbStoreSDRAMImageToFlash = 0;
    }

    EdbgOutputDebugString("gbJumpToFlash %d gbGotIP %d gbStoreSDRAMImageToFlash %d \r\n", gbJumpToFlash, gbGotIP, gbStoreSDRAMImageToFlash );

    // Initialize the download transport according to DIP switch

	if( !gbJumpToFlash ) {
		if( EthInit () )
		{
			// use Ether transport

			pfnPreDownload = EthPreDownload;
			pfnLaunch      = EthLaunch;
			pfnReadData    = EbootEtherReadData;
		}
		else
		{
			// no transport available, spin forever
			SpinForever();
		}
	}

    EdbgOutputDebugString ("-OEMPlatformInit(rc=1)\r\n");
    return TRUE;
}

//------------------------------------------------------------------------------
//  Function:  OEMPreDownload
//
//  Callback before image download. Function pointer set based on download
//  transport type.

DWORD OEMPreDownload (void)
{
    // Execute the transport callout function
	if(!pfnPreDownload) return(BL_JUMP);

    return( pfnPreDownload() );
}

//------------------------------------------------------------------------------
//  Function:  OEMLaunch
//
//  Callback to perform OS jump. Function pointer set based on download
//  transport type.

void OEMLaunch( DWORD dwImageStart, 
                DWORD dwImageLength, 
                DWORD dwLaunchAddr, 
                const ROMHDR *pRomHdr )
{
	ROMHDR RomHdr;							// ROM Table of Contents 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -