After mounting a bunch of filesystems I thought I’d just whip up a little shell script to help me out when working with jffs2 images, mtd, and linux (only tested on centos 6.) I won’t go over how to get kernel support and all that crap – there are many guides, and while many won’t work eventually something will for you too ;(
This one is fairly simple to use; assuming you have mounting jffs2 at all, it assumes the directory in /mnt exists (I just named mine “/mnt/jffs2”) and that the device in question to be mounted will be “/dev/mtdblock0” (both are vars at the top of the script.) It uses flash-erase to prep the /dev file (currently clears out 4megs there; as long as the image to be mounted is smaller, no problemo.) Not much error checking, but it works for me… in case someone else might have to deal with this stuff… should be modestly easy to change.
On Ubuntu you might do the following prior to running this script (the initial “#” is the root prompt):
Usage of below script simply “j-mount.sh jffs2-image”; it’ll complain if it can’t do it.
#
# try to mount a jffs2 fs from a file image... assumes
# kernel is ready to rumble
#
#
# Use: $0 jffs2-image-file
#
#
usage="Usage: $0 jffs2-image-file"
mtd="/dev/mtdblock0"
mnt="/mnt/jffs2"
image="$1"
#
# 1024*1024*4 = four megs
#
four=4194304
if [ "x$image" == "x" ] ; then
echo $usage
exit 1
fi
if [ ! -b $mtd ] ; then
echo "$mtd file doesn't exist or isn't a block device: $usage"
exit 2
fi
if [ ! -d $mnt ] ; then
echo "$mnt directory doesn't exist: $usage"
exit 2
fi
jmnt=$(df | grep $mnt)
if test $? == 0 ; then
echo Won\'t mount over another file system at $mnt:
echo
echo " $jmnt"
echo
exit 3
fi
# /dev/mtdblock0 4096 544 3552 14% /mnt/jffs2
# erase the past occupants....
echo erasing $mtd
flash_erase $mtd 0 0
echo copying $image to $mtd
dd if=$image of=$mtd bs=$four count=1
echo mounting $image on $mnt
mount -t jffs2 $mtd $mnt
if [ $? -eq 0 ] ; then
echo
echo win, it worked - $image has been mounted on $mnt
echo
echo df of newly mounted filesystem:
df $mnt
echo
echo ls -lasg of newly mounted filesystem:
echo
/bin/ls -lasg $mnt
echo
else
echo
echo no luck this time....
echo
fi
Sorry, the comment form is closed at this time.