#!/bin/sh # Copyright (C) 2006 OpenWrt.org # Copyright (C) 2010 Vertical Communications do_check_ext4(){ # $1 device block info $1 | grep "TYPE=\"ext4\"" if [ $? -ne 0 ]; then echo "formating " $1 "to ext4..." mkfs.ext4 $1 else echo $1 "already format by ext4" fi } do_check_jffs2(){ #1 device block info $1 | grep "TYPE=\"jffs2\"" if [ $? -ne 0 ]; then echo "formating " $1 "to jffs2..." mkdir -p /tmp/jffs2.dir/tmp #mkfs.jffs2 need to point out a directory to copy to image file or local directory(./) defaultly mkfs.jffs2 -p -e 0x$(cat /proc/mtd | grep $(basename $1) | awk '{print $3}') -d /tmp/jffs2.dir -o /tmp/jffs2.img dd if=/tmp/jffs2.img of=$1 rm -rf /tmp/jffs2.img /tmp/jffs2.dir else echo $1 "already format by jffs2" fi } do_check_format(){ # $1 device [ -h $1 ] && { lnk=`basename $(readlink $1)` #emmc [ ${lnk:0:6} = "mmcblk" ] && { do_check_ext4 $1 return } #nand [ ${lnk:0:4} = "nand" ] && { do_check_ext4 $1 return } #nor [ ${lnk:0:8} = "mtdblock" ] && { do_check_jffs2 $1 return } } } do_format_filesystem() { [ -d /dev/by-name -o -h /dev/by-name/rootfs ] || { mkdir -p -m 755 /dev/by-name for line in `cat /proc/cmdline` do if [ ${line%%=*} = 'partitions' ] ; then parts=${line##*=} part=" " while [ "$part" != "$parts" ] do part=${parts%%:*} ln -s "/dev/${part#*@}" "/dev/by-name/${part%@*}" parts=${parts#*:} done fi done } do_check_format /dev/by-name/UDISK do_check_format /dev/by-name/rootfs_data } [ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_format_filesystem