-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathtoolset.sh
executable file
·218 lines (166 loc) · 9.46 KB
/
toolset.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Copyright (C) 2018 Evgeny Golyshev <[email protected]>
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
toolchain_dir="gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf"
cross_compiler="${TOOLSET_FULL_PATH}/uboot-${UBOOT_VER}/${toolchain_dir}/bin/arm-linux-gnueabihf-"
toolchain_for_mender_dir="gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf"
cross_compiler_for_mender="${TOOLSET_FULL_PATH}/mender/${toolchain_for_mender_dir}/bin/arm-linux-gnueabihf-"
uboot_tools="${TOOLSET_FULL_PATH}/mender/uboot-mender/tools"
mendersoftware_dir="${TOOLSET_FULL_PATH}"/mender/client/src/mender/vendor/github.com/mendersoftware
info "checking Mender dependencies"
if $(are_mender_dependencies_satisfied); then
info "Mender dependencies are satisfied"
mender_dependencies_are_satisfied=true
else
info "Mender dependencies are not satisfied"
mender_dependencies_are_satisfied=false
fi
info "checking Das U-Boot dependencies"
if ! $(are_uboot_dependencies_satisfied) && [[ ! -d "${TOOLSET_FULL_PATH}/uboot-${UBOOT_VER}" ]]; then
fatal "Das U-Boot dependencies are not satisfied"
exit 1
else
info "Das U-Boot dependencies are satisfied"
fi
if $(init_installation_if_needed "${TOOLSET_FULL_PATH}/qemu-user-static"); then
info "fetching qemu-user-static"
pushd "${TOOLSET_FULL_PATH}/qemu-user-static"
get_qemu_emulation_binary
finalise_installation
popd
fi
if $(init_installation_if_needed "${TOOLSET_FULL_PATH}/apk"); then
info "fetching apk.static for Alpine Linux ${ALPINE_VER}"
pushd "${TOOLSET_FULL_PATH}"/apk
create_dir "${ALPINE_VER}"
addr=http://dl-cdn.alpinelinux.org/alpine/
apk_tools_version="$(get_apk_tools_version "${ALPINE_VER}")"
apk_tools_static="apk-tools-static-${apk_tools_version}.apk"
apk_tools_static_path="${TOOLSET_FULL_PATH}/apk/${ALPINE_VER}"
do_wget "${addr}/v${ALPINE_VER}/main/armhf/${apk_tools_static}" -O "${apk_tools_static_path}/${apk_tools_static}"
tar -xzf "${apk_tools_static_path}/${apk_tools_static}" -C "${apk_tools_static_path}"
mv "${apk_tools_static_path}/sbin/apk.static" "${apk_tools_static_path}"
finalise_installation \
"${apk_tools_static_path}/${apk_tools_static}" \
"${apk_tools_static_path}/sbin"
popd
fi
if [ ! -d "${TOOLSET_FULL_PATH}/debootstrap" ]; then
info "fetching debootstrap ${DEBOOTSTRAP_VER}"
pushd "${TOOLSET_FULL_PATH}"
git clone https://salsa.debian.org/installer-team/debootstrap.git
git -C debootstrap checkout "${DEBOOTSTRAP_VER}"
popd
else
info "checking if the debootstrap version is equal to or higher ${DEBOOTSTRAP_VER}"
if ! is_debootstrap_uptodate; then
pushd "${TOOLSET_FULL_PATH}"/debootstrap
info "upgrading debootstrap to ${DEBOOTSTRAP_VER}"
git checkout master
git pull
git checkout ${DEBOOTSTRAP_VER}
popd
fi
fi
if ${mender_dependencies_are_satisfied} && $(init_installation_if_needed "${TOOLSET_FULL_PATH}/mender"); then
pushd "${TOOLSET_FULL_PATH}/mender"
info "downloading inventory & identity scripts"
do_wget -q -O mender-device-identity "${MENDER_CLIENT_REPO}"/"${MENDER_CLIENT_REVISION}"/support/mender-device-identity
do_wget -q -O mender-inventory-bootloader-integration "${MENDER_CLIENT_REPO}"/"${MENDER_CLIENT_REVISION}"/support/mender-inventory-bootloader-integration
do_wget -q -O mender-inventory-hostinfo "${MENDER_CLIENT_REPO}"/"${MENDER_CLIENT_REVISION}"/support/mender-inventory-hostinfo
do_wget -q -O mender-inventory-network "${MENDER_CLIENT_REPO}"/"${MENDER_CLIENT_REVISION}"/support/mender-inventory-network
do_wget -q -O mender-inventory-os "${MENDER_CLIENT_REPO}"/"${MENDER_CLIENT_REVISION}"/support/mender-inventory-os
do_wget -q -O mender-inventory-rootfs-type "${MENDER_CLIENT_REPO}"/"${MENDER_CLIENT_REVISION}"/support/mender-inventory-rootfs-type
info "fetching cross-toolchain for building Das U-Boot (Mender flavour) and Mender client"
do_wget "https://releases.linaro.org/components/toolchain/binaries/6.3-2017.05/arm-linux-gnueabihf/${toolchain_for_mender_dir}.tar.xz" -O "${toolchain_for_mender_dir}.tar.xz"
info "unpacking archive with toolchain for building Das U-Boot (Mender flavour)"
tar xJf "${toolchain_for_mender_dir}.tar.xz"
rm "${toolchain_for_mender_dir}.tar.xz"
info "fetching Das U-Boot (Mender flavour) from https://github.com/mendersoftware/uboot-mender.git"
git clone https://github.com/mendersoftware/uboot-mender.git -b "${UBOOT_MENDER_BRANCH}"
git -C "uboot-mender" checkout "${UBOOT_MENDER_COMMIT}"
mkdir -p "${mendersoftware_dir}"
info "fetching Mender client from https://github.com/mendersoftware/mender.git"
git clone https://github.com/mendersoftware/mender.git "${mendersoftware_dir}"/mender
git -C "${mendersoftware_dir}"/mender checkout "${MENDER_CLIENT_VER}"
info "fetching Mender Artifacts Library from https://github.com/mendersoftware/mender-artifact.git"
git clone https://github.com/mendersoftware/mender-artifact.git "${mendersoftware_dir}"/mender-artifact
git -C "${mendersoftware_dir}"/mender-artifact checkout "${MENDER_ARTIFACT_VER}"
popd
pushd "${TOOLSET_FULL_PATH}/mender/uboot-mender"
info "building Das U-Boot (Mender flavour)"
ARCH=arm CROSS_COMPILE="${cross_compiler_for_mender}" make --quiet distclean
ARCH=arm CROSS_COMPILE="${cross_compiler_for_mender}" make rpi_3_32b_defconfig
ARCH=arm CROSS_COMPILE="${cross_compiler_for_mender}" make PYTHON=python2 -j $(number_of_cores)
ARCH=arm CROSS_COMPILE="${cross_compiler_for_mender}" make envtools -j $(number_of_cores)
cp "u-boot.bin" "${TOOLSET_FULL_PATH}/mender"
cp tools/env/fw_printenv "${TOOLSET_FULL_PATH}/mender"
info "generating image for Das U-Boot (Mender flavour)"
"${uboot_tools}"/mkimage -A arm -T script -C none -n "Boot script" -d "${PIEMAN_DIR}"/files/mender/boot.cmd "${TOOLSET_FULL_PATH}"/mender/boot.scr
popd
pushd "${mendersoftware_dir}"/mender
info "building Mender client"
env CGO_ENABLED=1 \
CC="${cross_compiler_for_mender}"gcc \
GOARCH=arm \
GOOS=linux \
GOPATH="${TOOLSET_FULL_PATH}"/mender/client make build
cp mender "${TOOLSET_FULL_PATH}"/mender
popd
pushd "${mendersoftware_dir}"/mender-artifact
info "building Mender Artifacts Library"
env GOPATH="${TOOLSET_FULL_PATH}"/mender/client make build
cp mender-artifact "${TOOLSET_FULL_PATH}"/mender
popd
pushd "${TOOLSET_FULL_PATH}/mender"
finalise_installation "${toolchain_for_mender_dir}" client uboot-mender
popd
fi
if $(init_installation_if_needed "${TOOLSET_FULL_PATH}/uboot-${UBOOT_VER}"); then
pushd "${TOOLSET_FULL_PATH}/uboot-${UBOOT_VER}"
info "fetching cross-toolchain for building Das U-Boot"
do_wget "https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/arm-linux-gnueabihf/${toolchain_dir}.tar.xz" -O "${toolchain_dir}.tar.xz"
info "unpacking archive with toolchain for building Das U-Boot"
tar xJf "${toolchain_dir}.tar.xz"
rm "${toolchain_dir}.tar.xz"
info "fetching Das U-Boot ${UBOOT_VER} from ${UBOOT_URL}"
git clone --depth=1 -b "v${UBOOT_VER}" https://github.com/u-boot/u-boot.git "u-boot-${UBOOT_VER}"
popd
pushd "${TOOLSET_FULL_PATH}/uboot-${UBOOT_VER}/u-boot-${UBOOT_VER}"
info "building Das U-Boot"
ARCH=arm CROSS_COMPILE="${cross_compiler}" make orangepi_pc_plus_defconfig
# The host system may have both Python 2 and 3 installed. U-Boot
# depends on Python 2, so it's necessary to specify it explicitly via
# the PYTHON variable.
ARCH=arm CROSS_COMPILE="${cross_compiler}" PYTHON=python2 make -j $(number_of_cores)
cp u-boot-sunxi-with-spl.bin "${TOOLSET_FULL_PATH}/uboot-${UBOOT_VER}"/u-boot-sunxi-with-spl-for-opi-pc-plus.bin
ARCH=arm CROSS_COMPILE="${cross_compiler}" make orangepi_zero_defconfig
ARCH=arm CROSS_COMPILE="${cross_compiler}" PYTHON=python2 make -j $(number_of_cores)
cp u-boot-sunxi-with-spl.bin "${TOOLSET_FULL_PATH}/uboot-${UBOOT_VER}"/u-boot-sunxi-with-spl-for-opi-zero.bin
cp tools/mkimage "${TOOLSET_FULL_PATH}/uboot-${UBOOT_VER}"
popd
pushd "${TOOLSET_FULL_PATH}/uboot-${UBOOT_VER}"
finalise_installation "${toolchain_dir}" "u-boot-${UBOOT_VER}" uboot-env
popd
fi
# Correct ownership if needed
pieman_dir_ownership="$(get_ownership "${PIEMAN_DIR}")"
if [ "$(get_ownership "${TOOLSET_FULL_PATH}")" != "${pieman_dir_ownership}" ]; then
info "correcting ownership for ${TOOLSET_FULL_PATH}"
chown -R "${pieman_dir_ownership}" "${TOOLSET_FULL_PATH}"
fi
if ${PREPARE_ONLY_TOOLSET}; then
success "exiting since PREPARE_ONLY_TOOLSET is set to true"
exit 0
fi