OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Oct 18, 2017 7:45 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: USB Compatible BPB Issue
PostPosted: Sun Oct 15, 2017 1:36 pm 
Offline

Joined: Mon Apr 18, 2011 5:25 pm
Posts: 4
I have been struggling with USB deployment for a week. I really need some advice on how to forge a valid BPB that will deploy gracefully on Floppy, CDROM, and USB, both in a VM and on the bare metal (I don't mind if there are differences for each build).

My setup works fine in bochs and emulates the drive as a floppy. But when I test on all hardware I have I'm getting HDD emulation. I've exhausted the following BPB's they all behave the same on my hardware:
https://github.com/alexfru/BootProg
https://board.flatassembler.net/topic.php?t=17130

I'm developing on windows and I've been using BootProg and Rufus. I've analyzed the contents of the disk through 010 editor and Rufus is working fine and the image does boot. The problem occurs when I read more than 18 sectors.

On bochs things look like this:
DX = 0000 on entry to 7C00
LBA = 18 -> reads sector 18
LBA = 19 -> reads sector 19
LBA = 1A -> reads sector 1A

On the hardware I get this
DX = 0080 on entry to 7C00
LBA = 18 -> reads sector 18
LBA = 19 -> reads sector 3F
LBA = 1A -> reads sector 40

Here is the current BPB that I'm using (lifted straight from Dex), can someone see any issues? I want to avoid developing a boot loader if at all possible, and wish to continue using BootProg or some other convenient alternative under windows.

Code:
jmp     short init
nop
bsOemName               DB      "MSDOS5.0"      ; 0x03
bpbBytesPerSector       DW      512             ; 0x0B
bpbSectorsPerCluster    DB      1               ; 0x0D
bpbReservedSectors      DW      1               ; 0x0E
bpbNumberOfFATs         DB      2               ; 0x10
bpbRootEntries          DW      224             ; 0x11
bpbTotalSectors         DW      2880            ; 0x13
bpbMedia                DB      0F0h            ; 0x15
bpbSectorsPerFAT        DW      9               ; 0x16
bpbSectorsPerTrack      DW      18              ; 0x18
bpbHeadsPerCylinder     DW      2               ; 0x1A
bpbHiddenSectors        DD      0               ; 0x1C
bpbTotalSectorsBig      DD      0               ; 0x20
bsDriveNumber           DB      0               ; 0x24
bsUnused                DB      0               ; 0x25
bsExtBootSignature      DB      29H             ; 0x26
bsSerialNumber          DD      1                     ; 0x27
bsVolumeLabel           DB      "BOOT FLOPPY"   ; 0x2B
bsFileSystem            DB      "FAT12   "      ; 0x36


full boot sector is attached, it dumps each sector and records the LBA, CHS, and DX in the first 6 bytes of each sector


Attachments:
test.zip [4.6 KiB]
Downloaded 2 times
Top
 Profile  
 
 Post subject: Re: USB Compatible BPB Issue
PostPosted: Sun Oct 15, 2017 2:07 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 49
Just an observation. I didn't look thoroughly through this code but it appears you put the stack at 0x800 and that grows downward. The BDA ends at about 0x500 which pretty much leaves 768 byte (0x800-0x500) on most modern hardware. That's about 768 bytes for stack space before you start overwriting the BDA and 1024 before you start over writing the interrupt table. I've encountered BIOSes that will use considerable stack space for things like disk read etc. I might caution you that 768 bytes might cause issues on some hardware. Not saying that has anything to do with your issues, just an observation.


Top
 Profile  
 
 Post subject: Re: USB Compatible BPB Issue
PostPosted: Sun Oct 15, 2017 2:18 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1160
Your boot code assumes there will always be 2 heads and 18 sectors per track. This is only true for 1.44MB floppy disks. For your code to work elsewhere, you will need to determine the appropriate parameters to translate between LBA and CHS using INT 0x13 AH=0x08.

(There are some rare situations involving very old floppy disks where INT 0x13 AH=0x08 won't work correctly, but you probably don't care about those.)


Top
 Profile  
 
 Post subject: Re: USB Compatible BPB Issue
PostPosted: Sun Oct 15, 2017 2:48 pm 
Offline

Joined: Mon Apr 18, 2011 5:25 pm
Posts: 4
This is only a test I wrote to isolate the issues I'm having with BootProg on a USB drive. I'm not writing a bootloader. But now that you mention it BootProg depends directly on the BPB for its disk geometry.

It was my understanding that if the BPB looks sane, then Floppy emulation may be used, which would suit me cos I can just use BootProg with no adjustments except to the BPB. This is not what I'm seeing though, I'm getting the same results on 6 different systems. Not one of them uses Floppy emulation

Thanks for the advice. I think I'm unblocked.


Top
 Profile  
 
 Post subject: Re: USB Compatible BPB Issue
PostPosted: Sun Oct 15, 2017 2:49 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 805
clns wrote:
I really need some advice on how to forge a valid BPB that will deploy gracefully on Floppy, CDROM, and USB, both in a VM and on the bare metal (I don't mind if there are differences for each build).

My setup works fine in bochs and emulates the drive as a floppy. But when I test on all hardware I have I'm getting HDD emulation. I've exhausted the following BPB's they all behave the same on my hardware:
https://github.com/alexfru/BootProg


Thanks for using BootProg!

What I did with USB was kinda simple. I FAT32-formatted my 2GB stick using standard Windows tools. I then just used the BPB they created and only changed the code in the boot sector. HDD emulation worked just fine on a few PCs I tried. Perhaps, that's what you should be doing as well. I mean, formatting for HDD emulation.


Top
 Profile  
 
 Post subject: Re: USB Compatible BPB Issue
PostPosted: Sun Oct 15, 2017 2:57 pm 
Offline

Joined: Mon Apr 18, 2011 5:25 pm
Posts: 4
Yeah I think your right there. I'll format it and grab a capture. BTW great tool, much more comfortable for me to develop under windows and it fits seamlessly into the build process.


Top
 Profile  
 
 Post subject: Re: USB Compatible BPB Issue
PostPosted: Sun Oct 15, 2017 5:10 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1160
clns wrote:
But now that you mention it BootProg depends directly on the BPB for its disk geometry.

There's no guarantee that the BIOS will use any particular geometry for a USB drive. You can't rely on the BPB having correct values for anything other than a real floppy disk. You must use INT 0x13 AH=0x08.

clns wrote:
It was my understanding that if the BPB looks sane, then Floppy emulation may be used, which would suit me cos I can just use BootProg with no adjustments except to the BPB.

Having a valid BPB is not a guarantee that the BIOS will choose floppy disk emulation. I suspect the BIOS doesn't consider 2 heads and 18 sectors per track a valid geometry for a USB drive anyway. You might have better luck with 255 (not 256) heads and 63 sectors per track.


Top
 Profile  
 
 Post subject: Re: USB Compatible BPB Issue
PostPosted: Sun Oct 15, 2017 6:25 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8114
Location: At his keyboard!
Hi,

clns wrote:
My setup works fine in bochs and emulates the drive as a floppy. But when I test on all hardware I have I'm getting HDD emulation.


You might like the Problems Booting From USB Flash wiki page. :)


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: USB Compatible BPB Issue
PostPosted: Mon Oct 16, 2017 3:48 am 
Offline

Joined: Mon Apr 18, 2011 5:25 pm
Posts: 4
I've read that a few times, thanks though Brendan, but there's a big issues with that article: It's full of folklore and superstition. The "must list" towards the bottom is a shaman's ritual. This USB boots just fine on ancient Pentiums with nothing more than the boot signature, all else is ignored. My problem is the cross-over to the second track, it reads wrong sectors. The advice Octocontrabass gave is exactly what I need to do.


Top
 Profile  
 
 Post subject: Re: USB Compatible BPB Issue
PostPosted: Mon Oct 16, 2017 10:55 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1160
clns wrote:
The "must list" towards the bottom is a shaman's ritual.

It's way more conservative than necessary, but it is not superstition. In order to reliably boot from USB on the greatest number of computers, you must have either a valid partition table or a valid BPB, and the criteria for "valid" are complicated and vary significantly between firmware. (The only foolproof way to appease every BIOS is to generate exactly the same partition table or BPB as Windows. Doing this without Windows is a huge challenge.)

clns wrote:
This USB boots just fine on ancient Pentiums with nothing more than the boot signature, all else is ignored.

Older BIOSes are not smart enough to validate the boot sector. It's newer BIOSes that will cause the most trouble.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group