-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash_bootable_mmc.sh
executable file
·82 lines (79 loc) · 1.94 KB
/
flash_bootable_mmc.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
#!/bin/sh
#This script is for beagle bone to build a bootable eMMC and copy sdcard boot contents into it.
#It can be run after booting the kernel wiht sd card.
function pause(){
read -p "$*"
}
if [ -z "$1" ] || [ -z "$2" ]
then
echo "
Usage: $0 <source-device> <destination-device>
Example: $0 /dev/mmcblk0 /dev/mmcblk1
"
exit 1
fi
ls $1
if [ $? -ne 0 ]
then
echo "The $1 device is not available."
exit 1
fi
ls $2
if [ $? -ne 0 ]
then
echo "The $2 device is not available."
exit 1
fi
source=$1
destination=$2
root_device=$(cat /proc/cmdline | awk -F'root=' '{print $2}' | awk '{print $1}')
if [ "$root_device" = "$destination"p2 ]
then
echo "You can't copy on mounted device as root"
exit 1
fi
umount ${source}p1
umount ${destination}p1
umount ${source}p2
umount ${destination}p2
dd if=/dev/zero of=${destination} bs=1M count=108
sync
dd if=${destination} of=/dev/null bs=1M count=108
sync
echo -e "o\nn\np\n1\n\n+200M\na\n1\nt\ne\nn\np\n2\n\n\nw\n" | fdisk $destination ; fdisk -l $destination
mkfs.vfat -F 16 ${destination}p1
mkfs.ext2 ${destination}p2
mkdir -p /mnt/source
mkdir -p /mnt/destination
umount /mnt/source
umount /mnt/destination
mount ${source}p1 /mnt/source
mount ${destination}p1 /mnt/destination
cd /mnt/source
cp MLO u-boot.img uEnv.txt /mnt/destination
if [ "$source" = "/dev/mmcblk0" ]
then
sed -E -i -e 's/uenvcmd=run.*/uenvcmd=run uenvcmd_mmc1/' /mnt/destination/uEnv.txt
elif [ "$source" = "/dev/mmcblk1" ]
then
sed -E -i -e 's/uenvcmd=run.*/uenvcmd=run uenvcmd_mmc0/' /mnt/destination/uEnv.txt
else
echo "source is not valid"
exit 1
fi
sync
cd ../..
umount /mnt/source
umount /mnt/destination
mount ${source}p2 /mnt/source
mount ${destination}p2 /mnt/destination
cd /mnt/source
cp -r ./* /mnt/destination
sync
cd ../..
umount /mnt/source || umount -l /mnt/source
umount /mnt/destination || umount -l /mnt/destination
rmdir /mnt/source
rmdir /mnt/destination
echo "End of make bootable MMC script."
exit 0