Compare commits
376 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
52f07dcca4 | |
![]() |
9cabae6b03 | |
![]() |
605dc044c3 | |
![]() |
7da5d106c7 | |
![]() |
53c63dd421 | |
![]() |
84d9dd2fcb | |
![]() |
97011d1f4e | |
![]() |
b841391bbd | |
![]() |
e0b7749c26 | |
![]() |
ecb21febfd | |
![]() |
7ebfcac852 | |
![]() |
f4c53f4ebf | |
![]() |
205fbef17b | |
![]() |
da85f91931 | |
![]() |
dd1b3e532d | |
![]() |
1ccd232709 | |
![]() |
ce1d858888 | |
![]() |
915daadbb6 | |
![]() |
4ea851f5a4 | |
![]() |
175d2a564c | |
![]() |
18f4f305fd | |
![]() |
267efc7d46 | |
![]() |
755db11535 | |
![]() |
bdca861200 | |
![]() |
0f69cedc08 | |
![]() |
56b2b30c5b | |
![]() |
1e8c5f60e1 | |
![]() |
6f183c7d92 | |
![]() |
66c7d0e6f4 | |
![]() |
9a969f3b70 | |
![]() |
4292b072a2 | |
![]() |
1c745a9bd1 | |
![]() |
b3bbee6b12 | |
![]() |
d1656730ab | |
![]() |
b75515af45 | |
![]() |
2d10aa2afe | |
![]() |
48795c82bd | |
![]() |
838f11e830 | |
![]() |
d1e2384185 | |
![]() |
18aa49a9f6 | |
![]() |
f9968fa069 | |
![]() |
9b5f65fb3d | |
![]() |
99031e3a4a | |
![]() |
3d5e376925 | |
![]() |
e277553b98 | |
![]() |
7e5a889840 | |
![]() |
78b6a85c11 | |
![]() |
3501d373f0 | |
![]() |
bcd02b5234 | |
![]() |
84b056a89d | |
![]() |
1df7b047fe | |
![]() |
61e88fdcec | |
![]() |
49d3089446 | |
![]() |
d54aaf9367 | |
![]() |
ab86f1e9fd | |
![]() |
7b8a30ecea | |
![]() |
ff4f17eb58 | |
![]() |
9e313b14e6 | |
![]() |
d598fc3648 | |
![]() |
b98239da2f | |
![]() |
c17d76ab5e | |
![]() |
ae26223a05 | |
![]() |
4dd831affd | |
![]() |
e6d2942008 | |
![]() |
855c934e26 | |
![]() |
4fd3f4f0a9 | |
![]() |
9ca7d62dbf | |
![]() |
bb51223083 | |
![]() |
e81900635c | |
![]() |
8221238569 | |
![]() |
1fad065080 | |
![]() |
b0aacd0a77 | |
![]() |
ae97d97458 | |
![]() |
057a7dbbb7 | |
![]() |
92b5d4e916 | |
![]() |
417e3299db | |
![]() |
5e6cefa17e | |
![]() |
24f60011fd | |
![]() |
da39ee0e68 | |
![]() |
a669223f7a | |
![]() |
3fbfdd08af | |
![]() |
dcef5f834e | |
![]() |
0b8026ff25 | |
![]() |
95c74d71f0 | |
![]() |
2283dd78ef | |
![]() |
79b9e326a1 | |
![]() |
52157f13ef | |
![]() |
d774337275 | |
![]() |
ad8bf9f9aa | |
![]() |
6c5e189fb9 | |
![]() |
a3dc9f006a | |
![]() |
35019949c4 | |
![]() |
cd3e2304f4 | |
![]() |
0f58645677 | |
![]() |
38165954c1 | |
![]() |
5e98b59793 | |
![]() |
d030a893be | |
![]() |
8d8372b137 | |
![]() |
761114effa | |
![]() |
bf6377a98d | |
![]() |
4c68e4b16b | |
![]() |
bdc5c8793a | |
![]() |
f088e381f2 | |
![]() |
6df5328a90 | |
![]() |
ccf1f62d59 | |
![]() |
71a8b8ef0a | |
![]() |
589d8c7653 | |
![]() |
e8364666d5 | |
![]() |
3b02a94b48 | |
![]() |
d4888958d6 | |
![]() |
ea3b9a1d2c | |
![]() |
b2b9671583 | |
![]() |
ab481e4830 | |
![]() |
c88038c9b8 | |
![]() |
0ac8b30ba5 | |
![]() |
f1657b2fb5 | |
![]() |
44bb89cafd | |
![]() |
60bcf1cde1 | |
![]() |
a6f997bc77 | |
![]() |
18f5ec12a1 | |
![]() |
df09327928 | |
![]() |
129bb4b78b | |
![]() |
390f481521 | |
![]() |
9f8b382ed4 | |
![]() |
2cdf93a6d4 | |
![]() |
72fc810c30 | |
![]() |
083ab26da8 | |
![]() |
6f8b28f496 | |
![]() |
fd68bb8c56 | |
![]() |
4718189c4c | |
![]() |
0b842c3c81 | |
![]() |
9cceabea1e | |
![]() |
0d56145938 | |
![]() |
61fa22b05f | |
![]() |
7a1d72a788 | |
![]() |
ee57999386 | |
![]() |
44c9b73801 | |
![]() |
5b60f5104f | |
![]() |
32174a66ef | |
![]() |
64a907f08b | |
![]() |
e3cde0613b | |
![]() |
4182182110 | |
![]() |
71c19f20b3 | |
![]() |
039a99414e | |
![]() |
9b62ec84bb | |
![]() |
3f29d6d85c | |
![]() |
2022bb1087 | |
![]() |
abbd523bae | |
![]() |
a41509bea3 | |
![]() |
2cd89f862c | |
![]() |
55778a03df | |
![]() |
73590342fc | |
![]() |
035fb90d53 | |
![]() |
98a07006c4 | |
![]() |
a036cc7b0c | |
![]() |
c6e92108bc | |
![]() |
e37c25677d | |
![]() |
50454658f2 | |
![]() |
e64a204196 | |
![]() |
f508c83fe6 | |
![]() |
c2ccf8a77d | |
![]() |
90b9d9de42 | |
![]() |
0ee1d479b2 | |
![]() |
b33a73c62c | |
![]() |
7ad60734b1 | |
![]() |
fd9b8c96c7 | |
![]() |
fda71da26e | |
![]() |
c7c7f17a83 | |
![]() |
01f23ffe16 | |
![]() |
ed310803ea | |
![]() |
c001fc01a4 | |
![]() |
26c54f840d | |
![]() |
ec7986e682 | |
![]() |
651410e54c | |
![]() |
4048aed12b | |
![]() |
ff5afb96d0 | |
![]() |
ca72944343 | |
![]() |
c0c2e115f8 | |
![]() |
cd5f69cbc0 | |
![]() |
a04f690250 | |
![]() |
83102717d7 | |
![]() |
d152126bb0 | |
![]() |
17739b7ef5 | |
![]() |
45f3d1a095 | |
![]() |
c19a4bafa5 | |
![]() |
1cc41b1c96 | |
![]() |
db72398cd4 | |
![]() |
383e148b70 | |
![]() |
23b56cb7e1 | |
![]() |
69a760747d | |
![]() |
0b106a77db | |
![]() |
c691776ddb | |
![]() |
5216f3f1bb | |
![]() |
4eda2590f4 | |
![]() |
0a3a9d3449 | |
![]() |
8fd24744e3 | |
![]() |
d8d1a9a778 | |
![]() |
52a16fd728 | |
![]() |
37fd700685 | |
![]() |
e33ce1d6a8 | |
![]() |
d24cc189dc | |
![]() |
ff3a30c115 | |
![]() |
5eb5927d81 | |
![]() |
0869f82691 | |
![]() |
69595a167f | |
![]() |
72d09e2682 | |
![]() |
b587787ef3 | |
![]() |
69bed6c241 | |
![]() |
9102211855 | |
![]() |
d966f08fcd | |
![]() |
ecfb438c07 | |
![]() |
5bec74a6d1 | |
![]() |
24e7f511fd | |
![]() |
b6910bec11 | |
![]() |
21d61d18f9 | |
![]() |
4c2ef8f4d1 | |
![]() |
e59ca36fb7 | |
![]() |
0c3fd9b6ac | |
![]() |
6b3081abc4 | |
![]() |
2dffc192a7 | |
![]() |
61e513439e | |
![]() |
c8bddd1060 | |
![]() |
ad4abfadb6 | |
![]() |
09c6a6e887 | |
![]() |
9bb9b8d0b4 | |
![]() |
b07b62ee33 | |
![]() |
a2def54799 | |
![]() |
4ca61f84dc | |
![]() |
34d708249a | |
![]() |
8e7ff260f7 | |
![]() |
88875268c0 | |
![]() |
9d2279e7e6 | |
![]() |
f527c867a8 | |
![]() |
183df9e9c2 | |
![]() |
0db6d09584 | |
![]() |
307afa1a7b | |
![]() |
ca16a723fa | |
![]() |
64990a272e | |
![]() |
163f0469bf | |
![]() |
3b01518e68 | |
![]() |
f7e5737f26 | |
![]() |
7cd5d5fe43 | |
![]() |
a7c4040993 | |
![]() |
bab85e48a6 | |
![]() |
f8b4609882 | |
![]() |
30a56bce4f | |
![]() |
5e735860c4 | |
![]() |
67849a3279 | |
![]() |
05874d0821 | |
![]() |
3bc3a6b9fe | |
![]() |
e1147b159e | |
![]() |
04cf1fdc0f | |
![]() |
b30013edb8 | |
![]() |
cbca977ea1 | |
![]() |
73e0f143b7 | |
![]() |
6c2be7d853 | |
![]() |
82525f41d5 | |
![]() |
fb1f65f158 | |
![]() |
f28aa27100 | |
![]() |
3d7c6f4419 | |
![]() |
10f682788c | |
![]() |
07158f4cf2 | |
![]() |
ce9e1f25a7 | |
![]() |
faa76fc10b | |
![]() |
54dca09853 | |
![]() |
f8e11e6162 | |
![]() |
0c43d4d7bf | |
![]() |
442ea3dd15 | |
![]() |
ca19c3db2b | |
![]() |
7bb86f1c09 | |
![]() |
3d522abc75 | |
![]() |
808cdaaf52 | |
![]() |
3e3138b4a9 | |
![]() |
9d7888cbf1 | |
![]() |
8259d59f59 | |
![]() |
fdabcf2980 | |
![]() |
2478b1652c | |
![]() |
f68bfc2668 | |
![]() |
7be250b4d0 | |
![]() |
81e0919a3e | |
![]() |
85e5d83984 | |
![]() |
b28464a550 | |
![]() |
87a656ae5f | |
![]() |
73d6e9ecb4 | |
![]() |
2525da3dba | |
![]() |
62cb4ad286 | |
![]() |
1f9a417508 | |
![]() |
c5995ddf4c | |
![]() |
e4ce227e89 | |
![]() |
9b75292c33 | |
![]() |
6c253afd07 | |
![]() |
95ec8ef706 | |
![]() |
2b5f62d109 | |
![]() |
76b43dcbd1 | |
![]() |
e5c92a4780 | |
![]() |
e5cc26b68b | |
![]() |
28fd7590aa | |
![]() |
fc207c3234 | |
![]() |
0f61c72ded | |
![]() |
f270f45fd5 | |
![]() |
c18bae9a4c | |
![]() |
fc03c4a2e0 | |
![]() |
77563ae72b | |
![]() |
57bc6327b8 | |
![]() |
464962489d | |
![]() |
0c5326cb28 | |
![]() |
cc6a5a0715 | |
![]() |
0e9225eb0d | |
![]() |
cab09eedd6 | |
![]() |
0eb1cb0b53 | |
![]() |
c40aeb60b4 | |
![]() |
9f86aff444 | |
![]() |
34c82275ba | |
![]() |
743000931b | |
![]() |
adcd676491 | |
![]() |
d9c55f855b | |
![]() |
7a22132c79 | |
![]() |
dbe80d577e | |
![]() |
af57d440d8 | |
![]() |
6ce585ac15 | |
![]() |
7150286225 | |
![]() |
fdf3f6d897 | |
![]() |
430419c281 | |
![]() |
588a29ff2e | |
![]() |
bc876708ab | |
![]() |
4c3c4ccb99 | |
![]() |
aa522da9ff | |
![]() |
0d0d0fa51b | |
![]() |
4605eb047b | |
![]() |
18d7b2f4ee | |
![]() |
67f790c1ad | |
![]() |
b111122ea5 | |
![]() |
60e0db3d65 | |
![]() |
95ce19c140 | |
![]() |
5345db19f6 | |
![]() |
b8d6eca782 | |
![]() |
184f510994 | |
![]() |
812b1956a0 | |
![]() |
5c715a4477 | |
![]() |
b993534748 | |
![]() |
d6de81b81b | |
![]() |
1c17714dbb | |
![]() |
ad57e4574a | |
![]() |
bbe3b36f54 | |
![]() |
6c2e61f083 | |
![]() |
297f5abb36 | |
![]() |
702c1b6c0e | |
![]() |
4097bbffcf | |
![]() |
94f87cd5b7 | |
![]() |
c4ffc05574 | |
![]() |
a5ac29baac | |
![]() |
7fb0f4db2e | |
![]() |
acfe84f2c4 | |
![]() |
87963ee206 | |
![]() |
825146d13d | |
![]() |
25bb080c18 | |
![]() |
243176c4ce | |
![]() |
ce01b21098 | |
![]() |
fbb62754ce | |
![]() |
228a44cce8 | |
![]() |
8f69567622 | |
![]() |
5c3513f689 | |
![]() |
00f9febf9c | |
![]() |
c5d45188f9 | |
![]() |
6ef8fcd05b | |
![]() |
26ee65a16c | |
![]() |
cca6546244 | |
![]() |
730875016a | |
![]() |
7dfb61ba96 | |
![]() |
2bc5b66d7f | |
![]() |
7fcf8208b8 | |
![]() |
ae795b2db7 | |
![]() |
eac2ad495b | |
![]() |
f67b471355 | |
![]() |
54ea41c224 | |
![]() |
4762ad051e |
|
@ -0,0 +1,135 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
#
|
||||
# clang-format configuration file. Intended for clang-format >= 11.
|
||||
#
|
||||
# For more information, see:
|
||||
#
|
||||
# Documentation/dev-tools/clang-format.rst
|
||||
# https://clang.llvm.org/docs/ClangFormat.html
|
||||
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||
#
|
||||
---
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakBeforeTernaryOperators: false
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: false
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 8
|
||||
ContinuationIndentWidth: 8
|
||||
Cpp11BracedListStyle: false
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: false
|
||||
|
||||
# Taken from:
|
||||
# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
|
||||
# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
|
||||
# | LC_ALL=C sort -u
|
||||
ForEachMacros:
|
||||
- 'fdt_for_each_property_offset'
|
||||
- 'fdt_for_each_subnode'
|
||||
- 'for_each_child'
|
||||
- 'for_each_child_withdel'
|
||||
- 'for_each_label'
|
||||
- 'for_each_label_withdel'
|
||||
- 'for_each_marker'
|
||||
- 'for_each_marker_of_type'
|
||||
- 'for_each_property'
|
||||
- 'for_each_property_withdel'
|
||||
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
IndentGotoLabels: false
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 8
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 8
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
|
||||
# Taken from git's rules
|
||||
PenaltyBreakAssignment: 10
|
||||
PenaltyBreakBeforeFirstCallParameter: 30
|
||||
PenaltyBreakComment: 10
|
||||
PenaltyBreakFirstLessLess: 0
|
||||
PenaltyBreakString: 10
|
||||
PenaltyExcessCharacter: 100
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
|
||||
PointerAlignment: Right
|
||||
ReflowComments: false
|
||||
SortIncludes: false
|
||||
SortUsingDeclarations: false
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatementsExceptForEachMacros
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp03
|
||||
TabWidth: 8
|
||||
UseTab: Always
|
||||
...
|
|
@ -0,0 +1,33 @@
|
|||
# EditorConfig is a file format and collection of text editor plugins
|
||||
# for maintaining consistent coding styles between different editors
|
||||
# and IDEs. Most popular editors support this either natively or via
|
||||
# plugin.
|
||||
#
|
||||
# Check https://editorconfig.org for details.
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
|
||||
[Makefile*]
|
||||
indent_style = tab
|
||||
indent_size = 8
|
||||
file_type_emacs = makefile
|
||||
|
||||
[*.[ch]]
|
||||
indent_style = tab
|
||||
indent_size = 8
|
||||
|
||||
[*.py]
|
||||
indent_size = 4
|
||||
|
||||
[meson.build]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.lds]
|
||||
indent_style = tab
|
|
@ -0,0 +1,113 @@
|
|||
---
|
||||
name: Build test
|
||||
'on':
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
# ensure that the workflow is only triggered once per PR, subsequent pushes to the PR will cancel
|
||||
# and restart the workflow. See https://docs.github.com/en/actions/using-jobs/using-concurrency
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build-make:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ "alpine", "archlinux", "fedora", "ubuntu" ]
|
||||
|
||||
container:
|
||||
image: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
./scripts/install-deps.sh
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
make
|
||||
|
||||
- name: Run check
|
||||
run: |
|
||||
make check
|
||||
|
||||
build-meson:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ "alpine", "archlinux", "fedora", "ubuntu" ]
|
||||
|
||||
container:
|
||||
image: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
./scripts/install-deps.sh
|
||||
|
||||
- name: Setup
|
||||
run: meson setup -D python=enabled -D yaml=enabled build
|
||||
|
||||
- name: Build
|
||||
run: meson compile -C build
|
||||
|
||||
- name: Run check
|
||||
run: if ! meson test -C build; then cat build/meson-logs/testlog.txt; false; fi
|
||||
|
||||
build-windows:
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- { sys: mingw32 }
|
||||
- { sys: mingw64 }
|
||||
- { sys: ucrt64 }
|
||||
- { sys: clang64 }
|
||||
name: ${{ matrix.sys }}
|
||||
defaults:
|
||||
run:
|
||||
shell: msys2 {0}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup MSYS2
|
||||
uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
msystem: ${{matrix.sys}}
|
||||
update: true
|
||||
install: >-
|
||||
git
|
||||
flex
|
||||
bison
|
||||
pacboy: >-
|
||||
toolchain:p
|
||||
meson:p
|
||||
ninja:p
|
||||
libyaml:p
|
||||
swig:p
|
||||
python-setuptools-scm:p
|
||||
|
||||
- name: '🚧 Build'
|
||||
run: |
|
||||
meson setup -Dtools=true -Dtests=false build
|
||||
meson compile -C build
|
|
@ -3,10 +3,13 @@
|
|||
*.a
|
||||
*.patch
|
||||
*.so
|
||||
*.so.*
|
||||
*~
|
||||
*.bak
|
||||
*.tab.[ch]
|
||||
lex.yy.c
|
||||
*.lex.c
|
||||
.*.swp
|
||||
/dtc
|
||||
/fdtdump
|
||||
/convert-dtsv0
|
||||
|
@ -16,3 +19,12 @@ lex.yy.c
|
|||
/fdtoverlay
|
||||
/patches
|
||||
/.pc
|
||||
|
||||
# cscope files
|
||||
cscope.*
|
||||
ncscope.*
|
||||
|
||||
.eggs/
|
||||
build/
|
||||
dist/
|
||||
*.egg-info/
|
||||
|
|
33
.travis.yml
33
.travis.yml
|
@ -1,33 +0,0 @@
|
|||
language: c
|
||||
|
||||
# Coverity Scan uploads
|
||||
env:
|
||||
global:
|
||||
# COVERITY_SCAN_TOKEN (dgibson/dtc)
|
||||
- secure: "vlHvXe618//IM9LQaKzqsrUbjs7ng0L9UCST4kJbJnFQDXvVe5JiSmJGd4ef7mm0NUv5bMRl2W3xCiu6BYAu/NvU3tMNHoLG+JgCJs0+wLJXbWOwji/NmH7olqgJG+CmpaCMXjARF6+nrTnBYHJL6cYyf4KVoV4B0I/hLUW91+s="
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- addons:
|
||||
apt:
|
||||
packages:
|
||||
- swig
|
||||
- python-dev
|
||||
- valgrind
|
||||
- libyaml-0-2
|
||||
coverity_scan:
|
||||
project:
|
||||
name: dtc
|
||||
description: Device Tree Compiler
|
||||
notification_email: david@gibson.dropbear.id.au
|
||||
build_command: make
|
||||
branch_pattern: coverity_scan
|
||||
script:
|
||||
- make
|
||||
- make check && make checkm
|
||||
|
||||
# Check it builds properly without optional packages:
|
||||
# python, valgrind, libyaml
|
||||
- script:
|
||||
- make
|
||||
- make check
|
|
@ -0,0 +1,32 @@
|
|||
Valid-License-Identifier: BSD-2-Clause
|
||||
SPDX-URL: https://spdx.org/licenses/BSD-2-Clause.html
|
||||
Usage-Guide:
|
||||
To use the BSD 2-clause "Simplified" License put the following SPDX
|
||||
tag/value pair into a comment according to the placement guidelines in
|
||||
the licensing rules documentation:
|
||||
SPDX-License-Identifier: BSD-2-Clause
|
||||
License-Text:
|
||||
|
||||
Copyright (c) <year> <owner> . All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,79 @@
|
|||
# Contributing to dtc or libfdt
|
||||
|
||||
There are two ways to submit changes for dtc or libfdt:
|
||||
|
||||
* Post patches directly to the
|
||||
[devicetree-compiler](mailto:devicetree-compiler@vger.kernel.org)
|
||||
mailing list.
|
||||
* Submit pull requests via
|
||||
[Github](https://github.com/dgibson/dtc/pulls)
|
||||
|
||||
## Adding a new function to libfdt.h
|
||||
|
||||
The shared library uses `libfdt/version.lds` to list the exported
|
||||
functions, so add your new function there. Check that your function
|
||||
works with pylibfdt. If it cannot be supported, put the declaration in
|
||||
`libfdt.h` behind `#ifndef SWIG` so that swig ignores it.
|
||||
|
||||
## Tests
|
||||
|
||||
Test files are kept in the `tests/` directory. Use `make check` to build and run
|
||||
all tests.
|
||||
|
||||
If you want to adjust a test file, be aware that `tree_tree1.dts` is compiled
|
||||
and checked against a binary tree from assembler macros in `trees.S`. So
|
||||
if you change that file you must change `tree.S` also.
|
||||
|
||||
## Developer's Certificate of Origin
|
||||
|
||||
Like many other projects, dtc and libfdt have adopted the "Developer's
|
||||
Certificate of Origin" (Signed-off-by) process created by the Linux
|
||||
kernel community to improve tracking of who did what. Here's how it
|
||||
works (this is a very slight modification of the description from
|
||||
`Documentation/process/submitting-patches.rst` in the kernel tree):
|
||||
|
||||
The sign-off is a simple line at the end of the explanation for the
|
||||
patch, which certifies that you wrote it or otherwise have the right
|
||||
to pass it on as an open-source patch. The rules are pretty simple:
|
||||
if you can certify the below:
|
||||
|
||||
Developer's Certificate of Origin 1.1
|
||||
|
||||
By making a contribution to this project, I certify that:
|
||||
|
||||
(a) The contribution was created in whole or in part by me and I
|
||||
have the right to submit it under the open source license
|
||||
indicated in the file; or
|
||||
|
||||
(b) The contribution is based upon previous work that, to the best
|
||||
of my knowledge, is covered under an appropriate open source
|
||||
license and I have the right under that license to submit that
|
||||
work with modifications, whether created in whole or in part
|
||||
by me, under the same open source license (unless I am
|
||||
permitted to submit under a different license), as indicated
|
||||
in the file; or
|
||||
|
||||
(c) The contribution was provided directly to me by some other
|
||||
person who certified (a), (b) or (c) and I have not modified
|
||||
it.
|
||||
|
||||
(d) I understand and agree that this project and the contribution
|
||||
are public and that a record of the contribution (including all
|
||||
personal information I submit with it, including my sign-off) is
|
||||
maintained indefinitely and may be redistributed consistent with
|
||||
this project or the open source license(s) involved.
|
||||
|
||||
then you just add a line saying::
|
||||
|
||||
Signed-off-by: Random J Developer <random@developer.example.org>
|
||||
|
||||
using your real name (sorry, no pseudonyms or anonymous
|
||||
contributions.) This will be done for you automatically if you use
|
||||
`git commit -s`. Reverts should also include "Signed-off-by". `git
|
||||
revert -s` does that for you.
|
||||
|
||||
Any further SoBs (Signed-off-by:'s) following the author's SoB are
|
||||
from people handling and transporting the patch, but were not involved
|
||||
in its development. SoB chains should reflect the **real** route a
|
||||
patch took as it was propagated to the maintainers, with the first SoB
|
||||
entry signalling primary authorship of a single author.
|
|
@ -6,7 +6,7 @@ the hardware capabilities. This is insufficient for platforms
|
|||
that need to dynamically insert Device Tree fragments into the
|
||||
live tree.
|
||||
|
||||
This document explains the the Device Tree object format and
|
||||
This document explains the Device Tree object format and
|
||||
modifications made to the Device Tree compiler, which make it possible.
|
||||
|
||||
1. Simplified Problem Definition
|
||||
|
@ -35,7 +35,7 @@ We have a number of peripherals that after probing (using some undefined method)
|
|||
should result in different Device Tree configuration.
|
||||
|
||||
We cannot boot with this static tree because due to the configuration of the
|
||||
foo platform there exist multiple conficting peripherals DT fragments.
|
||||
foo platform there exist multiple conflicting peripherals DT fragments.
|
||||
|
||||
So for the bar peripheral we would have this:
|
||||
|
||||
|
|
|
@ -37,15 +37,14 @@ The upstream repository is here:
|
|||
git://git.kernel.org/pub/scm/utils/dtc/dtc.git
|
||||
https://git.kernel.org/pub/scm/utils/dtc/dtc.git
|
||||
|
||||
The gitweb interface for the upstream respository is:
|
||||
The gitweb interface for the upstream repository is:
|
||||
|
||||
https://git.kernel.org/cgit/utils/dtc/dtc.git/
|
||||
|
||||
1.1) Submitting Patches
|
||||
|
||||
Patches should be sent to the maintainers:
|
||||
Patches should be sent to the maintainer:
|
||||
David Gibson <david@gibson.dropbear.id.au>
|
||||
Jon Loeliger <jdl@jdl.com>
|
||||
and CCed to <devicetree-compiler@vger.kernel.org>.
|
||||
|
||||
2) Description
|
||||
|
@ -123,12 +122,24 @@ Options:
|
|||
Relevant for dtb and asm output only.
|
||||
|
||||
-@
|
||||
Generates a __symbols__ node at the root node of the resulting blob
|
||||
for any node labels used, and for any local references using phandles
|
||||
it also generates a __local_fixups__ node that tracks them.
|
||||
Generates a __symbols__ node at the root node. This node contains a
|
||||
property for each label. The property's name is the label name and the
|
||||
value is the path of the labeled node.
|
||||
|
||||
When using the /plugin/ tag all unresolved label references to
|
||||
be tracked in the __fixups__ node, making dynamic resolution possible.
|
||||
-L
|
||||
Possibly generates a __local_fixups__ and a __fixups__ node at the root node.
|
||||
For each property that contains a phandle reference using a locally
|
||||
defined phandle, the __local_fixups__ node contains a property (at path
|
||||
/__local_fixups__/$a if $a is the path of the node). Its value is a list
|
||||
of offsets that are phandle values. If there are no such properties, no
|
||||
__local_fixups__ node is generated.
|
||||
For each undefined label used in at least one reference, the __fixups__
|
||||
node contains a property. Its name is the label name, its value is a
|
||||
list of locations where the label is used in a reference in the format
|
||||
"path:property:offset". If there is no undefined label, no __fixups__
|
||||
nodes is generated.
|
||||
Enabled by default for compiling overlays (i.e. dts files with a
|
||||
/plugin/ tag).
|
||||
|
||||
-A
|
||||
Generate automatically aliases for all node labels. This is similar to
|
||||
|
@ -234,7 +245,7 @@ For example:
|
|||
"childnode at address". It in turn has a string property
|
||||
called "childprop".
|
||||
|
||||
childnode@addresss {
|
||||
childnode@address {
|
||||
childprop = "hello\n";
|
||||
};
|
||||
|
||||
|
@ -253,7 +264,7 @@ Labels may be applied to nodes or properties. Labels appear
|
|||
before a node name, and are referenced using an ampersand: &label.
|
||||
Absolute node path names are also allowed in node references.
|
||||
|
||||
In this exmaple, a node is labled "mpic" and then referenced:
|
||||
In this example, a node is labeled "mpic" and then referenced:
|
||||
|
||||
mpic: interrupt-controller@40000 {
|
||||
...
|
||||
|
@ -264,7 +275,7 @@ In this exmaple, a node is labled "mpic" and then referenced:
|
|||
...
|
||||
};
|
||||
|
||||
And used in properties, lables may appear before or after any value:
|
||||
And used in properties, labels may appear before or after any value:
|
||||
|
||||
randomnode {
|
||||
prop: string = data: "mystring\n" data_end: ;
|
||||
|
@ -418,7 +429,7 @@ value of r3.
|
|||
among others, by kexec. If you are on an SMP system, this value
|
||||
should match the content of the "reg" property of the CPU node in
|
||||
the device-tree corresponding to the CPU calling the kernel entry
|
||||
point (see further chapters for more informations on the required
|
||||
point (see further chapters for more information on the required
|
||||
device-tree contents)
|
||||
|
||||
- size_dt_strings
|
||||
|
@ -584,7 +595,7 @@ looks like in practice.
|
|||
|
||||
This tree is almost a minimal tree. It pretty much contains the
|
||||
minimal set of required nodes and properties to boot a linux kernel;
|
||||
that is, some basic model informations at the root, the CPUs, and the
|
||||
that is, some basic model information at the root, the CPUs, and the
|
||||
physical memory layout. It also includes misc information passed
|
||||
through /chosen, like in this example, the platform type (mandatory)
|
||||
and the kernel command line arguments (optional).
|
||||
|
@ -712,7 +723,7 @@ The syntax of the fdtget command is:
|
|||
|
||||
where options are:
|
||||
|
||||
<type> s=string, i=int, u=unsigned, x=hex
|
||||
<type> s=string, i=int, u=unsigned, x=hex, r=raw
|
||||
Optional modifier prefix:
|
||||
hh or b=byte, h=2 byte, l=4 byte (default)
|
||||
|
||||
|
|
41
GPL
41
GPL
|
@ -1,12 +1,12 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
|
@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This
|
|||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
|
@ -55,8 +55,8 @@ patent must be licensed for everyone's free use or not licensed at all.
|
|||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
|
@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
|
|||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
|
@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
|
|||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
|
@ -225,7 +225,7 @@ impose that choice.
|
|||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
|
@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals
|
|||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
|
@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
|
@ -303,17 +303,16 @@ the "copyright" line and a pointer to where the full notice is found.
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
@ -336,5 +335,5 @@ necessary. Here is a sample; alter the names:
|
|||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
|
|
133
Makefile
133
Makefile
|
@ -1,32 +1,38 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#
|
||||
# Device Tree Compiler
|
||||
#
|
||||
|
||||
$(warning WARNING: Building dtc using make is deprecated, in favour of using Meson (https://mesonbuild.com))
|
||||
$(warning )
|
||||
$(warning Use `meson setup builddir/ && meson compile -C builddir/` to build, `meson test -C builddir/` to test, or `meson configure` to see build options.)
|
||||
|
||||
#
|
||||
# Version information will be constructed in this order:
|
||||
# EXTRAVERSION might be "-rc", for example.
|
||||
# DTC_VERSION release version as MAJOR.MINOR.PATCH
|
||||
# LOCAL_VERSION is likely from command line.
|
||||
# CONFIG_LOCALVERSION from some future config system.
|
||||
#
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 5
|
||||
SUBLEVEL = 0
|
||||
EXTRAVERSION =
|
||||
DTC_VERSION = $(shell cat VERSION.txt)
|
||||
LOCAL_VERSION =
|
||||
CONFIG_LOCALVERSION =
|
||||
|
||||
CPPFLAGS = -I libfdt -I .
|
||||
WARNINGS = -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \
|
||||
-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wshadow
|
||||
CFLAGS = -g -Os $(SHAREDLIB_CFLAGS) -Werror $(WARNINGS)
|
||||
# Control the assumptions made (e.g. risking security issues) in the code.
|
||||
# See libfdt_internal.h for details
|
||||
ASSUME_MASK ?= 0
|
||||
|
||||
CPPFLAGS = -I libfdt -I . -DFDT_ASSUME_MASK=$(ASSUME_MASK)
|
||||
WARNINGS = -Wall -Wpointer-arith -Wcast-qual -Wnested-externs -Wsign-compare \
|
||||
-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wshadow \
|
||||
-Wsuggest-attribute=format -Wwrite-strings
|
||||
CFLAGS = -g -Os $(SHAREDLIB_CFLAGS) -Werror $(WARNINGS) $(EXTRA_CFLAGS)
|
||||
|
||||
BISON = bison
|
||||
LEX = flex
|
||||
SWIG = swig
|
||||
PKG_CONFIG ?= pkg-config
|
||||
PYTHON ?= python2
|
||||
|
||||
INSTALL = /usr/bin/install
|
||||
INSTALL = install
|
||||
INSTALL_PROGRAM = $(INSTALL)
|
||||
INSTALL_LIB = $(INSTALL)
|
||||
INSTALL_DATA = $(INSTALL) -m 644
|
||||
|
@ -42,16 +48,21 @@ HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
|
|||
|
||||
NO_VALGRIND := $(shell $(PKG_CONFIG) --exists valgrind; echo $$?)
|
||||
ifeq ($(NO_VALGRIND),1)
|
||||
CFLAGS += -DNO_VALGRIND
|
||||
CPPFLAGS += -DNO_VALGRIND
|
||||
else
|
||||
CFLAGS += $(shell $(PKG_CONFIG) --cflags valgrind)
|
||||
endif
|
||||
|
||||
NO_YAML := $(shell $(PKG_CONFIG) --exists yaml-0.1; echo $$?)
|
||||
# libyaml before version 0.2.3 expects non-const string parameters. Supporting
|
||||
# both variants would require either cpp magic or passing
|
||||
# -Wno-error=discarded-qualifiers to the compiler. For the sake of simplicity
|
||||
# just support libyaml >= 0.2.3.
|
||||
NO_YAML := $(shell $(PKG_CONFIG) --atleast-version 0.2.3 yaml-0.1; echo $$?)
|
||||
ifeq ($(NO_YAML),1)
|
||||
CFLAGS += -DNO_YAML
|
||||
else
|
||||
LDLIBS += $(shell $(PKG_CONFIG) --libs yaml-0.1)
|
||||
LDLIBS_dtc += $(shell $(PKG_CONFIG) --libs yaml-0.1)
|
||||
CFLAGS += $(shell $(PKG_CONFIG) --cflags yaml-0.1)
|
||||
endif
|
||||
|
||||
ifeq ($(HOSTOS),darwin)
|
||||
|
@ -90,7 +101,6 @@ endif
|
|||
# Rules for versioning
|
||||
#
|
||||
|
||||
DTC_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
|
||||
VERSION_FILE = version_gen.h
|
||||
|
||||
CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
|
||||
|
@ -145,30 +155,8 @@ SCRIPTS = dtdiff
|
|||
|
||||
all: $(BIN) libfdt
|
||||
|
||||
# We need both Python and swig to build/install pylibfdt.
|
||||
# This builds the given make ${target} if those deps are found.
|
||||
check_python_deps = \
|
||||
if $(PKG_CONFIG) --cflags $(PYTHON) >/dev/null 2>&1; then \
|
||||
if which swig >/dev/null 2>&1; then \
|
||||
can_build=yes; \
|
||||
fi; \
|
||||
fi; \
|
||||
if [ "$${can_build}" = "yes" ]; then \
|
||||
$(MAKE) $${target}; \
|
||||
else \
|
||||
echo "\#\# Skipping pylibfdt (install python dev and swig to build)"; \
|
||||
fi ;
|
||||
|
||||
.PHONY: maybe_pylibfdt
|
||||
maybe_pylibfdt: FORCE
|
||||
target=pylibfdt; $(check_python_deps)
|
||||
|
||||
ifeq ($(NO_PYTHON),)
|
||||
all: maybe_pylibfdt
|
||||
endif
|
||||
|
||||
|
||||
ifneq ($(DEPTARGETS),)
|
||||
ifneq ($(MAKECMDGOALS),libfdt)
|
||||
-include $(DTC_OBJS:%.o=%.d)
|
||||
-include $(CONVERT_OBJS:%.o=%.d)
|
||||
-include $(FDTDUMP_OBJS:%.o=%.d)
|
||||
|
@ -176,6 +164,7 @@ ifneq ($(DEPTARGETS),)
|
|||
-include $(FDTPUT_OBJS:%.o=%.d)
|
||||
-include $(FDTOVERLAY_OBJS:%.o=%.d)
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
|
||||
|
@ -184,17 +173,30 @@ endif
|
|||
#
|
||||
LIBFDT_dir = libfdt
|
||||
LIBFDT_archive = $(LIBFDT_dir)/libfdt.a
|
||||
LIBFDT_lib = $(LIBFDT_dir)/libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT)
|
||||
LIBFDT_lib = $(LIBFDT_dir)/$(LIBFDT_LIB)
|
||||
LIBFDT_include = $(addprefix $(LIBFDT_dir)/,$(LIBFDT_INCLUDES))
|
||||
LIBFDT_version = $(addprefix $(LIBFDT_dir)/,$(LIBFDT_VERSION))
|
||||
|
||||
ifeq ($(STATIC_BUILD),1)
|
||||
CFLAGS += -static
|
||||
LIBFDT_dep = $(LIBFDT_archive)
|
||||
else
|
||||
LIBFDT_dep = $(LIBFDT_lib)
|
||||
endif
|
||||
|
||||
include $(LIBFDT_dir)/Makefile.libfdt
|
||||
|
||||
.PHONY: libfdt
|
||||
libfdt: $(LIBFDT_archive) $(LIBFDT_lib)
|
||||
|
||||
$(LIBFDT_archive): $(addprefix $(LIBFDT_dir)/,$(LIBFDT_OBJS))
|
||||
$(LIBFDT_lib): $(addprefix $(LIBFDT_dir)/,$(LIBFDT_OBJS))
|
||||
|
||||
$(LIBFDT_lib): $(addprefix $(LIBFDT_dir)/,$(LIBFDT_OBJS)) $(LIBFDT_version)
|
||||
@$(VECHO) LD $@
|
||||
$(CC) $(LDFLAGS) $(SHAREDLIB_LDFLAGS)$(LIBFDT_soname) -o $(LIBFDT_lib) \
|
||||
$(addprefix $(LIBFDT_dir)/,$(LIBFDT_OBJS))
|
||||
ln -sf $(LIBFDT_LIB) $(LIBFDT_dir)/$(LIBFDT_soname)
|
||||
ln -sf $(LIBFDT_soname) $(LIBFDT_dir)/$(LIBFDT_so)
|
||||
|
||||
ifneq ($(DEPTARGETS),)
|
||||
-include $(LIBFDT_OBJS:%.o=$(LIBFDT_dir)/%.d)
|
||||
|
@ -211,7 +213,7 @@ install-bin: all $(SCRIPTS)
|
|||
$(INSTALL_PROGRAM) $(BIN) $(DESTDIR)$(BINDIR)
|
||||
$(INSTALL_SCRIPT) $(SCRIPTS) $(DESTDIR)$(BINDIR)
|
||||
|
||||
install-lib: all
|
||||
install-lib: libfdt
|
||||
@$(VECHO) INSTALL-LIB
|
||||
$(INSTALL) -d $(DESTDIR)$(LIBDIR)
|
||||
$(INSTALL_LIB) $(LIBFDT_lib) $(DESTDIR)$(LIBDIR)
|
||||
|
@ -226,14 +228,6 @@ install-includes:
|
|||
|
||||
install: install-bin install-lib install-includes
|
||||
|
||||
.PHONY: maybe_install_pylibfdt
|
||||
maybe_install_pylibfdt: FORCE
|
||||
target=install_pylibfdt; $(check_python_deps)
|
||||
|
||||
ifeq ($(NO_PYTHON),)
|
||||
install: maybe_install_pylibfdt
|
||||
endif
|
||||
|
||||
$(VERSION_FILE): Makefile FORCE
|
||||
$(call filechk,version)
|
||||
|
||||
|
@ -246,11 +240,11 @@ convert-dtsv0: $(CONVERT_OBJS)
|
|||
|
||||
fdtdump: $(FDTDUMP_OBJS)
|
||||
|
||||
fdtget: $(FDTGET_OBJS) $(LIBFDT_archive)
|
||||
fdtget: $(FDTGET_OBJS) $(LIBFDT_dep)
|
||||
|
||||
fdtput: $(FDTPUT_OBJS) $(LIBFDT_archive)
|
||||
fdtput: $(FDTPUT_OBJS) $(LIBFDT_dep)
|
||||
|
||||
fdtoverlay: $(FDTOVERLAY_OBJS) $(LIBFDT_archive)
|
||||
fdtoverlay: $(FDTOVERLAY_OBJS) $(LIBFDT_dep)
|
||||
|
||||
dist:
|
||||
git archive --format=tar --prefix=dtc-$(dtc_version)/ HEAD \
|
||||
|
@ -259,16 +253,6 @@ dist:
|
|||
gzip -9 > ../dtc-$(dtc_version).tar.gz
|
||||
|
||||
|
||||
#
|
||||
# Rules for pylibfdt
|
||||
#
|
||||
PYLIBFDT_dir = pylibfdt
|
||||
|
||||
include $(PYLIBFDT_dir)/Makefile.pylibfdt
|
||||
|
||||
.PHONY: pylibfdt
|
||||
pylibfdt: $(PYLIBFDT_dir)/_libfdt.so
|
||||
|
||||
#
|
||||
# Release signing and uploading
|
||||
# This is for maintainer convenience, don't try this at home.
|
||||
|
@ -302,11 +286,10 @@ TESTS_BIN += fdtput
|
|||
TESTS_BIN += fdtget
|
||||
TESTS_BIN += fdtdump
|
||||
TESTS_BIN += fdtoverlay
|
||||
ifeq ($(NO_PYTHON),)
|
||||
TESTS_PYLIBFDT += maybe_pylibfdt
|
||||
endif
|
||||
|
||||
ifneq ($(MAKECMDGOALS),libfdt)
|
||||
include tests/Makefile.tests
|
||||
endif
|
||||
|
||||
#
|
||||
# Clean rules
|
||||
|
@ -314,7 +297,7 @@ include tests/Makefile.tests
|
|||
STD_CLEANFILES = *~ *.o *.$(SHAREDLIB_EXT) *.d *.a *.i *.s core a.out vgcore.* \
|
||||
*.tab.[ch] *.lex.c *.output
|
||||
|
||||
clean: libfdt_clean pylibfdt_clean tests_clean
|
||||
clean: libfdt_clean tests_clean
|
||||
@$(VECHO) CLEAN
|
||||
rm -f $(STD_CLEANFILES)
|
||||
rm -f $(VERSION_FILE)
|
||||
|
@ -326,7 +309,7 @@ clean: libfdt_clean pylibfdt_clean tests_clean
|
|||
#
|
||||
%: %.o
|
||||
@$(VECHO) LD $@
|
||||
$(LINK.c) -o $@ $^ $(LDLIBS)
|
||||
$(LINK.c) -o $@ $^ $(LDLIBS_$*)
|
||||
|
||||
%.o: %.c
|
||||
@$(VECHO) CC $@
|
||||
|
@ -334,11 +317,11 @@ clean: libfdt_clean pylibfdt_clean tests_clean
|
|||
|
||||
%.o: %.S
|
||||
@$(VECHO) AS $@
|
||||
$(CC) $(CPPFLAGS) $(AFLAGS) -D__ASSEMBLY__ -o $@ -c $<
|
||||
$(CC) $(CPPFLAGS) $(AFLAGS) -o $@ -c $<
|
||||
|
||||
%.d: %.c
|
||||
@$(VECHO) DEP $<
|
||||
$(CC) $(CPPFLAGS) -MM -MG -MT "$*.o $@" $< > $@
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -MM -MG -MT "$*.o $@" $< > $@
|
||||
|
||||
%.d: %.S
|
||||
@$(VECHO) DEP $<
|
||||
|
@ -356,16 +339,16 @@ clean: libfdt_clean pylibfdt_clean tests_clean
|
|||
@$(VECHO) AR $@
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
$(LIBFDT_lib):
|
||||
@$(VECHO) LD $@
|
||||
$(CC) $(LDFLAGS) $(SHAREDLIB_LDFLAGS)$(LIBFDT_soname) -o $(LIBFDT_lib) $^
|
||||
|
||||
%.lex.c: %.l
|
||||
@$(VECHO) LEX $@
|
||||
$(LEX) -o$@ $<
|
||||
|
||||
%.tab.c %.tab.h %.output: %.y
|
||||
%.tab.c %.tab.h: %.y
|
||||
@$(VECHO) BISON $@
|
||||
$(BISON) -d $<
|
||||
$(BISON) -b $(basename $(basename $@)) -d $<
|
||||
|
||||
FORCE:
|
||||
|
||||
ifeq ($(MAKE_RESTARTS),10)
|
||||
$(error "Make re-executed itself $(MAKE_RESTARTS) times. Infinite recursion?")
|
||||
endif
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#
|
||||
# This is not a complete Makefile of itself.
|
||||
# Instead, it is designed to be easily embeddable
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
# Makefile.dtc
|
||||
#
|
||||
# This is not a complete Makefile of itself. Instead, it is designed to
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#
|
||||
# This is not a complete Makefile of itself. Instead, it is designed to
|
||||
# be easily embeddable into other systems of Makefiles.
|
||||
|
|
93
README
93
README
|
@ -1,93 +0,0 @@
|
|||
The source tree contains the Device Tree Compiler (dtc) toolchain for
|
||||
working with device tree source and binary files and also libfdt, a
|
||||
utility library for reading and manipulating the binary format.
|
||||
|
||||
DTC and LIBFDT are maintained by:
|
||||
|
||||
David Gibson <david@gibson.dropbear.id.au>
|
||||
Jon Loeliger <jdl@jdl.com>
|
||||
|
||||
|
||||
Python library
|
||||
--------------
|
||||
|
||||
A Python library is also available. To build this you will need to install
|
||||
swig and Python development files. On Debian distributions:
|
||||
|
||||
sudo apt-get install swig python-dev
|
||||
|
||||
The library provides an Fdt class which you can use like this:
|
||||
|
||||
$ PYTHONPATH=../pylibfdt python
|
||||
>>> import libfdt
|
||||
>>> fdt = libfdt.Fdt(open('test_tree1.dtb').read())
|
||||
>>> node = fdt.path_offset('/subnode@1')
|
||||
>>> print node
|
||||
124
|
||||
>>> prop_offset = fdt.first_property_offset(node)
|
||||
>>> prop = fdt.get_property_by_offset(prop_offset)
|
||||
>>> print '%s=%r' % (prop.name, prop.value)
|
||||
compatible=bytearray(b'subnode1\x00')
|
||||
>>> print '%s=%s' % (prop.name, prop.value)
|
||||
compatible=subnode1
|
||||
>>> node2 = fdt.path_offset('/')
|
||||
>>> print fdt.getprop(node2, 'compatible')
|
||||
test_tree1
|
||||
|
||||
You will find tests in tests/pylibfdt_tests.py showing how to use each
|
||||
method. Help is available using the Python help command, e.g.:
|
||||
|
||||
$ cd pylibfdt
|
||||
$ python -c "import libfdt; help(libfdt)"
|
||||
|
||||
If you add new features, please check code coverage:
|
||||
|
||||
$ sudo apt-get install python-pip python-pytest
|
||||
$ sudo pip install coverage
|
||||
$ cd tests
|
||||
$ coverage run pylibfdt_tests.py
|
||||
$ coverage html
|
||||
# Open 'htmlcov/index.html' in your browser
|
||||
|
||||
|
||||
To install the library via the normal setup.py method, use:
|
||||
|
||||
./pylibfdt/setup.py [--prefix=/path/to/install_dir]
|
||||
|
||||
If --prefix is not provided, the default prefix is used, typically '/usr'
|
||||
or '/usr/local'. See Python's distutils documentation for details. You can
|
||||
also install via the Makefile if you like, but the above is more common.
|
||||
|
||||
To install both libfdt and pylibfdt you can use:
|
||||
|
||||
make install [SETUP_PREFIX=/path/to/install_dir] \
|
||||
[PREFIX=/path/to/install_dir]
|
||||
|
||||
To disable building the python library, even if swig and Python are available,
|
||||
use:
|
||||
|
||||
make NO_PYTHON=1
|
||||
|
||||
|
||||
More work remains to support all of libfdt, including access to numeric
|
||||
values.
|
||||
|
||||
|
||||
Tests
|
||||
-----
|
||||
|
||||
Test files are kept in the tests/ directory. Use 'make check' to build and run
|
||||
all tests.
|
||||
|
||||
If you want to adjust a test file, be aware that tree_tree1.dts is compiled
|
||||
and checked against a binary tree from assembler macros in trees.S. So
|
||||
if you change that file you must change tree.S also.
|
||||
|
||||
|
||||
Mailing list
|
||||
------------
|
||||
The following list is for discussion about dtc and libfdt implementation
|
||||
mailto:devicetree-compiler@vger.kernel.org
|
||||
|
||||
Core device tree bindings are discussed on the devicetree-spec list:
|
||||
mailto:devicetree-spec@vger.kernel.org
|
|
@ -4,11 +4,11 @@ Licensing and contribution policy of dtc and libfdt
|
|||
This dtc package contains two pieces of software: dtc itself, and
|
||||
libfdt which comprises the files in the libfdt/ subdirectory. These
|
||||
two pieces of software, although closely related, are quite distinct.
|
||||
dtc does not incoporate or rely on libfdt for its operation, nor vice
|
||||
dtc does not incorporate or rely on libfdt for its operation, nor vice
|
||||
versa. It is important that these two pieces of software have
|
||||
different license conditions.
|
||||
|
||||
As the copyright banners in each source file attest, dtc is licensed
|
||||
As SPDX license tags in each source file attest, dtc is licensed
|
||||
under the GNU GPL. The full text of the GPL can be found in the file
|
||||
entitled 'GPL' which should be included in this package. dtc code,
|
||||
therefore, may not be incorporated into works which do not have a GPL
|
||||
|
@ -16,10 +16,10 @@ compatible license.
|
|||
|
||||
libfdt, however, is GPL/BSD dual-licensed. That is, it may be used
|
||||
either under the terms of the GPL, or under the terms of the 2-clause
|
||||
BSD license (aka the ISC license). The full terms of that license are
|
||||
given in the copyright banners of each of the libfdt source files.
|
||||
This is, in practice, equivalent to being BSD licensed, since the
|
||||
terms of the BSD license are strictly more permissive than the GPL.
|
||||
BSD license (aka the ISC license). The full terms of that license can
|
||||
be found are in the file entitled 'BSD-2-Clause'. This is, in
|
||||
practice, equivalent to being BSD licensed, since the terms of the BSD
|
||||
license are strictly more permissive than the GPL.
|
||||
|
||||
I made the decision to license libfdt in this way because I want to
|
||||
encourage widespread and correct usage of flattened device trees,
|
||||
|
@ -28,12 +28,12 @@ tools. Allowing libfdt to be used under the terms of the BSD license
|
|||
makes that it easier for vendors or authors of such software to do so.
|
||||
|
||||
This does mean that libfdt code could be "stolen" - say, included in a
|
||||
proprietary fimware and extended without contributing those extensions
|
||||
proprietary firmware and extended without contributing those extensions
|
||||
back to the libfdt mainline. While I hope that doesn't happen, I
|
||||
believe the goal of allowing libfdt to be widely used is more
|
||||
important than avoiding that. libfdt is quite small, and hardly
|
||||
rocket science; so the incentive for such impolite behaviour is small,
|
||||
and the inconvenience caused therby is not dire.
|
||||
and the inconvenience caused thereby is not dire.
|
||||
|
||||
Licenses such as the LGPL which would allow code to be used in non-GPL
|
||||
software, but also require contributions to be returned were
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
# Device Tree Compiler and libfdt
|
||||
|
||||
The source tree contains the Device Tree Compiler (dtc) toolchain for
|
||||
working with device tree source and binary files and also libfdt, a
|
||||
utility library for reading and manipulating the binary format.
|
||||
|
||||
dtc and libfdt are maintained by:
|
||||
|
||||
* [David Gibson `<david@gibson.dropbear.id.au>`](mailto:david@gibson.dropbear.id.au)
|
||||
|
||||
## Python library
|
||||
|
||||
A Python library wrapping libfdt is also available. To build this you
|
||||
will need to install `swig` and Python development files. On Debian
|
||||
distributions:
|
||||
|
||||
```
|
||||
$ sudo apt-get install swig python3-dev
|
||||
```
|
||||
|
||||
The library provides an `Fdt` class which you can use like this:
|
||||
|
||||
```
|
||||
$ PYTHONPATH=../pylibfdt python3
|
||||
>>> import libfdt
|
||||
>>> fdt = libfdt.Fdt(open('test_tree1.dtb', mode='rb').read())
|
||||
>>> node = fdt.path_offset('/subnode@1')
|
||||
>>> print(node)
|
||||
124
|
||||
>>> prop_offset = fdt.first_property_offset(node)
|
||||
>>> prop = fdt.get_property_by_offset(prop_offset)
|
||||
>>> print('%s=%s' % (prop.name, prop.as_str()))
|
||||
compatible=subnode1
|
||||
>>> node2 = fdt.path_offset('/')
|
||||
>>> print(fdt.getprop(node2, 'compatible').as_str())
|
||||
test_tree1
|
||||
```
|
||||
|
||||
You will find tests in `tests/pylibfdt_tests.py` showing how to use each
|
||||
method. Help is available using the Python help command, e.g.:
|
||||
|
||||
```
|
||||
$ cd pylibfdt
|
||||
$ python3 -c "import libfdt; help(libfdt)"
|
||||
```
|
||||
|
||||
If you add new features, please check code coverage:
|
||||
|
||||
```
|
||||
$ sudo apt-get install python3-coverage
|
||||
$ cd tests
|
||||
# It's just 'coverage' on most other distributions
|
||||
$ python3-coverage run pylibfdt_tests.py
|
||||
$ python3-coverage html
|
||||
# Open 'htmlcov/index.html' in your browser
|
||||
```
|
||||
|
||||
The library can be installed with pip from a local source tree:
|
||||
|
||||
```
|
||||
$ pip install . [--user|--prefix=/path/to/install_dir]
|
||||
```
|
||||
|
||||
Or directly from a remote git repo:
|
||||
|
||||
```
|
||||
$ pip install git+git://git.kernel.org/pub/scm/utils/dtc/dtc.git@main
|
||||
```
|
||||
|
||||
The install depends on libfdt shared library being installed on the
|
||||
host system first. Generally, using `--user` or `--prefix` is not
|
||||
necessary and pip will use the default location for the Python
|
||||
installation which varies if the user is root or not.
|
||||
|
||||
You can also install everything via make if you like, but pip is
|
||||
recommended.
|
||||
|
||||
To install both libfdt and pylibfdt you can use:
|
||||
|
||||
```
|
||||
$ make install [PREFIX=/path/to/install_dir]
|
||||
```
|
||||
|
||||
To disable building the python library, even if swig and Python are available,
|
||||
use:
|
||||
|
||||
```
|
||||
$ make NO_PYTHON=1
|
||||
```
|
||||
|
||||
More work remains to support all of libfdt, including access to numeric
|
||||
values.
|
||||
|
||||
## Mailing lists
|
||||
|
||||
* The [devicetree-compiler](mailto:devicetree-compiler@vger.kernel.org)
|
||||
list is for discussion about dtc and libfdt implementation.
|
||||
* Core device tree bindings are discussed on the
|
||||
[devicetree-spec](mailto:devicetree-spec@vger.kernel.org) list.
|
||||
|
|
@ -0,0 +1 @@
|
|||
1.7.2
|
441
checks.c
441
checks.c
|
@ -1,21 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2007.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "dtc.h"
|
||||
|
@ -46,7 +31,7 @@ typedef void (*check_fn)(struct check *c, struct dt_info *dti, struct node *node
|
|||
struct check {
|
||||
const char *name;
|
||||
check_fn fn;
|
||||
void *data;
|
||||
const void *data;
|
||||
bool warn, error;
|
||||
enum checkstatus status;
|
||||
bool inprogress;
|
||||
|
@ -129,6 +114,7 @@ static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti,
|
|||
}
|
||||
|
||||
fputs(str, stderr);
|
||||
free(str);
|
||||
}
|
||||
|
||||
#define FAIL(c, dti, node, ...) \
|
||||
|
@ -158,6 +144,14 @@ static void check_nodes_props(struct check *c, struct dt_info *dti, struct node
|
|||
check_nodes_props(c, dti, child);
|
||||
}
|
||||
|
||||
static bool is_multiple_of(int multiple, int divisor)
|
||||
{
|
||||
if (divisor == 0)
|
||||
return multiple == 0;
|
||||
else
|
||||
return (multiple % divisor) == 0;
|
||||
}
|
||||
|
||||
static bool run_check(struct check *c, struct dt_info *dti)
|
||||
{
|
||||
struct node *dt = dti->dt;
|
||||
|
@ -214,7 +208,7 @@ static void check_is_string(struct check *c, struct dt_info *dti,
|
|||
struct node *node)
|
||||
{
|
||||
struct property *prop;
|
||||
char *propname = c->data;
|
||||
const char *propname = c->data;
|
||||
|
||||
prop = get_property(node, propname);
|
||||
if (!prop)
|
||||
|
@ -233,7 +227,7 @@ static void check_is_string_list(struct check *c, struct dt_info *dti,
|
|||
{
|
||||
int rem, l;
|
||||
struct property *prop;
|
||||
char *propname = c->data;
|
||||
const char *propname = c->data;
|
||||
char *str;
|
||||
|
||||
prop = get_property(node, propname);
|
||||
|
@ -261,7 +255,7 @@ static void check_is_cell(struct check *c, struct dt_info *dti,
|
|||
struct node *node)
|
||||
{
|
||||
struct property *prop;
|
||||
char *propname = c->data;
|
||||
const char *propname = c->data;
|
||||
|
||||
prop = get_property(node, propname);
|
||||
if (!prop)
|
||||
|
@ -312,19 +306,20 @@ ERROR(duplicate_property_names, check_duplicate_property_names, NULL);
|
|||
#define LOWERCASE "abcdefghijklmnopqrstuvwxyz"
|
||||
#define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
#define DIGITS "0123456789"
|
||||
#define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"
|
||||
#define NODECHARS LOWERCASE UPPERCASE DIGITS ",._+-@"
|
||||
#define PROPCHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"
|
||||
#define PROPNODECHARSSTRICT LOWERCASE UPPERCASE DIGITS ",-"
|
||||
|
||||
static void check_node_name_chars(struct check *c, struct dt_info *dti,
|
||||
struct node *node)
|
||||
{
|
||||
int n = strspn(node->name, c->data);
|
||||
size_t n = strspn(node->name, c->data);
|
||||
|
||||
if (n < strlen(node->name))
|
||||
FAIL(c, dti, node, "Bad character '%c' in node name",
|
||||
node->name[n]);
|
||||
}
|
||||
ERROR(node_name_chars, check_node_name_chars, PROPNODECHARS "@");
|
||||
ERROR(node_name_chars, check_node_name_chars, NODECHARS);
|
||||
|
||||
static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
|
||||
struct node *node)
|
||||
|
@ -345,6 +340,20 @@ static void check_node_name_format(struct check *c, struct dt_info *dti,
|
|||
}
|
||||
ERROR(node_name_format, check_node_name_format, NULL, &node_name_chars);
|
||||
|
||||
static void check_node_name_vs_property_name(struct check *c,
|
||||
struct dt_info *dti,
|
||||
struct node *node)
|
||||
{
|
||||
if (!node->parent)
|
||||
return;
|
||||
|
||||
if (get_property(node->parent, node->name)) {
|
||||
FAIL(c, dti, node, "node name and property name conflict");
|
||||
}
|
||||
}
|
||||
WARNING(node_name_vs_property_name, check_node_name_vs_property_name,
|
||||
NULL, &node_name_chars);
|
||||
|
||||
static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,
|
||||
struct node *node)
|
||||
{
|
||||
|
@ -367,7 +376,7 @@ static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,
|
|||
FAIL(c, dti, node, "node has a reg or ranges property, but no unit name");
|
||||
} else {
|
||||
if (unitname[0])
|
||||
FAIL(c, dti, node, "node has a unit name, but no reg property");
|
||||
FAIL(c, dti, node, "node has a unit name, but no reg or ranges property");
|
||||
}
|
||||
}
|
||||
WARNING(unit_address_vs_reg, check_unit_address_vs_reg, NULL);
|
||||
|
@ -378,14 +387,14 @@ static void check_property_name_chars(struct check *c, struct dt_info *dti,
|
|||
struct property *prop;
|
||||
|
||||
for_each_property(node, prop) {
|
||||
int n = strspn(prop->name, c->data);
|
||||
size_t n = strspn(prop->name, c->data);
|
||||
|
||||
if (n < strlen(prop->name))
|
||||
FAIL_PROP(c, dti, node, prop, "Bad character '%c' in property name",
|
||||
prop->name[n]);
|
||||
}
|
||||
}
|
||||
ERROR(property_name_chars, check_property_name_chars, PROPNODECHARS);
|
||||
ERROR(property_name_chars, check_property_name_chars, PROPCHARS);
|
||||
|
||||
static void check_property_name_chars_strict(struct check *c,
|
||||
struct dt_info *dti,
|
||||
|
@ -395,7 +404,7 @@ static void check_property_name_chars_strict(struct check *c,
|
|||
|
||||
for_each_property(node, prop) {
|
||||
const char *name = prop->name;
|
||||
int n = strspn(name, c->data);
|
||||
size_t n = strspn(name, c->data);
|
||||
|
||||
if (n == strlen(prop->name))
|
||||
continue;
|
||||
|
@ -512,7 +521,7 @@ static cell_t check_phandle_prop(struct check *c, struct dt_info *dti,
|
|||
|
||||
phandle = propval_cell(prop);
|
||||
|
||||
if ((phandle == 0) || (phandle == -1)) {
|
||||
if (!phandle_is_valid(phandle)) {
|
||||
FAIL_PROP(c, dti, node, prop, "bad value (0x%x) in %s property",
|
||||
phandle, prop->name);
|
||||
return 0;
|
||||
|
@ -571,7 +580,7 @@ static void check_name_properties(struct check *c, struct dt_info *dti,
|
|||
if (!prop)
|
||||
return; /* No name property, that's fine */
|
||||
|
||||
if ((prop->val.len != node->basenamelen+1)
|
||||
if ((prop->val.len != node->basenamelen + 1U)
|
||||
|| (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) {
|
||||
FAIL(c, dti, node, "\"name\" property is incorrect (\"%s\" instead"
|
||||
" of base node name)", prop->val.val);
|
||||
|
@ -660,6 +669,8 @@ ERROR(path_references, fixup_path_references, NULL, &duplicate_node_names);
|
|||
static void fixup_omit_unused_nodes(struct check *c, struct dt_info *dti,
|
||||
struct node *node)
|
||||
{
|
||||
if (generate_symbols && node->labels)
|
||||
return;
|
||||
if (node->omit_if_unused && !node->is_referenced)
|
||||
delete_node(node);
|
||||
}
|
||||
|
@ -670,7 +681,6 @@ ERROR(omit_unused_nodes, fixup_omit_unused_nodes, NULL, &phandle_references, &pa
|
|||
*/
|
||||
WARNING_IF_NOT_CELL(address_cells_is_cell, "#address-cells");
|
||||
WARNING_IF_NOT_CELL(size_cells_is_cell, "#size-cells");
|
||||
WARNING_IF_NOT_CELL(interrupt_cells_is_cell, "#interrupt-cells");
|
||||
|
||||
WARNING_IF_NOT_STRING(device_type_is_string, "device_type");
|
||||
WARNING_IF_NOT_STRING(model_is_string, "model");
|
||||
|
@ -685,8 +695,7 @@ static void check_names_is_string_list(struct check *c, struct dt_info *dti,
|
|||
struct property *prop;
|
||||
|
||||
for_each_property(node, prop) {
|
||||
const char *s = strrchr(prop->name, '-');
|
||||
if (!s || !streq(s, "-names"))
|
||||
if (!strends(prop->name, "-names"))
|
||||
continue;
|
||||
|
||||
c->data = prop->name;
|
||||
|
@ -704,6 +713,11 @@ static void check_alias_paths(struct check *c, struct dt_info *dti,
|
|||
return;
|
||||
|
||||
for_each_property(node, prop) {
|
||||
if (streq(prop->name, "phandle")
|
||||
|| streq(prop->name, "linux,phandle")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val)) {
|
||||
FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s)",
|
||||
prop->val.val);
|
||||
|
@ -761,7 +775,7 @@ static void check_reg_format(struct check *c, struct dt_info *dti,
|
|||
size_cells = node_size_cells(node->parent);
|
||||
entrylen = (addr_cells + size_cells) * sizeof(cell_t);
|
||||
|
||||
if (!entrylen || (prop->val.len % entrylen) != 0)
|
||||
if (!is_multiple_of(prop->val.len, entrylen))
|
||||
FAIL_PROP(c, dti, node, prop, "property has invalid length (%d bytes) "
|
||||
"(#address-cells == %d, #size-cells == %d)",
|
||||
prop->val.len, addr_cells, size_cells);
|
||||
|
@ -773,13 +787,15 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
|
|||
{
|
||||
struct property *prop;
|
||||
int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen;
|
||||
const char *ranges = c->data;
|
||||
|
||||
prop = get_property(node, "ranges");
|
||||
prop = get_property(node, ranges);
|
||||
if (!prop)
|
||||
return;
|
||||
|
||||
if (!node->parent) {
|
||||
FAIL_PROP(c, dti, node, prop, "Root node has a \"ranges\" property");
|
||||
FAIL_PROP(c, dti, node, prop, "Root node has a \"%s\" property",
|
||||
ranges);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -791,23 +807,24 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
|
|||
|
||||
if (prop->val.len == 0) {
|
||||
if (p_addr_cells != c_addr_cells)
|
||||
FAIL_PROP(c, dti, node, prop, "empty \"ranges\" property but its "
|
||||
FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
|
||||
"#address-cells (%d) differs from %s (%d)",
|
||||
c_addr_cells, node->parent->fullpath,
|
||||
ranges, c_addr_cells, node->parent->fullpath,
|
||||
p_addr_cells);
|
||||
if (p_size_cells != c_size_cells)
|
||||
FAIL_PROP(c, dti, node, prop, "empty \"ranges\" property but its "
|
||||
FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
|
||||
"#size-cells (%d) differs from %s (%d)",
|
||||
c_size_cells, node->parent->fullpath,
|
||||
ranges, c_size_cells, node->parent->fullpath,
|
||||
p_size_cells);
|
||||
} else if ((prop->val.len % entrylen) != 0) {
|
||||
FAIL_PROP(c, dti, node, prop, "\"ranges\" property has invalid length (%d bytes) "
|
||||
} else if (!is_multiple_of(prop->val.len, entrylen)) {
|
||||
FAIL_PROP(c, dti, node, prop, "\"%s\" property has invalid length (%d bytes) "
|
||||
"(parent #address-cells == %d, child #address-cells == %d, "
|
||||
"#size-cells == %d)", prop->val.len,
|
||||
"#size-cells == %d)", ranges, prop->val.len,
|
||||
p_addr_cells, c_addr_cells, c_size_cells);
|
||||
}
|
||||
}
|
||||
WARNING(ranges_format, check_ranges_format, NULL, &addr_size_cells);
|
||||
WARNING(ranges_format, check_ranges_format, "ranges", &addr_size_cells);
|
||||
WARNING(dma_ranges_format, check_ranges_format, "dma-ranges", &addr_size_cells);
|
||||
|
||||
static const struct bus_type pci_bus = {
|
||||
.name = "PCI",
|
||||
|
@ -876,7 +893,7 @@ static void check_pci_device_bus_num(struct check *c, struct dt_info *dti, struc
|
|||
} else {
|
||||
cells = (cell_t *)prop->val.val;
|
||||
min_bus = fdt32_to_cpu(cells[0]);
|
||||
max_bus = fdt32_to_cpu(cells[0]);
|
||||
max_bus = fdt32_to_cpu(cells[1]);
|
||||
}
|
||||
if ((bus_num < min_bus) || (bus_num > max_bus))
|
||||
FAIL_PROP(c, dti, node, prop, "PCI bus number %d out of range, expected (%d - %d)",
|
||||
|
@ -896,10 +913,8 @@ static void check_pci_device_reg(struct check *c, struct dt_info *dti, struct no
|
|||
return;
|
||||
|
||||
prop = get_property(node, "reg");
|
||||
if (!prop) {
|
||||
FAIL(c, dti, node, "missing PCI reg property");
|
||||
if (!prop)
|
||||
return;
|
||||
}
|
||||
|
||||
cells = (cell_t *)prop->val.val;
|
||||
if (cells[1] || cells[2])
|
||||
|
@ -1009,7 +1024,7 @@ static void check_i2c_bus_bridge(struct check *c, struct dt_info *dti, struct no
|
|||
} else if (strprefixeq(node->name, node->basenamelen, "i2c")) {
|
||||
struct node *child;
|
||||
for_each_child(node, child) {
|
||||
if (strprefixeq(child->name, node->basenamelen, "i2c-bus"))
|
||||
if (strprefixeq(child->name, child->basenamelen, "i2c-bus"))
|
||||
return;
|
||||
}
|
||||
node->bus = &i2c_bus;
|
||||
|
@ -1027,6 +1042,9 @@ static void check_i2c_bus_bridge(struct check *c, struct dt_info *dti, struct no
|
|||
}
|
||||
WARNING(i2c_bus_bridge, check_i2c_bus_bridge, NULL, &addr_size_cells);
|
||||
|
||||
#define I2C_OWN_SLAVE_ADDRESS (1U << 30)
|
||||
#define I2C_TEN_BIT_ADDRESS (1U << 31)
|
||||
|
||||
static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
|
||||
{
|
||||
struct property *prop;
|
||||
|
@ -1049,6 +1067,8 @@ static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node
|
|||
}
|
||||
|
||||
reg = fdt32_to_cpu(*cells);
|
||||
/* Ignore I2C_OWN_SLAVE_ADDRESS */
|
||||
reg &= ~I2C_OWN_SLAVE_ADDRESS;
|
||||
snprintf(unit_addr, sizeof(unit_addr), "%x", reg);
|
||||
if (!streq(unitname, unit_addr))
|
||||
FAIL(c, dti, node, "I2C bus unit address format error, expected \"%s\"",
|
||||
|
@ -1056,10 +1076,16 @@ static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node
|
|||
|
||||
for (len = prop->val.len; len > 0; len -= 4) {
|
||||
reg = fdt32_to_cpu(*(cells++));
|
||||
if (reg > 0x3ff)
|
||||
FAIL_PROP(c, dti, node, prop, "I2C address must be less than 10-bits, got \"0x%x\"",
|
||||
reg);
|
||||
/* Ignore I2C_OWN_SLAVE_ADDRESS */
|
||||
reg &= ~I2C_OWN_SLAVE_ADDRESS;
|
||||
|
||||
if (reg & I2C_TEN_BIT_ADDRESS) {
|
||||
if ((reg & ~I2C_TEN_BIT_ADDRESS) > 0x3ff)
|
||||
FAIL_PROP(c, dti, node, prop, "I2C address must be less than 10-bits, got \"0x%x\"",
|
||||
reg);
|
||||
} else if (reg > 0x7f)
|
||||
FAIL_PROP(c, dti, node, prop, "I2C address must be less than 7-bits, got \"0x%x\". Set I2C_TEN_BIT_ADDRESS for 10 bit addresses or fix the property",
|
||||
reg);
|
||||
}
|
||||
}
|
||||
WARNING(i2c_bus_reg, check_i2c_bus_reg, NULL, ®_format, &i2c_bus_bridge);
|
||||
|
@ -1084,7 +1110,7 @@ static void check_spi_bus_bridge(struct check *c, struct dt_info *dti, struct no
|
|||
for_each_child(node, child) {
|
||||
struct property *prop;
|
||||
for_each_property(child, prop) {
|
||||
if (strprefixeq(prop->name, 4, "spi-")) {
|
||||
if (strstarts(prop->name, "spi-")) {
|
||||
node->bus = &spi_bus;
|
||||
break;
|
||||
}
|
||||
|
@ -1156,7 +1182,7 @@ static void check_unit_address_format(struct check *c, struct dt_info *dti,
|
|||
/* skip over 0x for next test */
|
||||
unitname += 2;
|
||||
}
|
||||
if (unitname[0] == '0' && isxdigit(unitname[1]))
|
||||
if (unitname[0] == '0' && isxdigit((unsigned char)unitname[1]))
|
||||
FAIL(c, dti, node, "unit name should not have leading 0s");
|
||||
}
|
||||
WARNING(unit_address_format, check_unit_address_format, NULL,
|
||||
|
@ -1191,24 +1217,27 @@ WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,
|
|||
static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *dti,
|
||||
struct node *node)
|
||||
{
|
||||
struct property *prop;
|
||||
struct node *child;
|
||||
bool has_reg = false;
|
||||
|
||||
if (!node->parent || node->addr_cells < 0 || node->size_cells < 0)
|
||||
return;
|
||||
|
||||
if (get_property(node, "ranges") || !node->children)
|
||||
if (get_property(node, "ranges") || get_property(node, "dma-ranges") || !node->children)
|
||||
return;
|
||||
|
||||
for_each_child(node, child) {
|
||||
prop = get_property(child, "reg");
|
||||
if (prop)
|
||||
has_reg = true;
|
||||
/*
|
||||
* Even if the child devices' address space is not mapped into
|
||||
* the parent bus (no 'ranges' property on node), children can
|
||||
* still have registers on a local bus, or map local addresses
|
||||
* to another subordinate address space. The properties on the
|
||||
* child nodes then make #address-cells/#size-cells necessary:
|
||||
*/
|
||||
if (get_property(child, "reg") || get_property(child, "ranges"))
|
||||
return;
|
||||
}
|
||||
|
||||
if (!has_reg)
|
||||
FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\" or child \"reg\" property");
|
||||
FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\", \"dma-ranges\" or child \"reg\" or \"ranges\" property");
|
||||
}
|
||||
WARNING(avoid_unnecessary_addr_size, check_avoid_unnecessary_addr_size, NULL, &avoid_default_addr_size);
|
||||
|
||||
|
@ -1358,15 +1387,15 @@ struct provider {
|
|||
};
|
||||
|
||||
static void check_property_phandle_args(struct check *c,
|
||||
struct dt_info *dti,
|
||||
struct node *node,
|
||||
struct property *prop,
|
||||
const struct provider *provider)
|
||||
struct dt_info *dti,
|
||||
struct node *node,
|
||||
struct property *prop,
|
||||
const struct provider *provider)
|
||||
{
|
||||
struct node *root = dti->dt;
|
||||
int cell, cellsize = 0;
|
||||
unsigned int cell, cellsize = 0;
|
||||
|
||||
if (prop->val.len % sizeof(cell_t)) {
|
||||
if (!is_multiple_of(prop->val.len, sizeof(cell_t))) {
|
||||
FAIL_PROP(c, dti, node, prop,
|
||||
"property size (%d) is invalid, expected multiple of %zu",
|
||||
prop->val.len, sizeof(cell_t));
|
||||
|
@ -1376,14 +1405,15 @@ static void check_property_phandle_args(struct check *c,
|
|||
for (cell = 0; cell < prop->val.len / sizeof(cell_t); cell += cellsize + 1) {
|
||||
struct node *provider_node;
|
||||
struct property *cellprop;
|
||||
int phandle;
|
||||
cell_t phandle;
|
||||
unsigned int expected;
|
||||
|
||||
phandle = propval_cell_n(prop, cell);
|
||||
/*
|
||||
* Some bindings use a cell value 0 or -1 to skip over optional
|
||||
* entries when each index position has a specific definition.
|
||||
*/
|
||||
if (phandle == 0 || phandle == -1) {
|
||||
if (!phandle_is_valid(phandle)) {
|
||||
/* Give up if this is an overlay with external references */
|
||||
if (dti->dtsflags & DTSF_PLUGIN)
|
||||
break;
|
||||
|
@ -1426,10 +1456,12 @@ static void check_property_phandle_args(struct check *c,
|
|||
break;
|
||||
}
|
||||
|
||||
if (prop->val.len < ((cell + cellsize + 1) * sizeof(cell_t))) {
|
||||
expected = (cell + cellsize + 1) * sizeof(cell_t);
|
||||
if ((expected <= cell) || prop->val.len < expected) {
|
||||
FAIL_PROP(c, dti, node, prop,
|
||||
"property size (%d) too small for cell size %d",
|
||||
"property size (%d) too small for cell size %u",
|
||||
prop->val.len, cellsize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1438,7 +1470,7 @@ static void check_provider_cells_property(struct check *c,
|
|||
struct dt_info *dti,
|
||||
struct node *node)
|
||||
{
|
||||
struct provider *provider = c->data;
|
||||
const struct provider *provider = c->data;
|
||||
struct property *prop;
|
||||
|
||||
prop = get_property(node, provider->prop_name);
|
||||
|
@ -1449,7 +1481,8 @@ static void check_provider_cells_property(struct check *c,
|
|||
}
|
||||
#define WARNING_PROPERTY_PHANDLE_CELLS(nm, propname, cells_name, ...) \
|
||||
static struct provider nm##_provider = { (propname), (cells_name), __VA_ARGS__ }; \
|
||||
WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &phandle_references);
|
||||
WARNING_IF_NOT_CELL(nm##_is_cell, cells_name); \
|
||||
WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &nm##_is_cell, &phandle_references);
|
||||
|
||||
WARNING_PROPERTY_PHANDLE_CELLS(clocks, "clocks", "#clock-cells");
|
||||
WARNING_PROPERTY_PHANDLE_CELLS(cooling_device, "cooling-device", "#cooling-cells");
|
||||
|
@ -1470,24 +1503,17 @@ WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors, "thermal-sensors", "#thermal-sen
|
|||
|
||||
static bool prop_is_gpio(struct property *prop)
|
||||
{
|
||||
char *str;
|
||||
|
||||
/*
|
||||
* *-gpios and *-gpio can appear in property names,
|
||||
* so skip over any false matches (only one known ATM)
|
||||
*/
|
||||
if (strstr(prop->name, "nr-gpio"))
|
||||
if (strends(prop->name, ",nr-gpios"))
|
||||
return false;
|
||||
|
||||
str = strrchr(prop->name, '-');
|
||||
if (str)
|
||||
str++;
|
||||
else
|
||||
str = prop->name;
|
||||
if (!(streq(str, "gpios") || streq(str, "gpio")))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return strends(prop->name, "-gpios") ||
|
||||
streq(prop->name, "gpios") ||
|
||||
strends(prop->name, "-gpio") ||
|
||||
streq(prop->name, "gpio");
|
||||
}
|
||||
|
||||
static void check_gpios_property(struct check *c,
|
||||
|
@ -1522,13 +1548,10 @@ static void check_deprecated_gpio_property(struct check *c,
|
|||
struct property *prop;
|
||||
|
||||
for_each_property(node, prop) {
|
||||
char *str;
|
||||
|
||||
if (!prop_is_gpio(prop))
|
||||
continue;
|
||||
|
||||
str = strstr(prop->name, "gpio");
|
||||
if (!streq(str, "gpio"))
|
||||
if (!strends(prop->name, "gpio"))
|
||||
continue;
|
||||
|
||||
FAIL_PROP(c, dti, node, prop,
|
||||
|
@ -1552,6 +1575,121 @@ static bool node_is_interrupt_provider(struct node *node)
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void check_interrupt_provider(struct check *c,
|
||||
struct dt_info *dti,
|
||||
struct node *node)
|
||||
{
|
||||
struct property *prop;
|
||||
bool irq_provider = node_is_interrupt_provider(node);
|
||||
|
||||
prop = get_property(node, "#interrupt-cells");
|
||||
if (irq_provider && !prop) {
|
||||
FAIL(c, dti, node,
|
||||
"Missing '#interrupt-cells' in interrupt provider");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!irq_provider && prop) {
|
||||
FAIL(c, dti, node,
|
||||
"'#interrupt-cells' found, but node is not an interrupt provider");
|
||||
return;
|
||||
}
|
||||
}
|
||||
WARNING(interrupt_provider, check_interrupt_provider, NULL, &interrupts_extended_is_cell);
|
||||
|
||||
static void check_interrupt_map(struct check *c,
|
||||
struct dt_info *dti,
|
||||
struct node *node)
|
||||
{
|
||||
struct node *root = dti->dt;
|
||||
struct property *prop, *irq_map_prop;
|
||||
size_t cellsize, cell, map_cells;
|
||||
|
||||
irq_map_prop = get_property(node, "interrupt-map");
|
||||
if (!irq_map_prop)
|
||||
return;
|
||||
|
||||
if (node->addr_cells < 0) {
|
||||
FAIL(c, dti, node,
|
||||
"Missing '#address-cells' in interrupt-map provider");
|
||||
return;
|
||||
}
|
||||
cellsize = node_addr_cells(node);
|
||||
cellsize += propval_cell(get_property(node, "#interrupt-cells"));
|
||||
|
||||
prop = get_property(node, "interrupt-map-mask");
|
||||
if (prop && (prop->val.len != (cellsize * sizeof(cell_t))))
|
||||
FAIL_PROP(c, dti, node, prop,
|
||||
"property size (%d) is invalid, expected %zu",
|
||||
prop->val.len, cellsize * sizeof(cell_t));
|
||||
|
||||
if (!is_multiple_of(irq_map_prop->val.len, sizeof(cell_t))) {
|
||||
FAIL_PROP(c, dti, node, irq_map_prop,
|
||||
"property size (%d) is invalid, expected multiple of %zu",
|
||||
irq_map_prop->val.len, sizeof(cell_t));
|
||||
return;
|
||||
}
|
||||
|
||||
map_cells = irq_map_prop->val.len / sizeof(cell_t);
|
||||
for (cell = 0; cell < map_cells; ) {
|
||||
struct node *provider_node;
|
||||
struct property *cellprop;
|
||||
int phandle;
|
||||
size_t parent_cellsize;
|
||||
|
||||
if ((cell + cellsize) >= map_cells) {
|
||||
FAIL_PROP(c, dti, node, irq_map_prop,
|
||||
"property size (%d) too small, expected > %zu",
|
||||
irq_map_prop->val.len, (cell + cellsize) * sizeof(cell_t));
|
||||
break;
|
||||
}
|
||||
cell += cellsize;
|
||||
|
||||
phandle = propval_cell_n(irq_map_prop, cell);
|
||||
if (!phandle_is_valid(phandle)) {
|
||||
/* Give up if this is an overlay with external references */
|
||||
if (!(dti->dtsflags & DTSF_PLUGIN))
|
||||
FAIL_PROP(c, dti, node, irq_map_prop,
|
||||
"Cell %zu is not a phandle(%d)",
|
||||
cell, phandle);
|
||||
break;
|
||||
}
|
||||
|
||||
provider_node = get_node_by_phandle(root, phandle);
|
||||
if (!provider_node) {
|
||||
FAIL_PROP(c, dti, node, irq_map_prop,
|
||||
"Could not get phandle(%d) node for (cell %zu)",
|
||||
phandle, cell);
|
||||
break;
|
||||
}
|
||||
|
||||
cellprop = get_property(provider_node, "#interrupt-cells");
|
||||
if (cellprop) {
|
||||
parent_cellsize = propval_cell(cellprop);
|
||||
} else {
|
||||
FAIL(c, dti, node, "Missing property '#interrupt-cells' in node %s or bad phandle (referred from interrupt-map[%zu])",
|
||||
provider_node->fullpath, cell);
|
||||
break;
|
||||
}
|
||||
|
||||
cellprop = get_property(provider_node, "#address-cells");
|
||||
if (cellprop)
|
||||
parent_cellsize += propval_cell(cellprop);
|
||||
else
|
||||
FAIL_PROP(c, dti, node, irq_map_prop,
|
||||
"Missing property '#address-cells' in node %s, using 0 as fallback",
|
||||
provider_node->fullpath);
|
||||
|
||||
cell += 1 + parent_cellsize;
|
||||
if (cell > map_cells)
|
||||
FAIL_PROP(c, dti, node, irq_map_prop,
|
||||
"property size (%d) mismatch, expected %zu",
|
||||
irq_map_prop->val.len, cell * sizeof(cell_t));
|
||||
}
|
||||
}
|
||||
WARNING(interrupt_map, check_interrupt_map, NULL, &phandle_references, &addr_size_cells, &interrupt_provider);
|
||||
|
||||
static void check_interrupts_property(struct check *c,
|
||||
struct dt_info *dti,
|
||||
struct node *node)
|
||||
|
@ -1559,13 +1697,13 @@ static void check_interrupts_property(struct check *c,
|
|||
struct node *root = dti->dt;
|
||||
struct node *irq_node = NULL, *parent = node;
|
||||
struct property *irq_prop, *prop = NULL;
|
||||
int irq_cells, phandle;
|
||||
cell_t irq_cells, phandle;
|
||||
|
||||
irq_prop = get_property(node, "interrupts");
|
||||
if (!irq_prop)
|
||||
return;
|
||||
|
||||
if (irq_prop->val.len % sizeof(cell_t))
|
||||
if (!is_multiple_of(irq_prop->val.len, sizeof(cell_t)))
|
||||
FAIL_PROP(c, dti, node, irq_prop, "size (%d) is invalid, expected multiple of %zu",
|
||||
irq_prop->val.len, sizeof(cell_t));
|
||||
|
||||
|
@ -1578,10 +1716,14 @@ static void check_interrupts_property(struct check *c,
|
|||
prop = get_property(parent, "interrupt-parent");
|
||||
if (prop) {
|
||||
phandle = propval_cell(prop);
|
||||
/* Give up if this is an overlay with external references */
|
||||
if ((phandle == 0 || phandle == -1) &&
|
||||
(dti->dtsflags & DTSF_PLUGIN))
|
||||
if (!phandle_is_valid(phandle)) {
|
||||
/* Give up if this is an overlay with
|
||||
* external references */
|
||||
if (dti->dtsflags & DTSF_PLUGIN)
|
||||
return;
|
||||
FAIL_PROP(c, dti, parent, prop, "Invalid phandle");
|
||||
continue;
|
||||
}
|
||||
|
||||
irq_node = get_node_by_phandle(root, phandle);
|
||||
if (!irq_node) {
|
||||
|
@ -1605,12 +1747,12 @@ static void check_interrupts_property(struct check *c,
|
|||
|
||||
prop = get_property(irq_node, "#interrupt-cells");
|
||||
if (!prop) {
|
||||
FAIL(c, dti, irq_node, "Missing #interrupt-cells in interrupt-parent");
|
||||
/* We warn about that already in another test. */
|
||||
return;
|
||||
}
|
||||
|
||||
irq_cells = propval_cell(prop);
|
||||
if (irq_prop->val.len % (irq_cells * sizeof(cell_t))) {
|
||||
if (!is_multiple_of(irq_prop->val.len, irq_cells * sizeof(cell_t))) {
|
||||
FAIL_PROP(c, dti, node, prop,
|
||||
"size is (%d), expected multiple of %d",
|
||||
irq_prop->val.len, (int)(irq_cells * sizeof(cell_t)));
|
||||
|
@ -1636,6 +1778,11 @@ static void check_graph_nodes(struct check *c, struct dt_info *dti,
|
|||
get_property(child, "remote-endpoint")))
|
||||
continue;
|
||||
|
||||
/* The root node cannot be a port */
|
||||
if (!node->parent) {
|
||||
FAIL(c, dti, node, "root node contains endpoint node '%s', potentially misplaced remote-endpoint property", child->name);
|
||||
continue;
|
||||
}
|
||||
node->bus = &graph_port_bus;
|
||||
|
||||
/* The parent of 'port' nodes can be either 'ports' or a device */
|
||||
|
@ -1649,31 +1796,6 @@ static void check_graph_nodes(struct check *c, struct dt_info *dti,
|
|||
}
|
||||
WARNING(graph_nodes, check_graph_nodes, NULL);
|
||||
|
||||
static void check_graph_child_address(struct check *c, struct dt_info *dti,
|
||||
struct node *node)
|
||||
{
|
||||
int cnt = 0;
|
||||
struct node *child;
|
||||
|
||||
if (node->bus != &graph_ports_bus && node->bus != &graph_port_bus)
|
||||
return;
|
||||
|
||||
for_each_child(node, child) {
|
||||
struct property *prop = get_property(child, "reg");
|
||||
|
||||
/* No error if we have any non-zero unit address */
|
||||
if (prop && propval_cell(prop) != 0)
|
||||
return;
|
||||
|
||||
cnt++;
|
||||
}
|
||||
|
||||
if (cnt == 1 && node->addr_cells != -1)
|
||||
FAIL(c, dti, node, "graph node has single child node '%s', #address-cells/#size-cells are not necessary",
|
||||
node->children->name);
|
||||
}
|
||||
WARNING(graph_child_address, check_graph_child_address, NULL, &graph_nodes);
|
||||
|
||||
static void check_graph_reg(struct check *c, struct dt_info *dti,
|
||||
struct node *node)
|
||||
{
|
||||
|
@ -1711,17 +1833,21 @@ static void check_graph_port(struct check *c, struct dt_info *dti,
|
|||
if (node->bus != &graph_port_bus)
|
||||
return;
|
||||
|
||||
check_graph_reg(c, dti, node);
|
||||
|
||||
/* skip checks below for overlays */
|
||||
if (dti->dtsflags & DTSF_PLUGIN)
|
||||
return;
|
||||
|
||||
if (!strprefixeq(node->name, node->basenamelen, "port"))
|
||||
FAIL(c, dti, node, "graph port node name should be 'port'");
|
||||
|
||||
check_graph_reg(c, dti, node);
|
||||
}
|
||||
WARNING(graph_port, check_graph_port, NULL, &graph_nodes);
|
||||
|
||||
static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti,
|
||||
struct node *endpoint)
|
||||
{
|
||||
int phandle;
|
||||
cell_t phandle;
|
||||
struct node *node;
|
||||
struct property *prop;
|
||||
|
||||
|
@ -1731,7 +1857,7 @@ static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti,
|
|||
|
||||
phandle = propval_cell(prop);
|
||||
/* Give up if this is an overlay with external references */
|
||||
if (phandle == 0 || phandle == -1)
|
||||
if (!phandle_is_valid(phandle))
|
||||
return NULL;
|
||||
|
||||
node = get_node_by_phandle(dti->dt, phandle);
|
||||
|
@ -1749,11 +1875,15 @@ static void check_graph_endpoint(struct check *c, struct dt_info *dti,
|
|||
if (!node->parent || node->parent->bus != &graph_port_bus)
|
||||
return;
|
||||
|
||||
if (!strprefixeq(node->name, node->basenamelen, "endpoint"))
|
||||
FAIL(c, dti, node, "graph endpont node name should be 'endpoint'");
|
||||
|
||||
check_graph_reg(c, dti, node);
|
||||
|
||||
/* skip checks below for overlays */
|
||||
if (dti->dtsflags & DTSF_PLUGIN)
|
||||
return;
|
||||
|
||||
if (!strprefixeq(node->name, node->basenamelen, "endpoint"))
|
||||
FAIL(c, dti, node, "graph endpoint node name should be 'endpoint'");
|
||||
|
||||
remote_node = get_remote_endpoint(c, dti, node);
|
||||
if (!remote_node)
|
||||
return;
|
||||
|
@ -1764,10 +1894,35 @@ static void check_graph_endpoint(struct check *c, struct dt_info *dti,
|
|||
}
|
||||
WARNING(graph_endpoint, check_graph_endpoint, NULL, &graph_nodes);
|
||||
|
||||
static void check_graph_child_address(struct check *c, struct dt_info *dti,
|
||||
struct node *node)
|
||||
{
|
||||
int cnt = 0;
|
||||
struct node *child;
|
||||
|
||||
if (node->bus != &graph_ports_bus && node->bus != &graph_port_bus)
|
||||
return;
|
||||
|
||||
for_each_child(node, child) {
|
||||
struct property *prop = get_property(child, "reg");
|
||||
|
||||
/* No error if we have any non-zero unit address */
|
||||
if (prop && propval_cell(prop) != 0 )
|
||||
return;
|
||||
|
||||
cnt++;
|
||||
}
|
||||
|
||||
if (cnt == 1 && node->addr_cells != -1)
|
||||
FAIL(c, dti, node, "graph node has single child node '%s', #address-cells/#size-cells are not necessary",
|
||||
node->children->name);
|
||||
}
|
||||
WARNING(graph_child_address, check_graph_child_address, NULL, &graph_nodes, &graph_port, &graph_endpoint);
|
||||
|
||||
static struct check *check_table[] = {
|
||||
&duplicate_node_names, &duplicate_property_names,
|
||||
&node_name_chars, &node_name_format, &property_name_chars,
|
||||
&name_is_string, &name_properties,
|
||||
&name_is_string, &name_properties, &node_name_vs_property_name,
|
||||
|
||||
&duplicate_label,
|
||||
|
||||
|
@ -1775,7 +1930,7 @@ static struct check *check_table[] = {
|
|||
&phandle_references, &path_references,
|
||||
&omit_unused_nodes,
|
||||
|
||||
&address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell,
|
||||
&address_cells_is_cell, &size_cells_is_cell,
|
||||
&device_type_is_string, &model_is_string, &status_is_string,
|
||||
&label_is_string,
|
||||
|
||||
|
@ -1784,7 +1939,7 @@ static struct check *check_table[] = {
|
|||
&property_name_chars_strict,
|
||||
&node_name_chars_strict,
|
||||
|
||||
&addr_size_cells, ®_format, &ranges_format,
|
||||
&addr_size_cells, ®_format, &ranges_format, &dma_ranges_format,
|
||||
|
||||
&unit_address_vs_reg,
|
||||
&unit_address_format,
|
||||
|
@ -1810,25 +1965,43 @@ static struct check *check_table[] = {
|
|||
&chosen_node_is_root, &chosen_node_bootargs, &chosen_node_stdout_path,
|
||||
|
||||
&clocks_property,
|
||||
&clocks_is_cell,
|
||||
&cooling_device_property,
|
||||
&cooling_device_is_cell,
|
||||
&dmas_property,
|
||||
&dmas_is_cell,
|
||||
&hwlocks_property,
|
||||
&hwlocks_is_cell,
|
||||
&interrupts_extended_property,
|
||||
&interrupts_extended_is_cell,
|
||||
&io_channels_property,
|
||||
&io_channels_is_cell,
|
||||
&iommus_property,
|
||||
&iommus_is_cell,
|
||||
&mboxes_property,
|
||||
&mboxes_is_cell,
|
||||
&msi_parent_property,
|
||||
&msi_parent_is_cell,
|
||||
&mux_controls_property,
|
||||
&mux_controls_is_cell,
|
||||
&phys_property,
|
||||
&phys_is_cell,
|
||||
&power_domains_property,
|
||||
&power_domains_is_cell,
|
||||
&pwms_property,
|
||||
&pwms_is_cell,
|
||||
&resets_property,
|
||||
&resets_is_cell,
|
||||
&sound_dai_property,
|
||||
&sound_dai_is_cell,
|
||||
&thermal_sensors_property,
|
||||
&thermal_sensors_is_cell,
|
||||
|
||||
&deprecated_gpio_property,
|
||||
&gpios_property,
|
||||
&interrupts_property,
|
||||
&interrupt_provider,
|
||||
&interrupt_map,
|
||||
|
||||
&alias_paths,
|
||||
|
||||
|
@ -1852,7 +2025,7 @@ static void enable_warning_error(struct check *c, bool warn, bool error)
|
|||
|
||||
static void disable_warning_error(struct check *c, bool warn, bool error)
|
||||
{
|
||||
int i;
|
||||
unsigned int i;
|
||||
|
||||
/* Lowering level, also lower it for things this is the prereq
|
||||
* for */
|
||||
|
@ -1873,7 +2046,7 @@ static void disable_warning_error(struct check *c, bool warn, bool error)
|
|||
|
||||
void parse_checks_option(bool warn, bool error, const char *arg)
|
||||
{
|
||||
int i;
|
||||
unsigned int i;
|
||||
const char *name = arg;
|
||||
bool enable = true;
|
||||
|
||||
|
@ -1900,7 +2073,7 @@ void parse_checks_option(bool warn, bool error, const char *arg)
|
|||
|
||||
void process_checks(bool force, struct dt_info *dti)
|
||||
{
|
||||
int i;
|
||||
unsigned int i;
|
||||
int error = 0;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(check_table); i++) {
|
||||
|
|
|
@ -1,20 +1,6 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005, 2008.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
%option noyywrap nounput noinput never-interactive
|
||||
|
@ -108,7 +94,7 @@ static const struct {
|
|||
<INITIAL>[0-9a-fA-F]+ {
|
||||
unsigned long long val;
|
||||
int obase = 16, width = 0;
|
||||
int i;
|
||||
unsigned int i;
|
||||
|
||||
val = strtoull(yytext, NULL, cbase);
|
||||
|
||||
|
|
70
data.c
70
data.c
|
@ -1,21 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "dtc.h"
|
||||
|
@ -36,10 +21,10 @@ void data_free(struct data d)
|
|||
free(d.val);
|
||||
}
|
||||
|
||||
struct data data_grow_for(struct data d, int xlen)
|
||||
struct data data_grow_for(struct data d, unsigned int xlen)
|
||||
{
|
||||
struct data nd;
|
||||
int newsize;
|
||||
unsigned int newsize;
|
||||
|
||||
if (xlen == 0)
|
||||
return d;
|
||||
|
@ -99,7 +84,7 @@ struct data data_copy_file(FILE *f, size_t maxlen)
|
|||
while (!feof(f) && (d.len < maxlen)) {
|
||||
size_t chunksize, ret;
|
||||
|
||||
if (maxlen == -1)
|
||||
if (maxlen == (size_t)-1)
|
||||
chunksize = 4096;
|
||||
else
|
||||
chunksize = maxlen - d.len;
|
||||
|
@ -243,11 +228,7 @@ struct data data_add_marker(struct data d, enum markertype type, char *ref)
|
|||
{
|
||||
struct marker *m;
|
||||
|
||||
m = xmalloc(sizeof(*m));
|
||||
m->offset = d.len;
|
||||
m->type = type;
|
||||
m->ref = ref;
|
||||
m->next = NULL;
|
||||
m = alloc_marker(d.len, type, ref);
|
||||
|
||||
return data_append_markers(d, m);
|
||||
}
|
||||
|
@ -269,3 +250,44 @@ bool data_is_one_string(struct data d)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
struct data data_insert_data(struct data d, struct marker *m, struct data old)
|
||||
{
|
||||
unsigned int offset = m->offset;
|
||||
struct marker *next = m->next;
|
||||
struct marker *marker;
|
||||
struct data new_data;
|
||||
char *ref;
|
||||
|
||||
new_data = data_insert_at_marker(d, m, old.val, old.len);
|
||||
|
||||
/* Copy all markers from old value */
|
||||
marker = old.markers;
|
||||
for_each_marker(marker) {
|
||||
ref = NULL;
|
||||
|
||||
if (marker->ref)
|
||||
ref = xstrdup(marker->ref);
|
||||
|
||||
m->next = alloc_marker(marker->offset + offset, marker->type,
|
||||
ref);
|
||||
m = m->next;
|
||||
}
|
||||
m->next = next;
|
||||
|
||||
return new_data;
|
||||
}
|
||||
|
||||
struct marker *alloc_marker(unsigned int offset, enum markertype type,
|
||||
char *ref)
|
||||
{
|
||||
struct marker *m;
|
||||
|
||||
m = xmalloc(sizeof(*m));
|
||||
m->offset = offset;
|
||||
m->type = type;
|
||||
m->ref = ref;
|
||||
m->next = NULL;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
|
37
dtc-lexer.l
37
dtc-lexer.l
|
@ -1,21 +1,6 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
%option noyywrap nounput noinput never-interactive
|
||||
|
@ -38,7 +23,6 @@ LINECOMMENT "//".*\n
|
|||
#include "srcpos.h"
|
||||
#include "dtc-parser.tab.h"
|
||||
|
||||
YYLTYPE yylloc;
|
||||
extern bool treesource_error;
|
||||
|
||||
/* CAUTION: this will stop working if we ever use yyless() or yyunput() */
|
||||
|
@ -73,7 +57,7 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
|
|||
push_input_file(name);
|
||||
}
|
||||
|
||||
<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? {
|
||||
<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)* {
|
||||
char *line, *fnstart, *fnend;
|
||||
struct data fn;
|
||||
/* skip text before line # */
|
||||
|
@ -167,6 +151,21 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
|
|||
return DT_LABEL;
|
||||
}
|
||||
|
||||
<V1>{LABEL} {
|
||||
/* Missed includes or macro definitions while
|
||||
* preprocessing can lead to unexpected identifiers in
|
||||
* the input. Report a slightly more informative error
|
||||
* in this case */
|
||||
|
||||
lexical_error("Unexpected '%s'", yytext);
|
||||
|
||||
/* Treat it as a literal which often generates further
|
||||
* useful error messages */
|
||||
|
||||
yylval.integer = 0;
|
||||
return DT_LITERAL;
|
||||
}
|
||||
|
||||
<V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
|
||||
char *e;
|
||||
DPRINT("Integer Literal: '%s'\n", yytext);
|
||||
|
@ -216,7 +215,7 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
|
|||
return DT_LABEL_REF;
|
||||
}
|
||||
|
||||
<*>"&{/"{PATHCHAR}*\} { /* new-style path reference */
|
||||
<*>"&{"{PATHCHAR}*\} { /* new-style path reference */
|
||||
yytext[yyleng-1] = '\0';
|
||||
DPRINT("Ref: %s\n", yytext+2);
|
||||
yylval.labelref = xstrdup(yytext+2);
|
||||
|
|
54
dtc-parser.y
54
dtc-parser.y
|
@ -1,22 +1,9 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
%locations
|
||||
|
||||
%{
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
@ -32,8 +19,16 @@ extern void yyerror(char const *s);
|
|||
treesource_error = true; \
|
||||
} while (0)
|
||||
|
||||
#define YYERROR_CALL(msg) yyerror(msg)
|
||||
|
||||
extern struct dt_info *parser_output;
|
||||
extern bool treesource_error;
|
||||
|
||||
static bool is_ref_relative(const char *ref)
|
||||
{
|
||||
return ref[0] != '/' && strchr(&ref[1], '/');
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%union {
|
||||
|
@ -180,6 +175,8 @@ devicetree:
|
|||
*/
|
||||
if (!($<flags>-1 & DTSF_PLUGIN))
|
||||
ERROR(&@2, "Label or path %s not found", $1);
|
||||
else if (is_ref_relative($1))
|
||||
ERROR(&@2, "Label-relative reference %s not supported in plugin", $1);
|
||||
$$ = add_orphan_node(
|
||||
name_node(build_node(NULL, NULL, NULL),
|
||||
""),
|
||||
|
@ -189,6 +186,9 @@ devicetree:
|
|||
{
|
||||
struct node *target = get_node_by_ref($1, $3);
|
||||
|
||||
if (($<flags>-1 & DTSF_PLUGIN) && is_ref_relative($3))
|
||||
ERROR(&@2, "Label-relative reference %s not supported in plugin", $3);
|
||||
|
||||
if (target) {
|
||||
add_label(&target->labels, $2);
|
||||
merge_nodes(target, $4);
|
||||
|
@ -204,6 +204,8 @@ devicetree:
|
|||
* so $-1 is what we want (plugindecl)
|
||||
*/
|
||||
if ($<flags>-1 & DTSF_PLUGIN) {
|
||||
if (is_ref_relative($2))
|
||||
ERROR(&@2, "Label-relative reference %s not supported in plugin", $2);
|
||||
add_orphan_node($1, $3, $2);
|
||||
} else {
|
||||
struct node *target = get_node_by_ref($1, $2);
|
||||
|
@ -282,14 +284,17 @@ propdef:
|
|||
DT_PROPNODENAME '=' propdata ';'
|
||||
{
|
||||
$$ = build_property($1, $3, &@$);
|
||||
free($1);
|
||||
}
|
||||
| DT_PROPNODENAME ';'
|
||||
{
|
||||
$$ = build_property($1, empty_data, &@$);
|
||||
free($1);
|
||||
}
|
||||
| DT_DEL_PROP DT_PROPNODENAME ';'
|
||||
{
|
||||
$$ = build_property_delete($2);
|
||||
free($2);
|
||||
}
|
||||
| DT_LABEL propdef
|
||||
{
|
||||
|
@ -402,9 +407,14 @@ arrayprefix:
|
|||
* within the mask to one (i.e. | in the
|
||||
* mask), all bits are one.
|
||||
*/
|
||||
if (($2 > mask) && (($2 | mask) != -1ULL))
|
||||
ERROR(&@2, "Value out of range for"
|
||||
" %d-bit array element", $1.bits);
|
||||
if (($2 > mask) && (($2 | mask) != -1ULL)) {
|
||||
char *loc = srcpos_string(&@2);
|
||||
fprintf(stderr,
|
||||
"WARNING: %s: Value 0x%016" PRIx64
|
||||
" truncated to 0x%0*" PRIx64 "\n",
|
||||
loc, $2, $1.bits / 4, ($2 & mask));
|
||||
free(loc);
|
||||
}
|
||||
}
|
||||
|
||||
$$.data = data_append_integer($1.data, $2, $1.bits);
|
||||
|
@ -487,8 +497,8 @@ integer_rela:
|
|||
;
|
||||
|
||||
integer_shift:
|
||||
integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; }
|
||||
| integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; }
|
||||
integer_shift DT_LSHIFT integer_add { $$ = ($3 < 64) ? ($1 << $3) : 0; }
|
||||
| integer_shift DT_RSHIFT integer_add { $$ = ($3 < 64) ? ($1 >> $3) : 0; }
|
||||
| integer_add
|
||||
;
|
||||
|
||||
|
@ -563,10 +573,12 @@ subnode:
|
|||
DT_PROPNODENAME nodedef
|
||||
{
|
||||
$$ = name_node($2, $1);
|
||||
free($1);
|
||||
}
|
||||
| DT_DEL_NODE DT_PROPNODENAME ';'
|
||||
{
|
||||
$$ = name_node(build_node_delete(&@$), $2);
|
||||
free($2);
|
||||
}
|
||||
| DT_OMIT_NO_REF subnode
|
||||
{
|
||||
|
|
38
dtc.c
38
dtc.c
|
@ -1,21 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
@ -27,10 +12,10 @@
|
|||
* Command line options
|
||||
*/
|
||||
int quiet; /* Level of quietness */
|
||||
int reservenum; /* Number of memory reservation slots */
|
||||
unsigned int reservenum;/* Number of memory reservation slots */
|
||||
int minsize; /* Minimum blob size */
|
||||
int padsize; /* Additional padding to blob */
|
||||
int alignsize; /* Additional padding to blob accroding to the alignsize */
|
||||
int alignsize; /* Additional padding to blob according to the alignsize */
|
||||
int phandle_format = PHANDLE_EPAPR; /* Use linux,phandle or phandle properties */
|
||||
int generate_symbols; /* enable symbols & fixup support */
|
||||
int generate_fixups; /* suppress generation of fixups on symbol support */
|
||||
|
@ -62,7 +47,7 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
|
|||
|
||||
/* Usage related data. */
|
||||
static const char usage_synopsis[] = "dtc [options] <input file>";
|
||||
static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@AThv";
|
||||
static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@LAThv";
|
||||
static struct option const usage_long_opts[] = {
|
||||
{"quiet", no_argument, NULL, 'q'},
|
||||
{"in-format", a_argument, NULL, 'I'},
|
||||
|
@ -82,6 +67,7 @@ static struct option const usage_long_opts[] = {
|
|||
{"warning", a_argument, NULL, 'W'},
|
||||
{"error", a_argument, NULL, 'E'},
|
||||
{"symbols", no_argument, NULL, '@'},
|
||||
{"local-fixups", no_argument, NULL, 'L'},
|
||||
{"auto-alias", no_argument, NULL, 'A'},
|
||||
{"annotate", no_argument, NULL, 'T'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
|
@ -119,6 +105,7 @@ static const char * const usage_opts_help[] = {
|
|||
"\n\tEnable/disable warnings (prefix with \"no-\")",
|
||||
"\n\tEnable/disable errors (prefix with \"no-\")",
|
||||
"\n\tEnable generation of symbols",
|
||||
"\n\tPossibly generates a __local_fixups__ and a __fixups__ node at the root node",
|
||||
"\n\tEnable auto-alias of labels",
|
||||
"\n\tAnnotate output .dts with input source file and line (-T -T for more details)",
|
||||
"\n\tPrint this help and exit",
|
||||
|
@ -137,6 +124,8 @@ static const char *guess_type_by_name(const char *fname, const char *fallback)
|
|||
return "dts";
|
||||
if (!strcasecmp(s, ".yaml"))
|
||||
return "yaml";
|
||||
if (!strcasecmp(s, ".dtbo"))
|
||||
return "dtb";
|
||||
if (!strcasecmp(s, ".dtb"))
|
||||
return "dtb";
|
||||
return fallback;
|
||||
|
@ -210,7 +199,7 @@ int main(int argc, char *argv[])
|
|||
depname = optarg;
|
||||
break;
|
||||
case 'R':
|
||||
reservenum = strtol(optarg, NULL, 0);
|
||||
reservenum = strtoul(optarg, NULL, 0);
|
||||
break;
|
||||
case 'S':
|
||||
minsize = strtol(optarg, NULL, 0);
|
||||
|
@ -265,6 +254,11 @@ int main(int argc, char *argv[])
|
|||
case '@':
|
||||
generate_symbols = 1;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
generate_fixups = 1;
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
auto_label_aliases = 1;
|
||||
break;
|
||||
|
@ -295,7 +289,9 @@ int main(int argc, char *argv[])
|
|||
if (!depfile)
|
||||
die("Couldn't open dependency file %s: %s\n", depname,
|
||||
strerror(errno));
|
||||
fprintf(depfile, "%s:", outname);
|
||||
|
||||
fprint_path_escaped(depfile, outname);
|
||||
fputc(':', depfile);
|
||||
}
|
||||
|
||||
if (inform == NULL)
|
||||
|
|
116
dtc.h
116
dtc.h
|
@ -1,24 +1,9 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#ifndef DTC_H
|
||||
#define DTC_H
|
||||
|
||||
/*
|
||||
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -50,10 +35,10 @@
|
|||
* Command line options
|
||||
*/
|
||||
extern int quiet; /* Level of quietness */
|
||||
extern int reservenum; /* Number of memory reservation slots */
|
||||
extern unsigned int reservenum; /* Number of memory reservation slots */
|
||||
extern int minsize; /* Minimum blob size */
|
||||
extern int padsize; /* Additional padding to blob */
|
||||
extern int alignsize; /* Additional padding to blob accroding to the alignsize */
|
||||
extern int alignsize; /* Additional padding to blob according to the alignsize */
|
||||
extern int phandle_format; /* Use linux,phandle or phandle properties */
|
||||
extern int generate_symbols; /* generate symbols for nodes with labels */
|
||||
extern int generate_fixups; /* generate fixups */
|
||||
|
@ -66,10 +51,56 @@ extern int annotate; /* annotate .dts with input source location */
|
|||
|
||||
typedef uint32_t cell_t;
|
||||
|
||||
static inline bool phandle_is_valid(cell_t phandle)
|
||||
{
|
||||
return phandle != 0 && phandle != ~0U;
|
||||
}
|
||||
|
||||
static inline uint16_t dtb_ld16(const void *p)
|
||||
{
|
||||
const uint8_t *bp = (const uint8_t *)p;
|
||||
|
||||
return ((uint16_t)bp[0] << 8)
|
||||
| bp[1];
|
||||
}
|
||||
|
||||
static inline uint32_t dtb_ld32(const void *p)
|
||||
{
|
||||
const uint8_t *bp = (const uint8_t *)p;
|
||||
|
||||
return ((uint32_t)bp[0] << 24)
|
||||
| ((uint32_t)bp[1] << 16)
|
||||
| ((uint32_t)bp[2] << 8)
|
||||
| bp[3];
|
||||
}
|
||||
|
||||
static inline uint64_t dtb_ld64(const void *p)
|
||||
{
|
||||
const uint8_t *bp = (const uint8_t *)p;
|
||||
|
||||
return ((uint64_t)bp[0] << 56)
|
||||
| ((uint64_t)bp[1] << 48)
|
||||
| ((uint64_t)bp[2] << 40)
|
||||
| ((uint64_t)bp[3] << 32)
|
||||
| ((uint64_t)bp[4] << 24)
|
||||
| ((uint64_t)bp[5] << 16)
|
||||
| ((uint64_t)bp[6] << 8)
|
||||
| bp[7];
|
||||
}
|
||||
|
||||
#define streq(a, b) (strcmp((a), (b)) == 0)
|
||||
#define strstarts(s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0)
|
||||
#define strprefixeq(a, n, b) (strlen(b) == (n) && (memcmp(a, b, n) == 0))
|
||||
static inline bool strends(const char *str, const char *suffix)
|
||||
{
|
||||
unsigned int len, suffix_len;
|
||||
|
||||
len = strlen(str);
|
||||
suffix_len = strlen(suffix);
|
||||
if (len < suffix_len)
|
||||
return false;
|
||||
return streq(str + len - suffix_len, suffix);
|
||||
}
|
||||
|
||||
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
|
||||
|
||||
|
@ -85,17 +116,23 @@ enum markertype {
|
|||
TYPE_UINT64,
|
||||
TYPE_STRING,
|
||||
};
|
||||
|
||||
static inline bool is_type_marker(enum markertype type)
|
||||
{
|
||||
return type >= TYPE_UINT8;
|
||||
}
|
||||
|
||||
extern const char *markername(enum markertype markertype);
|
||||
|
||||
struct marker {
|
||||
enum markertype type;
|
||||
int offset;
|
||||
unsigned int offset;
|
||||
char *ref;
|
||||
struct marker *next;
|
||||
};
|
||||
|
||||
struct data {
|
||||
int len;
|
||||
unsigned int len;
|
||||
char *val;
|
||||
struct marker *markers;
|
||||
};
|
||||
|
@ -109,11 +146,26 @@ struct data {
|
|||
for_each_marker(m) \
|
||||
if ((m)->type == (t))
|
||||
|
||||
size_t type_marker_length(struct marker *m);
|
||||
static inline struct marker *next_type_marker(struct marker *m)
|
||||
{
|
||||
for_each_marker(m)
|
||||
if (is_type_marker(m->type))
|
||||
break;
|
||||
return m;
|
||||
}
|
||||
|
||||
static inline size_t type_marker_length(struct marker *m)
|
||||
{
|
||||
struct marker *next = next_type_marker(m->next);
|
||||
|
||||
if (next)
|
||||
return next->offset - m->offset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void data_free(struct data d);
|
||||
|
||||
struct data data_grow_for(struct data d, int xlen);
|
||||
struct data data_grow_for(struct data d, unsigned int xlen);
|
||||
|
||||
struct data data_copy_mem(const char *mem, int len);
|
||||
struct data data_copy_escape_string(const char *s, int len);
|
||||
|
@ -130,7 +182,10 @@ struct data data_append_addr(struct data d, uint64_t addr);
|
|||
struct data data_append_byte(struct data d, uint8_t byte);
|
||||
struct data data_append_zeroes(struct data d, int len);
|
||||
struct data data_append_align(struct data d, int align);
|
||||
struct data data_insert_data(struct data d, struct marker *m, struct data old);
|
||||
|
||||
struct marker *alloc_marker(unsigned int offset, enum markertype type,
|
||||
char *ref);
|
||||
struct data data_add_marker(struct data d, enum markertype type, char *ref);
|
||||
|
||||
bool data_is_one_string(struct data d);
|
||||
|
@ -208,16 +263,16 @@ struct node {
|
|||
void add_label(struct label **labels, char *label);
|
||||
void delete_labels(struct label **labels);
|
||||
|
||||
struct property *build_property(char *name, struct data val,
|
||||
struct property *build_property(const char *name, struct data val,
|
||||
struct srcpos *srcpos);
|
||||
struct property *build_property_delete(char *name);
|
||||
struct property *build_property_delete(const char *name);
|
||||
struct property *chain_property(struct property *first, struct property *list);
|
||||
struct property *reverse_properties(struct property *first);
|
||||
|
||||
struct node *build_node(struct property *proplist, struct node *children,
|
||||
struct srcpos *srcpos);
|
||||
struct node *build_node_delete(struct srcpos *srcpos);
|
||||
struct node *name_node(struct node *node, char *name);
|
||||
struct node *name_node(struct node *node, const char *name);
|
||||
struct node *omit_node_if_unused(struct node *node);
|
||||
struct node *reference_node(struct node *node);
|
||||
struct node *chain_node(struct node *first, struct node *list);
|
||||
|
@ -231,12 +286,13 @@ void add_child(struct node *parent, struct node *child);
|
|||
void delete_node_by_name(struct node *parent, char *name);
|
||||
void delete_node(struct node *node);
|
||||
void append_to_property(struct node *node,
|
||||
char *name, const void *data, int len);
|
||||
char *name, const void *data, int len,
|
||||
enum markertype type);
|
||||
|
||||
const char *get_unitname(struct node *node);
|
||||
struct property *get_property(struct node *node, const char *propname);
|
||||
cell_t propval_cell(struct property *prop);
|
||||
cell_t propval_cell_n(struct property *prop, int n);
|
||||
cell_t propval_cell_n(struct property *prop, unsigned int n);
|
||||
struct property *get_property_by_label(struct node *tree, const char *label,
|
||||
struct node **node);
|
||||
struct marker *get_marker_label(struct node *tree, const char *label,
|
||||
|
@ -283,9 +339,9 @@ struct dt_info *build_dt_info(unsigned int dtsflags,
|
|||
struct reserve_info *reservelist,
|
||||
struct node *tree, uint32_t boot_cpuid_phys);
|
||||
void sort_tree(struct dt_info *dti);
|
||||
void generate_label_tree(struct dt_info *dti, char *name, bool allocph);
|
||||
void generate_fixups_tree(struct dt_info *dti, char *name);
|
||||
void generate_local_fixups_tree(struct dt_info *dti, char *name);
|
||||
void generate_label_tree(struct dt_info *dti, const char *name, bool allocph);
|
||||
void generate_fixups_tree(struct dt_info *dti, const char *name);
|
||||
void generate_local_fixups_tree(struct dt_info *dti, const char *name);
|
||||
|
||||
/* Checks */
|
||||
|
||||
|
|
3
dtdiff
3
dtdiff
|
@ -1,4 +1,5 @@
|
|||
#! /bin/bash
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
# This script uses the bash <(...) extension.
|
||||
# If you want to change this to work with a generic /bin/sh, make sure
|
||||
|
@ -16,7 +17,7 @@ source_and_sort () {
|
|||
*.dts)
|
||||
IFORMAT=dts
|
||||
;;
|
||||
*.dtb)
|
||||
*.dtb|*.dtbo)
|
||||
IFORMAT=dtb
|
||||
;;
|
||||
esac
|
||||
|
|
11
fdtdump.c
11
fdtdump.c
|
@ -1,3 +1,4 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* fdtdump.c - Contributed by Pantelis Antoniou <pantelis.antoniou AT gmail.com>
|
||||
*/
|
||||
|
@ -17,10 +18,10 @@
|
|||
#include "util.h"
|
||||
|
||||
#define FDT_MAGIC_SIZE 4
|
||||
#define MAX_VERSION 17
|
||||
#define MAX_VERSION 17U
|
||||
|
||||
#define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
|
||||
#define PALIGN(p, a) ((void *)(ALIGN((unsigned long)(p), (a))))
|
||||
#define PALIGN(p, a) ((void *)(ALIGN((uintptr_t)(p), (a))))
|
||||
#define GET_CELL(p) (p += 4, *((const fdt32_t *)(p-4)))
|
||||
|
||||
static const char *tagname(uint32_t tag)
|
||||
|
@ -162,7 +163,7 @@ static const char * const usage_opts_help[] = {
|
|||
USAGE_COMMON_OPTS_HELP
|
||||
};
|
||||
|
||||
static bool valid_header(char *p, off_t len)
|
||||
static bool valid_header(char *p, size_t len)
|
||||
{
|
||||
if (len < sizeof(struct fdt_header) ||
|
||||
fdt_magic(p) != FDT_MAGIC ||
|
||||
|
@ -216,7 +217,7 @@ int main(int argc, char *argv[])
|
|||
char *p = buf;
|
||||
char *endp = buf + len;
|
||||
|
||||
fdt_set_magic(smagic, FDT_MAGIC);
|
||||
fdt32_st(smagic, FDT_MAGIC);
|
||||
|
||||
/* poor man's memmem */
|
||||
while ((endp - p) >= FDT_MAGIC_SIZE) {
|
||||
|
@ -234,7 +235,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
++p;
|
||||
}
|
||||
if (!p || endp - p < sizeof(struct fdt_header))
|
||||
if (!p || (size_t)(endp - p) < sizeof(struct fdt_header))
|
||||
die("%s: could not locate fdt magic\n", file);
|
||||
printf("%s: found fdt at offset %#tx\n", file, p - buf);
|
||||
buf = p;
|
||||
|
|
31
fdtget.c
31
fdtget.c
|
@ -1,3 +1,4 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
||||
*
|
||||
|
@ -6,21 +7,6 @@
|
|||
* Based on code written by:
|
||||
* Pantelis Antoniou <pantelis.antoniou@gmail.com> and
|
||||
* Matthew McClintock <msm@freescale.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -76,8 +62,14 @@ static int show_cell_list(struct display_info *disp, const char *data, int len,
|
|||
for (i = 0; i < len; i += size, p += size) {
|
||||
if (i)
|
||||
printf(" ");
|
||||
value = size == 4 ? fdt32_ld((const fdt32_t *)p) :
|
||||
size == 2 ? (*p << 8) | p[1] : *p;
|
||||
switch (size) {
|
||||
case 4: value = fdt32_ld((const fdt32_t *)p); break;
|
||||
case 2: value = fdt16_ld((const fdt16_t *)p); break;
|
||||
case 1:
|
||||
default:
|
||||
value = *p;
|
||||
break;
|
||||
}
|
||||
printf(fmt, value);
|
||||
}
|
||||
|
||||
|
@ -105,6 +97,11 @@ static int show_data(struct display_info *disp, const char *data, int len)
|
|||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
if (disp->type == 'r') {
|
||||
fwrite(data, 1, len, stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
is_string = (disp->type) == 's' ||
|
||||
(!disp->type && util_is_printable_string(data, len));
|
||||
if (is_string) {
|
||||
|
|
121
fdtoverlay.c
121
fdtoverlay.c
|
@ -1,23 +1,9 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* Copyright (c) 2017 Konsulko Group Inc. All rights reserved.
|
||||
*
|
||||
* Author:
|
||||
* Pantelis Antoniou <pantelis.antoniou@konsulko.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -32,12 +18,12 @@
|
|||
|
||||
#include "util.h"
|
||||
|
||||
#define BUF_INCREMENT 65536
|
||||
|
||||
/* Usage related data. */
|
||||
static const char usage_synopsis[] =
|
||||
"apply a number of overlays to a base blob\n"
|
||||
" fdtoverlay <options> [<overlay.dtbo> [<overlay.dtbo>]]\n"
|
||||
"\n"
|
||||
USAGE_TYPE_MSG;
|
||||
" fdtoverlay <options> [<overlay.dtbo> [<overlay.dtbo>]]";
|
||||
static const char usage_short_opts[] = "i:o:v" USAGE_COMMON_SHORT_OPTS;
|
||||
static struct option const usage_long_opts[] = {
|
||||
{"input", required_argument, NULL, 'i'},
|
||||
|
@ -54,65 +40,118 @@ static const char * const usage_opts_help[] = {
|
|||
|
||||
int verbose = 0;
|
||||
|
||||
static void *apply_one(char *base, const char *overlay, size_t *buf_len,
|
||||
const char *name)
|
||||
{
|
||||
char *tmp = NULL;
|
||||
char *tmpo;
|
||||
int ret;
|
||||
bool has_symbols;
|
||||
|
||||
/*
|
||||
* We take copies first, because a failed apply can trash
|
||||
* both the base blob and the overlay
|
||||
*/
|
||||
tmpo = xmalloc(fdt_totalsize(overlay));
|
||||
|
||||
do {
|
||||
tmp = xrealloc(tmp, *buf_len);
|
||||
ret = fdt_open_into(base, tmp, *buf_len);
|
||||
if (ret) {
|
||||
fprintf(stderr,
|
||||
"\nFailed to make temporary copy: %s\n",
|
||||
fdt_strerror(ret));
|
||||
goto fail;
|
||||
}
|
||||
ret = fdt_path_offset(tmp, "/__symbols__");
|
||||
has_symbols = ret >= 0;
|
||||
|
||||
memcpy(tmpo, overlay, fdt_totalsize(overlay));
|
||||
|
||||
ret = fdt_overlay_apply(tmp, tmpo);
|
||||
if (ret == -FDT_ERR_NOSPACE) {
|
||||
*buf_len += BUF_INCREMENT;
|
||||
}
|
||||
} while (ret == -FDT_ERR_NOSPACE);
|
||||
|
||||
if (ret) {
|
||||
fprintf(stderr, "\nFailed to apply '%s': %s\n",
|
||||
name, fdt_strerror(ret));
|
||||
if (!has_symbols) {
|
||||
fprintf(stderr,
|
||||
"base blob does not have a '/__symbols__' node, "
|
||||
"make sure you have compiled the base blob with '-@' option\n");
|
||||
}
|
||||
goto fail;
|
||||
}
|
||||
|
||||
free(base);
|
||||
free(tmpo);
|
||||
return tmp;
|
||||
|
||||
fail:
|
||||
free(tmpo);
|
||||
if (tmp)
|
||||
free(tmp);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
static int do_fdtoverlay(const char *input_filename,
|
||||
const char *output_filename,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
char *blob = NULL;
|
||||
char **ovblob = NULL;
|
||||
size_t blob_len, ov_len, total_len;
|
||||
size_t buf_len;
|
||||
int i, ret = -1;
|
||||
|
||||
blob = utilfdt_read(input_filename, &blob_len);
|
||||
blob = utilfdt_read(input_filename, &buf_len);
|
||||
if (!blob) {
|
||||
fprintf(stderr, "\nFailed to read base blob %s\n",
|
||||
input_filename);
|
||||
fprintf(stderr, "\nFailed to read '%s'\n", input_filename);
|
||||
goto out_err;
|
||||
}
|
||||
if (fdt_totalsize(blob) > blob_len) {
|
||||
if (fdt_totalsize(blob) > buf_len) {
|
||||
fprintf(stderr,
|
||||
"\nBase blob is incomplete (%lu / %" PRIu32 " bytes read)\n",
|
||||
(unsigned long)blob_len, fdt_totalsize(blob));
|
||||
(unsigned long)buf_len, fdt_totalsize(blob));
|
||||
goto out_err;
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
/* allocate blob pointer array */
|
||||
ovblob = malloc(sizeof(*ovblob) * argc);
|
||||
ovblob = xmalloc(sizeof(*ovblob) * argc);
|
||||
memset(ovblob, 0, sizeof(*ovblob) * argc);
|
||||
|
||||
/* read and keep track of the overlay blobs */
|
||||
total_len = 0;
|
||||
for (i = 0; i < argc; i++) {
|
||||
size_t ov_len;
|
||||
ovblob[i] = utilfdt_read(argv[i], &ov_len);
|
||||
if (!ovblob[i]) {
|
||||
fprintf(stderr, "\nFailed to read overlay %s\n",
|
||||
argv[i]);
|
||||
fprintf(stderr, "\nFailed to read '%s'\n", argv[i]);
|
||||
goto out_err;
|
||||
}
|
||||
if (fdt_totalsize(ovblob[i]) > ov_len) {
|
||||
fprintf(stderr,
|
||||
"\nOverlay '%s' is incomplete (%lu / %" PRIu32 " bytes read)\n",
|
||||
argv[i], (unsigned long)ov_len,
|
||||
fdt_totalsize(ovblob[i]));
|
||||
goto out_err;
|
||||
}
|
||||
total_len += ov_len;
|
||||
}
|
||||
|
||||
/* grow the blob to worst case */
|
||||
blob_len = fdt_totalsize(blob) + total_len;
|
||||
blob = xrealloc(blob, blob_len);
|
||||
fdt_open_into(blob, blob, blob_len);
|
||||
buf_len = fdt_totalsize(blob);
|
||||
|
||||
/* apply the overlays in sequence */
|
||||
for (i = 0; i < argc; i++) {
|
||||
ret = fdt_overlay_apply(blob, ovblob[i]);
|
||||
if (ret) {
|
||||
fprintf(stderr, "\nFailed to apply %s (%d)\n",
|
||||
argv[i], ret);
|
||||
blob = apply_one(blob, ovblob[i], &buf_len, argv[i]);
|
||||
if (!blob)
|
||||
goto out_err;
|
||||
}
|
||||
}
|
||||
|
||||
fdt_pack(blob);
|
||||
ret = utilfdt_write(output_filename, blob);
|
||||
if (ret)
|
||||
fprintf(stderr, "\nFailed to write output blob %s\n",
|
||||
output_filename);
|
||||
fprintf(stderr, "\nFailed to write '%s'\n",
|
||||
output_filename);
|
||||
|
||||
out_err:
|
||||
if (ovblob) {
|
||||
|
|
22
fdtput.c
22
fdtput.c
|
@ -1,20 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -403,8 +389,8 @@ static struct option const usage_long_opts[] = {
|
|||
USAGE_COMMON_LONG_OPTS,
|
||||
};
|
||||
static const char * const usage_opts_help[] = {
|
||||
"Create nodes if they don't already exist",
|
||||
"Delete nodes (and any subnodes) if they already exist",
|
||||
"Create nodes",
|
||||
"Delete nodes (and any subnodes)",
|
||||
"Delete properties if they already exist",
|
||||
"Automatically create nodes as needed for the node path",
|
||||
"Type of data",
|
||||
|
@ -447,6 +433,8 @@ int main(int argc, char *argv[])
|
|||
if (utilfdt_decode_type(optarg, &disp.type,
|
||||
&disp.size))
|
||||
usage("Invalid type string");
|
||||
if (disp.type == 'r')
|
||||
usage("Unsupported raw data type");
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
|
|
63
flattree.c
63
flattree.c
|
@ -1,21 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "dtc.h"
|
||||
|
@ -139,7 +124,8 @@ static void asm_emit_cell(void *e, cell_t val)
|
|||
{
|
||||
FILE *f = e;
|
||||
|
||||
fprintf(f, "\t.byte 0x%02x; .byte 0x%02x; .byte 0x%02x; .byte 0x%02x\n",
|
||||
fprintf(f, "\t.byte\t0x%02x\n" "\t.byte\t0x%02x\n"
|
||||
"\t.byte\t0x%02x\n" "\t.byte\t0x%02x\n",
|
||||
(val >> 24) & 0xff, (val >> 16) & 0xff,
|
||||
(val >> 8) & 0xff, val & 0xff);
|
||||
}
|
||||
|
@ -149,9 +135,9 @@ static void asm_emit_string(void *e, const char *str, int len)
|
|||
FILE *f = e;
|
||||
|
||||
if (len != 0)
|
||||
fprintf(f, "\t.string\t\"%.*s\"\n", len, str);
|
||||
fprintf(f, "\t.asciz\t\"%.*s\"\n", len, str);
|
||||
else
|
||||
fprintf(f, "\t.string\t\"%s\"\n", str);
|
||||
fprintf(f, "\t.asciz\t\"%s\"\n", str);
|
||||
}
|
||||
|
||||
static void asm_emit_align(void *e, int a)
|
||||
|
@ -164,14 +150,14 @@ static void asm_emit_align(void *e, int a)
|
|||
static void asm_emit_data(void *e, struct data d)
|
||||
{
|
||||
FILE *f = e;
|
||||
int off = 0;
|
||||
unsigned int off = 0;
|
||||
struct marker *m = d.markers;
|
||||
|
||||
for_each_marker_of_type(m, LABEL)
|
||||
emit_offset_label(f, m->ref, m->offset);
|
||||
|
||||
while ((d.len - off) >= sizeof(uint32_t)) {
|
||||
asm_emit_cell(e, fdt32_to_cpu(*((fdt32_t *)(d.val+off))));
|
||||
asm_emit_cell(e, dtb_ld32(d.val + off));
|
||||
off += sizeof(uint32_t);
|
||||
}
|
||||
|
||||
|
@ -234,7 +220,7 @@ static struct emitter asm_emitter = {
|
|||
|
||||
static int stringtable_insert(struct data *d, const char *str)
|
||||
{
|
||||
int i;
|
||||
unsigned int i;
|
||||
|
||||
/* FIXME: do this more efficiently? */
|
||||
|
||||
|
@ -310,7 +296,7 @@ static struct data flatten_reserve_list(struct reserve_info *reservelist,
|
|||
{
|
||||
struct reserve_info *re;
|
||||
struct data d = empty_data;
|
||||
int j;
|
||||
unsigned int j;
|
||||
|
||||
for (re = reservelist; re; re = re->next) {
|
||||
d = data_append_re(d, re->address, re->size);
|
||||
|
@ -360,7 +346,7 @@ static void make_fdt_header(struct fdt_header *fdt,
|
|||
void dt_to_blob(FILE *f, struct dt_info *dti, int version)
|
||||
{
|
||||
struct version_info *vi = NULL;
|
||||
int i;
|
||||
unsigned int i;
|
||||
struct data blob = empty_data;
|
||||
struct data reservebuf = empty_data;
|
||||
struct data dtbuf = empty_data;
|
||||
|
@ -453,7 +439,7 @@ static void dump_stringtable_asm(FILE *f, struct data strbuf)
|
|||
|
||||
while (p < (strbuf.val + strbuf.len)) {
|
||||
len = strlen(p);
|
||||
fprintf(f, "\t.string \"%s\"\n", p);
|
||||
fprintf(f, "\t.asciz \"%s\"\n", p);
|
||||
p += len+1;
|
||||
}
|
||||
}
|
||||
|
@ -461,7 +447,7 @@ static void dump_stringtable_asm(FILE *f, struct data strbuf)
|
|||
void dt_to_asm(FILE *f, struct dt_info *dti, int version)
|
||||
{
|
||||
struct version_info *vi = NULL;
|
||||
int i;
|
||||
unsigned int i;
|
||||
struct data strbuf = empty_data;
|
||||
struct reserve_info *re;
|
||||
const char *symprefix = "dt";
|
||||
|
@ -517,7 +503,7 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version)
|
|||
* Reserve map entries.
|
||||
* Align the reserve map to a doubleword boundary.
|
||||
* Each entry is an (address, size) pair of u64 values.
|
||||
* Always supply a zero-sized temination entry.
|
||||
* Always supply a zero-sized termination entry.
|
||||
*/
|
||||
asm_emit_align(f, 8);
|
||||
emit_label(f, symprefix, "reserve_map");
|
||||
|
@ -525,7 +511,7 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version)
|
|||
fprintf(f, "/* Memory reserve map from source file */\n");
|
||||
|
||||
/*
|
||||
* Use .long on high and low halfs of u64s to avoid .quad
|
||||
* Use .long on high and low halves of u64s to avoid .quad
|
||||
* as it appears .quad isn't available in some assemblers.
|
||||
*/
|
||||
for (re = dti->reservelist; re; re = re->next) {
|
||||
|
@ -618,11 +604,11 @@ static void flat_realign(struct inbuf *inb, int align)
|
|||
die("Premature end of data parsing flat device tree\n");
|
||||
}
|
||||
|
||||
static char *flat_read_string(struct inbuf *inb)
|
||||
static const char *flat_read_string(struct inbuf *inb)
|
||||
{
|
||||
int len = 0;
|
||||
const char *p = inb->ptr;
|
||||
char *str;
|
||||
const char *str;
|
||||
|
||||
do {
|
||||
if (p >= inb->limit)
|
||||
|
@ -630,7 +616,7 @@ static char *flat_read_string(struct inbuf *inb)
|
|||
len++;
|
||||
} while ((*p++) != '\0');
|
||||
|
||||
str = xstrdup(inb->ptr);
|
||||
str = inb->ptr;
|
||||
|
||||
inb->ptr += len;
|
||||
|
||||
|
@ -725,7 +711,7 @@ static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)
|
|||
}
|
||||
|
||||
|
||||
static char *nodename_from_path(const char *ppath, const char *cpath)
|
||||
static const char *nodename_from_path(const char *ppath, const char *cpath)
|
||||
{
|
||||
int plen;
|
||||
|
||||
|
@ -739,7 +725,7 @@ static char *nodename_from_path(const char *ppath, const char *cpath)
|
|||
if (!streq(ppath, "/"))
|
||||
plen++;
|
||||
|
||||
return xstrdup(cpath + plen);
|
||||
return cpath + plen;
|
||||
}
|
||||
|
||||
static struct node *unflatten_tree(struct inbuf *dtbuf,
|
||||
|
@ -747,7 +733,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
|
|||
const char *parent_flatname, int flags)
|
||||
{
|
||||
struct node *node;
|
||||
char *flatname;
|
||||
const char *flatname;
|
||||
uint32_t val;
|
||||
|
||||
node = build_node(NULL, NULL, NULL);
|
||||
|
@ -755,9 +741,10 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
|
|||
flatname = flat_read_string(dtbuf);
|
||||
|
||||
if (flags & FTF_FULLPATH)
|
||||
node->name = nodename_from_path(parent_flatname, flatname);
|
||||
node->name = xstrdup(nodename_from_path(parent_flatname,
|
||||
flatname));
|
||||
else
|
||||
node->name = flatname;
|
||||
node->name = xstrdup(flatname);
|
||||
|
||||
do {
|
||||
struct property *prop;
|
||||
|
@ -799,10 +786,6 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
|
|||
}
|
||||
} while (val != FDT_END_NODE);
|
||||
|
||||
if (node->name != flatname) {
|
||||
free(flatname);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
21
fstree.c
21
fstree.c
|
@ -1,21 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "dtc.h"
|
||||
|
@ -45,7 +30,7 @@ static struct node *read_fstree(const char *dirname)
|
|||
|
||||
tmpname = join_path(dirname, de->d_name);
|
||||
|
||||
if (lstat(tmpname, &st) < 0)
|
||||
if (stat(tmpname, &st) < 0)
|
||||
die("stat(%s): %s\n", tmpname, strerror(errno));
|
||||
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
|
@ -58,7 +43,7 @@ static struct node *read_fstree(const char *dirname)
|
|||
"WARNING: Cannot open %s: %s\n",
|
||||
tmpname, strerror(errno));
|
||||
} else {
|
||||
prop = build_property(xstrdup(de->d_name),
|
||||
prop = build_property(de->d_name,
|
||||
data_copy_file(pfile,
|
||||
st.st_size),
|
||||
NULL);
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
libfdt.so.1
|
|
@ -1,15 +1,22 @@
|
|||
# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
# Makefile.libfdt
|
||||
#
|
||||
# This is not a complete Makefile of itself. Instead, it is designed to
|
||||
# be easily embeddable into other systems of Makefiles.
|
||||
#
|
||||
|
||||
LIBFDT_so = libfdt.$(SHAREDLIB_EXT)
|
||||
LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1
|
||||
LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h
|
||||
LIBFDT_VERSION = version.lds
|
||||
LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \
|
||||
fdt_addresses.c fdt_overlay.c
|
||||
fdt_addresses.c fdt_overlay.c fdt_check.c
|
||||
LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
|
||||
LIBFDT_LIB = libfdt.$(SHAREDLIB_EXT).$(DTC_VERSION)
|
||||
|
||||
libfdt_clean:
|
||||
@$(VECHO) CLEAN "(libfdt)"
|
||||
rm -f $(STD_CLEANFILES:%=$(LIBFDT_dir)/%)
|
||||
rm -f $(LIBFDT_dir)/$(LIBFDT_so)
|
||||
rm -f $(LIBFDT_dir)/$(LIBFDT_soname)
|
||||
rm -f $(LIBFDT_dir)/$(LIBFDT_LIB)
|
||||
|
|
212
libfdt/fdt.c
212
libfdt/fdt.c
|
@ -1,52 +1,7 @@
|
|||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
|
@ -60,23 +15,38 @@
|
|||
* that the given buffer contains what appears to be a flattened
|
||||
* device tree with sane information in its header.
|
||||
*/
|
||||
int fdt_ro_probe_(const void *fdt)
|
||||
int32_t fdt_ro_probe_(const void *fdt)
|
||||
{
|
||||
uint32_t totalsize = fdt_totalsize(fdt);
|
||||
|
||||
if (can_assume(VALID_DTB))
|
||||
return totalsize;
|
||||
|
||||
/* The device tree must be at an 8-byte aligned address */
|
||||
if ((uintptr_t)fdt & 7)
|
||||
return -FDT_ERR_ALIGNMENT;
|
||||
|
||||
if (fdt_magic(fdt) == FDT_MAGIC) {
|
||||
/* Complete tree */
|
||||
if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
|
||||
return -FDT_ERR_BADVERSION;
|
||||
if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION)
|
||||
return -FDT_ERR_BADVERSION;
|
||||
if (!can_assume(LATEST)) {
|
||||
if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
|
||||
return -FDT_ERR_BADVERSION;
|
||||
if (fdt_last_comp_version(fdt) >
|
||||
FDT_LAST_SUPPORTED_VERSION)
|
||||
return -FDT_ERR_BADVERSION;
|
||||
}
|
||||
} else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
|
||||
/* Unfinished sequential-write blob */
|
||||
if (fdt_size_dt_struct(fdt) == 0)
|
||||
if (!can_assume(VALID_INPUT) && fdt_size_dt_struct(fdt) == 0)
|
||||
return -FDT_ERR_BADSTATE;
|
||||
} else {
|
||||
return -FDT_ERR_BADMAGIC;
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (totalsize < INT32_MAX)
|
||||
return totalsize;
|
||||
else
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
}
|
||||
|
||||
static int check_off_(uint32_t hdrsize, uint32_t totalsize, uint32_t off)
|
||||
|
@ -110,58 +80,79 @@ size_t fdt_header_size_(uint32_t version)
|
|||
return FDT_V17_SIZE;
|
||||
}
|
||||
|
||||
size_t fdt_header_size(const void *fdt)
|
||||
{
|
||||
return can_assume(LATEST) ? FDT_V17_SIZE :
|
||||
fdt_header_size_(fdt_version(fdt));
|
||||
}
|
||||
|
||||
int fdt_check_header(const void *fdt)
|
||||
{
|
||||
size_t hdrsize;
|
||||
|
||||
/* The device tree must be at an 8-byte aligned address */
|
||||
if ((uintptr_t)fdt & 7)
|
||||
return -FDT_ERR_ALIGNMENT;
|
||||
|
||||
if (fdt_magic(fdt) != FDT_MAGIC)
|
||||
return -FDT_ERR_BADMAGIC;
|
||||
if (!can_assume(LATEST)) {
|
||||
if ((fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
|
||||
|| (fdt_last_comp_version(fdt) >
|
||||
FDT_LAST_SUPPORTED_VERSION))
|
||||
return -FDT_ERR_BADVERSION;
|
||||
if (fdt_version(fdt) < fdt_last_comp_version(fdt))
|
||||
return -FDT_ERR_BADVERSION;
|
||||
}
|
||||
hdrsize = fdt_header_size(fdt);
|
||||
if ((fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
|
||||
|| (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION))
|
||||
return -FDT_ERR_BADVERSION;
|
||||
if (fdt_version(fdt) < fdt_last_comp_version(fdt))
|
||||
return -FDT_ERR_BADVERSION;
|
||||
|
||||
if ((fdt_totalsize(fdt) < hdrsize)
|
||||
|| (fdt_totalsize(fdt) > INT_MAX))
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
|
||||
/* Bounds check memrsv block */
|
||||
if (!check_off_(hdrsize, fdt_totalsize(fdt), fdt_off_mem_rsvmap(fdt)))
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
|
||||
/* Bounds check structure block */
|
||||
if (fdt_version(fdt) < 17) {
|
||||
if (!check_off_(hdrsize, fdt_totalsize(fdt),
|
||||
fdt_off_dt_struct(fdt)))
|
||||
if (!can_assume(VALID_DTB)) {
|
||||
if ((fdt_totalsize(fdt) < hdrsize)
|
||||
|| (fdt_totalsize(fdt) > INT_MAX))
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
} else {
|
||||
|
||||
/* Bounds check memrsv block */
|
||||
if (!check_off_(hdrsize, fdt_totalsize(fdt),
|
||||
fdt_off_mem_rsvmap(fdt)))
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
|
||||
/* Bounds check structure block */
|
||||
if (!can_assume(LATEST) && fdt_version(fdt) < 17) {
|
||||
if (!check_off_(hdrsize, fdt_totalsize(fdt),
|
||||
fdt_off_dt_struct(fdt)))
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
} else {
|
||||
if (!check_block_(hdrsize, fdt_totalsize(fdt),
|
||||
fdt_off_dt_struct(fdt),
|
||||
fdt_size_dt_struct(fdt)))
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
}
|
||||
|
||||
/* Bounds check strings block */
|
||||
if (!check_block_(hdrsize, fdt_totalsize(fdt),
|
||||
fdt_off_dt_struct(fdt),
|
||||
fdt_size_dt_struct(fdt)))
|
||||
fdt_off_dt_strings(fdt),
|
||||
fdt_size_dt_strings(fdt)))
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
}
|
||||
|
||||
/* Bounds check strings block */
|
||||
if (!check_block_(hdrsize, fdt_totalsize(fdt),
|
||||
fdt_off_dt_strings(fdt), fdt_size_dt_strings(fdt)))
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
|
||||
{
|
||||
unsigned absoffset = offset + fdt_off_dt_struct(fdt);
|
||||
unsigned int uoffset = offset;
|
||||
unsigned int absoffset = offset + fdt_off_dt_struct(fdt);
|
||||
|
||||
if ((absoffset < offset)
|
||||
|| ((absoffset + len) < absoffset)
|
||||
|| (absoffset + len) > fdt_totalsize(fdt))
|
||||
if (offset < 0)
|
||||
return NULL;
|
||||
|
||||
if (fdt_version(fdt) >= 0x11)
|
||||
if (((offset + len) < offset)
|
||||
if (!can_assume(VALID_INPUT))
|
||||
if ((absoffset < uoffset)
|
||||
|| ((absoffset + len) < absoffset)
|
||||
|| (absoffset + len) > fdt_totalsize(fdt))
|
||||
return NULL;
|
||||
|
||||
if (can_assume(LATEST) || fdt_version(fdt) >= 0x11)
|
||||
if (((uoffset + len) < uoffset)
|
||||
|| ((offset + len) > fdt_size_dt_struct(fdt)))
|
||||
return NULL;
|
||||
|
||||
|
@ -171,13 +162,13 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
|
|||
uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
|
||||
{
|
||||
const fdt32_t *tagp, *lenp;
|
||||
uint32_t tag;
|
||||
uint32_t tag, len, sum;
|
||||
int offset = startoffset;
|
||||
const char *p;
|
||||
|
||||
*nextoffset = -FDT_ERR_TRUNCATED;
|
||||
tagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE);
|
||||
if (!tagp)
|
||||
if (!can_assume(VALID_DTB) && !tagp)
|
||||
return FDT_END; /* premature end */
|
||||
tag = fdt32_to_cpu(*tagp);
|
||||
offset += FDT_TAGSIZE;
|
||||
|
@ -189,19 +180,27 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
|
|||
do {
|
||||
p = fdt_offset_ptr(fdt, offset++, 1);
|
||||
} while (p && (*p != '\0'));
|
||||
if (!p)
|
||||
if (!can_assume(VALID_DTB) && !p)
|
||||
return FDT_END; /* premature end */
|
||||
break;
|
||||
|
||||
case FDT_PROP:
|
||||
lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp));
|
||||
if (!lenp)
|
||||
if (!can_assume(VALID_DTB) && !lenp)
|
||||
return FDT_END; /* premature end */
|
||||
|
||||
len = fdt32_to_cpu(*lenp);
|
||||
sum = len + offset;
|
||||
if (!can_assume(VALID_DTB) &&
|
||||
(INT_MAX <= sum || sum < (uint32_t) offset))
|
||||
return FDT_END; /* premature end */
|
||||
|
||||
/* skip-name offset, length and value */
|
||||
offset += sizeof(struct fdt_property) - FDT_TAGSIZE
|
||||
+ fdt32_to_cpu(*lenp);
|
||||
if (fdt_version(fdt) < 0x10 && fdt32_to_cpu(*lenp) >= 8 &&
|
||||
((offset - fdt32_to_cpu(*lenp)) % 8) != 0)
|
||||
offset += sizeof(struct fdt_property) - FDT_TAGSIZE + len;
|
||||
|
||||
if (!can_assume(LATEST) &&
|
||||
fdt_version(fdt) < 0x10 && len >= 8 &&
|
||||
((offset - len) % 8) != 0)
|
||||
offset += 4;
|
||||
break;
|
||||
|
||||
|
@ -223,8 +222,11 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
|
|||
|
||||
int fdt_check_node_offset_(const void *fdt, int offset)
|
||||
{
|
||||
if ((offset < 0) || (offset % FDT_TAGSIZE)
|
||||
|| (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))
|
||||
if (!can_assume(VALID_INPUT)
|
||||
&& ((offset < 0) || (offset % FDT_TAGSIZE)))
|
||||
return -FDT_ERR_BADOFFSET;
|
||||
|
||||
if (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE)
|
||||
return -FDT_ERR_BADOFFSET;
|
||||
|
||||
return offset;
|
||||
|
@ -232,8 +234,11 @@ int fdt_check_node_offset_(const void *fdt, int offset)
|
|||
|
||||
int fdt_check_prop_offset_(const void *fdt, int offset)
|
||||
{
|
||||
if ((offset < 0) || (offset % FDT_TAGSIZE)
|
||||
|| (fdt_next_tag(fdt, offset, &offset) != FDT_PROP))
|
||||
if (!can_assume(VALID_INPUT)
|
||||
&& ((offset < 0) || (offset % FDT_TAGSIZE)))
|
||||
return -FDT_ERR_BADOFFSET;
|
||||
|
||||
if (fdt_next_tag(fdt, offset, &offset) != FDT_PROP)
|
||||
return -FDT_ERR_BADOFFSET;
|
||||
|
||||
return offset;
|
||||
|
@ -307,23 +312,26 @@ int fdt_next_subnode(const void *fdt, int offset)
|
|||
return offset;
|
||||
}
|
||||
|
||||
const char *fdt_find_string_(const char *strtab, int tabsize, const char *s)
|
||||
const char *fdt_find_string_len_(const char *strtab, int tabsize, const char *s,
|
||||
int slen)
|
||||
{
|
||||
int len = strlen(s) + 1;
|
||||
const char *last = strtab + tabsize - len;
|
||||
const char *last = strtab + tabsize - (slen + 1);
|
||||
const char *p;
|
||||
|
||||
for (p = strtab; p <= last; p++)
|
||||
if (memcmp(p, s, len) == 0)
|
||||
if (memcmp(p, s, slen) == 0 && p[slen] == '\0')
|
||||
return p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fdt_move(const void *fdt, void *buf, int bufsize)
|
||||
{
|
||||
if (!can_assume(VALID_INPUT) && bufsize < 0)
|
||||
return -FDT_ERR_NOSPACE;
|
||||
|
||||
FDT_RO_PROBE(fdt);
|
||||
|
||||
if (fdt_totalsize(fdt) > bufsize)
|
||||
if (fdt_totalsize(fdt) > (unsigned int)bufsize)
|
||||
return -FDT_ERR_NOSPACE;
|
||||
|
||||
memmove(buf, fdt, fdt_totalsize(fdt));
|
||||
|
|
55
libfdt/fdt.h
55
libfdt/fdt.h
|
@ -1,58 +1,13 @@
|
|||
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
|
||||
#ifndef FDT_H
|
||||
#define FDT_H
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
* Copyright 2012 Kim Phillips, Freescale Semiconductor.
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#ifndef __ASSEMBLER__
|
||||
|
||||
struct fdt_header {
|
||||
fdt32_t magic; /* magic word FDT_MAGIC */
|
||||
|
@ -80,17 +35,17 @@ struct fdt_reserve_entry {
|
|||
|
||||
struct fdt_node_header {
|
||||
fdt32_t tag;
|
||||
char name[0];
|
||||
char name[];
|
||||
};
|
||||
|
||||
struct fdt_property {
|
||||
fdt32_t tag;
|
||||
fdt32_t len;
|
||||
fdt32_t nameoff;
|
||||
char data[0];
|
||||
char data[];
|
||||
};
|
||||
|
||||
#endif /* !__ASSEMBLY */
|
||||
#endif /* !__ASSEMBLER__ */
|
||||
|
||||
#define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */
|
||||
#define FDT_TAGSIZE sizeof(fdt32_t)
|
||||
|
|
|
@ -1,53 +1,8 @@
|
|||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au>
|
||||
* Copyright (C) 2018 embedded brains GmbH
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
|
@ -59,7 +14,7 @@
|
|||
static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
|
||||
{
|
||||
const fdt32_t *c;
|
||||
int val;
|
||||
uint32_t val;
|
||||
int len;
|
||||
|
||||
c = fdt_getprop(fdt, nodeoffset, name, &len);
|
||||
|
@ -70,10 +25,10 @@ static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
|
|||
return -FDT_ERR_BADNCELLS;
|
||||
|
||||
val = fdt32_to_cpu(*c);
|
||||
if ((val <= 0) || (val > FDT_MAX_NCELLS))
|
||||
if (val > FDT_MAX_NCELLS)
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
|
||||
return val;
|
||||
return (int)val;
|
||||
}
|
||||
|
||||
int fdt_address_cells(const void *fdt, int nodeoffset)
|
||||
|
@ -81,6 +36,8 @@ int fdt_address_cells(const void *fdt, int nodeoffset)
|
|||
int val;
|
||||
|
||||
val = fdt_cells(fdt, nodeoffset, "#address-cells");
|
||||
if (val == 0)
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
if (val == -FDT_ERR_NOTFOUND)
|
||||
return 2;
|
||||
return val;
|
||||
|
@ -95,3 +52,50 @@ int fdt_size_cells(const void *fdt, int nodeoffset)
|
|||
return 1;
|
||||
return val;
|
||||
}
|
||||
|
||||
/* This function assumes that [address|size]_cells is 1 or 2 */
|
||||
int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
|
||||
const char *name, uint64_t addr, uint64_t size)
|
||||
{
|
||||
int addr_cells, size_cells, ret;
|
||||
uint8_t data[sizeof(fdt64_t) * 2], *prop;
|
||||
|
||||
ret = fdt_address_cells(fdt, parent);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
addr_cells = ret;
|
||||
|
||||
ret = fdt_size_cells(fdt, parent);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
size_cells = ret;
|
||||
|
||||
/* check validity of address */
|
||||
prop = data;
|
||||
if (addr_cells == 1) {
|
||||
if ((addr > UINT32_MAX) || (((uint64_t) UINT32_MAX + 1 - addr) < size))
|
||||
return -FDT_ERR_BADVALUE;
|
||||
|
||||
fdt32_st(prop, (uint32_t)addr);
|
||||
} else if (addr_cells == 2) {
|
||||
fdt64_st(prop, addr);
|
||||
} else {
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
}
|
||||
|
||||
/* check validity of size */
|
||||
prop += addr_cells * sizeof(fdt32_t);
|
||||
if (size_cells == 1) {
|
||||
if (size > UINT32_MAX)
|
||||
return -FDT_ERR_BADVALUE;
|
||||
|
||||
fdt32_st(prop, (uint32_t)size);
|
||||
} else if (size_cells == 2) {
|
||||
fdt64_st(prop, size);
|
||||
} else {
|
||||
return -FDT_ERR_BADNCELLS;
|
||||
}
|
||||
|
||||
return fdt_appendprop(fdt, nodeoffset, name, data,
|
||||
(addr_cells + size_cells) * sizeof(fdt32_t));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
#include <fdt.h>
|
||||
#include <libfdt.h>
|
||||
|
||||
#include "libfdt_internal.h"
|
||||
|
||||
int fdt_check_full(const void *fdt, size_t bufsize)
|
||||
{
|
||||
int err;
|
||||
int num_memrsv;
|
||||
int offset, nextoffset = 0;
|
||||
uint32_t tag;
|
||||
unsigned int depth = 0;
|
||||
const void *prop;
|
||||
const char *propname;
|
||||
bool expect_end = false;
|
||||
|
||||
if (bufsize < FDT_V1_SIZE)
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
if (bufsize < fdt_header_size(fdt))
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
err = fdt_check_header(fdt);
|
||||
if (err != 0)
|
||||
return err;
|
||||
if (bufsize < fdt_totalsize(fdt))
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
|
||||
num_memrsv = fdt_num_mem_rsv(fdt);
|
||||
if (num_memrsv < 0)
|
||||
return num_memrsv;
|
||||
|
||||
while (1) {
|
||||
offset = nextoffset;
|
||||
tag = fdt_next_tag(fdt, offset, &nextoffset);
|
||||
|
||||
if (nextoffset < 0)
|
||||
return nextoffset;
|
||||
|
||||
/* If we see two root nodes, something is wrong */
|
||||
if (expect_end && tag != FDT_END)
|
||||
return -FDT_ERR_BADSTRUCTURE;
|
||||
|
||||
switch (tag) {
|
||||
case FDT_NOP:
|
||||
break;
|
||||
|
||||
case FDT_END:
|
||||
if (depth != 0)
|
||||
return -FDT_ERR_BADSTRUCTURE;
|
||||
return 0;
|
||||
|
||||
case FDT_BEGIN_NODE:
|
||||
depth++;
|
||||
if (depth > INT_MAX)
|
||||
return -FDT_ERR_BADSTRUCTURE;
|
||||
|
||||
/* The root node must have an empty name */
|
||||
if (depth == 1) {
|
||||
const char *name;
|
||||
int len;
|
||||
|
||||
name = fdt_get_name(fdt, offset, &len);
|
||||
if (!name)
|
||||
return len;
|
||||
|
||||
if (*name || len)
|
||||
return -FDT_ERR_BADSTRUCTURE;
|
||||
}
|
||||
break;
|
||||
|
||||
case FDT_END_NODE:
|
||||
if (depth == 0)
|
||||
return -FDT_ERR_BADSTRUCTURE;
|
||||
depth--;
|
||||
if (depth == 0)
|
||||
expect_end = true;
|
||||
break;
|
||||
|
||||
case FDT_PROP:
|
||||
prop = fdt_getprop_by_offset(fdt, offset, &propname,
|
||||
&err);
|
||||
if (!prop)
|
||||
return err;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -FDT_ERR_INTERNAL;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,52 +1,7 @@
|
|||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2012 David Gibson, IBM Corporation.
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
|
|
|
@ -1,53 +1,8 @@
|
|||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2016 Free Electrons
|
||||
* Copyright (C) 2016 NextThing Co.
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
|
@ -85,37 +40,22 @@ static uint32_t overlay_get_target_phandle(const void *fdto, int fragment)
|
|||
return fdt32_to_cpu(*val);
|
||||
}
|
||||
|
||||
/**
|
||||
* overlay_get_target - retrieves the offset of a fragment's target
|
||||
* @fdt: Base device tree blob
|
||||
* @fdto: Device tree overlay blob
|
||||
* @fragment: node offset of the fragment in the overlay
|
||||
* @pathp: pointer which receives the path of the target (or NULL)
|
||||
*
|
||||
* overlay_get_target() retrieves the target offset in the base
|
||||
* device tree of a fragment, no matter how the actual targetting is
|
||||
* done (through a phandle or a path)
|
||||
*
|
||||
* returns:
|
||||
* the targetted node offset in the base device tree
|
||||
* Negative error code on error
|
||||
*/
|
||||
static int overlay_get_target(const void *fdt, const void *fdto,
|
||||
int fragment, char const **pathp)
|
||||
int fdt_overlay_target_offset(const void *fdt, const void *fdto,
|
||||
int fragment_offset, char const **pathp)
|
||||
{
|
||||
uint32_t phandle;
|
||||
const char *path = NULL;
|
||||
int path_len = 0, ret;
|
||||
|
||||
/* Try first to do a phandle based lookup */
|
||||
phandle = overlay_get_target_phandle(fdto, fragment);
|
||||
phandle = overlay_get_target_phandle(fdto, fragment_offset);
|
||||
if (phandle == (uint32_t)-1)
|
||||
return -FDT_ERR_BADPHANDLE;
|
||||
|
||||
/* no phandle, try path */
|
||||
if (!phandle) {
|
||||
/* And then a path based lookup */
|
||||
path = fdt_getprop(fdto, fragment, "target-path", &path_len);
|
||||
path = fdt_getprop(fdto, fragment_offset, "target-path", &path_len);
|
||||
if (path)
|
||||
ret = fdt_path_offset(fdt, path);
|
||||
else
|
||||
|
@ -161,26 +101,22 @@ static int overlay_get_target(const void *fdt, const void *fdto,
|
|||
static int overlay_phandle_add_offset(void *fdt, int node,
|
||||
const char *name, uint32_t delta)
|
||||
{
|
||||
const fdt32_t *val;
|
||||
uint32_t adj_val;
|
||||
fdt32_t *valp, val;
|
||||
int len;
|
||||
|
||||
val = fdt_getprop(fdt, node, name, &len);
|
||||
if (!val)
|
||||
valp = fdt_getprop_w(fdt, node, name, &len);
|
||||
if (!valp)
|
||||
return len;
|
||||
|
||||
if (len != sizeof(*val))
|
||||
if (len != sizeof(val))
|
||||
return -FDT_ERR_BADPHANDLE;
|
||||
|
||||
adj_val = fdt32_to_cpu(*val);
|
||||
if ((adj_val + delta) < adj_val)
|
||||
val = fdt32_ld(valp);
|
||||
if (val + delta < val || val + delta == (uint32_t)-1)
|
||||
return -FDT_ERR_NOPHANDLES;
|
||||
|
||||
adj_val += delta;
|
||||
if (adj_val == (uint32_t)-1)
|
||||
return -FDT_ERR_NOPHANDLES;
|
||||
|
||||
return fdt_setprop_inplace_u32(fdt, node, name, adj_val);
|
||||
fdt32_st(valp, val + delta);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -273,8 +209,8 @@ static int overlay_update_local_node_references(void *fdto,
|
|||
|
||||
fdt_for_each_property_offset(fixup_prop, fdto, fixup_node) {
|
||||
const fdt32_t *fixup_val;
|
||||
const char *tree_val;
|
||||
const char *name;
|
||||
char *tree_val;
|
||||
int fixup_len;
|
||||
int tree_len;
|
||||
int i;
|
||||
|
@ -286,8 +222,9 @@ static int overlay_update_local_node_references(void *fdto,
|
|||
|
||||
if (fixup_len % sizeof(uint32_t))
|
||||
return -FDT_ERR_BADOVERLAY;
|
||||
fixup_len /= sizeof(uint32_t);
|
||||
|
||||
tree_val = fdt_getprop(fdto, tree_node, name, &tree_len);
|
||||
tree_val = fdt_getprop_w(fdto, tree_node, name, &tree_len);
|
||||
if (!tree_val) {
|
||||
if (tree_len == -FDT_ERR_NOTFOUND)
|
||||
return -FDT_ERR_BADOVERLAY;
|
||||
|
@ -295,34 +232,16 @@ static int overlay_update_local_node_references(void *fdto,
|
|||
return tree_len;
|
||||
}
|
||||
|
||||
for (i = 0; i < (fixup_len / sizeof(uint32_t)); i++) {
|
||||
fdt32_t adj_val;
|
||||
uint32_t poffset;
|
||||
for (i = 0; i < fixup_len; i++) {
|
||||
fdt32_t *refp;
|
||||
|
||||
poffset = fdt32_to_cpu(fixup_val[i]);
|
||||
refp = (fdt32_t *)(tree_val + fdt32_ld_(fixup_val + i));
|
||||
|
||||
/*
|
||||
* phandles to fixup can be unaligned.
|
||||
*
|
||||
* Use a memcpy for the architectures that do
|
||||
* not support unaligned accesses.
|
||||
* phandles to fixup can be unaligned, so use
|
||||
* fdt32_{ld,st}() to read/write them.
|
||||
*/
|
||||
memcpy(&adj_val, tree_val + poffset, sizeof(adj_val));
|
||||
|
||||
adj_val = cpu_to_fdt32(fdt32_to_cpu(adj_val) + delta);
|
||||
|
||||
ret = fdt_setprop_inplace_namelen_partial(fdto,
|
||||
tree_node,
|
||||
name,
|
||||
strlen(name),
|
||||
poffset,
|
||||
&adj_val,
|
||||
sizeof(adj_val));
|
||||
if (ret == -FDT_ERR_NOSPACE)
|
||||
return -FDT_ERR_BADOVERLAY;
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
fdt32_st(refp, fdt32_ld(refp) + delta);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,7 +307,6 @@ static int overlay_update_local_references(void *fdto, uint32_t delta)
|
|||
|
||||
/**
|
||||
* overlay_fixup_one_phandle - Set an overlay phandle to the base one
|
||||
* @fdt: Base Device Tree blob
|
||||
* @fdto: Device tree overlay blob
|
||||
* @symbols_off: Node offset of the symbols node in the base device tree
|
||||
* @path: Path to a node holding a phandle in the overlay
|
||||
|
@ -396,7 +314,7 @@ static int overlay_update_local_references(void *fdto, uint32_t delta)
|
|||
* @name: Name of the property holding the phandle reference in the overlay
|
||||
* @name_len: number of name characters to consider
|
||||
* @poffset: Offset within the overlay property where the phandle is stored
|
||||
* @label: Label of the node referenced by the phandle
|
||||
* @phandle: Phandle referencing the node
|
||||
*
|
||||
* overlay_fixup_one_phandle() resolves an overlay phandle pointing to
|
||||
* a node in the base device tree.
|
||||
|
@ -409,34 +327,17 @@ static int overlay_update_local_references(void *fdto, uint32_t delta)
|
|||
* 0 on success
|
||||
* Negative error code on failure
|
||||
*/
|
||||
static int overlay_fixup_one_phandle(void *fdt, void *fdto,
|
||||
int symbols_off,
|
||||
static int overlay_fixup_one_phandle(void *fdto, int symbols_off,
|
||||
const char *path, uint32_t path_len,
|
||||
const char *name, uint32_t name_len,
|
||||
int poffset, const char *label)
|
||||
int poffset, uint32_t phandle)
|
||||
{
|
||||
const char *symbol_path;
|
||||
uint32_t phandle;
|
||||
fdt32_t phandle_prop;
|
||||
int symbol_off, fixup_off;
|
||||
int prop_len;
|
||||
int fixup_off;
|
||||
|
||||
if (symbols_off < 0)
|
||||
return symbols_off;
|
||||
|
||||
symbol_path = fdt_getprop(fdt, symbols_off, label,
|
||||
&prop_len);
|
||||
if (!symbol_path)
|
||||
return prop_len;
|
||||
|
||||
symbol_off = fdt_path_offset(fdt, symbol_path);
|
||||
if (symbol_off < 0)
|
||||
return symbol_off;
|
||||
|
||||
phandle = fdt_get_phandle(fdt, symbol_off);
|
||||
if (!phandle)
|
||||
return -FDT_ERR_NOTFOUND;
|
||||
|
||||
fixup_off = fdt_path_offset_namelen(fdto, path, path_len);
|
||||
if (fixup_off == -FDT_ERR_NOTFOUND)
|
||||
return -FDT_ERR_BADOVERLAY;
|
||||
|
@ -448,7 +349,7 @@ static int overlay_fixup_one_phandle(void *fdt, void *fdto,
|
|||
name, name_len, poffset,
|
||||
&phandle_prop,
|
||||
sizeof(phandle_prop));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* overlay_fixup_phandle - Set an overlay phandle to the base one
|
||||
|
@ -475,6 +376,10 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
|
|||
const char *value;
|
||||
const char *label;
|
||||
int len;
|
||||
const char *symbol_path;
|
||||
int prop_len;
|
||||
int symbol_off;
|
||||
uint32_t phandle;
|
||||
|
||||
value = fdt_getprop_by_offset(fdto, property,
|
||||
&label, &len);
|
||||
|
@ -485,6 +390,18 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
|
|||
return len;
|
||||
}
|
||||
|
||||
symbol_path = fdt_getprop(fdt, symbols_off, label, &prop_len);
|
||||
if (!symbol_path)
|
||||
return prop_len;
|
||||
|
||||
symbol_off = fdt_path_offset(fdt, symbol_path);
|
||||
if (symbol_off < 0)
|
||||
return symbol_off;
|
||||
|
||||
phandle = fdt_get_phandle(fdt, symbol_off);
|
||||
if (!phandle)
|
||||
return -FDT_ERR_NOTFOUND;
|
||||
|
||||
do {
|
||||
const char *path, *name, *fixup_end;
|
||||
const char *fixup_str = value;
|
||||
|
@ -524,9 +441,9 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
|
|||
if ((*endptr != '\0') || (endptr <= (sep + 1)))
|
||||
return -FDT_ERR_BADOVERLAY;
|
||||
|
||||
ret = overlay_fixup_one_phandle(fdt, fdto, symbols_off,
|
||||
ret = overlay_fixup_one_phandle(fdto, symbols_off,
|
||||
path, path_len, name, name_len,
|
||||
poffset, label);
|
||||
poffset, phandle);
|
||||
if (ret)
|
||||
return ret;
|
||||
} while (len > 0);
|
||||
|
@ -579,6 +496,255 @@ static int overlay_fixup_phandles(void *fdt, void *fdto)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* overlay_adjust_local_conflicting_phandle: Changes a phandle value
|
||||
* @fdto: Device tree overlay
|
||||
* @node: The node the phandle is set for
|
||||
* @fdt_phandle: The new value for the phandle
|
||||
*
|
||||
* returns:
|
||||
* 0 on success
|
||||
* Negative error code on failure
|
||||
*/
|
||||
static int overlay_adjust_local_conflicting_phandle(void *fdto, int node,
|
||||
uint32_t fdt_phandle)
|
||||
{
|
||||
const fdt32_t *php;
|
||||
int len, ret;
|
||||
|
||||
php = fdt_getprop(fdto, node, "phandle", &len);
|
||||
if (php && len == sizeof(*php)) {
|
||||
ret = fdt_setprop_inplace_u32(fdto, node, "phandle", fdt_phandle);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
php = fdt_getprop(fdto, node, "linux,phandle", &len);
|
||||
if (php && len == sizeof(*php)) {
|
||||
ret = fdt_setprop_inplace_u32(fdto, node, "linux,phandle", fdt_phandle);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* overlay_update_node_conflicting_references - Recursively replace phandle values
|
||||
* @fdto: Device tree overlay blob
|
||||
* @tree_node: Node to recurse into
|
||||
* @fixup_node: Node offset of the matching local fixups node
|
||||
* @fdt_phandle: Value to replace phandles with
|
||||
* @fdto_phandle: Value to be replaced
|
||||
*
|
||||
* Replaces all phandles with value @fdto_phandle by @fdt_phandle.
|
||||
*
|
||||
* returns:
|
||||
* 0 on success
|
||||
* Negative error code on failure
|
||||
*/
|
||||
static int overlay_update_node_conflicting_references(void *fdto, int tree_node,
|
||||
int fixup_node,
|
||||
uint32_t fdt_phandle,
|
||||
uint32_t fdto_phandle)
|
||||
{
|
||||
int fixup_prop;
|
||||
int fixup_child;
|
||||
int ret;
|
||||
|
||||
fdt_for_each_property_offset(fixup_prop, fdto, fixup_node) {
|
||||
const fdt32_t *fixup_val;
|
||||
const char *name;
|
||||
char *tree_val;
|
||||
int fixup_len;
|
||||
int tree_len;
|
||||
int i;
|
||||
|
||||
fixup_val = fdt_getprop_by_offset(fdto, fixup_prop,
|
||||
&name, &fixup_len);
|
||||
if (!fixup_val)
|
||||
return fixup_len;
|
||||
|
||||
if (fixup_len % sizeof(uint32_t))
|
||||
return -FDT_ERR_BADOVERLAY;
|
||||
fixup_len /= sizeof(uint32_t);
|
||||
|
||||
tree_val = fdt_getprop_w(fdto, tree_node, name, &tree_len);
|
||||
if (!tree_val) {
|
||||
if (tree_len == -FDT_ERR_NOTFOUND)
|
||||
return -FDT_ERR_BADOVERLAY;
|
||||
|
||||
return tree_len;
|
||||
}
|
||||
|
||||
for (i = 0; i < fixup_len; i++) {
|
||||
fdt32_t *refp;
|
||||
uint32_t valp;
|
||||
|
||||
refp = (fdt32_t *)(tree_val + fdt32_ld_(fixup_val + i));
|
||||
valp = fdt32_ld(refp);
|
||||
|
||||
if (valp == fdto_phandle)
|
||||
fdt32_st(refp, fdt_phandle);
|
||||
}
|
||||
}
|
||||
|
||||
fdt_for_each_subnode(fixup_child, fdto, fixup_node) {
|
||||
const char *fixup_child_name = fdt_get_name(fdto, fixup_child, NULL);
|
||||
int tree_child;
|
||||
|
||||
tree_child = fdt_subnode_offset(fdto, tree_node, fixup_child_name);
|
||||
|
||||
if (tree_child == -FDT_ERR_NOTFOUND)
|
||||
return -FDT_ERR_BADOVERLAY;
|
||||
if (tree_child < 0)
|
||||
return tree_child;
|
||||
|
||||
ret = overlay_update_node_conflicting_references(fdto, tree_child,
|
||||
fixup_child,
|
||||
fdt_phandle,
|
||||
fdto_phandle);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* overlay_update_local_conflicting_references - Recursively replace phandle values
|
||||
* @fdto: Device tree overlay blob
|
||||
* @fdt_phandle: Value to replace phandles with
|
||||
* @fdto_phandle: Value to be replaced
|
||||
*
|
||||
* Replaces all phandles with value @fdto_phandle by @fdt_phandle.
|
||||
*
|
||||
* returns:
|
||||
* 0 on success
|
||||
* Negative error code on failure
|
||||
*/
|
||||
static int overlay_update_local_conflicting_references(void *fdto,
|
||||
uint32_t fdt_phandle,
|
||||
uint32_t fdto_phandle)
|
||||
{
|
||||
int fixups;
|
||||
|
||||
fixups = fdt_path_offset(fdto, "/__local_fixups__");
|
||||
if (fixups == -FDT_ERR_NOTFOUND)
|
||||
return 0;
|
||||
if (fixups < 0)
|
||||
return fixups;
|
||||
|
||||
return overlay_update_node_conflicting_references(fdto, 0, fixups,
|
||||
fdt_phandle,
|
||||
fdto_phandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* overlay_prevent_phandle_overwrite_node - Helper function for overlay_prevent_phandle_overwrite
|
||||
* @fdt: Base Device tree blob
|
||||
* @fdtnode: Node in fdt that is checked for an overwrite
|
||||
* @fdto: Device tree overlay blob
|
||||
* @fdtonode: Node in fdto matching @fdtnode
|
||||
*
|
||||
* returns:
|
||||
* 0 on success
|
||||
* Negative error code on failure
|
||||
*/
|
||||
static int overlay_prevent_phandle_overwrite_node(void *fdt, int fdtnode,
|
||||
void *fdto, int fdtonode)
|
||||
{
|
||||
uint32_t fdt_phandle, fdto_phandle;
|
||||
int fdtochild;
|
||||
|
||||
fdt_phandle = fdt_get_phandle(fdt, fdtnode);
|
||||
fdto_phandle = fdt_get_phandle(fdto, fdtonode);
|
||||
|
||||
if (fdt_phandle && fdto_phandle) {
|
||||
int ret;
|
||||
|
||||
ret = overlay_adjust_local_conflicting_phandle(fdto, fdtonode,
|
||||
fdt_phandle);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = overlay_update_local_conflicting_references(fdto,
|
||||
fdt_phandle,
|
||||
fdto_phandle);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
fdt_for_each_subnode(fdtochild, fdto, fdtonode) {
|
||||
const char *name = fdt_get_name(fdto, fdtochild, NULL);
|
||||
int fdtchild;
|
||||
int ret;
|
||||
|
||||
fdtchild = fdt_subnode_offset(fdt, fdtnode, name);
|
||||
if (fdtchild == -FDT_ERR_NOTFOUND)
|
||||
/*
|
||||
* no further overwrites possible here as this node is
|
||||
* new
|
||||
*/
|
||||
continue;
|
||||
|
||||
ret = overlay_prevent_phandle_overwrite_node(fdt, fdtchild,
|
||||
fdto, fdtochild);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* overlay_prevent_phandle_overwrite - Fixes overlay phandles to not overwrite base phandles
|
||||
* @fdt: Base Device Tree blob
|
||||
* @fdto: Device tree overlay blob
|
||||
*
|
||||
* Checks recursively if applying fdto overwrites phandle values in the base
|
||||
* dtb. When such a phandle is found, the fdto is changed to use the fdt's
|
||||
* phandle value to not break references in the base.
|
||||
*
|
||||
* returns:
|
||||
* 0 on success
|
||||
* Negative error code on failure
|
||||
*/
|
||||
static int overlay_prevent_phandle_overwrite(void *fdt, void *fdto)
|
||||
{
|
||||
int fragment;
|
||||
|
||||
fdt_for_each_subnode(fragment, fdto, 0) {
|
||||
int overlay;
|
||||
int target;
|
||||
int ret;
|
||||
|
||||
overlay = fdt_subnode_offset(fdto, fragment, "__overlay__");
|
||||
if (overlay == -FDT_ERR_NOTFOUND)
|
||||
continue;
|
||||
|
||||
if (overlay < 0)
|
||||
return overlay;
|
||||
|
||||
target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL);
|
||||
if (target == -FDT_ERR_NOTFOUND)
|
||||
/*
|
||||
* The subtree doesn't exist in the base, so nothing
|
||||
* will be overwritten.
|
||||
*/
|
||||
continue;
|
||||
else if (target < 0)
|
||||
return target;
|
||||
|
||||
ret = overlay_prevent_phandle_overwrite_node(fdt, target,
|
||||
fdto, overlay);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* overlay_apply_node - Merges a node into the base device tree
|
||||
* @fdt: Base Device Tree blob
|
||||
|
@ -680,7 +846,7 @@ static int overlay_merge(void *fdt, void *fdto)
|
|||
if (overlay < 0)
|
||||
return overlay;
|
||||
|
||||
target = overlay_get_target(fdt, fdto, fragment, NULL);
|
||||
target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL);
|
||||
if (target < 0)
|
||||
return target;
|
||||
|
||||
|
@ -778,26 +944,36 @@ static int overlay_symbol_update(void *fdt, void *fdto)
|
|||
/* keep end marker to avoid strlen() */
|
||||
e = path + path_len;
|
||||
|
||||
/* format: /<fragment-name>/__overlay__/<relative-subnode-path> */
|
||||
|
||||
if (*path != '/')
|
||||
return -FDT_ERR_BADVALUE;
|
||||
|
||||
/* get fragment name first */
|
||||
s = strchr(path + 1, '/');
|
||||
if (!s)
|
||||
return -FDT_ERR_BADOVERLAY;
|
||||
if (!s) {
|
||||
/* Symbol refers to something that won't end
|
||||
* up in the target tree */
|
||||
continue;
|
||||
}
|
||||
|
||||
frag_name = path + 1;
|
||||
frag_name_len = s - path - 1;
|
||||
|
||||
/* verify format; safe since "s" lies in \0 terminated prop */
|
||||
len = sizeof("/__overlay__/") - 1;
|
||||
if ((e - s) < len || memcmp(s, "/__overlay__/", len))
|
||||
return -FDT_ERR_BADOVERLAY;
|
||||
|
||||
rel_path = s + len;
|
||||
rel_path_len = e - rel_path;
|
||||
if ((e - s) > len && (memcmp(s, "/__overlay__/", len) == 0)) {
|
||||
/* /<fragment-name>/__overlay__/<relative-subnode-path> */
|
||||
rel_path = s + len;
|
||||
rel_path_len = e - rel_path - 1;
|
||||
} else if ((e - s) == len
|
||||
&& (memcmp(s, "/__overlay__", len - 1) == 0)) {
|
||||
/* /<fragment-name>/__overlay__ */
|
||||
rel_path = "";
|
||||
rel_path_len = 0;
|
||||
} else {
|
||||
/* Symbol refers to something that won't end
|
||||
* up in the target tree */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* find the fragment index in which the symbol lies */
|
||||
ret = fdt_subnode_offset_namelen(fdto, 0, frag_name,
|
||||
|
@ -813,7 +989,7 @@ static int overlay_symbol_update(void *fdt, void *fdto)
|
|||
return -FDT_ERR_BADOVERLAY;
|
||||
|
||||
/* get the target of the fragment */
|
||||
ret = overlay_get_target(fdt, fdto, fragment, &target_path);
|
||||
ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
target = ret;
|
||||
|
@ -835,7 +1011,7 @@ static int overlay_symbol_update(void *fdt, void *fdto)
|
|||
|
||||
if (!target_path) {
|
||||
/* again in case setprop_placeholder changed it */
|
||||
ret = overlay_get_target(fdt, fdto, fragment, &target_path);
|
||||
ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
target = ret;
|
||||
|
@ -863,24 +1039,36 @@ static int overlay_symbol_update(void *fdt, void *fdto)
|
|||
|
||||
int fdt_overlay_apply(void *fdt, void *fdto)
|
||||
{
|
||||
uint32_t delta = fdt_get_max_phandle(fdt);
|
||||
uint32_t delta;
|
||||
int ret;
|
||||
|
||||
FDT_RO_PROBE(fdt);
|
||||
FDT_RO_PROBE(fdto);
|
||||
|
||||
ret = fdt_find_max_phandle(fdt, &delta);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
/* Increase all phandles in the fdto by delta */
|
||||
ret = overlay_adjust_local_phandles(fdto, delta);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
/* Adapt the phandle values in fdto to the above increase */
|
||||
ret = overlay_update_local_references(fdto, delta);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
/* Update fdto's phandles using symbols from fdt */
|
||||
ret = overlay_fixup_phandles(fdt, fdto);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
/* Don't overwrite phandles in fdt */
|
||||
ret = overlay_prevent_phandle_overwrite(fdt, fdto);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
ret = overlay_merge(fdt, fdto);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
|
316
libfdt/fdt_ro.c
316
libfdt/fdt_ro.c
|
@ -1,52 +1,7 @@
|
|||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
|
@ -78,35 +33,47 @@ static int fdt_nodename_eq_(const void *fdt, int offset,
|
|||
|
||||
const char *fdt_get_string(const void *fdt, int stroffset, int *lenp)
|
||||
{
|
||||
uint32_t absoffset = stroffset + fdt_off_dt_strings(fdt);
|
||||
int32_t totalsize;
|
||||
uint32_t absoffset;
|
||||
size_t len;
|
||||
int err;
|
||||
const char *s, *n;
|
||||
|
||||
err = fdt_ro_probe_(fdt);
|
||||
if (err != 0)
|
||||
if (can_assume(VALID_INPUT)) {
|
||||
s = (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset;
|
||||
|
||||
if (lenp)
|
||||
*lenp = strlen(s);
|
||||
return s;
|
||||
}
|
||||
totalsize = fdt_ro_probe_(fdt);
|
||||
err = totalsize;
|
||||
if (totalsize < 0)
|
||||
goto fail;
|
||||
|
||||
err = -FDT_ERR_BADOFFSET;
|
||||
if (absoffset >= fdt_totalsize(fdt))
|
||||
absoffset = stroffset + fdt_off_dt_strings(fdt);
|
||||
if (absoffset >= (unsigned)totalsize)
|
||||
goto fail;
|
||||
len = fdt_totalsize(fdt) - absoffset;
|
||||
len = totalsize - absoffset;
|
||||
|
||||
if (fdt_magic(fdt) == FDT_MAGIC) {
|
||||
if (stroffset < 0)
|
||||
goto fail;
|
||||
if (fdt_version(fdt) >= 17) {
|
||||
if (stroffset >= fdt_size_dt_strings(fdt))
|
||||
if (can_assume(LATEST) || fdt_version(fdt) >= 17) {
|
||||
if ((unsigned)stroffset >= fdt_size_dt_strings(fdt))
|
||||
goto fail;
|
||||
if ((fdt_size_dt_strings(fdt) - stroffset) < len)
|
||||
len = fdt_size_dt_strings(fdt) - stroffset;
|
||||
}
|
||||
} else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
|
||||
if ((stroffset >= 0)
|
||||
|| (stroffset < -fdt_size_dt_strings(fdt)))
|
||||
unsigned int sw_stroffset = -stroffset;
|
||||
|
||||
if ((stroffset >= 0) ||
|
||||
(sw_stroffset > fdt_size_dt_strings(fdt)))
|
||||
goto fail;
|
||||
if ((-stroffset) < len)
|
||||
len = -stroffset;
|
||||
if (sw_stroffset < len)
|
||||
len = sw_stroffset;
|
||||
} else {
|
||||
err = -FDT_ERR_INTERNAL;
|
||||
goto fail;
|
||||
|
@ -144,41 +111,64 @@ static int fdt_string_eq_(const void *fdt, int stroffset,
|
|||
return p && (slen == len) && (memcmp(p, s, len) == 0);
|
||||
}
|
||||
|
||||
uint32_t fdt_get_max_phandle(const void *fdt)
|
||||
int fdt_find_max_phandle(const void *fdt, uint32_t *phandle)
|
||||
{
|
||||
uint32_t max_phandle = 0;
|
||||
int offset;
|
||||
uint32_t max = 0;
|
||||
int offset = -1;
|
||||
|
||||
for (offset = fdt_next_node(fdt, -1, NULL);;
|
||||
offset = fdt_next_node(fdt, offset, NULL)) {
|
||||
uint32_t phandle;
|
||||
while (true) {
|
||||
uint32_t value;
|
||||
|
||||
if (offset == -FDT_ERR_NOTFOUND)
|
||||
return max_phandle;
|
||||
offset = fdt_next_node(fdt, offset, NULL);
|
||||
if (offset < 0) {
|
||||
if (offset == -FDT_ERR_NOTFOUND)
|
||||
break;
|
||||
|
||||
if (offset < 0)
|
||||
return (uint32_t)-1;
|
||||
return offset;
|
||||
}
|
||||
|
||||
phandle = fdt_get_phandle(fdt, offset);
|
||||
if (phandle == (uint32_t)-1)
|
||||
continue;
|
||||
value = fdt_get_phandle(fdt, offset);
|
||||
|
||||
if (phandle > max_phandle)
|
||||
max_phandle = phandle;
|
||||
if (value > max)
|
||||
max = value;
|
||||
}
|
||||
|
||||
if (phandle)
|
||||
*phandle = max;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fdt_generate_phandle(const void *fdt, uint32_t *phandle)
|
||||
{
|
||||
uint32_t max;
|
||||
int err;
|
||||
|
||||
err = fdt_find_max_phandle(fdt, &max);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (max == FDT_MAX_PHANDLE)
|
||||
return -FDT_ERR_NOPHANDLES;
|
||||
|
||||
if (phandle)
|
||||
*phandle = max + 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct fdt_reserve_entry *fdt_mem_rsv(const void *fdt, int n)
|
||||
{
|
||||
int offset = n * sizeof(struct fdt_reserve_entry);
|
||||
int absoffset = fdt_off_mem_rsvmap(fdt) + offset;
|
||||
unsigned int offset = n * sizeof(struct fdt_reserve_entry);
|
||||
unsigned int absoffset = fdt_off_mem_rsvmap(fdt) + offset;
|
||||
|
||||
if (absoffset < fdt_off_mem_rsvmap(fdt))
|
||||
return NULL;
|
||||
if (absoffset > fdt_totalsize(fdt) - sizeof(struct fdt_reserve_entry))
|
||||
return NULL;
|
||||
if (!can_assume(VALID_INPUT)) {
|
||||
if (absoffset < fdt_off_mem_rsvmap(fdt))
|
||||
return NULL;
|
||||
if (absoffset > fdt_totalsize(fdt) -
|
||||
sizeof(struct fdt_reserve_entry))
|
||||
return NULL;
|
||||
}
|
||||
return fdt_mem_rsv_(fdt, n);
|
||||
}
|
||||
|
||||
|
@ -188,11 +178,11 @@ int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)
|
|||
|
||||
FDT_RO_PROBE(fdt);
|
||||
re = fdt_mem_rsv(fdt, n);
|
||||
if (!re)
|
||||
if (!can_assume(VALID_INPUT) && !re)
|
||||
return -FDT_ERR_BADOFFSET;
|
||||
|
||||
*address = fdt64_ld(&re->address);
|
||||
*size = fdt64_ld(&re->size);
|
||||
*address = fdt64_ld_(&re->address);
|
||||
*size = fdt64_ld_(&re->size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -202,7 +192,7 @@ int fdt_num_mem_rsv(const void *fdt)
|
|||
const struct fdt_reserve_entry *re;
|
||||
|
||||
for (i = 0; (re = fdt_mem_rsv(fdt, i)) != NULL; i++) {
|
||||
if (fdt64_ld(&re->size) == 0)
|
||||
if (fdt64_ld_(&re->size) == 0)
|
||||
return i;
|
||||
}
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
|
@ -265,6 +255,9 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
|
|||
|
||||
FDT_RO_PROBE(fdt);
|
||||
|
||||
if (!can_assume(VALID_INPUT) && namelen <= 0)
|
||||
return -FDT_ERR_BADPATH;
|
||||
|
||||
/* see if we have an alias */
|
||||
if (*path != '/') {
|
||||
const char *q = memchr(path, '/', end - p);
|
||||
|
@ -313,13 +306,13 @@ const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
|
|||
const char *nameptr;
|
||||
int err;
|
||||
|
||||
if (((err = fdt_ro_probe_(fdt)) != 0)
|
||||
if (((err = fdt_ro_probe_(fdt)) < 0)
|
||||
|| ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0))
|
||||
goto fail;
|
||||
|
||||
nameptr = nh->name;
|
||||
|
||||
if (fdt_version(fdt) < 0x10) {
|
||||
if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) {
|
||||
/*
|
||||
* For old FDT versions, match the naming conventions of V16:
|
||||
* give only the leaf name (after all /). The actual tree
|
||||
|
@ -370,7 +363,8 @@ static const struct fdt_property *fdt_get_property_by_offset_(const void *fdt,
|
|||
int err;
|
||||
const struct fdt_property *prop;
|
||||
|
||||
if ((err = fdt_check_prop_offset_(fdt, offset)) < 0) {
|
||||
if (!can_assume(VALID_INPUT) &&
|
||||
(err = fdt_check_prop_offset_(fdt, offset)) < 0) {
|
||||
if (lenp)
|
||||
*lenp = err;
|
||||
return NULL;
|
||||
|
@ -379,7 +373,7 @@ static const struct fdt_property *fdt_get_property_by_offset_(const void *fdt,
|
|||
prop = fdt_offset_ptr_(fdt, offset);
|
||||
|
||||
if (lenp)
|
||||
*lenp = fdt32_ld(&prop->len);
|
||||
*lenp = fdt32_ld_(&prop->len);
|
||||
|
||||
return prop;
|
||||
}
|
||||
|
@ -391,7 +385,7 @@ const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
|
|||
/* Prior to version 16, properties may need realignment
|
||||
* and this API does not work. fdt_getprop_*() will, however. */
|
||||
|
||||
if (fdt_version(fdt) < 0x10) {
|
||||
if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) {
|
||||
if (lenp)
|
||||
*lenp = -FDT_ERR_BADVERSION;
|
||||
return NULL;
|
||||
|
@ -412,11 +406,12 @@ static const struct fdt_property *fdt_get_property_namelen_(const void *fdt,
|
|||
(offset = fdt_next_property_offset(fdt, offset))) {
|
||||
const struct fdt_property *prop;
|
||||
|
||||
if (!(prop = fdt_get_property_by_offset_(fdt, offset, lenp))) {
|
||||
prop = fdt_get_property_by_offset_(fdt, offset, lenp);
|
||||
if (!can_assume(LIBFDT_FLAWLESS) && !prop) {
|
||||
offset = -FDT_ERR_INTERNAL;
|
||||
break;
|
||||
}
|
||||
if (fdt_string_eq_(fdt, fdt32_ld(&prop->nameoff),
|
||||
if (fdt_string_eq_(fdt, fdt32_ld_(&prop->nameoff),
|
||||
name, namelen)) {
|
||||
if (poffset)
|
||||
*poffset = offset;
|
||||
|
@ -437,7 +432,7 @@ const struct fdt_property *fdt_get_property_namelen(const void *fdt,
|
|||
{
|
||||
/* Prior to version 16, properties may need realignment
|
||||
* and this API does not work. fdt_getprop_*() will, however. */
|
||||
if (fdt_version(fdt) < 0x10) {
|
||||
if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) {
|
||||
if (lenp)
|
||||
*lenp = -FDT_ERR_BADVERSION;
|
||||
return NULL;
|
||||
|
@ -468,8 +463,8 @@ const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
|
|||
return NULL;
|
||||
|
||||
/* Handle realignment */
|
||||
if (fdt_version(fdt) < 0x10 && (poffset + sizeof(*prop)) % 8 &&
|
||||
fdt32_ld(&prop->len) >= 8)
|
||||
if (!can_assume(LATEST) && fdt_version(fdt) < 0x10 &&
|
||||
(poffset + sizeof(*prop)) % 8 && fdt32_ld_(&prop->len) >= 8)
|
||||
return prop->data + 4;
|
||||
return prop->data;
|
||||
}
|
||||
|
@ -485,19 +480,24 @@ const void *fdt_getprop_by_offset(const void *fdt, int offset,
|
|||
if (namep) {
|
||||
const char *name;
|
||||
int namelen;
|
||||
name = fdt_get_string(fdt, fdt32_ld(&prop->nameoff),
|
||||
&namelen);
|
||||
if (!name) {
|
||||
if (lenp)
|
||||
*lenp = namelen;
|
||||
return NULL;
|
||||
|
||||
if (!can_assume(VALID_INPUT)) {
|
||||
name = fdt_get_string(fdt, fdt32_ld_(&prop->nameoff),
|
||||
&namelen);
|
||||
*namep = name;
|
||||
if (!name) {
|
||||
if (lenp)
|
||||
*lenp = namelen;
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
*namep = fdt_string(fdt, fdt32_ld_(&prop->nameoff));
|
||||
}
|
||||
*namep = name;
|
||||
}
|
||||
|
||||
/* Handle realignment */
|
||||
if (fdt_version(fdt) < 0x10 && (offset + sizeof(*prop)) % 8 &&
|
||||
fdt32_ld(&prop->len) >= 8)
|
||||
if (!can_assume(LATEST) && fdt_version(fdt) < 0x10 &&
|
||||
(offset + sizeof(*prop)) % 8 && fdt32_ld_(&prop->len) >= 8)
|
||||
return prop->data + 4;
|
||||
return prop->data;
|
||||
}
|
||||
|
@ -522,19 +522,34 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
|
|||
return 0;
|
||||
}
|
||||
|
||||
return fdt32_ld(php);
|
||||
return fdt32_ld_(php);
|
||||
}
|
||||
|
||||
static const void *fdt_path_getprop_namelen(const void *fdt, const char *path,
|
||||
const char *propname, int propnamelen,
|
||||
int *lenp)
|
||||
{
|
||||
int offset = fdt_path_offset(fdt, path);
|
||||
|
||||
if (offset < 0)
|
||||
return NULL;
|
||||
|
||||
return fdt_getprop_namelen(fdt, offset, propname, propnamelen, lenp);
|
||||
}
|
||||
|
||||
const char *fdt_get_alias_namelen(const void *fdt,
|
||||
const char *name, int namelen)
|
||||
{
|
||||
int aliasoffset;
|
||||
int len;
|
||||
const char *alias;
|
||||
|
||||
aliasoffset = fdt_path_offset(fdt, "/aliases");
|
||||
if (aliasoffset < 0)
|
||||
alias = fdt_path_getprop_namelen(fdt, "/aliases", name, namelen, &len);
|
||||
|
||||
if (!can_assume(VALID_DTB) &&
|
||||
!(alias && len > 0 && alias[len - 1] == '\0' && *alias == '/'))
|
||||
return NULL;
|
||||
|
||||
return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL);
|
||||
return alias;
|
||||
}
|
||||
|
||||
const char *fdt_get_alias(const void *fdt, const char *name)
|
||||
|
@ -542,6 +557,17 @@ const char *fdt_get_alias(const void *fdt, const char *name)
|
|||
return fdt_get_alias_namelen(fdt, name, strlen(name));
|
||||
}
|
||||
|
||||
const char *fdt_get_symbol_namelen(const void *fdt,
|
||||
const char *name, int namelen)
|
||||
{
|
||||
return fdt_path_getprop_namelen(fdt, "/__symbols__", name, namelen, NULL);
|
||||
}
|
||||
|
||||
const char *fdt_get_symbol(const void *fdt, const char *name)
|
||||
{
|
||||
return fdt_get_symbol_namelen(fdt, name, strlen(name));
|
||||
}
|
||||
|
||||
int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
|
||||
{
|
||||
int pdepth = 0, p = 0;
|
||||
|
@ -622,10 +648,12 @@ int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
|
|||
}
|
||||
}
|
||||
|
||||
if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))
|
||||
return -FDT_ERR_BADOFFSET;
|
||||
else if (offset == -FDT_ERR_BADOFFSET)
|
||||
return -FDT_ERR_BADSTRUCTURE;
|
||||
if (!can_assume(VALID_INPUT)) {
|
||||
if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))
|
||||
return -FDT_ERR_BADOFFSET;
|
||||
else if (offset == -FDT_ERR_BADOFFSET)
|
||||
return -FDT_ERR_BADSTRUCTURE;
|
||||
}
|
||||
|
||||
return offset; /* error from fdt_next_node() */
|
||||
}
|
||||
|
@ -637,7 +665,8 @@ int fdt_node_depth(const void *fdt, int nodeoffset)
|
|||
|
||||
err = fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, &nodedepth);
|
||||
if (err)
|
||||
return (err < 0) ? err : -FDT_ERR_INTERNAL;
|
||||
return (can_assume(LIBFDT_FLAWLESS) || err < 0) ? err :
|
||||
-FDT_ERR_INTERNAL;
|
||||
return nodedepth;
|
||||
}
|
||||
|
||||
|
@ -682,7 +711,7 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
|
|||
{
|
||||
int offset;
|
||||
|
||||
if ((phandle == 0) || (phandle == -1))
|
||||
if ((phandle == 0) || (phandle == ~0U))
|
||||
return -FDT_ERR_BADPHANDLE;
|
||||
|
||||
FDT_RO_PROBE(fdt);
|
||||
|
@ -857,66 +886,3 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
|
|||
|
||||
return offset; /* error from fdt_next_node() */
|
||||
}
|
||||
|
||||
int fdt_check_full(const void *fdt, size_t bufsize)
|
||||
{
|
||||
int err;
|
||||
int num_memrsv;
|
||||
int offset, nextoffset = 0;
|
||||
uint32_t tag;
|
||||
unsigned depth = 0;
|
||||
const void *prop;
|
||||
const char *propname;
|
||||
|
||||
if (bufsize < FDT_V1_SIZE)
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
err = fdt_check_header(fdt);
|
||||
if (err != 0)
|
||||
return err;
|
||||
if (bufsize < fdt_totalsize(fdt))
|
||||
return -FDT_ERR_TRUNCATED;
|
||||
|
||||
num_memrsv = fdt_num_mem_rsv(fdt);
|
||||
if (num_memrsv < 0)
|
||||
return num_memrsv;
|
||||
|
||||
while (1) {
|
||||
offset = nextoffset;
|
||||
tag = fdt_next_tag(fdt, offset, &nextoffset);
|
||||
|
||||
if (nextoffset < 0)
|
||||
return nextoffset;
|
||||
|
||||
switch (tag) {
|
||||
case FDT_NOP:
|
||||
break;
|
||||
|
||||
case FDT_END:
|
||||
if (depth != 0)
|
||||
return -FDT_ERR_BADSTRUCTURE;
|
||||
return 0;
|
||||
|
||||
case FDT_BEGIN_NODE:
|
||||
depth++;
|
||||
if (depth > INT_MAX)
|
||||
return -FDT_ERR_BADSTRUCTURE;
|
||||
break;
|
||||
|
||||
case FDT_END_NODE:
|
||||
if (depth == 0)
|
||||
return -FDT_ERR_BADSTRUCTURE;
|
||||
depth--;
|
||||
break;
|
||||
|
||||
case FDT_PROP:
|
||||
prop = fdt_getprop_by_offset(fdt, offset, &propname,
|
||||
&err);
|
||||
if (!prop)
|
||||
return err;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -FDT_ERR_INTERNAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
164
libfdt/fdt_rw.c
164
libfdt/fdt_rw.c
|
@ -1,52 +1,7 @@
|
|||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
|
@ -69,14 +24,16 @@ static int fdt_blocks_misordered_(const void *fdt,
|
|||
|
||||
static int fdt_rw_probe_(void *fdt)
|
||||
{
|
||||
if (can_assume(VALID_DTB))
|
||||
return 0;
|
||||
FDT_RO_PROBE(fdt);
|
||||
|
||||
if (fdt_version(fdt) < 17)
|
||||
if (!can_assume(LATEST) && fdt_version(fdt) < 17)
|
||||
return -FDT_ERR_BADVERSION;
|
||||
if (fdt_blocks_misordered_(fdt, sizeof(struct fdt_reserve_entry),
|
||||
fdt_size_dt_struct(fdt)))
|
||||
return -FDT_ERR_BADLAYOUT;
|
||||
if (fdt_version(fdt) > 17)
|
||||
if (!can_assume(LATEST) && fdt_version(fdt) > 17)
|
||||
fdt_set_version(fdt, 17);
|
||||
|
||||
return 0;
|
||||
|
@ -89,7 +46,7 @@ static int fdt_rw_probe_(void *fdt)
|
|||
return err_; \
|
||||
}
|
||||
|
||||
static inline int fdt_data_size_(void *fdt)
|
||||
static inline unsigned int fdt_data_size_(void *fdt)
|
||||
{
|
||||
return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
|
||||
}
|
||||
|
@ -97,15 +54,16 @@ static inline int fdt_data_size_(void *fdt)
|
|||
static int fdt_splice_(void *fdt, void *splicepoint, int oldlen, int newlen)
|
||||
{
|
||||
char *p = splicepoint;
|
||||
char *end = (char *)fdt + fdt_data_size_(fdt);
|
||||
unsigned int dsize = fdt_data_size_(fdt);
|
||||
size_t soff = p - (char *)fdt;
|
||||
|
||||
if (((p + oldlen) < p) || ((p + oldlen) > end))
|
||||
if ((oldlen < 0) || (soff + oldlen < soff) || (soff + oldlen > dsize))
|
||||
return -FDT_ERR_BADOFFSET;
|
||||
if ((p < (char *)fdt) || ((end - oldlen + newlen) < (char *)fdt))
|
||||
if ((p < (char *)fdt) || (dsize + newlen < (unsigned)oldlen))
|
||||
return -FDT_ERR_BADOFFSET;
|
||||
if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt)))
|
||||
if (dsize - oldlen + newlen > fdt_totalsize(fdt))
|
||||
return -FDT_ERR_NOSPACE;
|
||||
memmove(p + newlen, p + oldlen, end - p - oldlen);
|
||||
memmove(p + newlen, p + oldlen, ((char *)fdt + dsize) - (p + oldlen));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -136,6 +94,14 @@ static int fdt_splice_struct_(void *fdt, void *p,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Must only be used to roll back in case of error */
|
||||
static void fdt_del_last_string_(void *fdt, const char *s)
|
||||
{
|
||||
int newlen = strlen(s) + 1;
|
||||
|
||||
fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) - newlen);
|
||||
}
|
||||
|
||||
static int fdt_splice_string_(void *fdt, int newlen)
|
||||
{
|
||||
void *p = (char *)fdt
|
||||
|
@ -149,25 +115,42 @@ static int fdt_splice_string_(void *fdt, int newlen)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int fdt_find_add_string_(void *fdt, const char *s)
|
||||
/**
|
||||
* fdt_find_add_string_() - Find or allocate a string
|
||||
*
|
||||
* @fdt: pointer to the device tree to check/adjust
|
||||
* @s: string to find/add
|
||||
* @allocated: Set to 0 if the string was found, 1 if not found and so
|
||||
* allocated. Ignored if can_assume(NO_ROLLBACK)
|
||||
* @return offset of string in the string table (whether found or added)
|
||||
*/
|
||||
static int fdt_find_add_string_(void *fdt, const char *s, int slen,
|
||||
int *allocated)
|
||||
{
|
||||
char *strtab = (char *)fdt + fdt_off_dt_strings(fdt);
|
||||
const char *p;
|
||||
char *new;
|
||||
int len = strlen(s) + 1;
|
||||
int err;
|
||||
|
||||
p = fdt_find_string_(strtab, fdt_size_dt_strings(fdt), s);
|
||||
if (!can_assume(NO_ROLLBACK))
|
||||
*allocated = 0;
|
||||
|
||||
p = fdt_find_string_len_(strtab, fdt_size_dt_strings(fdt), s, slen);
|
||||
if (p)
|
||||
/* found it */
|
||||
return (p - strtab);
|
||||
|
||||
new = strtab + fdt_size_dt_strings(fdt);
|
||||
err = fdt_splice_string_(fdt, len);
|
||||
err = fdt_splice_string_(fdt, slen + 1);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
memcpy(new, s, len);
|
||||
if (!can_assume(NO_ROLLBACK))
|
||||
*allocated = 1;
|
||||
|
||||
memcpy(new, s, slen);
|
||||
new[slen] = '\0';
|
||||
|
||||
return (new - strtab);
|
||||
}
|
||||
|
||||
|
@ -200,13 +183,15 @@ int fdt_del_mem_rsv(void *fdt, int n)
|
|||
return fdt_splice_mem_rsv_(fdt, re, 1, 0);
|
||||
}
|
||||
|
||||
static int fdt_resize_property_(void *fdt, int nodeoffset, const char *name,
|
||||
static int fdt_resize_property_(void *fdt, int nodeoffset,
|
||||
const char *name, int namelen,
|
||||
int len, struct fdt_property **prop)
|
||||
{
|
||||
int oldlen;
|
||||
int err;
|
||||
|
||||
*prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
|
||||
*prop = fdt_get_property_namelen_w(fdt, nodeoffset, name, namelen,
|
||||
&oldlen);
|
||||
if (!*prop)
|
||||
return oldlen;
|
||||
|
||||
|
@ -219,17 +204,18 @@ static int fdt_resize_property_(void *fdt, int nodeoffset, const char *name,
|
|||
}
|
||||
|
||||
static int fdt_add_property_(void *fdt, int nodeoffset, const char *name,
|
||||
int len, struct fdt_property **prop)
|
||||
int namelen, int len, struct fdt_property **prop)
|
||||
{
|
||||
int proplen;
|
||||
int nextoffset;
|
||||
int namestroff;
|
||||
int err;
|
||||
int allocated;
|
||||
|
||||
if ((nextoffset = fdt_check_node_offset_(fdt, nodeoffset)) < 0)
|
||||
return nextoffset;
|
||||
|
||||
namestroff = fdt_find_add_string_(fdt, name);
|
||||
namestroff = fdt_find_add_string_(fdt, name, namelen, &allocated);
|
||||
if (namestroff < 0)
|
||||
return namestroff;
|
||||
|
||||
|
@ -237,8 +223,12 @@ static int fdt_add_property_(void *fdt, int nodeoffset, const char *name,
|
|||
proplen = sizeof(**prop) + FDT_TAGALIGN(len);
|
||||
|
||||
err = fdt_splice_struct_(fdt, *prop, 0, proplen);
|
||||
if (err)
|
||||
if (err) {
|
||||
/* Delete the string if we failed to add it */
|
||||
if (!can_assume(NO_ROLLBACK) && allocated)
|
||||
fdt_del_last_string_(fdt, name);
|
||||
return err;
|
||||
}
|
||||
|
||||
(*prop)->tag = cpu_to_fdt32(FDT_PROP);
|
||||
(*prop)->nameoff = cpu_to_fdt32(namestroff);
|
||||
|
@ -269,17 +259,18 @@ int fdt_set_name(void *fdt, int nodeoffset, const char *name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
|
||||
int len, void **prop_data)
|
||||
int fdt_setprop_placeholder_namelen(void *fdt, int nodeoffset, const char *name,
|
||||
int namelen, int len, void **prop_data)
|
||||
{
|
||||
struct fdt_property *prop;
|
||||
int err;
|
||||
|
||||
FDT_RW_PROBE(fdt);
|
||||
|
||||
err = fdt_resize_property_(fdt, nodeoffset, name, len, &prop);
|
||||
err = fdt_resize_property_(fdt, nodeoffset, name, namelen, len, &prop);
|
||||
if (err == -FDT_ERR_NOTFOUND)
|
||||
err = fdt_add_property_(fdt, nodeoffset, name, len, &prop);
|
||||
err = fdt_add_property_(fdt, nodeoffset, name, namelen, len,
|
||||
&prop);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -287,13 +278,14 @@ int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int fdt_setprop(void *fdt, int nodeoffset, const char *name,
|
||||
const void *val, int len)
|
||||
int fdt_setprop_namelen(void *fdt, int nodeoffset, const char *name,
|
||||
int namelen, const void *val, int len)
|
||||
{
|
||||
void *prop_data;
|
||||
int err;
|
||||
|
||||
err = fdt_setprop_placeholder(fdt, nodeoffset, name, len, &prop_data);
|
||||
err = fdt_setprop_placeholder_namelen(fdt, nodeoffset, name, namelen,
|
||||
len, &prop_data);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -321,7 +313,8 @@ int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
|
|||
prop->len = cpu_to_fdt32(newlen);
|
||||
memcpy(prop->data + oldlen, val, len);
|
||||
} else {
|
||||
err = fdt_add_property_(fdt, nodeoffset, name, len, &prop);
|
||||
err = fdt_add_property_(fdt, nodeoffset, name, strlen(name),
|
||||
len, &prop);
|
||||
if (err)
|
||||
return err;
|
||||
memcpy(prop->data, val, len);
|
||||
|
@ -363,7 +356,10 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
|
|||
return offset;
|
||||
|
||||
/* Try to place the new node after the parent's properties */
|
||||
fdt_next_tag(fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */
|
||||
tag = fdt_next_tag(fdt, parentoffset, &nextoffset);
|
||||
/* the fdt_subnode_offset_namelen() should ensure this never hits */
|
||||
if (!can_assume(LIBFDT_FLAWLESS) && (tag != FDT_BEGIN_NODE))
|
||||
return -FDT_ERR_INTERNAL;
|
||||
do {
|
||||
offset = nextoffset;
|
||||
tag = fdt_next_tag(fdt, offset, &nextoffset);
|
||||
|
@ -405,7 +401,9 @@ int fdt_del_node(void *fdt, int nodeoffset)
|
|||
}
|
||||
|
||||
static void fdt_packblocks_(const char *old, char *new,
|
||||
int mem_rsv_size, int struct_size)
|
||||
int mem_rsv_size,
|
||||
int struct_size,
|
||||
int strings_size)
|
||||
{
|
||||
int mem_rsv_off, struct_off, strings_off;
|
||||
|
||||
|
@ -420,8 +418,7 @@ static void fdt_packblocks_(const char *old, char *new,
|
|||
fdt_set_off_dt_struct(new, struct_off);
|
||||
fdt_set_size_dt_struct(new, struct_size);
|
||||
|
||||
memmove(new + strings_off, old + fdt_off_dt_strings(old),
|
||||
fdt_size_dt_strings(old));
|
||||
memmove(new + strings_off, old + fdt_off_dt_strings(old), strings_size);
|
||||
fdt_set_off_dt_strings(new, strings_off);
|
||||
fdt_set_size_dt_strings(new, fdt_size_dt_strings(old));
|
||||
}
|
||||
|
@ -440,17 +437,20 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
|
|||
mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
|
||||
* sizeof(struct fdt_reserve_entry);
|
||||
|
||||
if (fdt_version(fdt) >= 17) {
|
||||
if (can_assume(LATEST) || fdt_version(fdt) >= 17) {
|
||||
struct_size = fdt_size_dt_struct(fdt);
|
||||
} else {
|
||||
} else if (fdt_version(fdt) == 16) {
|
||||
struct_size = 0;
|
||||
while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END)
|
||||
;
|
||||
if (struct_size < 0)
|
||||
return struct_size;
|
||||
} else {
|
||||
return -FDT_ERR_BADVERSION;
|
||||
}
|
||||
|
||||
if (!fdt_blocks_misordered_(fdt, mem_rsv_size, struct_size)) {
|
||||
if (can_assume(LIBFDT_ORDER) ||
|
||||
!fdt_blocks_misordered_(fdt, mem_rsv_size, struct_size)) {
|
||||
/* no further work necessary */
|
||||
err = fdt_move(fdt, buf, bufsize);
|
||||
if (err)
|
||||
|
@ -478,7 +478,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
|
|||
return -FDT_ERR_NOSPACE;
|
||||
}
|
||||
|
||||
fdt_packblocks_(fdt, tmp, mem_rsv_size, struct_size);
|
||||
fdt_packblocks_(fdt, tmp, mem_rsv_size, struct_size,
|
||||
fdt_size_dt_strings(fdt));
|
||||
memmove(buf, tmp, newsize);
|
||||
|
||||
fdt_set_magic(buf, FDT_MAGIC);
|
||||
|
@ -498,7 +499,8 @@ int fdt_pack(void *fdt)
|
|||
|
||||
mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
|
||||
* sizeof(struct fdt_reserve_entry);
|
||||
fdt_packblocks_(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt));
|
||||
fdt_packblocks_(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt),
|
||||
fdt_size_dt_strings(fdt));
|
||||
fdt_set_totalsize(fdt, fdt_data_size_(fdt));
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -1,51 +1,7 @@
|
|||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
@ -82,8 +38,10 @@ static struct fdt_errtabent fdt_errtable[] = {
|
|||
FDT_ERRTABENT(FDT_ERR_BADVALUE),
|
||||
FDT_ERRTABENT(FDT_ERR_BADOVERLAY),
|
||||
FDT_ERRTABENT(FDT_ERR_NOPHANDLES),
|
||||
FDT_ERRTABENT(FDT_ERR_BADFLAGS),
|
||||
FDT_ERRTABENT(FDT_ERR_ALIGNMENT),
|
||||
};
|
||||
#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))
|
||||
#define FDT_ERRTABSIZE ((int)(sizeof(fdt_errtable) / sizeof(fdt_errtable[0])))
|
||||
|
||||
const char *fdt_strerror(int errval)
|
||||
{
|
||||
|
@ -91,7 +49,7 @@ const char *fdt_strerror(int errval)
|
|||
return "<valid offset/length>";
|
||||
else if (errval == 0)
|
||||
return "<no error>";
|
||||
else if (errval > -FDT_ERRTABSIZE) {
|
||||
else if (-errval < FDT_ERRTABSIZE) {
|
||||
const char *s = fdt_errtable[-errval].str;
|
||||
|
||||
if (s)
|
||||
|
|
167
libfdt/fdt_sw.c
167
libfdt/fdt_sw.c
|
@ -1,52 +1,7 @@
|
|||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
|
@ -57,10 +12,13 @@
|
|||
|
||||
static int fdt_sw_probe_(void *fdt)
|
||||
{
|
||||
if (fdt_magic(fdt) == FDT_MAGIC)
|
||||
return -FDT_ERR_BADSTATE;
|
||||
else if (fdt_magic(fdt) != FDT_SW_MAGIC)
|
||||
return -FDT_ERR_BADMAGIC;
|
||||
if (!can_assume(VALID_INPUT)) {
|
||||
if (fdt_magic(fdt) == FDT_MAGIC)
|
||||
return -FDT_ERR_BADSTATE;
|
||||
else if (fdt_magic(fdt) != FDT_SW_MAGIC)
|
||||
return -FDT_ERR_BADMAGIC;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -74,7 +32,7 @@ static int fdt_sw_probe_(void *fdt)
|
|||
/* 'memrsv' state: Initial state after fdt_create()
|
||||
*
|
||||
* Allowed functions:
|
||||
* fdt_add_reservmap_entry()
|
||||
* fdt_add_reservemap_entry()
|
||||
* fdt_finish_reservemap() [moves to 'struct' state]
|
||||
*/
|
||||
static int fdt_sw_probe_memrsv_(void *fdt)
|
||||
|
@ -83,7 +41,7 @@ static int fdt_sw_probe_memrsv_(void *fdt)
|
|||
if (err)
|
||||
return err;
|
||||
|
||||
if (fdt_off_dt_strings(fdt) != 0)
|
||||
if (!can_assume(VALID_INPUT) && fdt_off_dt_strings(fdt) != 0)
|
||||
return -FDT_ERR_BADSTATE;
|
||||
return 0;
|
||||
}
|
||||
|
@ -109,7 +67,8 @@ static int fdt_sw_probe_struct_(void *fdt)
|
|||
if (err)
|
||||
return err;
|
||||
|
||||
if (fdt_off_dt_strings(fdt) != fdt_totalsize(fdt))
|
||||
if (!can_assume(VALID_INPUT) &&
|
||||
fdt_off_dt_strings(fdt) != fdt_totalsize(fdt))
|
||||
return -FDT_ERR_BADSTATE;
|
||||
return 0;
|
||||
}
|
||||
|
@ -121,6 +80,12 @@ static int fdt_sw_probe_struct_(void *fdt)
|
|||
return err; \
|
||||
}
|
||||
|
||||
static inline uint32_t sw_flags(void *fdt)
|
||||
{
|
||||
/* assert: (fdt_magic(fdt) == FDT_SW_MAGIC) */
|
||||
return fdt_last_comp_version(fdt);
|
||||
}
|
||||
|
||||
/* 'complete' state: Enter this state after fdt_finish()
|
||||
*
|
||||
* Allowed functions: none
|
||||
|
@ -128,8 +93,8 @@ static int fdt_sw_probe_struct_(void *fdt)
|
|||
|
||||
static void *fdt_grab_space_(void *fdt, size_t len)
|
||||
{
|
||||
int offset = fdt_size_dt_struct(fdt);
|
||||
int spaceleft;
|
||||
unsigned int offset = fdt_size_dt_struct(fdt);
|
||||
unsigned int spaceleft;
|
||||
|
||||
spaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt)
|
||||
- fdt_size_dt_strings(fdt);
|
||||
|
@ -141,20 +106,31 @@ static void *fdt_grab_space_(void *fdt, size_t len)
|
|||
return fdt_offset_ptr_w_(fdt, offset);
|
||||
}
|
||||
|
||||
int fdt_create(void *buf, int bufsize)
|
||||
int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags)
|
||||
{
|
||||
const size_t hdrsize = FDT_ALIGN(sizeof(struct fdt_header),
|
||||
sizeof(struct fdt_reserve_entry));
|
||||
const int hdrsize = FDT_ALIGN(sizeof(struct fdt_header),
|
||||
sizeof(struct fdt_reserve_entry));
|
||||
void *fdt = buf;
|
||||
|
||||
if (bufsize < hdrsize)
|
||||
return -FDT_ERR_NOSPACE;
|
||||
|
||||
if (flags & ~FDT_CREATE_FLAGS_ALL)
|
||||
return -FDT_ERR_BADFLAGS;
|
||||
|
||||
memset(buf, 0, bufsize);
|
||||
|
||||
/*
|
||||
* magic and last_comp_version keep intermediate state during the fdt
|
||||
* creation process, which is replaced with the proper FDT format by
|
||||
* fdt_finish().
|
||||
*
|
||||
* flags should be accessed with sw_flags().
|
||||
*/
|
||||
fdt_set_magic(fdt, FDT_SW_MAGIC);
|
||||
fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION);
|
||||
fdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION);
|
||||
fdt_set_last_comp_version(fdt, flags);
|
||||
|
||||
fdt_set_totalsize(fdt, bufsize);
|
||||
|
||||
fdt_set_off_mem_rsvmap(fdt, hdrsize);
|
||||
|
@ -164,6 +140,11 @@ int fdt_create(void *buf, int bufsize)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int fdt_create(void *buf, int bufsize)
|
||||
{
|
||||
return fdt_create_with_flags(buf, bufsize, 0);
|
||||
}
|
||||
|
||||
int fdt_resize(void *fdt, void *buf, int bufsize)
|
||||
{
|
||||
size_t headsize, tailsize;
|
||||
|
@ -171,13 +152,17 @@ int fdt_resize(void *fdt, void *buf, int bufsize)
|
|||
|
||||
FDT_SW_PROBE(fdt);
|
||||
|
||||
if (bufsize < 0)
|
||||
return -FDT_ERR_NOSPACE;
|
||||
|
||||
headsize = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
|
||||
tailsize = fdt_size_dt_strings(fdt);
|
||||
|
||||
if ((headsize + tailsize) > fdt_totalsize(fdt))
|
||||
if (!can_assume(VALID_DTB) &&
|
||||
headsize + tailsize > fdt_totalsize(fdt))
|
||||
return -FDT_ERR_INTERNAL;
|
||||
|
||||
if ((headsize + tailsize) > bufsize)
|
||||
if ((headsize + tailsize) > (unsigned)bufsize)
|
||||
return -FDT_ERR_NOSPACE;
|
||||
|
||||
oldtail = (char *)fdt + fdt_totalsize(fdt) - tailsize;
|
||||
|
@ -262,43 +247,73 @@ int fdt_end_node(void *fdt)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int fdt_find_add_string_(void *fdt, const char *s)
|
||||
static int fdt_add_string_(void *fdt, const char *s)
|
||||
{
|
||||
char *strtab = (char *)fdt + fdt_totalsize(fdt);
|
||||
const char *p;
|
||||
unsigned int strtabsize = fdt_size_dt_strings(fdt);
|
||||
unsigned int len = strlen(s) + 1;
|
||||
unsigned int struct_top, offset;
|
||||
|
||||
offset = strtabsize + len;
|
||||
struct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
|
||||
if (fdt_totalsize(fdt) - offset < struct_top)
|
||||
return 0; /* no more room :( */
|
||||
|
||||
memcpy(strtab - offset, s, len);
|
||||
fdt_set_size_dt_strings(fdt, strtabsize + len);
|
||||
return -offset;
|
||||
}
|
||||
|
||||
/* Must only be used to roll back in case of error */
|
||||
static void fdt_del_last_string_(void *fdt, const char *s)
|
||||
{
|
||||
int strtabsize = fdt_size_dt_strings(fdt);
|
||||
int len = strlen(s) + 1;
|
||||
int struct_top, offset;
|
||||
|
||||
fdt_set_size_dt_strings(fdt, strtabsize - len);
|
||||
}
|
||||
|
||||
static int fdt_find_add_string_(void *fdt, const char *s, int *allocated)
|
||||
{
|
||||
char *strtab = (char *)fdt + fdt_totalsize(fdt);
|
||||
int strtabsize = fdt_size_dt_strings(fdt);
|
||||
const char *p;
|
||||
|
||||
*allocated = 0;
|
||||
|
||||
p = fdt_find_string_(strtab - strtabsize, strtabsize, s);
|
||||
if (p)
|
||||
return p - strtab;
|
||||
|
||||
/* Add it */
|
||||
offset = -strtabsize - len;
|
||||
struct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
|
||||
if (fdt_totalsize(fdt) + offset < struct_top)
|
||||
return 0; /* no more room :( */
|
||||
*allocated = 1;
|
||||
|
||||
memcpy(strtab + offset, s, len);
|
||||
fdt_set_size_dt_strings(fdt, strtabsize + len);
|
||||
return offset;
|
||||
return fdt_add_string_(fdt, s);
|
||||
}
|
||||
|
||||
int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp)
|
||||
{
|
||||
struct fdt_property *prop;
|
||||
int nameoff;
|
||||
int allocated;
|
||||
|
||||
FDT_SW_PROBE_STRUCT(fdt);
|
||||
|
||||
nameoff = fdt_find_add_string_(fdt, name);
|
||||
/* String de-duplication can be slow, _NO_NAME_DEDUP skips it */
|
||||
if (sw_flags(fdt) & FDT_CREATE_FLAG_NO_NAME_DEDUP) {
|
||||
allocated = 1;
|
||||
nameoff = fdt_add_string_(fdt, name);
|
||||
} else {
|
||||
nameoff = fdt_find_add_string_(fdt, name, &allocated);
|
||||
}
|
||||
if (nameoff == 0)
|
||||
return -FDT_ERR_NOSPACE;
|
||||
|
||||
prop = fdt_grab_space_(fdt, sizeof(*prop) + FDT_TAGALIGN(len));
|
||||
if (! prop)
|
||||
if (! prop) {
|
||||
if (allocated)
|
||||
fdt_del_last_string_(fdt, name);
|
||||
return -FDT_ERR_NOSPACE;
|
||||
}
|
||||
|
||||
prop->tag = cpu_to_fdt32(FDT_PROP);
|
||||
prop->nameoff = cpu_to_fdt32(nameoff);
|
||||
|
@ -360,6 +375,10 @@ int fdt_finish(void *fdt)
|
|||
|
||||
/* Finally, adjust the header */
|
||||
fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt));
|
||||
|
||||
/* And fix up fields that were keeping intermediate state. */
|
||||
fdt_set_last_comp_version(fdt, FDT_LAST_COMPATIBLE_VERSION);
|
||||
fdt_set_magic(fdt, FDT_MAGIC);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,52 +1,7 @@
|
|||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "libfdt_env.h"
|
||||
|
||||
|
@ -68,7 +23,7 @@ int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
|
|||
if (!propval)
|
||||
return proplen;
|
||||
|
||||
if (proplen < (len + idx))
|
||||
if ((unsigned)proplen < (len + idx))
|
||||
return -FDT_ERR_NOSPACE;
|
||||
|
||||
memcpy((char *)propval + idx, val, len);
|
||||
|
|
600
libfdt/libfdt.h
600
libfdt/libfdt.h
|
@ -1,60 +1,20 @@
|
|||
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
|
||||
#ifndef LIBFDT_H
|
||||
#define LIBFDT_H
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <libfdt_env.h>
|
||||
#include <fdt.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FDT_FIRST_SUPPORTED_VERSION 0x02
|
||||
#define FDT_LAST_COMPATIBLE_VERSION 0x10
|
||||
#define FDT_LAST_SUPPORTED_VERSION 0x11
|
||||
|
||||
/* Error codes: informative error codes */
|
||||
|
@ -138,7 +98,19 @@
|
|||
/* FDT_ERR_NOPHANDLES: The device tree doesn't have any
|
||||
* phandle available anymore without causing an overflow */
|
||||
|
||||
#define FDT_ERR_MAX 17
|
||||
#define FDT_ERR_BADFLAGS 18
|
||||
/* FDT_ERR_BADFLAGS: The function was passed a flags field that
|
||||
* contains invalid flags or an invalid combination of flags. */
|
||||
|
||||
#define FDT_ERR_ALIGNMENT 19
|
||||
/* FDT_ERR_ALIGNMENT: The device tree base address is not 8-byte
|
||||
* aligned. */
|
||||
|
||||
#define FDT_ERR_MAX 19
|
||||
|
||||
/* constants */
|
||||
#define FDT_MAX_PHANDLE 0xfffffffe
|
||||
/* Valid values for phandles range from 1 to 2^32-2. */
|
||||
|
||||
/**********************************************************************/
|
||||
/* Low-level functions (you probably don't need these) */
|
||||
|
@ -155,11 +127,16 @@ static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
|
|||
uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
|
||||
|
||||
/*
|
||||
* Alignment helpers:
|
||||
* These helpers access words from a device tree blob. They're
|
||||
* built to work even with unaligned pointers on platforms (ike
|
||||
* ARM) that don't like unaligned loads and stores
|
||||
* External helpers to access words from a device tree blob. They're built
|
||||
* to work even with unaligned pointers on platforms (such as ARMv5) that don't
|
||||
* like unaligned loads and stores.
|
||||
*/
|
||||
static inline uint16_t fdt16_ld(const fdt16_t *p)
|
||||
{
|
||||
const uint8_t *bp = (const uint8_t *)p;
|
||||
|
||||
return ((uint16_t)bp[0] << 8) | bp[1];
|
||||
}
|
||||
|
||||
static inline uint32_t fdt32_ld(const fdt32_t *p)
|
||||
{
|
||||
|
@ -171,6 +148,16 @@ static inline uint32_t fdt32_ld(const fdt32_t *p)
|
|||
| bp[3];
|
||||
}
|
||||
|
||||
static inline void fdt32_st(void *property, uint32_t value)
|
||||
{
|
||||
uint8_t *bp = (uint8_t *)property;
|
||||
|
||||
bp[0] = value >> 24;
|
||||
bp[1] = (value >> 16) & 0xff;
|
||||
bp[2] = (value >> 8) & 0xff;
|
||||
bp[3] = value & 0xff;
|
||||
}
|
||||
|
||||
static inline uint64_t fdt64_ld(const fdt64_t *p)
|
||||
{
|
||||
const uint8_t *bp = (const uint8_t *)p;
|
||||
|
@ -185,6 +172,20 @@ static inline uint64_t fdt64_ld(const fdt64_t *p)
|
|||
| bp[7];
|
||||
}
|
||||
|
||||
static inline void fdt64_st(void *property, uint64_t value)
|
||||
{
|
||||
uint8_t *bp = (uint8_t *)property;
|
||||
|
||||
bp[0] = value >> 56;
|
||||
bp[1] = (value >> 48) & 0xff;
|
||||
bp[2] = (value >> 40) & 0xff;
|
||||
bp[3] = (value >> 32) & 0xff;
|
||||
bp[4] = (value >> 24) & 0xff;
|
||||
bp[5] = (value >> 16) & 0xff;
|
||||
bp[6] = (value >> 8) & 0xff;
|
||||
bp[7] = value & 0xff;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
/* Traversal functions */
|
||||
/**********************************************************************/
|
||||
|
@ -193,23 +194,23 @@ int fdt_next_node(const void *fdt, int offset, int *depth);
|
|||
|
||||
/**
|
||||
* fdt_first_subnode() - get offset of first direct subnode
|
||||
*
|
||||
* @fdt: FDT blob
|
||||
* @offset: Offset of node to check
|
||||
* @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
|
||||
*
|
||||
* Return: offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
|
||||
*/
|
||||
int fdt_first_subnode(const void *fdt, int offset);
|
||||
|
||||
/**
|
||||
* fdt_next_subnode() - get offset of next direct subnode
|
||||
* @fdt: FDT blob
|
||||
* @offset: Offset of previous subnode
|
||||
*
|
||||
* After first calling fdt_first_subnode(), call this function repeatedly to
|
||||
* get direct subnodes of a parent node.
|
||||
*
|
||||
* @fdt: FDT blob
|
||||
* @offset: Offset of previous subnode
|
||||
* @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
|
||||
* subnodes
|
||||
* Return: offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
|
||||
* subnodes
|
||||
*/
|
||||
int fdt_next_subnode(const void *fdt, int offset);
|
||||
|
||||
|
@ -234,7 +235,6 @@ int fdt_next_subnode(const void *fdt, int offset);
|
|||
* Note that this is implemented as a macro and @node is used as
|
||||
* iterator in the loop. The parent variable be constant or even a
|
||||
* literal.
|
||||
*
|
||||
*/
|
||||
#define fdt_for_each_subnode(node, fdt, parent) \
|
||||
for (node = fdt_first_subnode(fdt, parent); \
|
||||
|
@ -263,31 +263,36 @@ int fdt_next_subnode(const void *fdt, int offset);
|
|||
struct fdt_header *fdth = (struct fdt_header *)fdt; \
|
||||
fdth->name = cpu_to_fdt32(val); \
|
||||
}
|
||||
fdt_set_hdr_(magic);
|
||||
fdt_set_hdr_(totalsize);
|
||||
fdt_set_hdr_(off_dt_struct);
|
||||
fdt_set_hdr_(off_dt_strings);
|
||||
fdt_set_hdr_(off_mem_rsvmap);
|
||||
fdt_set_hdr_(version);
|
||||
fdt_set_hdr_(last_comp_version);
|
||||
fdt_set_hdr_(boot_cpuid_phys);
|
||||
fdt_set_hdr_(size_dt_strings);
|
||||
fdt_set_hdr_(size_dt_struct);
|
||||
fdt_set_hdr_(magic)
|
||||
fdt_set_hdr_(totalsize)
|
||||
fdt_set_hdr_(off_dt_struct)
|
||||
fdt_set_hdr_(off_dt_strings)
|
||||
fdt_set_hdr_(off_mem_rsvmap)
|
||||
fdt_set_hdr_(version)
|
||||
fdt_set_hdr_(last_comp_version)
|
||||
fdt_set_hdr_(boot_cpuid_phys)
|
||||
fdt_set_hdr_(size_dt_strings)
|
||||
fdt_set_hdr_(size_dt_struct)
|
||||
#undef fdt_set_hdr_
|
||||
|
||||
/**
|
||||
* fdt_header_size - return the size of the tree's header
|
||||
* @fdt: pointer to a flattened device tree
|
||||
*
|
||||
* Return: size of DTB header in bytes
|
||||
*/
|
||||
size_t fdt_header_size(const void *fdt);
|
||||
|
||||
/**
|
||||
* fdt_header_size_ - internal function to get header size from a version number
|
||||
* @version: device tree version number
|
||||
*
|
||||
* Return: size of DTB header in bytes
|
||||
*/
|
||||
size_t fdt_header_size_(uint32_t version);
|
||||
static inline size_t fdt_header_size(const void *fdt)
|
||||
{
|
||||
return fdt_header_size_(fdt_version(fdt));
|
||||
}
|
||||
|
||||
/**
|
||||
* fdt_check_header - sanity check a device tree header
|
||||
|
||||
* @fdt: pointer to data which might be a flattened device tree
|
||||
*
|
||||
* fdt_check_header() checks that the given buffer contains what
|
||||
|
@ -361,6 +366,20 @@ const char *fdt_get_string(const void *fdt, int stroffset, int *lenp);
|
|||
*/
|
||||
const char *fdt_string(const void *fdt, int stroffset);
|
||||
|
||||
/**
|
||||
* fdt_find_max_phandle - find and return the highest phandle in a tree
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @phandle: return location for the highest phandle value found in the tree
|
||||
*
|
||||
* fdt_find_max_phandle() finds the highest phandle value in the given device
|
||||
* tree. The value returned in @phandle is only valid if the function returns
|
||||
* success.
|
||||
*
|
||||
* returns:
|
||||
* 0 on success or a negative error code on failure
|
||||
*/
|
||||
int fdt_find_max_phandle(const void *fdt, uint32_t *phandle);
|
||||
|
||||
/**
|
||||
* fdt_get_max_phandle - retrieves the highest phandle in a tree
|
||||
* @fdt: pointer to the device tree blob
|
||||
|
@ -369,12 +388,38 @@ const char *fdt_string(const void *fdt, int stroffset);
|
|||
* device tree. This will ignore badly formatted phandles, or phandles
|
||||
* with a value of 0 or -1.
|
||||
*
|
||||
* This function is deprecated in favour of fdt_find_max_phandle().
|
||||
*
|
||||
* returns:
|
||||
* the highest phandle on success
|
||||
* 0, if no phandle was found in the device tree
|
||||
* -1, if an error occurred
|
||||
*/
|
||||
uint32_t fdt_get_max_phandle(const void *fdt);
|
||||
static inline uint32_t fdt_get_max_phandle(const void *fdt)
|
||||
{
|
||||
uint32_t phandle;
|
||||
int err;
|
||||
|
||||
err = fdt_find_max_phandle(fdt, &phandle);
|
||||
if (err < 0)
|
||||
return (uint32_t)-1;
|
||||
|
||||
return phandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* fdt_generate_phandle - return a new, unused phandle for a device tree blob
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @phandle: return location for the new phandle
|
||||
*
|
||||
* Walks the device tree blob and looks for the highest phandle value. On
|
||||
* success, the new, unused phandle value (one higher than the previously
|
||||
* highest phandle value in the device tree blob) will be returned in the
|
||||
* @phandle parameter.
|
||||
*
|
||||
* Return: 0 on success or a negative error-code on failure
|
||||
*/
|
||||
int fdt_generate_phandle(const void *fdt, uint32_t *phandle);
|
||||
|
||||
/**
|
||||
* fdt_num_mem_rsv - retrieve the number of memory reserve map entries
|
||||
|
@ -392,9 +437,11 @@ int fdt_num_mem_rsv(const void *fdt);
|
|||
/**
|
||||
* fdt_get_mem_rsv - retrieve one memory reserve map entry
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @address, @size: pointers to 64-bit variables
|
||||
* @n: index of reserve map entry
|
||||
* @address: pointer to 64-bit variable to hold the start address
|
||||
* @size: pointer to 64-bit variable to hold the size of the entry
|
||||
*
|
||||
* On success, *address and *size will contain the address and size of
|
||||
* On success, @address and @size will contain the address and size of
|
||||
* the n-th reserve map entry from the device tree blob, in
|
||||
* native-endian format.
|
||||
*
|
||||
|
@ -417,6 +464,8 @@ int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
|
|||
* namelen characters of name for matching the subnode name. This is
|
||||
* useful for finding subnodes based on a portion of a larger string,
|
||||
* such as a full path.
|
||||
*
|
||||
* Return: offset of the subnode or -FDT_ERR_NOTFOUND if name not found.
|
||||
*/
|
||||
#ifndef SWIG /* Not available in Python */
|
||||
int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
|
||||
|
@ -456,6 +505,8 @@ int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
|
|||
*
|
||||
* Identical to fdt_path_offset(), but only consider the first namelen
|
||||
* characters of path as the path name.
|
||||
*
|
||||
* Return: offset of the node or negative libfdt error value otherwise
|
||||
*/
|
||||
#ifndef SWIG /* Not available in Python */
|
||||
int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
|
||||
|
@ -473,12 +524,37 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
|
|||
* level matching the given component, differentiated only by unit
|
||||
* address).
|
||||
*
|
||||
* If the path is not absolute (i.e. does not begin with '/'), the
|
||||
* first component is treated as an alias. That is, the property by
|
||||
* that name is looked up in the /aliases node, and the value of that
|
||||
* property used in place of that first component.
|
||||
*
|
||||
* For example, for this small fragment
|
||||
*
|
||||
* / {
|
||||
* aliases {
|
||||
* i2c2 = &foo; // RHS compiles to "/soc@0/i2c@30a40000/eeprom@52"
|
||||
* };
|
||||
* soc@0 {
|
||||
* foo: i2c@30a40000 {
|
||||
* bar: eeprom@52 {
|
||||
* };
|
||||
* };
|
||||
* };
|
||||
* };
|
||||
*
|
||||
* these would be equivalent:
|
||||
*
|
||||
* /soc@0/i2c@30a40000/eeprom@52
|
||||
* i2c2/eeprom@52
|
||||
*
|
||||
* returns:
|
||||
* structure block offset of the node with the requested path (>=0), on
|
||||
* success
|
||||
* -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
|
||||
* -FDT_ERR_BADPATH, given path does not begin with '/' and the first
|
||||
* component is not a valid alias
|
||||
* -FDT_ERR_NOTFOUND, if the requested node does not exist
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADVERSION,
|
||||
* -FDT_ERR_BADSTATE,
|
||||
* -FDT_ERR_BADSTRUCTURE,
|
||||
|
@ -523,7 +599,7 @@ const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
|
|||
* structure block offset of the property (>=0), on success
|
||||
* -FDT_ERR_NOTFOUND, if the requested node has no properties
|
||||
* -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADVERSION,
|
||||
* -FDT_ERR_BADSTATE,
|
||||
* -FDT_ERR_BADSTRUCTURE,
|
||||
|
@ -544,7 +620,7 @@ int fdt_first_property_offset(const void *fdt, int nodeoffset);
|
|||
* structure block offset of the next property (>=0), on success
|
||||
* -FDT_ERR_NOTFOUND, if the given property is the last in its node
|
||||
* -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADVERSION,
|
||||
* -FDT_ERR_BADSTATE,
|
||||
* -FDT_ERR_BADSTRUCTURE,
|
||||
|
@ -555,9 +631,9 @@ int fdt_next_property_offset(const void *fdt, int offset);
|
|||
/**
|
||||
* fdt_for_each_property_offset - iterate over all properties of a node
|
||||
*
|
||||
* @property_offset: property offset (int, lvalue)
|
||||
* @fdt: FDT blob (const void *)
|
||||
* @node: node offset (int)
|
||||
* @property: property offset (int, lvalue)
|
||||
* @fdt: FDT blob (const void *)
|
||||
* @node: node offset (int)
|
||||
*
|
||||
* This is actually a wrapper around a for loop and would be used like so:
|
||||
*
|
||||
|
@ -609,6 +685,13 @@ int fdt_next_property_offset(const void *fdt, int offset);
|
|||
const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
|
||||
int offset,
|
||||
int *lenp);
|
||||
static inline struct fdt_property *fdt_get_property_by_offset_w(void *fdt,
|
||||
int offset,
|
||||
int *lenp)
|
||||
{
|
||||
return (struct fdt_property *)(uintptr_t)
|
||||
fdt_get_property_by_offset(fdt, offset, lenp);
|
||||
}
|
||||
|
||||
/**
|
||||
* fdt_get_property_namelen - find a property based on substring
|
||||
|
@ -620,12 +703,22 @@ const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
|
|||
*
|
||||
* Identical to fdt_get_property(), but only examine the first namelen
|
||||
* characters of name for matching the property name.
|
||||
*
|
||||
* Return: pointer to the structure representing the property, or NULL
|
||||
* if not found
|
||||
*/
|
||||
#ifndef SWIG /* Not available in Python */
|
||||
const struct fdt_property *fdt_get_property_namelen(const void *fdt,
|
||||
int nodeoffset,
|
||||
const char *name,
|
||||
int namelen, int *lenp);
|
||||
static inline struct fdt_property *
|
||||
fdt_get_property_namelen_w(void *fdt, int nodeoffset, const char *name,
|
||||
int namelen, int *lenp)
|
||||
{
|
||||
return (struct fdt_property *)(uintptr_t)fdt_get_property_namelen(
|
||||
fdt, nodeoffset, name, namelen, lenp);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -678,7 +771,7 @@ static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
|
|||
* to within the device blob itself, not a copy of the value). If
|
||||
* lenp is non-NULL, the length of the property value is also
|
||||
* returned, in the integer pointed to by lenp. If namep is non-NULL,
|
||||
* the property's namne will also be returned in the char * pointed to
|
||||
* the property's name will also be returned in the char * pointed to
|
||||
* by namep (this will be a pointer to within the device tree's string
|
||||
* block, not a new copy of the name).
|
||||
*
|
||||
|
@ -686,7 +779,7 @@ static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
|
|||
* pointer to the property's value
|
||||
* if lenp is non-NULL, *lenp contains the length of the property
|
||||
* value (>=0)
|
||||
* if namep is non-NULL *namep contiains a pointer to the property
|
||||
* if namep is non-NULL *namep contains a pointer to the property
|
||||
* name.
|
||||
* NULL, on error
|
||||
* if lenp is non-NULL, *lenp contains an error code (<0):
|
||||
|
@ -712,6 +805,8 @@ const void *fdt_getprop_by_offset(const void *fdt, int offset,
|
|||
*
|
||||
* Identical to fdt_getprop(), but only examine the first namelen
|
||||
* characters of name for matching the property name.
|
||||
*
|
||||
* Return: pointer to the property's value or NULL on error
|
||||
*/
|
||||
#ifndef SWIG /* Not available in Python */
|
||||
const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
|
||||
|
@ -733,10 +828,10 @@ static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
|
|||
* @lenp: pointer to an integer variable (will be overwritten) or NULL
|
||||
*
|
||||
* fdt_getprop() retrieves a pointer to the value of the property
|
||||
* named 'name' of the node at offset nodeoffset (this will be a
|
||||
* named @name of the node at offset @nodeoffset (this will be a
|
||||
* pointer to within the device blob itself, not a copy of the value).
|
||||
* If lenp is non-NULL, the length of the property value is also
|
||||
* returned, in the integer pointed to by lenp.
|
||||
* If @lenp is non-NULL, the length of the property value is also
|
||||
* returned, in the integer pointed to by @lenp.
|
||||
*
|
||||
* returns:
|
||||
* pointer to the property's value
|
||||
|
@ -778,11 +873,14 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
|
|||
/**
|
||||
* fdt_get_alias_namelen - get alias based on substring
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @name: name of the alias th look up
|
||||
* @name: name of the alias to look up
|
||||
* @namelen: number of characters of name to consider
|
||||
*
|
||||
* Identical to fdt_get_alias(), but only examine the first namelen
|
||||
* characters of name for matching the alias name.
|
||||
* Identical to fdt_get_alias(), but only examine the first @namelen
|
||||
* characters of @name for matching the alias name.
|
||||
*
|
||||
* Return: a pointer to the expansion of the alias named @name, if it exists,
|
||||
* NULL otherwise
|
||||
*/
|
||||
#ifndef SWIG /* Not available in Python */
|
||||
const char *fdt_get_alias_namelen(const void *fdt,
|
||||
|
@ -792,10 +890,10 @@ const char *fdt_get_alias_namelen(const void *fdt,
|
|||
/**
|
||||
* fdt_get_alias - retrieve the path referenced by a given alias
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @name: name of the alias th look up
|
||||
* @name: name of the alias to look up
|
||||
*
|
||||
* fdt_get_alias() retrieves the value of a given alias. That is, the
|
||||
* value of the property named 'name' in the node /aliases.
|
||||
* value of the property named @name in the node /aliases.
|
||||
*
|
||||
* returns:
|
||||
* a pointer to the expansion of the alias named 'name', if it exists
|
||||
|
@ -803,6 +901,42 @@ const char *fdt_get_alias_namelen(const void *fdt,
|
|||
*/
|
||||
const char *fdt_get_alias(const void *fdt, const char *name);
|
||||
|
||||
/**
|
||||
* fdt_get_symbol_namelen - get symbol based on substring
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @name: name of the symbol to look up
|
||||
* @namelen: number of characters of name to consider
|
||||
*
|
||||
* Identical to fdt_get_symbol(), but only examine the first @namelen
|
||||
* characters of @name for matching the symbol name.
|
||||
*
|
||||
* Return: a pointer to the expansion of the symbol named @name, if it exists,
|
||||
* NULL otherwise
|
||||
*/
|
||||
#ifndef SWIG /* Not available in Python */
|
||||
const char *fdt_get_symbol_namelen(const void *fdt,
|
||||
const char *name, int namelen);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* fdt_get_symbol - retrieve the path referenced by a given symbol
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @name: name of the symbol to look up
|
||||
*
|
||||
* fdt_get_symbol() retrieves the value of a given symbol. That is,
|
||||
* the value of the property named @name in the node
|
||||
* /__symbols__. Such a node exists only for a device tree blob that
|
||||
* has been compiled with the -@ dtc option. Each property corresponds
|
||||
* to a label appearing in the device tree source, with the name of
|
||||
* the property being the label and the value being the full path of
|
||||
* the node it is attached to.
|
||||
*
|
||||
* returns:
|
||||
* a pointer to the expansion of the symbol named 'name', if it exists
|
||||
* NULL, if the given symbol or the /__symbols__ node does not exist
|
||||
*/
|
||||
const char *fdt_get_symbol(const void *fdt, const char *name);
|
||||
|
||||
/**
|
||||
* fdt_get_path - determine the full path of a node
|
||||
* @fdt: pointer to the device tree blob
|
||||
|
@ -971,14 +1105,13 @@ int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
|
|||
int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
|
||||
|
||||
/**
|
||||
* fdt_node_check_compatible: check a node's compatible property
|
||||
* fdt_node_check_compatible - check a node's compatible property
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @nodeoffset: offset of a tree node
|
||||
* @compatible: string to match against
|
||||
*
|
||||
*
|
||||
* fdt_node_check_compatible() returns 0 if the given node contains a
|
||||
* 'compatible' property with the given string as one of its elements,
|
||||
* @compatible property with the given string as one of its elements,
|
||||
* it returns non-zero otherwise, or on error.
|
||||
*
|
||||
* returns:
|
||||
|
@ -1042,7 +1175,7 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
|
|||
* one or more strings, each terminated by \0, as is found in a device tree
|
||||
* "compatible" property.
|
||||
*
|
||||
* @return: 1 if the string is found in the list, 0 not found, or invalid list
|
||||
* Return: 1 if the string is found in the list, 0 not found, or invalid list
|
||||
*/
|
||||
int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
|
||||
|
||||
|
@ -1051,7 +1184,8 @@ int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
|
|||
* @fdt: pointer to the device tree blob
|
||||
* @nodeoffset: offset of a tree node
|
||||
* @property: name of the property containing the string list
|
||||
* @return:
|
||||
*
|
||||
* Return:
|
||||
* the number of strings in the given property
|
||||
* -FDT_ERR_BADVALUE if the property value is not NUL-terminated
|
||||
* -FDT_ERR_NOTFOUND if the property does not exist
|
||||
|
@ -1071,7 +1205,7 @@ int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
|
|||
* small-valued cell properties, such as #address-cells, when searching for
|
||||
* the empty string.
|
||||
*
|
||||
* @return:
|
||||
* return:
|
||||
* the index of the string in the list of strings
|
||||
* -FDT_ERR_BADVALUE if the property value is not NUL-terminated
|
||||
* -FDT_ERR_NOTFOUND if the property does not exist or does not contain
|
||||
|
@ -1095,7 +1229,7 @@ int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
|
|||
* If non-NULL, the length of the string (on success) or a negative error-code
|
||||
* (on failure) will be stored in the integer pointer to by lenp.
|
||||
*
|
||||
* @return:
|
||||
* Return:
|
||||
* A pointer to the string at the given index in the string list or NULL on
|
||||
* failure. On success the length of the string will be stored in the memory
|
||||
* location pointed to by the lenp parameter, if non-NULL. On failure one of
|
||||
|
@ -1132,8 +1266,8 @@ const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
|
|||
*
|
||||
* returns:
|
||||
* 0 <= n < FDT_MAX_NCELLS, on success
|
||||
* 2, if the node has no #address-cells property
|
||||
* -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
|
||||
* 2, if the node has no #address-cells property
|
||||
* -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
|
||||
* #address-cells property
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADVERSION,
|
||||
|
@ -1153,8 +1287,8 @@ int fdt_address_cells(const void *fdt, int nodeoffset);
|
|||
*
|
||||
* returns:
|
||||
* 0 <= n < FDT_MAX_NCELLS, on success
|
||||
* 1, if the node has no #size-cells property
|
||||
* -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
|
||||
* 1, if the node has no #size-cells property
|
||||
* -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
|
||||
* #size-cells property
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADVERSION,
|
||||
|
@ -1184,6 +1318,8 @@ int fdt_size_cells(const void *fdt, int nodeoffset);
|
|||
* starting from the given index, and using only the first characters
|
||||
* of the name. It is useful when you want to manipulate only one value of
|
||||
* an array and you have a string that doesn't end with \0.
|
||||
*
|
||||
* Return: 0 on success, negative libfdt error value otherwise
|
||||
*/
|
||||
#ifndef SWIG /* Not available in Python */
|
||||
int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
|
||||
|
@ -1297,8 +1433,13 @@ static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
|
|||
|
||||
/**
|
||||
* fdt_setprop_inplace_cell - change the value of a single-cell property
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @nodeoffset: offset of the node containing the property
|
||||
* @name: name of the property to change the value of
|
||||
* @val: new value of the 32-bit cell
|
||||
*
|
||||
* This is an alternative name for fdt_setprop_inplace_u32()
|
||||
* Return: 0 on success, negative libfdt error number otherwise.
|
||||
*/
|
||||
static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
|
||||
const char *name, uint32_t val)
|
||||
|
@ -1360,7 +1501,45 @@ int fdt_nop_node(void *fdt, int nodeoffset);
|
|||
/* Sequential write functions */
|
||||
/**********************************************************************/
|
||||
|
||||
/* fdt_create_with_flags flags */
|
||||
#define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1
|
||||
/* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property
|
||||
* names in the fdt. This can result in faster creation times, but
|
||||
* a larger fdt. */
|
||||
|
||||
#define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP)
|
||||
|
||||
/**
|
||||
* fdt_create_with_flags - begin creation of a new fdt
|
||||
* @buf: pointer to memory allocated where fdt will be created
|
||||
* @bufsize: size of the memory space at fdt
|
||||
* @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0.
|
||||
*
|
||||
* fdt_create_with_flags() begins the process of creating a new fdt with
|
||||
* the sequential write interface.
|
||||
*
|
||||
* fdt creation process must end with fdt_finish() to produce a valid fdt.
|
||||
*
|
||||
* returns:
|
||||
* 0, on success
|
||||
* -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
|
||||
* -FDT_ERR_BADFLAGS, flags is not valid
|
||||
*/
|
||||
int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags);
|
||||
|
||||
/**
|
||||
* fdt_create - begin creation of a new fdt
|
||||
* @buf: pointer to memory allocated where fdt will be created
|
||||
* @bufsize: size of the memory space at fdt
|
||||
*
|
||||
* fdt_create() is equivalent to fdt_create_with_flags() with flags=0.
|
||||
*
|
||||
* returns:
|
||||
* 0, on success
|
||||
* -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
|
||||
*/
|
||||
int fdt_create(void *buf, int bufsize);
|
||||
|
||||
int fdt_resize(void *fdt, void *buf, int bufsize);
|
||||
int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
|
||||
int fdt_finish_reservemap(void *fdt);
|
||||
|
@ -1390,7 +1569,7 @@ static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
|
|||
* @fdt: pointer to the device tree blob
|
||||
* @name: name of property to add
|
||||
* @len: length of property value in bytes
|
||||
* @valp: returns a pointer to where where the value should be placed
|
||||
* @valp: returns a pointer to where the value should be placed
|
||||
*
|
||||
* returns:
|
||||
* 0, on success
|
||||
|
@ -1415,7 +1594,8 @@ int fdt_pack(void *fdt);
|
|||
/**
|
||||
* fdt_add_mem_rsv - add one memory reserve map entry
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @address, @size: 64-bit values (native endian)
|
||||
* @address: 64-bit start address of the reserve map entry
|
||||
* @size: 64-bit size of the reserved region
|
||||
*
|
||||
* Adds a reserve map entry to the given blob reserving a region at
|
||||
* address address of length size.
|
||||
|
@ -1486,6 +1666,38 @@ int fdt_del_mem_rsv(void *fdt, int n);
|
|||
*/
|
||||
int fdt_set_name(void *fdt, int nodeoffset, const char *name);
|
||||
|
||||
/**
|
||||
* fdt_setprop_namelen - create or change a property
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @nodeoffset: offset of the node whose property to change
|
||||
* @name: name of the property to change
|
||||
* @namelen: length of the name
|
||||
* @val: pointer to data to set the property value to
|
||||
* @len: length of the property value
|
||||
*
|
||||
* fdt_setprop_namelen() sets the value of the named property in the given
|
||||
* node to the given value and length, creating the property if it
|
||||
* does not already exist.
|
||||
*
|
||||
* This function may insert or delete data from the blob, and will
|
||||
* therefore change the offsets of some existing nodes.
|
||||
*
|
||||
* returns:
|
||||
* 0, on success
|
||||
* -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
||||
* contain the new property value
|
||||
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
||||
* -FDT_ERR_BADLAYOUT,
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADVERSION,
|
||||
* -FDT_ERR_BADSTATE,
|
||||
* -FDT_ERR_BADSTRUCTURE,
|
||||
* -FDT_ERR_BADLAYOUT,
|
||||
* -FDT_ERR_TRUNCATED, standard meanings
|
||||
*/
|
||||
int fdt_setprop_namelen(void *fdt, int nodeoffset, const char *name,
|
||||
int namelen, const void *val, int len);
|
||||
|
||||
/**
|
||||
* fdt_setprop - create or change a property
|
||||
* @fdt: pointer to the device tree blob
|
||||
|
@ -1514,18 +1726,23 @@ int fdt_set_name(void *fdt, int nodeoffset, const char *name);
|
|||
* -FDT_ERR_BADLAYOUT,
|
||||
* -FDT_ERR_TRUNCATED, standard meanings
|
||||
*/
|
||||
int fdt_setprop(void *fdt, int nodeoffset, const char *name,
|
||||
const void *val, int len);
|
||||
static inline int fdt_setprop(void *fdt, int nodeoffset, const char *name,
|
||||
const void *val, int len)
|
||||
{
|
||||
return fdt_setprop_namelen(fdt, nodeoffset, name, strlen(name), val,
|
||||
len);
|
||||
}
|
||||
|
||||
/**
|
||||
* fdt_setprop_placeholder - allocate space for a property
|
||||
* fdt_setprop_placeholder_namelen - allocate space for a property
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @nodeoffset: offset of the node whose property to change
|
||||
* @name: name of the property to change
|
||||
* @namelen: length of the name
|
||||
* @len: length of the property value
|
||||
* @prop_data: return pointer to property data
|
||||
*
|
||||
* fdt_setprop_placeholer() allocates the named property in the given node.
|
||||
* fdt_setprop_placeholder_namelen() allocates the named property in the given node.
|
||||
* If the property exists it is resized. In either case a pointer to the
|
||||
* property data is returned.
|
||||
*
|
||||
|
@ -1545,8 +1762,44 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,
|
|||
* -FDT_ERR_BADLAYOUT,
|
||||
* -FDT_ERR_TRUNCATED, standard meanings
|
||||
*/
|
||||
int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
|
||||
int len, void **prop_data);
|
||||
int fdt_setprop_placeholder_namelen(void *fdt, int nodeoffset, const char *name,
|
||||
int namelen, int len, void **prop_data);
|
||||
|
||||
/**
|
||||
* fdt_setprop_placeholder - allocate space for a property
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @nodeoffset: offset of the node whose property to change
|
||||
* @name: name of the property to change
|
||||
* @len: length of the property value
|
||||
* @prop_data: return pointer to property data
|
||||
*
|
||||
* fdt_setprop_placeholder() allocates the named property in the given node.
|
||||
* If the property exists it is resized. In either case a pointer to the
|
||||
* property data is returned.
|
||||
*
|
||||
* This function may insert or delete data from the blob, and will
|
||||
* therefore change the offsets of some existing nodes.
|
||||
*
|
||||
* returns:
|
||||
* 0, on success
|
||||
* -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
||||
* contain the new property value
|
||||
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
||||
* -FDT_ERR_BADLAYOUT,
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADVERSION,
|
||||
* -FDT_ERR_BADSTATE,
|
||||
* -FDT_ERR_BADSTRUCTURE,
|
||||
* -FDT_ERR_BADLAYOUT,
|
||||
* -FDT_ERR_TRUNCATED, standard meanings
|
||||
*/
|
||||
static inline int fdt_setprop_placeholder(void *fdt, int nodeoffset,
|
||||
const char *name, int len,
|
||||
void **prop_data)
|
||||
{
|
||||
return fdt_setprop_placeholder_namelen(fdt, nodeoffset, name,
|
||||
strlen(name), len, prop_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* fdt_setprop_u32 - set a property to a 32-bit integer
|
||||
|
@ -1620,8 +1873,14 @@ static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
|
|||
|
||||
/**
|
||||
* fdt_setprop_cell - set a property to a single cell value
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @nodeoffset: offset of the node whose property to change
|
||||
* @name: name of the property to change
|
||||
* @val: 32-bit integer value for the property (native endian)
|
||||
*
|
||||
* This is an alternative name for fdt_setprop_u32()
|
||||
*
|
||||
* Return: 0 on success, negative libfdt error value otherwise.
|
||||
*/
|
||||
static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
|
||||
uint32_t val)
|
||||
|
@ -1660,6 +1919,38 @@ static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
|
|||
#define fdt_setprop_string(fdt, nodeoffset, name, str) \
|
||||
fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
|
||||
|
||||
/**
|
||||
* fdt_setprop_namelen_string - set a property to a string value
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @nodeoffset: offset of the node whose property to change
|
||||
* @name: name of the property to change
|
||||
* @namelen: number of characters of name to consider
|
||||
* @str: string value for the property
|
||||
*
|
||||
* fdt_setprop_namelen_string() sets the value of the named property in the
|
||||
* given node to the given string value (using the length of the
|
||||
* string to determine the new length of the property), or creates a
|
||||
* new property with that value if it does not already exist.
|
||||
*
|
||||
* This function may insert or delete data from the blob, and will
|
||||
* therefore change the offsets of some existing nodes.
|
||||
*
|
||||
* returns:
|
||||
* 0, on success
|
||||
* -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
||||
* contain the new property value
|
||||
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
||||
* -FDT_ERR_BADLAYOUT,
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADVERSION,
|
||||
* -FDT_ERR_BADSTATE,
|
||||
* -FDT_ERR_BADSTRUCTURE,
|
||||
* -FDT_ERR_BADLAYOUT,
|
||||
* -FDT_ERR_TRUNCATED, standard meanings
|
||||
*/
|
||||
#define fdt_setprop_namelen_string(fdt, nodeoffset, name, namelen, str) \
|
||||
fdt_setprop_namelen((fdt), (nodeoffset), (name), (namelen), (str), \
|
||||
strlen(str) + 1)
|
||||
|
||||
/**
|
||||
* fdt_setprop_empty - set a property to an empty value
|
||||
|
@ -1792,8 +2083,14 @@ static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
|
|||
|
||||
/**
|
||||
* fdt_appendprop_cell - append a single cell value to a property
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @nodeoffset: offset of the node whose property to change
|
||||
* @name: name of the property to change
|
||||
* @val: 32-bit integer value to append to the property (native endian)
|
||||
*
|
||||
* This is an alternative name for fdt_appendprop_u32()
|
||||
*
|
||||
* Return: 0 on success, negative libfdt error value otherwise.
|
||||
*/
|
||||
static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
|
||||
const char *name, uint32_t val)
|
||||
|
@ -1831,13 +2128,50 @@ static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
|
|||
#define fdt_appendprop_string(fdt, nodeoffset, name, str) \
|
||||
fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
|
||||
|
||||
/**
|
||||
* fdt_appendprop_addrrange - append a address range property
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @parent: offset of the parent node
|
||||
* @nodeoffset: offset of the node to add a property at
|
||||
* @name: name of property
|
||||
* @addr: start address of a given range
|
||||
* @size: size of a given range
|
||||
*
|
||||
* fdt_appendprop_addrrange() appends an address range value (start
|
||||
* address and size) to the value of the named property in the given
|
||||
* node, or creates a new property with that value if it does not
|
||||
* already exist.
|
||||
*
|
||||
* Cell sizes are determined by parent's #address-cells and #size-cells.
|
||||
*
|
||||
* This function may insert data into the blob, and will therefore
|
||||
* change the offsets of some existing nodes.
|
||||
*
|
||||
* returns:
|
||||
* 0, on success
|
||||
* -FDT_ERR_BADLAYOUT,
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
|
||||
* #address-cells property
|
||||
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
||||
* -FDT_ERR_BADSTATE,
|
||||
* -FDT_ERR_BADSTRUCTURE,
|
||||
* -FDT_ERR_BADVERSION,
|
||||
* -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size
|
||||
* -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
||||
* contain a new property
|
||||
* -FDT_ERR_TRUNCATED, standard meanings
|
||||
*/
|
||||
int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
|
||||
const char *name, uint64_t addr, uint64_t size);
|
||||
|
||||
/**
|
||||
* fdt_delprop - delete a property
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @nodeoffset: offset of the node whose property to nop
|
||||
* @name: name of the property to nop
|
||||
*
|
||||
* fdt_del_property() will delete the given property.
|
||||
* fdt_delprop() will delete the given property.
|
||||
*
|
||||
* This function will delete data from the blob, and will therefore
|
||||
* change the offsets of some existing nodes.
|
||||
|
@ -1859,13 +2193,16 @@ int fdt_delprop(void *fdt, int nodeoffset, const char *name);
|
|||
* fdt_add_subnode_namelen - creates a new node based on substring
|
||||
* @fdt: pointer to the device tree blob
|
||||
* @parentoffset: structure block offset of a node
|
||||
* @name: name of the subnode to locate
|
||||
* @name: name of the subnode to create
|
||||
* @namelen: number of characters of name to consider
|
||||
*
|
||||
* Identical to fdt_add_subnode(), but use only the first namelen
|
||||
* characters of name as the name of the new node. This is useful for
|
||||
* Identical to fdt_add_subnode(), but use only the first @namelen
|
||||
* characters of @name as the name of the new node. This is useful for
|
||||
* creating subnodes based on a portion of a larger string, such as a
|
||||
* full path.
|
||||
*
|
||||
* Return: structure block offset of the created subnode (>=0),
|
||||
* negative libfdt error value otherwise
|
||||
*/
|
||||
#ifndef SWIG /* Not available in Python */
|
||||
int fdt_add_subnode_namelen(void *fdt, int parentoffset,
|
||||
|
@ -1884,10 +2221,9 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
|
|||
*
|
||||
* This function will insert data into the blob, and will therefore
|
||||
* change the offsets of some existing nodes.
|
||||
|
||||
*
|
||||
* returns:
|
||||
* structure block offset of the created nodeequested subnode (>=0), on
|
||||
* success
|
||||
* structure block offset of the created subnode (>=0), on success
|
||||
* -FDT_ERR_NOTFOUND, if the requested subnode does not exist
|
||||
* -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
|
||||
* tag
|
||||
|
@ -1897,7 +2233,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
|
|||
* blob to contain the new node
|
||||
* -FDT_ERR_NOSPACE
|
||||
* -FDT_ERR_BADLAYOUT
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADVERSION,
|
||||
* -FDT_ERR_BADSTATE,
|
||||
* -FDT_ERR_BADSTRUCTURE,
|
||||
|
@ -1942,7 +2278,7 @@ int fdt_del_node(void *fdt, int nodeoffset);
|
|||
* returns:
|
||||
* 0, on success
|
||||
* -FDT_ERR_NOSPACE, there's not enough space in the base device tree
|
||||
* -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
|
||||
* -FDT_ERR_NOTFOUND, the overlay points to some nonexistent nodes or
|
||||
* properties in the base DT
|
||||
* -FDT_ERR_BADPHANDLE,
|
||||
* -FDT_ERR_BADOVERLAY,
|
||||
|
@ -1959,10 +2295,32 @@ int fdt_del_node(void *fdt, int nodeoffset);
|
|||
*/
|
||||
int fdt_overlay_apply(void *fdt, void *fdto);
|
||||
|
||||
/**
|
||||
* fdt_overlay_target_offset - retrieves the offset of a fragment's target
|
||||
* @fdt: Base device tree blob
|
||||
* @fdto: Device tree overlay blob
|
||||
* @fragment_offset: node offset of the fragment in the overlay
|
||||
* @pathp: pointer which receives the path of the target (or NULL)
|
||||
*
|
||||
* fdt_overlay_target_offset() retrieves the target offset in the base
|
||||
* device tree of a fragment, no matter how the actual targeting is
|
||||
* done (through a phandle or a path)
|
||||
*
|
||||
* returns:
|
||||
* the targeted node offset in the base device tree
|
||||
* Negative error code on error
|
||||
*/
|
||||
int fdt_overlay_target_offset(const void *fdt, const void *fdto,
|
||||
int fragment_offset, char const **pathp);
|
||||
|
||||
/**********************************************************************/
|
||||
/* Debugging / informational functions */
|
||||
/**********************************************************************/
|
||||
|
||||
const char *fdt_strerror(int errval);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LIBFDT_H */
|
||||
|
|
|
@ -1,57 +1,13 @@
|
|||
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
|
||||
#ifndef LIBFDT_ENV_H
|
||||
#define LIBFDT_ENV_H
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
* Copyright 2012 Kim Phillips, Freescale Semiconductor.
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -1,71 +1,35 @@
|
|||
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
|
||||
#ifndef LIBFDT_INTERNAL_H
|
||||
#define LIBFDT_INTERNAL_H
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <fdt.h>
|
||||
#include <string.h>
|
||||
|
||||
#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
|
||||
#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE))
|
||||
|
||||
int fdt_ro_probe_(const void *fdt);
|
||||
#define FDT_RO_PROBE(fdt) \
|
||||
{ \
|
||||
int err_; \
|
||||
if ((err_ = fdt_ro_probe_(fdt)) != 0) \
|
||||
return err_; \
|
||||
int32_t fdt_ro_probe_(const void *fdt);
|
||||
#define FDT_RO_PROBE(fdt) \
|
||||
{ \
|
||||
int32_t totalsize_; \
|
||||
if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \
|
||||
return totalsize_; \
|
||||
}
|
||||
|
||||
int fdt_check_node_offset_(const void *fdt, int offset);
|
||||
int fdt_check_prop_offset_(const void *fdt, int offset);
|
||||
const char *fdt_find_string_(const char *strtab, int tabsize, const char *s);
|
||||
|
||||
const char *fdt_find_string_len_(const char *strtab, int tabsize, const char *s,
|
||||
int s_len);
|
||||
static inline const char *fdt_find_string_(const char *strtab, int tabsize,
|
||||
const char *s)
|
||||
{
|
||||
return fdt_find_string_len_(strtab, tabsize, s, strlen(s));
|
||||
}
|
||||
|
||||
int fdt_node_end_offset_(void *fdt, int nodeoffset);
|
||||
|
||||
static inline const void *fdt_offset_ptr_(const void *fdt, int offset)
|
||||
|
@ -91,6 +55,147 @@ static inline struct fdt_reserve_entry *fdt_mem_rsv_w_(void *fdt, int n)
|
|||
return (void *)(uintptr_t)fdt_mem_rsv_(fdt, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* Internal helpers to access structural elements of the device tree
|
||||
* blob (rather than for example reading integers from within property
|
||||
* values). We assume that we are either given a naturally aligned
|
||||
* address for the platform or if we are not, we are on a platform
|
||||
* where unaligned memory reads will be handled in a graceful manner.
|
||||
* If not the external helpers fdtXX_ld() from libfdt.h can be used
|
||||
* instead.
|
||||
*/
|
||||
static inline uint32_t fdt32_ld_(const fdt32_t *p)
|
||||
{
|
||||
return fdt32_to_cpu(*p);
|
||||
}
|
||||
|
||||
static inline uint64_t fdt64_ld_(const fdt64_t *p)
|
||||
{
|
||||
return fdt64_to_cpu(*p);
|
||||
}
|
||||
|
||||
#define FDT_SW_MAGIC (~FDT_MAGIC)
|
||||
|
||||
/**********************************************************************/
|
||||
/* Checking controls */
|
||||
/**********************************************************************/
|
||||
|
||||
#ifndef FDT_ASSUME_MASK
|
||||
#define FDT_ASSUME_MASK 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Defines assumptions which can be enabled. Each of these can be enabled
|
||||
* individually. For maximum safety, don't enable any assumptions!
|
||||
*
|
||||
* For minimal code size and no safety, use ASSUME_PERFECT at your own risk.
|
||||
* You should have another method of validating the device tree, such as a
|
||||
* signature or hash check before using libfdt.
|
||||
*
|
||||
* For situations where security is not a concern it may be safe to enable
|
||||
* ASSUME_SANE.
|
||||
*/
|
||||
enum {
|
||||
/*
|
||||
* This does essentially no checks. Only the latest device-tree
|
||||
* version is correctly handled. Inconsistencies or errors in the device
|
||||
* tree may cause undefined behaviour or crashes. Invalid parameters
|
||||
* passed to libfdt may do the same.
|
||||
*
|
||||
* If an error occurs when modifying the tree it may leave the tree in
|
||||
* an intermediate (but valid) state. As an example, adding a property
|
||||
* where there is insufficient space may result in the property name
|
||||
* being added to the string table even though the property itself is
|
||||
* not added to the struct section.
|
||||
*
|
||||
* Only use this if you have a fully validated device tree with
|
||||
* the latest supported version and wish to minimise code size.
|
||||
*/
|
||||
ASSUME_PERFECT = 0xff,
|
||||
|
||||
/*
|
||||
* This assumes that the device tree is sane. i.e. header metadata
|
||||
* and basic hierarchy are correct.
|
||||
*
|
||||
* With this assumption enabled, normal device trees produced by libfdt
|
||||
* and the compiler should be handled safely. Malicious device trees and
|
||||
* complete garbage may cause libfdt to behave badly or crash. Truncated
|
||||
* device trees (e.g. those only partially loaded) can also cause
|
||||
* problems.
|
||||
*
|
||||
* Note: Only checks that relate exclusively to the device tree itself
|
||||
* (not the parameters passed to libfdt) are disabled by this
|
||||
* assumption. This includes checking headers, tags and the like.
|
||||
*/
|
||||
ASSUME_VALID_DTB = 1 << 0,
|
||||
|
||||
/*
|
||||
* This builds on ASSUME_VALID_DTB and further assumes that libfdt
|
||||
* functions are called with valid parameters, i.e. not trigger
|
||||
* FDT_ERR_BADOFFSET or offsets that are out of bounds. It disables any
|
||||
* extensive checking of parameters and the device tree, making various
|
||||
* assumptions about correctness.
|
||||
*
|
||||
* It doesn't make sense to enable this assumption unless
|
||||
* ASSUME_VALID_DTB is also enabled.
|
||||
*/
|
||||
ASSUME_VALID_INPUT = 1 << 1,
|
||||
|
||||
/*
|
||||
* This disables checks for device-tree version and removes all code
|
||||
* which handles older versions.
|
||||
*
|
||||
* Only enable this if you know you have a device tree with the latest
|
||||
* version.
|
||||
*/
|
||||
ASSUME_LATEST = 1 << 2,
|
||||
|
||||
/*
|
||||
* This assumes that it is OK for a failed addition to the device tree,
|
||||
* due to lack of space or some other problem, to skip any rollback
|
||||
* steps (such as dropping the property name from the string table).
|
||||
* This is safe to enable in most circumstances, even though it may
|
||||
* leave the tree in a sub-optimal state.
|
||||
*/
|
||||
ASSUME_NO_ROLLBACK = 1 << 3,
|
||||
|
||||
/*
|
||||
* This assumes that the device tree components appear in a 'convenient'
|
||||
* order, i.e. the memory reservation block first, then the structure
|
||||
* block and finally the string block.
|
||||
*
|
||||
* This order is not specified by the device-tree specification,
|
||||
* but is expected by libfdt. The device-tree compiler always created
|
||||
* device trees with this order.
|
||||
*
|
||||
* This assumption disables a check in fdt_open_into() and removes the
|
||||
* ability to fix the problem there. This is safe if you know that the
|
||||
* device tree is correctly ordered. See fdt_blocks_misordered_().
|
||||
*/
|
||||
ASSUME_LIBFDT_ORDER = 1 << 4,
|
||||
|
||||
/*
|
||||
* This assumes that libfdt itself does not have any internal bugs. It
|
||||
* drops certain checks that should never be needed unless libfdt has an
|
||||
* undiscovered bug.
|
||||
*
|
||||
* This can generally be considered safe to enable.
|
||||
*/
|
||||
ASSUME_LIBFDT_FLAWLESS = 1 << 5,
|
||||
};
|
||||
|
||||
/**
|
||||
* can_assume_() - check if a particular assumption is enabled
|
||||
*
|
||||
* @mask: Mask to check (ASSUME_...)
|
||||
* @return true if that assumption is enabled, else false
|
||||
*/
|
||||
static inline bool can_assume_(int mask)
|
||||
{
|
||||
return FDT_ASSUME_MASK & mask;
|
||||
}
|
||||
|
||||
/** helper macros for checking assumptions */
|
||||
#define can_assume(_assume) can_assume_(ASSUME_ ## _assume)
|
||||
|
||||
#endif /* LIBFDT_INTERNAL_H */
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
version_script = '-Wl,--version-script=@0@'.format(meson.current_source_dir() / 'version.lds')
|
||||
if not cc.has_link_argument(version_script)
|
||||
version_script = []
|
||||
endif
|
||||
|
||||
sources = files(
|
||||
'fdt.c',
|
||||
'fdt_addresses.c',
|
||||
'fdt_check.c',
|
||||
'fdt_empty_tree.c',
|
||||
'fdt_overlay.c',
|
||||
'fdt_ro.c',
|
||||
'fdt_rw.c',
|
||||
'fdt_strerror.c',
|
||||
'fdt_sw.c',
|
||||
'fdt_wip.c',
|
||||
)
|
||||
|
||||
link_args = []
|
||||
if cc.has_link_argument('-Wl,--no-undefined')
|
||||
link_args += '-Wl,--no-undefined'
|
||||
else
|
||||
# -undefined error is the equivalent of --no-undefined for the macOS linker,
|
||||
# but -undefined would also be understood as a valid argument for GNU ld!
|
||||
link_args += cc.get_supported_link_arguments('-Wl,-undefined,error')
|
||||
endif
|
||||
|
||||
link_args += version_script
|
||||
libfdt = library(
|
||||
'fdt', sources,
|
||||
version: meson.project_version(),
|
||||
link_args: link_args,
|
||||
link_depends: 'version.lds',
|
||||
install: get_option('default_library') != 'static' or not wheel_only,
|
||||
)
|
||||
|
||||
libfdt_inc = include_directories('.')
|
||||
|
||||
libfdt_dep = declare_dependency(
|
||||
include_directories: libfdt_inc,
|
||||
link_with: libfdt,
|
||||
)
|
||||
meson.override_dependency('libfdt', libfdt_dep)
|
||||
|
||||
if not wheel_only
|
||||
install_headers(
|
||||
files(
|
||||
'fdt.h',
|
||||
'libfdt.h',
|
||||
'libfdt_env.h',
|
||||
)
|
||||
)
|
||||
|
||||
pkgconfig = import('pkgconfig')
|
||||
|
||||
pkgconfig.generate(
|
||||
libraries: libfdt,
|
||||
version: meson.project_version(),
|
||||
filebase: 'libfdt',
|
||||
name: 'libfdt',
|
||||
description: 'Flat Device Tree manipulation',
|
||||
)
|
||||
endif
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"bomFormat": "CycloneDX",
|
||||
"specVersion": "1.6",
|
||||
"version": 1,
|
||||
"metadata": {
|
||||
"authors": [
|
||||
{
|
||||
"name": "@VCS_SBOM_AUTHORS@"
|
||||
}
|
||||
]
|
||||
},
|
||||
"components": [
|
||||
{
|
||||
"type": "library",
|
||||
"bom-ref": "pkg:github/dgibson/libfdt@@VCS_TAG@",
|
||||
"cpe": "cpe:2.3:a:dgibson:libfdt:@VCS_TAG@:*:*:*:*:*:*:*",
|
||||
"name": "libfdt",
|
||||
"version": "@VCS_VERSION@",
|
||||
"description": "Utility library for reading and manipulating the FDT binary format",
|
||||
"supplier": {
|
||||
"name": "libfdt developers"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"license": {
|
||||
"id": "BSD-2-Clause"
|
||||
}
|
||||
},
|
||||
{
|
||||
"license": {
|
||||
"id": "GPL-2.0-or-later"
|
||||
}
|
||||
}
|
||||
],
|
||||
"externalReferences": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/dgibson/dtc"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
|
||||
LIBFDT_1.2 {
|
||||
global:
|
||||
fdt_next_node;
|
||||
|
@ -19,6 +20,7 @@ LIBFDT_1.2 {
|
|||
fdt_get_alias_namelen;
|
||||
fdt_get_alias;
|
||||
fdt_get_path;
|
||||
fdt_header_size;
|
||||
fdt_supernode_atdepth_offset;
|
||||
fdt_node_depth;
|
||||
fdt_parent_offset;
|
||||
|
@ -41,6 +43,7 @@ LIBFDT_1.2 {
|
|||
fdt_add_mem_rsv;
|
||||
fdt_del_mem_rsv;
|
||||
fdt_set_name;
|
||||
fdt_setprop_namelen;
|
||||
fdt_setprop;
|
||||
fdt_delprop;
|
||||
fdt_add_subnode_namelen;
|
||||
|
@ -66,6 +69,19 @@ LIBFDT_1.2 {
|
|||
fdt_resize;
|
||||
fdt_overlay_apply;
|
||||
fdt_get_string;
|
||||
fdt_find_max_phandle;
|
||||
fdt_generate_phandle;
|
||||
fdt_check_full;
|
||||
fdt_setprop_placeholder_namelen;
|
||||
fdt_setprop_placeholder;
|
||||
fdt_property_placeholder;
|
||||
fdt_header_size_;
|
||||
fdt_appendprop_addrrange;
|
||||
fdt_setprop_inplace_namelen_partial;
|
||||
fdt_create_with_flags;
|
||||
fdt_overlay_target_offset;
|
||||
fdt_get_symbol;
|
||||
fdt_get_symbol_namelen;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
|
166
livetree.c
166
livetree.c
|
@ -1,21 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "dtc.h"
|
||||
|
@ -51,27 +36,27 @@ void delete_labels(struct label **labels)
|
|||
label->deleted = 1;
|
||||
}
|
||||
|
||||
struct property *build_property(char *name, struct data val,
|
||||
struct property *build_property(const char *name, struct data val,
|
||||
struct srcpos *srcpos)
|
||||
{
|
||||
struct property *new = xmalloc(sizeof(*new));
|
||||
|
||||
memset(new, 0, sizeof(*new));
|
||||
|
||||
new->name = name;
|
||||
new->name = xstrdup(name);
|
||||
new->val = val;
|
||||
new->srcpos = srcpos_copy(srcpos);
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
struct property *build_property_delete(char *name)
|
||||
struct property *build_property_delete(const char *name)
|
||||
{
|
||||
struct property *new = xmalloc(sizeof(*new));
|
||||
|
||||
memset(new, 0, sizeof(*new));
|
||||
|
||||
new->name = name;
|
||||
new->name = xstrdup(name);
|
||||
new->deleted = 1;
|
||||
|
||||
return new;
|
||||
|
@ -131,11 +116,11 @@ struct node *build_node_delete(struct srcpos *srcpos)
|
|||
return new;
|
||||
}
|
||||
|
||||
struct node *name_node(struct node *node, char *name)
|
||||
struct node *name_node(struct node *node, const char *name)
|
||||
{
|
||||
assert(node->name == NULL);
|
||||
|
||||
node->name = name;
|
||||
node->name = xstrdup(name);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
@ -189,7 +174,7 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
|
|||
|
||||
old_prop->val = new_prop->val;
|
||||
old_prop->deleted = 0;
|
||||
free(old_prop->srcpos);
|
||||
srcpos_free(old_prop->srcpos);
|
||||
old_prop->srcpos = new_prop->srcpos;
|
||||
free(new_prop);
|
||||
new_prop = NULL;
|
||||
|
@ -249,6 +234,7 @@ struct node * add_orphan_node(struct node *dt, struct node *new_node, char *ref)
|
|||
char *name;
|
||||
|
||||
if (ref[0] == '/') {
|
||||
d = data_add_marker(d, TYPE_STRING, ref);
|
||||
d = data_append_data(d, ref, strlen(ref) + 1);
|
||||
|
||||
p = build_property("target-path", d, NULL);
|
||||
|
@ -264,6 +250,7 @@ struct node * add_orphan_node(struct node *dt, struct node *new_node, char *ref)
|
|||
name_node(new_node, "__overlay__");
|
||||
node = build_node(p, new_node, NULL);
|
||||
name_node(node, name);
|
||||
free(name);
|
||||
|
||||
add_child(dt, node);
|
||||
return dt;
|
||||
|
@ -350,17 +337,20 @@ void delete_node(struct node *node)
|
|||
}
|
||||
|
||||
void append_to_property(struct node *node,
|
||||
char *name, const void *data, int len)
|
||||
char *name, const void *data, int len,
|
||||
enum markertype type)
|
||||
{
|
||||
struct data d;
|
||||
struct property *p;
|
||||
|
||||
p = get_property(node, name);
|
||||
if (p) {
|
||||
d = data_append_data(p->val, data, len);
|
||||
d = data_add_marker(p->val, type, name);
|
||||
d = data_append_data(d, data, len);
|
||||
p->val = d;
|
||||
} else {
|
||||
d = data_append_data(empty_data, data, len);
|
||||
d = data_add_marker(empty_data, type, name);
|
||||
d = data_append_data(d, data, len);
|
||||
p = build_property(name, d, NULL);
|
||||
add_property(node, p);
|
||||
}
|
||||
|
@ -449,9 +439,9 @@ cell_t propval_cell(struct property *prop)
|
|||
return fdt32_to_cpu(*((fdt32_t *)prop->val.val));
|
||||
}
|
||||
|
||||
cell_t propval_cell_n(struct property *prop, int n)
|
||||
cell_t propval_cell_n(struct property *prop, unsigned int n)
|
||||
{
|
||||
assert(prop->val.len / sizeof(cell_t) >= n);
|
||||
assert(prop->val.len / sizeof(cell_t) > n);
|
||||
return fdt32_to_cpu(*((fdt32_t *)prop->val.val + n));
|
||||
}
|
||||
|
||||
|
@ -514,7 +504,7 @@ struct node *get_subnode(struct node *node, const char *nodename)
|
|||
struct node *child;
|
||||
|
||||
for_each_child(node, child)
|
||||
if (streq(child->name, nodename))
|
||||
if (streq(child->name, nodename) && !child->deleted)
|
||||
return child;
|
||||
|
||||
return NULL;
|
||||
|
@ -537,8 +527,7 @@ struct node *get_node_by_path(struct node *tree, const char *path)
|
|||
p = strchr(path, '/');
|
||||
|
||||
for_each_child(tree, child) {
|
||||
if (p && (strlen(child->name) == p-path) &&
|
||||
strprefixeq(path, p - path, child->name))
|
||||
if (p && strprefixeq(path, (size_t)(p - path), child->name))
|
||||
return get_node_by_path(child, p+1);
|
||||
else if (!p && streq(path, child->name))
|
||||
return child;
|
||||
|
@ -571,7 +560,7 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
|
|||
{
|
||||
struct node *child, *node;
|
||||
|
||||
if ((phandle == 0) || (phandle == -1)) {
|
||||
if (!phandle_is_valid(phandle)) {
|
||||
assert(generate_fixups);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -593,20 +582,62 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
|
|||
|
||||
struct node *get_node_by_ref(struct node *tree, const char *ref)
|
||||
{
|
||||
struct node *target = tree;
|
||||
const char *label = NULL, *path = NULL;
|
||||
|
||||
if (streq(ref, "/"))
|
||||
return tree;
|
||||
else if (ref[0] == '/')
|
||||
return get_node_by_path(tree, ref);
|
||||
|
||||
if (ref[0] == '/')
|
||||
path = ref;
|
||||
else
|
||||
return get_node_by_label(tree, ref);
|
||||
label = ref;
|
||||
|
||||
if (label) {
|
||||
const char *slash = strchr(label, '/');
|
||||
char *buf = NULL;
|
||||
|
||||
if (slash) {
|
||||
buf = xstrndup(label, slash - label);
|
||||
label = buf;
|
||||
path = slash + 1;
|
||||
}
|
||||
|
||||
target = get_node_by_label(tree, label);
|
||||
|
||||
free(buf);
|
||||
|
||||
if (!target)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (path)
|
||||
target = get_node_by_path(target, path);
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
static void add_phandle_property(struct node *node,
|
||||
const char *name, int format)
|
||||
{
|
||||
struct data d;
|
||||
|
||||
if (!(phandle_format & format))
|
||||
return;
|
||||
if (get_property(node, name))
|
||||
return;
|
||||
|
||||
d = data_add_marker(empty_data, TYPE_UINT32, NULL);
|
||||
d = data_append_cell(d, node->phandle);
|
||||
|
||||
add_property(node, build_property(name, d, NULL));
|
||||
}
|
||||
|
||||
cell_t get_node_phandle(struct node *root, struct node *node)
|
||||
{
|
||||
static cell_t phandle = 1; /* FIXME: ick, static local */
|
||||
struct data d = empty_data;
|
||||
|
||||
if ((node->phandle != 0) && (node->phandle != -1))
|
||||
if (phandle_is_valid(node->phandle))
|
||||
return node->phandle;
|
||||
|
||||
while (get_node_by_phandle(root, phandle))
|
||||
|
@ -614,16 +645,8 @@ cell_t get_node_phandle(struct node *root, struct node *node)
|
|||
|
||||
node->phandle = phandle;
|
||||
|
||||
d = data_add_marker(d, TYPE_UINT32, NULL);
|
||||
d = data_append_cell(d, phandle);
|
||||
|
||||
if (!get_property(node, "linux,phandle")
|
||||
&& (phandle_format & PHANDLE_LEGACY))
|
||||
add_property(node, build_property("linux,phandle", d, NULL));
|
||||
|
||||
if (!get_property(node, "phandle")
|
||||
&& (phandle_format & PHANDLE_EPAPR))
|
||||
add_property(node, build_property("phandle", d, NULL));
|
||||
add_phandle_property(node, "linux,phandle", PHANDLE_LEGACY);
|
||||
add_phandle_property(node, "phandle", PHANDLE_EPAPR);
|
||||
|
||||
/* If the node *does* have a phandle property, we must
|
||||
* be dealing with a self-referencing phandle, which will be
|
||||
|
@ -793,18 +816,18 @@ void sort_tree(struct dt_info *dti)
|
|||
}
|
||||
|
||||
/* utility helper to avoid code duplication */
|
||||
static struct node *build_and_name_child_node(struct node *parent, char *name)
|
||||
static struct node *build_and_name_child_node(struct node *parent, const char *name)
|
||||
{
|
||||
struct node *node;
|
||||
|
||||
node = build_node(NULL, NULL, NULL);
|
||||
name_node(node, xstrdup(name));
|
||||
name_node(node, name);
|
||||
add_child(parent, node);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static struct node *build_root_node(struct node *dt, char *name)
|
||||
static struct node *build_root_node(struct node *dt, const char *name)
|
||||
{
|
||||
struct node *an;
|
||||
|
||||
|
@ -858,8 +881,8 @@ static void generate_label_tree_internal(struct dt_info *dti,
|
|||
|
||||
/* insert it */
|
||||
p = build_property(l->label,
|
||||
data_copy_mem(node->fullpath,
|
||||
strlen(node->fullpath) + 1),
|
||||
data_copy_escape_string(node->fullpath,
|
||||
strlen(node->fullpath)),
|
||||
NULL);
|
||||
add_property(an, p);
|
||||
}
|
||||
|
@ -904,13 +927,19 @@ static void add_fixup_entry(struct dt_info *dti, struct node *fn,
|
|||
/* m->ref can only be a REF_PHANDLE, but check anyway */
|
||||
assert(m->type == REF_PHANDLE);
|
||||
|
||||
/* The format only permits fixups for references to label, not
|
||||
* references to path */
|
||||
if (strchr(m->ref, '/'))
|
||||
die("Can't generate fixup for reference to path &{%s}\n",
|
||||
m->ref);
|
||||
|
||||
/* there shouldn't be any ':' in the arguments */
|
||||
if (strchr(node->fullpath, ':') || strchr(prop->name, ':'))
|
||||
die("arguments should not contain ':'\n");
|
||||
|
||||
xasprintf(&entry, "%s:%s:%u",
|
||||
node->fullpath, prop->name, m->offset);
|
||||
append_to_property(fn, m->ref, entry, strlen(entry) + 1);
|
||||
append_to_property(fn, m->ref, entry, strlen(entry) + 1, TYPE_STRING);
|
||||
|
||||
free(entry);
|
||||
}
|
||||
|
@ -970,7 +999,7 @@ static void add_local_fixup_entry(struct dt_info *dti,
|
|||
char **compp;
|
||||
int i, depth;
|
||||
|
||||
/* walk back retreiving depth */
|
||||
/* walk back retrieving depth */
|
||||
depth = 0;
|
||||
for (wn = node; wn; wn = wn->parent)
|
||||
depth++;
|
||||
|
@ -985,15 +1014,13 @@ static void add_local_fixup_entry(struct dt_info *dti,
|
|||
/* walk the path components creating nodes if they don't exist */
|
||||
for (wn = lfn, i = 1; i < depth; i++, wn = nwn) {
|
||||
/* if no node exists, create it */
|
||||
nwn = get_subnode(wn, compp[i]);
|
||||
if (!nwn)
|
||||
nwn = build_and_name_child_node(wn, compp[i]);
|
||||
nwn = build_root_node(wn, compp[i]);
|
||||
}
|
||||
|
||||
free(compp);
|
||||
|
||||
value_32 = cpu_to_fdt32(m->offset);
|
||||
append_to_property(wn, prop->name, &value_32, sizeof(value_32));
|
||||
append_to_property(wn, prop->name, &value_32, sizeof(value_32), TYPE_UINT32);
|
||||
}
|
||||
|
||||
static void generate_local_fixups_tree_internal(struct dt_info *dti,
|
||||
|
@ -1019,7 +1046,7 @@ static void generate_local_fixups_tree_internal(struct dt_info *dti,
|
|||
generate_local_fixups_tree_internal(dti, lfn, c);
|
||||
}
|
||||
|
||||
void generate_label_tree(struct dt_info *dti, char *name, bool allocph)
|
||||
void generate_label_tree(struct dt_info *dti, const char *name, bool allocph)
|
||||
{
|
||||
if (!any_label_tree(dti, dti->dt))
|
||||
return;
|
||||
|
@ -1027,18 +1054,31 @@ void generate_label_tree(struct dt_info *dti, char *name, bool allocph)
|
|||
dti->dt, allocph);
|
||||
}
|
||||
|
||||
void generate_fixups_tree(struct dt_info *dti, char *name)
|
||||
void generate_fixups_tree(struct dt_info *dti, const char *name)
|
||||
{
|
||||
struct node *n = get_subnode(dti->dt, name);
|
||||
|
||||
/* Start with an empty __fixups__ node to not get duplicates */
|
||||
if (n)
|
||||
n->deleted = true;
|
||||
|
||||
if (!any_fixup_tree(dti, dti->dt))
|
||||
return;
|
||||
generate_fixups_tree_internal(dti, build_root_node(dti->dt, name),
|
||||
generate_fixups_tree_internal(dti,
|
||||
build_and_name_child_node(dti->dt, name),
|
||||
dti->dt);
|
||||
}
|
||||
|
||||
void generate_local_fixups_tree(struct dt_info *dti, char *name)
|
||||
void generate_local_fixups_tree(struct dt_info *dti, const char *name)
|
||||
{
|
||||
struct node *n = get_subnode(dti->dt, name);
|
||||
|
||||
/* Start with an empty __local_fixups__ node to not get duplicates */
|
||||
if (n)
|
||||
n->deleted = true;
|
||||
if (!any_local_fixup_tree(dti, dti->dt))
|
||||
return;
|
||||
generate_local_fixups_tree_internal(dti, build_root_node(dti->dt, name),
|
||||
generate_local_fixups_tree_internal(dti,
|
||||
build_and_name_child_node(dti->dt, name),
|
||||
dti->dt);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
project('dtc', 'c',
|
||||
version: files('VERSION.txt'),
|
||||
license: ['GPL2+', 'BSD-2'],
|
||||
default_options: ['werror=true', 'default_library=both'],
|
||||
meson_version: '>=0.57.0'
|
||||
)
|
||||
|
||||
cc = meson.get_compiler('c')
|
||||
|
||||
add_project_arguments(
|
||||
cc.get_supported_arguments([
|
||||
'-Wpointer-arith',
|
||||
'-Wcast-qual',
|
||||
'-Wnested-externs',
|
||||
'-Wstrict-prototypes',
|
||||
'-Wmissing-prototypes',
|
||||
'-Wredundant-decls',
|
||||
'-Wshadow',
|
||||
'-Wsuggest-attribute=format',
|
||||
'-Wwrite-strings',
|
||||
]),
|
||||
language: 'c'
|
||||
)
|
||||
|
||||
add_project_arguments(
|
||||
'-DFDT_ASSUME_MASK=' + get_option('assume-mask').to_string(),
|
||||
language: 'c'
|
||||
)
|
||||
|
||||
yamltree = 'yamltree.c'
|
||||
yaml = dependency('yaml-0.1', version: '>=0.2.3', required: get_option('yaml'))
|
||||
if not yaml.found()
|
||||
add_project_arguments('-DNO_YAML', language: 'c')
|
||||
yamltree = []
|
||||
endif
|
||||
|
||||
valgrind = dependency('valgrind', required: get_option('valgrind'))
|
||||
if not valgrind.found()
|
||||
add_project_arguments('-DNO_VALGRIND', language: 'c')
|
||||
endif
|
||||
|
||||
py = import('python')
|
||||
py = py.find_installation(required: get_option('python'))
|
||||
swig = find_program('swig', required: get_option('python'))
|
||||
pylibfdt_enabled = not meson.is_cross_build() and py.found() and swig.found() ? true : false
|
||||
wheel_only = get_option('wheel-only')
|
||||
|
||||
version_gen_h = vcs_tag(
|
||||
command: ['git', 'describe', '--dirty=+'],
|
||||
input: 'version_gen.h.in',
|
||||
output: 'version_gen.h',
|
||||
)
|
||||
|
||||
subdir('libfdt')
|
||||
|
||||
dtc_tools = []
|
||||
util_dep = declare_dependency(
|
||||
sources: ['util.c', version_gen_h],
|
||||
include_directories: '.',
|
||||
dependencies: libfdt_dep
|
||||
)
|
||||
|
||||
if get_option('tools') and not wheel_only
|
||||
flex = find_program('flex', required: true)
|
||||
bison = find_program('bison', required: true)
|
||||
|
||||
lgen = generator(
|
||||
flex,
|
||||
output: '@PLAINNAME@.lex.c',
|
||||
arguments: ['-o', '@OUTPUT@', '@INPUT@'],
|
||||
)
|
||||
|
||||
pgen = generator(
|
||||
bison,
|
||||
output: ['@BASENAME@.tab.c', '@BASENAME@.tab.h'],
|
||||
arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@'],
|
||||
)
|
||||
|
||||
if cc.check_header('fnmatch.h')
|
||||
dtc_tools += executable(
|
||||
'convert-dtsv0',
|
||||
[
|
||||
lgen.process('convert-dtsv0-lexer.l'),
|
||||
'srcpos.c',
|
||||
],
|
||||
dependencies: util_dep,
|
||||
install: true,
|
||||
)
|
||||
endif
|
||||
|
||||
dtc_tools += executable(
|
||||
'dtc',
|
||||
[
|
||||
lgen.process('dtc-lexer.l'),
|
||||
pgen.process('dtc-parser.y'),
|
||||
'checks.c',
|
||||
'data.c',
|
||||
'dtc.c',
|
||||
'flattree.c',
|
||||
'fstree.c',
|
||||
'livetree.c',
|
||||
'srcpos.c',
|
||||
'treesource.c',
|
||||
yamltree,
|
||||
],
|
||||
dependencies: [util_dep, yaml],
|
||||
install: true,
|
||||
)
|
||||
|
||||
foreach e: ['fdtdump', 'fdtget', 'fdtput', 'fdtoverlay']
|
||||
dtc_tools += executable(e, files(e + '.c'), dependencies: util_dep, install: true)
|
||||
endforeach
|
||||
|
||||
install_data(
|
||||
'dtdiff',
|
||||
install_dir: get_option('bindir'),
|
||||
install_mode: 'rwxr-xr-x',
|
||||
)
|
||||
endif
|
||||
|
||||
foreach e: dtc_tools
|
||||
meson.override_find_program(e.name(), e)
|
||||
endforeach
|
||||
|
||||
if pylibfdt_enabled
|
||||
subdir('pylibfdt')
|
||||
endif
|
||||
|
||||
if get_option('tests')
|
||||
subdir('tests')
|
||||
endif
|
|
@ -0,0 +1,14 @@
|
|||
option('tools', type: 'boolean', value: true,
|
||||
description: 'Build tools')
|
||||
option('assume-mask', type: 'integer', value: 0,
|
||||
description: 'Control the assumptions made (e.g. risking security issues) in the code.')
|
||||
option('yaml', type: 'feature', value: 'auto',
|
||||
description: 'YAML support')
|
||||
option('valgrind', type: 'feature', value: 'auto',
|
||||
description: 'Valgrind support')
|
||||
option('python', type: 'feature', value: 'auto',
|
||||
description: 'Build pylibfdt Python library')
|
||||
option('tests', type: 'boolean', value: true,
|
||||
description: 'Build tests')
|
||||
option('wheel-only', type: 'boolean', value: false,
|
||||
description: 'building from meson-python')
|
|
@ -1,3 +1,3 @@
|
|||
libfdt.py
|
||||
libfdt.pyc
|
||||
*.pyc
|
||||
libfdt_wrap.c
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
# Makefile.pylibfdt
|
||||
#
|
||||
|
||||
PYLIBFDT_srcs = $(PYLIBFDT_dir)/libfdt.i
|
||||
PYMODULE = $(PYLIBFDT_dir)/_libfdt.so
|
||||
PYLIBFDT_CLEANFILES_L = libfdt_wrap.c libfdt.py *.pyc *.so
|
||||
PYLIBFDT_CLEANFILES = $(PYLIBFDT_CLEANFILES_L:%=$(PYLIBFDT_dir)/%)
|
||||
PYLIBFDT_CLEANDIRS_L = build __pycache__
|
||||
PYLIBFDT_CLEANDIRS = $(PYLIBFDT_CLEANDIRS_L:%=$(PYLIBFDT_dir)/%)
|
||||
|
||||
SETUP = $(PYLIBFDT_dir)/setup.py
|
||||
SETUPFLAGS =
|
||||
|
||||
ifndef V
|
||||
SETUPFLAGS += --quiet
|
||||
endif
|
||||
|
||||
$(PYMODULE): $(PYLIBFDT_srcs) $(LIBFDT_archive) $(SETUP) $(VERSION_FILE)
|
||||
@$(VECHO) PYMOD $@
|
||||
$(PYTHON) $(SETUP) $(SETUPFLAGS) build_ext --build-lib=../$(PYLIBFDT_dir)
|
||||
|
||||
install_pylibfdt: $(PYMODULE)
|
||||
@$(VECHO) INSTALL-PYLIB
|
||||
$(PYTHON) $(SETUP) $(SETUPFLAGS) install --prefix=$(PREFIX)
|
||||
|
||||
pylibfdt_clean:
|
||||
@$(VECHO) CLEAN "(pylibfdt)"
|
||||
rm -f $(PYLIBFDT_CLEANFILES)
|
||||
rm -rf $(PYLIBFDT_CLEANDIRS)
|
|
@ -1,53 +1,8 @@
|
|||
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
||||
/*
|
||||
* pylibfdt - Flat Device Tree manipulation in Python
|
||||
* Copyright (C) 2017 Google, Inc.
|
||||
* Written by Simon Glass <sjg@chromium.org>
|
||||
*
|
||||
* libfdt is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
*
|
||||
* a) This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* Alternatively,
|
||||
*
|
||||
* b) Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
%module libfdt
|
||||
|
@ -63,7 +18,7 @@
|
|||
* a struct called fdt_property. That struct causes swig to create a class in
|
||||
* libfdt.py called fdt_property(), which confuses things.
|
||||
*/
|
||||
static int fdt_property_stub(void *fdt, const char *name, const char *val,
|
||||
static int fdt_property_stub(void *fdt, const char *name, const void *val,
|
||||
int len)
|
||||
{
|
||||
return fdt_property(fdt, name, val, len);
|
||||
|
@ -159,11 +114,14 @@ def check_err_null(val, quiet=()):
|
|||
FdtException if val indicates an error was reported and the error
|
||||
is not in @quiet.
|
||||
"""
|
||||
# Normally a list is returned which contains the data and its length.
|
||||
# If we get just an integer error code, it means the function failed.
|
||||
# Compatibility for SWIG v4.2 and earlier. SWIG 4.2 would drop the first
|
||||
# item from the list if it was None, returning only the second item.
|
||||
if not isinstance(val, list):
|
||||
if -val not in quiet:
|
||||
raise FdtException(val)
|
||||
val = [None, val]
|
||||
|
||||
if val[0] is None:
|
||||
if -val[1] not in quiet:
|
||||
raise FdtException(val[1])
|
||||
return val
|
||||
|
||||
class FdtRo(object):
|
||||
|
@ -204,7 +162,7 @@ class FdtRo(object):
|
|||
quiet: Errors to ignore (empty to raise on all errors)
|
||||
|
||||
Returns:
|
||||
Typle:
|
||||
Tuple:
|
||||
Offset of the next node, if any, else a -ve error
|
||||
Depth of the returned node, if any, else undefined
|
||||
|
||||
|
@ -340,7 +298,9 @@ class FdtRo(object):
|
|||
Returns:
|
||||
Number of memory reserve-map records
|
||||
"""
|
||||
return check_err(fdt_get_mem_rsv(self._fdt, index), quiet)
|
||||
val = fdt_get_mem_rsv(self._fdt, index)
|
||||
check_err(val[0], quiet)
|
||||
return val[1:]
|
||||
|
||||
def subnode_offset(self, parentoffset, name, quiet=()):
|
||||
"""Get the offset of a named subnode
|
||||
|
@ -438,8 +398,8 @@ class FdtRo(object):
|
|||
"""
|
||||
pdata = check_err_null(
|
||||
fdt_get_property_by_offset(self._fdt, prop_offset), quiet)
|
||||
if isinstance(pdata, (int)):
|
||||
return pdata
|
||||
if pdata[0] is None:
|
||||
return pdata[1]
|
||||
return Property(pdata[0], pdata[1])
|
||||
|
||||
def getprop(self, nodeoffset, prop_name, quiet=()):
|
||||
|
@ -460,10 +420,39 @@ class FdtRo(object):
|
|||
"""
|
||||
pdata = check_err_null(fdt_getprop(self._fdt, nodeoffset, prop_name),
|
||||
quiet)
|
||||
if isinstance(pdata, (int)):
|
||||
return pdata
|
||||
if pdata[0] is None:
|
||||
return pdata[1]
|
||||
return Property(prop_name, bytearray(pdata[0]))
|
||||
|
||||
def hasprop(self, nodeoffset, prop_name, quiet=()):
|
||||
"""Check if a node has a property
|
||||
|
||||
This can be used to check boolean properties
|
||||
|
||||
Args:
|
||||
nodeoffset: Node offset containing property to check
|
||||
prop_name: Name of property to check
|
||||
quiet: Errors to ignore (empty to raise on all errors). Note that
|
||||
NOTFOUND is added internally by this function so need not be
|
||||
provided
|
||||
|
||||
Returns:
|
||||
True if the property exists in the node, else False. If an error
|
||||
other than -NOTFOUND is returned by fdt_getprop() then the error
|
||||
is return (-ve integer)
|
||||
|
||||
Raises:
|
||||
FdtError if any error occurs other than NOTFOUND (e.g. the
|
||||
nodeoffset is invalid)
|
||||
"""
|
||||
pdata = check_err_null(fdt_getprop(self._fdt, nodeoffset, prop_name),
|
||||
quiet + (NOTFOUND,))
|
||||
if pdata[0] is None:
|
||||
if pdata[1] == -NOTFOUND:
|
||||
return False
|
||||
return pdata[1]
|
||||
return True
|
||||
|
||||
def get_phandle(self, nodeoffset):
|
||||
"""Get the phandle of a node
|
||||
|
||||
|
@ -476,6 +465,41 @@ class FdtRo(object):
|
|||
"""
|
||||
return fdt_get_phandle(self._fdt, nodeoffset)
|
||||
|
||||
def get_alias(self, name):
|
||||
"""Get the full path referenced by a given alias
|
||||
|
||||
Args:
|
||||
name: name of the alias to lookup
|
||||
|
||||
Returns:
|
||||
Full path to the node for the alias named 'name', if it exists
|
||||
None, if the given alias or the /aliases node does not exist
|
||||
"""
|
||||
return fdt_get_alias(self._fdt, name)
|
||||
|
||||
def get_path(self, nodeoffset, size_hint=1024, quiet=()):
|
||||
"""Get the full path of a node
|
||||
|
||||
Args:
|
||||
nodeoffset: Node offset to check
|
||||
size_hint: Hint for size of returned string
|
||||
|
||||
Returns:
|
||||
Full path to the node
|
||||
|
||||
Raises:
|
||||
FdtException if an error occurs
|
||||
"""
|
||||
while True:
|
||||
ret, path = fdt_get_path(self._fdt, nodeoffset, size_hint)
|
||||
if ret == -NOSPACE:
|
||||
size_hint *= 2
|
||||
continue
|
||||
err = check_err(ret, quiet)
|
||||
if err:
|
||||
return err
|
||||
return path
|
||||
|
||||
def parent_offset(self, nodeoffset, quiet=()):
|
||||
"""Get the offset of a node's parent
|
||||
|
||||
|
@ -615,6 +639,32 @@ class Fdt(FdtRo):
|
|||
return check_err(fdt_setprop(self._fdt, nodeoffset, prop_name, val,
|
||||
len(val)), quiet)
|
||||
|
||||
def setprop_bool(self, nodeoffset, prop_name, val, quiet=()):
|
||||
"""Set the boolean value of a property
|
||||
|
||||
Either:
|
||||
adds the property if not already present; or
|
||||
deletes the property if present
|
||||
|
||||
Args:
|
||||
nodeoffset: Node offset containing the property to create/delete
|
||||
prop_name: Name of property
|
||||
val: Boolean value to write (i.e. True or False)
|
||||
quiet: Errors to ignore (empty to raise on all errors)
|
||||
|
||||
Returns:
|
||||
Error code, or 0 if OK
|
||||
|
||||
Raises:
|
||||
FdtException if no parent found or other error occurs
|
||||
"""
|
||||
exists = self.hasprop(nodeoffset, prop_name, quiet)
|
||||
if val != exists:
|
||||
if val:
|
||||
return self.setprop(nodeoffset, prop_name, b'', quiet=quiet)
|
||||
else:
|
||||
return self.delprop(nodeoffset, prop_name, quiet=quiet)
|
||||
|
||||
def setprop_u32(self, nodeoffset, prop_name, val, quiet=()):
|
||||
"""Set the value of a property
|
||||
|
||||
|
@ -749,6 +799,21 @@ class Property(bytearray):
|
|||
def as_int64(self):
|
||||
return self.as_cell('q')
|
||||
|
||||
def as_list(self, fmt):
|
||||
return list(map(lambda x: x[0], struct.iter_unpack('>' + fmt, self)))
|
||||
|
||||
def as_uint32_list(self):
|
||||
return self.as_list('L')
|
||||
|
||||
def as_int32_list(self):
|
||||
return self.as_list('l')
|
||||
|
||||
def as_uint64_list(self):
|
||||
return self.as_list('Q')
|
||||
|
||||
def as_int64_list(self):
|
||||
return self.as_list('q')
|
||||
|
||||
def as_str(self):
|
||||
"""Unicode is supported by decoding from UTF-8"""
|
||||
if self[-1] != 0:
|
||||
|
@ -757,6 +822,13 @@ class Property(bytearray):
|
|||
raise ValueError('Property contains embedded nul characters')
|
||||
return self[:-1].decode('utf-8')
|
||||
|
||||
def as_stringlist(self):
|
||||
"""Unicode is supported by decoding from UTF-8"""
|
||||
if self[-1] != 0:
|
||||
raise ValueError('Property lacks nul termination')
|
||||
parts = self[:-1].split(b'\x00')
|
||||
return list(map(lambda x: x.decode('utf-8'), parts))
|
||||
|
||||
|
||||
class FdtSw(FdtRo):
|
||||
"""Software interface to create a device tree from scratch
|
||||
|
@ -772,8 +844,10 @@ class FdtSw(FdtRo):
|
|||
|
||||
# First create the device tree with a node and property:
|
||||
sw = FdtSw()
|
||||
with sw.add_node('node'):
|
||||
sw.property_u32('reg', 2)
|
||||
sw.finish_reservemap()
|
||||
with sw.add_node(''):
|
||||
with sw.add_node('node'):
|
||||
sw.property_u32('reg', 2)
|
||||
fdt = sw.as_fdt()
|
||||
|
||||
# Now we can use it as a real device tree
|
||||
|
@ -961,7 +1035,7 @@ class FdtSw(FdtRo):
|
|||
|
||||
Args:
|
||||
name: Name of property to add
|
||||
val: Value of property
|
||||
val: Value of property (bytes)
|
||||
quiet: Errors to ignore (empty to raise on all errors)
|
||||
|
||||
Raises:
|
||||
|
@ -1022,6 +1096,9 @@ class NodeAdder():
|
|||
|
||||
%rename(fdt_property) fdt_property_func;
|
||||
|
||||
%immutable fdt_property::data;
|
||||
%immutable fdt_node_header::name;
|
||||
|
||||
/*
|
||||
* fdt32_t is a big-endian 32-bit value defined to uint32_t in libfdt_env.h
|
||||
* so use the same type here.
|
||||
|
@ -1040,7 +1117,7 @@ typedef uint32_t fdt32_t;
|
|||
}
|
||||
$1 = (void *)PyByteArray_AsString($input);
|
||||
fdt = $1;
|
||||
fdt = fdt; /* avoid unused variable warning */
|
||||
(void)fdt; /* avoid unused variable warning */
|
||||
}
|
||||
|
||||
/* Some functions do change the device tree, so use void * */
|
||||
|
@ -1051,7 +1128,7 @@ typedef uint32_t fdt32_t;
|
|||
}
|
||||
$1 = PyByteArray_AsString($input);
|
||||
fdt = $1;
|
||||
fdt = fdt; /* avoid unused variable warning */
|
||||
(void)fdt; /* avoid unused variable warning */
|
||||
}
|
||||
|
||||
/* typemap used for fdt_get_property_by_offset() */
|
||||
|
@ -1063,7 +1140,7 @@ typedef uint32_t fdt32_t;
|
|||
fdt_string(fdt1, fdt32_to_cpu($1->nameoff)));
|
||||
buff = PyByteArray_FromStringAndSize(
|
||||
(const char *)($1 + 1), fdt32_to_cpu($1->len));
|
||||
resultobj = SWIG_Python_AppendOutput(resultobj, buff);
|
||||
resultobj = SWIG_AppendOutput(resultobj, buff);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1071,14 +1148,16 @@ typedef uint32_t fdt32_t;
|
|||
|
||||
/* typemap used for fdt_getprop() */
|
||||
%typemap(out) (const void *) {
|
||||
if (!$1)
|
||||
if (!$1) {
|
||||
$result = Py_None;
|
||||
else
|
||||
Py_INCREF($result);
|
||||
} else {
|
||||
%#if PY_VERSION_HEX >= 0x03000000
|
||||
$result = Py_BuildValue("y#", $1, *arg4);
|
||||
$result = Py_BuildValue("y#", $1, (Py_ssize_t)*arg4);
|
||||
%#else
|
||||
$result = Py_BuildValue("s#", $1, *arg4);
|
||||
$result = Py_BuildValue("s#", $1, (Py_ssize_t)*arg4);
|
||||
%#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* typemap used for fdt_setprop() */
|
||||
|
@ -1102,7 +1181,7 @@ typedef uint32_t fdt32_t;
|
|||
|
||||
%typemap(argout) int *depth {
|
||||
PyObject *val = Py_BuildValue("i", *arg$argnum);
|
||||
resultobj = SWIG_Python_AppendOutput(resultobj, val);
|
||||
resultobj = SWIG_AppendOutput(resultobj, val);
|
||||
}
|
||||
|
||||
%apply int *depth { int *depth };
|
||||
|
@ -1114,14 +1193,14 @@ typedef uint32_t fdt32_t;
|
|||
|
||||
%typemap(argout) uint64_t * {
|
||||
PyObject *val = PyLong_FromUnsignedLongLong(*arg$argnum);
|
||||
if (!result) {
|
||||
if (PyTuple_GET_SIZE(resultobj) == 0)
|
||||
resultobj = val;
|
||||
else
|
||||
resultobj = SWIG_Python_AppendOutput(resultobj, val);
|
||||
}
|
||||
resultobj = SWIG_AppendOutput(resultobj, val);
|
||||
}
|
||||
|
||||
%include "cstring.i"
|
||||
|
||||
%cstring_output_maxsize(char *buf, int buflen);
|
||||
int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
|
||||
|
||||
/* We have both struct fdt_property and a function fdt_property() */
|
||||
%warnfilter(302) fdt_property;
|
||||
|
||||
|
@ -1144,6 +1223,6 @@ int fdt_property_cell(void *fdt, const char *name, uint32_t val);
|
|||
* This function has a stub since the name fdt_property is used for both a
|
||||
* function and a struct, which confuses SWIG.
|
||||
*/
|
||||
int fdt_property_stub(void *fdt, const char *name, const char *val, int len);
|
||||
int fdt_property_stub(void *fdt, const char *name, const void *val, int len);
|
||||
|
||||
%include <libfdt.h>
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
libfdt_c = custom_target(
|
||||
'swig',
|
||||
input: 'libfdt.i',
|
||||
output: ['libfdt.c', 'libfdt.py'],
|
||||
install: true,
|
||||
install_dir: [false, py.get_install_dir(pure: false)],
|
||||
command: [swig, '-python', '-I'+meson.current_source_dir() / '../libfdt', '-o', '@OUTPUT0@', '@INPUT@']
|
||||
)
|
||||
|
||||
nowarn_gen = cc.get_supported_arguments(
|
||||
'-Wno-cast-qual',
|
||||
'-Wno-missing-prototypes',
|
||||
'-Wno-redundant-decls',
|
||||
)
|
||||
pylibfdt = py.extension_module(
|
||||
'_libfdt',
|
||||
libfdt_c,
|
||||
c_args: ['-DPY_SSIZE_T_CLEAN'] + nowarn_gen,
|
||||
dependencies: [libfdt_dep, py.dependency()],
|
||||
install: true,
|
||||
)
|
|
@ -1,44 +0,0 @@
|
|||
#!/usr/bin/env python2
|
||||
|
||||
"""
|
||||
setup.py file for SWIG libfdt
|
||||
Copyright (C) 2017 Google, Inc.
|
||||
Written by Simon Glass <sjg@chromium.org>
|
||||
"""
|
||||
|
||||
from distutils.core import setup, Extension
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
VERSION_PATTERN = '^#define DTC_VERSION "DTC ([^"]*)"$'
|
||||
|
||||
|
||||
def get_version():
|
||||
version_file = "../version_gen.h"
|
||||
f = open(version_file, 'rt')
|
||||
m = re.match(VERSION_PATTERN, f.readline())
|
||||
return m.group(1)
|
||||
|
||||
|
||||
setupdir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
os.chdir(setupdir)
|
||||
|
||||
libfdt_module = Extension(
|
||||
'_libfdt',
|
||||
sources=['libfdt.i'],
|
||||
include_dirs=['../libfdt'],
|
||||
libraries=['fdt'],
|
||||
library_dirs=['../libfdt'],
|
||||
swig_opts=['-I../libfdt'],
|
||||
)
|
||||
|
||||
setup(
|
||||
name='libfdt',
|
||||
version=get_version(),
|
||||
author='Simon Glass <sjg@chromium.org>',
|
||||
description='Python binding for libfdt',
|
||||
ext_modules=[libfdt_module],
|
||||
py_modules=['libfdt'],
|
||||
)
|
|
@ -0,0 +1,33 @@
|
|||
[build-system]
|
||||
build-backend = 'mesonpy'
|
||||
requires = ['meson-python']
|
||||
|
||||
[project]
|
||||
name = 'libfdt'
|
||||
authors = [
|
||||
{name = 'Simon Glass', email = 'sjg@chromium.org'},
|
||||
]
|
||||
classifiers = [
|
||||
'Programming Language :: Python :: 3',
|
||||
'License :: OSI Approved :: BSD License',
|
||||
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
|
||||
'Operating System :: OS Independent',
|
||||
]
|
||||
description = 'Python binding for libfdt'
|
||||
readme = 'README.md'
|
||||
requires-python = '>=3.8'
|
||||
dynamic = ['version']
|
||||
|
||||
[project.urls]
|
||||
'homepage' = 'https://git.kernel.org/pub/scm/utils/dtc/dtc.git'
|
||||
|
||||
# These arguments are applied only when building a redistributable binary wheel
|
||||
# for uploading to PyPI. We don't want to install libraries (or headers /
|
||||
# pkgconfig files / executables) that clash with system C installs, so we
|
||||
# disable everything other than the python bindings themselves, and build the
|
||||
# python C-API extension using static linkage to avoid juggling "libdir" /
|
||||
# LD_LIBRARY_PATH / RPATH around. When building both the C library and the
|
||||
# python bindings for a distro, `meson setup` will still default to shared
|
||||
# libraries.
|
||||
[tool.meson-python.args]
|
||||
setup = ['-Ddefault_library=static', '-Dwheel-only=true']
|
|
@ -0,0 +1,32 @@
|
|||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
if [ -f /etc/os-release ]
|
||||
then
|
||||
. /etc/os-release
|
||||
else
|
||||
echo "ERROR: OS name is not provided."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$NAME" = "Arch Linux" ]
|
||||
then
|
||||
pacman -Syu --needed --noconfirm bison diffutils flex gcc git libyaml \
|
||||
make meson pkgconf python python-setuptools-scm swig valgrind which
|
||||
elif [ "$NAME" = "Alpine Linux" ]
|
||||
then
|
||||
apk add build-base bison coreutils flex git yaml yaml-dev python3-dev \
|
||||
meson py3-setuptools_scm swig valgrind
|
||||
elif [ "$NAME" = "Fedora Linux" ]
|
||||
then
|
||||
dnf install -y bison diffutils flex gcc git libyaml libyaml-devel \
|
||||
make meson python3-devel python3-setuptools swig valgrind which
|
||||
elif [ "$NAME" = "Ubuntu" ]
|
||||
then
|
||||
apt update
|
||||
apt install -yq build-essential bison flex git libyaml-dev pkg-config \
|
||||
meson python3-dev python3-setuptools python3-setuptools-scm swig valgrind
|
||||
else
|
||||
echo "ERROR: OS name is not provided."
|
||||
exit 1
|
||||
fi
|
|
@ -1,4 +1,5 @@
|
|||
#! /bin/sh
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
REMOTE_GIT=/pub/scm/utils/dtc/dtc.git
|
||||
REMOTE_PATH=/pub/software/utils/dtc
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
# Print additional version information for non-release trees.
|
||||
|
||||
usage() {
|
||||
|
|
49
srcpos.c
49
srcpos.c
|
@ -1,23 +1,11 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* Copyright 2007 Jon Loeliger, Freescale Semiconductor, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -34,7 +22,7 @@ struct search_path {
|
|||
static struct search_path *search_path_head, **search_path_tail;
|
||||
|
||||
/* Detect infinite include recursion. */
|
||||
#define MAX_SRCFILE_DEPTH (100)
|
||||
#define MAX_SRCFILE_DEPTH (200)
|
||||
static int srcfile_depth; /* = 0 */
|
||||
|
||||
static char *get_dirname(const char *path)
|
||||
|
@ -172,8 +160,10 @@ FILE *srcfile_relative_open(const char *fname, char **fullnamep)
|
|||
strerror(errno));
|
||||
}
|
||||
|
||||
if (depfile)
|
||||
fprintf(depfile, " %s", fullname);
|
||||
if (depfile) {
|
||||
fputc(' ', depfile);
|
||||
fprint_path_escaped(depfile, fullname);
|
||||
}
|
||||
|
||||
if (fullnamep)
|
||||
*fullnamep = fullname;
|
||||
|
@ -297,6 +287,17 @@ struct srcpos *srcpos_extend(struct srcpos *pos, struct srcpos *newtail)
|
|||
return pos;
|
||||
}
|
||||
|
||||
void srcpos_free(struct srcpos *pos)
|
||||
{
|
||||
struct srcpos *p_next;
|
||||
|
||||
while (pos) {
|
||||
p_next = pos->next;
|
||||
free(pos);
|
||||
pos = p_next;
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
srcpos_string(struct srcpos *pos)
|
||||
{
|
||||
|
@ -325,8 +326,8 @@ srcpos_string(struct srcpos *pos)
|
|||
static char *
|
||||
srcpos_string_comment(struct srcpos *pos, bool first_line, int level)
|
||||
{
|
||||
char *pos_str, *fname, *first, *rest;
|
||||
bool fresh_fname = false;
|
||||
char *pos_str, *fresh_fname = NULL, *first, *rest;
|
||||
const char *fname;
|
||||
|
||||
if (!pos) {
|
||||
if (level > 1) {
|
||||
|
@ -344,9 +345,9 @@ srcpos_string_comment(struct srcpos *pos, bool first_line, int level)
|
|||
else if (level > 1)
|
||||
fname = pos->file->name;
|
||||
else {
|
||||
fname = shorten_to_initial_path(pos->file->name);
|
||||
if (fname)
|
||||
fresh_fname = true;
|
||||
fresh_fname = shorten_to_initial_path(pos->file->name);
|
||||
if (fresh_fname)
|
||||
fname = fresh_fname;
|
||||
else
|
||||
fname = pos->file->name;
|
||||
}
|
||||
|
@ -360,7 +361,7 @@ srcpos_string_comment(struct srcpos *pos, bool first_line, int level)
|
|||
first_line ? pos->first_line : pos->last_line);
|
||||
|
||||
if (fresh_fname)
|
||||
free(fname);
|
||||
free(fresh_fname);
|
||||
|
||||
if (pos->next != NULL) {
|
||||
rest = srcpos_string_comment(pos->next, first_line, level);
|
||||
|
|
17
srcpos.h
17
srcpos.h
|
@ -1,20 +1,6 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* Copyright 2007 Jon Loeliger, Freescale Semiconductor, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
#ifndef SRCPOS_H
|
||||
|
@ -102,6 +88,7 @@ extern void srcpos_update(struct srcpos *pos, const char *text, int len);
|
|||
extern struct srcpos *srcpos_copy(struct srcpos *pos);
|
||||
extern struct srcpos *srcpos_extend(struct srcpos *new_srcpos,
|
||||
struct srcpos *old_srcpos);
|
||||
extern void srcpos_free(struct srcpos *pos);
|
||||
extern char *srcpos_string(struct srcpos *pos);
|
||||
extern char *srcpos_string_first(struct srcpos *pos, int level);
|
||||
extern char *srcpos_string_last(struct srcpos *pos, int level);
|
||||
|
|
|
@ -8,6 +8,7 @@ tmp.*
|
|||
/addr_size_cells
|
||||
/addr_size_cells2
|
||||
/appendprop[12]
|
||||
/appendprop_addrrange
|
||||
/asm_tree_dump
|
||||
/boot-cpuid
|
||||
/char_literal
|
||||
|
@ -53,8 +54,10 @@ tmp.*
|
|||
/property_iterate
|
||||
/propname_escapes
|
||||
/references
|
||||
/relref_merge
|
||||
/root_node
|
||||
/rw_tree1
|
||||
/rw_oom
|
||||
/set_name
|
||||
/setprop
|
||||
/setprop_inplace
|
||||
|
@ -71,3 +74,4 @@ tmp.*
|
|||
/truncated_memrsv
|
||||
/utilfdt_test
|
||||
/value-labels
|
||||
/get_next_tag_invalid_prop_len
|
||||
|
|
|
@ -4,20 +4,21 @@ LIB_TESTS_L = get_mem_rsv \
|
|||
get_path supernode_atdepth_offset parent_offset \
|
||||
node_offset_by_prop_value node_offset_by_phandle \
|
||||
node_check_compatible node_offset_by_compatible \
|
||||
get_alias \
|
||||
get_alias get_next_tag_invalid_prop_len \
|
||||
char_literal \
|
||||
sized_cells \
|
||||
notfound \
|
||||
addr_size_cells \
|
||||
addr_size_cells2 \
|
||||
appendprop_addrrange \
|
||||
stringlist \
|
||||
setprop_inplace nop_property nop_node \
|
||||
sw_tree1 sw_states \
|
||||
move_and_save mangle-layout nopulate \
|
||||
open_pack rw_tree1 set_name setprop del_property del_node \
|
||||
open_pack rw_tree1 rw_oom set_name setprop del_property del_node \
|
||||
appendprop1 appendprop2 propname_escapes \
|
||||
string_escapes references path-references phandle_format \
|
||||
boot-cpuid incbin \
|
||||
boot-cpuid incbin relref_merge \
|
||||
extra-terminating-null \
|
||||
dtbs_equal_ordered \
|
||||
dtb_reverse dtbs_equal_unordered \
|
||||
|
@ -32,14 +33,19 @@ LIB_TESTS_L = get_mem_rsv \
|
|||
LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%)
|
||||
|
||||
LIBTREE_TESTS_L = truncated_property truncated_string truncated_memrsv
|
||||
|
||||
LIBTREE_TESTS = $(LIBTREE_TESTS_L:%=$(TESTS_PREFIX)%)
|
||||
|
||||
DL_LIB_TESTS_L = asm_tree_dump value-labels
|
||||
DL_LIB_TESTS = $(DL_LIB_TESTS_L:%=$(TESTS_PREFIX)%)
|
||||
ifneq ($(STATIC_BUILD),1)
|
||||
DL_LIB_TESTS_L = asm_tree_dump value-labels
|
||||
DL_LIB_TESTS = $(DL_LIB_TESTS_L:%=$(TESTS_PREFIX)%)
|
||||
endif
|
||||
|
||||
TESTS = $(LIB_TESTS) $(LIBTREE_TESTS) $(DL_LIB_TESTS)
|
||||
|
||||
TESTS_TREES_L = test_tree1.dtb
|
||||
TESTS_TREES_L = test_tree1.dtb bad_node_char.dtb bad_node_format.dtb \
|
||||
bad_prop_char.dtb ovf_size_strings.dtb truncated_property.dtb \
|
||||
truncated_string.dtb truncated_memrsv.dtb two_roots.dtb named_root.dtb
|
||||
TESTS_TREES = $(TESTS_TREES_L:%=$(TESTS_PREFIX)%)
|
||||
|
||||
TESTS_TARGETS = $(TESTS) $(TESTS_TREES)
|
||||
|
@ -48,7 +54,7 @@ TESTS_DEPFILES = $(TESTS:%=%.d) \
|
|||
$(addprefix $(TESTS_PREFIX),testutils.d trees.d dumptrees.d)
|
||||
|
||||
TESTS_CLEANFILES_L = $(STD_CLEANFILES) \
|
||||
*.dtb *.test.dts *.test.dt.yaml *.dtsv1 tmp.* \
|
||||
*.dtb *.test.dts *.test.dt.yaml *.dtsv1 tmp.* *.bak \
|
||||
dumptrees
|
||||
TESTS_CLEANFILES = $(TESTS) $(TESTS_CLEANFILES_L:%=$(TESTS_PREFIX)%)
|
||||
TESTS_CLEANDIRS_L = fs
|
||||
|
@ -57,23 +63,23 @@ TESTS_CLEANDIRS = $(TESTS_CLEANDIRS_L:%=$(TESTS_PREFIX)%)
|
|||
.PHONY: tests
|
||||
tests: $(TESTS) $(TESTS_TREES)
|
||||
|
||||
$(LIB_TESTS): %: $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_archive)
|
||||
$(LIB_TESTS): %: $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_dep)
|
||||
|
||||
# Not necessary on all platforms; allow -ldl to be excluded instead of forcing
|
||||
# other platforms to patch it out.
|
||||
LIBDL = -ldl
|
||||
$(DL_LIB_TESTS): %: %.o $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_archive)
|
||||
$(DL_LIB_TESTS): %: %.o $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_dep)
|
||||
@$(VECHO) LD [libdl] $@
|
||||
$(LINK.c) -o $@ $^ $(LIBDL)
|
||||
|
||||
$(LIBTREE_TESTS): %: $(TESTS_PREFIX)testutils.o $(TESTS_PREFIX)trees.o \
|
||||
util.o $(LIBFDT_archive)
|
||||
util.o $(LIBFDT_dep)
|
||||
|
||||
$(TESTS_PREFIX)dumptrees: $(TESTS_PREFIX)trees.o
|
||||
|
||||
$(TESTS_TREES): $(TESTS_PREFIX)dumptrees
|
||||
@$(VECHO) DUMPTREES
|
||||
cd $(TESTS_PREFIX); ./dumptrees >/dev/null
|
||||
cd $(TESTS_PREFIX); ./dumptrees . >/dev/null
|
||||
|
||||
tests_clean:
|
||||
@$(VECHO) CLEAN "(tests)"
|
||||
|
@ -81,18 +87,18 @@ tests_clean:
|
|||
rm -rf $(TESTS_CLEANDIRS)
|
||||
|
||||
check: tests ${TESTS_BIN} $(TESTS_PYLIBFDT)
|
||||
cd $(TESTS_PREFIX); PYTHON=$(PYTHON) ./run_tests.sh
|
||||
cd $(TESTS_PREFIX); ./run_tests.sh
|
||||
|
||||
ifeq ($(NO_VALGRIND),1)
|
||||
checkm:
|
||||
@echo "make checkm requires valgrind, but NO_VALGRIND=1"
|
||||
else
|
||||
checkm: tests ${TESTS_BIN} $(TESTS_PYLIBFDT)
|
||||
cd $(TESTS_PREFIX); PYTHON=$(PYTHON) ./run_tests.sh -m
|
||||
cd $(TESTS_PREFIX); ./run_tests.sh -m
|
||||
endif
|
||||
|
||||
checkv: tests ${TESTS_BIN} $(TESTS_PYLIBFDT)
|
||||
cd $(TESTS_PREFIX); PYTHON=$(PYTHON) ./run_tests.sh -v
|
||||
cd $(TESTS_PREFIX); ./run_tests.sh -v
|
||||
|
||||
ifneq ($(DEPTARGETS),)
|
||||
-include $(TESTS_DEPFILES)
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Testcase for fdt_nop_node()
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Testcase for #address-cells and #size-cells handling
|
||||
* Copyright (C) 2014 David Gibson, <david@gibson.dropbear.id.au>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -60,8 +47,10 @@ int main(int argc, char *argv[])
|
|||
check_node(fdt, "/", 2, 2);
|
||||
check_node(fdt, "/identity-bus@0", 2, 1);
|
||||
check_node(fdt, "/simple-bus@1000000", 2, 1);
|
||||
check_node(fdt, "/discrete-bus@2000000", 1, 0);
|
||||
check_node(fdt, "/c0", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
|
||||
check_node(fdt, "/c1", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
|
||||
check_node(fdt, "/c2", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
|
||||
check_node(fdt, "/c3", -FDT_ERR_BADNCELLS, 0);
|
||||
PASS();
|
||||
}
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Testcase for #address-cells and #size-cells handling
|
||||
* Copyright (C) 2014 David Gibson, <david@gibson.dropbear.id.au>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -13,6 +13,11 @@
|
|||
#size-cells = <1>;
|
||||
};
|
||||
|
||||
discrete-bus@2000000 {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
};
|
||||
|
||||
c0@0 {
|
||||
#address-cells = <1 1>;
|
||||
#size-cells = <1 1>;
|
||||
|
@ -27,4 +32,9 @@
|
|||
#address-cells = <5>;
|
||||
#size-cells = <5>;
|
||||
};
|
||||
|
||||
c3@0 {
|
||||
#address-cells = <0>;
|
||||
#size-cells = <0>;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
#size-cells = <0>;
|
||||
|
||||
aliases {
|
||||
empty = "";
|
||||
loop = "loop";
|
||||
nonull = [626164];
|
||||
relative = "s1/subsubnode";
|
||||
s1 = &sub1;
|
||||
ss1 = &subsub1;
|
||||
sss1 = &subsubsub1;
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Testcase for fdt_appendprop()
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Testcase for fdt_appendprop()
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -49,6 +36,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
buf = xmalloc(SPACE);
|
||||
CHECK(fdt_open_into(fdt, buf, SPACE));
|
||||
free(fdt);
|
||||
fdt = buf;
|
||||
|
||||
CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes)));
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Testcase for fdt_appendprop_addrrange()
|
||||
* Copyright (C) 2018 AKASHI Takahiro, Linaro Limited
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <libfdt.h>
|
||||
|
||||
#include "tests.h"
|
||||
#include "testdata.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
void *fdt, *buf;
|
||||
int offset, xac, xsc, num, i, err;
|
||||
uint64_t addr, size;
|
||||
|
||||
if (argc != 5)
|
||||
CONFIG("Usage: %s <dtb file> <address-cells> <size-cells> <num>\n",
|
||||
argv[0]);
|
||||
|
||||
test_init(argc, argv);
|
||||
fdt = load_blob(argv[1]);
|
||||
xac = strtol(argv[2], NULL, 10);
|
||||
xsc = strtol(argv[3], NULL, 10);
|
||||
num = strtol(argv[4], NULL, 10);
|
||||
|
||||
buf = xmalloc(0x1000);
|
||||
if (!buf)
|
||||
FAIL("Couldn't allocate temporary buffer");
|
||||
err = fdt_open_into(fdt, buf, 0x1000);
|
||||
if (err)
|
||||
FAIL("fdt_open_into(): %s", fdt_strerror(err));
|
||||
free(fdt);
|
||||
fdt = buf;
|
||||
|
||||
/* Set up */
|
||||
err = fdt_setprop_cell(fdt, 0, "#address-cells", xac);
|
||||
if (err)
|
||||
FAIL("fdt_setprop_cell(\"#address-cells\"): %s",
|
||||
fdt_strerror(err));
|
||||
err = fdt_setprop_cell(fdt, 0, "#size-cells", xsc);
|
||||
if (err)
|
||||
FAIL("fdt_setprop_cell(\"#size-cells\"): %s",
|
||||
fdt_strerror(err));
|
||||
|
||||
offset = fdt_path_offset(fdt, "/node@1");
|
||||
if (offset < 0)
|
||||
FAIL("Couldn't find path %s", "/node@1");
|
||||
|
||||
addr = TEST_MEMREGION_ADDR;
|
||||
if (xac > 1)
|
||||
addr += TEST_MEMREGION_ADDR_HI;
|
||||
size = TEST_MEMREGION_SIZE;
|
||||
if (xsc > 1)
|
||||
size += TEST_MEMREGION_SIZE_HI;
|
||||
|
||||
/*
|
||||
* Do test
|
||||
*/
|
||||
/* 1. repeat append's */
|
||||
for (i = 0; i < num; i++) {
|
||||
err = fdt_appendprop_addrrange(fdt, 0, offset,
|
||||
"prop-memregion", addr, size);
|
||||
if (err)
|
||||
FAIL("Failed to append[%d] \"prop-memregion\": %s",
|
||||
i, fdt_strerror(err));
|
||||
|
||||
check_getprop_addrrange(fdt, 0, offset, "prop-memregion",
|
||||
i + 1);
|
||||
|
||||
addr += size;
|
||||
size += TEST_MEMREGION_SIZE_INC;
|
||||
}
|
||||
|
||||
/* 2. default property name */
|
||||
addr = TEST_MEMREGION_ADDR;
|
||||
if (xac > 1)
|
||||
addr += TEST_MEMREGION_ADDR_HI;
|
||||
size = TEST_MEMREGION_SIZE;
|
||||
if (xsc > 1)
|
||||
size += TEST_MEMREGION_SIZE_HI;
|
||||
|
||||
err = fdt_appendprop_addrrange(fdt, 0, offset, "reg", addr, size);
|
||||
if (err)
|
||||
FAIL("Failed to set \"reg\": %s", fdt_strerror(err));
|
||||
check_getprop_addrrange(fdt, 0, offset, "reg", 1);
|
||||
|
||||
PASS();
|
||||
}
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Tests if an asm tree built into a shared object matches a given dtb
|
||||
* Copyright (C) 2008 David Gibson, IBM Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
/dts-v1/;
|
||||
|
||||
/ {
|
||||
#address-cells = <2>;
|
||||
#size-cells = <2>;
|
||||
node {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
ranges;
|
||||
dma-ranges = <0 0 0 0 0>;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
/dts-v1/;
|
||||
/ {
|
||||
bar: bar {
|
||||
ports {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
port@0 {
|
||||
reg = <0>;
|
||||
bar_con: endpoint {
|
||||
remote-endpoint = <&foo_con>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
foo {
|
||||
port {
|
||||
foo_con: endpoint {
|
||||
remote-endpoint = <&bar_con>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,36 @@
|
|||
/dts-v1/;
|
||||
/ {
|
||||
bar: bar {
|
||||
ports {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>; // should always be 0
|
||||
port@1 {
|
||||
reg = <1 2>; // should always contain only a single cell
|
||||
bar_con: endpoint {
|
||||
remote-endpoint = <&foo_con>;
|
||||
};
|
||||
};
|
||||
port@2 {
|
||||
reg = <2>;
|
||||
bar_con2: endpoint {
|
||||
remote-endpoint = <&foo_con2>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
foo {
|
||||
port {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>; // should always be 0
|
||||
foo_con: endpoint@1 {
|
||||
reg = <1 2>; // should always contain only a single cell
|
||||
remote-endpoint = <&bar_con>;
|
||||
};
|
||||
foo_con2: endpoint@2 {
|
||||
reg = <2>;
|
||||
remote-endpoint = <&bar_con2>;
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
/dts-v1/;
|
||||
|
||||
/ {
|
||||
foo {
|
||||
remote-endpoint = <0xdeadbeef>;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,2 @@
|
|||
/dts-v1/;
|
||||
/ { endpoint {}; };
|
|
@ -0,0 +1,14 @@
|
|||
/dts-v1/;
|
||||
|
||||
/ {
|
||||
bar: bar {
|
||||
port {
|
||||
bar_con: endpoint {
|
||||
remote-endpoint = <&foo_con>;
|
||||
};
|
||||
};
|
||||
};
|
||||
foo_con: endpoint {
|
||||
remote-endpoint = <&bar_con>;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,19 @@
|
|||
/dts-v1/;
|
||||
|
||||
/ {
|
||||
|
||||
bar: bar {
|
||||
port {
|
||||
bar_con: endpoint {
|
||||
remote-endpoint = <&foo_con>;
|
||||
};
|
||||
};
|
||||
};
|
||||
foo {
|
||||
remote-endpoint = <&bar_con>; // misplaced remote-endpoint property
|
||||
port {
|
||||
foo_con: endpoint {
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
/dts-v1/;
|
||||
|
||||
/ {
|
||||
intc: interrupt-controller {
|
||||
interrupt-controller;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
/dts-v1/;
|
||||
|
||||
/ {
|
||||
interrupt-parent = <&intc>;
|
||||
intc: interrupt-controller {
|
||||
#interrupt-cells = <3>;
|
||||
interrupt-controller;
|
||||
};
|
||||
|
||||
node {
|
||||
#address-cells = <0>;
|
||||
#interrupt-cells = <1>;
|
||||
interrupt-map = <1 &intc 1 2 3>;
|
||||
interrupt-map-mask = <0 0>;
|
||||
|
||||
child {
|
||||
interrupts = <1>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,17 @@
|
|||
/dts-v1/;
|
||||
|
||||
/ {
|
||||
interrupt-parent = <&intc>;
|
||||
intc: interrupt-controller {
|
||||
};
|
||||
|
||||
node {
|
||||
#address-cells = <0>;
|
||||
#interrupt-cells = <1>;
|
||||
interrupt-map = <1 &intc 1 2 3>;
|
||||
|
||||
child {
|
||||
interrupts = <1>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,19 @@
|
|||
/dts-v1/;
|
||||
|
||||
/ {
|
||||
interrupt-parent = <&intc>;
|
||||
intc: interrupt-controller {
|
||||
#interrupt-cells = <3>;
|
||||
interrupt-controller;
|
||||
};
|
||||
|
||||
node {
|
||||
/* Missing #address-cells = <0>; */
|
||||
#interrupt-cells = <1>;
|
||||
interrupt-map = <1 &intc 1 2 3>;
|
||||
|
||||
child {
|
||||
interrupts = <1>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -32,7 +32,7 @@ _dt_reserve_map:
|
|||
dt_struct_start:
|
||||
_dt_struct_start:
|
||||
.long OF_DT_BEGIN_NODE
|
||||
.string ""
|
||||
.asciz ""
|
||||
.balign 4
|
||||
.long OF_DT_PROP
|
||||
.long 0xa
|
||||
|
@ -58,7 +58,7 @@ _dt_struct_start:
|
|||
.long 0x2
|
||||
.balign 4
|
||||
.long OF_DT_BEGIN_NODE
|
||||
.string "memory@0"
|
||||
.asciz "memory@0"
|
||||
.balign 4
|
||||
.long OF_DT_PROP
|
||||
.long 0x7
|
||||
|
@ -77,7 +77,7 @@ _dt_struct_start:
|
|||
.balign 4
|
||||
.long OF_DT_END_NODE
|
||||
.long OF_DT_BEGIN_NODE
|
||||
.string "cpus"
|
||||
.asciz "cpus"
|
||||
.balign 4
|
||||
.long OF_DT_PROP
|
||||
.long 0x4
|
||||
|
@ -151,22 +151,22 @@ _dt_struct_end:
|
|||
.globl dt_strings_start
|
||||
dt_strings_start:
|
||||
_dt_strings_start:
|
||||
.string "model"
|
||||
.string "compatible"
|
||||
.string "#address-cells"
|
||||
.string "#size-cells"
|
||||
.string "device_type"
|
||||
.string "reg"
|
||||
.string "d10"
|
||||
.string "d23"
|
||||
.string "b101"
|
||||
.string "o17"
|
||||
.string "hd00d"
|
||||
.string "stuff"
|
||||
.string "bad-d-1"
|
||||
.string "bad-d-2"
|
||||
.string "bad-o-1"
|
||||
.string "bad-o-2"
|
||||
.asciz "model"
|
||||
.asciz "compatible"
|
||||
.asciz "#address-cells"
|
||||
.asciz "#size-cells"
|
||||
.asciz "device_type"
|
||||
.asciz "reg"
|
||||
.asciz "d10"
|
||||
.asciz "d23"
|
||||
.asciz "b101"
|
||||
.asciz "o17"
|
||||
.asciz "hd00d"
|
||||
.asciz "stuff"
|
||||
.asciz "bad-d-1"
|
||||
.asciz "bad-d-2"
|
||||
.asciz "bad-o-1"
|
||||
.asciz "bad-o-2"
|
||||
.globl dt_strings_end
|
||||
dt_strings_end:
|
||||
_dt_strings_end:
|
||||
|
|
|
@ -1,19 +1,6 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* Copyright (C) 2008 David Gibson, IBM Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
/dts-v1/;
|
||||
|
||||
/ {
|
||||
prop1 = < 0 >;
|
||||
prop2 = < 0xffffffff >;
|
||||
prop3 = < 0 >;
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
/dts-v1/;
|
||||
|
||||
/ {
|
||||
prop1 = < (-0xffffffff - 1) >;
|
||||
prop2 = < (-0xffffffff - 2) >;
|
||||
prop3 = < ((-0xffffffff - 1) * 2) >;
|
||||
};
|
|
@ -1,22 +1,9 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Testcase for character literals in dtc
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
* Copyright (C) 2011 The Chromium Authors. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Tests if two given dtbs are structurally equal (including order)
|
||||
* Copyright (C) 2007 David Gibson, IBM Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Testcase for fdt_check_header
|
||||
* Copyright (C) 2018 David Gibson
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Testcase for node existence
|
||||
* Copyright (C) 2016 Konsulko Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -45,6 +32,7 @@ static void *open_dt(char *path)
|
|||
* Resize our DTs to 4k so that we have room to operate on
|
||||
*/
|
||||
CHECK(fdt_open_into(dt, copy, FDT_COPY_SIZE));
|
||||
free(dt);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
prop7;
|
||||
/* yet
|
||||
* another
|
||||
* multline
|
||||
* multiline
|
||||
* comment
|
||||
*/
|
||||
prop8;
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Testcase for fdt_nop_node()
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -31,15 +18,16 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
void *fdt;
|
||||
void *fdt, *blob;
|
||||
int subnode1_offset, subnode2_offset, subsubnode2_offset;
|
||||
int err;
|
||||
int oldsize, delsize, newsize;
|
||||
|
||||
test_init(argc, argv);
|
||||
fdt = load_blob_arg(argc, argv);
|
||||
blob = load_blob_arg(argc, argv);
|
||||
|
||||
fdt = open_blob_rw(fdt);
|
||||
fdt = open_blob_rw(blob);
|
||||
free(blob);
|
||||
|
||||
oldsize = fdt_totalsize(fdt);
|
||||
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Testcase for fdt_delprop()
|
||||
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -31,16 +18,17 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
void *fdt;
|
||||
void *fdt, *blob;
|
||||
const uint32_t *intp;
|
||||
const char *strp;
|
||||
int err, lenerr;
|
||||
int oldsize, delsize, newsize;
|
||||
|
||||
test_init(argc, argv);
|
||||
fdt = load_blob_arg(argc, argv);
|
||||
blob = load_blob_arg(argc, argv);
|
||||
|
||||
fdt = open_blob_rw(fdt);
|
||||
fdt = open_blob_rw(blob);
|
||||
free(blob);
|
||||
|
||||
oldsize = fdt_totalsize(fdt);
|
||||
|
||||
|
@ -86,5 +74,6 @@ int main(int argc, char *argv[])
|
|||
if (newsize >= oldsize)
|
||||
FAIL("Tree failed to shrink after deletions");
|
||||
|
||||
free(fdt);
|
||||
PASS();
|
||||
}
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Tests if two given dtbs are structurally equal (including order)
|
||||
* Copyright (C) 2010 David Gibson, IBM Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/*
|
||||
* libfdt - Flat Device Tree manipulation
|
||||
* Tests if two given dtbs are structurally equal (including order)
|
||||
* Copyright (C) 2007 David Gibson, IBM Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue