Unpack & Repack mtd image
an mtd2 jffs2 image can be unpacked and repacked with a few commands
use the provided scripts as a sample, adjust at your needs
remember that both scripts are provided as-is, with no warranty at all
in order to run the scripts you need a linux box and a few modules related to jffs2 filesystem and block devices. Check your system and kernel configuration for buil-tin or modules support related to the needed modules/commands/filesystems.
consider this as a base (alfa-beta----whatever!), all of this refers to mtd2 (jffs2) image updates
unpack-img.sh
Kod:
#!/bin/sh
if [ $# -ne 2 ]; then
echo "use: unpack-img.sh <image> <folder>"
exit
fi
echo "unpacking image: "$1
gotit=$(file $1|grep -c jffs2)
if [ $gotit -ne 1 ]; then
echo "not a valid jffs2 image file"
exit
fi
echo "==================================="
echo "cleanup target folder"
rm -rf $2
echo "create target folder"
mkdir $2
echo "==================================="
echo "cleanup temp folder"
umount tmp.jffs2 &>/dev/null
sleep 1
rm -rf tmp.jffs2
echo "create temp folder"
mkdir tmp.jffs2
export loop=$(losetup -f)
echo "==================================="
echo "setting up loop device: "$loop
losetup $loop $1
echo "==================================="
echo "loading modules"
modprobe jffs2
modprobe mtdblock
echo "==================================="
echo "setting up block device"
modprobe block2mtd block2mtd=$loop,131072
sleep 5
echo "==================================="
echo "mounting jffs2 image on: "$2
mount -t jffs2 -o ro /dev/mtdblock0 tmp.jffs2
echo "==================================="
echo "copying data to target folder"
cp -a tmp.jffs2/* $2
echo "copying hidden files (.) to target folder"
cp --recursive tmp.jffs2/.[a-zA-Z0-9]* $2
sleep 1
echo "==================================="
umount tmp.jffs2
rmmod block2mtd
losetup -d $loop
echo "done!"
echo "<"$1"> copied to <"$2">"
Kod:
#!/bin/sh
if [ $# -ne 2 ]; then
echo "usage: build-img.sh <folder> <image>"
exit
fi
echo "building image from folder: "$1
gotit=$(file $1|grep -c directory)
if [ $gotit -ne 1 ]; then
echo $1" -> not a folder"
exit
fi
echo "==================================="
echo "cleanup target image"
rm -rf $2
echo "==================================="
echo "build jffs2 image file"
mkfs.jffs2 --root=$1 --output=$2 --eraseblock=131072 -l -p
echo "done!"
echo "<"$2"> image built from <"$1">"
Paylaş