i386_linux.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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;
  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. hdr = (image_header_t *)addr;
  54. printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
  55. if (!image_check_magic (hdr)) {
  56. printf ("Bad Magic Number\n");
  57. do_reset (cmdtp, flag, argc, argv);
  58. }
  59. if (!image_check_hcrc (hdr)) {
  60. printf ("Bad Header Checksum\n");
  61. do_reset (cmdtp, flag, argc, argv);
  62. }
  63. print_image_hdr (hdr);
  64. data = image_get_data (hdr);
  65. len = image_get_data_size (hdr);
  66. if (verify) {
  67. printf (" Verifying Checksum ... ");
  68. if (!image_check_dcrc (hdr)) {
  69. printf ("Bad Data CRC\n");
  70. do_reset (cmdtp, flag, argc, argv);
  71. }
  72. printf ("OK\n");
  73. }
  74. if (!image_check_os (hdr, IH_OS_LINUX) ||
  75. !image_check_arch (hdr, IH_ARCH_I386) ||
  76. !image_check_type (hdr, IH_TYPE_RAMDISK)) {
  77. printf ("No Linux i386 Ramdisk Image\n");
  78. do_reset (cmdtp, flag, argc, argv);
  79. }
  80. /*
  81. * Now check if we have a multifile image
  82. */
  83. } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) {
  84. ulong tail = image_to_cpu (len_ptr[0]) % 4;
  85. int i;
  86. /* skip kernel length and terminator */
  87. data = (ulong)(&len_ptr[2]);
  88. /* skip any additional image length fields */
  89. for (i=1; len_ptr[i]; ++i)
  90. data += 4;
  91. /* add kernel length, and align */
  92. data += image_to_cpu (len_ptr[0]);
  93. if (tail) {
  94. data += 4 - tail;
  95. }
  96. len = image_to_cpu (len_ptr[1]);
  97. } else {
  98. /*
  99. * no initrd image
  100. */
  101. data = 0;
  102. }
  103. #ifdef DEBUG
  104. if (!data) {
  105. printf ("No initrd\n");
  106. }
  107. #endif
  108. if (data) {
  109. initrd_start = data;
  110. initrd_end = initrd_start + len;
  111. printf (" Loading Ramdisk to %08lx, end %08lx ... ",
  112. initrd_start, initrd_end);
  113. memmove ((void *)initrd_start, (void *)data, len);
  114. printf ("OK\n");
  115. } else {
  116. initrd_start = 0;
  117. initrd_end = 0;
  118. }
  119. /* if multi-part image, we need to advance base ptr */
  120. if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) {
  121. int i;
  122. for (i=0, addr+=sizeof(int); len_ptr[i++]; addr+=sizeof(int));
  123. }
  124. base_ptr = load_zimage((void*)addr + image_get_header_size (),
  125. image_get_data_size (hdr),
  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. }