-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprepare_sd_image_rescue
executable file
·143 lines (102 loc) · 2.63 KB
/
prepare_sd_image_rescue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh
## hyphop ##
#= prerape rescue image for sd/usb/mmc disk - vfat
## usage ./prapare_sd_image_rescue [-r] [ /dev/FLASHDISK ] | [ @remote_host ]
DEV="$1"
sudo=sudo
mkimage=mkimage2
REBUILD_RESCUE=
for a in "$@"; do
case $a in
-r)
REBUILD_RESCUE=1
;;
*@*)
DEV="$a"
;;
*)
[ -b "$a" ] && {
DEV="$a"
}
;;
esac
done
## rebuild rescue image
[ "$REBUILD_RESCUE" ] && {
$(dirname $0)/pack_image -r
}
D=/tmp/krescue.sd
[ -d $D ] || mkdir $D
UBOOT_SD=../share/u-boot.sd.bin
[ -f $UBOOT_SD ] || {
echo "[e] not found $UBOOT_SD">&2
exit 1
}
P=$PWD
DD=$D.img
OF=3276 ## 1.6M before
S=$((14*1024*1024))
BS=512
CMD(){
echo "[#] $@">&2
"$@"
}
CMD dd if=/dev/zero count=$((S/$BS + $OF)) bs=$BS of=$DD
CMD dd if=$UBOOT_SD bs=$BS conv=notrunc of=$DD
printf "n\np\n1\n$OF\n\nw\nq\n" | fdisk $DD
CMD dd if=$UBOOT_SD bs=444 count=1 conv=notrunc of=$DD
LOOP=$($sudo losetup -f)
CMD $sudo losetup -o $((OF*$BS)) $LOOP $DD
CMD $sudo mkfs.vfat -n rescue $LOOP
CMD $sudo mount -o user,uid=$(id -u),gid=$(id -g) $LOOP $D
RESCUE=/rescue
[ -d $D$RESCUE ] || mkdir -p $D$RESCUE
CMD cp ../docs/README-rescue* $D
CMD cp ../share/uI* $D$RESCUE
CMD cp ../share/linux.dtb $D$RESCUE/uboot.dtb
CMD cp ../share/splash.bmp.gz $D$RESCUE
CMD cp ../files/boot.sd.cmd $D$RESCUE
CMD cp ../files/boot.sd.make $D$RESCUE
CMD $mkimage -C none -A arm -T script -d $D$RESCUE/boot.sd.cmd $D$RESCUE/boot.sd.scr
CMD cp ../files/80_user_env.txt $D$RESCUE
SS=$D$RESCUE/scripts
[ -d $SS ] || CMD mkdir -p $SS
CMD cp ../scripts/sd/* $SS
ls -l1 $D/* | tee $D$RESCUE/files.list
md5sum $D/$RESCUE/* > $D$RESCUE/files.md5sum
echo "$(date)" > $D$RESCUE/generated.date
CMD sync
CMD $sudo umount $D
#CMD $sudo losetup -d $LOOP || {
CMD $sudo losetup -D || {
echo "[i] loop $LOOP still used">&2
}
echo "[i] rescue sd image: $DD is ready">&2
ls -Ll1 $DD
gzip -c $DD > $DD.gz
ls -Ll1 $DD.gz
[ -b "$DEV" ] && {
# echo "[i] type Y for allow write to $DEV">&2
# [ "$(read YES)" = "Y" ] || {
# echo "[w] owe wait only Y not $YES">&2
# exit 1
# }
echo "[i] write image $DD -> $DEV flash disk! plz wait...">&2
CMD $sudo dd if=$DD of=$DEV conv=notrunc bs=8192
CMD sync
echo "[i] DONE">&2
exit
}
case $DEV in
*@*)
TO="root@${DEV#*@}"
echo "[i] remote ssh write image $DD to sd">&2
CMD ssh $TO dd of=/dev/mmcblk1 conv=sync bs=4096 < $DD
echo "[i] DONE">&2
exit
;;
esac
echo "[i] maybe next command for write it">&2
echo "./image2flash /tmp/krescue.upgrade.disk.img /dev/#your_drive " >&2
echo "# or remote write to sd">&2
echo "ssh root@vimu dd of=/dev/mmcblk1 bs=4096 < /tmp/krescue.spi.bin">&2