bootm.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. DECLARE_GLOBAL_DATA_PTR;
  32. #define PHYSADDR(x) x
  33. #define LINUX_MAX_ENVS 256
  34. #define LINUX_MAX_ARGS 256
  35. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  36. # include <status_led.h>
  37. # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
  38. #else
  39. # define SHOW_BOOT_PROGRESS(arg)
  40. #endif
  41. static ulong get_sp (void);
  42. void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
  43. int argc, char *argv[],
  44. image_header_t *hdr, int verify)
  45. {
  46. ulong sp_limit;
  47. ulong rd_data_start, rd_data_end, rd_len;
  48. ulong initrd_start, initrd_end;
  49. ulong cmd_start, cmd_end;
  50. char *cmdline;
  51. char *s;
  52. bd_t *kbd;
  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_limit = get_sp();
  64. debug("## Current stack ends at 0x%08lX ", sp_limit);
  65. sp_limit -= 2048; /* just to be sure */
  66. if (sp_limit > CFG_BOOTMAPSZ)
  67. sp_limit = CFG_BOOTMAPSZ;
  68. sp_limit &= ~0xF;
  69. debug("=> set upper limit to 0x%08lX\n", sp_limit);
  70. cmdline = (char *)((sp_limit - CFG_BARGSIZE) & ~0xF);
  71. kbd = (bd_t *) (((ulong) cmdline - sizeof(bd_t)) & ~0xF);
  72. if ((s = getenv("bootargs")) == NULL)
  73. s = "";
  74. strcpy(cmdline, s);
  75. cmd_start = (ulong) & cmdline[0];
  76. cmd_end = cmd_start + strlen(cmdline);
  77. *kbd = *(gd->bd);
  78. #ifdef DEBUG
  79. printf("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
  80. do_bdinfo(NULL, 0, 0, NULL);
  81. #endif
  82. if ((s = getenv("clocks_in_mhz")) != NULL) {
  83. /* convert all clock information to MHz */
  84. kbd->bi_intfreq /= 1000000L;
  85. kbd->bi_busfreq /= 1000000L;
  86. }
  87. /* find kernel */
  88. kernel =
  89. (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr);
  90. /* find ramdisk */
  91. get_ramdisk (cmdtp, flag, argc, argv, hdr, verify,
  92. IH_ARCH_M68K, &rd_data_start, &rd_data_end);
  93. rd_len = rd_data_end - rd_data_start;
  94. ramdisk_high (rd_data_start, rd_len, kdb, sp_limit, get_sp (),
  95. &initrd_start, &initrd_end);
  96. debug("## Transferring control to Linux (at address %08lx) ...\n",
  97. (ulong) kernel);
  98. SHOW_BOOT_PROGRESS(15);
  99. /*
  100. * Linux Kernel Parameters (passing board info data):
  101. * r3: ptr to board info data
  102. * r4: initrd_start or 0 if no initrd
  103. * r5: initrd_end - unused if r4 is 0
  104. * r6: Start of command line string
  105. * r7: End of command line string
  106. */
  107. (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
  108. /* does not return */
  109. }
  110. static ulong get_sp (void)
  111. {
  112. ulong sp;
  113. asm("movel %%a7, %%d0\n"
  114. "movel %%d0, %0\n": "=d"(sp): :"%d0");
  115. return sp;
  116. }