aboutsummaryrefslogtreecommitdiff
path: root/arclib/prom.c
diff options
context:
space:
mode:
authorFlorian Lohoff <flo@rfc822.org>2008-10-05 11:42:41 +0000
committerGuido Günther <agx@sigxcpu.org>2009-04-26 15:26:26 +0200
commit2fbf57533b7037c7b21c6c00a766fee91dd1b8c7 (patch)
tree17e8cc815570f9375833a57de3083d576e76c7a4 /arclib/prom.c
parent9a9e8c11088f1772eb7070e4e1ab1c8d5b4bc528 (diff)
Move arg handling to prom code
Diffstat (limited to 'arclib/prom.c')
-rw-r--r--arclib/prom.c106
1 files changed, 103 insertions, 3 deletions
diff --git a/arclib/prom.c b/arclib/prom.c
index 87a2bf3..5c12ff4 100644
--- a/arclib/prom.c
+++ b/arclib/prom.c
@@ -1,11 +1,20 @@
+#include <stdlib.h>
+#include <subarch.h>
#include <stdio.h>
+#include <string.h>
+
#include "arc.h"
#include "prom.h"
-#include <stddef.h>
-#include <stdlib.h>
-#include <subarch.h>
+#define MAX_ARG 64
+
+static char *iargv[MAX_ARG];
+static int iargc=0;
+
+static char *OSLoadPartition=NULL;
+static char *OSLoadFilename=NULL;
+static char *OSLoadOptions=NULL;
void prom_flush_cache_all(void ) {
ArcFlushAllCaches();
@@ -139,3 +148,94 @@ int prom_read(FILE stream, char *string, unsigned long len, unsigned long *rlen)
return ArcRead(stream, string, len, rlen);
}
+/* we filter these out of the command line */
+static char* env_vars[] = { "ConsoleIn=",
+ "ConsoleOut=",
+ "OSLoader=",
+ "OSLoadPartition=",
+ "OSLoadFilename=",
+ "OSLoadOptions=",
+ };
+#define NENTS(foo) ((sizeof((foo)) / (sizeof((foo[0])))))
+
+
+static int isEnvVar(const char* arg)
+{
+ unsigned int i;
+
+ for (i = 0; i < NENTS(env_vars); i++) {
+ if(strncmp( env_vars[i], arg, strlen(env_vars[i]) ) == 0)
+ return 1;
+ }
+ return 0;
+}
+
+int prom_parse_args(int argc, char **argv)
+{
+ unsigned long arg;
+ char *equals;
+ size_t len;
+
+ /* save some things we need later */
+ for (arg = 1; arg < argc; arg++) {
+ equals = strchr(argv[arg], '=');
+ if (equals != NULL) {
+ len = equals - argv[arg];
+ if (strncmp(argv[arg], "OSLoadPartition", len) == 0)
+ OSLoadPartition = equals + 1;
+ if (strncmp(argv[arg], "OSLoadFilename", len) == 0)
+ OSLoadFilename = equals + 1;
+ if (strncmp(argv[arg], "OSLoadOptions", len) == 0) {
+ /* Copy options to local memory to avoid overwrite later */
+ OSLoadOptions = strdup(equals + 1);
+ if (OSLoadOptions == NULL)
+ prom_fatal("Cannot allocate memory for options string\n\r");
+ }
+ }
+ }
+ /*
+ * in case the user typed "boot a b c" the argv looks like:
+ * scsi(0)..(8)/arcboot a b c OSLoadPartition=.. SystemPartition=..
+ * argv: `0 `-1`-2`-3`-4 `-5
+ * we're interested in a,b,c so scan the command line and check for
+ * each argument if it is an environment variable. We're using a fixed
+ * list instead of ArcGetEnvironmentVariable since e.g. the prom sets
+ * "OSLoadOptions=auto" on reboot but
+ * EnvironmentVariable("OSLoadOptions") == NULL
+ */
+ for( arg = 1; arg < argc; arg++ ) {
+ if(!isEnvVar(argv[arg])) {
+ iargv[iargc++]=strdup(argv[arg]);
+ } else {
+ if (OSLoadOptions) {
+ prom_add_arg(OSLoadOptions);
+ }
+ return (iargc);
+ }
+ }
+ return 0;
+}
+
+void prom_add_arg(char *arg) {
+ iargv[iargc++]=strdup(arg);
+}
+
+char *prom_get_label(void ) {
+ if (iargc > 1 && iargv[1]) {
+ return iargv[1];
+ }
+ return "Linux";
+}
+
+char *prom_get_partition(void ) {
+ return OSLoadPartition;
+}
+
+char *prom_get_options(void ) {
+ return OSLoadOptions;
+}
+
+void prom_get_karg(int *argc, char ***argv) {
+ *argc=iargc;
+ *argv=iargv;
+}