2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; version 2 of the License.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 * Copyright (C) 2018 Huaxintong Semiconductor Technology Co.,Ltd. All rights
17 * Author: Ge Song <ge.song@hxt-semitech.com>
23 #include <linux/limits.h>
29 #include <sys/statfs.h>
32 #include "efi/efivar.h"
33 #include "talloc/talloc.h"
35 #define DEF_ATTR (EFI_VARIABLE_NON_VOLATILE | \
36 EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)
38 static const char *test_efivar_guid = "c9c07add-256e-4452-b911-f8d0d35a1ac7";
39 static const char *test_varname = "efivartest";
40 static const char *test_data = "petitboot";
42 static char* find_efitest_path(void)
44 static char dir[PATH_MAX] = {0};
45 static bool run = false;
46 char *rest_path = "/efivarfs_data/";
52 readlink("/proc/self/exe", dir, PATH_MAX);
54 pos = strrchr(dir, '/');
57 strcat(dir, rest_path);
63 static bool probe(void)
68 path = find_efitest_path();
70 rc = access(path, F_OK);
72 if (errno == ENOENT) {
73 rc = mkdir(path, 0755);
81 set_efivarfs_path(path);
90 uint32_t attr = DEF_ATTR;
92 struct efi_data *efi_data;
99 efi_data = talloc_zero(ctx, struct efi_data);
100 efi_data->attributes = attr;
101 efi_data->data = talloc_strdup(efi_data, test_data);
102 efi_data->data_size = strlen(test_data) + 1;
104 rc = efi_set_variable(test_efivar_guid, test_varname,
107 talloc_free(efi_data);
108 rc = efi_get_variable(ctx, test_efivar_guid, test_varname,
111 assert(efi_data->data != NULL);
112 rc = strcmp((char *)efi_data->data, test_data);
118 rc = efi_del_variable(test_efivar_guid, test_varname);
120 rc = efi_get_variable(ctx, test_efivar_guid, test_varname,
126 assert(errno_value == ENOENT);
128 path = find_efitest_path();