Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is subject to the terms and conditions of the GNU General Public
0003  * License.  See the file "COPYING" in the main directory of this archive
0004  * for more details.
0005  *
0006  * Copyright (C) 2012 MIPS Technologies, Inc.  All rights reserved.
0007  */
0008 #include <linux/init.h>
0009 #include <linux/kernel.h>
0010 #include <linux/string.h>
0011 
0012 #include <asm/addrspace.h>
0013 #include <asm/fw/fw.h>
0014 
0015 int fw_argc;
0016 int *_fw_argv;
0017 int *_fw_envp;
0018 
0019 #ifndef CONFIG_HAVE_PLAT_FW_INIT_CMDLINE
0020 void __init fw_init_cmdline(void)
0021 {
0022     int i;
0023 
0024     /* Validate command line parameters. */
0025     if ((fw_arg0 >= CKSEG0) || (fw_arg1 < CKSEG0)) {
0026         fw_argc = 0;
0027         _fw_argv = NULL;
0028     } else {
0029         fw_argc = (fw_arg0 & 0x0000ffff);
0030         _fw_argv = (int *)fw_arg1;
0031     }
0032 
0033     /* Validate environment pointer. */
0034     if (fw_arg2 < CKSEG0)
0035         _fw_envp = NULL;
0036     else
0037         _fw_envp = (int *)fw_arg2;
0038 
0039     for (i = 1; i < fw_argc; i++) {
0040         strlcat(arcs_cmdline, fw_argv(i), COMMAND_LINE_SIZE);
0041         if (i < (fw_argc - 1))
0042             strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
0043     }
0044 }
0045 #endif
0046 
0047 char * __init fw_getcmdline(void)
0048 {
0049     return &(arcs_cmdline[0]);
0050 }
0051 
0052 char *fw_getenv(char *envname)
0053 {
0054     char *result = NULL;
0055 
0056     if (_fw_envp != NULL) {
0057         /*
0058          * Return a pointer to the given environment variable.
0059          * YAMON uses "name", "value" pairs, while U-Boot uses
0060          * "name=value".
0061          */
0062         int i, yamon, index = 0;
0063 
0064         yamon = (strchr(fw_envp(index), '=') == NULL);
0065         i = strlen(envname);
0066 
0067         while (fw_envp(index)) {
0068             if (strncmp(envname, fw_envp(index), i) == 0) {
0069                 if (yamon) {
0070                     result = fw_envp(index + 1);
0071                     break;
0072                 } else if (fw_envp(index)[i] == '=') {
0073                     result = fw_envp(index) + i + 1;
0074                     break;
0075                 }
0076             }
0077 
0078             /* Increment array index. */
0079             if (yamon)
0080                 index += 2;
0081             else
0082                 index += 1;
0083         }
0084     }
0085 
0086     return result;
0087 }
0088 
0089 unsigned long fw_getenvl(char *envname)
0090 {
0091     unsigned long envl = 0UL;
0092     char *str;
0093     int tmp;
0094 
0095     str = fw_getenv(envname);
0096     if (str) {
0097         tmp = kstrtoul(str, 0, &envl);
0098         if (tmp)
0099             envl = 0;
0100     }
0101 
0102     return envl;
0103 }