Page 1 of 1

booting from USB flash memory

Posted: Tue Mar 10, 2009 5:24 am
by weezo
hi
say i want my os to be installed and boot from usb flash memory and i dont it to support FAT or partitions also suppose i'm developing new file system,as if the usb flash memory is the only storage device attached to pc and bios support booting from usb device,now can i simply copy my boot sector to first sector then loading my kernel,according to my new file system,and let my os interface with the usb device,again according to my new file system formatting or layout,!?

now the reason for such question is,i am not trying to get my os replace windows nor linux nor even dos but to know how i am thinking,for example in james tutorial about running unix clone ,and it is so great tutorial, why developing new clone if it is already exist!
i hope i was somewhat clear,or over-clear may be?,

Re: booting from USB flash memory

Posted: Tue Mar 10, 2009 5:52 am
by djmauretto
weezo wrote:hi
say i want my os to be installed and boot from usb flash memory and i dont it to support FAT or partitions also suppose i'm developing new file system,as if the usb flash memory is the only storage device attached to pc and bios support booting from usb device,now can i simply copy my boot sector to first sector then loading my kernel,according to my new file system,and let my os interface with the usb device,again according to my new file system formatting or layout,!?
Sure :wink:
But note that some Laptop with Stupid Bios (HP with Phoenix BIOS)
fail the boot from USB if it don't see FAT format =D>

Re: booting from USB flash memory

Posted: Tue Mar 10, 2009 10:39 am
by quok
djmauretto wrote:
weezo wrote:hi
say i want my os to be installed and boot from usb flash memory and i dont it to support FAT or partitions also suppose i'm developing new file system,as if the usb flash memory is the only storage device attached to pc and bios support booting from usb device,now can i simply copy my boot sector to first sector then loading my kernel,according to my new file system,and let my os interface with the usb device,again according to my new file system formatting or layout,!?
Sure :wink:
But note that some Laptop with Stupid Bios (HP with Phoenix BIOS)
fail the boot from USB if it don't see FAT format =D>
I happen to have a HP laptop that has a Phoenix BIOS, but I don't have that problem. It's booted anything I've thrown at it. Could you provide more information about the BIOS in question? Perhaps BIOS version, date, model of machine or how old it is?

Re: booting from USB flash memory

Posted: Tue Mar 10, 2009 10:57 am
by Firestryke31
I have a Compaq (for all intents and purposed an HP) laptop with (IIRC) a Phoenix BIOS and it's had no problems trying to boot anything that had a valid signature. It even tries to boot from my iPod if I forget to unplug it.

Re: booting from USB flash memory

Posted: Tue Mar 10, 2009 12:16 pm
by Dex
We as a community need to clear this up, as its been asked too many time's and these different answers.
I have two simple boot sector here:
With BPB

Code: Select all

;************************************
; By Dex
; Assemble with fasm 
; c:\fasm USB1.asm USB1.bin
;
;************************************
org 0x7C00 
use16
Boot:     jmp   start
	  nop
;------------------------------------------;
;  Standard BIOS Parameter Block, "BPB".   ;
;------------------------------------------;
	  bpbOEM	  db  'MSDOS5.0'
	  bpbSectSize	  dw  512
	  bpbClustSize	  db  1
	  bpbReservedSec  dw  1
	  bpbFats	  db  2
	  bpbRootSize	  dw  224
	  bpbTotalSect	  dw  2880
	  bpbMedia	  db  240
	  bpbFatSize	  dw  9
	  bpbTrackSect	  dw  18
	  bpbHeads	  dw  2
	  bpbHiddenSect   dd  0
	  bpbLargeSect	  dd  0
     ;---------------------------------;
     ;  extended BPB for FAT12/FAT16   ;
     ;---------------------------------;
	  bpbDriveNo	  db  0
	  bpbReserved	  db  0
	  bpbSignature	  db  41		      
	  bpbID 	  dd  1
	  bpbVolumeLabel  db  'BOOT FLOPPY'
	  bpbFileSystem   db  'FAT12   '

;****************************
; Realmode startup code.
;****************************
start:
        xor   ax,ax
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   sp,0x7C00 
      	mov   si,Mesage1
        call  print
        jmp   $

;****************************
;  print.
;****************************
print:
        mov   ah,0Eh                       
again1:
	lodsb                              
        or   al,al                         
        jz   done1                         
	int  10h                           
        jmp  again1                        
done1:
	ret                               

Mesage1: db  'USB, with BPB works OK',0

;*************************************
; Make program 510 byte's + 0xaa55
;*************************************
times 510- ($-Boot)  db 0
dw 0xaa55
Without BPB

Code: Select all

;************************************
; By Dex
; Assemble with fasm 
; c:\fasm USB2.asm USB2.bin
;
;************************************
org 0x7C00 
use16
;****************************
; Realmode startup code.
;****************************
start:
        xor   ax,ax
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   sp,0x7C00 
      	mov   si,Mesage1
        call  print
        jmp   $

;****************************
;  print.
;****************************
print:
        mov   ah,0Eh                       
again1:
	lodsb                              
        or   al,al                         
        jz   done1                         
	int  10h                           
        jmp  again1                        
done1:
	ret                               

Mesage1: db  'USB, without BPB works OK',0

;*************************************
; Make program 510 byte's + 0xaa55
;*************************************
times 510- ($-start)  db 0
dw 0xaa55
Now the one without BPB should work just the same as the one with and they should both work on both hdd and fdd emulation, if it does not mater whats on the sector as some have said.
So please test it with your USB BIOS and we can find out for sure.

NOTE: I can post a .bin files and a prog to put it on usb, if that will help.

Re: booting from USB flash memory

Posted: Tue Mar 10, 2009 12:23 pm
by djmauretto
I happen to have a HP laptop that has a Phoenix BIOS, but I don't have that problem. It's booted anything I've thrown at it. Could you provide more information about the BIOS in question? Perhaps BIOS version, date, model of machine or how old it is?
HP Pavilion dv8000t, i just try to load my os ( note that it boot fine on every PC desktop)
with CDrom ,USB floppy and USB HD emulation ,but it's not work , of course
HP boot windows xp ,and also Win98 fine,and i don't understand why ,until i have
formatted my usb pen with fat format,then HP boot fine also me =D>

Re: booting from USB flash memory

Posted: Tue Mar 10, 2009 1:02 pm
by djmauretto
Of course BIOS don't search for FAT but needed only BPB for disk geometry,
but i don't have investigate because the HP it's not mine...

Re: booting from USB flash memory

Posted: Tue Mar 10, 2009 1:32 pm
by johnsa
I (sofar) concur with dex.. I opted for my boot loaders to not have any sort of BPB/MBR at all as I don't need it.. my file-system is managed in a totally separate way. Sofar my boot code has worked on cdrom/hdd/fdd and usb (hdd emulation) on the systems ive tested with. The only machine it didn't work on with usb is a machine that doesn't boot ANY bootable usb.. so thats a machine issue not a code issue.

Re: booting from USB flash memory

Posted: Tue Mar 10, 2009 1:44 pm
by Dex
So far from basic test with those boot sector, i get this;
If i use the one with BPB it boots on both pc/laptop, but without BPB it will only boot on one, but the differenc seems (on my test, anyway).
That under HDD emulation it will both both with or without the BPB, but with FDD emulation it will only boot with BPB.
As if i plug the same fob in with the BPB code,it shows up in the boot menu, as a FDD-USB, but without the BPB, it shows up as a HDD.

It maybe the case that if your BIOS only boots FDD emulation for USB, than it will need a BPB, but for HDD emulation it is not needed, but there may still be case where there is checks for "active partition" for example.
So my ? are,
1. Can anyone boot usb with FDD emulation, without the BPB being present ?.


So BPB is only needed for USB FDD emulation
This is why we are geting different results.

Re: booting from USB flash memory

Posted: Tue Mar 10, 2009 2:57 pm
by weezo
i posted a reply as topic by mistake lol
anyway i would like to thank u dex u always get to point ,so it is such simple as long as i know what i am doing?
something else,can u refere me to any resources or tutorials about interfacing with usb flash memory,i mean like ATA for hard disks?
thnx again

Re: booting from USB flash memory

Posted: Tue Mar 10, 2009 8:07 pm
by Dex
Thanks weezo, as to your request, if you boot from a usb fob, you can read/write to the fob just the same as you would to the device its emulating, eg: int 13h, but once you go to pmode emulation stops.
Now in my OS i have both a pmode fdd and hdd drivers and a go back to realmode to use int 13h, as whe you go back emuation starts again.
So this mean you can read/write to usb just like any other drive.
But if you want to talk to it dirctly that is much harder, and you need to write a usb stack, for your OS.
You need to get the usb spec pdf, see here:
http://www.usb.org/developers
http://www.usbmadesimple.co.uk/index.html
And here some basic starter code
http://forum.osdev.org/viewtopic.php?f= ... ex#p139910