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

📄 main.c

📁 老外的一个开源项目
💻 C
📖 第 1 页 / 共 5 页
字号:
	}
    return(retVal);
}


//------------------------------------------------------------------------------
//
//  Function Name:  OEMVerifyMemory( DWORD dwStartAddr, DWORD dwLength )
//  Description..:  This function verifies the passed address range lies
//                  within a valid region of memory. Additionally this function
//                  sets the g_ImageType if the image is a boot loader. 
//  Inputs.......:  DWORD           Memory start address
//                  DWORD           Memory length
//  Outputs......:  BOOL - true if verified, false otherwise
//
//------------------------------------------------------------------------------
BOOL OEMVerifyMemory(DWORD dwStartAddr, DWORD dwLength)
{
    BOOL  rc;
    DWORD dwPhysVerifyStart = (DWORD) OALVAtoPA((void *)dwStartAddr); 
    DWORD dwPhysVerifyEnd   = (DWORD) OALVAtoPA((void *)(dwStartAddr + dwLength - 1));


    OALMSG(1, (L"****** OEMVerifyMemory checking physical range [ 0x%08X ==> 0x%08X ]...\r\n", dwPhysVerifyStart, dwPhysVerifyEnd));


    if ((dwPhysVerifyStart >= IMAGE_BOOT_BLDRIMAGE_FLASH_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_BLDRIMAGE_FLASH_PA_END))
    {
        EdbgOutputDebugString("****** bootloader address ****** \r\n");

        g_ImageType = IMAGE_TYPE_BOOTLOADER;
        rc = TRUE;
    }
    else if ((dwPhysVerifyStart >= BOOT_FLASH_PA_BASE) && (dwPhysVerifyEnd <= (BOOT_FLASH_PA_BASE + g_PCIFlashInfo.MemLen.Reg[0])))
    {
        EdbgOutputDebugString("****** FLASH address ****** \r\n");

        g_ImageType = IMAGE_TYPE_FLASHIMAGE;
        rc = TRUE;
    }
    else if ((dwPhysVerifyStart >= SDRAM_PA_BASE) && (dwPhysVerifyEnd <= (SDRAM_PA_BASE + SDRAM_SIZE)))
    {
        EdbgOutputDebugString("****** RAM address ****** \r\n");

        g_ImageType = IMAGE_TYPE_RAMIMAGE;
        rc = TRUE;
    }
    else
    {
        EdbgOutputDebugString("****** OEMVerifyMemory FAILED - Invalid Memory Area ****** \r\n");
        rc = FALSE;
    }

	g_dwBytesRead = 0;
	if (rc == TRUE)
		g_dwTotalBytes = dwLength;
    return(rc);

}


/*
    @func   void | OEMDownloadFileNotify | Receives/processes download file manifest.
    @rdesc  None.
    @comm    
    @xref   
*/
//------------------------------------------------------------------------------
//
//  Function Name:  OEMDownloadFileNotify( PDownloadManifest pInfo )
//  Description..:  This function Receives/processes download file manifest.
//------------------------------------------------------------------------------
void OEMDownloadFileNotify(PDownloadManifest pInfo)
{
    DWORD dwCount;
    DWORD dwNumNB0Files = 0;

    if (!pInfo) return;

    EdbgOutputDebugString("\r\nDownload file information:\r\n");
    EdbgOutputDebugString("-------------------------------------------------------------------------------\r\n");

    for (dwCount = 0 ; dwCount < pInfo->dwNumRegions ; dwCount++)
    {

        EdbgOutputDebugString("[%d]: Address=0x%x  Length=0x%x  Name=%s\r\n", dwCount, 
                                                                              pInfo->Region[dwCount].dwRegionStart, 
                                                                              pInfo->Region[dwCount].dwRegionLength, 
                                                                              pInfo->Region[dwCount].szFileName);

        // .nb0 files will have a start address of 0 because Platform Builder
        // won't know where to place them.  We'll support only one .nb0 file
        // download (this is an Image Update disk image).  If we need to
        // support more than one .nb0 file download in the future, we'll need
        // to differentiate them by filename.
        //
        if (pInfo->Region[dwCount].dwRegionStart == 0)
        {
            // We only support one raw binary file (image).
            if (dwNumNB0Files++)
            {
                EdbgOutputDebugString("ERROR: This bootloader doesn't support downloading a second .nb0 binary image.\r\n");
                OALSpinForever();
            }

            // The image .nb0 file should be placed immediately after the
            // bootloader image in flash.
//            pInfo->Region[dwCount].dwRegionStart = 0x80001000;

            EdbgOutputDebugString("INFO: Changed start address for %s to 0x%x.\r\n", pInfo->Region[dwCount].szFileName, 
                                                                                     pInfo->Region[dwCount].dwRegionStart);

        }
    }

    EdbgOutputDebugString("\r\n");

    return;
}


BOOL OEMReportError(DWORD dwReason, DWORD dwReserved)
{
	EdbgOutputDebugString("Blcommon ERROR: %d\r\n",dwReason);
	return(TRUE);
}
	
//------------------------------------------------------------------------------
//
//  Function:  SetKmode
//
//  Just to make FMD happy.
//
DWORD SetKMode (DWORD fMode)
{
    return(1);
}



//------------------------------------------------------------------------------
//
//  Function:  InitSpeed
//
//  Initalize the speed of the processor.
//
//  If 400Mhz speed capable.. boost clock
//
static void InitSpeed(void)
{
	UINT32 Lfreq = 0;
	UINT32 Mfreq = 0;
	UINT32 Nfreq = 0;
	volatile CLK_REG_T  *pCLKRegs = (volatile CLK_REG_T *)OALPAtoVA(PXA255_BASE_REG_PA_CLK, FALSE);


	if (g_EbootCFG.dwPlatformHardware & GUMCFG_SPD)
	{
		pCLKRegs->CCCR = (CCCR_L27 | CCCR_M4 | CCCR_N10);	// 400Mhz
		FreqChange();
	}

	// L
	if ((pCLKRegs->CCCR & CCCR_L) == CCCR_L27)
	{
		Lfreq = OEM_CLOCK_FREQ * 27;
        EdbgOutputDebugString("Memory clock:      %d.%dMHz\r\n",
		Lfreq / 1000000, (Lfreq % 1000000) / 10000);
	}
	// M
	switch (pCLKRegs->CCCR & CCCR_M)
	{
	case CCCR_M1:
		Mfreq = Lfreq;
		break;
	case CCCR_M2:
		Mfreq = Lfreq * 2;
		break;
	case CCCR_M4:
		Mfreq = Lfreq * 4;
		break;
	}
    EdbgOutputDebugString("Run Mode clock:   %d.%dMHz\r\n",
	Mfreq / 1000000, (Mfreq % 1000000) / 10000);
	// N
	switch (pCLKRegs->CCCR & CCCR_N)
	{
	case CCCR_N10:
		Nfreq = Mfreq;
		break;
	case CCCR_N15:
		Nfreq = Mfreq + Mfreq / 2;
		break;
	case CCCR_N20:
		Nfreq = Mfreq * 2;
		break;
	case CCCR_N30:
		Nfreq = Mfreq * 4;
		break;
	}
    EdbgOutputDebugString("Turbo Mode clock: %d.%dMHz\r\n",
	Nfreq / 1000000, (Nfreq % 1000000) / 10000);
}


//------------------------------------------------------------------------------
//
//  Function:  InitFlash
//
//  Initalize the Flash memory system.
//
//
static BOOL InitFlash(void)
{
	BOOL xipMode = TRUE;

	// Initialize the flash interface
    memset(&g_PCIFlashInfo, 0, sizeof(PCI_REG_INFO));
    g_PCIFlashInfo.MemBase.Num = 1;
    g_PCIFlashInfo.MemLen.Num  = 1;
	if (DetectXMFlashDevice((DWORD)OALPAtoVA(BOOT_FLASH_PA_BASE,FALSE)))
	    g_PCIFlashInfo.MemLen.Reg[0] = BOOT_FLASH_16M_SIZE;
	else
	    g_PCIFlashInfo.MemLen.Reg[0] = BOOT_FLASH_4M_SIZE;
    g_PCIFlashInfo.MemBase.Reg[0] = (DWORD)OALPAtoVA(BOOT_FLASH_PA_BASE, FALSE);

	if (!FMD_OEMIoControl(IOCTL_FMD_SET_XIPMODE,(PBYTE)&xipMode,sizeof(xipMode),NULL,0,NULL))
	{
        EdbgOutputDebugString("ERROR: could not set XIP mode.\r\n");
        ResetDefaultEBootCFG(&g_EbootCFG);
	}
	else
	{
		if (!FMD_Init(NULL, &g_PCIFlashInfo, NULL))
		{
			// Load default bootloader configuration settings.
			//
			EdbgOutputDebugString("ERROR: flash initialization failed - loading bootloader defaults...\r\n");
			ResetDefaultEBootCFG(&g_EbootCFG);
		}
		else
		{
			if (!FMD_GetInfo(&g_FlashInfo))
			{
				EdbgOutputDebugString("ERROR: can't get Flash info.\r\n");
			}
			else
			{
				EdbgOutputDebugString("FLASH INFO:Size %d\r\n",(g_FlashInfo.dwBytesPerBlock * g_FlashInfo.dwNumBlocks));
				EdbgOutputDebugString("FLASH INFO:Bytes per blocks: %d Number of blocks: %d\r\n",
					g_FlashInfo.dwBytesPerBlock,
					g_FlashInfo.dwNumBlocks);
				EdbgOutputDebugString("FLASH INFO:Sectors per blocks: %d Data bytes per sector: %d\r\n",
					g_FlashInfo.wSectorsPerBlock,
                    g_FlashInfo.wDataBytesPerSector);
			}
		}
	}
	return(TRUE);
}


//------------------------------------------------------------------------------
//
//  Function:  LockBootBlocks
//
//  Lock the bootloader and parameter block(s).
//	If Lockit TRUE lock the blocks else unlock it.
//
//	returns TRUE if success
//
static BOOL LockBootBlocks(BOOL Lockit)
{
	BlockLockInfo blockLockInfo;

	blockLockInfo.StartBlock = (BLOCK_ID)(IMAGEFLASH_LOADER_BLOCKOFFSET);
	blockLockInfo.NumBlocks = IMAGEFLASH_NK_BLOCKOFFSET;	//i.e 3 blocks for bootloader and parameters

	if (Lockit)
	{
		if (!FMD_OEMIoControl(IOCTL_FMD_LOCK_BLOCKS,(PBYTE)&blockLockInfo,sizeof(blockLockInfo),NULL,0,NULL))
		{
			EdbgOutputDebugString("ERROR: Could not lock Flash bootloader block.\n");
			return(FALSE);
		}
	}
	else
	{
		if (!FMD_OEMIoControl(IOCTL_FMD_UNLOCK_BLOCKS,(PBYTE)&blockLockInfo,sizeof(blockLockInfo),NULL,0,NULL))
		{
			EdbgOutputDebugString("ERROR: Could not unlock Flash bootloader block.\n");
			return(FALSE);
		}
	}

	return(TRUE);
}


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

	LockBootBlocks(FALSE);	// unlock configuration/boot blocks
	
	memset(&g_SectorBuffer,0,sizeof(g_SectorBuffer));
	memcpy(&g_SectorBuffer,EBootCFG,sizeof(EBOOT_CFG));

	if (!FMD_EraseBlock((BLOCK_ID)(IMAGE_BOOT_CONFIG_FLASH_OFFSET / g_FlashInfo.dwBytesPerBlock)))
    {
        EdbgOutputDebugString("ERROR: StoreEBootCFG: failed to erase configuration in Flash.\r\n");
        return(FALSE);
    }
	if (!FMD_WriteSector(IMAGE_BOOT_CONFIG_FLASH_OFFSET / g_FlashInfo.wDataBytesPerSector, (LPBYTE)&g_SectorBuffer, NULL, 1))
    {
        EdbgOutputDebugString("ERROR: StoreEBootCFG: failed to write configuration to Flash.\r\n");
        return(FALSE);
    }

//	LockBootBlocks(TRUE);	// lock configuration/boot blocks
	if (LockBootBlocks(TRUE))	// lock configuration/boot blocks
	{
		LoadEBootCFG(&g_EbootCFG);	// read it back ..just to see if we can
	}
	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");

	if (DetectXMFlashDevice((DWORD)OALPAtoVA(BOOT_FLASH_PA_BASE,FALSE)))
    {
        pEbootCFG->dwPlatformHardware = GUMCFG_XM;
    }
	pEbootCFG->dwPlatformHardware= 0;
	pEbootCFG->imageLoadDevice   = IMG_LOAD_DOWNLOAD;
    pEbootCFG->IP                = inet_addr("0.0.0.0"); 
    pEbootCFG->subnetMask        = inet_addr("0.0.0.0"); 
	pEbootCFG->Eth1mac[0]		 = 0;
	pEbootCFG->Eth1mac[1]		 = 0;
	pEbootCFG->Eth1mac[2]		 = 0;
	pEbootCFG->Eth2mac[0]		 = 0;
	pEbootCFG->Eth2mac[1]		 = 0;
	pEbootCFG->Eth2mac[2]		 = 0;
	pEbootCFG->numBootMe         = 0;
    pEbootCFG->delay             = 3;
    pEbootCFG->Extra0            = 0;
	pEbootCFG->Extra1            = 0;
	pEbootCFG->Extra2            = 0;
	pEbootCFG->Extra3            = 0;
    pEbootCFG->DHCPEnable        = TRUE;
    pEbootCFG->priBootDevice     = BOOT_DEVICE_STUART;
    pEbootCFG->secBootDevice     = BOOT_DEVICE_ETH1;
    pEbootCFG->downloadBaud      = 115200;
    pEbootCFG->Extra5            = 0;
    pEbootCFG->Extra6            = 0;
    pEbootCFG->dwDbgSerPhysAddr  = DEFAULT_DEBUG_PORT;
    pEbootCFG->Extra7            = 0;
    pEbootCFG->CheckSignatures   = FALSE;
    pEbootCFG->ConfigMagicNumber = EBOOT_CFG_MAGIC_NUMBER;

}


//------------------------------------------------------------------------------
//
//  Function:  LoadEBootCFG
//
//  Retrieves bootloader configuration information (menu settings, etc.) from flash.
//
static BOOL LoadEBootCFG(EBOOT_CFG *EBootCFG)
{

	memset(&g_SectorBuffer,0,sizeof(g_SectorBuffer));
    if (!FMD_ReadSector(IMAGE_BOOT_CONFIG_FLASH_OFFSET / g_FlashInfo.wDataBytesPerSector, (LPBYTE)&g_SectorBuffer, NULL, 1))
    {
        EdbgOutputDebugString("ERROR: LoadEBootCFG: failed to load configuration.\r\n");
        return(FALSE);
    }
	memcpy(EBootCFG,&g_SectorBuffer,sizeof(EBOOT_CFG));
    // Is the CFG data valid?  Check for the magic number that was written the last time
    // the CFG block was updated.  If Eboot has never been run, there will be no configuration
    // information, so the magic number will likely not be found.  In this case, setup the 
    // factory defaults and store them into Flash.
    //
    if (EBootCFG->ConfigMagicNumber != EBOOT_CFG_MAGIC_NUMBER)
    {
        EdbgOutputDebugString("ERROR: LoadEBootCFG: failed to read magic number.\r\n");
        ResetDefaultEBootCFG(EBootCFG);
    }

    // Make sure a valid debug serial port address (physical) was found.
    //
    if (g_EbootCFG.dwDbgSerPhysAddr == 0)
    {
        g_EbootCFG.dwDbgSerPhysAddr = DEFAULT_DEBUG_PORT;
    }
    // auto set the flash size (XM bit) in dwPlatformHardware.
    //
	if (DetectXMFlashDevice((DWORD)OALPAtoVA(BOOT_FLASH_PA_BASE,FALSE)))
    {
        g_EbootCFG.dwPlatformHardware |= GUMCFG_XM;
    }
	else
    {
        g_EbootCFG.dwPlatformHardware &= ~GUMCFG_XM;
    }

    return(TRUE);
}


static void SetIPConfig(EBOOT_CFG *pEbootCFG)

⌨️ 快捷键说明

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