2 * Copyright (C) 2001-2003 Hewlett-Packard Co.
3 * Contributed by Stephane Eranian <eranian@hpl.hp.com>
4 * Contributed by Mike Johnston <johnston@intel.com>
5 * Contributed by Chris Ahna <christopher.j.ahna@intel.com>
7 * This file is part of the ELILO, the EFI Linux boot loader.
9 * ELILO is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * ELILO is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with ELILO; see the file COPYING. If not, write to the Free
21 * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 * Please check out the elilo.txt for complete documentation on how
25 * to use this program.
34 boot_params_t *param_start = NULL;
37 UINTN kernel_size = 0x400000; /* 4M (largest x86 bzImage kernel image) */
40 bzImage_probe(CHAR16 *kname)
42 EFI_STATUS efi_status;
47 DBG_PRT((L"probe_bzImage_boot()\n"));
50 ERR_PRT((L"kname == %xh", kname));
58 DBG_PRT((L"opening %s...\n", kname));
60 efi_status = fops_open(kname, &fd);
61 if (EFI_ERROR(efi_status)) {
62 ERR_PRT((L"Could not open %s.", kname));
70 DBG_PRT((L"\nreading boot sector...\n"));
72 size = sizeof bootsect;
73 efi_status = fops_read(fd, bootsect, &size);
74 if (EFI_ERROR(efi_status) || size != sizeof bootsect) {
75 ERR_PRT((L"Could not read boot sector from %s.", kname));
81 * Verify boot sector signature.
84 if (bootsect[0x1FE] != 0x55 || bootsect[0x1FF] != 0xAA) {
85 ERR_PRT((L"%s is not a bzImage kernel image.\n", kname));
91 * Check for out of range setup data size.
92 * Will almost always be 7, but we will accept 1 to 64.
95 DBG_PRT((L"bootsect[1F1h] == %d setup sectors\n", bootsect[0x1F1]));
97 if (bootsect[0x1F1] < 1 || bootsect[0x1F1] > 64) {
98 ERR_PRT((L"%s is not a valid bzImage kernel image.",
105 * Allocate and read setup data.
108 DBG_PRT((L"reading setup data...\n"));
110 param_size = (bootsect[0x1F1] + 1) * 512;
111 param_start = alloc(param_size, EfiLoaderData);
113 DBG_PRT((L"param_size=%d param_start=%x", param_size, param_start));
116 ERR_PRT((L"Could not allocate %d bytes of setup data.",
123 CopyMem(param_start, bootsect, sizeof bootsect);
125 size = param_size - 512;
126 efi_status = fops_read(fd, ((UINT8 *)param_start) + 512, &size);
128 if (EFI_ERROR(efi_status) || size != param_size - 512) {
129 ERR_PRT((L"Could not read %d bytes of setup data.",
139 * Check for setup data signature.
143 UINT8 *c = ((UINT8 *)param_start)+514;
144 DBG_PRT((L"param_start(c=%x): %c-%c-%c-%c",
145 c, (CHAR16)c[0],(CHAR16) c[1], (CHAR16)c[2], (CHAR16)c[3]));
147 if (CompareMem(((UINT8 *)param_start) + 514, "HdrS", 4)) {
148 ERR_PRT((L"%s does not have a setup signature.",
158 * Allocate memory for kernel.
162 * Get correct address for kernel from header, if applicable & available.
164 if ((param_start->s.hdr_major == 2) &&
165 (param_start->s.hdr_minor >= 6) &&
166 (param_start->s.kernel_start >= DEFAULT_KERNEL_START)) {
167 kernel_start = (void *)param_start->s.kernel_start;
168 VERB_PRT(3, Print(L"kernel header suggests kernel start at address "PTR_FMT"\n",
172 kernel_load_address = kernel_start;
174 if (alloc_kmem(kernel_start, EFI_SIZE_TO_PAGES(kernel_size)) != 0) {
176 * Couldn't get desired address--just load it anywhere and move it later.
177 * (Easier than relocating kernel, and also works with non-relocatable kernels.)
179 if (alloc_kmem_anywhere(&kernel_load_address, EFI_SIZE_TO_PAGES(kernel_size)) != 0) {
180 ERR_PRT((L"Could not allocate memory for kernel."));
189 VERB_PRT(3, Print(L"kernel_start: "PTR_FMT" kernel_size: %d loading at: "PTR_FMT"\n",
190 kernel_start, kernel_size, kernel_load_address));
193 * Now read the rest of the kernel image into memory.
196 DBG_PRT((L"reading kernel image...\n"));
199 efi_status = fops_read(fd, kernel_load_address, &size);
200 if (EFI_ERROR(efi_status) || size < 0x10000) {
201 ERR_PRT((L"Error reading kernel image %s.", kname));
210 DBG_PRT((L"kernel image read: %d bytes, %d Kbytes\n", size, size / 1024));
213 * Boot sector, setup data and kernel image loaded.
220 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
222 bzImage_load(CHAR16 *kname, kdesc_t *kd)
224 DBG_PRT((L"load_bzImage_boot()\n"));
227 ERR_PRT((L"kname="PTR_FMT" kd="PTR_FMT"", kname, kd));
234 kd->kstart = kd->kentry = kernel_start;
235 kd->kend = ((UINT8 *)kd->kstart) + kernel_size;
237 DBG_PRT((L"kstart="PTR_FMT" kentry="PTR_FMT" kend="PTR_FMT"\n", kd->kstart, kd->kentry, kd->kend));
242 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
243 loader_ops_t bzimage_loader = {