-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite-sdcard-beagleboneblack.sh
More file actions
executable file
·124 lines (102 loc) · 3.46 KB
/
write-sdcard-beagleboneblack.sh
File metadata and controls
executable file
·124 lines (102 loc) · 3.46 KB
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
#!/bin/bash
function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
# Format an SD card for Android on BeagelBone Black
if [ $# -ne 1 ]; then
echo "Usage: $0 [drive]"
echo " drive is 'sdb', 'mmcblk0'"
exit 1
fi
DRIVE=$1
# Check the drive exists in /sys/block
if [ ! -e /sys/block/${DRIVE}/size ]; then
echo "Drive does not exist"
exit 1
fi
# Check it is a flash drive (size < 32MiB)
NUM_SECTORS=`cat /sys/block/${DRIVE}/size`
if [ $NUM_SECTORS -eq 0 -o $NUM_SECTORS -gt 64000000 ]; then
echo "Does not look like an SD card, bailing out"
exit 1
fi
# Unmount any partitions that have been automounted
if [ $DRIVE == "mmcblk0" ]; then
sudo umount /dev/${DRIVE}*
BOOT_PART=/dev/${DRIVE}p1
SYSTEM_PART=/dev/${DRIVE}p2
USER_PART=/dev/${DRIVE}p3
CACHE_PART=/dev/${DRIVE}p4
else
sudo umount /dev/${DRIVE}[1-9]
BOOT_PART=/dev/${DRIVE}1
SYSTEM_PART=/dev/${DRIVE}2
USER_PART=/dev/${DRIVE}3
CACHE_PART=/dev/${DRIVE}4
fi
set -e
# Overwite existing partiton table with zeros
sudo dd if=/dev/zero of=/dev/${DRIVE} bs=1M count=10
if [ $? -ne 0 ]; then echo "Error: dd"; exit 1; fi
# Create 5 primary partitons on the sd card
# 1: boot: FAT32, 64 MiB, boot flag
# 2: system: Linux, 1024 MiB
# 3: data: Linux, 3072 MiB
# 4: cache: Linux, 256 MiB
# 5: vendor: Linux, 10 MiB
# Note that the formatting of parameters changed slightly v2.26
SFDISK_VERSION=`sfdisk --version | awk '{print $4}'`
if version_gt $SFDISK_VERSION "2.26"; then
echo "sfdisk uses new syntax"
sudo sfdisk --force /dev/${DRIVE} << EOF
,64M,0x0C,*,
,1024M,,,
,2048M,,,
,256M,,,
EOF
else
sudo sfdisk --force --unit M /dev/${DRIVE} << EOF
,64,0x0c,*
,1024,,,
,2048,,,
,256,,,
EOF
fi
if [ $? -ne 0 ]; then echo "Error: sdfisk"; exit 1; fi
sudo mkfs.vfat -nboot ${BOOT_PART}
if [ $? -ne 0 ]; then echo "Error: mkfs.ext4"; exit 1; fi
# Copy boot files
echo "Mounting $BOOT_PART"
sudo mount $BOOT_PART /mnt
if [ $? != 0 ]; then echo "ERROR"; exit; fi
UNAME=4.19.59-bone36
sudo mkdir -p /mnt/boot/dtbs/$UNAME
mkimage -A arm -O linux -T ramdisk -d ${ANDROID_PRODUCT_OUT}/ramdisk.img uRamdisk
if [ $? != 0 ]; then echo "ERROR"; exit; fi
sudo cp external/u-boot/MLO /mnt
if [ $? != 0 ]; then echo "ERROR"; exit; fi
sudo cp external/u-boot/u-boot.img /mnt
if [ $? != 0 ]; then echo "ERROR"; exit; fi
sudo cp uRamdisk /mnt/boot/initrd.img-$UNAME
if [ $? != 0 ]; then echo "ERROR"; exit; fi
sudo cp ${ANDROID_PRODUCT_OUT}/uEnv.txt /mnt/boot/
sudo mkenvimage -s 1024 -o/mnt/boot/uboot.env ${ANDROID_PRODUCT_OUT}/uEnv.txt
if [ $? != 0 ]; then echo "ERROR"; exit; fi
sudo cp $ANDROID_PRODUCT_OUT/am335x-boneblack-android.dtb /mnt/boot/dtbs/$UNAME
if [ $? != 0 ]; then echo "ERROR"; exit; fi
sudo cp $ANDROID_PRODUCT_OUT/zImage /mnt/boot/vmlinuz-$UNAME
if [ $? != 0 ]; then echo "ERROR"; exit; fi
sudo umount /mnt
# Copy disk images
echo "Writing system"
sudo dd if=${ANDROID_PRODUCT_OUT}/system.img of=$SYSTEM_PART bs=1M status=progress && sync
if [ $? != 0 ]; then echo "ERROR"; exit; fi
sudo e2label $SYSTEM_PART system
echo "Writing userdata (takes a long time)"
sudo dd if=${ANDROID_PRODUCT_OUT}/userdata.img of=$USER_PART bs=1M status=progress && sync
if [ $? != 0 ]; then echo "ERROR"; exit; fi
sudo e2label $USER_PART userdata
echo "Writing cache"
sudo dd if=${ANDROID_PRODUCT_OUT}/cache.img of=$CACHE_PART bs=1M status=progress && sync
if [ $? != 0 ]; then echo "ERROR"; exit; fi
sudo e2label $CACHE_PART cache
echo "SUCCESS! Android4Beagle installed on the uSD card. Enjoy"
exit 0