From: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
To: Devicetree Discuss
<devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org>
Subject: [PATCH 2/5] fdtput: Prepare to support multiple operations
Date: Tue, 10 Jul 2012 05:56:45 -0700 [thread overview]
Message-ID: <1341925008-10627-2-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1341925008-10627-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
We want to add new options to this tool. In preparation for this, add
the concept of a current operation.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
fdtput.c | 37 ++++++++++++++++++++++++++-----------
1 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/fdtput.c b/fdtput.c
index 244d1f1..eceb7f2 100644
--- a/fdtput.c
+++ b/fdtput.c
@@ -28,7 +28,13 @@
#include "util.h"
+/* These are the operations we support */
+enum operation_t {
+ OPER_WRITE_PROP, /* Write a property in a node */
+};
+
struct display_info {
+ enum operation_t oper; /* operation to perform */
int type; /* data type (s/i/u/x or 0 for default) */
int size; /* data size (1/2/4) */
int verbose; /* verbose output */
@@ -143,13 +149,19 @@ static int do_fdtput(struct display_info *disp, const char *filename,
if (!blob)
return -1;
- /* convert the arguments into a single binary value, then store */
- assert(arg_count >= 2);
- if (encode_value(disp, arg + 2, arg_count - 2, &value, &len) ||
- store_key_value(blob, *arg, arg[1], value, len))
- ret = -1;
-
- if (!ret)
+ switch (disp->oper) {
+ case OPER_WRITE_PROP:
+ /*
+ * Convert the arguments into a single binary value, then
+ * store them into the property.
+ */
+ assert(arg_count >= 2);
+ if (encode_value(disp, arg + 2, arg_count - 2, &value, &len) ||
+ store_key_value(blob, *arg, arg[1], value, len))
+ ret = -1;
+ break;
+ }
+ if (ret >= 0)
ret = utilfdt_write(filename, blob);
free(blob);
@@ -185,6 +197,7 @@ int main(int argc, char *argv[])
memset(&disp, '\0', sizeof(disp));
disp.size = -1;
+ disp.oper = OPER_WRITE_PROP;
for (;;) {
int c = getopt(argc, argv, "ht:v");
if (c == -1)
@@ -224,10 +237,12 @@ int main(int argc, char *argv[])
argv += optind;
argc -= optind;
- if (argc < 1)
- usage("Missing node");
- if (argc < 2)
- usage("Missing property");
+ if (disp.oper == OPER_WRITE_PROP) {
+ if (argc < 1)
+ usage("Missing node");
+ if (argc < 2)
+ usage("Missing property");
+ }
if (do_fdtput(&disp, filename, argv, argc))
return 1;
--
1.7.7.3
next prev parent reply other threads:[~2012-07-10 12:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-10 12:56 [PATCH 1/5] fdtput: Fix nit in help message Simon Glass
[not found] ` <1341925008-10627-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-07-10 12:56 ` Simon Glass [this message]
[not found] ` <1341925008-10627-2-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-07-12 12:37 ` [PATCH 2/5] fdtput: Prepare to support multiple operations David Gibson
[not found] ` <20120712123745.GB11326-MK4v0fQdeXQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2012-07-12 15:49 ` Simon Glass
2012-07-10 12:56 ` [PATCH 3/5] fdtput: Add -c option to create nodes Simon Glass
[not found] ` <1341925008-10627-3-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-07-12 12:39 ` David Gibson
2012-07-10 12:56 ` [PATCH 4/5] fdtput: Adjust report_error() to use name, namelen params Simon Glass
[not found] ` <1341925008-10627-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-07-12 12:40 ` David Gibson
2012-07-10 12:56 ` [PATCH 5/5] fdtput: Add -p option to create subnodes along entire path Simon Glass
2012-07-11 0:11 ` [PATCH 1/5] fdtput: Fix nit in help message David Gibson
[not found] ` <20120711001124.GA6652-MK4v0fQdeXQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2012-07-11 14:40 ` 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=1341925008-10627-2-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).