i386_linux.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 <cmd_boot.h>
  26. #include <image.h>
  27. #include <zlib.h>
  28. #include <asm/byteorder.h>
  29. #include <asm/zimage.h>
  30. extern image_header_t header; /* from cmd_bootm.c */
  31. image_header_t *fake_header(image_header_t *hdr, void *ptr, int size)
  32. {
  33. /* try each supported image type in order */
  34. if (NULL != fake_zimage_header(hdr, ptr, size)) {
  35. return hdr;
  36. }
  37. return NULL;
  38. }
  39. void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  40. ulong addr, ulong *len_ptr, int verify)
  41. {
  42. ulong base_ptr;
  43. ulong len = 0, checksum;
  44. ulong initrd_start, initrd_end;
  45. ulong data;
  46. image_header_t *hdr = &header;
  47. /*
  48. * Check if there is an initrd image
  49. */
  50. if (argc >= 3) {
  51. addr = simple_strtoul(argv[2], NULL, 16);
  52. printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
  53. /* Copy header so we can blank CRC field for re-calculation */
  54. memcpy (&header, (char *)addr, sizeof(image_header_t));
  55. if (ntohl(hdr->ih_magic) != IH_MAGIC) {
  56. printf ("Bad Magic Number\n");
  57. do_reset (cmdtp, flag, argc, argv);
  58. }
  59. data = (ulong)&header;
  60. len = sizeof(image_header_t);
  61. checksum = ntohl(hdr->ih_hcrc);
  62. hdr->ih_hcrc = 0;
  63. if (crc32 (0, (char *)data, len) != checksum) {
  64. printf ("Bad Header Checksum\n");
  65. do_reset (cmdtp, flag, argc, argv);
  66. }
  67. print_image_hdr (hdr);
  68. data = addr + sizeof(image_header_t);
  69. len = ntohl(hdr->ih_size);
  70. if (verify) {
  71. ulong csum = 0;
  72. printf (" Verifying Checksum ... ");
  73. csum = crc32 (0, (char *)data, len);
  74. if (csum != ntohl(hdr->ih_dcrc)) {
  75. printf ("Bad Data CRC\n");
  76. do_reset (cmdtp, flag, argc, argv);
  77. }
  78. printf ("OK\n");
  79. }
  80. if ((hdr->ih_os != IH_OS_LINUX) ||
  81. (hdr->ih_arch != IH_CPU_I386) ||
  82. (hdr->ih_type != IH_TYPE_RAMDISK) ) {
  83. printf ("No Linux i386 Ramdisk Image\n");
  84. do_reset (cmdtp, flag, argc, argv);
  85. }
  86. /*
  87. * Now check if we have a multifile image
  88. */
  89. } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
  90. ulong tail = ntohl(len_ptr[0]) % 4;
  91. int i;
  92. /* skip kernel length and terminator */
  93. data = (ulong)(&len_ptr[2]);
  94. /* skip any additional image length fields */
  95. for (i=1; len_ptr[i]; ++i)
  96. data += 4;
  97. /* add kernel length, and align */
  98. data += ntohl(len_ptr[0]);
  99. if (tail) {
  100. data += 4 - tail;
  101. }
  102. len = ntohl(len_ptr[1]);
  103. } else {
  104. /*
  105. * no initrd image
  106. */
  107. data = 0;
  108. }
  109. #ifdef DEBUG
  110. if (!data) {
  111. printf ("No initrd\n");
  112. }
  113. #endif
  114. if (data) {
  115. initrd_start = data;
  116. initrd_end = initrd_start + len;
  117. printf (" Loading Ramdisk to %08lx, end %08lx ... ",
  118. initrd_start, initrd_end);
  119. memmove ((void *)initrd_start, (void *)data, len);
  120. printf ("OK\n");
  121. } else {
  122. initrd_start = 0;
  123. initrd_end = 0;
  124. }
  125. base_ptr = load_zimage(addr + sizeof(image_header_t), ntohl(hdr->ih_size),
  126. initrd_start, initrd_end-initrd_start, 0);
  127. if (NULL == base_ptr) {
  128. printf ("## Kernel loading failed ...\n");
  129. do_reset(cmdtp, flag, argc, argv);
  130. }
  131. #ifdef DEBUG
  132. printf ("## Transferring control to Linux (at address %08x) ...\n",
  133. (u32)base_ptr);
  134. #endif
  135. /* we assume that the kernel is in place */
  136. printf("\nStarting kernel ...\n\n");
  137. boot_zimage(base_ptr);
  138. }