linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Jerry Van Baren <gerald.vanbaren@comcast.net>
To: linuxppc-dev@ozlabs.org
Subject: libfdt: going forward for u-boot
Date: Wed, 21 Mar 2007 20:08:23 -0400	[thread overview]
Message-ID: <4601C8F7.5060006@comcast.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 2900 bytes --]

Hi David,

I'm using libfdt in u-boot and getting close to pushing u-boot changes 
upstream.  I'm curious what libfdt's legal status is WRT dual licensing 
and the legal dogs you've unleashed.

One thought that occurred to me since we last discussed this is to 
relicense it LGPL.  That way it could be linked into proprietary code 
without having to maintain a dual license and the copyright assignment 
headaches that come with outside contributors.

I made some trivial changes to fdt.h and libfdt_env.h to allow libfdt to 
compiler both on linux and for u-boot.  I've attached a patch since it 
_is_ trivial.

Here is the thumbnail sketch of my current changes to use libfdt in u-boot:

Makefile
--------
* Replaced with a u-boot version, unavoidable.

fdt.h
-----
* See attached patchfile for trivial change to allow compiling under
     linux and u-boot.

libfdt_env.h
------------
* See attached patchfile for change to allow compiling under linux
     and u-boot.
* #include <asm/byteorder.h> which gives us direct byteswapping
     utilities without having to do a #if __BYTE_ORDER == __BIG_ENDIAN
#define fdt32_to_cpu(x)                (__be32_to_cpu(x))
#define cpu_to_fdt32(x)                (__cpu_to_be32(x))
#define fdt64_to_cpu(x)                (__be64_to_cpu(x))
#define cpu_to_fdt64(x)                (__cpu_to_be32(x))
    (could change the source to use __be32_to_cpu(x) and friends, but
    I was too lazy to do this).

fdt_ro.c
--------
* Added comments as I figured out how things worked... ;-)
* Added a new function to allow me to step through tags, which I needed
     to recursively print the tree/subtree.  This returns a pointer to
     the name of the next node/property (if appropriate) via **namep.
     The caller can then use the node type (return value) and the string
     to print the property or follow the node.

uint32_t fdt_next_tag(const void *fdt, int offset,
                       int *nextoffset, char **namep);

     *This is the only thing I would consider non-trivial, and that is
     seriously debatable since it is mostly a copy of _fdt_next_tag()*

     Not done: because I protected namep against NULL, the existing
     _fdt_next_tag() could be trivially rewritten to be:
     fdt_next_tag(fdt, offset, nextoffset, NULL);

* Added a (void *) typecast to the fdt_getprop() return value to get rid
     of a compiler warning.

fdt_rw.c
--------
* Nonessential improvements to fdt_open_into()
   * Validate the header (fdt_move() does the validation, but I skip
       the move if buf == fdt so I needed to add the validation)
   * Do the fdt_move() only if (buf != fdt) - I call this at times with
       a new (longer) length but don't want to actually move the blob,
       just want the longer length so I can modify the fdt in-place.  The
       current code works, but it seemed silly to do a move if I'm not
       actually moving it.

gvb

[-- Attachment #2: 0001-Use-a-common-header-set-linux-u-boot.txt --]
[-- Type: text/plain, Size: 1783 bytes --]

>From 6772dfdf27e153d0698f7fbecff767417ae76eab Mon Sep 17 00:00:00 2001
From: Gerald Van Baren <vanbaren@cideas.com>
Date: Wed, 21 Mar 2007 19:40:38 -0400
Subject: [PATCH] Use a common header set linux/u-boot

Using the "right" header files along with the __KERNEL__ discriminator
allows libfdt to be compiled under linux (userland) or u-boot.  It
also simplifies the byteswap #defines.

Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
---
 fdt.h        |    4 ++++
 libfdt_env.h |   21 +++++++++------------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/fdt.h b/fdt.h
index 4687a31..64507a9 100644
--- a/fdt.h
+++ b/fdt.h
@@ -3,7 +3,11 @@
 
 #ifndef __ASSEMBLY__
 
+#ifndef __KERNEL__
 #include <stdint.h>
+#else
+#include <linux/types.h>
+#endif
 
 struct fdt_header {
 	uint32_t magic;                  /* magic word FDT_MAGIC */
diff --git a/libfdt_env.h b/libfdt_env.h
index 59f2536..dc6562e 100644
--- a/libfdt_env.h
+++ b/libfdt_env.h
@@ -2,21 +2,18 @@
 #define _LIBFDT_ENV_H
 
 #include <stddef.h>
+#ifndef __KERNEL__
 #include <stdint.h>
 #include <string.h>
-#include <endian.h>
-#include <byteswap.h>
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define fdt32_to_cpu(x)		(x)
-#define cpu_to_fdt32(x)		(x)
-#define fdt64_to_cpu(x)		(x)
-#define cpu_to_fdt64(x)		(x)
 #else
-#define fdt32_to_cpu(x)		(bswap_32((x)))
-#define cpu_to_fdt32(x)		(bswap_32((x)))
-#define fdt64_to_cpu(x)		(bswap_64((x)))
-#define cpu_to_fdt64(x)		(bswap_64((x)))
+#include <linux/types.h>
+#include <linux/string.h>
 #endif
+#include <asm/byteorder.h>
+
+#define fdt32_to_cpu(x)		(__be32_to_cpu(x))
+#define cpu_to_fdt32(x)		(__cpu_to_be32(x))
+#define fdt64_to_cpu(x)		(__be64_to_cpu(x))
+#define cpu_to_fdt64(x)		(__cpu_to_be32(x))
 
 #endif /* _LIBFDT_ENV_H */
-- 
1.4.4.4


             reply	other threads:[~2007-03-22  0:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-22  0:08 Jerry Van Baren [this message]
2007-03-22  0:49 ` libfdt: going forward for u-boot David Gibson
2007-03-22  1:12   ` Jerry Van Baren
2007-03-22  1:25     ` David Gibson
2007-03-22  1:37       ` Jerry Van Baren
2007-03-22  1:49         ` David Gibson
2007-03-22 11:16   ` Segher Boessenkool
2007-03-22 16:42   ` Hollis Blanchard
2007-03-23  4:17     ` David Gibson

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=4601C8F7.5060006@comcast.net \
    --to=gerald.vanbaren@comcast.net \
    --cc=linuxppc-dev@ozlabs.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).