bootm.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 <zlib.h>
  27. #include <bzlib.h>
  28. #include <watchdog.h>
  29. #include <environment.h>
  30. #include <asm/byteorder.h>
  31. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  32. # include <status_led.h>
  33. #endif
  34. DECLARE_GLOBAL_DATA_PTR;
  35. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  36. #define PHYSADDR(x) x
  37. #define LINUX_MAX_ENVS 256
  38. #define LINUX_MAX_ARGS 256
  39. static ulong get_sp (void);
  40. static void set_clocks_in_mhz (bd_t *kbd);
  41. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  42. void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
  43. int argc, char *argv[],
  44. bootm_headers_t *images)
  45. {
  46. ulong sp, sp_limit, alloc_current;
  47. ulong rd_data_start, rd_data_end, rd_len;
  48. ulong initrd_start, initrd_end;
  49. int ret;
  50. ulong cmd_start, cmd_end;
  51. bd_t *kbd;
  52. ulong ep = 0;
  53. void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
  54. /*
  55. * Booting a (Linux) kernel image
  56. *
  57. * Allocate space for command line and board info - the
  58. * address should be as high as possible within the reach of
  59. * the kernel (see CFG_BOOTMAPSZ settings), but in unused
  60. * memory, which means far enough below the current stack
  61. * pointer.
  62. */
  63. sp = get_sp();
  64. debug ("## Current stack ends at 0x%08lx ", sp);
  65. alloc_current = sp_limit = get_boot_sp_limit(sp);
  66. debug ("=> set upper limit to 0x%08lx\n", sp_limit);
  67. /* allocate space and init command line */
  68. alloc_current = get_boot_cmdline (alloc_current, &cmd_start, &cmd_end);
  69. /* allocate space for kernel copy of board info */
  70. alloc_current = get_boot_kbd (alloc_current, &kbd);
  71. set_clocks_in_mhz(kbd);
  72. /* find kernel entry point */
  73. if (images->legacy_hdr_valid) {
  74. ep = image_get_ep (images->legacy_hdr_os);
  75. #if defined(CONFIG_FIT)
  76. } else if (images->fit_uname_os) {
  77. fit_unsupported_reset ("M68K linux bootm");
  78. do_reset (cmdtp, flag, argc, argv);
  79. #endif
  80. } else {
  81. puts ("Could not find kernel entry point!\n");
  82. do_reset (cmdtp, flag, argc, argv);
  83. }
  84. kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ep;
  85. /* find ramdisk */
  86. ret = get_ramdisk (cmdtp, flag, argc, argv, images,
  87. IH_ARCH_M68K, &rd_data_start, &rd_data_end);
  88. if (ret)
  89. goto error;
  90. rd_len = rd_data_end - rd_data_start;
  91. alloc_current = ramdisk_high (alloc_current, rd_data_start, rd_len,
  92. sp_limit, get_sp (), &initrd_start, &initrd_end);
  93. debug("## Transferring control to Linux (at address %08lx) ...\n",
  94. (ulong) kernel);
  95. show_boot_progress (15);
  96. /*
  97. * Linux Kernel Parameters (passing board info data):
  98. * r3: ptr to board info data
  99. * r4: initrd_start or 0 if no initrd
  100. * r5: initrd_end - unused if r4 is 0
  101. * r6: Start of command line string
  102. * r7: End of command line string
  103. */
  104. (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
  105. /* does not return */
  106. return ;
  107. error:
  108. do_reset (cmdtp, flag, argc, argv);
  109. return ;
  110. }
  111. static ulong get_sp (void)
  112. {
  113. ulong sp;
  114. asm("movel %%a7, %%d0\n"
  115. "movel %%d0, %0\n": "=d"(sp): :"%d0");
  116. return sp;
  117. }
  118. static void set_clocks_in_mhz (bd_t *kbd)
  119. {
  120. char *s;
  121. if ((s = getenv("clocks_in_mhz")) != NULL) {
  122. /* convert all clock information to MHz */
  123. kbd->bi_intfreq /= 1000000L;
  124. kbd->bi_busfreq /= 1000000L;
  125. }
  126. }