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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
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:


```
  attribute_name = value;
```

- **attribute_name** is a case-sensitive string of letters, digits, and underscores (_) and must start with a letter or underscore (_).

- 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 70 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:

W
wenjun 已提交
112 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:

W
wenjun 已提交
129 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 147 148 149
  
  ```
  // comment
  ```
W
wenjun 已提交
150

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

A
Annie_wang 已提交
153 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:

W
wenjun 已提交
168 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 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 197

```
root {
    module = "sample";
    foo {
        foo_ :& root.bar{
            attr = "foo";
        }
        foo1 :& foo2 {
            attr = 0x2;
        }
        foo2 {
            attr = 0x1;
        }
    }

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

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

W
wenjun 已提交
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214

```
root {
    module = "sample";
    foo {
        foo2 {
            attr = 0x2;
        }
    }
    bar {
        attr = "foo";
    }
}
```

A
Annie_wang 已提交
215
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 已提交
216

A
Annie_wang 已提交
217
- 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 已提交
218

A
Annie_wang 已提交
219 220 221 222 223 224
- 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 已提交
225 226 227 228 229 230


```
 node : source_node
```

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

Example:

W
wenjun 已提交
235 236 237 238 239 240 241 242 243 244 245 246 247

```
root {
	module = "sample";
    foo {
        attr_0 = 0x0;
    }
    bar:foo {
        attr_1 = 0x1;
    }
}
```

A
Annie_wang 已提交
248 249
The configuration tree generated is as follows:

W
wenjun 已提交
250 251 252 253 254

```
root {
    module = "sample";
    foo {
W
wenjun 已提交
255
        attr_0 = 0x0;
W
wenjun 已提交
256 257 258 259 260 261 262 263
    }
    bar {
        attr_1 = 0x1;
        attr_0 = 0x0;
    }
}
```

A
Annie_wang 已提交
264 265 266 267
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.

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](referencemodification).

W
wenjun 已提交
268

A
Annie_wang 已提交
269
### Delete
W
wenjun 已提交
270

A
Annie_wang 已提交
271 272 273
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:
W
wenjun 已提交
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294


```
// 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 已提交
295 296
The configuration tree generated is as follows:

W
wenjun 已提交
297 298 299 300 301 302 303

```
root {
    attr_1 = 0x1;
}
```

A
Annie_wang 已提交
304 305 306 307 308
> ![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 已提交
309

A
Annie_wang 已提交
310
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 已提交
311 312 313 314 315 316


```
 attribute = &node;
```

A
Annie_wang 已提交
317 318 319 320
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:

W
wenjun 已提交
321 322 323 324 325

```
node1 {
    attributes;
}
A
annie_wangli 已提交
326 327 328 329
node2 {
    attr_1 = &root.node1;
}
```
A
Annie_wang 已提交
330

A
Annie_wang 已提交
331
Or
W
wenjun 已提交
332

A
Annie_wang 已提交
333

A
annie_wangli 已提交
334
```
W
wenjun 已提交
335
node2 {
A
annie_wangli 已提交
336 337 338
    node1 {
        attributes;
    }
W
wenjun 已提交
339 340 341 342 343
    attr_1 = &node1;
}
```


A
Annie_wang 已提交
344 345 346 347
### 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 已提交
348
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 已提交
349 350

Example:
W
wenjun 已提交
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369


```
root {
    module = "sample";
    template foo {
        attr_1 = 0x1;
        attr_2 = 0x2;
    }

    bar :: foo {
    }

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

A
Annie_wang 已提交
370 371
The configuration tree generated is as follows:

W
wenjun 已提交
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386

```
root {
    module = "sample";
    bar {
        attr_1 = 0x1;
        attr_2 = 0x2;
    }
    bar_1 {
        attr_1 = 0x2;
        attr_2 = 0x2;
    }
}
```

A
Annie_wang 已提交
387
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 已提交
388 389


A
Annie_wang 已提交
390
## **Configuration Generation**
W
wenjun 已提交
391

A
Annie_wang 已提交
392 393 394 395 396 397
The HC-GEN tool checks the HCS configuration syntax and converts HCS source files into HCB files.


### HC-GEN

HC-GEN options:
W
wenjun 已提交
398 399 400 401 402 403 404 405 406


```
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 已提交
407
  -m          output config in macro source file style
W
wenjun 已提交
408 409 410 411 412 413 414 415
  -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 已提交
416 417
Generate a .c or .h configuration file.

W
wenjun 已提交
418 419 420 421 422 423 424

```
hc-gen -o [OutputCFileName] -t [SourceHcsFileName]
```

Generate an HCB file.

A
Annie_wang 已提交
425

W
wenjun 已提交
426 427 428 429
```
hc-gen -o [OutputHcbFileName] -b [SourceHcsFileName]
```

A
annie_wangli 已提交
430 431
Generate a macro definition file.

A
Annie_wang 已提交
432

A
annie_wangli 已提交
433 434 435 436
```
hc-gen -o [OutputMacroFileName] -m [SourceHcsFileName]
```

A
Annie_wang 已提交
437 438
Decompile an HCB file to an HCS file.

W
wenjun 已提交
439 440 441 442

```
hc-gen -o [OutputHcsFileName] -d [SourceHcbFileName]
```