init.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2013 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/kernel.h>
  19. #include <grub/mm.h>
  20. #include <grub/memory.h>
  21. #include <grub/machine/console.h>
  22. #include <grub/machine/kernel.h>
  23. #include <grub/offsets.h>
  24. #include <grub/types.h>
  25. #include <grub/err.h>
  26. #include <grub/dl.h>
  27. #include <grub/misc.h>
  28. #include <grub/loader.h>
  29. #include <grub/env.h>
  30. #include <grub/cache.h>
  31. #include <grub/time.h>
  32. #include <grub/symbol.h>
  33. #include <grub/video.h>
  34. #include <grub/coreboot/lbio.h>
  35. #include <grub/fdtbus.h>
  36. extern grub_uint8_t _start[];
  37. extern grub_uint8_t _end[];
  38. extern grub_uint8_t _edata[];
  39. grub_addr_t start_of_ram = ~(grub_addr_t)0;
  40. void __attribute__ ((noreturn))
  41. grub_exit (void)
  42. {
  43. /* We can't use grub_fatal() in this function. This would create an infinite
  44. loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */
  45. while (1)
  46. grub_cpu_idle ();
  47. }
  48. static grub_uint64_t modend;
  49. static int have_memory = 0;
  50. /* Helper for grub_machine_init. */
  51. static int
  52. heap_init (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
  53. void *data __attribute__ ((unused)))
  54. {
  55. grub_uint64_t begin = addr, end = addr + size;
  56. #if GRUB_CPU_SIZEOF_VOID_P == 4
  57. /* Restrict ourselves to 32-bit memory space. */
  58. if (begin > GRUB_ULONG_MAX)
  59. return 0;
  60. if (end > GRUB_ULONG_MAX)
  61. end = GRUB_ULONG_MAX;
  62. #endif
  63. if (start_of_ram > begin)
  64. start_of_ram = begin;
  65. if (type != GRUB_MEMORY_AVAILABLE)
  66. return 0;
  67. if (modend && begin < modend)
  68. {
  69. if (begin < (grub_addr_t)_start)
  70. {
  71. grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) ((grub_addr_t)_start - begin));
  72. have_memory = 1;
  73. }
  74. begin = modend;
  75. }
  76. /* Avoid DMA problems. */
  77. if (end >= 0xfe000000)
  78. end = 0xfe000000;
  79. if (end <= begin)
  80. return 0;
  81. grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) (end - begin));
  82. have_memory = 1;
  83. return 0;
  84. }
  85. void
  86. grub_machine_init (void)
  87. {
  88. struct grub_module_header *header;
  89. void *dtb = 0;
  90. grub_size_t dtb_size = 0;
  91. modend = grub_modules_get_end ();
  92. grub_video_coreboot_fb_early_init ();
  93. grub_machine_mmap_iterate (heap_init, NULL);
  94. if (!have_memory)
  95. grub_fatal ("No memory found");
  96. grub_video_coreboot_fb_late_init ();
  97. grub_font_init ();
  98. grub_gfxterm_init ();
  99. FOR_MODULES (header)
  100. if (header->type == OBJ_TYPE_DTB)
  101. {
  102. char *dtb_orig_addr, *dtb_copy;
  103. dtb_orig_addr = (char *) header + sizeof (struct grub_module_header);
  104. dtb_size = header->size - sizeof (struct grub_module_header);
  105. dtb = dtb_copy = grub_malloc (dtb_size);
  106. grub_memmove (dtb_copy, dtb_orig_addr, dtb_size);
  107. break;
  108. }
  109. if (!dtb)
  110. grub_fatal ("No DTB found");
  111. grub_fdtbus_init (dtb, dtb_size);
  112. grub_rk3288_spi_init ();
  113. grub_machine_timer_init ();
  114. grub_cros_init ();
  115. grub_pl050_init ();
  116. }
  117. void
  118. grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
  119. char **path __attribute__ ((unused)))
  120. {
  121. }
  122. void
  123. grub_machine_fini (int flags __attribute__ ((unused)))
  124. {
  125. }