|
2440 bootloader中,MBR是什么东西?
[复制链接]
请教,bootloader中有这么一个函数:
- // 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() 函数的代码如下:
- 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页?????
|
|