gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Making FSCR images on OSX?

#152575 - SiW - Mon Mar 17, 2008 10:00 pm

I'm having the hardest time figuring out how to build FSCR disk image in OSX. I've tried modifying davr's build.sh script, substituting newfs_msdos for the mkfs.vfat command, but OSX's mount doesn't accept the -o loop parameter. I think I can use hdiutil to create images but I don't know how to create a FAT12 image that way.

Any ideas?

#152579 - SiW - Mon Mar 17, 2008 11:17 pm

FWIW, the closest I got was this:

hdiutil create -srcfolder "source files directory" -fs MS-DOS -fsargs "-F 12" -ov output image


but it creates a .dmg image which then fails to work when I link it with my .nds file. Shame, because otherwise this would be a nice single-line command to do it all!

Until I can figure an alternative I guess I'll just run the Windows files in a virtual machine :|

(Edited for formatting)

#152594 - sonny_jim - Tue Mar 18, 2008 1:29 am

Have you tried GPF's one?
http://gpf.dcemu.co.uk/files/pc/fcsrimage.zip

It has the source for the tools used included so you should be able to recompile them for OSX.

#152612 - SiW - Tue Mar 18, 2008 5:23 am

Unfortunately the source for bfi.exe isn't available, that's the piece of GPF's chain (which is great and I use it under Windows) that is needed to copy the files to the disk image.

#152716 - josath - Thu Mar 20, 2008 12:28 am

Maybe the linux script can be modified to work on OS X? GPF's zip includes a build.sh written by me, linux is great in that you don't need any external apps to build a FAT image.

#152723 - SiW - Thu Mar 20, 2008 2:11 am

Well like my OP says, I did try working from your build.sh script first before checking out GPF's Windows collection of tools.

I feel like the OSX solution is close, but tantalizingly out of reach.. hopefully somebody can come up with the missing link.

#152987 - Jevin - Sun Mar 23, 2008 9:10 pm

Uhh... I did this about a year ago though I'm fuzzy on the details. I know I got a working image created from http://search.cpan.org/~hio/IO-DiskImage-Floppy-0.01/bin/fdimage.pl but I remember there being some limitation. I think the limitation was that it would only make a 1.44MB image, not up to 32MB like FAT12 can do. I remember trying to use hdiutil without much luck. I'll take a look at my IRC logs and Makefiles when I get back to my other machine to see how far I got.

#152989 - SiW - Sun Mar 23, 2008 9:35 pm

Well the "directories are not implemented yet" limitation makes it useless for my needs, but thanks for this, it will come in handy. If my Perl was any good I'd try and implement directories myself, but I run away screaming from any Perl project longer than 10 lines ;)

#153634 - TypeError - Thu Apr 03, 2008 7:56 am

SiW wrote:
FWIW, the closest I got was this:

hdiutil create -srcfolder "source files directory" -fs MS-DOS -fsargs "-F 12" -ov output image

but it creates a .dmg image which then fails to work when I link it with my .nds file. Shame, because otherwise this would be a nice single-line command to do it all!


As I understood the linux script you need to reserve an extra 64k in the disk image, so that's one problem. I wrote a (Leopard only, barely) script that *might* work, but I haven't actually *seen* it work yet. :-) My approach is to mount the disk image and then just copy the raw data from the /dev/diskXs1 device file, which I think should be the stuff we want.

Code:

#!/bin/zsh -e
# build.sh output.img sourcedatadir
#
# Builds a FAT disk image from a given directory.

if [ $# -lt 2 ]; then
    echo "Usage: $0 file.img src-dir"
    echo "  Create a FAT disk image from a directory."
    exit 1
fi

# calculate size of image needed
#SIZE=`du "$2"|cut -f1|tail -n1`
SIZE=`du -k $2 | cut -f1 | tail -n1`

# add 64KB for an overlay
SIZE=`expr $SIZE + 64`

# create empty file
echo Creating image with size $SIZE

# On mac we have to build a dmg and then pull out the FS...
hdiutil create -ov -size ${SIZE}k -srcfolder $2 -fs MS-DOS -fsargs '-F 12' $1.dmg
hdiutil attach -plist -nomount $1.dmg > $1.plist
dvice=`/usr/libexec/PlistBuddy -c 'Print :system-entities:0:dev-entry' $1.plist`
# The entries in the system-entities array seem to be randomly ordered, so
# sometimes we get the disk entry (/dev/diskX) and sometimes we get the
# partition entry (/dev/diskXs1).  We want the partition entry.
case $dvice in
    *s1) ;;
    *)  dvice=${dvice}s1 ;;
esac
echo Attached as partition: $dvice
dd if=$dvice of=$1
hdiutil detach $dvice
rm -f $1.dmg
rm -f $1.plist

echo "$SIZE KB FAT image built as $1 from $2\n"
file "$1"


It prints a mount error message that is safe to ignore. Assuming this works you'll still need to "bless" the image with the fcsr patcher. Let me know if it works for you!