-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathburn_sdcard.sh
executable file
·137 lines (114 loc) · 2.44 KB
/
burn_sdcard.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
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
#!/bin/bash
function pt_error()
{
echo -e "\033[1;31mERROR: $*\033[0m"
}
function pt_warn()
{
echo -e "\033[1;31mWARN: $*\033[0m"
}
function pt_info()
{
echo -e "\033[1;32mINFO: $*\033[0m"
}
function pt_ok()
{
echo -e "\033[1;33mOK: $*\033[0m"
}
mmc="mmcblk"
out="$1"
if [ -z "$out" ]; then
pt_error "Usage: $0 <SD card> (SD CARD: /dev/sdX where X is your sd card letter or /dev/mmcblkY where Y your device number)"
exit 1
fi
if [ $UID -ne 0 ]
then
pt_error "Please run as root."
exit
fi
if [[ $out == *$mmc* ]];
then
part="p"
else
part=""
fi
pt_info "Umounting $out, please wait..."
sync
umount ${out}* >/dev/null 2>&1
sleep 1
sync
set -e
pt_info "Formating sd card $out ..."
part_position=20480 # KiB
boot_size=80 # MiB
# Create beginning of disk
pt_info "Zeroing mbr on $out ..."
dd if=/dev/zero bs=1M count=$((part_position/1024)) of="$out"
sync
pt_info "Creating partition on $out ..."
pt_info "p1: $((part_position*2)) and size: ${boot_size}M, $((part_position*2 + boot_size*1024*2))"
# Add partition table
cat <<EOF | fdisk "$out"
o
n
p
1
$((part_position*2))
+${boot_size}M
t
83
n
p
2
$((part_position*2 + boot_size*1024*2))
t
2
83
w
EOF
sleep 1
sync
partprobe -s ${out}
sync
pt_warn "Formating $out ..."
# Create boot file system (ext4)
dd if=/dev/zero bs=1M count=${boot_size} of=${out}1
mkfs.ext4 -F -b 4096 -E stride=2,stripe-width=1024 -L boot ${out}${part}1
# Create ext4 file system for rootfs
mkfs.ext4 -F -b 4096 -E stride=2,stripe-width=1024 -L rootfs ${out}${part}2
sync
sudo tune2fs -O ^has_journal ${out}${part}2
sync
pt_info "Geometry created and sd card '$out' formatted, now flashing... it can take some time, please wait..."
sleep 2
pt_info "Reading partition..."
sudo partprobe
sleep 2
sync
sudo partprobe ${out}
sleep 2
set -e
pt_warn "Flashing $out...."
dd if=./boot0.bin conv=notrunc bs=1k seek=8 of=$out
dd if=./uboot.bin conv=notrunc bs=1k seek=16400 of=$out
pt_info "Decompressing rootfs to $out$part"2", please wait... (takes some time)"
mkdir -p erootfs
sudo partprobe ${out}
sleep 2
sync
sudo mount $out$part"2" erootfs
tar -xvpzf rootfs_neo2_rc1.tar.gz -C ./erootfs --numeric-ow
sync
sudo umount erootfs
rm -fR erootfs
sync
set +e
mkdir eboot
sudo mount $out$part"1" eboot
tar -xvpzf boot_neo2_rc1.tar.gz -C ./eboot --numeric-ow
sync
sudo umount eboot
rm -fR eboot
sync
pt_ok "Finished flashing $out!"
pt_ok "You can remove the SD card and boot the board with this new OS image. Enjoy!"