📄 flash.c
字号:
//
// 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: flash.c
//
#include <windows.h>
#include <blcommon.h>
#include <eboot.h>
BOOL OEMStartEraseFlash (DWORD dwStartAddr, DWORD dwLength)
{
BOOL rc = FALSE;
OALMSG(OAL_FUNC, (L"+OEMStartEraseFlash(0x%08x, 0x%08x)\r\n", dwStartAddr, dwLength));
switch (g_eboot.type)
{
case DOWNLOAD_TYPE_EBOOT:
if (!OALFlashLock((void*)DEVICE_CS3_PA, (void*)DEVICE_CS3_PA, DEVICE_NOR_HEADER_SIZE+IMAGE_EBOOT_NOR_SIZE, FALSE))
break;
if (!OALFlashErase((void*)DEVICE_CS3_PA, (void*)DEVICE_CS3_PA, DEVICE_NOR_HEADER_SIZE+IMAGE_EBOOT_NOR_SIZE))
break;
OALMSG(OAL_INFO, (L"Flash memory erased.\r\n"));
rc = TRUE;
break;
}
if (!rc)
{
OALMSG(OAL_ERROR, (L"ERROR: Flash erase failed\r\n"));
}
OALMSG(OAL_FUNC, (L"-OEMStartEraseFlash(rc = %d)\r\n", rc));
return rc;
}
VOID OEMContinueEraseFlash()
{
}
BOOL OEMFinishEraseFlash()
{
return TRUE;
}
BOOL OEMWriteFlash(DWORD dwStartAddr, DWORD dwLength)
{
BOOL rc = FALSE;
VOID *pSource;
OMAP5912_BOOT_TOC toc;
VOID *pBase, *pAddress;
OALMSG(OAL_FUNC, (L"+OEMWriteFlash(0x%08x, 0x%08x\r\n", dwStartAddr, dwLength));
switch (g_eboot.type)
{
case DOWNLOAD_TYPE_EBOOT:
pBase = OALPAtoUA(DEVICE_NOR_PA);
// Prepare header
memset(&toc, 0, sizeof(toc));
toc.start = 0x00000E00;
toc.size = 0x00020000;
memcpy(toc.name, "X-LOADER", 8);
// Flash header
pAddress = OALPAtoUA(DEVICE_NOR_PA + 0x0200);
KITLOutputDebugString("Writing flash bootloader TOC entry.\r\n");
if (!OALFlashWrite(pBase, pAddress, sizeof(toc), &toc))
break;
// Map buffer memory
pSource = OEMMapMemAddr(dwStartAddr, dwStartAddr);
if (pSource == NULL) break;
// Write EBOOT code
pAddress = OALPAtoUA(IMAGE_EBOOT_NOR_PA);
OALMSG(OAL_INFO, (L"Writing bootloader code.\r\n"));
if (!OALFlashWrite((void*)DEVICE_CS3_PA, (void*)(DEVICE_CS3_PA + DEVICE_NOR_HEADER_SIZE), IMAGE_EBOOT_NOR_SIZE-DEVICE_NOR_HEADER_SIZE, (void*) pSource))
break;
OALFlashLock((void*)DEVICE_CS3_PA, (void*)DEVICE_CS3_PA, DEVICE_NOR_HEADER_SIZE+IMAGE_EBOOT_NOR_SIZE, TRUE);
rc = TRUE;
break;
}
if (!rc)
{
OALMSG(OAL_ERROR, (L"ERROR: Flash write failed\r\n"));
}
OALMSG(OAL_FUNC, (L"-OEMWriteFlash(0x%08x, 0x%08x\r\n", dwStartAddr, dwLength));
return rc;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -