]> git.ozlabs.org Git - yaboot.git/blobdiff - second/prom.c
Commit yaboot 1.3.4-pre3
[yaboot.git] / second / prom.c
index 153020d63da2b6589ae84ffeefa350204b8337c5..33dfcda6d4dd0f5343dad627c24cff96a707a436 100644 (file)
@@ -29,6 +29,7 @@
 #include "types.h"
 #include "ctype.h"
 #include "asm/processor.h"
+#include "errors.h"
 
 #define READ_BLOCKS_USE_READ   1
 
@@ -124,7 +125,7 @@ call_method_1 (char *method, prom_handle h, int nargs, ...)
 
   if (prom_args.args[2+nargs] != 0)
     {
-      prom_printf ("method '%s' failed %d\n", method, prom_args.args[2+nargs]);
+      prom_printf ("method '%s' failed %p\n", method, prom_args.args[2+nargs]);
       return 0;
     }
   return prom_args.args[2+nargs+1];
@@ -163,6 +164,36 @@ prom_get_options (char *name, void *mem, int len)
   return prom_getprop (prom_options, name, mem, len);
 }
 
+int
+prom_get_devtype (char *device)
+{
+     phandle    dev;
+     int        result;
+     char       tmp[64];
+
+     /* Find OF device phandle */
+     dev = prom_finddevice(device);
+     if (dev == PROM_INVALID_HANDLE) {
+         return FILE_ERR_BADDEV;
+     }
+
+     /* Check the kind of device */
+     result = prom_getprop(dev, "device_type", tmp, 63);
+     if (result == -1) {
+         prom_printf("can't get <device_type> for device: %s\n", device);
+         return FILE_ERR_BADDEV;
+     }
+     tmp[result] = 0;
+     if (!strcmp(tmp, "block"))
+         return FILE_DEVICE_BLOCK;
+     else if (!strcmp(tmp, "network"))
+         return FILE_DEVICE_NET;
+     else {
+         prom_printf("Unkown device type <%s>\n", tmp);
+         return FILE_ERR_BADDEV;
+     }
+}
+
 void
 prom_init (prom_entry pp)
 {
@@ -384,7 +415,7 @@ prom_puts (prom_handle file, char *s)
 void
 prom_vfprintf (prom_handle file, char *fmt, va_list ap)
 {
-  static char printf_buf[1024];
+  static char printf_buf[1536];
   vsprintf (printf_buf, fmt, ap);
   prom_puts (file, printf_buf);
 }
@@ -392,7 +423,7 @@ prom_vfprintf (prom_handle file, char *fmt, va_list ap)
 void
 prom_vprintf (char *fmt, va_list ap)
 {
-  static char printf_buf[1024];
+  static char printf_buf[1536];
   vsprintf (printf_buf, fmt, ap);
   prom_puts (prom_stdout, printf_buf);
 }
@@ -415,6 +446,37 @@ prom_printf (char *fmt, ...)
   va_end (ap);
 }
 
+void
+prom_perror (int error, char *filename)
+{
+     if (error == FILE_ERR_EOF)
+         prom_printf("%s: Unexpected End Of File\n", filename);
+     else if (error == FILE_ERR_NOTFOUND)
+         prom_printf("%s: No such file or directory\n", filename);
+     else if (error == FILE_CANT_SEEK)
+         prom_printf("%s: Seek error\n", filename);
+     else if (error == FILE_IOERR)
+         prom_printf("%s: Input/output error\n", filename);
+     else if (error == FILE_BAD_PATH)
+         prom_printf("%s: Path too long\n", filename); 
+     else if (error == FILE_ERR_BAD_TYPE)
+         prom_printf("%s: Not a regular file\n", filename);
+     else if (error == FILE_ERR_NOTDIR)
+         prom_printf("%s: Not a directory\n", filename);
+     else if (error == FILE_ERR_BAD_FSYS)
+         prom_printf("%s: Unknown or corrupt filesystem\n", filename);
+     else if (error == FILE_ERR_SYMLINK_LOOP)
+         prom_printf("%s: Too many levels of symbolic links\n", filename);
+     else if (error == FILE_ERR_LENGTH)
+         prom_printf("%s: File too large\n", filename);
+     else if (error == FILE_ERR_FSBUSY)
+         prom_printf("%s: Filesystem busy\n", filename);
+     else if (error == FILE_ERR_BADDEV)
+         prom_printf("%s: Unable to open file, Invalid device\n", filename);
+     else
+         prom_printf("%s: Unknown error\n", filename);
+}
+
 void
 prom_readline (char *prompt, char *buf, int len)
 {
@@ -473,6 +535,14 @@ prom_abort (char *fmt, ...)
   prom_exit ();
 }
 
+void
+prom_sleep (int seconds)
+{
+     int end;
+     end = (prom_getms() + (seconds * 1000));
+     while (prom_getms() <= end);
+}
+
 void *
 prom_claim (void *virt, unsigned int size, unsigned int align)
 {