PowerPC kvm-userspace patches
PATCH v5 1/1 PowerPC kvm-userspace patches
This addresses a bug that was introduced with memory changes as well as compiler warnings that were fixed by casting. This should stop the spam fest ;-)
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/
PATCH 1/1 Add libfdt to KVM userspace
# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205952857 18000
# Branch merge
# Node ID 20c62a22bfaeca9f01439b96b7159b725fff0dcd # Parent 875cee462bb2d5d84fd5f8bf0aa9cd7ec4977490 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
@@ -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
@@ -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
@@ -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/
PATCH 1/1 Add libfdt support to qemu
In reply to Jerone Young# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205952857 18000
# Branch merge
# Node ID be1aa50ab7de0a9e0441e46769e2a40a582fc3c0 # Parent 20c62a22bfaeca9f01439b96b7159b725fff0dcd Add libfdt support to qemu
This patch libfdt support into the qemu configuation script. There is a portion for libfdt probing that is has some "XXX". The code commented out is how to properly do probing for a library, the issue is that with kvm-userspace we do not build libfdt before configuring qemu. So to pervent this check from failing everytime we just do a simple test with the libfdt header. Once this can be resolved elgantly then we can uncomment the place commented out and remove the lines below them.
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/
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 1205953006 18000
# Branch merge
# Node ID 05d6146c77066b2bc0dd8349ee39636bc303628d
# Parent be1aa50ab7de0a9e0441e46769e2a40a582fc3c0 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.
Also added is gunzip support to allow for loading of uimages with a compressed kenrel images.
qemu/loader.c +148 -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 = (free_func )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<<20 //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,35 @@ 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 +447,20 @@ 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/
Re: [PATCH 3 of 7] Create new load_uimage() & gunzip support to uboot loader in Qemu
Quoted 14 lines
qemu/loader.c +8
-3-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); +
qemu/loader.c int load_uboot(const char *filename, tar · line 431
Quoted 10 lines
qemu/loader.c +10
-0+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 {
You've still got braces issues.
Regards,
Anthony Liguori
-------------------------------------------------------------------------
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/
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 1205953011 18000
# Branch merge
# Node ID 03925441312877b8350e4af68e475d5d746304d4
# Parent 05d6146c77066b2bc0dd8349ee39636bc303628d
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
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/
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 1205953012 18000
# Branch merge
# Node ID 8e9da5ddf159eb6cf5a292ccbf5f735103b493ef
# Parent 03925441312877b8350e4af68e475d5d746304d4
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_uimage() 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
@@ -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 +78 -23
147 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/
Re: [PATCH 5 of 7] Add dynamic device tree manipulation & change uboot loader for PPC bamboo board model
Quoted 74 lines · Jerone Young
# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205953012 18000
# Branch merge
# Node ID8e9da5ddf159eb6cf5a292ccbf5f735103b493ef
# Parent03925441312877b8350e4af68e475d5d746304d4
Add dynamic device tree manipulation & change uboot loader for PPC bamboo board modelThis 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_uimage()to load kernel image.Signed-off-by Jerone Young <[email protected]>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.oqemu/hw/device_tree.c new file +42
-0@@ -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> +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> + +#include "config.h" +#include "ppc440.h" + +#ifdef CONFIG_LIBFDT +#include "libfdt.h" +#endif + +#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);
qemu/hw/device_tree.c line 52
Quoted 10 lines
qemu/hw/device_tree.c new file +10
-0+ + buf = (char *)malloc (i); +if (buf ==NULL ) { +printf ("%s: Unable to malloc string buffer buf\n" , + __func__); +exit (1 ); + } + + i =snprintf (buf, i+1 ,"%s/%s" ,DT_PROC_INTERFACE_PATH , + path_in_device_tree);
asprintf() is the right thing to do here. You allocate 'i' bytes but then snprintf() to 'i + 1' bytes, that's a buffer overflow.
qemu/hw/device_tree.c line 143
Quoted 11 lines
qemu/hw/device_tree.c new file +10
-0+fail: +if (dt_file) +qemu_free (dt_file); +return NULL ; +} + +void dump_device_tree_to_file (void *fdt,char *filename) +{ +int fd; + fd =open (filename,O_RDWR |O_CREAT );
Need to pass a permission mask when using O_CREAT.
Regards,
Anthony LIguori
-------------------------------------------------------------------------
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/
Re: [PATCH 5 of 7] Add dynamic device tree manipulation & change uboot loader for PPC bamboo board model
Quoted 80 lines · Anthony Liguori
Quoted 79 lines · Jerone Young
# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205953012 18000
# Branch merge
# Node ID8e9da5ddf159eb6cf5a292ccbf5f735103b493ef
# Parent03925441312877b8350e4af68e475d5d746304d4
Add dynamic device tree manipulation & change uboot loader for PPC bamboo board modelThis 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_uimage()to load kernel image.Signed-off-by Jerone Young <[email protected]>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.oqemu/hw/device_tree.c new file +48
-0@@ -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> +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> + +#include "config.h" +#include "ppc440.h" + +#ifdef CONFIG_LIBFDT +#include "libfdt.h" +#endif + +#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); +if (buf ==NULL ) { +printf ("%s: Unable to malloc string buffer buf\n" , + __func__); +exit (1 );
Quoted 8 lines
qemu/hw/device_tree.c line 52
Quoted 5 lines
qemu/hw/device_tree.c new file +4
-0+ } + + i =snprintf (buf, i+1 ,"%s/%s" ,DT_PROC_INTERFACE_PATH , + path_in_device_tree);
asprintf()is the right thing to do here. You allocate 'i' bytes but thensnprintf()to 'i + 1' bytes, that's a buffer overflow.
Ouch! Yes this has to be fixed. Not sure why I did this, but
Quoted 14 lines
qemu/hw/device_tree.c line 143
Quoted 12 lines
qemu/hw/device_tree.c new file +10
-0+fail: +if (dt_file) +qemu_free (dt_file); +return NULL ; +} + +void dump_device_tree_to_file (void *fdt,char *filename) +{ +int fd; + fd =open (filename,O_RDWR |O_CREAT );Need to pass a permission mask when using
O_CREAT.
I'll fix this also.
Quoted 5 lines
Regards,
Anthony LIguori
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-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-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/
PATCH 1/1 Modify PPC bamboo & ppc440 board models
In reply to Jerone Young# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1205953013 18000
# Branch merge
# Node ID f625aa6f92329c0069492849a389f41d024d479b # Parent 8e9da5ddf159eb6cf5a292ccbf5f735103b493ef 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
@@ -62,8 +62,7 @@ void bamboo_init(ram_addr_t ram_size, inprintf ("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 );
@@ -71,7 +70,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/
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 1205953014 18000
# Branch merge
# Node ID 1facd867795ba61a65f451047a2982457b9e02ab
# Parent f625aa6f92329c0069492849a389f41d024d479b
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 +26 -19
@@ -15,6 +15,8 @@#define BINARY_DEVICE_TREE_FILE "bamboo.dtb" +#define bytes_to_mb (a) (a>>20) + void bamboo_init(ram_addr_t ram_size, int vga_ram_size, const char *boot_device, DisplayState *ds, const char *kernel_filename,
@@ -23,7 +25,7 @@ void bamboo_init(ram_addr_t ram_size, in const char *cpu_model) {char *buf=NULL ; -target_phys_addr_t ram_bases[2 ], ram_sizes[2 ]; +target_phys_addr_t ram_bases[4 ], ram_sizes[4 ];qemu_irq *pic;CPUState *env;target_ulong ep=0 ;
@@ -35,31 +37,36 @@ void bamboo_init(ram_addr_t ram_size, intarget_ulong dt_base=0 ;void *fdt;int ret; +int ram_stick_sizes[] = {256 <<20 ,128 <<20 ,64 <<20 , +32 <<20 ,16 <<20 ,8 <<20 };/* in 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 ); +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 ((tmp_ram_size/ram_stick_sizes[k]) >0 ) { + ram_sizes[i] = ram_stick_sizes[k]; + tmp_ram_size -= 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" );
@@ -76,7 +83,7 @@ void bamboo_init(ram_addr_t ram_size, in/* Register mem */ cpu_register_physical_memory (0 , ram_size,0 );if (kvm_enabled ()) -kvm_cpu_register_physical_memory (0 , ram_size,0 ); +kvm_cpu_register_physical_memory (0 , ram_size,0 );/* load kernel with uboot loader */ printf ("%s: load kernel\n" , __func__);
-------------------------------------------------------------------------
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/