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

📄 main.c

📁 arm4 driver for freescale imx35
💻 C
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//------------------------------------------------------------------------------
//
//  File:  main.c
//
#include <windows.h>
#include <blcommon.h>

#include <omap5912_base_regs.h>
#include <image_cfg.h>
#include <oal.h>

//BSP Includes
#include <utilities.h>
#include <serial.h>
#include <led.h>

#include <eboot.h>
#include <kitl_cfg.h>
#include <boot_cfg.h>


//Assembly Language Routines
void StartUp();


//From BLCOMMON.C
void BootloaderMain (void);


// From the bootshell utility
void BootShell();




//------------------------------------------------------------------------------
//
//  Global: g_bootCfg
//
//  This global variable is used to save boot configuration. It is readed from
//  flash memory or initialized to default values if flash memory doesn't
//  contain valid structure. It can be modified by user in bootloader
//  configuration menu invoked by BLMenu.
//
BOOT_CFG g_bootCfg;

//------------------------------------------------------------------------------
//
//  Global: g_eboot
//
//  This global variable is used to save information about downloaded regions.
//
EBOOT_CONTEXT g_eboot;


//------------------------------------------------------------------------------
//
//  Static: g_pTimerRegs
//
OMAP5912_TIMER32K_REGS *g_pTimerRegs;





void SpinForever()
{
   KITLOutputDebugString("Spin Forever\r\n");
   while(TRUE)
   {
        SetLEDValue(0xff);
        OALWaitMS(500);
        SetLEDValue(0x00);
        OALWaitMS(500);
   }
}


//------------------------------------------------------------------------------
//
//  Function:  ArubaboardConfiguration
//
//  This function 
//
BOOL ArubaboardConfiguration()
{
   // Data for creating the TOC section of flash
   OMAP5912_BOOT_TOC BootloaderTOC, EmptyTOC;
   UCHAR TocEntryPtr, *TocDataPtr;

   INT32 retry = 4;

   KITLOutputDebugString("ArubaBoard configuration mode. \r\n");
   KITLOutputDebugString("Preparing flash memory with supervisor mode bootstrap code\r\n");

   // Create OMAP standard bootable code TOC entry
   memset(&BootloaderTOC, 0, sizeof(BootloaderTOC));
   BootloaderTOC.start = DEVICE_NOR_HEADER_SIZE - 0x00000200;
   BootloaderTOC.size  = IMAGE_EBOOT_NOR_SIZE;
   memcpy(BootloaderTOC.name, "X-LOADER", 8);

   // Create empty TOC entry
   memset(&EmptyTOC, 0xFF, sizeof(EmptyTOC));

   while (retry-- > 0 )
   {
      if (!OALFlashLock((void*)DEVICE_CS3_PA, (void*)DEVICE_CS3_PA, DEVICE_NOR_HEADER_SIZE+IMAGE_EBOOT_NOR_SIZE, FALSE))
      {
          KITLOutputDebugString("Flash unlock failed\r\n");
          continue;
      }

      if (!OALFlashErase((void*)DEVICE_CS3_PA, (void*)DEVICE_CS3_PA, DEVICE_NOR_HEADER_SIZE+IMAGE_EBOOT_NOR_SIZE))
      {
          KITLOutputDebugString("Flash erase failed\r\n");
          continue;
      }

      // Write NOR TOC to beginning of flash
      KITLOutputDebugString("Writing TOC to flash memory\r\n");

      // Do this entry by entry.  We will write the 'empty' entries to ensure they have been initialized properly
      // In the future we can just update the 'bootcode toc entry' if needed
      for( TocEntryPtr=0; TocEntryPtr < TOTAL_TOC_ENTRIES; TocEntryPtr++ )
      {
         if( TocEntryPtr != BOOTCODE_TOC_ENTRY )
         {
            TocDataPtr = (UCHAR*)&EmptyTOC; //NorTocEmptyEntry;
         }
         else
         {
            TocDataPtr = (UCHAR*)&BootloaderTOC; //XLoaderEntry;
         }

         if (!OALFlashWrite((void*)DEVICE_CS3_PA, (void*)(DEVICE_CS3_PA+TocEntryPtr*0x20), 0x20, (void*) TocDataPtr))
         {
            KITLOutputDebugString("Flash write failed\r\n");
         }
      }   

      KITLOutputDebugString("Writing bootloader code to flash memory\r\n");

      if (!OALFlashWrite((void*)DEVICE_CS3_PA, (void*)(DEVICE_CS3_PA + DEVICE_NOR_HEADER_SIZE), IMAGE_EBOOT_NOR_SIZE, (void*) IMAGE_EBOOT_CODE_PA))
      {
         KITLOutputDebugString("Flash write failed\r\n");
         continue;
      }
          
      if (!OALFlashLock((void*)DEVICE_CS3_PA, (void*)DEVICE_CS3_PA, DEVICE_NOR_HEADER_SIZE+IMAGE_EBOOT_NOR_SIZE, TRUE))
      {
         KITLOutputDebugString("Flash lock failed\r\n");
         continue;
      }

      break;
   }

   if(!retry)
   {
      KITLOutputDebugString("ERROR: Write FAILED\r\n");
   }
    
   return (retry > 0);
}


//------------------------------------------------------------------------------
//
//  Function:  ArubaboardMain
//
//  This function is called from StartUp.s and is responsible for determining the type
//  of bootstrap and passing control off to the appropriate routines.
//  
//  If we start from SDRAM then configuration mode will be entered and the flash memory
//  will be programmed with the bootstrap code.
//
//  If we start from flash memory then control will be handed off to BootloaderMain
//  in BLCOMMON.
//
//  The user has the ability to break into the startup routine and enter a debug shell.
//
void ArubaboardMain(UINT32 BootstrapAddress)
{
   BootstrapModeEnum BootstrapMode;

   // Initialize LED port
   SetupLEDSGPIO();
   SetLEDValue(0x00);

   // Initialize serial port
   OEMDebugInit();
   KITLOutputDebugString("\r\nSerial Port Initialized\r\n");

   if(BootstrapAddress != FLASH_BOOTSTRAP_ADDRESS)
   {
       // We started from SDRAM so the CPU will not be in supervisor mode
       // none of the related configuration would have taken place
       BootstrapMode = USER_ARUBABOARD_CONFIGURATION_MODE;
       KITLOutputDebugString("SDRAM based boot.\r\n");

       //Initialize 32k timer
       Setup32KTimer();

       // Let the user change the boot process by
       // detecting a key hit
       if( WaitForUser() == TRUE )
       {
          BootShell();
          SpinForever();  
          //Should not get here
       }
   }
   else
   {
       // We started from flash so we would have copied ourselfs to SDRAM for exection
       // as well as entered supervisor mode and configured the OMAP processor
       // We can enter into normal WinCE bootstrap routines and startup the kernel
       BootstrapMode = SUPERVISOR_KERNEL_BOOT_MODE;
       KITLOutputDebugString("FLASH based boot.\r\n");
   }


   
   // Otherwise execute appropriate bootstrap code
   switch( BootstrapMode )
   {
   case SUPERVISOR_KERNEL_BOOT_MODE:
       KITLOutputDebugString("Supervisor mode boot case.\r\n");

       // Go to BLCOMMON
       BootloaderMain ();

        // Should not end up here
       break;
   case USER_ARUBABOARD_CONFIGURATION_MODE:

       // Configuration mode will program the flash memory with bootstrap code
       // That way on subsequent boots, the code can run in supervisor mode and bring up the kernel
     
       if(TRUE == ArubaboardConfiguration())
       {
          KITLOutputDebugString("Flash memory has been prepared with bootloader code.\r\nPlease reset system.\r\n");
          SetLEDValue(0xaa);
          while(TRUE);
       }
       else
       {
          KITLOutputDebugString("An error occurred while preparing the flash memory.\r\n");
       }
       break;
        
   default:
       KITLOutputDebugString("ERROR: Unknown bootstrap mode\r\n");
       break;
   }

   SpinForever();
}



//------------------------------------------------------------------------------
//
//  Function:  OEMPlatformInit
//
//  This function provide platform initialization functions. 
//
BOOL OEMPlatformInit(void) 
{ 
    OALMSG(OAL_INFO, (
        L"Microsoft Windows CE EBOOT %d.%d for OMAP5912 ArubaBoard "
        L"Built %S at %S\r\n",
        EBOOT_VERSION_MAJOR, EBOOT_VERSION_MINOR, __DATE__, __TIME__
    ));

    Setup32KTimer();
 
    // Initialize callback pointer
    g_pOEMMultiBINNotify = OEMMultiBinNotify;
    g_pOEMReportError = OEMReportError;

    return TRUE;
}

void Setup32KTimer()
{
    // Initialize 32K timer
    g_pTimerRegs = (OMAP5912_TIMER32K_REGS *)OALPAtoUA(OMAP5912_TIMER32K_REGS_PA);
    OUTREG32(&g_pTimerRegs->TVR, 0xFFFFFF);
    SETREG32(&g_pTimerRegs->CR, CR_TRB);
    while ((INREG32(&g_pTimerRegs->CR) & CR_TRB) != 0);
    SETREG32(&g_pTimerRegs->CR, CR_TSS|CR_INT_EN|CR_ARL);
}

//------------------------------------------------------------------------------
//
//  Function:  OEMPreDownload
//
//  This function is called before downloading an image. 
//
DWORD OEMPreDownload(void) 
{ 
    ULONG rc = BL_ERROR;

    OALLog(L"INFO: Entered OEMPreDownload....\r\n");

    // Read saved configration and check for validity
    if (BLReadBootCfg(&g_bootCfg) &&
        (g_bootCfg.signature == BOOT_CFG_SIGNATURE) &&
        (g_bootCfg.version == BOOT_CFG_VERSION))
    {
        OALLog(L"INFO: Boot configuration found\r\n");

⌨️ 快捷键说明

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