经过几番改写,做了以下升级程序:
#!/bin/sh
if [ ! -n “$1” ] || [ ! -n “$2” ];then
echo “usage:”
echo " the first args is the file name (eg:rootfs_v0.1.tar.gz)"
echo " the second args is the ip address of server(192.168.6.101)"
echo " for example: ./upsys.sh rootfs_v0.1.tar.gz 192.168.6.101"
exit
fi
check_mountpart=mount | grep "on / type" | cut -d' ' -f 1#程序处理了是否绑定成功
default=rootfs
part2=/dev/mmcblk0p2#这里把EMMC的分区做了定义,一般都是这个节点
part3=/dev/mmcblk0p3
tmp_file=/mnt
rootfs_file=$1
kernel_version=uname -r
if [ $check_mountpart = KaTeX parse error: Expected group after '_' at position 82: …ch=rootfs_patch_̲kernel_version.tar.gz
serverip=$2
echo “serverip is $serverip”
echo “tftp to get the $rootfs_patch… "
tftp -g -r $rootfs_patch $serverip
if [ $? -eq 0 ];then
echo “tftp to get the $rootfs_file…”
tftp -g -r $rootfs_file $serverip
if [ $? -eq 0 ];then
echo “tftp to get the tools…”
tftp -g -r bootenv $serverip
if [ $? -eq 0 ];then
echo “"
echo “The root file system is mounted on $check_mountpart !”
echo "”
if [ $check_mountpart = $part2 ] ;then
umount $part3
cat /bin/busybox > $part3
mkfs.ext4 $part3
mount $part3 $tmp_file
tar xvf $rootfs_file -C $tmp_file
rm /mnt/lib/modules/* -rf
tar xvf
r
o
o
t
f
s
p
a
t
c
h
−
C
/
m
n
t
c
h
m
o
d
+
x
b
o
o
t
e
n
v
c
p
b
o
o
t
e
n
v
/
r
u
n
/
m
e
d
i
a
/
m
m
c
b
l
k
0
p
1
/
c
h
m
o
d
777
/
m
n
t
/
l
i
b
/
m
o
d
u
l
e
s
/
rootfs_patch -C /mnt chmod +x bootenv cp bootenv /run/media/mmcblk0p1/ chmod 777 /mnt/lib/modules/
rootfspatch−C/mntchmod+xbootenvcpbootenv/run/media/mmcblk0p1/chmod777/mnt/lib/modules/kernel_version/.ko
chmod +x /mnt/usr/bin/
rm /mnt/etc/init.d/xserver-nodm
rm /mnt/etc/init.d/nfs*
rm -f /mnt/etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /mnt/etc/localtime
rm .tar.gz
cd /run/media/mmcblk0p1
./bootenv sdroot0=“setenv bootargs earlycon clk_ignore_unused root=/dev/mmcblk0p2 rw rootwait cma=1000m”
./bootenv sdroot1=“setenv bootargs earlycon clk_ignore_unused root=/dev/mmcblk0p3 rw rootwait cma=1000m”
./bootenv sdboot=“run sdroot1 && load mmc 0:1 4000000 system.dtb && load mmc 0:1 0x80000 Image && booti 0x80000 - 4000000”
sync
echo “="
echo “Update rootfs successfully!”
echo “You can reboot now!”
echo "=”
else
umount $part2
cat /bin/busybox > $part2
mkfs.ext4 $part2
mount $part2 $tmp_file
tar xvf $rootfs_file -C $tmp_file
rm /mnt/lib/modules/ -rf
tar xvf
r
o
o
t
f
s
p
a
t
c
h
−
C
/
m
n
t
c
h
m
o
d
+
x
b
o
o
t
e
n
v
c
p
b
o
o
t
e
n
v
/
r
u
n
/
m
e
d
i
a
/
m
m
c
b
l
k
0
p
1
/
c
h
m
o
d
777
/
m
n
t
/
l
i
b
/
m
o
d
u
l
e
s
/
rootfs_patch -C /mnt chmod +x bootenv cp bootenv /run/media/mmcblk0p1/ chmod 777 /mnt/lib/modules/
rootfspatch−C/mntchmod+xbootenvcpbootenv/run/media/mmcblk0p1/chmod777/mnt/lib/modules/kernel_version/.ko
chmod +x /mnt/usr/bin/
rm /mnt/etc/init.d/xserver-nodm
rm /mnt/etc/init.d/nfs*
rm -f /mnt/etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /mnt/etc/localtime
rm .tar.gz
cd /run/media/mmcblk0p1
./bootenv sdroot0=“setenv bootargs earlycon clk_ignore_unused root=/dev/mmcblk0p2 rw rootwait cma=1000m”
./bootenv sdroot1=“setenv bootargs earlycon clk_ignore_unused root=/dev/mmcblk0p3 rw rootwait cma=1000m”
./bootenv sdboot=“run sdroot0 && load mmc 0:1 4000000 system.dtb && load mmc 0:1 0x80000 Image && booti 0x80000 - 4000000”
sync
echo “="
echo “Update rootfs successfully!”
echo “You can reboot now!”
echo "=”
fi
else
echo “"
echo “*Please make sure the server have the file tool bootenv!”
echo "”
exit
fi
else
echo “"
echo “*Please make sure the server have the file $rootfs!”
echo "”
exit
fi
else
echo ""
echo " Please make sure the server have the file $rootfs_patch!"
echo "**”
exit
fi



