driver-hdf-manage.md 11.2 KB
Newer Older
A
Annie_wang 已提交
1
# Configuration Management
W
wenjun 已提交
2 3


A
Annie_wang 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16
## HDF Configuration Overview

HDF Configuration Source (HCS) is the source code that describes the HDF configuration in key-value pairs. It decouples the configuration code from driver code, simplifying configuration management.

HDF Configuration Generator (HC-GEN) is a tool for converting an HDF configuration file into a file that can be read by the software.

- In a low-performance system on a chip (SoC), this tool converts an HCS configuration file into the source code or macro definitions of the configuration tree. The driver can obtain the configuration by calling the C library code or macro-based APIs.

- In a high-performance SoC, this tool converts an HCS configuration file into an HDF Configuration Binary (HCB) file. The driver can obtain the configuration by calling the configuration parsing APIs provided by the HDF.

The figure below illustrates how an HCB file is used.

  **Figure 1** Process of using an HCB file
W
wenjun 已提交
17

A
Annie_wang 已提交
18
  ![](figures/HCB-using-process.png)
W
wenjun 已提交
19

A
Annie_wang 已提交
20
The HC-GEN converts the HCS into an HCB file. The HCS Parser module in the HDF rebuilds a configuration tree from the HCB file. The HDF driver obtains the configuration through the configuration read API provided by the HCS Parser.
W
wenjun 已提交
21 22


A
Annie_wang 已提交
23
## Configuration Syntax
W
wenjun 已提交
24

A
Annie_wang 已提交
25
The following describes the HCS syntax.
W
wenjun 已提交
26 27


A
Annie_wang 已提交
28
### Keywords
W
wenjun 已提交
29

A
Annie_wang 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
The table below describes the keywords used in the HCS syntax.

  **Table 1** Keywords used in HCS syntax

| Keyword| Description| Remarks| 
| -------- | -------- | -------- |
| root | Sets the root node.| - | 
| include | References other HCS files.| - | 
| delete | Deletes a node or an attribute.| Applicable only to the configuration tree referenced by **include**.| 
| template | Defines a template node.| - | 
| match_attr | Marks the node attribute for matching.| During configuration parsing, the attribute value can be used to locate the corresponding node.| 


### Basic Structures

The HCS has two structures: attribute and node.

**Attribute**

An attribute is the minimum, independent configuration unit. The syntax is as follows:

A
Annie_wang 已提交
51
  
A
Annie_wang 已提交
52 53 54 55
```
  attribute_name = value;
```

A
Annie_wang 已提交
56
- **attribute_name** is a case-sensitive string of letters, digits, and underscores (\_) and must start with a letter or underscore (_).
A
Annie_wang 已提交
57 58 59 60 61 62 63 64 65 66 67 68

- The **value** can be in any of the following formats:

  - A binary, octal, decimal, or hexadecimal integer. For details, see the **Data Types** section.
  - String quoted by double quotation marks ("").
  - Node reference.

- An attribute key-value pair must end with a semicolon (;) and belong to a node.

**Node**

A node is a set of attributes. The syntax is as follows:
W
wenjun 已提交
69

A
Annie_wang 已提交
70
  
W
wenjun 已提交
71 72 73 74 75 76 77
```
  node_name {
      module = "sample";
      ...
  }
```

A
Annie_wang 已提交
78
- **node_name** is a case-sensitive string of letters, digits, and underscores (\_) and must start with a letter or underscore (_).
W
wenjun 已提交
79

A
Annie_wang 已提交
80
- No semicolon (;) is required after the curly brace ({) or (}).
W
wenjun 已提交
81

A
Annie_wang 已提交
82
- The keyword **root** is used to declare the root node of a configuration table. Each configuration table must start with the root node.
W
wenjun 已提交
83

A
Annie_wang 已提交
84
- The root node must contain a **module** attribute. The value is a string indicating the module to which the configuration belongs.
W
wenjun 已提交
85

A
Annie_wang 已提交
86
- The **match_attr** attribute can be added to a node. Its value is a globally unique string. During configuration parsing, the **match_attr** attribute can be used to quickly locate the node that contains the attribute.
W
wenjun 已提交
87

A
Annie_wang 已提交
88 89

### Data Types
W
wenjun 已提交
90

D
duangavin123 已提交
91
Attributes automatically use built-in data types, including integer, string, array, and boolean. You do not need to explicitly specify the data type for the attribute values.
W
wenjun 已提交
92 93 94

**Integer**

A
Annie_wang 已提交
95 96
  An integer can be binary, octal, decimal, or hexadecimal. The minimum space is automatically allocated to the integer based on the actual data length.
- Binary: prefixed with **0b**, for example, **0b1010**.
W
wenjun 已提交
97

A
Annie_wang 已提交
98
- Octal: prefixed with **0**, for example, **0664**.
W
wenjun 已提交
99

A
Annie_wang 已提交
100
- Decimal: signed or unsigned, without prefix, for example, **1024** or **+1024**. Negative integers can be read only via signed interfaces.
W
wenjun 已提交
101

A
Annie_wang 已提交
102
- Hexadecimal: prefixed with **0x**, for example, **0xff00** and **0xFF**.
W
wenjun 已提交
103 104 105

**String**

A
Annie_wang 已提交
106
A string is enclosed in double quotation marks ("").
W
wenjun 已提交
107 108 109

**Array**

A
Annie_wang 已提交
110 111
An array can hold either integers or strings, but not a mixture of them. The mixed use of **uint32_t** and **uint64_t** in an integer array will cause typecasting to **uint64**. The following is an example of an integer array and a string array:

A
Annie_wang 已提交
112
  
W
wenjun 已提交
113 114 115 116 117 118 119
```
attr_foo = [0x01, 0x02, 0x03, 0x04];
attr_bar = ["hello", "world"];
```

**Boolean**

A
Annie_wang 已提交
120 121
Boolean data type is a form of data with only two possible values: **true** and **false**.

W
wenjun 已提交
122

A
Annie_wang 已提交
123
### Preprocessing
W
wenjun 已提交
124 125 126

**include**

A
Annie_wang 已提交
127 128
The keyword **include** is used to import other HCS files. The syntax is as follows:

A
Annie_wang 已提交
129
  
W
wenjun 已提交
130 131 132 133 134
```
#include "foo.hcs"
#include "../bar.hcs"
```

A
Annie_wang 已提交
135 136 137
- The file name must be enclosed in double quotation marks (""). If the file to be included is in a different directory with the target file, use a relative path. The included file must be a valid HCS file.

- If multiple HCS files included contain the same nodes, the same nodes will be overridden and other nodes are listed in sequence.
W
wenjun 已提交
138 139


A
Annie_wang 已提交
140
### Comments
W
wenjun 已提交
141

A
Annie_wang 已提交
142
The following two comment formats are supported:
W
wenjun 已提交
143

A
Annie_wang 已提交
144
- Single-line comment
W
wenjun 已提交
145

A
Annie_wang 已提交
146
    
A
Annie_wang 已提交
147 148 149
  ```
  // comment
  ```
W
wenjun 已提交
150

A
Annie_wang 已提交
151
- Multi-line comment
W
wenjun 已提交
152

A
Annie_wang 已提交
153
    
A
Annie_wang 已提交
154 155 156 157 158
  ```
  /*
  comment
  */
  ```
W
wenjun 已提交
159

A
Annie_wang 已提交
160 161
  > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
  > Multi-line comments cannot be nested.
W
wenjun 已提交
162 163


A
Annie_wang 已提交
164 165 166 167
### Reference Modification

You can reference the content of a node to modify the content of another node. The syntax is as follows:

A
Annie_wang 已提交
168
  
W
wenjun 已提交
169 170 171 172
```
 node :& source_node
```

A
Annie_wang 已提交
173
In this statement, the content of **node** is referenced to modify the content of **source_node**. 
A
Annie_wang 已提交
174
  
A
Annie_wang 已提交
175
Example:
W
wenjun 已提交
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
```
root {
    module = "sample";
    foo {
        foo_ :& root.bar{
            attr = "foo";
        }
        foo1 :& foo2 {
            attr = 0x2;
        }
        foo2 {
            attr = 0x1;
        }
    }

    bar {
        attr = "bar";
    }
}
```

A
Annie_wang 已提交
197 198
The configuration tree generated is as follows:

A
Annie_wang 已提交
199
  
W
wenjun 已提交
200 201 202 203 204 205 206 207 208 209 210 211 212 213
```
root {
    module = "sample";
    foo {
        foo2 {
            attr = 0x2;
        }
    }
    bar {
        attr = "foo";
    }
}
```

A
Annie_wang 已提交
214
In this example, the value of **bar.attr** is changed to **foo** by referencing **foo.foo_**, and the value of **foo.foo2.attr** is changed to **0x2** by referencing **foo.foo1**. The **foo.foo_** and **foo.foo1** nodes are used to modify the content of the target nodes, and do not exist in the configuration tree generated.
W
wenjun 已提交
215

A
Annie_wang 已提交
216
- A node of the same level can be referenced simply using the node name. To reference a node of a different level, use the absolute path starting with **root**, and separate the node names using a period (.). **root** indicates the root node. For example, **root.foo.bar**.
W
wenjun 已提交
217

A
Annie_wang 已提交
218 219 220 221 222 223
- If multiple modifications are made to the same attribute, only one modification takes effect and a warning will be displayed for you to confirm the result.


### Node Replication

You can replicate a node to define a node with similar content. The syntax is as follows:
W
wenjun 已提交
224

A
Annie_wang 已提交
225
  
W
wenjun 已提交
226 227 228 229
```
 node : source_node
```

A
Annie_wang 已提交
230 231 232
This statement replicates the attributes of the **source_node** node to define **node**. 

Example:
A
Annie_wang 已提交
233
  
W
wenjun 已提交
234 235 236 237 238 239 240 241 242 243 244 245
```
root {
	module = "sample";
    foo {
        attr_0 = 0x0;
    }
    bar:foo {
        attr_1 = 0x1;
    }
}
```

A
Annie_wang 已提交
246 247
The configuration tree generated is as follows:

A
Annie_wang 已提交
248
  
W
wenjun 已提交
249 250 251 252
```
root {
    module = "sample";
    foo {
W
wenjun 已提交
253
        attr_0 = 0x0;
W
wenjun 已提交
254 255 256 257 258 259 260 261
    }
    bar {
        attr_1 = 0x1;
        attr_0 = 0x0;
    }
}
```

A
Annie_wang 已提交
262 263
In this example, the **bar** node contains **attr_0** and **attr_1** attributes, and the modification of the **attr_0** attribute in the **bar** node does not affect the **foo** node.

A
Annie_wang 已提交
264
You do not need to specify the path of the **foo** node if the **foo** node and the **bar** node are of the same level. Otherwise, specify the absolute path of **foo**. For details, see [Reference Modification](#reference-modification).
A
Annie_wang 已提交
265

W
wenjun 已提交
266

A
Annie_wang 已提交
267
### Delete
W
wenjun 已提交
268

A
Annie_wang 已提交
269 270 271
You can use the keyword **delete** to delete unnecessary nodes or attributes from the base configuration tree imported by using the **include** keyword. The following example includes the configuration in **sample2.hcs** to **sample1.hcs** and deletes the **attribute2** attribute and the **foo_2** node. 

Example:
A
Annie_wang 已提交
272
  
W
wenjun 已提交
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
```
// sample2.hcs
root {
    attr_1 = 0x1;
    attr_2 = 0x2;
    foo_2 {
        t = 0x1;
    }
}

// sample1.hcs
#include "sample2.hcs"
root {
    attr_2 = delete;
    foo_2 : delete {
    }
}
```

A
Annie_wang 已提交
292 293
The configuration tree generated is as follows:

A
Annie_wang 已提交
294
  
W
wenjun 已提交
295 296 297 298 299 300
```
root {
    attr_1 = 0x1;
}
```

A
Annie_wang 已提交
301 302 303 304 305
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> The keyword **delete** cannot be used to delete nodes or attributes in the same HCS file. In an HCS file, you can directly delete unnecessary attributes.


### Attribute Reference
W
wenjun 已提交
306

A
Annie_wang 已提交
307
You can associate an attribute and a node so that the node can be quickly located when the attribute is read during configuration parsing. The syntax is as follows:
W
wenjun 已提交
308

A
Annie_wang 已提交
309
  
W
wenjun 已提交
310 311 312 313
```
 attribute = &node;
```

A
Annie_wang 已提交
314 315 316
In this statement, the value of **attribute** is a referenced to the node. During code parsing, you can quickly locate the node based on this **attribute**. 

Example:
A
Annie_wang 已提交
317
  
W
wenjun 已提交
318 319 320 321
```
node1 {
    attributes;
}
A
annie_wangli 已提交
322 323 324 325
node2 {
    attr_1 = &root.node1;
}
```
A
Annie_wang 已提交
326

A
Annie_wang 已提交
327
or
A
Annie_wang 已提交
328

A
Annie_wang 已提交
329
  
A
annie_wangli 已提交
330
```
W
wenjun 已提交
331
node2 {
A
annie_wangli 已提交
332 333 334
    node1 {
        attributes;
    }
W
wenjun 已提交
335 336 337 338 339
    attr_1 = &node1;
}
```


A
Annie_wang 已提交
340 341 342 343
### Template

The template is used to generate nodes with consistent syntax, thereby facilitating the traverse and management of nodes of the same type.

A
Annie_wang 已提交
344
If a node is defined using the keyword **template**, its child nodes inherit from the node configuration through the double colon operator (::). The child nodes can modify or add but cannot delete attributes in **template**. The attributes not defined in the child nodes will use the attributes defined in **template** as the default values.
A
Annie_wang 已提交
345 346

Example:
A
Annie_wang 已提交
347
  
W
wenjun 已提交
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
```
root {
    module = "sample";
    template foo {
        attr_1 = 0x1;
        attr_2 = 0x2;
    }

    bar :: foo {
    }

    bar_1 :: foo {
        attr_1 = 0x2;
    }
}
```

A
Annie_wang 已提交
365 366
The configuration tree generated is as follows:

A
Annie_wang 已提交
367
  
W
wenjun 已提交
368 369 370 371 372 373 374 375 376 377 378 379 380 381
```
root {
    module = "sample";
    bar {
        attr_1 = 0x1;
        attr_2 = 0x2;
    }
    bar_1 {
        attr_1 = 0x2;
        attr_2 = 0x2;
    }
}
```

A
Annie_wang 已提交
382
In this example, the **bar** and **bar_1** nodes inherit from the **foo** node. The structure of the generated configuration tree is the same as that of the **foo** node, except that the attribute values are different.
W
wenjun 已提交
383 384


A
Annie_wang 已提交
385
## **Configuration Generation**
W
wenjun 已提交
386

A
Annie_wang 已提交
387 388 389 390 391 392
The HC-GEN tool checks the HCS configuration syntax and converts HCS source files into HCB files.


### HC-GEN

HC-GEN options:
W
wenjun 已提交
393

A
Annie_wang 已提交
394
  
W
wenjun 已提交
395 396 397 398 399 400 401
```
Usage: hc-gen [Options] [File]
options:
  -o <file>   output file name, default same as input
  -a          hcb align with four bytes
  -b          output binary output, default enable
  -t          output config in C language source file style
A
annie_wangli 已提交
402
  -m          output config in macro source file style
W
wenjun 已提交
403 404 405 406 407 408 409 410
  -i          output binary hex dump in C language source file style
  -p <prefix> prefix of generated symbol name
  -d          decompile hcb to hcs
  -V          show verbose info
  -v          show version
  -h          show this help message
```

A
Annie_wang 已提交
411 412
Generate a .c or .h configuration file.

A
Annie_wang 已提交
413
  
W
wenjun 已提交
414 415 416 417 418 419
```
hc-gen -o [OutputCFileName] -t [SourceHcsFileName]
```

Generate an HCB file.

A
Annie_wang 已提交
420
  
W
wenjun 已提交
421 422 423 424
```
hc-gen -o [OutputHcbFileName] -b [SourceHcsFileName]
```

A
annie_wangli 已提交
425 426
Generate a macro definition file.

A
Annie_wang 已提交
427
  
A
annie_wangli 已提交
428 429 430 431
```
hc-gen -o [OutputMacroFileName] -m [SourceHcsFileName]
```

A
Annie_wang 已提交
432 433
Decompile an HCB file to an HCS file.

A
Annie_wang 已提交
434
  
W
wenjun 已提交
435 436 437
```
hc-gen -o [OutputHcsFileName] -d [SourceHcbFileName]
```