| | 1 | DSX has some support for flattened device trees. |
| | 2 | |
| | 3 | DSX can convert: |
| | 4 | * a given flattened device tree to a soclib caba platform, |
| | 5 | * a given soclib caba platform to a flattened device tree. |
| | 6 | |
| | 7 | As all the needed data is '''not''' present in the components metadata, |
| | 8 | these conversions involve custom translator code. Therefore, support |
| | 9 | for translation is limited to known modules, i.e. modules having an |
| | 10 | associated ''handler''. |
| | 11 | |
| | 12 | = From a platform to a device tree = |
| | 13 | |
| | 14 | For a given platform, we may extract the corresponding device tree |
| | 15 | as seen for a given mapping table (a device tree can represent only one |
| | 16 | address-space): |
| | 17 | |
| | 18 | Import converter and built-in handlers: |
| | 19 | {{{ |
| | 20 | from dsx.contrib.dts_platform.platform_to_dts import PlatformToDts |
| | 21 | import dsx.contrib.dts_platform.platform_handlers |
| | 22 | }}} |
| | 23 | |
| | 24 | Convert the platform, for a given mapping table: |
| | 25 | {{{ |
| | 26 | dtsgen = PlatformToDts(arch, mapping_table) |
| | 27 | }}} |
| | 28 | |
| | 29 | Then we can retrieve the device tree |
| | 30 | {{{ |
| | 31 | device_tree = dtsgen.create_device_tree() |
| | 32 | }}} |
| | 33 | |
| | 34 | This device tree itself can be serialized to different formats. There |
| | 35 | are drivers for this task |
| | 36 | |
| | 37 | == Device tree serialization as ascii source (`dts`) == |
| | 38 | |
| | 39 | Import the driver |
| | 40 | {{{ |
| | 41 | from dsx.device_tree.dts import Driver |
| | 42 | }}} |
| | 43 | |
| | 44 | Call it for the device tree: |
| | 45 | {{{ |
| | 46 | driver = Driver( |
| | 47 | outdir = '.', |
| | 48 | parent = None, |
| | 49 | output_file = "my_platform.dts", |
| | 50 | ) |
| | 51 | |
| | 52 | device_tree.generate(driver) |
| | 53 | }}} |
| | 54 | |
| | 55 | == Device tree serialization as device tree blob (`dtb`) == |
| | 56 | |
| | 57 | Import the driver |
| | 58 | {{{ |
| | 59 | from dsx.device_tree.dtb import Driver |
| | 60 | }}} |
| | 61 | |
| | 62 | Call it for the device tree: |
| | 63 | {{{ |
| | 64 | driver = Driver( |
| | 65 | outdir = '.', |
| | 66 | parent = None, |
| | 67 | output_file = "my_platform.dtb", |
| | 68 | ) |
| | 69 | |
| | 70 | device_tree.generate(driver) |
| | 71 | }}} |
| | 72 | |
| | 73 | = From a device tree to a platform = |
| | 74 | |
| | 75 | Likewise, you may convert a device tree source or blob to a platform. |
| | 76 | |
| | 77 | The architecture generated will be flat around a VGMN. |
| | 78 | |
| | 79 | == Programmatically == |
| | 80 | |
| | 81 | import modules |
| | 82 | {{{ |
| | 83 | from dsx.contrib.dts_platform.dts_to_platform import DtsToPlatform |
| | 84 | import dsx.contrib.dts_platform.handlers |
| | 85 | from soclib.platform import PfDriver |
| | 86 | }}} |
| | 87 | |
| | 88 | Parse a dts and retrieve corresponding platform |
| | 89 | {{{ |
| | 90 | pgen = DtsToPlatform("test_3.dts", binary = 'kernel-soclib-mips.out') |
| | 91 | pf = pgen.create_caba_platform() |
| | 92 | }}} |
| | 93 | |
| | 94 | Generate the simulator, as usual: |
| | 95 | {{{ |
| | 96 | pf.generate(PfDriver("hard")) |
| | 97 | }}} |
| | 98 | |
| | 99 | == With a command-line one-liner == |
| | 100 | |
| | 101 | This tool can even create a netlist with GDB or memchecker-enabled platforms |
| | 102 | |
| | 103 | {{{ |
| | 104 | $ python -m dsx.contrib.dts_platform.converter -h |
| | 105 | Usage: converter.py [-o output_dir] [-b binary] file.dts |
| | 106 | |
| | 107 | Options: |
| | 108 | -h, --help show this help message and exit |
| | 109 | -o OUTPUT_DIR Output directory |
| | 110 | -b BINARY Binary kernel to load |
| | 111 | --gdb Whether to use GDB server |
| | 112 | --memchecker Whether to use Memchecker |
| | 113 | }}} |
| | 114 | |
| | 115 | For instance: |
| | 116 | {{{ |
| | 117 | $ python -m dsx.contrib.dts_platform.converter -o platform -b kernel.out --gdb my_platform.dts |
| | 118 | }}} |