-
Notifications
You must be signed in to change notification settings - Fork 1
/
overo-sdhc-popullate
executable file
·122 lines (96 loc) · 3.43 KB
/
overo-sdhc-popullate
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
#http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html
# set this script to exit at any point an operation returns failure
set -e
source settings.env
if [ ! -n "${U_UNIT_IP}" ]
then
echo "Which IP Address to give to this unit?"
echo "(you'll still need to modify other network info in '/etc/network/interfaces')"
echo "Example: 192.168.1.20"
read U_UNIT_IP
fi
# Where ~/overo-oe can be found
BOOT_PATH=${U_IMAGE_BOOT}
ROOT_PATH=${U_IMAGE_ROOT}
MAC_ADDR=`random-mac`
# Boot options
MLO=${BOOT_PATH}/MLO
UBOOT=${BOOT_PATH}/u-boot.bin
UIMAGE=${BOOT_PATH}/uImage
# Create the environment for this script
MNT=/mnt/tmp_`random-string`
# NOTE /dev/shm is way faster but may not be available once the filesystem size is large
# TODO TMDIR should not be allowed to be MNT
# TODO this script should not run from MNT
TMPDIR=/dev/shm
DEV=$1
DEFAULT_DEV=/dev/mmcblk0
IS_OVERO=`cat /proc/cpuinfo | grep Overo || true`
IS_MMCBLK=`echo ${DEV} | grep /dev/mmcblk || true`
if [ ! "root" == `whoami` ]
then
echo "Usage: sudo $0 $@"
exit 1
fi
if [ ! -n "${DEV}" ]
then
if [ -n "${IS_OVERO}" ]
then
echo "About to format (DESTROY data) ${DEFAULT_DEV}"
DEV=${DEFAULT_DEV}
echo "CTRL+C now if that's not what you wanted..."
sleep 3
echo "continuing..."
else
echo -n 'Usage: `'$0' /dev/MICRO_SDHC_BLOCK_DEVICE`'
exit 1;
fi
fi
# About the target system
# Matches mmcblk0p1 disk0s1 sdf1 - OpenEmbedded, Ubuntu, BSD
BOOT=${DEV}1
ROOT=${DEV}2
# Attempt to ensure that the disk is not in use
umount $DEV* 2>/dev/null || true
umount $DEV* 2>/dev/null || true
# Ready the mount point
#umount $MNT || true
#rm -rf $MNT
mkdir $MNT
# Prepare FAT boot partition
# MLO *must* be installed first
mount ${BOOT} ${MNT}
cp ${MLO} ${MNT}/MLO
cp ${UBOOT} ${MNT}/u-boot.bin
cp ${UIMAGE} ${MNT}/uImage
BOOT_CMD=/tmp/bootscript-`echo ${MAC_ADDR} | sed s/:/-/g`.cmd
sed "s/MAC_ADDR/${MAC_ADDR}/g" ${BOOT_PATH}/bootscript.tpl > ${BOOT_CMD}
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "bootscript" -d ${BOOT_CMD} ${MNT}/boot.scr
echo "sync-ing boot... this may take several seconds"
umount ${MNT}
umount $BOOT 2>/dev/null || true # overo auto-mounts in /media sometimes
# Prepare rootfs
mount ${ROOT} ${MNT}
rsync -avh ${ROOT_PATH}/ ${MNT}/
sed -i "s/IP_ADDR_HERE/${U_UNIT_IP}/g" ${MNT}/etc/network/interfaces
# Configure rootfs with any special sauce we might need
# sync and umount
echo "sync-ing root... this may take several minutes"
umount ${MNT}
umount $ROOT 2>/dev/null || true
# Cleanup any mess we made
rm -rf ${MNT}
# sync and reboot!
sync
sync
#echo 1 > /proc/sys/kernel/sysrq
rmdir /mnt/tmp_* 2> /dev/null || true
echo "popullated sd card successfully"
# if the process fails, enter uboot and `run nandboot` to boot the nand rather than the sd card
# Kernel from NAND, RootFS from MMC
# setenv bootargs console=${console} mpurate=${mpurate} vram=${vram} omapfb.mode=dvi:${dvimode} omapfb.debug=y omapdss.def_disp=${defaultdisplay} root=${mmcroot} rootfstype=${mmcrootfstype}
# setenv bootargs console=${console} mpurate=${mpurate} vram=${vram} omapfb.mode=dvi:${dvimode} omapfb.debug=y omapdss.def_disp=${defaultdisplay} root=${mmcroot} rootfstype=${mmcrootfstype}
# nand read ${loadaddr} 280000 400000; bootm ${loadaddr}
# the first boot takes forever to load
# mixedboot=echo Kernel on nand, RootFS on mmc...; run mmcargs; nand read ${loadaddr} 280000 400000; bootm ${loadaddr}