Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Difference between revisions of "Rockpi4/dev/Debian"

< Rockpi4‎ | dev
(Created page with "{{rockpi4_header}} {{Languages|rockpi4/dev/Debian}} ROCK Pi 4 > Development > Build Debian = Rockchip Debian SD...")
 
(15 intermediate revisions by 3 users not shown)
Line 7: Line 7:
 
= Rockchip Debian SDK =
 
= Rockchip Debian SDK =
  
Below is the instructions of how to build image for ROCK Pi 4.
+
Below is the instructions of how to build image for ROCK Pi 4 on a '''HOST PC'''.
  
 
== Get the source code ==
 
== Get the source code ==
Line 26: Line 26:
 
     build  kernel  README.md  rkbin  rootfs  u-boot
 
     build  kernel  README.md  rkbin  rootfs  u-boot
  
What are included  in these directories?
+
Directories usage introductions:
  
 
* build:
 
* build:
 
** Some script files and configuration files for building u-boot, kernel and rootfs.
 
** Some script files and configuration files for building u-boot, kernel and rootfs.
 
* kernel:  
 
* kernel:  
** kernel source code
+
** kernel source code, current version is 4.4
 
* rkbin:  
 
* rkbin:  
** Necessary files for building Rockchip loader binaries
+
** Prebuilt Rockchip binaries, include first stage loader and ATF(Arm Trustzone Firmware).
 
* rootfs:  
 
* rootfs:  
** rootfs source code
+
** Bootstrap a Debian based rootfs, support architechture armhf and arm64, support Debian Jessie and Stretch.
 
* u-boot:  
 
* u-boot:  
** u-boot source code
+
** u-boot as the second stage bootloader
  
== Install toolchain and other build tools ==
+
== Install toolchain from Linaro ==
  
     sudo apt-get install gcc-aarch64-linux-gnu device-tree-compiler libncurses5 libncurses5-dev build-essential libssl-dev
+
    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
 +
    sudo tar xvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz  -C /usr/local/
 +
    export CROSS_COMPILE=/usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
 +
    export PATH=/usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin:$PATH
 +
 
 +
Check if Linaro toolchain is the default choice:
 +
 
 +
    which aarch64-linux-gnu-gcc
 +
    /usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc
 +
 
 +
== Install other build tools ==
 +
 
 +
     sudo apt-get install gcc-aarch64-linux-gnu device-tree-compiler libncurses5 libncurses5-dev build-essential libssl-dev mtools
 +
    sudo apt-get install bc python dosfstools
  
 
== Build u-boot ==
 
== Build u-boot ==
Line 53: Line 66:
  
 
== Build kernel ==
 
== Build kernel ==
 +
Build kernel with default '''rockchip_linux_defconfig'''
  
 
     ./build/mk-kernel.sh rockpi4b    #For ROCK Pi 4 Mode B
 
     ./build/mk-kernel.sh rockpi4b    #For ROCK Pi 4 Mode B
 +
 +
=== Change kernel config(optional)===
 +
 +
Optionally, if you want to change the default kernel config
 +
 +
    cd kernel
 +
    export ARCH=arm64
 +
    export CROSS_COMPILE=aarch64-linux-gnu-
 +
    make rockchip_linux_defconfig
 +
    make menuconfig
 +
    cd ..
 +
    ./build/mk-kernel.sh rockpi4b    #For ROCK Pi 4 Mode B
 +
  
 
You will get the kernel image and dtb file
 
You will get the kernel image and dtb file
Line 62: Line 89:
  
 
== Make rootfs image ==
 
== Make rootfs image ==
 +
 +
To build 32bit rootfs:
 +
 +
    export ARCH=armhf
 +
 +
To build 64bit rootfs:
 +
 +
    export ARCH=arm64
  
 
Building a base debian system by ubuntu-build-service from linaro.
 
Building a base debian system by ubuntu-build-service from linaro.
  
     sudo apt-get install binfmt-support qemu-user-static
+
    cd rootfs
 +
     sudo apt-get install binfmt-support qemu-user-static cpio gdisk
 
     sudo dpkg -i ubuntu-build-service/packages/*        # ignore the broken dependencies, we will fix it next step
 
     sudo dpkg -i ubuntu-build-service/packages/*        # ignore the broken dependencies, we will fix it next step
 
     sudo apt-get install -f
 
     sudo apt-get install -f
     RELEASE=stretch TARGET=desktop ARCH=armhf ./mk-base-debian.sh
+
     RELEASE=stretch TARGET=desktop ARCH=$ARCH ./mk-base-debian.sh
  
This will bootstrap a Debian stretch image, you will get a rootfs tarball named `linaro-stretch-alip-xxxx.tar.gz`.  
+
This will bootstrap a Debian stretch image, you will get a rootfs tarball named '''linaro-stretch-alip-xxxx.tar.gz'''.  
  
 
Building the rk-debain rootfs with debug:
 
Building the rk-debain rootfs with debug:
  
     VERSION=debug ARCH=armhf ./mk-rootfs-stretch.sh  && ./mk-image.sh
+
     VERSION=debug ARCH=$ARCH ./mk-rootfs-stretch.sh  && ./mk-image.sh
  
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` .
+
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'''.
 
+
Please notice that when setting ARCH to armhf, you build a 32-bit rootfs. And when setting ARCH to arm64, you build a 64-bit rootfs.
+
  
 
== Combine everything into one image ==
 
== Combine everything into one image ==
Line 90: Line 124:
 
== Flash the image ==
 
== Flash the image ==
  
Follow instructions [here](http://wiki.radxa.com/Rockpi4/install).
+
For normal users, follow instructions [[Rockpi4/install | here]]. You will need the generated '''out/system.img''' only.
 +
 
 +
For developers, flash from USB OTG port, follow instructions [[Rockpi4/dev/usb-install |here]]. You will need the flash helper '''rk3399_loader_xxx.bin''' and generated '''out/system.img''' files.
  
 
== Troubleshooting ==
 
== Troubleshooting ==
  
Go to [ROCK Pi 4 FAQs](http://wiki.radxa.com/Rockpi4/FAQs)
+
Check [[Rockpi4/FAQs |ROCK Pi 4 FAQs]] first, if it doesn't help, start a new post on the forum https://forum.radxa.com/c/dev

Revision as of 02:05, 6 November 2019

    ROCK Pi 4 >  Development >  Build Debian

Rockchip Debian SDK

Below is the instructions of how to build image for ROCK Pi 4 on a HOST PC.

Get the source code

You need Git to get multiple git repositories to build the image.

Install Git if you don't have it.

   sudo apt-get update
   sudo apt-get install git

Clone the source code

   git clone --recursive https://github.com/radxa/rockchip-bsp.git

You will get

   build  kernel  README.md  rkbin  rootfs  u-boot

Directories usage introductions:

  • build:
    • Some script files and configuration files for building u-boot, kernel and rootfs.
  • kernel:
    • kernel source code, current version is 4.4
  • rkbin:
    • Prebuilt Rockchip binaries, include first stage loader and ATF(Arm Trustzone Firmware).
  • rootfs:
    • Bootstrap a Debian based rootfs, support architechture armhf and arm64, support Debian Jessie and Stretch.
  • u-boot:
    • u-boot as the second stage bootloader

Install toolchain from Linaro

   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
   sudo tar xvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz  -C /usr/local/
   export CROSS_COMPILE=/usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
   export PATH=/usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin:$PATH

Check if Linaro toolchain is the default choice:

   which aarch64-linux-gnu-gcc
   /usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc

Install other build tools

   sudo apt-get install gcc-aarch64-linux-gnu device-tree-compiler libncurses5 libncurses5-dev build-essential libssl-dev mtools
   sudo apt-get install bc python dosfstools

Build u-boot

   ./build/mk-uboot.sh rockpi4b     #For ROCK Pi 4 Mode B

The generated images will be copied to out/u-boot folder

   ls out/u-boot/
   idbloader.img  rk3399_loader_v1.12.112.bin  trust.img  uboot.img

Build kernel

Build kernel with default rockchip_linux_defconfig

   ./build/mk-kernel.sh rockpi4b    #For ROCK Pi 4 Mode B

Change kernel config(optional)

Optionally, if you want to change the default kernel config

   cd kernel
   export ARCH=arm64
   export CROSS_COMPILE=aarch64-linux-gnu-
   make rockchip_linux_defconfig
   make menuconfig
   cd ..
   ./build/mk-kernel.sh rockpi4b    #For ROCK Pi 4 Mode B


You will get the kernel image and dtb file

   ls out/kernel/
   Image  rockpi-4b-linux.dtb

Make rootfs image

To build 32bit rootfs:

   export ARCH=armhf

To build 64bit rootfs:

   export ARCH=arm64

Building a base debian system by ubuntu-build-service from linaro.

   cd rootfs
   sudo apt-get install binfmt-support qemu-user-static cpio gdisk
   sudo dpkg -i ubuntu-build-service/packages/*        # ignore the broken dependencies, we will fix it next step
   sudo apt-get install -f
   RELEASE=stretch TARGET=desktop ARCH=$ARCH ./mk-base-debian.sh

This will bootstrap a Debian stretch image, you will get a rootfs tarball named linaro-stretch-alip-xxxx.tar.gz.

Building the rk-debain rootfs with debug:

   VERSION=debug ARCH=$ARCH ./mk-rootfs-stretch.sh  && ./mk-image.sh

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.

Combine everything into one image

   build/mk-image.sh -c rk3399 -t system -r rootfs/linaro-rootfs.img

This will combine u-boot, kernel and rootfs into one image and generate GPT partition table. Output is

   out/system.img

Flash the image

For normal users, follow instructions here. You will need the generated out/system.img only.

For developers, flash from USB OTG port, follow instructions here. You will need the flash helper rk3399_loader_xxx.bin and generated out/system.img files.

Troubleshooting

Check ROCK Pi 4 FAQs first, if it doesn't help, start a new post on the forum https://forum.radxa.com/c/dev