main.c

来自「该BSP是基于PXA270+WINCE的BSP」· C语言 代码 · 共 1,654 行 · 第 1/4 页

C
1,654
字号
                    g_EbootCFG.bootDeviceOrder = 0;
     
                    EdbgOutputDebugString ( "%s\r\n", BootOrderString[g_EbootCFG.bootDeviceOrder]);
                }
                EdbgOutputDebugString ( "8) Debug serial port: ");
                {
                    switch (g_EbootCFG.dwDbgSerPhysAddr)
                    {
                        case BULVERDE_BASE_REG_PA_FFUART:
                        EdbgOutputDebugString ( "FFUART\r\n");
                        break;

                        case BULVERDE_BASE_REG_PA_BTUART:
                        default:
                        EdbgOutputDebugString ( "BTUART\r\n");
                        break;
                    }
                }
                EdbgOutputDebugString ( "D) Download image now\r\n");
                EdbgOutputDebugString ( "L) Launch existing flash resident image now\r\n");
                EdbgOutputDebugString ( "U) Boot to ULDR: %s\r\n", (g_pBSPArgs->bUpdateMode == TRUE?"(Yes)":"(No)"));

//-----------------------------------------------------------------
                EdbgOutputDebugString ( "P) Set display\r\n");
                EdbgOutputDebugString ( "S) Save change\r\n");
//-----------------------------------------------------------------
                EdbgOutputDebugString ( "\r\n\r\nEnter your selection: ");
                Selection = 0;
                while (! ( ( (Selection >= '0') && (Selection <= '8') ) || 
                           ( (Selection == 'D') || (Selection == 'd') ) || 
                           ( (Selection == 'L') || (Selection == 'l') ) || 
//-----------------------------------------------------------------
                           ( (Selection == 'P') || (Selection == 'p') ) || 
                           ( (Selection == 'S') || (Selection == 's') ) || 
//-----------------------------------------------------------------
                           ( (Selection == 'U') || (Selection == 'u') ) ))
                {
                    Selection = OEMReadDebugByte();
                }
                EdbgOutputDebugString ( "%c\r\n", Selection);
                switch (Selection)
                {
                case '0':
                    SetIP(&g_EbootCFG);
                    bCFGChanged=TRUE;
                    break;
                case '1':
                    SetMask(&g_EbootCFG);
                    bCFGChanged=TRUE;
                    break;
                case '2':
                    SetDelay(&g_EbootCFG);
                    bCFGChanged=TRUE;
                    break;
                case '3':
                    if (g_EbootCFG.DHCPEnable == TRUE)
                        g_EbootCFG.DHCPEnable = FALSE;
                    else
                        g_EbootCFG.DHCPEnable = TRUE;
                    bCFGChanged=TRUE;
                    break;
                case '4':
                    ResetDefaultEBootCFG(&g_EbootCFG);
                    bCFGChanged=TRUE;
                    break;
                case '5':
					//-------------------------------------------------
                    // SetMAC(&rndis_mac[0]);
                    //// Save the user enter RNDIS MAC address
                    //g_EbootCFG.RNDISMac[0] = (rndis_mac[1] << 8) | rndis_mac[0];
                    //g_EbootCFG.RNDISMac[1] = (rndis_mac[3] << 8) | rndis_mac[2];
                    //g_EbootCFG.RNDISMac[2] = (rndis_mac[5] << 8) | rndis_mac[4];
                    //bCFGChanged = TRUE;
					//-------------------------------------------------
					SetSMSCMACAddr2Flash(&g_EbootCFG);
					bCFGChanged=TRUE;
					//-------------------------------------------------					
                    break;
                case '6':
                    if (g_EbootCFG.autoDownloadImage == TRUE)
                        g_EbootCFG.autoDownloadImage = FALSE;
                    else
                        g_EbootCFG.autoDownloadImage = TRUE;
                    bCFGChanged=TRUE;
                    break;
                case '7':
                    g_EbootCFG.bootDeviceOrder++;
                    if (g_EbootCFG.bootDeviceOrder >= NUM_BOOT_ORDERS)
                        g_EbootCFG.bootDeviceOrder = 0;
                    bCFGChanged=TRUE;
                    break;
                case '8':
                    if ((g_EbootCFG.dwDbgSerPhysAddr == 0) || (g_EbootCFG.dwDbgSerPhysAddr == BULVERDE_BASE_REG_PA_BTUART))
                    {
                        g_EbootCFG.dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_FFUART;
                    }
                    else
                    {
                        g_EbootCFG.dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_BTUART;
                    }
                    bCFGChanged=TRUE;
                    break;
                case 'D':
                case 'd':
                    if (bCFGChanged == TRUE)
                    {
                        StoreEBootCFG(&g_EbootCFG);
                    }
                    g_DownloadImage = TRUE;
                    goto CONTINUE;
                case 'L':
                case 'l':
                    if (bCFGChanged == TRUE)
                    {
                        StoreEBootCFG(&g_EbootCFG);
                    }
                    g_DownloadImage = FALSE;
                    goto CONTINUE;

		//-----------------------------------------------------------------					
        case 'P':
        case 'p':
            {
				SetDisplayArgs(&g_EbootCFG);//
				bCFGChanged = TRUE;
            }
			break;

		case 'S':
		case 's':
			if (bCFGChanged == TRUE)	{
				StoreEBootCFG(&g_EbootCFG);
			}
			break;
		//-----------------------------------------------------------------

        case 'U':
        case 'u':
            {
                if(g_pBSPArgs->bUpdateMode == TRUE)
                {
                    g_pBSPArgs->bUpdateMode = FALSE;
                }
                else
                {
                    g_pBSPArgs->bUpdateMode = TRUE;
                }
                bCFGChanged=TRUE;
            }
                default:
                    break;
                }
            }
        }
    }

  CONTINUE:

	//-----------------------------------------------------
	memcpy(&(g_pBSPArgs->tDspRegVal),&(g_EbootCFG.tDspRegVal),sizeof(g_EbootCFG.tDspRegVal));
	//-----------------------------------------------------

	//-----------------------------------------------------
	memcpy(&(g_pBSPArgs->kitl.mac),&(g_EbootCFG.RNDISMac),sizeof(UINT16)*3);
	//-----------------------------------------------------


    // Provide the chosen debug serial port address to the OS image for debug output messages.
    //
    g_pBSPArgs->dbgSerPhysAddr = g_EbootCFG.dwDbgSerPhysAddr;

    EthDevice = -1;

    // Locate and initialize an Ethernet controller.
    //
    for(i = 0; (i < NUM_BOOT_ETHDEV) && (EthDevice == -1) ; i++) 
    {
        // Try each of the boot devices in the specified order (until one succeeds or they all fail).
        //
        EthDevice = InitSpecifiedEthDevice(&g_pBSPArgs->kitl, BootOrder[g_EbootCFG.bootDeviceOrder][i]);
    }

    // No device was found ... 
    //
    if (EthDevice == -1)
    {
        EdbgOutputDebugString("ERROR: Failed to detect and initialize Ethernet controller.\r\n");
        return(FALSE);
    }

    // Make sure MAC address has been programmed.
    //
    if (!g_pBSPArgs->kitl.mac[0] && !g_pBSPArgs->kitl.mac[1] && !g_pBSPArgs->kitl.mac[2])
    {
       EdbgOutputDebugString("ERROR: Invalid Ethernet address read from Ethernet controller.\n");
       return(FALSE);
    }
    else
    {
        EdbgOutputDebugString("INFO: MAC address: %x-%x-%x-%x-%x-%x\r\n",
              g_pBSPArgs->kitl.mac[0] & 0x00FF, g_pBSPArgs->kitl.mac[0] >> 8,
              g_pBSPArgs->kitl.mac[1] & 0x00FF, g_pBSPArgs->kitl.mac[1] >> 8,
              g_pBSPArgs->kitl.mac[2] & 0x00FF, g_pBSPArgs->kitl.mac[2] >> 8);
    }

    return(TRUE);

}


//------------------------------------------------------------------------------
//
//  Function:  OEMPreDownload
//
//  Pre-download initialization routine.
//
DWORD OEMPreDownload(void)
{
    UINT32 SubnetMask;
    BOOL  fGotJumpImg = FALSE, fGotIP = FALSE;
    UINT32 DHCPLeaseTime = 0;
    UINT32 *pDHCPLeaseTime = &DHCPLeaseTime;
    UINT32 BootFlags = 0;


    // Create device name based on Ethernet address (this is how Platform Builder identifies this device).
    //
    OALKitlCreateName(BSP_DEVICE_PREFIX, g_pBSPArgs->kitl.mac, g_pBSPArgs->deviceId);
    EdbgOutputDebugString("INFO: Using device name: '%s'\n", g_pBSPArgs->deviceId);

    // User doesn't want to get a DHCP address...
    // If user wants to jump to existing image, we may still need to populate
    //  ARGS so that a KITL session can correctly start up.
    //
    if (g_EbootCFG.DHCPEnable == FALSE)
    {
        pDHCPLeaseTime             = NULL;
        g_pBSPArgs->kitl.ipAddress = g_EbootCFG.IP;
        g_pBSPArgs->kitl.ipMask    = g_EbootCFG.subnetMask;
        g_pBSPArgs->kitl.flags    &= ~OAL_KITL_FLAGS_DHCP;
    }

    // If user wants to jump to existing image - skip download...
    //
    if (!g_DownloadImage)
    {
        return(BL_JUMP);
    }

    // Initialize the TFTP transport.
    memcpy(g_DeviceAddr.wMAC, g_pBSPArgs->kitl.mac, (sizeof(UINT16) * 3));
    g_DeviceAddr.dwIP  = g_pBSPArgs->kitl.ipAddress;
    g_DeviceAddr.wPort = 0;
    SubnetMask         = g_pBSPArgs->kitl.ipMask;

    if (!EbootInitEtherTransport(&g_DeviceAddr,
                                 &SubnetMask,
                                 &fGotJumpImg,
                                 pDHCPLeaseTime,
                                 EBOOT_VERSION_MAJOR,
                                 EBOOT_VERSION_MINOR,
                                 BSP_DEVICE_PREFIX,
                                 g_pBSPArgs->deviceId,
                                 EDBG_CPU_ARM720,
                                 BootFlags))
    {
        return(BL_ERROR);
    }

    // If the user wanted a DHCP address, save the values obtained in the init call above.
    //
    if (g_EbootCFG.DHCPEnable == TRUE)
    {
        g_pBSPArgs->kitl.ipAddress  = g_DeviceAddr.dwIP;
        g_pBSPArgs->kitl.ipMask     = SubnetMask;
        g_pBSPArgs->kitl.flags     |= OAL_KITL_FLAGS_DHCP;
    }

    return(fGotJumpImg? BL_JUMP : BL_DOWNLOAD);
}


//------------------------------------------------------------------------------
//
//  Function:  OEMLaunch
//
//  Launch downloaded/stored image.
//
void OEMLaunch(DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr, const ROMHDR *pRomHdr)
{
    EDBG_OS_CONFIG_DATA *pCfgData;
    EDBG_ADDR EshellHostAddr;
    UINT32 PhysAddress;


    // If a launch address wasn't specified - use the last known good address.
    //
    if (!dwLaunchAddr)
    {
        dwLaunchAddr = g_EbootCFG.dwLaunchAddr;
    }
    else
    {
        if (g_EbootCFG.dwLaunchAddr != dwLaunchAddr ||
            g_EbootCFG.dwPhysStart  != dwImageStart ||
            g_EbootCFG.dwPhysLen    != dwImageLength)
        {
            g_EbootCFG.dwLaunchAddr = dwLaunchAddr;
            g_EbootCFG.dwPhysStart  = dwImageStart;
            g_EbootCFG.dwPhysLen    = dwImageLength;
            g_EbootCFG.dwStoreAddr  = 0;

            StoreEBootCFG(&g_EbootCFG);
        }
    }

    // Translate the image start address (virtual address) to a physical address.
    //
    PhysAddress = (UINT32) OALVAtoPA((VOID *)dwLaunchAddr);
    EdbgOutputDebugString("Download successful!  Jumping to image at 0x%x (physical 0x%x)...\r\n", dwLaunchAddr, PhysAddress);

    // Wait for PB connection...
    //
    if (g_DownloadImage)
    {
        if (!(pCfgData = EbootWaitForHostConnect(&g_DeviceAddr, &EshellHostAddr)))
        {
            EdbgOutputDebugString("ERROR: EbootWaitForHostConnect failed!\r\n");
            SpinForever();
        }

        // If the user selected "passive" KITL (i.e., don't connect to the target at boot time), set the
        // flag in the args structure so the OS image can honor it when it boots.
        //
        if (pCfgData && (pCfgData->KitlTransport & KTS_PASSIVE_MODE))
        {
            g_pBSPArgs->kitl.flags |= OAL_KITL_FLAGS_PASSIVE;
        }
    }


    // Jump to the image we just downloaded.
    //
    EdbgOutputDebugString("\r\n\r\n\r\n");
    Launch(PhysAddress);

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

}


//------------------------------------------------------------------------------
//
//  Function:  StoreEBootCFG
//
//  Stores bootloader configuration information (menu settings, etc.) in flash.
//
static BOOL StoreEBootCFG(EBOOT_CFG *EBootCFG)
{

    if (!FlashWrite(EBOOT_FLASH_CFG_START, (PUCHAR)EBootCFG, sizeof(EBOOT_CFG)))
    {
        EdbgOutputDebugString("ERROR: StoreEBootCFG: failed to write configuration.\r\n");
        return(FALSE);
    }

    return(TRUE);
}


//------------------------------------------------------------------------------
//
//  Function:  ResetDefaultEBootCFG
//
//  Resets the debug bootloader configuration information (menu settings, etc.).
//
static void ResetDefaultEBootCFG(EBOOT_CFG *pEbootCFG)
{

    EdbgOutputDebugString("\r\nResetting factory default configuration...\r\n");

    pEbootCFG->autoDownloadImage = TRUE;
//--------------------
//  pEbootCFG->IP                = inet_addr("0.0.0.0"); 
//  pEbootCFG->subnetMask        = inet_addr("0.0.0.0"); 
    pEbootCFG->IP                = inet_addr("192.168.5.243"); 
    pEbootCFG->subnetMask        = inet_addr("255.255.255.0"); 
//--------------------
    pEbootCFG->numBootMe         = 50;
    pEbootCFG->delay             = 3;
//--------------------
//  pEbootCFG->DHCPEnable        = TRUE;
    pEbootCFG->DHCPEnable        = FALSE;
//--------------------
    pEbootCFG->dwLaunchAddr      = 0;
    pEbootCFG->dwPhysStart       = 0;
    pEbootCFG->dwPhysLen         = 0;
//--------------------
//  pEbootCFG->bootDeviceOrder   = 0;
    pEbootCFG->bootDeviceOrder   = 1;

//{ ETH_DEVICE_PCMCIA0, ETH_DEVICE_PCMCIA1, ETH_DEVICE_SMSC, ETH_DEVICE_USB,  },       // pEbootCFG->bootDeviceOrder = 0.
//{ ETH_DEVICE_SMSC,    ETH_DEVICE_USB,     ETH_DEVICE_PCMCIA0, ETH_DEVICE_PCMCIA1 },  // pEbootCFG->bootDeviceOrder = 1.
//{ ETH_DEVICE_USB,     ETH_DEVICE_SMSC,    ETH_DEVICE_PCMCIA0, ETH_DEVICE_PCMCIA1 },  // pEbootCFG->bootDeviceOrder = 2.
//{ ETH_DEVICE_PCMCIA1, ETH_DEVICE_PCMCIA0, ETH_DEVICE_SMSC, ETH_DEVICE_USB,  },       // pEbootCFG->bootDeviceOrder = 3.
//--------------------
//--------------------
//  pEbootCFG->dwDbgSerPhysAddr  = BULVERDE_BASE_REG_PA_BTUART;
    pEbootCFG->dwDbgSerPhysAddr  = BULVERDE_BASE_REG_PA_FFUART;
//--------------------	
    pEbootCFG->dwStoreAddr       = 0;
    pEbootCFG->CheckSignatures   = FALSE;

⌨️ 快捷键说明

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