九鼎创展论坛
标题:
PC端自动烧写脚本,s5pv210-burn-android.sh
[打印本页]
作者:
jjj
时间:
2013-2-27 11:58
标题:
PC端自动烧写脚本,s5pv210-burn-android.sh
此脚本在ubuntu系统中可以直接烧写镜像update.bin至外部SD卡中,基于xboot的镜像升级系统
脚本如下:
#!/bin/sh
# burn script
INAND_DEVICE=/dev/sdb
BURN_DIR=/tmp/burn
UPDATE_DIR=$BURN_DIR/update
SYSTEM_DIR=$BURN_DIR/system
DATA_DIR=$BURN_DIR/data
CACHE_DIR=$BURN_DIR/cache
do_setup_environment()
{
mkdir -p $BURN_DIR || { return 1; }
mkdir -p $UPDATE_DIR || { return 1; }
mkdir -p $SYSTEM_DIR || { return 1; }
mkdir -p $DATA_DIR || { return 1; }
mkdir -p $CACHE_DIR || { return 1; }
umount ${INAND_DEVICE}1;
umount ${INAND_DEVICE}2;
umount ${INAND_DEVICE}3;
umount ${INAND_DEVICE}4;
umount ${UPDATE_DIR};
sync; sync; sync;
return 0;
}
do_fdisk_del_partition()
{
[ -z "$1" ] && { return 1; }
[ -b $1 ] || { return 1; }
fdisk $1 << EOF
d
1
d
2
d
3
d
4
w
EOF
sync;
sync;
sync;
return 0;
}
do_fdisk_new_partition()
{
[ -z "$1" ] && { return 1; }
[ -b $1 ] || { return 1; }
fdisk $1 << EOF
n
p
1
+256M
+256M
n
p
2
+544M
+256M
n
p
3
+832M
+256M
n
p
+1120M
w
EOF
sync;
sync;
sync;
return 0;
}
do_mkfs_vfat()
{
[ -z "$1" ] && { return 1; }
mkfs.vfat $1 || { return 1; }
return 0;
}
do_mkfs_ext4()
{
[ -z "$1" ] && { return 1; }
mkfs.ext4 -q $1 || { return 1; }
return 0;
}
do_mount_updatebin()
{
[ -z "$1" -o -z "$2" ] && { return 1; }
[ -f $1 ] || { return 1; }
[ -d $2 ] || { return 1; }
mount -t romfs -o loop $1 $2 || { return 1; }
return 0;
}
do_umount_updatebin()
{
[ -d $1 ] || { return 1; }
umount $1 || { return 1; }
return 0;
}
do_check_updatebin()
{
[ -d $1 ] || { return 1; }
cd $1 || { return 1; }
md5sum -c md5sum.txt || { return 1; }
return 0;
}
do_mount_system()
{
[ -z "$1" -o -z "$2" ] && { return 1; }
[ -b $1 ] || { return 1; }
[ -d $2 ] || { return 1; }
mount -t ext4 $1 $2 || { return 1; }
return 0;
}
do_umount_system()
{
[ -d $1 ] || { return 1; }
umount $1 || { return 1; }
return 0;
}
do_mount_data()
{
[ -z "$1" -o -z "$2" ] && { return 1; }
[ -b $1 ] || { return 1; }
[ -d $2 ] || { return 1; }
mount -t ext4 $1 $2 || { return 1; }
return 0;
}
do_umount_data()
{
[ -d $1 ] || { return 1; }
umount $1 || { return 1; }
return 0;
}
do_mount_cache()
{
[ -z "$1" -o -z "$2" ] && { return 1; }
[ -b $1 ] || { return 1; }
[ -d $2 ] || { return 1; }
mount -t ext4 $1 $2 || { return 1; }
return 0;
}
do_umount_cache()
{
[ -d $1 ] || { return 1; }
umount $1 || { return 1; }
return 0;
}
do_burn_system()
{
[ -z "$1" -o -z "$2" ] && { return 1; }
[ -f $1 ] || { return 1; }
[ -d $2 ] || { return 1; }
rm -fr $2/* || { return 1; }
tar xvf $1 -C $2 || { return 1; }
return 0;
}
do_burn_data()
{
[ -z "$1" -o -z "$2" ] && { return 1; }
[ -f $1 ] || { return 1; }
[ -d $2 ] || { return 1; }
rm -fr $2/* || { return 1; }
tar xvf $1 -C $2 || { return 1; }
return 0;
}
do_burn_xboot()
{
[ -z "$1" -o -z "$2" ] && { return 1; }
[ -f $1 ] || { return 1; }
[ -b $2 ] || { return 1; }
dd if=$1 of=$2 bs=512 seek=1 conv=sync || { return 1; }
return 0;
}
do_burn_kernel_android()
{
[ -z "$1" -o -z "$2" ] && { return 1; }
[ -f $1 ] || { return 1; }
[ -b $2 ] || { return 1; }
dd if=$1 of=$2 bs=512 seek=40960 conv=sync || { return 1; }
return 0;
}
do_burn_kernel_initrd()
{
[ -z "$1" -o -z "$2" ] && { return 1; }
[ -f $1 ] || { return 1; }
[ -b $2 ] || { return 1; }
dd if=$1 of=$2 bs=512 seek=81920 conv=sync || { return 1; }
return 0;
}
do_error()
{
if [ ! -z "$1" ]; then
echo $1;
fi
sync;
exit 0;
}
burnxboot=no;
burnkernel=no;
burnsystem=no;
burncache=no;
burndata=no;
if [ -z $1 ]; then
burnxboot=yes;
burnkernel=yes;
burnsystem=yes;
burncache=yes;
burndata=yes;
fi
while [ "$1" ]; do
case "$1" in
-b|--bootloader)
burnxboot=yes;
;;
-k|--kernel)
burnkernel=yes;
;;
-s|--system)
burnsystem=yes;
;;
-d|--data)
burndata=yes;
;;
-c|--cache)
burncache=yes;
;;
-a|--all)
burnxboot=yes;
burnkernel=yes;
burnsystem=yes;
burncache=yes;
burndata=yes;
;;
-h|--help)
cat >&2 <<EOF
Usage: burn [OPTION]
burn script for burn system image.
-b, --bootloader burn bootloader
-k, --kernel burn kernel
-s, --system burn system
-d, --data burn data
-c, --cache burn cache
-a, --all burn all, include anything
-h, --help display this help and exit
EOF
exit 0
;;
*)
echo "burn: Unrecognised option $1" >&2
exit 1
;;
esac
shift
done
echo "setup environment ..."
do_setup_environment || { do_error "fail to setup environment"; }
echo "mount update.bin ..."
[ -f ./update.bin ] || { echo "update.bin does not exist"; exit 1; }
do_mount_updatebin ./update.bin ${UPDATE_DIR} || { do_error "fail to mount update.bin"; }
echo "check update.bin ..."
do_check_updatebin ${UPDATE_DIR} || { do_error "update.bin not correct"; }
echo "re-partition inand";
do_fdisk_del_partition ${INAND_DEVICE} || { do_error "fail to delete partition of inand"; }
do_fdisk_new_partition ${INAND_DEVICE} || { do_error "fail to create partition of inand"; }
echo "waiting 3 second ..."
sleep 3;
echo "format ${INAND_DEVICE}1 ..."
do_mkfs_ext4 ${INAND_DEVICE}1 || { do_error "fail to format ${INAND_DEVICE}1"; }
echo "format ${INAND_DEVICE}2 ..."
do_mkfs_ext4 ${INAND_DEVICE}2 || { do_error "fail to format ${INAND_DEVICE}2"; }
echo "format ${INAND_DEVICE}3 ..."
do_mkfs_ext4 ${INAND_DEVICE}3 || { do_error "fail to format ${INAND_DEVICE}3"; }
echo "format ${INAND_DEVICE}4 ..."
do_mkfs_ext4 ${INAND_DEVICE}4 || { do_error "fail to format ${INAND_DEVICE}4"; }
if [ "${burnxboot}" = yes ]; then
echo "write bootloader ...";
do_burn_xboot ${UPDATE_DIR}/xboot.bin ${INAND_DEVICE} || { do_error "fail to write bootloader"; }
fi
if [ "${burnkernel}" = yes ]; then
echo "write kernel ...";
do_burn_kernel_android ${UPDATE_DIR}/zImage-android ${INAND_DEVICE} || { do_error "fail to write android kernel"; }
do_burn_kernel_initrd ${UPDATE_DIR}/zImage-initrd ${INAND_DEVICE} || { do_error "fail to write initrd kernel"; }
fi
if [ "${burnsystem}" = yes ]; then
echo "write system ...";
do_mount_system ${INAND_DEVICE}2 ${SYSTEM_DIR} || { do_error "fail to mount system"; }
do_burn_system ${UPDATE_DIR}/system.tar ${SYSTEM_DIR} || { do_error "fail to write system"; }
do_umount_system ${SYSTEM_DIR} || { do_error "fail to umount system"; }
fi
if [ "${burncache}" = yes ]; then
echo "write cache ...";
do_mount_cache ${INAND_DEVICE}3 ${CACHE_DIR} || { do_error "fail to mount cache"; }
do_umount_cache ${CACHE_DIR} || { do_error "fail to umount cache"; }
fi
if [ "${burndata}" = yes ]; then
echo "write data ...";
do_mount_data ${INAND_DEVICE}4 ${DATA_DIR} || { do_error "fail to mount data"; }
do_burn_data ${UPDATE_DIR}/data.tar ${DATA_DIR} || { do_error "fail to write data"; }
do_umount_data ${DATA_DIR} || { do_error "fail to umount data"; }
fi
echo "umount some resource ..."
cd /;
do_umount_updatebin ${UPDATE_DIR};
sync; sync; sync;
do_error "update successed";
exit 0;
复制代码
升级步骤:
1) 将update.bin拷贝至脚本当前目录;
2) 插入待烧写的系统卡,运行命令 sudo ./s5pv210-burn-android.sh -a
3) 等待至烧写完成,可更换另一张系统卡继续烧写;
欢迎光临 九鼎创展论坛 (http://bbs.9tripod.com/)
Powered by Discuz! X3.2