USB Compatible BPB Issue

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: USB Compatible BPB Issue

Post by Octocontrabass »

BenLunt wrote:I have a valid DOS 5.0 1.44Meg Floppy BPB with 2 heads, 18 SPT, 2880 sectors, etc., and it still did not matter.
Of course that doesn't work, Windows would never write a floppy disk BPB to a USB flash drive. If you want it to work, you have to format the disk using Windows and copy the BPB created by Windows. If you choose different values than Windows, your BPB may not pass as "valid" even if it is.

For a specific example, your "hard disk" BPB in usbboot.asm says 16 heads, but Windows always uses 255 heads. BIOS code that was only tested with disks formatted by Windows may reject any value other than 255.
clns
Posts: 11
Joined: Mon Apr 18, 2011 5:25 pm

Re: USB Compatible BPB Issue

Post by clns »

Octo you maintain that the BIOS looks at the BPB under a microscope. The point is that it does in fact boot, and gets hard disk emulation.

It's really simple. The BIOS comes with a default implementation. It will present blocks of flash memory as sectors using that implementation. If the BIOS wants there to be 255 heads, then that's precisely what you get. The BIOS doesn't even look at your BPB, what you put in there does not matter. You get what the BIOS implements. Requiring a valid BPB is a myth.

And Thanks Michael but I also noted that I don't mind that each deployment differs.
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: USB Compatible BPB Issue

Post by BenLunt »

Antti wrote:Ben, this may be nitpicking but if you test for 386+ CPU, it would be a good idea to use 8086 compatible instructions when doing it or have a comment line that explains the decision. To me this is like a "do it well or don't do it at all" issue because your code is likely to be more referenced in general. Things like these may give a bad first impression about code quality and that is way more relevant than the test itself.

Push imm16 (opcode 0x68) was not supported or it was undocumented at least.
The code is something I quickly threw together from various sources. The 386+ check was a remanent of another code file.

If you notice, I don't check for the carry flag after the calls either. The code wasn't meant to be quality code. Simply a bootable block of code to print the DL register and a few parameters. The DL register is what I was after, really. Whether it was 00h or 80h.

As for the Push immd16 instruction, IIRC, it was documented from the 80x286 and then later CPU's, but again, not an issue since I was only after the results, not the quality of the code. :-)

Ben
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: USB Compatible BPB Issue

Post by BenLunt »

Octocontrabass wrote:
BenLunt wrote:I have a valid DOS 5.0 1.44Meg Floppy BPB with 2 heads, 18 SPT, 2880 sectors, etc., and it still did not matter.
Of course that doesn't work, Windows would never write a floppy disk BPB to a USB flash drive. If you want it to work, you have to format the disk using Windows and copy the BPB created by Windows. If you choose different values than Windows, your BPB may not pass as "valid" even if it is.

For a specific example, your "hard disk" BPB in usbboot.asm says 16 heads, but Windows always uses 255 heads. BIOS code that was only tested with disks formatted by Windows may reject any value other than 255.
You are probably correct, however, this just proves that most manufacturers thought "If it works for Windows, that's all that matters". Unfortunately. My idea is that a BIOS should not care, nor have any idea what the OS is that it is helping to load. Therefore, it should not only work if it works for Windows.

As for a Heads value of 255, this won't emulate as a floppy, so that is out of the question. It looks to me that a majority of the BIOS/Firmware, especially now-a-days, will only emulate to a hard drive. Probably only the first few USB bootable capable BIOS/Firmware machines emulated a 1.44Meg floppy. Just my observation.

Thanks,
Ben
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: USB Compatible BPB Issue

Post by Antti »

clns wrote:Even the Microsoft boot loader uses 32bit register extensions making it 386 as well. Why on earth would you self impose such a restriction? There is no such thing as an 8086 which boots USB (outside of hobby hardware hacking).
My comment should make sense if we put it into context. There already was a test for 386+ CPU with an obvious intent to do the test (based on comments, error message, etc.) and I pointed out that it should be "done well" or not at all. The latter would be a lot better option because, as have been said, the test is not really necessary. If there was a test anyway (and bytes spent on it), would it make perfect sense to bring some educational value and/or use it as a positive sign of author's style? This is more like a general discussion about programming and the whole "8086" is relatively insignificant but it started the discussion. "Low quality" code has many advantages (simplicity, development resources, etc.) but it is also important to make it obvious that it has been written with that in mind. If we looked at the code snippet (the 386+ CPU test), it is not very obvious.
BenLunt wrote:The code is something I quickly threw together from various sources. The 386+ check was a remanent of another code file.
Code snippets propagate. This is an important point.
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: USB Compatible BPB Issue

Post by Antti »

BenLunt wrote:It looks to me that a majority of the BIOS/Firmware, especially now-a-days, will only emulate to a hard drive. Probably only the first few USB bootable capable BIOS/Firmware machines emulated a 1.44Meg floppy. Just my observation.
I've tried my floppy VBR (with very "standard 1.44MB" values in BPB) on a USB flash drive and all but one of my computers used the floppy emulation. The partition table area did not make any sense (code + data). However, I wouldn't count on that behavior (my MBR handles both emulation scenarios but is in favor of HDD emulation).
mikegonta
Member
Member
Posts: 229
Joined: Thu May 19, 2011 5:13 am
Contact:

Re: USB Compatible BPB Issue

Post by mikegonta »

Antti wrote:I've tried my floppy VBR (with very "standard 1.44MB" values in BPB) on a USB flash drive and all but one of my computers used the floppy emulation. The partition table area did not make any sense (code + data). However, I wouldn't count on that behavior (my MBR handles both emulation scenarios but is in favor of HDD emulation).
On the computers that I have tested none failed to boot from a USB flash drive with a floppy disk image. These included PC's that only
(and did) boot with HD emulation with drive ID 0x80.
It's been my observation that if the PC can boot from USB that it also supports the int 0x13 extensions. This includes PC's that booted
with drive ID 0x00.
In fact, I have booted an actually floppy disk in a USB floppy drive with drive ID 0x00 and used the int 0x13 extensions.
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: USB Compatible BPB Issue

Post by Octocontrabass »

clns wrote:Octo you maintain that the BIOS looks at the BPB under a microscope.
No, I maintain that different BIOSes each look at the BPB differently, so writing a BPB that doesn't exactly match Windows may result in failure on some BIOSes. The further your BPB is from Windows, the fewer BIOSes will accept it.
BenLunt wrote:You are probably correct, however, this just proves that most manufacturers thought "If it works for Windows, that's all that matters". Unfortunately. My idea is that a BIOS should not care, nor have any idea what the OS is that it is helping to load. Therefore, it should not only work if it works for Windows.
Consumer hardware is almost exclusively tested with Windows. If you can come up with the correct algorithms to generate a BPB the same way Windows does, then you don't need to use Windows to generate your BPB. Anything else - even if it's valid in any other context - may be rejected.
BenLunt wrote:As for a Heads value of 255, this won't emulate as a floppy, so that is out of the question.
Of course it will. As a test, I formatted an unpartitioned flash drive as FAT16, booted it up on the nearest convenient PC, and the BIOS set DL to 0x00 and indicated the geometry as 15/255/63. For comparison, the same flash drive with a partition table instead of a BPB boots up with the BIOS setting DL to 0x80 and the same geometry.
BenLunt wrote:It looks to me that a majority of the BIOS/Firmware, especially now-a-days, will only emulate to a hard drive. Probably only the first few USB bootable capable BIOS/Firmware machines emulated a 1.44Meg floppy. Just my observation.
None of them emulate a 1.44MB floppy disk. The only similarity to a floppy disk is the value in DL. Several of our wiki pages refer to it as "superfloppy" to differentiate it from a real floppy disk. (The BIOS from the previous tests explicitly names its two modes "USB HDD" and "USB ZIP" - no floppy disks involved here at all.)
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: USB Compatible BPB Issue

Post by BenLunt »

Octocontrabass wrote:As a test, I formatted an unpartitioned flash drive as FAT16, booted it up on the nearest convenient PC, and the BIOS set DL to 0x00 and indicated the geometry as 15/255/63. For comparison, the same flash drive with a partition table instead of a BPB boots up with the BIOS setting DL to 0x80 and the same geometry.
If you don't mind, would you post somewhere, or send me an email with an attachment, an image of this unpartitioned flash drive as FAT16, at least the first few sectors of it? email is fys (the at sign) fysnet (the dot goes here) net.

I would like to see if any of the machines I tested with give the same results you show.

Thanks,
Ben
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: USB Compatible BPB Issue

Post by Octocontrabass »

I've attached a complete disk image to this post. If you boot it, it will report the disk identifier from DL and the geometry from INT 0x13 AH=0x08.
Attachments
usbdemo.zip.zip.zip
(2.1 KiB) Downloaded 72 times
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: USB Compatible BPB Issue

Post by Antti »

Octocontrabass, I made two tests on real computers. :)
Attachments
Octocontrabass_Test1.png
Octocontrabass_Test2.png
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: USB Compatible BPB Issue

Post by BenLunt »

Octocontrabass wrote:I've attached a complete disk image to this post. If you boot it, it will report the disk identifier from DL and the geometry from INT 0x13 AH=0x08.
Thank you for doing that. Here are my results:

HP Pavillion g6 Notebook, 64-bit, BIOS: "Insyde", version F.17:
- Doesn't recognize a valid USB bootable device. Does not show in the list of boot options.

Dell Inspiron 1440, 32-bit, BIOS: "Dell", version A07:
- Shows in Boot options, boots with: 80h, 992/255/63

Dell Dimension 8110, 32-bit, BIOS "Dell", version A01:
- Shows in Boot options, boots with: 80h, 1023/255/63

Those are the three I tried it with. It looks like the HP Pavillion *must* have a valid partition table or it won't even try. The "Inspiron" is the machine that boots almost anything. I am guessing that if I update the "Dimension" machine's BIOS to version A07, it probably will too.

Anyway, thanks for posting the file. It is interesting to see different results from different BIOS/Manufacturers.

Ben
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: USB Compatible BPB Issue

Post by Octocontrabass »

BenLunt wrote:HP Pavillion g6 Notebook, 64-bit, BIOS: "Insyde", version F.17:
- Doesn't recognize a valid USB bootable device. Does not show in the list of boot options.
That result is concerning, but it's still possible that it doesn't like how the filesystem is only 128MB even though your flash drive is much larger.

On the other hand, it might be better if we can definitively say that you need a partition table to reliably boot from USB.

(Isn't this actually UEFI? It's pretty common for UEFI CSMs to have poor support for features that aren't standardized, and I don't know of any standards for booting from USB.)
BenLunt wrote:Dell Inspiron 1440, 32-bit, BIOS: "Dell", version A07:
- Shows in Boot options, boots with: 80h, 992/255/63

Dell Dimension 8110, 32-bit, BIOS "Dell", version A01:
- Shows in Boot options, boots with: 80h, 1023/255/63
Funny enough, the test machine I was using earlier is also Dell (Inspiron 530, 64-bit, Phoenix-Award BIOS). It's interesting that the reported geometry is different between the two. How many sectors is your flash drive?
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: USB Compatible BPB Issue

Post by BenLunt »

Octocontrabass wrote:
BenLunt wrote:HP Pavillion g6 Notebook, 64-bit, BIOS: "Insyde", version F.17:
- Doesn't recognize a valid USB bootable device. Does not show in the list of boot options.
(Isn't this actually UEFI? It's pretty common for UEFI CSMs to have poor support for features that aren't standardized, and I don't know of any standards for booting from USB.)
This machine can be either/or. I can set it to use UEFI or I can set it to use Legacy BIOS. I currently have it set to boot Legacy BIOS.
Octocontrabass wrote:
BenLunt wrote:Dell Inspiron 1440, 32-bit, BIOS: "Dell", version A07:
- Shows in Boot options, boots with: 80h, 992/255/63

Dell Dimension 8110, 32-bit, BIOS "Dell", version A01:
- Shows in Boot options, boots with: 80h, 1023/255/63
Funny enough, the test machine I was using earlier is also Dell (Inspiron 530, 64-bit, Phoenix-Award BIOS). It's interesting that the reported geometry is different between the two. How many sectors is your flash drive?
It has 15,950,592 sectors.

Thanks,
Ben
mikegonta
Member
Member
Posts: 229
Joined: Thu May 19, 2011 5:13 am
Contact:

Re: USB Compatible BPB Issue

Post by mikegonta »

BenLunt wrote:HP Pavillion g6 Notebook, 64-bit, BIOS: "Insyde", version F.17:
- Doesn't recognize a valid USB bootable device. Does not show in the list of boot options.
I came across a PC with a BIOS that looks for an MBR table and if there appears to be a table (even if there really isn't one and that table
is malformed it refused to list (and boot) the flash drive. Coincidentally the byte at 0x7DBF (the first byte of the first partition entry) is
0x8B - not the required 0x80 but bit 7 set none the less. Even thought the usbdemo works fine on this PC, yours is a different BIOS with
possibly similar behavior. Here is a simple hello world boot sector with the same BPB to see if it will list and boot.
Attachments
hello usbdemo BPB!.zip
(314 Bytes) Downloaded 78 times
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post Reply