Invalid floppy image?!

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
indiocolifa
Member
Member
Posts: 41
Joined: Sat May 24, 2008 12:41 pm
Location: La Plata, Argentina

Invalid floppy image?!

Post by indiocolifa »

I'm totally confused, i'm using FASM to assemble my bootloader which is right under 512 bytes and I think defines a proper boot sector.

My makefile to generate the floppy image is:

Code: Select all

# boot loader makefile
#
# - assembles boot.asm
# - creates bootable floppy image

ASSEMBLER=fasm
BOOTLDR=boot
LOADER=pmdosldr
LOADEROUT=PMDOSLDR.SYS
FLOPPYIMAGE=floppy.img

all:
	if test -e $(FLOPPYIMAGE); then rm $(FLOPPYIMAGE); fi
	
	$(ASSEMBLER) $(BOOTLDR).s
	$(ASSEMBLER) $(LOADER).s $(LOADEROUT)
	dd status=noxfer conv=notrunc if=boot.bin of=$(FLOPPYIMAGE) bs=512 count=2880
PMDOSLDR.SYS is the file I will load the setup the proper kernel environment.

I tried to copy the file to the image using:

Code: Select all

sudo mount /mnt/flp floppy.img -t vfat -o loop 
That's OK, altough doing

Code: Select all

cp PMDOSLDR.SYS /mnt/flp
gives me 'NO SPACE LEFT ON DEVICE' like the image is not formatted properly.

Do I need to make a proper FAT12 floppy first with mkisofs?

This is my bootloader code:

Code: Select all

	;; ITCHIES/OS
	;;
	;; Sector 1 boot loader
	;;
	;; Loads PMDOSLDR from FAT12
	;; ====================================================================

	format binary
	use16

	org	0x7c00
	jmp 	short start	; jump to boot code
	nop
		
	;; -- BIOS PARAMETER BLOCK (BPB) --------------------------------------
	BS_OEMName	db	'MSWIN4.1'
	BPB_BytesPerSec	dw	512
	BPB_SecPerClus	db	1
	BPB_RsvdSecCnt	dw	1
	BPB_NumFATs	db	2
	BPB_RootEntCnt	dw	224
	BPB_TotSec16  	dw	2880
	BPB_Media       db	0xf0 ;1.4M floppy
	BPB_FATSz16	dw	9
	BPB_SecPerTrk	dw	18
	BPB_NumHeads	dw	2
	BPB_HiddSec   	dd	0
	BPB_TotSec32	dd	0
	BS_DrvNum   	dw 	0
	BS_BootSig   	db	0x29
	BS_VolID     	dd	0xDEAD0001
	BS_VolLab	db	'ITCHIESBOOT'
	BS_FilSysType	db	'FAT12   '
	
	LDADDR_OFFSET	equ	0x0000 ;will load from 1000:0000
	LDADDR_SEGMENT	equ	0x1000

	;; -- boot code -------------------------------------------------------
	
start:
	cli
	xor	ax, ax
	mov	ss, ax
	mov	sp, 0xf000
	mov	ds, ax
	mov	es, ax
	mov	fs, ax
	mov	gs, ax
	sti
	
 	mov	ax, 3	
 	int	0x10		; clear screen
	lea	si, byte[BOOTMSG]
	call	dispstr
	lea	si, byte[LOADMSG]
	call	dispstr
	call	resetfloppy
	call	readsector
	jmp	LDADDR_SEGMENT:LDADDR_OFFSET
	
include 'fdio.s'
include 'print.s'
include 'fatfs.s'
	
	;; -- message strings and constants -----------------------------------

	FAT_ENTRY_SIZE	dw	32
	BOOTMSG		db	'**** PM/DOS BOOT V0.1 ****',13,10,13,10,0
	LOADMSG		db	13,10,'Loading boot...',13,10,0
	LOADERFILE	db	'PMDOSLDRSYS'

	;; -- boot signature --------------------------------------------------

	db	510-($-$$) dup 0
	dw 	0xaa55

Help Please!!! I think it's everything right but I can't visualize where it's the floppy image problem!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

mkisofs is not for FAT filesystems.

Instead, find the vfat formatter and use that (iirc, its mkfs.vfat), Or use mtools which saves you from logging in as root.

Either way, your bootloader goes into the bootsector, and copying it to floppy is not exactly putting it there. So you either need to manually put it into place via dd, or you have to tell the formatter to use your bootsector when formatting. Since you have a FAT bootloader, I recommend the latter.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Hi,

Firstly, do you even have a file called "boot.bin"? Looking at your Makefile you don't specify the output location of your bootsector when assembled:

Code: Select all

$(ASSEMBLER) $(BOOTLDR).s
should surely be

Code: Select all

$(ASSEMBLER) $(BOOTLDR).s $(BOOTLDR)
but anyway, assuming that you have a boot.bin file, the dd command you use should work;

Code: Select all

dd status=noxfer conv=notrunc if=boot.bin of=$(FLOPPYIMAGE) bs=512 count=2880 
One thing missing in your question is ... the problem! What exactly is wrong? You've explained what you do, what your code is, but not what your code does incorrectly!

You'll never be able to mount a floppy image as a FAT block device that isn't formatted as FAT (that's a no-brainer), so your mount issues are moot. The bootloader should be installed properly by the 'dd' command.

What exactly is the problem?

Cheers,

James
indiocolifa
Member
Member
Posts: 41
Joined: Sat May 24, 2008 12:41 pm
Location: La Plata, Argentina

Post by indiocolifa »

Hi James, thanks for your attention.

Yes, FASM in the Makefile properly outputs a boot.bin file.

The problem is that I can't mount the image (i'm not at my dev machine actually). Of course that I find it natural since there is only the BPB on the first sector but no FAT or root dir entries, so no utility can find an entry point to the filesystem to copy files. But many kernel tutorials show the following steps:

a) Proper boot.asm source (with BPB)
b) Assemble into flat binary
c) Put into an empty floppy image with dd
d) Mount as msdos or VFAT

This creates a 512-byte image with a, e.g, FAT12 boot sector. But where is the FAT space to allocate the files? Should a cp to the mount properly allocate space? There is NO need for mkfs?

Thanks for your help.
indiocolifa
Member
Member
Posts: 41
Joined: Sat May 24, 2008 12:41 pm
Location: La Plata, Argentina

Invalid floppy image?! [SOLVED]

Post by indiocolifa »

I finally found how to properly initialize it:

z: drive for MTOOLS refers to floppy.img.

Code: Select all

dd if=/dev/zero of=floppy.img bs=512 count=2880
mformat -B boot.bin -f 1440 -L 'BOOTDISK'  z:
Mformat overwrites my BPB... so I will try removing it from bootloader.

:wink:
Post Reply