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

📄 main.c

📁 三星SMDK2410 BPS.支持Windows CE 5.0.
💻 C
📖 第 1 页 / 共 3 页
字号:
//
// 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 <pcireg.h>
#include <ethdbg.h>
#include <fmd.h>
#include "loader.h"


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);
// End   ***************************************


// Globals
//
DWORD EdbgDebugZone;
static BOOLEAN g_bWaitForConnect = TRUE;

IMAGE_TYPE     g_ImageType       = IMAGE_OS_BIN;
BOOT_CFG       g_BootConfig;

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.

// External definitions.
//
extern const BYTE ScreenBitmap[];
extern BOOL g_bSmartMediaExist;



/*
    @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.
    //    
    BootloaderMain();

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


/*
    @func   void | InitDisplay | Initializes the LCD controller and displays a splashscreen image.
    @rdesc  N/A.
    @comm    
    @xref   
*/
static void InitDisplay(void)
{
    volatile S3C2410X_IOPORT_REG *s2410IOP = (S3C2410X_IOPORT_REG *)OALPAtoVA(S3C2410X_BASE_REG_PA_IOPORT, FALSE);
    volatile S3C2410X_LCD_REG    *s2410LCD = (S3C2410X_LCD_REG *)OALPAtoVA(S3C2410X_BASE_REG_PA_LCD, FALSE);

    // Set up the LCD controller registers to display a power-on bitmap image.
    //
    s2410IOP->GPCUP     = 0xFFFFFFFF;
    s2410IOP->GPCCON    = 0xAAAAAAAA;
                                    
    s2410IOP->GPDUP     = 0xFFFFFFFF;
    s2410IOP->GPDCON    = 0xAAAAAAAA; 

    s2410LCD->LCDCON1   =  (6           <<  8) |       /* VCLK = HCLK / ((CLKVAL + 1) * 2) -> About 7 Mhz  */
                           (LCD_MVAL   <<  7)  |       /* 0 : Each Frame                                   */
                           (3           <<  5) |       /* TFT LCD Pannel                                   */
                           (12          <<  1) |       /* 16bpp Mode                                       */
                           (0           <<  0) ;       /* Disable LCD Output                               */

    s2410LCD->LCDCON2   =  (LCD_VBPD        << 24) |   /* VBPD          :   1                              */
                           (LCD_LINEVAL_TFT << 14) |   /* Vertical Size : 320 - 1                          */
                           (LCD_VFPD        <<  6) |   /* VFPD          :   2                              */
                           (LCD_VSPW        <<  0) ;   /* VSPW          :   1                              */

    s2410LCD->LCDCON3   =  (LCD_HBPD        << 19) |   /* HBPD          :   6                              */
                           (LCD_HOZVAL_TFT  <<  8) |   /* HOZVAL_TFT    : 240 - 1                          */
                           (LCD_HFPD        <<  0) ;   /* HFPD          :   2                              */


    s2410LCD->LCDCON4   =  (LCD_MVAL        <<  8) |   /* MVAL          :  13                              */
                           (LCD_HSPW        <<  0) ;   /* HSPW          :   4                              */

    s2410LCD->LCDCON5   =  (0           << 12) |       /* BPP24BL       : LSB valid                        */
                           (1           << 11) |       /* FRM565 MODE   : 5:6:5 Format                     */
                           (0           << 10) |       /* INVVCLK       : VCLK Falling Edge                */
                           (1           <<  9) |       /* INVVLINE      : Inverted Polarity                */
                           (1           <<  8) |       /* INVVFRAME     : Inverted Polarity                */
                           (0           <<  7) |       /* INVVD         : Normal                           */
                           (0           <<  6) |       /* INVVDEN       : Normal                           */
                           (0           <<  5) |       /* INVPWREN      : Normal                           */
                           (0           <<  4) |       /* INVENDLINE    : Normal                           */
                           (0           <<  3) |       /* PWREN         : Disable PWREN                    */
                           (0           <<  2) |       /* ENLEND        : Disable LEND signal              */
                           (0           <<  1) |       /* BSWP          : Swap Disable                     */
                           (1           <<  0) ;       /* HWSWP         : Swap Enable                      */

    s2410LCD->LCDSADDR1 = ((IMAGE_FRAMEBUFFER_DMA_BASE >> 22)     << 21) | 
                          ((M5D(IMAGE_FRAMEBUFFER_DMA_BASE >> 1)) <<  0);

    s2410LCD->LCDSADDR2 = M5D((IMAGE_FRAMEBUFFER_DMA_BASE + (LCD_XSIZE_TFT * LCD_YSIZE_TFT * 2)) >> 1);

    s2410LCD->LCDSADDR3 = (((LCD_XSIZE_TFT - LCD_XSIZE_TFT) / 1) << 11) | (LCD_XSIZE_TFT / 1);        

    s2410LCD->LPCSEL   |= 0x3;

    s2410LCD->TPAL      = 0x0;        
    s2410LCD->LCDCON1  |= 1;

    // Display a bitmap image on the LCD...
    //
    memcpy((void *)IMAGE_FRAMEBUFFER_UA_BASE, ScreenBitmap, LCD_ARRAY_SIZE_TFT_16BIT);

}

static void InitRealTimeClock(void)
{
    SYSTEMTIME defaultTime = {1998,1,0,1,12,0,0,0};
    OEMSetRealTime(&defaultTime);
}

/*
    @func   BOOL | WriteBootConfig | Write bootloader settings to flash.
    @rdesc  TRUE = Success, FALSE = Failure.
    @comm    
    @xref   
*/
static BOOL WriteBootConfig(PBOOT_CFG pBootCfg)
{
    BOOL bResult = FALSE;

    OALMSG(OAL_FUNC, (TEXT("+WriteBootConfig.\r\n")));

    if (!pBootCfg)
    {
        goto CleanUp;
    }

    // First, erase the eboot settings area in flash...
    //
    if (!AM29LV800_EraseFlash(EBOOT_CONFIG_OFFSET, sizeof(BOOT_CFG)))
    {
        OALMSG(OAL_ERROR, (TEXT("ERROR: WriteEbootConfig: Flash erase failed.\r\n")));
        goto CleanUp;
    }

    // Write settings to flash...
    //
    if (!AM29LV800_WriteFlash(EBOOT_CONFIG_OFFSET, (PBYTE)pBootCfg, sizeof(BOOT_CFG)))
    {
        OALMSG(OAL_ERROR, (TEXT("ERROR: WriteEbootConfig: Flash write failed.\r\n")));
        goto CleanUp;
    }

    bResult = TRUE;

CleanUp:
    OALMSG(OAL_FUNC, (TEXT("-WriteBootConfig.\r\n")));
    return(bResult);
}


/*
    @func   void | ResetBootConfig | Reset the bootloader settings to their default values.
    @rdesc  N/A.
    @comm    
    @xref   
*/
static void ResetBootConfig(PBOOT_CFG pBootCfg)
{
    // Default eboot configuration values (leave the MAC address field alone)...
    //
    pBootCfg->Signature        = CONFIG_SIGNATURE;
    pBootCfg->VerMajor         = EBOOT_VERSION_MAJOR;
    pBootCfg->VerMinor         = EBOOT_VERSION_MINOR;
    pBootCfg->BootDelay        = CONFIG_AUTOBOOT_DEFAULT_COUNT;
    pBootCfg->ConfigFlags      = CONFIG_FLAGS_DHCP;
    pBootCfg->IPAddr           = 0;
    pBootCfg->SubnetMask       = 0;
    pBootCfg->LoadDeviceOrder  = 0;

    return;
}


/*
    @func   BOOL | ReadBootConfig | Read bootloader settings from flash.
    @rdesc  TRUE = Success, FALSE = Failure.
    @comm    
    @xref   
*/
static BOOL ReadBootConfig(PBOOT_CFG pBootCfg)
{
    BOOLEAN bResult = FALSE;

    OALMSG(OAL_FUNC, (TEXT("+ReadBootConfig.\r\n")));

    // Valid caller buffer?
    if (!pBootCfg)
    {
        OALMSG(OAL_ERROR, (TEXT("ERROR: Bad caller buffer.\r\n")));
        goto CleanUp;
    }

    // Read settings from flash...
    //
    if (!AM29LV800_ReadFlash(EBOOT_CONFIG_OFFSET, (PBYTE)pBootCfg, sizeof(BOOT_CFG)))
    {
        OALMSG(OAL_ERROR, (TEXT("ERROR: Flash read failed.\r\n")));
        goto CleanUp;
    }

    // Check configuration signature...
    //
    if (pBootCfg->Signature != CONFIG_SIGNATURE)
    {
        OALMSG(OAL_WARN, (TEXT("WARNING: Boot configuration signature invalid - choosing defaults...\r\n")));
        ResetBootConfig(pBootCfg);
        WriteBootConfig(pBootCfg);
    }

    bResult = TRUE;

CleanUp:

    OALMSG(OAL_FUNC, (TEXT("-ReadBootConfig.\r\n")));
    return(TRUE);

}


/*
    @func   void | SetIP | Accepts IP address from user input.
    @rdesc  N/A.
    @comm    
    @xref   
*/

static void SetIP(PBOOT_CFG pBootCfg)
{
    CHAR   szDottedD[16];   // 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->IPAddr = 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]; // 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];
    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);

⌨️ 快捷键说明

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