├── .gitmodules ├── README.md └── docker └── Dockerfile /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "build"] 2 | path = build 3 | url = ../build.git 4 | [submodule "rkbin"] 5 | path = rkbin 6 | url = ../rkbin.git 7 | [submodule "u-boot"] 8 | path = u-boot 9 | url = ../u-boot.git 10 | [submodule "rootfs"] 11 | path = rootfs 12 | url = ../rk-rootfs-build.git 13 | [submodule "kernel"] 14 | path = kernel 15 | url = ../kernel.git 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rockchip Debian SDK 2 | 3 | Below is the instructions of how to build image for ROCK Pi 4 on a HOST PC. 4 | 5 | ## Get the source code 6 | 7 | Note that here the non-root user is jack and we are at the home folder. 8 | 9 | $ cd ~ 10 | $ pwd 11 | /home/jack 12 | 13 | When you have a different name, like rose, you can replace jack with rose in the next parts of this guide. 14 | 15 | Command prepended by $ means the command may be executed by an unprivileged user. And command prepended by # means the command may be executed by an privileged user. But the symbol, $ or #, is not part of the command. 16 | 17 | You need Git to get multiple git repositories to build the image. 18 | 19 | Install Git if you don't have it. 20 | 21 | $ sudo apt-get update && sudo apt-get upgrade 22 | $ sudo apt-get install git 23 | 24 | Clone the source code 25 | 26 | $ git clone -b master https://github.com/radxa/rockchip-bsp.git 27 | $ cd rockchip-bsp 28 | $ git submodule init 29 | $ git submodule update 30 | 31 | You will get 32 | 33 | build kernel README.md rkbin rootfs u-boot 34 | 35 | Directories usage introductions: 36 | 37 | * build: 38 | * Some script files and configuration files for building u-boot, kernel and rootfs. 39 | 40 | * kernel: 41 | * kernel source code, current version is 4.4 42 | 43 | * rkbin: 44 | * Prebuilt Rockchip binaries, include first stage loader and ATF(Arm Trustzone Firmware). 45 | 46 | * rootfs: 47 | * Bootstrap a Debian based rootfs, support architechture armhf and arm64, support Debian Jessie, Stretch and Buster. 48 | 49 | * u-boot: 50 | * u-boot as the second stage bootloader 51 | 52 | * docker: 53 | * Init a ubuntu 16.04 build environment for easier building u-boot, kernel, rootfs and system. 54 | 55 | ## Update the source code 56 | 57 | The rockchip-bsp will be updated all the time, so you can update the source to get more fearures before building the system image. 58 | 59 | $ cd ~/rockchip-bsp 60 | $ git checkout master 61 | $ git fetch origin 62 | $ git rebase origin/master 63 | $ git submodule update 64 | 65 | ## Build images 66 | 67 | Two methods of building images will be shown in the next parts. One uses Docker (Part one) and the other doesn't (Part two). Just select one part and start to build your wanted images. 68 | 69 | ### Part one 70 | 71 | #### Install Docker 72 | 73 | $ sudo apt-get update 74 | $ sudo apt-get install binfmt-support qemu-user-static 75 | $ sudo apt-get install \ 76 | apt-transport-https \ 77 | ca-certificates \ 78 | curl \ 79 | software-properties-common 80 | $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 81 | $ sudo apt-key fingerprint 0EBFCD88 82 | 83 | pub 4096R/0EBFCD88 2017-02-22 84 | Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 85 | uid Docker Release (CE deb) 86 | sub 4096R/F273FCD8 2017-02-22 87 | 88 | $ sudo add-apt-repository \ 89 | "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ 90 | $(lsb_release -cs) \ 91 | stable" 92 | 93 | $ sudo apt-get update 94 | $ sudo apt-get install docker-ce 95 | $ apt-cache madison docker-ce 96 | 97 | docker-ce | 18.09.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages 98 | 99 | $ sudo apt-get install docker-ce= 100 | 101 | Go to the docker folder. 102 | 103 | $ cd ~/rockchip-bsp/docker 104 | 105 | Build a Docker image, called rockchip-radxa:1. 106 | 107 | $ sudo docker build -t rockchip-radxa:1 -f ./Dockerfile . 108 | 109 | Now the Docker image, rockchip-radxa:1, is ready. You just need to build Docker image once. Everytime you want to build images, just run a Docker container. 110 | 111 | #### Run a Docker container 112 | 113 | $ docker run --privileged -it -v /home/jack/rockchip-bsp:/root rockchip-radxa:1 /bin/bash 114 | 115 | Now the Docker container should be running. 116 | 117 | Here Docker bind mounts /home/jack/rockchip-bsp in the host to /root in the Docker container. cd /root and ls will show: 118 | 119 | # cd /root 120 | # ls 121 | build kernel README.md rkbin rootfs u-boot 122 | 123 | #### Build u-boot 124 | 125 | # cd /root 126 | # ./build/mk-uboot.sh rockpi4b #For ROCK Pi 4 Mode B 127 | 128 | The generated images will be copied to out/u-boot folder 129 | 130 | # ls out/u-boot/ 131 | idbloader.img rk3399_loader_v1.12.112.bin trust.img uboot.img 132 | 133 | #### Build kernel 134 | 135 | # ./build/mk-kernel.sh rockpi4b #For ROCK Pi 4 Mode B 136 | 137 | You will get the kernel image and dtb file 138 | 139 | # ls out/kernel/ 140 | Image rockpi-4b-linux.dtb 141 | 142 | #### Make rootfs image 143 | 144 | To build 32bit rootfs: 145 | 146 | # export ARCH=armhf 147 | 148 | To build 64bit rootfs: 149 | 150 | # export ARCH=arm64 151 | 152 | Building a base debian system by ubuntu-build-service from linaro. 153 | 154 | # cd rootfs 155 | # dpkg -i ubuntu-build-service/packages/* # ignore the broken dependencies, we will fix it next step 156 | # apt-get install -f 157 | # RELEASE=buster TARGET=desktop ARCH=${ARCH} ./mk-base-debian.sh 158 | 159 | This will bootstrap a Debian buster image, you will get a rootfs tarball named `linaro-buster-alip-xxxx.tar.gz`. 160 | 161 | Building the rk-debain rootfs with debug: 162 | 163 | # VERSION=debug ARCH=${ARCH} ./mk-rootfs-buster.sh && ./mk-image.sh 164 | 165 | This will install Rockchip specified packages and hooks on the standard Debian rootfs and generate an ext4 format rootfs image at `rootfs/linaro-rootfs.img` . 166 | 167 | #### Combine everything into one image 168 | 169 | Generate system image with two partitions. 170 | 171 | # build/mk-image.sh -c rk3399 -t system -r rootfs/linaro-rootfs.img 172 | 173 | Generate ROCK Pi 4 system image with five partitions. 174 | 175 | # build/mk-image.sh -c rk3399 -b rockpi4 -t system -r rootfs/linaro-rootfs.img 176 | 177 | This will combine u-boot, kernel and rootfs into one image and generate GPT partition table. Output is 178 | 179 | out/system.img 180 | 181 | #### Exit Docker 182 | 183 | After getting all the wanted images, exit Docker; 184 | 185 | # exit 186 | 187 | In the host, all generated images are in the ~/rockchip-bsp/out directory. 188 | 189 | ### Part two 190 | 191 | When you don't want to use Docker to build images, you can try this way. 192 | 193 | Note that if you just used Docker to build the images, then you can't wait to try the new method, there may be operational permissions issues. 194 | 195 | #### Install toolchain from Linaro 196 | 197 | $ wget https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz 198 | $ sudo tar xvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz -C /usr/local/ 199 | $ export CROSS_COMPILE=/usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- 200 | $ export PATH=/usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin:$PATH 201 | 202 | Check if Linaro toolchain is the default choice: 203 | 204 | $ which aarch64-linux-gnu-gcc 205 | $ /usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc 206 | 207 | #### Install other build build tools 208 | 209 | $ sudo apt-get install gcc-aarch64-linux-gnu device-tree-compiler libncurses5 libncurses5-dev build-essential libssl-dev mtools bc python dosfstools 210 | 211 | #### Build u-boot/ 212 | 213 | $ cd ~/rockchip-bsp 214 | $ ./build/mk-uboot.sh rockpi4b #For ROCK Pi 4 Mode B 215 | 216 | The generated images will be copied to out/u-boot folder 217 | 218 | $ ls out/u-boot/ 219 | idbloader.img rk3399_loader_v1.12.112.bin trust.img uboot.img 220 | 221 | #### Build kernel 222 | 223 | $ ./build/mk-kernel.sh rockpi4b #For ROCK Pi 4 Mode B 224 | 225 | You will get the kernel image and dtb file 226 | 227 | $ ls out/kernel/ 228 | Image rockpi-4b-linux.dtb 229 | 230 | #### Make rootfs image 231 | 232 | To build 32bit rootfs: 233 | 234 | $ export ARCH=armhf 235 | 236 | To build 64bit rootfs: 237 | 238 | $ export ARCH=arm64 239 | 240 | Building a base debian system by ubuntu-build-service from linaro. 241 | 242 | $ cd rootfs 243 | $ sudo apt-get install binfmt-support qemu-user-static gdisk 244 | $ sudo dpkg -i ubuntu-build-service/packages/* # ignore the broken dependencies, we will fix it next step 245 | $ sudo apt-get install -f 246 | $ RELEASE=buster TARGET=desktop ARCH=${ARCH} ./mk-base-debian.sh 247 | 248 | This will bootstrap a Debian buster image, you will get a rootfs tarball named `linaro-buster-alip-xxxx.tar.gz`. 249 | 250 | Building the rk-debain rootfs with debug: 251 | 252 | $ VERSION=debug ARCH=${ARCH} ./mk-rootfs-buster.sh && ./mk-image.sh 253 | 254 | This will install Rockchip specified packages and hooks on the standard Debian rootfs and generate an ext4 format rootfs image at `rootfs/linaro-rootfs.img` . 255 | 256 | #### Combine everything into one image 257 | 258 | Generate system image with two partitions. 259 | 260 | $ build/mk-image.sh -c rk3399 -t system -r rootfs/linaro-rootfs.img 261 | 262 | Generate ROCK Pi 4 system image with five partitions. 263 | 264 | $ build/mk-image.sh -c rk3399 -b rockpi4 -t system -r rootfs/linaro-rootfs.img 265 | 266 | This will combine u-boot, kernel and rootfs into one image and generate GPT partition table. Output is 267 | 268 | out/system.img 269 | 270 | ## Flash the image 271 | 272 | For normal users, follow instructions [installation](http://wiki.radxa.com/Rockpi4/install). You will need the generated '''out/system.img''' only. 273 | 274 | For developers, flash from USB OTG port, follow instructions [usb-installation](http://wiki.radxa.com/Rockpi4/dev/usb-install). You will need the flash helper '''rk3399_loader_xxx.bin''' and generated '''out/system.img''' files. 275 | 276 | ## Troubleshooting 277 | 278 | Go to [ROCK Pi 4 FAQs](http://wiki.radxa.com/Rockpi4/FAQs) 279 | 280 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | # Add apt sources 4 | RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse" > /etc/apt/sources.list 5 | RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse" >> /etc/apt/sources.list 6 | RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse" >> /etc/apt/sources.list 7 | RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse" >> /etc/apt/sources.list 8 | 9 | # Install system packages 10 | RUN export DEBIAN_FRONTEND=noninteractive \ 11 | && apt-get update \ 12 | && apt-get install -y --no-install-recommends \ 13 | apt-utils \ 14 | automake \ 15 | bc \ 16 | binfmt-support \ 17 | bison \ 18 | build-essential \ 19 | ca-certificates \ 20 | ccache \ 21 | cmake \ 22 | cpio \ 23 | crossbuild-essential-arm64 \ 24 | curl \ 25 | device-tree-compiler \ 26 | devscripts \ 27 | dh-exec \ 28 | dh-make \ 29 | dosfstools \ 30 | dpkg-dev \ 31 | fakeroot \ 32 | flex \ 33 | gcc-aarch64-linux-gnu \ 34 | gdisk \ 35 | git \ 36 | kmod \ 37 | libncurses5 \ 38 | libncurses5-dev \ 39 | libssl-dev \ 40 | locales \ 41 | mtools \ 42 | parted \ 43 | pkg-config \ 44 | pv \ 45 | python \ 46 | python3-dev \ 47 | python-dev \ 48 | qemu-user-static \ 49 | sudo \ 50 | swig \ 51 | udev \ 52 | live-build \ 53 | && rm -rf /var/lib/apt/lists/* 54 | 55 | # Set the locale 56 | RUN locale-gen en_US.UTF-8 57 | ENV LANG en_US.UTF-8 58 | ENV LANGUAGE en_US:en 59 | ENV LC_ALL en_US.UTF-8 60 | 61 | --------------------------------------------------------------------------------