OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Jul 03, 2022 5:12 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Bootloader things.
PostPosted: Wed Apr 15, 2009 7:26 am 
Offline

Joined: Wed Apr 08, 2009 2:21 pm
Posts: 11
Um, I have a question.

I understand that the load module on hard disk or floppy happens on 0 head, 0 cylinder and 1 sector, that's where the PC is running in the first place, after the BIOS has loaded, but what I don't understand, is for me to write my own boot stamp, do I have to have a partition for that or it's not needed, if I'm not going to do anything more than just load in boot sector.


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Wed Apr 15, 2009 10:28 am 
Offline
Member
Member

Joined: Mon Oct 15, 2007 3:04 pm
Posts: 296
Hard-disk under a normal file-system would have partitions, in which case the MBR / initial boot-sector would contain a boot loader to scan the partitions, find the active (bootable) one and then load the boot-sector from that partition.

A floppy etc doesn't have partitions so the 1st sector is the one and only boot sector.

At the end of the day it's up to you what you want to do. If you just want to experiment and setup a 512byte bootsector you could initially ignore partitions and then just use that as your disk (floppy or hard-disk) image for an emulator (bochs, qemu etc).


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Wed Apr 15, 2009 12:36 pm 
Offline

Joined: Wed Apr 08, 2009 2:21 pm
Posts: 11
I'm trying to write MBR boot sector on USB stick (because I don't have a floppy). Assembler code compiles all right, but further I'm trying to write bin file with this command (through XP CMD):
DEBUG boot.bin
- w 100 5 0 1

(USB I have F:)
I'm trying to write MBR, but Windows gives an error (all though USB responds): 'Application popup: 16 bit Windows Subsystem : An application has attempted to directly access the hard disk, which cannot be supported.'

I don't want to use emulator to check out the code, so how can I change from xp usb stick boot sector?


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Wed Apr 15, 2009 12:49 pm 
Offline
Member
Member

Joined: Mon Apr 13, 2009 6:10 am
Posts: 30
Location: Oldenburg, Germany
I think it should be possible with dd or similar things.
Maybe this can help you:
http://www.chrysocome.net/dd

I don't know how to use it, I just read it can write on usb devices, so it should be the right for you.
Maybe someone else can help you with dd.


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Wed Apr 15, 2009 1:38 pm 
Offline
Member
Member

Joined: Sun Jan 06, 2008 8:41 am
Posts: 174
The partition table is not a BIOS thing. It just reads the first sector checks that it has proper signature and executes the code. You don't need to conform to boot sector layout or partition table format unless you want any other OS to be able to recognize the MBR.


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Wed Apr 15, 2009 2:28 pm 
Offline
Member
Member

Joined: Mon Oct 15, 2007 3:04 pm
Posts: 296
under XP if you want to write your boot-sector image/bin to a usb stick you can use HxD (a hex editor that can open images and physical disks).
Copy from your image (ctrl-c) and paste-write into the disk at sector 0 (ctrl-b)... careful to make sure you open the right physical disk... or you might have a bad day :)

sometimes i use my own little tool to do it as well.. but hxd does the job perfectly.

booting from usb you might find you run into lots of fun problems
#1 is the usb stick bootable ? (some aren't)
#2 does your bios support booting from usb (without bugs)
#3 when the bios boots from usb it does so by emulating either a hard-disk or floppy-disk, it all depends on the bios, so your boot code needs to work in both cases
#4 some bioses actually check for a BPB (ive tested this) and without it will NOT boot the usb stick in floppy emulation mode.. so even if you never plan to use the BPB you need it there to ensure that the stick will boot under those conditions.


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Thu Apr 16, 2009 4:00 pm 
Offline

Joined: Wed Apr 08, 2009 2:21 pm
Posts: 11
I've tried out like ten bootloader codes (with a start of [BITS 16], but they all don't work. This one is a Hello world bootloader, when I use emulator (emu8086) it doesn't work out and it gives errors. Here's a pic of the error: http://img150.imageshack.us/img150/6334/errorvyc.png

I have no idea what's wrong. Can anyone please help me?


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Thu Apr 16, 2009 4:41 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
emu8086 is a very "different" assembler(and the emulation is very incomplete). Download yasm and then download qemu. Read a tutorial about writing your bootloader to a floppy disk, and then read a tutorial about using qemu with a floppy disk.

http://www.viralpatel.net/taj/tutorial/hello_world_bootloader.php that seems to cover most of it.. (yasm and nasm are for the most part interchangeable)

edit:
woops I gave you the same tutorial rofl..

Just make sure to use nasm as the assembler and to use just about anything but emu8086 for emulation. You can use either bochs or qemu. Or you can always use real hardware.. your choice.(I personally think qemu is the easiest to use)

_________________
My new NEW blag


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Sat Apr 18, 2009 3:34 pm 
Offline

Joined: Wed Apr 08, 2009 2:21 pm
Posts: 11
Hi all,

I have a few things to ask. I hope I'm not a pain in the ... . HP tools only works with the DOS programs, and it doesn't let me copy in my own Bin file. I tried to work with DD (on Mac) with a boot loader code in assembly, the thing is that it said that everything's okay - it enters all well, but when I use the usually PC (Microsoft) nothing really happens...

Can anyone please share with me a simple assembler language boot loader and how exactly I can write on USB? Because I tried http://www.chrysocome.net/dd and it obviously doesn't work for me.


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Sun Apr 19, 2009 10:18 am 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2006 12:00 am
Posts: 1444
You can try DexOS bootloader, it loads a mz exe anywhere from the root dir of a floppy, hdd, usb drive etc.
The name of the file must be "kernel32.exe".
Theres a xp program to put it on a usb fob, see here: http://www.dex4u.com/USBboot.htm
Just replace my kernel32.exe, with yours.


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Sun Apr 19, 2009 5:21 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
There are a bunch of disk tools listed on the OSDev wiki that you might want to look thorugh. First, I'd suggest you learn a little about assembly and the tools you're using since you were trying to assemble NASM code with emu8086.

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Fri Apr 24, 2009 5:39 am 
Offline

Joined: Wed Apr 08, 2009 2:21 pm
Posts: 11
Bios USB flash recognizes as removable device, it it does not boot in a way it's boots from the floppy. And in usb.org I can't find anything about booting from USB. As though I write floppy bootable image 7c00, but it does not boot, I tried it on three computers and nothing is happening. Why even DOS is booting from USB, but this doesn't boot. Does he really isn't placed on 7c00.

Can anyone please give me an example or even explain why from USB it isn't possible. I don't have a floppy device on my laptop.


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Fri Apr 24, 2009 6:55 am 
Offline
Member
Member

Joined: Thu Apr 12, 2007 8:15 am
Posts: 204
Location: Michigan
likeagunfire wrote:
Bios USB flash recognizes as removable device, it it does not boot in a way it's boots from the floppy.
Recognizing the flash drive is not necessarily enough. I was almost pulling my hair out trying to get a netbook (no cd/dvd/floppy) to boot a live dvd image off of my roommate's flash USB drive (I couldn't find any of mine). It turns out the flash drive was equipped with "U3" (I'm not exactly sure what U3 is--hardware or software or a combination--apparently the software that came with the flash drive has an option of removing U3 from it, I don't know if that would also make it bootable).

Writing the exact same dvd image to a flash drive unequipped with U3 worked as expected.

likeagunfire wrote:
Why even DOS is booting from USB, but this doesn't boot. Does he really isn't placed on 7c00.
I'm fairly certain that the first 512 bytes of the USB drive are loaded to 0x7C00 as any other MBR. However, one possible error is that the BIOS could potentially load your MBR to 0x07C0:0x0000, which is the same physical address, but with an unexpected code (and perhaps data) segment. This might be the case if the computer crashes or freezes when trying to boot from USB rather than displaying some standard error message from the BIOS (No Operating System, No Bootable Drive, etc).

When you say that DOS is booting from USB, does that mean you have successfully installed DOS onto the same USB drive and it works? That would indicate that your flash drive does not have the U3 problem, so I'm wondering if you are really writing your boot code to the first 512 bytes of the USB drive, or the first 512 bytes of the first partition of the USB drive (or somewhere else...).

There have been a few tools mentioned in this thread so far, which one have you settled on using? and would you mind explaining the steps you take to write your boot code to the flash drive?

_________________
Some people are offended by the verifiable truth; such people tend to remain blissfully unencumbered by fact.
If you are one of these people, my posts may cause considerable discomfort. Read at your own risk.


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Fri Apr 24, 2009 9:06 am 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2006 12:00 am
Posts: 1444
There is no magic to booting from usb drives, it very simple.
But you must understand one or two things or you will not get it to boot. that is unlike any other method of booting USB does check what its booting.
Eg: normaly the MBR or boot sector is just load into memory at a set address and jump to.
But in the case of USB boot, it checks for BPB, if it users hdd emulation it will boot with or without BPB, if it users floppy emulation and you do not have a BPB, it will NOT boot.
Here are two examples, the one with BPB should work with any emulation, if placed on the disk right (assemble with fasm)
With BPB
Code:
;************************************
; 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:
;************************************
; 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


Top
 Profile  
 
 Post subject: Re: Bootloader things.
PostPosted: Fri Apr 24, 2009 9:24 am 
Offline

Joined: Wed Apr 08, 2009 2:21 pm
Posts: 11
madeofstaples wrote:
When you say that DOS is booting from USB, does that mean you have successfully installed DOS onto the same USB drive and it works?


Yes, it is the same flash drive, from this same flash drive I made that Linux (slax) was booting and not only booting was done, but it also worked.
You were asking me to give you tools I've used that other people gave me in this thread, so I'm using DD tool for Windows, with manual from it
Code:
dd --list
dd if=/bootfile of=//./f:

My flash is F: drive and blinking, when i try writing that code.
But bootfile i'm testing on other PC where is FDD - it loading "Hello World" on boot.

This is the Hello world bootloader source code.
DD manual is taken from Intel http://software.intel.com/en-us/article ... r-windows/.

I've tried serveral other things but nothing works. If I'm working on a floppy (I test it nowhere near my workplace) it goes all right, but not from USB stick. Also, I've tried like three different USB sticks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot], Google [Bot] and 4 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