[OpenBIOS] r314 - openbios-devel/arch/ppc/qemu

svn at openbios.org svn at openbios.org
Tue Dec 23 12:54:25 CET 2008


Author: blueswirl
Date: 2008-12-23 12:54:25 +0100 (Tue, 23 Dec 2008)
New Revision: 314

Modified:
   openbios-devel/arch/ppc/qemu/main.c
Log:
Parse bootscript in ppc\bootinfo.txt

Modified: openbios-devel/arch/ppc/qemu/main.c
===================================================================
--- openbios-devel/arch/ppc/qemu/main.c	2008-12-23 11:53:13 UTC (rev 313)
+++ openbios-devel/arch/ppc/qemu/main.c	2008-12-23 11:54:25 UTC (rev 314)
@@ -130,7 +130,83 @@
     /* won't come here */
 }
 
+/*
+  Parse SGML structure like:
+  <chrp-boot>
+  <description>Debian/GNU Linux Installation on IBM CHRP hardware</description>
+  <os-name>Debian/GNU Linux for PowerPC</os-name>
+  <boot-script>boot &device;:\install\yaboot</boot-script>
+  <icon size=64,64 color-space=3,3,2>
+
+  CHRP system bindings are described at:
+  http://playground.sun.com/1275/bindings/chrp/chrp1_7a.ps
+*/
 static void
+try_bootinfo(const char *path)
+{
+    int fd;
+    char tagbuf[256], bootscript[256], c, *left, *right;
+    int len, tag, taglen, script, scriptlen;
+
+    snprintf(bootscript, sizeof(bootscript), "%s,ppc\\bootinfo.txt", path);
+    ELF_DPRINTF("Trying %s\n", bootscript);
+    if ((fd = open_io(bootscript)) == -1) {
+        ELF_DPRINTF("Can't open %s\n", bootscript);
+        return;
+    }
+    len = read_io(fd, tagbuf, 11);
+    tagbuf[11] = '\0';
+    if (len < 0 || strcasecmp(tagbuf, "<chrp-boot>") != 0)
+        goto badf;
+
+    tag = 0;
+    taglen = 0;
+    script = 0;
+    scriptlen = 0;
+    do {
+        len = read_io(fd, &c, 1);
+        if (len < 0)
+            goto badf;
+        if (c == '<') {
+            tag = 1;
+            taglen = 0;
+        } else if (c == '>') {
+            tag = 0;
+            tagbuf[taglen] = '\0';
+            if (strcasecmp(tagbuf, "boot-script") == 0)
+                script = 1;
+            else if (strcasecmp(tagbuf, "/boot-script") == 0) {
+                bootscript[scriptlen] = '\0';
+                break;
+            }
+        } else if (tag && taglen < sizeof(tagbuf)) {
+            tagbuf[taglen++] = c;
+        } else if (script && scriptlen < sizeof(bootscript)) {
+            bootscript[scriptlen++] = c;
+        }
+    } while (1);
+
+    ELF_DPRINTF("got bootscript %s\n", bootscript);
+
+    // Replace &device;: with original path
+    push_str(bootscript);
+    PUSH('&');
+    fword("left-split");
+    fword("2swap");
+    PUSH(':');
+    fword("left-split");
+    fword("2drop");
+    right = pop_fstr_copy();
+    left = pop_fstr_copy();
+    snprintf(bootscript, sizeof(bootscript), "%s%s,%s", left, path, right);
+    ELF_DPRINTF("fixed bootscript %s\n", bootscript);
+
+    feval(bootscript);
+ badf:
+    close_io( fd );
+}
+
+static void
 yaboot_startup( void )
 {
         static const char * const paths[] = { "hd:2,\\ofclient", "hd:2,\\yaboot" };
@@ -139,6 +215,7 @@
         int i;
 
         if (!path) {
+            ELF_DPRINTF("Entering boot, no path\n");
             push_str("boot-device");
             push_str("/options");
             fword("(find-dev)");
@@ -159,8 +236,13 @@
                     POP();
                     param = pop_fstr_copy();
                 }
+                try_bootinfo(path);
                 try_path(path, param);
             }
+        } else {
+            ELF_DPRINTF("Entering boot, path %s\n", path);
+            try_path(path, "");
+            try_bootinfo(path);
         }
         for( i=0; i < sizeof(paths) / sizeof(paths[0]); i++ ) {
             try_path(paths[i], args[i]);




More information about the OpenBIOS mailing list