summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-01-09 17:38:26 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-01-09 17:38:26 +0100
commitcc843dadfd757e1b6e081afd90caec784f740542 (patch)
treeae3ae700efd83375ec332657a5badff5a35f9826
parentf5b8ea7cadeef27817675102bc1ad101d6def9b5 (diff)
parent75889a2900fbbd10ce2212661ed6c4d6a697d483 (diff)
downloadbarebox-cc843dadfd757e1b6e081afd90caec784f740542.tar.gz
barebox-cc843dadfd757e1b6e081afd90caec784f740542.tar.xz
Merge branch 'for-next/efi'
-rw-r--r--arch/efi/efi/efi.c18
-rw-r--r--common/efi-devicepath.c15
-rw-r--r--common/startup.c6
-rw-r--r--fs/efivarfs.c246
-rw-r--r--include/efi.h19
-rw-r--r--include/wchar.h2
-rw-r--r--lib/wchar.c16
7 files changed, 247 insertions, 75 deletions
diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index 7de8ec82e8..c1efe1d8ae 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -248,7 +248,7 @@ console_initcall(efi_console_init);
void reset_cpu(unsigned long addr)
{
- BS->exit(efi_parent_image, EFI_SUCCESS, 0, NULL);
+ RT->reset_system(EFI_RESET_WARM, EFI_SUCCESS, 0, NULL);
while(1);
}
@@ -341,3 +341,19 @@ efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
return EFI_SUCCESS;
}
+
+static int do_efiexit(int argc, char *argv[])
+{
+ return BS->exit(efi_parent_image, EFI_SUCCESS, 0, NULL);
+}
+
+BAREBOX_CMD_HELP_START(efiexit)
+BAREBOX_CMD_HELP_TEXT("Leave barebox and return to the calling EFI process\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(efiexit)
+ .cmd = do_efiexit,
+ BAREBOX_CMD_DESC("Usage: efiexit")
+ BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+ BAREBOX_CMD_HELP(cmd_efiexit_help)
+BAREBOX_CMD_END
diff --git a/common/efi-devicepath.c b/common/efi-devicepath.c
index 2b1d916768..a53c6d2e8b 100644
--- a/common/efi-devicepath.c
+++ b/common/efi-devicepath.c
@@ -1368,3 +1368,18 @@ char *device_path_to_str(struct efi_device_path *dev_path)
return str.str;
}
+
+u8 device_path_to_type(struct efi_device_path *dev_path)
+{
+ struct efi_device_path *dev_path_next;
+
+ dev_path = unpack_device_path(dev_path);
+ dev_path_next = next_device_path_node(dev_path);
+
+ while (!is_device_path_end(dev_path_next)) {
+ dev_path = dev_path_next;
+ dev_path_next = next_device_path_node(dev_path);
+ }
+
+ return device_path_type(dev_path);
+}
diff --git a/common/startup.c b/common/startup.c
index 2b92efcb95..e59b06d533 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -51,6 +51,12 @@ static int mount_root(void)
mount("none", "ramfs", "/", NULL);
mkdir("/dev", 0);
mount("none", "devfs", "/dev", NULL);
+
+ if (IS_ENABLED(CONFIG_FS_EFIVARFS)) {
+ mkdir("/efivars", 0);
+ mount("none", "efivarfs", "/efivars", NULL);
+ }
+
return 0;
}
fs_initcall(mount_root);
diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index 58c637ef19..9a1503bd13 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -1,7 +1,7 @@
/*
- * ramfs.c - a malloc based filesystem
+ * efivars.c - EFI variable filesystem
*
- * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
*
* See file CREDITS for list of people who contributed to this
* project.
@@ -34,9 +34,20 @@
#include <mach/efi.h>
#include <mach/efi-device.h>
+struct efivarfs_inode {
+ s16 *name;
+ efi_guid_t vendor;
+ char *full_name; /* name including vendor namespacing */
+ struct list_head node;
+};
+
+struct efivarfs_dir {
+ struct list_head *current;
+ DIR dir;
+};
+
struct efivarfs_priv {
- struct efi_file_handle *root_dir;
- struct efi_file_io_interface *protocol;
+ struct list_head inodes;
};
static int char_to_nibble(char c)
@@ -75,8 +86,8 @@ int efi_guid_parse(const char *str, efi_guid_t *guid)
if (*str != '-')
return -EINVAL;
str++;
- break;
- }
+ break;
+ }
}
return 0;
@@ -115,11 +126,81 @@ static int efivarfs_parse_filename(const char *filename, efi_guid_t *vendor, s16
return 0;
}
+static int efivars_create(struct device_d *dev, const char *pathname, mode_t mode)
+{
+ struct efivarfs_priv *priv = dev->priv;
+ struct efivarfs_inode *inode;
+ efi_guid_t vendor;
+ efi_status_t efiret;
+ u8 dummydata;
+ char *name8;
+ s16 *name;
+ int ret;
+
+ if (pathname[0] == '/')
+ pathname++;
+
+ /* deny creating files with other vendor GUID than our own */
+ ret = efivarfs_parse_filename(pathname, &vendor, &name);
+ if (ret)
+ return -ENOENT;
+
+ if (memcmp(&vendor, &EFI_BAREBOX_VENDOR_GUID, sizeof(efi_guid_t)))
+ return -EPERM;
+
+ inode = xzalloc(sizeof(*inode));
+ inode->name = name;
+ inode->vendor = vendor;
+
+
+ name8 = strdup_wchar_to_char(inode->name);
+ inode->full_name = asprintf("%s-%pUl", name8, &inode->vendor);
+ free(name8);
+
+ efiret = RT->set_variable(inode->name, &inode->vendor,
+ EFI_VARIABLE_NON_VOLATILE |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS,
+ 1, &dummydata);
+ if (EFI_ERROR(efiret)) {
+ free(inode);
+ return -efi_errno(efiret);
+ }
+
+ list_add_tail(&inode->node, &priv->inodes);
+
+ return 0;
+}
+
+static int efivars_unlink(struct device_d *dev, const char *pathname)
+{
+ struct efivarfs_priv *priv = dev->priv;
+ struct efivarfs_inode *inode, *tmp;
+ efi_status_t efiret;
+
+ if (pathname[0] == '/')
+ pathname++;
+
+ list_for_each_entry_safe(inode, tmp, &priv->inodes, node) {
+ if (!strcmp(inode->full_name, pathname)) {
+ efiret = RT->set_variable(inode->name, &inode->vendor,
+ 0, 0, NULL);
+ if (EFI_ERROR(efiret))
+ return -efi_errno(efiret);
+ list_del(&inode->node);
+ free(inode);
+ }
+ }
+
+ return 0;
+}
+
struct efivars_file {
void *buf;
unsigned long size;
efi_guid_t vendor;
s16 *name;
+ u32 attributes;
};
static int efivarfs_open(struct device_d *dev, FILE *f, const char *filename)
@@ -127,7 +208,6 @@ static int efivarfs_open(struct device_d *dev, FILE *f, const char *filename)
struct efivars_file *efile;
efi_status_t efiret;
int ret;
- uint32_t attributes;
efile = xzalloc(sizeof(*efile));
@@ -135,28 +215,27 @@ static int efivarfs_open(struct device_d *dev, FILE *f, const char *filename)
if (ret)
return -ENOENT;
- efiret = RT->get_variable(efile->name, &efile->vendor, &attributes, &efile->size, NULL);
+ efiret = RT->get_variable(efile->name, &efile->vendor,
+ &efile->attributes, &efile->size, NULL);
if (EFI_ERROR(efiret) && efiret != EFI_BUFFER_TOO_SMALL) {
ret = -efi_errno(efiret);
goto out;
}
- efile->buf = malloc(efile->size + sizeof(uint32_t));
+ efile->buf = malloc(efile->size);
if (!efile->buf) {
ret = -ENOMEM;
goto out;
}
efiret = RT->get_variable(efile->name, &efile->vendor, NULL, &efile->size,
- efile->buf + sizeof(uint32_t));
+ efile->buf);
if (EFI_ERROR(efiret)) {
ret = -efi_errno(efiret);
goto out;
}
- *(uint32_t *)efile->buf = attributes;
-
- f->size = efile->size + sizeof(uint32_t);
+ f->size = efile->size;
f->inode = efile;
return 0;
@@ -187,74 +266,68 @@ static int efivarfs_read(struct device_d *_dev, FILE *f, void *buf, size_t insiz
return insize;
}
-static loff_t efivarfs_lseek(struct device_d *dev, FILE *f, loff_t pos)
+static int efivarfs_write(struct device_d *_dev, FILE *f, const void *buf, size_t insize)
{
- f->pos = pos;
-
- return f->pos;
-}
-
-struct efivarfs_dir_entry {
- char *name;
- struct efivarfs_dir_entry *next;
-};
+ struct efivars_file *efile = f->inode;
-struct efivarfs_dir {
- struct efivarfs_dir_entry *first;
- struct efivarfs_dir_entry *current;
- DIR dir;
-};
+ if (efile->size < f->pos + insize) {
+ efile->buf = realloc(efile->buf, f->pos + insize);
+ efile->size = f->pos + insize;
+ }
-static DIR *efivarfs_opendir(struct device_d *dev, const char *pathname)
-{
- efi_status_t efiret;
- efi_guid_t vendor;
- s16 name[1024];
- struct efivarfs_dir *edir;
- unsigned long size;
- unsigned char *name8;
+ memcpy(efile->buf + f->pos, buf, insize);
- name[0] = 0;
+ RT->set_variable(efile->name, &efile->vendor, efile->attributes,
+ efile->size ? efile->size : 1, efile->buf);
- edir = xzalloc(sizeof(*edir));
+ return insize;
+}
- while (1) {
- struct efivarfs_dir_entry *entry;
+static int efivarfs_truncate(struct device_d *dev, FILE *f, ulong size)
+{
+ struct efivars_file *efile = f->inode;
- size = sizeof(name);
- efiret = RT->get_next_variable(&size, name, &vendor);
- if (EFI_ERROR(efiret))
- break;
+ efile->size = size;
+ efile->buf = realloc(efile->buf, efile->size + sizeof(uint32_t));
- entry = xzalloc(sizeof(*entry));
- name8 = strdup_wchar_to_char(name);
+ RT->set_variable(efile->name, &efile->vendor, efile->attributes,
+ efile->size ? efile->size : 1, efile->buf);
- entry->name = asprintf("%s-%pUl", name8, &vendor);
+ f->size = efile->size;
- free(name8);
+ return 0;
+}
- if (!edir->first)
- edir->first = entry;
+static loff_t efivarfs_lseek(struct device_d *dev, FILE *f, loff_t pos)
+{
+ f->pos = pos;
- if (edir->current)
- edir->current->next = entry;
+ return f->pos;
+}
- edir->current = entry;
- }
+static DIR *efivarfs_opendir(struct device_d *dev, const char *pathname)
+{
+ struct efivarfs_priv *priv = dev->priv;
+ struct efivarfs_dir *edir;
- edir->current = edir->first;
+ edir = xzalloc(sizeof(*edir));
+ edir->current = priv->inodes.next;
return &edir->dir;
}
static struct dirent *efivarfs_readdir(struct device_d *dev, DIR *dir)
{
+ struct efivarfs_priv *priv = dev->priv;
struct efivarfs_dir *edir = container_of(dir, struct efivarfs_dir, dir);
+ struct efivarfs_inode *inode;
- if (!edir->current)
+ if (edir->current == &priv->inodes)
return NULL;
- strcpy(dir->d.d_name, edir->current->name);
+ inode = list_entry(edir->current, struct efivarfs_inode, node);
+
+ strcpy(dir->d.d_name, inode->full_name);
edir->current = edir->current->next;
@@ -264,17 +337,6 @@ static struct dirent *efivarfs_readdir(struct device_d *dev, DIR *dir)
static int efivarfs_closedir(struct device_d *dev, DIR *dir)
{
struct efivarfs_dir *edir = container_of(dir, struct efivarfs_dir, dir);
- struct efivarfs_dir_entry *entry;
-
- entry = edir->first;
-
- while (entry) {
- struct efivarfs_dir_entry *tmp;
- free(entry->name);
- tmp = entry->next;
- free(entry);
- entry = tmp;
- }
free(edir);
@@ -308,18 +370,64 @@ static int efivarfs_stat(struct device_d *dev, const char *filename, struct stat
static int efivarfs_probe(struct device_d *dev)
{
+ efi_status_t efiret;
+ efi_guid_t vendor;
+ s16 name[1024];
+ char *name8;
+ unsigned long size;
+ struct efivarfs_priv *priv;
+
+ name[0] = 0;
+
+ priv = xzalloc(sizeof(*priv));
+ INIT_LIST_HEAD(&priv->inodes);
+
+ while (1) {
+ struct efivarfs_inode *inode;
+
+ size = sizeof(name);
+ efiret = RT->get_next_variable(&size, name, &vendor);
+ if (EFI_ERROR(efiret))
+ break;
+
+ inode = xzalloc(sizeof(*inode));
+ inode->name = strdup_wchar(name);
+
+ inode->vendor = vendor;
+
+ name8 = strdup_wchar_to_char(inode->name);
+ inode->full_name = asprintf("%s-%pUl", name8, &vendor);
+ free(name8);
+
+ list_add_tail(&inode->node, &priv->inodes);
+ }
+
+ dev->priv = priv;
+
return 0;
}
static void efivarfs_remove(struct device_d *dev)
{
- free(dev->priv);
+ struct efivarfs_priv *priv = dev->priv;
+ struct efivarfs_inode *inode, *tmp;
+
+ list_for_each_entry_safe(inode, tmp, &priv->inodes, node) {
+ free(inode->name);
+ free(inode);
+ }
+
+ free(priv);
}
static struct fs_driver_d efivarfs_driver = {
+ .create = efivars_create,
+ .unlink = efivars_unlink,
.open = efivarfs_open,
.close = efivarfs_close,
.read = efivarfs_read,
+ .write = efivarfs_write,
+ .truncate = efivarfs_truncate,
.lseek = efivarfs_lseek,
.opendir = efivarfs_opendir,
.readdir = efivarfs_readdir,
diff --git a/include/efi.h b/include/efi.h
index 4ad9f69237..9b4f16bd9f 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -255,9 +255,11 @@ extern efi_boot_services_t *BS;
/*
* Types and defines for EFI ResetSystem
*/
-#define EFI_RESET_COLD 0
-#define EFI_RESET_WARM 1
-#define EFI_RESET_SHUTDOWN 2
+typedef enum {
+ EFI_RESET_COLD = 0,
+ EFI_RESET_WARM = 1,
+ EFI_RESET_SHUTDOWN = 2
+} efi_reset_type_t;
/*
* EFI Runtime Services table
@@ -277,9 +279,11 @@ typedef struct {
u32 *Attributes, unsigned long *data_size, void *data);
efi_status_t (EFIAPI *get_next_variable)(unsigned long *variable_name_size,
s16 *variable_name, efi_guid_t *vendor);
- void *set_variable;
+ efi_status_t (EFIAPI *set_variable)(s16 *variable_name, efi_guid_t *vendor,
+ u32 Attributes, unsigned long data_size, void *data);
void *get_next_high_mono_count;
- void *reset_system;
+ void (EFIAPI *reset_system)(efi_reset_type_t reset_type, efi_status_t reset_status,
+ unsigned long data_size, void *reset_data);
void *update_capsule;
void *query_capsule_caps;
void *query_variable_info;
@@ -465,6 +469,10 @@ extern efi_runtime_services_t *RT;
#define EFI_VLANCONFIGDXE_INF_GUID \
EFI_GUID(0xe4f61863, 0xfe2c, 0x4b56, 0xa8, 0xf4, 0x08, 0x51, 0x9b, 0xc4, 0x39, 0xdf)
+/* barebox specific GUIDs */
+#define EFI_BAREBOX_VENDOR_GUID \
+ EFI_GUID(0x5b91f69c, 0x8b88, 0x4a2b, 0x92, 0x69, 0x5f, 0x1d, 0x80, 0x2b, 0x51, 0x75)
+
extern efi_guid_t efi_file_info_id;
extern efi_guid_t efi_simple_file_system_protocol_guid;
extern efi_guid_t efi_device_path_protocol_guid;
@@ -615,6 +623,7 @@ static inline int efi_compare_guid(efi_guid_t *a, efi_guid_t *b)
}
char *device_path_to_str(struct efi_device_path *dev_path);
+u8 device_path_to_type(struct efi_device_path *dev_path);
const char *efi_guid_string(efi_guid_t *g);
diff --git a/include/wchar.h b/include/wchar.h
index 80dcd81bf4..702d8e239a 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -5,6 +5,8 @@
typedef u16 wchar_t;
+wchar_t *strdup_wchar(const wchar_t *src);
+
char *strcpy_wchar_to_char(char *dst, const wchar_t *src);
wchar_t *strcpy_char_to_wchar(wchar_t *dst, const char *src);
diff --git a/lib/wchar.c b/lib/wchar.c
index 6368a01994..b2e9e7545b 100644
--- a/lib/wchar.c
+++ b/lib/wchar.c
@@ -31,6 +31,22 @@ size_t wcslen(const wchar_t *s)
return len;
}
+wchar_t *strdup_wchar(const wchar_t *src)
+{
+ int len = wcslen(src);
+ wchar_t *tmp, *dst;
+
+ if (!(dst = malloc((len + 1) * sizeof(wchar_t))))
+ return NULL;
+
+ tmp = dst;
+
+ while ((*dst++ = *src++))
+ /* nothing */;
+
+ return tmp;
+}
+
char *strcpy_wchar_to_char(char *dst, const wchar_t *src)
{
char *ret = dst;