cmdline.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #ifndef CONFIG_HAVE_PLAT_FW_INIT_CMDLINE
  17. void __init fw_init_cmdline(void)
  18. {
  19. int i;
  20. /* Validate command line parameters. */
  21. if ((fw_arg0 >= CKSEG0) || (fw_arg1 < CKSEG0)) {
  22. fw_argc = 0;
  23. _fw_argv = NULL;
  24. } else {
  25. fw_argc = (fw_arg0 & 0x0000ffff);
  26. _fw_argv = (int *)fw_arg1;
  27. }
  28. /* Validate environment pointer. */
  29. if (fw_arg2 < CKSEG0)
  30. _fw_envp = NULL;
  31. else
  32. _fw_envp = (int *)fw_arg2;
  33. for (i = 1; i < fw_argc; i++) {
  34. strlcat(arcs_cmdline, fw_argv(i), COMMAND_LINE_SIZE);
  35. if (i < (fw_argc - 1))
  36. strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
  37. }
  38. }
  39. #endif
  40. char * __init fw_getcmdline(void)
  41. {
  42. return &(arcs_cmdline[0]);
  43. }
  44. char *fw_getenv(char *envname)
  45. {
  46. char *result = NULL;
  47. if (_fw_envp != NULL && fw_envp(0) != NULL) {
  48. /*
  49. * Return a pointer to the given environment variable.
  50. * YAMON uses "name", "value" pairs, while U-Boot uses
  51. * "name=value".
  52. */
  53. int i, yamon, index = 0;
  54. yamon = (strchr(fw_envp(index), '=') == NULL);
  55. i = strlen(envname);
  56. while (fw_envp(index)) {
  57. if (strncmp(envname, fw_envp(index), i) == 0) {
  58. if (yamon) {
  59. result = fw_envp(index + 1);
  60. break;
  61. } else if (fw_envp(index)[i] == '=') {
  62. result = fw_envp(index) + i + 1;
  63. break;
  64. }
  65. }
  66. /* Increment array index. */
  67. if (yamon)
  68. index += 2;
  69. else
  70. index += 1;
  71. }
  72. }
  73. return result;
  74. }
  75. unsigned long fw_getenvl(char *envname)
  76. {
  77. unsigned long envl = 0UL;
  78. char *str;
  79. int tmp;
  80. str = fw_getenv(envname);
  81. if (str) {
  82. tmp = kstrtoul(str, 0, &envl);
  83. if (tmp)
  84. envl = 0;
  85. }
  86. return envl;
  87. }