2440 bootloader中,MBR是什么东西?

armeasy 2010-04-12 08:13:27
请教,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页?????
...全文
321 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
armeasy 2010-04-14
  • 打赏
  • 举报
回复
系统已经起来了,但是显示一片空白,不知是显存地址冲突还是什么原因,打印信息如下:
Microsoft Windows CE Ethernet Bootloader Common Library Version 1.1 Built Apr 12 2010 09:47:46
Microsoft Windows CE Bootloader for the Samsung SMDK2440 Version 2.4 Built Apr 14 2010

FMD: ReadID (Mfg=ec, Dev=76)
FMD_Init: finished successful
FMD_Init: reserved_blocks 104
FMD_GetInfo
Press [ENTER] to launch image stored on boot media, or [SPACE] to enter boot monitor.

Initiating image launch in 5 seconds.
Ethernet Boot Loader Configuration:

0) IP address: 192.168.1.115
1) Subnet mask: 255.255.255.0
2) DHCP: Disabled
3) Boot delay: 5 seconds
4) Reset to factory default configuration
5) Startup image: LAUNCH EXISTING
6) Program disk image into SmartMedia card: Enabled
7) Program CS8900 MAC address (00:11:22:33:44:55)
8) Kernel Debugger: DISABLED
9) Format Boot Media for BinFS
F) Low-level format the Smart Media card
D) Download image now
L) LAUNCH existing Boot Media image
U) DOWNLOAD image now(USB)
R) Read Configuration
W) Write Configuration Right Now

Enter your selection: u
System ready!
Preparing for download...
Please send the Image through USB.
pUSBCtrlAddr->OCSR1.out_pkt_rdy = 0x1
Ep3Handler : downPtIndex = 0x30800040

Download BIN file information:
-----------------------------------------------------
[0]: Base Address=0x80200000 Length=0x22620b0
-----------------------------------------------------
ROMHDR at Address 80200044h
Writing single region/multi-region update, dwBINFSPartLength: 36053168
IsValidMBR: MBR sector = 0x1a0
g_pbMBRSector[0] = 0xe9
g_pbMBRSector[1] = 0xfd
g_pbMBRSector[2] = 0xff
g_pbMBRSector[SECTOR_SIZE-2] = 0x55
g_pbMBRSector[SECTOR_SIZE-1] = 0xaa
OpenPartition: Partition Exists=0x1 for part 0x21.
BP_SetDataPointer at 0x0
WriteData: Start = 0x0, Length = 0x22620b0.
Log2Phys: Logical 0x1c0 -> Physical 0x360
IsBlockBad(43A): TRUE
Updateded TOC!
IsValidMBR: MBR sector = 0x1a0
g_pbMBRSector[0] = 0xe9
g_pbMBRSector[1] = 0xfd
g_pbMBRSector[2] = 0xff
g_pbMBRSector[SECTOR_SIZE-2] = 0x55
g_pbMBRSector[SECTOR_SIZE-1] = 0xaa
OpenPartition: Partition Exists=0x1 for part 0xb.
TOC {
dwSignature: 0x434F544E
BootCfg {
ConfigFlags: 0x830
BootDelay: 0x5
ImageIndex: 1
IP: 192.168.1.115
MAC Address: 00:11:22:33:44:55
Port: 0.0.0.0
SubnetMask: 255.255.255.0
}
ID[0] {
dwVersion: 0x20004
dwSignature: 0x45424F54
String: 'eboot.nb0'
dwImageType: 0x2
dwTtlSectors: 0x200
dwLoadAddress: 0x80038000
dwJumpAddress: 0x80038000
dwStoreOffset: 0x0
sgList[0].dwSector: 0xA0
sgList[0].dwLength: 0x200
}
ID[1] {
dwVersion: 0x1
dwSignature: 0x43465348
String: ''
dwImageType: 0x2
dwTtlSectors: 0x11311
dwLoadAddress: 0x80200000
dwJumpAddress: 0x8022C480
dwStoreOffset: 0x0
sgList[0].dwSector: 0x360
sgList[0].dwLength: 0x11311
}
chainInfo.dwLoadAddress: 0X00000000
chainInfo.dwFlashAddress: 0X00000000
chainInfo.dwLength: 0X00000000
}
waitforconnect
INFO: OEMLaunch: Jumping to Physical Address 0x3022C480h (Virtual Address 0x8022C480h)...


Windows CE Kernel for ARM (Thumb Enabled) Built on Aug 4 2008 at 18:38:38
ProcessorType=0920 Revision=0
sp_abt=ffff5000 sp_irq=ffff2800 sp_undef=ffffc800 OEMAddressTable = 8022c354
DCache: 8 sets, 64 ways, 32 line size, 16384 size
ICache: 8 sets, 64 ways, 32 line size, 16384 size
Sp=ffffc7cc
OEMIoControl: Unsupported Code 0x10100b4 - device 0x0101 func 45
OEMIoControl: Unsupported Code 0x101008c - device 0x0101 func 35
FMD: ReadID (Mfg=ec, Dev=76)
FMD_Init: finished successful
FMD_Init: reserved_blocks 104
FMD_GetInfo
IsBlockBad(6C): TRUE
IsBlockBad(43A): TRUE
OEMIoControl: Unsupported Code 0x1010104 - device 0x0101 func 65
OEMIoControl: Unsupported Code 0x10100c4 - device 0x0101 func 49
OEMIoControl: Unsupported Code 0x10100c4 - device 0x0101 func 49
OEMIoControl: Unsupported Code 0x10100d0 - device 0x0101 func 52
OEMIoControl: Unsupported Code 0x10100f8 - device 0x0101 func 62
+CS8900:DriverEntry
CS8900:CSInit failure!!

dm9000 init.
[dm9]: Chip signature is 0000291E
INFO: CReg2440Uart::CReg2440Uart using processor frequency reported by the OAL (50000000).
I2C Init
IIC IRQ mapping: [IRQ:27->sysIRQ:19].
Key: DLL_PROCESS_ATTACH.
[Pwrbtn2440.c] EINT_InitializeAddresses Success
[Pwrbtn2440.c] KEY_Init Sucessfully!
[Pwrbtn2440.c] Wait EINT4...
INFO: WAVEDEV.DLL: SetI2SClockRate: Using processor frequency reported by the OAL (50000000).
Prescaler:2
[Bak_hw.cpp] BL_InitializeAddresses - Success
BL_ON progress bar thread closed!
++S3C2440DISP::S3C2440DISP
[s3c2440disp.cpp] rGPCCON = 0xaaaaaaaa
[s3c2440disp.cpp] LCDCON1 = 0x6300179
[s3c2440disp.cpp] LCDCON2 = 0x1577c043
[s3c2440disp.cpp] LCDCON3 = 0x2c31f28
[s3c2440disp.cpp] LCDCON4 = 0xd80
[s3c2440disp.cpp] LCDCON5 = 0x14b09
--S3C2440DISP::InitDisplay done
DISPLAY:800*480
OEMIoControl: Unsupported Code 0x10100fc - device 0x0101 func 63
BL_OFF


二楼那篇文章很牛,按照那文章,系统已经正常运行。
armeasy 2010-04-13
  • 打赏
  • 举报
回复
看了上面的文章,大受启发,我将MBR放到了block13,这时能进系统了,但是仍然卡在flash驱动那里,打印信息如下:
Microsoft Windows CE Ethernet Bootloader Common Library Version 1.1 Built Apr 12 2010 09:47:46
Microsoft Windows CE Bootloader for the Samsung SMDK2440 Version 2.4 Built Apr 13 2010

FMD: ReadID (Mfg=ec, Dev=76)
FMD_Init: finished successful
FMD_Init: reserved_blocks 0
FMD_GetInfo
Press [ENTER] to launch image stored on boot media, or [SPACE] to enter boot monitor.

Initiating image launch in 5 seconds.
Ethernet Boot Loader Configuration:

0) IP address: 192.168.1.115
1) Subnet mask: 255.255.255.0
2) DHCP: Disabled
3) Boot delay: 5 seconds
4) Reset to factory default configuration
5) Startup image: LAUNCH EXISTING
6) Program disk image into SmartMedia card: Enabled
7) Program CS8900 MAC address (00:11:22:33:44:55)
8) Kernel Debugger: DISABLED
9) Format Boot Media for BinFS
F) Low-level format the Smart Media card
D) Download image now
L) LAUNCH existing Boot Media image
U) DOWNLOAD image now(USB)
R) Read Configuration
W) Write Configuration Right Now

Enter your selection: u
System ready!
Preparing for download...
Please send the Image through USB.
pUSBCtrlAddr->OCSR1.out_pkt_rdy = 0x1
Ep3Handler : downPtIndex = 0x30800040

Download BIN file information:
-----------------------------------------------------
[0]: Base Address=0x80200000 Length=0x22620b4
-----------------------------------------------------
ROMHDR at Address 80200044h
Writing single region/multi-region update, dwBINFSPartLength: 36053172
IsValidMBR: MBR sector = 0x1a0
g_pbMBRSector[0] = 0xff
g_pbMBRSector[1] = 0xff
g_pbMBRSector[2] = 0xff
g_pbMBRSector[SECTOR_SIZE-2] = 0xff
g_pbMBRSector[SECTOR_SIZE-1] = 0xff
OpenPartition: Invalid MBR. Formatting flash.
Enter LowLevelFormat [0xd, 0xfff].
Erasing flash block(s) [0xd, 0xfff] (please wait): IsBlockBad(43A): TRUE
EraseBlocks: found a bad block (0x43a) - skipping...
Done.
WriteMBR: MBR block = 0xd.
Done.

OpenPartition: Partition Exists=0x0 for part 0x21.
CreatePartition: Enter CreatePartition for 0x21.
IsBlockBad(43A): TRUE
LastLogSector: Last log sector is: 0x1fe3f.
CreatePartition: Start = 0x1c0, Num = 0x11320.
Log2Phys: Logical 0x1c0 -> Physical 0x360
IsBlockBad(43A): TRUE
WriteMBR: MBR block = 0xd.
BP_SetDataPointer at 0x0
WriteData: Start = 0x0, Length = 0x22620b4.
Log2Phys: Logical 0x1c0 -> Physical 0x360
IsBlockBad(43A): TRUE
Updateded TOC!
IsValidMBR: MBR sector = 0x1a0
g_pbMBRSector[0] = 0xe9
g_pbMBRSector[1] = 0xfd
g_pbMBRSector[2] = 0xff
g_pbMBRSector[SECTOR_SIZE-2] = 0x55
g_pbMBRSector[SECTOR_SIZE-1] = 0xaa
OpenPartition: Partition Exists=0x0 for part 0xb.
CreatePartition: Enter CreatePartition for 0xb.
FindFreeSector: FreeSector is: 0x114e0 after processing part 0x21.
CreatePartition: Num sectors set to 0xe820 to allow for compaction blocks.
CreatePartition: Start = 0x114e0, Num = 0xe820.
WriteMBR: MBR block = 0xd.
TOC {
dwSignature: 0x434F544E
BootCfg {
ConfigFlags: 0x830
BootDelay: 0x5
ImageIndex: 1
IP: 192.168.1.115
MAC Address: 00:11:22:33:44:55
Port: 0.0.0.0
SubnetMask: 255.255.255.0
}
ID[0] {
dwVersion: 0x20004
dwSignature: 0x45424F54
String: 'eboot.nb0'
dwImageType: 0x2
dwTtlSectors: 0x200
dwLoadAddress: 0x80038000
dwJumpAddress: 0x80038000
dwStoreOffset: 0x0
sgList[0].dwSector: 0xA0
sgList[0].dwLength: 0x200
}
ID[1] {
dwVersion: 0x1
dwSignature: 0x43465348
String: ''
dwImageType: 0x2
dwTtlSectors: 0x11311
dwLoadAddress: 0x80200000
dwJumpAddress: 0x8022C480
dwStoreOffset: 0x0
sgList[0].dwSector: 0x360
sgList[0].dwLength: 0x11311
}
chainInfo.dwLoadAddress: 0X00000000
chainInfo.dwFlashAddress: 0X00000000
chainInfo.dwLength: 0X00000000
}
waitforconnect
INFO: OEMLaunch: Jumping to Physical Address 0x3022C480h (Virtual Address 0x8022C480h)...


Windows CE Kernel for ARM (Thumb Enabled) Built on Aug 4 2008 at 18:38:38
ProcessorType=0920 Revision=0
sp_abt=ffff5000 sp_irq=ffff2800 sp_undef=ffffc800 OEMAddressTable = 8022c354
DCache: 8 sets, 64 ways, 32 line size, 16384 size
ICache: 8 sets, 64 ways, 32 line size, 16384 size
Sp=ffffc7cc
OEMIoControl: Unsupported Code 0x10100b4 - device 0x0101 func 45
OEMIoControl: Unsupported Code 0x101008c - device 0x0101 func 35
FMD: ReadID (Mfg=ec, Dev=76)
FMD_Init: finished successful
FMD_Init: reserved_blocks 0
FMD_GetInfo
IsBlockBad(4): TRUE
IsBlockBad(43A): TRUE
OEMIoControl: Unsupported Code 0x1010104 - device 0x0101 func 65

正在查原因,不知何解?
gooogleman 2010-04-13
  • 打赏
  • 举报
回复
文件系统相关的东西,这里是创建 fat分区的。
FrankBIBI 2010-04-13
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 jimigaga 的回复:]
你的FMD_OEMIoControl函数中应该没有对不支持的操作码进行处理,可在switch(dwIoControlCode)后加default处理。
[/Quote]

呵呵~学习了~MARK
jimigaga 2010-04-13
  • 打赏
  • 举报
回复
你的FMD_OEMIoControl函数中应该没有对不支持的操作码进行处理,可在switch(dwIoControlCode)后加default处理。
sikinzen 2010-04-13
  • 打赏
  • 举报
回复
学习。。。。
domworldjohn 2010-04-13
  • 打赏
  • 举报
回复
相当于文件的头文件
博说医械研发 2010-04-13
  • 打赏
  • 举报
回复
MBR是建立磁盘分区的
armeasy 2010-04-13
  • 打赏
  • 举报
回复
太感谢kyzf了,我好好看看,好文章
xilidecai 2010-04-13
  • 打赏
  • 举报
回复
BP开头的这些函数正在研究中...MARK!
kyzf 2010-04-12
  • 打赏
  • 举报
回复
建议楼主 好好看看这篇 文章:
http://blog.csdn.net/hugohong/archive/2009/05/20/4204700.aspx

19,502

社区成员

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

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