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

📄 main.c

📁 i.Mx31 bootloader(for WinCE6.0)
💻 C
📖 第 1 页 / 共 2 页
字号:
        // Set launch address for NAND/SDHC OS image.  OS is copied into RAM for execution.
        PhysAddress = IMAGE_BOOT_NKIMAGE_RAM_PA_START;
        break;

    case BOOT_CFG_AUTODOWNLOAD_IPL_NAND:
        // Set launch address for NAND IPL image.  IPL is copied into RAM for execution.
        PhysAddress = IMAGE_BOOT_IPLIMAGE_RAM_START;
        break;

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

                StoreBootCFG(&g_BootCFG);
            }
        }

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

    // Wait for PB connection...
    //
    if (g_DownloadImage)
    {
	GetLaunchInfo ();
    }

    // Jump to the image we just downloaded.
    //
    KITLOutputDebugString("\r\n\r\n\r\n");
    OEMWriteDebugLED(0, 0x00FF);
    Launch(PhysAddress);

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

}


//------------------------------------------------------------------------------
//
//  Function:  OEMMultiBINNotify
//
//  Receives/processes download file manifest.
//
//  Parameters:
//      pInfo 
//          [in] Download manifiest provided by BLCOMMON framework.
//
//  Returns:
//             void
//------------------------------------------------------------------------------
void OEMMultiBINNotify(const PMultiBINInfo pInfo)
{
    CHAR szFileName[MAX_PATH];
    int i, key, fileExtPos;

    if (!pInfo) return;

    KITLOutputDebugString("INFO: OEMMultiBINNotify (dwNumRegions = %d, dwRegionStart = 0x%x).\r\n", 
        pInfo->dwNumRegions, pInfo->Region[0].dwRegionStart);
    
    // Only inspect manifest if this is a monolithic .nb0 or diskimage file
    if (pInfo->dwNumRegions != 1) 
        return;

    //  NBO and DIO files will have start address of zero
    if (pInfo->Region[0].dwRegionStart == 0)
    {

        // Convert the file name to lower case
        i = 0;
        fileExtPos = 0;
        while ((pInfo->Region[0].szFileName[i] != '\0') && (i < MAX_PATH))
        {
            szFileName[i] = (CHAR)tolower(pInfo->Region[0].szFileName[i]);
            // Keep track of file extension position
            if (szFileName[i] == '.')
            {
                fileExtPos = i;
            }
            i++;
        }
        
        // Check for NAND XLDR update
        if (strncmp(szFileName, XLDR_NB0_FILE, XLDR_NB0_FILE_LEN) == 0)
        {
			// Remap the start address to the NAND XLDR region
            pInfo->Region[0].dwRegionStart = (DWORD) OALPAtoCA(IMAGE_BOOT_XLDRIMAGE_NAND_PA_START);
            KITLOutputDebugString("INFO: XLDR NB0 remapped to 0x%x.\r\n", pInfo->Region[0].dwRegionStart);
        }

        // Check for EBOOT/SBOOT update
        else if  ( (strncmp(szFileName, EBOOT_NB0_FILE, EBOOT_NB0_FILE_LEN) == 0) ||
		   (strncmp(szFileName, SBOOT_NB0_FILE, SBOOT_NB0_FILE_LEN) == 0) )
        {
            // Remap the start address to the region specified by the user
            KITLOutputDebugString("Specify destination for EBOOT/SBOOT NB0 [1 = NOR, 2 = NAND]: ");
            do {
                key = OEMReadDebugByte();
            } while ((key != '1') && (key != '2'));
            KITLOutputDebugString("\r\n");
            switch (key)
            {
            case '1':
                pInfo->Region[0].dwRegionStart = (DWORD) OALPAtoCA(IMAGE_BOOT_BOOTIMAGE_NOR_PA_START);
                break;
                
            case '2':
                pInfo->Region[0].dwRegionStart = (DWORD) OALPAtoCA(IMAGE_BOOT_BOOTIMAGE_NAND_PA_START);
                break;

			default:
                return;
            }

            KITLOutputDebugString("\r\nINFO: EBOOT/SBOOT NB0 remapped to 0x%x.\r\n", pInfo->Region[0].dwRegionStart);
        }
        
        // If  file to be downloaded has an NB0 extension, assume it is an NK NB0 image
        else if (fileExtPos && (strncmp(&szFileName[fileExtPos], ".nb0", 4) == 0))
        {
            // Remap the start address to the region specified by the user
            KITLOutputDebugString("Specify destination for NK NB0 [0 = RAM, 1 = NOR, 2 = NAND,]: ");
            do {
                key = OEMReadDebugByte();
            } while ((key != '0') && (key != '1') && (key != '2'));
            KITLOutputDebugString("\r\n");
            switch (key)
            {
            case '0':
                pInfo->Region[0].dwRegionStart = (DWORD) OALPAtoCA(IMAGE_BOOT_NKIMAGE_RAM_PA_START);
                break;

            case '1':
                pInfo->Region[0].dwRegionStart = (DWORD) OALPAtoCA(IMAGE_BOOT_NKIMAGE_NOR_PA_START);
                break;
                
            case '2':
                pInfo->Region[0].dwRegionStart = (DWORD) OALPAtoCA(IMAGE_BOOT_NKIMAGE_NAND_PA_START);
                break;

			default:
                return;
            }

            KITLOutputDebugString("\r\nINFO: NK NB0 remapped to 0x%x.\r\n", pInfo->Region[0].dwRegionStart);
        }

        // Notify user of unsupported format
        else 
        {
            KITLOutputDebugString("\r\nWARNING: Unsupported binary format.  Image not remapped.\r\n");
        }
    }

    // If this is a Windows Mobile disk image BIN, then dwRegionStart will
    // be offset into NAND.
    else if (pInfo->Region[0].dwRegionStart < IMAGE_BOOT_RAMDEV_RAM_PA_START)
    {
        g_ImageType = IMAGE_TYPE_BINDIO;
        g_ImageMemory = IMAGE_MEMORY_NAND;
        KITLOutputDebugString("\r\nINFO: DIO image with starting address 0x%x.\r\n", pInfo->Region[0].dwRegionStart);
    }
    
    return;
}

//------------------------------------------------------------------------------
//
//  Function:  OEMReportError
//
//  Error reporting function provided by BLCOMMON framework.
//
//  Parameters:
//      dwReason 
//          [in] Reason for error
//
//      dwReserved 
//          [in] Reserved parameter
//
//  Returns:
//             void
//------------------------------------------------------------------------------
BOOL OEMReportError (DWORD dwReason, DWORD dwReserved)
{
    // Remove-W4: Warning C4100 workaround
    UNREFERENCED_PARAMETER(dwReserved);

    KITLOutputDebugString("INFO: OEMReportError Reason 0x%x\r\n", dwReason);

	return TRUE;	
}

//-----------------------------------------------------------------------------
//
//  Function:  OEMVerifyMemory
//
//  This function verifies that the address provided is in valid memory,
//  and sets globals to describe the image region being updated.
//
//  Parameters:
//      dwStartAddr 
//          [in] Address to be verified. 
//
//      dwLength 
//          [in] Length of the address, in bytes.
//
//  Returns:
//      TRUE indicates success. FALSE indicates failure.
//
//-----------------------------------------------------------------------------
BOOL OEMVerifyMemory(DWORD dwStartAddr, DWORD dwLength)
{
    BOOL  rc = TRUE;
    DWORD dwPhysVerifyStart; 
    DWORD dwPhysVerifyEnd;

    // First check for DIO image flagged by OEMMultiBINNotify
    if (g_ImageType == IMAGE_TYPE_BINDIO)
    {
        KITLOutputDebugString("INFO: Downloading DIO NAND image.\r\n");
        return (TRUE);
    }

    dwPhysVerifyStart = (DWORD) OALVAtoPA((void *)dwStartAddr); 
    dwPhysVerifyEnd   = dwPhysVerifyStart + dwLength - 1;

    KITLOutputDebugString("INFO: OEMVerifyMemory (CA = 0x%x, PA = 0x%x, length = 0x%x)\r\n", 
        dwStartAddr, dwPhysVerifyStart, dwLength);

    if ((dwPhysVerifyStart >= IMAGE_BOOT_XLDRIMAGE_NAND_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_XLDRIMAGE_NAND_PA_END))
    {
        KITLOutputDebugString("INFO: Downloading XLDR NAND image.\r\n");
        g_ImageType = IMAGE_TYPE_XLDR;
        g_ImageMemory = IMAGE_MEMORY_NAND;
    }
    else if ((dwPhysVerifyStart >= IMAGE_BOOT_BOOTIMAGE_NAND_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_BOOTIMAGE_NAND_PA_END))
    {
        KITLOutputDebugString("INFO: Downloading EBOOT/SBOOT NAND image.\r\n");
        g_ImageType = IMAGE_TYPE_BOOT;
        g_ImageMemory = IMAGE_MEMORY_NAND;
    }
    else if ((dwPhysVerifyStart >= IMAGE_BOOT_IPLIMAGE_NAND_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_IPLIMAGE_NAND_PA_END))
    {
        KITLOutputDebugString("INFO: Downloading IPL NAND image.\r\n");
        g_ImageType = IMAGE_TYPE_IPL;
        g_ImageMemory = IMAGE_MEMORY_NAND;
    }
    // DIO and NK share this start address
    else if ((dwPhysVerifyStart >= IMAGE_BOOT_NKIMAGE_NAND_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_NKIMAGE_NAND_PA_END))
    {
        KITLOutputDebugString("INFO: Downloading NK NAND image.\r\n");
        g_ImageType = IMAGE_TYPE_NK;
        g_ImageMemory = IMAGE_MEMORY_NAND;
    }
    else if ((dwPhysVerifyStart >= IMAGE_BOOT_BOOTIMAGE_NOR_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_BOOTIMAGE_NOR_PA_END))
    {
        KITLOutputDebugString("INFO: Downloading EBOOT/SBOOT NOR image.\r\n");
        g_ImageType = IMAGE_TYPE_BOOT;
        g_ImageMemory = IMAGE_MEMORY_NOR;
    }
    else if ((dwPhysVerifyStart >= IMAGE_BOOT_NKIMAGE_NOR_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_NKIMAGE_NOR_PA_END))
    {
        KITLOutputDebugString("INFO: Downloading NK NOR image.\r\n");
        g_ImageType = IMAGE_TYPE_NK;
        g_ImageMemory = IMAGE_MEMORY_NOR;
    }
    else if ((dwPhysVerifyStart >= IMAGE_BOOT_NORDEV_NOR_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_NORDEV_NOR_PA_END))
    {
        KITLOutputDebugString("INFO: Downloading NK NOR image.\r\n");
        KITLOutputDebugString("WARNING:  NK image will overwrite EBOOT reserved space \r\n");
        g_ImageType = IMAGE_TYPE_NK;
        g_ImageMemory = IMAGE_MEMORY_NOR;
    }
    else if ((dwPhysVerifyStart >= IMAGE_BOOT_RAMDEV_RAM_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_RAMDEV_RAM_PA_END))
    {
        KITLOutputDebugString("INFO: Downloading NK RAM image.\r\n");
        g_ImageType = IMAGE_TYPE_NK;
        g_ImageMemory = IMAGE_MEMORY_RAM;
    }
    else
    {
        KITLOutputDebugString("ERROR: Invalid address range.\r\n");
        rc = FALSE;
    }

    return(rc);

}


//------------------------------------------------------------------------------
//
//  Function:  StoreBootCFG
//
//  Stores bootloader configuration information (menu settings, etc.) in flash.
//
//  Parameters:
//      BootCfg 
//          [in] Points to bootloader configuration to be stored. 
//
//  Returns:
//      TRUE indicates success. FALSE indicates failure.
//
//-----------------------------------------------------------------------------
BOOL StoreBootCFG(BOOT_CFG *BootCfg)
{

    if (!FlashStoreBootCFG((BYTE*) BootCfg, sizeof(BOOT_CFG)))
    {
        KITLOutputDebugString("ERROR: StoreBootCFG: failed to write configuration.\r\n");
        return(FALSE);
    }

    return(TRUE);
}


//------------------------------------------------------------------------------
//
//  Function:  LoadBootCFG
//
//  Retrieves bootloader configuration information (menu settings, etc.) from 
//  flash.
//
//  Parameters:
//      BootCfg 
//          [out] Points to bootloader configuration that will be filled with
//          loaded data. 
//
//  Returns:
//      TRUE indicates success. FALSE indicates failure.
//
//-----------------------------------------------------------------------------
BOOL LoadBootCFG(BOOT_CFG *BootCfg)
{

    if (!FlashLoadBootCFG((BYTE*) BootCfg, sizeof(BOOT_CFG))) {
        KITLOutputDebugString("ERROR: LoadBootCFG: failed to load configuration.\r\n");
        return(FALSE);
    }

    // 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 (BootCfg->ConfigMagicNumber != OEMGetMagicNumber())
    {
        KITLOutputDebugString("ERROR: LoadBootCFG: ConfigMagicNumber not correct. Expected = 0x%x ; Actual = 0x%x.\r\n", 
            OEMGetMagicNumber(), BootCfg->ConfigMagicNumber);
        ResetDefaultBootCFG(BootCfg);
    }

    g_DefaultRamAddress = (PUCHAR)g_BootCFG.dwLaunchAddr;

    return(TRUE);
}

⌨️ 快捷键说明

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