-
Notifications
You must be signed in to change notification settings - Fork 1
/
overo-sdhc-partition
executable file
·103 lines (87 loc) · 2.66 KB
/
overo-sdhc-partition
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
#!/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
# Create the environment for this script
DEV=$1
DEFAULT_DEV=/dev/mmcblk0
IS_OVERO=`cat /proc/cpuinfo | grep Overo || true`
IS_MMCBLK=`echo ${DEV} | grep /dev/mmcblk || true`
if [ ! -n "${DEV}" ]
then
if [ -n "${IS_OVERO}" ]
then
echo "About to partition (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
# Attempt to ensure that the disk is not in use
umount ${DEV} 2>/dev/null || true
umount ${DEV} 2>/dev/null || true
# Backup the MBR - in case the working hard drive is specified by mistake, rather than the sd card
dd if=$DEV of=./mbr.bak bs=512 count=1 2> /dev/null
echo "Created backup of MBR... just to be safe"
echo 'use `dd of='${DEV}' if=./mbr.bak bs=512 count=1` to restore or `rm mbr.bak` to remove'
# Calculate what the number of cylinders should be according to the overo uboot specs
let BYTES=`fdisk $DEV -l | grep Disk | grep bytes | cut -d',' -f2 | cut -d' ' -f2`
CYL=$(($BYTES/255/63/512))
# This scripts fdisk to run in expert mode
# it changes the head, sector, and cylinder, to match those required for the overo uboot
# it then creates a 32mb FAT boot partition and uses the rest of the card for the rootfs
#
# Comments may not be placed between the EOF blocks below
fdisk $DEV << EOF >/dev/null 2>/dev/null || true
o
x
h
255
s
63
c
$CYL
r
n
p
1
+32M
n
p
2
${U_SDHC_ROOT_SIZE}
t
1
c
a
1
w
EOF
# Add different partition schemes
#
#n - new partition
#p - primary
#3 - 3rd
# - blank or start cyl
# - blank, end cyl, or +xG
# The return of this process is almost always false due to that the kernel cannot resync the
# partition table.
# A reboot (on the overo) or unplugging and replugging the sdhc (on a Linux box)
# is required before continuing on to copy over the SD image.
# Overo Note:
# if the `reboot` command doesn't work use
# echo b > /proc/sysrq-trigger
# which is similar to a hard power cycle
echo -n "Probably prepared SD card successfully..."
if [ -n "${IS_OVERO}" ] && [ -n "${IS_MMCBLK}" ]
then
echo "The overo should be rebooted (to resync the partition table with the kernel) because you can't hot-swap/reinsert the microSDHC."
echo 'Try `reboot` (soft, but sometimes hangs) or `cd /; umount -a; sync; echo b > /proc/sysrq-trigger` (power cycle)'
else
echo "The microSDHC must be removed from and reinserted into the card reader to continue"
fi