fdt.hh (242b24828472137ec4411826b86e753d49bd2c39) | fdt.hh (21d5d37ba4c0131d6c141695366e266e32cc3bc1) |
---|---|
1/*- 2 * Copyright (c) 2013 David Chisnall 3 * All rights reserved. 4 * 5 * This software was developed by SRI International and the University of 6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 7 * ("CTSRD"), as part of the DARPA CRASH research programme. 8 * --- 197 unchanged lines hidden (view full) --- 206 * - Otherwise, it is printed as a byte buffer. 207 */ 208 void write_dts(FILE *file); 209 /** 210 * Tries to merge adjacent property values, returns true if it succeeds and 211 * false otherwise. 212 */ 213 bool try_to_merge(property_value &other); | 1/*- 2 * Copyright (c) 2013 David Chisnall 3 * All rights reserved. 4 * 5 * This software was developed by SRI International and the University of 6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 7 * ("CTSRD"), as part of the DARPA CRASH research programme. 8 * --- 197 unchanged lines hidden (view full) --- 206 * - Otherwise, it is printed as a byte buffer. 207 */ 208 void write_dts(FILE *file); 209 /** 210 * Tries to merge adjacent property values, returns true if it succeeds and 211 * false otherwise. 212 */ 213 bool try_to_merge(property_value &other); |
214 /** 215 * Returns the size (in bytes) of this property value. 216 */ 217 size_t size(); |
|
214 private: 215 /** 216 * Returns whether the value is of the specified type. If the type of 217 * the value has not yet been determined, then this calculates it. 218 */ 219 inline bool is_type(value_type v) 220 { 221 if (type == UNKNOWN) --- 153 unchanged lines hidden (view full) --- 375 void write(dtb::output_writer &writer, dtb::string_table &strings); 376 /** 377 * Writes in DTS format to the specified file, at the given indent 378 * level. This will begin the line with the number of tabs specified 379 * as the indent level and then write the property in the most 380 * applicable way that it can determine. 381 */ 382 void write_dts(FILE *file, int indent); | 218 private: 219 /** 220 * Returns whether the value is of the specified type. If the type of 221 * the value has not yet been determined, then this calculates it. 222 */ 223 inline bool is_type(value_type v) 224 { 225 if (type == UNKNOWN) --- 153 unchanged lines hidden (view full) --- 379 void write(dtb::output_writer &writer, dtb::string_table &strings); 380 /** 381 * Writes in DTS format to the specified file, at the given indent 382 * level. This will begin the line with the number of tabs specified 383 * as the indent level and then write the property in the most 384 * applicable way that it can determine. 385 */ 386 void write_dts(FILE *file, int indent); |
387 /** 388 * Returns the byte offset of the specified property value. 389 */ 390 size_t offset_of_value(property_value &val); |
|
383}; 384 385/** 386 * Class encapsulating a device tree node. Nodes may contain properties and 387 * other nodes. 388 */ 389class node 390{ --- 83 unchanged lines hidden (view full) --- 474 * already been parsed. 475 */ 476 node(text_input_buffer &input, 477 std::string &&n, 478 std::unordered_set<std::string> &&l, 479 std::string &&a, 480 define_map*); 481 /** | 391}; 392 393/** 394 * Class encapsulating a device tree node. Nodes may contain properties and 395 * other nodes. 396 */ 397class node 398{ --- 83 unchanged lines hidden (view full) --- 482 * already been parsed. 483 */ 484 node(text_input_buffer &input, 485 std::string &&n, 486 std::unordered_set<std::string> &&l, 487 std::string &&a, 488 define_map*); 489 /** |
490 * Creates a special node with the specified name and properties. 491 */ 492 node(const std::string &n, const std::vector<property_ptr> &p); 493 /** |
|
482 * Comparison function for properties, used when sorting the properties 483 * vector. Orders the properties based on their names. 484 */ 485 static inline bool cmp_properties(property_ptr &p1, property_ptr &p2); 486 /* 487 { 488 return p1->get_key() < p2->get_key(); 489 } --- 84 unchanged lines hidden (view full) --- 574 * Factory method for constructing a new node. Attempts to parse a 575 * node in DTB format from the input, and returns it on success. On 576 * any parse error, this will return 0. This should be called with the 577 * cursor on the open brace of the property, after the name and so on 578 * have been parsed. 579 */ 580 static node_ptr parse_dtb(input_buffer &structs, input_buffer &strings); 581 /** | 494 * Comparison function for properties, used when sorting the properties 495 * vector. Orders the properties based on their names. 496 */ 497 static inline bool cmp_properties(property_ptr &p1, property_ptr &p2); 498 /* 499 { 500 return p1->get_key() < p2->get_key(); 501 } --- 84 unchanged lines hidden (view full) --- 586 * Factory method for constructing a new node. Attempts to parse a 587 * node in DTB format from the input, and returns it on success. On 588 * any parse error, this will return 0. This should be called with the 589 * cursor on the open brace of the property, after the name and so on 590 * have been parsed. 591 */ 592 static node_ptr parse_dtb(input_buffer &structs, input_buffer &strings); 593 /** |
594 * Construct a new special node from a name and set of properties. 595 */ 596 static node_ptr create_special_node(const std::string &name, 597 const std::vector<property_ptr> &props); 598 /** |
|
582 * Returns a property corresponding to the specified key, or 0 if this 583 * node does not contain a property of that name. 584 */ 585 property_ptr get_property(const std::string &key); 586 /** 587 * Adds a new property to this node. 588 */ 589 inline void add_property(property_ptr &p) 590 { 591 props.push_back(p); 592 } 593 /** | 599 * Returns a property corresponding to the specified key, or 0 if this 600 * node does not contain a property of that name. 601 */ 602 property_ptr get_property(const std::string &key); 603 /** 604 * Adds a new property to this node. 605 */ 606 inline void add_property(property_ptr &p) 607 { 608 props.push_back(p); 609 } 610 /** |
611 * Adds a new child to this node. 612 */ 613 inline void add_child(node_ptr &&n) 614 { 615 children.push_back(std::move(n)); 616 } 617 /** |
|
594 * Merges a node into this one. Any properties present in both are 595 * overridden, any properties present in only one are preserved. 596 */ 597 void merge_node(node_ptr other); 598 /** 599 * Write this node to the specified output. Although nodes do not 600 * refer to a string table directly, their properties do. The string 601 * table passed as the second argument is used for the names of --- 19 unchanged lines hidden (view full) --- 621 */ 622class device_tree 623{ 624 public: 625 /** 626 * Type used for node paths. A node path is sequence of names and unit 627 * addresses. 628 */ | 618 * Merges a node into this one. Any properties present in both are 619 * overridden, any properties present in only one are preserved. 620 */ 621 void merge_node(node_ptr other); 622 /** 623 * Write this node to the specified output. Although nodes do not 624 * refer to a string table directly, their properties do. The string 625 * table passed as the second argument is used for the names of --- 19 unchanged lines hidden (view full) --- 645 */ 646class device_tree 647{ 648 public: 649 /** 650 * Type used for node paths. A node path is sequence of names and unit 651 * addresses. 652 */ |
629 typedef std::vector<std::pair<std::string,std::string> > node_path; | 653 class node_path : public std::vector<std::pair<std::string,std::string>> 654 { 655 public: 656 /** 657 * Converts this to a string representation. 658 */ 659 std::string to_string() const; 660 }; |
630 /** 631 * Name that we should use for phandle nodes. 632 */ 633 enum phandle_format 634 { 635 /** linux,phandle */ 636 LINUX, 637 /** phandle */ --- 38 unchanged lines hidden (view full) --- 676 */ 677 std::unordered_map<std::string, node_path> node_paths; 678 /** 679 * A collection of property values that are references to other nodes. 680 * These should be expanded to the full path of their targets. 681 */ 682 std::vector<property_value*> cross_references; 683 /** | 661 /** 662 * Name that we should use for phandle nodes. 663 */ 664 enum phandle_format 665 { 666 /** linux,phandle */ 667 LINUX, 668 /** phandle */ --- 38 unchanged lines hidden (view full) --- 707 */ 708 std::unordered_map<std::string, node_path> node_paths; 709 /** 710 * A collection of property values that are references to other nodes. 711 * These should be expanded to the full path of their targets. 712 */ 713 std::vector<property_value*> cross_references; 714 /** |
715 * The location of something requiring a fixup entry. 716 */ 717 struct fixup 718 { 719 /** 720 * The path to the node. 721 */ 722 node_path path; 723 /** 724 * The property containing the reference. 725 */ 726 property_ptr prop; 727 /** 728 * The property value that contains the reference. 729 */ 730 property_value &val; 731 }; 732 /** |
|
684 * A collection of property values that refer to phandles. These will 685 * be replaced by the value of the phandle property in their 686 * destination. 687 */ | 733 * A collection of property values that refer to phandles. These will 734 * be replaced by the value of the phandle property in their 735 * destination. 736 */ |
688 std::vector<property_value*> phandles; | 737 std::vector<fixup> fixups; |
689 /** | 738 /** |
739 * The locations of all of the values that are supposed to become phandle 740 * references, but refer to things outside of this file. 741 */ 742 std::vector<std::reference_wrapper<fixup>> unresolved_fixups; 743 /** |
|
690 * The names of nodes that target phandles. 691 */ 692 std::unordered_set<std::string> phandle_targets; 693 /** 694 * A collection of input buffers that we are using. These input 695 * buffers are the ones that own their memory, and so we must preserve 696 * them for the lifetime of the device tree. 697 */ --- 30 unchanged lines hidden (view full) --- 728 * The minimum size in bytes of the blob. 729 */ 730 uint32_t minimum_blob_size; 731 /** 732 * The number of bytes of padding to add to the end of the blob. 733 */ 734 uint32_t blob_padding; 735 /** | 744 * The names of nodes that target phandles. 745 */ 746 std::unordered_set<std::string> phandle_targets; 747 /** 748 * A collection of input buffers that we are using. These input 749 * buffers are the ones that own their memory, and so we must preserve 750 * them for the lifetime of the device tree. 751 */ --- 30 unchanged lines hidden (view full) --- 782 * The minimum size in bytes of the blob. 783 */ 784 uint32_t minimum_blob_size; 785 /** 786 * The number of bytes of padding to add to the end of the blob. 787 */ 788 uint32_t blob_padding; 789 /** |
790 * Is this tree a plugin? 791 */ 792 bool is_plugin; 793 /** |
|
736 * Visit all of the nodes recursively, and if they have labels then add 737 * them to the node_paths and node_names vectors so that they can be 738 * used in resolving cross references. Also collects phandle 739 * properties that have been explicitly added. 740 */ 741 void collect_names_recursive(node_ptr &n, node_path &path); 742 /** 743 * Assign phandle properties to all nodes that have been referenced and --- 23 unchanged lines hidden (view full) --- 767 /** 768 * Template function that writes a dtb blob using the specified writer. 769 * The writer defines the output format (assembly, blob). 770 */ 771 template<class writer> 772 void write(int fd); 773 public: 774 /** | 794 * Visit all of the nodes recursively, and if they have labels then add 795 * them to the node_paths and node_names vectors so that they can be 796 * used in resolving cross references. Also collects phandle 797 * properties that have been explicitly added. 798 */ 799 void collect_names_recursive(node_ptr &n, node_path &path); 800 /** 801 * Assign phandle properties to all nodes that have been referenced and --- 23 unchanged lines hidden (view full) --- 825 /** 826 * Template function that writes a dtb blob using the specified writer. 827 * The writer defines the output format (assembly, blob). 828 */ 829 template<class writer> 830 void write(int fd); 831 public: 832 /** |
833 * Should we write the __symbols__ node (to allow overlays to be linked 834 * against this blob)? 835 */ 836 bool write_symbols = false; 837 /** |
|
775 * Returns the node referenced by the property. If this is a tree that 776 * is in source form, then we have a string that we can use to index 777 * the cross_references array and so we can just look that up. 778 */ 779 node *referenced_node(property_value &v); 780 /** 781 * Writes this FDT as a DTB to the specified output. 782 */ --- 106 unchanged lines hidden --- | 838 * Returns the node referenced by the property. If this is a tree that 839 * is in source form, then we have a string that we can use to index 840 * the cross_references array and so we can just look that up. 841 */ 842 node *referenced_node(property_value &v); 843 /** 844 * Writes this FDT as a DTB to the specified output. 845 */ --- 106 unchanged lines hidden --- |