Compile Linux5.10 firmware Build the build environment This chapter introduces the compilation environment of the Linux SDK Note: (1) It is recommended to develop in the Ubuntu 18.04 system environment. If other system versions are used, the compilation environment may need to be adjusted accordingly. (2) Compile with ordinary user, do not compile with root user authority. Download Firefly_Linux_SDK First prepare an empty folder to place SDK, better under home, here we use "~/proj" as example. Attention: To avoid unnecessary errors, please do not place/unzip the SDK in VM shared folders or non-english directories. Get SDK needs: sudo apt update sudo apt install -y repo git python Method One Download via repo, you can choose to get full SDK or BSP: # Create SDK directory mkdir ~/proj/rk356x_sdk-linux5.10 cd ~/proj/rk356x_sdk-linux5.10 ## Full SDK repo init --no-clone-bundle --repo-url https://gitlab.com/firefly-linux/git-repo.git --no-repo-verify -u https://gitlab.com/firefly-linux/manifests.git -b master -m rk356x_linux5.10_release.xml ## BSP (Only include some basic repositories and compile tools) ## BSP includes device/rockchip, docs, kernel, u-boot, rkbin, tools and cross-compile toolchian repo init --no-clone-bundle --repo-url https://gitlab.com/firefly-linux/git-repo.git --no-repo-verify -u https://gitlab.com/firefly-linux/manifests.git -b master -m rk356x_linux5.10_bsp_release.xml Method Two Download Firefly_Linux_SDK sub-volume compressed package: rk356x_linux5.10_release_20240319_v1.4.0b Extract the SDK: # add execution permissions cd /path/to/rk356x_linux5.10_release_20240319_v1.4.0b chmod +x ./sdk_tools.sh # create SDK directory mkdir -p ~/proj/rk356x_sdk-linux5.10 # unzip ./sdk_tools.sh --unpack -C ~/proj/rk356x_sdk-linux5.10 # restore working directory ./sdk_tools.sh --sync -C ~/proj/rk356x_sdk-linux5.10 Sync Code Execute the following command to synchronize the code: # Enter the SDK root directory cd ~/proj/rk356x_sdk-linux5.10 # Sync .repo/repo/repo sync -c --no-tags .repo/repo/repo start firefly --all You can use the following command to update the SDK later: .repo/repo/repo sync -c --no-tags Directory . ├── app ├── buildroot # Buildroot root filesystem build directory ├── build.sh -> device/rockchip/common/build.sh # Compile script ├── device # Compile related configuration files ├── docs # Documentation ├── envsetup.sh -> buildroot/build/envsetup.sh ├── external ├── kernel # Kernel ├── Makefile -> buildroot/build/Makefile ├── prebuilts # Cross compilation toolchain ├── rkbin ├── tools # Tools directory └── u-boot # U-Boot Install dependencies Method 1: Install directly on PC: sudo apt-get install repo git ssh make gcc libssl-dev liblz4-tool \ expect g++ patchelf chrpath gawk texinfo chrpath diffstat binfmt-support \ qemu-user-static live-build bison flex fakeroot cmake \ unzip device-tree-compiler python-pip ncurses-dev python-pyelftools Method 2: Use Docker Use dockerfile to create a container, build SDK in the container, it will perfectly solve environment problems and isolate with host environments. First install docker in the host PC, you can refer to Docker instructions Create an empty folder as docker work dir, like "~/docker/", then touch a dockerfile with contents: FROM ubuntu:18.04 MAINTAINER firefly "service@t-firefly.com" ENV DEBIAN_FRONTEND=noninteractive RUN apt update RUN apt install -y build-essential crossbuild-essential-arm64 \ bash-completion vim sudo locales time rsync bc python RUN apt install -y repo git ssh libssl-dev liblz4-tool lib32stdc++6 \ expect patchelf chrpath gawk texinfo diffstat binfmt-support \ qemu-user-static live-build bison flex fakeroot cmake \ unzip device-tree-compiler python-pip ncurses-dev python-pyelftools \ subversion asciidoc w3m dblatex graphviz python-matplotlib cpio \ libparse-yapp-perl default-jre patchutils swig expect-dev u-boot-tools RUN apt update && apt install -y -f # language support RUN locale-gen en_US.UTF-8 ENV LANG en_US.UTF-8 # switch to a no-root user RUN useradd -c 'firefly user' -m -d /home/firefly -s /bin/bash firefly RUN sed -i -e '/\%sudo/ c \%sudo ALL=(ALL) NOPASSWD: ALL' /etc/sudoers RUN usermod -a -G sudo firefly USER firefly WORKDIR /home/firefly Create image cd ~/docker docker build -t sdkcompiler . # sdkcompiler is image name, you can change it, notice that there's a '.' at the end of cmd # This process takes a while, please wait Then create a container # Here we mount host SDK location into the container, so that you can access SDK inside container # source= is host SDK location; target= is a folder inside container, must be an empty folder # ubuntu18 is container name, firefly is container's hostname, you can change them # sdkcompiler is the image created in last step docker run --privileged --mount type=bind,source=/home/fierfly/proj,target=/home/firefly/proj --name="ubuntu18" -h firefly -it sdkcompiler Now you can build SDK inside the container. How to quit container and how to reopen: # Execute "exit" inside container will quit and close it # See all containers (include exited ones) docker ps -a # Start an exited container and attach it docker start ubuntu18 # container name docker attach ubuntu18 Compile Ubuntu firmware This chapter introduces the compilation process of Ubuntu firmware. It is recommended to develop under Ubuntu 18.04 system environment. If you use other system versions, you may need to adjust the compilation environment accordingly. A brief introduction to Ubuntu firmware What is Ubuntu Minimal ? What is Ubuntu Desktop ? Build Linux-SDK Precompile Configuration There are configuration files for different board in "device/rockchip/rk3566_rk3568/". Return to SDK root directory to select the configuration file: ./build.sh firefly_rk3568_roc-rk3568-pc-se_ubuntu_defconfig The configuration file will be connected to "output/defconfig", check the file to verify whether the configuration is successful. Configruation content: # prebuilt rootfs PREBUILT_ROOTFS_IMG="prebuilt_rootfs/rk356x_ubuntu_rootfs.img" # UART for bluetooth RK_WIFIBT_TTY="ttyS8" # kernel defconfig RK_KERNEL_CFG="firefly_linux_defconfig" # device tree name RK_KERNEL_DTS_NAME="rk3568-firefly-roc-pc-se" # ramdisk image RK_RAMDISK_IMG="ramdisk.img" # image tree source for boot partition image RK_BOOT_FIT_ITS="bootramdisk.its" # prebuilt recovery image RK_RECOVERY_RAMDISK="rk356x-recovery-arm64.cpio.gz" # parameter RK_PARAMETER="parameter-ubuntu-fit.txt" # use FIT image RK_USE_FIT_IMG=y # use extlinux way to load kernel USE_EXTBOOT=y Download Ubuntu filesystem Download: Ubuntu rootfs(64-bit),put in SDK path Unzip # For example, the archive you download is Ubuntu20.04-xxx_RK3568_KERNEL-5.10_xxx.7z 7z x Ubuntu20.04-xxx_RK3568_KERNEL-5.10_xxx.7z Move filesystem to prebuilt_rootfs/ mkdir prebuilt_rootfs # For example, after unzip, the filesystem image is Ubuntu20.04-xxx_RK3568_KERNEL-5.10_xxx.img mv Ubuntu20.04-xxx_RK3568_KERNEL-5.10_xxx.img prebuilt_rootfs/ ln -sf Ubuntu20.04-xxx_RK3568_KERNEL-5.10_xxx.img rk356x_ubuntu_rootfs.img Automatic compilation The automatic compilation will perform all compilation and packaging operations to generate RK firmware. ./build.sh all Firmware will be saved to the directory "output/update/". Partial compilation u-boot ./build.sh uboot Output image is u-boot/uboot.img kernel Notice:Firefly kernel does not come with all kernel features, need extra kernel features please refer to Kernel ./build.sh extboot Output image is kernel/extboot.img Pack the firmware ./build.sh updateimg Pack the firmware, the firmware will be saved to the directory "rockdev/pack/". Partition table parameter The parameter.txt file contains the partition information of the firmware. Take parameter-ubuntu-fit.txt as an example: path: "device/rockchip/rk3566_rk3568/parameter-ubuntu-fit.txt" FIRMWARE_VER: 1.0 MACHINE_MODEL: RK3568 MACHINE_ID: 007 MANUFACTURER: RK3568 MAGIC: 0x5041524B ATAG: 0x00200800 MACHINE: 0xffffffff CHECK_MASK: 0x80 PWR_HLD: 0,0,A,0,1 TYPE: GPT GROW_ALIGN: 0 CMDLINE: mtdparts=rk29xxnand:0x00002000@0x00004000(uboot),0x00002000@0x00006000(misc),0x00040000@0x00008000(boot:bootable),0x00020000@0x00048000(recovery),0x00010000@0x00068000(backup),0x00c00000@0x00078000(rootfs),-@0x00c78000(userdata:grow) uuid:rootfs=614e0000-0000-4b53-8000-1d28000054a9 The CMDLINE attribute is where we are concerned. Take uboot as an example. In 0x00002000@0x00004000(uboot), 0x00004000 is the starting position of the uboot partition, 0x00002000 is the size of the partition, and so on. The unit is block, each block is 512 Byte. Compile Buildroot firmware This chapter introduces the compilation process of Buildroot firmware. It is recommended to develop in the Ubuntu 18.04 system environment. If you use other system versions, you may need to adjust the compilation environment accordingly. Compile SDK Configuration before compilation In the "device/rockchip/rk3566_rk3568/" directory, there are configuration files of different board types. Return to SDK root directory to select the configuration file: ./build.sh firefly_rk3568_roc-rk3568-pc-se_buildroot_defconfig The configuration file will be linked to "output/defconfig", check the file to verify whether the configuration is successful. Related configuration introduction: # device tree name RK_KERNEL_DTS_NAME="rk3568-firefly-roc-pc-se" # kernel defconfig RK_KERNEL_CFG="firefly_linux_defconfig" # use FIT image RK_USE_FIT_IMG=y # UART for bluetooth RK_WIFIBT_TTY="ttyS8" # parameter RK_PARAMETER="parameter-buildroot-fit.txt" # image tree source of boot partition image RK_BOOT_FIT_ITS="bootramdisk.its" # ramdisk image RK_RAMDISK_IMG="ramdisk.img" # use extlinux way to load kernel USE_EXTBOOT=y Automatic compilation Fully automatic compilation will perform all compilation and packaging operations to generate complete firmware. ./build.sh all Firmware will be saved to "output/update/" directory Partial compilation Compile u-boot ./build.sh uboot Output image is u-boot/uboot.img Compile kernel Notice:Firefly kernel does not come with all kernel features, need extra kernel features please refer to Kernel ./build.sh extboot Output image is kernel/extboot.img Compile recovery ./build.sh recovery Outputs are under output/recovery Compile Buildroot root filesystem ./build.sh buildroot # Note: Make sure to compile the Buildroot root filesystem as a normal user to avoid unnecessary errors. Compiling the Buildroot root filesystem will generate a compilation output directory in "buildroot/output" Package the firmware ./build.sh updateimg Pack the firmware, the generated complete firmware will be saved to the "output/update/" directory. Partition description parameter partition table The parameter.txt file contains the partition information of the firmware. Take "parameter-buildroot-fit.txt" as an example: Path: "device/rockchip/rk3566_rk3568/parameter-buildroot-fit.txt" FIRMWARE_VER: 1.0 MACHINE_MODEL: RK3568 MACHINE_ID: 007 MANUFACTURER: RK3568 MAGIC: 0x5041524B ATAG: 0x00200800 MACHINE: 0xffffffff CHECK_MASK: 0x80 PWR_HLD: 0,0,A,0,1 TYPE: GPT GROW_ALIGN: 0 CMDLINE: mtdparts=:0x00002000@0x00004000(uboot),0x00002000@0x00006000(misc),0x00040000@0x00008000(boot:bootable),0x00020000@0x00048000(recovery),0x00010000@0x00068000(backup),0x00040000@0x00078000(oem),0x00c00000@0x000b8000(rootfs),-@0x00cb8000(userdata:grow) uuid:rootfs=614e0000-0000-4b53-8000-1d28000054a9 The CMDLINE attribute is our focus. Taking uboot as an example, 0x00004000 in 0x00002000@0x00004000(uboot) is the starting position of the uboot partition, 0x00002000 is the size of the partition, and so on. The unit is block, each block is 512 Byte.