cmdline.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/kernel.h>
  10. #include <linux/string.h>
  11. #include <asm/addrspace.h>
  12. #include <asm/fw/fw.h>
  13. int fw_argc;
  14. int *_fw_argv;
  15. int *_fw_envp;
  16. void __init fw_init_cmdline(void)
  17. {
  18. int i;
  19. /* Validate command line parameters. */
  20. if ((fw_arg0 >= CKSEG0) || (fw_arg1 < CKSEG0)) {
  21. fw_argc = 0;
  22. _fw_argv = NULL;
  23. } else {
  24. fw_argc = (fw_arg0 & 0x0000ffff);
  25. _fw_argv = (int *)fw_arg1;
  26. }
  27. /* Validate environment pointer. */
  28. if (fw_arg2 < CKSEG0)
  29. _fw_envp = NULL;
  30. else
  31. _fw_envp = (int *)fw_arg2;
  32. for (i = 1; i < fw_argc; i++) {
  33. strlcat(arcs_cmdline, fw_argv(i), COMMAND_LINE_SIZE);
  34. if (i < (fw_argc - 1))
  35. strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
  36. }
  37. }
  38. char * __init fw_getcmdline(void)
  39. {
  40. return &(arcs_cmdline[0]);
  41. }
  42. char *fw_getenv(char *envname)
  43. {
  44. char *result = NULL;
  45. if (_fw_envp != NULL) {
  46. /*
  47. * Return a pointer to the given environment variable.
  48. * YAMON uses "name", "value" pairs, while U-Boot uses
  49. * "name=value".
  50. */
  51. int i, yamon, index = 0;
  52. yamon = (strchr(fw_envp(index), '=') == NULL);
  53. i = strlen(envname);
  54. while (fw_envp(index)) {
  55. if (strncmp(envname, fw_envp(index), i) == 0) {
  56. if (yamon) {
  57. result = fw_envp(index + 1);
  58. break;
  59. } else if (fw_envp(index)[i] == '=') {
  60. result = fw_envp(index) + i + 1;
  61. break;
  62. }
  63. }
  64. /* Increment array index. */
  65. if (yamon)
  66. index += 2;
  67. else
  68. index += 1;
  69. }
  70. }
  71. return result;
  72. }
  73. unsigned long fw_getenvl(char *envname)
  74. {
  75. unsigned long envl = 0UL;
  76. char *str;
  77. int tmp;
  78. str = fw_getenv(envname);
  79. if (str) {
  80. tmp = kstrtoul(str, 0, &envl);
  81. if (tmp)
  82. envl = 0;
  83. }
  84. return envl;
  85. }