已经测试过在Fedora10上运行顺利,需要root权限才可以执行
- #! /bin/bash
- # written by cpuwolf@gmail.com 2010
- mountpt=/media/disk
- devicename=sdb
- sdcard=/dev/$devicename
-
- if test $# -le 0 ; then
- echo "Error: needs IROM image path"
- exit 1
- fi
- infile="$1"
- if [ -e $infile ] ; then
- echo "IROM image: $infile"
- else
- echo "IROM image: $infile does not existing"
- exit 1
- fi
- imagelen=`wc -c < $infile`
- echo "IROM image Size: $imagelen bytes"
-
- if [ -e /sys/block/$devicename/removable ] ; then
- removable=$(cat /sys/block/$devicename/removable)
- else
- echo "SD card: /dev/$devicename is not existing"
- exit 1;
- fi
- if [ ! $removable == "1" ]; then
- echo "/dev/$devicename is not removable"
- exit 1;
- fi
- if [ -e /sys/block/$devicename/queue/hw_sector_size ] ; then
- sectorsize=$(cat /sys/block/$devicename/queue/hw_sector_size)
- echo "SD card sector size: $sectorsize bytes"
- if ! test $sectorsize -eq 512 ; then
- echo "Warning: sector size is not 512"
- fi
- fi
- if [ -e /sys/block/$devicename/size ] ; then
- numsectors=$(cat /sys/block/$devicename/size)
- echo "SD card total size: $numsectors sectors"
- fi
- disksize=`expr $numsectors \* $sectorsize`
- echo "SD card total size: $disksize bytes"
- reservedsize=`expr $sectorsize \* 2`
- endsize=`expr $reservedsize + $imagelen`
- diskoffset=`expr $disksize - $endsize`
- echo "IROM image is writen to offset: $diskoffset (bytes)"
- diskoffsetsector=`expr $diskoffset / $sectorsize`
- echo "IROM image is writen to offset: $diskoffsetsector (sectors)"
- issectoralign=`expr $diskoffset % $sectorsize`
- if ! test $issectoralign -eq 0 ; then
- echo "Warning: IROM image size is not align on sectors"
- fi
- echo "start flushing IROM image..."
- dd if=$infile of=/dev/$devicename bs=$sectorsize seek=$diskoffsetsector > /dev/null 2>&1 && echo "flush successful" || echo "Error: flush"
阅读(1781) | 评论(0) | 转发(0) |