bootm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * (C) Copyright 2007 Michal Simek
  3. * (C) Copyright 2004 Atmark Techno, Inc.
  4. *
  5. * Michal SIMEK <monstr@monstr.eu>
  6. * Yasushi SHOJI <yashi@atmark-techno.com>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <command.h>
  28. #include <image.h>
  29. #include <zlib.h>
  30. #include <asm/byteorder.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. extern int do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
  33. void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
  34. image_header_t *hdr, int verify)
  35. {
  36. int i;
  37. ulong checksum;
  38. ulong rd_data, rd_len;
  39. ulong initrd_start, initrd_end;
  40. image_header_t *rd_hdr;
  41. /* First parameter is mapped to $r5 for kernel boot args */
  42. void (*theKernel) (char *);
  43. char *commandline = getenv ("bootargs");
  44. theKernel = (void (*)(char *))image_get_ep (hdr);
  45. /* Check if there is an initrd image */
  46. if (argc >= 3) {
  47. show_boot_progress (9);
  48. rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16);
  49. printf ("## Loading Ramdisk Image at %08lx ...\n", rd_hdr);
  50. if (!image_check_magic (rd_hdr)) {
  51. printf ("Bad Magic Number\n");
  52. show_boot_progress (-10);
  53. do_reset (cmdtp, flag, argc, argv);
  54. }
  55. if (!image_check_magic (rd_hdr)) {
  56. printf ("Bad Header Checksum\n");
  57. show_boot_progress (-11);
  58. do_reset (cmdtp, flag, argc, argv);
  59. }
  60. show_boot_progress (10);
  61. print_image_hdr (rd_hdr);
  62. rd_data = image_get_data (rd_hdr);
  63. rd_en = image_get_data_size (rd_hdr);
  64. if (verify) {
  65. printf (" Verifying Checksum ... ");
  66. if (!image_check_dcrc (rd_hdr)) {
  67. printf ("Bad Data CRC\n");
  68. show_boot_progress (-12);
  69. do_reset (cmdtp, flag, argc, argv);
  70. }
  71. printf ("OK\n");
  72. }
  73. show_boot_progress (11);
  74. if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
  75. !image_check_arch (rd_hdr, IH_ARCH_MICROBLAZE) ||
  76. !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
  77. printf ("No Linux Microblaze Ramdisk Image\n");
  78. show_boot_progress (-13);
  79. do_reset (cmdtp, flag, argc, argv);
  80. }
  81. /*
  82. * Now check if we have a multifile image
  83. */
  84. } else if (image_check_type (hdr, IH_TYPE_MULTI)) {
  85. /*
  86. * Get second entry data start address and len
  87. */
  88. show_boot_progress (13);
  89. image_multi_getimg (hdr, 1, &rd_data, &rd_len);
  90. } else {
  91. /*
  92. * no initrd image
  93. */
  94. show_boot_progress (14);
  95. rd_data = rd_len = 0;
  96. }
  97. #ifdef DEBUG
  98. if (!rd_data) {
  99. printf ("No initrd\n");
  100. }
  101. #endif
  102. if (rd_data) {
  103. initrd_start = rd_data;
  104. initrd_end = initrd_start + rd_len;
  105. } else {
  106. initrd_start = 0;
  107. initrd_end = 0;
  108. }
  109. show_boot_progress (15);
  110. #ifdef DEBUG
  111. printf ("## Transferring control to Linux (at address %08lx) ...\n",
  112. (ulong) theKernel);
  113. #endif
  114. theKernel (commandline);
  115. }