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

📄 main.c

📁 老外的一个开源项目
💻 C
📖 第 1 页 / 共 5 页
字号:
                case BOOT_DEVICE_ETH1:
                    EdbgOutputDebugString ( "ETH1\r\n");
                    break;
                case BOOT_DEVICE_ETH2:
                    EdbgOutputDebugString ( "ETH2\r\n");
                    break;
                case BOOT_DEVICE_STUART:
                    EdbgOutputDebugString ( "STUART\r\n");
                    break;
                case BOOT_DEVICE_FFUART:
                    EdbgOutputDebugString ( "FFUART (SRecord)\r\n");
                    break;
                case BOOT_DEVICE_HWUART:
                    EdbgOutputDebugString ( "HWUART\r\n");
                    break;
                case BOOT_DEVICE_BTUART:
                    EdbgOutputDebugString ( "BTUART\r\n");
                    break;
                default:
                    EdbgOutputDebugString ( "CF\r\n");
                    g_EbootCFG.secBootDevice = 0;
                    break;
                }

				EdbgOutputDebugString ( "8) Reset default configuration\r\n");
				EdbgOutputDebugString ( "9) Edit memory\r\n");
				if (g_EbootCFG.priBootDevice == BOOT_DEVICE_STUART || g_EbootCFG.priBootDevice == BOOT_DEVICE_HWUART || g_EbootCFG.priBootDevice == BOOT_DEVICE_BTUART ||
					g_EbootCFG.secBootDevice == BOOT_DEVICE_STUART || g_EbootCFG.secBootDevice == BOOT_DEVICE_HWUART || g_EbootCFG.secBootDevice == BOOT_DEVICE_BTUART)
				{
					EdbgOutputDebugString ( "B) Download baud rate:          %d\r\n",g_EbootCFG.downloadBaud);
				}

				if (g_EbootCFG.dwPlatformHardware & GUMCFG_PERREG)
				{
					EdbgOutputDebugString ( "C) Clean registry boot:         ");
					if (g_pBSPArgs->bootFlags & BOOTFLAGS_REGCLEAN)
						EdbgOutputDebugString ( "NEXT LAUNCH\r\n");
					else
						EdbgOutputDebugString ( "NO\r\n");
				}
				EdbgOutputDebugString ( "U) Unlock boot blocks\r\n");
				EdbgOutputDebugString ( "R) Reset\r\n");
				EdbgOutputDebugString ( "S) Store and lock configuration/boot blocks\r\n");
				EdbgOutputDebugString ( "D) Download image now\r\n");
                EdbgOutputDebugString ( "L) ");
				switch (g_EbootCFG.imageLoadDevice)
				{
				case IMG_LOAD_DOWNLOAD:
					EdbgOutputDebugString ( "Launch RAM ");
					break;
				case IMG_LOAD_MMC:
					EdbgOutputDebugString ( "Launch MMC ");
					break;
				case IMG_LOAD_CF:
					EdbgOutputDebugString ( "Launch CF ");
					break;
				case IMG_LOAD_FLASH:
				default: // flash
					EdbgOutputDebugString ( "Launch flash ");
					break;
				}
                EdbgOutputDebugString ( "resident image now\r\n");

				
				EdbgOutputDebugString ( "\r\nEnter your selection: ");
                Selection = 0;
                while (! ( ( (Selection >= '0') && (Selection <= '9') ) || 
							( (Selection == 'C') || (Selection == 'c') ) || 
							( (Selection == 'B') || (Selection == 'b') ) || 
							( (Selection == 'U') || (Selection == 'u') ) || 
							( (Selection == 'R') || (Selection == 'r') ) || 
							( (Selection == 'S') || (Selection == 's') ) || 
							( (Selection == 'D') || (Selection == 'd') ) || 
							( (Selection == 'L') || (Selection == 'l') ) ))
                {
                    Selection = OEMReadDebugByte();
                }
                EdbgOutputDebugString ( "%c\r\n", Selection);
                switch (Selection)
                {
                case '0':
                    SetIPConfig(&g_EbootCFG);
                    break;
                case '1':
					SetMACAddress(&g_EbootCFG, 1);
                    break;
                case '2':
					SetMACAddress(&g_EbootCFG, 2);
                    break;
                case '3':
                    SetDelay(&g_EbootCFG);
                    break;
                case '4':
                    SetHardwareCFG();
                    break;
                case '5':
                    g_EbootCFG.imageLoadDevice++;
                    if (g_EbootCFG.imageLoadDevice >= MAX_IMG_LOAD)
                        g_EbootCFG.imageLoadDevice = 0;
                    break;
                case '6':
                    g_EbootCFG.priBootDevice++;
                    if (g_EbootCFG.priBootDevice >= MAX_BOOT_DEVICE)
	                        g_EbootCFG.priBootDevice = 0;
                    break;
                case '7':
                    g_EbootCFG.secBootDevice++;
                    if (g_EbootCFG.secBootDevice >= MAX_BOOT_DEVICE)
	                        g_EbootCFG.secBootDevice = 0;
                    break;
                case '8':
                    ResetDefaultEBootCFG(&g_EbootCFG);
                    break;
                case '9':
                    EditMemory();
                    break;
                case 'B':
                case 'b':
					switch (g_EbootCFG.downloadBaud) {
					case 9600:
						g_EbootCFG.downloadBaud = 19200;
						break;
					case 19200:
						g_EbootCFG.downloadBaud = 38400;
						break;
					case 38400:
						g_EbootCFG.downloadBaud = 57600;
						break;
					case 57600:
						g_EbootCFG.downloadBaud = 115200;
						break;
					case 115200:
					default:
						g_EbootCFG.downloadBaud = 9600;
						break;
					}
					break;
                case 'C':
                case 'c':
					if (g_pBSPArgs->bootFlags & BOOTFLAGS_REGCLEAN)
						g_pBSPArgs->bootFlags &= ~BOOTFLAGS_REGCLEAN;
					else
						g_pBSPArgs->bootFlags |= BOOTFLAGS_REGCLEAN;
					break;
                case 'U':
                case 'u':
					LockBootBlocks(FALSE);
                    break;
                case 'R':
                case 'r':
					OEMReset();
					break;
                case 'S':
                case 's':
					if (!(StoreEBootCFG(&g_EbootCFG)))
				        ResetDefaultEBootCFG(&g_EbootCFG);
                    break;
                case 'D':
                case 'd':
					if (g_EbootCFG.priBootDevice == BOOT_DEVICE_FFUART)
					{
						SRecordDownload();
						break;
					}
					else
					{
	                    g_DownloadImage = TRUE;
		                goto CONTINUE;
					}
                case 'L':
                case 'l':
                    g_DownloadImage = FALSE;
                    goto CONTINUE;
                    break;
	            default:
                    break;
                }
            }
        }
    }

  CONTINUE:

    // Provide the chosen debug serial port address to the OS image for debug output messages.
    //
    g_pBSPArgs->dbgSerPhysAddr = g_EbootCFG.dwDbgSerPhysAddr;
    // Provide the platform hardware configuration to the OS image.
    //
	// merge set bits with arg soft set bits
    g_pBSPArgs->platformHardware |= g_EbootCFG.dwPlatformHardware;

	// If we need to download an image, locate and initialize an Ethernet controller.
    //
    if (g_DownloadImage)
    {
        // Try primary then secondary boot device (until one succeeds or they both fail).
        //
		g_EthDevice = InitSpecifiedEthDevice(&g_pBSPArgs->kitl, g_EbootCFG.priBootDevice, &g_EbootCFG);
        if (g_EthDevice == -1)
        {
            g_EthDevice = InitSpecifiedEthDevice(&g_pBSPArgs->kitl, g_EbootCFG.secBootDevice, &g_EbootCFG);
        }

        // No device was found ... 
        //
        if (g_EthDevice == -1)
        {
            EdbgOutputDebugString("ERROR: Failed to detect and initialize download device.\r\n");
            return(FALSE);
        }

        // Make sure MAC address has been programmed.
        //
		if (!(g_EthDevice == BOOT_DEVICE_STUART || g_EthDevice == BOOT_DEVICE_HWUART || g_EthDevice == BOOT_DEVICE_BTUART))
		{
			if (!g_pBSPArgs->kitl.mac[0] && !g_pBSPArgs->kitl.mac[1] && !g_pBSPArgs->kitl.mac[2])
			{
				EdbgOutputDebugString("ERROR: Invalid Ethernet mac address read from Ethernet controller.\n");
				return(FALSE);
			}
			else
			{
				OALMSG(1, (L"INFO: MAC address: %02X-%02X-%02X-%02X-%02X-%02X\r\n",
					g_pBSPArgs->kitl.mac[0] & 0x00FF, g_pBSPArgs->kitl.mac[0] >> 8,
					g_pBSPArgs->kitl.mac[1] & 0x00FF, g_pBSPArgs->kitl.mac[1] >> 8,
					g_pBSPArgs->kitl.mac[2] & 0x00FF, g_pBSPArgs->kitl.mac[2] >> 8));
			}
		}
    }
	else // no download
	{
		if (!InitSpecifiedImgBootDevice(g_EbootCFG.imageLoadDevice,g_EbootCFG.dwPlatformHardware))
        {
            EdbgOutputDebugString("ERROR: Failed to detect and initialize download device.\r\n");
            return(FALSE);
        }
		switch (g_EbootCFG.imageLoadDevice)
		{
		case IMG_LOAD_DOWNLOAD:
			break;
		case IMG_LOAD_MMC:
			EdbgOutputDebugString ( "Launching MMC resident image\r\n");
			break;
		case IMG_LOAD_CF:
			EdbgOutputDebugString ( "Launching CF resident image\r\n");
			break;
		case IMG_LOAD_FLASH:
		default: // flash
			EdbgOutputDebugString ( "Launching flash resident image\r\n");
			break;
		}

	}

    return(TRUE);

}


//------------------------------------------------------------------------------
//
//  Function:  OEMPreDownload
//
//  Pre-download initialization routine.
//
DWORD OEMPreDownload(void)
{
    UINT32 SubnetMask;
    BOOL  fGotJumpImg = FALSE, fGotIP = FALSE;
    UINT32 DHCPLeaseTime = 0;
    UINT32 *pDHCPLeaseTime = &DHCPLeaseTime;
    UINT32 BootFlags = 0;
    OAL_KITL_DEVICE *pDevice = NULL;
	UINT8 buffer[16];
	KITLTRANSPORT KitlTransport;


    // If user wants to jump to existing image - skip download...
    //
    if (!g_DownloadImage)
    {
        return(BL_JUMP);
    }

	if (g_EthDevice == BOOT_DEVICE_STUART || g_EthDevice == BOOT_DEVICE_HWUART || g_EthDevice == BOOT_DEVICE_BTUART)
	{
		strcpy(g_pBSPArgs->deviceId,BSP_DEVICE_PREFIX);
		_ultoa(g_pBSPArgs->kitl.baudRate,(char *)&buffer,10);
		strcat(g_pBSPArgs->deviceId,(char *)&buffer);
		EdbgOutputDebugString("INFO: Using serial device name: '%s'\n", g_pBSPArgs->deviceId);
		g_pBSPArgs->kitl.flags &= ~OAL_KITL_FLAGS_PASSIVE;
		g_pBSPArgs->kitl.flags |= (OAL_KITL_FLAGS_POLL | OAL_KITL_FLAGS_ENABLED);

		pDevice = OALKitlFindDevice(&g_pBSPArgs->kitl.devLoc, g_kitlDevices); 
		if (pDevice == NULL)
		{
			EdbgOutputDebugString("ERROR: Kitl Device not found in kitl_cfg table.\r\n");
		}
		
		if(!OALKitlSerialInit(g_pBSPArgs->deviceId, pDevice, &g_pBSPArgs->kitl, &KitlTransport))
		{
			EdbgOutputDebugString("OALKitlSerialInit fail!\r\n");
			return(BL_ERROR);
		}

		return (OEMSerialPreDownload());

	}
	else
	{
		// 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);

		// 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:  OEMReadData
//
//  Reads data from the download transport.
//
BOOL OEMReadData(DWORD cbData, LPBYTE pbData)
{

	g_dwBytesRead += cbData;
	if (g_EthDevice == BOOT_DEVICE_STUART || g_EthDevice == BOOT_DEVICE_HWUART || g_EthDevice == BOOT_DEVICE_BTUART)
	{
	    return(SerialReadData(cbData, pbData));
	}
	else
	{
	    return(EbootEtherReadData(cbData, pbData));
	}
}


//------------------------------------------------------------------------------
//
//  Function:  OEMSerialPreDownload
//
//  Pre-download initialization routine.
//
DWORD OEMSerialPreDownload (void)
{   
    BOOL fGotJump = FALSE;
    const char * platformString = BSP_DEVICE_PREFIX;

	// send boot requests indefinitely
	do
	{
		EdbgOutputDebugString("Sending boot request...\r\n");
		if(!SerialSendBootRequest(platformString))
		{
			EdbgOutputDebugString("Failed to send boot request\r\n");
			return BL_ERROR;
		}
	}
	while(!SerialWaitForBootAck(&fGotJump));

	// ack block zero to start the download
	SerialSendBlockAck(0);

	EdbgOutputDebugString("Received boot request ack... starting download. %d\r\n",fGotJump);

	return fGotJump  ? BL_JUMP : BL_DOWNLOAD;
}


//------------------------------------------------------------------------------
//
//  Function:  OEMSerialRecvRaw
//
//
BOOL OEMSerialRecvRaw(LPBYTE pbFrame, PUSHORT pcbFrame, BOOLEAN bWaitInfinite)
{
	volatile UART_REG_T	*pUARTRegs;
    USHORT ct = 0;
    DWORD tStart = 0;
    UINT32 uStatus = 0;
	UINT32 uCtrl;

	switch (g_EthDevice)
	{
		case BOOT_DEVICE_STUART:
			pUARTRegs = (volatile UART_REG_T *) OALPAtoVA(PXA255_BASE_REG_PA_STUART, FALSE);

⌨️ 快捷键说明

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