bootstr_32.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * bootstr.c: Boot string/argument acquisition from the PROM.
  3. *
  4. * Copyright(C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. */
  6. #include <linux/string.h>
  7. #include <asm/oplib.h>
  8. #include <linux/init.h>
  9. #define BARG_LEN 256
  10. static char barg_buf[BARG_LEN] = { 0 };
  11. static char fetched __initdata = 0;
  12. char * __init
  13. prom_getbootargs(void)
  14. {
  15. int iter;
  16. char *cp, *arg;
  17. /* This check saves us from a panic when bootfd patches args. */
  18. if (fetched) {
  19. return barg_buf;
  20. }
  21. switch (prom_vers) {
  22. case PROM_V0:
  23. cp = barg_buf;
  24. /* Start from 1 and go over fd(0,0,0)kernel */
  25. for (iter = 1; iter < 8; iter++) {
  26. arg = (*(romvec->pv_v0bootargs))->argv[iter];
  27. if (arg == NULL)
  28. break;
  29. while (*arg != 0) {
  30. /* Leave place for space and null. */
  31. if (cp >= barg_buf + BARG_LEN - 2)
  32. /* We might issue a warning here. */
  33. break;
  34. *cp++ = *arg++;
  35. }
  36. *cp++ = ' ';
  37. if (cp >= barg_buf + BARG_LEN - 1)
  38. /* We might issue a warning here. */
  39. break;
  40. }
  41. *cp = 0;
  42. break;
  43. case PROM_V2:
  44. case PROM_V3:
  45. /*
  46. * V3 PROM cannot supply as with more than 128 bytes
  47. * of an argument. But a smart bootstrap loader can.
  48. */
  49. strlcpy(barg_buf, *romvec->pv_v2bootargs.bootargs, sizeof(barg_buf));
  50. break;
  51. default:
  52. break;
  53. }
  54. fetched = 1;
  55. return barg_buf;
  56. }