linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* libfdt: going forward for u-boot
@ 2007-03-22  0:08 Jerry Van Baren
  2007-03-22  0:49 ` David Gibson
  0 siblings, 1 reply; 9+ messages in thread
From: Jerry Van Baren @ 2007-03-22  0:08 UTC (permalink / raw)
  To: linuxppc-dev

[-- 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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-03-23  4:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-22  0:08 libfdt: going forward for u-boot Jerry Van Baren
2007-03-22  0:49 ` 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

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).