Build Ubuntu16.04 firmware(GPT)

Foreword

The SDK development environment is on Ubuntu system. We recommend using Ubuntu 16.04 system compiles. Other Linux version may need to adjust the package accordingly. In addition to the system requirements, it also need other hardware and software requirements.

Preparatory work

Hardware requirements:

A 64 - bit system, hard disk space is more than 40 g. Multiple build, if you will need a bigger hard disk space.

Software requirements: Compiling environment initialization

  • Ubuntu 14.04 software package installation:

$ sudo apt-get install git gnupg flex bison gperf build-essential \
zip tar curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 cmake tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386 lzop lib32stdc++6
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
  • Ubuntu 16.04 software package installation:

sudo apt-get install git gcc-arm-linux-gnueabihf u-boot-tools device-tree-compiler mtools \
parted libudev-dev libusb-1.0-0-dev python-linaro-image-tools linaro-image-tools libssl-dev \
autotools-dev libsigsegv2 m4 libdrm-dev curl sed make binutils build-essential gcc g++ bash \
patch gzip bzip2 perl tar cpio python unzip rsync file bc wget libncurses5 libglib2.0-dev openssh-client lib32stdc++6
  • Install the software package related to ARM cross compiling tool chain and compiling kernel

$ sudo apt-get install gcc-arm-linux-gnueabihf \
gcc-aarch64-linux-gnu device-tree-compiler lzop libncurses5-dev \
libssl1.0.0 libssl-dev
  • Download Repo Tool:

git clone https://github.com/FireflyTeam/repo.git
  • Download Linux-SDK:

repo init --repo-url https://github.com/FireflyTeam/repo.git -u https://github.com/FireflyTeam/manifests.git -b linux-sdk -m rk3288/rk3288_linux_release.xml
  • Sync Code:

repo sync -c 

Directory

$ tree -L 1
.
├── app
├── buildroot                                               compile buildroot rootfs directory
├── build.sh -> device/rockchip/common/build.sh             automatic compile script
├── device
├── distro
├── docs                                                    document
├── envsetup.sh -> buildroot/build/envsetup.sh
├── external
├── kernel                                                  kernel directory
├── Makefile -> buildroot/build/Makefile
├── mkfirmware.sh -> device/rockchip/common/mkfirmware.sh   update rockdev script
├── prebuilts
├── rkbin
├── rkflash.sh -> device/rockchip/common/rkflash.sh         flashing firmware script
├── rootfs
├── tools
└── u-boot

Build Linux-SDK:

Precompile Configuration:

Select the Configuration file for the Board in device/rockchip/rk3288/

For example: select rk3288/aio-rk3288c.mk Run:

./build.sh aio-3288c.mk

If the configuration is successful,will create a file device/rockchip/.BoardConfig.mk , it soft links device/rockchip/rk3288/aio-3288c.mk

.BoardConfig.mk Configruation content:

# Target arch
export RK_ARCH=arm                                      
# Uboot defconfig
export RK_UBOOT_DEFCONFIG=firefly-rk3288                
# Kernel defconfig
export RK_KERNEL_DEFCONFIG=firefly_linux_defconfig      
# Kernel dts
export RK_KERNEL_DTS=rk3288-firefly-aioc                     
# parameter for GPT table
export RK_PARAMETER=parameter-ubuntu.txt
# packagefile for pack image files
export RK_PACKAGE_FILE=rk3288-ubuntu-package-file
# mkupdate for package updateimg
export RK_MKUPDATE_FILE=rk3288-mkupdate.sh
# rootfs image path
export RK_ROOTFS_IMG=buildroot/output/$RK_CFG_BUILDROOT/images/rootfs.$RK_ROOTFS_TYPE

Focus on:If you need to DIY, Open the file by “vim device/rockchip/.BoardConfig.mk”, and Modify the content you want to DIY, As an example:

  • The rootfs image you need is Ubuntu16.04:

In "# rootfs image path" Modify to:
export RK_ROOTFS_IMG=rootfs/ubuntu1604armhf-rootfs.img
  • The rootfs image you need is Debian:

In "# rootfs image path" Modify to:
export RK_ROOTFS_IMG=rootfs/linaro-rootfs.img

DTS specification for 3288 series Board

  • Firefly-rk3288

# The standard:
export RK_KERNEL_DTS=rk3288-firefly                                                                                                        
# with VGA:
export RK_KERNEL_DTS=rk3288-firefly-vga
  • AIO-3288C

# The standard:
export RK_KERNEL_DTS=rk3288-firefly-aioc
# with VGA:
export RK_KERNEL_DTS=rk3288-firefly-aioc-vga
# with LVDS(HSX101H40C):
export RK_KERNEL_DTS=rk3288-firefly-aioc-lvds
  • AIO-3288J

# The standard:
export RK_KERNEL_DTS=rk3288-firefly-aio
# with LVDS(HSX101H40C):
export RK_KERNEL_DTS=rk3288-firefly-aio-lvds

Build

  • Automatic compilation:

./build.sh 

Focus on:The script compiles the buildroot root file system by default, If the root file system you need is Debian or Ubuntu, Please ! prepare the corresponding root file system first, otherwise, when executing the build.sh script, these will be error about update partition image or packaging the firmware, This situation is explained in detail in the following “Part of compilation” : “Build rootfs”.

When the build.sh script finish, it will Move the partition image and unified firmware “update.img” to the rockdev/ directory, while creating an IMAGE/ directory backup

  • Part of compilation: 1、Build U-boot:

./build.sh uboot

2、Build kernel:

./build.sh kernle

3、Build rootfs:(The SDK supports three root file systems: buildroot, Debian, Ubuntu)

  • buildrootfs:

Compile Buildroot environment set up depends on package installation command is as follows:

sudo apt-get install repo git-core gitk git-gui gcc-arm-linux-gnueabihf u-boot-tools device-tree-compiler \
gcc-aarch64-linux-gnu mtools parted libudev-dev libusb-1.0-0-dev python-linaro-image-tools linaro-image-tools \
autoconf autotools-dev libsigsegv2 m4 intltool libdrm-dev curl sed make binutils build-essential gcc g++ bash \
patch gzip bzip2 perl tar cpio python unzip rsync file bc wget libncurses5 libqt4-dev libglib2.0-dev libgtk2.0-dev \
libglade2-dev cvs git mercurial rsync openssh-client subversion asciidoc w3m dblatex graphviz python-matplotlib \
libc6:i386 libssl-dev texinfo liblz4-tool genext2fs

After the completion of set up the environment, compile buildroot, perform the following commands:

./build.sh rootfs
  • debian:

Compile Debian environment set up depends on package installation command is as follows:

sudo apt-get install repo git-core gitk git-gui gcc-arm-linux-gnueabihf u-boot-tools device-tree-compiler \
gcc-aarch64-linux-gnu mtools parted libudev-dev libusb-1.0-0-dev python-linaro-image-tools linaro-image-tools \
gcc-4.8-multilib-arm-linux-gnueabihf gcc-arm-linux-gnueabihf libssl-dev gcc-aarch64-linux-gnu g+conf autotools-dev \
libsigsegv2 m4 intltool libdrm-dev curl sed make binutils build-essential gcc g++ bash patch gzip bzip2 perl \
tar cpio python unzip rsync file bc wget libncurses5 libqt4-dev libglib2.0-dev libgtk2.0-dev libglade2-dev cvs \
git mercurial rsync openssh-client subversion asciidoc w3m dblatex graphviz python-matplotlib libc6:i386 \
libssl-dev texinfo liblz4-tool genext2fs 

After the completion of set up the environment, compile the Debian, according to own needs, perform the following commands:

cd rootfs/

## Usage for 32bit Debian
Building a base debian system by ubuntu-build-service from linaro.

    sudo apt-get install binfmt-support qemu-user-static
    sudo dpkg -i ubuntu-build-service/packages/*
    sudo apt-get install -f
    RELEASE=stretch TARGET=desktop ARCH=armhf ./mk-base-debian.sh

Building the rk-debain rootfs with debug:

    VERSION=debug ARCH=armhf ./mk-rootfs-stretch.sh

Creating the ext4 image(linaro-rootfs.img):

    ./mk-image.sh
-----------------------------------------------------------------

## Usage for 64bit Debian
Building a base debian system by ubuntu-build-service from linaro.

    sudo apt-get install binfmt-support qemu-user-static
    sudo dpkg -i ubuntu-build-service/packages/*
    sudo apt-get install -f
    RELEASE=stretch TARGET=desktop ARCH=arm64 ./mk-base-debian.sh

Building the rk-debain rootfs with debug:

    VERSION=debug ARCH=arm64 ./mk-rootfs-stretch-arm64.sh

Creating the ext4 image(linaro-rootfs.img):

    ./mk-image.sh
  • ubuntu16.04

  1. Download The Rootfs:Ubuntu16.04 Rootfs(32bit),put it to the SDK working path;

  2. This file is 7z Compressed package, then make it decompression;

7z x ubuntu1604armhf-rootfs.7z
  1. Finally,copy it to the rootfs/

cp ubuntu1604armhf-rootfs.img rootfs/
  • Supplement:

/build.sh --help

====USAGE: build.sh modules====
uboot              -build uboot
kernel             -build kernel
rootfs             -build default rootfs, currently build buildroot as default
buildroot          -build buildroot rootfs
yocto              -build yocto rootfs, currently build ros as default
ros                -build ros rootfs
debian             -build debian rootfs
pcba               -build pcba
recovery           -build recovery
all                -build uboot, kernel, rootfs, recovery image
cleanall           -clean uboot, kernel, rootfs, recovery
firmware           -pack all the image we need to boot up system
updateimg          -pack update image
sdbootimg          -pack sdboot image
save               -save images, patches, commands used to debug
default            -build all modules
BoardConfig        -select the corresponding BoardConfig.mk file   

The recovery partition can be omitted, if you need, run as follows:

./build.sh recovery

Pack the firmware

The parameter partition table

The parameter.txt file contains important information about the firmware,for example:

path: device/rockchip/rk3288/parameter-ubuntu.txt

FIRMWARE_VER: 8.1             
MACHINE_MODEL:rk3288
MACHINE_ID:007
MANUFACTURER:RK3288
MAGIC: 0x5041524B
ATAG: 0x00200800
MACHINE: 3288
CHECK_MASK: 0x80
PWR_HLD: 0,0,A,0,1
TYPE: GPT 
CMDLINE: mtdparts=rk29xxnand:0x00002000@0x00004000(uboot),0x00002000@0x00006000(trust),0x00010000@0x0000a000(boot),0x00010000@0x0002a000(backup),-@0x0005a000(rootfs:grow)
uuid:rootfs=614e0000-0000-4b53-8000-1d28000054a9

The CMDLINE attribute is where we are concerned, using uboot as an example 0x00002000@0x00004000(uboot) as the starting position of the uboot partition 0x00002000 as the size of the partition, followed by the same. Users can add or subtract partition information according to their needs, but please keep at least the uboot,trust,boot and rootfs partition, which is the prerequisite for the machine to start normally.

  • Partition:

uboot : flashing uboot.img.
trust : flashing trust.img.
misc(omissible): flashing misc.img,responsible for starting the mode switch and first aid mode parameter transfer.
boot  : flashing boot.img,contain kernel.img and resource.img
recovery(omissible): flashing recovery.img.recovery mode image.
backup : Reserved
oem(omissible) : flashing oem.img,Used by the manufacturer to store the app or data. Read only. Mounted in the /oem directory.
rootfs : flashing rootfs.img.
userdata(omissible) : flashing userdata.img mount /userdata directory.

In the parameter.txt file, only five indispensable partitions are kept.

Note:If find rootfs partition size exceptional, execute the following command:

resize2fs /dev/mmcblk2p5

package-file

The package-file file is used to package firmware to determine the required partition image and path,and it needs to be consistent with the parameter.txt file.

for example:path:tools/linux/Linux_Pack_Firmware/rockdev/rk3288-ubuntu-package-file

# NAME          Relative path
#
#HWDEF          HWDEF
package-file    package-file
bootloader      Image/MiniLoaderAll.bin
parameter       Image/parameter.txt
trust           Image/trust.img
uboot           Image/uboot.img
boot            Image/boot.img
rootfs:grow     Image/rootfs.img
backup          RESERVED

Pack

  • Update partition image

./mkfirmware

copy the partition image to rockdev/

Tips:Sometime you will encounter the following error while running./mkfirmware

error: /home/ljh/proj/linux-sdk/buildroot/output/rockchip_rk3288_recovery/images/recovery.img not found!

It means the recovery partition is not found,which is similar to other cases such as oem.img or userdata.img, As mentioned above, these are partition images can be omitted ,So this error can be ignored.

  • Pack the firmware

./build.sh updateimg

Note:Each time you pack firmware,you need to run mkfirmware.sh to update the partition images in rockdev/

Burn firmware

Tools Download

Windows

Download AndroidTool.rar,then decompressing it , run the AndroidTool.exe , as following picture show: _images/en_win_tool.png

Premise: when the device burns firmware or partition images, it needs to be in Loader mode or Maskroom mode

Burn firmware

Steps are as follows:

  1. Switch to the “Upgrade Firmware” page;

  2. Click “Firmware” to select the firmware you wanna burn;

  3. Click “Upgrade” to start burn,finish the upgrade,will restart device;

as following picture show: _images/en_win_tool_firmware.png

Note:

  1. If the upgrade fails, try clicking the “EraseFlash” to erase Flash , then upgrade again;

  2. If the version of the firmware loader you burned is not consistent with the original machine, do “erase Flash” before upgrading the firmware;

  3. If “erase Flash” run failed , try lower version of AndroidTool, then Burn firmware with AndroidTool_v2.58

as following picture show: _images/en_win_tool_erase.png

Burn Partition Image

Steps are as follows:

  1. Switch to the “Download Image” page;

  2. Tick the partition you want to burn, you can choose more;

  3. Make sure the image file has the correct path. If necessary, click the blank table cells on the right side of the path to reselect;

  4. Click “Run” to start burn the partition image,finish it,will restart device;

as following picture show: _images/en_win_tool_partition.png

Linux

Download Upgrade_tool1.34.zip , then unzip it , copy the upgrade_tool to /usr/local/bin/

  • Burn by Upgrade_tool

# Burn the firmware
sudo upgrade_tool uf update.img

# Burn the partition images
sudo upgrade_tool ul $LOADER
sudo upgrade_tool di -p $PARAMETER
sudo upgrade_tool di -uboot $UBOOT
sudo upgrade_tool di -trust $TRUST
sudo upgrade_tool di -b $BOOT
sudo upgrade_tool di -rootfs $ROOTFS
  • Burn by Script

# Burn all image
./rkflash.sh 

# Burn the partition images
./rkflash.sh loader
./rkflash.sh parameter
./rkflash.sh uboot
./rkflash.sh trust                                                                                                                         
./rkflash.sh boot
./rkflash.sh rootfs

Note: rkflash.sh this script file works by using upgrade_tool