├── .gitignore ├── .editorconfig ├── .dockerignore ├── extra └── mlc-llm │ ├── config.cmake │ └── Dockerfile ├── rkdeveloptool-docker.sh ├── rknn ├── rknn-export.py └── Dockerfile ├── defconfig.sh ├── .github └── workflows │ ├── rkmpp.yaml │ ├── u-boot.yaml │ └── sdk.yaml ├── docker-bake.hcl ├── rkmpp ├── Dockerfile └── README.md ├── README.md └── Dockerfile /.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | 3 | # generated by defconfig.sh 4 | rockchip_linux_defconfig 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | charset = utf-8 3 | end_of_line = lf 4 | 5 | [*.{yml,yaml}] 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | # none of the files in this repo are actually needed for the build except a custom 2 | # kernel config if using `defconfig.sh` for convenience, so we allow that 3 | * 4 | !rockchip_linux_defconfig 5 | -------------------------------------------------------------------------------- /extra/mlc-llm/config.cmake: -------------------------------------------------------------------------------- 1 | set(TVM_HOME 3rdparty/tvm) 2 | set(CMAKE_BUILD_TYPE RelWithDebInfo) 3 | set(USE_CUDA OFF) 4 | set(USE_CUTLASS OFF) 5 | set(USE_CUBLAS OFF) 6 | set(USE_ROCM OFF) 7 | set(USE_VULKAN OFF) 8 | set(USE_METAL OFF) 9 | set(USE_OPENCL ON) 10 | -------------------------------------------------------------------------------- /rkdeveloptool-docker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | set -e 4 | 5 | self=$( 6 | self=${0} 7 | while [ -L "${self}" ] 8 | do 9 | cd "${self%/*}" 10 | self=$(readlink "${self}") 11 | done 12 | cd "${self%/*}" 13 | echo "$(pwd -P)/${self##*/}" 14 | ) 15 | 16 | # the substitution uses :+ to ensure that no empty quoted value is present 17 | # if no mount flags are being passed, or the run command will interpret the 18 | # empty literal as the image name 19 | mnt_args= 20 | if [ -d /dev/usb ]; then 21 | mnt_args="${mnt_args} --mount=type=bind,src=/dev/usb/,dst=/dev/usb/" 22 | fi 23 | 24 | out_dir=$(dirname "${self}")/out 25 | if [ -d "${out_dir}" ]; then 26 | mnt_args="${mnt_args} --mount=type=bind,src=$(dirname "${self}")/out,dst=/out" 27 | fi 28 | 29 | docker --context=default run \ 30 | --rm \ 31 | -it \ 32 | --init \ 33 | --privileged \ 34 | ${mnt_args:+${mnt_args}} \ 35 | docker.io/milas/rkdeveloptool "$@" 36 | -------------------------------------------------------------------------------- /rknn/rknn-export.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from rknn.api import RKNN 4 | 5 | # adapted from 6 | # https://github.com/rockchip-linux/rknn-toolkit2/blob/324671aa65785fd471920771de98baf9ca45ab43/examples/onnx/yolov5/test.py#L236-L268 7 | if __name__ == '__main__': 8 | if len(sys.argv) < 2: 9 | print('usage: rknn-export.py ONXX_MODEL_FILE') 10 | exit(1) 11 | 12 | onxx_model_filename = sys.argv[1] 13 | 14 | # Create RKNN object 15 | rknn = RKNN(verbose=True) 16 | 17 | # pre-process config 18 | print('--> Config model') 19 | rknn.config(mean_values=[[0, 0, 0]], std_values=[[255, 255, 255]], target_platform="rk3588") 20 | print('done') 21 | 22 | # Load ONNX model 23 | print('--> Loading model') 24 | ret = rknn.load_onnx(model=onxx_model_filename) 25 | if ret != 0: 26 | print('Load model failed!') 27 | exit(ret) 28 | print('done') 29 | 30 | # Build model 31 | print('--> Building model') 32 | ret = rknn.build(do_quantization=True) 33 | if ret != 0: 34 | print('Build model failed!') 35 | exit(ret) 36 | print('done') 37 | 38 | # Export RKNN model 39 | print('--> Export rknn model') 40 | ret = rknn.export_rknn(onxx_model_filename.rstrip('.onnx') + ".rknn") 41 | if ret != 0: 42 | print('Export rknn model failed!') 43 | exit(ret) 44 | print('done') 45 | -------------------------------------------------------------------------------- /defconfig.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | set -e 3 | 4 | # run kernel menuconfig in container, using `rockchip_linux_defconfig` from the 5 | # current working directory as a starting point if present (stock radxa config 6 | # otherwise) 7 | # 8 | # output will overwrite `rockchip_linux_defconfig` in current working directory 9 | 10 | self=$( 11 | self=${0} 12 | while [ -L "${self}" ] 13 | do 14 | cd "${self%/*}" 15 | self=$(readlink "${self}") 16 | done 17 | cd "${self%/*}" 18 | echo "$(pwd -P)/${self##*/}" 19 | ) 20 | 21 | if [ -f rockchip_linux_defconfig ]; then 22 | >&2 echo "This will overwrite rockchip_linux_defconfig in $(pwd)" 23 | while true; do 24 | read -p "Continue (y/N)? " choice 25 | case "$choice" in 26 | y|Y ) break;; 27 | n|N|'' ) exit 1;; 28 | * ) ;; 29 | esac 30 | done 31 | DEFCONFIG="$(pwd)" 32 | export DEFCONFIG 33 | fi 34 | 35 | docker rm -f rock5-kernel-config >/dev/null 2>&1 || true 36 | 37 | # shellcheck disable=SC2086 38 | (cd "$(dirname "${self}")" && docker buildx bake \ 39 | --pull \ 40 | --load \ 41 | kernel-config) 42 | 43 | docker run -it \ 44 | --name rock5-kernel-config \ 45 | -w /rk3588-sdk/kernel \ 46 | milas/rock5-toolchain:kernel-config \ 47 | sh -c 'make menuconfig && make savedefconfig' 48 | 49 | docker cp rock5-kernel-config:/rk3588-sdk/kernel/defconfig rockchip_linux_defconfig 50 | 51 | docker rm -f rock5-kernel-config >/dev/null 2>&1 || true 52 | -------------------------------------------------------------------------------- /.github/workflows/rkmpp.yaml: -------------------------------------------------------------------------------- 1 | name: Rockchip MPP 2 | 3 | on: 4 | workflow_dispatch: {} 5 | push: 6 | branches: [main] 7 | paths: 8 | - 'rkmpp/**' 9 | schedule: 10 | - cron: '15 18 * * 5' # 18:15 UTC on Friday 11 | 12 | jobs: 13 | images: 14 | runs-on: self-hosted 15 | 16 | permissions: 17 | contents: read 18 | packages: write 19 | 20 | strategy: 21 | matrix: 22 | include: 23 | - os: 'ubuntu' 24 | version: '20.04' 25 | - os: 'ubuntu' 26 | version: '22.04' 27 | - os: 'debian' 28 | version: 'bullseye' 29 | 30 | outputs: 31 | image: ${{ steps.meta.tags }} 32 | 33 | steps: 34 | - uses: docker/setup-buildx-action@v2 35 | with: 36 | buildkitd-flags: --debug 37 | 38 | - name: Docker Hub Login 39 | uses: docker/login-action@v2 40 | with: 41 | registry: docker.io 42 | username: milas 43 | password: ${{ secrets.DOCKER_HUB_TOKEN }} 44 | 45 | - name: GHCR Login 46 | uses: docker/login-action@v2 47 | with: 48 | registry: ghcr.io 49 | username: ${{ github.actor }} 50 | password: ${{ secrets.GITHUB_TOKEN }} 51 | 52 | - id: meta 53 | uses: docker/metadata-action@v4 54 | with: 55 | images: docker.io/milas/rkmpp-${{ matrix.os }} 56 | tags: | 57 | type=ref,event=branch,prefix=${{ matrix.version }}- 58 | type=raw,value=${{ matrix.version }},enable={{is_default_branch}} 59 | 60 | - uses: docker/build-push-action@v3 61 | with: 62 | push: true 63 | pull: true 64 | provenance: true 65 | tags: ${{ steps.meta.outputs.tags }} 66 | labels: ${{ steps.meta.outputs.labels }} 67 | cache-from: type=gha 68 | cache-to: type=gha,mode=max 69 | platforms: linux/arm64 70 | context: "{{defaultContext}}:rkmpp" 71 | target: os 72 | build-args: | 73 | OS_BASE=docker.io/${{ matrix.os }}:${{ matrix.version }} 74 | -------------------------------------------------------------------------------- /.github/workflows/u-boot.yaml: -------------------------------------------------------------------------------- 1 | name: U-Boot 2 | 3 | on: 4 | workflow_dispatch: {} 5 | push: 6 | branches: [main] 7 | schedule: 8 | - cron: '15 18 * * 2' # 18:15 UTC on Tuesday 9 | 10 | jobs: 11 | u-boot: 12 | runs-on: self-hosted 13 | 14 | strategy: 15 | matrix: 16 | board: [rock-5a, rock-5b] 17 | variant: [radxa, collabora] 18 | exclude: 19 | - board: rock-5a 20 | variant: collabora 21 | include: 22 | - board: rock-5a 23 | chip: rk3588s 24 | - board: rock-5b 25 | chip: rk3588 26 | 27 | permissions: 28 | contents: read 29 | packages: none 30 | 31 | steps: 32 | - uses: docker/setup-buildx-action@v2 33 | with: 34 | version: 'https://github.com/docker/buildx.git#master' 35 | buildkitd-flags: --debug 36 | driver-opts: | 37 | image=milas/buildkit 38 | 39 | - name: Docker Hub Login 40 | uses: docker/login-action@v2 41 | with: 42 | registry: docker.io 43 | username: ${{ github.actor }} 44 | password: ${{ secrets.DOCKER_HUB_TOKEN }} 45 | 46 | - uses: docker/metadata-action@v4 47 | id: meta 48 | with: 49 | images: docker.io/${{ github.actor }}/rock5-u-boot 50 | flavor: suffix=-${{ matrix.board }}-${{ matrix.variant }} 51 | tags: | 52 | type=schedule,pattern={{date 'YYYYMMDD'}} 53 | type=schedule,pattern=latest 54 | type=raw,value=latest,enable={{is_default_branch}} 55 | labels: | 56 | org.opencontainers.image.title=u-boot/${{ matrix.board }}/${{ matrix.variant }} 57 | org.opencontainers.image.description=U-Boot bootloader for Rock 5 58 | 59 | - uses: docker/build-push-action@v3 60 | with: 61 | push: true 62 | pull: true 63 | tags: ${{ steps.meta.outputs.tags }} 64 | labels: ${{ steps.meta.outputs.labels }} 65 | target: u-boot-${{ matrix.variant }} 66 | build-args: | 67 | CHIP=${{ matrix.chip }} 68 | BOARD=${{ matrix.board }} 69 | platforms: linux/arm64 70 | provenance: true 71 | cache-from: type=gha 72 | cache-to: type=gha,mode=max 73 | github-token: '' 74 | -------------------------------------------------------------------------------- /.github/workflows/sdk.yaml: -------------------------------------------------------------------------------- 1 | name: SDK 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | paths-ignore: 7 | - 'rkmpp/**' 8 | - 'rknn/**' 9 | 10 | jobs: 11 | images: 12 | runs-on: ubuntu-22.04 13 | permissions: 14 | contents: read 15 | packages: write 16 | 17 | outputs: 18 | image: ${{ steps.meta.tags }} 19 | 20 | steps: 21 | - uses: docker/setup-buildx-action@v2 22 | with: 23 | buildkitd-flags: --debug 24 | 25 | - name: Docker Hub Login 26 | uses: docker/login-action@v2 27 | with: 28 | registry: docker.io 29 | username: milas 30 | password: ${{ secrets.DOCKER_HUB_TOKEN }} 31 | 32 | - name: GHCR Login 33 | uses: docker/login-action@v2 34 | with: 35 | registry: ghcr.io 36 | username: ${{ github.actor }} 37 | password: ${{ secrets.GITHUB_TOKEN }} 38 | 39 | - name: SDK Meta 40 | id: sdk_meta 41 | uses: docker/metadata-action@v4 42 | with: 43 | images: docker.io/milas/rock5-sdk 44 | tags: | 45 | type=ref,event=branch 46 | type=raw,value=latest,enable={{is_default_branch}} 47 | 48 | - name: SDK Image 49 | uses: docker/build-push-action@v3 50 | with: 51 | push: true 52 | pull: true 53 | tags: ${{ steps.sdk_meta.outputs.tags }} 54 | labels: ${{ steps.sdk_meta.outputs.labels }} 55 | target: sdk 56 | platforms: linux/amd64,linux/arm64 57 | provenance: true 58 | cache-from: type=gha 59 | cache-to: type=gha,mode=max 60 | 61 | - name: rkdeveloptool Meta 62 | id: rkdeveloptool_meta 63 | uses: docker/metadata-action@v4 64 | with: 65 | images: | 66 | docker.io/milas/rkdeveloptool 67 | ghcr.io/milas/rkdeveloptool 68 | tags: | 69 | type=ref,event=branch 70 | type=raw,value=latest,enable={{is_default_branch}} 71 | 72 | - name: rkdeveloptool Image 73 | uses: docker/build-push-action@v3 74 | with: 75 | push: true 76 | pull: true 77 | tags: ${{ steps.rkdeveloptool_meta.outputs.tags }} 78 | labels: ${{ steps.rkdeveloptool_meta.outputs.labels }} 79 | target: rkdeveloptool 80 | platforms: linux/amd64,linux/arm64 81 | provenance: true 82 | cache-from: type=gha 83 | cache-to: type=gha,mode=max 84 | -------------------------------------------------------------------------------- /docker-bake.hcl: -------------------------------------------------------------------------------- 1 | variable DEBUG { 2 | default = false 3 | } 4 | 5 | variable DEFCONFIG { 6 | default = null 7 | } 8 | 9 | variable CHIP { 10 | default = null 11 | } 12 | 13 | variable BOARD { 14 | default = null 15 | } 16 | 17 | group default { 18 | targets = ["kernel", "u-boot"] 19 | } 20 | 21 | group u-boot { 22 | targets = ["u-boot-radxa", "u-boot-collabora"] 23 | } 24 | 25 | # virtual target for CI 26 | # https://github.com/docker/metadata-action#bake-definition 27 | target "docker-metadata-action" {} 28 | 29 | target sdk { 30 | target = "sdk" 31 | inherits = ["docker-metadata-action"] 32 | tags = ["docker.io/milas/rock5-sdk"] 33 | } 34 | 35 | target rkdeveloptool { 36 | target = "rkdeveloptool" 37 | inherits = ["docker-metadata-action"] 38 | tags = ["docker.io/milas/rkdeveloptool"] 39 | } 40 | 41 | 42 | variable KERNEL_REPO { 43 | default = null 44 | } 45 | 46 | variable KERNEL_REF { 47 | default = null 48 | } 49 | 50 | target kernel { 51 | target = "kernel" 52 | output = ["type=local,dest=./out/kernel"] 53 | inherits = ["kernel-config"] 54 | } 55 | 56 | target kernel-config { 57 | target = "kernel-build-config" 58 | inherits = ["docker-metadata-action"] 59 | tags = ["milas/rock5-toolchain:kernel-config"] 60 | contexts = notequal(null, DEFCONFIG) ? { defconfig = DEFCONFIG } : {} 61 | args = { 62 | KERNEL_REPO = KERNEL_REPO 63 | KERNEL_REF = KERNEL_REF 64 | } 65 | } 66 | 67 | target radxa-kernel-patches { 68 | target = "kernel-radxa-patches" 69 | output = ["type=local,dest=./out/kernel/patches"] 70 | } 71 | 72 | target spl { 73 | target = "rkbin-spl" 74 | output = ["type=local,dest=./out"] 75 | } 76 | 77 | target u-boot-radxa { 78 | target = "u-boot-radxa" 79 | output = ["type=local,dest=./out/u-boot/radxa"] 80 | args = { 81 | CHIP = CHIP 82 | BOARD = BOARD 83 | } 84 | } 85 | 86 | target u-boot-collabora { 87 | target = "u-boot-collabora" 88 | output = ["type=local,dest=./out/u-boot/collabora"] 89 | args = { 90 | CHIP = CHIP 91 | BOARD = BOARD 92 | } 93 | } 94 | 95 | target edk2 { 96 | target = "edk2" 97 | output = ["type=local,dest=./out/edk2"] 98 | args = { 99 | CHIP = CHIP 100 | BOARD = BOARD 101 | } 102 | } 103 | 104 | group yolov8 { 105 | targets = ["yolov8-model-onnx", "yolov8-model-rknn"] 106 | } 107 | 108 | target _yolov8-model { 109 | context = "./rknn" 110 | output = ["type=local,dest=./out/rknn"] 111 | args = { 112 | YOLO_MODEL = "yolov8s" 113 | } 114 | } 115 | 116 | target yolov8-model-onnx { 117 | inherits = ["_yolov8-model"] 118 | target = "yolo-model-onnx" 119 | } 120 | 121 | target yolov8-model-rknn { 122 | inherits = ["_yolov8-model"] 123 | target = "yolo-model-rknn" 124 | } 125 | 126 | variable YOLO_MODEL { 127 | default = null 128 | } 129 | 130 | target rknn-benchmark { 131 | context = "./rknn" 132 | target = "rknn-benchmark" 133 | platforms = ["linux/arm64"] 134 | tags = ["docker.io/milas/rknn-benchmark:yolov8s"] 135 | contexts = notequal(null, YOLO_MODEL) ? { yolo-model-rknn = YOLO_MODEL } : {} 136 | } 137 | 138 | target rknn-toolkit2 { 139 | context = "./rknn" 140 | target = "rknn-toolkit2" 141 | platforms = ["linux/amd64"] 142 | tags = ["docker.io/milas/rknn-toolkit2"] 143 | } 144 | 145 | group rkmpp { 146 | targets = ["rkmpp-libs", "rkmpp-debian"] 147 | } 148 | 149 | target _rkmpp { 150 | context = "./rkmpp" 151 | platforms = ["linux/arm64"] 152 | } 153 | 154 | group rkmpp-libs { 155 | targets = ["rkmpp-rga", "rkmpp-mpp", "rkmpp-gstreamer-plugin"] 156 | } 157 | 158 | target rkmpp-rga { 159 | inherits = ["_rkmpp"] 160 | target = "rockchip-rga" 161 | output = ["type=local,dest=./out/rkmpp/rga"] 162 | } 163 | 164 | target rkmpp-mpp { 165 | inherits = ["_rkmpp"] 166 | target = "rockchip-mpp" 167 | output = ["type=local,dest=./out/rkmpp/mpp"] 168 | } 169 | 170 | target rkmpp-gstreamer-plugin { 171 | inherits = ["_rkmpp"] 172 | target = "rockchip-gstreamer-plugin" 173 | output = ["type=local,dest=./out/rkmpp/gstreamer"] 174 | } 175 | 176 | target rkmpp-debian { 177 | inherits = ["_rkmpp"] 178 | target = "os" 179 | args = { 180 | OS_BASE = "docker.io/debian:bullseye" 181 | } 182 | tags = ["docker.io/milas/rkmpp-debian:bullseye"] 183 | } 184 | 185 | target rpm { 186 | target = "kernel-rpm" 187 | output = ["type=local,dest=./out/kernel"] 188 | inherits = ["kernel-config"] 189 | tags = [] 190 | } -------------------------------------------------------------------------------- /extra/mlc-llm/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1-labs 2 | 3 | ARG MODEL=RedPajama-INCITE-Chat-3B-v1-q4f16_1 4 | # WARNING: Llama-2 requires 16GB board 5 | #ARG MODEL=Llama-2-7b-chat-hf-q4f16_1 6 | #ARG MODEL=Llama-2-13b-chat-hf-q4f16_1 7 | 8 | # --------------------------------------------------------------------------- # 9 | 10 | FROM scratch AS git-libmali 11 | ADD https://github.com/JeffyCN/mirrors.git#libmali / 12 | 13 | # --------------------------------------------------------------------------- # 14 | 15 | FROM scratch AS git-mlc-llm 16 | ADD https://github.com/mlc-ai/mlc-llm.git / 17 | 18 | # --------------------------------------------------------------------------- # 19 | 20 | FROM scratch as libmali-driver 21 | COPY --link --from=git-libmali /lib/aarch64-linux-gnu/libmali-valhall-g610-*.so / 22 | 23 | # --------------------------------------------------------------------------- # 24 | 25 | FROM scratch AS libmali-firmware 26 | COPY --link --from=git-libmali /firmware/g610/mali_csffw.bin / 27 | 28 | # --------------------------------------------------------------------------- # 29 | 30 | FROM alpine AS fetch 31 | RUN apk add --no-cache \ 32 | git \ 33 | git-lfs \ 34 | ; 35 | 36 | FROM scratch AS git-binary-mlc-llm-libs 37 | ADD https://github.com/mlc-ai/binary-mlc-llm-libs.git / 38 | 39 | # --------------------------------------------------------------------------- # 40 | 41 | FROM scratch AS binary-mlc-llm-lib 42 | ARG MODEL 43 | COPY --link --from=git-binary-mlc-llm-libs /${MODEL}-mali.so / 44 | 45 | # --------------------------------------------------------------------------- # 46 | 47 | FROM fetch AS fetch-model 48 | ARG MODEL 49 | ARG GIT_URL="https://huggingface.co/mlc-ai/mlc-chat-${MODEL}.git" 50 | RUN --mount=type=cache,sharing=locked,id=git-${MODEL},target=/cache/${MODEL} \ 51 | git clone \ 52 | --single-branch --depth 1 \ 53 | --separate-git-dir=/cache/${MODEL}/git \ 54 | ${GIT_URL} \ 55 | /out/${MODEL} \ 56 | ; 57 | 58 | # --------------------------------------------------------------------------- # 59 | 60 | FROM scratch AS model 61 | COPY --link --from=fetch-model /out/ / 62 | 63 | # --------------------------------------------------------------------------- # 64 | 65 | FROM debian:bullseye AS opencl 66 | 67 | # based on https://mlc.ai/mlc-llm/docs/install/gpu.html#orange-pi-5-rk3588-based-sbc 68 | RUN --mount=type=cache,sharing=locked,id=apt-opencl,target=/var/lib/apt \ 69 | --mount=type=cache,sharing=locked,id=apt-opencl-cache,target=/var/cache/apt \ 70 | apt-get update \ 71 | && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ 72 | mesa-opencl-icd \ 73 | ocl-icd-opencl-dev \ 74 | libxcb-dri2-0 \ 75 | libxcb-dri3-0 \ 76 | libwayland-client0 \ 77 | libwayland-server0 \ 78 | libx11-xcb1 \ 79 | clinfo \ 80 | ; 81 | 82 | RUN mkdir -p /etc/OpenCL/vendors \ 83 | && echo "/usr/lib/libmali-valhall-g610-g6p0-x11-wayland-gbm.so" | tee /etc/OpenCL/vendors/mali.icd \ 84 | ; 85 | 86 | COPY --link --from=libmali-firmware / /lib/firmware/ 87 | COPY --link --from=libmali-driver / /usr/lib/ 88 | RUN ldconfig 89 | 90 | CMD ["clinfo"] 91 | 92 | # --------------------------------------------------------------------------- # 93 | 94 | FROM debian:bullseye-backports AS build 95 | LABEL authors="Milas Bowman " 96 | 97 | RUN --mount=type=cache,sharing=locked,id=apt-mlc-llm,target=/var/lib/apt \ 98 | --mount=type=cache,sharing=locked,id=apt-mlc-llm-cache,target=/var/cache/apt \ 99 | apt-get update \ 100 | && DEBIAN_FRONTEND=noninteractive apt-get -t bullseye-backports install -y --no-install-recommends \ 101 | build-essential \ 102 | ca-certificates \ 103 | cmake \ 104 | curl \ 105 | python3 \ 106 | ; 107 | 108 | # install rust 109 | ENV PATH="/root/.cargo/bin:${PATH}" 110 | RUN curl https://sh.rustup.rs -sSf | bash -s -- -y 111 | 112 | COPY --link --from=git-mlc-llm / /mlc-llm 113 | COPY config.cmake /mlc-llm/build/ 114 | 115 | # based on https://blog.mlc.ai/2023/08/09/GPU-Accelerated-LLM-on-Orange-Pi 116 | RUN cd /mlc-llm/build \ 117 | && cmake .. \ 118 | && cmake --build . --parallel $(nproc) \ 119 | && cmake --install . --prefix /out \ 120 | ; 121 | 122 | # --------------------------------------------------------------------------- # 123 | 124 | FROM opencl 125 | 126 | COPY --link --from=binary-mlc-llm-lib / /mlc-llm/dist/prebuilt/lib/ 127 | COPY --link --from=model / /mlc-llm/dist/prebuilt/ 128 | COPY --link --from=build /out/bin/ /out/lib/ /mlc-llm/build/ 129 | 130 | ENV LD_LIBRARY_PATH=/mlc-llm/build/ 131 | WORKDIR /mlc-llm 132 | 133 | # HACK: can't interpolate ARGs in CMD, so assign it to an ENV and wrap with 134 | # shell to resolve on start 135 | ARG MODEL 136 | ENV MODEL=${MODEL} 137 | CMD ["sh", "-c", "./build/mlc_chat_cli --local-id ${MODEL} --device mali"] 138 | -------------------------------------------------------------------------------- /rkmpp/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1-labs 2 | 3 | ARG OS_BASE=debian:bullseye 4 | 5 | FROM scratch AS git-rockchip-gstreamer 6 | 7 | ADD https://github.com/JeffyCN/mirrors.git#gstreamer-rockchip / 8 | 9 | # --------------------------------------------------------------------------- # 10 | 11 | FROM scratch AS git-rockchip-mpp 12 | 13 | ADD --keep-git-dir=true https://github.com/rockchip-linux/mpp.git#develop / 14 | 15 | # --------------------------------------------------------------------------- # 16 | 17 | FROM scratch AS git-rockchip-rga 18 | 19 | ADD https://github.com/JeffyCN/mirrors.git#linux-rga-multi / 20 | 21 | # --------------------------------------------------------------------------- # 22 | 23 | FROM --platform=${BUILDPLATFORM} ${OS_BASE} AS build-base 24 | 25 | RUN --mount=type=cache,sharing=locked,id=apt-base,target=/var/lib/apt \ 26 | --mount=type=cache,sharing=locked,id=apt-base,target=/var/cache/apt \ 27 | apt-get update \ 28 | && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ 29 | cmake \ 30 | g++ \ 31 | gcc \ 32 | git \ 33 | make \ 34 | wget \ 35 | && rm -rf /var/lib/apt/lists/* \ 36 | ; 37 | 38 | # --------------------------------------------------------------------------- # 39 | 40 | FROM build-base AS build-rockchip-mpp 41 | 42 | COPY --link --from=git-rockchip-mpp / /src/rockchip-mpp 43 | 44 | RUN cd /src/rockchip-mpp/build/linux/aarch64 \ 45 | && ./make-Makefiles.bash \ 46 | && DESTDIR=/out/rockchip-mpp make install -j$(nproc) 47 | 48 | # --------------------------------------------------------------------------- # 49 | 50 | FROM scratch AS rockchip-mpp 51 | 52 | COPY --link --from=build-rockchip-mpp /out/rockchip-mpp / 53 | 54 | # --------------------------------------------------------------------------- # 55 | 56 | FROM build-base AS build-rockchip-rga 57 | 58 | COPY --link --from=git-rockchip-rga / /src/rockchip-rga 59 | WORKDIR /src/rockchip-rga 60 | 61 | RUN --mount=type=cache,sharing=locked,id=apt-rkrga,target=/var/lib/apt \ 62 | --mount=type=cache,sharing=locked,id=apt-rkrga,target=/var/cache/apt \ 63 | apt-get update \ 64 | && DEBIAN_FRONTEND=noninterface apt-get install -y --no-install-recommends \ 65 | libdrm-dev \ 66 | meson \ 67 | pkg-config \ 68 | && rm -rf /var/lib/apt/lists/* \ 69 | ; 70 | 71 | RUN cd /src/rockchip-rga \ 72 | && meson build \ 73 | && cd build \ 74 | && DESTDIR=/out/rockchip-rga ninja install \ 75 | ; 76 | 77 | # --------------------------------------------------------------------------- # 78 | 79 | FROM scratch AS rockchip-rga 80 | 81 | COPY --link --from=build-rockchip-rga /out/rockchip-rga / 82 | 83 | # --------------------------------------------------------------------------- # 84 | 85 | FROM build-base AS build-rockchip-gstreamer 86 | 87 | RUN --mount=type=cache,sharing=locked,id=apt-rkgstreamer,target=/var/lib/apt \ 88 | --mount=type=cache,sharing=locked,id=apt-rkgstreamer,target=/var/cache/apt \ 89 | apt-get update \ 90 | && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ 91 | libdrm-dev \ 92 | libgstreamer-plugins-base1.0-dev \ 93 | meson \ 94 | pkg-config \ 95 | && rm -rf /var/lib/apt/lists/* \ 96 | ; 97 | 98 | COPY --link --from=rockchip-mpp / / 99 | COPY --link --from=rockchip-rga / / 100 | 101 | COPY --link --from=git-rockchip-gstreamer / /src/rockchip-gstreamer 102 | 103 | RUN ldconfig && \ 104 | pwd && \ 105 | cd /src/rockchip-gstreamer \ 106 | && meson build \ 107 | && cd build \ 108 | && DESTDIR=/out/rockchip-gstreamer ninja install \ 109 | ; 110 | 111 | # --------------------------------------------------------------------------- # 112 | 113 | FROM scratch AS rockchip-gstreamer-plugin 114 | 115 | COPY --link --from=build-rockchip-gstreamer /out/rockchip-gstreamer/ / 116 | 117 | # --------------------------------------------------------------------------- # 118 | 119 | FROM ${OS_BASE} AS os-gstreamer 120 | 121 | ENV GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0 122 | 123 | RUN --mount=type=cache,sharing=locked,id=apt-os,target=/var/lib/apt \ 124 | --mount=type=cache,sharing=locked,id=apt-os,target=/var/cache/apt \ 125 | apt-get update \ 126 | && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ 127 | libgstreamer1.0-0 \ 128 | gstreamer1.0-plugins-bad \ 129 | gstreamer1.0-plugins-good \ 130 | gstreamer1.0-tools \ 131 | && rm -rf /var/lib/apt/lists/* \ 132 | ; 133 | 134 | FROM os-gstreamer AS os 135 | 136 | COPY --link --from=rockchip-mpp / / 137 | COPY --link --from=rockchip-rga / / 138 | COPY --link --from=rockchip-gstreamer-plugin / / 139 | 140 | RUN ldconfig 141 | 142 | # --------------------------------------------------------------------------- # 143 | 144 | FROM os AS os-debug 145 | 146 | ENV mpi_debug=1 147 | ENV mpp_debug=1 148 | ENV h264d_debug=1 149 | ENV mpp_syslog_perror=1 150 | 151 | ADD https://dl.radxa.com/media/video/1080p.264 /media/1080p.264 152 | 153 | CMD mpi_dec_test -i /media/1080p.264 -t 7 -h 1080 -w 1920 154 | -------------------------------------------------------------------------------- /rknn/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1-labs 2 | 3 | FROM scratch AS git-rknntoolkit2 4 | 5 | ADD https://github.com/rockchip-linux/rknn-toolkit2.git / 6 | 7 | # --------------------------------------------------------------------------- # 8 | 9 | FROM scratch AS git-rknpu2 10 | 11 | ADD https://github.com/rockchip-linux/rknpu2.git / 12 | 13 | # --------------------------------------------------------------------------- # 14 | 15 | FROM --platform=linux/amd64 ubuntu:20.04 AS rknn-toolkit2 16 | 17 | RUN apt-get update \ 18 | && apt-get install -y --no-install-recommends \ 19 | build-essential \ 20 | python3-pip \ 21 | python3.8-dev \ 22 | ; 23 | 24 | COPY --link --from=git-rknntoolkit2 / /sdk/rknn-toolkit2 25 | 26 | # need to install numpy first to prevent dependency-ordering issues 27 | RUN pip3 install numpy==1.19.5 28 | RUN pip3 install -r /sdk/rknn-toolkit2/doc/requirements_cp38-1.4.0.txt 29 | RUN pip3 install /sdk/rknn-toolkit2/packages/rknn_toolkit2-1.4.0_22dcfef4-cp38-cp38-linux_x86_64.whl 30 | 31 | # --------------------------------------------------------------------------- # 32 | 33 | FROM --platform=${BUILDPLATFORM} python:3.11-bullseye AS yolo-build 34 | 35 | RUN apt-get update \ 36 | && apt-get install -y --no-install-recommends libgl1 \ 37 | ; 38 | 39 | ADD https://github.com/ultralytics/ultralytics.git /ultralytics 40 | WORKDIR /ultralytics 41 | 42 | RUN pip install . 43 | 44 | # --------------------------------------------------------------------------- # 45 | 46 | FROM yolo-build AS yolo-export-onnx 47 | 48 | ARG YOLO_MODEL=yolov8s 49 | RUN yolo export model=${YOLO_MODEL}.pt imgsz=480,640 format=onnx opset=12 50 | 51 | # --------------------------------------------------------------------------- # 52 | 53 | FROM scratch AS yolo-model-onnx 54 | 55 | ARG YOLO_MODEL=yolov8s 56 | COPY --link --from=yolo-export-onnx /ultralytics/${YOLO_MODEL}.onnx / 57 | 58 | # --------------------------------------------------------------------------- # 59 | 60 | FROM scratch AS dataset 61 | 62 | COPY --link --from=git-rknntoolkit2 /examples/onnx/yolov5/bus.jpg /examples/onnx/yolov5/dataset.txt / 63 | 64 | # --------------------------------------------------------------------------- # 65 | 66 | FROM rknn-toolkit2 AS yolo-convert-rknn 67 | 68 | RUN apt-get update \ 69 | && apt-get install -y --no-install-recommends \ 70 | libgl1 \ 71 | ; 72 | 73 | RUN pip uninstall opencv-python -y \ 74 | && pip install opencv-python-headless \ 75 | ; 76 | 77 | COPY rknn-export.py /sdk/tools/ 78 | 79 | ARG YOLO_MODEL=yolov8s 80 | COPY --link --from=yolo-model-onnx /${YOLO_MODEL}.onnx /sdk/models/ 81 | COPY --link --from=dataset / /sdk/models/ 82 | 83 | RUN cd /sdk/models && python3 /sdk/tools/rknn-export.py ${YOLO_MODEL}.onnx 84 | 85 | # --------------------------------------------------------------------------- # 86 | 87 | FROM scratch AS yolo-model-rknn 88 | 89 | ARG YOLO_MODEL=yolov8s 90 | COPY --link --from=yolo-convert-rknn /sdk/models/${YOLO_MODEL}.rknn / 91 | 92 | # --------------------------------------------------------------------------- # 93 | 94 | FROM --platform=${BUILDPLATFORM} alpine AS dl-cross-compile 95 | 96 | WORKDIR /cross-compile 97 | ADD https://dl.radxa.com/tools/linux/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.gz . 98 | RUN tar -xzf gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.gz --strip-components=4 \ 99 | && rm gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.gz 100 | 101 | # --------------------------------------------------------------------------- # 102 | 103 | FROM --platform=${BUILDPLATFORM} ubuntu:20.04 AS rknn-benchmark-build-base 104 | 105 | RUN apt-get update \ 106 | && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ 107 | cmake \ 108 | make \ 109 | ; 110 | 111 | # --------------------------------------------------------------------------- # 112 | 113 | FROM rknn-benchmark-build-base AS rknn-benchmark-build-amd64 114 | 115 | COPY --from=dl-cross-compile /cross-compile /sdk/toolchain 116 | RUN ln -s /sdk/toolchain/bin/aarch64-none-linux-gnu-gcc /usr/local/bin/aarch64-linux-gnu-gcc \ 117 | && ln -s /sdk/toolchain/bin/aarch64-none-linux-gnu-g++ /usr/local/bin/aarch64-linux-gnu-g++ \ 118 | ; 119 | 120 | # --------------------------------------------------------------------------- # 121 | 122 | FROM rknn-benchmark-build-base AS rknn-benchmark-build-arm64 123 | 124 | RUN apt-get update \ 125 | && apt-get install -y --no-install-recommends \ 126 | g++ \ 127 | gcc \ 128 | ; 129 | 130 | RUN ln -s $(which gcc) /usr/local/bin/aarch64-linux-gnu-gcc \ 131 | && ln -s $(which g++) /usr/local/bin/aarch64-linux-gnu-g++ \ 132 | ; 133 | 134 | # --------------------------------------------------------------------------- # 135 | 136 | FROM rknn-benchmark-build-${BUILDARCH} AS rknn-benchmark-build 137 | 138 | COPY --link --from=git-rknpu2 / /sdk/rknpu2 139 | RUN bash /sdk/rknpu2/examples/rknn_benchmark/build-linux_RK3588.sh 140 | 141 | # --------------------------------------------------------------------------- # 142 | 143 | FROM --platform=linux/arm64 ubuntu:20.04 AS rknn-benchmark 144 | 145 | COPY --link --from=git-rknpu2 /runtime/RK3588/Linux/librknn_api/aarch64/*.so /usr/local/lib/aarch64-linux-gnu/ 146 | RUN ldconfig 147 | 148 | COPY --link --from=rknn-benchmark-build /sdk/rknpu2/examples/rknn_benchmark/build/build_linux_aarch64/rknn_benchmark /usr/local/bin/ 149 | 150 | COPY --link --from=yolo-model-rknn /*.rknn /sdk/models/ 151 | -------------------------------------------------------------------------------- /rkmpp/README.md: -------------------------------------------------------------------------------- 1 | # Rockchip MPP 2 | Dockerized build system for Rockchip MPP with Gstreamer to provide accelerated video encoding & decoding. 3 | 4 | ## Build Prerequisites 5 | * Docker w/ buildx plugin 6 | * If `docker buildx inspect` works, you're all set! 7 | * `arm64` host 8 | * Cross-compilation from `amd64` not currently supported 9 | 10 | ## Quick Start 11 | Run the pre-built Debian Bullseye image: 12 | ```shell 13 | docker run -it --privileged docker.io/milas/rkmpp-debian:bullseye 14 | ``` 15 | > 💡 The `--privileged` flag is required to allow access to the hardware encoder/decoder. 16 | 17 | Individual groups and targets also exist if you don't want to build everything or want to use one of the experimental targets. 18 | 19 | ## Debian - Bullseye (11) 20 | Debian with the necessary Rockchip and Gstreamer libraries. 21 | 22 | This version is chosen to most closely align with the Rockchip libraries for compatibility. 23 | I would recommend using multi-stage builds with this as the final stage. 24 | 25 | You're also welcome to try `--set='*.build-arg=OS_BASE=debian:bookworm'` to build with Bookworm as the base image, for example. 26 | Ubuntu could be done the same way. 27 | 28 | Build the image: 29 | ```shell 30 | docker buildx bake rkmpp-debian --load 31 | ``` 32 | _This step is **optional**. Pre-built images are [available on Docker Hub][hub/rkmpp-debian]._ 33 | 34 | Run the image: 35 | ```shell 36 | docker run -it --privileged docker.io/milas/rkmpp-debian:bullseye 37 | ``` 38 | 39 | ## `librga` aka RGA (Raster Graphic Acceleration Unit) 40 | **Upstream**: https://github.com/JeffyCN/mirrors/tree/linux-rga-multi 41 | 42 | ```shell 43 | docker buildx bake rkmpp-rga 44 | ``` 45 | ``` 46 | out/rkmpp 47 | └── rga 48 | └── usr 49 | └── local 50 | ├── include 51 | │   └── rga 52 | │   ├── drmrga.h 53 | │   ├── GrallocOps.h 54 | │   ├── im2d_buffer.h 55 | │   ├── im2d_common.h 56 | │   ├── im2d_expand.h 57 | │   ├── im2d.h 58 | │   ├── im2d.hpp 59 | │   ├── im2d_mpi.h 60 | │   ├── im2d_single.h 61 | │   ├── im2d_task.h 62 | │   ├── im2d_type.h 63 | │   ├── im2d_version.h 64 | │   ├── RgaApi.h 65 | │   ├── rga.h 66 | │   ├── RgaMutex.h 67 | │   ├── RgaSingleton.h 68 | │   ├── RgaUtils.h 69 | │   └── RockchipRga.h 70 | └── lib 71 | ├── librga.so -> librga.so.2 72 | ├── librga.so.2 -> librga.so.2.1.0 73 | ├── librga.so.2.1.0 74 | └── pkgconfig 75 | └── librga.pc 76 | ``` 77 | 78 | ## `mpp` aka MPP (Media Process Platform) 79 | **Upstream**: https://github.com/rockchip-linux/mpp/tree/develop 80 | 81 | ```shell 82 | docker buildx bake rkmpp-mpp 83 | ``` 84 | ``` 85 | out/rkmpp 86 | └── mpp 87 | └── usr 88 | └── local 89 | ├── bin 90 | │   ├── mpi_dec_mt_test 91 | │   ├── mpi_dec_multi_test 92 | │   ├── mpi_dec_nt_test 93 | │   ├── mpi_dec_test 94 | │   ├── mpi_enc_mt_test 95 | │   ├── mpi_enc_test 96 | │   ├── mpi_rc2_test 97 | │   ├── mpp_info_test 98 | │   └── vpu_api_test 99 | ├── include 100 | │   └── rockchip 101 | │   ├── mpp_buffer.h 102 | │   ├── mpp_compat.h 103 | │   ├── mpp_err.h 104 | │   ├── mpp_frame.h 105 | │   ├── mpp_log_def.h 106 | │   ├── mpp_log.h 107 | │   ├── mpp_meta.h 108 | │   ├── mpp_packet.h 109 | │   ├── mpp_rc_api.h 110 | │   ├── mpp_rc_defs.h 111 | │   ├── mpp_task.h 112 | │   ├── rk_hdr_meta_com.h 113 | │   ├── rk_mpi_cmd.h 114 | │   ├── rk_mpi.h 115 | │   ├── rk_type.h 116 | │   ├── rk_vdec_cfg.h 117 | │   ├── rk_vdec_cmd.h 118 | │   ├── rk_venc_cfg.h 119 | │   ├── rk_venc_cmd.h 120 | │   ├── rk_venc_rc.h 121 | │   ├── rk_venc_ref.h 122 | │   ├── vpu_api.h 123 | │   └── vpu.h 124 | └── lib 125 | ├── librockchip_mpp.so -> librockchip_mpp.so.1 126 | ├── librockchip_mpp.so.0 127 | ├── librockchip_mpp.so.1 -> librockchip_mpp.so.0 128 | ├── librockchip_vpu.so -> librockchip_vpu.so.1 129 | ├── librockchip_vpu.so.0 130 | ├── librockchip_vpu.so.1 -> librockchip_vpu.so.0 131 | └── pkgconfig 132 | ├── rockchip_mpp.pc 133 | └── rockchip_vpu.pc 134 | ``` 135 | 136 | ## `gstreamer-rockhip` aka Gstreamer Plugin 137 | **Upstream**: https://github.com/JeffyCN/mirrors/tree/gstreamer-rockchip 138 | 139 | ```shell 140 | docker buildx bake rkmpp-gstreamer-plugin 141 | ``` 142 | ``` 143 | out/rkmpp 144 | └── gstreamer 145 | └── usr 146 | └── local 147 | └── lib 148 | └── gstreamer-1.0 149 | ├── libgstkmssrc.so 150 | ├── libgstrkximage.so 151 | └── libgstrockchipmpp.so 152 | ``` 153 | 154 | [hub/rkmpp-debian]: https://hub.docker.com/r/milas/rkmpp-debian/ 155 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rock 5 Toolchain 2 | Dockerized build system for Linux kernel & related (e.g. U-Boot) components for the Radxa Rock 5 series of devices 3 | 4 | ## Prerequisites 5 | * Docker w/ buildx plugin 6 | * If `docker buildx inspect` works, you're all set! 7 | * `amd64` or `arm64` host 8 | * `amd64` uses `gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu` as provided by Radxa for cross-compilation (no configuration needed) 9 | 10 | ## Quick Start 11 | Run `docker buildx bake` from the repo root to build the Kernel and stable U-Boot. 12 | 13 | Individual groups and targets also exist if you don't want to build everything or want to use one of the experimental targets. 14 | 15 | Artifacts will be output to `out/` in the repo root: 16 | ``` 17 | out 18 | ├── edk2 19 | │   └── RK3588_NOR_FLASH.img 20 | ├── kernel 21 | │   ├── dtb 22 | │   │   └── rockchip 23 | │   │   ├── overlay 24 | │   │   ├── rk3588-rock-5b.dtb 25 | │   │   └── rk3588-rock-5b-v11.dtb 26 | │   ├── lib 27 | │   │   └── modules 28 | │   │   └── 5.10.110-gd0b0fd354269 29 | │   └── vmlinuz 30 | └── u-boot 31 | ├── collabora 32 | │   ├── idbloader.img 33 | │   ├── rk3588_spl_loader_v1.08.111.bin 34 | │   ├── spi 35 | │   │   └── spi_image.img 36 | │   └── u-boot.itb 37 | └── radxa 38 | ├── idbloader.img 39 | ├── rk3588_spl_loader_v1.08.111.bin 40 | ├── spi 41 | │   └── spi_image.img 42 | └── u-boot.itb 43 | ``` 44 | 45 | ## Kernel 46 | **Upstream**: https://github.com/radxa/kernel/tree/linux-5.10-gen-rkr3.4 47 | 48 | ```shell 49 | docker buildx bake kernel 50 | ``` 51 | ``` 52 | out/kernel 53 | ├── dtb 54 | │   └── rockchip 55 | │   ├── overlay 56 | │   ├── rk3588-rock-5b.dtb 57 | │   └── rk3588-rock-5b-v11.dtb 58 | ├── lib 59 | │   └── modules 60 | │   └── 5.10.110-gd0b0fd354269 61 | └── vmlinuz 62 | 63 | # note: tree listing limited to three levels 64 | ``` 65 | 66 | ### Custom Kernel Config (`defconfig`) 67 | You can generate a custom kernel config with the `defconfig.sh` script in this repo: 68 | ```shell 69 | ./defconfig.sh 70 | ``` 71 | 72 | This builds an image with the kernel sources and then runs `make menuconfig` in a container. 73 | Afterwards, the resulting configuration is copied to the current working directory as `rockchip_linux_defconfig`. 74 | 75 | Then, set the `DEFCONFIG` environment variable to the current directory: 76 | ```shell 77 | DEFCONFIG='.' docker buildx bake kernel 78 | ``` 79 | This adds your current directory as an extra context for the build. 80 | The build will then copy & use `rockchip_linux_config` from your current directory to be used instead of the default Radxa config. 81 | 82 | ## U-Boot 83 | The buildx `u-boot` group will build both the stable U-Boot from Radxa as well as the experimental build from Collabora's mainline fork. 84 | 85 | Once the Collabora patches have been merged into upstream U-Boot, a target will be added to build directly from that and building from Collabora's fork will eventually be deprecated. 86 | 87 | ### Radxa (Stable) 88 | **Upstream**: https://github.com/radxa/u-boot/tree/stable-5.10-rock5 89 | ```shell 90 | docker buildx bake u-boot-radxa 91 | ``` 92 | ``` 93 | out/u-boot 94 | └── radxa 95 | ├── idbloader.img 96 | ├── rk3588_spl_loader_v1.08.111.bin 97 | ├── spi 98 | │   └── spi_image.img 99 | └── u-boot.itb 100 | ``` 101 | 102 | ### Collabora (Experimental) 103 | **Upstream**: https://gitlab.collabora.com/hardware-enablement/rockchip-3588/u-boot/-/tree/2023.04-rc2-rock5b 104 | 105 | Collabora is working on upstreaming RK3588 support into mainline U-Boot. 106 | The first set of patches have been submitted as of February 2023. 107 | See details at [RK3588 Mainline U-Boot Instructions](https://gitlab.collabora.com/hardware-enablement/rockchip-3588/notes-for-rockchip-3588/-/blob/main/upstream_uboot.md). 108 | 109 | ```shell 110 | docker buildx bake u-boot-collabora 111 | ``` 112 | ``` 113 | out/u-boot 114 | └── collabora 115 | ├── idbloader.img 116 | ├── rk3588_spl_loader_v1.08.111.bin 117 | ├── spi 118 | │   └── spi_image.img 119 | └── u-boot.itb 120 | ``` 121 | 122 | ### Flashing 123 | > 💁 Put the device into [maskrom mode](https://wiki.radxa.com/Rock5/install/spi#Advanced_.28external.29_method) before proceeding! 124 | 125 | > 🐳 Replace `sudo rkdeveloptool` with `./rkdeveloptool-docker.sh` to run via container (more details in the [`rkdeveloptool` (via Docker)](#rkdeveloptool-via-docker) section) 126 | 127 | First, run the bootloader to initialize the device for flashing: 128 | ```shell 129 | sudo rkdeveloptool db ./out/rk3588_spl_loader_v1.08.111.bin 130 | ``` 131 | 132 | #### Option 1: Convenience SPI Image 133 | The `spi_image.img` includes the pre-loader and U-Boot at the right offsets and is sized for the SPI chip. 134 | ```shell 135 | docker buildx bake spl 136 | sudo rkdeveloptool wl 0x0 ./out/u-boot/radxa/spi/spi_image.img 137 | ``` 138 | 139 | #### Option 2: Individual Components 140 | Alternatively, you can write the individual components at their offsets. 141 | 142 | This is helpful for non-SPI (e.g. eMMC) to avoid destroying the GPT partition table. 143 | 144 | 1. Flash pre-loader: 145 | ```shell 146 | sudo rkdeveloptool wl 0x40 ./out/u-boot/idbloader.img 147 | ``` 148 | 2. Flash U-Boot: 149 | ```shell 150 | sudo rkdeveloptool wl 0x4000 ./out/u-boot/u-boot.itb 151 | ``` 152 | 153 | ## EDK2 154 | **Upstream**: https://github.com/edk2-porting/edk2-rk35xx 155 | ```shell 156 | docker buildx bake edk2 157 | ``` 158 | ``` 159 | out/edk2 160 | └── RK3588_NOR_FLASH.img 161 | ``` 162 | 163 | ## `rkdeveloptool` (via Docker) 164 | **Upstream**: https://github.com/rockchip-linux/rkdeveloptool 165 | 166 | This is a Dockerized build for `rkdeveloptool`, which can be run as a **privileged** container with `/dev/usb` bind-mounted from the host. 167 | 168 | A helper script, `rkdeveloptool-docker.sh`, is provided: 169 | ```shell 170 | ./rkdeveloptool-docker.sh ld 171 | ``` 172 | ``` 173 | DevNo=1 Vid=0x2207,Pid=0x350b,LocationID=704 Maskrom 174 | ``` 175 | The `out/` directory will be bind-mounted to `/out`. 176 | 177 | If you're in the repo root directory, this means you can use relative paths: 178 | ```shell 179 | # get the latest spl loader from radxa repos 180 | docker buildx bake spl 181 | 182 | # initialize the bootloader on the device in maskrom mode 183 | ./rkdeveloptool-docker.sh db ./out/rk3588_spl_loader_v1.08.111.bin 184 | ``` 185 | 186 | ## Troubleshooting 187 | ### `rkdeveloptool` Error: `Creating Comm Object failed!` 188 | Disable USB auto-suspend (run this on your host machine, not via Docker): 189 | ```shell 190 | sudo sh -c 'echo -1 > /sys/module/usbcore/parameters/autosuspend' 191 | ``` 192 | NOTE: This won't be preserved across reboots. 193 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1-labs 2 | 3 | FROM scratch AS git-kernel 4 | 5 | ARG KERNEL_REPO=https://github.com/radxa/kernel.git 6 | ARG KERNEL_REF=linux-5.10-gen-rkr3.4 7 | ADD --keep-git-dir=true ${KERNEL_REPO}#${KERNEL_REF} / 8 | 9 | # --------------------------------------------------------------------------- # 10 | 11 | FROM scratch AS git-u-boot-radxa 12 | 13 | ADD https://github.com/radxa/u-boot.git#stable-5.10-rock5 / 14 | 15 | # --------------------------------------------------------------------------- # 16 | 17 | FROM scratch AS git-u-boot-collabora 18 | 19 | ADD https://gitlab.collabora.com/hardware-enablement/rockchip-3588/u-boot.git#2023.10-rk3588 / 20 | 21 | # --------------------------------------------------------------------------- # 22 | 23 | FROM scratch AS git-rkbin 24 | 25 | ADD https://github.com/radxa/rkbin.git#master / 26 | 27 | # --------------------------------------------------------------------------- # 28 | 29 | FROM scratch AS git-radxa-build 30 | 31 | ADD https://github.com/radxa/build.git#debian / 32 | 33 | # --------------------------------------------------------------------------- # 34 | 35 | FROM scratch AS git-edk2 36 | 37 | ADD --keep-git-dir=true https://github.com/edk2-porting/edk2-rk35xx.git#master / 38 | 39 | # --------------------------------------------------------------------------- # 40 | 41 | FROM scratch AS git-rkdeveloptool 42 | 43 | ADD https://github.com/rockchip-linux/rkdeveloptool.git#master / 44 | 45 | # --------------------------------------------------------------------------- # 46 | 47 | FROM scratch AS git-bsp 48 | 49 | ADD https://github.com/radxa-repo/bsp.git#main / 50 | 51 | # --------------------------------------------------------------------------- # 52 | 53 | FROM scratch AS git-overlays 54 | 55 | ADD https://github.com/radxa/overlays.git#main / 56 | 57 | # --------------------------------------------------------------------------- # 58 | 59 | FROM --platform=${BUILDPLATFORM} alpine AS fetch 60 | RUN apk add --no-cache \ 61 | curl \ 62 | git \ 63 | ; 64 | 65 | # --------------------------------------------------------------------------- # 66 | 67 | FROM fetch AS dl-cross-compiler 68 | WORKDIR /cross-compile 69 | 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 70 | 71 | # --------------------------------------------------------------------------- # 72 | 73 | FROM --platform=linux/amd64 debian:bullseye AS sdk-base-amd64 74 | 75 | COPY --from=dl-cross-compiler --link /cross-compile /rk3588-sdk/cross-compile 76 | ENV PATH="/rk3588-sdk/cross-compile/bin:${PATH}" 77 | ENV CROSS_COMPILE=aarch64-none-linux-gnu- 78 | 79 | ENV ARCH=arm64 80 | 81 | # --------------------------------------------------------------------------- # 82 | 83 | FROM --platform=linux/arm64 debian:bullseye AS sdk-base-arm64 84 | # no extra configuration required 85 | 86 | # --------------------------------------------------------------------------- # 87 | 88 | FROM sdk-base-${BUILDARCH} AS sdk-base 89 | 90 | RUN echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache 91 | 92 | RUN --mount=type=cache,sharing=locked,id=apt-sdk-deps,target=/var/lib/apt \ 93 | --mount=type=cache,sharing=locked,id=apt-sdk-deps-cache,target=/var/cache/apt \ 94 | apt-get update \ 95 | && apt-get install -y --no-install-recommends \ 96 | bc \ 97 | bison \ 98 | build-essential \ 99 | device-tree-compiler \ 100 | dosfstools \ 101 | flex \ 102 | git \ 103 | kmod \ 104 | libncurses5 \ 105 | libncurses5-dev \ 106 | libssl-dev \ 107 | mtools \ 108 | ostree \ 109 | python \ 110 | rpm \ 111 | rsync \ 112 | u-boot-tools \ 113 | && rm -rf /var/lib/apt/lists/* \ 114 | ; 115 | 116 | WORKDIR /rk3588-sdk 117 | 118 | # --------------------------------------------------------------------------- # 119 | 120 | FROM sdk-base AS sdk 121 | 122 | COPY --from=git-rkbin --link / /rk3588-sdk/rkbin 123 | 124 | # --------------------------------------------------------------------------- # 125 | 126 | FROM sdk-base AS bsp 127 | 128 | COPY --from=git-bsp --link / /rk3588-sdk/bsp 129 | 130 | # --------------------------------------------------------------------------- # 131 | 132 | FROM scratch AS kernel-radxa-patches 133 | 134 | COPY --from=git-bsp --link /linux/rockchip / 135 | 136 | # --------------------------------------------------------------------------- # 137 | 138 | # this is a circuitous no-op intended to be overridden via a var passed to 139 | # docker buildx bake (or alternatively, CLI flags to `buildx build`) 140 | FROM scratch AS defconfig 141 | 142 | COPY --from=git-kernel --link /arch/arm64/configs/rockchip_linux_defconfig / 143 | 144 | # --------------------------------------------------------------------------- # 145 | 146 | FROM sdk AS kernel-builder 147 | 148 | COPY --from=git-kernel --link / /rk3588-sdk/kernel/ 149 | 150 | RUN rm -rf /rk3588-sdk/kernel/arch/arm64/boot/dts/rockchip/overlay 151 | COPY --from=git-overlays --link /arch/arm64/boot/dts/amlogic/overlays /rk3588-sdk/kernel/arch/arm64/boot/dts/amlogic/overlays 152 | COPY --from=git-overlays --link /arch/arm64/boot/dts/rockchip/overlays /rk3588-sdk/kernel/arch/arm64/boot/dts/rockchip/overlays 153 | COPY --from=kernel-radxa-patches --link / /rk3588-sdk/kernel/patches 154 | 155 | COPY --from=defconfig --link /rockchip_linux_defconfig /rk3588-sdk/kernel/arch/arm64/configs/rockchip_linux_defconfig 156 | 157 | RUN cd /rk3588-sdk/kernel \ 158 | && git config --global user.email "rock5-docker@milas.dev" \ 159 | && git config --global user.name "Rock 5 Docker Build User" \ 160 | && find /rk3588-sdk/kernel/patches \ 161 | -name '*.patch' \ 162 | -not -iname "*-rock-4*" \ 163 | -type f \ 164 | -print0 \ 165 | | sort -z \ 166 | | xargs -r0 git am --reject --whitespace=fix \ 167 | ; 168 | 169 | # --------------------------------------------------------------------------- # 170 | 171 | FROM kernel-builder AS kernel-build-config 172 | RUN cd /rk3588-sdk/kernel \ 173 | && make rockchip_linux_defconfig \ 174 | ; 175 | 176 | # --------------------------------------------------------------------------- # 177 | 178 | FROM kernel-build-config AS kernel-build 179 | 180 | RUN cd /rk3588-sdk/kernel \ 181 | && make -j $(nproc) \ 182 | ; 183 | 184 | FROM kernel-build-config AS kernel-build-rpm 185 | 186 | RUN cd /rk3588-sdk/kernel \ 187 | && make -j $(nproc) rpm-pkg \ 188 | ; 189 | 190 | FROM scratch AS kernel-rpm 191 | 192 | COPY --link --from=kernel-build-rpm /root/rpmbuild/RPMS/aarch64/ / 193 | COPY --link --from=kernel-build-rpm /root/rpmbuild/SRPMS/ / 194 | 195 | # --------------------------------------------------------------------------- # 196 | 197 | FROM kernel-build AS kernel-build-modules 198 | 199 | ENV INSTALL_MOD_PATH=/rk3588-sdk/out/kernel/modules 200 | RUN mkdir -p /out \ 201 | && cd /rk3588-sdk/kernel \ 202 | && make modules_install INSTALL_MOD_PATH=/out \ 203 | && rm /out/lib/modules/*/build \ 204 | && rm /out/lib/modules/*/source \ 205 | ; 206 | 207 | # --------------------------------------------------------------------------- # 208 | 209 | FROM scratch AS kernel-modules 210 | 211 | COPY --from=kernel-build-modules --link /out / 212 | 213 | # --------------------------------------------------------------------------- # 214 | 215 | FROM kernel-build AS kernel-build-firmware 216 | 217 | RUN cd /rk3588-sdk/kernel \ 218 | && make firmware \ 219 | ; 220 | 221 | # --------------------------------------------------------------------------- # 222 | 223 | FROM scratch AS kernel 224 | 225 | COPY --from=kernel-build --link /rk3588-sdk/kernel/arch/arm64/boot/Image /vmlinuz 226 | 227 | COPY --from=kernel-build --link /rk3588-sdk/kernel/arch/arm64/boot/dts/rockchip/rk3588*-rock-5*.dtb /dtb/rockchip/ 228 | COPY --from=kernel-build --link /rk3588-sdk/kernel/arch/arm64/boot/dts/rockchip/overlays/rock-5*.dtbo /dtb/rockchip/overlay/ 229 | COPY --from=kernel-build --link /rk3588-sdk/kernel/arch/arm64/boot/dts/rockchip/overlays/rk3588*.dtbo /dtb/rockchip/overlay/ 230 | COPY --from=kernel-modules --link / / 231 | 232 | # --------------------------------------------------------------------------- # 233 | 234 | FROM scratch as rkbin-spl 235 | 236 | COPY --from=git-rkbin --link /bin/rk35/rk3588_spl_loader_v1.08.111.bin / 237 | 238 | # --------------------------------------------------------------------------- # 239 | 240 | FROM sdk AS u-boot-radxa-builder 241 | 242 | COPY --from=git-radxa-build --link / /rk3588-sdk/build 243 | COPY --from=git-u-boot-radxa --link / /rk3588-sdk/u-boot 244 | 245 | # --------------------------------------------------------------------------- # 246 | 247 | FROM u-boot-radxa-builder AS u-boot-radxa-build 248 | 249 | ARG CHIP="rk3588" 250 | ARG BOARD="rock-5b" 251 | RUN ./build/mk-uboot.sh "${CHIP}-${BOARD}" \ 252 | ; 253 | 254 | # --------------------------------------------------------------------------- # 255 | 256 | FROM scratch AS u-boot-radxa 257 | 258 | COPY --from=u-boot-radxa-build --link /rk3588-sdk/out/u-boot/ / 259 | 260 | # --------------------------------------------------------------------------- # 261 | 262 | FROM sdk-base as u-boot-collabora-builder 263 | 264 | RUN --mount=type=cache,sharing=locked,id=apt-u-boot-collabora,target=/var/lib/apt \ 265 | --mount=type=cache,sharing=locked,id=apt-u-boot-collabora,target=/var/cache/apt \ 266 | apt-get update \ 267 | && apt-get install -y \ 268 | python3 \ 269 | python3-dev \ 270 | python3-pyelftools \ 271 | python3-setuptools \ 272 | swig \ 273 | && rm -rf /var/lib/apt/lists/* \ 274 | ; 275 | 276 | COPY --from=git-rkbin --link /bin/rk35/rk3588_ddr_lp4_2112MHz_lp5_2736MHz_v1.11.bin /rk3588-sdk/u-boot/rockchip-tpl 277 | COPY --from=git-rkbin --link /bin/rk35/rk3588_bl31_v1.38.elf /rk3588-sdk/u-boot/atf-bl31 278 | COPY --from=git-u-boot-collabora --link / /rk3588-sdk/u-boot 279 | 280 | WORKDIR /rk3588-sdk/u-boot 281 | 282 | # --------------------------------------------------------------------------- # 283 | 284 | FROM u-boot-collabora-builder AS u-boot-collabora-build 285 | 286 | ARG CHIP="rk3588" 287 | ARG BOARD="rock-5b" 288 | RUN cd /rk3588-sdk/u-boot \ 289 | && make "$(echo "${BOARD}" | tr -d '-')-${CHIP}_defconfig" \ 290 | && make \ 291 | ; 292 | 293 | # adapted from https://github.com/radxa/build/blob/223bcb503769e862a05ebe08c2d49348c050e732/mk-uboot.sh#L29-L41 294 | RUN <