i386_linux.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  33. ulong addr, ulong *len_ptr, int verify)
  34. {
  35. void *base_ptr;
  36. ulong len = 0;
  37. ulong initrd_start, initrd_end;
  38. ulong data;
  39. image_header_t *hdr = &header;
  40. /*
  41. * Check if there is an initrd image
  42. */
  43. if (argc >= 3) {
  44. addr = simple_strtoul(argv[2], NULL, 16);
  45. hdr = (image_header_t *)addr;
  46. printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
  47. if (!image_check_magic (hdr)) {
  48. printf ("Bad Magic Number\n");
  49. do_reset (cmdtp, flag, argc, argv);
  50. }
  51. if (!image_check_hcrc (hdr)) {
  52. printf ("Bad Header Checksum\n");
  53. do_reset (cmdtp, flag, argc, argv);
  54. }
  55. print_image_hdr (hdr);
  56. data = image_get_data (hdr);
  57. len = image_get_data_size (hdr);
  58. if (verify) {
  59. printf (" Verifying Checksum ... ");
  60. if (!image_check_dcrc (hdr)) {
  61. printf ("Bad Data CRC\n");
  62. do_reset (cmdtp, flag, argc, argv);
  63. }
  64. printf ("OK\n");
  65. }
  66. if (!image_check_os (hdr, IH_OS_LINUX) ||
  67. !image_check_arch (hdr, IH_ARCH_I386) ||
  68. !image_check_type (hdr, IH_TYPE_RAMDISK)) {
  69. printf ("No Linux i386 Ramdisk Image\n");
  70. do_reset (cmdtp, flag, argc, argv);
  71. }
  72. /*
  73. * Now check if we have a multifile image
  74. */
  75. } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) {
  76. ulong tail = image_to_cpu (len_ptr[0]) % 4;
  77. int i;
  78. /* skip kernel length and terminator */
  79. data = (ulong)(&len_ptr[2]);
  80. /* skip any additional image length fields */
  81. for (i=1; len_ptr[i]; ++i)
  82. data += 4;
  83. /* add kernel length, and align */
  84. data += image_to_cpu (len_ptr[0]);
  85. if (tail) {
  86. data += 4 - tail;
  87. }
  88. len = image_to_cpu (len_ptr[1]);
  89. } else {
  90. /*
  91. * no initrd image
  92. */
  93. data = 0;
  94. }
  95. #ifdef DEBUG
  96. if (!data) {
  97. printf ("No initrd\n");
  98. }
  99. #endif
  100. if (data) {
  101. initrd_start = data;
  102. initrd_end = initrd_start + len;
  103. printf (" Loading Ramdisk to %08lx, end %08lx ... ",
  104. initrd_start, initrd_end);
  105. memmove ((void *)initrd_start, (void *)data, len);
  106. printf ("OK\n");
  107. } else {
  108. initrd_start = 0;
  109. initrd_end = 0;
  110. }
  111. /* if multi-part image, we need to advance base ptr */
  112. if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) {
  113. int i;
  114. for (i=0, addr+=sizeof(int); len_ptr[i++]; addr+=sizeof(int));
  115. }
  116. base_ptr = load_zimage((void*)addr + image_get_header_size (),
  117. image_get_data_size (hdr),
  118. initrd_start, initrd_end-initrd_start, 0);
  119. if (NULL == base_ptr) {
  120. printf ("## Kernel loading failed ...\n");
  121. do_reset(cmdtp, flag, argc, argv);
  122. }
  123. #ifdef DEBUG
  124. printf ("## Transferring control to Linux (at address %08x) ...\n",
  125. (u32)base_ptr);
  126. #endif
  127. /* we assume that the kernel is in place */
  128. printf("\nStarting kernel ...\n\n");
  129. boot_zimage(base_ptr);
  130. }