Page 1 of 1

I need help with bootloader

Posted: Thu Jan 12, 2017 2:11 pm
by TheDev100
Hey guys. I've put a BIOS parameter block in my bootloader. I assemble it using NASM.

Then, I do file boatload.bin

DOS/MBR boot sector (with BPB values separated by commas).

How would I fix it so it goes to a 1.44MB floppy? What would be wrong with my BPB table?

Thanks
John

Re: Bootloader won't show as floppy image

Posted: Thu Jan 12, 2017 2:53 pm
by Octocontrabass
Why is that a problem? The file command is not designed to validate your BPB.

Re: Bootloader won't show as floppy image

Posted: Thu Jan 12, 2017 3:18 pm
by TheDev100
My BPB won't work. What might be wrong with it? When I use dd, the floppy image is 512 bytes.

Re: Bootloader won't show as floppy image

Posted: Thu Jan 12, 2017 3:29 pm
by dozniak
You created a 512 byte boot sector with BPB. You now need to create a floppy image perhaps with some FS on it.

I suspect his article on the wiki should clear it up - http://wiki.osdev.org/Loopback_Device

Re: Bootloader won't show as floppy image

Posted: Thu Jan 12, 2017 4:42 pm
by mikegonta
dozniak wrote:You created a 512 byte boot sector with BPB. You now need to create a floppy image perhaps with some FS on it.
The FAT12 boot sector is typically followed by 2 (the second is a copy of the first) File Allocation Tables which is followed by the
root directory.

Code: Select all

  jmp start
  nop
  db "        " ; OEM string
  dw 512 ; bytes per sector
  db 1 ; sectors per cluster
  dw 1 ; reserved sector count
  db 2 ; number of FATs
  dw 14 * 16 ; root directory entries
  dw 18 * 2 * 80 ; sector count
  db 0xF0 ; media byte
  dw 9 ; sectors per fat
sectors_per_track:
  dw 18
number_of_heads:
  dw 2
  dd 0 ; hidden sector count
  dd 0 ; number of sectors huge
drive_number:
  db 0
  db 0 ; reserved
  db 0x29 ; signature
  dd 0x78563412 ; volume ID
  db "           " ; volume label
  db "FAT12   " ; file system type

start:

  times 510 - ($ - $$) db 0
  dw 0xAA55

fat1: ; empty FAT12 file system
  db 0xF0, 0xFF, 0xFF
  times (512 * 9) - ($ - fat1) db 0

fat2:
  db 0xF0, 0xFF, 0xFF
  times (512 * 9) - ($ - fat2) db 0

root_directory:
  times 512 * 14 db 0

  times (512 * 18 * 2 * 80) - ($ - $$) db 0xF6

Re: Bootloader won't show as floppy image

Posted: Fri Jan 13, 2017 6:28 am
by TheDev100
I'm talking about NASM right now.
Also, I've tried the dd command but it only shows 512 bytes instead of 1.44MB.

I've got a BPB. What should I do?

How do I make a floppy image with my bootloader and possibly other files?

Re: Bootloader won't show as floppy image

Posted: Fri Jan 13, 2017 7:12 am
by TheDev100
BPB won't work. Maybe I should try fat_imgen.

Re: Bootloader won't show as floppy image

Posted: Fri Jan 13, 2017 9:43 am
by matt11235
TheDev100 wrote:Also, I've tried the dd command but it only shows 512 bytes instead of 1.44MB.
Where do you expect dd to pull the extra bytes from? It can't read your mind.

Code: Select all

# create a 1.44MB file filled with zeroes
$ dd if=/dev/zero of=floppy.img count=1440 bs=1k

# copy your mbr onto the floppy
# we use conv=notrunc to make sure that the rest of the bytes in the file arent thrown away
$ dd if=your-mbr.bin of=floppy.img bs=512 count=1 conv=notrunc
Of course it should go without saying that you need to be careful when using dd to make sure you aren't overwriting your disks.

Re: I need help with bootloader

Posted: Fri Jan 13, 2017 11:59 am
by TheDev100
You mean that's what I had to do? Well, guess what. I did that many times and it failed. It was still 512 bytes.

Re: I need help with bootloader

Posted: Fri Jan 13, 2017 12:28 pm
by Schol-R-LEA
Wait, did you check the size of the file after you created it,

Code: Select all

dd if=/dev/zero of=floppy.img count=1440 bs=1k
(It should have been a 1.44M file filled with zeroes at this point)

but before you inserted to boot image?

Code: Select all

dd if=your-mbr.bin of=floppy.img bs=512 count=1 conv=notrunc
If it was 1.44M before insertion, but was reduced to 512 bytes afterwards, check to make sure that you remembered the conv=notrunc argument in the second shell command. I would actually add nocreat and fdatasync as well, to give you a sanity check on the file name (it would give an error message if the file doesn't already exist) and force it to write immediately rather than (potentially) cache the output. If that doesn't do it, I would further use the nocache flags for both the input and output files - while the chances that it would be a caching issue are negligible when working on a local fixed medium, IMAO it would be worth going belt-and-suspenders in this case just to see if it makes a difference.

Code: Select all

dd if=your-mbr.bin  iflag=nocache of=floppy.img oflag=nocache bs=512 count=1 conv=notrunc,nocreat,fdatasync
Beyond that, if you could paste the exact shell commands and/or shell scripts you are using, we might be able to double check them for you. It is all too easy for even an experience shell user to make less than obvious mistake, and getting more eyes on it might help.

Re: I need help with bootloader

Posted: Fri Jan 13, 2017 12:29 pm
by matt11235
TheDev100 wrote:You mean that's what I had to do? Well, guess what. I did that many times and it failed. It was still 512 bytes.
Are you sure you didn't forget conv=notrunc?

Code: Select all

matt@minidigger:~$ dd if=/dev/zero of=test.img count=1440 bs=1k
1440+0 records in
1440+0 records out
1474560 bytes (1.5 MB, 1.4 MiB) copied, 0.00276008 s, 534 MB/s
matt@minidigger:~$ ll test.img
-rw-r--r-- 1 matt matt 1474560 Jan 13 18:27 test.img
matt@minidigger:~$ dd if=/dev/zero of=test.img count=1 bs=512 conv=notrunc
1+0 records in
1+0 records out
512 bytes copied, 8.6221e-05 s, 5.9 MB/s
matt@minidigger:~$ ll test.img
-rw-r--r-- 1 matt matt 1474560 Jan 13 18:27 test.img
matt@minidigger:~$ dd if=/dev/zero of=test.img count=1 bs=512
1+0 records in
1+0 records out
512 bytes copied, 0.000143675 s, 3.6 MB/s
matt@minidigger:~$ ll test.img 
-rw-r--r-- 1 matt matt 512 Jan 13 18:27 test.img
You can see that without conv=notrunc my file is (unsurprisingly) truncated to 512 bytes.

Re: I need help with bootloader

Posted: Sat Jan 14, 2017 5:07 am
by TheDev100
Thank you so much! IT WORKED. The option worked. Thank you :) I must give you some free jokes:

- Why is everyone's code void these days? Never mind, its void main()!
- Mov aha aha! That's the way aha aha I like it aha aha. Mov aha aha, 0eh.
- Loading kernel... Loading trouble... Loading things that aren't required...

THANK YOU!