📄 main.c
字号:
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);
// If user wants to jump to existing image - skip download...
//
if (!g_DownloadImage)
{
return(BL_JUMP);
}
// User doesn't want to get a DHCP address...
//
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;
}
// 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->numBootMe = 50;
pEbootCFG->delay = 3;
pEbootCFG->DHCPEnable = TRUE;
pEbootCFG->dwLaunchAddr = 0;
pEbootCFG->dwPhysStart = 0;
pEbootCFG->dwPhysLen = 0;
pEbootCFG->bootDeviceOrder = 0;
pEbootCFG->dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_BTUART;
pEbootCFG->dwStoreAddr = 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)
{
if (!FlashRead(EBOOT_FLASH_CFG_START, (PUCHAR)EBootCFG, sizeof(EBOOT_CFG)))
{
EdbgOutputDebugString("ERROR: LoadEBootCFG: 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 (EBootCFG->ConfigMagicNumber != EBOOT_CFG_MAGIC_NUMBER)
{
ResetDefaultEBootCFG(EBootCFG);
}
// Make sure a valid debug serial port address (physical) was found.
//
if (g_EbootCFG.dwDbgSerPhysAddr == 0)
{
g_EbootCFG.dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_BTUART;
}
return(TRUE);
}
static void SetIP(EBOOT_CFG *pEbootCFG)
{
char szDottedD[16]; // The string used to collect the dotted decimal IP address
WORD cwNumChars = 0;
UINT16 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';
pEbootCFG->IP = inet_addr( szDottedD );
}
}
static void SetMask(EBOOT_CFG *pEbootCFG)
{
char szDottedD[16]; // The string used to collect the dotted masks
WORD cwNumChars = 0;
UINT16 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';
pEbootCFG->subnetMask = inet_addr( szDottedD );
}
}
static void SetBootMe(EBOOT_CFG *pEbootCFG)
{
char szCount[16];
WORD cwNumChars = 0;
UINT16 InChar = 0;
EdbgOutputDebugString ( "\r\nUse 0 for continuous boot me packets. \r\n");
EdbgOutputDebugString ( "Enter maximum number of boot me packets to send [0-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);
}
}
// 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)
{
szCount[cwNumChars] = '\0';
pEbootCFG->numBootMe = atoi(szCount);
if (pEbootCFG->numBootMe > 255)
{
pEbootCFG->numBootMe = 255;
}
else if (pEbootCFG->numBootMe < 0)
{
pEbootCFG->numBootMe = 1;
}
}
}
static void SetDelay(EBOOT_CFG *pEbootCFG)
{
char szCount[16];
WORD cwNumChars = 0;
UINT16 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);
}
}
// 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)
{
szCount[cwNumChars] = '\0';
pEbootCFG->delay = atoi(szCount);
if (pEbootCFG->delay > 255)
{
pEbootCFG->delay = 255;
}
else if (pEbootCFG->delay < 1)
{
pEbootCFG->delay = 1;
}
}
}
BOOL OEMVerifyMemory(DWORD dwStartAddr, DWORD dwLength)
{
BOOL rc;
DWORD dwPhysVerifyStart = (DWORD) OALVAtoPA((void *)dwStartAddr);
DWORD dwPhysVerifyEnd = (DWORD) OALVAtoPA((void *)(dwStartAddr + dwLength - 1));
EdbgOutputDebugString("****** OEMVerifyMemory checking physical range [ 0x%x ==> 0x%x ]...\r\n", dwPhysVerifyStart, dwPhysVerifyEnd);
if ((dwPhysVerifyStart >= IMAGE_BOOT_BLDRIMAGE_FLASH_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_BLDRIMAGE_FLASH_PA_END))
{
EdbgOutputDebugString("****** bootloader address ****** \r\n\r\n");
g_ImageType = IMAGE_TYPE_BOOTLOADER;
rc = TRUE;
}
else if ((dwPhysVerifyStart >= MAINSTONEII_BASE_PA_BOOT_FLASH) && (dwPhysVerifyEnd <= (MAINSTONEII_BASE_PA_BOOT_FLASH + MAINSTONEII_SIZE_BOOT_FLASH)))
{
EdbgOutputDebugString("****** FLASH address ****** \r\n\r\n");
g_ImageType = IMAGE_TYPE_FLASHIMAGE;
rc = TRUE;
}
else if ((dwPhysVerifyStart >= MAINSTONEII_BASE_PA_SDRAM) && (dwPhysVerifyEnd <= (MAINSTONEII_BASE_PA_SDRAM + MAINSTONEII_SIZE_SDRAM)))
{
EdbgOutputDebugString("****** RAM address ****** \r\n\r\n");
g_ImageType = IMAGE_TYPE_RAMIMAGE;
rc = TRUE;
}
else
{
EdbgOutputDebugString("****** OEMVerifyMemory FAILED - Invalid Memory Area ****** \r\n\r\n");
rc = FALSE;
}
return(rc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -