i386_linux.c 4.1 KB

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