This repository has been archived by the owner on Sep 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
mkcard.sh
executable file
·123 lines (114 loc) · 2.35 KB
/
mkcard.sh
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
#!/bin/bash -xv
# mkcard.sh v0.3.beagleboard-validation-scripts.1
# (c) Copyright 2009 Graeme Gregory <[email protected]>
# Licensed under terms of GPLv2
DRIVE=$1
CYLINDERS=$2
#LOCALSRC=/media/mmcblk0
WGETSRC=http://www.beagleboard.org/~arago/xm-testing
DST=/media/target
for tool in dd sfdisk partx mkfs.vfat mke2fs; do
if ! type $tool >/dev/null 2>&1; then
echo "ERROR: \"$tool\" not found."
echo " Try 'opkg install dosfstools e2fsprogs e2fsprogs-mke2fs'"
exit 2
fi
done
function do_clean {
if [ "x$DRIVE" = "x" ]; then
echo "DRIVE not set, exiting."
exit -1
fi
sleep 3
umount ${DRIVE}1
umount ${DRIVE}2
umount ${DRIVE}p1
umount ${DRIVE}p2
if [ `dd if=/dev/zero of=$DRIVE bs=1024 count=1024` ]; then
echo "Do you need to run the script as 'root'?"
exit -1
fi
}
function do_format {
if [ "x$DRIVE" = "x" ]; then
echo "DRIVE not set, exiting."
exit -1
fi
SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`
if [ "x$CYLINDERS" = "x" ]; then
if [ "x$SIZE" = "x" ]; then
echo "Unable to determine disk size, exiting."
exit -1
else
echo DISK SIZE - $SIZE bytes
CYLINDERS=`echo $SIZE/255/63/512 | bc`
fi
fi
echo CYLINDERS - $CYLINDERS
sync
sleep 3
{
echo ,9,0x0C,*
echo ,,,-
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
partx $DRIVE
sleep 3
if [ -b ${DRIVE}1 ]; then
DRIVE1=${DRIVE}1
else
if [ -b ${DRIVE}p1 ]; then
DRIVE1=${DRIVE}p1
else
echo "Cant find boot partition in ${DRIVE}(1|p1)"
exit -1
fi
fi
echo "Found first partition at ${DRIVE1}"
umount ${DRIVE1}
dd if=/dev/zero of=${DRIVE1} bs=512 count=1
mkfs.vfat -F 32 -n "boot" ${DRIVE1}
if [ -b ${DRIVE}2 ]; then
DRIVE2=${DRIVE}2
else
if [ -b ${DRIVE}p2 ]; then
DRIVE2=${DRIVE}2
else
echo "Cant find rootfs partition in ${DRIVE}(2|p2)"
exit -1
fi
fi
echo "Found second partition at ${DRIVE2}"
umount ${DRIVE2}
mke2fs -j -L "rootfs" ${DRIVE2}
}
function do_mount {
umount ${DRIVE1}
umount ${DRIVE2}
mkdir -p ${DST}-1
mkdir -p ${DST}-2
mount ${DRIVE1} ${DST}-1
mount ${DRIVE2} ${DST}-2
}
function do_copy {
for file in MLO u-boot.bin uImage boot.scr user.scr ramdisk.gz; do
if [ ! -e $file ]; then
echo "Cannot find $file, attempting to download from $WGETSRC"
wget $WGETSRC/$file
fi
if [ -e $file ]; then
cp -v $file ${DST}-1/$file
else
echo "Still cannot find $file"
#exit -1
fi
done
}
function do_umount {
umount ${DRIVE1}
umount ${DRIVE2}
}
do_clean
do_format
do_mount
do_copy
do_umount