====== Cross Compilation Toolchains ====== 官方参考:[[https://wiki.t-firefly.com/Core-3568J/linux_compile_gpt.html#da-jian-bian-yi-huan-jing|编译 Ubuntu 固件]] 在 Ubuntu 18.04 系统环境下搭建交叉编译环境。 ===== - 下载准备 ===== * SDK: [[https://www.t-firefly.com/doc/download/103.html|Linux_SDK 源码包]] Linux-SDK > rk356x_linux_release_v1.2.0_20211019_split_dir * Ubuntu:[[http://old-releases.ubuntu.com/releases/18.04.5/ubuntu-18.04.5-desktop-amd64.iso|Ubuntu 18.04 LTS (Bionic Beaver)]] ===== - 安装 Ubuntu ===== ==== - 安装Ubuntu 18.04.5 ==== 以下将在Vmware Workstation中安装 Ubuntu 18.04.5 === - 下载Ubuntu 18.04.5安装包(如已下载,此步跳过) === [http://old-releases.ubuntu.com/releases/18.04.5/ubuntu-18.04.5-desktop-amd64.iso]] [[http://old-releases.ubuntu.com/releases/|更多版本]] === - Vmware Workstation安装Ubuntu (PC) === * 新建虚拟机,资源:RAM 8GB, 硬盘:60G * 手动安装(**非常重要**,使用自动安装会导致后期安装开发环境缺少依赖包) * Ubuntu安装参数全部默认 * 安装vmtool - Vmware 菜单[VM]下,启动Vmware tools Installation - VMware Tools安装包被以光盘的形式挂载到系统桌面,在桌面点击进入安装光盘,从光盘目录下的 tar.gz压缩文件中解压安装包(到桌面) - 右键点解压后的安装包目录,以Open in Terminal方式打开 sudo ./vmware-install.pl # 运行安装程序,第一个问题是是否安装(Y),其他问题默认。 * 安装open-vm-tools-desktop apt-get install open-vm-tools-desktop fuse ==== - 安装其他软件包 ==== sudo apt-get install openssh-server ===== - 安装编译Toolchains ===== 参考 [[https://wiki.t-firefly.com/Core-3568J/linux_compile_gpt.html|编译 Ubuntu 固件]] 中安装编译环境的说明。 以下将在 Ubuntu 18.04.5 安装编译环境。 ==== - 安装依赖包 ==== sudo apt-get update 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 gcc-multilib g++-multilib \ unzip device-tree-compiler python-pip ncurses-dev python-pyelftools === - Other Ubuntu version === == - Ubuntu 22.04 LTS == Can not find 2 packages: ncurses-dev python-pyelftools 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 gcc-multilib g++-multilib \ unzip device-tree-compiler python-pip Make python2 as default python runner sudo apt install python2 cd /usr/bin sudo ln -s python2 python ==== - 安装SDK ==== Vmware可使用共享目录方式访问安装包(共享目录位于/mnt/hgfs) === - 校验安装包(非必须) === $ md5sum *firefly_split* b633414d69240faa0c3bd755c255ede8 rk356x_linux_release_v1.2.0_20211019_split_dir/rk356x_linux_release_v1.2.0_20211019_firefly_split.file0 5cb1e2b63bbb4e3595c731038f6723fd rk356x_linux_release_v1.2.0_20211019_split_dir/rk356x_linux_release_v1.2.0_20211019_firefly_split.file1 e06c0f29fd5a870e0942139a1877a470 rk356x_linux_release_v1.2.0_20211019_split_dir/rk356x_linux_release_v1.2.0_20211019_firefly_split.file2 4e14fbf72ccbb9b87f81d83a256205b0 rk356x_linux_release_v1.2.0_20211019_split_dir/rk356x_linux_release_v1.2.0_20211019_firefly_split.file3 be8b003703b51e7220e52bb36439a357 rk356x_linux_release_v1.2.0_20211019_split_dir/rk356x_linux_release_v1.2.0_20211019_firefly_split.file4 === - 解压安装包 === # 安装包文件位于/mnt/hgfs/sdk,解压到用户目录下的proj子目录 (路径根据实际情况而定) cd mkdir proj cd proj cat /mnt/hgfs/sdk/*firefly_split* | tar -xz === - 同步代码 === # 进入 SDK 根目录 cd ~/proj/rk356x_linux_release_20211019/ # 同步 .repo/repo/repo sync -l .repo/repo/repo sync -c --no-tags .repo/repo/repo start firefly --all #后续可以使用以下命令更新 SDK: .repo/repo/repo sync -c --no-tags ===== - 编译 SDK ===== 参考[[https://wiki.t-firefly.com/Core-3568J/linux_compile_gpt.html|编译 SDK]] * 编译前配置 # 进入 SDK 根目录 cd ~/proj/rk356x_linux_release_20211019/ # 选择配置文件 ./build.sh aio-3568j-ubuntu.mk 配置文件会链接到 device/rockchip/.BoardConfig.mk,检查该文件可以验证是否配置成功. * 编译 # 进入 SDK 根目录 cd ~/proj/rk356x_linux_release_20211019/ # 编译 u-boot ./build.sh uboot #编译 kernel ./build.sh kernel #编译 recovery ./build.sh recovery ===== - 编译APP ===== ==== - 设置编译环境 ==== #修改 ~/.bashrc,文件最后追究编译器路径 export PATH=~/proj/rk356x_linux_release_20211019/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin:$PATH 编译器在以上增加的路径下,编译命令: aarch64-linux-gnu-gcc \ 重新登录终端,执行命令 aarch64-linux-gnu-gcc 确认编译环境已就绪。 ==== - hello word ==== === - 编写代码,hello.c === #include "stdio.h" int main(void) { printf("Hello word!\n"); } === - 编译 x86版本的 app === gcc hello.c === - 运行x86版的app === ./a.out 以上步骤编译得到的a.out,是使用x86编译器编译出来的,可以在x86的 Linux下运行,看到 Hello word 输出。可以使用命令 file a.out 检查文件的格式。 === - 编译 ARM 版本的 app === aarch64-linux-gnu-gcc hello.c 同样得到a.out,但这个a.out不能在x86下运行,运行会报错。同样,可以使用命令 file a.out 检查文件的格式。 === - 运行ARM版的app === 将a.out传输到开发板上,方法使用U盘拷贝,也可以使用以下命令(在windows 终端执行)远程传输: # 把 <主机(IP1)上,用户(user1)的,目录test下的,a.out> 拷贝到 <本地 a.out> scp user1@IP1:~/test/a.out . # 把 <本地 a.out> 拷贝到 主机(IP2)上,用户(user2)的,目录test下,文件名a.out scp a.out user2@IP2:~/test 登录开发板终端,运行app,以下命令在开发板的终端运行。 cd ~/test # 修改a.out属性,添加可执行属性,否则运行会报错:Permission denied chmod a+x a.out # 运行 a.out ./a.out 同样,在终端打印出"Hello word!",APP编译运行正确。 至此,完成开发环境的配置,并编译执行了简单的app。