首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > WinCE >

2440 bootloader中,MBR是什么东西?该如何解决

2012-02-08 
2440 bootloader中,MBR是什么东西?请教,bootloader中有这么一个函数:C/C++ code// lqm: 1G08:dwStartSecto

2440 bootloader中,MBR是什么东西?
请教,bootloader中有这么一个函数:

C/C++ code
// lqm: 1G08:dwStartSector = 7 * 64 (boot:7个block)HANDLE BP_OpenPartition(DWORD dwStartSector, DWORD dwNumSectors, DWORD dwPartType, BOOL fActive, DWORD dwCreationFlags){        DWORD dwPartIndex;        BOOL fExists;        ASSERT (g_pbMBRSector);                if (!IsValidMBR()) // 这里的目的是什么???        {            DWORD dwFlags = 0;            if (dwCreationFlags == PART_OPEN_EXISTING)             {                RETAILMSG(1, (TEXT("OpenPartition: Invalid MBR.  Cannot open existing partition 0x%x.\r\n"), dwPartType));                return INVALID_HANDLE_VALUE;            }                        RETAILMSG(1, (TEXT("OpenPartition: Invalid MBR.  Formatting flash.\r\n")));            if (g_FlashInfo.flashType == NOR)             {                dwFlags |= FORMAT_SKIP_BLOCK_CHECK;            }            BP_LowLevelFormat (0, g_FlashInfo.dwNumBlocks, dwFlags);            dwPartIndex = 0;            fExists = FALSE;        }        else         {            fExists = GetPartitionTableIndex(dwPartType, fActive, &dwPartIndex);                }        RETAILMSG(1, (TEXT("OpenPartition: Partition Exists=0x%x for part 0x%x.\r\n"), fExists, dwPartType));        if (fExists) {            // Partition was found.              if (dwCreationFlags == PART_CREATE_NEW)                return INVALID_HANDLE_VALUE;                        if (g_partStateTable[dwPartIndex].pPartEntry == NULL) {                // Open partition.  If this is the boot section partition, then file pointer starts after MBR                g_partStateTable[dwPartIndex].pPartEntry = (PPARTENTRY)(g_pbMBRSector + PARTTABLE_OFFSET + sizeof(PARTENTRY)*dwPartIndex);                g_partStateTable[dwPartIndex].dwDataPointer = 0;            }                        return (HANDLE)&g_partStateTable[dwPartIndex];                    }        else {            // If there are already 4 partitions, or creation flag specified OPEN_EXISTING, fail.            if ((dwPartIndex == NUM_PARTS) || (dwCreationFlags == PART_OPEN_EXISTING))                return INVALID_HANDLE_VALUE;            // Create new partition            return CreatePartition (dwStartSector, dwNumSectors, dwPartType, fActive, dwPartIndex);        }        return INVALID_HANDLE_VALUE;        }


IsValidMBR() 函数的代码如下:
C/C++ code
static BOOL IsValidMBR() {    // Check to see if the MBR is valid    // MBR block is always located at logical sector 0    g_dwMBRSectorNum = GetMBRSectorNum();            RETAILMSG (1, (TEXT("IsValidMBR: MBR sector = 0x%x\r\n"), g_dwMBRSectorNum));       if ((g_dwMBRSectorNum == INVALID_ADDR) || !FMD_ReadSector (g_dwMBRSectorNum, g_pbMBRSector, NULL, 1))     {        return FALSE;      }    // lqm added for test.10-04-12    RETAILMSG (1, (TEXT("g_pbMBRSector[0] = 0x%x\r\n"), g_pbMBRSector[0]));    RETAILMSG (1, (TEXT("g_pbMBRSector[1] = 0x%x\r\n"), g_pbMBRSector[1]));    RETAILMSG (1, (TEXT("g_pbMBRSector[2] = 0x%x\r\n"), g_pbMBRSector[2]));    RETAILMSG (1, (TEXT("g_pbMBRSector[SECTOR_SIZE-2] = 0x%x\r\n"), g_pbMBRSector[SECTOR_SIZE-2]));    RETAILMSG (1, (TEXT("g_pbMBRSector[SECTOR_SIZE-1] = 0x%x\r\n"), g_pbMBRSector[SECTOR_SIZE-1]));    // end added.    return ((g_pbMBRSector[0] == 0xE9) &&         (g_pbMBRSector[1] == 0xfd) &&         (g_pbMBRSector[2] == 0xff) &&         (g_pbMBRSector[SECTOR_SIZE-2] == 0x55) &&         (g_pbMBRSector[SECTOR_SIZE-1] == 0xAA));}


打印信息中提示:g_dwMBRSectorNum = 0.
请问,这个MBR到底是个什么东西?存放在block0的第0个page吗?
我在FL2440开发板上,上面打印信息,读出来的g_pbMBRSector与后面的完全符合,
开发板的flash是K9F1G08的,另外一块板是用的K9F1208,更改bootloader相关代码后,这里打印的信息,


g_pbMBRSector[0] = 0x0
g_pbMBRSector[1] = 0x0
g_pbMBRSector[2] = 0x0
g_pbMBRSector[SECTOR_SIZE-2] = 0x0
g_pbMBRSector[SECTOR_SIZE-1] = 0x0
为什么这些会是0?错在哪里?
从程序分析,上面两个板的MBR都是放在block0的第0页?????

[解决办法]
建议楼主 好好看看这篇 文章:
http://blog.csdn.net/hugohong/archive/2009/05/20/4204700.aspx

热点排行