• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Driver Configuration Management<a name="EN-US_TOPIC_0000001053493462"></a>
2
3-   [HDF Configuration Overview](#section59914284576)
4-   [Configuration Syntax](#section533713333580)
5-   [Keywords](#section1316625413586)
6-   [Basic Syntax](#section173481622115918)
7-   [Data Types](#section96521601302)
8-   [Pre-processing](#section8164295515)
9-   [Commenting](#section0338205819610)
10-   [Modifying a Reference](#section179799204716)
11-   [Replicating Node Configuration](#section382424014712)
12-   [Deleting a Node or Attribute](#section165211112586)
13-   [Referencing an Attribute](#section192841514490)
14-   [Keyword Template](#section520134294)
15-   [Configuration Generation](#section106152531919)
16-   [Introduction to HC-GEN](#section8260625101012)
17
18## HDF Configuration Overview<a name="section59914284576"></a>
19
20HCS is the source code that describes the configuration of the HDF using key-value pairs. It decouples the configuration code from driver code, thereby facilitating configuration management.
21
22HDF Configuration Generator \(HC-GEN\) is a tool for converting a configuration file into a file that can be read by the target software.
23
24-   In a low-performance system on a chip \(SoC\), this tool can convert a configuration file into the source code of the configuration tree so that the driver can obtain the configuration by directly calling the C library code.
25-   In a high-performance SoC, this tool can convert an HCS configuration file into the HDF Configuration Binary \(HCB\) file, allowing the driver to obtain the configuration through the APIs provided by the HDF.
26
27The following figure shows the typical application scenario of the HCB mode.
28
29**Figure  1**  Process of using HCS<a name="fig814111371944"></a>
30
31
32![](figure/en-us_image_0000001053405727.png)
33
34The HCS is compiled using the HC-GEN tool to generate an HCB file. The HCS Parser module in the HDF recreates a configuration tree using the HCB file. Then, the HDF driver modules obtain the configurations using the API provided by the HCS Paser.
35
36## Configuration Syntax<a name="section533713333580"></a>
37
38The HCS syntax is described as follows:
39
40## Keywords<a name="section1316625413586"></a>
41
42The keywords listed in the following table below are reserved for HCS configuration files.
43
44**Table  1**  Reserved keywords for HCS configuration files
45
46<a name="table197619515016"></a>
47<table><thead align="left"><tr id="row107621651103"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p0745257902"><a name="p0745257902"></a><a name="p0745257902"></a>Keywords</p>
48</th>
49<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="p1974510571305"><a name="p1974510571305"></a><a name="p1974510571305"></a>Description</p>
50</th>
51<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="p10745175720020"><a name="p10745175720020"></a><a name="p10745175720020"></a>Remarks</p>
52</th>
53</tr>
54</thead>
55<tbody><tr id="row77624515014"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p8745657307"><a name="p8745657307"></a><a name="p8745657307"></a>root</p>
56</td>
57<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p074525719015"><a name="p074525719015"></a><a name="p074525719015"></a>Configures the root node.</p>
58</td>
59<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p1174515575018"><a name="p1174515575018"></a><a name="p1174515575018"></a>-</p>
60</td>
61</tr>
62<tr id="row18762175115012"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p11745175710019"><a name="p11745175710019"></a><a name="p11745175710019"></a>include</p>
63</td>
64<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p167458577016"><a name="p167458577016"></a><a name="p167458577016"></a>References other HCS configuration files.</p>
65</td>
66<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p9745135718012"><a name="p9745135718012"></a><a name="p9745135718012"></a>-</p>
67</td>
68</tr>
69<tr id="row20762251608"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p16745105712015"><a name="p16745105712015"></a><a name="p16745105712015"></a>delete</p>
70</td>
71<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p774585716016"><a name="p774585716016"></a><a name="p774585716016"></a>Deletes a node or an attribute.</p>
72</td>
73<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p974514571102"><a name="p974514571102"></a><a name="p974514571102"></a>This keyword applies only to the configuration tree imported using the <strong id="b2160333103716"><a name="b2160333103716"></a><a name="b2160333103716"></a>include</strong> keyword.</p>
74</td>
75</tr>
76<tr id="row18762751509"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p174617571907"><a name="p174617571907"></a><a name="p174617571907"></a>template</p>
77</td>
78<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p1874610571705"><a name="p1874610571705"></a><a name="p1874610571705"></a>Defines a template node.</p>
79</td>
80<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p774617571019"><a name="p774617571019"></a><a name="p774617571019"></a>-</p>
81</td>
82</tr>
83<tr id="row376320511903"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p3746557501"><a name="p3746557501"></a><a name="p3746557501"></a>match_attr</p>
84</td>
85<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p1174635712015"><a name="p1174635712015"></a><a name="p1174635712015"></a>Marks the node attribute for matching.</p>
86</td>
87<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p1774615571508"><a name="p1774615571508"></a><a name="p1774615571508"></a>During configuration parsing, the keyword value can be used to find the corresponding node.</p>
88</td>
89</tr>
90</tbody>
91</table>
92
93## Basic Syntax<a name="section173481622115918"></a>
94
95The HCS configuration file consists of configurations of attributes and nodes.
96
97**Attributes**
98
99An attribute, as the minimum configuration unit, is an independent configuration item. Its syntax is as follows:
100
101```
102  attribute_name = value;
103```
104
105-   The value of  **attribute\_name**  is a case-sensitive string of characters starting with a letter and consisting of letters, digits, and underscores \(\_\).
106
107-   Available formats of  **value**  are as follows:
108
109    -   A binary, octal, decimal, or hexadecimal integer. For details, see  [Data Types](#section96521601302).
110
111    -   A character string. The content should be enclosed in double quotation marks \(" "\).
112
113    -   A node reference
114
115
116-   An attribute key-value pair must end with a semicolon \(;\) and belong to a node.
117
118
119**Nodes**
120
121A node is a set of attributes. Its syntax is as follows:
122
123```
124  node_name {
125      module = "sample";
126      ...
127  }
128```
129
130-   The value of  **node\_name**  is a case-sensitive string of characters starting with a letter and consisting of letters, digits, and underscores \(\_\).
131
132-   A semicolon \(;\) is not required after the curly brace \(\}\).
133
134-   The reserved keyword  **root**  is used to declare the root node of a configuration table.
135
136-   The root node must contain a  **module**  attribute that uses a string to represent the module to which the configuration belongs.
137
138-   The  **match\_attr**  attribute can be added to a node. Its value is a globally unique character string. During configuration parsing, the query interface can be invoked to query the nodes with the attribute based on the attribute value.
139
140## Data Types<a name="section96521601302"></a>
141
142Attributes automatically use built-in data types, including integers, strings, arrays, and booleans. You do not need to explicitly specify the data type for the attribute values.
143
144**Integer**
145
146An integer can be binary, octal, decimal, or hexadecimal. The minimum space is automatically allocated to the integer based on the actual data length.
147
148-   Binary: prefixed with 0b, for example, 0b1010
149
150-   Octal: prefixed with 0, for example, 0664
151-   Decimal: either signed or unsigned, without a prefix, for example, 1024 or +1024. Negative integers can be read only via signed interfaces.
152
153-   Hexadecimal: prefixed with 0x, for example, 0xff00 and 0xFF
154
155
156**String**
157
158A string is enclosed by double quotation marks \(" "\).
159
160**Array**
161
162The elements in an array can be integers or strings, but cannot be a combination of both. The combination of  **uint32\_t**  and  **uint64\_t**  in an integer array will enable up-casting to  **uint64**. The following is an example of an integer array and a string array:
163
164```
165attr_foo = [0x01, 0x02, 0x03, 0x04];
166attr_bar = ["hello", "world"];
167```
168
169**Boolean**
170
171A Boolean data type has two possible values:  **true**  and  **false**.
172
173## Pre-processing<a name="section8164295515"></a>
174
175**include**
176
177The  **include**  keyword is used to import other HCS files. The syntax is as follows:
178
179```
180#include "foo.hcs"
181#include "../bar.hcs"
182```
183
184-   The file names must be enclosed by double quotation marks \(" "\). Files in different directories can be referenced using relative paths. The file included must be a valid HCS file.
185-   In the scenario that multiple HCS files are imported using  **include**, if the same nodes exist, the latter node will override the former one, and other nodes are listed in sequence.
186
187## Commenting<a name="section0338205819610"></a>
188
189Comments can be formatted as follows:
190
191-   Single-line comment
192
193    ```
194    // comment
195    ```
196
197-   Multi-line comment
198
199    ```
200    /*
201    comment
202    */
203    ```
204
205    >![](../public_sys-resources/icon-note.gif) **NOTE:**
206    >Multi-line comments cannot be nested.
207
208
209## Modifying a Reference<a name="section179799204716"></a>
210
211You can use the following syntax to modify the content of any other node:
212
213```
214 node :& source_node
215```
216
217This syntax indicates that the node value is a modification of the source\_node value. Example:
218
219```
220root {
221    module = "sample";
222    foo {
223        foo_ :& root.bar{
224            attr = "foo";
225        }
226        foo1 :& foo2 {
227            attr = 0x2;
228        }
229        foo2 {
230            attr = 0x1;
231        }
232    }
233
234    bar {
235        attr = "bar";
236    }
237}
238```
239
240The following configuration tree is generated:
241
242```
243root {
244    module = "sample";
245    foo {
246        foo2 {
247            attr = 0x2;
248        }
249    }
250    bar {
251        attr = "foo";
252    }
253}
254```
255
256In the preceding example, the  **foo.foo\_**  node changes the value of the referenced  **bar.attr**  to "**foo**", and the  **foo.foo1**  node changes the value of the referenced  **foo.foo2.attr**  to  **0x2**. In the generated configuration tree,  **foo.foo\_**  and  **foo.foo1**  are not displayed, but their configuration modifications are presented by their referenced nodes.
257
258-   A node of the same level can be referenced simply using the node name. A node of a different level must be referenced by the absolute path, and node names are separated using a period \(.\).  **root**  indicates the root node. The path format is the node path sequence starting with root. For example,  **root.foo.bar**  is a valid absolute path.
259-   If multiple modifications are made to the same attribute, only one uncertain modification can take effect, and a warning will be displayed.
260
261## Replicating Node Configuration<a name="section382424014712"></a>
262
263The content of a node can be replicated to another node to define the node with similar content. The syntax is as follows:
264
265```
266 node : source_node
267```
268
269The preceding statement indicates that the attributes of  **source\_node**  are replicated to  **node**. Example:
270
271```
272root {
273	module = "sample";
274    foo {
275        attr_0 = 0x0;
276    }
277    bar:foo {
278        attr_1 = 0x1;
279    }
280}
281```
282
283The following configuration tree is generated:
284
285```
286root {
287    module = "sample";
288    foo {
289        attr_0 = 0x0;
290    }
291    bar {
292        attr_1 = 0x1;
293        attr_0 = 0x0;
294    }
295}
296```
297
298In the preceding example, the  **bar**  node configuration includes both the  **attr\_0**  and  **attr\_1**  values. The modification to  **attr\_0**  in the  **bar**  node does not affect the  **foo**  node.
299
300The path of the  **foo**  node is not required if the  **foo**  node and the  **bar**  node are of the same level. Otherwise, the absolute path must be used. For details, see  [Modifying a Reference](#section179799204716).
301
302## Deleting a Node or Attribute<a name="section165211112586"></a>
303
304You can use the keyword  **delete**  to delete unnecessary nodes or attributes in the base configuration tree imported by the  **include**  keyword. In the following example,  **sample1.hcs**  imports the configuration of  **sample2.hcs**  using  **include**, and deletes the  **attribute2**  attribute and the  **foo\_2**  node using the  **delete**  keyword.
305
306```
307// sample2.hcs
308root {
309    attr_1 = 0x1;
310    attr_2 = 0x2;
311    foo_2 {
312        t = 0x1;
313    }
314}
315
316// sample1.hcs
317#include "sample2.hcs"
318root {
319    attr_2 = delete;
320    foo_2 : delete {
321    }
322}
323```
324
325The following configuration tree is generated:
326
327```
328root {
329    attr_1 = 0x1;
330}
331```
332
333>![](../public_sys-resources/icon-note.gif) **NOTE:**
334>The  **delete**  keyword cannot be used in the same HCS file. It is recommended that you delete unnecessary attributes directly from the configuration source code.
335
336## Referencing an Attribute<a name="section192841514490"></a>
337
338To quickly locate the associated node during configuration parsing, you can use the node as the value of the attribute and read the attribute to find the corresponding node. The syntax is as follows:
339
340```
341 attribute = &node;
342```
343
344This syntax indicates that the  **attribute**  value is a reference to  **node**. During code parsing, you can quickly locate the node using this attribute. Example:
345
346```
347node1 {
348    attributes;
349}
350
351node2 {
352    attr_1 = &node1;
353}
354```
355
356## Keyword Template<a name="section520134294"></a>
357
358The  **template**  keyword is used to generate nodes with strictly consistent syntax, thereby facilitating the traverse and management of nodes of the same type.
359
360If a node is defined using the keyword  **template**, its child nodes inherit the node configuration through the double colon operator \(::\). The child nodes can modify but cannot add or delete attributes in  **template**. The attributes not defined in the child nodes will use the attributes defined in  **template**  as the default values. Example:
361
362```
363root {
364    module = "sample";
365    template foo {
366        attr_1 = 0x1;
367        attr_2 = 0x2;
368    }
369
370    bar :: foo {
371    }
372
373    bar_1 :: foo {
374        attr_1 = 0x2;
375    }
376}
377```
378
379The following configuration tree is generated:
380
381```
382root {
383    module = "sample";
384    bar {
385        attr_1 = 0x1;
386        attr_2 = 0x2;
387    }
388    bar_1 {
389        attr_1 = 0x2;
390        attr_2 = 0x2;
391    }
392}
393```
394
395In the preceding example, the  **bar**  and  **bar\_1**  nodes inherit the  **foo**  node. The structures of the generated configuration tree nodes are the same as that of the  **foo**  node, but the attribute values are different.
396
397## Configuration Generation<a name="section106152531919"></a>
398
399The HC-GEN tool is used to generate configurations. It checks the HCS configuration syntax and converts HCS source files into HCB files.
400
401## Introduction to HC-GEN<a name="section8260625101012"></a>
402
403Parameter description:
404
405```
406Usage: hc-gen [Options] [File]
407options:
408  -o <file>   output file name, default same as input
409  -a          hcb align with four bytes
410  -b          output binary output, default enable
411  -t          output config in C language source file style
412  -i          output binary hex dump in C language source file style
413  -p <prefix> prefix of generated symbol name
414  -d          decompile hcb to hcs
415  -V          show verbose info
416  -v          show version
417  -h          show this help message
418```
419
420Generate a  **.c**  or  **.h**  configuration file.
421
422```
423hc-gen -o [OutputCFileName] -t [SourceHcsFileName]
424```
425
426Generate an HCB file.
427
428```
429hc-gen -o [OutputHcbFileName] -b [SourceHcsFileName]
430```
431
432Compile an  **HCB**  file to an  **HCS**  file:
433
434```
435hc-gen -o [OutputHcsFileName] -d [SourceHcbFileName]
436```
437
438