2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2013 Free Software Foundation, Inc.
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.
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.
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/>.
19 #include <grub/kernel.h>
21 #include <grub/memory.h>
22 #include <grub/machine/console.h>
23 #include <grub/machine/kernel.h>
24 #include <grub/offsets.h>
25 #include <grub/types.h>
28 #include <grub/misc.h>
29 #include <grub/loader.h>
31 #include <grub/cache.h>
32 #include <grub/time.h>
33 #include <grub/symbol.h>
34 #include <grub/video.h>
35 #include <grub/coreboot/lbio.h>
36 #include <grub/fdtbus.h>
38 extern grub_uint8_t _start[];
39 extern grub_uint8_t _end[];
40 extern grub_uint8_t _edata[];
41 grub_addr_t start_of_ram = ~(grub_addr_t)0;
43 void __attribute__ ((noreturn))
46 /* We can't use grub_fatal() in this function. This would create an infinite
47 loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */
52 static grub_uint64_t modend;
53 static int have_memory = 0;
55 /* Helper for grub_machine_init. */
57 heap_init (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
58 void *data __attribute__ ((unused)))
60 grub_uint64_t begin = addr, end = addr + size;
62 #if GRUB_CPU_SIZEOF_VOID_P == 4
63 /* Restrict ourselves to 32-bit memory space. */
64 if (begin > GRUB_ULONG_MAX)
66 if (end > GRUB_ULONG_MAX)
70 if (start_of_ram > begin)
73 if (type != GRUB_MEMORY_AVAILABLE)
76 if (modend && begin < modend)
78 if (begin < (grub_addr_t)_start)
80 grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) ((grub_addr_t)_start - begin));
86 /* Avoid DMA problems. */
87 if (end >= 0xfe000000)
93 grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) (end - begin));
101 grub_machine_init (void)
103 struct grub_module_header *header;
105 grub_size_t dtb_size = 0;
107 modend = grub_modules_get_end ();
109 grub_video_coreboot_fb_early_init ();
111 grub_machine_mmap_iterate (heap_init, NULL);
113 grub_fatal ("No memory found");
115 grub_video_coreboot_fb_late_init ();
118 grub_gfxterm_init ();
121 if (header->type == OBJ_TYPE_DTB)
123 char *dtb_orig_addr, *dtb_copy;
124 dtb_orig_addr = (char *) header + sizeof (struct grub_module_header);
126 dtb_size = header->size - sizeof (struct grub_module_header);
127 dtb = dtb_copy = grub_malloc (dtb_size);
128 grub_memmove (dtb_copy, dtb_orig_addr, dtb_size);
132 grub_fatal ("No DTB found");
133 grub_fdtbus_init (dtb, dtb_size);
135 grub_rk3288_spi_init ();
137 grub_machine_timer_init ();
142 grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
143 char **path __attribute__ ((unused)))
148 grub_machine_fini (int flags __attribute__ ((unused)))