Duo cv1800b first time builds C compilation and remote gdb environment

Reference link: https://community.milkv.io/t/duo-cv1800b-first-time-c-gdb/56ss?s
Author: tinnu

Environment setup

  1. apt installs necessary components

    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. Download a higher version of 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. Pull repo

    • Note that github must add a public key; if it is a newly created ubuntu system, you need the ssh-keygen command to generate a public key and submit it to your github account, otherwise permission problems will occur later.
    • Create a path to save the repo and pull the repo from Tsinghua source
    mkdir <path_to_repo>/duo-manifest
    curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
    
    • Grant permissions
    chmod a + rx repo
    
  4. Pull sdk

    • Create and enter new directory
    • Export the repo address above (form good habits and refuse to add garbage to bashrc and PATH)
    export PATH="<path_to_repo>/duo-manifest:${PATH}"
    
    • Point to Tsinghua source
    export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
    
    • Pull sdk
    repo init -u [email protected]:milk-v/duo-manifest.git -b main -m milk-v_duo_cv180xb_sdk.xml
    repo sync
    
  5. compile

    • Specify cmake
    export PATH="<path_to_cmake>/cmake-3.19.3-Linux-x86_64/bin:${PATH}"
    
    • compile
    source build/cvisetup.sh
    defconfig cv1800b_sophpi_duo_sd
    build_all
    pack_sd_image
    
  6. Burn

    sudo dd if=./install/soc_cv1800b_sophpi_duo_sd/sophpi-duo-<**>.img of=/dev/sda bs=32M status=progress oflag=direct
    
  7. Connect to uart interface

    • As shown in the lower left corner of the picture, starting from the fourth pin from the bottom, the baud rate is 115200
    • If garbled characters appear, use 120000 to see the bl output, which is usually a startup failure.

Explore

  • In order to use GADGET, modify the configuration before compiling:

    CONFIG_USB_OSDRV_CVITEK_GADGET=y
    

    But it doesn’t seem to be taking effect.

    [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)
    

    The 202305 version of the firmware already supports RADIS. I don’t know if the latest version of the code configuration has not yet been submitted to the warehouse.

    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)
    
  • The spi device is not mounted either:

    [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
    

    Look at the device tree and there is already a spi device enabled.

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

program

  • Since the system I compiled does not have radis, I used the official release image; in the Ubuntu 20 system, I can directly virtualize the network card without a driver. The PC can see that it belongs to the 192.168.42.x network segment. From the above, I can see that the development board IP is 192.168. .42.1

  • ssh connection

  • gdbserver

    • Find gdbserver in sdk
    find -name gdbserver
    
    • Download it using scp
    scp ./ramdisk/rootfs/public/gdbserver/riscv_musl/usr/bin/gdbserver [email protected]:~/
    
  • compile

    • riscv64-elf compilation chain. The program compiled by this compilation chain can be run directly. Maybe the system library is compiled using this? But once the breakpoint is triggered during debugging, it cannot continue to run.
    <path_to_sdk>/duo-src/host-tools/gcc/riscv64-elf-x86_64/bin/riscv64-unknown-elf-gcc -o main main.c -g
    
    • There are also two compilation chains: riscv64-linux-x86_64 riscv64-linux-musl-x86_64. However, the programs compiled by dynamic linking cannot be run directly, so static compilation is chosen, but debug can be stepped normally.
    <path_to_sdk>/duo-src/host-tools/gcc/riscv64-elf-x86_64/bin/riscv64-unknown-elf-gcc -o main main.c -g -static
    
    • Download program
    scp main [email protected]:~/
    
  • run

    - ./main
    
  • debug

    - ./gdbserver:1234 main
    
  • Added to vscode:

    {
    "name": "(gdb) start",
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceRoot}/main",
    "args": [],
    "stopAtEntry": false,
    "miDebuggerServerAddress": "192.168.42.1:1234",//IP address and port of the target board
    "cwd": "${workspaceRoot}",
    "environment": [],
    "externalConsole": false,
    "MIMode": "gdb",
    // "miDebuggerPath":"<path_to_sdk>/duo-src/host-tools/gcc/riscv64-elf-x86_64/bin/riscv64-unknown-elf-gdb",
    "miDebuggerPath":"<path_to_sdk>/duo-src/host-tools/gcc/riscv64-linux-x86_64/bin/riscv64-unknown-linux-gnu-gdb",
    "setupCommands": [
    {
    "description": "Enable neat printing for gdb",
    "text": "-enable-pretty-printing",
    "ignoreFailures": true
    },
    {
    "description": "Set disassembly style to Intel",
    "text": "-gdb-set disassembly-flavor intel",
    "ignoreFailures": true
    }
    ]
    }
    
    • Click F5 to debug
    • Effect

    1684905972465

    ?