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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
|
#!/bin/bash -e
#
# Copyright (c) 2009-2010 Robert Nelson <robertcnelson@gmail.com>
# Copyright (c) 2010 Mario Di Francesco <mdf-code@digitalexile.it>
# Copyright (c) 2010 Till Harbaum <till@harbaum.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# Latest can be found at:
# http://github.com/RobertCNelson/omap-image-builder/blob/master/tools/setup_sdcard.sh
#Notes: need to check for: parted, fdisk, wget, mkfs.*, mkimage, md5sum
#Debug Tips
#oem-config username/password
#add: "debug-oem-config" to bootargs
unset MMC
unset SWAP_BOOT_USER
unset DEFAULT_USER
unset DEBUG
#Defaults
RFS=ext3
BOOT_LABEL=BOOT
RFS_LABEL=ROOT
PARTITION_PREFIX=""
UBOOT_TYPE=beagle
SWAPSIZE=512
if [ "$TYPE" == "" ]; then
TYPE=handset
fi
RELEASE=latest
ARCH=armv7l
DIR=$PWD
function detect_software {
#Currently only Ubuntu and Debian..
#Working on Fedora...
unset PACKAGE
unset APT
if [ ! $(which mkimage) ];then
echo "Missing uboot-mkimage"
PACKAGE="uboot-mkimage "
APT=1
fi
if [ ! $(which wget) ];then
echo "Missing wget"
PACKAGE+="wget "
APT=1
fi
if [ ! $(which pv) ];then
echo "Missing pv"
PACKAGE+="pv "
APT=1
fi
if [ "${APT}" ];then
echo "Installing Dependencies"
sudo aptitude install $PACKAGE
fi
}
function beagle_boot_scripts {
cat > /tmp/boot.cmd <<beagle_boot_cmd
echo "Booting MeeGo Community Image"
if test "\${beaglerev}" = "xMA"; then
echo "Kernel is not ready for 1Ghz limiting to 800Mhz"
setenv mpurate 800
fi
if test "\${beaglerev}" = "xMB"; then
echo "Kernel is not ready for 1Ghz limiting to 800Mhz"
setenv mpurate 800
fi
setenv dvimode 800x480-16@60
setenv vram 0:2M,1:2M,2:2M
setenv bootcmd 'mmc init; fatload mmc 0:1 0x80300000 uImage; bootm 0x80300000'
#setenv bootargs console=ttyO2,115200n8 console=tty0 root=/dev/mmcblk0p2 rootwait ro omapfb.vram=\${vram} omapfb.mode=dvi:\${dvimode} fixrtc mpurate=\${mpurate}
setenv bootargs console=ttyO2,115200n8 console=tty0 root=/dev/mmcblk0p2 rootwait ro omapfb.mode=dvi:\${dvimode} fixrtc mpurate=\${mpurate}
boot
beagle_boot_cmd
}
function touchbook_boot_scripts {
cat > /tmp/boot.cmd <<touchbook_boot_cmd
setenv dvimode 1024x600MR-16@60
setenv vram 12MB
setenv bootcmd 'mmc init; fatload mmc 0:1 0x80300000 uImage; fatload mmc 0:1 0x81600000 uInitrd; bootm 0x80300000 0x81600000'
setenv bootargs console=tty1 root=/dev/mmcblk0p2 rootwait ro vram=\${vram} omapfb.mode=dvi:\${dvimode} fixrtc mpurate=600
boot
touchbook_boot_cmd
}
function panda_boot_scripts {
cat > /tmp/boot.cmd <<panda_boot_cmd
setenv dvimode 1024x600MR-16@60
setenv vram 16MB
setenv bootcmd 'mmc init; fatload mmc 0:1 0x80300000 uImage; fatload mmc 0:1 0x81600000 uInitrd; bootm 0x80300000 0x81600000'
setenv bootargs console=ttyO2,115200n8 console=tty0 root=/dev/mmcblk0p2 rootwait ro vram=\${vram} omapfb.mode=dvi:\${dvimode} fixrtc mpurate=600
boot
panda_boot_cmd
}
function dl_xload_uboot {
# sudo rm -rfd ${DIR}/downloads/ || true
#mkdir -p ${DIR}/downloads/
case "$SYSTEM" in
beagle)
beagle_boot_scripts
#beagle
MIRROR="http://rcn-ee.net/deb/"
echo ""
echo "1 / 7: Downloading X-loader and Uboot"
echo ""
rm -f ${DIR}/downloads/bootloader || true
wget -c --directory-prefix=${DIR}/downloads/ ${MIRROR}tools/latest/bootloader
MLO=$(cat ${DIR}/downloads/bootloader | grep "ABI:1:MLO" | awk '{print $2}')
UBOOT=$(cat ${DIR}/downloads/bootloader | grep "ABI:1:UBOOT" | awk '{print $2}')
#wget -c --no-verbose --directory-prefix=${DIR}/downloads/ ${MLO}
#wget -c --no-verbose --directory-prefix=${DIR}/downloads/ ${UBOOT}
MLO=${MLO##*/}
UBOOT=${UBOOT##*/}
;;
igepv2)
#MLO=${MLO##*/}
#UBOOT=${UBOOT##*/}
MLO=NA
UBOOT=NA
;;
touchbook)
touchbook_boot_scripts
MIRROR="http://rcn-ee.net/deb/"
echo ""
echo "1 / 7: Downloading X-loader and Uboot"
echo ""
rm -f ${DIR}/downloads/bootloader || true
wget -c --no-verbose --directory-prefix=${DIR}/downloads/ ${MIRROR}tools/latest/bootloader
MLO=$(cat ${DIR}/downloads/bootloader | grep "ABI:5:MLO" | awk '{print $2}')
UBOOT=$(cat ${DIR}/downloads/bootloader | grep "ABI:5:UBOOT" | awk '{print $2}')
wget -c --no-verbose --directory-prefix=${DIR}/downloads/ ${MLO}
wget -c --no-verbose --directory-prefix=${DIR}/downloads/ ${UBOOT}
MLO=${MLO##*/}
UBOOT=${UBOOT##*/}
;;
panda)
panda_boot_scripts
MIRROR="http://rcn-ee.net/deb/"
echo ""
echo "1 / 7: Downloading X-loader and Uboot"
echo ""
rm -f ${DIR}/downloads/bootloader || true
wget -c --no-verbose --directory-prefix=${DIR}/downloads/ ${MIRROR}tools/latest/bootloader
MLO=$(cat ${DIR}/downloads/bootloader | grep "ABI:2:MLO" | awk '{print $2}')
UBOOT=$(cat ${DIR}/downloads/bootloader | grep "ABI:2:UBOOT" | awk '{print $2}')
wget -c --no-verbose --directory-prefix=${DIR}/downloads/ ${MLO}
wget -c --no-verbose --directory-prefix=${DIR}/downloads/ ${UBOOT}
MLO=${MLO##*/}
UBOOT=${UBOOT##*/}
;;
esac
}
function cleanup_sd {
echo ""
echo "2 / 7: Unmountting Partitions"
echo ""
NUM_MOUNTS=$(mount | grep -v none | grep "$MMC" | wc -l)
for (( c=1; c<=$NUM_MOUNTS; c++ ))
do
DRIVE=$(mount | grep -v none | grep "$MMC" | tail -1 | awk '{print $1}')
sudo umount ${DRIVE} &> /dev/null || true
done
sudo parted -s ${MMC} mklabel msdos
}
function create_partitions {
sudo fdisk -H 255 -S 63 ${MMC} << END
n
p
1
1
+64M
a
1
t
e
p
w
END
echo ""
echo "3 / 7: Formatting Boot Partition"
echo ""
sudo mkfs.vfat -F 16 ${MMC}${PARTITION_PREFIX}1 -n ${BOOT_LABEL}
sudo rm -rfd ${DIR}/disk || true
mkdir ${DIR}/disk
sudo mount ${MMC}${PARTITION_PREFIX}1 ${DIR}/disk
if [ "$DO_UBOOT" ];then
if ls ${DIR}/downloads/${MLO} >/dev/null 2>&1;then
sudo cp -v ${DIR}/downloads/${MLO} ${DIR}/disk/MLO
fi
if ls ${DIR}/downloads/${UBOOT} >/dev/null 2>&1;then
sudo cp -v ${DIR}/downloads/${UBOOT} ${DIR}/disk/u-boot.bin
fi
fi
cd ${DIR}/disk
sync
cd ${DIR}/
sudo umount ${DIR}/disk || true
echo "done"
SIZE=`sudo fdisk -s ${MMC}`
SIZE=$(( (SIZE/1024)-64-SWAPSIZE ))
echo "rootfs size = ${SIZE}"
sudo fdisk ${MMC} << ROOTFS
n
p
2
+${SIZE}M
p
w
ROOTFS
echo ""
echo "4 / 7: Formating ${RFS} Partition"
echo ""
sudo mkfs.${RFS} ${MMC}${PARTITION_PREFIX}2 -L ${RFS_LABEL}
sudo fdisk ${MMC} << SWAP
n
p
3
t
3
82
p
w
SWAP
echo ""
echo "4a / 7: Creating Swap Partition"
echo ""
sudo mkswap ${MMC}${PARTITION_PREFIX}3
echo "done"
}
function populate_boot {
echo ""
echo "5 / 7: Populating Boot Partition"
echo ""
sudo mount ${MMC}${PARTITION_PREFIX}1 ${DIR}/disk
sudo cp ${LATEST_UIMAGE} ${DIR}/disk/uImage
if [ "$DO_UBOOT" ];then
if ls /tmp/boot.cmd >/dev/null 2>&1;then
sudo mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Boot Script" -d /tmp/boot.cmd ${DIR}/disk/boot.scr
sudo cp /tmp/boot.cmd ${DIR}/disk/boot.cmd
rm -f /tmp/boot.cmd || true
fi
#for igepv2 users
# if ls ${DIR}/disk/boot.scr >/dev/null 2>&1;then
# sudo cp -v ${DIR}/disk/boot.scr ${DIR}/disk/boot.ini
# fi
fi
cd ${DIR}/disk/
sync
sync
cd ${DIR}/
sudo umount ${DIR}/disk || true
}
function populate_rootfs {
echo ""
echo "6 / 7: Populating rootfs Partition"
echo "Be patient, this may take a few minutes"
echo ""
sudo mount ${MMC}${PARTITION_PREFIX}2 ${DIR}/disk
mkdir image
sudo mount -o loop ./${RELEASE}/images/meego-${TYPE}-${ARCH}-beagle/meego-${TYPE}-${ARCH}-beagle-${RELEASE}.img ./image
sudo rsync -aHx --delete ./image/* ${DIR}/disk/
# add SGX and kernel modules
INSTALL_ROOT=${DIR}/disk/
# check if module tarball exists and install modules
if [ -d ./$KERNEL_VERSION-devel/deploy ]; then
echo "Installing kernel modules for $KERNEL_VERSION"
# find latest module package
LATEST_MODULES=`ls -t1 ./$KERNEL_VERSION-devel/deploy/$KERNEL_VERSION-*-modules.tar.gz | head -n1`
sudo tar xfz $LATEST_MODULES -C $INSTALL_ROOT
else
echo "WARNING: kernel module path ./$KERNEL_VERSION-devel/deploy not found!"
fi
sudo umount ./image
rmdir ./image
cd ${DIR}/disk/
sync
sync
cd ${DIR}/
sudo umount ${DIR}/disk || true
echo ""
echo "7 / 7: setup_sdcard.sh script complete"
echo ""
}
function check_mmc {
FDISK=$(sudo LC_ALL=C sfdisk -l 2>/dev/null | grep "[Disk] ${MMC}" | awk '{print $2}')
if test "-$FDISK-" = "-$MMC:-"
then
echo ""
echo "I see..."
echo "sudo sfdisk -l:"
sudo LC_ALL=C sfdisk -l 2>/dev/null | grep "[Disk] /dev/" --color=never
echo ""
echo "mount:"
mount | grep -v none | grep "/dev/" --color=never
echo ""
read -p "Are you 100% sure, on selecting [${MMC}] (y/n)? "
[ "$REPLY" == "y" ] || exit
echo ""
else
echo ""
echo "Are you sure? I Don't see [${MMC}], here is what I do see..."
echo ""
echo "sudo sfdisk -l:"
sudo LC_ALL=C sfdisk -l 2>/dev/null | grep "[Disk] /dev/" --color=never
echo ""
echo "mount:"
mount | grep -v none | grep "/dev/" --color=never
echo ""
exit
fi
}
function check_uboot_type {
IN_VALID_UBOOT=1
unset DO_UBOOT
case "$UBOOT_TYPE" in
beagle)
SYSTEM=beagle
unset IN_VALID_UBOOT
DO_UBOOT=1
;;
beagle-proto)
#hidden: proto button bug
SYSTEM=beagle
SWAP_BOOT_USER=1
unset IN_VALID_UBOOT
DO_UBOOT=1
;;
igepv2)
SYSTEM=igepv2
unset IN_VALID_UBOOT
DO_UBOOT=1
;;
touchbook)
SYSTEM=touchbook
unset IN_VALID_UBOOT
DO_UBOOT=1
;;
panda)
SYSTEM=panda
unset IN_VALID_UBOOT
DO_UBOOT=1
;;
esac
if [ "$IN_VALID_UBOOT" ] ; then
usage
fi
}
function check_addon_type {
IN_VALID_ADDON=1
if test "-$ADDON_TYPE-" = "-pico-"
then
ADDON=pico
unset IN_VALID_ADDON
fi
if [ "$IN_VALID_ADDON" ] ; then
usage
fi
}
function check_fs_type {
IN_VALID_FS=1
case "$FS_TYPE" in
ext2)
RFS=ext2
unset IN_VALID_FS
;;
ext3)
RFS=ext3
unset IN_VALID_FS
;;
ext4)
RFS=ext4
unset IN_VALID_FS
;;
btrfs)
if [ ! $(which mkfs.btrfs) ];then
echo "Missing btrfs tools"
sudo aptitude install btrfs-tools
fi
RFS=btrfs
unset IN_VALID_FS
;;
esac
if [ "$IN_VALID_FS" ] ; then
usage
fi
}
function check_contents {
# determine name of latest kernel built
KERNEL_VERSION=2.6.38
if [ -d ./$KERNEL_VERSION-devel/deploy ]; then
echo "Installing kernel modules for $KERNEL_VERSION"
# find latest module package
LATEST_UIMAGE=`ls -t1 ./$KERNEL_VERSION-devel/deploy/$KERNEL_VERSION-*.uImage | head -n1`
else
echo "No kernel image found in ./$KERNEL_VERSION-devel/deploy!"
exit -1
fi
if [ ! -f ./${RELEASE}/images/meego-${TYPE}-${ARCH}-beagle/meego-${TYPE}-${ARCH}-beagle-${RELEASE}.img ]; then
echo "No meego image found at ./${RELEASE}/images/meego-${TYPE}-${ARCH}-beagle/meego-${TYPE}-${ARCH}-beagle-${RELEASE}.img"
echo "Please run ./build_image.sh first"
exit -1
fi
}
function usage {
echo "usage: $(basename $0) --mmc /dev/sdX"
cat <<EOF
required options:
--mmc </dev/sdX>
Unformated MMC Card
Additional/Optional options:
-h --help
this help
--uboot <dev board>
beagle - <Bx, C2/C3/C4, xMA, xMB>
igepv2 - <no u-boot or MLO yet>
panda - <A1>
--use-default-user
(useful for serial only modes and when oem-config is broken)
--rootfs <fs_type>
ext3
ext4 - <set as default>
btrfs
--boot_label <boot_label>
boot partition label
--rfs_label <rfs_label>
rootfs partition label
--debug
enable all debug options for troubleshooting
EOF
exit
}
function checkparm {
if [ "$(echo $1|grep ^'\-')" ];then
echo "E: Need an argument"
usage
fi
}
# parse commandline options
while [ ! -z "$1" ]; do
case $1 in
-h|--help)
usage
MMC=1
;;
--mmc)
checkparm $2
MMC="$2"
if [[ "${MMC}" =~ "mmcblk" ]]
then
PARTITION_PREFIX="p"
fi
check_mmc
;;
--uboot)
checkparm $2
UBOOT_TYPE="$2"
check_uboot_type
;;
--addon)
checkparm $2
ADDON_TYPE="$2"
check_addon_type
;;
--rootfs)
checkparm $2
FS_TYPE="$2"
check_fs_type
;;
--use-default-user)
DEFAULT_USER=1
;;
--boot_label)
checkparm $2
BOOT_LABEL="$2"
;;
--rfs_label)
checkparm $2
RFS_LABEL="$2"
;;
--debug)
DEBUG=1
;;
esac
shift
done
if [ ! "${MMC}" ];then
usage
fi
check_contents
check_uboot_type
detect_software
if [ "$DO_UBOOT" ];then
dl_xload_uboot
fi
cleanup_sd
create_partitions
populate_boot
populate_rootfs
|