Skip to contentSkip to conversation

[6064] Implement device tree support needed for Bamboo emulation

Qemu-devel Aurelien Jarno 8 participants 11 messages Dec 16, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

Revision: 6064

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6064
Author:   aurel32
Date:     2008-12-16 10:43:48 +0000 (Tue, 16 Dec 2008)

Log Message:
-----------
Implement device tree support needed for Bamboo emulation

To implement the -kernel, -initrd, and -append options, 4xx board emulation must load the guest kernel as if firmware had loaded it. Where u-boot would be the firmware, we must load the flat device tree into memory and set key fields such as /chosen/bootargs.

This patch introduces a dependency on libfdt for flat device tree support.

Modified Paths:
--------------
trunk/Makefile.target
trunk/configure

Added Paths:
-----------
trunk/device_tree.c
trunk/device_tree.h
trunk/libfdt_env.h

Modified: trunk/Makefile.target
===================================================================

Makefile.target +4 -0
@@ -655,6 +655,10 @@
 OBJS+= unin_pci.o ppc_chrp.o
 # PowerPC 4xx boards
 OBJS+= pflash_cfi02.o ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
+ifdef FDT_LIBS
+OBJS+= device_tree.o
+LIBS+= $(FDT_LIBS)
+endif
 # virtio support
 OBJS+= virtio.o virtio-blk.o virtio-balloon.o
 endif

Modified: trunk/configure
===================================================================

configure +18 -0
@@ -119,6 +119,7 @@
 kerneldir=""
 aix="no"
 blobs="yes"
+fdt="yes"
 
 # OS specific
 targetos=`uname -s`
@@ -966,6 +967,18 @@
   iovec=yes
 fi
 
+##########################################
+# fdt probe
+if test "$fdt" = "yes" ; then
+    fdt=no
+    cat > $TMPC << EOF
+int main(void) { return 0; }
+EOF
+  if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $TMPC -lfdt 2> /dev/null ; then
+    fdt=yes
+  fi
+fi
+
 # Check if tools are available to build documentation.
 if [ -x "`which texi2html 2>/dev/null`" ] && \
    [ -x "`which pod2man 2>/dev/null`" ]; then
@@ -1061,6 +1074,7 @@
 echo "AIO support       $aio"
 echo "Install blobs     $blobs"
 echo "KVM support       $kvm"
+echo "fdt support       $fdt"
 
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -1350,6 +1364,10 @@
 if test "$iovec" = "yes" ; then
   echo "#define HAVE_IOVEC 1" >> $config_h
 fi
+if test "$fdt" = "yes" ; then
+  echo "#define HAVE_FDT 1" >> $config_h
+  echo "FDT_LIBS=-lfdt" >> $config_mak
+fi
 
 # XXX: suppress that
 if [ "$bsd" = "yes" ] ; then

Added: trunk/device_tree.c
===================================================================

device_tree.c +114 -0

114 lines not on this page · raw message

Added: trunk/device_tree.h
===================================================================

device_tree.h +26 -0
@@ -0,0 +1,26 @@
+/*
+ * Header with function prototypes to help device tree manipulation using
+ * libfdt. It also provides functions to read entries from device tree proc
+ * interface.
+ *
+ * Copyright 2008 IBM Corporation.
+ * Authors: Jerone Young <[email protected]>
+ *          Hollis Blanchard <[email protected]>
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#ifndef __DEVICE_TREE_H__
+#define __DEVICE_TREE_H__
+
+void *load_device_tree(const char *filename_path, void *load_addr);
+
+int qemu_devtree_setprop(void *fdt, const char *node_path,
+                         const char *property, uint32_t *val_array, int size);
+int qemu_devtree_setprop_cell(void *fdt, const char *node_path,
+                              const char *property, uint32_t val);
+int qemu_devtree_setprop_string(void *fdt, const char *node_path,
+                                const char *property, const char *string);
+
+#endif /* __DEVICE_TREE_H__ */

Added: trunk/libfdt_env.h
===================================================================

libfdt_env.h +41 -0

41 lines not on this page · raw message

#1 lore raw
Quoted 4 lines

To implement the -kernel, -initrd, and -append options, 4xx board emulation must load the guest kernel as if firmware had loaded it. Where u-boot would be the firmware, we must load the flat device tree into memory and set key fields such as /chosen/bootargs.

Then why is it optional?

Quoted 1 line

This patch introduces a dependency on libfdt for flat device tree support.

I don't like the way this is done.

AFAIK libfdt isn't present in any of the major distros. I thought the conclusion was that we should import libfdt into qemu.

Certainly adding libfdt_env.h, which is never used, seems very wrong. I'm pretty sure this won't build on win32 either.

Paul

#2 lore raw
Quoted 6 lines · Paul Brook
Quoted 4 lines

To implement the -kernel, -initrd, and -append options, 4xx board emulation must load the guest kernel as if firmware had loaded it. Where u-boot would be the firmware, we must load the flat device tree into memory and set key fields such as /chosen/bootargs.

Then why is it optional?

As you mention below, libfdt isn't generally available yet, and since it's possible to make a real firmware work in this environment (in which case -kernel isn't needed), the code can still be useful.

If you'd prefer to make libfdt mandatory, I'm fine with that.

Quoted 6 lines
Quoted 1 line

This patch introduces a dependency on libfdt for flat device tree support.

I don't like the way this is done.

AFAIK libfdt isn't present in any of the major distros. I thought the conclusion was that we should import libfdt into qemu.

That was our conclusion, but Anthony never agreed.

FWIW, I have requested that Fedora and Debian package libfdt, and they agreed in principle, but it's still missing in Fedora 10 for example.

Is the existence of distribution packages a requirement for use, or should we say "install it by hand into /usr/local"? If it is a requirement, which versions of which distributions?

Quoted 2 lines

Certainly adding libfdt_env.h, which is never used, seems very wrong. I'm pretty sure this won't build on win32 either.

Oops, that was a holdover from when we *were* importing libfdt source. I can remove that, or if we want to import a copy of libfdt, I can leave it.

I doubt anyone has tried to build libfdt on Windows...

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#3 lore raw
Quoted 2 lines · Hollis Blanchard

If you'd prefer to make libfdt mandatory, I'm fine with that.

No, it shouldn't be mandatory :-)

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

This patch introduces a dependency on libfdt for flat device tree support.

I don't like the way this is done.

AFAIK libfdt isn't present in any of the major distros. I thought the conclusion was that we should import libfdt into qemu.

That was our conclusion, but Anthony never agreed.

Because it's better to let the distros maintain this. That way, they can deal with security issues, etc.

Quoted 3 lines

FWIW, I have requested that Fedora and Debian package libfdt, and they agreed in principle, but it's still missing in Fedora 10 for example.

As long as it's heading toward distros, it should be fine. If we decide to use libfdt for core QEMU functionality (like config file), we should revisit this though.

Regards,

Anthony Liguori

#4 lore raw
Quoted 10 lines · Anthony Liguori
Quoted 1 line · Hollis Blanchard

If you'd prefer to make libfdt mandatory, I'm fine with that.

No, it shouldn't be mandatory :-)

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

This patch introduces a dependency on libfdt for flat device tree support.

I don't like the way this is done.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

AFAIK libfdt isn't present in any of the major distros. I thought the conclusion was that we should import libfdt into qemu.

That was our conclusion, but Anthony never agreed.

Because it's better to let the distros maintain this. That way, they
can deal with security issues, etc.

That's fine in theory. In practice it means we can't realistically use libfdt for anything important for at least another 12 months or so. I'm also rather sceptical about the stability of the libfdt API.

Quoted 6 lines
Quoted 2 lines

FWIW, I have requested that Fedora and Debian package libfdt, and they agreed in principle, but it's still missing in Fedora 10 for example.

As long as it's heading toward distros, it should be fine. If we decide to use libfdt for core QEMU functionality (like config file), we should revisit this though.

That's likely to happen fairly soon. And IIUC it's already fairly critical for the new PPC boards.

Paul

#5 lore raw
Quoted 16 lines · Paul Brook
Quoted 15 lines · Anthony Liguori
Quoted 1 line · Hollis Blanchard

If you'd prefer to make libfdt mandatory, I'm fine with that.

No, it shouldn't be mandatory :-)

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

This patch introduces a dependency on libfdt for flat device tree support.

I don't like the way this is done.

AFAIK libfdt isn't present in any of the major distros. I thought the conclusion was that we should import libfdt into qemu.

That was our conclusion, but Anthony never agreed.

Quoted 7 lines
Quoted 2 lines

Because it's better to let the distros maintain this. That way, they
can deal with security issues, etc.

That's fine in theory. In practice it means we can't realistically use libfdt
for anything important for at least another 12 months or so. I'm also rather sceptical about the stability of the libfdt API.

I also vote for importing libfdt for now, it should be useful for Sparc too.

If one day the major distros (think also about BSDs, Solaris etc.) have libfdt, we can remove ours.

#6 lore raw
In reply to Paul Brook
Quoted 14 lines · Paul Brook
Quoted 13 lines · Anthony Liguori
Quoted 1 line · Hollis Blanchard

If you'd prefer to make libfdt mandatory, I'm fine with that.

No, it shouldn't be mandatory :-)

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

This patch introduces a dependency on libfdt for flat device tree support.

I don't like the way this is done.

AFAIK libfdt isn't present in any of the major distros. I thought the conclusion was that we should import libfdt into qemu.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

That was our conclusion, but Anthony never agreed.

Because it's better to let the distros maintain this. That way, they
can deal with security issues, etc.

That's fine in theory. In practice it means we can't realistically use libfdt for anything important for at least another 12 months or so. I'm also rather sceptical about the stability of the libfdt API.

An approach commonly taken is to try to link against a system-provided (dynamic) library, and fall back to the in-tree version if this fails. (This assumes a system will only provide libfdt once its API/ABI is stable enough.)

Thiemo

#7 lore raw
In reply to Hollis Blanchard
Quoted 7 lines
Quoted 1 line

Then why is it optional?

As you mention below, libfdt isn't generally available yet, and since it's possible to make a real firmware work in this environment (in which case -kernel isn't needed), the code can still be useful.

If you'd prefer to make libfdt mandatory, I'm fine with that.

Well, from your description it sounds like your ppc bits are fairly useless without it. History has shown that if it's possible for people to build something incorrectly, they usually will. Even more so if the required libraries are even vaguely standard.

Quoted 11 lines
Quoted 2 lines

AFAIK libfdt isn't present in any of the major distros. I thought the conclusion was that we should import libfdt into qemu.

That was our conclusion, but Anthony never agreed.

FWIW, I have requested that Fedora and Debian package libfdt, and they agreed in principle, but it's still missing in Fedora 10 for example.

Is the existence of distribution packages a requirement for use, or should we say "install it by hand into /usr/local"? If it is a requirement, which versions of which distributions?

I'm extremely reluctant to require an external library that everyone has to go fetch and build themselves. IIRC The libfdt docs say it's expected that people will include it in their projects.

I can say from experience that it drops in pretty easily. It's a 4-line qemu patch, plus make libfdt_env.h use the qemu byteswap routines.

Quoted 1 line

I doubt anyone has tried to build libfdt on Windows...

I have (well, technically a cross build from linux, but same difference).

Makefile +5 -1
Index: Makefile
===================================================================
@@ -5,7 +5,7 @@ include config-host.mak
 .PHONY: all clean cscope distclean dvi html info install install-doc \
 	recurse-all speed tar tarbin test
 
-VPATH=$(SRC_PATH):$(SRC_PATH)/hw
+VPATH=$(SRC_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/libfdt
 
 CFLAGS += $(OS_CFLAGS) $(ARCH_CFLAGS)
 LDFLAGS += $(OS_LDFLAGS) $(ARCH_LDFLAGS)
@@ -68,7 +68,11 @@ endif
 # system emulation, i.e. a single QEMU executable should support all
 # CPUs and machines.
 
+include $(SRC_PATH)/libfdt/Makefile.libfdt
+$(LIBFDT_OBJS): CPPFLAGS += -I$(SRC_PATH)/libfdt
+
 OBJS=$(BLOCK_OBJS)
+OBJS+=$(LIBFDT_OBJS)
 OBJS+=readline.o console.o
 
 OBJS+=irq.o

Minor changes are required to get libfdt to build as part of qemu. The patch below records modifications relative to upstream dtc-v1.2.0.

libfdt_env.h +2 -3
Index: libfdt_env.h
===================================================================
@@ -4,10 +4,9 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <string.h>
-#include <endian.h>
-#include <byteswap.h>
+#include "bswap.h"
 
-#if __BYTE_ORDER == __BIG_ENDIAN
+#ifdef WORDS_BIGENDIAN
 #define fdt32_to_cpu(x)		(x)
 #define cpu_to_fdt32(x)		(x)
 #define fdt64_to_cpu(x)		(x)
#8 lore raw
In reply to Hollis Blanchard
Quoted 18 lines · Hollis Blanchard
Quoted 6 lines · Paul Brook
Quoted 4 lines

To implement the -kernel, -initrd, and -append options, 4xx board emulation must load the guest kernel as if firmware had loaded it. Where u-boot would be the firmware, we must load the flat device tree into memory and set key fields such as /chosen/bootargs.

Then why is it optional?

As you mention below, libfdt isn't generally available yet, and since it's possible to make a real firmware work in this environment (in which case -kernel isn't needed), the code can still be useful.

If you'd prefer to make libfdt mandatory, I'm fine with that.

Quoted 4 lines
Quoted 1 line

This patch introduces a dependency on libfdt for flat device tree support.

I don't like the way this is done.

Quoted 7 lines
Quoted 2 lines

AFAIK libfdt isn't present in any of the major distros. I thought the conclusion was that we should import libfdt into qemu.

That was our conclusion, but Anthony never agreed.

FWIW, I have requested that Fedora and Debian package libfdt, and they agreed in principle, but it's still missing in Fedora 10 for example.

If you've got a package review ticket open against Fedora for libfdt inclusion, let me know the bug number and I'm happy to do the review, so it is not unduely delayed on its path into Fedora repositories.

I far far prefer to see this kind of thing properly packaged, than copied into the source tree. Indeed if any application copies another library's code into their source tree, then when we package that app for Fedora we typically try to reverse this and make it link against a proper separately packaged shared library. Copy+paste of libraries into other apps's source tree is a maintenance disaster, particularly for security updates.

Regards,
Daniel

Signature · 4 lines
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#9 lore raw
Quoted 22 lines · Daniel P. Berrange
Quoted 21 lines · Hollis Blanchard
Quoted 6 lines · Paul Brook
Quoted 4 lines

To implement the -kernel, -initrd, and -append options, 4xx board emulation must load the guest kernel as if firmware had loaded it. Where u-boot would be the firmware, we must load the flat device tree into memory and set key fields such as /chosen/bootargs.

Then why is it optional?

As you mention below, libfdt isn't generally available yet, and since it's possible to make a real firmware work in this environment (in which case -kernel isn't needed), the code can still be useful.

If you'd prefer to make libfdt mandatory, I'm fine with that.

Quoted 6 lines
Quoted 1 line

This patch introduces a dependency on libfdt for flat device tree support.

I don't like the way this is done.

AFAIK libfdt isn't present in any of the major distros. I thought the conclusion was that we should import libfdt into qemu.

Quoted 8 lines
Quoted 4 lines

That was our conclusion, but Anthony never agreed.

FWIW, I have requested that Fedora and Debian package libfdt, and they agreed in principle, but it's still missing in Fedora 10 for example.

If you've got a package review ticket open against Fedora for libfdt inclusion, let me know the bug number and I'm happy to do the review, so it is not unduely delayed on its path into Fedora repositories.

https://bugzilla.redhat.com/show_bug.cgi?id=443882

IIRC Josh Boyer looked into this beyond what's reflected in the bug report, but I don't remember the current status.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#10 lore raw
Quoted 11 lines · Hollis Blanchard
Quoted 6 lines
Quoted 2 lines

FWIW, I have requested that Fedora and Debian package libfdt, and they agreed in principle, but it's still missing in Fedora 10 for example.

If you've got a package review ticket open against Fedora for libfdt inclusion, let me know the bug number and I'm happy to do the review, so it is not unduely delayed on its path into Fedora repositories.

https://bugzilla.redhat.com/show_bug.cgi?id=443882

IIRC Josh Boyer looked into this beyond what's reflected in the bug report, but I don't remember the current status.

I did. I submitted a patch and had a couple comments come back on it. I think I need to fixup the testsuite in dtc to link against and use the .so that is created and it should be OK for inclusion.

josh