====== Edge2 Rockchip Linux SDK developer guide ====== ===== Introduction ===== The Rockchip Linux SDK support Buildroot, Debian and Yocto. We will introduce how to build Edge2 firmware using the Rockchip Linux SDK here. For readability, the subsequent Rockchip Linux SDK will be referred to as SDK. ===== Preparation ===== Install essential dependencies. **It is recommended to use Ubuntu 22.04 for compilation**, or you can choose to [[#build-in-docker | Build in Docker]]. ```shell $ sudo apt update && sudo apt install -y git ssh make gcc libssl-dev \ liblz4-tool expect expect-dev g++ patchelf chrpath gawk texinfo chrpath \ diffstat binfmt-support qemu-user-static live-build bison flex fakeroot \ cmake gcc-multilib g++-multilib unzip device-tree-compiler ncurses-dev \ libgucharmap-2-90-dev bzip2 expat gpgv2 cpp-aarch64-linux-gnu libgmp-dev \ libmpc-dev bc python-is-python3 python2 libstdc++-12-dev xz-utils repo git-lfs ``` ===== Get SDK ===== 1. Download the base SDK packages here: [[https://dl.khadas.com/development/yocto/khadas_edges_yocto_sdk_base/ | khadas_edges_yocto_sdk_base.tar.gz0x]] You need to download all 5 compressed files: * khadas_edges_yocto_sdk_base.tar.gz00 * khadas_edges_yocto_sdk_base.tar.gz01 * khadas_edges_yocto_sdk_base.tar.gz02 * khadas_edges_yocto_sdk_base.tar.gz03 * khadas_edges_yocto_sdk_base.tar.gz04 You can also download the [[dl>development/yocto/khadas_edges_yocto_sdk_base/md5sum/ | md5 checksum]] to verify the downloaded files: ```shell $ md5sum -c md5sum/* khadas_edges_yocto_sdk_base.tar.gz00: OK khadas_edges_yocto_sdk_base.tar.gz01: OK khadas_edges_yocto_sdk_base.tar.gz02: OK khadas_edges_yocto_sdk_base.tar.gz03: OK khadas_edges_yocto_sdk_base.tar.gz04: OK ``` 2. Create and enter the working directory: ```shell $ mkdir -p ~/project/edge2-linux-sdk && cd ~/project/edge2-linux-sdk ``` 3. Decompress base SDK: ```shell $ cat path/to/sdk-base-packages/khadas_edges_yocto_sdk_base.tar.gz* | tar -zxv -C ~/project/edge2-linux-sdk ``` 4. Then you can see ''.repo'' derctory in ''~/project/edge2-linux-sdk'' directory by using ''ls -la'' command. ```shell $ ls -al ~/project/edge2-linux-sdk total 12 drwxrwxr-x 3 nick nick 4096 Dec 31 14:40 . drwxrwxr-x 3 nick nick 4096 Dec 31 14:39 .. drwxrwxr-x 7 nick nick 4096 Dec 30 16:21 .repo ``` 5. Sync and update code: ```shell $ .repo/repo/repo sync -l $ .repo/repo/repo sync -c $ ls Copyright_Statement.md Makefile app build.sh buildroot debian device docs external kernel prebuilts rkbin rkflash.sh tools u-boot yocto ``` 6. Sync large files: ```shell $ .repo/repo/repo forall -c 'git lfs pull' ``` 7. If you need to build Yocto, please disable the auto-detaching feature of git gc: ```shell $ git config --global gc.autoDetach false ``` 8. Create a work branch for each repository: ```shell $ .repo/repo/repo start khadas --all ``` ===== Update SDK ===== In the future, you can use the following command to update the SDK code: ```shell $ cd ~/project/edge2-linux-sdk $ .repo/repo/repo sync -c ``` ===== Introduction to SDK project directory ===== The SDK project directory includes buildroot, debian, app, kernel, u-boot, device, docs, external, etc. Repositories are managed by manifests, and the repo tool is utilized to manage each directory or its corresponding Git project, including the following subdirectories: * app : Contains upper-level application apps, mainly various application demos. * buildroot : Contains the root file system developed with Buildroot. * debian : Contains the root file system developed with Debian. * device/rockchip : Contains chip board-level configurations and scripts/files for compiling and packaging firmware. * docs : Contains general development guides, Linux system development guides, chip platform-related documents, etc. * external : Contains third-party related repositories, including display, audio/video, camera, network, security, etc. * kernel : Contains Kernel development code. * output : Contains firmware information, compilation details, XML files, host environment, etc., generated during each build. * prebuilts : Contains cross-compilation toolchains. * rkbin : Contains Rockchip-related binaries and tools. * rockdev : Contains compiled output firmware, actually, it soft link to xxx output/firmware . * tools : Contains commonly used tools for both Linux and Windows operating systems. * u-boot : Contains U-Boot code developed based on version v2017.09. * yocto : Contains the root file system developed with Yocto. ===== Compilation ===== The SDK can be easily compiled using the ''build.sh'' script. ==== Setup the Compile Configuration ==== You should setup the compile configuration before compilation. ```shell $ cd $ ./build.sh lunch ``` Just input the number of ''khadas_rk3588s_edge2_xxx_defconfig'' is ok. ''xxx'' can be ''buildroot'', ''debian'', ''yocto''. There are three configuration files for Edge2 in /device/rockchip/rk3588/ ```shell $ ls /device/rockchip/rk3588/khadas_rk3588s_edge2_* khadas_rk3588s_edge2_buildroot_defconfig # for Buildroot khadas_rk3588s_edge2_debian_defconfig # for Debian khadas_rk3588s_edge2_yocto_defconfig # for Yocto ``` The ''khadas_rk3588s_edge2_xxx_defconfig'' content is as follow: ```bash khadas_rk3588s_edge2_buildroot_defconfig KHADAS=y # Flag of Khadas RK_BUILDROOT_BASE_CFG="rk3588s_edge2" # Indicate Buildroot default configuration file RK_ROOTFS_HOSTNAME_CUSTOM=y # Custom the host name RK_ROOTFS_HOSTNAME="Edge2" # Set the host name as Edge2 RK_UBOOT_CFG="khadas-edge2-rk3588s" # Indicate U-Boot default configuration file RK_KERNEL_CFG="kedges_defconfig" # Indicate Kernel default configuration file RK_KERNEL_DTS_NAME="rk3588s-khadas-edge2" # Indicate Kernel DTS file RK_USE_FIT_IMG=y # Use FIT Image ``` ```bash khadas_rk3588s_edge2_debian_defconfig RK_ROOTFS_SYSTEM_DEBIAN=y # Set Debian as default rootfs. RK_ROOTFS_HOSTNAME_CUSTOM=y # Custom the host name RK_ROOTFS_HOSTNAME="Edge2" # Set the host name as Edge2 RK_UBOOT_CFG="khadas-edge2-rk3588s" # Indicate U-Boot default configuration file RK_KERNEL_CFG="kedges_defconfig" # Indicate Kernel default configuration file RK_KERNEL_DTS_NAME="rk3588s-khadas-edge2" # Indicate Kernel DTS file RK_USE_FIT_IMG=y # Use FIT Image ``` ```bash khadas_rk3588s_edge2_yocto_defconfig RK_YOCTO_CFG_CUSTOM=y # Use custom configuration file RK_YOCTO_CFG="khadas-edge2.conf" # Custom configuration file name RK_ROOTFS_SYSTEM_YOCTO=y # Set Yocto as default rootfs. RK_ROOTFS_HOSTNAME_CUSTOM=y # Custom the host name RK_ROOTFS_HOSTNAME="Edge2" # Set the host name as Edge2 RK_UBOOT_CFG="khadas-edge2-rk3588s" # Indicate U-Boot default configuration file RK_KERNEL_CFG="kedges_defconfig" # Indicate Kernel default configuration file RK_KERNEL_DTS_NAME="rk3588s-khadas-edge2" # Indicate Kernel DTS file RK_USE_FIT_IMG=y # Use FIT Image ``` ==== Build the OS Image ==== After setting up the compile configuration, just run ''./build.sh'' to start building. Then you can get the image in ''/output/'' directory. You have to install some packages before compiling Debian ```bash sudo dpkg -i /debian/ubuntu-build-service/packages/* sudo apt-get install -f ``` Important Points for Yocto Build: - The network must have access to Google. - The build process requires fetching packages from the internet. If fetching fails, retry continuously. - You need a system with at least 150 GB of free disk space and at least 8 GB of RAM. ==== Other Build Commands ==== === Build u-boot === ```shell $ ./build.sh uboot ``` === Build kernel === ```shell $ ./build.sh kernel ``` === Build rootfs === ```shell $ ./build.sh rootfs ``` ==== Help messages ==== You can get help messages by executing ''./build.sh help'': ```txt Usage: build.sh [OPTIONS] Available options: chip[:[:]] choose chip defconfig[:] choose defconfig *_defconfig switch to specified defconfig available defconfigs: khadas_rk3588s_edge2_buildroot_defconfig khadas_rk3588s_edge2_debian_defconfig khadas_rk3588s_edge2_yocto_defconfig olddefconfig resolve any unresolved symbols in .config savedefconfig save current config to defconfig menuconfig interactive curses-based configurator config modify SDK defconfig print-parts print partitions list-parts alias of print-parts mod-parts interactive partition table modify edit-parts edit raw partitions new-parts:::... re-create partitions insert-part::[:] insert partition del-part:(|) delete partition move-part:(|): move partition rename-part:(|): rename partition resize-part:(|): resize partition misc pack misc image kernel[:cmds] build kernel recovery-kernel[:cmds] build kernel for recovery modules[:cmds] build kernel modules linux-headers[:cmds] build linux-headers kernel-config[:cmds] modify kernel defconfig kconfig[:cmds] alias of kernel-config kernel-make[::] run kernel make kmake[::] alias of kernel-make wifibt[:[:]] build Wifi/BT rtos build and pack RTOS buildroot-config[:] modify buildroot defconfig bconfig[:] alias of buildroot-config buildroot-make[::] run buildroot make bmake[::] alias of buildroot-make rootfs[:] build default rootfs buildroot build buildroot rootfs yocto build yocto rootfs debian build debian rootfs recovery build recovery pcba build PCBA security-createkeys create keys for security security-misc build misc with system encryption key security-ramboot build security ramboot security-system build security system loader[:cmds] build loader (uboot) uboot[:cmds] build u-boot uefi[:cmds] build uefi extra-part pack extra partition images firmware pack and check firmwares edit-package-file edit package-file edit-ota-package-file edit package-file for OTA updateimg build update image ota-updateimg build update image for OTA all build images release release images and build info all-release build and release images shell setup a shell for developing cleanall cleanup clean[:module[:module]]... cleanup modules available modules: all config extra-part firmware kernel loader misc pcba recovery rootfs rtos security updateimg post-rootfs trigger post-rootfs hook scripts help usage Default option is 'all'. ``` ===== Build in Docker ===== You can also choose to build the OS image in a Docker container. ==== Install Docker ==== Please refer to [[https://docs.docker.com/engine/install/|Docker Documentation]]. ==== Add User to a Docker Group ==== ```shell $ sudo usermod -aG docker $USER ``` You need to logout or reboot the system to take effect. ==== Build SDK in Docker ==== Get Docker image: ```shell $ docker pull wesion/yocto-rockchip ``` Enter Docker: ```shell $ cd ~/project/edge2-linux-sdk $ docker run --rm -it --privileged --device=/dev/loop-control:/dev/loop-control \ --device=/dev/loop0:/dev/loop0 --cap-add SYS_ADMIN -v /opt:/opt \ -v $(pwd):/home/khadas/yocto wesion/yocto-rockchip bash ``` Start your build from inside the Docker container. ```shell khadas@59f19b6a36e2:~/yocto$ ./build.sh lunch khadas@59f19b6a36e2:~/yocto$ ./build.sh ``` ===== Install OS ===== ==== Preparation ==== 1. Copy upgrade tool to your local path ```shell $ sudo cp /tools/linux/Linux_Upgrade_Tool/Linux_Upgrade_Tool/upgrade_tool /usr/local/bin/ ``` 2. Put your Edge2 into upgrade mode. Ref:[[products:sbc:edge2:install-os:boot-into-upgrade-mode| Boot into upgrade mode]] ==== Install OS into eMMC ==== Please check [[products:sbc:edge2:install-os:install-os-into-emmc-via-usb-tool|]]. ==== Partition Upgrade ==== Invalid in Maskrom Mode! ==== Upgrade Uboot ==== ```shell $ sudo upgrade_tool di -uboot /output/update/Image/uboot.img ``` ==== Upgrade kernel ==== ```shell $ sudo upgrade_tool di -boot /output/update/Image/boot.img ``` ==== Upgrade rootfs ==== ```shell $ sudo upgrade_tool di -rootfs /output/update/Image/rootfs.img ``` You can execute ''upgrade_tool RD'' to reboot Edge2 after upgrade. ===== User and password ===== * user: root * password: khadas * user: root * Have no password, you can use ''passwd'' command to set a password for root. * user: root * Have no password, you can use ''passwd'' command to set a password for root. * (default)user: khadas * password: khadas * user: linaro * password: linaro ===== WIFI ===== You can use the following command to connect WIFI: ```shell $ wifi-connect.sh $ udhcpc -i wlan0 -b ``` Or reboot after editing /etc/wpa_supplicant.conf as follow: ```txt ctrl_interface=/var/run/wpa_supplicant ap_scan=1 update_config=1 network={ ssid="wifi_name" psk="wifi_password" key_mgmt=WPA-PSK } ``` You can use the following command to connect WIFI: ```shell $ sudo nmcli radio wifi on $ sudo nmcli device wifi connect wifi_name password wifi_password ``` Or use the desktop UI to connect WIFI. ===== Bluetooth ===== Please refer to [[products:sbc:edge2:configurations:bluetooth#ubuntu-server| the bluetooth usage on ubuntu-server ]]. Bluetooth settings are in the upper-right corner, click ''Bluetooth Enabled'' to set the bluetooth. ===== Camera ===== Please refer to [[products:sbc:edge2:add-ons:edge2-mipi-camera|]]