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.
31 #define ELILO_ALTK_VAR L"EliloAlt"
34 * we use a NULL GUID for now because it is more convenient
36 static EFI_GUID altk_guid={0,};
39 * Check for the existence of an EFI variable named EliloAlt.
40 * It contains the name of an alternate kernel (and possible options)
42 * The variable is then deleted. This ensures that next reboot won't
45 * The content of the variable is assumed to be Unicode string. It is
46 * preferrably NULL terminated but the code can deal with this as well.
48 * The size of the buffer MUST be expressed in bytes (not CHAR16).
52 * - -1 in case nothing happened (no variable found)
53 * Please note that no fatal error is reported by this function
56 alternate_kernel(CHAR16 *buffer, INTN size)
62 * size of the buffer is expressed in bytes
64 * we reserve one Unicode for CHAR_NULL (forced), so
65 * the buffer must be at least 2 more bytes to accomodate one Unicode
67 if (size < 4) return -1;
70 * reserve for CHAR_NULL
75 * Look if the variable exists.
76 * We may fail because:
77 * - the variable does not exist
78 * - our buffer size is too small.
80 status = RT->GetVariable(ELILO_ALTK_VAR, &altk_guid, NULL, &size, buffer);
81 if (EFI_ERROR(status)) {
82 DBG_PRT((L"cannot access variable %s: %r", ELILO_ALTK_VAR, status));
84 /* if buffer is too small, erase variable because it's unuseable */
85 if (status == EFI_BUFFER_TOO_SMALL) goto delete_var;
93 * verify that size (expressed in bytes) is multiple of 2. If
94 * not then it can't possibly be representing a UNICODE string
97 * We also consider empty as useless (2nd test).
100 Print(L"invalid content for %s variable, erasing variable\n", ELILO_ALTK_VAR);
104 /* We also consider empty as useless (2nd test) */
105 if (size == 2) goto delete_var;
107 buffer[size] = CHAR_NULL;
109 VERB_PRT(2, Print(L"found alternate variable %s : %s\n", ELILO_ALTK_VAR, buffer));
113 status = RT->SetVariable(ELILO_ALTK_VAR, &altk_guid, 0, 0, NULL);
114 if (EFI_ERROR(status)) {
115 ERR_PRT((L"cannot erase variable %s", ELILO_ALTK_VAR));