init.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright 2000 MontaVista Software Inc.
  3. * Author: MontaVista Software, Inc.
  4. * ppopov@mvista.com or source@mvista.com
  5. *
  6. * This file was derived from Carsten Langgaard's
  7. * arch/mips/mips-boards/generic/generic.c
  8. *
  9. * Carsten Langgaard, carstenl@mips.com
  10. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  20. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  23. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  24. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * You should have received a copy of the GNU General Public License along
  29. * with this program; if not, write to the Free Software Foundation, Inc.,
  30. * 675 Mass Ave, Cambridge, MA 02139, USA.
  31. */
  32. #include <linux/init.h>
  33. #include <linux/mm.h>
  34. #include <linux/sched.h>
  35. #include <linux/bootmem.h>
  36. #include <linux/string.h>
  37. #include <linux/kernel.h>
  38. #include <asm/addrspace.h>
  39. #include <asm/bootinfo.h>
  40. #include <asm/gt64120.h>
  41. /* Environment variable */
  42. typedef struct {
  43. char *name;
  44. char *val;
  45. } t_env_var;
  46. int prom_argc;
  47. char **prom_argv, **prom_envp;
  48. int init_debug = 0;
  49. char * __init prom_getcmdline(void)
  50. {
  51. return &(arcs_cmdline[0]);
  52. }
  53. unsigned long __init prom_free_prom_memory(void)
  54. {
  55. return 0;
  56. }
  57. void __init prom_init_cmdline(void)
  58. {
  59. char *cp;
  60. int actr;
  61. actr = 1; /* Always ignore argv[0] */
  62. cp = &(arcs_cmdline[0]);
  63. while(actr < prom_argc) {
  64. strcpy(cp, prom_argv[actr]);
  65. cp += strlen(prom_argv[actr]);
  66. *cp++ = ' ';
  67. actr++;
  68. }
  69. if (cp != &(arcs_cmdline[0])) /* get rid of trailing space */
  70. --cp;
  71. *cp = '\0';
  72. }
  73. char *prom_getenv(char *envname)
  74. {
  75. /*
  76. * Return a pointer to the given environment variable.
  77. */
  78. t_env_var *env = (t_env_var *) prom_envp;
  79. int i;
  80. i = strlen(envname);
  81. while (env->name) {
  82. if (strncmp(envname, env->name, i) == 0) {
  83. return (env->val);
  84. }
  85. env++;
  86. }
  87. return (NULL);
  88. }
  89. static inline unsigned char str2hexnum(unsigned char c)
  90. {
  91. if (c >= '0' && c <= '9')
  92. return c - '0';
  93. if (c >= 'a' && c <= 'f')
  94. return c - 'a' + 10;
  95. return 0; /* foo */
  96. }
  97. static inline void str2eaddr(unsigned char *ea, unsigned char *str)
  98. {
  99. int i;
  100. for (i = 0; i < 6; i++) {
  101. unsigned char num;
  102. if ((*str == '.') || (*str == ':'))
  103. str++;
  104. num = str2hexnum(*str++) << 4;
  105. num |= (str2hexnum(*str++));
  106. ea[i] = num;
  107. }
  108. }
  109. int get_ethernet_addr(char *ethernet_addr)
  110. {
  111. char *ethaddr_str;
  112. ethaddr_str = prom_getenv("ethaddr");
  113. if (!ethaddr_str) {
  114. printk("ethaddr not set in boot prom\n");
  115. return -1;
  116. }
  117. str2eaddr(ethernet_addr, ethaddr_str);
  118. if (init_debug > 1) {
  119. int i;
  120. printk("get_ethernet_addr: ");
  121. for (i = 0; i < 5; i++)
  122. printk("%02x:",
  123. (unsigned char) *(ethernet_addr + i));
  124. printk("%02x\n", *(ethernet_addr + i));
  125. }
  126. return 0;
  127. }
  128. const char *get_system_type(void)
  129. {
  130. return "Galileo EV96100";
  131. }
  132. void __init prom_init(void)
  133. {
  134. volatile unsigned char *uart;
  135. char ppbuf[8];
  136. prom_argc = fw_arg0;
  137. prom_argv = (char **) fw_arg1;
  138. prom_envp = (char **) fw_arg2;
  139. mips_machgroup = MACH_GROUP_GALILEO;
  140. mips_machtype = MACH_EV96100;
  141. prom_init_cmdline();
  142. /* 32 MB upgradable */
  143. add_memory_region(0, 32 << 20, BOOT_MEM_RAM);
  144. }