ia64/xen-unstable

changeset 13939:09b3fd488726

[XEND][POWERPC] Remove FlatDeviceTree.py, eliminate devtree from prose builder.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com>
author Jimi Xenidis <jimix@watson.ibm.com>
date Sun Jan 21 08:15:39 2007 -0500 (2007-01-21)
parents 7bf078335342
children aa00ced0a10a
files tools/libxc/powerpc64/utils.c tools/libxc/powerpc64/utils.h tools/libxc/powerpc64/xc_prose_build.c tools/libxc/xenguest.h tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/FlatDeviceTree.py tools/python/xen/xend/image.py
line diff
     1.1 --- a/tools/libxc/powerpc64/utils.c	Sun Jan 21 08:14:27 2007 -0500
     1.2 +++ b/tools/libxc/powerpc64/utils.c	Sun Jan 21 08:15:39 2007 -0500
     1.3 @@ -13,7 +13,7 @@
     1.4   * along with this program; if not, write to the Free Software
     1.5   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     1.6   *
     1.7 - * Copyright (C) IBM Corporation 2006
     1.8 + * Copyright IBM Corporation 2006, 2007
     1.9   *
    1.10   * Authors: Hollis Blanchard <hollisb@us.ibm.com>
    1.11   *          Jimi Xenidis <jimix@watson.ibm.com>
    1.12 @@ -37,29 +37,6 @@
    1.13  #include "flatdevtree.h"
    1.14  #include "utils.h"
    1.15  
    1.16 -unsigned long get_rma_pages(void *devtree)
    1.17 -{
    1.18 -    void *rma;
    1.19 -    uint64_t rma_reg[2];
    1.20 -    int rc;
    1.21 -
    1.22 -    rma = ft_find_node(devtree, "/memory@0");
    1.23 -    if (rma == NULL) {
    1.24 -        DPRINTF("couldn't find /memory@0\n");
    1.25 -        return 0;
    1.26 -    }
    1.27 -    rc = ft_get_prop(devtree, rma, "reg", rma_reg, sizeof(rma_reg));
    1.28 -    if (rc < 0) {
    1.29 -        DPRINTF("couldn't get /memory@0/reg\n");
    1.30 -        return 0;
    1.31 -    }
    1.32 -    if (rma_reg[0] != 0) {
    1.33 -        DPRINTF("RMA did not start at 0\n");
    1.34 -        return 0;
    1.35 -    }
    1.36 -    return rma_reg[1] >> PAGE_SHIFT;
    1.37 -}
    1.38 -
    1.39  int get_rma_page_array(int xc_handle, int domid, xen_pfn_t **page_array,
    1.40  		       unsigned long nr_pages)
    1.41  {
     2.1 --- a/tools/libxc/powerpc64/utils.h	Sun Jan 21 08:14:27 2007 -0500
     2.2 +++ b/tools/libxc/powerpc64/utils.h	Sun Jan 21 08:15:39 2007 -0500
     2.3 @@ -13,13 +13,12 @@
     2.4   * along with this program; if not, write to the Free Software
     2.5   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     2.6   *
     2.7 - * Copyright (C) IBM Corporation 2006
     2.8 + * Copyright IBM Corporation 2006, 2007
     2.9   *
    2.10   * Authors: Hollis Blanchard <hollisb@us.ibm.com>
    2.11   *          Jimi Xenidis <jimix@watson.ibm.com>
    2.12   */
    2.13  
    2.14 -extern unsigned long get_rma_pages(void *devtree);
    2.15  extern int get_rma_page_array(int xc_handle, int domid, xen_pfn_t **page_array,
    2.16  			      unsigned long nr_pages);
    2.17  extern int install_image(int xc_handle, int domid, xen_pfn_t *page_array,
     3.1 --- a/tools/libxc/powerpc64/xc_prose_build.c	Sun Jan 21 08:14:27 2007 -0500
     3.2 +++ b/tools/libxc/powerpc64/xc_prose_build.c	Sun Jan 21 08:15:39 2007 -0500
     3.3 @@ -13,7 +13,7 @@
     3.4   * along with this program; if not, write to the Free Software
     3.5   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     3.6   *
     3.7 - * Copyright (C) IBM Corporation 2006
     3.8 + * Copyright IBM Corporation 2006, 2007
     3.9   *
    3.10   * Authors: Hollis Blanchard <hollisb@us.ibm.com>
    3.11   *          Jonathan Appavoo <jappavoo@us.ibm.com>
    3.12 @@ -34,18 +34,14 @@
    3.13  #include <xg_private.h>
    3.14  #include <xenctrl.h>
    3.15  
    3.16 -#include "flatdevtree_env.h"
    3.17 -#include "flatdevtree.h"
    3.18  #include "utils.h"
    3.19  
    3.20  #define INITRD_ADDR (24UL << 20)
    3.21 -#define DEVTREE_ADDR (16UL << 20)
    3.22  
    3.23  static int init_boot_vcpu(
    3.24      int xc_handle,
    3.25      int domid,
    3.26      struct domain_setup_info *dsi,
    3.27 -    unsigned long devtree_addr,
    3.28      unsigned long kern_addr)
    3.29  {
    3.30      vcpu_guest_context_t ctxt;
    3.31 @@ -55,7 +51,7 @@ static int init_boot_vcpu(
    3.32      ctxt.user_regs.pc = dsi->v_kernentry;
    3.33      ctxt.user_regs.msr = 0;
    3.34      ctxt.user_regs.gprs[1] = 0; /* Linux uses its own stack */
    3.35 -    ctxt.user_regs.gprs[3] = devtree_addr;
    3.36 +    ctxt.user_regs.gprs[3] = 0;
    3.37      ctxt.user_regs.gprs[4] = kern_addr;
    3.38      ctxt.user_regs.gprs[5] = 0; /* reserved for specifying OF handler */
    3.39      /* There is a buggy kernel that does not zero the "local_paca", so
    3.40 @@ -79,85 +75,6 @@ static int init_boot_vcpu(
    3.41      return rc;
    3.42  }
    3.43  
    3.44 -static int load_devtree(
    3.45 -    int xc_handle,
    3.46 -    int domid,
    3.47 -    xen_pfn_t *page_array,
    3.48 -    void *devtree,
    3.49 -    unsigned long devtree_addr,
    3.50 -    uint64_t initrd_base,
    3.51 -    unsigned long initrd_len,
    3.52 -    start_info_t *start_info __attribute__((unused)),
    3.53 -    unsigned long start_info_addr)
    3.54 -{
    3.55 -    uint32_t si[4] = {0, start_info_addr, 0, 0x1000};
    3.56 -    struct boot_param_header *header;
    3.57 -    void *chosen;
    3.58 -    void *xen;
    3.59 -    uint64_t initrd_end = initrd_base + initrd_len;
    3.60 -    unsigned int devtree_size;
    3.61 -    int rc = 0;
    3.62 -
    3.63 -    DPRINTF("adding initrd props\n");
    3.64 -
    3.65 -    chosen = ft_find_node(devtree, "/chosen");
    3.66 -    if (chosen == NULL) {
    3.67 -        DPRINTF("couldn't find /chosen\n");
    3.68 -        return -1;
    3.69 -    }
    3.70 -
    3.71 -    xen = ft_find_node(devtree, "/xen");
    3.72 -    if (xen == NULL) {
    3.73 -        DPRINTF("couldn't find /xen\n");
    3.74 -        return -1;
    3.75 -    }
    3.76 -
    3.77 -    /* initrd-start */
    3.78 -    rc = ft_set_prop(&devtree, chosen, "linux,initrd-start",
    3.79 -            &initrd_base, sizeof(initrd_base));
    3.80 -    if (rc < 0) {
    3.81 -        DPRINTF("couldn't set /chosen/linux,initrd-start\n");
    3.82 -        return rc;
    3.83 -    }
    3.84 -
    3.85 -    /* initrd-end */
    3.86 -    rc = ft_set_prop(&devtree, chosen, "linux,initrd-end",
    3.87 -            &initrd_end, sizeof(initrd_end));
    3.88 -    if (rc < 0) {
    3.89 -        DPRINTF("couldn't set /chosen/linux,initrd-end\n");
    3.90 -        return rc;
    3.91 -    }
    3.92 -
    3.93 -    rc = ft_set_rsvmap(devtree, 1, initrd_base, initrd_len);
    3.94 -    if (rc < 0) {
    3.95 -        DPRINTF("couldn't set initrd reservation\n");
    3.96 -        return ~0UL;
    3.97 -    }
    3.98 -
    3.99 -    /* start-info (XXX being removed soon) */
   3.100 -    rc = ft_set_prop(&devtree, xen, "start-info", si, sizeof(si));
   3.101 -    if (rc < 0) {
   3.102 -        DPRINTF("couldn't set /xen/start-info\n");
   3.103 -        return rc;
   3.104 -    }
   3.105 -
   3.106 -    header = devtree;
   3.107 -    devtree_size = header->totalsize;
   3.108 -    {
   3.109 -        static const char dtb[] = "/tmp/xc_domU.dtb";
   3.110 -        int dfd = creat(dtb, 0666);
   3.111 -        if (dfd != -1) {
   3.112 -            write(dfd, devtree, devtree_size);
   3.113 -            close(dfd);
   3.114 -        } else
   3.115 -            DPRINTF("could not open(\"%s\")\n", dtb);
   3.116 -    }
   3.117 -
   3.118 -    DPRINTF("copying device tree to 0x%lx[0x%x]\n", DEVTREE_ADDR, devtree_size);
   3.119 -    return install_image(xc_handle, domid, page_array, devtree, DEVTREE_ADDR,
   3.120 -                       devtree_size);
   3.121 -}
   3.122 -
   3.123  static int load_initrd(
   3.124      int xc_handle,
   3.125      int domid,
   3.126 @@ -188,13 +105,12 @@ out:
   3.127  }
   3.128  
   3.129  static unsigned long create_start_info(
   3.130 -	void *devtree, start_info_t *start_info,
   3.131 +	start_info_t *start_info,
   3.132          unsigned int console_evtchn, unsigned int store_evtchn,
   3.133  	unsigned long nr_pages, unsigned long rma_pages, const char *cmdline)
   3.134  {
   3.135      unsigned long start_info_addr;
   3.136      uint64_t rma_top;
   3.137 -    int rc;
   3.138  
   3.139      memset(start_info, 0, sizeof(*start_info));
   3.140      snprintf(start_info->magic, sizeof(start_info->magic),
   3.141 @@ -214,12 +130,6 @@ static unsigned long create_start_info(
   3.142      start_info->cmd_line[MAX_GUEST_CMDLINE-1]=0;
   3.143      start_info_addr = rma_top - 4*PAGE_SIZE;
   3.144  
   3.145 -    rc = ft_set_rsvmap(devtree, 0, start_info_addr, 4*PAGE_SIZE);
   3.146 -    if (rc < 0) {
   3.147 -        DPRINTF("couldn't set start_info reservation\n");
   3.148 -        return ~0UL;
   3.149 -    }
   3.150 -
   3.151      return start_info_addr;
   3.152  }
   3.153  
   3.154 @@ -239,14 +149,12 @@ int xc_prose_build(int xc_handle,
   3.155                     unsigned int store_evtchn,
   3.156                     unsigned long *store_mfn,
   3.157                     unsigned int console_evtchn,
   3.158 -                   unsigned long *console_mfn,
   3.159 -                   void *devtree)
   3.160 +                   unsigned long *console_mfn)
   3.161  {
   3.162      start_info_t start_info;
   3.163      struct domain_setup_info dsi;
   3.164      xen_pfn_t *page_array = NULL;
   3.165      unsigned long nr_pages;
   3.166 -    unsigned long devtree_addr = 0;
   3.167      unsigned long kern_addr;
   3.168      unsigned long initrd_base = 0;
   3.169      unsigned long initrd_len = 0;
   3.170 @@ -261,11 +169,7 @@ int xc_prose_build(int xc_handle,
   3.171      nr_pages = mem_mb << (20 - PAGE_SHIFT);
   3.172      DPRINTF("nr_pages 0x%lx\n", nr_pages);
   3.173  
   3.174 -    rma_pages = get_rma_pages(devtree);
   3.175 -    if (rma_pages == 0) {
   3.176 -	    rc = -1;
   3.177 -	    goto out;
   3.178 -    }
   3.179 +    rma_pages = (1 << 26) >> PAGE_SHIFT; /* 64 MB */
   3.180  
   3.181      if (get_rma_page_array(xc_handle, domid, &page_array, rma_pages)) {
   3.182          rc = -1;
   3.183 @@ -289,9 +193,9 @@ int xc_prose_build(int xc_handle,
   3.184      }
   3.185  
   3.186      /* start_info stuff: about to be removed  */
   3.187 -    start_info_addr = create_start_info(devtree, &start_info, console_evtchn,
   3.188 +    start_info_addr = create_start_info(&start_info, console_evtchn,
   3.189                                          store_evtchn, nr_pages,
   3.190 -					rma_pages, cmdline);
   3.191 +                                        rma_pages, cmdline);
   3.192      *console_mfn = page_array[start_info.console.domU.mfn];
   3.193      *store_mfn = page_array[start_info.store_mfn];
   3.194      if (install_image(xc_handle, domid, page_array, &start_info,
   3.195 @@ -300,19 +204,7 @@ int xc_prose_build(int xc_handle,
   3.196          goto out;
   3.197      }
   3.198  
   3.199 -    if (devtree) {
   3.200 -        DPRINTF("loading flattened device tree\n");
   3.201 -        devtree_addr = DEVTREE_ADDR;
   3.202 -        if (load_devtree(xc_handle, domid, page_array, devtree, devtree_addr,
   3.203 -                         initrd_base, initrd_len, &start_info,
   3.204 -                         start_info_addr)) {
   3.205 -            DPRINTF("couldn't load flattened device tree.\n");
   3.206 -            rc = -1;
   3.207 -            goto out;
   3.208 -        }
   3.209 -    }
   3.210 -
   3.211 -    if (init_boot_vcpu(xc_handle, domid, &dsi, devtree_addr, kern_addr)) {
   3.212 +    if (init_boot_vcpu(xc_handle, domid, &dsi, kern_addr)) {
   3.213          rc = -1;
   3.214          goto out;
   3.215      }
     4.1 --- a/tools/libxc/xenguest.h	Sun Jan 21 08:14:27 2007 -0500
     4.2 +++ b/tools/libxc/xenguest.h	Sun Jan 21 08:15:39 2007 -0500
     4.3 @@ -122,18 +122,4 @@ int xc_set_hvm_param(
     4.4  int xc_get_hvm_param(
     4.5      int handle, domid_t dom, int param, unsigned long *value);
     4.6  
     4.7 -/* PowerPC specific. */
     4.8 -int xc_prose_build(int xc_handle,
     4.9 -                   uint32_t domid,
    4.10 -                   unsigned int mem_mb,
    4.11 -                   const char *image_name,
    4.12 -                   const char *ramdisk_name,
    4.13 -                   const char *cmdline,
    4.14 -                   const char *features,
    4.15 -                   unsigned long flags,
    4.16 -                   unsigned int store_evtchn,
    4.17 -                   unsigned long *store_mfn,
    4.18 -                   unsigned int console_evtchn,
    4.19 -                   unsigned long *console_mfn);
    4.20 -
    4.21  #endif /* XENGUEST_H */
     5.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Sun Jan 21 08:14:27 2007 -0500
     5.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Sun Jan 21 08:15:39 2007 -0500
     5.3 @@ -947,28 +947,26 @@ static PyObject *pyxc_prose_build(XcObje
     5.4      unsigned int mem_mb;
     5.5      unsigned long store_mfn = 0;
     5.6      unsigned long console_mfn = 0;
     5.7 -    void *arch_args = NULL;
     5.8      int unused;
     5.9  
    5.10      static char *kwd_list[] = { "dom", "store_evtchn",
    5.11                                  "console_evtchn", "image", "memsize",
    5.12                                  /* optional */
    5.13                                  "ramdisk", "cmdline", "flags",
    5.14 -                                "features", "arch_args", NULL };
    5.15 +                                "features", NULL };
    5.16  
    5.17 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssiss#", kwd_list,
    5.18 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssis#", kwd_list,
    5.19                                        &dom, &store_evtchn, &mem_mb,
    5.20                                        &console_evtchn, &image,
    5.21                                        /* optional */
    5.22                                        &ramdisk, &cmdline, &flags,
    5.23 -                                      &features, &arch_args, &unused) )
    5.24 +                                      &features, &unused) )
    5.25          return NULL;
    5.26  
    5.27      if ( xc_prose_build(self->xc_handle, dom, mem_mb, image,
    5.28                          ramdisk, cmdline, features, flags,
    5.29                          store_evtchn, &store_mfn,
    5.30 -                        console_evtchn, &console_mfn,
    5.31 -                        arch_args) != 0 ) {
    5.32 +                        console_evtchn, &console_mfn) != 0 ) {
    5.33          if (!errno)
    5.34               errno = EINVAL;
    5.35          return pyxc_error_to_exception();
     6.1 --- a/tools/python/xen/xend/FlatDeviceTree.py	Sun Jan 21 08:14:27 2007 -0500
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,359 +0,0 @@
     6.4 -#!/usr/bin/env python
     6.5 -#
     6.6 -# This library is free software; you can redistribute it and/or
     6.7 -# modify it under the terms of version 2.1 of the GNU Lesser General Public
     6.8 -# License as published by the Free Software Foundation.
     6.9 -#
    6.10 -# This library is distributed in the hope that it will be useful,
    6.11 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.12 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.13 -# Lesser General Public License for more details.
    6.14 -#
    6.15 -# You should have received a copy of the GNU Lesser General Public
    6.16 -# License along with this library; if not, write to the Free Software
    6.17 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.18 -#
    6.19 -# Copyright (C) IBM Corp. 2006
    6.20 -#
    6.21 -# Authors: Hollis Blanchard <hollisb@us.ibm.com>
    6.22 -
    6.23 -import os
    6.24 -import sys
    6.25 -import struct
    6.26 -import stat
    6.27 -import re
    6.28 -import glob
    6.29 -import math
    6.30 -
    6.31 -_host_devtree_root = '/proc/device-tree'
    6.32 -
    6.33 -_OF_DT_HEADER = int("d00dfeed", 16) # avoid signed/unsigned FutureWarning
    6.34 -_OF_DT_BEGIN_NODE = 0x1
    6.35 -_OF_DT_END_NODE = 0x2
    6.36 -_OF_DT_PROP = 0x3
    6.37 -_OF_DT_END = 0x9
    6.38 -
    6.39 -def _bincat(seq, separator=''):
    6.40 -    '''Concatenate the contents of seq into a bytestream.'''
    6.41 -    strs = []
    6.42 -    for item in seq:
    6.43 -        if isinstance(item, int):
    6.44 -            strs.append(struct.pack(">I", item))
    6.45 -        elif isinstance(item, long):
    6.46 -            strs.append(struct.pack(">Q", item))
    6.47 -        else:
    6.48 -            try:
    6.49 -                strs.append(item.to_bin())
    6.50 -            except AttributeError, e:
    6.51 -                strs.append(item)
    6.52 -    return separator.join(strs)
    6.53 -
    6.54 -def _alignup(val, alignment):
    6.55 -    return (val + alignment - 1) & ~(alignment - 1)
    6.56 -
    6.57 -def _pad(buf, alignment):
    6.58 -    '''Pad bytestream with NULLs to specified alignment.'''
    6.59 -    padlen = _alignup(len(buf), alignment)
    6.60 -    return buf + '\0' * (padlen - len(buf))
    6.61 -    # not present in Python 2.3:
    6.62 -    #return buf.ljust(_padlen, '\0')
    6.63 -
    6.64 -def _indent(item):
    6.65 -    indented = []
    6.66 -    for line in str(item).splitlines(True):
    6.67 -        indented.append('    ' + line)
    6.68 -    return ''.join(indented)
    6.69 -
    6.70 -class _Property:
    6.71 -    _nonprint = re.compile('[\000-\037\200-\377]')
    6.72 -    def __init__(self, node, name, value):
    6.73 -        self.node = node
    6.74 -        self.value = value
    6.75 -        self.name = name
    6.76 -        self.node.tree.stradd(name)
    6.77 -
    6.78 -    def __str__(self):
    6.79 -        result = self.name
    6.80 -        if self.value:
    6.81 -            searchtext = self.value
    6.82 -            # it's ok for a string to end in NULL
    6.83 -            if searchtext.find('\000') == len(searchtext)-1:
    6.84 -                searchtext = searchtext[:-1]
    6.85 -            m = self._nonprint.search(searchtext)
    6.86 -            if m:
    6.87 -                bytes = struct.unpack("B" * len(self.value), self.value)
    6.88 -                hexbytes = [ '%02x' % b for b in bytes ]
    6.89 -                words = []
    6.90 -                for i in range(0, len(self.value), 4):
    6.91 -                    words.append(''.join(hexbytes[i:i+4]))
    6.92 -                v = '<' + ' '.join(words) + '>'
    6.93 -            else:
    6.94 -                v = '"%s"' % self.value
    6.95 -            result += ': ' + v
    6.96 -        return result
    6.97 -
    6.98 -    def to_bin(self):
    6.99 -        offset = self.node.tree.stroffset(self.name)
   6.100 -        return struct.pack('>III', _OF_DT_PROP, len(self.value), offset) \
   6.101 -            + _pad(self.value, 4)
   6.102 -
   6.103 -class _Node:
   6.104 -    def __init__(self, tree, name):
   6.105 -        self.tree = tree
   6.106 -        self.name = name
   6.107 -        self.props = {}
   6.108 -        self.children = {}
   6.109 -        self.phandle = 0
   6.110 -
   6.111 -    def __str__(self):
   6.112 -        propstrs = [ _indent(prop) for prop in self.props.values() ]
   6.113 -        childstrs = [ _indent(child) for child in self.children.values() ]
   6.114 -        return '%s:\n%s\n%s' % (self.name, '\n'.join(propstrs),
   6.115 -            '\n'.join(childstrs))
   6.116 -
   6.117 -    def to_bin(self):
   6.118 -        name = _pad(self.name + '\0', 4)
   6.119 -        return struct.pack('>I', _OF_DT_BEGIN_NODE) + \
   6.120 -                name + \
   6.121 -                _bincat(self.props.values()) + \
   6.122 -                _bincat(self.children.values()) + \
   6.123 -                struct.pack('>I', _OF_DT_END_NODE)
   6.124 -
   6.125 -    def addprop(self, propname, *cells):
   6.126 -        '''setprop with duplicate error-checking.'''
   6.127 -        if propname in self.props:
   6.128 -            raise AttributeError('%s/%s already exists' % (self.name, propname))
   6.129 -        self.setprop(propname, *cells)
   6.130 -
   6.131 -    def setprop(self, propname, *cells):
   6.132 -        self.props[propname] = _Property(self, propname, _bincat(cells))
   6.133 -
   6.134 -    def addnode(self, nodename):
   6.135 -        '''newnode with duplicate error-checking.'''
   6.136 -        if nodename in self.children:
   6.137 -            raise AttributeError('%s/%s already exists' % (self.name, nodename))
   6.138 -        return self.newnode(nodename)
   6.139 -
   6.140 -    def newnode(self, nodename):
   6.141 -        node = _Node(self.tree, nodename)
   6.142 -        self.children[nodename] = node
   6.143 -        return node
   6.144 -
   6.145 -    def getprop(self, propname):
   6.146 -        return self.props[propname]
   6.147 -
   6.148 -    def getchild(self, nodename):
   6.149 -        return self.children[nodename]
   6.150 -
   6.151 -    def get_phandle(self):
   6.152 -        if self.phandle:
   6.153 -            return self.phandle
   6.154 -        self.phandle = self.tree.alloc_phandle()
   6.155 -        self.addprop('linux,phandle', self.phandle)
   6.156 -        return self.phandle
   6.157 -
   6.158 -class _Header:
   6.159 -    def __init__(self):
   6.160 -        self.magic = 0
   6.161 -        self.totalsize = 0
   6.162 -        self.off_dt_struct = 0
   6.163 -        self.off_dt_strings = 0
   6.164 -        self.off_mem_rsvmap = 0
   6.165 -        self.version = 0
   6.166 -        self.last_comp_version = 0
   6.167 -        self.boot_cpuid_phys = 0
   6.168 -        self.size_dt_strings = 0
   6.169 -    def to_bin(self):
   6.170 -        return struct.pack('>9I',
   6.171 -            self.magic,
   6.172 -            self.totalsize,
   6.173 -            self.off_dt_struct,
   6.174 -            self.off_dt_strings,
   6.175 -            self.off_mem_rsvmap,
   6.176 -            self.version,
   6.177 -            self.last_comp_version,
   6.178 -            self.boot_cpuid_phys,
   6.179 -            self.size_dt_strings)
   6.180 -
   6.181 -class _StringBlock:
   6.182 -    def __init__(self):
   6.183 -        self.table = []
   6.184 -    def to_bin(self):
   6.185 -        return _bincat(self.table, '\0') + '\0'
   6.186 -    def add(self, str):
   6.187 -        self.table.append(str)
   6.188 -    def getoffset(self, str):
   6.189 -        return self.to_bin().index(str + '\0')
   6.190 -
   6.191 -class Tree(_Node):
   6.192 -    def __init__(self):
   6.193 -        self.last_phandle = 0
   6.194 -        self.strings = _StringBlock()
   6.195 -        self.reserved = [(0, 0)]
   6.196 -        _Node.__init__(self, self, '\0')
   6.197 -
   6.198 -    def alloc_phandle(self):
   6.199 -        self.last_phandle += 1
   6.200 -        return self.last_phandle
   6.201 -
   6.202 -    def stradd(self, str):
   6.203 -        return self.strings.add(str)
   6.204 -
   6.205 -    def stroffset(self, str):
   6.206 -        return self.strings.getoffset(str)
   6.207 -
   6.208 -    def reserve(self, start, len):
   6.209 -        self.reserved.insert(0, (start, len))
   6.210 -
   6.211 -    def to_bin(self):
   6.212 -        # layout:
   6.213 -        #   header
   6.214 -        #   reservation map
   6.215 -        #   string block
   6.216 -        #   data block
   6.217 -
   6.218 -        datablock = _Node.to_bin(self)
   6.219 -
   6.220 -        r = [ struct.pack('>QQ', rsrv[0], rsrv[1]) for rsrv in self.reserved ]
   6.221 -        reserved = _bincat(r)
   6.222 -
   6.223 -        strblock = _pad(self.strings.to_bin(), 4)
   6.224 -        strblocklen = len(strblock)
   6.225 -
   6.226 -        header = _Header()
   6.227 -        header.magic = _OF_DT_HEADER
   6.228 -        header.off_mem_rsvmap = _alignup(len(header.to_bin()), 8)
   6.229 -        header.off_dt_strings = header.off_mem_rsvmap + len(reserved)
   6.230 -        header.off_dt_struct = header.off_dt_strings + strblocklen
   6.231 -        header.version = 0x10
   6.232 -        header.last_comp_version = 0x10
   6.233 -        header.boot_cpuid_phys = 0
   6.234 -        header.size_dt_strings = strblocklen
   6.235 -
   6.236 -        payload = reserved + \
   6.237 -                strblock + \
   6.238 -                datablock + \
   6.239 -                struct.pack('>I', _OF_DT_END)
   6.240 -        header.totalsize = len(payload) + _alignup(len(header.to_bin()), 8)
   6.241 -        return _pad(header.to_bin(), 8) + payload
   6.242 -
   6.243 -def _readfile(fullpath):
   6.244 -    '''Return full contents of a file.'''
   6.245 -    f = file(fullpath, 'r')
   6.246 -    data = f.read()
   6.247 -    f.close()
   6.248 -    return data
   6.249 -
   6.250 -def _find_first_cpu(dirpath):
   6.251 -    '''Find the first node of type 'cpu' in a directory tree.'''
   6.252 -    cpulist = glob.glob(os.path.join(dirpath, 'cpus', '*'))
   6.253 -    for node in cpulist:
   6.254 -        try:
   6.255 -            data = _readfile(os.path.join(node, 'device_type'))
   6.256 -        except IOError:
   6.257 -            continue
   6.258 -        if 'cpu' in data:
   6.259 -            return node
   6.260 -    raise IOError("couldn't find any CPU nodes under " + dirpath)
   6.261 -
   6.262 -def _copynode(node, dirpath, propfilter):
   6.263 -    '''Copy all properties and children nodes from a directory tree.'''
   6.264 -    dirents = os.listdir(dirpath)
   6.265 -    for dirent in dirents:
   6.266 -        fullpath = os.path.join(dirpath, dirent)
   6.267 -        st = os.lstat(fullpath)
   6.268 -        if stat.S_ISDIR(st.st_mode):
   6.269 -            child = node.addnode(dirent)
   6.270 -            _copynode(child, fullpath, propfilter)
   6.271 -        elif stat.S_ISREG(st.st_mode) and propfilter(fullpath):
   6.272 -            node.addprop(dirent, _readfile(fullpath))
   6.273 -
   6.274 -def build(imghandler):
   6.275 -    '''Construct a device tree by combining the domain's configuration and
   6.276 -    the host's device tree.'''
   6.277 -    root = Tree()
   6.278 -
   6.279 -    # 1st reseravtion entry used for start_info, console, store, shared_info
   6.280 -    root.reserve(0x3ffc000, 0x4000)
   6.281 -
   6.282 -    # 2nd reservation enrty used for initrd, later on when we load the
   6.283 -    # initrd we may fill this in with zeroes which signifies the end
   6.284 -    # of the reservation map.  So as to avoid adding a zero map now we
   6.285 -    # put some bogus yet sensible numbers here.
   6.286 -    root.reserve(0x1000000, 0x1000)
   6.287 -
   6.288 -    root.addprop('device_type', 'chrp-but-not-really\0')
   6.289 -    root.addprop('#size-cells', 2)
   6.290 -    root.addprop('#address-cells', 2)
   6.291 -    root.addprop('model', 'Momentum,Maple-D\0')
   6.292 -    root.addprop('compatible', 'Momentum,Maple\0')
   6.293 -
   6.294 -    xen = root.addnode('xen')
   6.295 -    xen.addprop('start-info', long(0x3ffc000), long(0x1000))
   6.296 -    xen.addprop('version', 'Xen-3.0-unstable\0')
   6.297 -    xen.addprop('reg', long(imghandler.vm.domid), long(0))
   6.298 -    xen.addprop('domain-name', imghandler.vm.getName() + '\0')
   6.299 -    xencons = xen.addnode('console')
   6.300 -    xencons.addprop('interrupts', 1, 0)
   6.301 -
   6.302 -    # add memory nodes
   6.303 -    totalmem = imghandler.vm.getMemoryTarget() * 1024
   6.304 -    rma_log = 26 ### imghandler.vm.info.get('powerpc_rma_log')
   6.305 -    rma_bytes = 1 << rma_log
   6.306 -
   6.307 -    # RMA node
   6.308 -    rma = root.addnode('memory@0')
   6.309 -    rma.addprop('reg', long(0), long(rma_bytes))
   6.310 -    rma.addprop('device_type', 'memory\0')
   6.311 -
   6.312 -    # all the rest in a single node
   6.313 -    remaining = totalmem - rma_bytes
   6.314 -    if remaining > 0:
   6.315 -        mem = root.addnode('memory@1')
   6.316 -        mem.addprop('reg', long(rma_bytes), long(remaining))
   6.317 -        mem.addprop('device_type', 'memory\0')
   6.318 -
   6.319 -    # add CPU nodes
   6.320 -    cpus = root.addnode('cpus')
   6.321 -    cpus.addprop('smp-enabled')
   6.322 -    cpus.addprop('#size-cells', 0)
   6.323 -    cpus.addprop('#address-cells', 1)
   6.324 -
   6.325 -    # Copy all properties the system firmware gave us, except for 'linux,'
   6.326 -    # properties, from the first CPU node in the device tree. Do this once for
   6.327 -    # every vcpu. Hopefully all cpus are identical...
   6.328 -    cpu0 = None
   6.329 -    cpu0path = _find_first_cpu(_host_devtree_root)
   6.330 -    def _nolinuxprops(fullpath):
   6.331 -        return not os.path.basename(fullpath).startswith('linux,')
   6.332 -    for i in range(imghandler.vm.getVCpuCount()):
   6.333 -        # create new node and copy all properties
   6.334 -        cpu = cpus.addnode('PowerPC,970@%d' % i)
   6.335 -        _copynode(cpu, cpu0path, _nolinuxprops)
   6.336 -
   6.337 -        # overwrite what we need to
   6.338 -        shadow_mb = imghandler.vm.info.get('shadow_memory', 1)
   6.339 -        shadow_mb_log = int(math.log(shadow_mb, 2))
   6.340 -        pft_size = shadow_mb_log + 20
   6.341 -        cpu.setprop('ibm,pft-size', 0, pft_size)
   6.342 -
   6.343 -        # set default CPU
   6.344 -        if cpu0 == None:
   6.345 -            cpu0 = cpu
   6.346 -
   6.347 -    chosen = root.addnode('chosen')
   6.348 -    chosen.addprop('cpu', cpu0.get_phandle())
   6.349 -    chosen.addprop('memory', rma.get_phandle())
   6.350 -    chosen.addprop('linux,stdout-path', '/xen/console\0')
   6.351 -    chosen.addprop('interrupt-controller', xen.get_phandle())
   6.352 -    chosen.addprop('bootargs', imghandler.cmdline + '\0')
   6.353 -    # xc_linux_load.c will overwrite these 64-bit properties later
   6.354 -    chosen.addprop('linux,initrd-start', long(0))
   6.355 -    chosen.addprop('linux,initrd-end', long(0))
   6.356 -
   6.357 -    if 1:
   6.358 -        f = file('/tmp/domU.dtb', 'w')
   6.359 -        f.write(root.to_bin())
   6.360 -        f.close()
   6.361 -
   6.362 -    return root
     7.1 --- a/tools/python/xen/xend/image.py	Sun Jan 21 08:14:27 2007 -0500
     7.2 +++ b/tools/python/xen/xend/image.py	Sun Jan 21 08:15:39 2007 -0500
     7.3 @@ -29,7 +29,6 @@ from xen.xend.XendLogging import log
     7.4  from xen.xend.server.netif import randomMAC
     7.5  from xen.xend.xenstore.xswatch import xswatch
     7.6  from xen.xend import arch
     7.7 -from xen.xend import FlatDeviceTree
     7.8  
     7.9  xc = xen.lowlevel.xc.xc()
    7.10  
    7.11 @@ -215,9 +214,11 @@ class LinuxImageHandler(ImageHandler):
    7.12                                ramdisk        = self.ramdisk,
    7.13                                features       = self.vm.getFeatures())
    7.14  
    7.15 -class PPC_LinuxImageHandler(LinuxImageHandler):
    7.16  
    7.17 -    ostype = "linux"
    7.18 +
    7.19 +class PPC_ProseImageHandler(LinuxImageHandler):
    7.20 +
    7.21 +    ostype = "prose"
    7.22  
    7.23      def configure(self, vmConfig, imageConfig, deviceConfig):
    7.24          LinuxImageHandler.configure(self, vmConfig, imageConfig, deviceConfig)
    7.25 @@ -229,44 +230,6 @@ class PPC_LinuxImageHandler(LinuxImageHa
    7.26  
    7.27          mem_mb = self.getRequiredInitialReservation() / 1024
    7.28  
    7.29 -        log.debug("domid          = %d", self.vm.getDomid())
    7.30 -        log.debug("memsize        = %d", mem_mb)
    7.31 -        log.debug("image          = %s", self.kernel)
    7.32 -        log.debug("store_evtchn   = %d", store_evtchn)
    7.33 -        log.debug("console_evtchn = %d", console_evtchn)
    7.34 -        log.debug("cmdline        = %s", self.cmdline)
    7.35 -        log.debug("ramdisk        = %s", self.ramdisk)
    7.36 -        log.debug("vcpus          = %d", self.vm.getVCpuCount())
    7.37 -        log.debug("features       = %s", self.vm.getFeatures())
    7.38 -
    7.39 -        return xc.linux_build(domid          = self.vm.getDomid(),
    7.40 -                              memsize        = mem_mb,
    7.41 -                              image          = self.kernel,
    7.42 -                              store_evtchn   = store_evtchn,
    7.43 -                              console_evtchn = console_evtchn,
    7.44 -                              cmdline        = self.cmdline,
    7.45 -                              ramdisk        = self.ramdisk,
    7.46 -                              features       = self.vm.getFeatures())
    7.47 -
    7.48 -    def getRequiredShadowMemory(self, shadow_mem_kb, maxmem_kb):
    7.49 -        """@param shadow_mem_kb The configured shadow memory, in KiB.
    7.50 -        @param maxmem_kb The configured maxmem, in KiB.
    7.51 -        @return The corresponding required amount of shadow memory, also in
    7.52 -        KiB.
    7.53 -        PowerPC currently uses "shadow memory" to refer to the hash table."""
    7.54 -        return max(maxmem_kb / 64, shadow_mem_kb)
    7.55 -
    7.56 -
    7.57 -class PPC_ProseImageHandler(PPC_LinuxImageHandler):
    7.58 -
    7.59 -    ostype = "prose"
    7.60 -
    7.61 -    def buildDomain(self):
    7.62 -        store_evtchn = self.vm.getStorePort()
    7.63 -        console_evtchn = self.vm.getConsolePort()
    7.64 -
    7.65 -        mem_mb = self.getRequiredInitialReservation() / 1024
    7.66 -
    7.67          log.debug("dom            = %d", self.vm.getDomid())
    7.68          log.debug("memsize        = %d", mem_mb)
    7.69          log.debug("image          = %s", self.kernel)
    7.70 @@ -277,8 +240,6 @@ class PPC_ProseImageHandler(PPC_LinuxIma
    7.71          log.debug("vcpus          = %d", self.vm.getVCpuCount())
    7.72          log.debug("features       = %s", self.vm.getFeatures())
    7.73  
    7.74 -        devtree = FlatDeviceTree.build(self)
    7.75 -
    7.76          return xc.arch_prose_build(dom            = self.vm.getDomid(),
    7.77                                     memsize        = mem_mb,
    7.78                                     image          = self.kernel,
    7.79 @@ -286,8 +247,7 @@ class PPC_ProseImageHandler(PPC_LinuxIma
    7.80                                     console_evtchn = console_evtchn,
    7.81                                     cmdline        = self.cmdline,
    7.82                                     ramdisk        = self.ramdisk,
    7.83 -                                   features       = self.vm.getFeatures(),
    7.84 -                                   arch_args      = devtree.to_bin())
    7.85 +                                   features       = self.vm.getFeatures())
    7.86  
    7.87      def getRequiredShadowMemory(self, shadow_mem_kb, maxmem_kb):
    7.88          """@param shadow_mem_kb The configured shadow memory, in KiB.
    7.89 @@ -628,7 +588,7 @@ class X86_Linux_ImageHandler(LinuxImageH
    7.90  
    7.91  _handlers = {
    7.92      "powerpc": {
    7.93 -        "linux": PPC_LinuxImageHandler,
    7.94 +        "linux": LinuxImageHandler,
    7.95          "prose": PPC_ProseImageHandler,
    7.96      },
    7.97      "ia64": {