114aecdd4SSteven J. Hill /*
214aecdd4SSteven J. Hill * This file is subject to the terms and conditions of the GNU General Public
314aecdd4SSteven J. Hill * License. See the file "COPYING" in the main directory of this archive
414aecdd4SSteven J. Hill * for more details.
514aecdd4SSteven J. Hill *
614aecdd4SSteven J. Hill * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
714aecdd4SSteven J. Hill */
814aecdd4SSteven J. Hill #include <linux/init.h>
914aecdd4SSteven J. Hill #include <linux/kernel.h>
1014aecdd4SSteven J. Hill #include <linux/string.h>
1114aecdd4SSteven J. Hill
1214aecdd4SSteven J. Hill #include <asm/addrspace.h>
1314aecdd4SSteven J. Hill #include <asm/fw/fw.h>
1414aecdd4SSteven J. Hill
1514aecdd4SSteven J. Hill int fw_argc;
1614aecdd4SSteven J. Hill int *_fw_argv;
1714aecdd4SSteven J. Hill int *_fw_envp;
1814aecdd4SSteven J. Hill
1978bdbbacSMasahiro Yamada #ifndef CONFIG_HAVE_PLAT_FW_INIT_CMDLINE
fw_init_cmdline(void)2014aecdd4SSteven J. Hill void __init fw_init_cmdline(void)
2114aecdd4SSteven J. Hill {
2214aecdd4SSteven J. Hill int i;
2314aecdd4SSteven J. Hill
2414aecdd4SSteven J. Hill /* Validate command line parameters. */
2514aecdd4SSteven J. Hill if ((fw_arg0 >= CKSEG0) || (fw_arg1 < CKSEG0)) {
2614aecdd4SSteven J. Hill fw_argc = 0;
2714aecdd4SSteven J. Hill _fw_argv = NULL;
2814aecdd4SSteven J. Hill } else {
2914aecdd4SSteven J. Hill fw_argc = (fw_arg0 & 0x0000ffff);
3014aecdd4SSteven J. Hill _fw_argv = (int *)fw_arg1;
3114aecdd4SSteven J. Hill }
3214aecdd4SSteven J. Hill
3314aecdd4SSteven J. Hill /* Validate environment pointer. */
3414aecdd4SSteven J. Hill if (fw_arg2 < CKSEG0)
3514aecdd4SSteven J. Hill _fw_envp = NULL;
3614aecdd4SSteven J. Hill else
3714aecdd4SSteven J. Hill _fw_envp = (int *)fw_arg2;
3814aecdd4SSteven J. Hill
3914aecdd4SSteven J. Hill for (i = 1; i < fw_argc; i++) {
4014aecdd4SSteven J. Hill strlcat(arcs_cmdline, fw_argv(i), COMMAND_LINE_SIZE);
4114aecdd4SSteven J. Hill if (i < (fw_argc - 1))
4214aecdd4SSteven J. Hill strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
4314aecdd4SSteven J. Hill }
4414aecdd4SSteven J. Hill }
4578bdbbacSMasahiro Yamada #endif
4614aecdd4SSteven J. Hill
fw_getcmdline(void)4714aecdd4SSteven J. Hill char * __init fw_getcmdline(void)
4814aecdd4SSteven J. Hill {
4914aecdd4SSteven J. Hill return &(arcs_cmdline[0]);
5014aecdd4SSteven J. Hill }
5114aecdd4SSteven J. Hill
fw_getenv(char * envname)5214aecdd4SSteven J. Hill char *fw_getenv(char *envname)
5314aecdd4SSteven J. Hill {
5414aecdd4SSteven J. Hill char *result = NULL;
5514aecdd4SSteven J. Hill
56*ee1809edSJiaxun Yang if (_fw_envp != NULL && fw_envp(0) != NULL) {
5714aecdd4SSteven J. Hill /*
5814aecdd4SSteven J. Hill * Return a pointer to the given environment variable.
5914aecdd4SSteven J. Hill * YAMON uses "name", "value" pairs, while U-Boot uses
6014aecdd4SSteven J. Hill * "name=value".
6114aecdd4SSteven J. Hill */
6214aecdd4SSteven J. Hill int i, yamon, index = 0;
6314aecdd4SSteven J. Hill
6414aecdd4SSteven J. Hill yamon = (strchr(fw_envp(index), '=') == NULL);
6514aecdd4SSteven J. Hill i = strlen(envname);
6614aecdd4SSteven J. Hill
6714aecdd4SSteven J. Hill while (fw_envp(index)) {
6814aecdd4SSteven J. Hill if (strncmp(envname, fw_envp(index), i) == 0) {
6914aecdd4SSteven J. Hill if (yamon) {
7014aecdd4SSteven J. Hill result = fw_envp(index + 1);
7114aecdd4SSteven J. Hill break;
7214aecdd4SSteven J. Hill } else if (fw_envp(index)[i] == '=') {
734a792e56SAlban Bedel result = fw_envp(index) + i + 1;
7414aecdd4SSteven J. Hill break;
7514aecdd4SSteven J. Hill }
7614aecdd4SSteven J. Hill }
7714aecdd4SSteven J. Hill
7814aecdd4SSteven J. Hill /* Increment array index. */
7914aecdd4SSteven J. Hill if (yamon)
8014aecdd4SSteven J. Hill index += 2;
8114aecdd4SSteven J. Hill else
8214aecdd4SSteven J. Hill index += 1;
8314aecdd4SSteven J. Hill }
8414aecdd4SSteven J. Hill }
8514aecdd4SSteven J. Hill
8614aecdd4SSteven J. Hill return result;
8714aecdd4SSteven J. Hill }
8814aecdd4SSteven J. Hill
fw_getenvl(char * envname)8914aecdd4SSteven J. Hill unsigned long fw_getenvl(char *envname)
9014aecdd4SSteven J. Hill {
9114aecdd4SSteven J. Hill unsigned long envl = 0UL;
9214aecdd4SSteven J. Hill char *str;
9314aecdd4SSteven J. Hill int tmp;
9414aecdd4SSteven J. Hill
9514aecdd4SSteven J. Hill str = fw_getenv(envname);
9614aecdd4SSteven J. Hill if (str) {
97484c3449SAlban Bedel tmp = kstrtoul(str, 0, &envl);
98484c3449SAlban Bedel if (tmp)
99484c3449SAlban Bedel envl = 0;
10014aecdd4SSteven J. Hill }
10114aecdd4SSteven J. Hill
10214aecdd4SSteven J. Hill return envl;
10314aecdd4SSteven J. Hill }
104