···22# Makefile for generic prom monitor library routines under Linux.33#4455+lib-y += cmdline.o66+57lib-$(CONFIG_64BIT) += call_o32.o
+101
arch/mips/fw/lib/cmdline.c
···11+/*22+ * This file is subject to the terms and conditions of the GNU General Public33+ * License. See the file "COPYING" in the main directory of this archive44+ * for more details.55+ *66+ * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.77+ */88+#include <linux/init.h>99+#include <linux/kernel.h>1010+#include <linux/string.h>1111+1212+#include <asm/addrspace.h>1313+#include <asm/fw/fw.h>1414+1515+int fw_argc;1616+int *_fw_argv;1717+int *_fw_envp;1818+1919+void __init fw_init_cmdline(void)2020+{2121+ int i;2222+2323+ /* Validate command line parameters. */2424+ if ((fw_arg0 >= CKSEG0) || (fw_arg1 < CKSEG0)) {2525+ fw_argc = 0;2626+ _fw_argv = NULL;2727+ } else {2828+ fw_argc = (fw_arg0 & 0x0000ffff);2929+ _fw_argv = (int *)fw_arg1;3030+ }3131+3232+ /* Validate environment pointer. */3333+ if (fw_arg2 < CKSEG0)3434+ _fw_envp = NULL;3535+ else3636+ _fw_envp = (int *)fw_arg2;3737+3838+ for (i = 1; i < fw_argc; i++) {3939+ strlcat(arcs_cmdline, fw_argv(i), COMMAND_LINE_SIZE);4040+ if (i < (fw_argc - 1))4141+ strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);4242+ }4343+}4444+4545+char * __init fw_getcmdline(void)4646+{4747+ return &(arcs_cmdline[0]);4848+}4949+5050+char *fw_getenv(char *envname)5151+{5252+ char *result = NULL;5353+5454+ if (_fw_envp != NULL) {5555+ /*5656+ * Return a pointer to the given environment variable.5757+ * YAMON uses "name", "value" pairs, while U-Boot uses5858+ * "name=value".5959+ */6060+ int i, yamon, index = 0;6161+6262+ yamon = (strchr(fw_envp(index), '=') == NULL);6363+ i = strlen(envname);6464+6565+ while (fw_envp(index)) {6666+ if (strncmp(envname, fw_envp(index), i) == 0) {6767+ if (yamon) {6868+ result = fw_envp(index + 1);6969+ break;7070+ } else if (fw_envp(index)[i] == '=') {7171+ result = (fw_envp(index + 1) + i);7272+ break;7373+ }7474+ }7575+7676+ /* Increment array index. */7777+ if (yamon)7878+ index += 2;7979+ else8080+ index += 1;8181+ }8282+ }8383+8484+ return result;8585+}8686+8787+unsigned long fw_getenvl(char *envname)8888+{8989+ unsigned long envl = 0UL;9090+ char *str;9191+ long val;9292+ int tmp;9393+9494+ str = fw_getenv(envname);9595+ if (str) {9696+ tmp = kstrtol(str, 0, &val);9797+ envl = (unsigned long)val;9898+ }9999+100100+ return envl;101101+}
+47
arch/mips/include/asm/fw/fw.h
···11+/*22+ * This file is subject to the terms and conditions of the GNU General Public33+ * License. See the file "COPYING" in the main directory of this archive44+ * for more details.55+ *66+ * Copyright (C) 2012 MIPS Technologies, Inc.77+ */88+#ifndef __ASM_FW_H_99+#define __ASM_FW_H_1010+1111+#include <asm/bootinfo.h> /* For cleaner code... */1212+1313+enum fw_memtypes {1414+ fw_dontuse,1515+ fw_code,1616+ fw_free,1717+};1818+1919+typedef struct {2020+ unsigned long base; /* Within KSEG0 */2121+ unsigned int size; /* bytes */2222+ enum fw_memtypes type; /* fw_memtypes */2323+} fw_memblock_t;2424+2525+/* Maximum number of memory block descriptors. */2626+#define FW_MAX_MEMBLOCKS 322727+2828+extern int fw_argc;2929+extern int *_fw_argv;3030+extern int *_fw_envp;3131+3232+/*3333+ * Most firmware like YAMON, PMON, etc. pass arguments and environment3434+ * variables as 32-bit pointers. These take care of sign extension.3535+ */3636+#define fw_argv(index) ((char *)(long)_fw_argv[(index)])3737+#define fw_envp(index) ((char *)(long)_fw_envp[(index)])3838+3939+extern void fw_init_cmdline(void);4040+extern char *fw_getcmdline(void);4141+extern fw_memblock_t *fw_getmdesc(void);4242+extern void fw_meminit(void);4343+extern char *fw_getenv(char *name);4444+extern unsigned long fw_getenvl(char *name);4545+extern void fw_init_early_console(char port);4646+4747+#endif /* __ASM_FW_H_ */