Bochs and HD Use

Joel Sherrill <joel@OARcorp.com> joel.sherrill at OARcorp.com
Wed Oct 13 21:07:15 UTC 2004


Thank you very much.  I still do not have it completely there
yet though.  What does your mtsetup script do?
Would you mind sharing it with us all?

I hope it wasn't a problem that I adapted your instructions for the
hard disk as the guts of a Wiki entry.

--joel

Richardson, Anthony wrote:
> Joel Sherrill <joel at OARcorp dot com> wrote:
> 
>>Well I have gotten this far and would like ot play with the
>>file IO support on RTEMS with Bochs.  I assume that I need
>>to create a disk image file and then do something to the
>>Bochs configuration file based upon this command:
>>
>>http://bochs.sourceforge.net/doc/docbook/user/bochsrc.html#AEN1252
>>
>>What configuration parameters match a PC with 1 HD?
>>
>>I assume that I can format a 5 MB file under Linux as FAT32
>>and just use that.
> 
> 
> Here are some instructions for I wrote for creating disk images for
> Bochs under Windows using cygwin and mtools.  They should apply
> to Linux too.  The instructions describe how to make a disk image
> of arbitrary size.  For the 10 MB example given, the corresponding
> bochs lines are:
> 
> ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
> ata0-master: type=disk, path="harddisk.img", cylinders=20, heads=16, spt=63, tra
> nslation=auto, biosdetect=auto, model="Generic 1234"
> 
> I hope this helps.
> 
> Tony Richardson
> 
> ===========================================================
> EE458
> Real Time Programming
> 
> Lecture 2 - In Class Exercise
> Working with cygwin, mtools and disk images
> 
> In this exercise you will learn how to create FAT filesystems on both floppy disk images and hard disk images.  The cygwin tools provide a UNIX like environment for windows.  eCos requires that the cygwin tools be installed.  mtools are a set of tools for working with FAT partitions and disk images under UNIX.  They are also very useful for working with disk images under cygwin.
> 
> Floppy Disk Images
> 
> 1.Go to the fdos-10meg directory created in the previous exercise.  From a cygwin prompt use dd to create 1.44 MB floppy image containing just zeroes:
> 
> dd  if=/dev/zero  of=flop144.img  bs=1k  count=1440
> 
> The so called 1.44 MB floppy is actually 1440 x 1 KB or 1440 x 1024 B or 1,474,560 B or really 1.40625 MB (1,474,560/(1024 * 1024)).  It is important to know these things when working with disk images because we have to create one of exactly the right size.  You could also have used:
> 
> dd  if=/dev/zero  of=flop144.img  bs=1474560  count=1
> or
> dd  if=/dev/zero  of=flop144.img  bs=512  count=2880
> 
> 2.Now that we have an image of the right size we need to create a FAT filesystem on the image, i.e. format the floppy.  We could boot up FreeDOS under Bochs and format the floppy from FreeDOS, but it is more convenient to use the mtools utilities.  Use mtsetup to configure mtools to use your floppy image:
> 
> mtsetup  -f  flop144.img
> 
> Note: mtsetup is a utility script that I wrote to make it easier to work with disk images under mtools.  It automatically generates an .mtoolsrc configuration file under your home directory.  Take a look at the configuration file (cat ~/.mtoolsrc) before proceeding.  mtsetup has created an .mtoolsrc configuration file in which flop144.img is now your mtools A: drive.  Normally, you can just type  mtsetup  fileimage  and mtsetup will autodetect whether the image is a floppy image or a hard disk image, since the floppy isn't formatted though the autodetection fails.  The  -f  option tells mtsetup to assume the image is a floppy image.  Use -h to indicate that the image is a hard disk image.  The mtsetup script is included on the eCos course CD in the uestuff/mtools3.9.9 directory.
> 
> 3.You should now be able to format the floppy image:
> 
> mformat a:
> 
> 4.Now copy a text file to the image.  For example, to copy the bochsrc.txt to the image enter:
> 
> mcopy bochsrc.txt a:
> 5.Use mdir a: to get a directory listing, mtype a:file to display a file, mmd a:dir to create a directory.  Other commands are mcd, mrd, mmove, etc.  Refer to the mtools man page or the man page for the the specific mtools command.
> 
> 6.Now change the bochsrc.txt file so that the floppy image will be available under FreeDOS.  Boot FreeDOS/Bochs and verify that you can see a copy of the bochsrc.txt file on the FreeDOS A: drive.  Create other files and/or directories on the FreeDOS A: drive, exit FreeDOS and verify that you can access those files and directories using the mtools utilities.
> 
> Hard Disk Images
> 
> 1.Hard disks have a particular logical geometry that is specified in terms of cylinders/head/sectors or CHS.  Visualize a stack of CD-ROM disks all turning on a common spindle.  The number of CD-ROM disks would correspond to the number of heads in a hard disk drive.  Each CD-ROM has a certain number of tracks (or cylinders) and each track has a certain number of disk sectors.  On a hard disk a sector is 512 bytes.  We can figure out the total disk capacity (in bytes) from: C*H*S*512.  The maximum allow value for H is 255 and that for S is 63.  The maximum allowed value of C is 1024.  The largest allowable hard disk size is therefore 1024*255*63*512 or about 8.4 GB.  (Note: Newer PC BIOSes use a different geometry scheme know as LBA that allows for much larger drives, but for a long time PCs could get by using CHS addressing because no one could dream of drives ever exceeding the 8.4 GB size limit.  I'm not sure if Bochs and/or FreeDOS support LBA, but that doesn't really ma
tter to us.  We will normally work with 10 MB hard disk images, not GB disk images.) Assuming S=63 and H=16, we can figure out how many cylinder we need for a 10 MB drive: C = (10x1024x1024)/(63x16x512) = 20.317.  We need an integer value for C so a value of C = 20 will give us about a 10 MB hard disk image.  Create the image as follows (C*H*S = 20*16*63 = 20160):
> 
> dd  if=/dev/zero  of=harddisk.img  bs=512  count=20160
> 
> 2.Unfortunately, there is not an mtools utility for partitioning a hard disk image and writing a boot manager to the MBR.  We will need to use FreeDOS for that.  So change the bochsrc.txt file so that harddisk.img is now the AT0 slave drive.  (You still need the AT0 master drive because it contains the FreeDOS operating system.)  Boot FreeDOS, use fdisk to create a single primary partition on the new disk drive (make sure you are partitioning the new slave drive and not the original master drive).  fdisk writes a boot loader and partition table to the MBR of the drive.  You will probably need to reboot FreeDOS after running fdisk, do so, and then use format to format the new partition (it should be the D: partition.)  (All of this seems complicated, but I wish adding a new disk drive to a real PC were this easy.)  Now create files and/or directories on your new D: partition.
> 
> 3.Configure mtools to access the new partition.  Since the partition is already formatted, just mtsetup  harddisk.img  should do it.  Verify that you can copy files to/from the partition using the mtools utilities.  Note: The partition is configured as the mtools C: drive, while under FreeDOS it is the D: drive.
> 


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
    Support Available             (256) 722-9985




More information about the users mailing list