summaryrefslogtreecommitdiff
path: root/tool/rpi_sdcard_setup.sh
blob: 0dd3e49c221f6dfa2b87cc2588faac48be0c8876 (plain)
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
#! /bin/bash
download_dir=download
script_fusing=sd_fusing_rpi3.sh
binary_prefix=tizen-unified
binary_version=20170824.1
boot_img_name=common-boot-arm64-rpi3
platform_img_name=common-iot_core-2parts-armv7l-rpi3
usb_node=/dev/sdb
tmp_rfs_dir=$download_dir/rootfs

download_binaries() {
if [ ! -d $download_dir ]; then 
	mkdir -p $download_dir
else
	echo "download directory aleady exist"
fi

if [ ! -e $download_dir/$script_fusing ]; then
	wget https://git.tizen.org/cgit/platform/kernel/u-boot/plain/scripts/tizen/sd_fusing_rpi3.sh?h=tizen --output-document=$download_dir/$script_fusing
fi

chmod 755 $download_dir/$script_fusing

if [ ! -e $download_dir/brcmfmac43430-sdio.bin ]; then
	wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.bin -P $download_dir
fi

if [ ! -e $download_dir/brcmfmac43430-sdio.txt ]; then
	wget https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.txt -P $download_dir
fi

if [ ! -e $download_dir/BCM43430A1.hcd ]; then
	wget https://github.com/OpenELEC/misc-firmware/raw/master/firmware/brcm/BCM43430A1.hcd -P $download_dir
fi

if [ ! -e $download_dir/$boot_img ]; then
	wget http://download.tizen.org/snapshots/tizen/unified/${binary_prefix}_${binary_version}/images/standard/${boot_img_name}/$boot_img -P $download_dir
fi

if [ ! -e $download_dir/$platform_img ]; then
	wget http://download.tizen.org/snapshots/tizen/unified/${binary_prefix}_${binary_version}/images/standard/${platform_img_name}/$platform_img -P $download_dir
fi
}

fusing_sdcard() {
sudo /bin/bash $download_dir/$script_fusing -d $usb_node --format
sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$boot_img
sudo /bin/bash $download_dir/$script_fusing -d $usb_node -b $download_dir/$platform_img
}

copy_firmware() {
mkdir -p $tmp_rfs_dir
sudo mount ${usb_node}2 $tmp_rfs_dir
sudo mkdir -p $tmp_rfs_dir/usr/etc/bluetooth
sudo cp $download_dir/BCM43430A1.hcd $tmp_rfs_dir/usr/etc/bluetooth
sudo mkdir -p $tmp_rfs_dir/usr/lib/firmware/brcm
sudo cp $download_dir/brcmfmac43430-sdio.* $tmp_rfs_dir/usr/lib/firmware/brcm
sync
sudo umount $tmp_rfs_dir
rmdir $tmp_rfs_dir
}

display_help() {
    echo "Usage: $0 [dev node of usb] [binary version]"
    echo "example : $0 /dev/sdb 20170824.1" 
    exit 1
}


################################
#set -x

#if [ $# -lt 2 ] ; then
#	display_help
#fi

echo "########### Your Storage Device nodes ############"
echo
lsblk
echo
echo "##################################################"
echo
echo "Please enter device node of usb[enter to use default($usb_node) : "
read input_node
if [ "$input_node" = "" ]; then
	echo "###########  use default dev node : ${usb_node}"
else
	if [ "$input_node" = "/dev/sda" ]; then
		echo "[ERROR] /dev/sda is your main storage"
		exit 1
	fi
	usb_node=${input_node}
	echo "###########  use dev node : $usb_node"
fi

echo "Please enter binary version of usb[enter to use default($binary_version) : "
read input_version
if [ "$input_version" = "" ]; then
	echo "###########  use default version : $binary_version"
else
	binary_version=$input_version
	echo "###########  use binary version : $binary_version"
fi

boot_img=${binary_prefix}_${binary_version}_${boot_img_name}.tar.gz
platform_img=${binary_prefix}_${binary_version}_${platform_img_name}.tar.gz

download_binaries

sleep 5

fusing_sdcard
copy_firmware