1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
/*
* Copyright (C) 2001-2002 Hewlett-Packard Co.
* Contributed by Stephane Eranian <eranian@hpl.hp.com>
*
* This file is part of the ELILO, the EFI Linux boot loader.
*
* ELILO is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* ELILO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ELILO; see the file COPYING. If not, write to the Free
* Software Foundation, 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* Please check out the elilo.txt for complete documentation on how
* to use this program.
*/
#include <efi.h>
#include <efilib.h>
#include "elilo.h"
/*
* Initialize the generic part of the boot parameters and call the architecture specific
* subroutine.
* Output:
* cookie: the memory map cookie to use with ExitBootServices()
* Return:
* NULL: if an error occured
* bp : the address of the bootparams otherwise (opaque type)
*/
VOID *
create_boot_params(CHAR16 *args, memdesc_t *initrd, UINTN *cookie)
{
/*
* XXX: need cleanup
* See ia32 code for explanation on why it is so big.
*/
#define BOOT_PARAM_MEMSIZE 16384
UINTN bpsize, cmdline_size;
boot_params_t *bp;
CHAR8 *cp;
CHAR16 ch;
/*
* Allocate runtime services memory to hold memory descriptor table and
* command line arguments and fetch memory map:
*
* arg_size = number of character in ASCII form
*/
cmdline_size = StrLen(args) + 1;
bpsize = sizeof(boot_params_t) + cmdline_size;
if (bpsize > BOOT_PARAM_MEMSIZE) {
ERR_PRT((L"BOOT_PARAM_MEMSIZE too small, need at least %d bytes", bpsize));
return NULL;
}
/*
* Allocate memory for boot parameters.
* This CANNOT be EfiLoaderData or EfiLoaderCode as the kernel
* frees this region when initializing.
*/
bp = (boot_params_t *)alloc(BOOT_PARAM_MEMSIZE, EfiLoaderData);
if (bp == NULL) {
ERR_PRT((L"can't allocate boot params"));
return 0;
}
VERB_PRT(3, Print(L"boot params @ 0x%lx\n", bp));
cp = ((CHAR8 *)bp) + BOOT_PARAM_MEMSIZE - cmdline_size;
/*
* clear entire buffer. The boot param structure is bigger than
* needs be but this allows the kernel bootparam structure to grow
* (up to BOOT_PARAM_MEMSIZE) without having to worry about fixing the bootloader.
* By convention between the laoder and the kernel, the value 0 means
* don't care or not set.
*/
Memset(bp, 0, BOOT_PARAM_MEMSIZE);
if (sysdeps_create_boot_params(bp, cp, initrd, cookie) == -1) return 0;
/*
* Convert kernel command line args from UNICODE to ASCII and put them where
* the kernel expects them:
*/
while (1) {
ch = *args++;
if (!ch) break;
*cp++ = ch;
}
*cp++ = '\0';
return bp;
}
VOID
free_boot_params(VOID *bp)
{
boot_params_t *real_bp = (boot_params_t *)bp;
sysdeps_free_boot_params(real_bp);
free(real_bp);
}
|