## 1. Failure in running the KV store on the LiteOS Cortex-A kernel \(Hi3516 or Hi3518\) due to incorrect path setting for the KV store<a name="section2041345718513"></a>
**Problem**
When the LiteOS Cortex-A kernel \(Hi3516 or Hi3518 platform\) directly calls the API provided by the KV store, the compiled executable program fails to run.
**Possible Causes**
The compiled executable program is run directly without being converted to an application using **AbilityKit** APIs. In this case, the Bundle Manager Service \(BMS\) cannot correctly set the path for storing application data during application installation. As a result, the KV store fails to run.
**Solution**
Call the **UtilsSetEnv** function of the KV store to set the data storage path.
<tbody><trid="row671818445506"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p871814441501"><aname="p871814441501"></a><aname="p871814441501"></a>int UtilsFileOpen(const char* path, int oflag, int mode)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p127181444165016"><aname="p127181444165016"></a><aname="p127181444165016"></a>Opens or creates a file.</p>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p1071884416504"><aname="p1071884416504"></a><aname="p1071884416504"></a>Closes a file with a specified file descriptor.</p>
</td>
</tr>
<trid="row6718744105017"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p137181644145015"><aname="p137181644145015"></a><aname="p137181644145015"></a>int UtilsFileRead(int fd, char *buf, unsigned int len)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p1171854410509"><aname="p1171854410509"></a><aname="p1171854410509"></a>Reads a specified length of data from a file with the specified file descriptor and writes the data into the buffer.</p>
</td>
</tr>
<trid="row2071817440509"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p17718144465012"><aname="p17718144465012"></a><aname="p17718144465012"></a>int UtilsFileWrite(int fd, const char *buf, unsigned int len)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p67191444145012"><aname="p67191444145012"></a><aname="p67191444145012"></a>Writes a specified length of data into a file with the specified file descriptor.</p>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p2071919446507"><aname="p2071919446507"></a><aname="p2071919446507"></a>Deletes a specified file.</p>
</td>
</tr>
<trid="row1071964425013"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p20719114405010"><aname="p20719114405010"></a><aname="p20719114405010"></a>int UtilsFileStat(const char *path, unsigned int *fileSize)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p8719144435015"><aname="p8719144435015"></a><aname="p8719144435015"></a>Obtains the file size.</p>
</td>
</tr>
<trid="row2071924417504"><tdclass="cellrowborder"valign="top"width="45.540000000000006%"headers="mcps1.2.3.1.1 "><pid="p57193447501"><aname="p57193447501"></a><aname="p57193447501"></a>int UtilsFileSeek(int fd, int offset, unsigned int whence)</p>
</td>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p1071934495014"><aname="p1071934495014"></a><aname="p1071934495014"></a>Adjusts the read and write position offset in a file.</p>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p113501041155511"><aname="p113501041155511"></a><aname="p113501041155511"></a>Copies the source file to a target file.</p>
<tdclass="cellrowborder"valign="top"width="54.459999999999994%"headers="mcps1.2.3.1.2 "><pid="p921744595517"><aname="p921744595517"></a><aname="p921744595517"></a>Moves the source file into a target file.</p>
<tbody><trid="row34145016535"><tdclass="cellrowborder"valign="top"width="57.38999999999999%"headers="mcps1.2.3.1.1 "><pid="p980953910190"><aname="p980953910190"></a><aname="p980953910190"></a>int UtilsGetValue(const char* key, char* value, unsigned int len)</p>
</td>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p13562171015712"><aname="p13562171015712"></a><aname="p13562171015712"></a>Obtains the value matching a specified key from the file system or cache.</p>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p2431455765"><aname="p2431455765"></a><aname="p2431455765"></a>Adds or updates the value matching a specified key in the file system or cache.</p>
<tdclass="cellrowborder"valign="top"width="42.61%"headers="mcps1.2.3.1.2 "><pid="p126575774517"><aname="p126575774517"></a><aname="p126575774517"></a>Deletes the value matching a specified key from the file system or cache.</p>
</td>
</tr>
</tbody>
</table>
Sample code for the KV store:
```
// Set the value matching the specified key.
char key[] = "rw.sys.version_100";
char value[] = "Hello kv operation implement!";
int ret = UtilsSetValue(key, value);
printf("UtilsSetValue set ret = %d\n", ret);
// Obtain the value matching the specified key.
char temp[128] = {0};
ret = UtilsGetValue(key, temp, 128);
printf("UtilsGetValue get ret = %d, temp = %s\n", ret, temp);
// Delete the value matching the specified key.
ret = UtilsDeleteValue(key);
printf("UtilsDeleteValue delete ret = %d\n", ret);
```
## How to Develop<a name="section17450172710292"></a>
### Developing a Native Application for the KV Store That Uses the LiteOS Cortex-A Kernel \(Hi3516 or Hi3518\)<a name="section258354119295"></a>
1. Develop the native application for the KV store using **AbilityKit** APIs.
- Write the user program by calling the APIs provided by the KV store and compile the **libLauncher.so** file.
```
// Set the value matching the specified key.
char key[] = "rw.sys.version_100";
char value[] = "Hello kv operation implement!";
int ret = UtilsSetValue(key, value);
printf("UtilsSetValue set ret = %d\n", ret);
// Obtain the value matching the specified key.
char temp[128] = {0};
ret = UtilsGetValue(key, temp, 128);
printf("UtilsGetValue get ret = %d, temp = %s\n", ret, temp);
// Delete the value matching the specified key.
ret = UtilsDeleteValue(key);
printf("UtilsDeleteValue delete ret = %d\n", ret);
- Add resource files in the **res/drawable** directory based on the following directory structure.

- Compress the **libLauncher.so**, **config.json**, and resource files into a ZIP package and change the file name extension to **.hap**, for example, **Launcher.hap**.
2. Connect the development board and send the command for installing the native KV store application to the board through the serial port.
The Utils library stores common basic components of OpenHarmony. These basic components can be used by OpenHarmony service subsystems and upper-layer applications.
The Utils library provides the following capabilities on different platforms:
LiteOS Cortex-M \(Hi3861 platform\): KV store, file operations, IoT peripheral control, and system attribute dumping
LiteOS Cortex-A \(Hi3516 or Hi3518 platform\): KV store, timer, JavaScript APIs for data and file storage, and system attribute dumping
hdc\_std \(OpenHarmony Device Connector\) is a command line tool provided by OpenHarmony for debugging. With this tool, you can interact with real devices or simulators from a Windows or Linux OS.
This section describes how to set up the hdc\_std environment and use its common commands.
Obtain **hdc\_std** from the **prebuilt** directory at [developtools\_hdc\_standard](https://gitee.com/openharmony/developtools_hdc_standard).
**Example:**
To obtain hdc\_std on Windows, obtain the executable file **hdc\_std.exe** from **prebuilt/windows** and place it in a directory on the disk.
## Important Notes<a name="section19543134915210"></a>
- If an exception occurs when you are using hdc\_std, run the **hdc\_std kill** command to kill the hdc\_std service or run the **hdc\_std start -r** command to restart the service process.
- If no device information is obtained after **hdc\_std list targets** is executed, use the task manager to check whether the **hdc.exe** process exists. If it exists, kill the process.
<tdclass="cellrowborder"valign="top"width="50%"><pid="p135611718111618"><aname="p135611718111618"></a><aname="p135611718111618"></a>hdc help or version information</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p26051123547"><aname="p26051123547"></a><aname="p26051123547"></a>Key that identifies the device. The value is in the <emid="i15978153415214"><aname="i15978153415214"></a><aname="i15978153415214"></a>IP address:Port number</em> format or is a USB serial number.</p>
<trid="row1760531211546"><tdclass="cellrowborder"valign="top"width="50%"><pid="p232481834"><aname="p232481834"></a><aname="p232481834"></a>1. error: device '***' not found</p>
<pid="p12191171320"><aname="p12191171320"></a><aname="p12191171320"></a>②Nothing to do...</p>
</td>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p85527328314"><aname="p85527328314"></a><aname="p85527328314"></a>1. The device does not exist.</p>
<pid="p10343124416277"><aname="p10343124416277"></a><aname="p10343124416277"></a>2. The command appended to <strongid="b18734194624117"><aname="b18734194624117"></a><aname="b18734194624117"></a>-t key</strong> does not exist.</p>
</td>
</tr>
</tbody>
</table>
Examples:
This option must be used together with a specific operation command. The following uses the shell command as an example:
**hdc\_std list targets**\(obtain device information\)
**hdc\_std -t _key_ shell**\(replace _key_ with the device information obtained\)
>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 connected through a network or the serial number for a device connected through USB.
## Querying the Device List<a name="section174891132104218"></a>
The following command is used to query the device list:
### list targets\[-v\]<a name="section12911142313168"></a>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p6334859174310"><aname="p6334859174310"></a><aname="p6334859174310"></a>1. A list of connected devices</p>
<pid="p57581926125318"><aname="p57581926125318"></a><aname="p57581926125318"></a>2. No device information is found.</p>
</td>
</tr>
</tbody>
</table>
Examples:
hdc\_std list targets
hdc\_std list targets -v
## Service Process Commands<a name="section680531510497"></a>
<pid="p43471519204114"><aname="p43471519204114"></a><aname="p43471519204114"></a>2. Returned information</p>
</td>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p1551336123011"><aname="p1551336123011"></a><aname="p1551336123011"></a>1. Information returned when the operation is successful.</p>
<pid="p2034731984115"><aname="p2034731984115"></a><aname="p2034731984115"></a>2. Information returned when the operation fails.</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p18405337142911"><aname="p18405337142911"></a><aname="p18405337142911"></a>Triggers the service restart.</p>
<trid="row15405163702915"><tdclass="cellrowborder"valign="top"width="50%"><pid="p0976152811311"><aname="p0976152811311"></a><aname="p0976152811311"></a>①Kill server finish</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p10405123732915"><aname="p10405123732915"></a><aname="p10405123732915"></a>1. Information returned when the operation is successful.</p>
<pid="p19405337152916"><aname="p19405337152916"></a><aname="p19405337152916"></a>2. The operation fails.</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p1860525413414"><aname="p1860525413414"></a><aname="p1860525413414"></a>Restarts the service process if it has started.</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p14129038443"><aname="p14129038443"></a><aname="p14129038443"></a>IP address and port number of the device to be connected</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p24693194612"><aname="p24693194612"></a><aname="p24693194612"></a>Disconnects from the specified device.</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p1353282314492"><aname="p1353282314492"></a><aname="p1353282314492"></a>1. The operation fails.</p>
<pid="p053312316491"><aname="p053312316491"></a><aname="p053312316491"></a>2. The operation is successful.</p>
</td>
</tr>
</tbody>
</table>
Example:
hdc\_std tconn 192.168.0.100:8710
### tmode usb<a name="section17840182562015"></a>
Restarts the daemon process and connects to the device using USB.
<tdclass="cellrowborder"valign="top"width="50%"><pid="p81911527145413"><aname="p81911527145413"></a><aname="p81911527145413"></a>1. The operation fails.</p>
<pid="p4191192720546"><aname="p4191192720546"></a><aname="p4191192720546"></a>2. The operation is successful.</p>
</td>
</tr>
</tbody>
</table>
Example:
hdc\_std tmode usb
### tmode port _port-number_<a name="section101113462113"></a>
Restarts the daemon process and connects to the device over TCP.
<tdclass="cellrowborder"valign="top"width="50%"><pid="p18198921171715"><aname="p18198921171715"></a><aname="p18198921171715"></a>Port number used to connect to the device</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p17426133416542"><aname="p17426133416542"></a><aname="p17426133416542"></a>1. The operation fails.</p>
<pid="p20426834195419"><aname="p20426834195419"></a><aname="p20426834195419"></a>2. The operation is successful.</p>
>After this command is executed, the remote daemon process exits and restarts, and the TCP connection is enabled by default. If you do not include **port-number** in this command, a random port will be used to connect to the device.
<tdclass="cellrowborder"valign="top"width="50%"><pid="p176225193115"><aname="p176225193115"></a><aname="p176225193115"></a>Path of the file to send</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p1634515316"><aname="p1634515316"></a><aname="p1634515316"></a>Destination path on the remote device</p>
<pid="p0550151385512"><aname="p0550151385512"></a><aname="p0550151385512"></a>2. File transfer result</p>
</td>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p1955091315517"><aname="p1955091315517"></a><aname="p1955091315517"></a>1. The operation fails.</p>
<pid="p1555041375519"><aname="p1555041375519"></a><aname="p1555041375519"></a>2. The operation is successful.</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p1783912455333"><aname="p1783912455333"></a><aname="p1783912455333"></a>Path on the local device to receive the file</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p179411118193416"><aname="p179411118193416"></a><aname="p179411118193416"></a>File path on the remote device</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p117511052144218"><aname="p117511052144218"></a><aname="p117511052144218"></a>Replaces an existing application.</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p16720113145610"><aname="p16720113145610"></a><aname="p16720113145610"></a>1. The operation fails.</p>
<pid="p8720031185611"><aname="p8720031185611"></a><aname="p8720031185611"></a>2. The operation is successful.</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p167181136125610"><aname="p167181136125610"></a><aname="p167181136125610"></a>1. The operation fails.</p>
<pid="p1371811369562"><aname="p1371811369562"></a><aname="p1371811369562"></a>2. The operation is successful.</p>
<tdclass="cellrowborder"valign="top"width="50%"><pid="p2481349195711"><aname="p2481349195711"></a><aname="p2481349195711"></a>Execution result of the command</p>
### hdc\_std Fails to Connect to a Device<a name="section74019384588"></a>
-**Symptom**
**\[Empty\]** is displayed in the output after the **hdc\_std list targets** command is executed.
-**Solutions**
1. The device cannot be identified.
Check whether **HDC Device** exists in the universal serial bus device of the device manager. If **HDC Device** does not exist, the device cannot be connected. In this case, remove and then insert the device or burn the latest image for the device.
2. hdc\_std works improperly.
Run the **hdc kill** or **hdc start -r** command to kill or restart the hdc service. Then, run the **hdc list targets** command to check whether device information can be obtained.
3. hdc\_std does not match the device.
If the latest image is burnt on the device, the latest hdc\_std version must be used. As hdc\_std is updated continuously, obtain hdc\_std of the latest version from the **developtools\_hdc\_standard** repository in the **prebuilt** directory.
## hdc\_std Fails to Run<a name="section6825095917"></a>
-**Symptom**
The **hdc\_std.exe** file does not run after being clicked.
-**Solutions**
**hdc\_std.exe** requires no installation. It can be directly used on a disk or added to environment variables. Open the cmd window and run the **hdc\_std** command to use **hdc\_std.exe**.