forked from friendlyarm/sd-fuse_rk3328
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-uboot.sh
executable file
·170 lines (144 loc) · 4.65 KB
/
build-uboot.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
set -eu
# Copyright (C) Guangzhou FriendlyARM Computer Tech. Co., Ltd.
# (http://www.friendlyarm.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can access it online at
# http://www.gnu.org/licenses/gpl-2.0.html.
true ${SOC:=rk3328}
true ${DISABLE_MKIMG:=0}
UBOOT_REPO=https://github.com/friendlyarm/uboot-rockchip
UBOOT_BRANCH=nanopi4-v2014.10_oreo
ARCH=arm64
UCFG=nanopi_r2_defconfig
CROSS_COMPILE=aarch64-linux-
TOPPATH=$PWD
OUT=$TOPPATH/out
if [ ! -d $OUT ]; then
echo "path not found: $OUT"
exit 1
fi
true ${UBOOT_SRC:=${OUT}/uboot-${SOC}}
echo "uboot src: ${UBOOT_SRC}"
# You need to install:
# apt-get install swig python-dev python3-dev
function usage() {
echo "Usage: $0 <friendlycore-arm64|friendlywrt>"
echo "# example:"
echo "# clone uboot source from github:"
echo " git clone ${UBOOT_REPO} --depth 1 -b ${UBOOT_BRANCH} ${UBOOT_SRC}"
echo "# or clone your local repo:"
echo " git clone [email protected]:/path/to/uboot.git --depth 1 -b ${UBOOT_BRANCH} ${UBOOT_SRC}"
echo "# then"
echo " ./build-uboot.sh friendlycore-arm64 "
echo " ./mk-emmc-image.sh friendlycore-arm64 "
echo "# also can do:"
echo " UBOOT_SRC=~/myuboot ./build-uboot.sh friendlycore-arm64"
exit 0
}
if [ $# -ne 1 ]; then
usage
fi
# ----------------------------------------------------------
# Get target OS
true ${TARGET_OS:=${1,,}}
RKPARAM=./${TARGET_OS}/parameter.txt
RKPARAM2=./${TARGET_OS}/param4sd.txt
case ${TARGET_OS} in
friendlycore* | friendlywrt | eflasher)
;;
*)
echo "Error: Unsupported target OS: ${TARGET_OS}"
exit 0
esac
# Automatically re-run script under sudo if not root
# if [ $(id -u) -ne 0 ]; then
# echo "Re-running script under sudo..."
# sudo UBOOT_SRC=${UBOOT_SRC} DISABLE_MKIMG=${DISABLE_MKIMG} "$0" "$@"
# exit
# fi
download_img() {
if [ -f "${RKPARAM}" -o -f "${RKPARAM2}" ]; then
echo ""
else
ROMFILE=`./tools/get_pkg_filename.sh ${1}`
cat << EOF
Warn: Image not found for "${1}"
----------------
you may download them from the netdisk (dl.friendlyarm.com) to get a higher downloading speed,
the image files are stored in a directory called images-for-eflasher, for example:
tar xvzf /path/to/NETDISK/images-for-eflasher/${ROMFILE}
----------------
Or, download from http (Y/N)?
EOF
while read -r -n 1 -t 3600 -s USER_REPLY; do
if [[ ${USER_REPLY} = [Nn] ]]; then
echo ${USER_REPLY}
exit 1
elif [[ ${USER_REPLY} = [Yy] ]]; then
echo ${USER_REPLY}
break;
fi
done
if [ -z ${USER_REPLY} ]; then
echo "Cancelled."
exit 1
fi
./tools/get_rom.sh "${1}" || exit 1
fi
}
if [ ! -d ${UBOOT_SRC} ]; then
git clone ${UBOOT_REPO} --depth 1 -b ${UBOOT_BRANCH} ${UBOOT_SRC}
fi
if [ ! -d /opt/FriendlyARM/toolchain/6.4-aarch64 ]; then
echo "please install aarch64-gcc-6.4 first, using these commands: "
echo "\tgit clone https://github.com/friendlyarm/prebuilts.git -b master --depth 1"
echo "\tcd prebuilts/gcc-x64"
echo "\tcat toolchain-6.4-aarch64.tar.gz* | sudo tar xz -C /"
exit 1
fi
export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH
if ! [ -x "$(command -v simg2img)" ]; then
sudo apt install android-tools-fsutils
fi
if ! [ -x "$(command -v swig)" ]; then
sudo apt install swig
fi
# get include path for this python version
INCLUDE_PY=$(python -c "from distutils import sysconfig as s; print s.get_config_vars()['INCLUDEPY']")
if [ ! -f "${INCLUDE_PY}/Python.h" ]; then
sudo apt install python-dev python3-dev
fi
cd ${UBOOT_SRC}
make distclean
make CROSS_COMPILE=${CROSS_COMPILE} ${UCFG}
make CROSS_COMPILE=${CROSS_COMPILE} -j$(nproc)
if [ $? -ne 0 ]; then
echo "failed to build uboot."
exit 1
fi
if [ x"$DISABLE_MKIMG" = x"1" ]; then
exit 0
fi
echo "building uboot ok."
cd ${TOPPATH}
download_img ${TARGET_OS}
./tools/update_uboot_bin.sh ${OUT} ${UBOOT_SRC} ${TOPPATH}/${TARGET_OS}
if [ $? -eq 0 ]; then
echo "updating ${TARGET_OS}/bootloader.img ok."
else
echo "failed."
exit 1
fi
exit 0