forked from devicetree-org/lopper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.pydoc
2808 lines (2773 loc) · 106 KB
/
README.pydoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Help on module lopper:
NAME
lopper
DESCRIPTION
#/*
# * Copyright (c) 2019,2020 Xilinx Inc. All rights reserved.
# *
# * Author:
# * Bruce Ashfield <bruce.ashfield@xilinx.com>
# *
# * SPDX-License-Identifier: BSD-3-Clause
# */
CLASSES
builtins.object
LopperAssist
LopperFile
LopperSDT
class LopperAssist(builtins.object)
| Internal class to contain the details of a lopper assist
|
| Methods defined here:
|
| __init__(self, lop_file, module='', properties_dict={})
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class LopperFile(builtins.object)
| Internal class to contain the details of a lopper file
|
| Attributes:
| - dts: the dts source file path for a lop
| - dtb: the compiled dtb file path for a lop
| - fdt: the loaded FDT representation of the dtb
|
| Methods defined here:
|
| __init__(self, lop_file)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class LopperSDT(builtins.object)
| The LopperSDT Class represents and manages the full system DTS file
|
| In particular this class:
| - wraps a dts/dtb/fdt containing a system description
| - Has a LopperTree representation of the system device tree
| - manages and applies operations to the tree
| - calls modules and assist functions for processing of that tree
|
| Attributes:
| - dts (string): the source device tree file
| - dtb (blob): the compiled dts
| - FDT (fdt): the primary flattened device tree represention of the dts
| - lops (list): list of loaded lopper operations
| - verbose (int): the verbosity level of operations
| - tree (LopperTree): node/property representation of the system device tree
| - dry_run (bool): whether or not changes should be written to disk
| - output_file (string): default output file for writing
|
| Methods defined here:
|
| __init__(self, sdt_file)
| Initialize self. See help(type(self)) for accurate signature.
|
| assist_find(self, assist_name, local_load_paths=[])
| Locates a python module that matches assist_name
|
| This routine searches both system (lopper_directory, lopper_directory +
| "assists", and passed paths (local_load_paths) to locate a matching
| python implementation.
|
| Args:
| assist_name (string): name of the assist to locate
| local_load_paths (list of strings, optional): list of directories to search
| in addition to system dirs
|
| Returns:
| Path: Path object to the located python module, None on failure
|
| assists_setup(self, assists=[])
| assists (list,optional): list of python assist modules to load. Default is []
|
| assists_wrap(self)
| wrap assists that have been added to the device tree
|
| Wraps any command line assists that have been added to the system
| device tree. A standard lop format dtb is generated for any found
| assists, such that they will be loaded in the same manner as
| assists passed directly in lop files.
|
| Note: this is for internal use only
|
| Args:
| None
|
| Returns:
| Nothing
|
| cleanup(self)
| cleanup any temporary or copied files
|
| Either called directly, or registered as an atexit handler. Any
| temporary or copied files are removed, as well as other relevant
| cleanup.
|
| Args:
| None
|
| Returns:
| Nothing
|
| domain_spec(self, tgt_domain)
| generate a lop for a command line passed domain
|
| When a target domain is passed on the command line, we must generate
| a lop dtb for it, so that it can be processed along with other
| operations
|
| Args:
| tgt_domain (string): path to the node to use as the domain
|
| Returns:
| Nothing
|
| exec_lop(self, lops_fdt, lop_node_number, options=None)
| Executes a a lopper operation (lop)
|
| Runs a lopper operation against the system device tree.
|
| Details of the lop are in the lops_fdt, with extra parameters and lop
| specific information from the caller being passed in the options
| variable.
|
| Args:
| lops_fdt (FDT): lopper operation flattened device tree
| lop_node_number (int): node number for the operation in lops_fdt
| options (dictionary,optional): lop specific options passed from the caller
|
| Returns:
| boolean
|
| find_compatible_assist(self, cb_node=None, cb_id='', mask='')
| Finds a registered assist that is compatible with a given ID
|
| Searches the registered assists for one that is compatible with an ID.
|
| The is_compat() routine is called for each registered module. If an
| assist is capabable of handling a given ID, it returns True and
| associated actions can then be taken.
|
| I addition to an ID string, a mask can optionally be provided to this
| routine. Any assists that have registered a mask, will have that
| checked, before calling the is_compat() routine. This allows assists to
| be generically registered, but filtered by the caller rather than only
| their is_compat() routines.
|
| Args:
| cb_node (int,optional): node offset to be tested. Default is 0 (root)
| cb_id (string,optional): ID to be tested for compatibility. Default is ""
| mask (string,optional): caller mask for filtering nodes. Default is ""
|
| Returns:
| function reference: the callback routine, or "", if no compatible routine found
|
| module_setup(self, module_name, module_args=[])
|
| node_find(self, node_prefix)
| Finds a node by its prefix
|
| Wrapper around the Lopper routine of the same name, to abstract the
| FDT that is part of the LopperSDT class.
|
| perform_lops(self)
| Execute all loaded lops
|
| Iterates and executes all the loaded lopper operations (lops) for the
| System Device tree.
|
| The lops are processed in priority order (priority specified at the file
| level), and the rules processed in order as they appear in the lop file.
|
| lopper operations can immediately process the output of the previous
| operation and hence can be stacked to perform complex operations.
|
| Args:
| None
|
| Returns:
| Nothing
|
| setup(self, sdt_file, input_files, include_paths, force=False)
| executes setup and initialization tasks for a system device tree
|
| setup validates the inputs, and calls the appropriate routines to
| preprocess and compile passed input files (.dts).
|
| Args:
| sdt_file (String): system device tree path/file
| input_files (list): list of input files (.dts, or .dtb) in addition to the sdt_file
| include_paths (list): list of paths to search for files
| force (bool,optional): flag indicating if files should be overwritten and compilation
| forced. Default is False.
|
| Returns:
| Nothing
|
| write(self, fdt=None, output_filename=None, overwrite=True, enhanced=False)
| Write a system device tree to a file
|
| Write a fdt (or system device tree) to an output file. This routine uses
| the output filename to determine if a module should be used to write the
| output.
|
| If the output format is .dts or .dtb, Lopper takes care of writing the
| output. If it is an unrecognized output type, the available assist
| modules are queried for compatibility. If there is a compatible assist,
| it is called to write the file, otherwise, a warning or error is raised.
|
| Args:
| fdt (fdt,optional): source flattened device tree to write
| output_filename (string,optional): name of the output file to create
| overwrite (bool,optional): Should existing files be overwritten. Default is True.
| enhanced(bool,optional): whether enhanced printing should be performed. Default is False
|
| Returns:
| Nothing
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| phandle_safe_name(phandle_name)
| Make the passed name safe to use as a phandle label/reference
|
| Args:
| phandle_name (string): the name to use for a phandle
|
| Returns:
| The modified phandle safe string
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
FUNCTIONS
at_exit_cleanup()
main()
stdoutIO(stdout=None)
usage()
DATA
LOPPER_VERSION = '2020.4-beta'
QUIET_ALL = range(1, 18)
QUIET_NOTFOUND = (1,)
lopper_directory = '/home/bruce/git/system-device-tree'
yaml_support = True
FILE
/home/bruce/git/system-device-tree/lopper.py
Help on module lopper_fdt:
NAME
lopper_fdt
DESCRIPTION
#/*
# * Copyright (c) 2019,2020 Xilinx Inc. All rights reserved.
# *
# * Author:
# * Bruce Ashfield <bruce.ashfield@xilinx.com>
# *
# * SPDX-License-Identifier: BSD-3-Clause
# */
CLASSES
builtins.object
Lopper
enum.Enum(builtins.object)
LopperFmt
class Lopper(builtins.object)
| The Lopper Class contains static methods for manipulating device trees
|
| Use the lopper methods when manipulating device trees (in particular
| libfdt FDT objects) or SystemDeviceTree classes.
|
| Static methods defined here:
|
| dt_compile(dts_file, i_files, includes, force_overwrite=False, outdir='./', save_temps=False, verbose=0)
| Compile a dts file to a dtb
|
| This routine takes a dts input file, other dts include files,
| include search path and then uses standard tools (cpp, dtc, etc).
|
| Environment variables can be used tweak the execution of the various
| tools and stages:
|
| LOPPER_CPP: set if a different cpp than the standard one should
| be used, or if cpp is not on the path
| LOPPER_PPFLAGS: flags to be used when calling cpp
| LOPPER_DTC: set if a non standard dtc should be used, or if dtc
| is not on the path
| LOPPER_DTC_FLAGS: flags to use when calling dtc
| LOPPER_DTC_OFLAGS: extra dtc flags if an overlay is being compiled
| LOPPER_DTC_BFLAGS: extra dtc args/flags
|
| Args:
| dts_file (string): path to the dts file to be compiled
| i_files (list): files to be included
| includes (list): list of include directories (translated into -i <foo>
| for dtc calls)
| force_overwrite (bool,optional): should files be overwritten.
| Default is False
| save_temps (bool, optional): should temporary files be saved on failure
| verbose (bool,optional): verbosity level
|
| Returns:
| string: Name of the compiled dtb
|
| dt_preprocess(dts_file, includes, outdir='./', verbose=0)
| Compile a dts file to a dtb
|
| This routine takes a dts input file, include search path and then
| uses standard tools (cpp, etc) to expand references.
|
| Environment variables can be used tweak the execution of the various
| tools and stages:
|
| LOPPER_CPP: set if a different cpp than the standard one should
| be used, or if cpp is not on the path
| LOPPER_PPFLAGS: flags to be used when calling cpp
|
| Args:
| dts_file (string): path to the dts file to be preprocessed
| includes (list): list of include directories (translated into -i <foo>
| for cpp calls)
| outdir (string): directory to place all output and temporary files
| verbose (bool,optional): verbosity level
|
| Returns:
| string: Name of the preprocessed dts
|
| dt_to_fdt(dtb, rmode='rb')
| takes a dtb and returns a flattened device tree object
|
| Args:
| dtb: a compiled device tree
| rmode (string,optional): the read mode of the file, see libfdt for possible values
| default is 'rb'
|
| Returns:
| A flattended device tree object (as defined by libfdt)
|
| dtb_dts_export(dtb, outfilename='', verbose=0)
| writes a dtb to a file or to stdout as a dts
|
| Args:
| dtb: a compiled device tree
| outfilename (string): the output filename (stdout is used if empty)
| verbose (int,optional): extra debug info. default 0.
|
| Returns:
| The return value of executing dtc to dump the dtb to dts
|
| encode_byte_array(values)
| utility to encode a list of values into a bytearray
|
| Args:
| values (list): integer (numeric) values to encode
|
| Returns:
| byte array: the encoded byte array
|
| encode_byte_array_from_strings(values)
| utility to encode a list of strings into a bytearray
|
| Args:
| values (list): string values to encode
|
| Returns:
| byte array: the encoded byte array
|
| fdt(size=None, other_fdt=None)
| Create a new FDT
|
| Creats a new FDT of a passed size. If other_fdt is passed, it
| is used as the start size of the fdt.
|
| If no size or other fdt is passed, 128 bytes is the default
| size
|
| Args:
| size (int,optional): size in bytes of the FDT
| other_fdt (FDT,optional): reference FDT for size
|
| Returns:
| fdt: The newly created FDT
|
| fdt_copy(fdt)
| Copy a fdt
|
| Creats a new FDT that is a copy of the passed one.
|
| Args:
| fdt (FDT): reference FDT
|
| Returns:
| fdt: The newly created FDT
|
| input_file_type(infile)
| utility to return the "type" of a file, aka the extension
|
| Args:
| infile (string): path of the file
|
| Returns:
| string: the extension of the file
|
| node_abspath(fdt, nodeid)
| Get the absolute (fully specified) path of a nodes
|
| Args:
| fdt (fdt): flattened device tree object
| nodeid: device tree node offset
|
| Returns:
| string: node path, if successful, otherwise ""
|
| node_add(fdt_dest, node_full_path, create_parents=True, verbose=0)
| Add an empty node to a flattened device tree
|
| Creates a new node in a flattened devide tree at a given path. If
| desired a node structure (aka parents) will be created as part of
| adding the node at the specified path.
|
| Args:
| fdt_dest (fdt): flattened device tree object
| node_full_path (string): fully specified path (and name) of the node to create
| create_parents (bool,optional): Should parent nodes be created. Default is True.
| True: create parents as required, False: error if parents are missing
| verbose (int,optional): verbosity level. default is 0.
|
| Returns:
| int: The node offset of the created node, if successfull, otherwise -1
|
| node_by_phandle(fdt, phandle, verbose=0)
| Get a node offset by a phandle
|
| Thin wrapper around the libfdt routine. The wrapper provides
| consistent exception handling and verbosity level handling.
|
| Args:
| fdt (fdt): flattened device tree object
| phandle(int): phandle to use as lookup key
| verbose(bool,optional): verbosity level. Deafult is 0.
|
| Returns:
| int: if > 0, the node that was found. -1 if node was not found.
|
| node_copy(fdt_source, node_source_offset, fdt_dest, node_dest_parent_offset, verbose=0)
| Copies a node from one FDT to another
|
| Copies a node between flattened device trees. The node (and
| properties) will be copied to the specified target device tree and
| path (ensure that a node does not already exist at the destination
| path).
|
| Note: the destination node parent must exist before calling this routine
|
| Properties are iterated, decoded and then copied (encoded) to the
| destination node. As such, the copies are limited by the
| decode/encode capabilities. If properties do not look correct in the
| copy, the decode/encode routines need to be checked.
|
| Args:
| fdt_source (fdt): source flattened device tree object
| node_source_offset: source device tree node offset
| fdt_dest (fdt): destination flattened device tree object
| node_dest_parent_offset: destination device parent node
| verbose (int,optional): verbosity level. default is 0.
|
| Returns:
| bool: True if the node was copied, otherise, False
|
| node_copy_from_path(fdt_source, node_source_path, fdt_dest, node_full_dest, verbose=0)
| Copies a node from one FDT to another
|
| Copies a node between flattened device trees. The node (and
| properties) will be copied to the specified target device tree and
| path (ensure that a node does not already exist at the destination
| path).
|
| This routine is a wrapper around node_copy(), and will create a
| parent node structure in the destination fdt as required.
|
| Args:
| fdt_source (fdt): source flattened device tree object
| node_source_path: source device tree node path (fully specified)
| fdt_dest (fdt): destination flattened device tree object
| node_full_dest: destination device tree path for copied node (fully specified)
| verbose (int,optional): verbosity level. default is 0.
|
| Returns:
| bool: True if the node was copied, otherise, False
|
| node_find(fdt, node_prefix)
| Finds a node by its prefix
|
| Args:
| fdt (fdt): flattened device tree object
| node_prefix (string): device tree path
|
| Returns:
| int: node number if successful, otherwise -1
|
| node_find_by_name(fdt, node_name, starting_node=0, multi_match=False)
| Finds a node by its name (not path)
|
| Searches for a node by its name, and returns the offset of that same node
| Note: use this when you don't know the full path of a node
|
| Args:
| fdt (fdt): flattened device tree object
| node_name (string): name of the node
| starting_node (int): node number to use as the search starting point
| multi_match (bool,optional): flag to indicate if more than one matching
| node should be found, default is False
|
| Returns:
| tuple: first matching node, list of matching nodes. -1 and [] if no match is found
|
| node_find_by_regex(fdt, node_regex, starting_node=0, multi_match=False, paths_not_numbers=False)
| Finds a node by a regex /path/<regex>/<name>
|
| Searches for nodes that match a regex (path + name).
|
| Note: if you pass the name of a node as the regex, you'll get a list of
| that node + children
| Note: if you pass no regex, you'll get all nodes from the starting point
| to the end of the tree.
|
| Args:
| fdt (fdt): flattened device tree object
| node_regex (string): regex to use for comparision
| starting_node (int): node number to use as the search starting point
| multi_match (bool,optional): flag to indicate if more than one matching
| node should be found, default is False
| paths_not_numbers (bool,optional): flag to request paths, not node numbers
| be returned
|
| Returns:
| tuple: first matching node, list of matching nodes. -1 and [] if no match is found
|
| node_getname(fdt, node_number_or_path)
| Gets the FDT name of a node
|
| Args:
| fdt (fdt): flattened device tree object
| node_number_or_path: node number or path
|
| Returns:
| string: name of the node, or "" if node wasn't found
|
| node_getphandle(fdt, node_number)
| utility command to get a phandle (as a number) from a node
|
| Args:
| fdt (FDT): flattened device tree
| node_number (int): node number in the fdt
|
| Returns:
| int: the phandle of the node number, if successful, -1 if not
|
| node_number(fdt, node)
| Get the number for the passed node
|
| Return the node number of a node by its path, or just return
| its number if it is already a number. This is a normalization
| routine for node references
|
| Args:
| fdt (fdt): flattened device tree object
| node (string or ing): the name or node number to check
|
| Returns:
| string: node number, or -1 if the node doesn't exist
|
| node_parent(fdt, node_number_or_path)
|
| node_prop_check(fdt, node_name, property_name)
| Check if a node contains a property
|
| Boolean check to see if a node contains a property.
|
| The node name does not need to be a full path or path prefix, since
| the node will be searched starting at the root node, which means that
| a non-unique node name could match multiple nodes.
|
| Args:
| fdt (fdt): flattened device tree object
| node_name (string): name of the node
| property_name (string): name of the property to check
|
| Returns:
| bool: True if the node has the property, otherwise False
|
| node_properties(fdt, node_number_or_path)
| Get the list of properties for a node
|
| Gather the list of FDT properties for a given node.
|
| Args:
| fdt (fdt): flattened device tree object
| node_number_or_path: (string or int): node number or full path to
| the target node.
|
| Returns:
| list (FDT prop): The properties of the node [] if no props
|
| node_properties_as_dict(fdt, node, verbose=0)
| Create a dictionary populated with the nodes properties.
|
| Builds a dictionary that is propulated with a node's properties as
| the keys, and their values. Used as a utility routine to avoid
| multiple calls to check if a property exists, and then to fetch its
| value.
|
| Args:
| fdt (fdt): flattened device tree object
| node (int or string): either a node number or node path
| verbose (int,optional): verbosity level. default is 0.
|
| Returns:
| dict: dictionary of the properties, if successfull, otherwise and empty dict
|
| node_remove(fdt, target_node_offset, verbose=0)
| remove a node from the device tree
|
| Thin wrapper and consistent logging around libfdt's node delete.
|
| Args:
| fdt (fdt): flattended device tree
| target_node_offset (int): offset of the node to be deleted
|
| Returns:
| Boolean: True if node is removed, false otherwise
|
| node_remove_if_not_compatible(fdt, node_prefix, compat_string)
| Remove a node if incompatible with passed string
|
| Utility/cleanup function to remove all nodues under a node_prefix
| that are not compatible with a given string.
|
| Args:
| fdt (FDT): flattened device tree
| node_prefix (string): starting node path
| compat_strin (string): string for compat property comparison
|
| Returns:
| Nothing
|
| node_setname(fdt, node_number_or_path, newname)
| Sets the FDT name of a node
|
| Args:
| fdt (fdt): flattened device tree object
| node_number_or_path: node number or path
| newname (string): name of the node
|
| Returns:
| boolean: True if the name was set, False otherwise
|
| node_subnodes(fdt, node_number_or_path, abs_paths=True)
| Get the list of properties for a node
|
| Gather the list of FDT properties for a given node.
|
| Args:
| fdt (fdt): flattened device tree object
| node_number_or_path: (string or int): node number or full path to
| the target node.
| abs_paths (boolean, optional): indicate if absolute paths should be returned
|
| Returns:
| list (strings): The subnodes, [] if no subnodes
|
| node_type(fdt, node_offset, verbose=0)
| Utility function to get the "type" of a node
|
| A small wrapper around the compatible property, but we can use this
| instead of directly getting compatible, since if we switch formats or if
| we want to infer anything based on the name of a node, we can hide it in
| this routine
|
| Args:
| fdt (fdt): flattened device tree object
| node_offset (int): node number
| verbose (int): verbose output level
|
| Returns:
| string: compatible string of the node if successful, otherwise ''
|
| node_walk(fdt, verbose=0)
| Walk nodes and gather a list
|
| Utility / reference routine for gathering a list of nodes.
| Always starts at node 0.
|
| Args:
| fdt (FDT): flattened device tree
| verbose (int,optional): verbosity level, default 0.
|
| Returns:
| List of nodes. Each containg the [node number, name, phandle, depth]
|
| nodes(fdt, node_number_or_path, abs_paths=True)
| Get the nodes of a tree from a starting point
|
| Gather the list nodes in the tree from a particular starting point
|
| Args:
| fdt (fdt): flattened device tree object
| node_number_or_path: (string or int): node number or full path to
| the target node.
| abs_paths (boolean, optional): indicate if absolute paths should be returned
|
| Returns:
| list (strings): The nodes, [] if no nodes
|
| nodes_with_property(fdt, match_propname, match_regex='', start_path='/', include_children=True, match_depth=0)
| Get a list of nodes with a particular property
|
| Searches a device tree and returns a list of nodes that contain
| a given property.
|
| Matching is done by the existence of a property name in a node.
|
| If a match_regex is passed, then the value of the property is
| tested against the regex. If there's a match, then the node is
| added to the list.
|
| Args:
| fdt (fdt): source flattened device tree to search
| match_propname (string): target property name
| match_regex (string,optional): property value match regex. Default is ""
| start_path (string,optional): starting path in the device tree. Default is "/"
| include_children (bool,optional): should child nodes be searched. Default is True.
| match_depth (int): depth of the node, relative to the start path. Default is 0 (all nodes)
|
| Returns:
| list: list of matching nodes if successful, otherwise an empty list
|
| phandle_possible_properties()
| Get the diectionary of properties that can contain phandles
|
| dictionary of possible properties that can have phandles.
| To do the replacement, we map out the properties so we can locate any
| handles and do replacement on them with symbolic values. This format is
| internal only, and yes, could be the schema for the fields, but for now,
| this is easier.
|
| Each key (property name) maps to a list of: 'format', 'flag'
| flag is currently unused, and format is the following:
|
| - field starting with #: is a size value, we'll look it up and add 'x'
| number of fields based on it. If we can't find it, we'll just use '1'
| - phandle: this is the location of a phandle, size is '1'
| - anything else: is just a field we can ignore, size is '1'
|
| Args:
| None
|
| Returns:
| The phandle property dictionary
|
| phandle_safe_name(phandle_name)
| Make the passed name safe to use as a phandle label/reference
|
| Args:
| phandle_name (string): the name to use for a phandle
|
| Returns:
| The modified phandle safe string
|
| property_get(fdt, node_number, prop_name, ftype=<LopperFmt.SIMPLE: 1>, encode=<LopperFmt.DEC: 4>)
| utility command to get a property (as a string) from a node
|
| A more robust way to get the value of a property in a node, when
| you aren't sure of the format of that property. This routine takes
| hints when getting the property in the form of a "format type" and
| an encoding.
|
| The format and encoding options are in the following enum type:
|
| class LopperFmt(Enum):
| SIMPLE = 1 (format)
| COMPOUND = 2 (format)
| HEX = 3 (encoding)
| DEC = 4 (encoding)
| STRING = 5 (encoding)
| MULTI_STRING = 5 (encoding)
|
| Args:
| fdt (FDT): flattened device tree
| node_number (int): node number in the fdt
| property (string): property name whose value to get
| ftype (LopperFmt,optional): format of the property. Default SIMPLE.
| encode (LopperFmt,optional); encoding of the property. Default DEC
|
| Returns:
| string: if format is SIMPLE: string value of the property, or "" if not found
| list: if format is COMPOUND: list of property values as strings, [] if not found
|
| property_list(fdt, node_path)
| Read a list of properties from a node
|
| Args:
| node_path: Full path to node, e.g. '/subnode@1/subsubnode'
|
| Returns:
| List of property names for that node, e.g. ['compatible', 'reg']
|
| property_phandle_params(fdt, nodeoffset, property_name)
| Determines the phandle elements/params of a property
|
| Takes a property name and returns where to find a phandle in
| that property.
|
| Both the index of the phandle, and the number of fields in
| the property are returned.
|
| Args:
| fdt (FDT): flattened device tree
| nodeoffset (int): node number of the property
| property_name (string): the name of the property to fetch
|
| Returns:
| The the phandle index and number of fields, if the node can't
| be found 0, 0 are returned.
|
| property_remove(fdt, node_name, prop_name, verbose=0)
| removes a property from a fdt
|
| Removes a property (if it exists) from a node (and optionally its children).
|
| Args:
| fdt (FDT): flattened device tree to modify
| node_name (int or string): the node number or name to process
| prop_name (string): name of property to remove
|
| Returns:
| Boolean: True if the property was deleted, False if it wasn't
|
| property_resolve_phandles(fdt, nodeoffset, property_name)
| Resolve the targets of any phandles in a property
|
| Args:
| fdt (FDT): flattened device tree
| nodeoffset (int): node number of the property
| property_name (string): the name of the property to resolve
|
| Returns:
| A list of all resolved phandle nodes, [] if no phandles are present
|
| property_set(fdt, node_number, prop_name, prop_val, ftype=<LopperFmt.SIMPLE: 1>, verbose=False)
| utility command to set a property in a node
|
| A more robust way to set the value of a property in a node, This routine
| takes hints when getting the property in the form of a "format type"
|
| The format options are in the following enum type:
|
| class LopperFmt(Enum):
| SIMPLE = 1 (format)
| COMPOUND = 2 (format)
|
| Based on the format hint, and the passed value, the property is encoded
| into a byte array and stored into the flattened device tree node.
|
| Args:
| fdt_dst (FDT): flattened device tree
| node_number (int): node number in the fdt
| prop_name (string): property name whose value to set
| ftype (LopperFmt,optional): format of the property. Default SIMPLE.
|
| Returns:
| Nothing
|
| property_type_guess(prop)
| utility routine to guess the type of a property
|
| Often the type of a property is not know, in particular if there isn't
| access to markers via libfdt.
|
| This routine looks at the data of a libFDT property and returns the best
| guess for the type. The logic behind the guesses is documented in the code
| itself
|
| Args:
| prop (libfdt property): the property to process
|
| Returns:
| LopperFmt description of the property. Default is UINT8 (binary)
| LopperFmt.STRING: string
| LopperFmt.UINT32 1: uint32
| LopperFmt.UINT64 2: uint64
| LopperFmt.UINT8 3: uint8 (binary)
| LopperFmt.EMPTY 4: empty (just a name)
|
| property_value_decode(prop, poffset, ftype=<LopperFmt.SIMPLE: 1>, encode=<LopperFmt.UNKNOWN: 11>, verbose=0)
| Decodes a property
|
| Decode a property into a common data type (string, integer, list of
| strings, etc).
|
| This is a robust wrapper around the decode facilities provided via
| libfdt. This routine tries multiple encode formats and uses
| heuristics to determine the best format for the decoded property.
|
| The format type (ftype) and encod arguments can be used to help
| decode properly when the type of a property is known.
|
| The format and encoding options are in the following enum type:
|
| class LopperFmt(Enum):
| SIMPLE = 1 (format)
| COMPOUND = 2 (format)
| HEX = 3 (encoding)
| DEC = 4 (encoding)
| STRING = 5 (encoding)
| MULTI_STRING = 5 (encoding)
|
| Args:
| prop (libfdt property): property to decode
| poffset (int): offset of the property in the node (unused)
| ftype (LopperFmt,optional): format hint for the property. default is SIMPLE
| encode (LopperFmt,optional): encoding hint. default is DEC
| verbose (int,optional): verbosity level, default is 0
|
| Returns:
| (string): if SIMPLE. The property as a string
| (list): if COMPOUND. The property as a list of strings / values
|
| string_test(prop, allow_multiline=True)
| Check if a property (byte array) is a string
|
| Args:
| prop: (libfdt property)
|
| Returns:
| boolean: True if the property looks like a string
|
| write_fdt(fdt_to_write, output_filename, overwrite=True, verbose=0, enhanced=False)
| Write a system device tree to a file
|
| Write a fdt (or system device tree) to an output file. This routine uses
| the output filename to determine if a module should be used to write the
| output.
|
| If the output format is .dts or .dtb, Lopper takes care of writing the
| output. If it is an unrecognized output type, the available assist
| modules are queried for compatibility. If there is a compatible assist,
| it is called to write the file, otherwise, a warning or error is raised.
|
| Args:
| fdt_to_write (fdt): source flattened device tree to write
| output_filename (string): name of the output file to create
| overwrite (bool,optional): Should existing files be overwritten. Default is True.
| verbose (int,optional): verbosity level to use.
| enhanced(bool,optional): whether enhanced printing should be performed. Default is False
|