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);
92 uint32_t attr = DEF_ATTR;
99 size = strlen(test_data) + 1;
100 rc = efi_set_variable(ctx, test_efivar_guid, test_varname,
101 (uint8_t *)test_data, size, attr);
103 rc = efi_get_variable(ctx, test_efivar_guid, test_varname,
104 &data, &size, &attr);
106 assert(data != NULL);
107 rc = strcmp((char *)data, test_data);
113 rc = efi_del_variable(ctx, test_efivar_guid, test_varname);
115 rc = efi_get_variable(ctx, test_efivar_guid, test_varname,
116 &data, &size, &attr);
121 assert(errno_value == ENOENT);
123 path = find_efitest_path();