2 * Copyright (C) 2001-2003 Hewlett-Packard Co.
3 * Contributed by Stephane Eranian <eranian@hpl.hp.com>
5 * This file is part of the ELILO, the EFI Linux boot loader.
7 * ELILO is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * ELILO is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with ELILO; see the file COPYING. If not, write to the Free
19 * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 * Please check out the elilo.txt for complete documentation on how
23 * to use this program.
32 * This function allocates memory for file image and loads it to memory
34 * - ELILO_LOAD_SUCCESS: if everything works
35 * - ELILO_LOAD_ABORTED: in case the user decided to abort loading
36 * - ELILO_LOAD_ERROR: there was an error during alloc/read
38 * Adapted from Bill Nottingham <notting@redhat.com> patch for ELI.
41 load_file(CHAR16 *filename, memdesc_t *image)
44 VOID *start_addr = NULL;
48 INTN ret = ELILO_LOAD_ERROR;
51 if (filename == NULL || filename[0] == 0) return -1;
54 status = fops_open(filename, &fd);
55 if (EFI_ERROR(status)) {
56 ERR_PRT((L"Open file %s failed: %r", filename, status));
60 DBG_PRT((L"open %s worked", filename));
62 /* warning: this function allocates memory */
63 status = fops_infosize(fd, &size);
64 if (EFI_ERROR(status)) {
65 ERR_PRT((L"Couldn't read file %s info %r", filename, status));
71 /* round up to get required number of pages (4KB) */
72 image->pgcnt = pgcnt = EFI_SIZE_TO_PAGES(image->size);
74 start_addr = alloc_pages(pgcnt, EfiLoaderData, start_addr ? AllocateAddress : AllocateAnyPages, 0 );
75 if (start_addr == NULL) {
76 ERR_PRT((L"Failed to allocate %d pages for %s image", pgcnt,
80 VERB_PRT(2, Print(L"%s image: total_size: %d bytes base: " PTR_FMT " "
81 "pages %d\n", filename, image->size,
84 Print(L"Loading file %s...", filename);
86 ret = read_file(fd, image->size, start_addr);
90 if (ret != ELILO_LOAD_SUCCESS) {
91 ERR_PRT((L"read image(%s) failed: %d", filename, ret));
97 image->start_addr = start_addr;
99 return ELILO_LOAD_SUCCESS;
102 if (start_addr) free(start_addr);
105 * make sure nothing is passed to kernel
108 image->start_addr = 0;