Page 1 of 1
USB BOOTING :-(
Posted: Wed May 06, 2009 12:26 pm
by eric77
I'm developing small bootloader and it correctly works in case of booting from floppy or cd (floppy emulation). However i am unable to make it work on USB sticks. My code executes but it fails on reading USB disk sectors of stage2 (i tried it with BPB and without). When i try to read disk sectors with int 13h function 02h im getting an error AH=01 (invalid function in AH or invalid parameter) - which is odd because same code works on floppy and cd. I've tried to replace 'cli' and 'sti' instructions as someone adviced in some older post regarding USB booting, however without cli at the start it just don't boot from USB stick at all. By the way i have tried putting DOS images and old Windows 98 start disks on same USB stick and they work correctly - completely dunno whats the problem
Any ideas? THANKS!@
Re: USB BOOTING :-(
Posted: Wed May 06, 2009 1:20 pm
by Dex
Heres some things to try go here:
http://www.dex4u.com/USBboot.htm
And down load the program there and see if that works, if it does then i think i know what the problem is, i think the hdd emulation should work.
Anyway let me know and we can go on from there.
Re: USB BOOTING :-(
Posted: Wed May 06, 2009 1:32 pm
by eric77
The UsbDex.exe program is causing a BSOD on my Windows XP lol.
Re: USB BOOTING :-(
Posted: Wed May 06, 2009 6:30 pm
by Dex
Not had any reports of that, does it do that as soon as you run it ?
Re: USB BOOTING :-(
Posted: Wed May 06, 2009 6:47 pm
by bontanu
USB's usually emulate a small hard drive and NOT a floppy disk.
1) One possible cause of error is if your loader code does not use the correct drive number (probably 0x80 or 0x81) and uses a hard coded 0x00 drive ...
2) A harddisk does have a MBR (unlike floppy disks) and if your boot sector was loaded by the MBR code then you should read the partition table to find the next sector to load...
3) Sectors for a HDD used in CHS mode start from 1 (not from 0) ... but for a HDD used in LBA mode sectors start from 0.
Re: USB BOOTING :-(
Posted: Wed May 06, 2009 10:05 pm
by eric77
@bontanu you were right!
1) I was using the correct number of disk (i dont have hardcoded values, i'm using drive number passed by BIOS), however the drive number was not 00 in case of USB stick, but 80h so a hard drive
I belive i need to update my sector reading mechanism now and fit it to harddrive access. Anyway when i put floppy image as hard drive image into Bochs as follows:
ata0-master: type=disk, path="disk.bin", mode=flat, cylinders=80, heads=2, spt=18
it still works, maybe USB geometry is wrong...
Btw. is there any emulator arround that can simulate USB boot? I'm tried of switching ON and OFF my only computer :/
@Dex: Just after i click i want the FD emulation mode - maybe it is just my computer i have some antiviruses installed
Re: USB BOOTING :-(
Posted: Thu May 07, 2009 3:29 am
by eric77
Btw. if USB drive is 80h, then first (primary) physical drive will be 81h?
Re: USB BOOTING :-(
Posted: Thu May 07, 2009 5:47 am
by bontanu
Btw. if USB drive is 80h, then first (primary) physical drive will be 81h?
Probably. It all depends on how BIOS re-maps drives to allow the USB to be booted. Anyway this is valid ONLY in BIOS emulation mode. Once you go to PMODE or use your own ATA and USB drivers then the drives return to their default hardware positions.
ata0-master: type=disk, path="disk.bin", mode=flat, cylinders=80, heads=2, spt=18
it still works, maybe USB geometry is wrong...
It is very unlikely that a HDD will have 18 spt and 80 tracks
. And you can not force BIOS to use a specific geometry like you can force BOCHS.
You must get and use the CHS geometry (or LBA) specifications that the BIOS uses in order to read by using BIOS int13h.
Btw. is there any emulator around that can simulate USB boot? I'm tried of switching ON and OFF my only computer :/
When i test USB boot or drivers I use a nearby eeePC. It boots fast and contains no important data to loose.
I am not aware if any emulator that can simulate a boot from USB accurately but I have not checked exhaustively either.
A word of caution: When testing my drivers I have used an emulator (not for booting)
Everything worked "fine" and it was really usefully for my first baby steps in USB world.
However when I tested on real hardware then everything was not working... hence the emulation of USB devices was not very accurate. I had to change the code a lot in order to adapt it to hardware reality.
Re: USB BOOTING :-(
Posted: Sat May 09, 2009 12:14 am
by eric77
I have a pissing-off problem :> Lets say my USB boot loader give user a choice to stay in my operating system or to use one from the original primary disk. Since we are now marked by BIOS as disk number 80h, the primary disk is now 81h.
Now the problem start, since user picks he want to use his original operating system, im loading MBR from the primary drive 81h, and pass the execution there with changed dl=81h (to simulate BIOS). However the primary disk boot loader assumes he is 80h not 81h - and it stucks in the original loader
Any ideas how to fix this?
Re: USB BOOTING :-(
Posted: Sun May 10, 2009 1:34 pm
by Combuster
However the primary disk boot loader assumes he is 80h not 81h
It'd be the bootloader's problem if it ignores the value in DL.