bootstr_32.c 1.3 KB

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