-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprepare_sd_image_rescue_vim2_spi
executable file
·167 lines (119 loc) · 3.14 KB
/
prepare_sd_image_rescue_vim2_spi
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/sh
set -e
## hyphop ##
#= prerape rescue image for sd/usb/mmc disk - vfat - spi
## usage ./prapare_sd_image_rescue [-r] [ /dev/FLASHDISK ] | [ @remote_host ]
DEV="$1"
sudo=sudo
REBUILD_RESCUE=
DEV2=/dev/mmcblk1
for a in "$@"; do
case $a in
-r)
REBUILD_RESCUE=1
;;
*@*)
DEV="$a"
;;
/dev/mmc*)
DEV2=$a
;;
*)
[ -b "$a" ] && {
DEV="$a"
}
;;
esac
done
## rebuild rescue image
[ "$REBUILD_RESCUE" ] && {
$(dirname $0)/pack_image -r
}
CMD(){
echo "[#] $@">&2
"$@"
}
D=/tmp/krescue.sd
grep $D /proc/mounts && CMD $sudo umount $D
CMD $sudo losetup -D
[ -d $D ] || mkdir $D
UBOOT_SD=../share/u-boot.sd.bin
UBOOT_SPI=../share/u-boot.spi.bin
[ -f $UBOOT_SD ] || {
echo "[e] not found $UBOOT_SD">&2
exit 1
}
P=$PWD
DD=$D.img
OF=3276 ## 1.6M before
S=$((28*1024*1024))
BS=512
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/Image $D$RESCUE
CMD cp ../share/uInitrd* $D$RESCUE
CMD cp ../share/uImage* $D$RESCUE
CMD cp ../share/u-boot.*.bin $D$RESCUE
CMD cp ../share/linux.dtb $D$RESCUE/uboot.dtb
CMD cp ../share/*.dtb $D$RESCUE/
CMD cp ../share/splash.bmp.gz $D$RESCUE
CMD cp ../files/boot.sd.cmd $D$RESCUE
CMD cp ../files/boot.am.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 mkimage -C none -A arm -T script -d $D$RESCUE/boot.am.cmd $D/boot.scr
## cp or links
CMD cp $D/boot.scr $D/boot.scr.uimg
CMD cp $D/boot.scr $D/s905_autoscript
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 tar -czf $D.tar.gz -C$D .
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: $DEV2">&2
CMD ssh $TO dd of=$DEV2 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