├── .gitignore ├── .travis.yml ├── Android.bp ├── Android.mk ├── Documentation ├── dt-object-internal.txt ├── dtc-paper.bib ├── dtc-paper.tex ├── dts-format.txt └── manual.txt ├── GPL ├── MODULE_LICENSE_GPL ├── Makefile ├── Makefile.convert-dtsv0 ├── Makefile.dtc ├── Makefile.utils ├── NOTICE ├── OWNERS ├── README ├── README.license ├── README.version ├── TODO ├── checks.c ├── convert-dtsv0-lexer.l ├── data.c ├── dtc-lexer.l ├── dtc-parser.y ├── dtc.c ├── dtc.h ├── dtdiff ├── fdtdump.c ├── fdtget.c ├── fdtoverlay.c ├── fdtput.c ├── flattree.c ├── fstree.c ├── libfdt ├── Android.bp ├── Makefile.libfdt ├── TODO ├── acpi.c ├── fdt.c ├── fdt.h ├── fdt_addresses.c ├── fdt_empty_tree.c ├── fdt_overlay.c ├── fdt_ro.c ├── fdt_rw.c ├── fdt_strerror.c ├── fdt_sw.c ├── fdt_wip.c ├── libacpi.h ├── libfdt.h ├── libfdt_env.h ├── libfdt_internal.h └── version.lds ├── livetree.c ├── pylibfdt ├── .gitignore ├── Makefile.pylibfdt ├── libfdt.i └── setup.py ├── scripts ├── kup-dtc └── setlocalversion ├── srcpos.c ├── srcpos.h ├── tests ├── .gitignore ├── Makefile.tests ├── add_subnode_with_nops.c ├── addr_size_cells.c ├── addresses.dts ├── aliases.dts ├── appendprop.dts ├── appendprop1.c ├── appendprop2.c ├── asm_tree_dump.c ├── bad-empty-ranges.dts ├── bad-name-property.dts ├── bad-ncells.dts ├── bad-octal-literal.dts ├── bad-reg-ranges.dts ├── bad-size-cells.dts ├── bad-string-props.dts ├── base01.asm ├── base01.cmd ├── base01.dts ├── base01.stderr ├── boot-cpuid.c ├── boot-cpuid.dts ├── char_literal.c ├── char_literal.dts ├── check_path.c ├── comments-cmp.dts ├── comments.dts ├── data.S ├── default-addr-size.dts ├── del_node.c ├── del_property.c ├── delete_reinstate_multilabel.dts ├── delete_reinstate_multilabel_ref.dts ├── dependencies.cmp ├── dependencies.dts ├── deps_inc1.dtsi ├── deps_inc2.dtsi ├── division-by-zero.dts ├── dtb_reverse.c ├── dtbs_equal_ordered.c ├── dtbs_equal_unordered.c ├── dtc-checkfails.sh ├── dtc-fails.sh ├── dtc-fatal.sh ├── dumptrees.c ├── dup-nodename.dts ├── dup-phandle.dts ├── dup-propname.dts ├── embedded_nul.dts ├── embedded_nul_equiv.dts ├── empty.dts ├── escapes.dts ├── extra-terminating-null.c ├── extra-terminating-null.dts ├── fdtdump-runtest.sh ├── fdtdump.dts ├── fdtget-runtest.sh ├── fdtoverlay-runtest.sh ├── fdtput-runtest.sh ├── find_property.c ├── get_alias.c ├── get_mem_rsv.c ├── get_name.c ├── get_path.c ├── get_phandle.c ├── getprop.c ├── incbin.bin ├── incbin.c ├── incbin.dts ├── include0.dts ├── include1.dts ├── include2.dts ├── include3.dts ├── include4.dts ├── include5.dts ├── include5a.dts ├── include6.dts ├── include7.dts ├── include8.dts ├── integer-expressions.c ├── label01.dts ├── label_repeated.dts ├── line_directives.dts ├── lorem.txt ├── mangle-layout.c ├── mangle-layout.supp ├── minusone-phandle.dts ├── move_and_save.c ├── multilabel.dts ├── multilabel_merge.dts ├── node_check_compatible.c ├── node_offset_by_compatible.c ├── node_offset_by_phandle.c ├── node_offset_by_prop_value.c ├── nonexist-label-ref.dts ├── nonexist-node-ref.dts ├── nonexist-node-ref2.dts ├── nop_node.c ├── nop_property.c ├── nopulate.c ├── notfound.c ├── nul-in-escape.dts ├── nul-in-line-info1.dts ├── nul-in-line-info2.dts ├── obsolete-chosen-interrupt-controller.dts ├── open_pack.c ├── open_pack.supp ├── overlay.c ├── overlay_bad_fixup.c ├── overlay_bad_fixup_bad_index.dts ├── overlay_bad_fixup_base.dtsi ├── overlay_bad_fixup_empty.dts ├── overlay_bad_fixup_empty_index.dts ├── overlay_bad_fixup_index_trailing.dts ├── overlay_bad_fixup_path_empty_prop.dts ├── overlay_bad_fixup_path_only.dts ├── overlay_bad_fixup_path_only_sep.dts ├── overlay_bad_fixup_path_prop.dts ├── overlay_base.dts ├── overlay_base_manual_symbols.dts ├── overlay_overlay.dts ├── overlay_overlay_manual_fixups.dts ├── overlay_overlay_no_fixups.dts ├── overlay_overlay_simple.dts ├── parent_offset.c ├── path-references.c ├── path-references.dts ├── path_offset.c ├── path_offset_aliases.c ├── phandle_format.c ├── prop-after-subnode.dts ├── property_iterate.c ├── property_iterate.dts ├── propname_escapes.c ├── propname_escapes.dts ├── pylibfdt_tests.py ├── references.c ├── references.dts ├── reg-ranges-root.dts ├── reg-without-unit-addr.dts ├── reuse-label.dts ├── reuse-label1.dts ├── reuse-label2.dts ├── reuse-label3.dts ├── reuse-label4.dts ├── reuse-label5.dts ├── reuse-label6.dts ├── root_node.c ├── run_tests.sh ├── rw_tree1.c ├── search_dir │ ├── search_test.dtsi │ └── search_test2.dtsi ├── search_dir_b │ ├── search_paths_subdir.dts │ ├── search_test_b.dtsi │ ├── search_test_b2.dtsi │ └── search_test_c.dtsi ├── search_paths.dts ├── search_paths_b.dts ├── set_name.c ├── setprop.c ├── setprop_inplace.c ├── sized_cells.c ├── sized_cells.dts ├── sourceoutput.dts ├── string_escapes.c ├── stringlist.c ├── stringlist.dts ├── subnode_iterate.c ├── subnode_iterate.dts ├── subnode_offset.c ├── supernode_atdepth_offset.c ├── sw_tree1.c ├── sw_tree1.supp ├── test01.asm ├── test01.dts ├── test01.stderr ├── test_kernel_dts ├── test_label_ref.dts ├── test_tree1.dts ├── test_tree1_delete.dts ├── test_tree1_label_noderef.dts ├── test_tree1_merge.dts ├── test_tree1_merge_labelled.dts ├── test_tree1_merge_path.dts ├── test_tree1_wrong1.dts ├── test_tree1_wrong2.dts ├── test_tree1_wrong3.dts ├── test_tree1_wrong4.dts ├── test_tree1_wrong5.dts ├── test_tree1_wrong6.dts ├── test_tree1_wrong7.dts ├── test_tree1_wrong8.dts ├── test_tree1_wrong9.dts ├── testdata.h ├── tests.h ├── tests.sh ├── testutils.c ├── trees.S ├── truncated_property.c ├── unit-addr-leading-0s.dts ├── unit-addr-leading-0x.dts ├── unit-addr-without-reg.dts ├── utilfdt_test.c ├── value-labels.c ├── value-labels.dts └── zero-phandle.dts ├── treesource.c ├── util.c ├── util.h └── version_non_gen.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.d 3 | *.a 4 | *.patch 5 | *.so 6 | *~ 7 | *.tab.[ch] 8 | lex.yy.c 9 | *.lex.c 10 | /dtc 11 | /fdtdump 12 | /convert-dtsv0 13 | /version_gen.h 14 | /fdtget 15 | /fdtput 16 | /patches 17 | /.pc 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | # Coverity Scan uploads 4 | env: 5 | global: 6 | # COVERITY_SCAN_TOKEN (dgibson/dtc) 7 | - secure: "vlHvXe618//IM9LQaKzqsrUbjs7ng0L9UCST4kJbJnFQDXvVe5JiSmJGd4ef7mm0NUv5bMRl2W3xCiu6BYAu/NvU3tMNHoLG+JgCJs0+wLJXbWOwji/NmH7olqgJG+CmpaCMXjARF6+nrTnBYHJL6cYyf4KVoV4B0I/hLUW91+s=" 8 | 9 | matrix: 10 | include: 11 | - addons: 12 | apt: 13 | packages: 14 | - swig 15 | - python-dev 16 | coverity_scan: 17 | project: 18 | name: dtc 19 | description: Device Tree Compiler 20 | notification_email: david@gibson.dropbear.id.au 21 | build_command: make 22 | branch_pattern: coverity_scan 23 | 24 | - addons: 25 | apt: 26 | packages: 27 | 28 | script: 29 | - make 30 | - make check 31 | -------------------------------------------------------------------------------- /Android.bp: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Android Open Source Project 2 | cc_defaults { 3 | name: "dt_defaults", 4 | cflags: [ 5 | "-Wall", 6 | "-Werror", 7 | "-Wno-sign-compare", 8 | "-Wno-missing-field-initializers", 9 | "-Wno-unused-parameter", 10 | ], 11 | 12 | static_libs: ["libfdt"], 13 | 14 | stl: "none", 15 | dist: { 16 | targets: [ 17 | "dist_files", 18 | ], 19 | dir: "dtc", 20 | }, 21 | } 22 | 23 | cc_binary_host { 24 | name: "dtc", 25 | defaults: ["dt_defaults"], 26 | srcs: [ 27 | "checks.c", 28 | "data.c", 29 | "dtc.c", 30 | "dtc-lexer.l", 31 | "dtc-parser.y", 32 | "flattree.c", 33 | "fstree.c", 34 | "livetree.c", 35 | "srcpos.c", 36 | "treesource.c", 37 | "util.c", 38 | ], 39 | } 40 | 41 | cc_binary_host { 42 | name: "fdtget", 43 | defaults: ["dt_defaults"], 44 | srcs: [ 45 | "fdtget.c", 46 | "util.c", 47 | ], 48 | } 49 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2023 LibXZR . All Rights Reserved. 2 | # Usage: ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk 3 | 4 | LOCAL_PATH := $(call my-dir) 5 | 6 | include $(CLEAR_VARS) 7 | include $(LOCAL_PATH)/libfdt/Makefile.libfdt 8 | LOCAL_MODULE := libfdt 9 | LOCAL_SRC_FILES := $(patsubst %,$(LOCAL_PATH)/libfdt/%,$(LIBFDT_SRCS)) 10 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/libfdt 11 | include $(BUILD_STATIC_LIBRARY) 12 | 13 | include $(CLEAR_VARS) 14 | include $(LOCAL_PATH)/Makefile.dtc 15 | LOCAL_MODULE := dtc 16 | LOCAL_SRC_FILES := $(DTC_SRCS) $(DTC_GEN_SRCS) 17 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/libfdt 18 | LOCAL_STATIC_LIBRARIES := libfdt 19 | LOCAL_LDFLAGS := -static 20 | include $(BUILD_EXECUTABLE) 21 | 22 | dtc-lexer.lex.c: dtc-lexer.l dtc-parser.tab.h 23 | flex -o$@ $< 24 | 25 | %.tab.c %.tab.h %.output: %.y 26 | bison -d $< 27 | -------------------------------------------------------------------------------- /Documentation/dtc-paper.bib: -------------------------------------------------------------------------------- 1 | @STRING{pub-IEEE = "IEEE Computer Society"} 2 | @STRING{pub-IEEE:adr = "345 E. 47th St, New York, NY 10017, USA"} 3 | 4 | @BOOK{IEEE1275, 5 | key = "IEEE1275", 6 | title = "{IEEE} {S}tandard for {B}oot ({I}nitialization {C}onfiguration) {F}irmware: {C}ore {R}equirements and {P}ractices", 7 | publisher = pub-IEEE, 8 | address = pub-IEEE:adr, 9 | series = "IEEE Std 1275-1994", 10 | year = 1994, 11 | } 12 | 13 | @BOOK{IEEE1275-pci, 14 | key = "IEEE1275-pci", 15 | title = "{PCI} {B}us {B}inding to: {IEEE} {S}td 1275-1994 {S}tandard for {B}oot ({I}nitialization {C}onfiguration) {F}irmware", 16 | publisher = pub-IEEE, 17 | address = pub-IEEE:adr, 18 | note = "Revision 2.1", 19 | year = 1998, 20 | } 21 | 22 | @MISC{noof1, 23 | author = "Benjamin Herrenschmidt", 24 | title = "Booting the {L}inux/ppc kernel without {O}pen {F}irmware", 25 | month = may, 26 | year = 2005, 27 | note = "v0.1, \url{http://ozlabs.org/pipermail/linuxppc64-dev/2005-May/004073.html}", 28 | } 29 | 30 | @MISC{noof5, 31 | author = "Benjamin Herrenschmidt", 32 | title = "Booting the {L}inux/ppc kernel without {O}pen {F}irmware", 33 | month = nov, 34 | year = 2005, 35 | note = "v0.5, \url{http://ozlabs.org/pipermail/linuxppc64-dev/2005-December/006994.html}", 36 | } 37 | 38 | @MISC{dtcgit, 39 | author = "David Gibson et al.", 40 | title = "\dtc{}", 41 | howpublished = "git tree", 42 | note = "\url{http://ozlabs.org/~dgibson/dtc/dtc.git}", 43 | } 44 | -------------------------------------------------------------------------------- /MODULE_LICENSE_GPL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libxzr/dtc-aosp/90d19beedfcc09cc76a6145015110de0eafad10e/MODULE_LICENSE_GPL -------------------------------------------------------------------------------- /Makefile.convert-dtsv0: -------------------------------------------------------------------------------- 1 | # 2 | # This is not a complete Makefile of itself. 3 | # Instead, it is designed to be easily embeddable 4 | # into other systems of Makefiles. 5 | # 6 | 7 | CONVERT_SRCS = \ 8 | srcpos.c \ 9 | util.c 10 | 11 | CONVERT_GEN_SRCS = convert-dtsv0-lexer.lex.c 12 | 13 | CONVERT_OBJS = $(CONVERT_SRCS:%.c=%.o) $(CONVERT_GEN_SRCS:%.c=%.o) 14 | -------------------------------------------------------------------------------- /Makefile.dtc: -------------------------------------------------------------------------------- 1 | # Makefile.dtc 2 | # 3 | # This is not a complete Makefile of itself. Instead, it is designed to 4 | # be easily embeddable into other systems of Makefiles. 5 | # 6 | DTC_SRCS = \ 7 | checks.c \ 8 | data.c \ 9 | dtc.c \ 10 | flattree.c \ 11 | fstree.c \ 12 | livetree.c \ 13 | srcpos.c \ 14 | treesource.c \ 15 | util.c 16 | 17 | DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c 18 | DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o) 19 | -------------------------------------------------------------------------------- /Makefile.utils: -------------------------------------------------------------------------------- 1 | # 2 | # This is not a complete Makefile of itself. Instead, it is designed to 3 | # be easily embeddable into other systems of Makefiles. 4 | # 5 | 6 | FDTDUMP_SRCS = \ 7 | fdtdump.c \ 8 | util.c 9 | 10 | FDTDUMP_OBJS = $(FDTDUMP_SRCS:%.c=%.o) 11 | 12 | 13 | FDTGET_SRCS = \ 14 | fdtget.c \ 15 | util.c 16 | 17 | FDTGET_OBJS = $(FDTGET_SRCS:%.c=%.o) 18 | 19 | 20 | FDTPUT_SRCS = \ 21 | fdtput.c \ 22 | util.c 23 | 24 | FDTPUT_OBJS = $(FDTPUT_SRCS:%.c=%.o) 25 | 26 | FDTOVERLAY_SRCS = \ 27 | fdtoverlay.c \ 28 | util.c 29 | 30 | FDTOVERLAY_OBJS = $(FDTOVERLAY_SRCS:%.c=%.o) 31 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | # Default code reviewers picked from top 3 or more developers. 2 | # Please update this list if you find better candidates. 3 | szuweilin@google.com 4 | bowgotsai@google.com 5 | hridya@google.com 6 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | The source tree contains the Device Tree Compiler (dtc) toolchain for 2 | working with device tree source and binary files and also libfdt, a 3 | utility library for reading and manipulating the binary format. 4 | 5 | DTC and LIBFDT are maintained by: 6 | 7 | David Gibson 8 | Jon Loeliger 9 | 10 | 11 | Python library 12 | -------------- 13 | 14 | A Python library is also available. To build this you will need to install 15 | swig and Python development files. On Debian distributions: 16 | 17 | sudo apt-get install swig python-dev 18 | 19 | The library provides an Fdt class which you can use like this: 20 | 21 | $ PYTHONPATH=../pylibfdt python 22 | >>> import libfdt 23 | >>> fdt = libfdt.Fdt(open('test_tree1.dtb').read()) 24 | >>> node = fdt.path_offset('/subnode@1') 25 | >>> print node 26 | 124 27 | >>> prop_offset = fdt.first_property_offset(node) 28 | >>> prop = fdt.get_property_by_offset(prop_offset) 29 | >>> print '%s=%r' % (prop.name, prop.value) 30 | compatible=bytearray(b'subnode1\x00') 31 | >>> print '%s=%s' % (prop.name, prop.value) 32 | compatible=subnode1 33 | >>> node2 = fdt.path_offset('/') 34 | >>> print fdt.getprop(node2, 'compatible') 35 | test_tree1 36 | 37 | You will find tests in tests/pylibfdt_tests.py showing how to use each 38 | method. Help is available using the Python help command, e.g.: 39 | 40 | $ cd pylibfdt 41 | $ python -c "import libfdt; help(libfdt)" 42 | 43 | If you add new features, please check code coverage: 44 | 45 | $ sudo apt-get install python-pip python-pytest 46 | $ sudo pip install coverage 47 | $ cd tests 48 | $ coverage run pylibfdt_tests.py 49 | $ coverage html 50 | # Open 'htmlcov/index.html' in your browser 51 | 52 | 53 | To install the library via the normal setup.py method, use: 54 | 55 | ./pylibfdt/setup.py [--prefix=/path/to/install_dir] 56 | 57 | If --prefix is not provided, the default prefix is used, typically '/usr' 58 | or '/usr/local'. See Python's distutils documentation for details. You can 59 | also install via the Makefile if you like, but the above is more common. 60 | 61 | To install both libfdt and pylibfdt you can use: 62 | 63 | make install [SETUP_PREFIX=/path/to/install_dir] \ 64 | [PREFIX=/path/to/install_dir] 65 | 66 | To disable building the python library, even if swig and Python are available, 67 | use: 68 | 69 | make NO_PYTHON=1 70 | 71 | 72 | More work remains to support all of libfdt, including access to numeric 73 | values. 74 | 75 | 76 | Mailing list 77 | ------------ 78 | The following list is for discussion about dtc and libfdt implementation 79 | mailto:devicetree-compiler@vger.kernel.org 80 | 81 | Core device tree bindings are discussed on the devicetree-spec list: 82 | mailto:devicetree-spec@vger.kernel.org 83 | -------------------------------------------------------------------------------- /README.license: -------------------------------------------------------------------------------- 1 | Licensing and contribution policy of dtc and libfdt 2 | =================================================== 3 | 4 | This dtc package contains two pieces of software: dtc itself, and 5 | libfdt which comprises the files in the libfdt/ subdirectory. These 6 | two pieces of software, although closely related, are quite distinct. 7 | dtc does not incoporate or rely on libfdt for its operation, nor vice 8 | versa. It is important that these two pieces of software have 9 | different license conditions. 10 | 11 | As the copyright banners in each source file attest, dtc is licensed 12 | under the GNU GPL. The full text of the GPL can be found in the file 13 | entitled 'GPL' which should be included in this package. dtc code, 14 | therefore, may not be incorporated into works which do not have a GPL 15 | compatible license. 16 | 17 | libfdt, however, is GPL/BSD dual-licensed. That is, it may be used 18 | either under the terms of the GPL, or under the terms of the 2-clause 19 | BSD license (aka the ISC license). The full terms of that license are 20 | given in the copyright banners of each of the libfdt source files. 21 | This is, in practice, equivalent to being BSD licensed, since the 22 | terms of the BSD license are strictly more permissive than the GPL. 23 | 24 | I made the decision to license libfdt in this way because I want to 25 | encourage widespread and correct usage of flattened device trees, 26 | including by proprietary or otherwise GPL-incompatible firmware or 27 | tools. Allowing libfdt to be used under the terms of the BSD license 28 | makes that it easier for vendors or authors of such software to do so. 29 | 30 | This does mean that libfdt code could be "stolen" - say, included in a 31 | proprietary fimware and extended without contributing those extensions 32 | back to the libfdt mainline. While I hope that doesn't happen, I 33 | believe the goal of allowing libfdt to be widely used is more 34 | important than avoiding that. libfdt is quite small, and hardly 35 | rocket science; so the incentive for such impolite behaviour is small, 36 | and the inconvenience caused therby is not dire. 37 | 38 | Licenses such as the LGPL which would allow code to be used in non-GPL 39 | software, but also require contributions to be returned were 40 | considered. However, libfdt is designed to be used in firmwares and 41 | other environments with unusual technical constraints. It's difficult 42 | to anticipate all possible changes which might be needed to meld 43 | libfdt into such environments and so difficult to suitably word a 44 | license that puts the boundary between what is and isn't permitted in 45 | the intended place. Again, I judged encouraging widespread use of 46 | libfdt by keeping the license terms simple and familiar to be the more 47 | important goal. 48 | 49 | **IMPORTANT** It's intended that all of libfdt as released remain 50 | permissively licensed this way. Therefore only contributions which 51 | are released under these terms can be merged into the libfdt mainline. 52 | 53 | 54 | David Gibson 55 | (principal original author of dtc and libfdt) 56 | 2 November 2007 57 | -------------------------------------------------------------------------------- /README.version: -------------------------------------------------------------------------------- 1 | URL: https://git.kernel.org/cgit/utils/dtc/dtc.git/commit/?id=120775eb1cf39f8dcecd695c3ff1cfef8aeb669d 2 | Version: 1.4.2 plus bugfixes 3 | Owners: cphoenix 4 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - Bugfixes: 2 | * Proper handling of boot cpu information 3 | - Generate mem reserve map 4 | * linux,reserve-map property 5 | * generating reserve entry for device tree itself 6 | * generating reserve entries from tce, rtas etc. properties 7 | - Expression support 8 | - Macro system 9 | -------------------------------------------------------------------------------- /dtdiff: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # This script uses the bash <(...) extension. 4 | # If you want to change this to work with a generic /bin/sh, make sure 5 | # you fix that. 6 | 7 | 8 | DTC=dtc 9 | 10 | source_and_sort () { 11 | DT="$1" 12 | if [ -d "$DT" ]; then 13 | IFORMAT=fs 14 | elif [ -f "$DT" ]; then 15 | case "$DT" in 16 | *.dts) 17 | IFORMAT=dts 18 | ;; 19 | *.dtb) 20 | IFORMAT=dtb 21 | ;; 22 | esac 23 | fi 24 | 25 | if [ -z "$IFORMAT" ]; then 26 | echo "Unrecognized format for $DT" >&2 27 | exit 2 28 | fi 29 | 30 | $DTC -I $IFORMAT -O dts -qq -f -s -o - "$DT" 31 | } 32 | 33 | if [ $# != 2 ]; then 34 | echo "Usage: dtdiff " >&2 35 | exit 1 36 | fi 37 | 38 | diff -u <(source_and_sort "$1") <(source_and_sort "$2") 39 | -------------------------------------------------------------------------------- /fstree.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright David Gibson , IBM Corporation. 2005. 3 | * 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation; either version 2 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 18 | * USA 19 | */ 20 | 21 | #include "dtc.h" 22 | 23 | #include 24 | #include 25 | 26 | static struct node *read_fstree(const char *dirname) 27 | { 28 | DIR *d; 29 | struct dirent *de; 30 | struct stat st; 31 | struct node *tree; 32 | 33 | d = opendir(dirname); 34 | if (!d) 35 | die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno)); 36 | 37 | tree = build_node(NULL, NULL); 38 | 39 | while ((de = readdir(d)) != NULL) { 40 | char *tmpname; 41 | 42 | if (streq(de->d_name, ".") 43 | || streq(de->d_name, "..")) 44 | continue; 45 | 46 | tmpname = join_path(dirname, de->d_name); 47 | 48 | if (lstat(tmpname, &st) < 0) 49 | die("stat(%s): %s\n", tmpname, strerror(errno)); 50 | 51 | if (S_ISREG(st.st_mode)) { 52 | struct property *prop; 53 | FILE *pfile; 54 | 55 | pfile = fopen(tmpname, "rb"); 56 | if (! pfile) { 57 | fprintf(stderr, 58 | "WARNING: Cannot open %s: %s\n", 59 | tmpname, strerror(errno)); 60 | } else { 61 | prop = build_property(xstrdup(de->d_name), 62 | data_copy_file(pfile, 63 | st.st_size)); 64 | add_property(tree, prop); 65 | fclose(pfile); 66 | } 67 | } else if (S_ISDIR(st.st_mode)) { 68 | struct node *newchild; 69 | 70 | newchild = read_fstree(tmpname); 71 | newchild = name_node(newchild, xstrdup(de->d_name)); 72 | add_child(tree, newchild); 73 | } 74 | 75 | free(tmpname); 76 | } 77 | 78 | closedir(d); 79 | return tree; 80 | } 81 | 82 | struct dt_info *dt_from_fs(const char *dirname) 83 | { 84 | struct node *tree; 85 | 86 | tree = read_fstree(dirname); 87 | tree = name_node(tree, ""); 88 | 89 | return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree)); 90 | } 91 | -------------------------------------------------------------------------------- /libfdt/Android.bp: -------------------------------------------------------------------------------- 1 | cc_library_static { 2 | name: "libfdt", 3 | host_supported: true, 4 | 5 | cflags: [ 6 | "-Werror", 7 | "-Wno-macro-redefined", 8 | "-Wno-sign-compare", 9 | ], 10 | srcs: [ 11 | "fdt.c", 12 | "fdt_ro.c", 13 | "fdt_wip.c", 14 | "fdt_sw.c", 15 | "fdt_rw.c", 16 | "fdt_strerror.c", 17 | "fdt_empty_tree.c", 18 | "fdt_addresses.c", 19 | "fdt_overlay.c", 20 | "acpi.c", 21 | ], 22 | export_include_dirs: ["."], 23 | } 24 | -------------------------------------------------------------------------------- /libfdt/Makefile.libfdt: -------------------------------------------------------------------------------- 1 | # Makefile.libfdt 2 | # 3 | # This is not a complete Makefile of itself. Instead, it is designed to 4 | # be easily embeddable into other systems of Makefiles. 5 | # 6 | LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1 7 | LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h 8 | LIBFDT_VERSION = version.lds 9 | LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \ 10 | fdt_addresses.c fdt_overlay.c acpi.c 11 | LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) 12 | -------------------------------------------------------------------------------- /libfdt/TODO: -------------------------------------------------------------------------------- 1 | - Tree traversal functions 2 | - Graft function 3 | - Complete libfdt.h documenting comments 4 | -------------------------------------------------------------------------------- /libfdt/acpi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Intel Corporation 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer 13 | * in the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 19 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 20 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 27 | * OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | */ 30 | 31 | #include "libacpi.h" 32 | 33 | uint8_t acpi_csum(const void *base, int n) { 34 | const uint8_t *p; 35 | uint8_t sum; 36 | int bytesDone; 37 | 38 | p = (const uint8_t*)base; 39 | 40 | sum = 0; 41 | for (bytesDone = 0; bytesDone < n; bytesDone++) { 42 | sum += *p; 43 | p++; 44 | } 45 | 46 | return sum; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /libfdt/fdt_addresses.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Copyright (C) 2014 David Gibson 4 | * 5 | * libfdt is dual licensed: you can use it either under the terms of 6 | * the GPL, or the BSD license, at your option. 7 | * 8 | * a) This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU General Public License as 10 | * published by the Free Software Foundation; either version 2 of the 11 | * License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public 19 | * License along with this library; if not, write to the Free 20 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21 | * MA 02110-1301 USA 22 | * 23 | * Alternatively, 24 | * 25 | * b) Redistribution and use in source and binary forms, with or 26 | * without modification, are permitted provided that the following 27 | * conditions are met: 28 | * 29 | * 1. Redistributions of source code must retain the above 30 | * copyright notice, this list of conditions and the following 31 | * disclaimer. 32 | * 2. Redistributions in binary form must reproduce the above 33 | * copyright notice, this list of conditions and the following 34 | * disclaimer in the documentation and/or other materials 35 | * provided with the distribution. 36 | * 37 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 38 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 39 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 40 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 41 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 42 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 44 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 45 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 46 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 47 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 48 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 49 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 50 | */ 51 | #include "libfdt_env.h" 52 | 53 | #include 54 | #include 55 | 56 | #include "libfdt_internal.h" 57 | 58 | int fdt_address_cells(const void *fdt, int nodeoffset) 59 | { 60 | const fdt32_t *ac; 61 | int val; 62 | int len; 63 | 64 | ac = fdt_getprop(fdt, nodeoffset, "#address-cells", &len); 65 | if (!ac) 66 | return 2; 67 | 68 | if (len != sizeof(*ac)) 69 | return -FDT_ERR_BADNCELLS; 70 | 71 | val = fdt32_to_cpu(*ac); 72 | if ((val <= 0) || (val > FDT_MAX_NCELLS)) 73 | return -FDT_ERR_BADNCELLS; 74 | 75 | return val; 76 | } 77 | 78 | int fdt_size_cells(const void *fdt, int nodeoffset) 79 | { 80 | const fdt32_t *sc; 81 | int val; 82 | int len; 83 | 84 | sc = fdt_getprop(fdt, nodeoffset, "#size-cells", &len); 85 | if (!sc) 86 | return 2; 87 | 88 | if (len != sizeof(*sc)) 89 | return -FDT_ERR_BADNCELLS; 90 | 91 | val = fdt32_to_cpu(*sc); 92 | if ((val < 0) || (val > FDT_MAX_NCELLS)) 93 | return -FDT_ERR_BADNCELLS; 94 | 95 | return val; 96 | } 97 | -------------------------------------------------------------------------------- /libfdt/fdt_empty_tree.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Copyright (C) 2012 David Gibson, IBM Corporation. 4 | * 5 | * libfdt is dual licensed: you can use it either under the terms of 6 | * the GPL, or the BSD license, at your option. 7 | * 8 | * a) This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU General Public License as 10 | * published by the Free Software Foundation; either version 2 of the 11 | * License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public 19 | * License along with this library; if not, write to the Free 20 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21 | * MA 02110-1301 USA 22 | * 23 | * Alternatively, 24 | * 25 | * b) Redistribution and use in source and binary forms, with or 26 | * without modification, are permitted provided that the following 27 | * conditions are met: 28 | * 29 | * 1. Redistributions of source code must retain the above 30 | * copyright notice, this list of conditions and the following 31 | * disclaimer. 32 | * 2. Redistributions in binary form must reproduce the above 33 | * copyright notice, this list of conditions and the following 34 | * disclaimer in the documentation and/or other materials 35 | * provided with the distribution. 36 | * 37 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 38 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 39 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 40 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 41 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 42 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 44 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 45 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 46 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 47 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 48 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 49 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 50 | */ 51 | #include "libfdt_env.h" 52 | 53 | #include 54 | #include 55 | 56 | #include "libfdt_internal.h" 57 | 58 | int fdt_create_empty_tree(void *buf, int bufsize) 59 | { 60 | int err; 61 | 62 | err = fdt_create(buf, bufsize); 63 | if (err) 64 | return err; 65 | 66 | err = fdt_finish_reservemap(buf); 67 | if (err) 68 | return err; 69 | 70 | err = fdt_begin_node(buf, ""); 71 | if (err) 72 | return err; 73 | 74 | err = fdt_end_node(buf); 75 | if (err) 76 | return err; 77 | 78 | err = fdt_finish(buf); 79 | if (err) 80 | return err; 81 | 82 | return fdt_open_into(buf, buf, bufsize); 83 | } 84 | -------------------------------------------------------------------------------- /libfdt/libacpi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Intel Corporation 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer 13 | * in the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 19 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 20 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 27 | * OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | */ 30 | 31 | #ifndef _LIBACPI_H 32 | #define _LIBACPI_H 33 | 34 | #include "libfdt.h" 35 | 36 | #pragma pack(1) 37 | typedef struct { 38 | uint32_t Signature; /* ASCII Table identifier */ 39 | uint32_t Length; /* Length of the table, including the header */ 40 | uint8_t Revision; /* Revision of the structure */ 41 | uint8_t Checksum; /* Sum of all fields must be 0 */ 42 | uint8_t OemId[6]; /* ASCII OEM identifier */ 43 | uint64_t OemTableId; /* ASCII OEM table identifier */ 44 | uint32_t OemRevision; /* OEM supplied revision number */ 45 | uint32_t CreatorId; /* Vendor ID of utility creator of the table */ 46 | uint32_t CreatorRevision; /* Revision of utility creator of the table */ 47 | } EFI_ACPI_DESCRIPTION_HEADER; 48 | #pragma pack() 49 | 50 | /**********************************************************************/ 51 | /* General functions */ 52 | /**********************************************************************/ 53 | #define acpi_get_header(acpi, field) \ 54 | ((const EFI_ACPI_DESCRIPTION_HEADER *)(acpi))->field 55 | #define acpi_signature(acpi) (acpi_get_header(acpi, Signature)) 56 | #define acpi_length(acpi) (acpi_get_header(acpi, Length)) 57 | 58 | /* convert 2 bytes ASCII to uint16 */ 59 | #define SIGNATURE_16(A, B) ((A) | (B << 8)) 60 | /* convert 4 bytes ASCII to uint32 */ 61 | #define SIGNATURE_32(A, B, C, D) ((SIGNATURE_16 (A, B)) | (SIGNATURE_16 (C, D) << 16)) 62 | /* convert 8 bytes ASCII to uint64 */ 63 | #define SIGNATURE_64(A, B, C, D, E, F, G, H) \ 64 | (SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32)) 65 | 66 | #define SSDT_MAGIC (const unsigned)SIGNATURE_32('S', 'S', 'D', 'T') 67 | #define DSDT_MAGIC (const unsigned)SIGNATURE_32('D', 'S', 'D', 'T') 68 | 69 | #define ACPI_TABLE_MAGIC 0x41435049 70 | 71 | /* checksum byte by byte for acpi table */ 72 | uint8_t acpi_csum(const void *base, int n); 73 | 74 | #endif /* ifndef _LIBACPI_H */ 75 | -------------------------------------------------------------------------------- /libfdt/version.lds: -------------------------------------------------------------------------------- 1 | LIBFDT_1.2 { 2 | global: 3 | fdt_next_node; 4 | fdt_check_header; 5 | fdt_move; 6 | fdt_string; 7 | fdt_num_mem_rsv; 8 | fdt_get_mem_rsv; 9 | fdt_subnode_offset_namelen; 10 | fdt_subnode_offset; 11 | fdt_path_offset_namelen; 12 | fdt_path_offset; 13 | fdt_get_name; 14 | fdt_get_property_namelen; 15 | fdt_get_property; 16 | fdt_getprop_namelen; 17 | fdt_getprop; 18 | fdt_get_phandle; 19 | fdt_get_alias_namelen; 20 | fdt_get_alias; 21 | fdt_get_path; 22 | fdt_supernode_atdepth_offset; 23 | fdt_node_depth; 24 | fdt_parent_offset; 25 | fdt_node_offset_by_prop_value; 26 | fdt_node_offset_by_phandle; 27 | fdt_node_check_compatible; 28 | fdt_node_offset_by_compatible; 29 | fdt_setprop_inplace; 30 | fdt_nop_property; 31 | fdt_nop_node; 32 | fdt_create; 33 | fdt_add_reservemap_entry; 34 | fdt_finish_reservemap; 35 | fdt_begin_node; 36 | fdt_property; 37 | fdt_end_node; 38 | fdt_finish; 39 | fdt_open_into; 40 | fdt_pack; 41 | fdt_add_mem_rsv; 42 | fdt_del_mem_rsv; 43 | fdt_set_name; 44 | fdt_setprop; 45 | fdt_delprop; 46 | fdt_add_subnode_namelen; 47 | fdt_add_subnode; 48 | fdt_del_node; 49 | fdt_strerror; 50 | fdt_offset_ptr; 51 | fdt_next_tag; 52 | fdt_appendprop; 53 | fdt_create_empty_tree; 54 | fdt_first_property_offset; 55 | fdt_get_property_by_offset; 56 | fdt_getprop_by_offset; 57 | fdt_next_property_offset; 58 | fdt_first_subnode; 59 | fdt_next_subnode; 60 | fdt_address_cells; 61 | fdt_size_cells; 62 | fdt_stringlist_contains; 63 | fdt_resize; 64 | fdt_overlay_apply; 65 | 66 | local: 67 | *; 68 | }; 69 | -------------------------------------------------------------------------------- /pylibfdt/.gitignore: -------------------------------------------------------------------------------- 1 | libfdt.py 2 | libfdt.pyc 3 | libfdt_wrap.c 4 | -------------------------------------------------------------------------------- /pylibfdt/Makefile.pylibfdt: -------------------------------------------------------------------------------- 1 | # Makefile.pylibfdt 2 | # 3 | 4 | PYLIBFDT_srcs = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_SRCS)) \ 5 | $(PYLIBFDT_srcdir)/libfdt.i 6 | PYMODULE = $(PYLIBFDT_objdir)/_libfdt.so 7 | 8 | define run_setup 9 | SOURCES="$(1)" CPPFLAGS="$(CPPFLAGS)" OBJDIR="$(PYLIBFDT_objdir)" 10 | VERSION="$(dtc_version)" 11 | $(PYLIBFDT_objdir)/setup.py --quiet $(2) 12 | endef 13 | 14 | $(PYMODULE): $(PYLIBFDT_srcs) 15 | @$(VECHO) PYMOD $@ 16 | $(call run_setup, $^, build_ext --inplace) 17 | mv _libfdt.so $@ 18 | 19 | install_pylibfdt: $(PYMODULE) 20 | $(VECHO) INSTALL-PYLIB; \ 21 | $(call run_setup, $(PYLIBFDT_srcs), \ 22 | install $(if $(SETUP_PREFIX),--prefix=$(SETUP_PREFIX))) 23 | 24 | PYLIBFDT_cleanfiles = libfdt_wrap.c libfdt.py libfdt.pyc _libfdt.so 25 | -------------------------------------------------------------------------------- /scripts/kup-dtc: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | REMOTE_GIT=/pub/scm/utils/dtc/dtc.git 4 | REMOTE_PATH=/pub/software/utils/dtc 5 | 6 | set -e 7 | 8 | kup_one () { 9 | VERSION="$1" 10 | 11 | TAG="v$VERSION" 12 | 13 | PREFIX="dtc-$VERSION/" 14 | TAR="dtc-$VERSION.tar" 15 | SIG="$TAR.sign" 16 | 17 | git archive --format=tar --prefix="$PREFIX" -o "$TAR" "$TAG" 18 | gpg --detach-sign --armor -o "$SIG" "$TAR" 19 | 20 | ls -l "$TAR"* 21 | 22 | # Verify the signature as a sanity check 23 | gpg --verify "$SIG" "$TAR" 24 | 25 | kup put --tar --prefix="$PREFIX" "$REMOTE_GIT" "$TAG" "$SIG" "$REMOTE_PATH/$TAR.gz" 26 | } 27 | 28 | for version; do 29 | kup_one $version 30 | done 31 | 32 | -------------------------------------------------------------------------------- /scripts/setlocalversion: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Print additional version information for non-release trees. 3 | 4 | usage() { 5 | echo "Usage: $0 [srctree]" >&2 6 | exit 1 7 | } 8 | 9 | cd "${1:-.}" || usage 10 | 11 | # Check for git and a git repo. 12 | if head=`git rev-parse --verify HEAD 2>/dev/null`; then 13 | # Do we have an untagged version? 14 | if git name-rev --tags HEAD | grep -E '^HEAD[[:space:]]+(.*~[0-9]*|undefined)$' > /dev/null; then 15 | printf '%s%s' -g `echo "$head" | cut -c1-8` 16 | fi 17 | 18 | # Are there uncommitted changes? 19 | if git diff-index HEAD | read dummy; then 20 | printf '%s' -dirty 21 | fi 22 | fi 23 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | *.dtb 2 | *.dts.test.s 3 | *.test.dts 4 | tmp.* 5 | /add_subnode_with_nops 6 | /addr_size_cells 7 | /appendprop[12] 8 | /asm_tree_dump 9 | /boot-cpuid 10 | /char_literal 11 | /check_path 12 | /del_node 13 | /del_property 14 | /dtbs_equal_ordered 15 | /dtbs_equal_unordered 16 | /dtb_reverse 17 | /dumptrees 18 | /extra-terminating-null 19 | /find_property 20 | /get_alias 21 | /get_mem_rsv 22 | /get_name 23 | /get_path 24 | /get_phandle 25 | /getprop 26 | /incbin 27 | /integer-expressions 28 | /mangle-layout 29 | /move_and_save 30 | /node_check_compatible 31 | /node_offset_by_compatible 32 | /node_offset_by_phandle 33 | /node_offset_by_prop_value 34 | /nop_node 35 | /nop_property 36 | /nopulate 37 | /notfound 38 | /open_pack 39 | /overlay 40 | /overlay_bad_fixup 41 | /parent_offset 42 | /path-references 43 | /path_offset 44 | /path_offset_aliases 45 | /phandle_format 46 | /property_iterate 47 | /propname_escapes 48 | /references 49 | /root_node 50 | /rw_tree1 51 | /set_name 52 | /setprop 53 | /setprop_inplace 54 | /sized_cells 55 | /string_escapes 56 | /stringlist 57 | /subnode_iterate 58 | /subnode_offset 59 | /supernode_atdepth_offset 60 | /sw_tree1 61 | /truncated_property 62 | /utilfdt_test 63 | /value-labels 64 | -------------------------------------------------------------------------------- /tests/Makefile.tests: -------------------------------------------------------------------------------- 1 | LIB_TESTS_L = get_mem_rsv \ 2 | root_node find_property subnode_offset path_offset \ 3 | get_name getprop get_phandle \ 4 | get_path supernode_atdepth_offset parent_offset \ 5 | node_offset_by_prop_value node_offset_by_phandle \ 6 | node_check_compatible node_offset_by_compatible \ 7 | get_alias \ 8 | char_literal \ 9 | sized_cells \ 10 | notfound \ 11 | addr_size_cells \ 12 | stringlist \ 13 | setprop_inplace nop_property nop_node \ 14 | sw_tree1 \ 15 | move_and_save mangle-layout nopulate \ 16 | open_pack rw_tree1 set_name setprop del_property del_node \ 17 | appendprop1 appendprop2 propname_escapes \ 18 | string_escapes references path-references phandle_format \ 19 | boot-cpuid incbin \ 20 | extra-terminating-null \ 21 | dtbs_equal_ordered \ 22 | dtb_reverse dtbs_equal_unordered \ 23 | add_subnode_with_nops path_offset_aliases \ 24 | utilfdt_test \ 25 | integer-expressions \ 26 | property_iterate \ 27 | subnode_iterate \ 28 | overlay overlay_bad_fixup \ 29 | check_path 30 | LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%) 31 | 32 | LIBTREE_TESTS_L = truncated_property 33 | LIBTREE_TESTS = $(LIBTREE_TESTS_L:%=$(TESTS_PREFIX)%) 34 | 35 | DL_LIB_TESTS_L = asm_tree_dump value-labels 36 | DL_LIB_TESTS = $(DL_LIB_TESTS_L:%=$(TESTS_PREFIX)%) 37 | 38 | TESTS = $(LIB_TESTS) $(LIBTREE_TESTS) $(DL_LIB_TESTS) 39 | 40 | TESTS_TREES_L = test_tree1.dtb 41 | TESTS_TREES = $(TESTS_TREES_L:%=$(TESTS_PREFIX)%) 42 | 43 | TESTS_TARGETS = $(TESTS) $(TESTS_TREES) 44 | 45 | TESTS_DEPFILES = $(TESTS:%=%.d) \ 46 | $(addprefix $(TESTS_PREFIX),testutils.d trees.d dumptrees.d) 47 | 48 | TESTS_CLEANFILES_L = *.output vglog.* vgcore.* *.dtb *.test.dts *.dtsv1 tmp.* 49 | TESTS_CLEANFILES_L += dumptrees 50 | TESTS_CLEANFILES = $(TESTS) $(TESTS_CLEANFILES_L:%=$(TESTS_PREFIX)%) 51 | 52 | .PHONY: tests 53 | tests: $(TESTS) $(TESTS_TREES) 54 | 55 | $(LIB_TESTS): %: $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_archive) 56 | 57 | $(DL_LIB_TESTS): %: %.o $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_archive) 58 | @$(VECHO) LD [libdl] $@ 59 | $(LINK.c) -o $@ $^ -ldl 60 | 61 | $(LIBTREE_TESTS): %: $(TESTS_PREFIX)testutils.o $(TESTS_PREFIX)trees.o \ 62 | util.o $(LIBFDT_archive) 63 | 64 | $(TESTS_PREFIX)dumptrees: $(TESTS_PREFIX)trees.o 65 | 66 | $(TESTS_TREES): $(TESTS_PREFIX)dumptrees 67 | @$(VECHO) DUMPTREES 68 | cd $(TESTS_PREFIX); ./dumptrees >/dev/null 69 | 70 | tests_clean: 71 | @$(VECHO) CLEAN "(tests)" 72 | rm -f $(STD_CLEANFILES:%=$(TESTS_PREFIX)%) 73 | rm -f $(TESTS_CLEANFILES) 74 | 75 | check: tests ${TESTS_BIN} $(TESTS_PYLIBFDT) 76 | cd $(TESTS_PREFIX); ./run_tests.sh 77 | 78 | checkm: tests ${TESTS_BIN} $(TESTS_PYLIBFDT) 79 | cd $(TESTS_PREFIX); ./run_tests.sh -m 2>&1 | tee vglog.$$$$ 80 | 81 | checkv: tests ${TESTS_BIN} $(TESTS_PYLIBFDT) 82 | cd $(TESTS_PREFIX); ./run_tests.sh -v 83 | 84 | ifneq ($(DEPTARGETS),) 85 | -include $(TESTS_DEPFILES) 86 | endif 87 | 88 | -------------------------------------------------------------------------------- /tests/add_subnode_with_nops.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_nop_node() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "tests.h" 30 | #include "testdata.h" 31 | 32 | #define SPACE 65536 33 | 34 | #define CHECK(code) \ 35 | { \ 36 | err = (code); \ 37 | if (err) \ 38 | FAIL(#code ": %s", fdt_strerror(err)); \ 39 | } 40 | 41 | #define OFF_CHECK(off, code) \ 42 | { \ 43 | (off) = (code); \ 44 | if (off < 0) \ 45 | FAIL(#code ": %s", fdt_strerror(off)); \ 46 | } 47 | 48 | int main(int argc, char *argv[]) 49 | { 50 | void *fdt; 51 | int err; 52 | int offset; 53 | 54 | test_init(argc, argv); 55 | 56 | fdt = xmalloc(SPACE); 57 | 58 | CHECK(fdt_create(fdt, SPACE)); 59 | 60 | CHECK(fdt_finish_reservemap(fdt)); 61 | CHECK(fdt_begin_node(fdt, "")); 62 | CHECK(fdt_property_cell(fdt, "prop1", TEST_VALUE_1)); 63 | CHECK(fdt_property_cell(fdt, "prop2", TEST_VALUE_2)); 64 | CHECK(fdt_end_node(fdt)); 65 | CHECK(fdt_finish(fdt)); 66 | 67 | verbose_printf("Built empty tree, totalsize = %d\n", 68 | fdt_totalsize(fdt)); 69 | 70 | CHECK(fdt_open_into(fdt, fdt, SPACE)); 71 | 72 | check_getprop_cell(fdt, 0, "prop1", TEST_VALUE_1); 73 | check_getprop_cell(fdt, 0, "prop2", TEST_VALUE_2); 74 | 75 | CHECK(fdt_nop_property(fdt, 0, "prop1")); 76 | 77 | check_getprop_cell(fdt, 0, "prop2", TEST_VALUE_2); 78 | 79 | OFF_CHECK(offset, fdt_add_subnode(fdt, 0, "subnode")); 80 | 81 | check_getprop_cell(fdt, 0, "prop2", TEST_VALUE_2); 82 | 83 | PASS(); 84 | } 85 | -------------------------------------------------------------------------------- /tests/addr_size_cells.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for #address-cells and #size-cells handling 4 | * Copyright (C) 2014 David Gibson, 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | static void check_node(const void *fdt, const char *path, int ac, int sc) 31 | { 32 | int offset; 33 | int xac, xsc; 34 | 35 | offset = fdt_path_offset(fdt, path); 36 | if (offset < 0) 37 | FAIL("Couldn't find path %s", path); 38 | 39 | xac = fdt_address_cells(fdt, offset); 40 | xsc = fdt_size_cells(fdt, offset); 41 | 42 | if (xac != ac) 43 | FAIL("Address cells for %s is %d instead of %d\n", 44 | path, xac, ac); 45 | if (xsc != sc) 46 | FAIL("Size cells for %s is %d instead of %d\n", 47 | path, xsc, sc); 48 | } 49 | 50 | int main(int argc, char *argv[]) 51 | { 52 | void *fdt; 53 | 54 | if (argc != 2) 55 | CONFIG("Usage: %s \n", argv[0]); 56 | 57 | test_init(argc, argv); 58 | fdt = load_blob(argv[1]); 59 | 60 | check_node(fdt, "/", 2, 2); 61 | check_node(fdt, "/identity-bus@0", 2, 2); 62 | check_node(fdt, "/simple-bus@1000000", 2, 1); 63 | PASS(); 64 | } 65 | -------------------------------------------------------------------------------- /tests/addresses.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | compatible = "test_addresses"; 5 | #address-cells = <2>; 6 | #size-cells = <2>; 7 | 8 | identity-bus@0 { 9 | }; 10 | 11 | simple-bus@1000000 { 12 | #address-cells = <2>; 13 | #size-cells = <1>; 14 | }; 15 | }; 16 | -------------------------------------------------------------------------------- /tests/aliases.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = <1>; 5 | #size-cells = <0>; 6 | 7 | aliases { 8 | s1 = &sub1; 9 | ss1 = &subsub1; 10 | sss1 = &subsubsub1; 11 | }; 12 | 13 | sub1: subnode@1 { 14 | compatible = "subnode1"; 15 | reg = <1>; 16 | 17 | subsub1: subsubnode { 18 | compatible = "subsubnode1", "subsubnode"; 19 | 20 | subsubsub1: subsubsubnode { 21 | compatible = "subsubsubnode1", "subsubsubnode"; 22 | }; 23 | }; 24 | }; 25 | }; 26 | -------------------------------------------------------------------------------- /tests/appendprop.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | prop-str = "hello world", "nastystring: \a\b\t\n\v\f\r\\\""; 5 | prop-int64 = /bits/ 64 <0xdeadbeef01abcdef 0xdeadbeef01abcdef>; 6 | prop-int = <0xdeadbeef 123456789>; 7 | prop-bytes = [00010203040001020304]; 8 | }; 9 | -------------------------------------------------------------------------------- /tests/appendprop1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_appendprop() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "tests.h" 30 | #include "testdata.h" 31 | 32 | #define SPACE 65536 33 | 34 | #define CHECK(code) \ 35 | { \ 36 | err = (code); \ 37 | if (err) \ 38 | FAIL(#code ": %s", fdt_strerror(err)); \ 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | void *fdt; 44 | int err; 45 | uint8_t bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04}; 46 | 47 | test_init(argc, argv); 48 | 49 | /* Create an empty tree first */ 50 | fdt = xmalloc(SPACE); 51 | CHECK(fdt_create(fdt, SPACE)); 52 | CHECK(fdt_finish_reservemap(fdt)); 53 | CHECK(fdt_begin_node(fdt, "")); 54 | CHECK(fdt_end_node(fdt)); 55 | CHECK(fdt_finish(fdt)); 56 | 57 | /* Now use appendprop to add properties */ 58 | CHECK(fdt_open_into(fdt, fdt, SPACE)); 59 | 60 | CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes))); 61 | CHECK(fdt_appendprop_cell(fdt, 0, "prop-int", TEST_VALUE_1)); 62 | CHECK(fdt_appendprop_u64(fdt, 0, "prop-int64", TEST_VALUE64_1)); 63 | CHECK(fdt_appendprop_string(fdt, 0, "prop-str", TEST_STRING_1)); 64 | 65 | CHECK(fdt_pack(fdt)); 66 | 67 | save_blob("appendprop1.test.dtb", fdt); 68 | 69 | PASS(); 70 | } 71 | -------------------------------------------------------------------------------- /tests/appendprop2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_appendprop() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "tests.h" 30 | #include "testdata.h" 31 | 32 | #define SPACE 65536 33 | 34 | #define CHECK(code) \ 35 | { \ 36 | err = (code); \ 37 | if (err) \ 38 | FAIL(#code ": %s", fdt_strerror(err)); \ 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | void *fdt, *buf; 44 | int err; 45 | uint8_t bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04}; 46 | 47 | test_init(argc, argv); 48 | fdt = load_blob_arg(argc, argv); 49 | 50 | buf = xmalloc(SPACE); 51 | CHECK(fdt_open_into(fdt, buf, SPACE)); 52 | fdt = buf; 53 | 54 | CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes))); 55 | CHECK(fdt_appendprop_cell(fdt, 0, "prop-int", TEST_VALUE_2)); 56 | CHECK(fdt_appendprop_u64(fdt, 0, "prop-int64", TEST_VALUE64_1)); 57 | CHECK(fdt_appendprop_string(fdt, 0, "prop-str", TEST_STRING_2)); 58 | 59 | CHECK(fdt_pack(fdt)); 60 | 61 | save_blob("appendprop2.test.dtb", fdt); 62 | 63 | PASS(); 64 | } 65 | -------------------------------------------------------------------------------- /tests/asm_tree_dump.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Tests if an asm tree built into a shared object matches a given dtb 4 | * Copyright (C) 2008 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | 31 | #include "tests.h" 32 | #include "testdata.h" 33 | 34 | int main(int argc, char *argv[]) 35 | { 36 | void *sohandle; 37 | void *fdt; 38 | int err; 39 | 40 | test_init(argc, argv); 41 | if (argc != 3) 42 | CONFIG("Usage: %s ", argv[0]); 43 | 44 | sohandle = dlopen(argv[1], RTLD_NOW); 45 | if (!sohandle) 46 | FAIL("Couldn't dlopen() %s", argv[1]); 47 | 48 | fdt = dlsym(sohandle, "dt_blob_start"); 49 | if (!fdt) 50 | FAIL("Couldn't locate \"dt_blob_start\" symbol in %s", 51 | argv[1]); 52 | 53 | err = fdt_check_header(fdt); 54 | if (err != 0) 55 | FAIL("%s contains invalid tree: %s", argv[1], 56 | fdt_strerror(err)); 57 | 58 | save_blob(argv[2], fdt); 59 | 60 | PASS(); 61 | } 62 | -------------------------------------------------------------------------------- /tests/bad-empty-ranges.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = <2>; 5 | #size-cells = <2>; 6 | node { 7 | #address-cells = <1>; 8 | #size-cells = <1>; 9 | ranges; 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /tests/bad-name-property.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | node@0 { 5 | name = "badthing"; 6 | }; 7 | }; 8 | -------------------------------------------------------------------------------- /tests/bad-ncells.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = "badthing"; 5 | #size-cells = "badthing"; 6 | #interrupt-cells = "badthing"; 7 | }; 8 | -------------------------------------------------------------------------------- /tests/bad-octal-literal.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | x = <09>; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/bad-reg-ranges.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = <2>; 5 | #size-cells = <2>; 6 | node { 7 | reg = <0 0>; 8 | #address-cells = <1>; 9 | #size-cells = <1>; 10 | ranges = <0 0 0>; 11 | }; 12 | }; 13 | -------------------------------------------------------------------------------- /tests/bad-size-cells.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | mangled { 5 | #address-cells = <0x0>; 6 | #size-cells = <0x0>; 7 | 8 | valid { 9 | reg = <0x0 0x4000000>; 10 | }; 11 | }; 12 | }; 13 | -------------------------------------------------------------------------------- /tests/bad-string-props.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | device_type = <0xdeadbeef>; 5 | model = <0xdeadbeef>; 6 | status = <0xdeadbeef>; 7 | }; 8 | -------------------------------------------------------------------------------- /tests/base01.cmd: -------------------------------------------------------------------------------- 1 | dtc -f -b 0 -V 16 -I dts -O asm 2 | -------------------------------------------------------------------------------- /tests/base01.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | model = "SomeModel"; 5 | compatible = "Nothing"; 6 | #address-cells = <2>; 7 | #size-cells = <2>; 8 | 9 | memory@0 { 10 | device_type = "memory"; 11 | reg = <0x00000000 0x00000000 0x00000000 0x20000000>; 12 | }; 13 | 14 | cpus { 15 | #address-cells = <1>; 16 | #size-cells = <0>; 17 | d10 = < 10>; // hex: 0xa 18 | d23 = < 23>; // hex: 0x17 19 | b101 = < 0x5>; // hex: 0x5 20 | o17 = < 017>; // hex: 0xf 21 | hd00d = < 0xd00d>; // hex: 0xd00d 22 | 23 | // hex: 0x4d2 0x163e 0x2334 0xd80 24 | stuff = < 1234 5678 9012 3456>; 25 | 26 | 27 | bad-d-1 = < 0>; // Hrm. 0 28 | bad-d-2 = < 123456789012345>; 29 | bad-o-1 = < 00>; 30 | bad-o-2 = < 0123456123456>; 31 | }; 32 | 33 | }; 34 | -------------------------------------------------------------------------------- /tests/base01.stderr: -------------------------------------------------------------------------------- 1 | DTC: dts->asm on file "tests/base01.dts" 2 | Line 26: Invalid cell value '123456789012345'; -1 assumed 3 | Line 27: Invalid cell value '891'; 0 assumed 4 | Line 28: Invalid cell value '123456123456'; -1 assumed 5 | ERROR: Missing /chosen node 6 | Input tree has errors 7 | -------------------------------------------------------------------------------- /tests/boot-cpuid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 David Gibson, IBM Corporation. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public License 6 | * as published by the Free Software Foundation; either version 2.1 of 7 | * the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include "tests.h" 27 | #include "testdata.h" 28 | 29 | int main(int argc, char *argv[]) 30 | { 31 | void *fdt; 32 | uint32_t cpuid; 33 | 34 | test_init(argc, argv); 35 | 36 | if (argc != 3) 37 | CONFIG("Usage: %s ", argv[0]); 38 | 39 | fdt = load_blob(argv[1]); 40 | cpuid = strtoul(argv[2], NULL, 0); 41 | 42 | if (fdt_boot_cpuid_phys(fdt) != cpuid) 43 | FAIL("Incorrect boot_cpuid_phys (0x%x instead of 0x%x)", 44 | fdt_boot_cpuid_phys(fdt), cpuid); 45 | 46 | PASS(); 47 | } 48 | -------------------------------------------------------------------------------- /tests/boot-cpuid.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | cpus { 5 | cpu@10 { 6 | device_type = "cpu"; 7 | compatible = "fake-cpu"; 8 | reg = <0x10>; 9 | }; 10 | cpu@11 { 11 | device_type = "cpu"; 12 | compatible = "fake-cpu"; 13 | reg = <0x11>; 14 | }; 15 | }; 16 | }; 17 | -------------------------------------------------------------------------------- /tests/char_literal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for character literals in dtc 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * Copyright (C) 2011 The Chromium Authors. All rights reserved. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public License 9 | * as published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "tests.h" 29 | #include "testdata.h" 30 | 31 | int main(int argc, char *argv[]) 32 | { 33 | void *fdt; 34 | fdt32_t expected_cells[5]; 35 | 36 | expected_cells[0] = cpu_to_fdt32((unsigned char)TEST_CHAR1); 37 | expected_cells[1] = cpu_to_fdt32((unsigned char)TEST_CHAR2); 38 | expected_cells[2] = cpu_to_fdt32((unsigned char)TEST_CHAR3); 39 | expected_cells[3] = cpu_to_fdt32((unsigned char)TEST_CHAR4); 40 | expected_cells[4] = cpu_to_fdt32((unsigned char)TEST_CHAR5); 41 | 42 | test_init(argc, argv); 43 | fdt = load_blob_arg(argc, argv); 44 | 45 | check_getprop(fdt, 0, "char-literal-cells", 46 | sizeof(expected_cells), expected_cells); 47 | 48 | PASS(); 49 | } 50 | -------------------------------------------------------------------------------- /tests/char_literal.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | char-literal-cells = <'\r' 'b' '\0' '\'' '\xff'>; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/check_path.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for node existence 4 | * Copyright (C) 2016 Konsulko Inc. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include "tests.h" 26 | 27 | #define CHECK(code) \ 28 | { \ 29 | int err = (code); \ 30 | if (err) \ 31 | FAIL(#code ": %s", fdt_strerror(err)); \ 32 | } 33 | 34 | /* 4k ought to be enough for anybody */ 35 | #define FDT_COPY_SIZE (4 * 1024) 36 | 37 | static void *open_dt(char *path) 38 | { 39 | void *dt, *copy; 40 | 41 | dt = load_blob(path); 42 | copy = xmalloc(FDT_COPY_SIZE); 43 | 44 | /* 45 | * Resize our DTs to 4k so that we have room to operate on 46 | */ 47 | CHECK(fdt_open_into(dt, copy, FDT_COPY_SIZE)); 48 | 49 | return copy; 50 | } 51 | 52 | int main(int argc, char *argv[]) 53 | { 54 | void *fdt_base; 55 | int fail_config, exists, check_exists; 56 | 57 | test_init(argc, argv); 58 | fail_config = 0; 59 | 60 | if (argc != 4) 61 | fail_config = 1; 62 | 63 | if (!fail_config) { 64 | if (!strcmp(argv[2], "exists")) 65 | check_exists = 1; 66 | else if (!strcmp(argv[2], "not-exists")) 67 | check_exists = 0; 68 | else 69 | fail_config = 1; 70 | } 71 | 72 | if (fail_config) 73 | CONFIG("Usage: %s <[exists|not-exists]> ", argv[0]); 74 | 75 | fdt_base = open_dt(argv[1]); 76 | 77 | exists = fdt_path_offset(fdt_base, argv[3]) >= 0; 78 | 79 | if (exists == check_exists) 80 | PASS(); 81 | else 82 | FAIL(); 83 | } 84 | -------------------------------------------------------------------------------- /tests/comments-cmp.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | prop1; 5 | prop2; 6 | prop3; 7 | prop4; 8 | prop5; 9 | prop6; 10 | prop7; 11 | prop8; 12 | prop9; 13 | prop10; 14 | child { 15 | }; 16 | }; 17 | -------------------------------------------------------------------------------- /tests/comments.dts: -------------------------------------------------------------------------------- 1 | /* regexps for lexing comments are.. tricky. Check if we've actually 2 | * got it right */ 3 | /dts-v1/; 4 | 5 | / { 6 | // line comment 7 | prop1; 8 | /* comment */ 9 | prop2; 10 | /* multiline 11 | 12 | notaprop1; 13 | 14 | comment */ 15 | prop3; 16 | /**/ 17 | prop4; 18 | /***/ 19 | prop5; 20 | /****/ 21 | prop6; 22 | /* another 23 | * multiline 24 | * comment */ 25 | prop7; 26 | /* yet 27 | * another 28 | * multline 29 | * comment 30 | */ 31 | prop8; 32 | /** try this */ 33 | prop9; 34 | /* and this **/ 35 | prop10; 36 | child /* finally */ { 37 | }; 38 | }; 39 | /* final comment */ 40 | -------------------------------------------------------------------------------- /tests/data.S: -------------------------------------------------------------------------------- 1 | /* Used in combination with dtc -Oasm output to embed 2 | * a device tree in the data section of a .o */ 3 | .data 4 | -------------------------------------------------------------------------------- /tests/default-addr-size.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | node { 5 | reg = <0 0 0>; 6 | }; 7 | }; 8 | -------------------------------------------------------------------------------- /tests/del_property.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_delprop() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "tests.h" 30 | #include "testdata.h" 31 | 32 | int main(int argc, char *argv[]) 33 | { 34 | void *fdt; 35 | const uint32_t *intp; 36 | const char *strp; 37 | int err, lenerr; 38 | int oldsize, delsize, newsize; 39 | 40 | test_init(argc, argv); 41 | fdt = load_blob_arg(argc, argv); 42 | 43 | fdt = open_blob_rw(fdt); 44 | 45 | oldsize = fdt_totalsize(fdt); 46 | 47 | intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1); 48 | verbose_printf("int value was 0x%08x\n", *intp); 49 | 50 | err = fdt_delprop(fdt, 0, "prop-int"); 51 | if (err) 52 | FAIL("Failed to delete \"prop-int\": %s", fdt_strerror(err)); 53 | 54 | intp = fdt_getprop(fdt, 0, "prop-int", &lenerr); 55 | if (intp) 56 | FAIL("prop-int still present after deletion"); 57 | if (lenerr != -FDT_ERR_NOTFOUND) 58 | FAIL("Unexpected error on second getprop: %s", 59 | fdt_strerror(lenerr)); 60 | 61 | strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1, 62 | TEST_STRING_1); 63 | verbose_printf("string value was \"%s\"\n", strp); 64 | err = fdt_delprop(fdt, 0, "prop-str"); 65 | if (err) 66 | FAIL("Failed to delete \"prop-str\": %s", fdt_strerror(err)); 67 | 68 | strp = fdt_getprop(fdt, 0, "prop-str", &lenerr); 69 | if (strp) 70 | FAIL("prop-str still present after deletion"); 71 | if (lenerr != -FDT_ERR_NOTFOUND) 72 | FAIL("Unexpected error on second getprop: %s", 73 | fdt_strerror(lenerr)); 74 | 75 | delsize = fdt_totalsize(fdt); 76 | 77 | err = fdt_pack(fdt); 78 | if (err) 79 | FAIL("fdt_pack(): %s\n", fdt_strerror(err)); 80 | 81 | newsize = fdt_totalsize(fdt); 82 | 83 | verbose_printf("oldsize = %d, delsize = %d, newsize = %d\n", 84 | oldsize, delsize, newsize); 85 | 86 | if (newsize >= oldsize) 87 | FAIL("Tree failed to shrink after deletions"); 88 | 89 | PASS(); 90 | } 91 | -------------------------------------------------------------------------------- /tests/delete_reinstate_multilabel.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /* Create some nodes and properties with multiple labels */ 4 | 5 | / { 6 | label1: label2: prop = "value"; 7 | 8 | label3: label4: node { 9 | label5: label6: prop = "value"; 10 | }; 11 | }; 12 | 13 | /* Delete them, and everything that's part of them, i.e. the labels */ 14 | 15 | / { 16 | /delete-property/ prop; 17 | /delete-node/ node; 18 | }; 19 | 20 | /* 21 | * Re-instate them. None of the old labels should come back 22 | * 23 | * Note: Do not add any new/extra labels here. As of the time of writing, 24 | * when dtc adds labels to an object, they are added to the head of the list 25 | * of labels, and this test is specifically about ensuring the correct 26 | * handling of lists of labels where the first label in the list is marked as 27 | * deleted. Failure to observe this note may result in the test passing when 28 | * it should not. 29 | */ 30 | 31 | / { 32 | prop = "value"; 33 | 34 | node { 35 | prop = "value"; 36 | }; 37 | }; 38 | -------------------------------------------------------------------------------- /tests/delete_reinstate_multilabel_ref.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | prop = "value"; 5 | 6 | node { 7 | prop = "value"; 8 | }; 9 | }; 10 | -------------------------------------------------------------------------------- /tests/dependencies.cmp: -------------------------------------------------------------------------------- 1 | dependencies.test.dtb: dependencies.dts deps_inc1.dtsi deps_inc2.dtsi 2 | -------------------------------------------------------------------------------- /tests/dependencies.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /include/ "deps_inc1.dtsi" 4 | 5 | / { 6 | }; 7 | -------------------------------------------------------------------------------- /tests/deps_inc1.dtsi: -------------------------------------------------------------------------------- 1 | /include/ "deps_inc2.dtsi" 2 | -------------------------------------------------------------------------------- /tests/deps_inc2.dtsi: -------------------------------------------------------------------------------- 1 | /* Empty */ 2 | -------------------------------------------------------------------------------- /tests/division-by-zero.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | prop-div = < (1/0) >; 5 | prop-mod = < (1%0) >; 6 | }; 7 | -------------------------------------------------------------------------------- /tests/dtc-checkfails.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | . ./tests.sh 4 | 5 | for x; do 6 | shift 7 | if [ "$x" = "-n" ]; then 8 | for x; do 9 | shift 10 | if [ "$x" = "--" ]; then 11 | break; 12 | fi 13 | NOCHECKS="$NOCHECKS $x" 14 | done 15 | break; 16 | fi 17 | if [ "$x" = "--" ]; then 18 | break; 19 | fi 20 | YESCHECKS="$YESCHECKS $x" 21 | done 22 | 23 | LOG=tmp.log.$$ 24 | rm -f $LOG 25 | trap "rm -f $LOG" 0 26 | 27 | verbose_run_log "$LOG" $VALGRIND "$DTC" -o /dev/null "$@" 28 | ret="$?" 29 | 30 | FAIL_IF_SIGNAL $ret 31 | 32 | for c in $YESCHECKS; do 33 | if ! grep -E "^(ERROR)|(Warning) \($c\):" $LOG > /dev/null; then 34 | FAIL "Failed to trigger check \"$c\"" 35 | fi 36 | done 37 | 38 | for c in $NOCHECKS; do 39 | if grep -E "^(ERROR)|(Warning) \($c\):" $LOG > /dev/null; then 40 | FAIL "Incorrectly triggered check \"$c\"" 41 | fi 42 | done 43 | 44 | PASS 45 | -------------------------------------------------------------------------------- /tests/dtc-fails.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | . ./tests.sh 4 | 5 | if [ "$1" = "-n" ]; then 6 | NEG="$1" 7 | shift 8 | fi 9 | 10 | OUTPUT="$1" 11 | shift 12 | 13 | verbose_run $VALGRIND "$DTC" -o "$OUTPUT" "$@" 14 | ret="$?" 15 | 16 | FAIL_IF_SIGNAL $ret 17 | 18 | if [ -n "$NEG" ]; then 19 | if [ ! -e "$OUTPUT" ]; then 20 | FAIL "Produced no output" 21 | fi 22 | else 23 | if [ -e "$OUTPUT" ]; then 24 | FAIL "Incorrectly produced output" 25 | fi 26 | fi 27 | 28 | rm -f "$OUTPUT" 29 | 30 | PASS 31 | -------------------------------------------------------------------------------- /tests/dtc-fatal.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | . ./tests.sh 4 | 5 | verbose_run $VALGRIND "$DTC" -o/dev/null "$@" 6 | ret="$?" 7 | 8 | if [ "$ret" -gt 127 ]; then 9 | FAIL "dtc killed by signal (ret=$ret)" 10 | elif [ "$ret" != "1" ]; then 11 | FAIL "dtc returned incorrect status $ret instead of 1" 12 | fi 13 | 14 | PASS 15 | -------------------------------------------------------------------------------- /tests/dumptrees.c: -------------------------------------------------------------------------------- 1 | /* 2 | * dumptrees - utility for libfdt testing 3 | * 4 | * (C) Copyright David Gibson , IBM Corporation. 2006. 5 | * 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation; either version 2 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | * USA 21 | */ 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include "testdata.h" 31 | 32 | static struct { 33 | void *blob; 34 | const char *filename; 35 | } trees[] = { 36 | #define TREE(name) { &_##name, #name ".dtb" } 37 | TREE(test_tree1), 38 | TREE(bad_node_char), TREE(bad_node_format), TREE(bad_prop_char), 39 | TREE(ovf_size_strings), 40 | }; 41 | 42 | #define NUM_TREES (sizeof(trees) / sizeof(trees[0])) 43 | 44 | int main(int argc, char *argv[]) 45 | { 46 | int i; 47 | 48 | for (i = 0; i < NUM_TREES; i++) { 49 | void *blob = trees[i].blob; 50 | const char *filename = trees[i].filename; 51 | int size; 52 | int fd; 53 | int ret; 54 | 55 | size = fdt_totalsize(blob); 56 | 57 | printf("Tree \"%s\", %d bytes\n", filename, size); 58 | 59 | fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); 60 | if (fd < 0) 61 | perror("open()"); 62 | 63 | ret = write(fd, blob, size); 64 | if (ret != size) 65 | perror("write()"); 66 | 67 | close(fd); 68 | } 69 | exit(0); 70 | } 71 | -------------------------------------------------------------------------------- /tests/dup-nodename.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | node { 5 | }; 6 | node { 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /tests/dup-phandle.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | node1 { 5 | linux,phandle = <1>; 6 | }; 7 | node2 { 8 | linux,phandle = <1>; 9 | }; 10 | }; 11 | -------------------------------------------------------------------------------- /tests/dup-propname.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | prop; 5 | prop; 6 | }; 7 | -------------------------------------------------------------------------------- /tests/embedded_nul.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | reserved-names = "aaaaaaaaaaaaaaaaaabbbbbbccccccccccccc"; 5 | reserved-ranges = < 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 >; 6 | }; 7 | -------------------------------------------------------------------------------- /tests/embedded_nul_equiv.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | reserved-names = "aaaaaaaaaaaaaaaaaa\0bbbbbb\0ccccccccccccc"; 5 | reserved-ranges = < 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 >; 6 | }; 7 | -------------------------------------------------------------------------------- /tests/empty.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | }; 5 | -------------------------------------------------------------------------------- /tests/escapes.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | compatible = "test_string_escapes"; 5 | escape-str = "nastystring: \a\b\t\n\v\f\r\\\""; 6 | escape-str-2 = "\xde\xad\xbe\xef"; 7 | }; 8 | -------------------------------------------------------------------------------- /tests/extra-terminating-null.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for properties with more than one terminating null 4 | * Copyright (C) 2009 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | static void check_extranull(void *fdt, const char *prop, const char *str, int numnulls) 31 | { 32 | int len = strlen(str); 33 | char checkbuf[len+numnulls]; 34 | 35 | memset(checkbuf, 0, sizeof(checkbuf)); 36 | memcpy(checkbuf, TEST_STRING_1, len); 37 | 38 | check_getprop(fdt, 0, prop, len+numnulls, checkbuf); 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | void *fdt; 44 | 45 | test_init(argc, argv); 46 | 47 | fdt = load_blob_arg(argc, argv); 48 | 49 | check_extranull(fdt, "extranull0", TEST_STRING_1, 1); 50 | check_extranull(fdt, "extranull1,1", TEST_STRING_1, 2); 51 | check_extranull(fdt, "extranull1,2", TEST_STRING_1, 2); 52 | check_extranull(fdt, "extranull2,1", TEST_STRING_1, 3); 53 | check_extranull(fdt, "extranull2,2", TEST_STRING_1, 3); 54 | check_extranull(fdt, "extranull2,3", TEST_STRING_1, 3); 55 | check_extranull(fdt, "extranull2,4", TEST_STRING_1, 3); 56 | 57 | PASS(); 58 | } 59 | -------------------------------------------------------------------------------- /tests/extra-terminating-null.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | extranull0 = "hello world"; 5 | extranull1,1 = "hello world\0"; 6 | extranull1,2 = "hello world", ""; 7 | extranull2,1 = "hello world\0\0"; 8 | extranull2,2 = "hello world", "", ""; 9 | extranull2,3 = "hello world\0", ""; 10 | extranull2,4 = "hello world", "\0"; 11 | }; 12 | -------------------------------------------------------------------------------- /tests/fdtdump-runtest.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Arguments: 4 | # $1 - source file to compile and compare with fdtdump output of the 5 | # compiled file. 6 | 7 | . ./tests.sh 8 | 9 | dts="$1" 10 | dtb="${dts}.dtb" 11 | out="${dts}.out" 12 | LOG=tmp.log.$$ 13 | 14 | files="$dtb $out $LOG" 15 | 16 | rm -f $files 17 | trap "rm -f $files" 0 18 | 19 | verbose_run_log_check "$LOG" $VALGRIND $DTC -O dtb $dts -o $dtb 20 | $FDTDUMP ${dtb} | grep -v "//" >${out} 21 | 22 | if diff -w $dts $out >/dev/null; then 23 | PASS 24 | else 25 | if [ -z "$QUIET_TEST" ]; then 26 | echo "DIFF :-:" 27 | diff -u -w $dts $out 28 | fi 29 | FAIL "Results differ from expected" 30 | fi 31 | -------------------------------------------------------------------------------- /tests/fdtdump.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0 0xe; 4 | / { 5 | model = "MyBoardName"; 6 | compatible = "MyBoardName", "MyBoardFamilyName"; 7 | #address-cells = <0x00000002>; 8 | #size-cells = <0x00000002>; 9 | cpus { 10 | linux,phandle = <0x00000001>; 11 | #address-cells = <0x00000001>; 12 | #size-cells = <0x00000000>; 13 | PowerPC,970@0 { 14 | device_type = "cpu"; 15 | reg = <0x00000000>; 16 | linux,boot-cpu; 17 | }; 18 | PowerPC,970@1 { 19 | device_type = "cpu"; 20 | reg = <0x00000001>; 21 | }; 22 | }; 23 | randomnode { 24 | string = "foo", "stuff"; 25 | bytes = [61 62 63 64 65]; 26 | nbytes = [80 ff]; 27 | child { 28 | }; 29 | }; 30 | memory@0 { 31 | device_type = "memory"; 32 | reg = <0x00000000 0x00000123 0x00000456 0x87654321>; 33 | }; 34 | chosen { 35 | bootargs = "root=/dev/sda2"; 36 | linux,platform = <0x00000600>; 37 | }; 38 | }; 39 | -------------------------------------------------------------------------------- /tests/fdtget-runtest.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | . ./tests.sh 4 | 5 | LOG=tmp.log.$$ 6 | EXPECT=tmp.expect.$$ 7 | rm -f $LOG $EXPECT 8 | trap "rm -f $LOG $EXPECT" 0 9 | 10 | expect="$1" 11 | printf '%b\n' "$expect" > $EXPECT 12 | shift 13 | 14 | verbose_run_log_check "$LOG" $VALGRIND $DTGET "$@" 15 | 16 | if cmp $EXPECT $LOG>/dev/null; then 17 | PASS 18 | else 19 | if [ -z "$QUIET_TEST" ]; then 20 | echo "EXPECTED :-:" 21 | cat $EXPECT 22 | fi 23 | FAIL "Results differ from expected" 24 | fi 25 | -------------------------------------------------------------------------------- /tests/fdtoverlay-runtest.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Run script for fdtoverlay tests 4 | # We run fdtoverlay to generate a target device tree, thn fdtget to check it 5 | 6 | # Usage 7 | # fdtoverlay-runtest.sh name expected_output dtb_file node property flags value 8 | 9 | . ./tests.sh 10 | 11 | LOG=tmp.log.$$ 12 | EXPECT=tmp.expect.$$ 13 | rm -f $LOG $EXPECT 14 | trap "rm -f $LOG $EXPECT" 0 15 | 16 | expect="$1" 17 | echo $expect >$EXPECT 18 | node="$2" 19 | property="$3" 20 | flags="$4" 21 | basedtb="$5" 22 | targetdtb="$6" 23 | shift 6 24 | overlays="$@" 25 | 26 | # First run fdtoverlay 27 | verbose_run_check $VALGRIND "$FDTOVERLAY" -i "$basedtb" -o "$targetdtb" $overlays 28 | 29 | # Now fdtget to read the value 30 | verbose_run_log_check "$LOG" $VALGRIND "$DTGET" "$targetdtb" "$node" "$property" $flags 31 | 32 | if cmp $EXPECT $LOG >/dev/null; then 33 | PASS 34 | else 35 | if [ -z "$QUIET_TEST" ]; then 36 | echo "EXPECTED :-:" 37 | cat $EXPECT 38 | fi 39 | FAIL "Results differ from expected" 40 | fi 41 | -------------------------------------------------------------------------------- /tests/fdtput-runtest.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Run script for fdtput tests 4 | # We run fdtput to update the device tree, thn fdtget to check it 5 | 6 | # Usage 7 | # fdtput-runtest.sh name expected_output dtb_file node property flags value 8 | 9 | . ./tests.sh 10 | 11 | LOG=tmp.log.$$ 12 | EXPECT=tmp.expect.$$ 13 | rm -f $LOG $EXPECT 14 | trap "rm -f $LOG $EXPECT" 0 15 | 16 | expect="$1" 17 | echo $expect >$EXPECT 18 | dtb="$2" 19 | node="$3" 20 | property="$4" 21 | flags="$5" 22 | shift 5 23 | value="$@" 24 | 25 | # First run fdtput 26 | verbose_run_check $VALGRIND "$DTPUT" "$dtb" "$node" "$property" $value $flags 27 | 28 | # Now fdtget to read the value 29 | verbose_run_log_check "$LOG" $VALGRIND "$DTGET" "$dtb" "$node" "$property" $flags 30 | 31 | if cmp $EXPECT $LOG >/dev/null; then 32 | PASS 33 | else 34 | if [ -z "$QUIET_TEST" ]; then 35 | echo "EXPECTED :-:" 36 | cat $EXPECT 37 | fi 38 | FAIL "Results differ from expected" 39 | fi 40 | -------------------------------------------------------------------------------- /tests/find_property.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_property_offset() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | void *fdt; 33 | 34 | test_init(argc, argv); 35 | fdt = load_blob_arg(argc, argv); 36 | 37 | check_property_cell(fdt, 0, "prop-int", TEST_VALUE_1); 38 | check_property(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1, TEST_STRING_1); 39 | 40 | PASS(); 41 | } 42 | -------------------------------------------------------------------------------- /tests/get_alias.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_get_alias() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "tests.h" 29 | #include "testdata.h" 30 | 31 | static void check_alias(void *fdt, const char *path, const char *alias) 32 | { 33 | const char *aliaspath; 34 | 35 | aliaspath = fdt_get_alias(fdt, alias); 36 | 37 | if (path && !aliaspath) 38 | FAIL("fdt_get_alias(%s) failed\n", alias); 39 | 40 | if (strcmp(aliaspath, path) != 0) 41 | FAIL("fdt_get_alias(%s) returned %s instead of %s\n", 42 | alias, aliaspath, path); 43 | } 44 | 45 | int main(int argc, char *argv[]) 46 | { 47 | void *fdt; 48 | 49 | test_init(argc, argv); 50 | fdt = load_blob_arg(argc, argv); 51 | 52 | check_alias(fdt, "/subnode@1", "s1"); 53 | check_alias(fdt, "/subnode@1/subsubnode", "ss1"); 54 | check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "sss1"); 55 | 56 | PASS(); 57 | } 58 | -------------------------------------------------------------------------------- /tests/get_mem_rsv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_get_mem_rsv() and fdt_num_mem_rsv() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "tests.h" 29 | #include "testdata.h" 30 | 31 | int main(int argc, char *argv[]) 32 | { 33 | void *fdt; 34 | int rc; 35 | 36 | test_init(argc, argv); 37 | fdt = load_blob_arg(argc, argv); 38 | 39 | rc = fdt_num_mem_rsv(fdt); 40 | if (rc < 0) 41 | FAIL("fdt_num_mem_rsv(): %s", fdt_strerror(rc)); 42 | if (rc != 2) 43 | FAIL("fdt_num_mem_rsv() returned %d instead of 2", rc); 44 | 45 | check_mem_rsv(fdt, 0, TEST_ADDR_1, TEST_SIZE_1); 46 | check_mem_rsv(fdt, 1, TEST_ADDR_2, TEST_SIZE_2); 47 | PASS(); 48 | } 49 | -------------------------------------------------------------------------------- /tests/get_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_get_name() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | static void check_name(void *fdt, const char *path) 31 | { 32 | int offset; 33 | const char *getname, *getname2, *checkname; 34 | int len; 35 | 36 | checkname = strrchr(path, '/'); 37 | if (!checkname) 38 | TEST_BUG(); 39 | checkname += 1; 40 | 41 | offset = fdt_path_offset(fdt, path); 42 | if (offset < 0) 43 | FAIL("Couldn't find %s", path); 44 | 45 | getname = fdt_get_name(fdt, offset, &len); 46 | verbose_printf("fdt_get_name(%d) returns \"%s\" (len=%d)\n", 47 | offset, getname, len); 48 | if (!getname) 49 | FAIL("fdt_get_name(%d): %s", offset, fdt_strerror(len)); 50 | 51 | if (strcmp(getname, checkname) != 0) 52 | FAIL("fdt_get_name(%s) returned \"%s\" instead of \"%s\"", 53 | path, getname, checkname); 54 | 55 | if (len != strlen(getname)) 56 | FAIL("fdt_get_name(%s) returned length %d instead of %zd", 57 | path, len, strlen(getname)); 58 | 59 | /* Now check that it doesn't break if we omit len */ 60 | getname2 = fdt_get_name(fdt, offset, NULL); 61 | if (!getname2) 62 | FAIL("fdt_get_name(%d, NULL) failed", offset); 63 | if (strcmp(getname2, getname) != 0) 64 | FAIL("fdt_get_name(%d, NULL) returned \"%s\" instead of \"%s\"", 65 | offset, getname2, getname); 66 | } 67 | 68 | int main(int argc, char *argv[]) 69 | { 70 | void *fdt; 71 | 72 | test_init(argc, argv); 73 | fdt = load_blob_arg(argc, argv); 74 | 75 | check_name(fdt, "/"); 76 | check_name(fdt, "/subnode@1"); 77 | check_name(fdt, "/subnode@2"); 78 | check_name(fdt, "/subnode@1/subsubnode"); 79 | check_name(fdt, "/subnode@2/subsubnode@0"); 80 | 81 | PASS(); 82 | } 83 | -------------------------------------------------------------------------------- /tests/get_path.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_get_path() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | #define POISON ('\xff') 31 | 32 | static void check_path_buf(void *fdt, const char *path, int pathlen, int buflen) 33 | { 34 | int offset; 35 | char buf[buflen+1]; 36 | int len; 37 | 38 | offset = fdt_path_offset(fdt, path); 39 | if (offset < 0) 40 | FAIL("Couldn't find path \"%s\": %s", path, fdt_strerror(offset)); 41 | 42 | memset(buf, POISON, sizeof(buf)); /* poison the buffer */ 43 | 44 | len = fdt_get_path(fdt, offset, buf, buflen); 45 | verbose_printf("get_path() %s -> %d -> %s\n", path, offset, buf); 46 | 47 | if (buflen <= pathlen) { 48 | if (len != -FDT_ERR_NOSPACE) 49 | FAIL("fdt_get_path([%d bytes]) returns %d with " 50 | "insufficient buffer space", buflen, len); 51 | } else { 52 | if (len < 0) 53 | FAIL("fdt_get_path([%d bytes]): %s", buflen, 54 | fdt_strerror(len)); 55 | if (len != 0) 56 | FAIL("fdt_get_path([%d bytes]) returns %d " 57 | "instead of 0", buflen, len); 58 | if (strcmp(buf, path) != 0) 59 | FAIL("fdt_get_path([%d bytes]) returns \"%s\" " 60 | "instead of \"%s\"", buflen, buf, path); 61 | } 62 | 63 | if (buf[buflen] != POISON) 64 | FAIL("fdt_get_path([%d bytes]) overran buffer", buflen); 65 | } 66 | 67 | static void check_path(void *fdt, const char *path) 68 | { 69 | int pathlen = strlen(path); 70 | 71 | check_path_buf(fdt, path, pathlen, 1024); 72 | check_path_buf(fdt, path, pathlen, pathlen+1); 73 | check_path_buf(fdt, path, pathlen, pathlen); 74 | check_path_buf(fdt, path, pathlen, 0); 75 | check_path_buf(fdt, path, pathlen, 2); 76 | } 77 | 78 | int main(int argc, char *argv[]) 79 | { 80 | void *fdt; 81 | 82 | test_init(argc, argv); 83 | fdt = load_blob_arg(argc, argv); 84 | 85 | check_path(fdt, "/"); 86 | check_path(fdt, "/subnode@1"); 87 | check_path(fdt, "/subnode@2"); 88 | check_path(fdt, "/subnode@1/subsubnode"); 89 | check_path(fdt, "/subnode@2/subsubnode@0"); 90 | 91 | PASS(); 92 | } 93 | -------------------------------------------------------------------------------- /tests/get_phandle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_get_phandle() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | static void check_phandle(void *fdt, const char *path, uint32_t checkhandle) 31 | { 32 | int offset; 33 | uint32_t phandle; 34 | 35 | offset = fdt_path_offset(fdt, path); 36 | if (offset < 0) 37 | FAIL("Couldn't find %s", path); 38 | 39 | phandle = fdt_get_phandle(fdt, offset); 40 | if (phandle != checkhandle) 41 | FAIL("fdt_get_phandle(%s) returned 0x%x instead of 0x%x\n", 42 | path, phandle, checkhandle); 43 | } 44 | 45 | int main(int argc, char *argv[]) 46 | { 47 | uint32_t max; 48 | void *fdt; 49 | 50 | test_init(argc, argv); 51 | fdt = load_blob_arg(argc, argv); 52 | 53 | check_phandle(fdt, "/", 0); 54 | check_phandle(fdt, "/subnode@2", PHANDLE_1); 55 | check_phandle(fdt, "/subnode@2/subsubnode@0", PHANDLE_2); 56 | 57 | max = fdt_get_max_phandle(fdt); 58 | if (max != PHANDLE_2) 59 | FAIL("fdt_get_max_phandle returned 0x%x instead of 0x%x\n", 60 | max, PHANDLE_2); 61 | 62 | PASS(); 63 | } 64 | -------------------------------------------------------------------------------- /tests/getprop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_getprop() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "tests.h" 29 | #include "testdata.h" 30 | 31 | int main(int argc, char *argv[]) 32 | { 33 | void *fdt; 34 | 35 | test_init(argc, argv); 36 | fdt = load_blob_arg(argc, argv); 37 | 38 | check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1); 39 | check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1, TEST_STRING_1); 40 | 41 | PASS(); 42 | } 43 | -------------------------------------------------------------------------------- /tests/incbin.bin: -------------------------------------------------------------------------------- 1 | abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -------------------------------------------------------------------------------- /tests/incbin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for string escapes in dtc 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "tests.h" 29 | #include "testdata.h" 30 | 31 | #define CHUNKSIZE 1024 32 | 33 | static char *load_file(const char *name, int *len) 34 | { 35 | FILE *f; 36 | char *buf = NULL; 37 | int bufsize = 0, n; 38 | 39 | *len = 0; 40 | 41 | f = fopen(name, "r"); 42 | if (!f) 43 | FAIL("Couldn't open \"%s\": %s", name, strerror(errno)); 44 | 45 | while (!feof(f)) { 46 | if (bufsize < (*len + CHUNKSIZE)) { 47 | buf = xrealloc(buf, *len + CHUNKSIZE); 48 | bufsize = *len + CHUNKSIZE; 49 | } 50 | 51 | n = fread(buf + *len, 1, CHUNKSIZE, f); 52 | if (ferror(f)) 53 | FAIL("Error reading \"%s\": %s", name, strerror(errno)); 54 | *len += n; 55 | } 56 | 57 | return buf; 58 | } 59 | 60 | int main(int argc, char *argv[]) 61 | { 62 | void *fdt; 63 | char *incbin; 64 | int len; 65 | 66 | test_init(argc, argv); 67 | 68 | incbin = load_file("incbin.bin", &len); 69 | fdt = load_blob_arg(argc, argv); 70 | 71 | check_getprop(fdt, 0, "incbin", len, incbin); 72 | check_getprop(fdt, 0, "incbin-partial", 17, incbin + 13); 73 | 74 | PASS(); 75 | } 76 | -------------------------------------------------------------------------------- /tests/incbin.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | incbin = /incbin/("incbin.bin"); 5 | incbin-partial = /incbin/("incbin.bin", 13, 17); 6 | }; 7 | -------------------------------------------------------------------------------- /tests/include0.dts: -------------------------------------------------------------------------------- 1 | /include/ "include1.dts" 2 | -------------------------------------------------------------------------------- /tests/include1.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /include/ "include2.dts" 4 | /memreserve/ /include/ "include3.dts"; 5 | 6 | / { 7 | /include/ "include4.dts" 8 | /include/ "include5.dts" = <0xdeadbeef>; 9 | prop-int64 /include/ "include5a.dts"; 10 | prop-str = /include/ "include6.dts"; 11 | #address-cells = <1>; 12 | #size-cells = <0>; 13 | 14 | /include/ "include7.dts" 15 | 16 | subnode@2 { 17 | reg = <2>; 18 | linux,phandle = <0x2000>; 19 | prop-int = <123456789>; 20 | #address-cells = <1>; 21 | #size-cells = <0>; 22 | 23 | /include/ "include8.dts" 24 | phandle = <0x2001>; 25 | compatible = "subsubnode2", "subsubnode"; 26 | prop-int = <0726746425>; 27 | }; 28 | 29 | ss2 { 30 | }; 31 | }; 32 | }; 33 | -------------------------------------------------------------------------------- /tests/include2.dts: -------------------------------------------------------------------------------- 1 | /memreserve/ 0xdeadbeef00000000 0x100000; 2 | -------------------------------------------------------------------------------- /tests/include3.dts: -------------------------------------------------------------------------------- 1 | 123456789 010000 2 | -------------------------------------------------------------------------------- /tests/include4.dts: -------------------------------------------------------------------------------- 1 | compatible = "test_tree1"; 2 | -------------------------------------------------------------------------------- /tests/include5.dts: -------------------------------------------------------------------------------- 1 | prop-int 2 | -------------------------------------------------------------------------------- /tests/include5a.dts: -------------------------------------------------------------------------------- 1 | = /bits/ 64 <0xdeadbeef01abcdef> -------------------------------------------------------------------------------- /tests/include6.dts: -------------------------------------------------------------------------------- 1 | "hello world" 2 | -------------------------------------------------------------------------------- /tests/include7.dts: -------------------------------------------------------------------------------- 1 | subnode@1 { 2 | compatible = "subnode1"; 3 | reg = <1>; 4 | prop-int = [deadbeef]; 5 | 6 | subsubnode { 7 | compatible = "subsubnode1", "subsubnode"; 8 | placeholder = "this is a placeholder string", "string2"; 9 | prop-int = <0xdeadbeef>; 10 | }; 11 | 12 | ss1 { 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /tests/include8.dts: -------------------------------------------------------------------------------- 1 | subsubnode@0 { 2 | reg = <0>; 3 | -------------------------------------------------------------------------------- /tests/label01.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0x1000000000000000 0x0000000002000000; 4 | memrsv2: /memreserve/ 0x2000000000000000 0x0100000000000000; 5 | /memreserve/ 0x0000000000000000 0x0000000000000014; 6 | 7 | / { 8 | model = "MyBoardName"; 9 | compatible = "MyBoardName", "MyBoardFamilyName"; 10 | #address-cells = <2>; 11 | #size-cells = <2>; 12 | 13 | cpus { 14 | linux,phandle = <0x1>; 15 | #address-cells = <1>; 16 | #size-cells = <0>; 17 | PowerPC,970@0 { 18 | name = "PowerPC,970"; 19 | device_type = "cpu"; 20 | reg = <0x00000000>; 21 | clock-frequency = <1600000000>; 22 | timebase-frequency = <33333333>; 23 | linux,boot-cpu; 24 | i-cache-size = <65536>; 25 | d-cache-size = <32768>; 26 | }; 27 | 28 | PowerPC,970@1 { 29 | name = "PowerPC,970"; 30 | device_type = "cpu"; 31 | reg = <0x00000001>; 32 | clock-frequency = <1600000000>; 33 | timebase-frequency = <33333333>; 34 | i-cache-size = <65536>; 35 | d-cache-size = <32768>; 36 | }; 37 | 38 | }; 39 | 40 | node: randomnode { 41 | prop: string = str: "foo", str_mid: "stuffstuff\t\t\t\n\n\n" str_end: ; 42 | blob = [byte: 0a 0b 0c 0d byte_mid: de ea ad be ef byte_end: ]; 43 | ref = < cell: &{/memory@0} 0x0 cell_mid: 0xffffffff cell_end: >; 44 | mixed = "abc", pre: [1234] post: , gap: < aligned: 0xa 0xb 0xc>; 45 | tricky1 = [61 lt1: 62 63 00]; 46 | subnode: child { 47 | }; 48 | /* subnode_end: is auto-generated by node emit */ 49 | }; 50 | /* node_end: is auto-generated by node emit */ 51 | 52 | memory@0 { 53 | device_type = "memory"; 54 | memreg: reg = <0x00000000 0x00000000 0x00000000 0x20000000>; 55 | }; 56 | 57 | chosen { 58 | bootargs = "root=/dev/sda2"; 59 | linux,platform = <0x600>; 60 | }; 61 | 62 | }; 63 | 64 | -------------------------------------------------------------------------------- /tests/label_repeated.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | l0: prop = "foo"; 5 | 6 | l1: node { 7 | }; 8 | }; 9 | 10 | / { 11 | l0: prop = "foo"; 12 | 13 | l1: node { 14 | }; 15 | }; 16 | -------------------------------------------------------------------------------- /tests/line_directives.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /* common format */ 4 | #line 3 "foo.dts" 5 | /* newer gcc format */ 6 | # 9 "baz.dts" 1 7 | /* flags are optional */ 8 | # 6 "bar.dts" 9 | 10 | / { 11 | /* 12 | * Make sure optional flags don't consume integer data on next line. The issue 13 | * was that the {WS} in the trailing ({WS}+[0-9]+)? could cross the * line- 14 | * break, and consume the leading "0" of the hex constant, leaving "x12345678" 15 | * to be parsed as a number, which is invalid syntax. 16 | */ 17 | prop1 = < 18 | # 10 "qux.dts" 19 | 0x12345678 20 | >; 21 | /* 22 | * Check processing of escapes in filenames 23 | */ 24 | # 100 "\".dts" 25 | # 200 "\\.dts" 26 | }; 27 | -------------------------------------------------------------------------------- /tests/lorem.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris eros 2 | arcu, egestas non pellentesque non, euismod eu nibh. Proin arcu metus, 3 | dapibus vitae sodales rhoncus, suscipit vel nulla. Etiam lorem est, 4 | aliquam ut fringilla sit amet, condimentum et quam. Duis eu arcu odio, 5 | at pulvinar nisi. Morbi condimentum eros ut turpis rhoncus 6 | pharetra. Pellentesque habitant morbi tristique senectus et netus et 7 | malesuada fames ac turpis egestas. Nam et nulla enim. Etiam fringilla 8 | eleifend neque, at posuere ante lacinia a. Duis orci tortor, dictum ac 9 | gravida ac, euismod eu leo. Sed eget dolor tortor. Pellentesque 10 | venenatis, lectus eu vulputate porta, libero ipsum convallis mi, sit 11 | amet vehicula arcu elit sit amet odio. 12 | 13 | Fusce iaculis massa metus, id sagittis diam. Praesent molestie ante 14 | vel odio tincidunt auctor. Cum sociis natoque penatibus et magnis dis 15 | parturient montes, nascetur ridiculus mus. Duis rutrum vehicula nisl 16 | eget condimentum. In in justo nisl. Nullam id arcu at nisl eleifend 17 | pretium. Nulla interdum ligula id elit mollis dictum a sit amet 18 | quam. Nullam iaculis laoreet ipsum at tempus. Vestibulum in cursus 19 | dui. Curabitur porta lectus eget urna bibendum congue eget elementum 20 | nisi. Proin sit amet lectus ut neque iaculis consectetur eu sit amet 21 | nibh. Maecenas rhoncus dolor ac nunc gravida blandit. Fusce sem felis, 22 | aliquam a porttitor a, porta quis odio. 23 | 24 | Nunc purus lorem, sollicitudin non ultricies id, porta vitae 25 | enim. Nulla tristique gravida leo ut suscipit. Phasellus vitae turpis 26 | libero. Proin ac purus dolor, in suscipit magna. Sed et enim 27 | arcu. Morbi semper aliquet suscipit. Aenean laoreet condimentum massa, 28 | eu pharetra magna fermentum ut. Morbi euismod convallis tortor, eget 29 | fringilla lacus sagittis non. Nullam bibendum posuere feugiat. 30 | 31 | In at pulvinar massa. Mauris nunc lectus, mollis et malesuada 32 | pharetra, cursus sed lacus. Integer dolor urna, interdum a mollis at, 33 | vestibulum non nisl. Sed in urna tortor. Mauris arcu felis, volutpat 34 | quis euismod vel, congue sit amet ipsum. Morbi in aliquet purus. Duis 35 | cras amet. 36 | -------------------------------------------------------------------------------- /tests/mangle-layout.supp: -------------------------------------------------------------------------------- 1 | { 2 | uninitialized alignment gaps can be dumped to output 3 | Memcheck:Param 4 | write(buf) 5 | obj:/lib/ld-*.so 6 | fun:main 7 | } 8 | -------------------------------------------------------------------------------- /tests/minusone-phandle.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | node { 5 | linux,phandle = <0xffffffff>; 6 | }; 7 | }; 8 | -------------------------------------------------------------------------------- /tests/move_and_save.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Basic testcase for read-only access 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "tests.h" 30 | #include "testdata.h" 31 | 32 | int main(int argc, char *argv[]) 33 | { 34 | void *fdt, *fdt1, *fdt2, *fdt3; 35 | char *buf; 36 | int shuntsize; 37 | int bufsize; 38 | int err; 39 | const char *inname; 40 | char outname[PATH_MAX]; 41 | 42 | test_init(argc, argv); 43 | fdt = load_blob_arg(argc, argv); 44 | inname = argv[1]; 45 | 46 | shuntsize = ALIGN(fdt_totalsize(fdt) / 2, sizeof(uint64_t)); 47 | bufsize = fdt_totalsize(fdt) + shuntsize; 48 | buf = xmalloc(bufsize); 49 | 50 | fdt1 = buf; 51 | err = fdt_move(fdt, fdt1, bufsize); 52 | if (err) 53 | FAIL("Failed to move tree into new buffer: %s", 54 | fdt_strerror(err)); 55 | sprintf(outname, "moved.%s", inname); 56 | save_blob(outname, fdt1); 57 | 58 | fdt2 = buf + shuntsize; 59 | err = fdt_move(fdt1, fdt2, bufsize-shuntsize); 60 | if (err) 61 | FAIL("Failed to shunt tree %d bytes: %s", 62 | shuntsize, fdt_strerror(err)); 63 | sprintf(outname, "shunted.%s", inname); 64 | save_blob(outname, fdt2); 65 | 66 | fdt3 = buf; 67 | err = fdt_move(fdt2, fdt3, bufsize); 68 | if (err) 69 | FAIL("Failed to deshunt tree %d bytes: %s", 70 | shuntsize, fdt_strerror(err)); 71 | sprintf(outname, "deshunted.%s", inname); 72 | save_blob(outname, fdt3); 73 | 74 | PASS(); 75 | } 76 | -------------------------------------------------------------------------------- /tests/multilabel.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | m1: mq: /memreserve/ 0 0x1000; 4 | 5 | / { 6 | p0: pw: prop = "foo"; 7 | 8 | rref = <&{/}>; 9 | 10 | /* Explicit phandles */ 11 | n1: nx: node1 { 12 | linux,phandle = <0x2000>; 13 | ref = <&{/node2}>; /* reference precedes target */ 14 | p1: px: lref = <&ny>; 15 | }; 16 | ny: n2: node2 { 17 | p2: py: phandle = <0x1>; 18 | ref = <&{/node1}>; /* reference after target */ 19 | lref = <&nx>; 20 | }; 21 | 22 | /* Implicit phandles */ 23 | n3: node3 { 24 | p3: ref = <&{/node4}>; 25 | lref = <&n4>; 26 | }; 27 | n4: node4 { 28 | p4: prop; 29 | }; 30 | 31 | /* Explicit phandle with implicit value */ 32 | /* This self-reference is the standard way to tag a node as requiring 33 | * a phandle (perhaps for reference by nodes that will be dynamically 34 | * added) without explicitly allocating it a phandle. 35 | * The self-reference requires some special internal handling, though 36 | * so check it actually works */ 37 | n5: nz: node5 { 38 | linux,phandle = <&n5>; 39 | phandle = <&nz>; 40 | n1 = &n1; 41 | n2 = &n2; 42 | n3 = &n3; 43 | }; 44 | }; 45 | -------------------------------------------------------------------------------- /tests/multilabel_merge.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | m1: mq: /memreserve/ 0 0x1000; 4 | 5 | / { 6 | p0: pw: prop = "foo"; 7 | 8 | /* Explicit phandles */ 9 | n1: node1 { 10 | linux,phandle = <0x2000>; 11 | ref = <&{/node2}>; /* reference precedes target */ 12 | p1: lref; 13 | }; 14 | node2 { 15 | phandle = <0x1>; 16 | ref = <&{/node1}>; /* reference after target */ 17 | lref = <&nx>; 18 | }; 19 | 20 | /* Implicit phandles */ 21 | n3: node3 { 22 | p3: ref = <&{/node4}>; 23 | lref = <&n4>; 24 | }; 25 | n4: node4 { 26 | p4: prop = "foo"; 27 | }; 28 | 29 | /* Explicit phandle with implicit value */ 30 | /* This self-reference is the standard way to tag a node as requiring 31 | * a phandle (perhaps for reference by nodes that will be dynamically 32 | * added) without explicitly allocating it a phandle. 33 | * The self-reference requires some special internal handling, though 34 | * so check it actually works */ 35 | n5: nz: node5 { 36 | linux,phandle = <&n5>; 37 | phandle = <&nz>; 38 | n1 = &n1; 39 | n2 = &n2; 40 | n3 = &n3; 41 | }; 42 | }; 43 | 44 | / { 45 | /* Append labels (also changes property content) */ 46 | nx: node1 { 47 | px: lref = <&ny>; 48 | }; 49 | 50 | /* Add multiple labels */ 51 | ny: n2: node2 { 52 | /* Add a label to a property */ 53 | p2: py: phandle = <0x1>; 54 | }; 55 | 56 | /* Reassigning the same label should be a no-op */ 57 | n3: node3 { 58 | p3: ref = <&{/node4}>; 59 | }; 60 | 61 | /* Redefining a node/property should not remove labels */ 62 | node4 { 63 | prop; 64 | }; 65 | 66 | }; 67 | 68 | / { 69 | rref = <&{/}>; 70 | }; 71 | -------------------------------------------------------------------------------- /tests/node_check_compatible.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_node_check_compatible() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "tests.h" 29 | #include "testdata.h" 30 | 31 | static void check_compatible(const void *fdt, const char *path, 32 | const char *compat) 33 | { 34 | int offset, err; 35 | 36 | offset = fdt_path_offset(fdt, path); 37 | if (offset < 0) 38 | FAIL("fdt_path_offset(%s): %s", path, fdt_strerror(offset)); 39 | 40 | err = fdt_node_check_compatible(fdt, offset, compat); 41 | if (err < 0) 42 | FAIL("fdt_node_check_compatible(%s): %s", path, 43 | fdt_strerror(err)); 44 | if (err != 0) 45 | FAIL("%s is not compatible with \"%s\"", path, compat); 46 | } 47 | 48 | int main(int argc, char *argv[]) 49 | { 50 | void *fdt; 51 | 52 | test_init(argc, argv); 53 | fdt = load_blob_arg(argc, argv); 54 | 55 | check_compatible(fdt, "/", "test_tree1"); 56 | check_compatible(fdt, "/subnode@1/subsubnode", "subsubnode1"); 57 | check_compatible(fdt, "/subnode@1/subsubnode", "subsubnode"); 58 | check_compatible(fdt, "/subnode@2/subsubnode", "subsubnode2"); 59 | check_compatible(fdt, "/subnode@2/subsubnode", "subsubnode"); 60 | 61 | PASS(); 62 | } 63 | -------------------------------------------------------------------------------- /tests/node_offset_by_compatible.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_node_offset_by_compatible() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "tests.h" 29 | #include "testdata.h" 30 | 31 | static void check_search(void *fdt, const char *compat, ...) 32 | { 33 | va_list ap; 34 | int offset = -1, target; 35 | 36 | va_start(ap, compat); 37 | do { 38 | target = va_arg(ap, int); 39 | verbose_printf("Searching (target = %d): %d ->", 40 | target, offset); 41 | offset = fdt_node_offset_by_compatible(fdt, offset, compat); 42 | verbose_printf("%d\n", offset); 43 | 44 | if (offset != target) 45 | FAIL("fdt_node_offset_by_compatible(%s) returns %d " 46 | "instead of %d", compat, offset, target); 47 | } while (target >= 0); 48 | 49 | va_end(ap); 50 | } 51 | 52 | int main(int argc, char *argv[]) 53 | { 54 | void *fdt; 55 | int subnode1_offset, subnode2_offset; 56 | int subsubnode1_offset, subsubnode2_offset; 57 | 58 | test_init(argc, argv); 59 | fdt = load_blob_arg(argc, argv); 60 | 61 | subnode1_offset = fdt_path_offset(fdt, "/subnode@1"); 62 | subnode2_offset = fdt_path_offset(fdt, "/subnode@2"); 63 | subsubnode1_offset = fdt_path_offset(fdt, "/subnode@1/subsubnode"); 64 | subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode@0"); 65 | 66 | if ((subnode1_offset < 0) || (subnode2_offset < 0) 67 | || (subsubnode1_offset < 0) || (subsubnode2_offset < 0)) 68 | FAIL("Can't find required nodes"); 69 | 70 | check_search(fdt, "test_tree1", 0, -FDT_ERR_NOTFOUND); 71 | check_search(fdt, "subnode1", subnode1_offset, -FDT_ERR_NOTFOUND); 72 | check_search(fdt, "subsubnode1", subsubnode1_offset, -FDT_ERR_NOTFOUND); 73 | check_search(fdt, "subsubnode2", subsubnode2_offset, -FDT_ERR_NOTFOUND); 74 | /* Eek.. HACK to make this work whatever the order in the 75 | * example tree */ 76 | if (subsubnode1_offset < subsubnode2_offset) 77 | check_search(fdt, "subsubnode", subsubnode1_offset, 78 | subsubnode2_offset, -FDT_ERR_NOTFOUND); 79 | else 80 | check_search(fdt, "subsubnode", subsubnode2_offset, 81 | subsubnode1_offset, -FDT_ERR_NOTFOUND); 82 | check_search(fdt, "nothing-like-this", -FDT_ERR_NOTFOUND); 83 | 84 | PASS(); 85 | } 86 | -------------------------------------------------------------------------------- /tests/node_offset_by_phandle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_node_offset_by_phandle() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "tests.h" 29 | #include "testdata.h" 30 | 31 | static void check_search(void *fdt, uint32_t phandle, int target) 32 | { 33 | int offset; 34 | 35 | offset = fdt_node_offset_by_phandle(fdt, phandle); 36 | 37 | if (offset != target) 38 | FAIL("fdt_node_offset_by_phandle(0x%x) returns %d " 39 | "instead of %d", phandle, offset, target); 40 | } 41 | 42 | int main(int argc, char *argv[]) 43 | { 44 | void *fdt; 45 | int subnode2_offset, subsubnode2_offset; 46 | 47 | test_init(argc, argv); 48 | fdt = load_blob_arg(argc, argv); 49 | 50 | subnode2_offset = fdt_path_offset(fdt, "/subnode@2"); 51 | subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode@0"); 52 | 53 | if ((subnode2_offset < 0) || (subsubnode2_offset < 0)) 54 | FAIL("Can't find required nodes"); 55 | 56 | check_search(fdt, PHANDLE_1, subnode2_offset); 57 | check_search(fdt, PHANDLE_2, subsubnode2_offset); 58 | check_search(fdt, ~PHANDLE_1, -FDT_ERR_NOTFOUND); 59 | check_search(fdt, 0, -FDT_ERR_BADPHANDLE); 60 | check_search(fdt, -1, -FDT_ERR_BADPHANDLE); 61 | 62 | PASS(); 63 | } 64 | -------------------------------------------------------------------------------- /tests/nonexist-label-ref.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | ref = <&label>; 5 | badref = <&nosuchlabel>; 6 | label: node { 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /tests/nonexist-node-ref.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | ref = < &{/node} >; 5 | badref = < &{/nosuchnode} >; 6 | label: node { 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /tests/nonexist-node-ref2.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | label: node { 5 | }; 6 | }; 7 | 8 | /* Try to redefine a node using a non-existent label */ 9 | &nosuchnode { 10 | }; 11 | -------------------------------------------------------------------------------- /tests/nop_property.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_nop_property() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "tests.h" 30 | #include "testdata.h" 31 | 32 | int main(int argc, char *argv[]) 33 | { 34 | void *fdt; 35 | const uint32_t *intp; 36 | const char *strp; 37 | int err; 38 | int lenerr; 39 | 40 | test_init(argc, argv); 41 | fdt = load_blob_arg(argc, argv); 42 | 43 | intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1); 44 | verbose_printf("int value was 0x%08x\n", *intp); 45 | 46 | err = fdt_nop_property(fdt, 0, "prop-int"); 47 | if (err) 48 | FAIL("Failed to nop \"prop-int\": %s", fdt_strerror(err)); 49 | 50 | intp = fdt_getprop(fdt, 0, "prop-int", &lenerr); 51 | if (intp) 52 | FAIL("prop-int still present after nopping"); 53 | if (lenerr != -FDT_ERR_NOTFOUND) 54 | FAIL("Unexpected error on second getprop: %s", fdt_strerror(err)); 55 | 56 | strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1, 57 | TEST_STRING_1); 58 | verbose_printf("string value was \"%s\"\n", strp); 59 | err = fdt_nop_property(fdt, 0, "prop-str"); 60 | if (err) 61 | FAIL("Failed to nop \"prop-str\": %s", fdt_strerror(err)); 62 | 63 | strp = fdt_getprop(fdt, 0, "prop-str", &lenerr); 64 | if (strp) 65 | FAIL("prop-str still present after nopping"); 66 | if (lenerr != -FDT_ERR_NOTFOUND) 67 | FAIL("Unexpected error on second getprop: %s", fdt_strerror(err)); 68 | 69 | PASS(); 70 | } 71 | -------------------------------------------------------------------------------- /tests/nopulate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase/tool for rearranging blocks of a dtb 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "tests.h" 30 | #include "testdata.h" 31 | 32 | static int nopulate_struct(char *buf, const char *fdt) 33 | { 34 | int offset, nextoffset = 0; 35 | uint32_t tag; 36 | char *p; 37 | 38 | p = buf; 39 | 40 | do { 41 | offset = nextoffset; 42 | tag = fdt_next_tag(fdt, offset, &nextoffset); 43 | 44 | memcpy(p, (const char *)fdt + fdt_off_dt_struct(fdt) + offset, 45 | nextoffset - offset); 46 | p += nextoffset - offset; 47 | 48 | *((fdt32_t *)p) = cpu_to_fdt32(FDT_NOP); 49 | p += FDT_TAGSIZE; 50 | 51 | } while (tag != FDT_END); 52 | 53 | return p - buf; 54 | } 55 | 56 | int main(int argc, char *argv[]) 57 | { 58 | char *fdt, *fdt2, *buf; 59 | int newsize, struct_start, struct_end_old, struct_end_new, delta; 60 | const char *inname; 61 | char outname[PATH_MAX]; 62 | 63 | test_init(argc, argv); 64 | if (argc != 2) 65 | CONFIG("Usage: %s ", argv[0]); 66 | 67 | inname = argv[1]; 68 | fdt = load_blob(argv[1]); 69 | sprintf(outname, "noppy.%s", inname); 70 | 71 | if (fdt_version(fdt) < 17) 72 | FAIL("Can't deal with version <17"); 73 | 74 | buf = xmalloc(2 * fdt_size_dt_struct(fdt)); 75 | 76 | newsize = nopulate_struct(buf, fdt); 77 | 78 | verbose_printf("Nopulated structure block has new size %d\n", newsize); 79 | 80 | /* Replace old strcutre block with the new */ 81 | 82 | fdt2 = xmalloc(fdt_totalsize(fdt) + newsize); 83 | 84 | struct_start = fdt_off_dt_struct(fdt); 85 | delta = newsize - fdt_size_dt_struct(fdt); 86 | struct_end_old = struct_start + fdt_size_dt_struct(fdt); 87 | struct_end_new = struct_start + newsize; 88 | 89 | memcpy(fdt2, fdt, struct_start); 90 | memcpy(fdt2 + struct_start, buf, newsize); 91 | memcpy(fdt2 + struct_end_new, fdt + struct_end_old, 92 | fdt_totalsize(fdt) - struct_end_old); 93 | 94 | fdt_set_totalsize(fdt2, fdt_totalsize(fdt) + delta); 95 | fdt_set_size_dt_struct(fdt2, newsize); 96 | 97 | if (fdt_off_mem_rsvmap(fdt) > struct_start) 98 | fdt_set_off_mem_rsvmap(fdt2, fdt_off_mem_rsvmap(fdt) + delta); 99 | if (fdt_off_dt_strings(fdt) > struct_start) 100 | fdt_set_off_dt_strings(fdt2, fdt_off_dt_strings(fdt) + delta); 101 | 102 | save_blob(outname, fdt2); 103 | 104 | PASS(); 105 | } 106 | -------------------------------------------------------------------------------- /tests/notfound.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for behaviour on searching for a non-existent node 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | static void check_error(const char *s, int err) 31 | { 32 | if (err != -FDT_ERR_NOTFOUND) 33 | FAIL("%s return error %s instead of -FDT_ERR_NOTFOUND", s, 34 | fdt_strerror(err)); 35 | } 36 | 37 | int main(int argc, char *argv[]) 38 | { 39 | void *fdt; 40 | int offset; 41 | int subnode1_offset; 42 | int lenerr; 43 | 44 | test_init(argc, argv); 45 | fdt = load_blob_arg(argc, argv); 46 | 47 | fdt_get_property(fdt, 0, "nonexistant-property", &lenerr); 48 | check_error("fdt_get_property(\"nonexistant-property\")", lenerr); 49 | 50 | fdt_getprop(fdt, 0, "nonexistant-property", &lenerr); 51 | check_error("fdt_getprop(\"nonexistant-property\"", lenerr); 52 | 53 | subnode1_offset = fdt_subnode_offset(fdt, 0, "subnode@1"); 54 | if (subnode1_offset < 0) 55 | FAIL("Couldn't find subnode1: %s", fdt_strerror(subnode1_offset)); 56 | 57 | fdt_getprop(fdt, subnode1_offset, "prop-str", &lenerr); 58 | check_error("fdt_getprop(\"prop-str\")", lenerr); 59 | 60 | offset = fdt_subnode_offset(fdt, 0, "nonexistant-subnode"); 61 | check_error("fdt_subnode_offset(\"nonexistant-subnode\")", offset); 62 | 63 | offset = fdt_subnode_offset(fdt, 0, "subsubnode"); 64 | check_error("fdt_subnode_offset(\"subsubnode\")", offset); 65 | 66 | offset = fdt_path_offset(fdt, "/nonexistant-subnode"); 67 | check_error("fdt_path_offset(\"/nonexistant-subnode\")", offset); 68 | 69 | PASS(); 70 | } 71 | -------------------------------------------------------------------------------- /tests/nul-in-escape.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | x = "\"; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/nul-in-line-info1.dts: -------------------------------------------------------------------------------- 1 | # 0 "" 2 | -------------------------------------------------------------------------------- /tests/nul-in-line-info2.dts: -------------------------------------------------------------------------------- 1 | # 0 "\0" 2 | -------------------------------------------------------------------------------- /tests/obsolete-chosen-interrupt-controller.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = <1>; 5 | #size-cells = <1>; 6 | PIC: pic@0 { 7 | reg = <0x0 0x10>; 8 | interrupt-controller; 9 | }; 10 | chosen { 11 | interrupt-controller = <&PIC>; 12 | }; 13 | }; 14 | -------------------------------------------------------------------------------- /tests/open_pack.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Basic testcase for read-only access 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "tests.h" 30 | #include "testdata.h" 31 | 32 | int main(int argc, char *argv[]) 33 | { 34 | void *fdt, *fdt1; 35 | void *buf; 36 | int oldsize, bufsize, packsize; 37 | int err; 38 | const char *inname; 39 | char outname[PATH_MAX]; 40 | 41 | test_init(argc, argv); 42 | fdt = load_blob_arg(argc, argv); 43 | inname = argv[1]; 44 | 45 | oldsize = fdt_totalsize(fdt); 46 | 47 | bufsize = oldsize * 2; 48 | 49 | buf = xmalloc(bufsize); 50 | /* don't leak uninitialized memory into our output */ 51 | memset(buf, 0, bufsize); 52 | 53 | fdt1 = buf; 54 | err = fdt_open_into(fdt, fdt1, bufsize); 55 | if (err) 56 | FAIL("fdt_open_into(): %s", fdt_strerror(err)); 57 | sprintf(outname, "opened.%s", inname); 58 | save_blob(outname, fdt1); 59 | 60 | err = fdt_pack(fdt1); 61 | if (err) 62 | FAIL("fdt_pack(): %s", fdt_strerror(err)); 63 | sprintf(outname, "repacked.%s", inname); 64 | save_blob(outname, fdt1); 65 | 66 | packsize = fdt_totalsize(fdt1); 67 | 68 | verbose_printf("oldsize = %d, bufsize = %d, packsize = %d\n", 69 | oldsize, bufsize, packsize); 70 | PASS(); 71 | } 72 | -------------------------------------------------------------------------------- /tests/open_pack.supp: -------------------------------------------------------------------------------- 1 | { 2 | opened blob dumps uninitialized data 3 | Memcheck:Param 4 | write(buf) 5 | obj:/lib/ld-*.so 6 | fun:main 7 | } 8 | -------------------------------------------------------------------------------- /tests/overlay_bad_fixup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for DT overlays() 4 | * Copyright (C) 2016 Free Electrons 5 | * Copyright (C) 2016 NextThing Co. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public License 9 | * as published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include "tests.h" 27 | 28 | #define CHECK(code, expected) \ 29 | { \ 30 | err = (code); \ 31 | if (err != expected) \ 32 | FAIL(#code ": %s", fdt_strerror(err)); \ 33 | } 34 | 35 | /* 4k ought to be enough for anybody */ 36 | #define FDT_COPY_SIZE (4 * 1024) 37 | 38 | static void *open_dt(char *path) 39 | { 40 | void *dt, *copy; 41 | int err; 42 | 43 | dt = load_blob(path); 44 | copy = xmalloc(FDT_COPY_SIZE); 45 | 46 | /* 47 | * Resize our DTs to 4k so that we have room to operate on 48 | */ 49 | CHECK(fdt_open_into(dt, copy, FDT_COPY_SIZE), 0); 50 | 51 | return copy; 52 | } 53 | 54 | int main(int argc, char *argv[]) 55 | { 56 | void *fdt_base, *fdt_overlay; 57 | int err; 58 | 59 | test_init(argc, argv); 60 | if (argc != 3) 61 | CONFIG("Usage: %s ", argv[0]); 62 | 63 | fdt_base = open_dt(argv[1]); 64 | fdt_overlay = open_dt(argv[2]); 65 | 66 | /* Apply the overlay */ 67 | CHECK(fdt_overlay_apply(fdt_base, fdt_overlay), -FDT_ERR_BADOVERLAY); 68 | 69 | PASS(); 70 | } 71 | -------------------------------------------------------------------------------- /tests/overlay_bad_fixup_bad_index.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * 5 | * SPDX-License-Identifier: GPL-2.0+ 6 | */ 7 | 8 | /include/ "overlay_bad_fixup_base.dtsi" 9 | 10 | / { 11 | __fixups__ { 12 | test = "/fragment@0:target:ab"; 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /tests/overlay_bad_fixup_base.dtsi: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * 5 | * SPDX-License-Identifier: GPL-2.0+ 6 | */ 7 | 8 | /dts-v1/; 9 | 10 | / { 11 | fragment@0 { 12 | target = <0xffffffff>; 13 | 14 | __overlay__ { 15 | test-property; 16 | }; 17 | }; 18 | }; 19 | -------------------------------------------------------------------------------- /tests/overlay_bad_fixup_empty.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * 5 | * SPDX-License-Identifier: GPL-2.0+ 6 | */ 7 | 8 | /include/ "overlay_bad_fixup_base.dtsi" 9 | 10 | / { 11 | __fixups__ { 12 | test = ""; 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /tests/overlay_bad_fixup_empty_index.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * 5 | * SPDX-License-Identifier: GPL-2.0+ 6 | */ 7 | 8 | /include/ "overlay_bad_fixup_base.dtsi" 9 | 10 | / { 11 | __fixups__ { 12 | test = "/fragment@0:target:"; 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /tests/overlay_bad_fixup_index_trailing.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * 5 | * SPDX-License-Identifier: GPL-2.0+ 6 | */ 7 | 8 | /include/ "overlay_bad_fixup_base.dtsi" 9 | 10 | / { 11 | __fixups__ { 12 | test = "/fragment@0:target:0a"; 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /tests/overlay_bad_fixup_path_empty_prop.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * 5 | * SPDX-License-Identifier: GPL-2.0+ 6 | */ 7 | 8 | /include/ "overlay_bad_fixup_base.dtsi" 9 | 10 | / { 11 | __fixups__ { 12 | test = "/fragment@0::"; 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /tests/overlay_bad_fixup_path_only.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * 5 | * SPDX-License-Identifier: GPL-2.0+ 6 | */ 7 | 8 | /include/ "overlay_bad_fixup_base.dtsi" 9 | 10 | / { 11 | __fixups__ { 12 | test = "/fragment@0"; 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /tests/overlay_bad_fixup_path_only_sep.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * 5 | * SPDX-License-Identifier: GPL-2.0+ 6 | */ 7 | 8 | /include/ "overlay_bad_fixup_base.dtsi" 9 | 10 | / { 11 | __fixups__ { 12 | test = "/fragment@0:"; 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /tests/overlay_bad_fixup_path_prop.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * 5 | * SPDX-License-Identifier: GPL-2.0+ 6 | */ 7 | 8 | /include/ "overlay_bad_fixup_base.dtsi" 9 | 10 | / { 11 | __fixups__ { 12 | test = "/fragment@0:target"; 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /tests/overlay_base.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * 5 | * SPDX-License-Identifier: GPL-2.0+ 6 | */ 7 | 8 | /dts-v1/; 9 | 10 | / { 11 | test: test-node { 12 | test-int-property = <42>; 13 | test-str-property = "foo"; 14 | 15 | subtest: sub-test-node { 16 | sub-test-property; 17 | }; 18 | }; 19 | }; 20 | 21 | 22 | -------------------------------------------------------------------------------- /tests/overlay_base_manual_symbols.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * 5 | * SPDX-License-Identifier: GPL-2.0+ 6 | */ 7 | 8 | /dts-v1/; 9 | 10 | / { 11 | test: test-node { 12 | phandle = <&test>; /* Force phandle generation */ 13 | test-int-property = <42>; 14 | test-str-property = "foo"; 15 | 16 | subtest: sub-test-node { 17 | sub-test-property; 18 | }; 19 | }; 20 | __symbols__ { 21 | test = &test; 22 | }; 23 | }; 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/overlay_overlay.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * Copyright (c) 2016 Konsulko Inc. 5 | * 6 | * SPDX-License-Identifier: GPL-2.0+ 7 | */ 8 | 9 | /dts-v1/; 10 | /plugin/; 11 | 12 | / { 13 | /* Test that we can change an int by another */ 14 | fragment@0 { 15 | target = <&test>; 16 | 17 | __overlay__ { 18 | test-int-property = <43>; 19 | }; 20 | }; 21 | 22 | /* Test that we can replace a string by a longer one */ 23 | fragment@1 { 24 | target = <&test>; 25 | 26 | __overlay__ { 27 | test-str-property = "foobar"; 28 | }; 29 | }; 30 | 31 | /* Test that we add a new property */ 32 | fragment@2 { 33 | target = <&test>; 34 | 35 | __overlay__ { 36 | test-str-property-2 = "foobar2"; 37 | }; 38 | }; 39 | 40 | /* Test that we add a new node (by phandle) */ 41 | fragment@3 { 42 | target = <&test>; 43 | 44 | __overlay__ { 45 | new-node { 46 | new-property; 47 | }; 48 | }; 49 | }; 50 | 51 | fragment@5 { 52 | target = <&test>; 53 | 54 | __overlay__ { 55 | local: new-local-node { 56 | new-property; 57 | }; 58 | }; 59 | }; 60 | 61 | fragment@6 { 62 | target = <&test>; 63 | 64 | __overlay__ { 65 | test-phandle = <&test>, <&local>; 66 | }; 67 | }; 68 | 69 | fragment@7 { 70 | target = <&test>; 71 | 72 | __overlay__ { 73 | test-several-phandle = <&local>, <&local>; 74 | }; 75 | }; 76 | 77 | fragment@8 { 78 | target = <&test>; 79 | 80 | __overlay__ { 81 | sub-test-node { 82 | new-sub-test-property; 83 | }; 84 | }; 85 | }; 86 | }; 87 | -------------------------------------------------------------------------------- /tests/overlay_overlay_manual_fixups.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * Copyright (c) 2016 Konsulko Inc. 5 | * 6 | * SPDX-License-Identifier: GPL-2.0+ 7 | */ 8 | 9 | /dts-v1/; 10 | 11 | /* Note no /plugin/ tag - we're manually generating the metadata for 12 | testing purposes */ 13 | 14 | / { 15 | /* Test that we can change an int by another */ 16 | fragment@0 { 17 | target = <0xffffffff /*&test*/>; 18 | 19 | __overlay__ { 20 | test-int-property = <43>; 21 | }; 22 | }; 23 | 24 | /* Test that we can replace a string by a longer one */ 25 | fragment@1 { 26 | target = <0xffffffff /*&test*/>; 27 | 28 | __overlay__ { 29 | test-str-property = "foobar"; 30 | }; 31 | }; 32 | 33 | /* Test that we add a new property */ 34 | fragment@2 { 35 | target = <0xffffffff /*&test*/>; 36 | 37 | __overlay__ { 38 | test-str-property-2 = "foobar2"; 39 | }; 40 | }; 41 | 42 | /* Test that we add a new node (by phandle) */ 43 | fragment@3 { 44 | target = <0xffffffff /*&test*/>; 45 | 46 | __overlay__ { 47 | new-node { 48 | new-property; 49 | }; 50 | }; 51 | }; 52 | 53 | fragment@5 { 54 | target = <0xffffffff /*&test*/>; 55 | 56 | __overlay__ { 57 | local: new-local-node { 58 | new-property; 59 | }; 60 | }; 61 | }; 62 | 63 | fragment@6 { 64 | target = <0xffffffff /*&test*/>; 65 | 66 | __overlay__ { 67 | test-phandle = <0xffffffff /*&test*/>, <&local>; 68 | }; 69 | }; 70 | 71 | fragment@7 { 72 | target = <0xffffffff /*&test*/>; 73 | 74 | __overlay__ { 75 | test-several-phandle = <&local>, <&local>; 76 | }; 77 | }; 78 | 79 | fragment@8 { 80 | target = <0xffffffff /*&test*/>; 81 | 82 | __overlay__ { 83 | sub-test-node { 84 | new-sub-test-property; 85 | }; 86 | }; 87 | }; 88 | 89 | __local_fixups__ { 90 | fragment@6 { 91 | __overlay__ { 92 | test-phandle = <4>; 93 | }; 94 | }; 95 | fragment@7 { 96 | __overlay__ { 97 | test-several-phandle = <0 4>; 98 | }; 99 | }; 100 | }; 101 | __fixups__ { 102 | test = "/fragment@0:target:0", 103 | "/fragment@1:target:0", 104 | "/fragment@2:target:0", 105 | "/fragment@3:target:0", 106 | "/fragment@5:target:0", 107 | "/fragment@6:target:0", 108 | "/fragment@6/__overlay__:test-phandle:0", 109 | "/fragment@7:target:0", 110 | "/fragment@8:target:0"; 111 | }; 112 | }; 113 | -------------------------------------------------------------------------------- /tests/overlay_overlay_no_fixups.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 NextThing Co 3 | * Copyright (c) 2016 Free Electrons 4 | * 5 | * SPDX-License-Identifier: GPL-2.0+ 6 | */ 7 | 8 | /dts-v1/; 9 | 10 | / { 11 | fragment@0 { 12 | target-path = "/test-node"; 13 | 14 | __overlay__ { 15 | test-int-property = <43>; 16 | }; 17 | }; 18 | 19 | /* Test that we can replace a string by a longer one */ 20 | fragment@1 { 21 | target-path = "/test-node"; 22 | 23 | __overlay__ { 24 | test-str-property = "foobar"; 25 | }; 26 | }; 27 | 28 | /* Test that we add a new property */ 29 | fragment@2 { 30 | target-path = "/test-node"; 31 | 32 | __overlay__ { 33 | test-str-property-2 = "foobar2"; 34 | }; 35 | }; 36 | 37 | fragment@3 { 38 | target-path = "/test-node"; 39 | 40 | __overlay__ { 41 | new-node { 42 | new-property; 43 | }; 44 | }; 45 | }; 46 | 47 | fragment@4 { 48 | target-path = "/"; 49 | 50 | __overlay__ { 51 | local: new-local-node { 52 | new-property; 53 | }; 54 | }; 55 | }; 56 | 57 | fragment@5 { 58 | target-path = "/"; 59 | 60 | __overlay__ { 61 | test-several-phandle = <&local>, <&local>; 62 | }; 63 | }; 64 | 65 | fragment@6 { 66 | target-path = "/test-node"; 67 | 68 | __overlay__ { 69 | sub-test-node { 70 | new-sub-test-property; 71 | }; 72 | }; 73 | }; 74 | 75 | __local_fixups__ { 76 | fragment@5 { 77 | __overlay__ { 78 | test-several-phandle = <0 4>; 79 | }; 80 | }; 81 | }; 82 | }; 83 | -------------------------------------------------------------------------------- /tests/overlay_overlay_simple.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Konsulko Inc. 3 | * 4 | * SPDX-License-Identifier: GPL-2.0+ 5 | */ 6 | 7 | /dts-v1/; 8 | /plugin/; 9 | 10 | &test { 11 | test-int-property = <43>; 12 | }; 13 | -------------------------------------------------------------------------------- /tests/parent_offset.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_parent_offset() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | static int path_parent_len(const char *path) 31 | { 32 | const char *p = strrchr(path, '/'); 33 | 34 | if (!p) 35 | TEST_BUG(); 36 | if (p == path) 37 | return 1; 38 | else 39 | return p - path; 40 | } 41 | 42 | static void check_path(struct fdt_header *fdt, const char *path) 43 | { 44 | char *parentpath; 45 | int nodeoffset, parentoffset, parentpathoffset, pathparentlen; 46 | 47 | pathparentlen = path_parent_len(path); 48 | parentpath = alloca(pathparentlen + 1); 49 | strncpy(parentpath, path, pathparentlen); 50 | parentpath[pathparentlen] = '\0'; 51 | 52 | verbose_printf("Path: \"%s\"\tParent: \"%s\"\n", path, parentpath); 53 | 54 | nodeoffset = fdt_path_offset(fdt, path); 55 | if (nodeoffset < 0) 56 | FAIL("fdt_path_offset(%s): %s", path, fdt_strerror(nodeoffset)); 57 | 58 | parentpathoffset = fdt_path_offset(fdt, parentpath); 59 | if (parentpathoffset < 0) 60 | FAIL("fdt_path_offset(%s): %s", parentpath, 61 | fdt_strerror(parentpathoffset)); 62 | 63 | parentoffset = fdt_parent_offset(fdt, nodeoffset); 64 | if (parentoffset < 0) 65 | FAIL("fdt_parent_offset(): %s", fdt_strerror(parentoffset)); 66 | 67 | if (parentoffset != parentpathoffset) 68 | FAIL("fdt_parent_offset() returns %d instead of %d", 69 | parentoffset, parentpathoffset); 70 | } 71 | 72 | int main(int argc, char *argv[]) 73 | { 74 | void *fdt; 75 | int err; 76 | 77 | test_init(argc, argv); 78 | fdt = load_blob_arg(argc, argv); 79 | 80 | check_path(fdt, "/subnode@1"); 81 | check_path(fdt, "/subnode@2"); 82 | check_path(fdt, "/subnode@1/subsubnode"); 83 | check_path(fdt, "/subnode@2/subsubnode@0"); 84 | err = fdt_parent_offset(fdt, 0); 85 | if (err != -FDT_ERR_NOTFOUND) 86 | FAIL("fdt_parent_offset(/) returns %d instead of " 87 | "-FDT_ERR_NOTFOUND", err); 88 | 89 | PASS(); 90 | } 91 | -------------------------------------------------------------------------------- /tests/path-references.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for string references in dtc 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | static void check_ref(const void *fdt, int node, const char *checkpath) 31 | { 32 | const char *p; 33 | int len; 34 | 35 | p = fdt_getprop(fdt, node, "ref", &len); 36 | if (!p) 37 | FAIL("fdt_getprop(%d, \"ref\"): %s", node, fdt_strerror(len)); 38 | if (!streq(p, checkpath)) 39 | FAIL("'ref' in node at %d has value \"%s\" instead of \"%s\"", 40 | node, p, checkpath); 41 | 42 | p = fdt_getprop(fdt, node, "lref", &len); 43 | if (!p) 44 | FAIL("fdt_getprop(%d, \"lref\"): %s", node, fdt_strerror(len)); 45 | if (!streq(p, checkpath)) 46 | FAIL("'lref' in node at %d has value \"%s\" instead of \"%s\"", 47 | node, p, checkpath); 48 | } 49 | 50 | static void check_rref(const void *fdt) 51 | { 52 | const char *p; 53 | int len; 54 | 55 | /* Check reference to root node */ 56 | p = fdt_getprop(fdt, 0, "rref", &len); 57 | if (!p) 58 | FAIL("fdt_getprop(0, \"rref\"): %s", fdt_strerror(len)); 59 | if (!streq(p, "/")) 60 | FAIL("'rref' in root node has value \"%s\" instead of \"/\"", 61 | p); 62 | } 63 | 64 | int main(int argc, char *argv[]) 65 | { 66 | void *fdt; 67 | const char *p; 68 | int len, multilen; 69 | int n1, n2, n3, n4; 70 | 71 | test_init(argc, argv); 72 | fdt = load_blob_arg(argc, argv); 73 | 74 | n1 = fdt_path_offset(fdt, "/node1"); 75 | if (n1 < 0) 76 | FAIL("fdt_path_offset(/node1): %s", fdt_strerror(n1)); 77 | n2 = fdt_path_offset(fdt, "/node2"); 78 | if (n2 < 0) 79 | FAIL("fdt_path_offset(/node2): %s", fdt_strerror(n2)); 80 | 81 | check_ref(fdt, n1, "/node2"); 82 | check_ref(fdt, n2, "/node1"); 83 | 84 | /* Check multiple reference */ 85 | multilen = strlen("/node1") + strlen("/node2") + 2; 86 | p = fdt_getprop(fdt, 0, "multiref", &len); 87 | if (!p) 88 | FAIL("fdt_getprop(0, \"multiref\"): %s", fdt_strerror(len)); 89 | if (len != multilen) 90 | FAIL("multiref has wrong length, %d instead of %d", 91 | len, multilen); 92 | if ((!streq(p, "/node1") || !streq(p + strlen("/node1") + 1, "/node2"))) 93 | FAIL("multiref has wrong value"); 94 | 95 | /* Check reference to nested nodes with common prefix */ 96 | n3 = fdt_path_offset(fdt, "/foo/baz"); 97 | if (n3 < 0) 98 | FAIL("fdt_path_offset(/foo/baz): %s", fdt_strerror(n3)); 99 | n4 = fdt_path_offset(fdt, "/foobar/baz"); 100 | if (n4 < 0) 101 | FAIL("fdt_path_offset(/foobar/baz): %s", fdt_strerror(n4)); 102 | check_ref(fdt, n3, "/foobar/baz"); 103 | check_ref(fdt, n4, "/foo/baz"); 104 | 105 | check_rref(fdt); 106 | 107 | PASS(); 108 | } 109 | -------------------------------------------------------------------------------- /tests/path-references.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | rref = &{/}; 5 | /* Check multiple references case */ 6 | multiref = &n1 , &n2; 7 | n1: node1 { 8 | ref = &{/node2}; /* reference precedes target */ 9 | lref = &n2; 10 | }; 11 | n2: node2 { 12 | ref = &{/node1}; /* reference after target */ 13 | lref = &n1; 14 | }; 15 | /* Check references to nested nodes with common prefix */ 16 | foobar { 17 | n3: baz { 18 | ref = &{/foo/baz}; 19 | lref = &n4; 20 | }; 21 | }; 22 | foo { 23 | n4: baz { 24 | ref = &{/foobar/baz}; 25 | lref = &n3; 26 | }; 27 | }; 28 | }; 29 | -------------------------------------------------------------------------------- /tests/path_offset_aliases.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_path_offset() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * Copyright 2008 Kumar Gala, Freescale Semiconductor, Inc. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public License 9 | * as published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "tests.h" 29 | #include "testdata.h" 30 | 31 | static void check_alias(void *fdt, const char *full_path, const char *alias_path) 32 | { 33 | int offset, offset_a; 34 | 35 | offset = fdt_path_offset(fdt, full_path); 36 | offset_a = fdt_path_offset(fdt, alias_path); 37 | 38 | if (offset != offset_a) 39 | FAIL("Mismatch between %s path_offset (%d) and %s path_offset alias (%d)", 40 | full_path, offset, alias_path, offset_a); 41 | } 42 | 43 | int main(int argc, char *argv[]) 44 | { 45 | void *fdt; 46 | 47 | test_init(argc, argv); 48 | fdt = load_blob_arg(argc, argv); 49 | 50 | check_alias(fdt, "/subnode@1", "s1"); 51 | check_alias(fdt, "/subnode@1/subsubnode", "ss1"); 52 | check_alias(fdt, "/subnode@1/subsubnode", "s1/subsubnode"); 53 | check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "sss1"); 54 | check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "ss1/subsubsubnode"); 55 | check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "s1/subsubnode/subsubsubnode"); 56 | 57 | PASS(); 58 | } 59 | -------------------------------------------------------------------------------- /tests/phandle_format.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for phandle format options 4 | * Copyright (C) 2009 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | #define PHANDLE_LEGACY 0x1 31 | #define PHANDLE_EPAPR 0x2 32 | #define PHANDLE_BOTH 0x3 33 | 34 | int main(int argc, char *argv[]) 35 | { 36 | void *fdt; 37 | int phandle_format; 38 | int n4; 39 | uint32_t h4; 40 | 41 | if (argc != 3) 42 | CONFIG("Usage: %s \n", argv[0]); 43 | 44 | test_init(argc, argv); 45 | fdt = load_blob(argv[1]); 46 | 47 | if (streq(argv[2], "legacy")) 48 | phandle_format = PHANDLE_LEGACY; 49 | else if (streq(argv[2], "epapr")) 50 | phandle_format = PHANDLE_EPAPR; 51 | else if (streq(argv[2], "both")) 52 | phandle_format = PHANDLE_BOTH; 53 | else 54 | CONFIG("Usage: %s \n", argv[0]); 55 | 56 | n4 = fdt_path_offset(fdt, "/node4"); 57 | if (n4 < 0) 58 | FAIL("fdt_path_offset(/node4): %s", fdt_strerror(n4)); 59 | 60 | h4 = fdt_get_phandle(fdt, n4); 61 | if ((h4 == 0) || (h4 == -1)) 62 | FAIL("/node4 has bad phandle 0x%x\n", h4); 63 | 64 | if (phandle_format & PHANDLE_LEGACY) 65 | check_getprop_cell(fdt, n4, "linux,phandle", h4); 66 | else 67 | if (fdt_getprop(fdt, n4, "linux,phandle", NULL)) 68 | FAIL("linux,phandle property present in non-legacy mode"); 69 | 70 | if (phandle_format & PHANDLE_EPAPR) 71 | check_getprop_cell(fdt, n4, "phandle", h4); 72 | else 73 | if (fdt_getprop(fdt, n4, "phandle", NULL)) 74 | FAIL("phandle property present in legacy-only mode"); 75 | 76 | PASS(); 77 | } 78 | -------------------------------------------------------------------------------- /tests/prop-after-subnode.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | node1 { 5 | }; 6 | prop; 7 | node2 { 8 | }; 9 | }; 10 | -------------------------------------------------------------------------------- /tests/property_iterate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Tests that fdt_next_subnode() works as expected 4 | * 5 | * Copyright (C) 2013 Google, Inc 6 | * 7 | * Copyright (C) 2007 David Gibson, IBM Corporation. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public License 11 | * as published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include "tests.h" 32 | #include "testdata.h" 33 | 34 | static void test_node(void *fdt, int parent_offset) 35 | { 36 | uint32_t properties; 37 | const fdt32_t *prop; 38 | int offset, property; 39 | int count; 40 | int len; 41 | 42 | /* 43 | * This property indicates the number of properties in our 44 | * test node to expect 45 | */ 46 | prop = fdt_getprop(fdt, parent_offset, "test-properties", &len); 47 | if (!prop || len != sizeof(fdt32_t)) { 48 | FAIL("Missing/invalid test-properties property at '%s'", 49 | fdt_get_name(fdt, parent_offset, NULL)); 50 | } 51 | properties = fdt32_to_cpu(*prop); 52 | 53 | count = 0; 54 | offset = fdt_first_subnode(fdt, parent_offset); 55 | if (offset < 0) 56 | FAIL("Missing test node\n"); 57 | 58 | fdt_for_each_property_offset(property, fdt, offset) 59 | count++; 60 | 61 | if (count != properties) { 62 | FAIL("Node '%s': Expected %d properties, got %d\n", 63 | fdt_get_name(fdt, parent_offset, NULL), properties, 64 | count); 65 | } 66 | } 67 | 68 | static void check_fdt_next_subnode(void *fdt) 69 | { 70 | int offset; 71 | int count = 0; 72 | 73 | fdt_for_each_subnode(offset, fdt, 0) { 74 | test_node(fdt, offset); 75 | count++; 76 | } 77 | 78 | if (count != 2) 79 | FAIL("Expected %d tests, got %d\n", 2, count); 80 | } 81 | 82 | int main(int argc, char *argv[]) 83 | { 84 | void *fdt; 85 | 86 | test_init(argc, argv); 87 | if (argc != 2) 88 | CONFIG("Usage: %s ", argv[0]); 89 | 90 | fdt = load_blob(argv[1]); 91 | if (!fdt) 92 | FAIL("No device tree available"); 93 | 94 | check_fdt_next_subnode(fdt); 95 | 96 | PASS(); 97 | } 98 | -------------------------------------------------------------------------------- /tests/property_iterate.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = <1>; 5 | #size-cells = <0>; 6 | 7 | test1 { 8 | test-properties = <3>; 9 | 10 | test { 11 | linux,phandle = <0x1>; 12 | #address-cells = <1>; 13 | #size-cells = <0>; 14 | }; 15 | }; 16 | 17 | test2 { 18 | test-properties = <0>; 19 | 20 | test { 21 | }; 22 | }; 23 | }; 24 | -------------------------------------------------------------------------------- /tests/propname_escapes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_getprop() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public License 9 | * as published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "tests.h" 30 | 31 | int main(int argc, char *argv[]) 32 | { 33 | void *fdt; 34 | 35 | test_init(argc, argv); 36 | fdt = load_blob_arg(argc, argv); 37 | 38 | check_getprop_cell(fdt, 0, "#address-cells", 1); 39 | check_getprop_cell(fdt, 0, "#gpio-cells", 2); 40 | 41 | PASS(); 42 | } 43 | -------------------------------------------------------------------------------- /tests/propname_escapes.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = <1>; 5 | \#gpio-cells = <2>; 6 | }; 7 | -------------------------------------------------------------------------------- /tests/references.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | rref = <&{/}>; 5 | 6 | /* Explicit phandles */ 7 | n1: node1 { 8 | linux,phandle = <0x2000>; 9 | ref = <&{/node2}>; /* reference precedes target */ 10 | lref = <&n2>; 11 | }; 12 | n2: node2 { 13 | phandle = <0x1>; 14 | ref = <&{/node1}>; /* reference after target */ 15 | lref = <&n1>; 16 | }; 17 | 18 | /* Implicit phandles */ 19 | n3: node3 { 20 | ref = <&{/node4}>; 21 | lref = <&n4>; 22 | }; 23 | n4: node4 { 24 | }; 25 | 26 | /* Explicit phandle with implicit value */ 27 | /* This self-reference is the standard way to tag a node as requiring 28 | * a phandle (perhaps for reference by nodes that will be dynamically 29 | * added) without explicitly allocating it a phandle. 30 | * The self-reference requires some special internal handling, though 31 | * so check it actually works */ 32 | n5: node5 { 33 | linux,phandle = <&n5>; 34 | phandle = <&n5>; 35 | }; 36 | }; 37 | -------------------------------------------------------------------------------- /tests/reg-ranges-root.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = <1>; 5 | #size-cells = <1>; 6 | reg = <0x1000 0x10>; 7 | ranges = <0x1000 0x2000 0x1000>; 8 | }; 9 | -------------------------------------------------------------------------------- /tests/reg-without-unit-addr.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = <1>; 5 | #size-cells = <1>; 6 | 7 | node { 8 | reg = <0 1>; 9 | }; 10 | }; 11 | -------------------------------------------------------------------------------- /tests/reuse-label.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | label: property1 = "foo"; 5 | label: property2 = "bar"; 6 | 7 | test1 = &label; 8 | 9 | label: node1 { 10 | prop = "foo"; 11 | }; 12 | label: node2 { 13 | prop = "bar"; 14 | }; 15 | }; 16 | -------------------------------------------------------------------------------- /tests/reuse-label1.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | label: node1 { 5 | prop = "foo"; 6 | }; 7 | label: node2 { 8 | prop = "bar"; 9 | }; 10 | }; 11 | -------------------------------------------------------------------------------- /tests/reuse-label2.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | label: property1 = "foo"; 5 | label: property2 = "bar"; 6 | }; 7 | -------------------------------------------------------------------------------- /tests/reuse-label3.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | label: property = "foo"; 5 | 6 | label: node { 7 | property = "foo"; 8 | }; 9 | }; 10 | -------------------------------------------------------------------------------- /tests/reuse-label4.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | property = label: "foo" label:; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/reuse-label5.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | prop1 = label: "foo"; 5 | prop2 = "bar" label:; 6 | }; 7 | -------------------------------------------------------------------------------- /tests/reuse-label6.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | label: prop1 = "foo"; 5 | prop2 = "bar" label:; 6 | }; 7 | -------------------------------------------------------------------------------- /tests/root_node.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Basic testcase for read-only access 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "tests.h" 29 | #include "testdata.h" 30 | 31 | int main(int argc, char *argv[]) 32 | { 33 | void *fdt; 34 | const struct fdt_node_header *nh; 35 | 36 | test_init(argc, argv); 37 | fdt = load_blob_arg(argc, argv); 38 | 39 | nh = fdt_offset_ptr(fdt, 0, sizeof(*nh)); 40 | 41 | if (! nh) 42 | FAIL("NULL retrieving root node"); 43 | 44 | if (fdt32_to_cpu(nh->tag) != FDT_BEGIN_NODE) 45 | FAIL("Wrong tag on root node"); 46 | 47 | if (strlen(nh->name) != 0) 48 | FAIL("Wrong name for root node, \"%s\" instead of empty", 49 | nh->name); 50 | 51 | PASS(); 52 | } 53 | -------------------------------------------------------------------------------- /tests/rw_tree1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_nop_node() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "tests.h" 30 | #include "testdata.h" 31 | 32 | #define SPACE 65536 33 | 34 | #define CHECK(code) \ 35 | { \ 36 | err = (code); \ 37 | if (err) \ 38 | FAIL(#code ": %s", fdt_strerror(err)); \ 39 | } 40 | 41 | #define OFF_CHECK(off, code) \ 42 | { \ 43 | (off) = (code); \ 44 | if (off < 0) \ 45 | FAIL(#code ": %s", fdt_strerror(off)); \ 46 | } 47 | 48 | int main(int argc, char *argv[]) 49 | { 50 | void *fdt; 51 | int err; 52 | int offset, s1, s2; 53 | 54 | test_init(argc, argv); 55 | 56 | fdt = xmalloc(SPACE); 57 | 58 | /* First create empty tree with SW */ 59 | CHECK(fdt_create_empty_tree(fdt, SPACE)); 60 | 61 | CHECK(fdt_add_mem_rsv(fdt, TEST_ADDR_1, TEST_SIZE_1)); 62 | CHECK(fdt_add_mem_rsv(fdt, TEST_ADDR_2, TEST_SIZE_2)); 63 | 64 | CHECK(fdt_setprop_string(fdt, 0, "compatible", "test_tree1")); 65 | CHECK(fdt_setprop_u32(fdt, 0, "prop-int", TEST_VALUE_1)); 66 | CHECK(fdt_setprop_u64(fdt, 0, "prop-int64", TEST_VALUE64_1)); 67 | CHECK(fdt_setprop_string(fdt, 0, "prop-str", TEST_STRING_1)); 68 | 69 | OFF_CHECK(offset, fdt_add_subnode(fdt, 0, "subnode@1")); 70 | s1 = offset; 71 | CHECK(fdt_setprop_string(fdt, s1, "compatible", "subnode1")); 72 | CHECK(fdt_setprop_cell(fdt, s1, "prop-int", TEST_VALUE_1)); 73 | OFF_CHECK(offset, fdt_add_subnode(fdt, s1, "subsubnode")); 74 | CHECK(fdt_setprop(fdt, offset, "compatible", 75 | "subsubnode1\0subsubnode", 23)); 76 | CHECK(fdt_setprop_cell(fdt, offset, "prop-int", TEST_VALUE_1)); 77 | OFF_CHECK(offset, fdt_add_subnode(fdt, s1, "ss1")); 78 | 79 | OFF_CHECK(offset, fdt_add_subnode(fdt, 0, "subnode@2")); 80 | s2 = offset; 81 | CHECK(fdt_setprop_cell(fdt, s2, "linux,phandle", PHANDLE_1)); 82 | CHECK(fdt_setprop_cell(fdt, s2, "prop-int", TEST_VALUE_2)); 83 | OFF_CHECK(offset, fdt_add_subnode(fdt, s2, "subsubnode@0")); 84 | CHECK(fdt_setprop_cell(fdt, offset, "linux,phandle", PHANDLE_2)); 85 | CHECK(fdt_setprop(fdt, offset, "compatible", 86 | "subsubnode2\0subsubnode", 23)); 87 | CHECK(fdt_setprop_cell(fdt, offset, "prop-int", TEST_VALUE_2)); 88 | OFF_CHECK(offset, fdt_add_subnode(fdt, s2, "ss2")); 89 | 90 | CHECK(fdt_pack(fdt)); 91 | 92 | save_blob("rw_tree1.test.dtb", fdt); 93 | 94 | PASS(); 95 | } 96 | -------------------------------------------------------------------------------- /tests/search_dir/search_test.dtsi: -------------------------------------------------------------------------------- 1 | /include/ "search_test2.dtsi" 2 | 3 | / { 4 | }; 5 | -------------------------------------------------------------------------------- /tests/search_dir/search_test2.dtsi: -------------------------------------------------------------------------------- 1 | 2 | / { 3 | }; 4 | -------------------------------------------------------------------------------- /tests/search_dir_b/search_paths_subdir.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /include/ "search_test_c.dtsi" 4 | 5 | / { 6 | }; 7 | -------------------------------------------------------------------------------- /tests/search_dir_b/search_test_b.dtsi: -------------------------------------------------------------------------------- 1 | /include/ "search_test_b2.dtsi" 2 | 3 | / { 4 | }; 5 | -------------------------------------------------------------------------------- /tests/search_dir_b/search_test_b2.dtsi: -------------------------------------------------------------------------------- 1 | 2 | /include/ "search_test.dtsi" 3 | 4 | / { 5 | }; 6 | -------------------------------------------------------------------------------- /tests/search_dir_b/search_test_c.dtsi: -------------------------------------------------------------------------------- 1 | / { 2 | }; 3 | -------------------------------------------------------------------------------- /tests/search_paths.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /include/ "search_test.dtsi" 4 | 5 | / { 6 | }; 7 | -------------------------------------------------------------------------------- /tests/search_paths_b.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /include/ "search_test_b.dtsi" 4 | 5 | / { 6 | }; 7 | -------------------------------------------------------------------------------- /tests/set_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_set_name() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | static void check_set_name(void *fdt, const char *path, const char *newname) 31 | { 32 | int offset; 33 | const char *getname, *oldname; 34 | int len, err; 35 | 36 | oldname = strrchr(path, '/'); 37 | if (!oldname) 38 | TEST_BUG(); 39 | oldname += 1; 40 | 41 | offset = fdt_path_offset(fdt, path); 42 | if (offset < 0) 43 | FAIL("Couldn't find %s", path); 44 | 45 | getname = fdt_get_name(fdt, offset, &len); 46 | verbose_printf("fdt_get_name(%d) returns \"%s\" (len=%d)\n", 47 | offset, getname, len); 48 | if (!getname) 49 | FAIL("fdt_get_name(%d): %s", offset, fdt_strerror(len)); 50 | 51 | if (strcmp(getname, oldname) != 0) 52 | FAIL("fdt_get_name(%s) returned \"%s\" instead of \"%s\"", 53 | path, getname, oldname); 54 | 55 | if (len != strlen(getname)) 56 | FAIL("fdt_get_name(%s) returned length %d instead of %zd", 57 | path, len, strlen(getname)); 58 | 59 | err = fdt_set_name(fdt, offset, newname); 60 | if (err) 61 | FAIL("fdt_set_name(%d, \"%s\"): %s", offset, newname, 62 | fdt_strerror(err)); 63 | 64 | getname = fdt_get_name(fdt, offset, &len); 65 | if (!getname) 66 | FAIL("fdt_get_name(%d): %s", offset, fdt_strerror(len)); 67 | 68 | if (strcmp(getname, newname) != 0) 69 | FAIL("fdt_get_name(%s) returned \"%s\" instead of \"%s\"", 70 | path, getname, newname); 71 | 72 | if (len != strlen(getname)) 73 | FAIL("fdt_get_name(%s) returned length %d instead of %zd", 74 | path, len, strlen(getname)); 75 | } 76 | 77 | int main(int argc, char *argv[]) 78 | { 79 | void *fdt; 80 | 81 | test_init(argc, argv); 82 | fdt = load_blob_arg(argc, argv); 83 | fdt = open_blob_rw(fdt); 84 | 85 | check_set_name(fdt, "/subnode@1", "subnode@17"); 86 | check_set_name(fdt, "/subnode@2/subsubnode@0", "fred@0"); 87 | check_set_name(fdt, "/subnode@17/subsubnode", "something@0"); 88 | 89 | PASS(); 90 | } 91 | -------------------------------------------------------------------------------- /tests/setprop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_setprop() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "tests.h" 30 | #include "testdata.h" 31 | 32 | #define SPACE 65536 33 | #define NEW_STRING "here is quite a long test string, blah blah blah" 34 | 35 | int main(int argc, char *argv[]) 36 | { 37 | void *fdt; 38 | void *buf; 39 | const uint32_t *intp; 40 | const char *strp; 41 | int err; 42 | 43 | test_init(argc, argv); 44 | fdt = load_blob_arg(argc, argv); 45 | 46 | buf = xmalloc(SPACE); 47 | 48 | err = fdt_open_into(fdt, buf, SPACE); 49 | if (err) 50 | FAIL("fdt_open_into(): %s", fdt_strerror(err)); 51 | 52 | fdt = buf; 53 | 54 | intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1); 55 | 56 | verbose_printf("Old int value was 0x%08x\n", *intp); 57 | err = fdt_setprop_string(fdt, 0, "prop-int", NEW_STRING); 58 | if (err) 59 | FAIL("Failed to set \"prop-int\" to \"%s\": %s", 60 | NEW_STRING, fdt_strerror(err)); 61 | 62 | strp = check_getprop_string(fdt, 0, "prop-int", NEW_STRING); 63 | verbose_printf("New value is \"%s\"\n", strp); 64 | 65 | strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1, 66 | TEST_STRING_1); 67 | 68 | verbose_printf("Old string value was \"%s\"\n", strp); 69 | err = fdt_setprop_empty(fdt, 0, "prop-str"); 70 | if (err) 71 | FAIL("Failed to empty \"prop-str\": %s", 72 | fdt_strerror(err)); 73 | 74 | check_getprop(fdt, 0, "prop-str", 0, NULL); 75 | 76 | err = fdt_setprop_u32(fdt, 0, "prop-u32", TEST_VALUE_2); 77 | if (err) 78 | FAIL("Failed to set \"prop-u32\" to 0x%08x: %s", 79 | TEST_VALUE_2, fdt_strerror(err)); 80 | check_getprop_cell(fdt, 0, "prop-u32", TEST_VALUE_2); 81 | 82 | err = fdt_setprop_cell(fdt, 0, "prop-cell", TEST_VALUE_2); 83 | if (err) 84 | FAIL("Failed to set \"prop-cell\" to 0x%08x: %s", 85 | TEST_VALUE_2, fdt_strerror(err)); 86 | check_getprop_cell(fdt, 0, "prop-cell", TEST_VALUE_2); 87 | 88 | err = fdt_setprop_u64(fdt, 0, "prop-u64", TEST_VALUE64_1); 89 | if (err) 90 | FAIL("Failed to set \"prop-u64\" to 0x%016llx: %s", 91 | TEST_VALUE64_1, fdt_strerror(err)); 92 | check_getprop_64(fdt, 0, "prop-u64", TEST_VALUE64_1); 93 | 94 | PASS(); 95 | } 96 | -------------------------------------------------------------------------------- /tests/setprop_inplace.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_setprop_inplace() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include "tests.h" 31 | #include "testdata.h" 32 | 33 | int main(int argc, char *argv[]) 34 | { 35 | void *fdt; 36 | const uint32_t *intp; 37 | const uint64_t *int64p; 38 | const char *strp; 39 | char *xstr; 40 | int xlen, i; 41 | int err; 42 | 43 | test_init(argc, argv); 44 | fdt = load_blob_arg(argc, argv); 45 | 46 | intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1); 47 | 48 | verbose_printf("Old int value was 0x%08x\n", *intp); 49 | err = fdt_setprop_inplace_cell(fdt, 0, "prop-int", ~TEST_VALUE_1); 50 | if (err) 51 | FAIL("Failed to set \"prop-int\" to 0x%08x: %s", 52 | ~TEST_VALUE_1, fdt_strerror(err)); 53 | intp = check_getprop_cell(fdt, 0, "prop-int", ~TEST_VALUE_1); 54 | verbose_printf("New int value is 0x%08x\n", *intp); 55 | 56 | strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1, 57 | TEST_STRING_1); 58 | 59 | 60 | int64p = check_getprop_64(fdt, 0, "prop-int64", TEST_VALUE64_1); 61 | 62 | verbose_printf("Old int64 value was 0x%016" PRIx64 "\n", *int64p); 63 | err = fdt_setprop_inplace_u64(fdt, 0, "prop-int64", ~TEST_VALUE64_1); 64 | if (err) 65 | FAIL("Failed to set \"prop-int64\" to 0x%016llx: %s", 66 | ~TEST_VALUE64_1, fdt_strerror(err)); 67 | int64p = check_getprop_64(fdt, 0, "prop-int64", ~TEST_VALUE64_1); 68 | verbose_printf("New int64 value is 0x%016" PRIx64 "\n", *int64p); 69 | 70 | strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1, 71 | TEST_STRING_1); 72 | 73 | verbose_printf("Old string value was \"%s\"\n", strp); 74 | xstr = strdup(strp); 75 | xlen = strlen(xstr); 76 | for (i = 0; i < xlen; i++) 77 | xstr[i] = toupper(xstr[i]); 78 | err = fdt_setprop_inplace(fdt, 0, "prop-str", xstr, xlen+1); 79 | if (err) 80 | FAIL("Failed to set \"prop-str\" to \"%s\": %s", 81 | xstr, fdt_strerror(err)); 82 | 83 | strp = check_getprop(fdt, 0, "prop-str", xlen+1, xstr); 84 | verbose_printf("New string value is \"%s\"\n", strp); 85 | 86 | err = fdt_setprop_inplace_namelen_partial(fdt, 0, "compatible", 87 | strlen("compatible"), 4, 88 | TEST_STRING_4_PARTIAL, 89 | strlen(TEST_STRING_4_PARTIAL)); 90 | if (err) 91 | FAIL("Failed to set \"compatible\": %s\n", fdt_strerror(err)); 92 | 93 | check_getprop(fdt, 0, "compatible", strlen(TEST_STRING_4_RESULT) + 1, 94 | TEST_STRING_4_RESULT); 95 | 96 | PASS(); 97 | } 98 | -------------------------------------------------------------------------------- /tests/sized_cells.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for variable sized cells in dtc 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * Copyright (C) 2011 The Chromium Authors. All rights reserved. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public License 9 | * as published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "tests.h" 29 | #include "testdata.h" 30 | 31 | static void check_compare_properties(void *fdt, 32 | char const *name_one, 33 | char const *name_two) 34 | { 35 | const void *propval; 36 | int proplen; 37 | 38 | propval = fdt_getprop(fdt, 0, name_one, &proplen); 39 | 40 | if (!propval) 41 | FAIL("fdt_getprop(\"%s\"): %s", 42 | name_one, 43 | fdt_strerror(proplen)); 44 | 45 | check_getprop(fdt, 0, name_two, proplen, propval); 46 | } 47 | 48 | int main(int argc, char *argv[]) 49 | { 50 | void *fdt; 51 | uint8_t expected_8[6] = {TEST_CHAR1, 52 | TEST_CHAR2, 53 | TEST_CHAR3, 54 | TEST_CHAR4, 55 | TEST_CHAR5, 56 | TEST_VALUE_1 >> 24}; 57 | fdt16_t expected_16[6]; 58 | fdt32_t expected_32[6]; 59 | fdt64_t expected_64[6]; 60 | int i; 61 | 62 | for (i = 0; i < 5; ++i) { 63 | expected_16[i] = cpu_to_fdt16(expected_8[i]); 64 | expected_32[i] = cpu_to_fdt32(expected_8[i]); 65 | expected_64[i] = cpu_to_fdt64(expected_8[i]); 66 | } 67 | 68 | expected_16[5] = cpu_to_fdt16(TEST_VALUE_1 >> 16); 69 | expected_32[5] = cpu_to_fdt32(TEST_VALUE_1); 70 | expected_64[5] = cpu_to_fdt64(TEST_ADDR_1); 71 | 72 | test_init(argc, argv); 73 | fdt = load_blob_arg(argc, argv); 74 | 75 | check_getprop(fdt, 0, "cells-8b", sizeof(expected_8), expected_8); 76 | check_getprop(fdt, 0, "cells-16b", sizeof(expected_16), expected_16); 77 | check_getprop(fdt, 0, "cells-32b", sizeof(expected_32), expected_32); 78 | check_getprop(fdt, 0, "cells-64b", sizeof(expected_64), expected_64); 79 | 80 | check_compare_properties(fdt, "cells-one-16b", "cells-one-32b"); 81 | 82 | PASS(); 83 | } 84 | -------------------------------------------------------------------------------- /tests/sized_cells.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | cells-8b = /bits/ 8 <'\r' 'b' '\0' '\'' '\xff' 0xde>; 5 | cells-16b = /bits/ 16 <'\r' 'b' '\0' '\'' '\xff' 0xdead>; 6 | cells-32b = /bits/ 32 <'\r' 'b' '\0' '\'' '\xff' 0xdeadbeef>; 7 | cells-64b = /bits/ 64 <'\r' 'b' '\0' '\'' '\xff' 0xdeadbeef00000000>; 8 | 9 | cells-one-16b = /bits/ 16 <0x1234 0x5678 0x0 0xffff>; 10 | cells-one-32b = <0x12345678 0x0000ffff>; 11 | }; 12 | -------------------------------------------------------------------------------- /tests/sourceoutput.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | /* Some versions had an off-by-2 bug which caused an abort 5 | * when outputing labels within strings like this in source 6 | * format */ 7 | prop1: prop1 = start1: "foo", mid1: "bar" end1: ; 8 | 9 | /* Make sure that we correctly handle source output of things 10 | * which could almost be expressed as strings, except for the 11 | * embedded labels */ 12 | prop2 = start2: [66 6f 6f], mid2: "bar" end2: ; 13 | }; 14 | 15 | -------------------------------------------------------------------------------- /tests/string_escapes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for string escapes in dtc 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | void *fdt; 33 | 34 | test_init(argc, argv); 35 | fdt = load_blob_arg(argc, argv); 36 | 37 | check_getprop(fdt, 0, "escape-str", 38 | strlen(TEST_STRING_2)+1, TEST_STRING_2); 39 | check_getprop(fdt, 0, "escape-str-2", 40 | strlen(TEST_STRING_3)+1, TEST_STRING_3); 41 | 42 | PASS(); 43 | } 44 | -------------------------------------------------------------------------------- /tests/stringlist.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | compatible = "test-strings"; 5 | #address-cells = <2>; 6 | #size-cells = <2>; 7 | 8 | device { 9 | compatible = "foo", "bar"; 10 | big-endian; 11 | }; 12 | }; 13 | -------------------------------------------------------------------------------- /tests/subnode_iterate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Tests that fdt_next_subnode() works as expected 4 | * 5 | * Copyright (C) 2013 Google, Inc 6 | * 7 | * Copyright (C) 2007 David Gibson, IBM Corporation. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public License 11 | * as published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include "tests.h" 32 | #include "testdata.h" 33 | 34 | static void test_node(void *fdt, int parent_offset) 35 | { 36 | uint32_t subnodes; 37 | const fdt32_t *prop; 38 | int offset; 39 | int count; 40 | int len; 41 | 42 | /* This property indicates the number of subnodes to expect */ 43 | prop = fdt_getprop(fdt, parent_offset, "subnodes", &len); 44 | if (!prop || len != sizeof(fdt32_t)) { 45 | FAIL("Missing/invalid subnodes property at '%s'", 46 | fdt_get_name(fdt, parent_offset, NULL)); 47 | } 48 | subnodes = fdt32_to_cpu(*prop); 49 | 50 | count = 0; 51 | fdt_for_each_subnode(offset, fdt, parent_offset) 52 | count++; 53 | 54 | if (count != subnodes) { 55 | FAIL("Node '%s': Expected %d subnodes, got %d\n", 56 | fdt_get_name(fdt, parent_offset, NULL), subnodes, 57 | count); 58 | } 59 | } 60 | 61 | static void check_fdt_next_subnode(void *fdt) 62 | { 63 | int offset; 64 | int count = 0; 65 | 66 | fdt_for_each_subnode(offset, fdt, 0) { 67 | test_node(fdt, offset); 68 | count++; 69 | } 70 | 71 | if (count != 2) 72 | FAIL("Expected %d tests, got %d\n", 2, count); 73 | } 74 | 75 | int main(int argc, char *argv[]) 76 | { 77 | void *fdt; 78 | 79 | test_init(argc, argv); 80 | if (argc != 2) 81 | CONFIG("Usage: %s ", argv[0]); 82 | 83 | fdt = load_blob(argv[1]); 84 | if (!fdt) 85 | FAIL("No device tree available"); 86 | 87 | check_fdt_next_subnode(fdt); 88 | 89 | PASS(); 90 | } 91 | -------------------------------------------------------------------------------- /tests/subnode_iterate.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = <1>; 5 | #size-cells = <0>; 6 | 7 | test1 { 8 | subnodes = <2>; 9 | linux,phandle = <0x1>; 10 | #address-cells = <1>; 11 | #size-cells = <0>; 12 | PowerPC,970@0 { 13 | name = "PowerPC,970"; 14 | device_type = "cpu"; 15 | reg = <0x00000000>; 16 | clock-frequency = <1600000000>; 17 | timebase-frequency = <33333333>; 18 | linux,boot-cpu; 19 | i-cache-size = <65536>; 20 | d-cache-size = <32768>; 21 | another-sub-node { 22 | should-be-ignored; 23 | yet-another { 24 | should-also-be-ignored; 25 | }; 26 | }; 27 | }; 28 | 29 | PowerPC,970@1 { 30 | name = "PowerPC,970"; 31 | device_type = "cpu"; 32 | reg = <0x00000001>; 33 | clock-frequency = <1600000000>; 34 | timebase-frequency = <33333333>; 35 | i-cache-size = <65536>; 36 | d-cache-size = <32768>; 37 | }; 38 | }; 39 | 40 | test2 { 41 | subnodes = <0>; 42 | }; 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /tests/subnode_offset.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for fdt_subnode_offset() 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "tests.h" 28 | #include "testdata.h" 29 | 30 | static int check_subnode(struct fdt_header *fdt, int parent, const char *name) 31 | { 32 | int offset; 33 | const struct fdt_node_header *nh; 34 | uint32_t tag; 35 | 36 | verbose_printf("Checking subnode \"%s\" of %d...", name, parent); 37 | offset = fdt_subnode_offset(fdt, parent, name); 38 | verbose_printf("offset %d...", offset); 39 | if (offset < 0) 40 | FAIL("fdt_subnode_offset(\"%s\"): %s", name, fdt_strerror(offset)); 41 | nh = fdt_offset_ptr(fdt, offset, sizeof(*nh)); 42 | verbose_printf("pointer %p\n", nh); 43 | if (! nh) 44 | FAIL("NULL retrieving subnode \"%s\"", name); 45 | 46 | tag = fdt32_to_cpu(nh->tag); 47 | 48 | if (tag != FDT_BEGIN_NODE) 49 | FAIL("Incorrect tag 0x%08x on property \"%s\"", tag, name); 50 | if (!nodename_eq(nh->name, name)) 51 | FAIL("Subnode name mismatch \"%s\" instead of \"%s\"", 52 | nh->name, name); 53 | 54 | return offset; 55 | } 56 | 57 | int main(int argc, char *argv[]) 58 | { 59 | void *fdt; 60 | int subnode1_offset, subnode2_offset; 61 | int subsubnode1_offset, subsubnode2_offset, subsubnode2_offset2; 62 | int ss12_off, ss21_off; 63 | 64 | test_init(argc, argv); 65 | fdt = load_blob_arg(argc, argv); 66 | 67 | subnode1_offset = check_subnode(fdt, 0, "subnode@1"); 68 | subnode2_offset = check_subnode(fdt, 0, "subnode@2"); 69 | 70 | if (subnode1_offset == subnode2_offset) 71 | FAIL("Different subnodes have same offset"); 72 | 73 | check_property_cell(fdt, subnode1_offset, "prop-int", TEST_VALUE_1); 74 | check_property_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2); 75 | 76 | subsubnode1_offset = check_subnode(fdt, subnode1_offset, "subsubnode"); 77 | subsubnode2_offset = check_subnode(fdt, subnode2_offset, "subsubnode@0"); 78 | subsubnode2_offset2 = check_subnode(fdt, subnode2_offset, "subsubnode"); 79 | 80 | check_property_cell(fdt, subsubnode1_offset, "prop-int", TEST_VALUE_1); 81 | check_property_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2); 82 | check_property_cell(fdt, subsubnode2_offset2, "prop-int", TEST_VALUE_2); 83 | 84 | if (subsubnode2_offset != subsubnode2_offset2) 85 | FAIL("Different offsets with and without unit address"); 86 | 87 | check_subnode(fdt, subnode1_offset, "ss1"); 88 | ss21_off = fdt_subnode_offset(fdt, subnode2_offset, "ss1"); 89 | if (ss21_off != -FDT_ERR_NOTFOUND) 90 | FAIL("Incorrectly found ss1 in subnode2"); 91 | 92 | ss12_off = fdt_subnode_offset(fdt, subnode1_offset, "ss2"); 93 | if (ss12_off != -FDT_ERR_NOTFOUND) 94 | FAIL("Incorrectly found ss2 in subnode1"); 95 | check_subnode(fdt, subnode2_offset, "ss2"); 96 | 97 | PASS(); 98 | } 99 | -------------------------------------------------------------------------------- /tests/sw_tree1.supp: -------------------------------------------------------------------------------- 1 | { 2 | allocation methods causes uninitialized data in alignment gap 3 | Memcheck:Param 4 | write(buf) 5 | fun:__write_nocancel 6 | fun:utilfdt_write_err 7 | fun:save_blob 8 | fun:main 9 | } 10 | { 11 | allocation methods causes uninitialized data in alignment gap 12 | Memcheck:Param 13 | write(buf) 14 | fun:__write_nocancel 15 | fun:utilfdt_write_err 16 | fun:save_blob 17 | fun:main 18 | } 19 | -------------------------------------------------------------------------------- /tests/test01.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0x1000000000000000 0x0000000002000000; 4 | /memreserve/ 0x2000000000000000 0x0100000000000000; 5 | /memreserve/ 0x0000000000000000 0x0000000000000014; 6 | 7 | / { 8 | model = "MyBoardName"; 9 | compatible = "MyBoardName", "MyBoardFamilyName"; 10 | #address-cells = <2>; 11 | #size-cells = <2>; 12 | 13 | cpus { 14 | linux,phandle = <0x1>; 15 | #address-cells = <1>; 16 | #size-cells = <0>; 17 | PowerPC,970@0 { 18 | name = "PowerPC,970"; 19 | device_type = "cpu"; 20 | reg = <0x00000000>; 21 | clock-frequency = <1600000000>; 22 | timebase-frequency = <33333333>; 23 | linux,boot-cpu; 24 | i-cache-size = <65536>; 25 | d-cache-size = <32768>; 26 | }; 27 | 28 | PowerPC,970@1 { 29 | name = "PowerPC,970"; 30 | device_type = "cpu"; 31 | reg = <0x00000001>; 32 | clock-frequency = <1600000000>; 33 | timebase-frequency = <33333333>; 34 | i-cache-size = <65536>; 35 | d-cache-size = <32768>; 36 | }; 37 | 38 | }; 39 | 40 | randomnode { 41 | string = "\xff\0stuffstuff\t\t\t\n\n\n"; 42 | blob = [0a 0b 0c 0d de ea ad be ef]; 43 | ref = < &{/memory@0} >; 44 | mixed = "abc", [1234], <0xa 0xb 0xc>; 45 | }; 46 | 47 | memory@0 { 48 | device_type = "memory"; 49 | memreg: reg = <0x00000000 0x00000000 0x00000000 0x20000000>; 50 | }; 51 | 52 | chosen { 53 | bootargs = "root=/dev/sda2"; 54 | linux,platform = <0x600>; 55 | }; 56 | 57 | }; 58 | -------------------------------------------------------------------------------- /tests/test01.stderr: -------------------------------------------------------------------------------- 1 | DTC: dts->asm on file "test.dts" 2 | Warning: "linux,boot-cpu" property is deprecated in blob version 2 or higher 3 | Warning: /chosen has no "linux,stdout-path" property 4 | Warning: /chosen has no "interrupt-controller" property 5 | -------------------------------------------------------------------------------- /tests/test_kernel_dts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | my $dtc_old = "/home/jdl/FSL/dtc/dtc-old"; 4 | my $dtc_new = "/home/jdl/FSL/dtc/dtc-new"; 5 | 6 | my $basic_options = "-b 0 -f -I dts -O dtb"; 7 | 8 | my $linux_dts_dir = "/usr/src/linux-2.6/arch/powerpc/boot/dts"; 9 | 10 | # Yeah, sure, we could, like, readdir() this instead... 11 | my @boards = ( 12 | "bamboo", 13 | "ebony", 14 | "ep88xc", 15 | "holly", 16 | "kilauea", 17 | "kuroboxHD", 18 | "kuroboxHG", 19 | "lite5200", 20 | "lite5200b", 21 | "mpc7448hpc2", 22 | "mpc8272ads", 23 | "mpc8313erdb", 24 | "mpc832x_mds", 25 | "mpc832x_rdb", 26 | "mpc8349emitx", 27 | "mpc8349emitxgp", 28 | "mpc834x_mds", 29 | "mpc836x_mds", 30 | "mpc8540ads", 31 | "mpc8541cds", 32 | "mpc8544ds", 33 | "mpc8548cds", 34 | "mpc8555cds", 35 | "mpc8560ads", 36 | "mpc8568mds", 37 | "mpc8572ds", 38 | "mpc8610_hpcd", 39 | "mpc8641_hpcn", 40 | "mpc866ads", # Feh. Bad node references... 41 | "mpc885ads", 42 | "pq2fads", 43 | "prpmc2800", 44 | "ps3", 45 | "sequoia", 46 | "walnut", 47 | ); 48 | 49 | foreach my $board (@boards) { 50 | my $dts_file = "$linux_dts_dir/$board.dts"; 51 | 52 | my $old_dtb_file = "/tmp/$board.dtb.old"; 53 | my $new_dtb_file = "/tmp/$board.dtb.new"; 54 | 55 | my $cmd_old = "$dtc_old $basic_options -o $old_dtb_file $dts_file"; 56 | my $cmd_new = "$dtc_new $basic_options -o $new_dtb_file $dts_file"; 57 | my $cmd_cmp = "cmp $old_dtb_file $new_dtb_file"; 58 | 59 | print "------------------------------------------------\n"; 60 | print "OLD: $cmd_old\n"; 61 | unlink($old_dtb_file) if (-f $old_dtb_file); 62 | system("$cmd_old >& /dev/null"); 63 | my $status = $?; 64 | if ($status) { 65 | print " FAILED to run old DTC on $board\n"; 66 | } 67 | 68 | print "NEW: $cmd_new\n"; 69 | unlink($new_dtb_file) if (-f $new_dtb_file); 70 | system("$cmd_new >& /dev/null"); 71 | $status = $?; 72 | if ($status) { 73 | print " FAILED to run new DTC on $board\n"; 74 | } 75 | 76 | if (-f $old_dtb_file && -f $new_dtb_file) { 77 | print "CMP: $cmd_cmp\n"; 78 | system($cmd_cmp); 79 | $status = $?; 80 | if ($status) { 81 | print " FAILED $board\n"; 82 | } 83 | } else { 84 | printf " FAILED: Missing dtb file\n"; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /tests/test_label_ref.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | 5 | }; 6 | 7 | label: &handle { 8 | 9 | }; 10 | -------------------------------------------------------------------------------- /tests/test_tree1.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0xdeadbeef00000000 0x100000; 4 | /memreserve/ 123456789 010000; 5 | 6 | / { 7 | compatible = "test_tree1"; 8 | prop-int = <0xdeadbeef>; 9 | prop-int64 = /bits/ 64 <0xdeadbeef01abcdef>; 10 | prop-str = "hello world"; 11 | #address-cells = <1>; 12 | #size-cells = <0>; 13 | 14 | subnode@1 { 15 | compatible = "subnode1"; 16 | reg = <1>; 17 | prop-int = [deadbeef]; 18 | 19 | subsubnode { 20 | compatible = "subsubnode1", "subsubnode"; 21 | placeholder = "this is a placeholder string", "string2"; 22 | prop-int = <0xdeadbeef>; 23 | }; 24 | 25 | ss1 { 26 | }; 27 | }; 28 | 29 | subnode@2 { 30 | reg = <2>; 31 | linux,phandle = <0x2000>; 32 | prop-int = <123456789>; 33 | #address-cells = <1>; 34 | #size-cells = <0>; 35 | 36 | ssn0: subsubnode@0 { 37 | reg = <0>; 38 | phandle = <0x2001>; 39 | compatible = "subsubnode2", "subsubnode"; 40 | prop-int = <0726746425>; 41 | }; 42 | 43 | ss2 { 44 | }; 45 | }; 46 | }; 47 | -------------------------------------------------------------------------------- /tests/test_tree1_delete.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /include/ "test_tree1.dts" 4 | 5 | / { 6 | nonexistant-property = <0xdeadbeef>; 7 | 8 | nonexistant-subnode { 9 | prop-int = <1>; 10 | }; 11 | 12 | dellabel: deleted-by-label { 13 | prop-int = <1>; 14 | }; 15 | 16 | subnode@1 { 17 | delete-this-str = "deadbeef"; 18 | }; 19 | 20 | }; 21 | 22 | / { 23 | /delete-property/ nonexistant-property; 24 | 25 | /delete-node/ nonexistant-subnode; 26 | 27 | subnode@1 { 28 | /delete-property/ delete-this-str; 29 | }; 30 | }; 31 | 32 | /delete-node/ &dellabel; 33 | 34 | / { 35 | /delete-property/ prop-str; 36 | }; 37 | 38 | / { 39 | prop-str = "hello world"; 40 | }; 41 | 42 | / { 43 | subnode@1 { 44 | /delete-node/ ss1; 45 | }; 46 | }; 47 | 48 | / { 49 | subnode@1 { 50 | ss1 { 51 | }; 52 | }; 53 | }; 54 | 55 | /{ 56 | duplabel1: foo1 = "bar"; 57 | duplabel2: foo2 = "bar"; 58 | }; 59 | 60 | /{ 61 | duplabel1: baz1 = "qux"; 62 | duplabel2: baz2 = "qux"; 63 | }; 64 | 65 | /{ 66 | /delete-property/ foo1; 67 | /delete-property/ baz2; 68 | }; 69 | -------------------------------------------------------------------------------- /tests/test_tree1_label_noderef.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0xdeadbeef00000000 0x100000; 4 | /memreserve/ 123456789 010000; 5 | 6 | / { 7 | compatible = "test_tree1"; 8 | prop-int = <0xdeadbeef>; 9 | prop-int64 = /bits/ 64 <0xdeadbeef01abcdef>; 10 | prop-str = "hello world"; 11 | #address-cells = <1>; 12 | #size-cells = <0>; 13 | 14 | subnode@1 { 15 | compatible = "subnode1"; 16 | reg = <1>; 17 | prop-int = [deadbeef]; 18 | 19 | subsubnode { 20 | compatible = "subsubnode1", "subsubnode"; 21 | placeholder = "this is a placeholder string", "string2"; 22 | prop-int = <0xdeadbeef>; 23 | }; 24 | 25 | ss1 { 26 | }; 27 | }; 28 | 29 | subnode@2 { 30 | reg = <2>; 31 | linux,phandle = <0x2000>; 32 | prop-int = <123456789>; 33 | #address-cells = <1>; 34 | #size-cells = <0>; 35 | 36 | ssn0: subsubnode@0 { 37 | phandle = <0x2001>; 38 | prop-int = <0xbad>; 39 | }; 40 | 41 | ss2 { 42 | }; 43 | }; 44 | }; 45 | 46 | /* Add label to a noderef */ 47 | ssn1: &ssn0 { 48 | reg = <0>; 49 | prop-int = <123456789>; 50 | }; 51 | 52 | /* Use the new label for merging */ 53 | &ssn1 { 54 | prop-int = <0726746425>; 55 | compatible = "subsubnode2", "subsubnode"; 56 | }; 57 | -------------------------------------------------------------------------------- /tests/test_tree1_merge.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | /memreserve/ 0xdeadbeef00000000 0x100000; 3 | /memreserve/ 123456789 010000; 4 | 5 | / { 6 | compatible = "test_tree1"; 7 | prop-int = "wrong!"; 8 | prop-str = "hello world"; 9 | #address-cells = <1>; 10 | #size-cells = <0>; 11 | 12 | subnode@1 { 13 | compatible = "subnode1"; 14 | reg = <1>; 15 | 16 | subsubnode { 17 | compatible = "subsubnode1", "subsubnode"; 18 | prop-int = <0xdeadbeef>; 19 | }; 20 | 21 | ss1 { 22 | }; 23 | }; 24 | 25 | subnode@2 { 26 | reg = <2>; 27 | linux,phandle = <0x2000>; 28 | prop-int = <123456789>; 29 | #address-cells = <1>; 30 | #size-cells = <0>; 31 | 32 | ss2 { 33 | }; 34 | }; 35 | }; 36 | 37 | / { 38 | prop-int = <0xdeadbeef>; 39 | prop-int64 = /bits/ 64 <0xdeadbeef01abcdef>; 40 | subnode@1 { 41 | prop-int = [deadbeef]; 42 | }; 43 | subnode@2 { 44 | ssn0: subsubnode@0 { 45 | reg = <0>; 46 | phandle = <0x2001>; 47 | compatible = "subsubnode2", "subsubnode"; 48 | prop-int = <0726746425>; 49 | }; 50 | }; 51 | }; 52 | -------------------------------------------------------------------------------- /tests/test_tree1_merge_labelled.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0xdeadbeef00000000 0x100000; 4 | /memreserve/ 123456789 010000; 5 | 6 | / { 7 | compatible = "test_tree1"; 8 | prop-int = <0xdeadbeef>; 9 | prop-int64 = /bits/ 64 <0xdeadbeef01abcdef>; 10 | prop-str = "hello world"; 11 | #address-cells = <1>; 12 | #size-cells = <0>; 13 | 14 | subnode@1 { 15 | compatible = "subnode1"; 16 | reg = <1>; 17 | prop-int = [deadbeef]; 18 | 19 | subsubnode { 20 | compatible = "subsubnode1", "subsubnode"; 21 | prop-int = <0xdeadbeef>; 22 | }; 23 | 24 | ss1 { 25 | }; 26 | }; 27 | 28 | subnode@2 { 29 | reg = <2>; 30 | linux,phandle = <0x2000>; 31 | prop-int = <123456789>; 32 | #address-cells = <1>; 33 | #size-cells = <0>; 34 | 35 | ssn0: subsubnode@0 { 36 | reg = <0>; 37 | phandle = <0x2001>; 38 | prop-int = <0xbad>; 39 | }; 40 | 41 | ss2 { 42 | }; 43 | }; 44 | }; 45 | 46 | &ssn0 { 47 | compatible = "subsubnode2", "subsubnode"; 48 | prop-int = <0726746425>; 49 | }; 50 | -------------------------------------------------------------------------------- /tests/test_tree1_merge_path.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0xdeadbeef00000000 0x100000; 4 | /memreserve/ 123456789 010000; 5 | 6 | / { 7 | compatible = "test_tree1"; 8 | prop-int = <0xdeadbeef>; 9 | prop-int64 = /bits/ 64 <0xdeadbeef01abcdef>; 10 | prop-str = "hello world"; 11 | #address-cells = <1>; 12 | #size-cells = <0>; 13 | 14 | subnode@1 { 15 | compatible = "subnode1"; 16 | reg = <1>; 17 | prop-int = [deadbeef]; 18 | 19 | subsubnode { 20 | compatible = "subsubnode1", "subsubnode"; 21 | prop-int = <0xdeadbeef>; 22 | }; 23 | 24 | ss1 { 25 | }; 26 | }; 27 | 28 | subnode@2 { 29 | reg = <2>; 30 | linux,phandle = <0x2000>; 31 | prop-int = <123456789>; 32 | #address-cells = <1>; 33 | #size-cells = <0>; 34 | 35 | ssn0: subsubnode@0 { 36 | reg = <0>; 37 | phandle = <0x2001>; 38 | prop-int = <0xbad>; 39 | }; 40 | 41 | ss2 { 42 | }; 43 | }; 44 | }; 45 | 46 | &{/subnode@2/subsubnode@0} { 47 | compatible = "subsubnode2", "subsubnode"; 48 | prop-int = <0726746425>; 49 | }; 50 | -------------------------------------------------------------------------------- /tests/test_tree1_wrong1.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 123456789 010000; 4 | 5 | / { 6 | compatible = "test_tree1"; 7 | prop-int = <0xdeadbeef>; 8 | prop-str = "hello world"; 9 | #address-cells = <1>; 10 | #size-cells = <0>; 11 | 12 | subnode@1 { 13 | compatible = "subnode1"; 14 | reg = <1>; 15 | prop-int = [deadbeef]; 16 | 17 | subsubnode { 18 | compatible = "subsubnode1", "subsubnode"; 19 | prop-int = <0xdeadbeef>; 20 | }; 21 | 22 | ss1 { 23 | }; 24 | }; 25 | 26 | subnode@2 { 27 | reg = <2>; 28 | linux,phandle = <0x2000>; 29 | prop-int = <123456789>; 30 | #address-cells = <1>; 31 | #size-cells = <0>; 32 | 33 | subsubnode@0 { 34 | reg = <0>; 35 | phandle = <0x2001>; 36 | compatible = "subsubnode2", "subsubnode"; 37 | prop-int = <0726746425>; 38 | }; 39 | 40 | ss2 { 41 | }; 42 | }; 43 | }; 44 | -------------------------------------------------------------------------------- /tests/test_tree1_wrong2.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0xdeadbeef00000000 0x100000; 4 | /memreserve/ 123456789 010000; 5 | 6 | / { 7 | compatible = "test_tree1"; 8 | prop-str = "hello world"; 9 | #address-cells = <1>; 10 | #size-cells = <0>; 11 | 12 | subnode@1 { 13 | compatible = "subnode1"; 14 | reg = <1>; 15 | prop-int = [deadbeef]; 16 | 17 | subsubnode { 18 | compatible = "subsubnode1", "subsubnode"; 19 | prop-int = <0xdeadbeef>; 20 | }; 21 | 22 | ss1 { 23 | }; 24 | }; 25 | 26 | subnode@2 { 27 | reg = <2>; 28 | linux,phandle = <0x2000>; 29 | prop-int = <123456789>; 30 | #address-cells = <1>; 31 | #size-cells = <0>; 32 | 33 | subsubnode@0 { 34 | reg = <0>; 35 | phandle = <0x2001>; 36 | compatible = "subsubnode2", "subsubnode"; 37 | prop-int = <0726746425>; 38 | }; 39 | 40 | ss2 { 41 | }; 42 | }; 43 | }; 44 | -------------------------------------------------------------------------------- /tests/test_tree1_wrong3.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0xdeadbeef00000000 0x100000; 4 | /memreserve/ 123456789 010000; 5 | 6 | / { 7 | compatible = "test_tree1"; 8 | prop-int = <0xdeadbeef>; 9 | prop-str = "hello world"; 10 | #address-cells = <1>; 11 | #size-cells = <0>; 12 | 13 | subnode@1 { 14 | compatible = "subnode1"; 15 | reg = <1>; 16 | 17 | subsubnode { 18 | compatible = "subsubnode1", "subsubnode"; 19 | prop-int = <0xdeadbeef>; 20 | }; 21 | 22 | ss1 { 23 | }; 24 | }; 25 | 26 | subnode@2 { 27 | reg = <2>; 28 | linux,phandle = <0x2000>; 29 | prop-int = <123456789>; 30 | #address-cells = <1>; 31 | #size-cells = <0>; 32 | 33 | subsubnode@0 { 34 | reg = <0>; 35 | phandle = <0x2001>; 36 | compatible = "subsubnode2", "subsubnode"; 37 | prop-int = <0726746425>; 38 | }; 39 | 40 | ss2 { 41 | }; 42 | }; 43 | }; 44 | -------------------------------------------------------------------------------- /tests/test_tree1_wrong4.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0xdeadbeef00000000 0x100000; 4 | /memreserve/ 123456789 010000; 5 | 6 | / { 7 | compatible = "test_tree1"; 8 | prop-int = <0xdeadbeef>; 9 | prop-str = "hello world"; 10 | #address-cells = <1>; 11 | #size-cells = <0>; 12 | 13 | subnode@1 { 14 | compatible = "subnode1"; 15 | reg = <1>; 16 | prop-int = [deadbeef]; 17 | 18 | subsubnode { 19 | compatible = "subsubnode1", "subsubnode"; 20 | prop-int = <0xdeadbeef>; 21 | }; 22 | 23 | ss1 { 24 | }; 25 | }; 26 | 27 | subnode@2 { 28 | reg = <2>; 29 | linux,phandle = <0x2000>; 30 | prop-int = <123456789>; 31 | #address-cells = <1>; 32 | #size-cells = <0>; 33 | 34 | subsubnode@0 { 35 | reg = <0>; 36 | phandle = <0x2001>; 37 | compatible = "subsubnode2", "subsubnode"; 38 | prop-int = <0726746425>; 39 | }; 40 | }; 41 | }; 42 | -------------------------------------------------------------------------------- /tests/test_tree1_wrong5.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0xdeadbeef00000000 0x100000; 4 | /memreserve/ 123456789 010000; 5 | 6 | / { 7 | compatible = "test_tree1"; 8 | prop-int = <0xdeadbefe>; 9 | prop-str = "hello world"; 10 | #address-cells = <1>; 11 | #size-cells = <0>; 12 | 13 | subnode@1 { 14 | compatible = "subnode1"; 15 | reg = <1>; 16 | prop-int = [deadbeef]; 17 | 18 | subsubnode { 19 | compatible = "subsubnode1", "subsubnode"; 20 | prop-int = <0xdeadbeef>; 21 | }; 22 | 23 | ss1 { 24 | }; 25 | }; 26 | 27 | subnode@2 { 28 | reg = <2>; 29 | linux,phandle = <0x2000>; 30 | prop-int = <123456789>; 31 | #address-cells = <1>; 32 | #size-cells = <0>; 33 | 34 | subsubnode@0 { 35 | reg = <0>; 36 | phandle = <0x2001>; 37 | compatible = "subsubnode2", "subsubnode"; 38 | prop-int = <0726746425>; 39 | }; 40 | 41 | ss2 { 42 | }; 43 | }; 44 | }; 45 | -------------------------------------------------------------------------------- /tests/test_tree1_wrong6.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0xdeadbeef00000000 0x100000; 4 | /memreserve/ 123456789 010000; 5 | 6 | / { 7 | compatible = "test_tree1"; 8 | prop-int = <0xdeadbeef>; 9 | prop-str = "hello world"; 10 | #address-cells = <1>; 11 | #size-cells = <0>; 12 | 13 | subnode@1 { 14 | compatible = "subnode1"; 15 | reg = <1>; 16 | prop-int = [deadbeef]; 17 | 18 | subsubnode { 19 | compatible = "subsubnode1", "subsubnode"; 20 | prop-int = <0xdeadbeef>; 21 | }; 22 | 23 | ss1 { 24 | extra-prop; 25 | }; 26 | }; 27 | 28 | subnode@2 { 29 | reg = <2>; 30 | linux,phandle = <0x2000>; 31 | prop-int = <123456789>; 32 | #address-cells = <1>; 33 | #size-cells = <0>; 34 | 35 | subsubnode@0 { 36 | reg = <0>; 37 | phandle = <0x2001>; 38 | compatible = "subsubnode2", "subsubnode"; 39 | prop-int = <0726746425>; 40 | }; 41 | 42 | ss2 { 43 | }; 44 | }; 45 | }; 46 | -------------------------------------------------------------------------------- /tests/test_tree1_wrong7.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0xdeadbeef00000000 0x100000; 4 | /memreserve/ 123456789 010000; 5 | 6 | / { 7 | compatible = "test_tree1"; 8 | prop-int = <0xdeadbeef>; 9 | prop-str = "hello world"; 10 | #address-cells = <1>; 11 | #size-cells = <0>; 12 | 13 | subnode@1 { 14 | compatible = "subnode1"; 15 | reg = <1>; 16 | prop-int = [deadbeef]; 17 | 18 | subsubnode { 19 | compatible = "subsubnode1", "subsubnode"; 20 | prop-int = <0xdeadbeef>; 21 | }; 22 | 23 | ss1 { 24 | }; 25 | }; 26 | 27 | subnode@2 { 28 | reg = <2>; 29 | linux,phandle = <0x2000>; 30 | prop-int = <123456789>; 31 | #address-cells = <1>; 32 | #size-cells = <0>; 33 | 34 | subsubnode@0 { 35 | reg = <0>; 36 | phandle = <0x2001>; 37 | compatible = "subsubnode2", "subsubnode"; 38 | prop-int = <0726746425>; 39 | }; 40 | 41 | ss2 { 42 | extranode { 43 | }; 44 | }; 45 | }; 46 | }; 47 | -------------------------------------------------------------------------------- /tests/test_tree1_wrong8.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0xdeadbeef00000000 0x100000; 4 | /memreserve/ 123456789 010001; 5 | 6 | / { 7 | compatible = "test_tree1"; 8 | prop-int = <0xdeadbeef>; 9 | prop-str = "hello world"; 10 | #address-cells = <1>; 11 | #size-cells = <0>; 12 | 13 | subnode@1 { 14 | compatible = "subnode1"; 15 | reg = <1>; 16 | prop-int = [deadbeef]; 17 | 18 | subsubnode { 19 | compatible = "subsubnode1", "subsubnode"; 20 | prop-int = <0xdeadbeef>; 21 | }; 22 | 23 | ss1 { 24 | }; 25 | }; 26 | 27 | subnode@2 { 28 | linux,phandle = <0x2000>; 29 | prop-int = <123456789>; 30 | #address-cells = <1>; 31 | #size-cells = <0>; 32 | reg = <2>; 33 | 34 | subsubnode@0 { 35 | reg = <0>; 36 | phandle = <0x2001>; 37 | compatible = "subsubnode2", "subsubnode"; 38 | prop-int = <0726746425>; 39 | }; 40 | 41 | ss2 { 42 | }; 43 | }; 44 | }; 45 | -------------------------------------------------------------------------------- /tests/test_tree1_wrong9.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | /memreserve/ 0xdeadbeef00000000 0x100000; 4 | /memreserve/ 123456789 010000; 5 | /memreserve/ 0 1; 6 | 7 | / { 8 | compatible = "test_tree1"; 9 | prop-int = <0xdeadbeef>; 10 | prop-str = "hello world"; 11 | #address-cells = <1>; 12 | #size-cells = <0>; 13 | 14 | subnode@1 { 15 | compatible = "subnode1"; 16 | reg = <1>; 17 | prop-int = [deadbeef]; 18 | 19 | subsubnode { 20 | compatible = "subsubnode1", "subsubnode"; 21 | prop-int = <0xdeadbeef>; 22 | }; 23 | 24 | ss1 { 25 | }; 26 | }; 27 | 28 | subnode@2 { 29 | reg = <2>; 30 | linux,phandle = <0x2000>; 31 | prop-int = <123456789>; 32 | #address-cells = <1>; 33 | #size-cells = <0>; 34 | 35 | subsubnode@0 { 36 | reg = <0>; 37 | phandle = <0x2001>; 38 | compatible = "subsubnode2", "subsubnode"; 39 | prop-int = <0726746425>; 40 | }; 41 | 42 | ss2 { 43 | }; 44 | }; 45 | }; 46 | -------------------------------------------------------------------------------- /tests/testdata.h: -------------------------------------------------------------------------------- 1 | #ifdef __ASSEMBLY__ 2 | #define ASM_CONST_LL(x) (x) 3 | #else 4 | #define ASM_CONST_LL(x) (x##ULL) 5 | #endif 6 | 7 | #define TEST_ADDR_1 ASM_CONST_LL(0xdeadbeef00000000) 8 | #define TEST_SIZE_1 ASM_CONST_LL(0x100000) 9 | #define TEST_ADDR_2 ASM_CONST_LL(123456789) 10 | #define TEST_SIZE_2 ASM_CONST_LL(010000) 11 | 12 | #define TEST_VALUE_1 0xdeadbeef 13 | #define TEST_VALUE_2 123456789 14 | 15 | #define TEST_VALUE64_1 ASM_CONST_LL(0xdeadbeef01abcdef) 16 | 17 | #define PHANDLE_1 0x2000 18 | #define PHANDLE_2 0x2001 19 | 20 | #define TEST_STRING_1 "hello world" 21 | #define TEST_STRING_2 "nastystring: \a\b\t\n\v\f\r\\\"" 22 | #define TEST_STRING_3 "\xde\xad\xbe\xef" 23 | 24 | #define TEST_STRING_4_PARTIAL "foobar" 25 | #define TEST_STRING_4_RESULT "testfoobar" 26 | 27 | #define TEST_CHAR1 '\r' 28 | #define TEST_CHAR2 'b' 29 | #define TEST_CHAR3 '\0' 30 | #define TEST_CHAR4 '\'' 31 | #define TEST_CHAR5 '\xff' 32 | 33 | #ifndef __ASSEMBLY__ 34 | extern struct fdt_header _test_tree1; 35 | extern struct fdt_header _truncated_property; 36 | extern struct fdt_header _bad_node_char; 37 | extern struct fdt_header _bad_node_format; 38 | extern struct fdt_header _bad_prop_char; 39 | extern struct fdt_header _ovf_size_strings; 40 | #endif /* ! __ASSEMBLY */ 41 | -------------------------------------------------------------------------------- /tests/tests.sh: -------------------------------------------------------------------------------- 1 | # Common functions for shell testcases 2 | 3 | PASS () { 4 | echo "PASS" 5 | exit 0 6 | } 7 | 8 | FAIL () { 9 | echo "FAIL" "$@" 10 | exit 2 11 | } 12 | 13 | FAIL_IF_SIGNAL () { 14 | ret="$1" 15 | if [ "$ret" -gt 127 ]; then 16 | signame=$(kill -l $((ret - 128))) 17 | FAIL "Killed by SIG$signame" 18 | fi 19 | } 20 | 21 | DTC=../dtc 22 | DTGET=../fdtget 23 | DTPUT=../fdtput 24 | FDTDUMP=../fdtdump 25 | FDTOVERLAY=../fdtoverlay 26 | 27 | verbose_run () { 28 | if [ -z "$QUIET_TEST" ]; then 29 | "$@" 30 | else 31 | "$@" > /dev/null 2> /dev/null 32 | fi 33 | } 34 | 35 | verbose_run_check () { 36 | verbose_run "$@" 37 | ret="$?" 38 | FAIL_IF_SIGNAL $ret 39 | if [ $ret != 0 ]; then 40 | FAIL "Returned error code $ret" 41 | fi 42 | } 43 | 44 | verbose_run_log () { 45 | LOG="$1" 46 | shift 47 | "$@" > "$LOG" 2>&1 48 | ret=$? 49 | if [ -z "$QUIET_TEST" ]; then 50 | cat "$LOG" >&2 51 | fi 52 | return $ret 53 | } 54 | 55 | verbose_run_log_check () { 56 | verbose_run_log "$@" 57 | ret="$?" 58 | FAIL_IF_SIGNAL $ret 59 | if [ $ret != 0 ]; then 60 | FAIL "Returned error code $ret" 61 | fi 62 | } 63 | 64 | -------------------------------------------------------------------------------- /tests/truncated_property.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libfdt - Flat Device Tree manipulation 3 | * Testcase for misbehaviour on a truncated property 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public License 8 | * as published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "tests.h" 29 | #include "testdata.h" 30 | 31 | int main(int argc, char *argv[]) 32 | { 33 | void *fdt = &_truncated_property; 34 | const void *prop; 35 | int len; 36 | 37 | test_init(argc, argv); 38 | 39 | prop = fdt_getprop(fdt, 0, "truncated", &len); 40 | if (prop) 41 | FAIL("fdt_getprop() succeeded on truncated property"); 42 | if (len != -FDT_ERR_BADSTRUCTURE) 43 | FAIL("fdt_getprop() failed with \"%s\" instead of \"%s\"", 44 | fdt_strerror(len), fdt_strerror(-FDT_ERR_BADSTRUCTURE)); 45 | 46 | PASS(); 47 | } 48 | -------------------------------------------------------------------------------- /tests/unit-addr-leading-0s.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = <1>; 5 | #size-cells = <1>; 6 | 7 | bus { 8 | node@001 { 9 | reg = <1 0>; 10 | }; 11 | }; 12 | }; 13 | -------------------------------------------------------------------------------- /tests/unit-addr-leading-0x.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = <1>; 5 | #size-cells = <1>; 6 | 7 | bus { 8 | node@0x1 { 9 | reg = <1 0>; 10 | }; 11 | }; 12 | }; 13 | -------------------------------------------------------------------------------- /tests/unit-addr-without-reg.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | #address-cells = <1>; 5 | #size-cells = <1>; 6 | 7 | node@1 { 8 | }; 9 | }; 10 | -------------------------------------------------------------------------------- /tests/value-labels.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | prop1: prop1 = start1: "a", mid1: "b" end1:; 5 | prop2: prop2 = start2: < innerstart2: 0xdeadbeef innermid2: 0xabcd1234 innerend2: > end2:; 6 | prop3: prop3 = start3: [ innerstart3: ab innermid3: cd innerend3: ] end3:; 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /tests/zero-phandle.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | 3 | / { 4 | node { 5 | linux,phandle = <0>; 6 | }; 7 | }; 8 | -------------------------------------------------------------------------------- /version_non_gen.h: -------------------------------------------------------------------------------- 1 | #define DTC_VERSION "DTC 1.4.4-Android-build" 2 | --------------------------------------------------------------------------------