Page 1 of 1

Why is floppy image (created by dd) not booting?

Posted: Wed Dec 16, 2015 11:04 pm
by mooseman
Hi all -

In the process of slowly developing my OS I've been poking around with the brokenthorn.com tutorials about OS development. In particular, I've been trying to convert the "BUILD.bat" batch files in the tutorial to Makefiles.

This is what I have so far -

Code: Select all

This is the code for the first batch file.  

nasm -f bin Boot1.asm -o Boot1.bin
PARTCOPY Boot1.bin 0 3 -f0 0 
PARTCOPY Boot1.bin 3E 1C2 -f0 3E 
pause
.... and I've converted it to this Makefile -

Code: Select all

#  Demo1 - Makefile -  Stage 1
#  Author -  mooseman  

all:
	nasm -f bin boot1.asm -o boot1.bin
	dd bs=512 count=2880 if=/dev/zero of=floppy.img
	mkfs.msdos floppy.img
	sudo mount -o loop floppy.img /media/floppy/
	cp boot1.bin floppy.img
	sudo umount /media/floppy/
The second batch file code is here -

Code: Select all

nasm -f bin Stage2.asm -o KRNLDR.SYS
copy KRNLDR.SYS  A:\KRNLDR.SYS
pause


.... which I've converted to this - the Stage 2 binary is copied onto the existing floppy image from Stage 1 -

Code: Select all


#  Demo1 - Makefile -  Stage 2
#  Author -  mooseman  

all:

	nasm -f bin stage2.asm -o krnldr.sys
	cp ~/plan_42/Demo1/Stage1/floppy.img .
	sudo mount -o loop floppy.img /media/floppy/
	cp krnldr.sys floppy.img
	sudo umount /media/floppy/


Ok. Now, the good news is that the makefiles *work* - they do exactly as expected. The bad news is that the floppy image resulting from stage 2 doesn't boot ( I use Qemu for testing ).

This is the Qemu command I use - $ is the prompt -
$ qemu-system-i386 -boot once=a -fda floppy.img

This is the Qemu error that I get -
Booting from Floppy....
This is not a bootable disk. Please insert a bootable floppy and press any key to try again....

I am *so close* to a bootable image with having the makefiles working now!
I am *sure* that the problem lies in Stage1 with the two PARTCOPY commands (PARTCOPY is apparently an obscure copying utility made by John Fine. )
http://www.brokenthorn.com/Resources/Pr ... RTCOPY.TXT

What I believe I need to be able to do is to reproduce these two commands from the first batch file *exactly*, using dd -
PARTCOPY Boot1.bin 0 3 -f0 0
PARTCOPY Boot1.bin 3E 1C2 -f0 3E

From the PARTCOPY manual shown above -
"USAGE:

PARTCOPY source source_offset length destination {destination_offset}

Only destination_offset is optional. The other parameters are always required. The offsets and length are always in HEX. "

So - does anyone know how to reproduce those two commands using dd (or something else)?

Many thanks in advance -
- mooseman

Re: Why is floppy image (created by dd) not booting?

Posted: Wed Dec 16, 2015 11:19 pm
by Brendan
Hi,
mooseman wrote:So - does anyone know how to reproduce those two commands using dd (or something else)?
Don't bother - just have a BPB that's "good enough" for 1400 KiB floppies built into your boot loader so that you don't need to do messy things to keep the floppy disk's original (probably dodgy/absent) BPB unmodified.

Of course you can also write your own "floppy disk image creator" utility that does whatever you like. If you're doing things right (e.g. not using broken/wasteful old FAT for floppies where it's unlikely there's going to be enough room left on the disk for normal files anyway) it's fairly trivial. For example, mine is about 500 lines of C (including whitespace, comments, etc) and supports multiple targets (2880 KiB floppy, 1440 KiB, ..., 160 KiB), checks (and sets) CRCs in my files, supports "redundant floppies" (2 copies of everything, one on each side of the disk, if there's enough disk space), and creates the final disk image as a sparse file.


Cheers,

Brendan

Re: Why is floppy image (created by dd) not booting?

Posted: Wed Dec 16, 2015 11:37 pm
by mooseman
Brendan wrote:Hi,
mooseman wrote:So - does anyone know how to reproduce those two commands using dd (or something else)?
Don't bother - just have a BPB that's "good enough" for 1400 KiB floppies built into your boot loader so that you don't need to do messy things to keep the floppy disk's original (probably dodgy/absent) BPB unmodified.

(snip)

Cheers,

Brendan
Hi Brendan -

Thanks for your reply!

I'll think all this over and will get back into the coding again tomorrow I think (when the ol' mind is a bit fresher..... :) )

Bye for now -
- mooseman

Re: Why is floppy image (created by dd) not booting?

Posted: Thu Dec 17, 2015 1:09 am
by alexfru

Re: Why is floppy image (created by dd) not booting?

Posted: Thu Dec 17, 2015 2:41 am
by iansjack
If I understand your code correctly, your boot sector is contained in boot1.bin. You then "cp" this to a FAT formatted image file, which places it in the disk's data area. But you need this code in the first sector so you need to "dd" it to the disk.

Re: Why is floppy image (created by dd) not booting?

Posted: Thu Dec 17, 2015 4:22 pm
by mooseman
iansjack wrote:If I understand your code correctly, your boot sector is contained in boot1.bin. You then "cp" this to a FAT formatted image file, which places it in the disk's data area. But you need this code in the first sector so you need to "dd" it to the disk.
Hi iansjack - thanks for that!

That sounds like exactly what I need! I'll try that out and see how it goes.

I've also found what looks like a very useful utility - Swiss File Knife - http://swissfileknife.sourceforge.net/

It has a utility also called "partcopy" (possibly inspired by John Fine's one) -
sfk partcopy - copy part from a file into another one

The good thing is that SFK is actively maintained.

Thanks again (and thanks also to all others who have answered my query).
- mooseman

Re: Why is floppy image (created by dd) not booting?

Posted: Thu Dec 17, 2015 6:06 pm
by neon
Hello,

It should be noted that we only host a copy of his software on our site. The original version is found here.

We used the software to install the boot code while maintaining the integrity of the BPB. This is the only valid method to install the boot code. However, you certainly do not need to use PartCopy. As noted earlier, due to the well defined structure of the 1.44MB floppy disk format, you should be able to define the BPB inside of your code and just write over the boot sector in a single pass. However, it is important to have a method to properly install the boot code on other devices that may have different properties (e.g. different sector sizes, different file systems, etc.; such as hard disks.)

stage1.bin is the volume boot record (VBR). It must be installed in the volume boot sector (either using an existing utility, hex editor, or writing your own - which is trivial.) Afterwords, you can mount the image and copy over all other files using cp.

If interested, we also provide support for those that prefer to boot from a hard disk or CD. We provide copies of our boot records to the public that you can use and can provide assistance for supporting it. Please note, however, that if you decide to go this route, you will need a proper utility to merge your boot code into the boot sector.

Re: Why is floppy image (created by dd) not booting?

Posted: Thu Dec 17, 2015 9:53 pm
by mooseman
Hi neon -

Thanks for your reply, that's really good and helpful!

I'm having a *lot* of fun poking around with this stuff anyway.
The amount of stuff that you learn is *amazing* - for example, I only found out a few days ago that you can use ordinary ol' os commands (like cp, dd etc) in a makefile.... :)

Thanks again - bye for now -
- mooseman