2 * Copyright (C) 2001-2003 Hewlett-Packard Co.
3 * Contributed by Stephane Eranian <eranian@hpl.hp.com>
4 * Contributed by Fenghua Yu <fenghua.yu@intel.com>
5 * Contributed by Bibo Mao <bibo.mao@intel.com>
6 * Contributed by Chandramouli Narayanan<mouli@linux.intel.com>
8 * This file is part of the ELILO, the EFI Linux boot loader.
10 * ELILO is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * ELILO is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with ELILO; see the file COPYING. If not, write to the Free
22 * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 * Please check out the elilo.txt for complete documentation on how
26 * to use this program.
34 #define ELILO_ALTK_VAR L"EliloAlt"
37 * we use a NULL GUID for now because it is more convenient
39 static EFI_GUID altk_guid={0,};
42 * Check for the existence of an EFI variable named EliloAlt.
43 * It contains the name of an alternate kernel (and possible options)
45 * The variable is then deleted. This ensures that next reboot won't
48 * The content of the variable is assumed to be Unicode string. It is
49 * preferrably NULL terminated but the code can deal with this as well.
51 * The size of the buffer MUST be expressed in bytes (not CHAR16).
55 * - -1 in case nothing happened (no variable found)
56 * Please note that no fatal error is reported by this function
59 alternate_kernel(CHAR16 *buffer, UINTN size)
65 * size of the buffer is expressed in bytes
67 * we reserve one Unicode for CHAR_NULL (forced), so
68 * the buffer must be at least 2 more bytes to accomodate one Unicode
70 if (size < 4) return -1;
73 * reserve for CHAR_NULL
78 * Look if the variable exists.
79 * We may fail because:
80 * - the variable does not exist
81 * - our buffer size is too small.
83 status = uefi_call_wrapper(RT->GetVariable, 5, ELILO_ALTK_VAR, &altk_guid, NULL, &size, buffer);
84 if (EFI_ERROR(status)) {
85 DBG_PRT((L"cannot access variable %s: %r", ELILO_ALTK_VAR, status));
87 /* if buffer is too small, erase variable because it's unuseable */
88 if (status == EFI_BUFFER_TOO_SMALL) goto delete_var;
96 * verify that size (expressed in bytes) is multiple of 2. If
97 * not then it can't possibly be representing a UNICODE string
100 * We also consider empty as useless (2nd test).
103 Print(L"invalid content for %s variable, erasing variable\n", ELILO_ALTK_VAR);
107 /* We also consider empty as useless (2nd test) */
108 if (size == 2) goto delete_var;
110 buffer[size] = CHAR_NULL;
112 VERB_PRT(2, Print(L"found alternate variable %s : %s\n", ELILO_ALTK_VAR, buffer));
116 status = uefi_call_wrapper(RT->SetVariable, 5, ELILO_ALTK_VAR, &altk_guid, 0, 0, NULL);
117 if (EFI_ERROR(status)) {
118 ERR_PRT((L"cannot erase variable %s", ELILO_ALTK_VAR));