Skip to contentSkip to conversation

PowerPC kvm-userspace patches

PATCH Superseded Jerone Young 2 participants 20 messages Mar 18, 2008

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 PowerPC kvm-userspace patches

This set address issues disscussed by Hollis & Anthony on the second go around. As well as some minor fixes.

This set of patches enables the following:
-Device tree Support
- Add libfdt to kvm-userspace
- Add bamboo device tree to qemu source
- Detection of host Device Tree attributes
- Device tree loading
- Ability to specify initrd on the command line
- Ability to add kernel arguments on the command line
- Ability to load compressed uImages
- Ability to specify memory on the command line

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#1 lore raw

PATCH 1/1 Add libfdt to KVM userspace

# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205870472 18000
# Branch merge
# Node ID 499d36637c8b4fcc0cd0008186d7974bb28369ab # Parent 601564603bfa37149a3484d1c1b8f1f15500e887 Add libfdt to KVM userspace

This patch adds libfdt to allow for motification of device tree entries into the KVM userspace tree.

Makefile +7 -2
@@ -5,7 +5,7 @@ DESTDIR=
 
 rpmrelease = devel
 
-.PHONY: kernel user libkvm qemu bios vgabios extboot clean
+.PHONY: kernel user libkvm qemu bios vgabios extboot clean libfdt
 
 all: libkvm qemu
 ifneq '$(filter $(ARCH), x86_64 i386 ia64)' ''
@@ -20,6 +20,9 @@ qemu: libkvm
 qemu: libkvm
 ifneq '$(filter $(ARCH), i386 x86_64)' ''
     qemu: extboot
+endif
+ifneq '$(filter $(ARCH), powerpc)' ''
+    qemu: libfdt
 endif
 user: libkvm
 
@@ -38,6 +41,8 @@ extboot:
            || ! cmp -s qemu/pc-bios/extboot.bin extboot/extboot.bin; then \
 		cp extboot/extboot.bin qemu/pc-bios/extboot.bin; \
 	fi
+libfdt:
+	$(MAKE) -C $@
 
 
 bindir = /usr/bin
@@ -88,7 +93,7 @@ srpm:
 	$(RM) $(tmpspec)
 
 clean:
-	for i in $(if $(WANT_MODULE), kernel) user libkvm qemu; do \
+	for i in $(if $(WANT_MODULE), kernel) user libkvm qemu libfdt; do \
 		make -C $$i clean; \
 	done
 	rm -f config.mak user/config.mak
configure +2 -0
@@ -103,6 +103,8 @@ fi
 
 if [ "$arch" = "powerpc" ]; then
     target_exec="ppcemb-softmmu"
+    qemu_cflags="$qemu_cflags -I $PWD/libfdt"
+    qemu_ldflags="$qemu_ldflags -L $PWD/libfdt"
 fi
 
 #configure user dir
libfdt/Makefile new file +19 -0
new file mode 100644
@@ -0,0 +1,19 @@
+include ../config.mak
+include ../user/config.mak
+
+LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c
+LIBFDT_INCLUDES = fdt.h libfdt.h
+LIBFDT_EXTRA = libfdt_internal.h
+LIBFDT_LIB = libfdt.a
+
+LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
+
+CFLAGS += -I .
+
+$(LIBFDT_LIB): $(LIBFDT_OBJS)
+	$(AR) rcs $@ $^
+
+all: $(LIBFDT_LIB)
+
+clean: 
+	rm -rf *.o *.a
libfdt/README new file +3 -0
new file mode 100644
@@ -0,0 +1,3 @@
+libfdt was grabbed from dtc source. This is the upstream source for libfdt.
+It can be found here:
+http://www.jdl.com/software/
libfdt/fdt.c new file +194 -0

194 lines not on this page · raw message

libfdt/fdt.h new file +60 -0

60 lines not on this page · raw message

libfdt/fdt_ro.c new file +476 -0

476 lines not on this page · raw message

libfdt/fdt_rw.c new file +467 -0

467 lines not on this page · raw message

libfdt/fdt_strerror.c new file +96 -0

96 lines not on this page · raw message

libfdt/fdt_sw.c new file +258 -0

258 lines not on this page · raw message

libfdt/fdt_wip.c new file +144 -0

144 lines not on this page · raw message

libfdt/libfdt.h new file +1076 -0

1,076 lines not on this page · raw message

libfdt/libfdt_env.h new file +22 -0
new file mode 100644
@@ -0,0 +1,22 @@
+#ifndef _LIBFDT_ENV_H
+#define _LIBFDT_ENV_H
+
+#include <stddef.h>
+#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)))
+#endif
+
+#endif /* _LIBFDT_ENV_H */
libfdt/libfdt_internal.h new file +96 -0

96 lines not on this page · raw message

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#2 lore raw

PATCH 1/1 Add libfdt support to qemu

In reply to Jerone Young

# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205870472 18000
# Branch merge
# Node ID aa10b5ca2f11cd571ae8a06c1e92425b7f7407ca # Parent 499d36637c8b4fcc0cd0008186d7974bb28369ab Add libfdt support to qemu

This patch adds needed configuration options to compile in libfdt support into qemu.

qemu/Makefile.target +5 -0
@@ -555,6 +555,11 @@ ifdef CONFIG_VNC_TLS
 ifdef CONFIG_VNC_TLS
 CPPFLAGS += $(CONFIG_VNC_TLS_CFLAGS)
 LIBS += $(CONFIG_VNC_TLS_LIBS)
+endif
+
+ifdef CONFIG_LIBFDT
+LIBS += -lfdt
+DEPLIBS += libfdt.a
 endif
 
 # SCSI layer
qemu/configure +36 -0
@@ -112,6 +112,7 @@ uname_release=""
 uname_release=""
 curses="yes"
 cpu_emulation="yes"
+device_tree_support=""
 
 # OS specific
 targetos=`uname -s`
@@ -345,6 +346,8 @@ for opt do
   ;;
   --disable-cpu-emulation) cpu_emulation="no"
   ;;
+  --disable-libfdt) device_tree_support="no"
+  ;;
   *) echo "ERROR: unknown option $opt"; exit 1
   ;;
   esac
@@ -449,6 +452,7 @@ echo "  --enable-uname-release=R Return 
 echo "  --enable-uname-release=R Return R for uname -r in usermode emulation"
 echo "  --sparc_cpu=V            Build qemu for Sparc architecture v7, v8, v8plus, v8plusa, v9"
 echo "  --disable-cpu-emulation  disables use of qemu cpu emulation code"
+echo "  --disable-libfdt         disables use of libfdt support for device tree"
 echo ""
 echo "NOTE: The object files are built at the place where configure is launched"
 exit 1
@@ -732,6 +736,31 @@ else
   binsuffix="/bin"
 fi
 
+######################################
+# libfdt probe
+#
+if test -z "$device_tree_support" -a \
+   "$cpu" = "powerpc"; then 
+  device_tree_support="no"
+  cat > $TMPC << EOF
+#include <libfdt.h>
+/* XXX uncomment later when libfdt is built before this test */ 
+//int main(void) { void *fdt; return fdt_create(fdt, 1024); }
+int main (void) {return 0;}
+EOF
+# XXX for now do not try to link to libfdt and just check for header */
+# if $cc $ARCH_CFLAGS $CFLAGS $LDFLAGS -o $TMPE $TMPC -lfdt 2> /dev/null ; then
+  if $cc $ARCH_CFLAGS $CFLAGS $LDFLAGS -o $TMPE $TMPC 2> /dev/null; then 
+   device_tree_support="yes"
+  else
+    echo
+    echo "Error: Could not find libfdt"
+    echo "Make sure to have the libfdt libs and headers installed."
+    echo
+    exit 1
+  fi
+fi
+
 echo "Install prefix    $prefix"
 echo "BIOS directory    $prefix$datasuffix"
 echo "binary directory  $prefix$binsuffix"
@@ -793,6 +822,9 @@ echo "kqemu support     $kqemu"
 echo "kqemu support     $kqemu"
 echo "kvm support       $kvm"
 echo "CPU emulation     $cpu_emulation"
+if test $cpu = "powerpc"; then
+echo "libfdt support    $device_tree_support"
+fi
 echo "Documentation     $build_docs"
 [ ! -z "$uname_release" ] && \
 echo "uname -r          $uname_release"
@@ -1186,6 +1218,10 @@ elif test "$target_cpu" = "ppcemb" ; the
   echo "#define TARGET_ARCH \"ppcemb\"" >> $config_h
   echo "#define TARGET_PPC 1" >> $config_h
   echo "#define TARGET_PPCEMB 1" >> $config_h
+  if test "$device_tree_support" = "yes" ; then
+      echo "#define CONFIG_LIBFDT 1" >> $config_h
+      echo "CONFIG_LIBFDT=1" >> $config_mak
+  fi
   configure_kvm
 elif test "$target_cpu" = "ppc64" ; then
   echo "TARGET_ARCH=ppc64" >> $config_mak

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#3 lore raw

Re: [kvm-ppc-devel] [PATCH 2 of 7] Add libfdt support to qemu

Quoted 14 lines · Jerone Young
qemu/configure +14 -0
+######################################
+# libfdt probe
+#
+if test -z "$device_tree_support" -a \
+   "$cpu" = "powerpc"; then 
+  device_tree_support="no"
+  cat > $TMPC << EOF
+#include <libfdt.h>
+/* XXX uncomment later when libfdt is built before this test */ 
+//int main(void) { void *fdt; return fdt_create(fdt, 1024); }
+int main (void) {return 0;}
+EOF
+# XXX for now do not try to link to libfdt and just check for header */
+# if $cc $ARCH_CFLAGS $CFLAGS $LDFLAGS -o $TMPE $TMPC -lfdt 2> /dev/null ; then

qemu/configure else · line 762

Quoted 10 lines
qemu/configure +10 -0
+  if $cc $ARCH_CFLAGS $CFLAGS $LDFLAGS -o $TMPE $TMPC 2> /dev/null; then 
+   device_tree_support="yes"
+  else
+    echo
+    echo "Error: Could not find libfdt"
+    echo "Make sure to have the libfdt libs and headers installed."
+    echo
+    exit 1
+  fi
+fi

What is the problem here? Should you describe it in the patch description? Did you mean to fix this before committing?

Signature · 8 lines
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
#4 lore raw

Re: [kvm-ppc-devel] [PATCH 2 of 7] Add libfdt support to qemu

So this is the code Anthony asked for for probing libfdt. The problem is that if you do ./configure <params> at kvm-userpace top directory for the first time or after a clean you do not have libfdt.a. When qemu configure is run this probe would allways fail. So to check we just check for the header. So we compile a very simple program that include libfdt.h as the test.

All the XXX are if we ever do break libfdt out then we can do the proper probing for it (and the code for it is ready to be uncommented).

Quoted 20 lines · Hollis Blanchard
Quoted 19 lines · Jerone Young
qemu/configure +19 -0
+######################################
+# libfdt probe
+#
+if test -z "$device_tree_support" -a \
+   "$cpu" = "powerpc"; then 
+  device_tree_support="no"
+  cat > $TMPC << EOF
+#include <libfdt.h>
+/* XXX uncomment later when libfdt is built before this test */ 
+//int main(void) { void *fdt; return fdt_create(fdt, 1024); }
+int main (void) {return 0;}
+EOF
+# XXX for now do not try to link to libfdt and just check for header */
+# if $cc $ARCH_CFLAGS $CFLAGS $LDFLAGS -o $TMPE $TMPC -lfdt 2> /dev/null ; then
+  if $cc $ARCH_CFLAGS $CFLAGS $LDFLAGS -o $TMPE $TMPC 2> /dev/null; then 
+   device_tree_support="yes"
+  else
+    echo
+    echo "Error: Could not find libfdt"
Quoted 9 lines

qemu/configure else · line 762

Quoted 5 lines
qemu/configure +5 -0
+    echo "Make sure to have the libfdt libs and headers installed."
+    echo
+    exit 1
+  fi
+fi

What is the problem here? Should you describe it in the patch description? Did you mean to fix this before committing?

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#5 lore raw

Re: [kvm-ppc-devel] [PATCH 2 of 7] Add libfdt support to qemu

OK, if that's acceptable to the qemu folks, could you put that in the patch description?

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
Quoted 43 lines · Jerone Young

So this is the code Anthony asked for for probing libfdt. The problem is that if you do ./configure <params> at kvm-userpace top directory for the first time or after a clean you do not have libfdt.a. When qemu configure is run this probe would allways fail. So to check we just check for the header. So we compile a very simple program that include libfdt.h as the test.

All the XXX are if we ever do break libfdt out then we can do the proper probing for it (and the code for it is ready to be uncommented).

Quoted 20 lines · Hollis Blanchard
Quoted 19 lines · Jerone Young
qemu/configure +19 -0
+######################################
+# libfdt probe
+#
+if test -z "$device_tree_support" -a \
+   "$cpu" = "powerpc"; then 
+  device_tree_support="no"
+  cat > $TMPC << EOF
+#include <libfdt.h>
+/* XXX uncomment later when libfdt is built before this test */ 
+//int main(void) { void *fdt; return fdt_create(fdt, 1024); }
+int main (void) {return 0;}
+EOF
+# XXX for now do not try to link to libfdt and just check for header */
+# if $cc $ARCH_CFLAGS $CFLAGS $LDFLAGS -o $TMPE $TMPC -lfdt 2> /dev/null ; then
+  if $cc $ARCH_CFLAGS $CFLAGS $LDFLAGS -o $TMPE $TMPC 2> /dev/null; then 
+   device_tree_support="yes"
+  else
+    echo
+    echo "Error: Could not find libfdt"
Quoted 9 lines

qemu/configure else · line 762

Quoted 5 lines
qemu/configure +5 -0
+    echo "Make sure to have the libfdt libs and headers installed."
+    echo
+    exit 1
+  fi
+fi

What is the problem here? Should you describe it in the patch description? Did you mean to fix this before committing?

Quoted 8 lines

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
kvm-ppc-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-ppc-devel

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#6 lore raw

Re: [kvm-ppc-devel] [PATCH 2 of 7] Add libfdt support to qemu

Well this can not go upstream. If it were to go into upstream qemu we would need for them to take in libfdt (which they most likely will have big issue with). Also we wouldn't do the probing if they did take it in. But for the forseable future we are not getting stuff into qemu yet. If we do then will cross this road and remove this completely. Or if libfdt ever is packaged separately. For now this is what we have to do for probing

Quoted 3 lines · Hollis Blanchard

OK, if that's acceptable to the qemu folks, could you put that in the patch description?

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#7 lore raw

PATCH 1/1 Create new load_uimage() & gunzip support to uboot loader in Qemu

In reply to Jerone Young

# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205870472 18000
# Branch merge
# Node ID 25515e6983ba1e070cbdcb7be1527426a097048b
# Parent aa10b5ca2f11cd571ae8a06c1e92425b7f7407ca Create new load_uimage() & gunzip support to uboot loader in Qemu

This patch adds the ability for the load address to be caputred when loading a uImage or cuImage. It also adds a better return code as the size can be an usigned long. This is done by creating a new function prototype and calling it load_uimage. To keep compatibility with code already using the old load_uboot a wrapper function has been created so current callers will not break them.

Also added is gunzip support to allow for loading of uimages with a compressed kenrel images.

qemu/loader.c +150 -9
@@ -26,6 +26,8 @@
 #include "sysemu.h"
 #include "uboot_image.h"
 
+#include <zlib.h>
+
 /* return the size or -1 if error */
 int get_image_size(const char *filename)
 {
@@ -263,14 +265,106 @@ static void bswap_uboot_header(uboot_ima
 }
 
 /* Load a U-Boot image.  */
-int load_uboot(const char *filename, target_ulong *ep, int *is_linux)
-{
-
+
+/* gunzip functionality is derived from gunzip function 
+ * in uboot source code 
+ */
+
+#define	ZALLOC_ALIGNMENT	16
+
+static void *zalloc(void *x, unsigned items, unsigned size)
+{
+	void *p;
+
+	size *= items;
+	size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
+
+	p = malloc (size);
+
+	return (p);
+}
+
+static void zfree(void *x, void *addr, unsigned nb)
+{
+	free (addr);
+}
+
+
+#define HEAD_CRC	2
+#define EXTRA_FIELD	4
+#define ORIG_NAME	8
+#define COMMENT		0x10
+#define RESERVED	0xe0
+
+#define DEFLATED	8
+
+static int gunzip(void *dst, int dstlen, unsigned char *src,
+		unsigned long *lenp)
+{
+	z_stream s;
+	int r, i, flags;
+
+	/* skip header */
+	i = 10;
+	flags = src[3];
+	if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
+		puts ("Error: Bad gzipped data\n");
+		return -1;
+	}
+	if ((flags & EXTRA_FIELD) != 0)
+		i = 12 + src[10] + (src[11] << 8);
+	if ((flags & ORIG_NAME) != 0)
+		while (src[i++] != 0)
+			;
+	if ((flags & COMMENT) != 0)
+		while (src[i++] != 0)
+			;
+	if ((flags & HEAD_CRC) != 0)
+		i += 2;
+	if (i >= *lenp) {
+		puts ("Error: gunzip out of data in header\n");
+		return -1;
+	}
+
+	s.zalloc = zalloc;
+	s.zfree = zfree;
+
+	r = inflateInit2(&s, -MAX_WBITS);
+	if (r != Z_OK) {
+		printf ("Error: inflateInit2() returned %d\n", r);
+		return (-1);
+	}
+	s.next_in = src + i;
+	s.avail_in = *lenp - i;
+	s.next_out = dst;
+	s.avail_out = dstlen;
+	r = inflate(&s, Z_FINISH);
+	if (r != Z_OK && r != Z_STREAM_END) {
+		printf ("Error: inflate() returned %d\n", r);
+		return -1;
+	}
+	*lenp = s.next_out - (unsigned char *) dst;
+	inflateEnd(&s);
+
+	return 0;
+}
+
+
+#define MAX_KERNEL_SIZE 8*1024*1024  //8MB
+/* This functions can load uImage & cuImage files */
+int load_uimage(const char *filename, target_ulong *ep,
+                  target_ulong *load_address, 
+                  target_ulong *loaded_image_size,
+                  int *is_linux)
+{
     int fd;
     int size;
+    int ret;
     uboot_image_header_t h;
     uboot_image_header_t *hdr = &h;
     uint8_t *data = NULL;
+    uint8_t *uncompressed_data = NULL;
+    unsigned long tmp_loaded_image_size;
 
     fd = open(filename, O_RDONLY | O_BINARY);
     if (fd < 0)
@@ -291,13 +385,14 @@ int load_uboot(const char *filename, tar
         goto fail;
     }
 
-    /* TODO: Implement compressed images.  */
-    if (hdr->ih_comp != IH_COMP_NONE) {
-        fprintf(stderr, "Unable to load compressed u-boot images\n");
+    /* TODO bzip2 support */
+    if (hdr->ih_comp == IH_COMP_BZIP2) {
+        fprintf(stderr, "Unable to load bzip2 compressed u-boot images\n");
         goto fail;
     }
 
     /* TODO: Check CPU type.  */
+
     if (is_linux) {
         if (hdr->ih_type == IH_TYPE_KERNEL && hdr->ih_os == IH_OS_LINUX)
             *is_linux = 1;
@@ -306,6 +401,7 @@ int load_uboot(const char *filename, tar
     }
 
     *ep = hdr->ih_ep;
+    
     data = qemu_malloc(hdr->ih_size);
     if (!data)
         goto fail;
@@ -315,9 +411,36 @@ int load_uboot(const char *filename, tar
         goto fail;
     }
 
-    cpu_physical_memory_write_rom(hdr->ih_load, data, hdr->ih_size);
-
-    return hdr->ih_size;
+    tmp_loaded_image_size = hdr->ih_size;
+    
+    if (hdr->ih_comp == IH_COMP_GZIP) {
+	uncompressed_data = qemu_malloc(MAX_KERNEL_SIZE);
+	ret = gunzip(uncompressed_data, MAX_KERNEL_SIZE,
+                    (unsigned char *) data, 
+                    &tmp_loaded_image_size);
+
+	if (ret < 0) {
+            fprintf(stderr, "Unable to decompress gziped image!\n");
+            goto fail;
+        }
+
+        qemu_free(data);
+        cpu_physical_memory_write_rom(hdr->ih_load, uncompressed_data,
+                                      tmp_loaded_image_size);
+
+    }
+    else {
+        cpu_physical_memory_write_rom(hdr->ih_load, data, 
+                                      tmp_loaded_image_size);
+    }
+
+    if (loaded_image_size != NULL)
+        *loaded_image_size = tmp_loaded_image_size;
+   
+    if ( load_address != NULL)
+    	*load_address = hdr->ih_load;
+ 
+    return 0;
 
 fail:
     if (data)
@@ -325,3 +448,21 @@ fail:
     close(fd);
     return -1;
 }
+
+/* XXX this function is to keep compatibility with other
+ * qemu callers. Once those callers are modified. This function
+ * should be removed from here & sysemu.h
+ */
+int load_uboot(const char *filename, target_ulong *ep, int *is_linux)
+{
+    int ret;
+    target_ulong size;
+   
+
+    ret = load_uimage(filename, ep, NULL, &size, is_linux);
+
+    if (ret < 0)
+	return ret;
+    else
+	return (int)size;
+}
qemu/sysemu.h +3 -0
@@ -210,6 +210,9 @@ int load_elf(const char *filename, int64
              uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr);
 int load_aout(const char *filename, uint8_t *addr);
 int load_uboot(const char *filename, target_ulong *ep, int *is_linux);
+int load_uimage(const char *filename, target_ulong *ep, 
+             target_ulong *la, target_ulong *loaded_image_size,
+             int *is_linux);
 #endif
 
 #ifdef HAS_AUDIO

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#8 lore raw

Re: [kvm-ppc-devel] [PATCH 3 of 7] Create new load_uimage() & gunzip support to uboot loader in Qemu

Quoted 18 lines · Jerone Young
qemu/loader.c +18 -0
+    tmp_loaded_image_size = hdr->ih_size;
+    
+    if (hdr->ih_comp == IH_COMP_GZIP) {
+       uncompressed_data = qemu_malloc(MAX_KERNEL_SIZE);
+       ret = gunzip(uncompressed_data, MAX_KERNEL_SIZE,
+                    (unsigned char *) data, 
+                    &tmp_loaded_image_size);
+
+       if (ret < 0) {
+            fprintf(stderr, "Unable to decompress gziped image!\n");
+            goto fail;
+        }
+
+        qemu_free(data);
+        cpu_physical_memory_write_rom(hdr->ih_load, uncompressed_data,
+                                      tmp_loaded_image_size);
+
+    }

qemu/loader.c int load_uboot(const char *filename, tar · line 441

Quoted 10 lines
qemu/loader.c +10 -0
+    else {
+        cpu_physical_memory_write_rom(hdr->ih_load, data, 
+                                      tmp_loaded_image_size);
+    }
+
+    if (loaded_image_size != NULL)
+        *loaded_image_size = tmp_loaded_image_size;
+   
+    if ( load_address != NULL)
+       *load_address = hdr->ih_load;

Your whitespace in here is all over the place. Please fix.

Signature · 8 lines
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
#9 lore raw

Re: [kvm-ppc-devel] [PATCH 3 of 7] Create new load_uimage() & gunzip support to uboot loader in Qemu

Quoted 18 lines · Hollis Blanchard

qemu/loader.c int load_uboot(const char *filename, tar

Quoted 10 lines · Jerone Young
qemu/loader.c +10 -0
+    tmp_loaded_image_size = hdr->ih_size;
+    
+    if (hdr->ih_comp == IH_COMP_GZIP) {
+       uncompressed_data = qemu_malloc(MAX_KERNEL_SIZE);
+       ret = gunzip(uncompressed_data, MAX_KERNEL_SIZE,
+                    (unsigned char *) data, 
+                    &tmp_loaded_image_size);
+
+       if (ret < 0) {
+            fprintf(stderr, "Unable to decompress gziped image!

\n");

qemu/loader.c int load_uboot(const char *filename, tar

Quoted 5 lines
qemu/loader.c +5 -0
+            goto fail;
+        }
+
+        qemu_free(data);
+        cpu_physical_memory_write_rom(hdr->ih_load,

uncompressed_data,

Quoted 15 lines

qemu/loader.c int load_uboot(const char *filename, tar · line 441

Quoted 13 lines
qemu/loader.c +13 -0
+                                      tmp_loaded_image_size);
+
+    }
+    else {
+        cpu_physical_memory_write_rom(hdr->ih_load, data, 
+                                      tmp_loaded_image_size);
+    }
+
+    if (loaded_image_size != NULL)
+        *loaded_image_size = tmp_loaded_image_size;
+   
+    if ( load_address != NULL)
+       *load_address = hdr->ih_load;

Your whitespace in here is all over the place. Please fix.

Actually this matches the style of this entire file. I see the one white space. I see also I used a tab one place.

The problem is there is no set style in qemu. So I followed the style of the already created file.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#10 lore raw

Re: [kvm-ppc-devel] [PATCH 3 of 7] Create new load_uimage() & gunzip support to uboot loader in Qemu

Quoted 35 lines · Jerone Young
Quoted 18 lines · Hollis Blanchard

qemu/loader.c int load_uboot(const char *filename, tar

Quoted 10 lines · Jerone Young
qemu/loader.c +10 -0
+    tmp_loaded_image_size = hdr->ih_size;
+    
+    if (hdr->ih_comp == IH_COMP_GZIP) {
+       uncompressed_data = qemu_malloc(MAX_KERNEL_SIZE);
+       ret = gunzip(uncompressed_data, MAX_KERNEL_SIZE,
+                    (unsigned char *) data, 
+                    &tmp_loaded_image_size);
+
+       if (ret < 0) {
+            fprintf(stderr, "Unable to decompress gziped image!

\n");

qemu/loader.c int load_uboot(const char *filename, tar

Quoted 5 lines
qemu/loader.c +5 -0
+            goto fail;
+        }
+
+        qemu_free(data);
+        cpu_physical_memory_write_rom(hdr->ih_load,

uncompressed_data,

Quoted 15 lines

qemu/loader.c int load_uboot(const char *filename, tar · line 441

Quoted 13 lines
qemu/loader.c +13 -0
+                                      tmp_loaded_image_size);
+
+    }
+    else {
+        cpu_physical_memory_write_rom(hdr->ih_load, data, 
+                                      tmp_loaded_image_size);
+    }
+
+    if (loaded_image_size != NULL)
+        *loaded_image_size = tmp_loaded_image_size;
+   
+    if ( load_address != NULL)
+       *load_address = hdr->ih_load;

Your whitespace in here is all over the place. Please fix.

Quoted 2 lines

Actually this matches the style of this entire file. I see the one white space. I see also I used a tab one place.

You switch from 8-space indentation in gunzip() to 4-space in load_uimage(), and then things go *really* screwy around "Unable to decompress gziped image" (which you spelled wrong btw). It looks like you alternate between 4- and 3-space indentation after that. That does NOT match the style of the rest of the file.

As for the "if ( " syntax, there are only a handful of people doing it that way in the whole qemu tree, and more importantly, none of them are in our code.

Signature · 8 lines
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
#11 lore raw

PATCH 1/1 Add PPC 440EP bamboo board device tree source & binary into qemu

In reply to Jerone Young

# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205870472 18000
# Branch merge
# Node ID ba2876c3e8916ba9c19b75c4464cbb8dc6858fbd
# Parent 25515e6983ba1e070cbdcb7be1527426a097048b
Add PPC 440EP bamboo board device tree source & binary into qemu

This patch places the bamboo device tree for the PPC 440EP bamboo board into the pc-bios directory of the qemu source. This also adds a rule into the pc-bios/Makefile to build device tree files.

qemu/Makefile +2 -1
@@ -195,7 +195,8 @@ endif
 	mkdir -p "$(DESTDIR)$(datadir)"
 	for x in bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
 		video.x openbios-sparc32 pxe-ne2k_pci.bin \
-		pxe-rtl8139.bin pxe-pcnet.bin pxe-e1000.bin extboot.bin; \
+		pxe-rtl8139.bin pxe-pcnet.bin pxe-e1000.bin extboot.bin \
+		bamboo.dtb; \
         do \
 		$(INSTALL) -m 644 $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
 	done
qemu/pc-bios/Makefile +4 -1
@@ -12,6 +12,9 @@ all: $(TARGETS)
 %.o: %.S
 	$(CC) $(DEFINES) -c -o $@ $<
 
+%.dtb: %.dts 
+	dtc -O dtb -I dts -o $@ $< 
+
 clean:
-	rm -f $(TARGETS) *.o *~
+	rm -f $(TARGETS) *.o *~ *.dtb
 
qemu/pc-bios/bamboo.dtb new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..e02fa8e0bf23b992b04fe87dfce37d4cc08777a6
GIT binary patch
qemu/pc-bios/bamboo.dts new file +195 -0

195 lines not on this page · raw message

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#12 lore raw

PATCH 1/1 Add dynamic device tree manipulation & change uboot loader for PPC bamboo board model

In reply to Jerone Young

# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205870472 18000
# Branch merge
# Node ID 3e87db599895937824b9bf3369eb67ea7f5a7595
# Parent ba2876c3e8916ba9c19b75c4464cbb8dc6858fbd
Add dynamic device tree manipulation & change uboot loader for PPC bamboo board model

This patch adds code to dynamically manipulate the device tree when loaded into memory. This allows us to finally have the ability to manipulate the kernel command line & initrd from the qemu command line. This will also let us setup different settings for the board.

This patch also now uses new uboot loader load_image() to load kernel image.

qemu/Makefile.target +1 -1
@@ -617,7 +617,7 @@ OBJS+= unin_pci.o ppc_chrp.o
 OBJS+= unin_pci.o ppc_chrp.o
 # PowerPC 4xx boards
 OBJS+= pflash_cfi02.o ppc4xx_devs.o ppc405_uc.o ppc405_boards.o
-OBJS+= ppc440.o ppc440_bamboo.o
+OBJS+= ppc440.o ppc440_bamboo.o device_tree.o
 endif
 ifeq ($(TARGET_BASE_ARCH), mips)
 OBJS+= mips_r4k.o mips_malta.o mips_pica61.o mips_mipssim.o
qemu/hw/device_tree.c new file +181 -0

181 lines not on this page · raw message

qemu/hw/device_tree.h new file +24 -0
new file mode 100644
@@ -0,0 +1,24 @@
+/*
+ * 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]>
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+/* device-tree proc support functions */
+uint32_t read_proc_dt_prop_cell(char *path_in_device_tree);
+
+#ifdef CONFIG_LIBFDT
+/* device tree functions */
+void *load_device_tree(char *filename_path, target_ulong load_addr);
+void dump_device_tree_to_file(void *fdt, char *filename);
+void dt_cell(void *fdt, char *node_path, char *property,
+		uint32_t val);
+void dt_string(void *fdt, char *node_path, char *property,
+		char *string);
+#endif
qemu/hw/ppc440_bamboo.c +68 -18

132 lines not on this page · raw message

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#13 lore raw

Re: [kvm-ppc-devel] [PATCH 5 of 7] Add dynamic device tree manipulation & change uboot loader for PPC bamboo board model

Quoted 8 lines · Jerone Young

# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205870472 18000
# Branch merge
# Node ID 3e87db599895937824b9bf3369eb67ea7f5a7595
# Parent ba2876c3e8916ba9c19b75c4464cbb8dc6858fbd
Add dynamic device tree manipulation & change uboot loader for PPC bamboo board model

Quoted 7 lines

This patch adds code to dynamically manipulate the device tree when loaded into memory. This allows us to finally have the ability to manipulate the kernel command line & initrd from the qemu command line. This will also let us setup different settings for the board.

This patch also now uses new uboot loader load_image() to load kernel image.

Again, the load_uimage part (which you've misspelled here) should be a separate patch?

Quoted 34 lines
qemu/Makefile.target +1 -1
@@ -617,7 +617,7 @@ OBJS+= unin_pci.o ppc_chrp.o
 OBJS+= unin_pci.o ppc_chrp.o
 # PowerPC 4xx boards
 OBJS+= pflash_cfi02.o ppc4xx_devs.o ppc405_uc.o ppc405_boards.o
-OBJS+= ppc440.o ppc440_bamboo.o
+OBJS+= ppc440.o ppc440_bamboo.o device_tree.o
 endif
 ifeq ($(TARGET_BASE_ARCH), mips)
 OBJS+= mips_r4k.o mips_malta.o mips_pica61.o mips_mipssim.o
qemu/hw/device_tree.c new file +15 -0
new file mode 100644
@@ -0,0 +1,181 @@
+/*
+ * Functions 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]>
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>

qemu/hw/device_tree.c line 25

Quoted 10 lines
qemu/hw/device_tree.c new file +10 -0
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "config.h"
+#include "ppc440.h"
+
+#ifdef CONFIG_LIBFDT
+	#include "libfdt.h"
+#endif

Again, don't indent this.

Quoted 14 lines
qemu/hw/device_tree.c new file +14 -0
+#define DT_PROC_INTERFACE_PATH "/proc/device-tree"
+
+/* FUNCTIONS FOR READING FROM DEVICE TREE OF HOST IN /PROC */
+
+/* This function reads device-tree property files that are of
+ * a single cell size
+ */
+uint32_t read_proc_dt_prop_cell(char *path_in_device_tree)
+{
+	char *buf = NULL;
+	int i;
+	uint32_t num;
+	FILE *stream;
+

qemu/hw/device_tree.c line 50

Quoted 10 lines
qemu/hw/device_tree.c new file +10 -0
+	i = snprintf(buf, 0, "%s/%s", DT_PROC_INTERFACE_PATH,
+		path_in_device_tree);
+
+	buf = (char *)malloc(i);
+	if (buf == NULL)
+	{
+		printf("%s: Unable to malloc string buffer buf\n",
+			__func__);
+		exit(1);
+	}

Braces.

qemu/hw/device_tree.c line 61

Quoted 10 lines
qemu/hw/device_tree.c new file +10 -0
+	i = snprintf(buf, i+1, "%s/%s",  DT_PROC_INTERFACE_PATH,
+		path_in_device_tree);
+
+	stream = fopen(buf, "rb");
+	
+	if (stream == NULL)
+	{
+		printf("%s: Unable to open '%s'\n", __func__, buf);
+		exit(1);
+	}

Braces.

Quoted 18 lines
qemu/hw/device_tree.c new file +18 -0
+	fread(&num, sizeof(num), 1, stream);
+	fclose(stream);
+
+	return num;
+} 
+
+/* FUNCTIONS FOR LOADING & MANIPULATION OF DEVICE TREE IN GUEST */
+
+#ifdef CONFIG_LIBFDT
+/* support functions */
+static int get_offset_of_node(void *fdt, char *node_path)
+{
+	int node_offset;
+	node_offset = fdt_path_offset(fdt, node_path);
+	if (node_offset < 0) {
+		printf("Unable to find node in device tree '%s'\n", 
+			node_path);
+		exit(1);

qemu/hw/device_tree.c line 90

Quoted 10 lines
qemu/hw/device_tree.c new file +10 -0
+	}
+	return node_offset;
+}
+
+/* public functions */
+void *load_device_tree(char *filename_path, unsigned long load_addr)
+{
+	int dt_file_size;
+	int dt_file_load_size;
+	int new_dt_size;	int ret;

Does this look right to you?

...

Quoted 13 lines
qemu/hw/ppc440_bamboo.c +2 -1
@@ -4,15 +4,16 @@
  * Copyright 2007 IBM Corporation.
  * Authors: Jerone Young <[email protected]>
  *
- * This work is licensed under the GNU GPL licence version 2 or later.
+ * This work is licensed under the GNU GPL license version 2 or later.
  *
  */
 
+#include "config.h"

qemu/hw/ppc440_bamboo.c line 18

Quoted 10 lines
qemu/hw/ppc440_bamboo.c +3 -3
 #include "ppc440.h"
+#include "qemu-kvm.h"
+#include "device_tree.h"
 
-#define KERNEL_LOAD_ADDR 0x400000 /* uboot loader puts kernel at 4MB */
-
-#include "qemu-kvm.h"
+#define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
 
 /* PPC 440 refrence demo board

Could you fix this typo while you're at it?

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 30

Quoted 5 lines
qemu/hw/ppc440_bamboo.c +1 -0
@@ -26,14 +27,22 @@ void bamboo_init(ram_addr_t ram_size, in
 			const char *initrd_filename,
 			const char *cpu_model)
 {
+	char buf[1024];

You previously said you had removed 'buf' and replaced it with dynamic allocation, but I don't see that here.

Quoted 8 lines
qemu/hw/ppc440_bamboo.c +2 -2
 	target_phys_addr_t ram_bases[2], ram_sizes[2];
 	qemu_irq *pic;
 	CPUState *env;
-	target_ulong ep;
+	target_ulong ep=0;
+	target_ulong la=0;
 	int is_linux=1; /* Will assume allways is Linux for now */
-	long kernel_size=0;

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 45

Quoted 10 lines
qemu/hw/ppc440_bamboo.c +8 -1
+	target_long kernel_size=0;
 	target_ulong initrd_base=0;
-	target_ulong initrd_size=0;
+	target_long initrd_size=0;
+	target_ulong dt_base=0;
+	void *fdt;
+	int ret;
+
+	uint32_t cpu_freq;
+	uint32_t timebase_freq;

Why is there an extra blank line here?

Signature · 8 lines
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
#14 lore raw

Re: [kvm-ppc-devel] [PATCH 5 of 7] Add dynamic device tree manipulation & change uboot loader for PPC bamboo board model

Quoted 85 lines · Hollis Blanchard
Quoted 8 lines · Jerone Young

# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205870472 18000
# Branch merge
# Node ID 3e87db599895937824b9bf3369eb67ea7f5a7595
# Parent ba2876c3e8916ba9c19b75c4464cbb8dc6858fbd
Add dynamic device tree manipulation & change uboot loader for PPC bamboo board model

Quoted 7 lines

This patch adds code to dynamically manipulate the device tree when loaded into memory. This allows us to finally have the ability to manipulate the kernel command line & initrd from the qemu command line. This will also let us setup different settings for the board.

This patch also now uses new uboot loader load_image() to load kernel image.

Again, the load_uimage part (which you've misspelled here) should be a separate patch?

Quoted 34 lines
qemu/Makefile.target +1 -1
@@ -617,7 +617,7 @@ OBJS+= unin_pci.o ppc_chrp.o
 OBJS+= unin_pci.o ppc_chrp.o
 # PowerPC 4xx boards
 OBJS+= pflash_cfi02.o ppc4xx_devs.o ppc405_uc.o ppc405_boards.o
-OBJS+= ppc440.o ppc440_bamboo.o
+OBJS+= ppc440.o ppc440_bamboo.o device_tree.o
 endif
 ifeq ($(TARGET_BASE_ARCH), mips)
 OBJS+= mips_r4k.o mips_malta.o mips_pica61.o mips_mipssim.o
qemu/hw/device_tree.c new file +15 -0
new file mode 100644
@@ -0,0 +1,181 @@
+/*
+ * Functions 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]>
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>

qemu/hw/device_tree.c line 25

Quoted 10 lines
qemu/hw/device_tree.c new file +10 -0
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "config.h"
+#include "ppc440.h"
+
+#ifdef CONFIG_LIBFDT
+	#include "libfdt.h"
+#endif

Again, don't indent this.

Quoted 18 lines
qemu/hw/device_tree.c new file +18 -0
+#define DT_PROC_INTERFACE_PATH "/proc/device-tree"
+
+/* FUNCTIONS FOR READING FROM DEVICE TREE OF HOST IN /PROC */
+
+/* This function reads device-tree property files that are of
+ * a single cell size
+ */
+uint32_t read_proc_dt_prop_cell(char *path_in_device_tree)
+{
+	char *buf = NULL;
+	int i;
+	uint32_t num;
+	FILE *stream;
+
+	i = snprintf(buf, 0, "%s/%s", DT_PROC_INTERFACE_PATH,
+		path_in_device_tree);
+
+	buf = (char *)malloc(i);
Quoted 8 lines

qemu/hw/device_tree.c line 50

Quoted 6 lines
qemu/hw/device_tree.c new file +6 -0
+	if (buf == NULL)
+	{
+		printf("%s: Unable to malloc string buffer buf\n",
+			__func__);
+		exit(1);
+	}

Braces.

What is the deal. They are braces. They are done diffrenent through outt the qemu code. This

Quoted 36 lines

qemu/hw/device_tree.c line 61

Quoted 11 lines
qemu/hw/device_tree.c new file +10 -0
+	i = snprintf(buf, i+1, "%s/%s",  DT_PROC_INTERFACE_PATH,
+		path_in_device_tree);
+
+	stream = fopen(buf, "rb");
+	
+	if (stream == NULL)
+	{
+		printf("%s: Unable to open '%s'\n", __func__, buf);
+		exit(1);
+	}

Braces.

Quoted 22 lines
qemu/hw/device_tree.c new file +22 -0
+	fread(&num, sizeof(num), 1, stream);
+	fclose(stream);
+
+	return num;
+} 
+
+/* FUNCTIONS FOR LOADING & MANIPULATION OF DEVICE TREE IN GUEST */
+
+#ifdef CONFIG_LIBFDT
+/* support functions */
+static int get_offset_of_node(void *fdt, char *node_path)
+{
+	int node_offset;
+	node_offset = fdt_path_offset(fdt, node_path);
+	if (node_offset < 0) {
+		printf("Unable to find node in device tree '%s'\n", 
+			node_path);
+		exit(1);
+	}
+	return node_offset;
+}
+
Quoted 9 lines

qemu/hw/device_tree.c line 90

Quoted 6 lines
qemu/hw/device_tree.c new file +6 -0
+/* public functions */
+void *load_device_tree(char *filename_path, unsigned long load_addr)
+{
+	int dt_file_size;
+	int dt_file_load_size;
+	int new_dt_size;	int ret;

Does this look right to you?

can clean that.

Quoted 27 lines

...

Quoted 13 lines
qemu/hw/ppc440_bamboo.c +2 -1
@@ -4,15 +4,16 @@
  * Copyright 2007 IBM Corporation.
  * Authors: Jerone Young <[email protected]>
  *
- * This work is licensed under the GNU GPL licence version 2 or later.
+ * This work is licensed under the GNU GPL license version 2 or later.
  *
  */
 
+#include "config.h"

qemu/hw/ppc440_bamboo.c line 18

Quoted 10 lines
qemu/hw/ppc440_bamboo.c +3 -3
 #include "ppc440.h"
+#include "qemu-kvm.h"
+#include "device_tree.h"
 
-#define KERNEL_LOAD_ADDR 0x400000 /* uboot loader puts kernel at 4MB */
-
-#include "qemu-kvm.h"
+#define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
 
 /* PPC 440 refrence demo board

Could you fix this typo while you're at it?

Quoted 8 lines

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 30

Quoted 5 lines
qemu/hw/ppc440_bamboo.c +1 -0
@@ -26,14 +27,22 @@ void bamboo_init(ram_addr_t ram_size, in
 			const char *initrd_filename,
 			const char *cpu_model)
 {
+	char buf[1024];

You previously said you had removed 'buf' and replaced it with dynamic allocation, but I don't see that here.

Removing of buf discussed was from hw/device_tree.c not this file.

Quoted 13 lines
Quoted 13 lines
qemu/hw/ppc440_bamboo.c +4 -3
 	target_phys_addr_t ram_bases[2], ram_sizes[2];
 	qemu_irq *pic;
 	CPUState *env;
-	target_ulong ep;
+	target_ulong ep=0;
+	target_ulong la=0;
 	int is_linux=1; /* Will assume allways is Linux for now */
-	long kernel_size=0;
+	target_long kernel_size=0;
 	target_ulong initrd_base=0;
-	target_ulong initrd_size=0;
+	target_long initrd_size=0;
Quoted 9 lines

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 45

Quoted 6 lines
qemu/hw/ppc440_bamboo.c +6 -0
+	target_ulong dt_base=0;
+	void *fdt;
+	int ret;
+
+	uint32_t cpu_freq;
+	uint32_t timebase_freq;

Why is there an extra blank line here?

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#15 lore raw

Re: [kvm-ppc-devel] [PATCH 5 of 7] Add dynamic device tree manipulation & change uboot loader for PPC bamboo board model

I can only assume that you will actually make the corrections that you didn't respond to in this mail.

Quoted 29 lines · Jerone Young
Quoted 19 lines · Hollis Blanchard
Quoted 19 lines
qemu/hw/device_tree.c new file +18 -0
+#define DT_PROC_INTERFACE_PATH "/proc/device-tree"
+
+/* FUNCTIONS FOR READING FROM DEVICE TREE OF HOST IN /PROC */
+
+/* This function reads device-tree property files that are of
+ * a single cell size
+ */
+uint32_t read_proc_dt_prop_cell(char *path_in_device_tree)
+{
+	char *buf = NULL;
+	int i;
+	uint32_t num;
+	FILE *stream;
+
+	i = snprintf(buf, 0, "%s/%s", DT_PROC_INTERFACE_PATH,
+		path_in_device_tree);
+
+	buf = (char *)malloc(i);
Quoted 8 lines

qemu/hw/device_tree.c line 50

Quoted 6 lines
qemu/hw/device_tree.c new file +6 -0
+	if (buf == NULL)
+	{
+		printf("%s: Unable to malloc string buffer buf\n",
+			__func__);
+		exit(1);
+	}

Braces.

Quoted 2 lines

What is the deal. They are braces. They are done diffrenent through outt the qemu code. This

I don't enjoy correcting whitespace, and in fact I hate it when that's all comments are about. If it weren't so egregious in this patch series, I probably would have let it slide.

In general I don't really care as long as it's *consistent*. The tabs you use in this code clashes with the rest of qemu, and that makes it difficult to use the right editor settings. Despite that, I still didn't say anything, because at least it's consistent.

In general, don't just make your code work; make it pretty too.

Quoted 10 lines
Quoted 8 lines

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 30

Quoted 5 lines
qemu/hw/ppc440_bamboo.c +1 -0
@@ -26,14 +27,22 @@ void bamboo_init(ram_addr_t ram_size, in
 			const char *initrd_filename,
 			const char *cpu_model)
 {
+	char buf[1024];

You previously said you had removed 'buf' and replaced it with dynamic allocation, but I don't see that here.

Removing of buf discussed was from hw/device_tree.c not this file.

So you can fix it here too, right?

Signature · 8 lines
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
#16 lore raw

PATCH 1/1 Modify PPC bamboo & ppc440 board models

In reply to Jerone Young

# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205870472 18000
# Branch merge
# Node ID ac0fc9dfd78d2eddd083326e9b635a9286fc3b19 # Parent 3e87db599895937824b9bf3369eb67ea7f5a7595 Modify PPC bamboo & ppc440 board models

This patch renames pp440_init to ppc440ep_init, as ppc440 is the name of the core and ppc440ep is the name of the SOC. When we init we are initializing the SOC.

Also in this patch we now call cpu_ppc_init for bamboo with string 440 .. as 440 is the core.

qemu/hw/ppc440.c +1 -1
@@ -10,7 +10,7 @@
 
 #include "ppc440.h"
 
-void ppc440_init(CPUState *env,
+void ppc440ep_init(CPUState *env,
 		target_phys_addr_t ram_bases[2],
 		target_phys_addr_t ram_sizes[2],
 		qemu_irq **picp,
qemu/hw/ppc440.h +1 -1
@@ -20,7 +20,7 @@
 #include "exec-all.h"
 #include "boards.h"
 
-void ppc440_init(CPUState *env,
+void ppc440ep_init(CPUState *env,
 		target_phys_addr_t ram_bases[2],
 		target_phys_addr_t ram_sizes[2],
 		qemu_irq **picp,
qemu/hw/ppc440_bamboo.c +2 -3
@@ -68,8 +68,7 @@ void bamboo_init(ram_addr_t ram_size, in
 	printf("Ram size of domain is %d bytes\n", (int)ram_size);
 
 	/* Setup CPU */
-	/* XXX We cheat for now and use 405 */
-	env = cpu_ppc_init("405");
+	env = cpu_ppc_init("440");
 	if (!env) {
 		fprintf(stderr, "Unable to initilize CPU!\n");
 		exit(1);
@@ -77,7 +76,7 @@ void bamboo_init(ram_addr_t ram_size, in
 
 	/* call init */
 	printf("Calling function ppc440_init\n");
-	ppc440_init(env, ram_bases, ram_sizes, &pic,1);
+	ppc440ep_init(env, ram_bases, ram_sizes, &pic,1);
 	printf("Done calling ppc440_init\n");
 
 	/* Register mem */

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#17 lore raw

PATCH 1/1 Add ability to specify ram on command line for bamboo board model

In reply to Jerone Young

# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205870472 18000
# Branch merge
# Node ID 4f90f7d25186f55bfb1503764af5264201df067f
# Parent ac0fc9dfd78d2eddd083326e9b635a9286fc3b19
Add ability to specify ram on command line for bamboo board model

This patch adds the ability to now specify ram sizes on the command line. Due to the nature of the code there are restictions on exactly how much ram and the multiple that the size must match.

qemu/hw/ppc440_bamboo.c +29 -19
@@ -15,6 +15,9 @@
 
 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
 
+#define bytes_to_mb(a) (a>>20)
+#define mb_to_bytes(a) (a<<20)
+
 /* PPC 440 refrence demo board
  *
  * 440 PowerPC CPU
@@ -28,7 +31,7 @@ void bamboo_init(ram_addr_t ram_size, in
 			const char *cpu_model)
 {
 	char buf[1024];	
-	target_phys_addr_t ram_bases[2], ram_sizes[2];
+	target_phys_addr_t ram_bases[2], ram_sizes[2]; 
 	qemu_irq *pic;
 	CPUState *env;
 	target_ulong ep=0;
@@ -40,32 +43,39 @@ void bamboo_init(ram_addr_t ram_size, in
 	target_ulong dt_base=0;
 	void *fdt;
 	int ret;
+	int ram_stick_sizes[] = {256, 128, 64, 32, 16, 8 }; /* in Mega bytes */
+	ram_addr_t tmp_ram_size;
+	int i=0, k=0;
 
 	uint32_t cpu_freq;
 	uint32_t timebase_freq;
 
 	printf("%s: START\n", __func__);
 
-	/* Setup Memory */
-	if (ram_size) {
-		printf("Ram size specified on command line is %i bytes\n",
-								(int)ram_size);
-		printf("WARNING: RAM is hard coded to 144MB\n");
-	}
-	else {
-		printf("Using defualt ram size of %iMB\n",
-						((int)ram_size/1024)/1024);
+ 	/* Setup Memory */
+ 	printf("Ram size passed is: %i MB\n",
+ 				bytes_to_mb((int)ram_size));
+
+	tmp_ram_size = ram_size;
+ 
+	for (i=0; i < (sizeof(ram_sizes)/sizeof(ram_sizes[0])); i++)
+	{
+		for (k=0; k < (sizeof(ram_stick_sizes)/sizeof(ram_stick_sizes[0])); k++)
+		{
+			if ((bytes_to_mb(ram_size)/ram_stick_sizes[k]) > 0)
+			{
+				ram_sizes[i] = mb_to_bytes(ram_stick_sizes[k]);
+				tmp_ram_size -= mb_to_bytes(ram_stick_sizes[k]);
+				break;
+			}
+		}
 	}
 
-	/* Each bank can only have memory in configurations of
-	 *   16MB, 32MB, 64MB, 128MB, or 256MB
-	 */
-	ram_bases[0] = 0x0;
-	ram_sizes[0] = 0x08000000;
-	ram_bases[1] = 0x0;
-	ram_sizes[1] = 0x01000000;
-
-	printf("Ram size of domain is %d bytes\n", (int)ram_size);
+	if (tmp_ram_size) {
+		printf("WARNING: %i MB left over memory is ram\n", 
+			bytes_to_mb((int)tmp_ram_size));
+		ram_size -= tmp_ram_size;
+	}
 
 	/* Setup CPU */
 	env = cpu_ppc_init("440");

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#18 lore raw

Re: [kvm-ppc-devel] [PATCH 7 of 7] Add ability to specify ram on command line for bamboo board model

Quoted 28 lines · Jerone Young

# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205870472 18000
# Branch merge
# Node ID 4f90f7d25186f55bfb1503764af5264201df067f
# Parent ac0fc9dfd78d2eddd083326e9b635a9286fc3b19
Add ability to specify ram on command line for bamboo board model

This patch adds the ability to now specify ram sizes on the command line. Due to the nature of the code there are restictions on exactly how much ram and the multiple that the size must match.

qemu/hw/ppc440_bamboo.c +3 -0
@@ -15,6 +15,9 @@
 
 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
 
+#define bytes_to_mb(a) (a>>20)
+#define mb_to_bytes(a) (a<<20)
+
 /* PPC 440 refrence demo board
  *
  * 440 PowerPC CPU

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 37

Quoted 8 lines
qemu/hw/ppc440_bamboo.c +1 -1
@@ -28,7 +31,7 @@ void bamboo_init(ram_addr_t ram_size, in
 			const char *cpu_model)
 {
 	char buf[1024];	
-	target_phys_addr_t ram_bases[2], ram_sizes[2];
+	target_phys_addr_t ram_bases[2], ram_sizes[2]; 
 	qemu_irq *pic;
 	CPUState *env;
 	target_ulong ep=0;

Here you have added a trailing space.

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 48

Quoted 7 lines
qemu/hw/ppc440_bamboo.c +3 -0
@@ -40,32 +43,39 @@ void bamboo_init(ram_addr_t ram_size, in
 	target_ulong dt_base=0;
 	void *fdt;
 	int ret;
+	int ram_stick_sizes[] = {256, 128, 64, 32, 16, 8 }; /* in Mega bytes */
+	ram_addr_t tmp_ram_size;
+	int i=0, k=0;

Define ram_stick_sizes[] in MB and then remove all the shifting inside the loops.

Quoted 16 lines
qemu/hw/ppc440_bamboo.c +2 -9
 	uint32_t cpu_freq;
 	uint32_t timebase_freq;
 
 	printf("%s: START\n", __func__);
 
-	/* Setup Memory */
-	if (ram_size) {
-		printf("Ram size specified on command line is %i bytes\n",
-								(int)ram_size);
-		printf("WARNING: RAM is hard coded to 144MB\n");
-	}
-	else {
-		printf("Using defualt ram size of %iMB\n",
-						((int)ram_size/1024)/1024);
+ 	/* Setup Memory */
+ 	printf("Ram size passed is: %i MB\n",

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 66

Quoted 10 lines
qemu/hw/ppc440_bamboo.c +10 -0
+ 				bytes_to_mb((int)ram_size));
+
+	tmp_ram_size = ram_size;
+ 
+	for (i=0; i < (sizeof(ram_sizes)/sizeof(ram_sizes[0])); i++)
+	{
+		for (k=0; k < (sizeof(ram_stick_sizes)/sizeof(ram_stick_sizes[0])); k++)
+		{
+			if ((bytes_to_mb(ram_size)/ram_stick_sizes[k]) > 0)
+			{

Don't divide, just use a logical comparison.

Also, put all the open-braces on the previous lines.

Quoted 13 lines
qemu/hw/ppc440_bamboo.c +5 -7
+				ram_sizes[i] = mb_to_bytes(ram_stick_sizes[k]);
+				tmp_ram_size -= mb_to_bytes(ram_stick_sizes[k]);
+				break;
+			}
+		}
 	}
-	/* Each bank can only have memory in configurations of
-	 *   16MB, 32MB, 64MB, 128MB, or 256MB
-	 */
-	ram_bases[0] = 0x0;
-	ram_sizes[0] = 0x08000000;
-	ram_bases[1] = 0x0;
-	ram_sizes[1] = 0x01000000;

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 81

Quoted 10 lines
qemu/hw/ppc440_bamboo.c +5 -2
-
-	printf("Ram size of domain is %d bytes\n", (int)ram_size);
+	if (tmp_ram_size) {
+		printf("WARNING: %i MB left over memory is ram\n", 
+			bytes_to_mb((int)tmp_ram_size));
+		ram_size -= tmp_ram_size;
+	}
 
 	/* Setup CPU */
 	env = cpu_ppc_init("440");

Remove tmp_ram_size completely. Just decrement ram_size in the loop and check if it's non-zero at the end.

Signature · 8 lines
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
#19 lore raw

Re: [kvm-ppc-devel] [PATCH 7 of 7] Add ability to specify ram on command line for bamboo board model

Quoted 31 lines · Hollis Blanchard
Quoted 30 lines · Jerone Young

# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205870472 18000
# Branch merge
# Node ID 4f90f7d25186f55bfb1503764af5264201df067f
# Parent ac0fc9dfd78d2eddd083326e9b635a9286fc3b19
Add ability to specify ram on command line for bamboo board model

This patch adds the ability to now specify ram sizes on the command line. Due to the nature of the code there are restictions on exactly how much ram and the multiple that the size must match.

qemu/hw/ppc440_bamboo.c +3 -0
@@ -15,6 +15,9 @@
 
 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
 
+#define bytes_to_mb(a) (a>>20)
+#define mb_to_bytes(a) (a<<20)
+
 /* PPC 440 refrence demo board
  *
  * 440 PowerPC CPU
@@ -28,7 +31,7 @@ void bamboo_init(ram_addr_t ram_size, in
 			const char *cpu_model)
 {
Quoted 8 lines

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 37

Quoted 6 lines
qemu/hw/ppc440_bamboo.c +1 -1
 	char buf[1024];	
-	target_phys_addr_t ram_bases[2], ram_sizes[2];
+	target_phys_addr_t ram_bases[2], ram_sizes[2]; 
 	qemu_irq *pic;
 	CPUState *env;
 	target_ulong ep=0;

Here you have added a trailing space.

ok

Quoted 11 lines

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 48

Quoted 8 lines
qemu/hw/ppc440_bamboo.c +3 -0
@@ -40,32 +43,39 @@ void bamboo_init(ram_addr_t ram_size, in
 	target_ulong dt_base=0;
 	void *fdt;
 	int ret;
+	int ram_stick_sizes[] = {256, 128, 64, 32, 16, 8 }; /* in Mega bytes */
+	ram_addr_t tmp_ram_size;
+	int i=0, k=0;

Define ram_stick_sizes[] in MB and then remove all the shifting inside the loops.

You must mean define them in bytes. That can be done also.

Quoted 21 lines
Quoted 21 lines
qemu/hw/ppc440_bamboo.c +6 -9
 	uint32_t cpu_freq;
 	uint32_t timebase_freq;
 
 	printf("%s: START\n", __func__);
 
-	/* Setup Memory */
-	if (ram_size) {
-		printf("Ram size specified on command line is %i bytes\n",
-								(int)ram_size);
-		printf("WARNING: RAM is hard coded to 144MB\n");
-	}
-	else {
-		printf("Using defualt ram size of %iMB\n",
-						((int)ram_size/1024)/1024);
+ 	/* Setup Memory */
+ 	printf("Ram size passed is: %i MB\n",
+ 				bytes_to_mb((int)ram_size));
+
+	tmp_ram_size = ram_size;
+ 
Quoted 8 lines

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 66

Quoted 6 lines
qemu/hw/ppc440_bamboo.c +6 -0
+	for (i=0; i < (sizeof(ram_sizes)/sizeof(ram_sizes[0])); i++)
+	{
+		for (k=0; k < (sizeof(ram_stick_sizes)/sizeof(ram_stick_sizes[0])); k++)
+		{
+			if ((bytes_to_mb(ram_size)/ram_stick_sizes[k]) > 0)
+			{

Don't divide, just use a logical comparison.

This can be done. Though it really doesn't matter. Both ways work.

Quoted 1 line

Also, put all the open-braces on the previous lines.

ok

Quoted 22 lines
Quoted 22 lines
qemu/hw/ppc440_bamboo.c +10 -9
+				ram_sizes[i] = mb_to_bytes(ram_stick_sizes[k]);
+				tmp_ram_size -= mb_to_bytes(ram_stick_sizes[k]);
+				break;
+			}
+		}
 	}
-	/* Each bank can only have memory in configurations of
-	 *   16MB, 32MB, 64MB, 128MB, or 256MB
-	 */
-	ram_bases[0] = 0x0;
-	ram_sizes[0] = 0x08000000;
-	ram_bases[1] = 0x0;
-	ram_sizes[1] = 0x01000000;
-
-	printf("Ram size of domain is %d bytes\n", (int)ram_size);
+	if (tmp_ram_size) {
+		printf("WARNING: %i MB left over memory is ram\n", 
+			bytes_to_mb((int)tmp_ram_size));
+		ram_size -= tmp_ram_size;
+	}
 
Quoted 6 lines

qemu/hw/ppc440_bamboo.c void bamboo_init(ram_addr_t ram_size, in · line 81

Quoted 2 lines
qemu/hw/ppc440_bamboo.c +0 -0
 	/* Setup CPU */
 	env = cpu_ppc_init("440");

Remove tmp_ram_size completely. Just decrement ram_size in the loop and
check if it's non-zero at the end.

tmp_ram_size is needed because we use ram_size later used allocate memory.

Quoted 1 line

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/