1
|
#!/bin/bash
|
2
|
# must run this script with sudo, requires root privileges
|
3
|
if [ "$(id -u)" != "0" ]; then
|
4
|
echo "Sorry, you are not root."
|
5
|
exit 1
|
6
|
fi
|
7
|
|
8
|
# get all paths needed
|
9
|
source ./set_altera.sh
|
10
|
|
11
|
pushd ${DELIVERABLESDIR}
|
12
|
|
13
|
image_file=${DELIVERABLESDIR}/mitysom5csx_sensis.img
|
14
|
|
15
|
# create the reference SDCARD image
|
16
|
rm -rf ${image_file}
|
17
|
|
18
|
# 500 MB image is plenty for now
|
19
|
dd if=/dev/zero of=${image_file} bs=1 seek=500M count=0 >/dev/null 2>&1
|
20
|
RETVAL=$?
|
21
|
|
22
|
# exit on failure
|
23
|
if [ "$RETVAL" -ne "0" ]; then
|
24
|
echo "????? dd failed @ Return value: $RETVAL ?????"
|
25
|
popd > /dev/null
|
26
|
exit $RETVAL
|
27
|
fi
|
28
|
|
29
|
# find the next available loop device and assign to loop (ex: /dev/loop0 /dev/loop1)
|
30
|
loop=`losetup -f`
|
31
|
|
32
|
# attach loop device to the image file
|
33
|
# ex: losetup /dev/loop0 image_file.img
|
34
|
losetup ${loop} ${image_file}
|
35
|
RETVAL=$?
|
36
|
|
37
|
# exit on failure
|
38
|
if [ "$RETVAL" -ne "0" ]; then
|
39
|
echo "????? losetup ${loop} failed @ Return value: $RETVAL ?????"
|
40
|
popd > /dev/null
|
41
|
exit $RETVAL
|
42
|
fi
|
43
|
|
44
|
# create partition table
|
45
|
IMAGE_SIZE=$((1024 * 1024 * 1024))
|
46
|
# root filesystem (ext) 83 = linux
|
47
|
RFS_TYPE=83
|
48
|
RFS_NUM=1
|
49
|
RFS_SIZE=$((512 * 1024 * 1024))
|
50
|
RFS_OFFSET=$((4 * 1024 * 1024))
|
51
|
|
52
|
# create partions using fdisk on the loop device
|
53
|
cat <<EOT | fdisk ${loop}
|
54
|
c
|
55
|
u
|
56
|
p
|
57
|
n
|
58
|
p
|
59
|
${RFS_NUM}
|
60
|
$((${RFS_OFFSET}/512))
|
61
|
+$((${RFS_SIZE}/1024))K
|
62
|
t
|
63
|
${RFS_TYPE}
|
64
|
p
|
65
|
w
|
66
|
EOT
|
67
|
|
68
|
RETVAL=$?
|
69
|
|
70
|
# exit on failure
|
71
|
#if [ "$RETVAL" -ne "0" ]; then
|
72
|
# echo "????? fdisk ${loop} failed @ Return value: $RETVAL ?????"
|
73
|
# popd > /dev/null
|
74
|
# exit $RETVAL
|
75
|
#fi
|
76
|
|
77
|
sync
|
78
|
RETVAL=$?
|
79
|
|
80
|
# exit on failure
|
81
|
if [ "$RETVAL" -ne "0" ]; then
|
82
|
echo "????? sync failed @ Return value: $RETVAL ?????"
|
83
|
popd > /dev/null
|
84
|
exit $RETVAL
|
85
|
fi
|
86
|
|
87
|
losetup -d ${loop}
|
88
|
RETVAL=$?
|
89
|
|
90
|
# exit on failure
|
91
|
if [ "$RETVAL" -ne "0" ]; then
|
92
|
echo "????? losetup -d ${loop} failed @ Return value: $RETVAL ?????"
|
93
|
popd > /dev/null
|
94
|
exit $RETVAL
|
95
|
fi
|
96
|
|
97
|
# populate the filesystem
|
98
|
loop=`losetup -f`
|
99
|
losetup ${loop} -o ${RFS_OFFSET} --sizelimit ${RFS_SIZE} ${image_file}
|
100
|
mkfs -t ext3 ${loop}
|
101
|
|
102
|
# remove mount point directory to expand the root ball
|
103
|
rm -rf ./mnt
|
104
|
|
105
|
# make mount point for root ball
|
106
|
mkdir ./mnt
|
107
|
|
108
|
|
109
|
# mount the directory for the roo ball to the image file
|
110
|
mount -t ext3 ${loop} ./mnt
|
111
|
|
112
|
|
113
|
|
114
|
# move to the mnt directory/image file
|
115
|
pushd ./mnt > /dev/null
|
116
|
|
117
|
# untar the root ball into the image file
|
118
|
tar xvzf ${DELIVERABLESDIR}/core-image-sensis-mitysom-5csx.tar.gz
|
119
|
|
120
|
|
121
|
popd > /dev/null
|
122
|
|
123
|
find ./mnt | wc
|
124
|
umount ${loop}
|
125
|
losetup -d ${loop}
|
126
|
|
127
|
rm -rf ./mnt
|
128
|
|
129
|
popd > /dev/null
|
130
|
|