bootm.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <common.h>
  24. #include <command.h>
  25. #include <image.h>
  26. #include <u-boot/zlib.h>
  27. #include <asm/byteorder.h>
  28. #include <asm/addrspace.h>
  29. DECLARE_GLOBAL_DATA_PTR;
  30. #define LINUX_MAX_ENVS 256
  31. #define LINUX_MAX_ARGS 256
  32. static int linux_argc;
  33. static char ** linux_argv;
  34. static char ** linux_env;
  35. static char * linux_env_p;
  36. static int linux_env_idx;
  37. static void linux_params_init (ulong start, char * commandline);
  38. static void linux_env_set (char * env_name, char * env_val);
  39. int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
  40. {
  41. void (*theKernel) (int, char **, char **, int *);
  42. char *commandline = getenv ("bootargs");
  43. char env_buf[12];
  44. char *cp;
  45. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  46. return 1;
  47. /* find kernel entry point */
  48. theKernel = (void (*)(int, char **, char **, int *))images->ep;
  49. show_boot_progress (15);
  50. #ifdef DEBUG
  51. printf ("## Transferring control to Linux (at address %08lx) ...\n",
  52. (ulong) theKernel);
  53. #endif
  54. linux_params_init (UNCACHED_SDRAM (gd->bd->bi_boot_params), commandline);
  55. #ifdef CONFIG_MEMSIZE_IN_BYTES
  56. sprintf (env_buf, "%lu", (ulong)gd->ram_size);
  57. debug ("## Giving linux memsize in bytes, %lu\n", (ulong)gd->ram_size);
  58. #else
  59. sprintf (env_buf, "%lu", (ulong)(gd->ram_size >> 20));
  60. debug ("## Giving linux memsize in MB, %lu\n", (ulong)(gd->ram_size >> 20));
  61. #endif /* CONFIG_MEMSIZE_IN_BYTES */
  62. linux_env_set ("memsize", env_buf);
  63. sprintf (env_buf, "0x%08X", (uint) UNCACHED_SDRAM (images->rd_start));
  64. linux_env_set ("initrd_start", env_buf);
  65. sprintf (env_buf, "0x%X", (uint) (images->rd_end - images->rd_start));
  66. linux_env_set ("initrd_size", env_buf);
  67. sprintf (env_buf, "0x%08X", (uint) (gd->bd->bi_flashstart));
  68. linux_env_set ("flash_start", env_buf);
  69. sprintf (env_buf, "0x%X", (uint) (gd->bd->bi_flashsize));
  70. linux_env_set ("flash_size", env_buf);
  71. cp = getenv("ethaddr");
  72. if (cp != NULL) {
  73. linux_env_set("ethaddr", cp);
  74. }
  75. cp = getenv("eth1addr");
  76. if (cp != NULL) {
  77. linux_env_set("eth1addr", cp);
  78. }
  79. /* we assume that the kernel is in place */
  80. printf ("\nStarting kernel ...\n\n");
  81. theKernel (linux_argc, linux_argv, linux_env, 0);
  82. /* does not return */
  83. return 1;
  84. }
  85. static void linux_params_init (ulong start, char *line)
  86. {
  87. char *next, *quote, *argp;
  88. linux_argc = 1;
  89. linux_argv = (char **) start;
  90. linux_argv[0] = 0;
  91. argp = (char *) (linux_argv + LINUX_MAX_ARGS);
  92. next = line;
  93. while (line && *line && linux_argc < LINUX_MAX_ARGS) {
  94. quote = strchr (line, '"');
  95. next = strchr (line, ' ');
  96. while (next != NULL && quote != NULL && quote < next) {
  97. /* we found a left quote before the next blank
  98. * now we have to find the matching right quote
  99. */
  100. next = strchr (quote + 1, '"');
  101. if (next != NULL) {
  102. quote = strchr (next + 1, '"');
  103. next = strchr (next + 1, ' ');
  104. }
  105. }
  106. if (next == NULL) {
  107. next = line + strlen (line);
  108. }
  109. linux_argv[linux_argc] = argp;
  110. memcpy (argp, line, next - line);
  111. argp[next - line] = 0;
  112. argp += next - line + 1;
  113. linux_argc++;
  114. if (*next)
  115. next++;
  116. line = next;
  117. }
  118. linux_env = (char **) (((ulong) argp + 15) & ~15);
  119. linux_env[0] = 0;
  120. linux_env_p = (char *) (linux_env + LINUX_MAX_ENVS);
  121. linux_env_idx = 0;
  122. }
  123. static void linux_env_set (char *env_name, char *env_val)
  124. {
  125. if (linux_env_idx < LINUX_MAX_ENVS - 1) {
  126. linux_env[linux_env_idx] = linux_env_p;
  127. strcpy (linux_env_p, env_name);
  128. linux_env_p += strlen (env_name);
  129. strcpy (linux_env_p, "=");
  130. linux_env_p += 1;
  131. strcpy (linux_env_p, env_val);
  132. linux_env_p += strlen (env_val);
  133. linux_env_p++;
  134. linux_env[++linux_env_idx] = 0;
  135. }
  136. }