How to use HDC
This section will describe how to use hdc.
Download SDK
You can download the corresponding version of the Public SDK package by clicking the button below, please select the appropriate version starting with toolchains for your system.
Download Public SDKCreate hdc soft link
tar zxf ohos-sdk-windows_linux-public.tar.gz -C ~ &&
cd ~/ohos-sdk/linux &&
unzip toolchains-linux-x64-3.2.13.5-Release.zip &&
sudo ln -sf ~/ohos-sdk/linux/toolchains/hdc /usr/local/bin/hdc
Configure the environment
For computer in the physical environment
- Liunx
- Windows
Use the command to create a virtual bridge.
sudo modprobe tun tap &&
sudo ip link add br0 type bridge &&
sudo ip address add 192.168.137.1/24 dev br0 &&
sudo ip link set dev br0 up
Create a bridge configuration file, which is included in the official installer.
mkdir -p /path/to/qemu/etc/qemu/ &&
echo "allow all" >> /path/to/qemu/etc/qemu/bridge.conf
Use the command Allow to connect to an external network (Optional).
- Configure iptables
ip -o route get 8/8 2>/dev/null | grep -o 'dev [^ ]*' | cut -d' ' -f2 # Get networkable interface
eth0
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE # Replace eth0 with a networkable interface on your computer
- Open ip_forward
sudo sysctl net.ipv4.ip_forward=1
- Disable the firewall
sudo ufw disable
Download and install openvpn: https://community.openvpn.net/openvpn/wiki/Downloads and set the IP and netmask for the TAP network interface.
Optional: 打开可上网网络接口->右键属性->共享->勾选“允许其他用户通过此计算机的 Internet 连接来连接”->家庭网络连接选择“OpenVPN TAP-Windows6”以上操作会自动给 OpenVPN TAP-Windows6 设置 IP 为 192.168.137.1
如果不需要连接外部网络可以手动设置。OpenVPN TAP-Windows6->右键属性->网络->Internet 协议版本 4(TCP/IPv4) IP 地址:192.168.137.1 子网掩码:255.255.255.0
For computer in the virtual environment
- Liunx
- Windows
Please set the netdev option -netdev bridge,id=net0 -device virtio-net-device,netdev=net0,mac=12:22:33:44:55:66
and use sudo
to run qemu-system-riscv64.
Please set the netdev option -netdev tap,id=net0,ifname="OpenVPN TAP-Windows6" -device virtio-net-device,netdev=net0,mac=12:22:33:44:55:66
and replace "OpenVPN TAP-Windows6" into true name.
Enter the system and set ip and route.
ifconfig eth0 192.168.137.2/24 && route add default gw 192.168.137.1
By default, the system will start hdcd automatically. You can check the port number currently used by hdcd with the command.
The default port number is 5555, if there is a port conflict, a new port will be randomly assigned.
# netstat -nap | grep hdcd | grep tcp
tcp 0 0 0.0.0.0:5555 0.0.0.0:* LISTEN 104/hdcd
If the process did not start, you can start the hdcd process manually.
# hdcd -t
[D][2023-07-17 09:08:01.236][e8c5ef08][main.cpp:141] Foreground cli-mode
Option TCP enabled
[D][2023-07-17 09:08:01.252][e8c5ef08][main.cpp:304] HdcDaemon main run
[I][2023-07-17 09:08:01.257][e8c5ef08][session.cpp:25] Program running. Ver: 1.1.2a Pid:2394
[I][2023-07-17 09:08:01.259][e8c5ef08][session.cpp:33] set UV_THREADPOOL_SIZE:16
[D][2023-07-17 09:08:01.267][e8c5ef08][session.cpp:44] loopMain init
[D][2023-07-17 09:08:01.271][e8c5ef08][daemon.cpp:99] HdcDaemon InitMod
[D][2023-07-17 09:08:01.275][e8c5ef08][daemon.cpp:101] bEnableTCP:1,bEnableUSB:0
[D][2023-07-17 09:08:01.279][e8c5ef08][daemon_tcp.cpp:136] HdcDaemonTCP init
[I][2023-07-17 09:08:01.288][e8c5ef08][daemon_tcp.cpp:143] TCP listen on port:[45111]
[D][2023-07-17 09:08:01.291][e8c5ef08][daemon.cpp:122] bEnableUART:0
Connect the virtual machine
Connect the device in the physical machine based on the tcp port returned by hdcd in the virtual machine.
- Liunx
- Windows
$ hdc tconn 192.168.137.2:5555
Connect OK
$ hdc list targets -v
192.168.137.2:5555 TCP Connected localhost hdc
You can do this by right clicking in the toolchains directory and selecting "Open in Terminal". If the connection fails, don't worry, you can try again a few times.
> .\hdc.exe tconn 192.168.137.2:5555
[Fail]Connect failed
> .\hdc.exe tconn 192.168.137.2:5555
Connect OK