-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathre-run.sh
More file actions
executable file
·383 lines (349 loc) · 14.4 KB
/
re-run.sh
File metadata and controls
executable file
·383 lines (349 loc) · 14.4 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
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/bin/bash
source $PWD/defaults.set 2>/dev/null && rm -f defaults.set
source $PWD/choices.set 2>/dev/null && rm -f choices.set
env | sort >> env/re-run.env && echo "" >> env/re-run.env
mv build.info tmp && echo "Starting Build: $(date -u '+on %D at %R UTC')" > build.info && cat tmp >> build.info && rm -f tmp
echo "Starting Build: $(date -u '+on %D at %R UTC')"
ARCHS=$(echo $ARCHS | tr ' ' '\n' | sort -u | tr '\n' ' ')
TARGETS=$(echo $TARGETS | tr ' ' '\n' | sort -u | tr '\n' ' ')
BUILDT="--driver docker-container --driver-opt \"network=host\""
BUILDK="--buildkitd-flags \"--oci-worker-rootless=true\" $BUILDT --name U-Boot-Builder"
docker='/snap/docker/current/bin/docker'
if [ "$TARGETS" != "" ]; then
echo "TARGET: $TARGETS"
export TARGET="$TARGETS"
fi
if [ "$CHECK" = "yes" ]; then
echo "CHECK REPRODUCIBILITY: $6"
export check_file=1
fi
if [ "$MOUNT" != "" ]; then
echo "MOUNT: /dev/$MOUNT"
export mount="$MOUNT"
export unmount="unmount"
fi
if [ "$CR_C" = "yes" ]; then
echo "CROSS_COMPILE: $CR_C"
export CROSS="--platform linux/arm64"
export cross="cross"
fi
if [ "$CLEAN" = "yes" ]; then
echo "CLEAN_BUILD: $CLEAN"
export remove="remove"
else
echo "CLEAN_BUILD: $CLEAN"
fi
if [ "$EPOCH" != "" ]; then
echo "SOURCE_DATE_EPOCH: $EPOCH"
export source_date_epoch=$EPOCH
source_date="@$source_date_epoch"
echo "SOURCE_DATE: $source_date"
build_message_timestamp="$(date +'%b %d %Y - 00:00:00 +0000' -d $source_date)";
echo "BUILD_MESSAGE_TIMESTAMP: $build_message_timestamp"
fi
stop() { # $1 = Name
if [[ "$TARGET" == *$1* ]]; then
$docker cp $1:/.env Results/env/$1.env
$docker stop $1 > /dev/null && echo "$1 stopped" && $docker rm --volumes $1 > /dev/null && echo "$1 removed"
if [[ "$cross" == "" && "$DEV" == *no* ]]; then
$docker buildx rm U-Boot-Builder-$1
fi
fi
}
if [ "$DEV" = "yes" ]; then
echo "DEV_BUILD: $DEV"
CACHE="--cache-to type=local,dest=.git/Cache,mode=max --cache-from type=local,src=.git/Cache"
load() { # $1 = Name
if [[ "$TARGET" == *$1* ]]; then
stop $NAME
export LOAD="--load $CROSS $CACHE --target $1 --tag $1"
fi
export NAME=$1
}
else
export BUILDX_METADATA_PROVENANCE=max
export BUILDX_METADATA_WARNINGS=1
export install="install"
export signing=1
load() { # $1 Name
if [[ "$TARGET" == *$1* ]]; then
if [ "$cross" = "" ]; then
$docker buildx create $BUILDK-$1 --node u-boot-builder-$1 --bootstrap --use
fi
stop $NAME
export LOAD="--load $CROSS --target $1 --tag $1 --metadata-file Results/$1/$1.meta.json"
fi
export NAME=$1
}
fi
init_runner() {
export DOCKER_HOST=unix:///run/user/1000/docker.sock
sleep 15
cp $HOME/tmp/log Results/logs/rootless.log
cp $HOME/tmp/environment-docker Results/env/rootless.env
$docker info | grep rootless >> Results/logs/rootless.log
if [[ "$cross" == "cross" || "$DEV" == *yes* ]]; then
$docker buildx create $CROSS $BUILDT --name U-Boot-Builder --node u-boot-builder-0 --bootstrap --use
if [[ "$cross" = "cross" ]]; then
$docker run --privileged --rm tonistiigi/binfmt:qemu-v10.0.4-56 --install arm64
fi
fi
}
scan_using_grype() { # $1 = Name, $2 = Type:[Name]
if [ "$DEV" != "yes" ]; then
pushd Results/$1
TMPDIR="$HOME/.local/share/docker/tmp" SYFT_CACHE_DIR="$HOME/.local/share/docker/tmp" syft scan $2 -o spdx-json=$1.spdx.json
script -q -c "TMPDIR='$HOME/.local/share/docker/tmp' GRYPE_DB_CACHE_DIR='$HOME/.local/share/docker/tmp' grype $GRCONF sbom:$1.spdx.json -o json > $1.grype.json" $1.grype.tmp.tmp > $1.grype.tmp
marker() { # $1 = Name, $2 = Order, $3 = Marker/ID
grep "$3" $1.grype.tmp | tail -n 1 > $1.grype.status.$2
tr -d '\000-\037\177' < $1.grype.status.$2 | sed '/^$/d' > $1.grype.status.$2.tmp
line1=$(<"${1}.grype.status.${2}.tmp")
left1="${line1%%' [K[2A'*}"
right1="${line1#*' [K[2A'}"
if [[ "$right1" == *$3* ]]; then
export "wright$2"="${right1%%' [K'*}"
elif [[ "$left1" == *$3* ]]; then
export "wright$2"="${left1%%' [K'*}"
fi
}
marker $1 1 "✔ Scanned for vulnerabilities"
marker $1 2 "├── by severity:"
marker $1 3 "└── by status:"
echo $wright1 > $1.grype.status
echo $wright2 >> $1.grype.status
echo $wright3 >> $1.grype.status
sed -i "s'\[K''" $1.grype.status
sed -i "s'\[2A''" $1.grype.status
rm -f $1.grype.tmp*
rm -f $1.grype.status.*
cat $1.grype.status
popd
else
wait
fi
}
pushd ..
./install.sh run.install \"$install\" \"$remove\" $(whoami) \"$cross\" $mount
init_runner
load base
if [[ "$TARGET" == *$NAME* ]]; then
$docker buildx build $LOAD \
--build-arg HUB=$HUB \
--build-arg BASE=$BASE \
--build-arg ENTRYPOINT=u-boot \
-f Dockerfile .
fi
load base_extra
if [[ "$TARGET" == *$NAME* ]]; then
$docker buildx build $LOAD \
--build-arg HUB=$HUB \
--build-arg BASE_EXTRA=$BASE_EXTRA \
--build-arg ENTRYPOINT=u-boot \
-f Dockerfile .
fi
load crosstool-ng
if [[ "$TARGET" == *$NAME* ]]; then
$docker buildx build $LOAD \
--build-arg SOURCE_DATE_EPOCH=$source_date_epoch \
--build-arg CROSS_VER=$CROSS_VER \
--build-arg CROSS_SUM=$CROSS_SUM \
--build-arg HUB=$HUB \
--build-arg BASE_EXTRA=$BASE_EXTRA \
--build-arg ENTRYPOINT=$NAME \
-f Dockerfile .
scan_using_grype $NAME docker:$NAME
$docker run -it --cpus=$(nproc) \
--name $NAME $CROSS \
--network=name=host,\"driver-opt=network=host\" \
-e SOURCE_DATE_EPOCH=$source_date_epoch \
-e CROSS_VER=$CROSS_VER \
$NAME
$docker cp $NAME:/home/cross/x-tools/aarch64-unknown-linux-gnu/bin/. Builds/rk3399/
sha512sum Builds/rk3399/aarch64-* && sha512sum Builds/rk3399/aarch64-* >> Results/release.sha512sum
openssl dgst -SHA3-256 Builds/rk3399/aarch64-* && openssl dgst -SHA3-256 Builds/rk3399/aarch64-* >> Results/release.sha3sum
fi
load edk2
if [[ "$TARGET" == *$NAME* ]]; then
$docker buildx build $LOAD \
--build-arg SOURCE_DATE_EPOCH=$source_date_epoch \
--build-arg EDKP_VER=$EDKP_VER \
--build-arg EDKP_SUM=$EDKP_SUM \
--build-arg EDK_VER=$EDK_VER \
--build-arg HUB=$HUB \
--build-arg BASE=$BASE \
--build-arg ENTRYPOINT=$NAME \
-f Dockerfile .
scan_using_grype $NAME docker:$NAME
$docker run -it --cpus=$(nproc) \
--name $NAME $CROSS \
-e SOURCE_DATE_EPOCH=$source_date_epoch \
-e EDKP_VER=$EDKP_VER \
-e EDK_VER=$EDK_VER \
-e WORKSPACE=/ \
-e PACKAGES_PATH="/edk2-$(echo $EDK_VER):/edk2-platforms-$(echo $EDKP_VER)" \
-e ACTIVE_PLATFORM="Platform/StandaloneMm/PlatformStandaloneMmPkg/PlatformStandaloneMmRpmb.dsc" \
-e GCC5_AARCH64_PREFIX="aarch64-linux-gnu-" \
$NAME
$docker cp $NAME:/Build/MmStandaloneRpmb/RELEASE_GCC5/FV/BL32_AP_MM.fd Builds/rk3399/BL32_AP_MM.fd
sha512sum Builds/rk3399/BL32_AP_MM.fd && sha512sum Builds/rk3399/BL32_AP_MM.fd >> Results/release.sha512sum
openssl dgst -SHA3-256 Builds/rk3399/BL32_AP_MM.fd && openssl dgst -SHA3-256 Builds/rk3399/BL32_AP_MM.fd >> Results/release.sha3sum
fi
load openssl
if [[ "$TARGET" == *$NAME* ]]; then
$docker buildx build $LOAD \
--build-arg SOURCE_DATE_EPOCH=$source_date_epoch \
--build-arg SSL_VER=$SSL_VER \
--build-arg SSL_SUM=$SSL_SUM \
--build-arg HUB=$HUB \
--build-arg BASE=$BASE \
--build-arg ENTRYPOINT=$NAME \
-f Dockerfile .
scan_using_grype $NAME docker:$NAME
$docker run -it --cpus=$(nproc) \
--name $NAME $CROSS \
-e SOURCE_DATE_EPOCH=$source_date_epoch \
-e SSL_VER=$SSL_VER \
$NAME
$docker cp $NAME:/SSL/include/openssl/. Builds/rk3399/openssl/
sha512sum Builds/rk3399/openssl/* && sha512sum Builds/rk3399/openssl/* >> Results/release.sha512sum
openssl dgst -SHA3-256 Builds/rk3399/openssl/* && openssl dgst -SHA3-256 Builds/rk3399/openssl/* >> Results/release.sha3sum
fi
load optee
if [[ "$TARGET" == *$NAME* ]]; then
$docker buildx build $LOAD \
--build-arg SOURCE_DATE_EPOCH=$source_date_epoch \
--build-arg OPT_VER=$OPT_VER \
--build-arg OPT_SUM=$OPT_SUM \
--build-arg OPT_SUM2=$OPT_SUM2 \
--build-arg TPM_SUM=$TPM_SUM \
--build-arg ROT_SUM=$ROT_SUM \
--build-arg HUB=$HUB \
--build-arg BASE_EXTRA=$BASE_EXTRA \
--build-arg ENTRYPOINT=$NAME \
-f Dockerfile .
scan_using_grype $NAME docker:$NAME
$docker run -it --cpus=$(nproc) \
--name $NAME $CROSS \
-e SOURCE_DATE_EPOCH=$source_date_epoch \
-e OPT_VER=$OPT_VER \
-e ARCHS="$ARCHS" \
$NAME
for arch in $ARCHS
do
for tpm in ":-tpm" "/NOTPM:"
do
tpm=$(echo $tpm | cut -d':' -f2)
$docker cp $NAME:$(echo $tpm | cut -d':' -f1)/$arch/optee_os-$OPT_VER/out/arm-plat-rockchip/core/tee.bin Builds/$arch/tee$tpm.bin
sha512sum Builds/$arch/tee$tpm.bin && sha512sum Builds/$arch/tee$tpm.bin >> Results/release.sha512sum
openssl dgst -SHA3-256 Builds/$arch/tee$tpm.bin && openssl dgst -SHA3-256 Builds/$arch/tee$tpm.bin >> Results/release.sha3sum
done
done
fi
load arm-trusted
if [[ "$TARGET" == *$NAME* ]]; then
$docker buildx build $LOAD \
--build-arg SOURCE_DATE_EPOCH=$source_date_epoch \
--build-arg BUILD_MESSAGE_TIMESTAMP="$build_message_timestamp" \
--build-arg ATF_VER=$ATF_VER \
--build-arg ATF_SUM=$ATF_SUM \
--build-arg MTLS_VER=$MTLS_VER \
--build-arg MTLS_SUM=$MTLS_SUM \
--build-arg HUB=$HUB \
--build-arg BASE=$BASE \
--build-arg ENTRYPOINT=$NAME \
-f Dockerfile .
scan_using_grype $NAME docker:$NAME
$docker run -it --cpus=$(nproc) \
--name $NAME $CROSS \
-e SOURCE_DATE_EPOCH=$source_date_epoch \
-e BUILD_MESSAGE_TIMESTAMP="$build_message_timestamp" \
-e ATF_VER=$ATF_VER \
-e ARCHS="$ARCHS" \
$NAME
for arch in $ARCHS
do
$docker cp $NAME:/$arch/arm-trusted-firmware-$ATF_VER/build/$arch/release/bl31/bl31.elf Builds/$arch/
sha512sum Builds/$arch/bl31.elf && sha512sum Builds/$arch/bl31.elf >> Results/release.sha512sum
openssl dgst -SHA3-256 Builds/$arch/bl31.elf && openssl dgst -SHA3-256 Builds/$arch/bl31.elf >> Results/release.sha3sum
done
fi
load u-boot
if [[ "$TARGET" == *$NAME* ]]; then
$docker buildx build $LOAD \
--build-arg SOURCE_DATE_EPOCH=$source_date_epoch \
--build-arg UB_VER=$UB_VER \
--build-arg UB_SUM=$UB_SUM \
--build-arg HUB=$HUB \
--build-arg BASE=$BASE \
--build-arg ENTRYPOINT=$NAME \
-f Dockerfile .
scan_using_grype $NAME docker:$NAME
$docker run -it --cpus=$(nproc) \
--name $NAME $CROSS \
-e SOURCE_DATE_EPOCH=$source_date_epoch \
-e SOURCE_DATE=$source_date \
-e UB_VER=$UB_VER \
-e BUILD_LIST="$BUILD_LIST" \
-e DEV_BUILD=$DEV \
$NAME
for dev in $LIST
do
for loc in $VARIANTS
do
$docker cp $NAME:/$dev$loc/. Builds/
sha512sum Builds/$dev$loc/u-boot-rockchip.bin && sha512sum Builds/$dev$loc/u-boot-rockchip.bin >> Results/release.sha512sum
openssl dgst -SHA3-256 Builds/$dev$loc/u-boot-rockchip.bin && openssl dgst -SHA3-256 Builds/$dev$loc/u-boot-rockchip.bin >> Results/release.sha3sum
sha512sum Builds/$dev$loc/u-boot-rockchip-spi.bin && sha512sum Builds/$dev$loc/u-boot-rockchip-spi.bin >> Results/release.sha512sum
openssl dgst -SHA3-256 Builds/$dev$loc/u-boot-rockchip-spi.bin && openssl dgst -SHA3-256 Builds/$dev$loc/u-boot-rockchip-spi.bin >> Results/release.sha3sum
done
$docker cp $NAME:/$dev/. Builds/
sha512sum Builds/$dev/u-boot-rockchip.bin && sha512sum Builds/$dev/u-boot-rockchip.bin >> Results/release.sha512sum
openssl dgst -SHA3-256 Builds/$dev/u-boot-rockchip.bin && openssl dgst -SHA3-256 Builds/$dev/u-boot-rockchip.bin >> Results/release.sha3sum
sha512sum Builds/$dev/u-boot-rockchip-spi.bin && sha512sum Builds/$dev/u-boot-rockchip-spi.bin >> Results/release.sha512sum
openssl dgst -SHA3-256 Builds/$dev/u-boot-rockchip-spi.bin && openssl dgst -SHA3-256 Builds/$dev/u-boot-rockchip-spi.bin >> Results/release.sha3sum
done
$docker cp $NAME:/sys.info Results/sys.info
fi
load ubuntu
if [[ "$TARGET" == *$NAME* ]]; then
scan_using_grype ubuntu "/ --select-catalogers debian"
fi
./install.sh run.uninstall \"$remove\" \"$unmount\"
load u-boot
if [[ "$TARGET" == *$NAME* ]]; then
if [ "$DEV" != "yes" ]; then
mkfs.fat -i 00000000 -n "U-BOOT" --invariant -C /tmp/sdcard.img 35000
for dev in $LIST
do
for loc in $VARIANTS
do
pushd Builds/$dev$loc/
echo "dc3272192cb9339d79bc1b8d6066ba056e2d7f952313688085f8009d221f692842f6cd0f378bd83c22dfcd2b5b266e8b0c6805ae5c9a05b4ffe0edefe7b4d079 /tmp/sdcard.img" | sha512sum -c - && wait || exit 1
cp /tmp/sdcard.img sdcard.img && mount sdcard.img /mnt
cp u-boot-rockchip.bin /mnt/u-boot-rockchip.bin
cp u-boot-rockchip-spi.bin /mnt/u-boot-rockchip-spi.bin
touch -d "$(date -R -d $source_date)" /mnt/*
touch -d "$(date -R -d $source_date)" /mnt
touch -c -d "$(date -R -d $source_date)" /mnt/*
touch -c -d "$(date -R -d $source_date)" /mnt
touch -a -d "$(date -R -d $source_date)" /mnt/*
touch -a -d "$(date -R -d $source_date)" /mnt
dd if=/mnt/u-boot-rockchip.bin of=sdcard.img seek=64 conv=notrunc status=progress
sync && umount /mnt
popd
sha512sum Builds/$dev$loc/sdcard.img >> Results/release.sha512sum
done
done
rm -f /tmp/sdcard.img
fi
fi
stop $NAME
popd
echo "0mniteck's Current GPG Key ID: 287EE837E6ED2DD3" >> build.info
echo "Base Build System: $(uname -o) $(uname -r) $(uname -m) $(lsb_release -ds) $(lsb_release -cs) $(uname -v)" >> build.info && cat sys.info >> build.info
echo "Build Complete: $(date -u '+on %D at %R UTC')" >> build.info && echo "Build Complete: $(date -u '+on %D at %R UTC')"
if [ "$check_file" = "1" ]; then
cp /tmp/release.last.sha512sum release.last.sha512sum && cp /tmp/release.last.sha3sum release.last.sha3sum
sha512sum -c release.last.sha512sum && REP="ly Reproduced" || wait
fi
echo "Successful$REP Build of U-Boot v$UB_VER on $build_message_timestamp W/ TF-A $ATF_VER & OP-TEE v$OPT_VER" > status.info