WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-ppc-devel

[XenPPC] [pushed] [ppc] fix dom creation

changeset:   10269:d2680c1914f16f249a4d045dcf326dcb4e4dc158
user:        jimix@xxxxxxxxxxxxxxxxxxxxx
date:        Fri May 12 16:05:41 2006 -0400
files:       tools/domctrl/create.c
description:
[ppc] fix dom creation


diff -r e8877f530c35434e15137ba0ca6a94cd1290da24 -r 
d2680c1914f16f249a4d045dcf326dcb4e4dc158 tools/domctrl/create.c
--- a/tools/domctrl/create.c    Fri May 12 16:05:10 2006 -0400
+++ b/tools/domctrl/create.c    Fri May 12 16:05:41 2006 -0400
@@ -22,17 +22,9 @@
         (void) (&_x == &_y);            \
         _x > _y ? _x : _y; })
 
-const char firmware_path[] = "ofh_bin";
-const char devtree_path[] = "domU-devtree.bin";
-const char initrd_path[] = "initrd";
-
-const unsigned long FIRMWARE_ADDR = 16<<20;
-const unsigned long DEVTREE_ADDR = 20<<20;
-const unsigned long INITRD_ADDR = 24<<20;
-
-static uint8_t *load_file(const char *path, unsigned long *filesize)
-{
-       uint8_t *img;
+static void *load_file(const char *path, unsigned long *filesize)
+{
+       void *img;
        ssize_t size;
        int fd;
 
@@ -47,6 +39,7 @@ static uint8_t *load_file(const char *pa
        size = lseek(fd, 0, SEEK_END);
        if (size < 0) {
                perror(path);
+        close(fd);
                return NULL;
        }
        lseek(fd, 0, SEEK_SET);
@@ -54,22 +47,29 @@ static uint8_t *load_file(const char *pa
        img = malloc(size);
        if (img == NULL) {
                perror(path);
+        close(fd);
                return NULL;
        }
 
        size = read(fd, img, size);
        if (size <= 0) {
                perror(path);
+        close(fd);
                free(img);
                return NULL;
        }
 
        if (filesize)
                *filesize = size;
-
+    close(fd);
        return img;
 }
 
+static void free_file(void *img)
+{
+    if (img != NULL)
+        free(img);
+}
 static int create_domain(int *domid)
 {
        xen_domain_handle_t dummy = { 0 };
@@ -106,9 +106,11 @@ static int create_domain(int *domid)
        return 0;
 }
 
-static int init_boot_vcpu(int domid, struct domain_setup_info *dsi,
-                       unsigned long fwbase, unsigned long initrd_base,
-                       unsigned long initrd_len)
+static int init_boot_vcpu(
+    int domid,
+    struct domain_setup_info *dsi,
+    unsigned long dtb,
+    unsigned long kaddr)
 {
        vcpu_guest_context_t ctxt;
        int rc;
@@ -117,9 +119,9 @@ static int init_boot_vcpu(int domid, str
        ctxt.user_regs.pc = dsi->v_kernentry;
        ctxt.user_regs.msr = 0;
        ctxt.user_regs.gprs[1] = 32<<20; /* XXX arbitrary stack address */
-       ctxt.user_regs.gprs[3] = initrd_base;
-       ctxt.user_regs.gprs[4] = initrd_len;
-       ctxt.user_regs.gprs[5] = fwbase;
+       ctxt.user_regs.gprs[3] = dtb;
+       ctxt.user_regs.gprs[4] = kaddr;
+       ctxt.user_regs.gprs[5] = 0;
 
        DEBUG(printf("xc_vcpu_setvcpucontext\n"));
        rc = xc_vcpu_setcontext(xc_handle, domid, 0, &ctxt);
@@ -155,56 +157,27 @@ static int install_image(int domid, unsi
 }
 
 /* XXX be more flexible about placement in memory */
-static int load_firmware(int domid, const char *fwpath, const char *dtpath,
-                       struct domain_setup_info *dsi,
-                       unsigned long *page_array, unsigned long *fwbase)
-{
-       uint64_t *ofh_tree;
+static int load_dtb(
+    int domid,
+    const char *dtb_path,
+    unsigned long dtb_addr,
+    struct domain_setup_info *dsi,
+    unsigned long *page_array)
+{
        uint8_t *img;
-       unsigned long fwsize;
-       unsigned long dtsize;
+       unsigned long dtb_size;
        int rc = 0;
 
-       img = load_file(dtpath, &dtsize);
-       if (img == NULL) {
-               rc = -1;
-               goto out;
-       }
-
-       /* place the device tree at 20MB */
-       DEBUG(printf("copying device tree to 0x%lx - 0x%lx\n", DEVTREE_ADDR,
-                               DEVTREE_ADDR + dtsize));
-       if (install_image(domid, page_array, img, DEVTREE_ADDR, dtsize))
-               goto out;
-       free(img);
-
-       /* load firmware image */
-       img = load_file(fwpath, &fwsize);
-       if (img == NULL) {
-               rc = -1;
-               goto out;
-       }
-
-       /* inform firmware of the device tree location */
-       ofh_tree = (uint64_t *)(img + 0x10);
-       if (*ofh_tree != 0xdeadbeef00000000) {
-               fprintf(stderr, "error: misformatted firmware image\n");
-               rc = -1;
-               goto out;
-       }
-       *ofh_tree = DEVTREE_ADDR;
-
-       /* place the firmware image at 16MB */
-       DEBUG(printf("copying firmware to 0x%lx - 0x%lx\n", FIRMWARE_ADDR,
-                               FIRMWARE_ADDR + fwsize));
-       if (install_image(domid, page_array, img, FIRMWARE_ADDR, fwsize))
-               goto out;
-
-       dsi->v_end = max(DEVTREE_ADDR + dtsize, FIRMWARE_ADDR + fwsize);
-       *fwbase = FIRMWARE_ADDR;
-
-out:
-       free(img);
+       img = load_file(dtb_path, &dtb_size);
+    if (img != NULL) {
+        DEBUG(printf("copying device tree to 0x%lx[0x%lx]\n",
+                     dtb_addr, dtb_size));
+        if (install_image(domid, page_array, img, dtb_addr, dtb_size) != 0)
+            printf("%s: install_image(): failed\n", __func__);
+    } else
+        printf("%s: load_file(%s): fialed\n", __func__, dtb_path);
+
+       free_file(img);
        return rc;
 }
 
@@ -238,9 +211,11 @@ static void hack_kernel_img(uint8_t *img
        }
 }
 
-static int load_kernel(int domid, const char *kernel_path,
-                       struct domain_setup_info *dsi,
-                       unsigned long *page_array)
+static int load_kernel(
+    int domid,
+    const char *kernel_path,
+    struct domain_setup_info *dsi,
+    unsigned long *page_array)
 {
        struct load_funcs load_funcs;
        uint8_t *kernel_img;
@@ -259,6 +234,7 @@ static int load_kernel(int domid, const 
        DEBUG(printf("probe_elf\n"));
        rc = probe_elf(kernel_img, kernel_size, &load_funcs);
        if (rc < 0) {
+        rc = -1;
                printf("%s is not an ELF file\n", kernel_path);
                goto out;
        }
@@ -266,6 +242,7 @@ static int load_kernel(int domid, const 
        DEBUG(printf("parseimage\n"));
        rc = (load_funcs.parseimage)(kernel_img, kernel_size, dsi);
        if (rc < 0) {
+        rc = -1;
                goto out;
        }
 
@@ -280,12 +257,17 @@ static int load_kernel(int domid, const 
        DEBUG(printf("  v_kernentry %lx\n", dsi->v_kernentry));
 
 out:
-       free(kernel_img);
-       return rc;
-}
-
-static int load_initrd(int domid, unsigned long *page_array,
-               const char *initrd_path, unsigned long *base, unsigned long 
*len)
+       free_file(kernel_img);
+       return rc;
+}
+
+#ifdef INITRD
+static int load_initrd(
+    int domid,
+    unsigned long *page_array,
+    const char *initrd_path,
+    unsigned long *base,
+    unsigned long *len)
 {
        uint8_t *initrd_img;
 
@@ -302,36 +284,45 @@ static int load_initrd(int domid, unsign
        *base = INITRD_ADDR;
 
 out:
-       free(initrd_img);
+       free_file(initrd_img);
        return 0;
 }
+#endif
 
 /* place start_info in the uppermost page */
-static int load_start_info(int domid, unsigned long *page_array)
-{
-       start_info_t start_info;
-       start_info_t *si = &start_info;
-       int rc;
-
-       memset(si, 0, sizeof(start_info_t));
-       snprintf(si->magic, sizeof(si->magic), "xen-%d.%d-ppc", 3, 0);
-       /* these pages should have been pre-zeroed */
-       si->shared_info = SHARED_MFN;
-       si->console_mfn = CONSOLE_MFN;
-
-       DEBUG(printf("start_info (%lx):\n", START_MFN));
-       DEBUG(printf("    shared_info = %lx\n", si->shared_info));
-       DEBUG(printf("    console_mfn = %lx\n", si->console_mfn));
-
-       rc = domain_copy(domid, page_array, si, START_MFN << PAGE_SHIFT,
-                       sizeof(start_info_t), PUSH);
+static int load_start_info(
+    int domid,
+    start_info_t *si,
+    unsigned long si_addr,
+    unsigned long *page_array)
+{
+       int rc;
+
+       rc = domain_copy(domid, page_array, si,
+                     si_addr, sizeof(start_info_t), PUSH);
        if (rc) {
                perror("domain_copy");
-               goto out;
-       }
-
-out:
-       return rc;
+       }
+       return rc;
+}
+
+static unsigned long create_start_info(start_info_t *si)
+{
+    unsigned long eomem;
+    unsigned long si_addr;
+
+       memset(si, 0, sizeof(*si));
+       snprintf(si->magic, sizeof(si->magic), "xen-%d.%d-powerpc64HV", 3, 0);
+
+    eomem = (64 << 20);
+    si->nr_pages = eomem >> PAGE_SHIFT;
+    si->shared_info = eomem - (PAGE_SIZE * 1);
+    si->store_mfn = si->nr_pages - 2;
+    si->console_mfn = si->nr_pages - 3;
+    si->console_evtchn = 2;
+    si_addr = eomem - (PAGE_SIZE * 4);
+
+    return si_addr;
 }
 
 static int start_domain(int xc_handle, int domid)
@@ -350,14 +341,19 @@ int create(char *argv[], int argc)
 {
        struct domain_setup_info dsi;
        unsigned long *page_array;
-       unsigned long fwbase;
+    unsigned long kern_addr;
+    unsigned long dtb_addr;
+    unsigned long si_addr;
+    start_info_t si;
+       int domid = 0;
+       int rc = 0;
+#ifdef INITRD
        unsigned long initrd_base = 0;
        unsigned long initrd_len = 0;
-       int domid = 0;
-       int rc = 0;
-
-       if (argc < 2) {
-               printf("Usage: domctrl create <kernel>\n");
+#endif
+
+       if (argc < 3) {
+               printf("Usage: domctrl create <kernel> <dtb>\n");
                return -1;
        }
 
@@ -371,24 +367,28 @@ int create(char *argv[], int argc)
                goto out;
        }
 
-       if (-1 == load_kernel(domid, argv[1], &dsi, page_array)) {
-               rc = -1;
-               goto out;
-       }
-
-       if (-1 == load_firmware(domid, firmware_path, devtree_path, &dsi,
-                               page_array, &fwbase)) {
-               rc = -1;
-               goto out;
-       }
-
+       if (-1 ==  load_kernel(domid, argv[1], &dsi, page_array)) {
+               rc = -1;
+               goto out;
+       }
+    kern_addr = 0;
+
+    dtb_addr = (32 << 20);
+       if (-1 == load_dtb(domid, argv[2], dtb_addr, &dsi, page_array)) {
+               rc = -1;
+               goto out;
+       }
+
+#ifdef INITRD
        if (-1 == load_initrd(domid, page_array, initrd_path, &initrd_base,
                                &initrd_len)) {
                rc = -1;
                goto out;
        }
-
-       if (-1 == load_start_info(domid, page_array)) {
+#endif
+
+    si_addr = create_start_info(&si);
+       if (-1 == load_start_info(domid, &si, si_addr, page_array)) {
                rc = -1;
                goto out;
        }
@@ -399,7 +399,7 @@ int create(char *argv[], int argc)
         * store page
         */
 
-       if (0 > init_boot_vcpu(domid, &dsi, fwbase, initrd_base, initrd_len)) {
+       if (0 > init_boot_vcpu(domid, &dsi, dtb_addr, kern_addr)) {
                rc = -1;
                goto out;
        }



_______________________________________________
Xen-ppc-devel mailing list
Xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ppc-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [XenPPC] [pushed] [ppc] fix dom creation, jimix <=