orphan
[debian/elilo] / bootparams.c
1 /*
2  *  Copyright (C) 2001-2003 Hewlett-Packard Co.
3  *      Contributed by Stephane Eranian <eranian@hpl.hp.com>
4  *
5  * This file is part of the ELILO, the EFI Linux boot loader.
6  *
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)
10  *  any later version.
11  *
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.
16  *
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
20  *  02111-1307, USA.
21  *
22  * Please check out the elilo.txt for complete documentation on how
23  * to use this program.
24  */
25
26 #include <efi.h>
27 #include <efilib.h>
28
29 #include "elilo.h"
30
31 /*
32  * Initialize the generic part of the boot parameters and call the architecture specific
33  * subroutine.
34  * Output:
35  *      cookie: the memory map cookie to use with ExitBootServices()
36  * Return:
37  *      NULL: if an error occured
38  *      bp  : the address of the bootparams otherwise (opaque type)
39  */
40 VOID *
41 create_boot_params(CHAR16 *args, memdesc_t *initrd, memdesc_t *vmcode, UINTN *cookie)
42 {
43 /* 
44  * XXX: need cleanup
45  * See ia32 code for explanation on why it is so big.
46  */
47 #define BOOT_PARAM_MEMSIZE      16384   
48         UINTN bpsize, cmdline_size;
49         boot_params_t *bp;
50         CHAR8 *cp;
51         CHAR16 ch;
52
53         /*
54          * Allocate runtime services memory to hold memory descriptor table and
55          * command line arguments and fetch memory map:
56          *
57          * arg_size = number of character in ASCII form
58          */
59         cmdline_size = StrLen(args) + 1;
60         bpsize       = sizeof(boot_params_t) + cmdline_size;
61
62         if (bpsize > BOOT_PARAM_MEMSIZE) {
63                 ERR_PRT((L"BOOT_PARAM_MEMSIZE too small, need at least %d bytes", bpsize));
64                 return NULL;
65         }
66
67
68         /*
69          * Allocate memory for boot parameters.
70          * This CANNOT be EfiLoaderData or EfiLoaderCode as the kernel
71          * frees this region when initializing.
72          * FIXME:  Is this a bug?  (since the memory type *is* EfiLoaderData)
73          */
74
75         bp = (boot_params_t *)alloc(BOOT_PARAM_MEMSIZE, EfiLoaderData);
76         if (bp == NULL) {
77                 ERR_PRT((L"can't allocate boot params"));
78                 return 0;
79         }
80
81         VERB_PRT(3, Print(L"boot params @ " PTR_FMT "\n", bp));
82
83 /* XXX: need to fix this for 3.5 */
84 #ifdef CONFIG_ia64
85        cp = ((CHAR8 *)bp) + BOOT_PARAM_MEMSIZE - cmdline_size;
86 #elif defined CONFIG_ia32 || CONFIG_x86_64
87        cp = ((CHAR8 *)bp) + BOOT_PARAM_MEMSIZE - 2048;
88 #endif
89
90         /* 
91          * clear entire buffer. The boot param structure is bigger than
92          * needs be but this allows the kernel bootparam structure to grow
93          * (up to BOOT_PARAM_MEMSIZE) without having to worry about fixing the bootloader.
94          * By convention between the laoder and the kernel, the value 0 means 
95          * don't care or not set.
96          */
97         Memset(bp, 0, BOOT_PARAM_MEMSIZE);
98
99         U2ascii(args, cp, cmdline_size);
100
101         if (sysdeps_create_boot_params(bp, cp, initrd, vmcode, cookie) == -1) return 0;
102
103         /*
104          * Convert kernel command line args from UNICODE to ASCII and put them where
105          * the kernel expects them:
106          */
107         while (1) {
108                 ch = *args++;
109                 if (!ch) break;
110                 *cp++ = ch;
111         }
112         *cp++ = '\0';
113
114         return bp;
115 }
116
117 VOID
118 free_boot_params(VOID *bp)
119 {
120         boot_params_t *real_bp = (boot_params_t *)bp;
121
122         sysdeps_free_boot_params(real_bp);
123
124         free(real_bp);
125 }
126