summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Implement string concatenate and repeat operatorsexpressionsDavid Gibson2014-03-036-3/+223
| | | | | | | | | | This patch exercises the new expression infrastructure to implement syntax to concatenate and repeat strings. We use syntax inspired by Python, with '+' overloaded for string concatenation and '*' overloaded for string repeat. Normally we'd use C syntax to inspire dts syntax, but C has no obvious candidates for these string operators. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Re-implement "," in property definitions as a bytestring operatorDavid Gibson2014-03-031-23/+14
| | | | | | | | | | | | | We've already introduced an internal "join" operator which appends bytestring expressions together. This uses it to implement the "," syntax in property values as expressions. This is the last piece of property value syntax to be converted to use the expression infrastructure, so all (non-empty) property values can now be implemented as a single expression. For now we still just immediately evaluate the expression though. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Implement path references in terms of bytestring expressionsDavid Gibson2014-03-031-4/+5
| | | | | | | | | | | | | | This patch re-implements path references (&label which expands to the referenced node's full path) in terms of the bytestring expression infrastructure. Internally this is implemented as a constant bytestring expression containing nothing but the marker to insert the path reference later. Logically it would be neater to have the expression itself expand directly to the right value itself, but for now we're evaluating these expressions before all the tree's paths have been constructed. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Implement labels within property values as bytestring expressionsDavid Gibson2014-03-031-10/+28
| | | | | | | | | This re-implements labels within property values as a form of bytestring expression. The grammar gets a little hairy to handle the fact that labels are allowed both at the beginning and end of property values without introducing parser conflicts. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Implement arrays as expressionsDavid Gibson2014-03-033-31/+89
| | | | | | | | | | | | | | | | This implements dtc's < ... > array syntax in terms of the new expression infrastructure. Internally this uses two operator types, one to convert an integer expression to a bytestring expression and another to append multiple bytestring expressions together. phandle references require some fiddling. These are implemented by using a constant bytestring expression containing a placeholder plus the marker to substitute in the correct phandle later. Logically it would be neater for an integer expression itself to expand to the right phandle value, but we can't do that just yet since the tree's phandle values aren't all resolved at the time we evaluate expressions. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Integrate /incbin/ with expanded expressionsDavid Gibson2014-03-033-41/+60
| | | | | | | | Implement /incbin/ as a new type of bytestring expression operator. This delays the evaluation of the /incbin/'s parameters until the evaluation of the /incbin/ itself. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Add string and bytestring expression typesDavid Gibson2014-03-034-16/+165
| | | | | | | | | | Both string and bytestring expression values are represented by a bytestring internally to handle things like "\0abc". So, the only real distinction is that string expressions must evaluate to a bytestring which has a \0 in the last bye. For now the only actual "expressions" of these types are literals, but we'll expand on that later. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Add type information to expression treesDavid Gibson2014-03-033-25/+123
| | | | | | | | | This implements a rudimentary dynamic typing system for dtc expressions, laying the groundwork for expressions of multiple types (e.g. string, bytestring). For now, we don't actually implement any types beyond integer, though. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Add srcpos information to expressionsDavid Gibson2014-03-033-42/+58
| | | | | | | | This patch allows information about source locations to be attached to expression structures. We'll need this information later on in order to provide reasonable error messages. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* First cut at expression treesDavid Gibson2014-03-034-76/+321
| | | | | | | | | | | | | At the moment, the integer expressions supported by dtc are always constant expressions, and are evaluated as we parse. That's nice and simple but limits us in a number of ways. It makes named constants awkward to implement and user defined functions more or less impossible. As a first step to allowing more possibilities, create the structures we need to represent expressions at runtime. For now we just construct them in the parser, then immediately evaluate, but one thing at a time. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Update source code location for dtc in manual.txtHeinrich Schuchardt2014-03-031-12/+10
| | | | | | | | The information about the location of the source code of the device tree compiler was inaccurate. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Remove duplicate assignmentHeinrich Schuchardt2014-03-031-1/+0
| | | | Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* Consistently use xrealloc instead of reallocHeinrich Schuchardt2014-03-031-6/+1
| | | | | | | | fdtput.c: Replace the remaining call to realloc by xrealloc. Some redundant lines in encode_value can be saved. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* Remove dead code in util.cHeinrich Schuchardt2014-03-021-4/+0
| | | | | | xrealloc never returns null Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* Remove references to unused DT_BASE tokenDavid Gibson2014-02-151-2/+0
| | | | | | Also remove the cbase bison union member that was only used for it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Add a README file for dtc and libfdtGrant Likely2014-02-121-0/+20
| | | | | | | Add a README file to document the location of the mailing list, the home page and state who the maintainers are. Signed-off-by: Grant Likely <grant.likely@linaro.org>
* Makefile: add a make "dist" targetFlorian Fainelli2014-02-041-0/+5
| | | | | | | | | make dist can be used to produce tarballs directly from the git repository, which can be useful to automate the release process as well as shipping custom releases. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: fix some more -Wshadow warningsFlorian Fainelli2014-02-014-17/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Building on a RHEL6 system produced the following -Wshadow warnings in fstree.c, util.c and checks.c: cc1: warnings being treated as errors checks.c: In function 'parse_checks_option': checks.c:709: error: declaration of 'optarg' shadows a global declaration /usr/include/getopt.h:59: error: shadowed declaration is here make[1]: *** [checks.o] Error 1 make[1]: *** Waiting for unfinished jobs.... make[1]: *** Waiting for unfinished jobs.... cc1: warnings being treated as errors fstree.c: In function 'read_fstree': fstree.c:40: error: declaration of 'tmpnam' shadows a global declaration /usr/include/stdio.h:208: error: shadowed declaration is here make[1]: *** [fstree.o] Error 1 cc1: warnings being treated as errors util.c: In function 'xstrdup': util.c:42: error: declaration of 'dup' shadows a global declaration /usr/include/unistd.h:528: error: shadowed declaration is here Fix all of these -Wshadow warnings by using slightly different variable names which won't collide with anything else. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
* Makefile: enable -Wshadow by defaultFlorian Fainelli2014-01-251-1/+1
| | | | | | | Now that all -Wshadow build warnings/errors are fixed, turn on -Wshadow by default to make sure we would catch new potential shadow warnings. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
* libfdt: avoid shadowing "err" in FDT_RW_CHECK_HEADERFlorian Fainelli2014-01-251-3/+3
| | | | | | | | | | | | | | | | | | | | | | | FDT_RW_CHECK_HEADER declares an internal variable named "err" which is far too generic and will produce the following -Wshadow warnings: libfdt/fdt_rw.c: In function 'fdt_add_mem_rsv': libfdt/fdt_rw.c:177:2: error: declaration of 'err' shadows a previous local [-Werror=shadow] libfdt/fdt_rw.c:175:6: error: shadowed declaration is here [-Werror=shadow] libfdt/fdt_rw.c: In function 'fdt_del_mem_rsv': libfdt/fdt_rw.c:194:2: error: declaration of 'err' shadows a previous local [-Werror=shadow] libfdt/fdt_rw.c:192:6: error: shadowed declaration is here [-Werror=shadow] libfdt/fdt_rw.c: In function 'fdt_set_name': ... Since this variable is only used internally in the macro, rename to __err which should be prefixed enough not to cause new shadow warnings. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
* libfdt: avoid shadowing "err" in FDT_CHECK_HEADERFlorian Fainelli2014-01-251-3/+3
| | | | | | | | | | | | | | | | | FDT_CHECK_HEADER declares an internal variable named "err" whose name is far too generic and will produce the following -Wshadow warnings: libfdt/fdt_ro.c: In function 'fdt_node_offset_by_compatible': libfdt/fdt_ro.c:555:2: error: declaration of 'err' shadows a previous local [-Werror=shadow] libfdt/fdt_ro.c:553:14: error: shadowed declaration is here [-Werror=shadow] cc1: all warnings being treated as errors Since this variable is only used internally in the macro, rename to __err which should be prefixed enough not to cause new shadow warnings. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
* dtc: avoid shadowing dirname()Florian Fainelli2014-01-251-2/+2
| | | | | | | | | | | | | | | | | | | | | dirname() is declared as a function, and later on try_open() another variable dirname is used, which shadows the dirname() function declaration and will produce the following warnings/errors with -Wshadow turned on: srcpos.c: In function 'try_open': srcpos.c:71:35: error: declaration of 'dirname' shadows a global declaration [-Werror=shadow] srcpos.c:37:14: error: shadowed declaration is here [-Werror=shadow] srcpos.c: In function 'srcfile_add_search_path': srcpos.c:183:42: error: declaration of 'dirname' shadows a global declaration [-Werror=shadow] srcpos.c:37:14: error: shadowed declaration is here [-Werror=shadow] cc1: all warnings being treated as errors Fix this by renaming the function dirname() to get_dirname(). Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
* Clean up parser error messagesDavid Gibson2014-01-041-26/+18
| | | | | | | | Generally edit parser error messages for brevity and clarity. Replace the print_error() function with a a new macro for brevity and clarity in the source. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Correct locations in parser error messaesDavid Gibson2014-01-041-14/+12
| | | | | | | | | | | | | | | | The print_error() function used in several places in the parser uses the location information in yylloc to describe the location of the error. This is not correct in most cases. yylloc gives the location of the lookahead token, whereas the error is generally associated with one of the already parsed non-terminals. This patch corrects this, adding a location parameter to print_error() and supplying it with the appropriate bison @N symbols. This probably breaks yacc compatiblity, but too bad - accurate error messages are more important. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Die on failed /incbin/ seeksDavid Gibson2014-01-041-4/+3
| | | | | | | | | | | | | Failing to open an input file, with /include/ or /incbin/ is treated as immediately fatal inside srcfile_relative_open(). However, filing to seek() to the requested offset in an /incbin/ is not. This is a bit oddly inconsistent, and leaves us with a strange case that's awkward to deal with down the line. So, get rid of it and have failed seeks on an /incbin/ be immediately fatal. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Move character literal processing to the lexerDavid Gibson2014-01-042-36/+18
| | | | | | | | | | | | To match the processing of integer literals, character literals are passed as a string from lexer to parser then interpreted there. This is just as awkward as it was for integer literals, without the excuse that we used to need the information about the dts version to process them correctly. So, move character literal processing back to the lexer as well, cleaning things up. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Move integer literal processing back to the lexerDavid Gibson2014-01-032-34/+38
| | | | | | | | | | | | | | | | | | At the moment integer literals are passed from the lexer to the parser as a string, where it's evaluated into an integer by eval_literal(). That strange approach happened because we needed to know whether we were processing dts-v0 or dts-v1 - only known at the parser level - to know how to interpret the literal properly. dts-v0 support has been gone for some time now, and the base and bits parameters to eval_literal() are essentially useless. So, clean things up by moving the literal interpretation back to the lexer. This also introduces a new lexical_error() function to report malformed literals and set the treesource_error flag so that they'll cause a parse failure at the top level. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Make srcpos_{v,}error() more widely usefulDavid Gibson2014-01-013-11/+13
| | | | | | | Allow them to take a prefix argument giving the general type of error, which will be useful in future. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Fix memory leak in srcpos_verror()David Gibson2014-01-011-1/+3
| | | | | | | | Since dtc runs are short, we don't care that much about memory leaks. Still, leaking the source position string every time we print an error messages is pretty nasty. Fix it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Fix indentation of srcpos_verror()David Gibson2014-01-011-5/+5
| | | | | | | Somehow this function ended up with a 7 space indent, instead of the usual 8 space (1 tab) indent. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Fix typo in type of srcpos_verror() et al.David Gibson2014-01-012-4/+4
| | | | | | | The srcpos_verror() and srcpos_error() functions declare the format string as 'char const *' instead of 'const char *'. Fix it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Remove unused srcpos_warn() functionDavid Gibson2014-01-012-19/+0
| | | | | | This function has no users, and we can replace it more generally later. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Fix valgrind errors in sw_tree1David Gibson2013-12-312-5/+26
| | | | | | | | | | | | | | | The sw_tree1 testcase has accumulated some valgrind errors, at least in the "realloc" mode. * It had both a realloc_fdt() and explicit xmalloc() for the initial allocation which was redundant and caused errors. * It doesn't make sense to call fdt_resize() until after we've created the initial stub tree * Alignment gaps inserted into the tree contain uninitialized data, which trips an error when we write it out. We could zero the buffer, but that would make it easier to miss real bugs, so we add suppressions for the valgrind warnings instead. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Add option to run_tests.sh to stop immediately on a failing testDavid Gibson2013-12-301-1/+8
| | | | | | | This is a debugging convenience option, which makes it much easier to find the failing tests and fix them one by one. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Pass 'unsigned char' type to isdigit()/isspace()/isprint() functionsSerge Lamikhov-Center2013-12-253-5/+5
| | | | | | | | | | | | | | | | | | | | The isdigit(), isprint(), etc. functions take an int, whose value is required to be in the range of an _unsigned_ char, or EOF. This, horribly, means that systems which have a signed char by default need casts to pass a char variable safely to these functions. We can't do this more nicely by making the variables themselves 'unsigned char *' because then we'll get warnings passing them to the strchr() etc. functions. At least the cygwin version of these functions, are designed to generate warnings if this isn't done, as explained by this comment from ctype.h: These macros are intentionally written in a manner that will trigger a gcc -Wall warning if the user mistakenly passes a 'char' instead of an int containing an 'unsigned char'. Signed-off-by: Serge Lamikhov-Center <Serge.Lamikhov@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Use stdbool more widelyDavid Gibson2013-10-2812-37/+39
| | | | | | | | We already use the C99 bool type from stdbool.h in a few places. However there are many other places we represent boolean values as plain ints. This patch changes that. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* libfdt: Add function to resize the buffer for a sequential write treeDavid Gibson2013-10-264-8/+114
| | | | | | | | At present, when using sequential write mode, there's no straightforward means of resizing the buffer the fdt is being built into. This patch adds an fdt_resize() function for this purpose. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* util: Fix out of bounds memory accessSerge Lamikhov-Center2013-10-011-1/+1
| | | | | | The change also fixes numeric values output produced by fdtdump. Signed-off-by: Serge Lamikhov-Center <Serge.Lamikhov@gmail.com>
* Ensure all tests have matching reg and unit addressStephen Warren2013-09-2019-1/+120
| | | | | | | | | | | | | ePAPR 1.1 section 2.2.1.1 "Node Name Requirements" specifies that any node that has a reg property must include a unit address in its name with value matching the first entry in its reg property. Conversely, if a node does not have a reg property, the node name must not include a unit address. Adjust all the dtc test-cases to conform to this rule. Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Makefile: provide separate install targetsDavid Gibson2013-08-151-2/+10
| | | | | | | | | | | | Currently `make install` will install the binaries, libraries and includes. This change separates the install target into install-bin, install-lib and install-includes, so we have more flexibility, particularly when we're just using libfdt. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Tag Version 1.4.0v1.4.0Jon Loeliger2013-06-221-1/+1
| | | | Signed-off-by: Jon Loeliger <jdl@jdl.com>
* dtc: ensure #line directives don't consume data from the next lineStephen Warren2013-06-032-1/+11
| | | | | | | | | | | | | | | | | | | | | | Previously, the #line parsing regex ended with ({WS}+[0-9]+)?. The {WS} could match line-break characters. If the #line directive did not contain the optional flags field at the end, this could cause any integer data on the next line to be consumed as part of the #line directive parsing. This could cause syntax errors (i.e. #line parsing consuming the leading 0 from a hex literal 0x1234, leaving x1234 to be parsed as cell data, which is a syntax error), or invalid compilation results (i.e. simply consuming literal 1234 as part of the #line processing, thus removing it from the cell data). Fix this by replacing {WS} with [ \t] so that it can't match line-breaks. Convert all instances of {WS}, even though the other instances should be irrelevant for any well-formed #line directive. This is done for consistency and ultimate safety. Reported-by: Ian Campbell <Ian.Campbell@citrix.com> Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
* Add missing test binary to .gitignoreDavid Gibson2013-05-291-0/+1
| | | | | | The subnode_iterate test binary was missing from .gitignore, this fixes it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* fdtput: expand fdt if value does not fitSrinivas Kandagatla2013-05-292-15/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If you try to insert a new node or extend a property with large value, using fdtput you will notice that it always fails. example: fdtput -v -p -ts ./tst.dtb "/node-1" "property-1" "value-1 Error at 'node-1': FDT_ERR_NOSPACE or fdtput -v -c ./tst.dtb "/node-1" Error at 'node-1': FDT_ERR_NOSPACE or fdtput -v -ts ./tst.dtb "/node" "property" "very big value" Decoding value: string: 'very big value' Value size 15 Error at 'property': FDT_ERR_NOSPACE All these error are returned from libfdt, as the size of the fdt passed has no space to accomdate these new properties. This patch adds realloc functions in fdtput to allocate new space in fdt when it detects a shortage in space for new value or node. With this patch, fdtput can insert a new node or property or extend a property with new value greater than original size. Also it packs the final blob to clean up any extra padding. Without this patch fdtput tool complains with FDT_ERR_NOSPACE when we try to add a node/property or extend the value of a property. Testcases for the new behaviour added by David Gibson. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Remove some tests for misfeaturesDavid Gibson2013-05-291-4/+0
| | | | | | | | | There are a couple of fdtput related tests which are rather pointless - they explicitly test for the presence of an undesirable limitation in fdtput, which will cause test failures when we fix it. This patch removes the tests. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Use shorten_echo for wrap_testsDavid Gibson2013-05-291-1/+1
| | | | | | | | | | We have certain tests which generate extremely long command lines, which are shortened in the testsuite output with the 'shorten_echo' function. Currently that is used in run_fdtput_test and run_wrap_test, this patch uses it for run_wrap_test as well, allowing more general tests with long command lines. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* fdtdump: add a debug modeMike Frysinger2013-05-241-4/+37
| | | | | | | | When hacking raw fdt files, it's useful to know the actual offsets into the file each node appears. Add a --debug mode that includes this. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* util: add common ARRAY_SIZE defineMike Frysinger2013-05-243-3/+2
| | | | | | | | I want to use this in more places, so put it in util.h rather than copying & pasting it into another file. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* util: drop "long" from usage helpersMike Frysinger2013-05-247-24/+24
| | | | | | | | Now that all utils have converted to the new usage framework, we can rename to just plain "usage()" and avoid naming conflicts. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc/fdt{get, put}/convert-dtsv0-lexer: convert to new usage helpersMike Frysinger2013-05-245-127/+131
| | | | | | | | | | This helps standardize the flag processing and the usage screens. Only lightly tested; would be great if someone who uses these utils could double check. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>