bootm.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
  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 <asm/byteorder.h>
  28. #include <asm/zimage.h>
  29. /*cmd_boot.c*/
  30. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  31. void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  32. image_header_t *hdr, int verify)
  33. {
  34. void *base_ptr;
  35. ulong os_data, os_len;
  36. ulong rd_data, rd_len;
  37. ulong initrd_start, initrd_end;
  38. image_header_t *rd_hdr;
  39. /*
  40. * Check if there is an initrd image
  41. */
  42. if (argc >= 3) {
  43. rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16);
  44. printf ("## Loading Ramdisk Image at %08lx ...\n", rd_hdr);
  45. if (!image_check_magic (rd_hdr)) {
  46. printf ("Bad Magic Number\n");
  47. do_reset (cmdtp, flag, argc, argv);
  48. }
  49. if (!image_check_hcrc (rd_hdr)) {
  50. printf ("Bad Header Checksum\n");
  51. do_reset (cmdtp, flag, argc, argv);
  52. }
  53. print_image_hdr (rd_hdr);
  54. rd_data = image_get_data (rd_hdr);
  55. rd_len = image_get_data_size (rd_hdr);
  56. if (verify) {
  57. printf (" Verifying Checksum ... ");
  58. if (!image_check_dcrc (rd_hdr)) {
  59. printf ("Bad Data CRC\n");
  60. do_reset (cmdtp, flag, argc, argv);
  61. }
  62. printf ("OK\n");
  63. }
  64. if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
  65. !image_check_arch (rd_hdr, IH_ARCH_I386) ||
  66. !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
  67. printf ("No Linux i386 Ramdisk Image\n");
  68. do_reset (cmdtp, flag, argc, argv);
  69. }
  70. /*
  71. * Now check if we have a multifile image
  72. */
  73. } else if (image_check_type (hdr, IH_TYPE_MULTI)) {
  74. /*
  75. * Get second entry data start address and len
  76. */
  77. image_multi_getimg (hdr, 1, &rd_data, &rd_len);
  78. } else {
  79. /*
  80. * no initrd image
  81. */
  82. rd_data = rd_len = 0;
  83. }
  84. #ifdef DEBUG
  85. if (!rd_data) {
  86. printf ("No initrd\n");
  87. }
  88. #endif
  89. if (rd_data) {
  90. initrd_start = rd_data;
  91. initrd_end = initrd_start + rd_len;
  92. printf (" Loading Ramdisk to %08lx, end %08lx ... ",
  93. initrd_start, initrd_end);
  94. memmove ((void *)initrd_start, (void *)rd_data, rd_len);
  95. printf ("OK\n");
  96. } else {
  97. initrd_start = 0;
  98. initrd_end = 0;
  99. }
  100. /* if multi-part image, we need to advance base ptr */
  101. if (image_check_type (hdr, IH_TYPE_MULTI)) {
  102. image_multi_getimg (hdr, 0, &os_data, &os_len);
  103. } else {
  104. os_data = image_get_data (hdr);
  105. os_len = image_get_data_size (hdr);
  106. }
  107. base_ptr = load_zimage ((void*)os_data, os_len,
  108. initrd_start, rd_len, 0);
  109. if (NULL == base_ptr) {
  110. printf ("## Kernel loading failed ...\n");
  111. do_reset(cmdtp, flag, argc, argv);
  112. }
  113. #ifdef DEBUG
  114. printf ("## Transferring control to Linux (at address %08x) ...\n",
  115. (u32)base_ptr);
  116. #endif
  117. /* we assume that the kernel is in place */
  118. printf("\nStarting kernel ...\n\n");
  119. boot_zimage(base_ptr);
  120. }