From: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
To: Devicetree Discuss
<devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org>
Subject: [PATCH 4/4] fdtget: Add -d to provide a default value
Date: Fri, 2 Mar 2012 17:12:10 -0800 [thread overview]
Message-ID: <1330737130-29600-4-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1330737130-29600-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Sometimes the requested node or property is not present in the device
tree. This option provides a way of reporting a default value in this
case, rather than halting with an error.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
fdtget.c | 20 +++++++++++++++++---
tests/run_tests.sh | 6 ++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/fdtget.c b/fdtget.c
index 9ed5edd..5e87545 100644
--- a/fdtget.c
+++ b/fdtget.c
@@ -45,6 +45,7 @@ struct display_info {
int type; /* data type (s/i/u/x or 0 for default) */
int size; /* data size (1/2/4) */
enum display_mode mode; /* display mode that we are using */
+ const char *default_val; /* default value if node/property not found */
};
static void report_error(const char *where, int err)
@@ -225,6 +226,8 @@ static int show_data_for_item(const void *blob, struct display_info *disp,
err = -1;
else
printf("\n");
+ } else if (disp->default_val) {
+ puts(disp->default_val);
} else {
report_error(property, len);
err = -1;
@@ -258,8 +261,13 @@ static int do_fdtget(struct display_info *disp, const char *filename,
for (i = 0; i + args_per_step <= arg_count; i += args_per_step) {
node = fdt_path_offset(blob, arg[i]);
if (node < 0) {
- report_error(arg[i], node);
- return -1;
+ if (disp->default_val) {
+ puts(disp->default_val);
+ continue;
+ } else {
+ report_error(arg[i], node);
+ return -1;
+ }
}
prop = args_per_step == 1 ? NULL : arg[i + 1];
@@ -280,6 +288,8 @@ static const char *usage_msg =
"\t-t <type>\tType of data\n"
"\t-p\t\tList properties for each node\n"
"\t-l\t\tList children for each node\n"
+ "\t-d\t\tDefault value to display when the property is "
+ "missing\n"
"\t-h\t\tPrint this help\n\n"
USAGE_TYPE_MSG;
@@ -303,7 +313,7 @@ int main(int argc, char *argv[])
disp.size = -1;
disp.mode = MODE_SHOW_VALUE;
for (;;) {
- int c = getopt(argc, argv, "hlpt:");
+ int c = getopt(argc, argv, "d:hlpt:");
if (c == -1)
break;
@@ -327,6 +337,10 @@ int main(int argc, char *argv[])
disp.mode = MODE_LIST_CHILDREN;
args_per_step = 1;
break;
+
+ case 'd':
+ disp.default_val = optarg;
+ break;
}
}
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index ac6fa17..deffae3 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -478,6 +478,12 @@ fdtget_tests () {
# Test multiple arguments
run_fdtget_test "MyBoardName\nmemory" -ts $dtb / model /memory device_type
+
+ # Test defaults
+ run_wrap_error_test $DTGET -tx $dtb /randomnode doctor-who
+ run_fdtget_test "<the dead silence>" -tx \
+ -d "<the dead silence>" $dtb /randomnode doctor-who
+ run_fdtget_test "<blink>" -tx -d "<blink>" $dtb /memory doctor-who
}
fdtput_tests () {
--
1.7.7.3
next prev parent reply other threads:[~2012-03-03 1:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-03 1:12 [PATCH 1/4] fdtget: Fix multiple arg bug and add test for it Simon Glass
[not found] ` <1330737130-29600-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-03-03 1:12 ` [PATCH 2/4] fdtget: Add -p to list the properties of a node Simon Glass
[not found] ` <1330737130-29600-2-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-03-06 2:22 ` David Gibson
2012-03-07 19:27 ` Jon Loeliger
[not found] ` <E1S5MWl-000880-59-CYoMK+44s/E@public.gmane.org>
2012-03-07 23:38 ` David Gibson
[not found] ` <20120307233853.GN1929-MK4v0fQdeXQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2012-03-08 1:25 ` Jon Loeliger
[not found] ` <E1S5S6J-0001jL-27-CYoMK+44s/E@public.gmane.org>
2012-03-08 1:31 ` David Gibson
2012-03-03 1:12 ` [PATCH 3/4] fdtget: Add -l to list the children " Simon Glass
[not found] ` <1330737130-29600-3-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-03-06 2:23 ` David Gibson
[not found] ` <20120306022323.GC12818-MK4v0fQdeXQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2012-03-07 0:37 ` Simon Glass
2012-03-07 19:27 ` Jon Loeliger
2012-03-03 1:12 ` Simon Glass [this message]
[not found] ` <1330737130-29600-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-03-06 2:23 ` [PATCH 4/4] fdtget: Add -d to provide a default value David Gibson
2012-03-07 19:28 ` Jon Loeliger
2012-03-06 2:21 ` [PATCH 1/4] fdtget: Fix multiple arg bug and add test for it David Gibson
2012-03-07 19:27 ` Jon Loeliger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1330737130-29600-4-git-send-email-sjg@chromium.org \
--to=sjg-f7+t8e8rja9g9huczpvpmw@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).