Win10 + WSL2 + Docker:K510(DongshanPI-Vision)开发环境从踩坑到跑通全记录(交叉编译 + 上板运行)

文章目录

前情提要

最近翻看吃灰的开发板们,勘智的k510被我翻出来,想到18年就买了官方预购的K210,最后吃灰,K510也如此,有点不甘心,尤其是AI 编程盛行的时代,没理由不拿出来搞点事情

结果没想到,踩坑踩到麻

win10下的WSL2已经好用到爆炸,所以我不想再用vmware进行开发,准备直接用wsl2(因为已经用wsl2编译rk3506,感觉很不错),结果没想到这才是噩梦的开始

wsl2下的编译失败

创建WSL2这个就不多说了,自行百度即可

当我尝试使用韦东山的K510 SDK默认编译的时候,问题出现

bash 复制代码
cd ~/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot/

之后

bash 复制代码
./relocate-sdk.sh

查看一下

bash 复制代码
ls $SDK/bin | grep -E "riscv64.*gcc$|riscv64.*g\+\+$"
# riscv64-linux-gcc
# riscv64-linux-g++

但执行却总是失败

bash 复制代码
~/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot$ riscv64-linux-gcc -v 2>&1 | head -20 
ccache: error: execv of /home/zkp/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot/opt/ext-toolchain/bin/riscv64-linux-gcc failed: Exec format error

这个确实有点疑惑,理论上板厂提供的sdk不会出错,那问题一定是WSL2了

(说实话,这会儿我收手用vmware就没事了,但是那一瞬间倔脾气上来了,非要搞定他不可)

之后就是寻找原因

bash 复制代码
~/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot$ ls $SDK/bin | grep gcc | head -50 
riscv64-linux-gcc 
riscv64-linux-gcc-7.3.0 
riscv64-linux-gcc-ar 
riscv64-linux-gcc-nm 
riscv64-linux-gcc-ranlib 
riscv64-linux-gcc.gnu

然后最大的问题出现了

bash 复制代码
zkp@DESKTOP-N3OJVP7:~/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot$ file $SDK/bin/riscv64-linux-gcc /home/zkp/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot/bin/riscv64-linux-gcc: symbolic link to toolchain-wrapper

zkp@DESKTOP-N3OJVP7:~/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot$ file $SDK/opt/ext-toolchain/bin/riscv64-linux-gcc /home/zkp/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot/opt/ext-toolchain/bin/riscv64-linux-gcc: 
ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.9, stripped 

zkp@DESKTOP-N3OJVP7:~/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot$ ls -l $SDK/opt/ext-toolchain/bin/riscv64-linux-gcc 
-rwxr-xr-x 1 zkp zkp 100236 Nov 20 2019 
/home/zkp/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot/opt/ext-toolchain/bin/riscv64-linux-gcc 

zkp@DESKTOP-N3OJVP7:~/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot$

傻眼了,问题很简单,编译器的GCC是基于32位的x86,而WSL2的gcc是64位的

然后就是一系列的尝试安装i386,但是没用,略过

最后在询问AI后,提出了一个更好的办法,使用官方的docker库

docker安装

然后就是docker的安装:

bash 复制代码
zkp@DESKTOP-N3OJVP7:~/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot$ docker version 
Client: Version: 26.1.3 
API version: 1.45 
Go version: go1.22.2 
Git commit: 26.1.3-0
ubuntu1~20.04.1 
Built: Mon Oct 14 22:06:01 2024 
OS/Arch: linux/amd64 
Context: default 
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. 
Is the docker daemon running? 
zkp@DESKTOP-N3OJVP7:~/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot$ docker info | head 
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. 
Is the docker daemon running? 
errors pretty printing info Client: Version: 26.1.3 Context: default Debug Mode: false Server: zkp@DESKTOP-N3OJVP7:~/work/k510/riscv64-buildroot-linux-gnu_sdk-buildroot$

行,接下来就是折腾docker的部分,简单说一下,大概就是先安装docker desktop版本,然后配置wsl2

这部分教程蛮多,就不多说了了

能看到helloworld就行了

bash 复制代码
zkp@DESKTOP-N3OJVP7:~$ docker run --rm hello-world 
Unable to find image 'hello-world:latest' 
locally latest: Pulling from library/hello-world 17eec7bbc9d7: 
Pull complete ea52d2000f90: 
Download complete Digest: sha256:05813aedc15fb7b4d732e1be879d3252c1c9c25d885824f6295cab4538cb85cd 
Status: Downloaded newer image for hello-world:latest 
Hello from Docker! 
This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/

之后就是在docker环境里编译k510的sdk

配置官方docker库

首先,在合适的目录下git官方代码

bash 复制代码
git clone --depth=1 https://github.com/kendryte/k510_buildroot.git

之后,运行docker

bash 复制代码
sh k510_buildroot/tools/docker/run_k510_docker.sh

看到这个就是成功了

bash 复制代码
[CAN k510_buildroot]$
[CAN k510_buildroot]$ ls
Config.in  buildroot-2020.02.11  external.desc                patches
LICENSE    ccache                external.mk                  release_notes.md  
Makefile   configs               k510_buildroot               toolchain
README.md  dl                    k510_crb_lp3_v1_2_defconfig  tools
board      docs                  package
[CAN k510_buildroot]$

编译

接下来就是编译

bash 复制代码
make -j$(nproc)

这部分建议(一定)挂代理,不然下载部分会慢到让你怀疑人生

中间漫长的编译就省略了

最后结果应该是这样

bash 复制代码
[CAN k510_buildroot]$ ls k510_crb_lp3_v1_2_defconfig/images/
bbl.bin        nand_deploy.tar.gz  sysimage-nand.img        uboot-emmc.env
bbl.elf        rootfs.ext2         sysimage-sdcard.img      uboot-nand.env      
bootfs.vfat    rootfs.tar          u-boot.bin               uboot-nfs.env       
bootm-bbl.img  rootfs.ubi          u-boot_burn.bin          uboot-sd.env        
k510-hdmi.dtb  rootfs.ubifs        u-boot_burn.bin.aes      update_nand.sh      
k510.dtb       sysimage-emmc.img   u-boot_burn.bin.aes_otp  vmlinux
[CAN k510_buildroot]$

此时交叉编译链也可以看到了

bash 复制代码
[CAN k510_buildroot]$ find . -type f -name "*riscv64*-linux*-gcc" -print | head 
-50
./toolchain/nds64le-linux-glibc-v5d/bin/riscv64-linux-gcc
[CAN k510_buildroot]$

测试

然后简简单单编译一个hello world(省略了交叉编译,ssh,scp的内容)

最终结果

bash 复制代码
[root@canaan ~ ]$ chmod +x hello.elf
[root@canaan ~ ]$ ./hello.elf
Hello, World!
[root@canaan ~ ]$

大功告成

说实话,从没想过配一个环境搞这么麻烦,诚挚感谢OpenAI

相关推荐
Free Tester3 小时前
基于已有容器生成Dockerfile
docker
禅口魔心3 小时前
K510 开发记录:通用 CMake 交叉编译 + DRM 显示测试
嵌入式开发·k510
lcx_defender3 小时前
【Docker】Docker部署运行nacos
运维·docker·容器
啦啦啦小石头4 小时前
docker添加用户权限不使用sudo
运维·docker·容器
cuber膜拜4 小时前
Weaviate 简介与基本使用
数据库·python·docker·向量数据库·weaviate
xuefuhe5 小时前
Docker常用命令
docker
云草桑5 小时前
15分钟快速了解 Odoo
数据库·python·docker·postgresql·.net·odoo
春日见5 小时前
Autoware使用教程
大数据·人工智能·深度学习·elasticsearch·搜索引擎·docker·容器
阿_焦6 小时前
docker部署dify踩坑笔记
docker·ai·dify