📄 kitl.c
字号:
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004, Freescale Semiconductor, Inc. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// FREESCALE SEMICONDUCTOR, INC.
//
//-----------------------------------------------------------------------------
//
// File: kitl.c
//
// Support routines for KITL.
//
// Note: These routines are stubbed out in the kern image.
//
//-----------------------------------------------------------------------------
#include <bsp.h>
#include <kitl_cfg.h>
//-----------------------------------------------------------------------------
#define BSP_PREV_ARGS_COOKIE 0x8C020800
#define BSP_PREV_ARGS_MAC 0x8C02080C
#define USE_DHCP_RENEW 1
static PCSP_EPIT_REG g_pEPIT;
//-----------------------------------------------------------------------------
BOOL OALKitlStart()
{
BOOL rc;
OAL_KITL_ARGS *pArgs, args;
CHAR *szDeviceId, buffer[OAL_KITL_ID_SIZE];
BYTE *pMacBytes = (BYTE *) &args.mac;
OAL_KITL_DEVICE *pKitlDevice = NULL;
#ifndef PLAT_PMC
BOOT_CFG bootConfig;
#endif
UINT32 *kitlFlags;
OALMSG(OAL_KITL&&OAL_FUNC, (L"+OALKitlStart\r\n"));
// Get uncached virtual addresses for timer used in OALGetTickCount
g_pEPIT = (PCSP_EPIT_REG) OALPAtoUA(CSP_BASE_REG_PA_EPIT1);
if (g_pEPIT == NULL)
{
OALMSG(OAL_ERROR, (L"+OALKitlStart: EPIT null pointer!\r\n"));
rc = FALSE;
goto cleanUp;
}
// Look for bootargs left by the bootloader or left over from an earlier boot.
//
pArgs = (OAL_KITL_ARGS*)OALArgsQuery(OAL_ARGS_QUERY_KITL);
szDeviceId = (CHAR*)OALArgsQuery(OAL_ARGS_QUERY_DEVID);
kitlFlags = (BOOL *) OALArgsQuery(BSP_ARGS_QUERY_KITL_FLAGS); // Always valid
#ifndef PLAT_PMC // Dev note: We should always get args in a PMC build
// If we don't get kitl arguments use default
if (pArgs == NULL)
{
OALMSG(OAL_WARN, (L"WARN: Boot arguments not found, use defaults\r\n"));
memset(&args, 0, sizeof(args));
args.flags = *kitlFlags;
#ifdef FORCE_KITL_SERIAL
pKitlDevice = &g_kitlDevices[OAL_KITL_SERIAL_INDEX];
args.flags |= OAL_KITL_FLAGS_ENABLED;
args.devLoc.LogicalLoc = BSP_BASE_REG_PA_SERIALKITL;
args.devLoc.IfcType = Internal;
#else
pKitlDevice = &g_kitlDevices[OAL_KITL_ETH_INDEX];
OALReadBootCFG(&bootConfig);
args.flags |= OAL_KITL_FLAGS_ENABLED | OAL_KITL_FLAGS_VMINI;
if(bootConfig.ConfigFlags & CONFIG_FLAGS_DHCP)
args.flags |= OAL_KITL_FLAGS_DHCP;
args.ipAddress = bootConfig.IPAddr;
args.ipMask = bootConfig.SubnetMask;
memcpy(pMacBytes, bootConfig.CS8900MAC, 6);
args.devLoc.LogicalLoc = BSP_BASE_REG_PA_CS8900A_IOBASE;
args.devLoc.IfcType = Internal;
#endif
pArgs = &args;
}
#ifndef USE_DHCP_RENEW
else if (pArgs->flags & OAL_KITL_FLAGS_DHCP)
{
// Reset IP address to force DHCP request instead of renew which
// is acknowleged much sooner from the DHCP server
pArgs->ipAddress = 0;
}
#endif
#endif // PLAT_PMC
// If there isn't device id from bootloader create some.
//
if (szDeviceId == NULL)
{
OALKitlCreateName(BSP_DEVICE_PREFIX, args.mac, buffer);
szDeviceId = buffer;
}
// If we have not configured pointer to KITL transport device,
// set it to Ethernet
if (pKitlDevice == NULL)
{
pKitlDevice = &g_kitlDevices[OAL_KITL_ETH_INDEX];
}
// Finally call KITL library.
//
rc = OALKitlInit(szDeviceId, pArgs, pKitlDevice);
cleanUp:
OALMSG(OAL_KITL&&OAL_FUNC, (L"-OALKitlStart(rc = %d)\r\n", rc));
return(rc);
}
//------------------------------------------------------------------------------
//
// Function: OALGetTickCount
//
// This function is called by some KITL libraries to obtain relative time
// since device boot. It is mostly used to implement timeout in network
// protocol.
//
//------------------------------------------------------------------------------
UINT32 OALGetTickCount()
{
UINT32 ticks;
// Calculate EPIT ticks since we started the system
ticks = EPIT_CNT_COUNT_MAX - INREG32(&g_pEPIT->CNT);
// Return the number of 1ms ticks that have elapsed
return ticks / g_oalTimer.countsPerMSec;
}
//-----------------------------------------------------------------------------
//
// Function: OEMEthGetSecs
//
// Function returns a free-running seconds count.
//
// Parameters:
//
// Returns:
// DWORD dwSeconds - the count of seconds
//
//-----------------------------------------------------------------------------
DWORD OEMEthGetSecs(void)
{
SYSTEMTIME st;
OEMGetRealTime( &st );
return ((60UL * (60UL * (24UL * (31UL * st.wMonth + st.wDay) + st.wHour) + st.wMinute)) + st.wSecond);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -