-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.sh
executable file
·303 lines (281 loc) · 8.74 KB
/
build.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/bin/bash
usage () {
echo "usage: $0 <command> [<args>]"
echo
echo "Commands:"
echo " dev-build build PC Engines firmware from given path"
echo " release build PC Engines firmware from branch/tag/commit of"
echo " upstream or PC Engines fork of coreboot"
echo " release-CI release command prepared to be run in Gitlab CI"
echo
echo "dev-build: $0 dev-build <path> <platform> [<menuconfig_param>]"
echo " <path> path to coreboot source"
echo " <platform> apu1, apu2, apu3, apu4 or apu5"
echo " <menuconfig_param> menuconfig interface, give 'help' for more information"
echo
echo "release: $0 release <ref> <platform>"
echo " <ref> valid reference branch, tag or commit"
echo " <platform> apu1, apu2, apu3, apu4 or apu5"
echo " <menuconfig_param> menuconfig interface, give 'help' for more information"
echo
echo "Used SDK version can be overridden by environment variable SDK_VER e.g."
echo "SDK_VER=psec2019 ./build.sh dev-build apu2"
echo "will use pcengines/pcw-fw-builder:psec2019 container"
echo
exit
}
check_if_legacy() {
product_version=${1//v/}
case "$product_version" in
4\.0\.1[7-9]*)
return 1
;;
4\.0\.[2-9][0-9]*)
return 1
;;
4\.0\.1[0-6]*)
return 2
;;
4\.0\.[1-9][^0-9]*)
return 2
;;
4\.0\.[1-9])
return 2
;;
4\.[1-9][0-9]*)
return 0
;;
4\.[1-5]\.*)
return 2
;;
4\.6\.[2-8]*)
return 2
;;
4\.6\.[0-1])
return 2
;;
4\.6\.9)
return 0
;;
4\.6\.1[0-9])
return 0
;;
4\.1[^0-9]*)
return 1
;;
4\.[7-9]*)
return 0
;;
24\.[0-9][0-9]*)
return 0
;;
*)
return 2
exit
;;
esac
}
check_version () {
product_version=${1//v/}
semver=( ${product_version//./ } )
major="${semver[0]:-0}"
minor="${semver[1]:-0}"
patch="${semver[2]:-0}"
if [ $major -ge 4 ]; then
if [ $minor -eq 0 -a $patch -le 16 ]; then
echo "ERROR: version unsupported ($product_version < 4.0.17)"
exit 1
elif [ $minor -eq 6 -a $patch -le 9 ]; then
echo "ERROR: version unsupported ($product_version < 4.6.10)"
exit 1
fi
else
echo "ERROR: version unsupported ($product_version < 4.0.17 || $product_version < 4.6.10)"
exit 1
fi
}
check_sdk_version () {
product_version=${1//v/}
semver=( ${product_version//./ } )
major="${semver[0]:-0}"
minor="${semver[1]:-0}"
patch="${semver[2]:-0}"
release="${semver[3]:-0}"
sslverify=true
if [ ! -z "${SDK_VER}" ]; then
sdk_ver=$SDK_VER
return 0
fi
if [ $major -ge 24 ]; then
if [ "$minor" == "05" ]; then
sdk_ver=2024-03-30_cccada28f7
return 0
fi
elif [ $major -ge 4 ]; then
if [ $minor -ge 15 ] || ( [ $minor -ge 14 ] && [ $release -ge 5 ] ); then
# for >= 4.14.0.5 use newer SDK with updated ca-certificates
sdk_ver=2.0.0
return 0
elif [ $minor -ge 9 ]; then
# for >= v4.9.x.x use older SDK with SSL disabled
sdk_ver=1.52.6
sslverify=false
return 0
elif [ $minor -lt 9 ]; then
# for versions < 4.9.x.x use legacy SDK
sdk_ver=1.50.1
return 0
fi
fi
# should not happen
sdk_ver=latest
sslverify=true
}
dev_build() {
# remove dev-build from options
shift
cb_path="`realpath $1`"
pushd $cb_path
tag=$(git describe --tags --abbrev=0)
check_version $tag
if [[ ${tag:0:1} == "v" ]] ; then tag=${tag:1}; fi
check_if_legacy $tag
legacy=$?
popd
# remove coreboot path
shift
# Save uid and gid from executing user, file permissions fix for users with uid!=1000
USER_ID=`id -u`
GROUP_ID=`id -g`
if [ "$legacy" == 1 ]; then
echo "Dev-build coreboot legacy"
docker run --rm -it -v $cb_path:/home/coreboot/coreboot \
-e USER_ID=$USER_ID -e GROUP_ID=$GROUP_ID \
-v $PWD/scripts:/home/coreboot/scripts pcengines/pce-fw-builder-legacy:latest \
/home/coreboot/scripts/pce-fw-builder.sh $legacy $*
elif [ "$legacy" == 0 ]; then
sdk_ver=latest
sslverify=true
check_sdk_version $tag
echo "Dev-build coreboot mainline"
if [ ! -d "$PWD/ccache" ]; then
mkdir $PWD/ccache
fi
docker run --rm -it -v $cb_path:/home/coreboot/coreboot \
-e USER_ID=$USER_ID -e GROUP_ID=$GROUP_ID \
-v $PWD/ccache:/home/coreboot/.ccache \
-v $PWD/scripts:/home/coreboot/scripts pcengines/pce-fw-builder:$sdk_ver \
/home/coreboot/scripts/pce-fw-builder.sh $legacy $sslverify $*
elif [[ $legacy == 2 ]]; then
echo "$tag3 is UNSUPPORTED"
else
echo "ERROR: Exit"
exit
fi
}
release() {
if [ -d release ]; then
sudo rm -rf release
fi
# remove release from options
shift
mkdir release
git clone https://review.coreboot.org/coreboot.git release/coreboot
cd release/coreboot
git submodule update --init --checkout
git remote add pcengines https://github.com/pcengines/coreboot.git
git fetch pcengines
# fetch tags additionally, sometimes git fetch does not find all revisions
git fetch pcengines -t
git checkout -f $1
git submodule update --init --checkout
tag=$(git describe --tags --abbrev=0 ${1})
check_version $tag
if [[ ${tag:0:1} == "v" ]] ; then tag=${tag:1}; fi
check_if_legacy $tag
legacy=$?
cd ../..
VERSION=$1
OUT_FILE_NAME="$2_${VERSION}.rom"
# remove tag|branch from options
shift
# Save uid and gid from executing user, file permissions fix for users with uid!=1000
USER_ID=`id -u`
GROUP_ID=`id -g`
if [ "$legacy" == 1 ]; then
echo "Release $1 build coreboot legacy"
docker run --rm -it -v $PWD/release/coreboot:/home/coreboot/coreboot \
-e USER_ID=$USER_ID -e GROUP_ID=$GROUP_ID \
-v $PWD/scripts:/home/coreboot/scripts pcengines/pce-fw-builder-legacy:latest \
/home/coreboot/scripts/pce-fw-builder.sh $legacy $*
elif [ "$legacy" == 0 ]; then
sdk_ver=latest
sslverify=true
check_sdk_version $tag
echo "Release $1 build coreboot mainline"
docker run --rm -it -v $PWD/release/coreboot:/home/coreboot/coreboot \
-e USER_ID=$USER_ID -e GROUP_ID=$GROUP_ID \
-v $PWD/scripts:/home/coreboot/scripts pcengines/pce-fw-builder:$sdk_ver \
/home/coreboot/scripts/pce-fw-builder.sh $legacy $sslverify $*
elif [[ $legacy == 2 ]]; then
echo "$tag3 is UNSUPPORTED"
else
echo "ERROR: Exit"
exit
fi
cd release
cp coreboot/build/coreboot.rom "${OUT_FILE_NAME}"
sha256sum "${OUT_FILE_NAME}"
}
release_ci() {
# remove release-CI from options
shift
# increase the buffer to avoid unexpected remote hangs
git config --global http.postBuffer 1048576000
git clone --depth=1 https://review.coreboot.org/coreboot.git /home/coreboot/coreboot
cd /home/coreboot/coreboot || exit 1
git submodule update --init --checkout
git remote add pcengines https://github.com/pcengines/coreboot.git
git fetch pcengines
# fetch tags additionally, sometimes git fetch does not find all revisions
git fetch pcengines -t
git checkout -f $1
git submodule update --init --checkout
tag=$(git describe --tags --abbrev=0 ${1})
check_version $tag
if [[ ${tag:0:1} == "v" ]] ; then tag=${tag:1}; fi
check_if_legacy $tag
legacy=$?
# always verify ssl certificates in CI
sslverify=true
cd /home/coreboot/pce-fw-builder
VERSION=$1
OUT_FILE_NAME="$2_${VERSION}.rom"
# remove tag|branch from options
shift
scripts/pce-fw-builder.sh $legacy $sslverify $*
pwd
ls -al /home/coreboot/coreboot/build/
if [ ! -d /home/coreboot/release ]; then
mkdir -p /home/coreboot/release
fi
cp /home/coreboot/coreboot/build/coreboot.rom /home/coreboot/"${OUT_FILE_NAME}"
sha256sum /home/coreboot/"${OUT_FILE_NAME}"
}
case "$1" in
help)
usage
;;
dev-build)
dev_build $*
;;
release)
release $*
;;
release-CI)
release_ci $*
;;
*)
usage
;;
esac