Eboot解析NK.bin的问题

weixiao361 2010-07-15 10:09:24
大家好!在网上看见很多人说NK.bin和NK.nb0都可下载到RAM中,如果下载到RAM的是NK.bin文件因为是压缩的,需要先通过BootLoader进行先解压才能往NAND Flash中烧写。

我用的平台是PXA270+Wince6.0 ,板子的Eboot就是通过以太网下载NK.bin映像到板子上内存,再写入FLASH的,但是就是不知道Bootloader中的那个函数将NK.bin解压成NK.nb0 ? 请各位大虾指教,谢谢!
...全文
1364 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinyancode 2013-02-04
  • 打赏
  • 举报
回复
楼上的,这一段并不是解压成nb0.只是原封不动地逐条record写入Flash。
博说医械研发 2010-07-19
  • 打赏
  • 举报
回复
//------------------------------------------------------------------------
// Download .bin records
//------------------------------------------------------------------------

while ( OEMReadData (sizeof (DWORD), (LPBYTE) &dwRecAddr) &&
OEMReadData (sizeof (DWORD), (LPBYTE) &dwRecLen) &&
OEMReadData (sizeof (DWORD), (LPBYTE) &dwRecChk) )

这就是一段一段在解压
weixiao361 2010-07-19
  • 打赏
  • 举报
回复
顶了!
unsway123 2010-07-18
  • 打赏
  • 举报
回复
参考blcommon.c
博说医械研发 2010-07-15
  • 打赏
  • 举报
回复
DownloadImage函数
博说医械研发 2010-07-15
  • 打赏
  • 举报
回复
解压缩的代码在PUBLIC\COMMON\OAK\DRIVERS\ETHDBG\BLCOMMON\blcommon.c中的函数
weixiao361 2010-07-15
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 linux_lee 的回复:]
贴出来是要怎么?
[/Quote]

呵呵,贴出来给大家帮我看看哈,我不知道是nk.bin是如何解压成nk.nb0的
weixiao361 2010-07-15
  • 打赏
  • 举报
回复
貌似没看见什么解压的,难道直接把NK.bin下载进去了??
Linux_lee 2010-07-15
  • 打赏
  • 举报
回复
贴出来是要怎么?
weixiao361 2010-07-15
  • 打赏
  • 举报
回复
下面是我的DownloadBin 函数

static BOOL DownloadBin (LPDWORD pdwImageStart, LPDWORD pdwImageLength, LPDWORD pdwLaunchAddr)
{
RegionInfo *pCurDownloadFile;
BOOL fIsFlash = FALSE;
LPBYTE lpDest = NULL;
DWORD dwImageStart, dwImageLength, dwRecAddr, dwRecLen, dwRecChk;
DWORD dwRecNum = 0;

g_bBINDownload = TRUE;

if (!OEMReadData (sizeof (DWORD), (LPBYTE) &dwImageStart)
|| !OEMReadData (sizeof (DWORD), (LPBYTE) &dwImageLength))
{
KITLOutputDebugString ("Unable to read image start/length\r\n");
HALT (BLERR_MAGIC);
return (FALSE);
}

// If Platform Builder didn't provide a manifest (i.e., we're only
// downloading a single .bin file), manufacture a manifest so we
// can notify the OEM.
//
if (!g_DownloadManifest.dwNumRegions)
{
g_DownloadManifest.dwNumRegions = 1;
g_DownloadManifest.Region[0].dwRegionStart = dwImageStart;
g_DownloadManifest.Region[0].dwRegionLength = dwImageLength;
}

// Provide the download manifest to the OEM.
//
if (!g_fOEMNotified && g_pOEMMultiBINNotify)
{
g_pOEMMultiBINNotify((PDownloadManifest)&g_DownloadManifest);
g_fOEMNotified = TRUE;
}

// Locate the current download manifest entry (current download file).
//
pCurDownloadFile = &g_DownloadManifest.Region[g_DownloadManifest.dwNumRegions - g_downloadFilesRemaining];

// give the OEM a chance to verify memory
if (g_pOEMVerifyMemory && !g_pOEMVerifyMemory (pCurDownloadFile->dwRegionStart, pCurDownloadFile->dwRegionLength))
{
KITLOutputDebugString ("!OEMVERIFYMEMORY: Invalid image\r\n");
HALT (BLERR_OEMVERIFY);
return (FALSE);
}

// check for flash image. Start erasing if it is.
if ((fIsFlash = OEMIsFlashAddr (pCurDownloadFile->dwRegionStart))
&& !OEMStartEraseFlash (pCurDownloadFile->dwRegionStart, pCurDownloadFile->dwRegionLength))
{
KITLOutputDebugString ("Invalid flash address/length\r\n");
HALT (BLERR_FLASHADDR);
return (FALSE);
}

#ifdef DEBUG
// Clearing memory ensures no garbage between sparse .bin records, so that
// our post-download checksum will be accurate.
memset( (LPVOID) OEMMapMemAddr(pCurDownloadFile->dwRegionStart, pCurDownloadFile->dwRegionStart),
0, pCurDownloadFile->dwRegionLength );
#endif


//------------------------------------------------------------------------
// Download .bin records
//------------------------------------------------------------------------

while ( OEMReadData (sizeof (DWORD), (LPBYTE) &dwRecAddr) &&
OEMReadData (sizeof (DWORD), (LPBYTE) &dwRecLen) &&
OEMReadData (sizeof (DWORD), (LPBYTE) &dwRecChk) )
{
#ifdef DEBUG
KITLOutputDebugString(" <> Record [ %d ] dwRecAddr = 0x%x, dwRecLen = 0x%x\r\n",
dwRecNum, dwRecAddr, dwRecLen);
#endif

// last record of .bin file uses sentinel values for address and checksum.
if (!dwRecAddr && !dwRecChk)
{
break;
}

// map the record address (FLASH data is cached, for example)
lpDest = OEMMapMemAddr (pCurDownloadFile->dwRegionStart, dwRecAddr);

// read data block
if (!OEMReadData (dwRecLen, lpDest))
{
KITLOutputDebugString ("****** Data record %d corrupted, ABORT!!! ******\r\n", dwRecNum);
HALT (BLERR_CORRUPTED_DATA);
return (FALSE);
}

if (!VerifyChecksum (dwRecLen, lpDest, dwRecChk))
{
KITLOutputDebugString ("****** Checksum failure on record %d, ABORT!!! ******\r\n", dwRecNum);
HALT (BLERR_CHECKSUM);
return (FALSE);
}

// Look for ROMHDR to compute ROM offset. NOTE: romimage guarantees that the record containing
// the TOC signature and pointer will always come before the record that contains the ROMHDR contents.
//
if (dwRecLen == sizeof(ROMHDR) && (*(LPDWORD) OEMMapMemAddr(pCurDownloadFile->dwRegionStart, pCurDownloadFile->dwRegionStart + ROM_SIGNATURE_OFFSET) == ROM_SIGNATURE))
{
DWORD dwTempOffset = (dwRecAddr - *(LPDWORD)OEMMapMemAddr(pCurDownloadFile->dwRegionStart, pCurDownloadFile->dwRegionStart + ROM_SIGNATURE_OFFSET + sizeof(ULONG)));
ROMHDR *pROMHdr = (ROMHDR *)lpDest;

// Check to make sure this record really contains the ROMHDR.
//
if ((pROMHdr->physfirst == (pCurDownloadFile->dwRegionStart - dwTempOffset)) &&
(pROMHdr->physlast == (pCurDownloadFile->dwRegionStart - dwTempOffset + pCurDownloadFile->dwRegionLength)) &&
(DWORD)(HIWORD(pROMHdr->dllfirst << 16) <= pROMHdr->dlllast) &&
(DWORD)(LOWORD(pROMHdr->dllfirst << 16) <= pROMHdr->dlllast))
{
g_dwROMOffset = dwTempOffset;
KITLOutputDebugString("rom_offset=0x%x.\r\n", g_dwROMOffset);
}
}

// verify partial checksum
OEMShowProgress (dwRecNum++);

if (fIsFlash)
{
OEMContinueEraseFlash ();
}
} // while( records remaining )


//------------------------------------------------------------------------
// Determine the image entry point
//------------------------------------------------------------------------

// Does this .bin file contain a TOC?
if (*(LPDWORD) OEMMapMemAddr(pCurDownloadFile->dwRegionStart, pCurDownloadFile->dwRegionStart + ROM_SIGNATURE_OFFSET) == ROM_SIGNATURE)
{
// Contain the kernel?
if (IsKernelRegion(pCurDownloadFile->dwRegionStart, pCurDownloadFile->dwRegionLength))
{
*pdwImageStart = pCurDownloadFile->dwRegionStart;
*pdwImageLength = pCurDownloadFile->dwRegionLength;
*pdwLaunchAddr = dwRecLen;
}
}
// No TOC - not made by romimage.
else if (g_DownloadManifest.dwNumRegions == 1)
{
*pdwImageStart = pCurDownloadFile->dwRegionStart;
*pdwImageLength = pCurDownloadFile->dwRegionLength;
*pdwLaunchAddr = dwRecLen;
}
else
{
// If we're downloading more than one .bin file, it's probably
// chain.bin which doesn't have a TOC (and which isn't
// going to be downloaded on its own) and we should ignore it.

}
//to save the boot parameter .added by A.M.Xiao 2007-11-09

g_EbootCFG.dwLaunchAddr = dwRecLen;
g_EbootCFG.dwPhysStart = dwImageStart;
g_EbootCFG.dwPhysLen = dwImageLength;

if(g_EbootCFG.Store_In_NandFlash == TRUE)
StoreEBootCFG(&g_EbootCFG);


if (fIsFlash)
{
// finish the flash erase
if (!OEMFinishEraseFlash())
{
HALT (BLERR_FLASH_ERASE);
return (FALSE);
}

}

KITLOutputDebugString("ImageStart = 0x%x, ImageLength = 0x%x, LaunchAddr = 0x%x\r\n",
*pdwImageStart, *pdwImageLength, *pdwLaunchAddr);

return TRUE;
}

weixiao361 2010-07-15
  • 打赏
  • 举报
回复
下面是我的DownloadImage函数
static BOOL DownloadImage (LPDWORD pdwImageStart, LPDWORD pdwImageLength, LPDWORD pdwLaunchAddr)
{
BOOL rval = TRUE;
DWORD dwImageType;

*pdwImageStart = *pdwImageLength = *pdwLaunchAddr = 0;
KITLOutputDebugString ("\r\nUnable to read image signature.\r\n");


//
// Download each region (multiple can be sent)
//
do
{
dwImageType = GetImageType();

switch(dwImageType)
{

case BL_IMAGE_TYPE_BIN:
rval &= DownloadBin( pdwImageStart, pdwImageLength, pdwLaunchAddr );
break;

default:
// should never get here
return (FALSE);

}
}
while (--g_downloadFilesRemaining);

ComputeChecksum();

if(g_EbootCFG.Store_In_NandFlash)
{
// NandflashInit();

if(FlashFormated == FALSE)
{

BP_LowLevelFormat((DWORD)g_dwStartBlock,(DWORD)(NUM_BLOCKS - g_dwStartBlock),0) ;
}

rval &= WriteImageToFlash();

#if 0

KITLOutputDebugString ("create partition.\r\n");
BP_OpenPartition( NEXT_FREE_LOC,
USE_REMAINING_SPACE,
PART_DOS32,
TRUE,
PART_OPEN_ALWAYS);

#endif


}

19,500

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧