subsys-toolchain-hdc-guide.md 12.0 KB
Newer Older
A
Annie_wang 已提交
1
# hdc_std
W
wusongqing 已提交
2 3


A
Annie_wang 已提交
4
OpenHarmony Device Connector (hdc_std) is a command-line tool used for debugging. You can use it on a Windows, Linux, or macOS system to interact with real devices or simulators.
W
wusongqing 已提交
5 6


A
Annie_wang 已提交
7
The following describes how to obtain and use hdc_std.
W
wusongqing 已提交
8 9


A
Annie_wang 已提交
10
## How to Obtain
W
wusongqing 已提交
11

A
Annie_wang 已提交
12
Obtain hdc_std from the **toolchains** directory of the OpenHarmony SDK.
W
wusongqing 已提交
13

A
Annie_wang 已提交
14
**Example**
W
wusongqing 已提交
15

A
Annie_wang 已提交
16
If you use hdc_std on Windows, obtain the SDK for Windows and copy **hdc_std.exe** from **toolchains** to a directory on the disk.
W
wusongqing 已提交
17 18


A
Annie_wang 已提交
19
## NOTICE
W
wusongqing 已提交
20

A
Annie_wang 已提交
21
- If an exception occurs when you are using hdc_std, run the **hdc_std kill** command to terminate the hdc_std service or run the **hdc_std start -r** command to restart the service process.
W
wusongqing 已提交
22

A
Annie_wang 已提交
23
- If no device information is obtained after **hdc_std list targets** is executed, check whether the hdc_std process exists in the **Task Manager**. If yes, terminate it.
W
wusongqing 已提交
24 25


A
Annie_wang 已提交
26
## Option-related Commands
W
wusongqing 已提交
27

A
Annie_wang 已提交
28
The following commands are available:
W
wusongqing 已提交
29

30

A
Annie_wang 已提交
31 32 33 34 35 36
- **-h/help -v/version**
  
  Displays hdc_std help or version information.
  
  **Table 1** Command description
  | **Return Value**| **Description**|
37
  | -------- | -------- |
A
Annie_wang 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  | Required information| hdc_std help or version information.|

  Example:
  
  ```
  hdc_std -h / hdc_std help
  ```
  
  ```
  hdc_std -v / hdc_std version
  ```
  
   

- **-l 0-5**
  
  Sets the levels of the logs generated during the running of the tool. The default value is **LOG_INFO**.
  
  **Table 2** Command description

  | Parameter| Description|
  | -------- | -------- |
  | 0 | LOG_OFF  |
  | 1 | LOG_FATAL|
  | 2 | LOG_WARN |
  | 3 | LOG_INFO |
  | 4 | LOG_DEBUG|
  | 5 | LOG_ALL  |

  Example:
  
  ```
  hdc_std -l5 start
  ```

- **-t key**
  
  Connects to a device based on the specified key.
  
  **Table 3** Command description

  | Parameter| Description|
  | -------- | -------- |
  | key | Key that identifies the device to connect. The value can be in the *IP address:port number* format or be a USB serial number.|
  | **Return Value** | **Description** |
  | 1. error: device '\*\*\*' not found<br>2. Nothing to do ..| 1. The device does not exist.<br>2. The command appended to **-t key** does not exist.|
W
wusongqing 已提交
84

A
Annie_wang 已提交
85
  Example:
W
wusongqing 已提交
86

A
Annie_wang 已提交
87
  **-t key** must be used with a command. The following uses **shell** as an example:
W
wusongqing 已提交
88

A
Annie_wang 已提交
89
  **hdc_std list targets** (obtain device information)
W
wusongqing 已提交
90

A
Annie_wang 已提交
91
  **hdc_std -t *key* shell** (replace *key* with the device identifier obtained)
W
wusongqing 已提交
92

A
Annie_wang 已提交
93 94
  > **NOTE**<br>
  > You can connect to multiple devices from the device you use for development. Each device has a unique key. The key can be *IP address:port number* for a device to be connected over the network or the serial number for a device to be connected through USB. A specific command must be used with this command.
95

A
Annie_wang 已提交
96 97 98 99 100
- **checkserver**
  
  Obtains the client and server version information.
  
  **Table 4** Command description
101

A
Annie_wang 已提交
102
  | Return Value| Description|
103
  | -------- | -------- |
A
Annie_wang 已提交
104
  | Client version:  server version: | Client and server version information.|
W
wusongqing 已提交
105

A
Annie_wang 已提交
106
  Example:
W
wusongqing 已提交
107

A
Annie_wang 已提交
108 109 110
  ```
  hdc_std checkserver
  ```
W
wusongqing 已提交
111 112


A
Annie_wang 已提交
113
## Displaying Device Information
W
wusongqing 已提交
114

A
Annie_wang 已提交
115
Run the following command to display all connected devices:
W
wusongqing 已提交
116 117


A
Annie_wang 已提交
118 119 120
```
list targets[-v]
```
W
wusongqing 已提交
121

122 123
**Table 5** Command description

A
Annie_wang 已提交
124 125 126 127 128
| Parameter| Description|
| -------- | -------- |
| -v | Displays detailed device information.|
| **Return Value** | **Description**|
| 1. Device information<br>2. [Empty]| 1. A list of connected devices.<br>2. No device information is found.|
W
wusongqing 已提交
129 130


A
Annie_wang 已提交
131
Example:
W
wusongqing 已提交
132

A
Annie_wang 已提交
133 134 135
```
hdc_std list targets
```
136

A
Annie_wang 已提交
137 138 139
```
hdc_std list targets -v
```
W
wusongqing 已提交
140 141


A
Annie_wang 已提交
142
## Service Process Commands
W
wusongqing 已提交
143 144 145

The following commands are available:

A
Annie_wang 已提交
146
- **target mount**
W
wusongqing 已提交
147

A
Annie_wang 已提交
148
  Mounts the **/system** partition in read/write mode.
W
wusongqing 已提交
149

A
Annie_wang 已提交
150
  **Table 6** Command description
151

A
Annie_wang 已提交
152
  | Parameter| Description|
153
  | -------- | -------- |
A
Annie_wang 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
  | –| –|
  | **Return Value**| **Description**|
  | 1. Mount&nbsp;finish<br>2. Error information| 1. The operation is successful.<br>2. The operation fails.|

  Example:
  
  ```
  hdc_std target mount
  ```
  
    


- **target boot**
  
  Boots the device.
  
   Example:
  
  ```
   hdc_std target boot
  ```
  
   

- **smode [-r]**
  
  Grants the **root** permission to the background hdc service. Use **off** to revoke the granted permissions.
  
  Example:
  
  ```
  hdc_std smode
  ```
  
  ```
   hdc_std smode -r
  ```
  
  

- **kill [-r]**
  
  Terminates the hdc process.
  
  **Table 7** Command description

  | Parameter| Description|
202
  | -------- | -------- |
A
Annie_wang 已提交
203 204 205
  | -r | Restarts the hdc process.|
  | **Return Value**| **Description**|
  | 1. Kill&nbsp;server&nbsp;finish<br>2. Error information| 1. The operation is successful.<br>2. The operation fails.|
W
wusongqing 已提交
206

A
Annie_wang 已提交
207
  Example:
W
wusongqing 已提交
208

A
Annie_wang 已提交
209 210 211
  ```
  hdc_std kill
  ```
W
wusongqing 已提交
212

A
Annie_wang 已提交
213 214 215 216 217
- **start [-r]**
  
  Starts the hdc process.
  
  **Table 8** Command description 
W
wusongqing 已提交
218

A
Annie_wang 已提交
219 220 221 222 223
  | Parameter| Description|
  | -------- | -------- |
  | -r | Restarts the hdc process if it has started.|
  | **Return Value**| **Description**|
  | –| –|
W
wusongqing 已提交
224

A
Annie_wang 已提交
225
  Example:
226

A
Annie_wang 已提交
227 228 229
  ```
  hdc_std start
  ```
W
wusongqing 已提交
230 231 232 233




A
Annie_wang 已提交
234
## Network Commands
W
wusongqing 已提交
235 236 237

The following commands are available:

238

A
Annie_wang 已提交
239
- **tconn host[:port][-remove]**
W
wusongqing 已提交
240

A
Annie_wang 已提交
241
  Connects to a device with the specified IP address and port number.
W
wusongqing 已提交
242

A
Annie_wang 已提交
243
  **Table 9** Command description
W
wusongqing 已提交
244

A
Annie_wang 已提交
245
  | Parameter| Description|
246
  | -------- | -------- |
A
Annie_wang 已提交
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
  | host[:port] | IP address and port number for the device to connect.|
  | -remove | Disconnects from the specified device.|
  | **Return Value**| **Description**|
  | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.|

  Example:
  
  ```
  hdc_std tconn 192.168.0.100:8710
  ```
  
    

- **tmode usb**
  
  Restarts the daemon process and connects to the device using USB preferentially.

  **Table 10** Command description

  | Parameter| Description|
  | -------- | -------- |
  | –| –|
  | **Return Value**| **Description**|
  | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.|

  Example:
  
  ```
  hdc_std tmode usb
  ```
  
    

- **tmode port port-number**
  
  Restarts the daemon process and connects to the device over TCP preferentially. If the TCP connection fails, a USB connection will be initiated.
  
  **Table 11** Command description

  | Parameter| Description|
  | -------- | -------- |
  | port-number | Port used to connect to the device.|
  | **Return Value**| **Description**|
  | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.|

  Example:
  
  ```
  hdc_std tmode port 8710
  ```
  
    

  > **NOTE**<br>
  > After this command is executed, the remote daemon process exits and restarts, and a TCP connection is set up by default. If the port number is not specified in the command, a random port will be used to connect to the device.

- **fport localnode remotenode**
  
  Forwards data from a host port to a device port.
  
  Example:
  
  ```
  hdc_std fport tcp:1234 tcp:1080
  ```
  
    

- **rport remotenode localnode**
  
  Forwards data from a device port to a host port.
  
  Example:
  
  ```
   hdc_std rport tcp:2080 tcp:2345 
  ```
  
   

- **fport ls**
  
  Lists all port forwarding tasks.
  
  **Table 12** Command description  

  | Parameter| Description|
  | -------- | -------- |
  | –| –|
  | **Return Value**| **Description**|
  | 'tcp:1234 tcp:1080'     [Forward] | Forward port forwarding task.|
  | 'tcp:2080 tcp:2345'     [Reverse] | Reverse port forwarding task.|

  Example:
  
  ```
  hdc_std fport ls 
  ```
  
    

- **fport rm**
  
  Deletes a port forwarding task.
  
  Example:
  
  ```
  hdc_std fport rm tcp:1234 tcp:1080 
  ```
  
   


## File Commands
W
wusongqing 已提交
362 363 364 365

The following commands are available:


A
Annie_wang 已提交
366 367 368 369 370
- **file send local remote**
  
  Sends a file to a remote device.
  
  **Table 13** Command description 
371

A
Annie_wang 已提交
372
  | Parameter| Description|
373
  | -------- | -------- |
A
Annie_wang 已提交
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
  | local | Path of the file to send.|
  | remote | Destination path on the remote device.|
  | **Return Value**| **Description**|
  | 1. Error information<br>2. File transfer result| 1. The operation fails.<br>2. The operation is successful.|

  Example:
  
  ```
  hdc_std file send E:\a.txt   /data/local/tmp/a.txt
  ```
  
    

- **file recv [-a] remote local**
  
  Receives a file from a remote device.
  
  **Table 14** Command description

  | Parameter| Description|
  | -------- | -------- |
  | -a | Retains the file timestamp.|
  | local | Destination path on the local device.|
  | remote | File path on the remote device.|
  | **Return Value**| **Description**|
  | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.|
W
wusongqing 已提交
400

A
Annie_wang 已提交
401 402 403 404 405 406 407
  Example:
  
  ```
   hdc_std file recv  /data/local/tmp/a.txt   ./a.txt
  ```
  
   
W
wusongqing 已提交
408 409


A
Annie_wang 已提交
410
## App Commands
W
wusongqing 已提交
411

A
Annie_wang 已提交
412
The following commands are available:
W
wusongqing 已提交
413

414

A
Annie_wang 已提交
415 416 417 418 419 420
- **install [-r/-d/-g]** *package*
  
  Installs an OpenHarmony app.
  
  **Table 15** Command description 
  | Parameter| Description|
421
  | -------- | -------- |
A
Annie_wang 已提交
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
  | package | OpenHarmony app installation package.|
  | -r | Replaces the existing app.|
  | -d | Allows downgrade installation.|
  | -g | Grants permissions dynamically.|
  | **Return Value**| **Description**|
  | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.|

  Example:
  
  ```
  hdc_std install hwadmin.hap
  ```
  
    

- **uninstall [-k] package**
  
  Uninstalls an OpenHarmony app.
  
  **Table 16** Command description 

  | Parameter| Description|
  | -------- | -------- |
  | package | OpenHarmony app installation package.|
  | -k | Retains **/data/cache**.|
  | **Return Value**| **Description**|
  | 1. Error information<br>2. –| 1. The operation fails.<br>2. The operation is successful.|
W
wusongqing 已提交
449

A
Annie_wang 已提交
450 451 452 453 454 455 456
  Example:
  
  ```
  hdc_std uninstall package
  ```
  
   
W
wusongqing 已提交
457 458


A
Annie_wang 已提交
459
## Debugging Commands
W
wusongqing 已提交
460 461 462 463

The following commands are available:


A
Annie_wang 已提交
464
- **hilog**
W
wusongqing 已提交
465

A
Annie_wang 已提交
466
  Obtains logs for debugging.
467

A
Annie_wang 已提交
468
  **Table 17** Command description  
W
wusongqing 已提交
469

A
Annie_wang 已提交
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
  | Parameter| Description|
  | -------- | -------- |
  | –| –|
  | **Return Value**| **Description**|
  | Log obtained| Log information obtained.|

  Example: Obtain log information.
  
  ```
  hdc_std hilog
  ```
  
  Clear the cached logs.
  
  ```
  hdc_std shell "hilog -r"
  ```
  


- **shell** [*command*]
  
  Executes a command remotely or enters an interactive command environment.
  
  **Table 18** Command description  

  | Parameter| Description|
  | -------- | -------- |
  | command | Command to execute.|
  | **Return Value**| **Description**|
  | Returned information| Command execution result.|
W
wusongqing 已提交
501

A
Annie_wang 已提交
502 503 504 505 506 507 508
  Example:
  
  ```
  hdc_std shell
  ```
  
    
W
wusongqing 已提交
509

A
Annie_wang 已提交
510 511 512 513 514 515 516 517 518 519 520
- **jpid**
  
  Obtains the list of processes that can be debugged.
  
  Example:
  
  ```
  hdc_std jpid
  ```
  
    
W
wusongqing 已提交
521

522

A
Annie_wang 已提交
523
## FAQs
W
wusongqing 已提交
524 525


A
Annie_wang 已提交
526
### Failed to Connect to a Device from hdc_std
W
wusongqing 已提交
527

A
Annie_wang 已提交
528 529 530
- **Symptom**
  
  After the **hdc_std list targets** command is executed, **[Empty]** is displayed.
W
wusongqing 已提交
531

A
Annie_wang 已提交
532 533 534 535 536 537 538 539 540 541 542 543 544
- **Solution**
  
  - The device cannot be identified.
  
    Check whether **HDC Device** exists under the **Universal Serial Bus controllers** in the **Device Manager**. If **HDC Device** does not exist, the device cannot be connected. In this case, disconnect and then reconnect the USB connection between the test PC and the OpenHarmony device, or burn the latest image.
  
  - hdc_std works improperly.
  
    Run the **hdc kill** command to terminate the hdc_std process or run the **hdc start -r** command to restart the hdc service. Then, run the **hdc list targets** command to check whether device information can be obtained.
  
  - hdc_std does not match the device.
  
    If the latest image is burnt on the device, the latest hdc_std version must be used.
W
wusongqing 已提交
545 546


A
Annie_wang 已提交
547
### hdc_std Fails to Run
W
wusongqing 已提交
548

A
Annie_wang 已提交
549 550 551 552 553 554 555
- **Symptom**
  
  After you click **hdc_std.exe**, the file fails to execute.
  
- **Solution**
  
  **hdc_std.exe** requires no installation. You can use it after placing it to a local directory or adding the tool path to environment variables. Run the **cmd** command and then run the **hdc_std** command to start the tool.
W
wusongqing 已提交
556 557 558



A
Annie_wang 已提交
559
### Accessing a Server from the Client
W
wusongqing 已提交
560

A
Annie_wang 已提交
561
1. Run the **kill** command to stop the local server.
W
wusongqing 已提交
562

A
Annie_wang 已提交
563
2. Run the **-s [ip:]port -m** command to start the remote server.
W
wusongqing 已提交
564

A
Annie_wang 已提交
565
    Example:
W
wusongqing 已提交
566

A
Annie_wang 已提交
567 568 569
   ```
   hdc_std -s severIP:8710 -m
   ```
W
wusongqing 已提交
570

A
Annie_wang 已提交
571
   
W
wusongqing 已提交
572

A
Annie_wang 已提交
573
3. Run **-s [ip:]port** *command* to execute a command on the remote server.
W
wusongqing 已提交
574

A
Annie_wang 已提交
575
   Example:
W
wusongqing 已提交
576

A
Annie_wang 已提交
577 578 579
   ```
   hdc_std -s severIP:8710 list targets
   ```
W
wusongqing 已提交
580

A
Annie_wang 已提交
581