cmdline.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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.  * cmdline.c: Kernel command line creation using ARCS argc/argv.
  7.  *
  8.  * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
  9.  */
  10. #include <linux/init.h>
  11. #include <linux/kernel.h>
  12. #include <linux/string.h>
  13. #include <asm/sgialib.h>
  14. #include <asm/bootinfo.h>
  15. #undef DEBUG_CMDLINE
  16. char arcs_cmdline[CL_SIZE];
  17. char * __init prom_getcmdline(void)
  18. {
  19. return &(arcs_cmdline[0]);
  20. }
  21. static char *ignored[] = {
  22. "ConsoleIn=",
  23. "ConsoleOut=",
  24. "SystemPartition=",
  25. "OSLoader=",
  26. "OSLoadPartition=",
  27. "OSLoadFilename=",
  28. "OSLoadOptions="
  29. };
  30. #define NENTS(foo) ((sizeof((foo)) / (sizeof((foo[0])))))
  31. static char *used_arc[][2] = {
  32. { "OSLoadPartition=", "root=" },
  33. { "OSLoadOptions=", "" }
  34. };
  35. static char * __init move_firmware_args(char* cp)
  36. {
  37. char *s;
  38. int actr, i;
  39. actr = 1; /* Always ignore argv[0] */
  40. while (actr < prom_argc) {
  41. for(i = 0; i < NENTS(used_arc); i++) {
  42. int len = strlen(used_arc[i][0]);
  43. if (!strncmp(prom_argv(actr), used_arc[i][0], len)) {
  44. /* Ok, we want it. First append the replacement... */
  45. strcat(cp, used_arc[i][1]);
  46. cp += strlen(used_arc[i][1]);
  47. /* ... and now the argument */
  48. s = strstr(prom_argv(actr), "=");
  49. if (s) {
  50. s++;
  51. strcpy(cp, s);
  52. cp += strlen(s);
  53. }
  54. *cp++ = ' ';
  55. break;
  56. }
  57. }
  58. actr++;
  59. }
  60. return cp;
  61. }
  62. void __init prom_init_cmdline(void)
  63. {
  64. char *cp;
  65. int actr, i;
  66. actr = 1; /* Always ignore argv[0] */
  67. cp = &(arcs_cmdline[0]);
  68. /*
  69.  * Move ARC variables to the beginning to make sure they can be
  70.  * overridden by later arguments.
  71.  */
  72. cp = move_firmware_args(cp);
  73. while (actr < prom_argc) {
  74. for (i = 0; i < NENTS(ignored); i++) {
  75. int len = strlen(ignored[i]);
  76. if (!strncmp(prom_argv(actr), ignored[i], len))
  77. goto pic_cont;
  78. }
  79. /* Ok, we want it. */
  80. strcpy(cp, prom_argv(actr));
  81. cp += strlen(prom_argv(actr));
  82. *cp++ = ' ';
  83. pic_cont:
  84. actr++;
  85. }
  86. if (cp != &(arcs_cmdline[0])) /* get rid of trailing space */
  87. --cp;
  88. *cp = '';
  89. #ifdef DEBUG_CMDLINE
  90. prom_printf("prom_init_cmdline: %sn", &(arcs_cmdline[0]));
  91. #endif
  92. }