Duo cv1800b first time 搭建C编译及远程gdb环境

参考链接:https://community.milkv.io/t/duo-cv1800b-first-time-c-gdb/56ss​​​​​​​s
作者:tinnu

环境搭建

  1. apt安装必要组件

    sudo apt install dialog python3-dev make git bc gcc flex bison ninja-build libssl-dev rsync pkg-config device-tree-compiler squashfs-tools parted dosfstools
    
  2. 下载高版本的cmake

    • Releases · Kitware/CMake · GitHub 2
    • https://github.com/Kitware/CMake/releases/download/v3.19.3/cmake-3.19.3-Linux-x86_64.tar.gz 2
  3. 拉repo

    • 注意github一定要加了公钥;如果是新建的ubuntu系统,需要ssh-keygen命令生成公钥提交到自己的github账号,否则后期会出现权限问题。
    • 创建一个路径保存repo,从清华源拉repo
    mkdir /duo-manifest
    curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
    
    • 赋予权限
    chmod a+rx repo
    
  4. 拉sdk

    • 创建并进入新目录
    • export上面的repo地址(养成良好习惯,拒绝往bashrc和PATH加垃圾)
    export PATH="/duo-manifest:${PATH}"
    
    • 指向清华源
    export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
    
    • 拉sdk
    repo init -u [email protected]:milk-v/duo-manifest.git -b main -m milk-v_duo_cv180xb_sdk.xml
    repo sync
    
  5. 编译

    • 指定cmake
    export PATH="/cmake-3.19.3-Linux-x86_64/bin:${PATH}"
    
    • 编译
    source build/cvisetup.sh
    defconfig cv1800b_sophpi_duo_sd
    build_all
    pack_sd_image
    
  6. 烧录

    sudo dd if=./install/soc_cv1800b_sophpi_duo_sd/sophpi-duo-<**>.img of=/dev/sda bs=32M status=progress oflag=direct
    
  7. 连上uart接口

    • Duo cv1800b first time 搭建C编译及远程gdb环境_第1张图片

    • 如图左下角倒数第四针开始,波特率115200
    • 如果出现乱码,则使用120000可以看到bl输出,通常是启动失败

探索

  • 为了使用GADGET,在编译之前修改了配置:

    CONFIG_USB_OSDRV_CVITEK_GADGET=y
    

    但是似乎没有生效。

    [root@cvitek]~# ifconfig -a
    eth0      Link encap:Ethernet  HWaddr 0E:43:45:E2:0F:6E  
    		UP BROADCAST MULTICAST  MTU:1500  Metric:1
    		RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    		TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    		collisions:0 txqueuelen:1000 
    		RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    		Interrupt:19 
    
    lo        Link encap:Local Loopback  
    		inet addr:127.0.0.1  Mask:255.0.0.0
    		UP LOOPBACK RUNNING  MTU:65536  Metric:1
    		RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    		TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    		collisions:0 txqueuelen:1000 
    		RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    

    202305版固件已经支持RADIS,不知道是不是最新版本的代码配置还没提交到仓库

    usb0      Link encap:Ethernet  HWaddr 62:56:94:45:C3:29  
    		inet addr:192.168.42.1  Bcast:192.168.42.255  Mask:255.255.255.0
    		UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
    		RX packets:35 errors:0 dropped:16 overruns:0 frame:0
    		TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
    		collisions:0 txqueuelen:1000 
    		RX bytes:6450 (6.2 KiB)  TX bytes:1608 (1.5 KiB)
    
  • spi设备也没有挂载:

    [root@cvitek]~# ls /dev/
    bus             cvi_vc_dec4     full            null
    console         cvi_vc_dec5     gpiochip0       ptmx
    cvi-base        cvi_vc_dec6     gpiochip1       pts
    cvi-dwa         cvi_vc_dec7     gpiochip2       random
    cvi-fast-image  cvi_vc_dec8     gpiochip3       rfkill
    cvi-mipi-rx     cvi_vc_enc0     gpiochip4       root
    cvi-rgn         cvi_vc_enc1     hwrng           shm
    cvi-rtos-cmdqu  cvi_vc_enc2     i2c-0           snd
    cvi-sys         cvi_vc_enc3     i2c-1           tty
    cvi-tpu0        cvi_vc_enc4     i2c-2           ttyS0
    cvi-vi          cvi_vc_enc5     ion             ttyS1
    cvi-vpss        cvi_vc_enc6     kmsg            ttyS2
    cvi_vc_dec0     cvi_vc_enc7     mem             ttyS3
    cvi_vc_dec1     cvi_vc_enc8     mmcblk0         ttyS4
    cvi_vc_dec2     cvitekaadc      mmcblk0p1       urandom
    cvi_vc_dec3     cvitekadac      mmcblk0p2       zero
    

    看设备树已经有一个spi设备使能了

    &spi3 {
    	status = "okay";
    	num-cs = <1>;
    	spidev@0 {
    		compatible = "rohm,dh2228fv";
    		spi-max-frequency = <1000000>;
    		reg = <0>;
    	};
    };
    

program

  • 鉴于自己编译的系统没有radis,所以使用官方release镜像;在ubuntu 20 系统下免驱直接虚拟出网卡,pc可以看到属于192.168.42.x网段,串口从上面已经看到开发板ip为192.168.42.1

  • ssh 连接

  • gdbserver

    • 找到sdk里面的gdbserver
    find -name gdbserver
    
    • 用scp下载进去
    scp ./ramdisk/rootfs/public/gdbserver/riscv_musl/usr/bin/gdbserver [email protected]:~/
    
  • 编译

    • riscv64-elf 编译链,这个编译链编译出来的程序可以直接运行,系统库可能是用这个编译的?但debug的时候一旦触发断点之后就无法继续运行了。
    /duo-src/host-tools/gcc/riscv64-elf-x86_64/bin/riscv64-unknown-elf-gcc -o main main.c -g
    
    • 还有两个编译链:riscv64-linux-x86_64 riscv64-linux-musl-x86_64 但动态链接编译出来的程序都无法直接运行,因此选择静态编译,不过debug可以正常步进
    /duo-src/host-tools/gcc/riscv64-elf-x86_64/bin/riscv64-unknown-elf-gcc -o main main.c -g -static
    
    • 下载程序
    scp main [email protected]:~/
    
  • 运行

    - ./main
    
  • 调试

    - ./gdbserver :1234 main
    
  • vscode 中加入:

    {
    	"name": "(gdb) 启动",
    	"type": "cppdbg",
    	"request": "launch",
    	"program": "${workspaceRoot}/main",
    	"args": [],
    	"stopAtEntry": false,
    	"miDebuggerServerAddress": "192.168.42.1:1234",//目标板的ip地址和端口
    	"cwd": "${workspaceRoot}",
    	"environment": [],
    	"externalConsole": false,
    	"MIMode": "gdb",
    	// "miDebuggerPath":"/duo-src/host-tools/gcc/riscv64-elf-x86_64/bin/riscv64-unknown-elf-gdb",
    	"miDebuggerPath":"/duo-src/host-tools/gcc/riscv64-linux-x86_64/bin/riscv64-unknown-linux-gnu-gdb",
    	"setupCommands": [
    		{
    			"description": "为 gdb 启用整齐打印",
    			"text": "-enable-pretty-printing",
    			"ignoreFailures": true
    		},
    		{
    			"description": "将反汇编风格设置为 Intel",
    			"text": "-gdb-set disassembly-flavor intel",
    			"ignoreFailures": true
    		}
    	]
    }
    
    • 点击F5调试
    • 效果

    Duo cv1800b first time 搭建C编译及远程gdb环境_第2张图片

    ​​​​​​​

你可能感兴趣的:(SOPHGO设备硬件,技术内容活动,elasticsearch,硬件工程)