-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile
436 lines (297 loc) · 13.7 KB
/
Dockerfile
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# syntax=docker/dockerfile:1-labs
FROM scratch AS git-kernel
ARG KERNEL_REPO=https://github.com/radxa/kernel.git
ARG KERNEL_REF=linux-5.10-gen-rkr3.4
ADD --keep-git-dir=true ${KERNEL_REPO}#${KERNEL_REF} /
# --------------------------------------------------------------------------- #
FROM scratch AS git-u-boot-radxa
ADD https://github.com/radxa/u-boot.git#stable-5.10-rock5 /
# --------------------------------------------------------------------------- #
FROM scratch AS git-u-boot-collabora
ADD https://gitlab.collabora.com/hardware-enablement/rockchip-3588/u-boot.git#2023.10-rk3588 /
# --------------------------------------------------------------------------- #
FROM scratch AS git-rkbin
ADD https://github.com/radxa/rkbin.git#master /
# --------------------------------------------------------------------------- #
FROM scratch AS git-radxa-build
ADD https://github.com/radxa/build.git#debian /
# --------------------------------------------------------------------------- #
FROM scratch AS git-edk2
ADD --keep-git-dir=true https://github.com/edk2-porting/edk2-rk35xx.git#master /
# --------------------------------------------------------------------------- #
FROM scratch AS git-rkdeveloptool
ADD https://github.com/rockchip-linux/rkdeveloptool.git#master /
# --------------------------------------------------------------------------- #
FROM scratch AS git-bsp
ADD https://github.com/radxa-repo/bsp.git#main /
# --------------------------------------------------------------------------- #
FROM scratch AS git-overlays
ADD https://github.com/radxa/overlays.git#main /
# --------------------------------------------------------------------------- #
FROM --platform=${BUILDPLATFORM} alpine AS fetch
RUN apk add --no-cache \
curl \
git \
;
# --------------------------------------------------------------------------- #
FROM fetch AS dl-cross-compiler
WORKDIR /cross-compile
RUN curl -sS https://dl.radxa.com/tools/linux/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.gz | tar -xz --strip-components=4
# --------------------------------------------------------------------------- #
FROM --platform=linux/amd64 debian:bullseye AS sdk-base-amd64
COPY --from=dl-cross-compiler --link /cross-compile /rk3588-sdk/cross-compile
ENV PATH="/rk3588-sdk/cross-compile/bin:${PATH}"
ENV CROSS_COMPILE=aarch64-none-linux-gnu-
ENV ARCH=arm64
# --------------------------------------------------------------------------- #
FROM --platform=linux/arm64 debian:bullseye AS sdk-base-arm64
# no extra configuration required
# --------------------------------------------------------------------------- #
FROM sdk-base-${BUILDARCH} AS sdk-base
RUN echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
RUN --mount=type=cache,sharing=locked,id=apt-sdk-deps,target=/var/lib/apt \
--mount=type=cache,sharing=locked,id=apt-sdk-deps-cache,target=/var/cache/apt \
apt-get update \
&& apt-get install -y --no-install-recommends \
bc \
bison \
build-essential \
device-tree-compiler \
dosfstools \
flex \
git \
kmod \
libncurses5 \
libncurses5-dev \
libssl-dev \
mtools \
ostree \
python \
rpm \
rsync \
u-boot-tools \
&& rm -rf /var/lib/apt/lists/* \
;
WORKDIR /rk3588-sdk
# --------------------------------------------------------------------------- #
FROM sdk-base AS sdk
COPY --from=git-rkbin --link / /rk3588-sdk/rkbin
# --------------------------------------------------------------------------- #
FROM sdk-base AS bsp
COPY --from=git-bsp --link / /rk3588-sdk/bsp
# --------------------------------------------------------------------------- #
FROM scratch AS kernel-radxa-patches
COPY --from=git-bsp --link /linux/rockchip /
# --------------------------------------------------------------------------- #
# this is a circuitous no-op intended to be overridden via a var passed to
# docker buildx bake (or alternatively, CLI flags to `buildx build`)
FROM scratch AS defconfig
COPY --from=git-kernel --link /arch/arm64/configs/rockchip_linux_defconfig /
# --------------------------------------------------------------------------- #
FROM sdk AS kernel-builder
COPY --from=git-kernel --link / /rk3588-sdk/kernel/
RUN rm -rf /rk3588-sdk/kernel/arch/arm64/boot/dts/rockchip/overlay
COPY --from=git-overlays --link /arch/arm64/boot/dts/amlogic/overlays /rk3588-sdk/kernel/arch/arm64/boot/dts/amlogic/overlays
COPY --from=git-overlays --link /arch/arm64/boot/dts/rockchip/overlays /rk3588-sdk/kernel/arch/arm64/boot/dts/rockchip/overlays
COPY --from=kernel-radxa-patches --link / /rk3588-sdk/kernel/patches
COPY --from=defconfig --link /rockchip_linux_defconfig /rk3588-sdk/kernel/arch/arm64/configs/rockchip_linux_defconfig
RUN cd /rk3588-sdk/kernel \
&& git config --global user.email "[email protected]" \
&& git config --global user.name "Rock 5 Docker Build User" \
&& find /rk3588-sdk/kernel/patches \
-name '*.patch' \
-not -iname "*-rock-4*" \
-type f \
-print0 \
| sort -z \
| xargs -r0 git am --reject --whitespace=fix \
;
# --------------------------------------------------------------------------- #
FROM kernel-builder AS kernel-build-config
RUN cd /rk3588-sdk/kernel \
&& make rockchip_linux_defconfig \
;
# --------------------------------------------------------------------------- #
FROM kernel-build-config AS kernel-build
RUN cd /rk3588-sdk/kernel \
&& make -j $(nproc) \
;
FROM kernel-build-config AS kernel-build-rpm
RUN cd /rk3588-sdk/kernel \
&& make -j $(nproc) rpm-pkg \
;
FROM scratch AS kernel-rpm
COPY --link --from=kernel-build-rpm /root/rpmbuild/RPMS/aarch64/ /
COPY --link --from=kernel-build-rpm /root/rpmbuild/SRPMS/ /
# --------------------------------------------------------------------------- #
FROM kernel-build AS kernel-build-modules
ENV INSTALL_MOD_PATH=/rk3588-sdk/out/kernel/modules
RUN mkdir -p /out \
&& cd /rk3588-sdk/kernel \
&& make modules_install INSTALL_MOD_PATH=/out \
&& rm /out/lib/modules/*/build \
&& rm /out/lib/modules/*/source \
;
# --------------------------------------------------------------------------- #
FROM scratch AS kernel-modules
COPY --from=kernel-build-modules --link /out /
# --------------------------------------------------------------------------- #
FROM kernel-build AS kernel-build-firmware
RUN cd /rk3588-sdk/kernel \
&& make firmware \
;
# --------------------------------------------------------------------------- #
FROM scratch AS kernel
COPY --from=kernel-build --link /rk3588-sdk/kernel/arch/arm64/boot/Image /vmlinuz
COPY --from=kernel-build --link /rk3588-sdk/kernel/arch/arm64/boot/dts/rockchip/rk3588*-rock-5*.dtb /dtb/rockchip/
COPY --from=kernel-build --link /rk3588-sdk/kernel/arch/arm64/boot/dts/rockchip/overlays/rock-5*.dtbo /dtb/rockchip/overlay/
COPY --from=kernel-build --link /rk3588-sdk/kernel/arch/arm64/boot/dts/rockchip/overlays/rk3588*.dtbo /dtb/rockchip/overlay/
COPY --from=kernel-modules --link / /
# --------------------------------------------------------------------------- #
FROM scratch as rkbin-spl
COPY --from=git-rkbin --link /bin/rk35/rk3588_spl_loader_v1.08.111.bin /
# --------------------------------------------------------------------------- #
FROM sdk AS u-boot-radxa-builder
COPY --from=git-radxa-build --link / /rk3588-sdk/build
COPY --from=git-u-boot-radxa --link / /rk3588-sdk/u-boot
# --------------------------------------------------------------------------- #
FROM u-boot-radxa-builder AS u-boot-radxa-build
ARG CHIP="rk3588"
ARG BOARD="rock-5b"
RUN ./build/mk-uboot.sh "${CHIP}-${BOARD}" \
;
# --------------------------------------------------------------------------- #
FROM scratch AS u-boot-radxa
COPY --from=u-boot-radxa-build --link /rk3588-sdk/out/u-boot/ /
# --------------------------------------------------------------------------- #
FROM sdk-base as u-boot-collabora-builder
RUN --mount=type=cache,sharing=locked,id=apt-u-boot-collabora,target=/var/lib/apt \
--mount=type=cache,sharing=locked,id=apt-u-boot-collabora,target=/var/cache/apt \
apt-get update \
&& apt-get install -y \
python3 \
python3-dev \
python3-pyelftools \
python3-setuptools \
swig \
&& rm -rf /var/lib/apt/lists/* \
;
COPY --from=git-rkbin --link /bin/rk35/rk3588_ddr_lp4_2112MHz_lp5_2736MHz_v1.11.bin /rk3588-sdk/u-boot/rockchip-tpl
COPY --from=git-rkbin --link /bin/rk35/rk3588_bl31_v1.38.elf /rk3588-sdk/u-boot/atf-bl31
COPY --from=git-u-boot-collabora --link / /rk3588-sdk/u-boot
WORKDIR /rk3588-sdk/u-boot
# --------------------------------------------------------------------------- #
FROM u-boot-collabora-builder AS u-boot-collabora-build
ARG CHIP="rk3588"
ARG BOARD="rock-5b"
RUN cd /rk3588-sdk/u-boot \
&& make "$(echo "${BOARD}" | tr -d '-')-${CHIP}_defconfig" \
&& make \
;
# adapted from https://github.com/radxa/build/blob/223bcb503769e862a05ebe08c2d49348c050e732/mk-uboot.sh#L29-L41
RUN <<EOF
SPI_IMAGE="/rk3588-sdk/u-boot/spi_image.img"
dd if=/dev/zero of=$SPI_IMAGE bs=1M count=0 seek=16
parted -s $SPI_IMAGE mklabel gpt
parted -s $SPI_IMAGE unit s mkpart idbloader 64 7167
parted -s $SPI_IMAGE unit s mkpart vnvm 7168 7679
parted -s $SPI_IMAGE unit s mkpart reserved_space 7680 8063
parted -s $SPI_IMAGE unit s mkpart reserved1 8064 8127
parted -s $SPI_IMAGE unit s mkpart uboot_env 8128 8191
parted -s $SPI_IMAGE unit s mkpart reserved2 8192 16383
parted -s $SPI_IMAGE unit s mkpart uboot 16384 32734
dd if=/rk3588-sdk/u-boot/idbloader.img of=$SPI_IMAGE seek=64 conv=notrunc
dd if=/rk3588-sdk/u-boot/u-boot.itb of=$SPI_IMAGE seek=16384 conv=notrunc
EOF
# --------------------------------------------------------------------------- #
FROM scratch AS u-boot-collabora
COPY --from=rkbin-spl --link / /
COPY --from=u-boot-collabora-build --link /rk3588-sdk/u-boot/idbloader.img /
COPY --from=u-boot-collabora-build --link /rk3588-sdk/u-boot/u-boot.itb /
COPY --from=u-boot-collabora-build --link /rk3588-sdk/u-boot/spi_image.img /spi/spi_image.img
# --------------------------------------------------------------------------- #
FROM u-boot-radxa-builder AS u-boot-radxa-tools-build
ARG CHIP="rk3588"
ARG BOARD="rock-5b"
RUN cd /rk3588-sdk/u-boot \
&& make "${BOARD}-${CHIP}_defconfig" \
&& make tools \
;
# --------------------------------------------------------------------------- #
FROM scratch AS u-boot-radxa-tools
COPY --from=u-boot-radxa-tools-build --link /rk3588-sdk/u-boot/tools/boot_merger /
COPY --from=u-boot-radxa-tools-build --link /rk3588-sdk/u-boot/tools/loaderimage /
COPY --from=u-boot-radxa-tools-build --link /rk3588-sdk/u-boot/tools/mkimage /
# --------------------------------------------------------------------------- #
FROM sdk-base AS edk2-deps
RUN --mount=type=cache,sharing=locked,id=apt-edk2,target=/var/lib/apt \
--mount=type=cache,sharing=locked,id=apt-edk2,target=/var/cache/apt \
apt-get update \
&& apt-get install -y --no-install-recommends \
binutils-aarch64-linux-gnu \
device-tree-compiler \
gcc-aarch64-linux-gnu \
git \
gettext \
iasl \
libc-dev-arm64-cross \
python3-pyelftools \
uuid-dev \
&& rm -rf /var/lib/apt/lists/* \
;
# --------------------------------------------------------------------------- #
FROM edk2-deps AS edk2-builder-base
COPY --from=git-edk2 --link / /rk3588-sdk/edk2-rk35xx
# --------------------------------------------------------------------------- #
FROM edk2-builder-base AS edk2-builder-arm64
# the vendored rkbin tools are all precompiled for x86, so need to grab them
# from a u-boot build on arm64
# see https://forum.radxa.com/t/edk2-uefi-firmware/14050/2
ENV IDBLOCK_BUILDTOOL=mkimage
COPY --from=u-boot-radxa-tools --link / /rk3588-sdk/edk2-rk35xx/misc/rkbin/tools/
FROM edk2-builder-base AS edk2-builder-amd64
# --------------------------------------------------------------------------- #
FROM edk2-builder-${BUILDARCH} AS edk2-build
ARG BOARD="rock-5b"
RUN /rk3588-sdk/edk2-rk35xx/build.sh -d "${BOARD}"
# --------------------------------------------------------------------------- #
FROM scratch AS edk2
COPY --from=edk2-build --link /rk3588-sdk/edk2-rk35xx/RK3588_NOR_FLASH.img /
# --------------------------------------------------------------------------- #
FROM sdk-base AS rkdeveloptool-build
RUN --mount=type=cache,sharing=locked,id=apt-rkdeveloptool-build,target=/var/lib/apt \
--mount=type=cache,sharing=locked,id=apt-rkdeveloptool-build,target=/var/cache/apt \
apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
dh-autoreconf \
git \
libudev-dev \
libusb-1.0-0-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/* \
;
COPY --from=git-rkdeveloptool --link / /rk3588-sdk/rkdeveloptool
RUN cd /rk3588-sdk/rkdeveloptool \
&& curl -qL https://github.com/rockchip-linux/rkdeveloptool/pull/57.patch | git apply \
&& aclocal \
&& autoreconf -i \
&& autoheader \
&& automake --add-missing \
&& ./configure \
&& make \
;
# --------------------------------------------------------------------------- #
FROM debian:bullseye AS rkdeveloptool
RUN --mount=type=cache,sharing=locked,id=apt-rkdeveloptool,target=/var/lib/apt \
--mount=type=cache,sharing=locked,id=apt-rkdeveloptool,target=/var/cache/apt \
apt-get update \
&& apt-get install -y --no-install-recommends \
libusb-1.0.0 \
&& rm -rf /var/lib/apt/lists/* \
;
COPY --from=rkdeveloptool-build --link /rk3588-sdk/rkdeveloptool/rkdeveloptool /usr/local/bin/
VOLUME "/out"
ENTRYPOINT ["/usr/local/bin/rkdeveloptool"]
# --------------------------------------------------------------------------- #