* [PATCH 001/112] string: implement strcmp_ptr and streq_ptr helpers
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 002/112] commands: efiexit: flush console and shutdown barebox Ahmad Fatoum
` (110 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
These helpers take care of NULL transparently and will be useful to
avoid explicit NULL checks in follow-up commits.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/string.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/include/string.h b/include/string.h
index 43911b75762f..71810180b5ba 100644
--- a/include/string.h
+++ b/include/string.h
@@ -3,6 +3,7 @@
#define __STRING_H
#include <linux/string.h>
+#include <linux/minmax.h>
void *mempcpy(void *dest, const void *src, size_t count);
int strtobool(const char *str, int *val);
@@ -20,4 +21,14 @@ char *parse_assignment(char *str);
int strverscmp(const char *a, const char *b);
+static inline int strcmp_ptr(const char *a, const char *b)
+{
+ return a && b ? strcmp(a, b) : compare3(a, b);
+}
+
+static inline bool streq_ptr(const char *a, const char *b)
+{
+ return strcmp_ptr(a, b) == 0;
+}
+
#endif /* __STRING_H */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 002/112] commands: efiexit: flush console and shutdown barebox
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 001/112] string: implement strcmp_ptr and streq_ptr helpers Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 003/112] treewide: add errno_set helper for returning positive error code in errno Ahmad Fatoum
` (109 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
barebox as EFI payload may have direct device access over PCI. These
devices may be doing DMA and need to be quiesced before barebox returns
control to the EFI loader. Therefore start calling shutdown_barebox()
in the efiexit path.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/efi/payload/init.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/common/efi/payload/init.c b/common/efi/payload/init.c
index cfacdffa6761..ffa466e3ad44 100644
--- a/common/efi/payload/init.c
+++ b/common/efi/payload/init.c
@@ -428,16 +428,23 @@ late_initcall(efi_late_init);
static int do_efiexit(int argc, char *argv[])
{
+ console_flush();
+
+ if (!streq_ptr(argv[1], "-f"))
+ shutdown_barebox();
+
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_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-f", "force exit, don't call barebox shutdown")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(efiexit)
.cmd = do_efiexit,
- BAREBOX_CMD_DESC("Usage: efiexit")
+ BAREBOX_CMD_DESC("Leave barebox and return to the calling EFI process")
+ BAREBOX_CMD_OPTS("[-flrw]")
BAREBOX_CMD_GROUP(CMD_GRP_MISC)
BAREBOX_CMD_HELP(cmd_efiexit_help)
BAREBOX_CMD_END
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 003/112] treewide: add errno_set helper for returning positive error code in errno
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 001/112] string: implement strcmp_ptr and streq_ptr helpers Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 002/112] commands: efiexit: flush console and shutdown barebox Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 004/112] vsprintf: guard against NULL in UUID %pU Ahmad Fatoum
` (108 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We have this sequence at multiple places: Check a return value for being
below zero and if so, turn it positive and store into errno.
Instead of opencoding it everywhere, add a helper to encapsulate this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 112 ++++++++++++------------------------------------
include/errno.h | 7 +++
lib/libfile.c | 15 +++----
lib/parameter.c | 22 ++++------
4 files changed, 48 insertions(+), 108 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 68e7873e9c54..4b64f6fcf1df 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -365,10 +365,8 @@ int ftruncate(int fd, loff_t length)
return 0;
ret = fsdev_truncate(&f->fsdev->dev, f, length);
- if (ret) {
- errno = -ret;
- return ret;
- }
+ if (ret)
+ return errno_set(ret);
f->size = length;
f->f_inode->i_size = f->size;
@@ -391,9 +389,8 @@ int ioctl(int fd, int request, void *buf)
ret = fsdrv->ioctl(&f->fsdev->dev, f, request, buf);
else
ret = -ENOSYS;
- if (ret)
- errno = -ret;
- return ret;
+
+ return errno_set(ret);
}
static ssize_t __read(FILE *f, void *buf, size_t count)
@@ -419,9 +416,7 @@ static ssize_t __read(FILE *f, void *buf, size_t count)
ret = fsdrv->read(&f->fsdev->dev, f, buf, count);
out:
- if (ret < 0)
- errno = -ret;
- return ret;
+ return errno_set(ret);
}
ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
@@ -490,9 +485,7 @@ static ssize_t __write(FILE *f, const void *buf, size_t count)
}
ret = fsdrv->write(&f->fsdev->dev, f, buf, count);
out:
- if (ret < 0)
- errno = -ret;
- return ret;
+ return errno_set(ret);
}
ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset)
@@ -544,10 +537,7 @@ int flush(int fd)
else
ret = 0;
- if (ret)
- errno = -ret;
-
- return ret;
+ return errno_set(ret);
}
loff_t lseek(int fd, loff_t offset, int whence)
@@ -597,8 +587,7 @@ loff_t lseek(int fd, loff_t offset, int whence)
return pos;
out:
- if (ret)
- errno = -ret;
+ errno_set(ret);
return -1;
}
@@ -629,10 +618,7 @@ int erase(int fd, loff_t count, loff_t offset)
else
ret = -ENOSYS;
- if (ret)
- errno = -ret;
-
- return ret;
+ return errno_set(ret);
}
EXPORT_SYMBOL(erase);
@@ -659,10 +645,7 @@ int protect(int fd, size_t count, loff_t offset, int prot)
else
ret = -ENOSYS;
- if (ret)
- errno = -ret;
-
- return ret;
+ return errno_set(ret);
}
EXPORT_SYMBOL(protect);
@@ -689,10 +672,7 @@ int discard_range(int fd, loff_t count, loff_t offset)
else
ret = -ENOSYS;
- if (ret)
- errno = -ret;
-
- return ret;
+ return errno_set(ret);
}
int protect_file(const char *file, int prot)
@@ -730,9 +710,7 @@ void *memmap(int fd, int flags)
else
ret = -EINVAL;
- if (ret)
- errno = -ret;
-
+ errno_set(ret);
return retp;
}
EXPORT_SYMBOL(memmap);
@@ -756,10 +734,7 @@ int close(int fd)
put_file(f);
- if (ret)
- errno = -ret;
-
- return ret;
+ return errno_set(ret);
}
EXPORT_SYMBOL(close);
@@ -2464,10 +2439,7 @@ int mkdir (const char *pathname, mode_t mode)
dput(dentry);
path_put(&path);
out:
- if (error)
- errno = -error;
-
- return error;
+ return errno_set(error);
}
EXPORT_SYMBOL(mkdir);
@@ -2519,10 +2491,7 @@ int rmdir (const char *pathname)
path_put(&path);
putname(name);
- if (error)
- errno = -error;
-
- return error;
+ return errno_set(error);
}
EXPORT_SYMBOL(rmdir);
@@ -2676,10 +2645,7 @@ int open(const char *pathname, int flags, ...)
out:
put_file(f);
out1:
-
- if (error)
- errno = -error;
- return error;
+ return errno_set(error);
}
EXPORT_SYMBOL(open);
@@ -2717,9 +2683,7 @@ int unlink(const char *pathname)
out_put:
path_put(&path);
out:
- if (ret)
- errno = -ret;
- return ret;
+ return errno_set(ret);
}
EXPORT_SYMBOL(unlink);
@@ -2746,10 +2710,7 @@ int symlink(const char *pathname, const char *newpath)
error = vfs_symlink(path.dentry->d_inode, dentry, pathname);
out:
- if (error)
- errno = -error;
-
- return error;
+ return errno_set(error);
}
EXPORT_SYMBOL(symlink);
@@ -2819,7 +2780,7 @@ DIR *opendir(const char *pathname)
out_put:
path_put(&path);
out:
- errno = -ret;
+ errno_set(ret);
return NULL;
}
@@ -2827,10 +2788,8 @@ EXPORT_SYMBOL(opendir);
int closedir(DIR *dir)
{
- if (!dir) {
- errno = EBADF;
- return -EBADF;
- }
+ if (!dir)
+ return errno_set(-EBADF);
release_dir(dir);
@@ -2876,10 +2835,7 @@ int readlink(const char *pathname, char *buf, size_t bufsiz)
out_put:
path_put(&path);
out:
- if (ret)
- errno = -ret;
-
- return ret;
+ return errno_set(ret);
}
EXPORT_SYMBOL(readlink);
@@ -2909,10 +2865,7 @@ static int stat_filename(const char *filename, struct stat *s, unsigned int flag
out_put:
path_put(&path);
out:
- if (ret)
- errno = -ret;
-
- return ret;
+ return errno_set(ret);
}
int stat(const char *filename, struct stat *s)
@@ -3000,9 +2953,7 @@ char *canonicalize_path(const char *pathname)
res = dpath(path.dentry, d_root);
out:
- if (ret)
- errno = -ret;
-
+ errno_set(ret);
return res;
}
@@ -3036,10 +2987,7 @@ int chdir(const char *pathname)
ret = 0;
out:
- if (ret)
- errno = -ret;
-
- return ret;
+ return errno_set(ret);
}
EXPORT_SYMBOL(chdir);
@@ -3234,9 +3182,7 @@ int mount(const char *device, const char *fsname, const char *pathname,
out:
path_put(&path);
- errno = -ret;
-
- return ret;
+ return errno_set(ret);
}
EXPORT_SYMBOL(mount);
@@ -3273,10 +3219,8 @@ int umount(const char *pathname)
}
}
- if (!fsdev) {
- errno = EFAULT;
- return -EFAULT;
- }
+ if (!fsdev)
+ return errno_set(-EFAULT);
return fsdev_umount(fsdev);
}
diff --git a/include/errno.h b/include/errno.h
index 6ec7af4d7e9f..12e526a0d7ed 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -10,4 +10,11 @@ extern int errno;
void perror(const char *s);
const char *strerror(int errnum);
+static inline int errno_set(int err)
+{
+ if (err < 0)
+ errno = -err;
+ return err;
+}
+
#endif /* __ERRNO_H */
diff --git a/lib/libfile.c b/lib/libfile.c
index 72a2fc79c721..185c7af721b5 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -33,10 +33,8 @@ int pwrite_full(int fd, const void *buf, size_t size, loff_t offset)
while (size) {
now = pwrite(fd, buf, size, offset);
- if (now == 0) {
- errno = ENOSPC;
- return -errno;
- }
+ if (now == 0)
+ return errno_set(-ENOSPC);
if (now < 0)
return now;
size -= now;
@@ -61,10 +59,8 @@ int write_full(int fd, const void *buf, size_t size)
while (size) {
now = write(fd, buf, size);
- if (now == 0) {
- errno = ENOSPC;
- return -errno;
- }
+ if (now == 0)
+ return errno_set(-ENOSPC);
if (now < 0)
return now;
size -= now;
@@ -240,8 +236,7 @@ int read_file_2(const char *filename, size_t *size, void **outbuf,
/* ensure wchar_t nul termination */
buf = calloc(ALIGN(read_size, 2) + 2, 1);
if (!buf) {
- ret = -ENOMEM;
- errno = ENOMEM;
+ ret = errno_set(-ENOMEM);
goto err_out;
}
diff --git a/lib/parameter.c b/lib/parameter.c
index aac33e3a1940..c2b8536ee93f 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -90,28 +90,22 @@ int dev_set_param(struct device *dev, const char *name, const char *val)
struct param_d *param;
int ret;
- if (!dev) {
- errno = ENODEV;
- return -ENODEV;
- }
+ if (!dev)
+ return errno_set(-ENODEV);
param = get_param_by_name(dev, name);
- if (!param) {
- errno = EINVAL;
- return -EINVAL;
- }
+ if (!param)
+ return errno_set(-EINVAL);
- if (param->flags & PARAM_FLAG_RO) {
- errno = EACCES;
- return -EACCES;
- }
+ if (param->flags & PARAM_FLAG_RO)
+ return errno_set(-EACCES);
ret = param->set(dev, param, val);
if (ret)
- errno = -ret;
+ return errno_set(ret);
- return ret;
+ return 0;
}
/**
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 004/112] vsprintf: guard against NULL in UUID %pU
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (2 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 003/112] treewide: add errno_set helper for returning positive error code in errno Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 005/112] common: add option to poweroff system on failure Ahmad Fatoum
` (107 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
To make %pU more useful for debugging, have it handle NULL gracefully.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
lib/vsprintf.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 7d943706ddea..ea092c06d3d6 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -309,6 +309,10 @@ char *uuid_string(char *buf, const char *end, const u8 *addr, int field_width,
const u8 *index = be;
bool uc = false;
+ /* If addr == NULL output the string '<NULL>' */
+ if (!addr)
+ return string(buf, end, NULL, field_width, precision, flags);
+
switch (*(++fmt)) {
case 'L':
uc = true; /* fall-through */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 005/112] common: add option to poweroff system on failure
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (3 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 004/112] vsprintf: guard against NULL in UUID %pU Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 006/112] boot: print error code when booting fails Ahmad Fatoum
` (106 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
When developing using Qemu and KASAN/Hardening options enabled, it can
be useful to just terminate Qemu on an error, because a stack trace is
already printed to console and restarting barebox or hanging just
results in the developer having to kill the process.
For this use case, add shutdown as third option besides hang and reset.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/Kconfig | 44 ++++++++++++++++++++++++++++++++++----------
common/misc.c | 12 ++++++++----
2 files changed, 42 insertions(+), 14 deletions(-)
diff --git a/common/Kconfig b/common/Kconfig
index 18ad01713293..6377a587f00b 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -353,16 +353,40 @@ config RELOCATABLE
allowing it to relocate to the end of the available RAM. This
way you have the whole memory in a single piece.
-config PANIC_HANG
- bool "hang the system in case of a fatal error"
- help
- This option enables stop of the system in case of a
- fatal error, so that you have to reset it manually.
- This is probably NOT a good idea for an embedded
- system where you want the system to reboot
- automatically as fast as possible, but it may be
- useful during development since you can try to debug
- the conditions that lead to the situation.
+choice
+ prompt "Configure action on fatal error"
+ default PANIC_RESET
+
+ config PANIC_POWEROFF
+ bool "power off the system"
+ help
+ This option shuts down the system in case of a
+ fatal error, so that you have to power it on manually.
+ This is probably NOT a good idea for an embedded
+ system where you want the system to reboot
+ automatically as fast as possible, but it may be
+ useful in emulation, because the system returns
+ to parent shell immediately.
+
+ config PANIC_HANG
+ bool "hang the system"
+ help
+ This option enables stop of the system in case of a
+ fatal error, so that you have to reset it manually.
+ This is probably NOT a good idea for an embedded
+ system where you want the system to reboot
+ automatically as fast as possible, but it may be
+ useful during development since you can try to debug
+ the conditions that lead to the situation.
+
+ config PANIC_RESET
+ bool "reset the system"
+ help
+ This option enables reset of the system in case of a
+ fatal error, so you don't have to reset it manually.
+ This is the recommended configuration in production.
+
+endchoice
config PROMPT
string
diff --git a/common/misc.c b/common/misc.c
index e266f0951ee9..04ff4e6eb5c5 100644
--- a/common/misc.c
+++ b/common/misc.c
@@ -13,6 +13,7 @@
#include <led.h>
#include <of.h>
#include <restart.h>
+#include <poweroff.h>
#include <linux/stringify.h>
int errno;
@@ -226,12 +227,15 @@ static void __noreturn do_panic(bool stacktrace, const char *fmt, va_list ap)
led_trigger(LED_TRIGGER_PANIC, TRIGGER_ENABLE);
- if (IS_ENABLED(CONFIG_PANIC_HANG)) {
+ if (IS_ENABLED(CONFIG_PANIC_HANG))
hang();
- } else {
- udelay(100000); /* allow messages to go out */
+
+ udelay(100000); /* allow messages to go out */
+
+ if (IS_ENABLED(CONFIG_PANIC_POWEROFF))
+ poweroff_machine();
+ else
restart_machine();
- }
}
void __noreturn panic(const char *fmt, ...)
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 006/112] boot: print error code when booting fails
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (4 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 005/112] common: add option to poweroff system on failure Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 007/112] common: efi: move directory to top-level Ahmad Fatoum
` (105 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Depending on how boot_entry() is called, the actual error code may be
never printed anywhere for user inspection. Improve user experience by
always printing it along with the failure message.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/boot.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/boot.c b/common/boot.c
index dd9e26afc769..28bb459883cf 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -152,7 +152,7 @@ int boot_entry(struct bootentry *be, int verbose, int dryrun)
ret = be->boot(be, verbose, dryrun);
if (ret && ret != -ENOMEDIUM)
- pr_err("Booting entry '%s' failed\n", be->title);
+ pr_err("Booting entry '%s' failed: %pe\n", be->title, ERR_PTR(ret));
return ret;
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 007/112] common: efi: move directory to top-level
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (5 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 006/112] boot: print error code when booting fails Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 008/112] efi: payload: rename CONFIG_EFI_BOOTUP to CONFIG_EFI_PAYLOAD Ahmad Fatoum
` (104 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The EFI code will grow considerably with the addition of loader support,
so it makes sense to move it to top-level to shorten the path and to
improve visibility.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Kconfig | 1 +
Makefile | 1 +
common/Kconfig | 2 --
common/Makefile | 1 -
{common/efi => efi}/Kconfig | 0
{common/efi => efi}/Makefile | 0
{common/efi => efi}/devicepath.c | 0
{common/efi => efi}/efivar-filename.c | 0
{common/efi => efi}/errno.c | 0
{common/efi => efi}/guid.c | 0
{common/efi => efi}/payload/Makefile | 0
{common/efi => efi}/payload/env-efi/network/eth0-discover | 0
{common/efi => efi}/payload/fdt.c | 0
{common/efi => efi}/payload/image.c | 0
{common/efi => efi}/payload/init.c | 0
{common/efi => efi}/payload/iomem.c | 0
16 files changed, 2 insertions(+), 3 deletions(-)
rename {common/efi => efi}/Kconfig (100%)
rename {common/efi => efi}/Makefile (100%)
rename {common/efi => efi}/devicepath.c (100%)
rename {common/efi => efi}/efivar-filename.c (100%)
rename {common/efi => efi}/errno.c (100%)
rename {common/efi => efi}/guid.c (100%)
rename {common/efi => efi}/payload/Makefile (100%)
rename {common/efi => efi}/payload/env-efi/network/eth0-discover (100%)
rename {common/efi => efi}/payload/fdt.c (100%)
rename {common/efi => efi}/payload/image.c (100%)
rename {common/efi => efi}/payload/init.c (100%)
rename {common/efi => efi}/payload/iomem.c (100%)
diff --git a/Kconfig b/Kconfig
index 4c076026b0c9..9c3a20a9a9a3 100644
--- a/Kconfig
+++ b/Kconfig
@@ -11,6 +11,7 @@ source "scripts/Kconfig.include"
source "arch/Kconfig"
source "common/Kconfig"
+source "efi/Kconfig"
source "commands/Kconfig"
source "net/Kconfig"
source "drivers/Kconfig"
diff --git a/Makefile b/Makefile
index 9a982e943cd4..c5c627bb6a8c 100644
--- a/Makefile
+++ b/Makefile
@@ -601,6 +601,7 @@ common-y := common/ drivers/ commands/ lib/ crypto/ net/ fs/ firmware/
include $(srctree)/arch/$(SRCARCH)/Makefile
+common-$(CONFIG_EFI) += efi/
common-y += test/
ifdef need-config
diff --git a/common/Kconfig b/common/Kconfig
index 6377a587f00b..0e8188d2b2fb 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1789,8 +1789,6 @@ config WERROR
endmenu
-source "common/efi/Kconfig"
-
config HAS_DEBUG_LL
bool
diff --git a/common/Makefile b/common/Makefile
index 7fb864f61480..936997d9bcdd 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -70,7 +70,6 @@ obj-$(CONFIG_BOOTCHOOSER) += bootchooser.o
obj-$(CONFIG_UIMAGE) += image.o uimage.o
obj-$(CONFIG_FITIMAGE) += image-fit.o
obj-$(CONFIG_MENUTREE) += menutree.o
-obj-$(CONFIG_EFI) += efi/
lwl-$(CONFIG_IMD) += imd-barebox.o
obj-$(CONFIG_IMD) += imd.o
obj-y += file-list.o
diff --git a/common/efi/Kconfig b/efi/Kconfig
similarity index 100%
rename from common/efi/Kconfig
rename to efi/Kconfig
diff --git a/common/efi/Makefile b/efi/Makefile
similarity index 100%
rename from common/efi/Makefile
rename to efi/Makefile
diff --git a/common/efi/devicepath.c b/efi/devicepath.c
similarity index 100%
rename from common/efi/devicepath.c
rename to efi/devicepath.c
diff --git a/common/efi/efivar-filename.c b/efi/efivar-filename.c
similarity index 100%
rename from common/efi/efivar-filename.c
rename to efi/efivar-filename.c
diff --git a/common/efi/errno.c b/efi/errno.c
similarity index 100%
rename from common/efi/errno.c
rename to efi/errno.c
diff --git a/common/efi/guid.c b/efi/guid.c
similarity index 100%
rename from common/efi/guid.c
rename to efi/guid.c
diff --git a/common/efi/payload/Makefile b/efi/payload/Makefile
similarity index 100%
rename from common/efi/payload/Makefile
rename to efi/payload/Makefile
diff --git a/common/efi/payload/env-efi/network/eth0-discover b/efi/payload/env-efi/network/eth0-discover
similarity index 100%
rename from common/efi/payload/env-efi/network/eth0-discover
rename to efi/payload/env-efi/network/eth0-discover
diff --git a/common/efi/payload/fdt.c b/efi/payload/fdt.c
similarity index 100%
rename from common/efi/payload/fdt.c
rename to efi/payload/fdt.c
diff --git a/common/efi/payload/image.c b/efi/payload/image.c
similarity index 100%
rename from common/efi/payload/image.c
rename to efi/payload/image.c
diff --git a/common/efi/payload/init.c b/efi/payload/init.c
similarity index 100%
rename from common/efi/payload/init.c
rename to efi/payload/init.c
diff --git a/common/efi/payload/iomem.c b/efi/payload/iomem.c
similarity index 100%
rename from common/efi/payload/iomem.c
rename to efi/payload/iomem.c
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 008/112] efi: payload: rename CONFIG_EFI_BOOTUP to CONFIG_EFI_PAYLOAD
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (6 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 007/112] common: efi: move directory to top-level Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 009/112] efi: payload: image: return actual read_file() error Ahmad Fatoum
` (103 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The symbol is internal, so we don't break anything by renaming it.
CONFIG_EFI_PAYLOAD is clearer in intent, as BOOTUP doesn't clearly
indificate whether barebox would act as EFI payload or as EFI loader.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/x86/Kconfig | 2 +-
drivers/Makefile | 2 +-
drivers/block/Kconfig | 2 +-
drivers/bus/Kconfig | 2 +-
drivers/clocksource/Kconfig | 4 ++--
drivers/net/Kconfig | 2 +-
drivers/of/Kconfig | 2 +-
drivers/pci/Kconfig | 2 +-
drivers/serial/Kconfig | 4 ++--
drivers/video/Kconfig | 2 +-
drivers/watchdog/Kconfig | 2 +-
efi/Kconfig | 2 +-
efi/Makefile | 2 +-
fs/Kconfig | 4 ++--
include/efi.h | 2 +-
15 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index bd6a94bd0b0e..8b00a674a688 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -45,5 +45,5 @@ config MACH_EFI_GENERIC
config X86_EFI
def_bool y
- select EFI_BOOTUP
+ select EFI_PAYLOAD
select CLOCKSOURCE_EFI_X86
diff --git a/drivers/Makefile b/drivers/Makefile
index 42a71f73c259..4be519d1fe4a 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -2,7 +2,7 @@
obj-y += base/
obj-y += block/
obj-$(CONFIG_ARM_AMBA) += amba/
-obj-$(CONFIG_EFI_BOOTUP) += efi/
+obj-$(CONFIG_EFI_PAYLOAD) += efi/
obj-y += net/
obj-y += serial/
obj-y += mtd/
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 625e81a4ec97..bf8dfdbd5c12 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -9,7 +9,7 @@ config VIRTIO_BLK
config EFI_BLK
bool "EFI block I/O driver"
default y
- depends on EFI_BOOTUP
+ depends on EFI_PAYLOAD
config EFI_BLK_SEPARATE_USBDISK
bool "rename USB devices to /dev/usbdiskX"
diff --git a/drivers/bus/Kconfig b/drivers/bus/Kconfig
index e622ed239c7c..b480cf8bff0f 100644
--- a/drivers/bus/Kconfig
+++ b/drivers/bus/Kconfig
@@ -29,7 +29,7 @@ config MVEBU_MBUS
config ACPI
bool "Advanced Configuration and Power Interface (ACPI)"
default y
- depends on EFI_BOOTUP
+ depends on EFI_PAYLOAD
help
Driver needed for supporting drivers probed from ACPI tables.
The root SDT is found via UEFI.
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index e1bff23320de..5ee83d2b383c 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -42,11 +42,11 @@ config CLOCKSOURCE_DUMMY_RATE
config CLOCKSOURCE_EFI
bool "Generic EFI Driver"
- depends on EFI_BOOTUP
+ depends on EFI_PAYLOAD
config CLOCKSOURCE_EFI_X86
bool "EFI X86 HW driver"
- depends on EFI_BOOTUP && X86
+ depends on EFI_PAYLOAD && X86
config CLOCKSOURCE_KVX
bool "KVX core timer clocksource"
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index e3571cbb20a4..a02d00f672bd 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -276,7 +276,7 @@ config DRIVER_NET_TAP
config DRIVER_NET_EFI_SNP
bool "EFI SNP ethernet driver"
- depends on EFI_BOOTUP
+ depends on EFI_PAYLOAD
config DRIVER_NET_VIRTIO
bool "virtio net driver"
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 816aff0063b0..8dd796572062 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -5,7 +5,7 @@ config OFTREE
config OFTREE_MEM_GENERIC
depends on OFTREE
- depends on PPC || ARM || EFI_BOOTUP || OPENRISC || SANDBOX || RISCV || KVX
+ depends on PPC || ARM || EFI_PAYLOAD || OPENRISC || SANDBOX || RISCV || KVX
def_bool y
config DTC
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 39df54f215cf..8f37805d71ca 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -64,7 +64,7 @@ config PCI_ROCKCHIP
config PCI_EFI
bool "EFI PCI protocol"
- depends on EFI_BOOTUP
+ depends on EFI_PAYLOAD
select PCI
config PCI_ECAM_GENERIC
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 803f6b6aee9e..60b0e5f1dc1f 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -31,7 +31,7 @@ config DRIVER_SERIAL_AR933X
config DRIVER_SERIAL_EFI
bool "EFI serial"
- depends on EFI_BOOTUP
+ depends on EFI_PAYLOAD
config DRIVER_SERIAL_IMX
depends on ARCH_IMX
@@ -58,7 +58,7 @@ config DRIVER_SERIAL_LINUX_CONSOLE
bool "linux console driver"
config DRIVER_SERIAL_EFI_STDIO
- depends on EFI_BOOTUP
+ depends on EFI_PAYLOAD
bool "EFI stdio driver"
config DRIVER_SERIAL_MPC5XXX
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index b4e37a92586e..571ce49ef616 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -31,7 +31,7 @@ config DRIVER_VIDEO_ATMEL_HLCD
config DRIVER_VIDEO_EFI_GOP
bool "EFI Graphics Output Protocol (GOP)"
- depends on EFI_BOOTUP
+ depends on EFI_PAYLOAD
config DRIVER_VIDEO_IMX
bool "i.MX framebuffer driver"
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 159b495acbd9..762e37c9c2dd 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -31,7 +31,7 @@ config WATCHDOG_AT91SAM9
config WATCHDOG_EFI
bool "Generic EFI Watchdog Driver"
- depends on EFI_BOOTUP
+ depends on EFI_PAYLOAD
help
Add support for the EFI watchdog.
diff --git a/efi/Kconfig b/efi/Kconfig
index 15246ccbf0e0..971d58a7a9c0 100644
--- a/efi/Kconfig
+++ b/efi/Kconfig
@@ -2,7 +2,7 @@
menu "EFI (Extensible Firmware Interface) Support"
-config EFI_BOOTUP
+config EFI_PAYLOAD
bool
select EFI
select EFI_GUID
diff --git a/efi/Makefile b/efi/Makefile
index a7cebde4f1b3..2b188bafa0a4 100644
--- a/efi/Makefile
+++ b/efi/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only
-obj-$(CONFIG_EFI_BOOTUP) += payload/
+obj-$(CONFIG_EFI_PAYLOAD) += payload/
obj-$(CONFIG_EFI_GUID) += guid.o
obj-$(CONFIG_EFI_DEVICEPATH) += devicepath.o
obj-y += errno.o efivar-filename.o
diff --git a/fs/Kconfig b/fs/Kconfig
index 0c4934285942..a3ba84b6aefd 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -69,7 +69,7 @@ config FS_NFS
prompt "nfs support"
config FS_EFI
- depends on EFI_BOOTUP
+ depends on EFI_PAYLOAD
select FS_LEGACY
bool
prompt "EFI filesystem support"
@@ -78,7 +78,7 @@ config FS_EFI
by the EFI Firmware via the EFI Simple File System Protocol.
config FS_EFIVARFS
- depends on EFI_BOOTUP
+ depends on EFI_PAYLOAD
select FS_LEGACY
bool
prompt "EFI variable filesystem support (efivarfs)"
diff --git a/include/efi.h b/include/efi.h
index 1904caf3a4b6..f1567f7791b8 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -16,7 +16,7 @@
#include <linux/types.h>
#include <linux/uuid.h>
-#ifdef CONFIG_EFI_BOOTUP
+#ifdef CONFIG_EFI_PAYLOAD
#define EFIAPI __attribute__((ms_abi))
#else
#define EFIAPI
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 009/112] efi: payload: image: return actual read_file() error
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (7 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 008/112] efi: payload: rename CONFIG_EFI_BOOTUP to CONFIG_EFI_PAYLOAD Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 010/112] of: don't report failure to of_read_file twice Ahmad Fatoum
` (102 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
read_file returns NULL on error and sets errno, e.g. to ENOMEM if the
image to be booted exceeds memory available to barebox. Yet, errno was
ignored and EINVAL was returned as error code unconditionally. Fix this
to improve user experience.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/image.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/efi/payload/image.c b/efi/payload/image.c
index 8e39098ae81b..8d29bf9bb434 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -86,7 +86,7 @@ static int efi_load_image(const char *file, efi_loaded_image_t **loaded_image,
exe = read_file(file, &size);
if (!exe)
- return -EINVAL;
+ return -errno;
efiret = BS->load_image(false, efi_parent_image, efi_device_path, exe, size,
&handle);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 010/112] of: don't report failure to of_read_file twice
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (8 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 009/112] efi: payload: image: return actual read_file() error Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 011/112] efi: payload: make missing state reporting less verbose Ahmad Fatoum
` (101 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
of_read_file already prints to log messages when it fails, so
duplicating the error message in the caller is needlessly verbose.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/of_diff.c | 5 ++---
commands/of_display_timings.c | 4 +---
commands/of_overlay.c | 4 +---
commands/oftree.c | 4 +---
drivers/of/overlay.c | 4 +---
efi/payload/init.c | 4 +---
6 files changed, 7 insertions(+), 18 deletions(-)
diff --git a/commands/of_diff.c b/commands/of_diff.c
index 8b19c093ddab..623b033c7323 100644
--- a/commands/of_diff.c
+++ b/commands/of_diff.c
@@ -19,15 +19,14 @@ static struct device_node *get_tree(const char *filename, struct device_node *ro
if (!strcmp(filename, "-")) {
node = of_dup(root) ?: ERR_PTR(-ENOENT);
+ if (IS_ERR(node))
+ printf("Cannot duplicate live tree: %pe\n", node);
} else if (!strcmp(filename, "+")) {
return NULL;
} else {
node = of_read_file(filename);
}
- if (IS_ERR(node))
- printf("Cannot read %s: %pe\n", filename, node);
-
return node;
}
diff --git a/commands/of_display_timings.c b/commands/of_display_timings.c
index 4cc79ec88d7e..232074fce786 100644
--- a/commands/of_display_timings.c
+++ b/commands/of_display_timings.c
@@ -68,10 +68,8 @@ static int do_of_display_timings(int argc, char *argv[])
/* Check if external dtb given */
if (dtbfile) {
root = of_read_file(dtbfile);
- if (IS_ERR(root)) {
- printf("Cannot open %s: %pe\n", dtbfile, root);
+ if (IS_ERR(root))
return PTR_ERR(root);
- }
} else {
root = of_get_root_node();
}
diff --git a/commands/of_overlay.c b/commands/of_overlay.c
index fda9115a8201..2013c4b27867 100644
--- a/commands/of_overlay.c
+++ b/commands/of_overlay.c
@@ -36,10 +36,8 @@ static int do_of_overlay(int argc, char *argv[])
}
overlay = of_read_file(argv[optind]);
- if (IS_ERR(overlay)) {
- printf("Cannot open %s: %pe\n", argv[optind], overlay);
+ if (IS_ERR(overlay))
return PTR_ERR(overlay);
- }
if (live_tree) {
ret = of_overlay_apply_tree(of_get_root_node(), overlay);
diff --git a/commands/oftree.c b/commands/oftree.c
index 7b12c86e1dc3..76227a10b033 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -76,10 +76,8 @@ static int do_oftree(int argc, char *argv[])
if (load) {
root = of_read_file(load);
- if (IS_ERR(root)) {
- printf("Cannot open %s: %pe\n", load, root);
+ if (IS_ERR(root))
return PTR_ERR(root);
- }
ret = of_set_root_node(root);
if (ret) {
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 2d2367fc101b..73c7a91db9b5 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -315,10 +315,8 @@ int of_overlay_apply_file(struct device_node *root, const char *filename,
return 0;
ovl = of_read_file(filename);
- if (IS_ERR(ovl)) {
- pr_err("Failed to unflatten %s: %pe\n", filename, ovl);
+ if (IS_ERR(ovl))
return PTR_ERR(ovl);
- }
if (filter && !of_overlay_matches_filter(NULL, ovl))
return 0;
diff --git a/efi/payload/init.c b/efi/payload/init.c
index ffa466e3ad44..caab28741cc5 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -399,10 +399,8 @@ static int efi_late_init(void)
struct state *state;
root = of_read_file(state_desc);
- if (IS_ERR(root)) {
- printf("Cannot open %s: %pe\n", state_desc, root);
+ if (IS_ERR(root))
return PTR_ERR(root);
- }
ret = barebox_register_of(root);
if (ret)
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 011/112] efi: payload: make missing state reporting less verbose
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (9 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 010/112] of: don't report failure to of_read_file twice Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 012/112] libfile: factor out read_file_into_buf helper Ahmad Fatoum
` (100 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
A non-existing state may not be a problem if barebox state is unused.
An error message is printed in that case inside of_read_file and failing
the initcall results in a second error message, which is annoying.
Change this to only print an info message and move along.
of_unflatten_dtb() will report errors to parse the file on its own.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/init.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/efi/payload/init.c b/efi/payload/init.c
index caab28741cc5..b0612276654e 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -385,28 +385,31 @@ postcore_initcall(efi_postcore_init);
static int efi_late_init(void)
{
- char *state_desc;
+ const char *state_desc = "/boot/EFI/barebox/state.dtb";
+ struct device_node *state_root = NULL;
+ size_t size;
+ void *fdt;
int ret;
if (!IS_ENABLED(CONFIG_STATE))
return 0;
- state_desc = xasprintf("/boot/EFI/barebox/state.dtb");
+ fdt = read_file(state_desc, &size);
+ if (!fdt) {
+ pr_info("unable to read %s: %m\n", state_desc);
+ return 0;
+ }
- if (state_desc) {
- struct device_node *root = NULL;
+ state_root = of_unflatten_dtb(fdt, size);
+ if (!IS_ERR(state_root)) {
struct device_node *np = NULL;
struct state *state;
- root = of_read_file(state_desc);
- if (IS_ERR(root))
- return PTR_ERR(root);
-
- ret = barebox_register_of(root);
+ ret = barebox_register_of(state_root);
if (ret)
pr_warn("Failed to register device-tree: %pe\n", ERR_PTR(ret));
- np = of_find_node_by_alias(root, "state");
+ np = of_find_node_by_alias(state_root, "state");
state = state_new_from_node(np, false);
if (IS_ERR(state))
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 012/112] libfile: factor out read_file_into_buf helper
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (10 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 011/112] efi: payload: make missing state reporting less verbose Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 013/112] efi: payload: image: allocate image via loader if it exceeds malloc area Ahmad Fatoum
` (99 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We do open -> read_full -> close at a number of places. Add a function
that does this all at once and start using it to implement read_file.
More users can follow later.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/libfile.h | 4 ++++
lib/libfile.c | 44 ++++++++++++++++++++++++++++++--------------
2 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/include/libfile.h b/include/libfile.h
index 423e7ffec5b7..1240276e1d74 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -2,12 +2,16 @@
#ifndef __LIBFILE_H
#define __LIBFILE_H
+#include <linux/types.h>
+
int pread_full(int fd, void *buf, size_t size, loff_t offset);
int pwrite_full(int fd, const void *buf, size_t size, loff_t offset);
int write_full(int fd, const void *buf, size_t size);
int read_full(int fd, void *buf, size_t size);
int copy_fd(int in, int out);
+ssize_t read_file_into_buf(const char *filename, void *buf, size_t size);
+
char *read_file_line(const char *fmt, ...);
void *read_file(const char *filename, size_t *size);
diff --git a/lib/libfile.c b/lib/libfile.c
index 185c7af721b5..67fc9cc7f3a2 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -186,6 +186,33 @@ char *read_file_line(const char *fmt, ...)
}
EXPORT_SYMBOL_GPL(read_file_line);
+/**
+ * read_file_into_buf - read a file to an external buffer
+ * @filename: The filename to read
+ * @buf: The buffer to read into
+ * @size: The buffer size
+ *
+ * This function reads a file to an external buffer. At maximum @size
+ * bytes are read.
+ *
+ * Return: number of bytes read, or negative error code.
+ */
+ssize_t read_file_into_buf(const char *filename, void *buf, size_t size)
+{
+ int fd;
+ ssize_t ret;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return fd;
+
+ ret = read_full(fd, buf, size);
+
+ close(fd);
+
+ return ret;
+}
+
/**
* read_file_2 - read a file to an allocated buffer
* @filename: The filename to read
@@ -208,11 +235,10 @@ EXPORT_SYMBOL_GPL(read_file_line);
int read_file_2(const char *filename, size_t *size, void **outbuf,
loff_t max_size)
{
- int fd;
struct stat s;
void *buf = NULL;
const char *tmpfile = "/.read_file_tmp";
- int ret;
+ ssize_t ret;
loff_t read_size;
again:
@@ -240,17 +266,9 @@ int read_file_2(const char *filename, size_t *size, void **outbuf,
goto err_out;
}
- fd = open(filename, O_RDONLY);
- if (fd < 0) {
- ret = fd;
- goto err_out;
- }
-
- ret = read_full(fd, buf, read_size);
+ ret = read_file_into_buf(filename, buf, read_size);
if (ret < 0)
- goto err_out1;
-
- close(fd);
+ goto err_out;
if (size)
*size = ret;
@@ -265,8 +283,6 @@ int read_file_2(const char *filename, size_t *size, void **outbuf,
return 0;
-err_out1:
- close(fd);
err_out:
free(buf);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 013/112] efi: payload: image: allocate image via loader if it exceeds malloc area
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (11 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 012/112] libfile: factor out read_file_into_buf helper Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 014/112] efi: payload: image: use assigned barebox loader type on x86 Ahmad Fatoum
` (98 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
barebox allocates at maximum 256M for its own use when running as EFI
payload. With bigger kernel images and initrds, this may exceed the
space barebox has available, especially if decompression needs to happen
within barebox.
In that case, instead of failing with -ENOMEM, let's ask the EFI
firmware for a suitably sized buffer and read into that if the
allocation succeeds.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/image.c | 49 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 47 insertions(+), 2 deletions(-)
diff --git a/efi/payload/image.c b/efi/payload/image.c
index 8d29bf9bb434..b7f4b7560b4b 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -76,6 +76,51 @@ struct linux_kernel_header {
uint32_t handover_offset; /** */
} __attribute__ ((packed));
+static void *efi_read_file(const char *file, size_t *size)
+{
+ efi_physical_addr_t mem;
+ efi_status_t efiret;
+ struct stat s;
+ char *buf;
+ ssize_t ret;
+
+ buf = read_file(file, size);
+ if (buf || errno != ENOMEM)
+ return buf;
+
+ ret = stat(file, &s);
+ if (ret)
+ return NULL;
+
+ efiret = BS->allocate_pages(EFI_ALLOCATE_ANY_PAGES,
+ EFI_LOADER_CODE,
+ DIV_ROUND_UP(s.st_size, EFI_PAGE_SIZE),
+ &mem);
+ if (EFI_ERROR(efiret)) {
+ errno = efi_errno(efiret);
+ return NULL;
+ }
+
+ buf = (void *)mem;
+
+ ret = read_file_into_buf(file, buf, s.st_size);
+ if (ret < 0)
+ return NULL;
+
+ *size = ret;
+ return buf;
+}
+
+static void efi_free_file(void *_mem, size_t size)
+{
+ efi_physical_addr_t mem = (efi_physical_addr_t)_mem;
+
+ if (mem_malloc_start() <= mem && mem < mem_malloc_end())
+ free(_mem);
+ else
+ BS->free_pages(mem, DIV_ROUND_UP(size, EFI_PAGE_SIZE));
+}
+
static int efi_load_image(const char *file, efi_loaded_image_t **loaded_image,
efi_handle_t *h)
{
@@ -84,7 +129,7 @@ static int efi_load_image(const char *file, efi_loaded_image_t **loaded_image,
efi_handle_t handle;
efi_status_t efiret = EFI_SUCCESS;
- exe = read_file(file, &size);
+ exe = efi_read_file(file, &size);
if (!exe)
return -errno;
@@ -106,7 +151,7 @@ static int efi_load_image(const char *file, efi_loaded_image_t **loaded_image,
*h = handle;
out:
- free(exe);
+ efi_free_file(exe, size);
return -efi_errno(efiret);
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 014/112] efi: payload: image: use assigned barebox loader type on x86
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (12 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 013/112] efi: payload: image: allocate image via loader if it exceeds malloc area Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 015/112] efi: payload: iomem: adjust types to avoid casting Ahmad Fatoum
` (97 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Starting with Linux v6.2, there's a loader type assigned to barebox:
commit a27e292b8a54e24f85181d949fac8c51fdec8ff3
Author: Ahmad Fatoum <a.fatoum@pengutronix.de>
AuthorDate: Sun Oct 2 14:57:53 2022 +0200
Commit: Borislav Petkov <bp@suse.de>
CommitDate: Mon Oct 17 11:22:33 2022 +0200
Documentation/x86/boot: Reserve type_of_loader=13 for barebox
barebox[1], a bootloader for mostly ARM and MIPS embedded systems, can
also be built as EFI payload for x86[2] to provide redundant power-fail
safe, watchdog-supervised boot up.
Since its v2015.09.0 release, it has been booting Linux on x86 with
type_of_loader=0xff[3]. Reserve 13, the next free id, so that can be
used instead in the future.
[1]: https://www.barebox.org/
[2]: https://www.barebox.org/doc/latest/boards/efi.html
[3]: https://elixir.bootlin.com/barebox/v2022.09.0/source/common/efi/payload/image.c#L217
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/20221002125752.3400831-1-a.fatoum@pengutronix.de
Thus, let's start making use of that.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/image.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/efi/payload/image.c b/efi/payload/image.c
index b7f4b7560b4b..a8748da1df88 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -261,7 +261,10 @@ static int do_bootm_efi(struct image_data *data)
memset(boot_header, 0, 0x4000);
memcpy(boot_header, image_header, sizeof(*image_header));
- boot_header->type_of_loader = 0xff;
+ /* Refer to Linux kernel commit a27e292b8a54
+ * ("Documentation/x86/boot: Reserve type_of_loader=13 for barebox")
+ */
+ boot_header->type_of_loader = 0x13;
if (data->initrd_file) {
tmp = read_file(data->initrd_file, &size);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 015/112] efi: payload: iomem: adjust types to avoid casting
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (13 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 014/112] efi: payload: image: use assigned barebox loader type on x86 Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 016/112] commands: kallsyms: add command-line interface Ahmad Fatoum
` (96 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We make ample use of GNU C's support for void pointer arithmetic, so use
it here as well to get rid of the helper variable.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/iomem.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/efi/payload/iomem.c b/efi/payload/iomem.c
index 6b92ca993aa7..316dacd6b3c2 100644
--- a/efi/payload/iomem.c
+++ b/efi/payload/iomem.c
@@ -142,8 +142,7 @@ static int efi_parse_mmap(struct efi_memory_desc *desc, bool verbose)
static int efi_barebox_populate_mmap(void)
{
- void *desc;
- u8 *mmap_buf = NULL;
+ void *mmap_buf = NULL, *desc;
efi_status_t efiret;
size_t mmap_size;
size_t mapkey;
@@ -169,7 +168,7 @@ static int efi_barebox_populate_mmap(void)
goto out;
}
- for (desc = mmap_buf; (u8 *)desc < mmap_buf + mmap_size; desc += descsz)
+ for (desc = mmap_buf; desc < mmap_buf + mmap_size; desc += descsz)
efi_parse_mmap(desc, __is_defined(DEBUG));
out:
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 016/112] commands: kallsyms: add command-line interface
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (14 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 015/112] efi: payload: iomem: adjust types to avoid casting Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 017/112] block: define BLOCKSIZE globally in block.h Ahmad Fatoum
` (95 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
When working on kallsyms code, it's useful to be able to resolve symbols
and decode addresses on the fly. Add a simple command to facilitate
this. There should be no need to enable this except for development.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/Kconfig | 9 ++++++++
commands/Makefile | 1 +
commands/kallsyms.c | 50 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 60 insertions(+)
create mode 100644 commands/kallsyms.c
diff --git a/commands/Kconfig b/commands/Kconfig
index a6806f198ec4..d27c20478fcf 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2178,6 +2178,15 @@ config CMD_FIRMWARELOAD
Provides the "firmwareload" command which deals with devices which need
firmware to work. It is also used to upload firmware to FPGA devices.
+config CMD_KALLSYMS
+ depends on KALLSYMS
+ bool
+ prompt "kallsyms"
+ help
+ query kallsyms table
+
+ Usage: kallsyns [SYMBOL | ADDRESS]
+
config CMD_KEYSTORE
depends on CRYPTO_KEYSTORE
bool
diff --git a/commands/Makefile b/commands/Makefile
index 4924755500e3..c8cb21a7db88 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -106,6 +106,7 @@ obj-$(CONFIG_CMD_READLINK) += readlink.o
obj-$(CONFIG_CMD_LET) += let.o
obj-$(CONFIG_CMD_LN) += ln.o
obj-$(CONFIG_CMD_CLK) += clk.o
+obj-$(CONFIG_CMD_KALLSYMS) += kallsyms.o
obj-$(CONFIG_CMD_KEYSTORE) += keystore.o
obj-$(CONFIG_CMD_TFTP) += tftp.o
obj-$(CONFIG_CMD_FILETYPE) += filetype.o
diff --git a/commands/kallsyms.c b/commands/kallsyms.c
new file mode 100644
index 000000000000..163cd99c1079
--- /dev/null
+++ b/commands/kallsyms.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/*
+ * kallsyms.c - translate address to symbols
+ */
+
+#include <common.h>
+#include <kallsyms.h>
+#include <command.h>
+#include <malloc.h>
+#include <complete.h>
+#include <getopt.h>
+#include <string.h>
+
+static int do_kallsyms(int argc, char *argv[])
+{
+ unsigned long addr;
+
+ if (argc != 2)
+ return COMMAND_ERROR_USAGE;
+
+ if (kstrtoul(argv[1], 16, &addr) == 0) {
+ char sym[KSYM_SYMBOL_LEN];
+
+ sprint_symbol(sym, addr);
+
+ printf("%s\n", sym);
+ return 0;
+ }
+
+ if ((addr = kallsyms_lookup_name(argv[1]))) {
+ printf("0x%08lx\n", addr);
+ return 0;
+ }
+
+ return COMMAND_ERROR;
+}
+
+BAREBOX_CMD_HELP_START(kallsyms)
+BAREBOX_CMD_HELP_TEXT("Lookup address or symbol using kallsyms table")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(kallsyms)
+ .cmd = do_kallsyms,
+ BAREBOX_CMD_DESC("query kallsyms table")
+ BAREBOX_CMD_OPTS("[SYMBOL | ADDRESS]")
+ BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+ BAREBOX_CMD_COMPLETE(empty_complete)
+ BAREBOX_CMD_HELP(cmd_kallsyms_help)
+BAREBOX_CMD_END
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 017/112] block: define BLOCKSIZE globally in block.h
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (15 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 016/112] commands: kallsyms: add command-line interface Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 018/112] cdev: implement setter/getter for cdev device node Ahmad Fatoum
` (94 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
For use by EFI loader code that needs to report block size, export the
BLOCKSIZE macro.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/block.c | 2 --
include/block.h | 2 ++
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/common/block.c b/common/block.c
index 3a4a9fb73149..79d277e35ae1 100644
--- a/common/block.c
+++ b/common/block.c
@@ -13,8 +13,6 @@
#include <dma.h>
#include <file-list.h>
-#define BLOCKSIZE(blk) (1 << blk->blockbits)
-
LIST_HEAD(block_device_list);
/* a chunk of contiguous data */
diff --git a/include/block.h b/include/block.h
index 44037bd74c61..2419a96c2365 100644
--- a/include/block.h
+++ b/include/block.h
@@ -35,6 +35,8 @@ struct block_device {
struct cdev cdev;
};
+#define BLOCKSIZE(blk) (1u << (blk)->blockbits)
+
extern struct list_head block_device_list;
#define for_each_block_device(bdev) list_for_each_entry(bdev, &block_device_list, list)
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 018/112] cdev: implement setter/getter for cdev device node
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (16 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 017/112] block: define BLOCKSIZE globally in block.h Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 019/112] block: virtio: assign virtio-mmio device tree node to cdevs Ahmad Fatoum
` (93 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
A cdev has two device tree node pointers, one directly at struct
cdev.device_node and another indirectly via cdev.dev->device_node.
We may want to remove cdev::device_node in future, but till then to
avoid users having to guess, which device_node is the correct one, add a
helper to set and get the device tree node.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/sandbox/board/hostfile.c | 2 +-
drivers/mci/mci-core.c | 2 +-
drivers/nvmem/core.c | 2 +-
drivers/of/of_path.c | 4 ++--
drivers/of/partition.c | 12 ++++++------
fs/devfs-core.c | 2 +-
fs/fs.c | 2 +-
include/driver.h | 11 +++++++++++
8 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/arch/sandbox/board/hostfile.c b/arch/sandbox/board/hostfile.c
index 225617fe910f..88d4d6605fd1 100644
--- a/arch/sandbox/board/hostfile.c
+++ b/arch/sandbox/board/hostfile.c
@@ -153,7 +153,7 @@ static int hf_probe(struct device *dev)
cdev = is_blockdev ? &priv->blk.cdev : &priv->cdev;
- cdev->device_node = np;
+ cdev_set_of_node(cdev, np);
if (is_blockdev) {
cdev->name = np->name;
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 2b39985d5e72..663d366666b0 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -557,7 +557,7 @@ static void mci_part_add(struct mci *mci, uint64_t size,
part->idx = idx;
if (area_type == MMC_BLK_DATA_AREA_MAIN) {
- part->blk.cdev.device_node = mci->host->hw_dev->of_node;
+ cdev_set_of_node(&part->blk.cdev, mci->host->hw_dev->of_node);
part->blk.cdev.flags |= DEVFS_IS_MCI_MAIN_PART_DEV;
}
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 67bb1d799376..e7341b62f6e6 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -213,7 +213,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
nvmem->dev.parent = config->dev;
nvmem->reg_read = config->reg_read;
nvmem->reg_write = config->reg_write;
- np = config->cdev ? config->cdev->device_node : config->dev->of_node;
+ np = config->cdev ? cdev_of_node(config->cdev) : config->dev->of_node;
nvmem->dev.of_node = np;
nvmem->priv = config->priv;
nvmem->cell_post_process = config->cell_post_process;
diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c
index 12a2dfce553e..42efb1ad1dbf 100644
--- a/drivers/of/of_path.c
+++ b/drivers/of/of_path.c
@@ -181,9 +181,9 @@ struct device_node *of_find_node_by_devpath(struct device_node *root, const char
part_size = cdev->size;
pr_debug("%s path %s: is a partition with offset 0x%08llx, size 0x%08llx\n",
__func__, path, part_offset, part_size);
- np = cdev->master->device_node;
+ np = cdev_of_node(cdev->master);
} else {
- np = cdev->device_node;
+ np = cdev_of_node(cdev);
}
/*
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index b91fe616d990..395ebbc45ac8 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -95,7 +95,7 @@ int of_parse_partitions(struct cdev *cdev, struct device_node *node)
if (!node)
return -EINVAL;
- cdev->device_node = node;
+ cdev_set_of_node(cdev, node);
subnode = of_get_child_by_name(node, "partitions");
if (subnode) {
@@ -276,21 +276,21 @@ int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
static int of_partition_fixup(struct device_node *root, void *ctx)
{
struct cdev *cdev = ctx;
- struct device_node *np;
+ struct device_node *cdev_np, *np;
char *name;
- if (!cdev->device_node)
+ cdev_np = cdev_of_node(cdev);
+ if (!cdev_np)
return -EINVAL;
if (list_empty(&cdev->partitions))
return 0;
- name = of_get_reproducible_name(cdev->device_node);
+ name = of_get_reproducible_name(cdev_np);
np = of_find_node_by_reproducible_name(root, name);
free(name);
if (!np) {
- dev_err(cdev->dev, "Cannot find nodepath %pOF, cannot fixup\n",
- cdev->device_node);
+ dev_err(cdev->dev, "Cannot find nodepath %pOF, cannot fixup\n", cdev_np);
return -EINVAL;
}
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 9f5b41761f52..c5c62028a03f 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -91,7 +91,7 @@ struct cdev *cdev_by_device_node(struct device_node *node)
return NULL;
for_each_cdev(cdev) {
- if (cdev->device_node == node)
+ if (cdev_of_node(cdev) == node)
return cdev_readlink(cdev);
}
return NULL;
diff --git a/fs/fs.c b/fs/fs.c
index 4b64f6fcf1df..1e357872f6ae 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -3038,7 +3038,7 @@ static char *get_linux_mmcblkdev(const struct cdev *root_cdev)
if (!cdevm || !cdev_is_mci_main_part_dev(cdevm))
return NULL;
- id = of_alias_get_id(cdevm->device_node, "mmc");
+ id = of_alias_get_id(cdev_of_node(cdevm), "mmc");
if (id < 0)
return NULL;
diff --git a/include/driver.h b/include/driver.h
index f4f26151e365..c6da5a3d0d54 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -556,6 +556,17 @@ struct cdev {
};
};
+static inline struct device_node *cdev_of_node(const struct cdev *cdev)
+{
+ return IS_ENABLED(CONFIG_OFDEVICE) ? cdev->device_node : NULL;
+}
+
+static inline void cdev_set_of_node(struct cdev *cdev, struct device_node *np)
+{
+ if (IS_ENABLED(CONFIG_OFDEVICE))
+ cdev->device_node = np;
+}
+
int devfs_create(struct cdev *);
int devfs_create_link(struct cdev *, const char *name);
int devfs_remove(struct cdev *);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 019/112] block: virtio: assign virtio-mmio device tree node to cdevs
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (17 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 018/112] cdev: implement setter/getter for cdev device node Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 020/112] commands: stat: print DT node for cdevs if available Ahmad Fatoum
` (92 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
All block devices except for virtio-mmio have a pointer to the hardware
device tree node if available, so add it to virtio-mmio as well.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/block/virtio_blk.c | 1 +
drivers/virtio/virtio.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 11e52d9e6457..625daf6879c0 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -99,6 +99,7 @@ static int virtio_blk_probe(struct virtio_device *vdev)
devnum = cdev_find_free_index("virtioblk");
priv->blk.cdev.name = xasprintf("virtioblk%d", devnum);
+ cdev_set_of_node(&priv->blk.cdev, vdev->dev.device_node);
priv->blk.dev = &vdev->dev;
priv->blk.blockbits = SECTOR_SHIFT;
virtio_cread(vdev, struct virtio_blk_config, capacity, &cap);
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index aeca04aa9237..c4854e7d11aa 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -289,6 +289,7 @@ int register_virtio_device(struct virtio_device *dev)
dev->dev.bus = &virtio_bus;
dev->dev.id = DEVICE_ID_DYNAMIC;
dev->dev.name = "virtio";
+ dev->dev.device_node = dev_of_node(dev->dev.parent);
spin_lock_init(&dev->config_lock);
dev->config_enabled = false;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 020/112] commands: stat: print DT node for cdevs if available
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (18 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 019/112] block: virtio: assign virtio-mmio device tree node to cdevs Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 021/112] partitions: have parsers record bootable bits Ahmad Fatoum
` (91 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
It may not be directly apparent, what device a cdev spawned from.
Have stat report this information for debugging purposes.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/fs.c b/fs/fs.c
index 1e357872f6ae..a7097dd3946e 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -69,6 +69,7 @@ EXPORT_SYMBOL(mkmodestr);
void cdev_print(const struct cdev *cdev)
{
+ struct device_node *np;
int nbytes;
if (cdev->dev || cdev->master || cdev->partname) {
@@ -118,6 +119,10 @@ void cdev_print(const struct cdev *cdev)
if (nbytes)
printf("\n");
+
+ np = cdev_of_node(cdev);
+ if (np)
+ printf("DT node: %pOF\n", np);
}
EXPORT_SYMBOL(cdev_print);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 021/112] partitions: have parsers record bootable bits
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (19 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 020/112] commands: stat: print DT node for cdevs if available Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 022/112] commands: stat: display bootable partition table bit info Ahmad Fatoum
` (90 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
barebox as EFI loader can use the information about which partitions are
bootable to guide its decision. Record this information.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/partitions.c | 4 ++--
common/partitions/dos.c | 10 ++++++++++
common/partitions/efi.c | 18 ++++++++++++++++++
common/partitions/parser.h | 3 +++
include/driver.h | 5 +++++
include/efi/partition.h | 6 ++++--
6 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/common/partitions.c b/common/partitions.c
index 8a245a1eee3d..53001a64770f 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -52,8 +52,8 @@ static int register_one_partition(struct block_device *blk,
goto out;
}
- cdev->flags |= DEVFS_PARTITION_FROM_TABLE;
-
+ cdev->flags |= DEVFS_PARTITION_FROM_TABLE | part->flags;
+ cdev->typeflags |= part->typeflags;
cdev->typeuuid = part->typeuuid;
strcpy(cdev->partuuid, part->partuuid);
diff --git a/common/partitions/dos.c b/common/partitions/dos.c
index 7472824b00b9..bf37b2852b9e 100644
--- a/common/partitions/dos.c
+++ b/common/partitions/dos.c
@@ -163,6 +163,15 @@ static void dos_extended_partition(struct block_device *blk, struct partition_de
return;
}
+static void extract_flags(const struct partition_entry *p,
+ struct partition *pentry)
+{
+ if (p->boot_indicator == 0x80)
+ pentry->flags |= DEVFS_PARTITION_BOOTABLE_LEGACY;
+ if (p->type == 0xef)
+ pentry->flags |= DEVFS_PARTITION_BOOTABLE_ESP;
+}
+
/**
* Check if a DOS like partition describes this block device
* @param blk Block device to register to
@@ -199,6 +208,7 @@ static void dos_partition(void *buf, struct block_device *blk,
pd->parts[n].first_sec = pentry.first_sec;
pd->parts[n].size = pentry.size;
pd->parts[n].dos_partition_type = pentry.dos_partition_type;
+ extract_flags(&table[i], &pd->parts[n]);
if (signature)
sprintf(pd->parts[n].partuuid, "%08x-%02d",
signature, i + 1);
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 0add66e6e4a6..6260702577f9 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -431,6 +431,23 @@ static void part_set_efi_name(gpt_entry *pte, char *dest)
dest[i] = 0;
}
+static void extract_flags(const gpt_entry *p, struct partition *pentry)
+{
+ static const guid_t system_guid = PARTITION_SYSTEM_GUID;
+
+ if (p->attributes.required_to_function)
+ pentry->flags |= DEVFS_PARTITION_REQUIRED;
+ if (p->attributes.no_block_io_protocol)
+ pentry->flags |= DEVFS_PARTITION_NO_EXPORT;
+ if (p->attributes.legacy_bios_bootable)
+ pentry->flags |= DEVFS_PARTITION_BOOTABLE_LEGACY;
+
+ if (guid_equal(&p->partition_type_guid, &system_guid))
+ pentry->flags |= DEVFS_PARTITION_BOOTABLE_ESP;
+
+ pentry->typeflags = p->attributes.type_guid_specific;
+}
+
static void efi_partition(void *buf, struct block_device *blk,
struct partition_desc *pd)
{
@@ -466,6 +483,7 @@ static void efi_partition(void *buf, struct block_device *blk,
}
pentry = &pd->parts[pd->used_entries];
+ extract_flags(&ptes[i], pentry);
pentry->first_sec = le64_to_cpu(ptes[i].starting_lba);
pentry->size = le64_to_cpu(ptes[i].ending_lba) - pentry->first_sec;
pentry->size++;
diff --git a/common/partitions/parser.h b/common/partitions/parser.h
index 9cc41a7573fe..fce368156400 100644
--- a/common/partitions/parser.h
+++ b/common/partitions/parser.h
@@ -11,6 +11,7 @@
#include <filetype.h>
#include <linux/uuid.h>
#include <linux/list.h>
+#include <driver.h>
#define MAX_PARTITION 128
#define MAX_PARTITION_NAME 38
@@ -24,6 +25,8 @@ struct partition {
u8 dos_partition_type;
guid_t typeuuid;
};
+ unsigned int flags;
+ unsigned int typeflags;
};
struct partition_desc {
diff --git a/include/driver.h b/include/driver.h
index c6da5a3d0d54..b6fe8712837b 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -543,6 +543,7 @@ struct cdev {
loff_t offset;
loff_t size;
unsigned int flags;
+ u16 typeflags; /* GPT type-specific attributes */
int open;
struct mtd_info *mtd;
struct cdev *link;
@@ -615,6 +616,10 @@ extern struct list_head cdev_list;
#define DEVFS_PARTITION_FROM_TABLE (1U << 6)
#define DEVFS_IS_MBR_PARTITIONED (1U << 7)
#define DEVFS_IS_GPT_PARTITIONED (1U << 8)
+#define DEVFS_PARTITION_REQUIRED (1U << 9)
+#define DEVFS_PARTITION_NO_EXPORT (1U << 10)
+#define DEVFS_PARTITION_BOOTABLE_LEGACY (1U << 11)
+#define DEVFS_PARTITION_BOOTABLE_ESP (1U << 12)
static inline bool cdev_is_mbr_partitioned(const struct cdev *master)
{
diff --git a/include/efi/partition.h b/include/efi/partition.h
index 0ca2a72eb9b7..29175673e351 100644
--- a/include/efi/partition.h
+++ b/include/efi/partition.h
@@ -95,8 +95,10 @@ typedef struct _gpt_header {
typedef struct _gpt_entry_attributes {
u64 required_to_function:1;
- u64 reserved:47;
- u64 type_guid_specific:16;
+ u64 no_block_io_protocol:1;
+ u64 legacy_bios_bootable:1;
+ u64 reserved:45;
+ u64 type_guid_specific:16;
} __attribute__ ((packed)) gpt_entry_attributes;
#define GPT_PARTNAME_MAX_SIZE (72 / sizeof (wchar_t))
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 022/112] commands: stat: display bootable partition table bit info
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (20 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 021/112] partitions: have parsers record bootable bits Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 023/112] block: record block device type Ahmad Fatoum
` (89 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
There's no common code yet, but board code may iterate over cdevs to
handle the boot partition specially. Make writing such code easier
by adding the new flags to the stat command's output.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/fs.c b/fs/fs.c
index a7097dd3946e..b3eac2e55ad6 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -101,6 +101,10 @@ void cdev_print(const struct cdev *cdev)
printf(" gpt-partitioned");
if (cdev->mtd)
printf(" mtd");
+ if (cdev->flags & DEVFS_PARTITION_BOOTABLE_ESP)
+ printf(" boot-esp");
+ if (cdev->flags & DEVFS_PARTITION_BOOTABLE_LEGACY)
+ printf(" boot-legacy");
printf(" )");
}
printf("\n");
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 023/112] block: record block device type
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (21 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 022/112] commands: stat: display bootable partition table bit info Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 024/112] include: add definitions for UAPI discoverable partitions spec Ahmad Fatoum
` (88 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Software running under EFI can query the type of a block device. For
barebox to be able to report this, start assigning types to all block
devices it can create. No functional change yet.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/sandbox/board/hostfile.c | 1 +
common/block.c | 24 ++++++++++++++++++++++++
drivers/ata/ahci.c | 1 +
drivers/ata/disk_ata_drive.c | 1 +
drivers/block/efi-block-io.c | 1 +
drivers/block/virtio_blk.c | 1 +
drivers/mci/mci-core.c | 1 +
drivers/nvme/host/core.c | 1 +
drivers/usb/storage/usb.c | 1 +
include/ata_drive.h | 5 +++--
include/block.h | 16 +++++++++++++++-
11 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/arch/sandbox/board/hostfile.c b/arch/sandbox/board/hostfile.c
index 88d4d6605fd1..7afad95b6d8b 100644
--- a/arch/sandbox/board/hostfile.c
+++ b/arch/sandbox/board/hostfile.c
@@ -161,6 +161,7 @@ static int hf_probe(struct device *dev)
priv->blk.ops = &hf_blk_ops;
priv->blk.blockbits = SECTOR_SHIFT;
priv->blk.num_blocks = reg[1] / SECTOR_SIZE;
+ priv->blk.type = BLK_TYPE_VIRTUAL;
err = blockdevice_register(&priv->blk);
if (err)
diff --git a/common/block.c b/common/block.c
index 79d277e35ae1..b4263906f455 100644
--- a/common/block.c
+++ b/common/block.c
@@ -472,3 +472,27 @@ unsigned file_list_add_blockdevs(struct file_list *files)
return count;
}
+
+const char *blk_type_str(enum blk_type type)
+{
+ switch (type) {
+ case BLK_TYPE_UNSPEC:
+ return "unspecified";
+ case BLK_TYPE_SD:
+ return "SD";
+ case BLK_TYPE_MMC:
+ return "MMC";
+ case BLK_TYPE_VIRTUAL:
+ return "virtual";
+ case BLK_TYPE_IDE:
+ return "IDE";
+ case BLK_TYPE_AHCI:
+ return "AHCI";
+ case BLK_TYPE_USB:
+ return "USB";
+ case BLK_TYPE_NVME:
+ return "NVMe";
+ default:
+ return "unknown";
+ }
+}
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index d4d1005f6165..de6748288141 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -624,6 +624,7 @@ int ahci_add_host(struct ahci_device *ahci)
ahci_port->ata.dev = ahci->dev;
ahci_port->port_mmio = ahci_port_base(ahci->mmio_base, i);
ahci_port->ata.ops = &ahci_ops;
+ ahci_port->ata.ahci = true;
ata_port_register(&ahci_port->ata);
}
diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c
index 2d97710b827a..56815346c181 100644
--- a/drivers/ata/disk_ata_drive.c
+++ b/drivers/ata/disk_ata_drive.c
@@ -245,6 +245,7 @@ static int ata_port_init(struct ata_port *port)
port->blk.num_blocks = ata_id_n_sectors(port->id);
port->blk.blockbits = SECTOR_SHIFT;
+ priv->blk.type = port->ahci ? BLK_TYPE_AHCI : BLK_TYPE_IDE;
rc = blockdevice_register(&port->blk);
if (rc != 0) {
diff --git a/drivers/block/efi-block-io.c b/drivers/block/efi-block-io.c
index 79a62d53d30a..810b6da32d55 100644
--- a/drivers/block/efi-block-io.c
+++ b/drivers/block/efi-block-io.c
@@ -179,6 +179,7 @@ static int efi_bio_probe(struct efi_device *efidev)
priv->blk.num_blocks = media->last_block + 1;
priv->blk.ops = &efi_bio_ops;
priv->blk.dev = &efidev->dev;
+ priv->blk.type = BLK_TYPE_VIRTUAL;
priv->media_id = media->media_id;
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 625daf6879c0..cbef500d59b3 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -105,6 +105,7 @@ static int virtio_blk_probe(struct virtio_device *vdev)
virtio_cread(vdev, struct virtio_blk_config, capacity, &cap);
priv->blk.num_blocks = cap;
priv->blk.ops = &virtio_blk_ops;
+ priv->blk.type = BLK_TYPE_VIRTUAL;
return blockdevice_register(&priv->blk);
}
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 663d366666b0..bd9083b9f77c 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1901,6 +1901,7 @@ static int mci_register_partition(struct mci_part *part)
*/
part->blk.dev = &mci->dev;
part->blk.ops = &mci_ops;
+ part->blk.type = IS_SD(mci) ? BLK_TYPE_SD : BLK_TYPE_MMC;
rc = blockdevice_register(&part->blk);
if (rc != 0) {
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 79a5f9325ef8..33a592caeb14 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -361,6 +361,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
ns->blk.dev = ctrl->dev;
ns->blk.ops = &nvme_block_device_ops;
+ ns->blk.type = BLK_TYPE_NVME;
ns->blk.cdev.name = strdup(disk_name);
__nvme_revalidate_disk(&ns->blk, id);
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index f281e0186d68..cc241e69be1b 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -421,6 +421,7 @@ static int usb_stor_add_blkdev(struct us_data *us, unsigned char lun)
pblk_dev->blk.cdev.name = basprintf("disk%d", result);
pblk_dev->blk.blockbits = SECTOR_SHIFT;
+ pblk_dev->blk.type = BLK_TYPE_USB;
result = blockdevice_register(&pblk_dev->blk);
if (result != 0) {
diff --git a/include/ata_drive.h b/include/ata_drive.h
index 47b74826866c..e840d89f4ae8 100644
--- a/include/ata_drive.h
+++ b/include/ata_drive.h
@@ -134,8 +134,9 @@ struct ata_port {
void *drvdata;
struct block_device blk;
uint16_t *id;
- int lba48;
- int initialized;
+ bool lba48;
+ bool initialized;
+ bool ahci;
int probe;
};
diff --git a/include/block.h b/include/block.h
index 2419a96c2365..f215eb8bf0c1 100644
--- a/include/block.h
+++ b/include/block.h
@@ -17,11 +17,25 @@ struct block_device_ops {
struct chunk;
+enum blk_type {
+ BLK_TYPE_UNSPEC = 0,
+ BLK_TYPE_USB,
+ BLK_TYPE_SD,
+ BLK_TYPE_AHCI,
+ BLK_TYPE_IDE,
+ BLK_TYPE_NVME,
+ BLK_TYPE_VIRTUAL,
+ BLK_TYPE_MMC,
+};
+
+const char *blk_type_str(enum blk_type);
+
struct block_device {
struct device *dev;
struct list_head list;
struct block_device_ops *ops;
- int blockbits;
+ u8 blockbits;
+ u8 type; /* holds enum blk_type */
blkcnt_t num_blocks;
int rdbufsize;
int blkmask;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 024/112] include: add definitions for UAPI discoverable partitions spec
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (22 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 023/112] block: record block device type Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 025/112] efi: payload: restrict 8250 UART at I/O port 0x3f8 registration to x86 Ahmad Fatoum
` (87 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Now that we remember the Type GUID of block devices, let's import the
UUIDs assigned by the UAPI group discoverable partition specification
as found in systemd v255's src/systemd/sd-gpt.h.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/uapi/spec/dps.h | 370 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 370 insertions(+)
create mode 100644 include/uapi/spec/dps.h
diff --git a/include/uapi/spec/dps.h b/include/uapi/spec/dps.h
new file mode 100644
index 000000000000..7597166467bf
--- /dev/null
+++ b/include/uapi/spec/dps.h
@@ -0,0 +1,370 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * This file holds GUIDs defined in The Discoverable Partitions Specification (DPS).
+ *
+ * systemd is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * systemd is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with systemd; If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef __DPS_H_
+#define __DPS_H_
+
+#include <linux/uuid.h>
+
+#define SD_ID128_ARRAY(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) \
+ { .b = { 0x##v0, 0x##v1, 0x##v2, 0x##v3, 0x##v4, 0x##v5, 0x##v6, 0x##v7, \
+ 0x##v8, 0x##v9, 0x##v10, 0x##v11, 0x##v12, 0x##v13, 0x##v14, 0x##v15 }}
+
+#define SD_ID128_MAKE(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) \
+ ((const guid_t) SD_ID128_ARRAY(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15))
+
+#define SD_ID128_MAKE_UUID_STR(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
+ #a #b #c #d "-" #e #f "-" #g #h "-" #i #j "-" #k #l #m #n #o #p
+
+#define SD_GPT_ROOT_ALPHA SD_ID128_MAKE(65,23,f8,ae,3e,b1,4e,2a,a0,5a,18,b6,95,ae,65,6f)
+#define SD_GPT_ROOT_ARC SD_ID128_MAKE(d2,7f,46,ed,29,19,4c,b8,bd,25,95,31,f3,c1,65,34)
+#define SD_GPT_ROOT_ARM SD_ID128_MAKE(69,da,d7,10,2c,e4,4e,3c,b1,6c,21,a1,d4,9a,be,d3)
+#define SD_GPT_ROOT_ARM64 SD_ID128_MAKE(b9,21,b0,45,1d,f0,41,c3,af,44,4c,6f,28,0d,3f,ae)
+#define SD_GPT_ROOT_IA64 SD_ID128_MAKE(99,3d,8d,3d,f8,0e,42,25,85,5a,9d,af,8e,d7,ea,97)
+#define SD_GPT_ROOT_LOONGARCH64 SD_ID128_MAKE(77,05,58,00,79,2c,4f,94,b3,9a,98,c9,1b,76,2b,b6)
+#define SD_GPT_ROOT_MIPS SD_ID128_MAKE(e9,43,45,44,6e,2c,47,cc,ba,e2,12,d6,de,af,b4,4c)
+#define SD_GPT_ROOT_MIPS64 SD_ID128_MAKE(d1,13,af,76,80,ef,41,b4,bd,b6,0c,ff,4d,3d,4a,25)
+#define SD_GPT_ROOT_MIPS_LE SD_ID128_MAKE(37,c5,8c,8a,d9,13,41,56,a2,5f,48,b1,b6,4e,07,f0)
+#define SD_GPT_ROOT_MIPS64_LE SD_ID128_MAKE(70,0b,da,43,7a,34,45,07,b1,79,ee,b9,3d,7a,7c,a3)
+#define SD_GPT_ROOT_PARISC SD_ID128_MAKE(1a,ac,db,3b,54,44,41,38,bd,9e,e5,c2,23,9b,23,46)
+#define SD_GPT_ROOT_PPC SD_ID128_MAKE(1d,e3,f1,ef,fa,98,47,b5,8d,cd,4a,86,0a,65,4d,78)
+#define SD_GPT_ROOT_PPC64 SD_ID128_MAKE(91,2a,de,1d,a8,39,49,13,89,64,a1,0e,ee,08,fb,d2)
+#define SD_GPT_ROOT_PPC64_LE SD_ID128_MAKE(c3,1c,45,e6,3f,39,41,2e,80,fb,48,09,c4,98,05,99)
+#define SD_GPT_ROOT_RISCV32 SD_ID128_MAKE(60,d5,a7,fe,8e,7d,43,5c,b7,14,3d,d8,16,21,44,e1)
+#define SD_GPT_ROOT_RISCV64 SD_ID128_MAKE(72,ec,70,a6,cf,74,40,e6,bd,49,4b,da,08,e8,f2,24)
+#define SD_GPT_ROOT_S390 SD_ID128_MAKE(08,a7,ac,ea,62,4c,4a,20,91,e8,6e,0f,a6,7d,23,f9)
+#define SD_GPT_ROOT_S390X SD_ID128_MAKE(5e,ea,d9,a9,fe,09,4a,1e,a1,d7,52,0d,00,53,13,06)
+#define SD_GPT_ROOT_TILEGX SD_ID128_MAKE(c5,0c,dd,70,38,62,4c,c3,90,e1,80,9a,8c,93,ee,2c)
+#define SD_GPT_ROOT_X86 SD_ID128_MAKE(44,47,95,40,f2,97,41,b2,9a,f7,d1,31,d5,f0,45,8a)
+#define SD_GPT_ROOT_X86_64 SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
+#define SD_GPT_USR_ALPHA SD_ID128_MAKE(e1,8c,f0,8c,33,ec,4c,0d,82,46,c6,c6,fb,3d,a0,24)
+#define SD_GPT_USR_ARC SD_ID128_MAKE(79,78,a6,83,63,16,49,22,bb,ee,38,bf,f5,a2,fe,cc)
+#define SD_GPT_USR_ARM SD_ID128_MAKE(7d,03,59,a3,02,b3,4f,0a,86,5c,65,44,03,e7,06,25)
+#define SD_GPT_USR_ARM64 SD_ID128_MAKE(b0,e0,10,50,ee,5f,43,90,94,9a,91,01,b1,71,04,e9)
+#define SD_GPT_USR_IA64 SD_ID128_MAKE(43,01,d2,a6,4e,3b,4b,2a,bb,94,9e,0b,2c,42,25,ea)
+#define SD_GPT_USR_LOONGARCH64 SD_ID128_MAKE(e6,11,c7,02,57,5c,4c,be,9a,46,43,4f,a0,bf,7e,3f)
+#define SD_GPT_USR_MIPS SD_ID128_MAKE(77,3b,2a,bc,2a,99,43,98,8b,f5,03,ba,ac,40,d0,2b)
+#define SD_GPT_USR_MIPS64 SD_ID128_MAKE(57,e1,39,58,73,31,43,65,8e,6e,35,ee,ee,17,c6,1b)
+#define SD_GPT_USR_MIPS_LE SD_ID128_MAKE(0f,48,68,e9,99,52,47,06,97,9f,3e,d3,a4,73,e9,47)
+#define SD_GPT_USR_MIPS64_LE SD_ID128_MAKE(c9,7c,1f,32,ba,06,40,b4,9f,22,23,60,61,b0,8a,a8)
+#define SD_GPT_USR_PARISC SD_ID128_MAKE(dc,4a,44,80,69,17,42,62,a4,ec,db,93,84,94,9f,25)
+#define SD_GPT_USR_PPC SD_ID128_MAKE(7d,14,fe,c5,cc,71,41,5d,9d,6c,06,bf,0b,3c,3e,af)
+#define SD_GPT_USR_PPC64 SD_ID128_MAKE(2c,97,39,e2,f0,68,46,b3,9f,d0,01,c5,a9,af,bc,ca)
+#define SD_GPT_USR_PPC64_LE SD_ID128_MAKE(15,bb,03,af,77,e7,4d,4a,b1,2b,c0,d0,84,f7,49,1c)
+#define SD_GPT_USR_RISCV32 SD_ID128_MAKE(b9,33,fb,22,5c,3f,4f,91,af,90,e2,bb,0f,a5,07,02)
+#define SD_GPT_USR_RISCV64 SD_ID128_MAKE(be,ae,c3,4b,84,42,43,9b,a4,0b,98,43,81,ed,09,7d)
+#define SD_GPT_USR_S390 SD_ID128_MAKE(cd,0f,86,9b,d0,fb,4c,a0,b1,41,9e,a8,7c,c7,8d,66)
+#define SD_GPT_USR_S390X SD_ID128_MAKE(8a,4f,57,70,50,aa,4e,d3,87,4a,99,b7,10,db,6f,ea)
+#define SD_GPT_USR_TILEGX SD_ID128_MAKE(55,49,70,29,c7,c1,44,cc,aa,39,81,5e,d1,55,86,30)
+#define SD_GPT_USR_X86 SD_ID128_MAKE(75,25,0d,76,8c,c6,45,8e,bd,66,bd,47,cc,81,a8,12)
+#define SD_GPT_USR_X86_64 SD_ID128_MAKE(84,84,68,0c,95,21,48,c6,9c,11,b0,72,06,56,f6,9e)
+
+/* Verity partitions for the root partitions above (we only define them for the root and /usr partitions,
+ * because only they are commonly read-only and hence suitable for verity). */
+#define SD_GPT_ROOT_ALPHA_VERITY SD_ID128_MAKE(fc,56,d9,e9,e6,e5,4c,06,be,32,e7,44,07,ce,09,a5)
+#define SD_GPT_ROOT_ARC_VERITY SD_ID128_MAKE(24,b2,d9,75,0f,97,45,21,af,a1,cd,53,1e,42,1b,8d)
+#define SD_GPT_ROOT_ARM_VERITY SD_ID128_MAKE(73,86,cd,f2,20,3c,47,a9,a4,98,f2,ec,ce,45,a2,d6)
+#define SD_GPT_ROOT_ARM64_VERITY SD_ID128_MAKE(df,33,00,ce,d6,9f,4c,92,97,8c,9b,fb,0f,38,d8,20)
+#define SD_GPT_ROOT_IA64_VERITY SD_ID128_MAKE(86,ed,10,d5,b6,07,45,bb,89,57,d3,50,f2,3d,05,71)
+#define SD_GPT_ROOT_LOONGARCH64_VERITY SD_ID128_MAKE(f3,39,3b,22,e9,af,46,13,a9,48,9d,3b,fb,d0,c5,35)
+#define SD_GPT_ROOT_MIPS_VERITY SD_ID128_MAKE(7a,43,07,99,f7,11,4c,7e,8e,5b,1d,68,5b,d4,86,07)
+#define SD_GPT_ROOT_MIPS64_VERITY SD_ID128_MAKE(57,95,36,f8,6a,33,40,55,a9,5a,df,2d,5e,2c,42,a8)
+#define SD_GPT_ROOT_MIPS_LE_VERITY SD_ID128_MAKE(d7,d1,50,d2,2a,04,4a,33,8f,12,16,65,12,05,ff,7b)
+#define SD_GPT_ROOT_MIPS64_LE_VERITY SD_ID128_MAKE(16,b4,17,f8,3e,06,4f,57,8d,d2,9b,52,32,f4,1a,a6)
+#define SD_GPT_ROOT_PARISC_VERITY SD_ID128_MAKE(d2,12,a4,30,fb,c5,49,f9,a9,83,a7,fe,ef,2b,8d,0e)
+#define SD_GPT_ROOT_PPC64_LE_VERITY SD_ID128_MAKE(90,6b,d9,44,45,89,4a,ae,a4,e4,dd,98,39,17,44,6a)
+#define SD_GPT_ROOT_PPC64_VERITY SD_ID128_MAKE(92,25,a9,a3,3c,19,4d,89,b4,f6,ee,ff,88,f1,76,31)
+#define SD_GPT_ROOT_PPC_VERITY SD_ID128_MAKE(98,cf,e6,49,15,88,46,dc,b2,f0,ad,d1,47,42,49,25)
+#define SD_GPT_ROOT_RISCV32_VERITY SD_ID128_MAKE(ae,02,53,be,11,67,40,07,ac,68,43,92,6c,14,c5,de)
+#define SD_GPT_ROOT_RISCV64_VERITY SD_ID128_MAKE(b6,ed,55,82,44,0b,42,09,b8,da,5f,f7,c4,19,ea,3d)
+#define SD_GPT_ROOT_S390_VERITY SD_ID128_MAKE(7a,c6,3b,47,b2,5c,46,3b,8d,f8,b4,a9,4e,6c,90,e1)
+#define SD_GPT_ROOT_S390X_VERITY SD_ID128_MAKE(b3,25,bf,be,c7,be,4a,b8,83,57,13,9e,65,2d,2f,6b)
+#define SD_GPT_ROOT_TILEGX_VERITY SD_ID128_MAKE(96,60,61,ec,28,e4,4b,2e,b4,a5,1f,0a,82,5a,1d,84)
+#define SD_GPT_ROOT_X86_64_VERITY SD_ID128_MAKE(2c,73,57,ed,eb,d2,46,d9,ae,c1,23,d4,37,ec,2b,f5)
+#define SD_GPT_ROOT_X86_VERITY SD_ID128_MAKE(d1,3c,5d,3b,b5,d1,42,2a,b2,9f,94,54,fd,c8,9d,76)
+#define SD_GPT_USR_ALPHA_VERITY SD_ID128_MAKE(8c,ce,0d,25,c0,d0,4a,44,bd,87,46,33,1b,f1,df,67)
+#define SD_GPT_USR_ARC_VERITY SD_ID128_MAKE(fc,a0,59,8c,d8,80,45,91,8c,16,4e,da,05,c7,34,7c)
+#define SD_GPT_USR_ARM_VERITY SD_ID128_MAKE(c2,15,d7,51,7b,cd,46,49,be,90,66,27,49,0a,4c,05)
+#define SD_GPT_USR_ARM64_VERITY SD_ID128_MAKE(6e,11,a4,e7,fb,ca,4d,ed,b9,e9,e1,a5,12,bb,66,4e)
+#define SD_GPT_USR_IA64_VERITY SD_ID128_MAKE(6a,49,1e,03,3b,e7,45,45,8e,38,83,32,0e,0e,a8,80)
+#define SD_GPT_USR_LOONGARCH64_VERITY SD_ID128_MAKE(f4,6b,2c,26,59,ae,48,f0,91,06,c5,0e,d4,7f,67,3d)
+#define SD_GPT_USR_MIPS_VERITY SD_ID128_MAKE(6e,5a,1b,c8,d2,23,49,b7,bc,a8,37,a5,fc,ce,b9,96)
+#define SD_GPT_USR_MIPS64_VERITY SD_ID128_MAKE(81,cf,9d,90,74,58,4d,f4,8d,cf,c8,a3,a4,04,f0,9b)
+#define SD_GPT_USR_MIPS_LE_VERITY SD_ID128_MAKE(46,b9,8d,8d,b5,5c,4e,8f,aa,b3,37,fc,a7,f8,07,52)
+#define SD_GPT_USR_MIPS64_LE_VERITY SD_ID128_MAKE(3c,3d,61,fe,b5,f3,41,4d,bb,71,87,39,a6,94,a4,ef)
+#define SD_GPT_USR_PARISC_VERITY SD_ID128_MAKE(58,43,d6,18,ec,37,48,d7,9f,12,ce,a8,e0,87,68,b2)
+#define SD_GPT_USR_PPC64_LE_VERITY SD_ID128_MAKE(ee,2b,99,83,21,e8,41,53,86,d9,b6,90,1a,54,d1,ce)
+#define SD_GPT_USR_PPC64_VERITY SD_ID128_MAKE(bd,b5,28,a5,a2,59,47,5f,a8,7d,da,53,fa,73,6a,07)
+#define SD_GPT_USR_PPC_VERITY SD_ID128_MAKE(df,76,5d,00,27,0e,49,e5,bc,75,f4,7b,b2,11,8b,09)
+#define SD_GPT_USR_RISCV32_VERITY SD_ID128_MAKE(cb,1e,e4,e3,8c,d0,41,36,a0,a4,aa,61,a3,2e,87,30)
+#define SD_GPT_USR_RISCV64_VERITY SD_ID128_MAKE(8f,10,56,be,9b,05,47,c4,81,d6,be,53,12,8e,5b,54)
+#define SD_GPT_USR_S390_VERITY SD_ID128_MAKE(b6,63,c6,18,e7,bc,4d,6d,90,aa,11,b7,56,bb,17,97)
+#define SD_GPT_USR_S390X_VERITY SD_ID128_MAKE(31,74,1c,c4,1a,2a,41,11,a5,81,e0,0b,44,7d,2d,06)
+#define SD_GPT_USR_TILEGX_VERITY SD_ID128_MAKE(2f,b4,bf,56,07,fa,42,da,81,32,6b,13,9f,20,26,ae)
+#define SD_GPT_USR_X86_64_VERITY SD_ID128_MAKE(77,ff,5f,63,e7,b6,46,33,ac,f4,15,65,b8,64,c0,e6)
+#define SD_GPT_USR_X86_VERITY SD_ID128_MAKE(8f,46,1b,0d,14,ee,4e,81,9a,a9,04,9b,6f,b9,7a,bd)
+
+/* PKCS#7 Signatures for the Verity Root Hashes */
+#define SD_GPT_ROOT_ALPHA_VERITY_SIG SD_ID128_MAKE(d4,64,95,b7,a0,53,41,4f,80,f7,70,0c,99,92,1e,f8)
+#define SD_GPT_ROOT_ARC_VERITY_SIG SD_ID128_MAKE(14,3a,70,ba,cb,d3,4f,06,91,9f,6c,05,68,3a,78,bc)
+#define SD_GPT_ROOT_ARM_VERITY_SIG SD_ID128_MAKE(42,b0,45,5f,eb,11,49,1d,98,d3,56,14,5b,a9,d0,37)
+#define SD_GPT_ROOT_ARM64_VERITY_SIG SD_ID128_MAKE(6d,b6,9d,e6,29,f4,47,58,a7,a5,96,21,90,f0,0c,e3)
+#define SD_GPT_ROOT_IA64_VERITY_SIG SD_ID128_MAKE(e9,8b,36,ee,32,ba,48,82,9b,12,0c,e1,46,55,f4,6a)
+#define SD_GPT_ROOT_LOONGARCH64_VERITY_SIG SD_ID128_MAKE(5a,fb,67,eb,ec,c8,4f,85,ae,8e,ac,1e,7c,50,e7,d0)
+#define SD_GPT_ROOT_MIPS_VERITY_SIG SD_ID128_MAKE(bb,a2,10,a2,9c,5d,45,ee,9e,87,ff,2c,cb,d0,02,d0)
+#define SD_GPT_ROOT_MIPS64_VERITY_SIG SD_ID128_MAKE(43,ce,94,d4,0f,3d,49,99,82,50,b9,de,af,d9,8e,6e)
+#define SD_GPT_ROOT_MIPS_LE_VERITY_SIG SD_ID128_MAKE(c9,19,cc,1f,44,56,4e,ff,91,8c,f7,5e,94,52,5c,a5)
+#define SD_GPT_ROOT_MIPS64_LE_VERITY_SIG SD_ID128_MAKE(90,4e,58,ef,5c,65,4a,31,9c,57,6a,f5,fc,7c,5d,e7)
+#define SD_GPT_ROOT_PARISC_VERITY_SIG SD_ID128_MAKE(15,de,61,70,65,d3,43,1c,91,6e,b0,dc,d8,39,3f,25)
+#define SD_GPT_ROOT_PPC64_LE_VERITY_SIG SD_ID128_MAKE(d4,a2,36,e7,e8,73,4c,07,bf,1d,bf,6c,f7,f1,c3,c6)
+#define SD_GPT_ROOT_PPC64_VERITY_SIG SD_ID128_MAKE(f5,e2,c2,0c,45,b2,4f,fa,bc,e9,2a,60,73,7e,1a,af)
+#define SD_GPT_ROOT_PPC_VERITY_SIG SD_ID128_MAKE(1b,31,b5,aa,ad,d9,46,3a,b2,ed,bd,46,7f,c8,57,e7)
+#define SD_GPT_ROOT_RISCV32_VERITY_SIG SD_ID128_MAKE(3a,11,2a,75,87,29,43,80,b4,cf,76,4d,79,93,44,48)
+#define SD_GPT_ROOT_RISCV64_VERITY_SIG SD_ID128_MAKE(ef,e0,f0,87,ea,8d,44,69,82,1a,4c,2a,96,a8,38,6a)
+#define SD_GPT_ROOT_S390_VERITY_SIG SD_ID128_MAKE(34,82,38,8e,42,54,43,5a,a2,41,76,6a,06,5f,99,60)
+#define SD_GPT_ROOT_S390X_VERITY_SIG SD_ID128_MAKE(c8,01,87,a5,73,a3,49,1a,90,1a,01,7c,3f,a9,53,e9)
+#define SD_GPT_ROOT_TILEGX_VERITY_SIG SD_ID128_MAKE(b3,67,14,39,97,b0,4a,53,90,f7,2d,5a,8f,3a,d4,7b)
+#define SD_GPT_ROOT_X86_64_VERITY_SIG SD_ID128_MAKE(41,09,2b,05,9f,c8,45,23,99,4f,2d,ef,04,08,b1,76)
+#define SD_GPT_ROOT_X86_VERITY_SIG SD_ID128_MAKE(59,96,fc,05,10,9c,48,de,80,8b,23,fa,08,30,b6,76)
+#define SD_GPT_USR_ALPHA_VERITY_SIG SD_ID128_MAKE(5c,6e,1c,76,07,6a,45,7a,a0,fe,f3,b4,cd,21,ce,6e)
+#define SD_GPT_USR_ARC_VERITY_SIG SD_ID128_MAKE(94,f9,a9,a1,99,71,42,7a,a4,00,50,cb,29,7f,0f,35)
+#define SD_GPT_USR_ARM_VERITY_SIG SD_ID128_MAKE(d7,ff,81,2f,37,d1,49,02,a8,10,d7,6b,a5,7b,97,5a)
+#define SD_GPT_USR_ARM64_VERITY_SIG SD_ID128_MAKE(c2,3c,e4,ff,44,bd,4b,00,b2,d4,b4,1b,34,19,e0,2a)
+#define SD_GPT_USR_IA64_VERITY_SIG SD_ID128_MAKE(8d,e5,8b,c2,2a,43,46,0d,b1,4e,a7,6e,4a,17,b4,7f)
+#define SD_GPT_USR_LOONGARCH64_VERITY_SIG SD_ID128_MAKE(b0,24,f3,15,d3,30,44,4c,84,61,44,bb,de,52,4e,99)
+#define SD_GPT_USR_MIPS_VERITY_SIG SD_ID128_MAKE(97,ae,15,8d,f2,16,49,7b,80,57,f7,f9,05,77,0f,54)
+#define SD_GPT_USR_MIPS64_VERITY_SIG SD_ID128_MAKE(05,81,6c,e2,dd,40,4a,c6,a6,1d,37,d3,2d,c1,ba,7d)
+#define SD_GPT_USR_MIPS_LE_VERITY_SIG SD_ID128_MAKE(3e,23,ca,0b,a4,bc,4b,4e,80,87,5a,b6,a2,6a,a8,a9)
+#define SD_GPT_USR_MIPS64_LE_VERITY_SIG SD_ID128_MAKE(f2,c2,c7,ee,ad,cc,43,51,b5,c6,ee,98,16,b6,6e,16)
+#define SD_GPT_USR_PARISC_VERITY_SIG SD_ID128_MAKE(45,0d,d7,d1,32,24,45,ec,9c,f2,a4,3a,34,6d,71,ee)
+#define SD_GPT_USR_PPC64_LE_VERITY_SIG SD_ID128_MAKE(c8,bf,bd,1e,26,8e,45,21,8b,ba,bf,31,4c,39,95,57)
+#define SD_GPT_USR_PPC64_VERITY_SIG SD_ID128_MAKE(0b,88,88,63,d7,f8,4d,9e,97,66,23,9f,ce,4d,58,af)
+#define SD_GPT_USR_PPC_VERITY_SIG SD_ID128_MAKE(70,07,89,1d,d3,71,4a,80,86,a4,5c,b8,75,b9,30,2e)
+#define SD_GPT_USR_RISCV32_VERITY_SIG SD_ID128_MAKE(c3,83,6a,13,31,37,45,ba,b5,83,b1,6c,50,fe,5e,b4)
+#define SD_GPT_USR_RISCV64_VERITY_SIG SD_ID128_MAKE(d2,f9,00,0a,7a,18,45,3f,b5,cd,4d,32,f7,7a,7b,32)
+#define SD_GPT_USR_S390_VERITY_SIG SD_ID128_MAKE(17,44,0e,4f,a8,d0,46,7f,a4,6e,39,12,ae,6e,f2,c5)
+#define SD_GPT_USR_S390X_VERITY_SIG SD_ID128_MAKE(3f,32,48,16,66,7b,46,ae,86,ee,9b,0c,0c,6c,11,b4)
+#define SD_GPT_USR_TILEGX_VERITY_SIG SD_ID128_MAKE(4e,de,75,e2,6c,cc,4c,c8,b9,c7,70,33,4b,08,75,10)
+#define SD_GPT_USR_X86_64_VERITY_SIG SD_ID128_MAKE(e7,bb,33,fb,06,cf,4e,81,82,73,e5,43,b4,13,e2,e2)
+#define SD_GPT_USR_X86_VERITY_SIG SD_ID128_MAKE(97,4a,71,c0,de,41,43,c3,be,5d,5c,5c,cd,1a,d2,c0)
+
+#define SD_GPT_ESP SD_ID128_MAKE(c1,2a,73,28,f8,1f,11,d2,ba,4b,00,a0,c9,3e,c9,3b)
+#define SD_GPT_ESP_STR SD_ID128_MAKE_UUID_STR(c1,2a,73,28,f8,1f,11,d2,ba,4b,00,a0,c9,3e,c9,3b)
+#define SD_GPT_XBOOTLDR SD_ID128_MAKE(bc,13,c2,ff,59,e6,42,62,a3,52,b2,75,fd,6f,71,72)
+#define SD_GPT_XBOOTLDR_STR SD_ID128_MAKE_UUID_STR(bc,13,c2,ff,59,e6,42,62,a3,52,b2,75,fd,6f,71,72)
+#define SD_GPT_SWAP SD_ID128_MAKE(06,57,fd,6d,a4,ab,43,c4,84,e5,09,33,c8,4b,4f,4f)
+#define SD_GPT_SWAP_STR SD_ID128_MAKE_UUID_STR(06,57,fd,6d,a4,ab,43,c4,84,e5,09,33,c8,4b,4f,4f)
+#define SD_GPT_HOME SD_ID128_MAKE(93,3a,c7,e1,2e,b4,4f,13,b8,44,0e,14,e2,ae,f9,15)
+#define SD_GPT_HOME_STR SD_ID128_MAKE_UUID_STR(93,3a,c7,e1,2e,b4,4f,13,b8,44,0e,14,e2,ae,f9,15)
+#define SD_GPT_SRV SD_ID128_MAKE(3b,8f,84,25,20,e0,4f,3b,90,7f,1a,25,a7,6f,98,e8)
+#define SD_GPT_SRV_STR SD_ID128_MAKE_UUID_STR(3b,8f,84,25,20,e0,4f,3b,90,7f,1a,25,a7,6f,98,e8)
+#define SD_GPT_VAR SD_ID128_MAKE(4d,21,b0,16,b5,34,45,c2,a9,fb,5c,16,e0,91,fd,2d)
+#define SD_GPT_VAR_STR SD_ID128_MAKE_UUID_STR(4d,21,b0,16,b5,34,45,c2,a9,fb,5c,16,e0,91,fd,2d)
+#define SD_GPT_TMP SD_ID128_MAKE(7e,c6,f5,57,3b,c5,4a,ca,b2,93,16,ef,5d,f6,39,d1)
+#define SD_GPT_TMP_STR SD_ID128_MAKE_UUID_STR(7e,c6,f5,57,3b,c5,4a,ca,b2,93,16,ef,5d,f6,39,d1)
+#define SD_GPT_USER_HOME SD_ID128_MAKE(77,3f,91,ef,66,d4,49,b5,bd,83,d6,83,bf,40,ad,16)
+#define SD_GPT_USER_HOME_STR SD_ID128_MAKE_UUID_STR(77,3f,91,ef,66,d4,49,b5,bd,83,d6,83,bf,40,ad,16)
+#define SD_GPT_LINUX_GENERIC SD_ID128_MAKE(0f,c6,3d,af,84,83,47,72,8e,79,3d,69,d8,47,7d,e4)
+#define SD_GPT_LINUX_GENERIC_STR SD_ID128_MAKE_UUID_STR(0f,c6,3d,af,84,83,47,72,8e,79,3d,69,d8,47,7d,e4)
+
+/* Maintain same order as above */
+#if defined(__alpha__)
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_ALPHA
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_ALPHA_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_ALPHA_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_ALPHA
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_ALPHA_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_ALPHA_VERITY_SIG
+
+#elif defined(__arc__)
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_ARC
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_ARC_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_ARC_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_ARC
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_ARC_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_ARC_VERITY_SIG
+
+#elif defined(__aarch64__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_ARM64
+# define SD_GPT_ROOT_SECONDARY SD_GPT_ROOT_ARM
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_ARM64_VERITY
+# define SD_GPT_ROOT_SECONDARY_VERITY SD_GPT_ROOT_ARM_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_ARM64_VERITY_SIG
+# define SD_GPT_ROOT_SECONDARY_VERITY_SIG SD_GPT_ROOT_ARM_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_ARM64
+# define SD_GPT_USR_SECONDARY SD_GPT_USR_ARM
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_ARM64_VERITY
+# define SD_GPT_USR_SECONDARY_VERITY SD_GPT_USR_ARM_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_ARM64_VERITY_SIG
+# define SD_GPT_USR_SECONDARY_VERITY_SIG SD_GPT_USR_ARM_VERITY_SIG
+#elif defined(__arm__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_ARM
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_ARM_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_ARM_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_ARM
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_ARM_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_ARM_VERITY_SIG
+
+#elif defined(__ia64__)
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_IA64
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_IA64_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_IA64_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_IA64
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_IA64_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_IA64_VERITY_SIG
+
+#elif defined(__loongarch_lp64)
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_LOONGARCH64
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_LOONGARCH64_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_LOONGARCH64_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_LOONGARCH64
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_LOONGARCH64_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_LOONGARCH64_VERITY_SIG
+
+#elif defined(__mips__) && !defined(__mips64) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_MIPS
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_MIPS_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_MIPS_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_MIPS
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_MIPS_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_MIPS_VERITY_SIG
+#elif defined(__mips64) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_MIPS64
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_MIPS64_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_MIPS64_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_MIPS64
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_MIPS64_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_MIPS64_VERITY_SIG
+
+#elif defined(__mips__) && !defined(__mips64) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_MIPS_LE
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_MIPS_LE_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_MIPS_LE_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_MIPS_LE
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_MIPS_LE_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_MIPS_LE_VERITY_SIG
+#elif defined(__mips64) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_MIPS64_LE
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_MIPS64_LE_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_MIPS64_LE_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_MIPS64_LE
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_MIPS64_LE_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_MIPS64_LE_VERITY_SIG
+
+#elif defined(__parisc__)
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_PARISC
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_PARISC_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_PARISC_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_PARISC
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_PARISC_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_PARISC_VERITY_SIG
+
+#elif defined(__powerpc__) && defined(__PPC64__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_PPC64_LE
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_PPC64_LE_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_PPC64_LE_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_PPC64_LE
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_PPC64_LE_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_PPC64_LE_VERITY_SIG
+#elif defined(__powerpc__) && defined(__powerpc64__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_PPC64
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_PPC64_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_PPC64_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_PPC64
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_PPC64_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_PPC64_VERITY_SIG
+#elif defined(__powerpc__)
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_PPC
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_PPC_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_PPC_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_PPC
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_PPC_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_PPC_VERITY_SIG
+
+#elif defined(__riscv) && __riscv_xlen == 32
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_RISCV32
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_RISCV32_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_RISCV32_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_RISCV32
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_RISCV32_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_RISCV32_VERITY_SIG
+#elif defined(__riscv) && __riscv_xlen == 64
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_RISCV64
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_RISCV64_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_RISCV64_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_RISCV64
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_RISCV64_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_RISCV64_VERITY_SIG
+
+#elif defined(__s390__) && !defined(__s390x__)
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_S390
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_S390_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_S390_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_S390
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_S390_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_S390_VERITY_SIG
+
+#elif defined(__s390x__)
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_S390X
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_S390X_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_S390X_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_S390X
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_S390X_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_S390X_VERITY_SIG
+
+#elif defined(__tilegx__)
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_TILEGX
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_TILEGX_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_TILEGX_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_TILEGX
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_TILEGX_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_TILEGX_VERITY_SIG
+
+#elif defined(__x86_64__)
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_X86_64
+# define SD_GPT_ROOT_SECONDARY SD_GPT_ROOT_X86
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_X86_64_VERITY
+# define SD_GPT_ROOT_SECONDARY_VERITY SD_GPT_ROOT_X86_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_X86_64_VERITY_SIG
+# define SD_GPT_ROOT_SECONDARY_VERITY_SIG SD_GPT_ROOT_X86_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_X86_64
+# define SD_GPT_USR_SECONDARY SD_GPT_USR_X86
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_X86_64_VERITY
+# define SD_GPT_USR_SECONDARY_VERITY SD_GPT_USR_X86_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_X86_64_VERITY_SIG
+# define SD_GPT_USR_SECONDARY_VERITY_SIG SD_GPT_USR_X86_VERITY_SIG
+#elif defined(__i386__)
+# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_X86
+# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_X86_VERITY
+# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_X86_VERITY_SIG
+# define SD_GPT_USR_NATIVE SD_GPT_USR_X86
+# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_X86_VERITY
+# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_X86_VERITY_SIG
+#endif
+
+/* Flags we recognize on the root, usr, xbootldr, swap, home, srv, var, tmp partitions when doing
+ * auto-discovery.
+ *
+ * The first two happen to be identical to what Microsoft defines for its own Basic Data Partitions
+ * in "winioctl.h": GPT_BASIC_DATA_ATTRIBUTE_READ_ONLY, GPT_BASIC_DATA_ATTRIBUTE_NO_DRIVE_LETTER.
+ */
+#define DPS_TYPE_FLAG_READ_ONLY (1ull << 12)
+#define DPS_TYPE_FLAG_NO_AUTO (1ull << 15)
+#define DPS_TYPE_FLAG_GROWFS (1ull << 11)
+
+#endif
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 025/112] efi: payload: restrict 8250 UART at I/O port 0x3f8 registration to x86
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (23 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 024/112] include: add definitions for UAPI discoverable partitions spec Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 026/112] fs: fix unreaddir, so readdir returns unread dirent first Ahmad Fatoum
` (86 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The 8250 is available on other platforms, but being located at I/O port
0x3f8 is mostly a x86 PC thing, so restrict registering that console to
x86.
This will become required when we start building EFI payload binaries
for architectures besides x86.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/init.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/efi/payload/init.c b/efi/payload/init.c
index b0612276654e..8a9080115ffd 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -215,8 +215,9 @@ static int efi_console_init(void)
add_generic_device("efi-stdio", DEVICE_ID_SINGLE, NULL, 0 , 0, 0, NULL);
- add_ns16550_device(0, 0x3f8, 0x10, IORESOURCE_IO | IORESOURCE_MEM_8BIT,
- &ns16550_plat);
+ if (IS_ENABLED(CONFIG_X86))
+ add_ns16550_device(0, 0x3f8, 0x10, IORESOURCE_IO | IORESOURCE_MEM_8BIT,
+ &ns16550_plat);
return 0;
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 026/112] fs: fix unreaddir, so readdir returns unread dirent first
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (24 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 025/112] efi: payload: restrict 8250 UART at I/O port 0x3f8 registration to x86 Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 027/112] fs: turn creat into static inline helper Ahmad Fatoum
` (85 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
unreaddir should return a directory entry at the top of the list, so
readdir consumes it again, not at the end.
Fixes: 7876018f7333 ("fs: implement unreaddir")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/fs.c b/fs/fs.c
index b3eac2e55ad6..bd2f0b6294ff 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1024,7 +1024,7 @@ int unreaddir(DIR *dir, const struct dirent *d)
entry = xzalloc(sizeof(*entry));
entry->d = *d;
- list_add_tail(&entry->list, &dir->entries);
+ list_add(&entry->list, &dir->entries);
return 0;
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 027/112] fs: turn creat into static inline helper
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (25 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 026/112] fs: fix unreaddir, so readdir returns unread dirent first Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 028/112] fs: drop unused LOOKUP_ flags Ahmad Fatoum
` (84 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
creat is a oneliner that can be inlined at no extra cost, so move it
into a header.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 6 ------
include/fcntl.h | 6 +++++-
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index bd2f0b6294ff..7c4e2f250ea8 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -349,12 +349,6 @@ static int create(struct dentry *dir, struct dentry *dentry)
return inode->i_op->create(inode, dentry, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO);
}
-int creat(const char *pathname, mode_t mode)
-{
- return open(pathname, O_CREAT | O_WRONLY | O_TRUNC);
-}
-EXPORT_SYMBOL(creat);
-
static int fsdev_truncate(struct device *dev, FILE *f, loff_t length)
{
struct fs_driver *fsdrv = f->fsdev->driver;
diff --git a/include/fcntl.h b/include/fcntl.h
index 1b4cd8ad3783..06289abc4376 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -29,6 +29,10 @@
#define O_RWSIZE_8 010000000
int open(const char *pathname, int flags, ...);
-int creat(const char *pathname, mode_t mode);
+
+static inline int creat(const char *pathname, mode_t mode)
+{
+ return open(pathname, O_CREAT | O_WRONLY | O_TRUNC);
+}
#endif /* __FCNTL_H */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 028/112] fs: drop unused LOOKUP_ flags
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (26 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 027/112] fs: turn creat into static inline helper Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 029/112] fs: opendir: reference mount point until closedir is called Ahmad Fatoum
` (83 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Most flags used during VFS lookup are apparently unused, so let's delete
them to make the code easier to reason about.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 11 +----------
include/linux/namei.h | 13 -------------
2 files changed, 1 insertion(+), 23 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 7c4e2f250ea8..7d9bee539db5 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1696,9 +1696,7 @@ static int follow_automount(struct path *path, struct nameidata *nd,
* as being automount points. These will need the attentions
* of the daemon to instantiate them before they can be used.
*/
- if (!(nd->flags & (LOOKUP_PARENT | LOOKUP_DIRECTORY |
- LOOKUP_OPEN | LOOKUP_CREATE | LOOKUP_AUTOMOUNT)) &&
- path->dentry->d_inode)
+ if (!(nd->flags & (LOOKUP_PARENT | LOOKUP_DIRECTORY)) && path->dentry->d_inode)
return -EISDIR;
return automount_mount(path->dentry);
@@ -2278,12 +2276,6 @@ static struct dentry *filename_create(struct filename *name,
int error;
bool is_dir = (lookup_flags & LOOKUP_DIRECTORY);
- /*
- * Note that only LOOKUP_REVAL and LOOKUP_DIRECTORY matter here. Any
- * other flags passed in are ignored!
- */
- lookup_flags &= LOOKUP_REVAL;
-
name = filename_parentat(name, 0, path, &last, &type);
if (IS_ERR(name))
return ERR_CAST(name);
@@ -2298,7 +2290,6 @@ static struct dentry *filename_create(struct filename *name,
/*
* Do the final lookup.
*/
- lookup_flags |= LOOKUP_CREATE | LOOKUP_EXCL;
dentry = __lookup_hash(&last, path->dentry, lookup_flags);
if (IS_ERR(dentry))
goto unlock;
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 9f6e568591af..29c3460ace2a 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -19,30 +19,17 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
* - follow links at the end
* - require a directory
* - ending slashes ok even for nonexistent files
- * - internal "there are more path components" flag
- * - dentry cache is untrusted; force a real lookup
- * - suppress terminal automount
*/
#define LOOKUP_FOLLOW 0x0001
#define LOOKUP_DIRECTORY 0x0002
#define LOOKUP_AUTOMOUNT 0x0004
#define LOOKUP_PARENT 0x0010
-#define LOOKUP_REVAL 0x0020
-#define LOOKUP_RCU 0x0040
-#define LOOKUP_NO_REVAL 0x0080
/*
* Intent data
*/
-#define LOOKUP_OPEN 0x0100
-#define LOOKUP_CREATE 0x0200
-#define LOOKUP_EXCL 0x0400
-#define LOOKUP_RENAME_TARGET 0x0800
#define LOOKUP_JUMPED 0x1000
-#define LOOKUP_ROOT 0x2000
-#define LOOKUP_EMPTY 0x4000
-#define LOOKUP_DOWN 0x8000
#endif /* _LINUX_NAMEI_H */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 029/112] fs: opendir: reference mount point until closedir is called
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (27 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 028/112] fs: drop unused LOOKUP_ flags Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 030/112] fs: factor out opendir iteration Ahmad Fatoum
` (82 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We currently don't keep the path used for opendir alive beyond
the function, because all files are read and added into a linked
list at once. If an unmount happens before closedir though, the file
names will become invalidated, which shouldn't happen. Keep the path
alive for longer to block unmount until directory iteration is over.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 4 ++--
include/dirent.h | 2 ++
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 7d9bee539db5..a31343e2e272 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2757,6 +2757,7 @@ DIR *opendir(const char *pathname)
file.f_op = dir->d_inode->i_fop;
d = xzalloc(sizeof(*d));
+ d->path = path;
INIT_LIST_HEAD(&d->entries);
rd.dir = d;
@@ -2765,8 +2766,6 @@ DIR *opendir(const char *pathname)
if (ret)
goto out_release;
- path_put(&path);
-
return d;
out_release:
@@ -2785,6 +2784,7 @@ int closedir(DIR *dir)
if (!dir)
return errno_set(-EBADF);
+ path_put(&dir->path);
release_dir(dir);
return 0;
diff --git a/include/dirent.h b/include/dirent.h
index 75627730f84b..6e77058d2903 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -3,6 +3,7 @@
#define __DIRENT_H
#include <linux/list.h>
+#include <linux/path.h>
struct dirent {
char d_name[256];
@@ -13,6 +14,7 @@ typedef struct dir {
struct fs_driver *fsdrv;
struct dirent d;
void *priv; /* private data for the fs driver */
+ struct path path;
struct list_head entries;
} DIR;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 030/112] fs: factor out opendir iteration
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (28 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 029/112] fs: opendir: reference mount point until closedir is called Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 031/112] fs: implement fdopendir and rewinddir Ahmad Fatoum
` (81 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
In preparation for supporting fdopendir and rewinddir, add an __opendir
helper that is reused in a follow-up commit.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 52 ++++++++++++++++++++++++++++++++--------------------
1 file changed, 32 insertions(+), 20 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index a31343e2e272..96ca0f110393 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2708,15 +2708,39 @@ int symlink(const char *pathname, const char *newpath)
}
EXPORT_SYMBOL(symlink);
-static void release_dir(DIR *d)
+static void __release_dir(DIR *d)
{
struct readdir_entry *entry, *tmp;
list_for_each_entry_safe(entry, tmp, &d->entries, list) {
free(entry);
}
+}
- free(d);
+static int __opendir(DIR *d)
+{
+ int ret;
+ struct file file = {};
+ struct path *path = &d->path;
+ struct dentry *dir = path->dentry;
+ struct readdir_callback rd = {
+ .ctx = {
+ .actor = fillonedir,
+ },
+ };
+
+ file.f_path.dentry = dir;
+ file.f_inode = d_inode(dir);
+ file.f_op = dir->d_inode->i_fop;
+
+ INIT_LIST_HEAD(&d->entries);
+ rd.dir = d;
+
+ ret = file.f_op->iterate(&file, &rd.ctx);
+ if (ret)
+ __release_dir(d);
+
+ return ret;
}
DIR *opendir(const char *pathname)
@@ -2724,14 +2748,8 @@ DIR *opendir(const char *pathname)
int ret;
struct dentry *dir;
struct inode *inode;
- struct file file = {};
DIR *d;
struct path path = {};
- struct readdir_callback rd = {
- .ctx = {
- .actor = fillonedir,
- },
- };
ret = filename_lookup(getname(pathname),
LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
@@ -2752,24 +2770,17 @@ DIR *opendir(const char *pathname)
goto out_put;
}
- file.f_path.dentry = dir;
- file.f_inode = d_inode(dir);
- file.f_op = dir->d_inode->i_fop;
-
d = xzalloc(sizeof(*d));
d->path = path;
- INIT_LIST_HEAD(&d->entries);
- rd.dir = d;
-
- ret = file.f_op->iterate(&file, &rd.ctx);
+ ret = __opendir(d);
if (ret)
- goto out_release;
+ goto out_free;
return d;
-out_release:
- release_dir(d);
+out_free:
+ free(d);
out_put:
path_put(&path);
out:
@@ -2785,7 +2796,8 @@ int closedir(DIR *dir)
return errno_set(-EBADF);
path_put(&dir->path);
- release_dir(dir);
+ __release_dir(dir);
+ free(dir);
return 0;
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 031/112] fs: implement fdopendir and rewinddir
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (29 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 030/112] fs: factor out opendir iteration Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 032/112] fs: remove unused member from struct nameidata Ahmad Fatoum
` (80 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We will be using the incoming O_PATH support to implement the EFI file
system protocol for when barebox acts as EFI loader.
The protocol also requires being able to rewind iteration, so add
support for that too.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++--
include/dirent.h | 3 +++
2 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 96ca0f110393..ca1bcef1adf0 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2643,6 +2643,20 @@ int open(const char *pathname, int flags, ...)
}
EXPORT_SYMBOL(open);
+static const char *fd_getpath(int fd)
+{
+ FILE *f;
+
+ if (fd < 0)
+ return ERR_PTR(errno_set(fd));
+
+ f = fd_to_file(fd);
+ if (IS_ERR(f))
+ return ERR_CAST(f);
+
+ return f->path;
+}
+
int unlink(const char *pathname)
{
int ret;
@@ -2710,9 +2724,11 @@ EXPORT_SYMBOL(symlink);
static void __release_dir(DIR *d)
{
- struct readdir_entry *entry, *tmp;
+ while (!list_empty(&d->entries)) {
+ struct readdir_entry *entry =
+ list_first_entry(&d->entries, struct readdir_entry, list);
- list_for_each_entry_safe(entry, tmp, &d->entries, list) {
+ list_del(&entry->list);
free(entry);
}
}
@@ -2772,6 +2788,7 @@ DIR *opendir(const char *pathname)
d = xzalloc(sizeof(*d));
d->path = path;
+ d->fd = -ENOENT;
ret = __opendir(d);
if (ret)
@@ -2790,6 +2807,27 @@ DIR *opendir(const char *pathname)
}
EXPORT_SYMBOL(opendir);
+DIR *fdopendir(int fd)
+{
+ const char *path;
+ DIR *dir;
+
+ path = fd_getpath(fd);
+ if (IS_ERR(path))
+ return NULL;
+
+ dir = opendir(path);
+ if (!dir)
+ return NULL;
+
+ /* we intentionally don't increment the reference count,
+ * as POSIX specifies that fd ownership is transferred
+ */
+ dir->fd = fd;
+ return dir;
+}
+EXPORT_SYMBOL(fdopendir);
+
int closedir(DIR *dir)
{
if (!dir)
@@ -2797,12 +2835,25 @@ int closedir(DIR *dir)
path_put(&dir->path);
__release_dir(dir);
+ if (dir->fd >= 0)
+ close(dir->fd);
free(dir);
return 0;
}
EXPORT_SYMBOL(closedir);
+int rewinddir(DIR *dir)
+{
+ if (!dir)
+ return errno_set(-EBADF);
+
+ __release_dir(dir);
+
+ return __opendir(dir);
+}
+EXPORT_SYMBOL(rewinddir);
+
int readlink(const char *pathname, char *buf, size_t bufsiz)
{
int ret;
diff --git a/include/dirent.h b/include/dirent.h
index 6e77058d2903..4f7ff2a5f91f 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -14,13 +14,16 @@ typedef struct dir {
struct fs_driver *fsdrv;
struct dirent d;
void *priv; /* private data for the fs driver */
+ int fd;
struct path path;
struct list_head entries;
} DIR;
DIR *opendir(const char *pathname);
+DIR *fdopendir(int fd);
struct dirent *readdir(DIR *dir);
int unreaddir(DIR *dir, const struct dirent *d);
+int rewinddir(DIR *dir);
int closedir(DIR *dir);
#endif /* __DIRENT_H */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 032/112] fs: remove unused member from struct nameidata
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (30 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 031/112] fs: implement fdopendir and rewinddir Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 033/112] fs: always check path_init for errors Ahmad Fatoum
` (79 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
A number of members in the struct are either unused or only ever written
and never read. Drop them to tidy up the code.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index ca1bcef1adf0..be0b38d8bc30 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1605,21 +1605,16 @@ enum {WALK_FOLLOW = 1, WALK_MORE = 2};
struct nameidata {
struct path path;
struct qstr last;
- struct inode *inode; /* path.dentry.d_inode */
unsigned int flags;
- unsigned seq, m_seq;
int last_type;
unsigned depth;
int total_link_count;
struct saved {
struct path link;
const char *name;
- unsigned seq;
} *stack, internal[EMBEDDED_LEVELS];
struct filename *name;
- struct nameidata *saved;
struct inode *link_inode;
- unsigned root_seq;
};
struct filename {
@@ -1879,8 +1874,6 @@ static int follow_dotdot(struct nameidata *nd)
follow_mount(&nd->path);
- nd->inode = nd->path.dentry->d_inode;
-
return 0;
}
@@ -1961,7 +1954,6 @@ static inline int step_into(struct nameidata *nd, struct path *path,
!(flags & WALK_FOLLOW || nd->flags & LOOKUP_FOLLOW)) {
/* not a symlink or should not follow */
path_to_nameidata(path, nd);
- nd->inode = inode;
return 0;
}
@@ -2185,7 +2177,6 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
return s;
} else {
get_pwd(&nd->path);
- nd->inode = nd->path.dentry->d_inode;
return s;
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 033/112] fs: always check path_init for errors
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (31 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 032/112] fs: remove unused member from struct nameidata Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 034/112] fs: set current working dir directly when mounting root Ahmad Fatoum
` (78 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We have three calls to path_init, but Only one of them checks the returned
pointer value for errors. This didn't hurt so far, because the function
always succeeded, but a follow-up commit will cause it to fail in some
circumstances, so prepare for that by duly checking the return value.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/fs.c b/fs/fs.c
index be0b38d8bc30..c034f2cb9a0d 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2324,6 +2324,8 @@ static int filename_lookup(struct filename *name, unsigned flags,
set_nameidata(&nd, name);
s = path_init(&nd, flags);
+ if (IS_ERR(s))
+ return PTR_ERR(s);
while (!(err = link_path_walk(s, &nd)) && ((err = lookup_last(&nd)) > 0)) {
s = trailing_symlink(&nd);
@@ -2529,6 +2531,8 @@ int open(const char *pathname, int flags, ...)
set_nameidata(&nd, filename);
s = path_init(&nd, LOOKUP_FOLLOW);
+ if (IS_ERR(s))
+ return PTR_ERR(s);
while (1) {
error = link_path_walk(s, &nd);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 034/112] fs: set current working dir directly when mounting root
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (32 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 033/112] fs: always check path_init for errors Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 035/112] fs: implement openat and friends Ahmad Fatoum
` (77 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The default current working directory is the root directory, but this
can't be initialized statically, because the root directory is only
mounted at runtime. Therefore, the get_pwd accessor initializes the
current working directory on first access.
Instead we could just initialize them when we mount the root directory
and simplify the code a tiny bit.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index c034f2cb9a0d..bf527f1b2d9b 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1651,11 +1651,6 @@ static inline void get_root(struct path *root)
static inline void get_pwd(struct path *pwd)
{
- if (!cwd_dentry) {
- cwd_dentry = d_root;
- cwd_mnt = mnt_root;
- }
-
pwd->dentry = cwd_dentry;
pwd->mnt = cwd_mnt;
@@ -3211,6 +3206,9 @@ int mount(const char *device, const char *fsname, const char *pathname,
fsdev->vfsmount.mountpoint = d_root;
fsdev->vfsmount.parent = &fsdev->vfsmount;
fsdev->path = xstrdup("/");
+
+ cwd_dentry = d_root;
+ cwd_mnt = mnt_root;
}
fsdev->vfsmount.mnt_root = fsdev->sb.s_root;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 035/112] fs: implement openat and friends
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (33 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 034/112] fs: set current working dir directly when mounting root Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 036/112] fs: implement O_PATH Ahmad Fatoum
` (76 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The EFI file system API takes as handle an arbitrary file within the
volume. Directory iteration should happen relative to that file, which
lends itself well to mapping this to openat and friends.
Add support for these to barebox in preparation.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/readlink.c | 2 +-
fs/fs.c | 140 +++++++++++++++++++++++++-------------------
include/fcntl.h | 14 ++++-
include/fs.h | 2 +-
include/sys/stat.h | 8 ++-
include/unistd.h | 35 +++++++++--
6 files changed, 132 insertions(+), 69 deletions(-)
diff --git a/commands/readlink.c b/commands/readlink.c
index 81ad25c733ab..55f8249028e1 100644
--- a/commands/readlink.c
+++ b/commands/readlink.c
@@ -31,7 +31,7 @@ static int do_readlink(int argc, char *argv[])
return COMMAND_ERROR_USAGE;
if (canonicalize) {
- char *buf = canonicalize_path(argv[optind]);
+ char *buf = canonicalize_path(AT_FDCWD, argv[optind]);
struct stat s;
if (!buf)
diff --git a/fs/fs.c b/fs/fs.c
index bf527f1b2d9b..6b71440318af 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -130,10 +130,11 @@ void cdev_print(const struct cdev *cdev)
}
EXPORT_SYMBOL(cdev_print);
-static struct fs_device *get_fsdevice_by_path(const char *path);
+static struct fs_device *get_fsdevice_by_path(int dirfd, const char *path);
void stat_print(const char *filename, const struct stat *st)
{
+ int dirfd = AT_FDCWD;
struct block_device *bdev = NULL;
struct fs_device *fdev;
struct cdev *cdev = NULL;
@@ -156,7 +157,7 @@ void stat_print(const char *filename, const struct stat *st)
if (st->st_mode & S_IFCHR) {
char *path;
- path = canonicalize_path(filename);
+ path = canonicalize_path(dirfd, filename);
if (path) {
const char *devicefile = devpath_to_name(path);
struct cdev *lcdev;
@@ -198,7 +199,7 @@ void stat_print(const char *filename, const struct stat *st)
if (type)
printf(" %s%s", typeprefix, type);
- fdev = get_fsdevice_by_path(filename);
+ fdev = get_fsdevice_by_path(dirfd, filename);
printf("\nDevice: %s\tInode: %lu\n",
fdev ? dev_name(&fdev->dev) : "<unknown>",
@@ -235,7 +236,7 @@ postcore_initcall(init_fs);
struct filename;
-static int filename_lookup(struct filename *name, unsigned flags,
+static int filename_lookup(int dirfd, struct filename *name, unsigned flags,
struct path *path);;
static struct filename *getname(const char *filename);
static void path_put(const struct path *path);
@@ -282,7 +283,7 @@ struct cdev *get_cdev_by_mountpath(const char *path)
{
struct fs_device *fsdev;
- fsdev = get_fsdevice_by_path(path);
+ fsdev = get_fsdevice_by_path(AT_FDCWD, path);
if (!fsdev)
return NULL;
@@ -293,7 +294,7 @@ char *get_mounted_path(const char *path)
{
struct fs_device *fdev;
- fdev = get_fsdevice_by_path(path);
+ fdev = get_fsdevice_by_path(AT_FDCWD, path);
if (!fdev)
return NULL;
@@ -828,7 +829,7 @@ static void fs_remove(struct device *dev)
if (fsdev->loop && fsdev->cdev) {
cdev_remove_loop(fsdev->cdev);
- ret = filename_lookup(getname(fsdev->backingstore),
+ ret = filename_lookup(AT_FDCWD, getname(fsdev->backingstore),
LOOKUP_FOLLOW, &path);
if (!ret) {
mntput(path.mnt);
@@ -912,7 +913,7 @@ int fsdev_open_cdev(struct fs_device *fsdev)
parseopt_b(fsdev->options, "loop", &fsdev->loop);
parseopt_llu_suffix(fsdev->options, "offset", &offset);
if (fsdev->loop) {
- ret = filename_lookup(getname(fsdev->backingstore),
+ ret = filename_lookup(AT_FDCWD, getname(fsdev->backingstore),
LOOKUP_FOLLOW, &path);
if (ret)
return ret;
@@ -1194,7 +1195,7 @@ char *path_get_linux_rootarg(const char *path)
struct fs_device *fsdev;
const char *str;
- fsdev = get_fsdevice_by_path(path);
+ fsdev = get_fsdevice_by_path(AT_FDCWD, path);
if (!fsdev)
return ERR_PTR(-EINVAL);
@@ -1217,7 +1218,7 @@ bool __is_tftp_fs(const char *path)
{
struct fs_device *fsdev;
- fsdev = get_fsdevice_by_path(path);
+ fsdev = get_fsdevice_by_path(AT_FDCWD, path);
if (!fsdev)
return false;
@@ -2156,9 +2157,10 @@ static int link_path_walk(const char *name, struct nameidata *nd)
}
}
-static const char *path_init(struct nameidata *nd, unsigned flags)
+static const char *path_init(int dirfd, struct nameidata *nd, unsigned flags)
{
const char *s = nd->name->name;
+ FILE *f = NULL;
nd->last_type = LAST_ROOT; /* if there are only slashes... */
nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT;
@@ -2167,12 +2169,23 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
nd->path.mnt = NULL;
nd->path.dentry = NULL;
+ /* We don't check for error here yet, as POSIX allows checking
+ * whether paths are absolute with openat(-1, path, O_PATH)
+ */
+ if (dirfd != AT_FDCWD)
+ f = fd_to_file(dirfd);
+
if (*s == '/') {
get_root(&nd->path);
- return s;
- } else {
+ } else if (dirfd == AT_FDCWD) {
get_pwd(&nd->path);
- return s;
+ } else {
+ if (IS_ERR(f))
+ return ERR_CAST(f);
+
+ nd->path.mnt = &f->fsdev->vfsmount;
+ nd->path.dentry = f->dentry;
+ follow_mount(&nd->path);
}
return s;
@@ -2210,10 +2223,10 @@ static void terminate_walk(struct nameidata *nd)
}
/* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
-static int path_parentat(struct nameidata *nd, unsigned flags,
+static int path_parentat(int dirfd, struct nameidata *nd, unsigned flags,
struct path *parent)
{
- const char *s = path_init(nd, flags);
+ const char *s = path_init(dirfd, nd, flags);
int err;
if (IS_ERR(s))
@@ -2229,7 +2242,8 @@ static int path_parentat(struct nameidata *nd, unsigned flags,
return err;
}
-static struct filename *filename_parentat(struct filename *name,
+static struct filename *filename_parentat(int dirfd,
+ struct filename *name,
unsigned int flags, struct path *parent,
struct qstr *last, int *type)
{
@@ -2241,7 +2255,7 @@ static struct filename *filename_parentat(struct filename *name,
set_nameidata(&nd, name);
- retval = path_parentat(&nd, flags, parent);
+ retval = path_parentat(dirfd, &nd, flags, parent);
if (likely(!retval)) {
*last = nd.last;
*type = nd.last_type;
@@ -2253,7 +2267,7 @@ static struct filename *filename_parentat(struct filename *name,
return name;
}
-static struct dentry *filename_create(struct filename *name,
+static struct dentry *filename_create(int dirfd, struct filename *name,
struct path *path, unsigned int lookup_flags)
{
struct dentry *dentry = ERR_PTR(-EEXIST);
@@ -2262,7 +2276,7 @@ static struct dentry *filename_create(struct filename *name,
int error;
bool is_dir = (lookup_flags & LOOKUP_DIRECTORY);
- name = filename_parentat(name, 0, path, &last, &type);
+ name = filename_parentat(dirfd, name, 0, path, &last, &type);
if (IS_ERR(name))
return ERR_CAST(name);
@@ -2306,7 +2320,7 @@ static struct dentry *filename_create(struct filename *name,
return dentry;
}
-static int filename_lookup(struct filename *name, unsigned flags,
+static int filename_lookup(int dirfd, struct filename *name, unsigned flags,
struct path *path)
{
int err;
@@ -2318,7 +2332,7 @@ static int filename_lookup(struct filename *name, unsigned flags,
set_nameidata(&nd, name);
- s = path_init(&nd, flags);
+ s = path_init(dirfd, &nd, flags);
if (IS_ERR(s))
return PTR_ERR(s);
@@ -2345,13 +2359,13 @@ static int filename_lookup(struct filename *name, unsigned flags,
return err;
}
-static struct fs_device *get_fsdevice_by_path(const char *pathname)
+static struct fs_device *get_fsdevice_by_path(int dirfd, const char *pathname)
{
struct fs_device *fsdev;
struct path path;
int ret;
- ret = filename_lookup(getname(pathname), 0, &path);
+ ret = filename_lookup(dirfd, getname(pathname), 0, &path);
if (ret)
return NULL;
@@ -2403,14 +2417,14 @@ static int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
/* libfs.c */
/* ---------------------------------------------------------------- */
-int mkdir (const char *pathname, mode_t mode)
+int mkdirat(int dirfd, const char *pathname, mode_t mode)
{
struct dentry *dentry;
struct path path;
int error;
unsigned int lookup_flags = LOOKUP_DIRECTORY;
- dentry = filename_create(getname(pathname), &path, lookup_flags);
+ dentry = filename_create(dirfd, getname(pathname), &path, lookup_flags);
if (IS_ERR(dentry)) {
error = PTR_ERR(dentry);
goto out;
@@ -2423,9 +2437,9 @@ int mkdir (const char *pathname, mode_t mode)
out:
return errno_set(error);
}
-EXPORT_SYMBOL(mkdir);
+EXPORT_SYMBOL(mkdirat);
-int rmdir (const char *pathname)
+static int rmdirat(int dirfd, const char *pathname)
{
int error = 0;
struct filename *name;
@@ -2434,7 +2448,7 @@ int rmdir (const char *pathname)
struct qstr last;
int type;
- name = filename_parentat(getname(pathname), 0,
+ name = filename_parentat(dirfd, getname(pathname), 0,
&path, &last, &type);
if (IS_ERR(name))
return PTR_ERR(name);
@@ -2475,9 +2489,8 @@ int rmdir (const char *pathname)
return errno_set(error);
}
-EXPORT_SYMBOL(rmdir);
-int open(const char *pathname, int flags, ...)
+int openat(int dirfd, const char *pathname, int flags)
{
struct fs_device *fsdev;
struct fs_driver *fsdrv;
@@ -2491,7 +2504,7 @@ int open(const char *pathname, int flags, ...)
struct filename *filename;
if (flags & O_TMPFILE) {
- fsdev = get_fsdevice_by_path(pathname);
+ fsdev = get_fsdevice_by_path(dirfd, pathname);
if (!fsdev) {
errno = ENOENT;
return -errno;
@@ -2525,7 +2538,7 @@ int open(const char *pathname, int flags, ...)
set_nameidata(&nd, filename);
- s = path_init(&nd, LOOKUP_FOLLOW);
+ s = path_init(dirfd, &nd, LOOKUP_FOLLOW);
if (IS_ERR(s))
return PTR_ERR(s);
@@ -2592,7 +2605,7 @@ int open(const char *pathname, int flags, ...)
goto out1;
}
- f->path = xstrdup(pathname);
+ f->path = dpath(dentry, d_root);
f->dentry = dentry;
f->f_inode = iget(inode);
f->flags = flags;
@@ -2631,7 +2644,7 @@ int open(const char *pathname, int flags, ...)
out1:
return errno_set(error);
}
-EXPORT_SYMBOL(open);
+EXPORT_SYMBOL(openat);
static const char *fd_getpath(int fd)
{
@@ -2647,14 +2660,19 @@ static const char *fd_getpath(int fd)
return f->path;
}
-int unlink(const char *pathname)
+int unlinkat(int dirfd, const char *pathname, int flags)
{
int ret;
struct dentry *dentry;
struct inode *inode;
struct path path;
- ret = filename_lookup(getname(pathname), 0, &path);
+ if (flags == AT_REMOVEDIR)
+ return rmdirat(dirfd, pathname);
+ if (flags)
+ return -EINVAL;
+
+ ret = filename_lookup(dirfd, getname(pathname), 0, &path);
if (ret)
goto out;
@@ -2683,7 +2701,7 @@ int unlink(const char *pathname)
out:
return errno_set(ret);
}
-EXPORT_SYMBOL(unlink);
+EXPORT_SYMBOL(unlinkat);
static int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname)
{
@@ -2700,7 +2718,7 @@ int symlink(const char *pathname, const char *newpath)
int error;
unsigned int lookup_flags = LOOKUP_DIRECTORY;
- dentry = filename_create(getname(newpath), &path, lookup_flags);
+ dentry = filename_create(AT_FDCWD, getname(newpath), &path, lookup_flags);
if (IS_ERR(dentry)) {
error = PTR_ERR(dentry);
goto out;
@@ -2757,7 +2775,7 @@ DIR *opendir(const char *pathname)
DIR *d;
struct path path = {};
- ret = filename_lookup(getname(pathname),
+ ret = filename_lookup(AT_FDCWD, getname(pathname),
LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
if (ret)
goto out;
@@ -2844,7 +2862,7 @@ int rewinddir(DIR *dir)
}
EXPORT_SYMBOL(rewinddir);
-int readlink(const char *pathname, char *buf, size_t bufsiz)
+int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz)
{
int ret;
struct dentry *dentry;
@@ -2852,7 +2870,7 @@ int readlink(const char *pathname, char *buf, size_t bufsiz)
const char *link;
struct path path = {};
- ret = filename_lookup(getname(pathname), 0, &path);
+ ret = filename_lookup(dirfd, getname(pathname), 0, &path);
if (ret)
goto out;
@@ -2884,16 +2902,16 @@ int readlink(const char *pathname, char *buf, size_t bufsiz)
out:
return errno_set(ret);
}
-EXPORT_SYMBOL(readlink);
+EXPORT_SYMBOL(readlinkat);
-static int stat_filename(const char *filename, struct stat *s, unsigned int flags)
+static int stat_filename(int dirfd, const char *filename, struct stat *s, unsigned int flags)
{
int ret;
struct dentry *dentry;
struct inode *inode;
struct path path = {};
- ret = filename_lookup(getname(filename), flags, &path);
+ ret = filename_lookup(dirfd, getname(filename), flags, &path);
if (ret)
goto out;
@@ -2915,17 +2933,17 @@ static int stat_filename(const char *filename, struct stat *s, unsigned int flag
return errno_set(ret);
}
-int stat(const char *filename, struct stat *s)
+int statat(int dirfd, const char *filename, struct stat *s)
{
- return stat_filename(filename, s, LOOKUP_FOLLOW);
+ return stat_filename(dirfd, filename, s, LOOKUP_FOLLOW);
}
-EXPORT_SYMBOL(stat);
+EXPORT_SYMBOL(statat);
-int lstat(const char *filename, struct stat *s)
+int lstatat(int dirfd, const char *filename, struct stat *s)
{
- return stat_filename(filename, s, 0);
+ return stat_filename(dirfd, filename, s, 0);
}
-EXPORT_SYMBOL(lstat);
+EXPORT_SYMBOL(lstatat);
static char *__dpath(struct dentry *dentry, struct dentry *root)
{
@@ -2981,6 +2999,8 @@ char *dpath(struct dentry *dentry, struct dentry *root)
/**
* canonicalize_path - resolve links in path
+ *
+ * @dirfd: directory file descriptor to look up relative to
* @pathname: The input path
*
* This function resolves all links in @pathname and returns
@@ -2988,13 +3008,13 @@ char *dpath(struct dentry *dentry, struct dentry *root)
*
* Return: Path with links resolved. Allocated, must be freed after use.
*/
-char *canonicalize_path(const char *pathname)
+char *canonicalize_path(int dirfd, const char *pathname)
{
char *res = NULL;
struct path path;
int ret;
- ret = filename_lookup(getname(pathname), LOOKUP_FOLLOW, &path);
+ ret = filename_lookup(dirfd, getname(pathname), LOOKUP_FOLLOW, &path);
if (ret)
goto out;
@@ -3016,7 +3036,7 @@ int chdir(const char *pathname)
struct path path;
int ret;
- ret = filename_lookup(getname(pathname), LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
+ ret = filename_lookup(AT_FDCWD, getname(pathname), LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
if (ret)
goto out;
@@ -3135,7 +3155,7 @@ int mount(const char *device, const char *fsname, const char *pathname,
struct path path = {};
if (d_root) {
- ret = filename_lookup(getname(pathname), LOOKUP_FOLLOW, &path);
+ ret = filename_lookup(AT_FDCWD, getname(pathname), LOOKUP_FOLLOW, &path);
if (ret)
goto out;
@@ -3242,7 +3262,7 @@ int umount(const char *pathname)
struct path path = {};
int ret;
- ret = filename_lookup(getname(pathname), LOOKUP_FOLLOW, &path);
+ ret = filename_lookup(AT_FDCWD, getname(pathname), LOOKUP_FOLLOW, &path);
if (ret)
return ret;
@@ -3313,7 +3333,7 @@ void automount_remove(const char *pathname)
struct path path;
int ret;
- ret = filename_lookup(getname(pathname), LOOKUP_FOLLOW, &path);
+ ret = filename_lookup(AT_FDCWD, getname(pathname), LOOKUP_FOLLOW, &path);
if (ret)
return;
@@ -3329,7 +3349,7 @@ int automount_add(const char *pathname, const char *cmd)
struct path path;
int ret;
- ret = filename_lookup(getname(pathname), LOOKUP_FOLLOW, &path);
+ ret = filename_lookup(AT_FDCWD, getname(pathname), LOOKUP_FOLLOW, &path);
if (ret)
return ret;
@@ -3441,14 +3461,14 @@ static int do_lookup_dentry(int argc, char *argv[])
if (argc < 2)
return COMMAND_ERROR_USAGE;
- ret = filename_lookup(getname(argv[1]), 0, &path);
+ ret = filename_lookup(AT_FDCWD, getname(argv[1]), 0, &path);
if (ret) {
printf("Cannot lookup path \"%s\": %s\n",
argv[1], strerror(-ret));
return 1;
}
- canon = canonicalize_path(argv[1]);
+ canon = canonicalize_path(AT_FDCWD, argv[1]);
printf("path \"%s\":\n", argv[1]);
printf("dentry: 0x%p\n", path.dentry);
diff --git a/include/fcntl.h b/include/fcntl.h
index 06289abc4376..a6ed50b92eaf 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -4,6 +4,13 @@
#include <linux/types.h>
+#define AT_FDCWD -100 /* Special value used to indicate
+ openat should use the current
+ working directory. */
+
+#define AT_REMOVEDIR 0x200 /* Remove directory instead of
+ unlinking file. */
+
/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
located on an ext2 file system */
#define O_ACCMODE 00000003
@@ -28,7 +35,12 @@
#define O_RWSIZE_4 004000000
#define O_RWSIZE_8 010000000
-int open(const char *pathname, int flags, ...);
+int openat(int dirfd, const char *pathname, int flags);
+
+static inline int open(const char *pathname, int flags, ...)
+{
+ return openat(AT_FDCWD, pathname, flags);
+}
static inline int creat(const char *pathname, mode_t mode)
{
diff --git a/include/fs.h b/include/fs.h
index a61982e59ade..c4af8659b0d3 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -150,7 +150,7 @@ char *mkmodestr(unsigned long mode, char *str);
void stat_print(const char *filename, const struct stat *st);
void cdev_print(const struct cdev *cdev);
-char *canonicalize_path(const char *pathname);
+char *canonicalize_path(int dirfd, const char *pathname);
char *get_mounted_path(const char *path);
diff --git a/include/sys/stat.h b/include/sys/stat.h
index 0dd43d1f02c8..7af49a1d3ccc 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -5,7 +5,13 @@
#include <linux/types.h>
#include <linux/stat.h>
+#include <fcntl.h>
-int mkdir (const char *pathname, mode_t mode);
+int mkdirat(int dirfd, const char *pathname, mode_t mode);
+
+static inline int mkdir(const char *pathname, mode_t mode)
+{
+ return mkdirat(AT_FDCWD, pathname, mode);
+}
#endif /* __STAT_H */
diff --git a/include/unistd.h b/include/unistd.h
index f7fe737d002b..b78acbfd737a 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -3,26 +3,51 @@
#define __UNISTD_H
#include <linux/types.h>
+#include <fcntl.h>
struct stat;
-int unlink(const char *pathname);
+int unlinkat(int dirfd, const char *pathname, int flags);
int close(int fd);
-int lstat(const char *filename, struct stat *s);
-int stat(const char *filename, struct stat *s);
+int lstatat(int dirfd, const char *filename, struct stat *s);
+int statat(int dirfd, const char *filename, struct stat *s);
int fstat(int fd, struct stat *s);
ssize_t read(int fd, void *buf, size_t count);
ssize_t pread(int fd, void *buf, size_t count, loff_t offset);
ssize_t write(int fd, const void *buf, size_t count);
ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset);
loff_t lseek(int fildes, loff_t offset, int whence);
-int rmdir (const char *pathname);
int symlink(const char *pathname, const char *newpath);
-int readlink(const char *path, char *buf, size_t bufsiz);
+int readlinkat(int dirfd, const char *path, char *buf, size_t bufsiz);
int chdir(const char *pathname);
char *pushd(const char *dir);
int popd(char *dir);
const char *getcwd(void);
int ftruncate(int fd, loff_t length);
+static inline int unlink(const char *pathname)
+{
+ return unlinkat(AT_FDCWD, pathname, 0);
+}
+
+static inline int lstat(const char *filename, struct stat *s)
+{
+ return lstatat(AT_FDCWD, filename, s);
+}
+
+static inline int stat(const char *filename, struct stat *s)
+{
+ return statat(AT_FDCWD, filename, s);
+}
+
+static inline int rmdir(const char *pathname)
+{
+ return unlinkat(AT_FDCWD, pathname, AT_REMOVEDIR);
+}
+
+static inline int readlink(const char *path, char *buf, size_t bufsiz)
+{
+ return readlinkat(AT_FDCWD, path, buf, bufsiz);
+}
+
#endif /* __UNISTD_H */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 036/112] fs: implement O_PATH
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (34 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 035/112] fs: implement openat and friends Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-05 11:22 ` Sascha Hauer
2024-01-03 18:11 ` [PATCH 037/112] fs: support different root directories Ahmad Fatoum
` (75 subsequent siblings)
111 siblings, 1 reply; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
For use with the newly added openat and friends API, add O_PATH file
descriptors that are not usable for doing actual I/O, but only for use
as dirfd.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 58 +++++++++++++++++++++++++++++--------------------
include/fcntl.h | 1 +
2 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 6b71440318af..54f38aa2e63b 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -325,12 +325,16 @@ static void put_file(FILE *f)
dput(f->dentry);
}
-static FILE *fd_to_file(int fd)
+static FILE *fd_to_file(int fd, bool allow_pathonly)
{
if (fd < 0 || fd >= MAX_FILES || !files[fd].in_use) {
errno = EBADF;
return ERR_PTR(-errno);
}
+ if (!allow_pathonly && (files[fd].flags & O_PATH)) {
+ errno = EINVAL;
+ return ERR_PTR(-errno);
+ }
return &files[fd];
}
@@ -359,7 +363,7 @@ static int fsdev_truncate(struct device *dev, FILE *f, loff_t length)
int ftruncate(int fd, loff_t length)
{
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, false);
int ret;
if (IS_ERR(f))
@@ -381,7 +385,7 @@ int ftruncate(int fd, loff_t length)
int ioctl(int fd, int request, void *buf)
{
struct fs_driver *fsdrv;
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, false);
int ret;
if (IS_ERR(f))
@@ -426,7 +430,7 @@ static ssize_t __read(FILE *f, void *buf, size_t count)
ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
{
loff_t pos;
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, false);
int ret;
if (IS_ERR(f))
@@ -443,7 +447,7 @@ EXPORT_SYMBOL(pread);
ssize_t read(int fd, void *buf, size_t count)
{
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, false);
int ret;
if (IS_ERR(f))
@@ -495,7 +499,7 @@ static ssize_t __write(FILE *f, const void *buf, size_t count)
ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset)
{
loff_t pos;
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, false);
int ret;
if (IS_ERR(f))
@@ -512,7 +516,7 @@ EXPORT_SYMBOL(pwrite);
ssize_t write(int fd, const void *buf, size_t count)
{
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, false);
int ret;
if (IS_ERR(f))
@@ -529,7 +533,7 @@ EXPORT_SYMBOL(write);
int flush(int fd)
{
struct fs_driver *fsdrv;
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, false);
int ret;
if (IS_ERR(f))
@@ -547,7 +551,7 @@ int flush(int fd)
loff_t lseek(int fd, loff_t offset, int whence)
{
struct fs_driver *fsdrv;
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, false);
loff_t pos;
int ret;
@@ -600,7 +604,7 @@ EXPORT_SYMBOL(lseek);
int erase(int fd, loff_t count, loff_t offset)
{
struct fs_driver *fsdrv;
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, false);
int ret;
if (IS_ERR(f))
@@ -629,7 +633,7 @@ EXPORT_SYMBOL(erase);
int protect(int fd, size_t count, loff_t offset, int prot)
{
struct fs_driver *fsdrv;
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, false);
int ret;
if (IS_ERR(f))
@@ -656,7 +660,7 @@ EXPORT_SYMBOL(protect);
int discard_range(int fd, loff_t count, loff_t offset)
{
struct fs_driver *fsdrv;
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, false);
int ret;
if (IS_ERR(f))
@@ -697,7 +701,7 @@ int protect_file(const char *file, int prot)
void *memmap(int fd, int flags)
{
struct fs_driver *fsdrv;
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, false);
void *retp = MAP_FAILED;
int ret;
@@ -721,20 +725,23 @@ EXPORT_SYMBOL(memmap);
int close(int fd)
{
- struct fs_driver *fsdrv;
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, true);
int ret = 0;
if (IS_ERR(f))
return -errno;
- fsdrv = f->fsdev->driver;
+ if (!(f->flags & O_PATH)) {
+ struct fs_driver *fsdrv;
- if (fsdrv != ramfs_driver)
- assert_command_context();
+ fsdrv = f->fsdev->driver;
- if (fsdrv->close)
- ret = fsdrv->close(&f->fsdev->dev, f);
+ if (fsdrv != ramfs_driver)
+ assert_command_context();
+
+ if (fsdrv->close)
+ ret = fsdrv->close(&f->fsdev->dev, f);
+ }
put_file(f);
@@ -1056,7 +1063,7 @@ static void stat_inode(struct inode *inode, struct stat *s)
int fstat(int fd, struct stat *s)
{
- FILE *f = fd_to_file(fd);
+ FILE *f = fd_to_file(fd, true);
if (IS_ERR(f))
return -errno;
@@ -2173,7 +2180,7 @@ static const char *path_init(int dirfd, struct nameidata *nd, unsigned flags)
* whether paths are absolute with openat(-1, path, O_PATH)
*/
if (dirfd != AT_FDCWD)
- f = fd_to_file(dirfd);
+ f = fd_to_file(dirfd, true);
if (*s == '/') {
get_root(&nd->path);
@@ -2590,7 +2597,7 @@ int openat(int dirfd, const char *pathname, int flags)
error = -ENOENT;
goto out1;
}
- } else {
+ } else if (!(flags & O_PATH)) {
if (d_is_dir(dentry) && !dentry_is_tftp(dentry)) {
error = -EISDIR;
goto out1;
@@ -2617,6 +2624,9 @@ int openat(int dirfd, const char *pathname, int flags)
f->fsdev = fsdev;
+ if (flags & O_PATH)
+ return f->no;
+
if (fsdrv->open) {
char *pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
@@ -2653,7 +2663,7 @@ static const char *fd_getpath(int fd)
if (fd < 0)
return ERR_PTR(errno_set(fd));
- f = fd_to_file(fd);
+ f = fd_to_file(fd, true);
if (IS_ERR(f))
return ERR_CAST(f);
diff --git a/include/fcntl.h b/include/fcntl.h
index a6ed50b92eaf..a3f5d96cd0ac 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -23,6 +23,7 @@
#define O_APPEND 00002000
#define O_DIRECTORY 00200000 /* must be a directory */
#define O_NOFOLLOW 00400000 /* don't follow links */
+#define O_PATH 02000000 /* open as path */
#define __O_TMPFILE 020000000
#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 036/112] fs: implement O_PATH
2024-01-03 18:11 ` [PATCH 036/112] fs: implement O_PATH Ahmad Fatoum
@ 2024-01-05 11:22 ` Sascha Hauer
2024-01-05 11:26 ` Ahmad Fatoum
0 siblings, 1 reply; 134+ messages in thread
From: Sascha Hauer @ 2024-01-05 11:22 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Jan 03, 2024 at 07:11:56PM +0100, Ahmad Fatoum wrote:
> For use with the newly added openat and friends API, add O_PATH file
> descriptors that are not usable for doing actual I/O, but only for use
> as dirfd.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> fs/fs.c | 58 +++++++++++++++++++++++++++++--------------------
> include/fcntl.h | 1 +
> 2 files changed, 35 insertions(+), 24 deletions(-)
>
> diff --git a/fs/fs.c b/fs/fs.c
> index 6b71440318af..54f38aa2e63b 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -325,12 +325,16 @@ static void put_file(FILE *f)
> dput(f->dentry);
> }
>
> -static FILE *fd_to_file(int fd)
> +static FILE *fd_to_file(int fd, bool allow_pathonly)
This parameter name confuses me. I read this as "only O_PATH is
allowed". Maybe rename this to "o_path_allowed" or "o_path_ok"?
Sascha
> {
> if (fd < 0 || fd >= MAX_FILES || !files[fd].in_use) {
> errno = EBADF;
> return ERR_PTR(-errno);
> }
> + if (!allow_pathonly && (files[fd].flags & O_PATH)) {
> + errno = EINVAL;
> + return ERR_PTR(-errno);
> + }
>
> return &files[fd];
> }
> @@ -359,7 +363,7 @@ static int fsdev_truncate(struct device *dev, FILE *f, loff_t length)
>
> int ftruncate(int fd, loff_t length)
> {
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, false);
> int ret;
>
> if (IS_ERR(f))
> @@ -381,7 +385,7 @@ int ftruncate(int fd, loff_t length)
> int ioctl(int fd, int request, void *buf)
> {
> struct fs_driver *fsdrv;
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, false);
> int ret;
>
> if (IS_ERR(f))
> @@ -426,7 +430,7 @@ static ssize_t __read(FILE *f, void *buf, size_t count)
> ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
> {
> loff_t pos;
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, false);
> int ret;
>
> if (IS_ERR(f))
> @@ -443,7 +447,7 @@ EXPORT_SYMBOL(pread);
>
> ssize_t read(int fd, void *buf, size_t count)
> {
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, false);
> int ret;
>
> if (IS_ERR(f))
> @@ -495,7 +499,7 @@ static ssize_t __write(FILE *f, const void *buf, size_t count)
> ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset)
> {
> loff_t pos;
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, false);
> int ret;
>
> if (IS_ERR(f))
> @@ -512,7 +516,7 @@ EXPORT_SYMBOL(pwrite);
>
> ssize_t write(int fd, const void *buf, size_t count)
> {
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, false);
> int ret;
>
> if (IS_ERR(f))
> @@ -529,7 +533,7 @@ EXPORT_SYMBOL(write);
> int flush(int fd)
> {
> struct fs_driver *fsdrv;
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, false);
> int ret;
>
> if (IS_ERR(f))
> @@ -547,7 +551,7 @@ int flush(int fd)
> loff_t lseek(int fd, loff_t offset, int whence)
> {
> struct fs_driver *fsdrv;
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, false);
> loff_t pos;
> int ret;
>
> @@ -600,7 +604,7 @@ EXPORT_SYMBOL(lseek);
> int erase(int fd, loff_t count, loff_t offset)
> {
> struct fs_driver *fsdrv;
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, false);
> int ret;
>
> if (IS_ERR(f))
> @@ -629,7 +633,7 @@ EXPORT_SYMBOL(erase);
> int protect(int fd, size_t count, loff_t offset, int prot)
> {
> struct fs_driver *fsdrv;
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, false);
> int ret;
>
> if (IS_ERR(f))
> @@ -656,7 +660,7 @@ EXPORT_SYMBOL(protect);
> int discard_range(int fd, loff_t count, loff_t offset)
> {
> struct fs_driver *fsdrv;
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, false);
> int ret;
>
> if (IS_ERR(f))
> @@ -697,7 +701,7 @@ int protect_file(const char *file, int prot)
> void *memmap(int fd, int flags)
> {
> struct fs_driver *fsdrv;
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, false);
> void *retp = MAP_FAILED;
> int ret;
>
> @@ -721,20 +725,23 @@ EXPORT_SYMBOL(memmap);
>
> int close(int fd)
> {
> - struct fs_driver *fsdrv;
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, true);
> int ret = 0;
>
> if (IS_ERR(f))
> return -errno;
>
> - fsdrv = f->fsdev->driver;
> + if (!(f->flags & O_PATH)) {
> + struct fs_driver *fsdrv;
>
> - if (fsdrv != ramfs_driver)
> - assert_command_context();
> + fsdrv = f->fsdev->driver;
>
> - if (fsdrv->close)
> - ret = fsdrv->close(&f->fsdev->dev, f);
> + if (fsdrv != ramfs_driver)
> + assert_command_context();
> +
> + if (fsdrv->close)
> + ret = fsdrv->close(&f->fsdev->dev, f);
> + }
>
> put_file(f);
>
> @@ -1056,7 +1063,7 @@ static void stat_inode(struct inode *inode, struct stat *s)
>
> int fstat(int fd, struct stat *s)
> {
> - FILE *f = fd_to_file(fd);
> + FILE *f = fd_to_file(fd, true);
>
> if (IS_ERR(f))
> return -errno;
> @@ -2173,7 +2180,7 @@ static const char *path_init(int dirfd, struct nameidata *nd, unsigned flags)
> * whether paths are absolute with openat(-1, path, O_PATH)
> */
> if (dirfd != AT_FDCWD)
> - f = fd_to_file(dirfd);
> + f = fd_to_file(dirfd, true);
>
> if (*s == '/') {
> get_root(&nd->path);
> @@ -2590,7 +2597,7 @@ int openat(int dirfd, const char *pathname, int flags)
> error = -ENOENT;
> goto out1;
> }
> - } else {
> + } else if (!(flags & O_PATH)) {
> if (d_is_dir(dentry) && !dentry_is_tftp(dentry)) {
> error = -EISDIR;
> goto out1;
> @@ -2617,6 +2624,9 @@ int openat(int dirfd, const char *pathname, int flags)
>
> f->fsdev = fsdev;
>
> + if (flags & O_PATH)
> + return f->no;
> +
> if (fsdrv->open) {
> char *pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
>
> @@ -2653,7 +2663,7 @@ static const char *fd_getpath(int fd)
> if (fd < 0)
> return ERR_PTR(errno_set(fd));
>
> - f = fd_to_file(fd);
> + f = fd_to_file(fd, true);
> if (IS_ERR(f))
> return ERR_CAST(f);
>
> diff --git a/include/fcntl.h b/include/fcntl.h
> index a6ed50b92eaf..a3f5d96cd0ac 100644
> --- a/include/fcntl.h
> +++ b/include/fcntl.h
> @@ -23,6 +23,7 @@
> #define O_APPEND 00002000
> #define O_DIRECTORY 00200000 /* must be a directory */
> #define O_NOFOLLOW 00400000 /* don't follow links */
> +#define O_PATH 02000000 /* open as path */
> #define __O_TMPFILE 020000000
>
> #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
> --
> 2.39.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 036/112] fs: implement O_PATH
2024-01-05 11:22 ` Sascha Hauer
@ 2024-01-05 11:26 ` Ahmad Fatoum
0 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-05 11:26 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 05.01.24 12:22, Sascha Hauer wrote:
> On Wed, Jan 03, 2024 at 07:11:56PM +0100, Ahmad Fatoum wrote:
>> For use with the newly added openat and friends API, add O_PATH file
>> descriptors that are not usable for doing actual I/O, but only for use
>> as dirfd.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> fs/fs.c | 58 +++++++++++++++++++++++++++++--------------------
>> include/fcntl.h | 1 +
>> 2 files changed, 35 insertions(+), 24 deletions(-)
>>
>> diff --git a/fs/fs.c b/fs/fs.c
>> index 6b71440318af..54f38aa2e63b 100644
>> --- a/fs/fs.c
>> +++ b/fs/fs.c
>> @@ -325,12 +325,16 @@ static void put_file(FILE *f)
>> dput(f->dentry);
>> }
>>
>> -static FILE *fd_to_file(int fd)
>> +static FILE *fd_to_file(int fd, bool allow_pathonly)
>
> This parameter name confuses me. I read this as "only O_PATH is
> allowed". Maybe rename this to "o_path_allowed" or "o_path_ok"?
Yes, your suggestions sound better.
>
> Sascha
>
>> {
>> if (fd < 0 || fd >= MAX_FILES || !files[fd].in_use) {
>> errno = EBADF;
>> return ERR_PTR(-errno);
>> }
>> + if (!allow_pathonly && (files[fd].flags & O_PATH)) {
>> + errno = EINVAL;
>> + return ERR_PTR(-errno);
>> + }
>>
>> return &files[fd];
>> }
>> @@ -359,7 +363,7 @@ static int fsdev_truncate(struct device *dev, FILE *f, loff_t length)
>>
>> int ftruncate(int fd, loff_t length)
>> {
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, false);
>> int ret;
>>
>> if (IS_ERR(f))
>> @@ -381,7 +385,7 @@ int ftruncate(int fd, loff_t length)
>> int ioctl(int fd, int request, void *buf)
>> {
>> struct fs_driver *fsdrv;
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, false);
>> int ret;
>>
>> if (IS_ERR(f))
>> @@ -426,7 +430,7 @@ static ssize_t __read(FILE *f, void *buf, size_t count)
>> ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
>> {
>> loff_t pos;
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, false);
>> int ret;
>>
>> if (IS_ERR(f))
>> @@ -443,7 +447,7 @@ EXPORT_SYMBOL(pread);
>>
>> ssize_t read(int fd, void *buf, size_t count)
>> {
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, false);
>> int ret;
>>
>> if (IS_ERR(f))
>> @@ -495,7 +499,7 @@ static ssize_t __write(FILE *f, const void *buf, size_t count)
>> ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset)
>> {
>> loff_t pos;
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, false);
>> int ret;
>>
>> if (IS_ERR(f))
>> @@ -512,7 +516,7 @@ EXPORT_SYMBOL(pwrite);
>>
>> ssize_t write(int fd, const void *buf, size_t count)
>> {
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, false);
>> int ret;
>>
>> if (IS_ERR(f))
>> @@ -529,7 +533,7 @@ EXPORT_SYMBOL(write);
>> int flush(int fd)
>> {
>> struct fs_driver *fsdrv;
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, false);
>> int ret;
>>
>> if (IS_ERR(f))
>> @@ -547,7 +551,7 @@ int flush(int fd)
>> loff_t lseek(int fd, loff_t offset, int whence)
>> {
>> struct fs_driver *fsdrv;
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, false);
>> loff_t pos;
>> int ret;
>>
>> @@ -600,7 +604,7 @@ EXPORT_SYMBOL(lseek);
>> int erase(int fd, loff_t count, loff_t offset)
>> {
>> struct fs_driver *fsdrv;
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, false);
>> int ret;
>>
>> if (IS_ERR(f))
>> @@ -629,7 +633,7 @@ EXPORT_SYMBOL(erase);
>> int protect(int fd, size_t count, loff_t offset, int prot)
>> {
>> struct fs_driver *fsdrv;
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, false);
>> int ret;
>>
>> if (IS_ERR(f))
>> @@ -656,7 +660,7 @@ EXPORT_SYMBOL(protect);
>> int discard_range(int fd, loff_t count, loff_t offset)
>> {
>> struct fs_driver *fsdrv;
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, false);
>> int ret;
>>
>> if (IS_ERR(f))
>> @@ -697,7 +701,7 @@ int protect_file(const char *file, int prot)
>> void *memmap(int fd, int flags)
>> {
>> struct fs_driver *fsdrv;
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, false);
>> void *retp = MAP_FAILED;
>> int ret;
>>
>> @@ -721,20 +725,23 @@ EXPORT_SYMBOL(memmap);
>>
>> int close(int fd)
>> {
>> - struct fs_driver *fsdrv;
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, true);
>> int ret = 0;
>>
>> if (IS_ERR(f))
>> return -errno;
>>
>> - fsdrv = f->fsdev->driver;
>> + if (!(f->flags & O_PATH)) {
>> + struct fs_driver *fsdrv;
>>
>> - if (fsdrv != ramfs_driver)
>> - assert_command_context();
>> + fsdrv = f->fsdev->driver;
>>
>> - if (fsdrv->close)
>> - ret = fsdrv->close(&f->fsdev->dev, f);
>> + if (fsdrv != ramfs_driver)
>> + assert_command_context();
>> +
>> + if (fsdrv->close)
>> + ret = fsdrv->close(&f->fsdev->dev, f);
>> + }
>>
>> put_file(f);
>>
>> @@ -1056,7 +1063,7 @@ static void stat_inode(struct inode *inode, struct stat *s)
>>
>> int fstat(int fd, struct stat *s)
>> {
>> - FILE *f = fd_to_file(fd);
>> + FILE *f = fd_to_file(fd, true);
>>
>> if (IS_ERR(f))
>> return -errno;
>> @@ -2173,7 +2180,7 @@ static const char *path_init(int dirfd, struct nameidata *nd, unsigned flags)
>> * whether paths are absolute with openat(-1, path, O_PATH)
>> */
>> if (dirfd != AT_FDCWD)
>> - f = fd_to_file(dirfd);
>> + f = fd_to_file(dirfd, true);
>>
>> if (*s == '/') {
>> get_root(&nd->path);
>> @@ -2590,7 +2597,7 @@ int openat(int dirfd, const char *pathname, int flags)
>> error = -ENOENT;
>> goto out1;
>> }
>> - } else {
>> + } else if (!(flags & O_PATH)) {
>> if (d_is_dir(dentry) && !dentry_is_tftp(dentry)) {
>> error = -EISDIR;
>> goto out1;
>> @@ -2617,6 +2624,9 @@ int openat(int dirfd, const char *pathname, int flags)
>>
>> f->fsdev = fsdev;
>>
>> + if (flags & O_PATH)
>> + return f->no;
>> +
>> if (fsdrv->open) {
>> char *pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
>>
>> @@ -2653,7 +2663,7 @@ static const char *fd_getpath(int fd)
>> if (fd < 0)
>> return ERR_PTR(errno_set(fd));
>>
>> - f = fd_to_file(fd);
>> + f = fd_to_file(fd, true);
>> if (IS_ERR(f))
>> return ERR_CAST(f);
>>
>> diff --git a/include/fcntl.h b/include/fcntl.h
>> index a6ed50b92eaf..a3f5d96cd0ac 100644
>> --- a/include/fcntl.h
>> +++ b/include/fcntl.h
>> @@ -23,6 +23,7 @@
>> #define O_APPEND 00002000
>> #define O_DIRECTORY 00200000 /* must be a directory */
>> #define O_NOFOLLOW 00400000 /* don't follow links */
>> +#define O_PATH 02000000 /* open as path */
>> #define __O_TMPFILE 020000000
>>
>> #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
>> --
>> 2.39.2
>>
>>
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 037/112] fs: support different root directories
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (35 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 036/112] fs: implement O_PATH Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 038/112] fs: implement O_CHROOT Ahmad Fatoum
` (74 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
A root directory is a directory that has itself as the parent.
There is only one such directory, but for chroot support we will want to
stop path resolution at a non-root directory as well.
We do this by giving struct nameidata a d_root field, which serves as a
root directory for the lookup. As we initialize it to the global root
directory, this introduces no functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 54f38aa2e63b..7fc638451f13 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1623,6 +1623,7 @@ struct nameidata {
} *stack, internal[EMBEDDED_LEVELS];
struct filename *name;
struct inode *link_inode;
+ struct dentry *d_root;
};
struct filename {
@@ -1635,6 +1636,7 @@ static void set_nameidata(struct nameidata *p, struct filename *name)
p->stack = p->internal;
p->name = name;
p->total_link_count = 0;
+ p->d_root = d_root;
}
static void path_get(const struct path *path)
@@ -1820,16 +1822,16 @@ static int lookup_fast(struct nameidata *nd, struct path *path)
* Return 1 if we went up a level and 0 if we were already at the
* root.
*/
-static int follow_up(struct path *path)
+static int follow_up(struct nameidata *nd)
{
- struct vfsmount *parent, *mnt = path->mnt;
+ struct path *path = &nd->path;
+ struct vfsmount *mnt = path->mnt;
struct dentry *mountpoint;
- parent = mnt->parent;
- if (parent == mnt)
+ if (nd->d_root == path->dentry)
return 0;
- mntget(parent);
+ mntget(mnt->parent);
mountpoint = dget(mnt->mountpoint);
dput(path->dentry);
path->dentry = mountpoint;
@@ -1871,7 +1873,7 @@ static int follow_dotdot(struct nameidata *nd)
break;
}
- if (!follow_up(&nd->path))
+ if (!follow_up(nd))
break;
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 038/112] fs: implement O_CHROOT
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (36 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 037/112] fs: support different root directories Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:11 ` [PATCH 039/112] commands: introduce new findmnt command Ahmad Fatoum
` (73 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
For use by EFI file system path resolution, implement an O_CHROOT
flag that will map / to the root of the file system the dirfd points
to instead of the VFS root. If the dirfd points to a mountpoint, it will
be followed to the file system inside. This is similar to Linux openat2
with RESOLVE_IN_ROOT.
Without this, the EFI protocol would have to do path sanitization itself
before passing paths to the barebox VFS implementation.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 19 +++++++++++++++++--
include/fcntl.h | 1 +
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 7fc638451f13..5f46918caafe 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2166,9 +2166,17 @@ static int link_path_walk(const char *name, struct nameidata *nd)
}
}
+static bool file_has_flag(FILE *f, unsigned flag)
+{
+ if (IS_ERR_OR_NULL(f))
+ return false;
+ return (f->flags & flag) == flag;
+}
+
static const char *path_init(int dirfd, struct nameidata *nd, unsigned flags)
{
const char *s = nd->name->name;
+ bool chroot = false;
FILE *f = NULL;
nd->last_type = LAST_ROOT; /* if there are only slashes... */
@@ -2181,10 +2189,12 @@ static const char *path_init(int dirfd, struct nameidata *nd, unsigned flags)
/* We don't check for error here yet, as POSIX allows checking
* whether paths are absolute with openat(-1, path, O_PATH)
*/
- if (dirfd != AT_FDCWD)
+ if (dirfd != AT_FDCWD) {
f = fd_to_file(dirfd, true);
+ chroot = file_has_flag(f, O_CHROOT);
+ }
- if (*s == '/') {
+ if (*s == '/' && !chroot) {
get_root(&nd->path);
} else if (dirfd == AT_FDCWD) {
get_pwd(&nd->path);
@@ -2195,6 +2205,11 @@ static const char *path_init(int dirfd, struct nameidata *nd, unsigned flags)
nd->path.mnt = &f->fsdev->vfsmount;
nd->path.dentry = f->dentry;
follow_mount(&nd->path);
+
+ if (*s == '/')
+ nd->path.dentry = nd->path.mnt->mnt_root;
+ if (chroot)
+ nd->d_root = nd->path.mnt->mnt_root;
}
return s;
diff --git a/include/fcntl.h b/include/fcntl.h
index a3f5d96cd0ac..532a3a0f6b1e 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -24,6 +24,7 @@
#define O_DIRECTORY 00200000 /* must be a directory */
#define O_NOFOLLOW 00400000 /* don't follow links */
#define O_PATH 02000000 /* open as path */
+#define O_CHROOT 04000000 /* dirfd: stay within filesystem root */
#define __O_TMPFILE 020000000
#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 039/112] commands: introduce new findmnt command
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (37 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 038/112] fs: implement O_CHROOT Ahmad Fatoum
@ 2024-01-03 18:11 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 040/112] fs: initialize struct nameidata::last Ahmad Fatoum
` (72 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
EFI loader support will need to map barebox VFS paths to fs_device and
back. Make development easier by providing a findmnt command to test
the mapping.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/Kconfig | 15 +++++++
commands/Makefile | 1 +
commands/findmnt.c | 108 +++++++++++++++++++++++++++++++++++++++++++++
fs/fs.c | 4 +-
include/driver.h | 5 +++
include/fs.h | 2 +
6 files changed, 132 insertions(+), 3 deletions(-)
create mode 100644 commands/findmnt.c
diff --git a/commands/Kconfig b/commands/Kconfig
index d27c20478fcf..cd2eab801a84 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -655,6 +655,21 @@ config CMD_MOUNT
-o OPTIONS set file system OPTIONS
-v verbose
+config CMD_FINDMNT
+ tristate
+ prompt "findmnt"
+ help
+ Find a file system
+
+ Usage: findmnt [ DEVICE | -T FILE ]
+
+ findmnt will list all mounted filesystems or search
+ for a filesystem when given the mountpoint or the
+ source device as an argument
+
+ Options:
+ -T mount target file path
+
config CMD_UBI
tristate
default y if MTD_UBI
diff --git a/commands/Makefile b/commands/Makefile
index c8cb21a7db88..81bf5651ddc2 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_CMD_RM) += rm.o
obj-$(CONFIG_CMD_CAT) += cat.o
obj-$(CONFIG_CMD_MOUNT) += mount.o
obj-$(CONFIG_CMD_UMOUNT) += umount.o
+obj-$(CONFIG_CMD_FINDMNT) += findmnt.o
obj-$(CONFIG_CMD_REGINFO) += reginfo.o
obj-$(CONFIG_CMD_CRC) += crc.o
obj-$(CONFIG_CMD_CLEAR) += clear.o
diff --git a/commands/findmnt.c b/commands/findmnt.c
new file mode 100644
index 000000000000..da8f58835f28
--- /dev/null
+++ b/commands/findmnt.c
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: © 2022 Ahmad Fatoum, Pengutronix
+
+#include <common.h>
+#include <command.h>
+#include <fs.h>
+#include <errno.h>
+#include <getopt.h>
+
+static void print_header(bool *header_printed)
+{
+ if (*header_printed)
+ return;
+ printf("%-20s%-25s%-10s%-20s\n", "TARGET", "SOURCE", "FSTYPE", "OPTIONS");
+ *header_printed = true;
+}
+
+static void report_findmnt(const struct fs_device *fsdev)
+{
+ const char *backingstore;
+
+ backingstore = fsdev->backingstore ?: cdev_name(fsdev->cdev) ?: "none";
+
+ printf("%-20s%-25s%-10s%-20s\n", fsdev->path, backingstore,
+ fsdev->driver->drv.name, fsdev->options);
+}
+
+static int do_findmnt(int argc, char *argv[])
+{
+ bool header_printed = false;
+ struct fs_device *target = NULL;
+ char *device = NULL;
+ int opt, dirfd = AT_FDCWD;
+
+ while ((opt = getopt(argc, argv, "T:")) > 0) {
+ switch(opt) {
+ case 'T':
+ target = get_fsdevice_by_path(dirfd, optarg);
+ if (!target)
+ return COMMAND_ERROR;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ argv += optind;
+ argc -= optind;
+
+ if ((target && argc > 0) || (!target && argc > 1))
+ return COMMAND_ERROR_USAGE;
+
+ if (target) {
+ print_header(&header_printed);
+ report_findmnt(target);
+ return 0;
+ }
+
+ if (argv[0]) {
+ device = canonicalize_path(dirfd, argv[0]);
+ if (!device)
+ return COMMAND_ERROR;
+ }
+
+ for_each_fs_device(target) {
+ if (!device || streq_ptr(target->path, device) ||
+ streq_ptr(target->backingstore, device)) {
+ print_header(&header_printed);
+ report_findmnt(target);
+ } else {
+ const char *backingstore;
+ struct cdev *cdev;
+
+ cdev = cdev_by_name(devpath_to_name(device));
+ if (!cdev)
+ continue;
+
+ backingstore = target->backingstore;
+ backingstore += str_has_prefix(backingstore, "/dev/");
+
+ if (streq_ptr(backingstore, cdev->name)) {
+ print_header(&header_printed);
+ report_findmnt(target);
+ }
+ }
+ }
+
+ free(device);
+
+ return header_printed ? 0 : COMMAND_ERROR;
+}
+
+BAREBOX_CMD_HELP_START(findmnt)
+BAREBOX_CMD_HELP_TEXT("findmnt will list all mounted filesystems or search")
+BAREBOX_CMD_HELP_TEXT("for a filesystem when given the mountpoint or the")
+BAREBOX_CMD_HELP_TEXT("source device as an argument")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-T", "mount target file path")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(findmnt)
+ .cmd = do_findmnt,
+ BAREBOX_CMD_DESC("find a file system")
+ BAREBOX_CMD_OPTS("[ DEVICE | -T FILE ]")
+ BAREBOX_CMD_GROUP(CMD_GRP_FILE)
+ BAREBOX_CMD_HELP(cmd_findmnt_help)
+BAREBOX_CMD_END
diff --git a/fs/fs.c b/fs/fs.c
index 5f46918caafe..bd6b9f504adb 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -130,8 +130,6 @@ void cdev_print(const struct cdev *cdev)
}
EXPORT_SYMBOL(cdev_print);
-static struct fs_device *get_fsdevice_by_path(int dirfd, const char *path);
-
void stat_print(const char *filename, const struct stat *st)
{
int dirfd = AT_FDCWD;
@@ -2383,7 +2381,7 @@ static int filename_lookup(int dirfd, struct filename *name, unsigned flags,
return err;
}
-static struct fs_device *get_fsdevice_by_path(int dirfd, const char *pathname)
+struct fs_device *get_fsdevice_by_path(int dirfd, const char *pathname)
{
struct fs_device *fsdev;
struct path path;
diff --git a/include/driver.h b/include/driver.h
index b6fe8712837b..7a8b46ac4109 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -568,6 +568,11 @@ static inline void cdev_set_of_node(struct cdev *cdev, struct device_node *np)
cdev->device_node = np;
}
+static inline const char *cdev_name(struct cdev *cdev)
+{
+ return cdev ? cdev->name : NULL;
+}
+
int devfs_create(struct cdev *);
int devfs_create_link(struct cdev *, const char *name);
int devfs_remove(struct cdev *);
diff --git a/include/fs.h b/include/fs.h
index c4af8659b0d3..020761692cad 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -152,6 +152,8 @@ void cdev_print(const struct cdev *cdev);
char *canonicalize_path(int dirfd, const char *pathname);
+struct fs_device *get_fsdevice_by_path(int dirfd, const char *path);
+
char *get_mounted_path(const char *path);
struct cdev *get_cdev_by_mountpath(const char *path);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 040/112] fs: initialize struct nameidata::last
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (38 preceding siblings ...)
2024-01-03 18:11 ` [PATCH 039/112] commands: introduce new findmnt command Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 041/112] fs: support opening / Ahmad Fatoum
` (71 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The last member is normally written by link_path_walk(), before being
read by __lookup_hash, among others.
In the special case of calling open() on "/", link_path_walk() will
terminate early without setting the last member, leading __d_alloc
called by __lookup_hash to read uninitialized memory.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/fs.c b/fs/fs.c
index bd6b9f504adb..74ece0e9a7d0 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1631,6 +1631,7 @@ struct filename {
static void set_nameidata(struct nameidata *p, struct filename *name)
{
+ p->last = slash_name;
p->stack = p->internal;
p->name = name;
p->total_link_count = 0;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 041/112] fs: support opening /
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (39 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 040/112] fs: initialize struct nameidata::last Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 042/112] test: self: add dirfd tests Ahmad Fatoum
` (70 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
With open() on / no longer accessing uninitialized memory, it now always
fails with errno == ENOENT. This is because d_lookup only compares
children of /, but never / itself.
Fix this by comparing the parent and while at it, rework the existing
code to be more concise.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 74ece0e9a7d0..220b4d95cdb1 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1502,7 +1502,6 @@ void d_add(struct dentry *dentry, struct inode *inode)
}
static bool d_same_name(const struct dentry *dentry,
- const struct dentry *parent,
const struct qstr *name)
{
if (dentry->d_name.len != name->len)
@@ -1511,17 +1510,16 @@ static bool d_same_name(const struct dentry *dentry,
return strncmp(dentry->d_name.name, name->name, name->len) == 0;
}
-static struct dentry *d_lookup(const struct dentry *parent, const struct qstr *name)
+static struct dentry *d_lookup(struct dentry *parent, const struct qstr *name)
{
struct dentry *dentry;
+ if (d_same_name(parent, name))
+ return dget(parent);
+
list_for_each_entry(dentry, &parent->d_subdirs, d_child) {
- if (!d_same_name(dentry, parent, name))
- continue;
-
- dget(dentry);
-
- return dentry;
+ if (d_same_name(dentry, name))
+ return dget(dentry);
}
return NULL;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 042/112] test: self: add dirfd tests
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (40 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 041/112] fs: support opening / Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 043/112] commands: stat: add option for statat Ahmad Fatoum
` (69 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Adding directory fds involved a bit of rework to the VFS layer.
We have ramfs tests that check the previous behavior, so add now tests
to check that path resolution in openat and statat work as one would expect.
As we need a separate file system to test O_CHROOT, the test has a
dependency on the devfs.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
test/self/Kconfig | 5 ++
test/self/Makefile | 1 +
test/self/dirfd.c | 129 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 135 insertions(+)
create mode 100644 test/self/dirfd.c
diff --git a/test/self/Kconfig b/test/self/Kconfig
index 6b9a4bf4a6e4..33e478aee882 100644
--- a/test/self/Kconfig
+++ b/test/self/Kconfig
@@ -34,6 +34,7 @@ config SELFTEST_ENABLE_ALL
select SELFTEST_OF_MANIPULATION
select SELFTEST_ENVIRONMENT_VARIABLES if ENVIRONMENT_VARIABLES
select SELFTEST_FS_RAMFS if FS_RAMFS
+ select SELFTEST_DIRFD if FS_RAMFS && FS_DEVFS
select SELFTEST_TFTP if FS_TFTP
select SELFTEST_JSON if JSMN
select SELFTEST_JWT if JWT
@@ -73,6 +74,10 @@ config SELFTEST_FS_RAMFS
bool "ramfs selftest"
depends on FS_RAMFS
+config SELFTEST_DIRFD
+ bool "dirfd selftest"
+ depends on FS_RAMFS && FS_DEVFS
+
config SELFTEST_JSON
bool "JSON selftest"
depends on JSMN
diff --git a/test/self/Makefile b/test/self/Makefile
index 51131474f333..fbc186725487 100644
--- a/test/self/Makefile
+++ b/test/self/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_SELFTEST_PROGRESS_NOTIFIER) += progress-notifier.o
obj-$(CONFIG_SELFTEST_OF_MANIPULATION) += of_manipulation.o of_manipulation.dtb.o
obj-$(CONFIG_SELFTEST_ENVIRONMENT_VARIABLES) += envvar.o
obj-$(CONFIG_SELFTEST_FS_RAMFS) += ramfs.o
+obj-$(CONFIG_SELFTEST_DIRFD) += dirfd.o
obj-$(CONFIG_SELFTEST_JSON) += json.o
obj-$(CONFIG_SELFTEST_JWT) += jwt.o jwt_test.pem.o
obj-$(CONFIG_SELFTEST_DIGEST) += digest.o
diff --git a/test/self/dirfd.c b/test/self/dirfd.c
new file mode 100644
index 000000000000..20b54258715a
--- /dev/null
+++ b/test/self/dirfd.c
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <common.h>
+#include <fcntl.h>
+#include <fs.h>
+#include <string.h>
+#include <linux/bitfield.h>
+#include <unistd.h>
+#include <bselftest.h>
+
+BSELFTEST_GLOBALS();
+
+#define expect(cond, res, fmt, ...) ({ \
+ int __cond = (cond); \
+ int __res = (res); \
+ total_tests++; \
+ if (__cond != __res) { \
+ failed_tests++; \
+ printf("%s:%d failed: %s == %d: " fmt "\n", \
+ __func__, __LINE__, #cond, __cond, ##__VA_ARGS__); \
+ } \
+ __cond == __res; \
+})
+
+static void check_statat(const char *at, int dirfd, const char *prefix, unsigned expected)
+{
+ static const char *paths[] = { ".", "..", "zero", "dev" };
+ struct stat s;
+
+ for (int i = 0; i < ARRAY_SIZE(paths); i++) {
+ const char *path = paths[i];
+ char *fullpath = NULL, *testpath = basprintf("%s%s", prefix, path);
+ struct fs_device *fsdev1, *fsdev2;
+ int ret;
+
+ ret = statat(dirfd, testpath, &s);
+ if (!expect(ret == 0, FIELD_GET(BIT(2), expected),
+ "statat(%s, %s): %m", at, testpath))
+ goto next;
+
+ fullpath = canonicalize_path(dirfd, testpath);
+ if (!expect(fullpath != NULL, FIELD_GET(BIT(1), expected),
+ "canonicalize_path(%s, %s): %m", at, testpath))
+ goto next;
+
+ if (!fullpath)
+ goto next;
+
+ fsdev1 = get_fsdevice_by_path(AT_FDCWD, fullpath);
+ if (!expect(IS_ERR_OR_NULL(fsdev1), false, "get_fsdevice_by_path(AT_FDCWD, %s)",
+ fullpath))
+ goto next;
+
+ fsdev2 = get_fsdevice_by_path(dirfd, testpath);
+ if (!expect(IS_ERR_OR_NULL(fsdev1), false, "get_fsdevice_by_path(%s, %s)",
+ at, testpath))
+ goto next;
+
+ if (!expect(fsdev1 == fsdev2, true,
+ "get_fsdevice_by_path(%s, %s) != get_fsdevice_by_path(AT_FDCWD, %s)",
+ fullpath, at, testpath))
+ goto next;
+
+ ret = strcmp_ptr(fsdev1->path, "/dev");
+ if (!expect(ret == 0, FIELD_GET(BIT(0), expected),
+ "fsdev_of(%s)->path = %s != /dev", fullpath, fsdev1->path))
+ goto next;
+
+next:
+ expected >>= 3;
+ free(testpath);
+ free(fullpath);
+ }
+}
+
+static void do_test_dirfd(const char *at, int dirfd,
+ unsigned expected1, unsigned expected2,
+ unsigned expected3, unsigned expected4)
+{
+ if (dirfd < 0 && dirfd != AT_FDCWD)
+ return;
+
+ check_statat(at, dirfd, "", expected1);
+ check_statat(at, dirfd, "./", expected1);
+ check_statat(at, dirfd, "/dev/", expected2);
+ check_statat(at, dirfd, "/dev/./", expected2);
+ check_statat(at, dirfd, "/dev/../dev/", expected2);
+ check_statat(at, dirfd, "/", expected3);
+ check_statat(at, dirfd, "../", expected4);
+
+ if (dirfd >= 0)
+ close(dirfd);
+}
+
+
+static void test_dirfd(void)
+{
+ int fd;
+
+ fd = open("/", O_PATH);
+ if (expect(fd < 0, false, "open(/, O_PATH) = %d", fd))
+ close(fd);
+
+#define B(dot, dotdot, zero, dev) 0b##dev##zero##dotdot##dot
+ /* We do fiften tests for every configuration
+ * for dir in ./ /dev / ../ ; do
+ * for file in . .. zero dev ; do
+ * test if file exists
+ * test if file can be canonicalized
+ * test if parent FS is mounted at /dev
+ * done
+ * done
+ *
+ * The bits belows correspond to whether a test fails in the above loop
+ */
+
+ do_test_dirfd("AT_FDCWD", AT_FDCWD,
+ B(110,110,000,111), B(111,110,111,000),
+ B(110,110,000,111), B(110,110,000,111));
+ do_test_dirfd("/dev", open("/dev", O_PATH),
+ B(111,110,111,000), B(111,110,111,000),
+ B(110,110,000,111), B(110,110,000,111));
+ do_test_dirfd("/dev O_CHROOT", open("/dev", O_PATH | O_CHROOT),
+ B(111,111,111,000), B(000,000,000,000),
+ B(111,111,111,000), B(111,111,111,000));
+}
+bselftest(core, test_dirfd);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 043/112] commands: stat: add option for statat
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (41 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 042/112] test: self: add dirfd tests Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 044/112] efi: payload: lower command line options print from error to info Ahmad Fatoum
` (68 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The stat command is a debugging aid for developing the VFS, so it makes
sense to add support for dirfd, so they can be tested interactively.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/Kconfig | 6 ++++--
commands/stat.c | 26 +++++++++++++++++++-------
fs/fs.c | 5 ++---
include/fs.h | 2 +-
4 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/commands/Kconfig b/commands/Kconfig
index cd2eab801a84..eddfbee208a1 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -990,12 +990,14 @@ config CMD_STAT
help
Display file status
- Usage: stat [-L] [FILEDIR...]
+ Usage: stat [-LcC] [FILEDIR...]
Display status information about the specified files or directories.
Options:
- -L follow symlinks
+ -L follow symlinks
+ -c DIR lookup file relative to directory DIR
+ -C DIR change root to DIR before file lookup
config CMD_MD5SUM
tristate
diff --git a/commands/stat.c b/commands/stat.c
index 153eac50f1fa..10662005cdda 100644
--- a/commands/stat.c
+++ b/commands/stat.c
@@ -12,15 +12,23 @@
static int do_stat(int argc, char *argv[])
{
- int (*statfn)(const char *, struct stat *) = lstat;
- int ret, opt, exitcode = 0;
+ int (*statfn)(int dirfd, const char *, struct stat *) = lstatat;
+ int ret, opt, dirfd = AT_FDCWD, extra_flags = 0, exitcode = 0;
char **filename;
struct stat st;
- while((opt = getopt(argc, argv, "L")) > 0) {
+ while((opt = getopt(argc, argv, "Lc:C:")) > 0) {
switch(opt) {
case 'L':
- statfn = stat;
+ statfn = statat;
+ break;
+ case 'C':
+ extra_flags |= O_CHROOT;
+ fallthrough;
+ case 'c':
+ dirfd = open(optarg, O_PATH | extra_flags);
+ if (dirfd < 0)
+ return dirfd;
break;
default:
return COMMAND_ERROR_USAGE;
@@ -31,7 +39,7 @@ static int do_stat(int argc, char *argv[])
return COMMAND_ERROR_USAGE;
for (filename = &argv[optind]; *filename; filename++) {
- ret = statfn(*filename, &st);
+ ret = statfn(dirfd, *filename, &st);
if (ret) {
printf("%s: %s: %m\n", argv[0], *filename);
@@ -39,9 +47,11 @@ static int do_stat(int argc, char *argv[])
continue;
}
- stat_print(*filename, &st);
+ stat_print(dirfd, *filename, &st);
}
+ close(dirfd);
+
return exitcode;
}
@@ -51,12 +61,14 @@ BAREBOX_CMD_HELP_TEXT("or directories.")
BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT ("-L", "follow links")
+BAREBOX_CMD_HELP_OPT ("-c DIR", "lookup file relative to directory DIR")
+BAREBOX_CMD_HELP_OPT ("-C DIR", "change root to DIR before file lookup")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(stat)
.cmd = do_stat,
BAREBOX_CMD_DESC("display file status")
- BAREBOX_CMD_OPTS("[-L] [FILEDIR...]")
+ BAREBOX_CMD_OPTS("[-LcC] [FILEDIR...]")
BAREBOX_CMD_GROUP(CMD_GRP_FILE)
BAREBOX_CMD_HELP(cmd_stat_help)
BAREBOX_CMD_END
diff --git a/fs/fs.c b/fs/fs.c
index 220b4d95cdb1..fc9e56168c9c 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -130,9 +130,8 @@ void cdev_print(const struct cdev *cdev)
}
EXPORT_SYMBOL(cdev_print);
-void stat_print(const char *filename, const struct stat *st)
+void stat_print(int dirfd, const char *filename, const struct stat *st)
{
- int dirfd = AT_FDCWD;
struct block_device *bdev = NULL;
struct fs_device *fdev;
struct cdev *cdev = NULL;
@@ -177,7 +176,7 @@ void stat_print(const char *filename, const struct stat *st)
char realname[PATH_MAX] = {};
int ret;
- ret = readlink(filename, realname, PATH_MAX - 1);
+ ret = readlinkat(dirfd, filename, realname, PATH_MAX - 1);
if (ret)
printf(" -> <readlink error %pe>", ERR_PTR(ret));
else
diff --git a/include/fs.h b/include/fs.h
index 020761692cad..70903142e89b 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -147,7 +147,7 @@ int ls(const char *path, ulong flags);
char *mkmodestr(unsigned long mode, char *str);
-void stat_print(const char *filename, const struct stat *st);
+void stat_print(int dirfd, const char *filename, const struct stat *st);
void cdev_print(const struct cdev *cdev);
char *canonicalize_path(int dirfd, const char *pathname);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 044/112] efi: payload: lower command line options print from error to info
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (42 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 043/112] commands: stat: add option for statat Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 045/112] efi: payload: init: warn if /boot FS is unknown Ahmad Fatoum
` (67 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
What command line arguments are passed is informational at best and
doesn't warrant an error log level.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/image.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/efi/payload/image.c b/efi/payload/image.c
index a8748da1df88..fb77ce4437fc 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -177,7 +177,7 @@ static int efi_execute_image(const char *file)
image_header->header == 0x53726448) {
pr_debug("Linux kernel detected. Adding bootargs.");
options = linux_bootargs_get();
- pr_err("add linux options '%s'\n", options);
+ pr_info("add linux options '%s'\n", options);
if (options) {
loaded_image->load_options = xstrdup_char_to_wchar(options);
loaded_image->load_options_size =
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 045/112] efi: payload: init: warn if /boot FS is unknown
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (43 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 044/112] efi: payload: lower command line options print from error to info Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 046/112] commands: time: refactor into new strjoin Ahmad Fatoum
` (66 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The initcall's only function is to open /boot/EFI/barebox/state.dtb
and to register it as barebox state description. If nothing is mounted
at /boot, this will fail anyway, so early exit in that case.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/init.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/efi/payload/init.c b/efi/payload/init.c
index 8a9080115ffd..6d65f6d53464 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -9,6 +9,8 @@
#define DEBUG
#endif
+#define pr_fmt(fmt) "efi-init: " fmt
+
#include <linux/linkage.h>
#include <common.h>
#include <linux/sizes.h>
@@ -395,6 +397,11 @@ static int efi_late_init(void)
if (!IS_ENABLED(CONFIG_STATE))
return 0;
+ if (!get_mounted_path("/boot")) {
+ pr_warn("boot device couldn't be determined\n");
+ return 0;
+ }
+
fdt = read_file(state_desc, &size);
if (!fdt) {
pr_info("unable to read %s: %m\n", state_desc);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 046/112] commands: time: refactor into new strjoin
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (44 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 045/112] efi: payload: init: warn if /boot FS is unknown Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 047/112] string: reduce strjoin runtime, drop trailing separator Ahmad Fatoum
` (65 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
time concatenates all its remaining arguments with a space in-between
and then passes that to the command executor. This can be useful
elsewhere as well, so factor it out into a new strjoin function.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/time.c | 11 +----------
include/string.h | 2 ++
lib/string.c | 23 +++++++++++++++++++++++
3 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/commands/time.c b/commands/time.c
index 5b8933ea6553..336128f6a9be 100644
--- a/commands/time.c
+++ b/commands/time.c
@@ -12,26 +12,17 @@ static int do_time(int argc, char *argv[])
unsigned char *buf;
u64 start, end, diff64;
bool nanoseconds = false;
- int len = 1; /* '\0' */
if (argc < 2)
return COMMAND_ERROR_USAGE;
- for (i = 1; i < argc; i++)
- len += strlen(argv[i]) + 1;
-
- buf = xzalloc(len);
-
i = 1;
if (!strcmp(argv[i], "-n")) {
nanoseconds = true;
i++;
}
- for (; i < argc; i++) {
- strcat(buf, argv[i]);
- strcat(buf, " ");
- }
+ buf = strjoin(" ", &argv[i], argc - i);
start = get_time_ns();
diff --git a/include/string.h b/include/string.h
index 71810180b5ba..2f2af85b554f 100644
--- a/include/string.h
+++ b/include/string.h
@@ -21,6 +21,8 @@ char *parse_assignment(char *str);
int strverscmp(const char *a, const char *b);
+char *strjoin(const char *separator, char **array, size_t len);
+
static inline int strcmp_ptr(const char *a, const char *b)
{
return a && b ? strcmp(a, b) : compare3(a, b);
diff --git a/lib/string.c b/lib/string.c
index bf0f0455ab3f..d8e5edd40648 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -1000,3 +1000,26 @@ char *parse_assignment(char *str)
return value;
}
+
+char *strjoin(const char *separator, char **arr, size_t arrlen)
+{
+ size_t separatorlen;
+ int len = 1; /* '\0' */
+ char *buf;
+ int i;
+
+ separatorlen = strlen(separator);
+
+ for (i = 0; i < arrlen; i++)
+ len += strlen(arr[i]) + separatorlen;
+
+ buf = xzalloc(len);
+
+ for (i = 0; i < arrlen; i++) {
+ strcat(buf, arr[i]);
+ strcat(buf, separator);
+ }
+
+ return buf;
+}
+EXPORT_SYMBOL(strjoin);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 047/112] string: reduce strjoin runtime, drop trailing separator
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (45 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 046/112] commands: time: refactor into new strjoin Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-08 7:11 ` Sascha Hauer
2024-01-03 18:12 ` [PATCH 048/112] test: self: add strjoin tests Ahmad Fatoum
` (64 subsequent siblings)
111 siblings, 1 reply; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The implementation of strjoin is a bit suboptimal. The destination
string is traversed from the beginning due to strcat and we have a
left-over separator at the end, while it should only be in-between.
Fix this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Originally posted at: https://lore.barebox.org/barebox/20221027073334.GS6702@pengutronix.de/
Changes:
- remove if statemnt in loop (Sascha)
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
lib/string.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/lib/string.c b/lib/string.c
index d8e5edd40648..695e50bc8fc1 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -1005,7 +1005,7 @@ char *strjoin(const char *separator, char **arr, size_t arrlen)
{
size_t separatorlen;
int len = 1; /* '\0' */
- char *buf;
+ char *buf, *p;
int i;
separatorlen = strlen(separator);
@@ -1013,13 +1013,18 @@ char *strjoin(const char *separator, char **arr, size_t arrlen)
for (i = 0; i < arrlen; i++)
len += strlen(arr[i]) + separatorlen;
- buf = xzalloc(len);
+ if (!arrlen)
+ return xzalloc(1);
- for (i = 0; i < arrlen; i++) {
- strcat(buf, arr[i]);
- strcat(buf, separator);
+ p = buf = xmalloc(len);
+
+ for (i = 0; i < arrlen - 1; i++) {
+ p = stpcpy(p, arr[i]);
+ p = mempcpy(p, separator, separatorlen);
}
+ stpcpy(p, arr[i]);
+
return buf;
}
EXPORT_SYMBOL(strjoin);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 047/112] string: reduce strjoin runtime, drop trailing separator
2024-01-03 18:12 ` [PATCH 047/112] string: reduce strjoin runtime, drop trailing separator Ahmad Fatoum
@ 2024-01-08 7:11 ` Sascha Hauer
2024-01-08 7:18 ` Ahmad Fatoum
0 siblings, 1 reply; 134+ messages in thread
From: Sascha Hauer @ 2024-01-08 7:11 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Jan 03, 2024 at 07:12:07PM +0100, Ahmad Fatoum wrote:
> The implementation of strjoin is a bit suboptimal. The destination
> string is traversed from the beginning due to strcat and we have a
> left-over separator at the end, while it should only be in-between.
>
> Fix this.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> Originally posted at: https://lore.barebox.org/barebox/20221027073334.GS6702@pengutronix.de/
Once again I ended up reviewing a suboptimal version of strjoin() first
just to find my potential comments addressed in the next patch. So my
comment to the last version still stands: Please implement a good
version of strjoin() first and then switch over to use it.
>
> Changes:
> - remove if statemnt in loop (Sascha)
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> lib/string.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/lib/string.c b/lib/string.c
> index d8e5edd40648..695e50bc8fc1 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -1005,7 +1005,7 @@ char *strjoin(const char *separator, char **arr, size_t arrlen)
> {
> size_t separatorlen;
> int len = 1; /* '\0' */
> - char *buf;
> + char *buf, *p;
> int i;
>
> separatorlen = strlen(separator);
> @@ -1013,13 +1013,18 @@ char *strjoin(const char *separator, char **arr, size_t arrlen)
> for (i = 0; i < arrlen; i++)
> len += strlen(arr[i]) + separatorlen;
Not that it matters much for memory usage, but for consistency you could
drop the final separatorlen just like you did for copying the strings
below.
Sascha
>
> - buf = xzalloc(len);
> + if (!arrlen)
> + return xzalloc(1);
>
> - for (i = 0; i < arrlen; i++) {
> - strcat(buf, arr[i]);
> - strcat(buf, separator);
> + p = buf = xmalloc(len);
> +
> + for (i = 0; i < arrlen - 1; i++) {
> + p = stpcpy(p, arr[i]);
> + p = mempcpy(p, separator, separatorlen);
> }
>
> + stpcpy(p, arr[i]);
> +
> return buf;
> }
> EXPORT_SYMBOL(strjoin);
> --
> 2.39.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 047/112] string: reduce strjoin runtime, drop trailing separator
2024-01-08 7:11 ` Sascha Hauer
@ 2024-01-08 7:18 ` Ahmad Fatoum
2024-01-08 7:43 ` Sascha Hauer
0 siblings, 1 reply; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-08 7:18 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 08.01.24 08:11, Sascha Hauer wrote:
> On Wed, Jan 03, 2024 at 07:12:07PM +0100, Ahmad Fatoum wrote:
>> The implementation of strjoin is a bit suboptimal. The destination
>> string is traversed from the beginning due to strcat and we have a
>> left-over separator at the end, while it should only be in-between.
>>
>> Fix this.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> Originally posted at: https://lore.barebox.org/barebox/20221027073334.GS6702@pengutronix.de/
>
> Once again I ended up reviewing a suboptimal version of strjoin() first
> just to find my potential comments addressed in the next patch. So my
> comment to the last version still stands: Please implement a good
> version of strjoin() first and then switch over to use it.
The first patch just moves code around. I find it completely valid to move
code before doing changes to it...
>
>>
>> Changes:
>> - remove if statemnt in loop (Sascha)
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> lib/string.c | 15 ++++++++++-----
>> 1 file changed, 10 insertions(+), 5 deletions(-)
>>
>> diff --git a/lib/string.c b/lib/string.c
>> index d8e5edd40648..695e50bc8fc1 100644
>> --- a/lib/string.c
>> +++ b/lib/string.c
>> @@ -1005,7 +1005,7 @@ char *strjoin(const char *separator, char **arr, size_t arrlen)
>> {
>> size_t separatorlen;
>> int len = 1; /* '\0' */
>> - char *buf;
>> + char *buf, *p;
>> int i;
>>
>> separatorlen = strlen(separator);
>> @@ -1013,13 +1013,18 @@ char *strjoin(const char *separator, char **arr, size_t arrlen)
>> for (i = 0; i < arrlen; i++)
>> len += strlen(arr[i]) + separatorlen;
>
> Not that it matters much for memory usage, but for consistency you could
> drop the final separatorlen just like you did for copying the strings
> below.
>
> Sascha
>
>>
>> - buf = xzalloc(len);
>> + if (!arrlen)
>> + return xzalloc(1);
>>
>> - for (i = 0; i < arrlen; i++) {
>> - strcat(buf, arr[i]);
>> - strcat(buf, separator);
>> + p = buf = xmalloc(len);
>> +
>> + for (i = 0; i < arrlen - 1; i++) {
>> + p = stpcpy(p, arr[i]);
>> + p = mempcpy(p, separator, separatorlen);
>> }
>>
>> + stpcpy(p, arr[i]);
>> +
>> return buf;
>> }
>> EXPORT_SYMBOL(strjoin);
>> --
>> 2.39.2
>>
>>
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 047/112] string: reduce strjoin runtime, drop trailing separator
2024-01-08 7:18 ` Ahmad Fatoum
@ 2024-01-08 7:43 ` Sascha Hauer
0 siblings, 0 replies; 134+ messages in thread
From: Sascha Hauer @ 2024-01-08 7:43 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Jan 08, 2024 at 08:18:46AM +0100, Ahmad Fatoum wrote:
> On 08.01.24 08:11, Sascha Hauer wrote:
> > On Wed, Jan 03, 2024 at 07:12:07PM +0100, Ahmad Fatoum wrote:
> >> The implementation of strjoin is a bit suboptimal. The destination
> >> string is traversed from the beginning due to strcat and we have a
> >> left-over separator at the end, while it should only be in-between.
> >>
> >> Fix this.
> >>
> >> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> >> ---
> >> Originally posted at: https://lore.barebox.org/barebox/20221027073334.GS6702@pengutronix.de/
> >
> > Once again I ended up reviewing a suboptimal version of strjoin() first
> > just to find my potential comments addressed in the next patch. So my
> > comment to the last version still stands: Please implement a good
> > version of strjoin() first and then switch over to use it.
>
> The first patch just moves code around. I find it completely valid to move
> code before doing changes to it...
I find this valid as well, but you have not just moved it around, you
have introduced a new library function in the same step. As such it
should be in good shape when introducing it.
Sascha
>
> >
> >>
> >> Changes:
> >> - remove if statemnt in loop (Sascha)
> >> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> >> ---
> >> lib/string.c | 15 ++++++++++-----
> >> 1 file changed, 10 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/lib/string.c b/lib/string.c
> >> index d8e5edd40648..695e50bc8fc1 100644
> >> --- a/lib/string.c
> >> +++ b/lib/string.c
> >> @@ -1005,7 +1005,7 @@ char *strjoin(const char *separator, char **arr, size_t arrlen)
> >> {
> >> size_t separatorlen;
> >> int len = 1; /* '\0' */
> >> - char *buf;
> >> + char *buf, *p;
> >> int i;
> >>
> >> separatorlen = strlen(separator);
> >> @@ -1013,13 +1013,18 @@ char *strjoin(const char *separator, char **arr, size_t arrlen)
> >> for (i = 0; i < arrlen; i++)
> >> len += strlen(arr[i]) + separatorlen;
> >
> > Not that it matters much for memory usage, but for consistency you could
> > drop the final separatorlen just like you did for copying the strings
> > below.
> >
> > Sascha
> >
> >>
> >> - buf = xzalloc(len);
> >> + if (!arrlen)
> >> + return xzalloc(1);
> >>
> >> - for (i = 0; i < arrlen; i++) {
> >> - strcat(buf, arr[i]);
> >> - strcat(buf, separator);
> >> + p = buf = xmalloc(len);
> >> +
> >> + for (i = 0; i < arrlen - 1; i++) {
> >> + p = stpcpy(p, arr[i]);
> >> + p = mempcpy(p, separator, separatorlen);
> >> }
> >>
> >> + stpcpy(p, arr[i]);
> >> +
> >> return buf;
> >> }
> >> EXPORT_SYMBOL(strjoin);
> >> --
> >> 2.39.2
> >>
> >>
> >>
> >
>
> --
> Pengutronix e.K. | |
> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 048/112] test: self: add strjoin tests
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (46 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 047/112] string: reduce strjoin runtime, drop trailing separator Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 049/112] filetype: have cdev_detect_type take a cdev Ahmad Fatoum
` (63 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Just to make sure strjoin works as intended, add some simple unit tests.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
test/self/string.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/test/self/string.c b/test/self/string.c
index f03a7410cd64..d33e2d7918ca 100644
--- a/test/self/string.c
+++ b/test/self/string.c
@@ -168,8 +168,36 @@ static void test_strverscmp(void)
strverscmp_assert_one("", "", 0);
}
+static void __expect_streq(const char *func, int line,
+ char *is, const char *expect, bool free_is)
+{
+ total_tests++;
+ if (strcmp(is, expect)) {
+ failed_tests++;
+ printf("%s:%d: got %s, but %s expected\n", func, line, is, expect);
+ }
+
+ if (free_is)
+ free(is);
+}
+
+#define expect_dynstreq(args...) \
+ __expect_streq(__func__, __LINE__, args, true)
+
+static void test_strjoin(void)
+{
+ char *strs[] = { "ayy", "bee", "cee" };
+
+ expect_dynstreq(strjoin("", strs, ARRAY_SIZE(strs)), "ayybeecee");
+ expect_dynstreq(strjoin(" ", strs, ARRAY_SIZE(strs)), "ayy bee cee");
+ expect_dynstreq(strjoin(", ", strs, ARRAY_SIZE(strs)), "ayy, bee, cee");
+ expect_dynstreq(strjoin(" ", strs, 1), "ayy");
+ expect_dynstreq(strjoin(" ", NULL, 0), "");
+}
+
static void test_string(void)
{
test_strverscmp();
+ test_strjoin();
}
bselftest(parser, test_string);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 049/112] filetype: have cdev_detect_type take a cdev
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (47 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 048/112] test: self: add strjoin tests Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 050/112] ARM: mmu-early: gracefully handle already enabled MMU Ahmad Fatoum
` (62 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
cdev_detect_type reads as if it would take a cdev argument, but instead
it takes the adev's path. Fix it, so it takes a cdev and change the
only user. A new user will be added later that will pass in an already
open cdev.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/filetype.c | 12 ++----------
fs/fs.c | 14 +++++++++++---
include/filetype.h | 4 +++-
3 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/common/filetype.c b/common/filetype.c
index 43d292c27baf..f726a933d245 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -450,20 +450,14 @@ int file_name_detect_type(const char *filename, enum filetype *type)
return file_name_detect_type_offset(filename, 0, type);
}
-int cdev_detect_type(const char *name, enum filetype *type)
+int cdev_detect_type(struct cdev *cdev, enum filetype *type)
{
int ret;
- struct cdev *cdev;
void *buf;
- cdev = cdev_open_by_name(name, O_RDONLY);
- if (!cdev)
- return -ENOENT;
-
if (cdev->filetype != filetype_unknown) {
*type = cdev->filetype;
- ret = 0;
- goto cdev_close;
+ return 0;
}
buf = xzalloc(FILE_TYPE_SAFE_BUFSIZE);
@@ -476,8 +470,6 @@ int cdev_detect_type(const char *name, enum filetype *type)
err_out:
free(buf);
-cdev_close:
- cdev_close(cdev);
return ret;
}
diff --git a/fs/fs.c b/fs/fs.c
index fc9e56168c9c..9b177911efba 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -890,10 +890,18 @@ const char *fs_detect(const char *filename, const char *fsoptions)
parseopt_b(fsoptions, "loop", &loop);
parseopt_llu_suffix(fsoptions, "offset", &offset);
- if (loop)
+
+ if (loop) {
ret = file_name_detect_type_offset(filename, offset, &type);
- else
- ret = cdev_detect_type(filename, &type);
+ } else {
+ struct cdev *cdev = cdev_open_by_name(filename, O_RDONLY);
+ if (cdev) {
+ ret = cdev_detect_type(cdev, &type);
+ cdev_close(cdev);
+ } else {
+ ret = -ENOENT;
+ }
+ }
if (ret || type == filetype_unknown)
return NULL;
diff --git a/include/filetype.h b/include/filetype.h
index e5aa050ebc27..4e646aec9d6f 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -65,13 +65,15 @@ enum filetype {
#define FILE_TYPE_SAFE_BUFSIZE 2048
+struct cdev;
+
const char *file_type_to_string(enum filetype f);
const char *file_type_to_short_string(enum filetype f);
enum filetype file_detect_partition_table(const void *_buf, size_t bufsize);
enum filetype file_detect_type(const void *_buf, size_t bufsize);
int file_name_detect_type(const char *filename, enum filetype *type);
int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type);
-int cdev_detect_type(const char *name, enum filetype *type);
+int cdev_detect_type(struct cdev *cdev, enum filetype *type);
enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec);
int is_fat_boot_sector(const void *_buf);
bool filetype_is_barebox_image(enum filetype ft);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 050/112] ARM: mmu-early: gracefully handle already enabled MMU
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (48 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 049/112] filetype: have cdev_detect_type take a cdev Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 051/112] efi: don't hide structs, enums or unions behind _t Ahmad Fatoum
` (61 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
arm_cpu_lowlevel_init will disable the MMU, but there are valid cases to
not call it on startup, e.g. when barebox is being run as EFI payload.
To allow booting an EFI-stubbed barebox both as primary bootloader and
as EFI payload, teach mmu_early_enable() to bail out when the MMU is
already set up.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/cpu/mmu_32.c | 3 +++
arch/arm/cpu/mmu_64.c | 3 +++
2 files changed, 6 insertions(+)
diff --git a/arch/arm/cpu/mmu_32.c b/arch/arm/cpu/mmu_32.c
index c6eecf9c9d2d..3a8d025ecdee 100644
--- a/arch/arm/cpu/mmu_32.c
+++ b/arch/arm/cpu/mmu_32.c
@@ -597,6 +597,9 @@ void mmu_early_enable(unsigned long membase, unsigned long memsize)
pr_debug("enabling MMU, ttb @ 0x%p\n", ttb);
+ if (get_cr() & CR_M)
+ return;
+
set_ttbr(ttb);
/* For the XN bit to take effect, we can't be using DOMAIN_MANAGER. */
diff --git a/arch/arm/cpu/mmu_64.c b/arch/arm/cpu/mmu_64.c
index 3e182f70ccb1..a392789ab696 100644
--- a/arch/arm/cpu/mmu_64.c
+++ b/arch/arm/cpu/mmu_64.c
@@ -313,6 +313,9 @@ void mmu_early_enable(unsigned long membase, unsigned long memsize)
int el;
unsigned long ttb = arm_mem_ttb(membase + memsize);
+ if (get_cr() & CR_M)
+ return;
+
pr_debug("enabling MMU, ttb @ 0x%08lx\n", ttb);
el = current_el();
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 051/112] efi: don't hide structs, enums or unions behind _t
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (49 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 050/112] ARM: mmu-early: gracefully handle already enabled MMU Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 052/112] efi: make headers self-contained Ahmad Fatoum
` (60 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Kernel coding style is to usually not hide the fact that a type is a
struct or enum behind a typedef. Follow that in the EFI code.
Besides being more descriptive, this also allows forward declarations,
so <efi.h> doesn't have to be included everywhere.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/x86/mach-efi/reloc_ia32.c | 2 +-
drivers/bus/acpi.c | 4 +-
drivers/efi/efi-device.c | 2 +-
drivers/net/efi-snp.c | 20 ++++----
efi/devicepath.c | 6 +--
efi/payload/fdt.c | 2 +-
efi/payload/image.c | 8 ++--
efi/payload/init.c | 10 ++--
fs/efi.c | 6 +--
include/efi.h | 86 +++++++++++++++++-----------------
include/efi/device-path.h | 16 +++----
include/efi/efi-payload.h | 4 +-
12 files changed, 83 insertions(+), 83 deletions(-)
diff --git a/arch/x86/mach-efi/reloc_ia32.c b/arch/x86/mach-efi/reloc_ia32.c
index 46929631ec02..c235421ce180 100644
--- a/arch/x86/mach-efi/reloc_ia32.c
+++ b/arch/x86/mach-efi/reloc_ia32.c
@@ -38,7 +38,7 @@
#include <elf.h>
-efi_status_t _relocate(long ldbase, Elf32_Dyn *dyn, efi_handle_t image, efi_system_table_t *systab)
+efi_status_t _relocate(long ldbase, Elf32_Dyn *dyn, efi_handle_t image, struct efi_system_table *systab)
{
long relsz = 0, relent = 0;
Elf32_Rel *rel = 0;
diff --git a/drivers/bus/acpi.c b/drivers/bus/acpi.c
index ac034cce4569..953ccd755f98 100644
--- a/drivers/bus/acpi.c
+++ b/drivers/bus/acpi.c
@@ -149,7 +149,7 @@ static struct device *acpi_add_device(struct bus_type *bus,
static int acpi_register_devices(struct bus_type *bus)
{
- efi_config_table_t *table = bus->dev->priv;
+ struct efi_config_table *table = bus->dev->priv;
struct acpi_rsdp *rsdp;
struct acpi_rsdt *root;
size_t entry_count;
@@ -225,7 +225,7 @@ struct bus_type acpi_bus = {
static int efi_acpi_probe(void)
{
- efi_config_table_t *ect, *table = NULL;
+ struct efi_config_table *ect, *table = NULL;
for_each_efi_config_table(ect) {
/* take ACPI < 2 table only if no ACPI 2.0 is available */
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index ad6899ad5c45..f93bbc6a4e50 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -347,7 +347,7 @@ struct bus_type efi_bus = {
static void efi_businfo(struct device *dev)
{
- efi_config_table_t *t;
+ struct efi_config_table *t;
int i = 0;
printf("Tables:\n");
diff --git a/drivers/net/efi-snp.c b/drivers/net/efi-snp.c
index 7e94b613a1d1..476015f1c2a2 100644
--- a/drivers/net/efi-snp.c
+++ b/drivers/net/efi-snp.c
@@ -69,10 +69,10 @@ struct efi_simple_network_mode {
uint32_t ReceiveFilterSetting;
uint32_t MaxMCastFilterCount;
uint32_t MCastFilterCount;
- efi_mac_address MCastFilter[MAX_MCAST_FILTER_CNT];
- efi_mac_address CurrentAddress;
- efi_mac_address BroadcastAddress;
- efi_mac_address PermanentAddress;
+ struct efi_mac_address MCastFilter[MAX_MCAST_FILTER_CNT];
+ struct efi_mac_address CurrentAddress;
+ struct efi_mac_address BroadcastAddress;
+ struct efi_mac_address PermanentAddress;
uint8_t IfType;
bool MacAddressChangeable;
bool MultipleTxSupported;
@@ -92,14 +92,14 @@ struct efi_simple_network {
efi_status_t (EFIAPI *shutdown) (struct efi_simple_network *This);
efi_status_t (EFIAPI *receive_filters) (struct efi_simple_network *This,
uint32_t Enable, uint32_t Disable, bool ResetMCastFilter,
- unsigned long MCastFilterCnt, efi_mac_address *MCastFilter);
+ unsigned long MCastFilterCnt, struct efi_mac_address *MCastFilter);
efi_status_t (EFIAPI *station_address) (struct efi_simple_network *This,
- bool Reset, efi_mac_address *New);
+ bool Reset, struct efi_mac_address *New);
efi_status_t (EFIAPI *statistics) (struct efi_simple_network *This,
bool Reset, unsigned long *StatisticsSize,
struct efi_network_statistics *StatisticsTable);
efi_status_t (EFIAPI *mcast_ip_to_mac) (struct efi_simple_network *This,
- bool IPv6, efi_ip_address *IP, efi_mac_address *MAC);
+ bool IPv6, union efi_ip_address *IP, struct efi_mac_address *MAC);
efi_status_t (EFIAPI *nvdata) (struct efi_simple_network *This,
bool ReadWrite, unsigned long Offset, unsigned long BufferSize,
void *Buffer);
@@ -107,11 +107,11 @@ struct efi_simple_network {
uint32_t *InterruptStatus, void **TxBuf);
efi_status_t (EFIAPI *transmit) (struct efi_simple_network *This,
unsigned long HeaderSize, unsigned long BufferSize, void *Buffer,
- efi_mac_address *SrcAddr, efi_mac_address *DestAddr,
+ struct efi_mac_address *SrcAddr, struct efi_mac_address *DestAddr,
uint16_t *Protocol);
efi_status_t (EFIAPI *receive) (struct efi_simple_network *This,
unsigned long *HeaderSize, unsigned long *BufferSize, void *Buffer,
- efi_mac_address *SrcAddr, efi_mac_address *DestAddr, uint16_t *Protocol);
+ struct efi_mac_address *SrcAddr, struct efi_mac_address *DestAddr, uint16_t *Protocol);
void *WaitForPacket;
struct efi_simple_network_mode *Mode;
};
@@ -220,7 +220,7 @@ static int efi_snp_eth_open(struct eth_device *edev)
}
efiret = priv->snp->station_address(priv->snp, false,
- (efi_mac_address *)priv->snp->Mode->PermanentAddress.Addr );
+ (struct efi_mac_address *)priv->snp->Mode->PermanentAddress.Addr );
if (EFI_ERROR(efiret)) {
dev_err(priv->dev, "failed to set MAC address: %s\n",
efi_strerror(efiret));
diff --git a/efi/devicepath.c b/efi/devicepath.c
index 584f1fbd1d7a..fad36c78a260 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -334,14 +334,14 @@ dev_path_mac_addr(struct string *str, void *dev_path)
}
static void
-cat_print_iPv4(struct string *str, efi_ipv4_address * address)
+cat_print_iPv4(struct string *str, struct efi_ipv4_address * address)
{
cprintf(str, "%d.%d.%d.%d", address->Addr[0], address->Addr[1],
address->Addr[2], address->Addr[3]);
}
static bool
-is_not_null_iPv4(efi_ipv4_address * address)
+is_not_null_iPv4(struct efi_ipv4_address * address)
{
u8 val;
@@ -405,7 +405,7 @@ dev_path_iPv4(struct string *str, void *dev_path)
#define cat_print_iPv6_ADD( x , y ) ( ( (u16) ( x ) ) << 8 | ( y ) )
static void
-cat_print_ipv6(struct string *str, efi_ipv6_address * address)
+cat_print_ipv6(struct string *str, struct efi_ipv6_address * address)
{
cprintf(str, "%x:%x:%x:%x:%x:%x:%x:%x",
cat_print_iPv6_ADD(address->Addr[0], address->Addr[1]),
diff --git a/efi/payload/fdt.c b/efi/payload/fdt.c
index dbbc93fb7d68..faa7a5ad8d41 100644
--- a/efi/payload/fdt.c
+++ b/efi/payload/fdt.c
@@ -10,7 +10,7 @@
static int efi_fdt_probe(void)
{
- efi_config_table_t *ect;
+ struct efi_config_table *ect;
for_each_efi_config_table(ect) {
struct fdt_header *oftree;
diff --git a/efi/payload/image.c b/efi/payload/image.c
index fb77ce4437fc..f9706c028ed9 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -121,7 +121,7 @@ static void efi_free_file(void *_mem, size_t size)
BS->free_pages(mem, DIV_ROUND_UP(size, EFI_PAGE_SIZE));
}
-static int efi_load_image(const char *file, efi_loaded_image_t **loaded_image,
+static int efi_load_image(const char *file, struct efi_loaded_image **loaded_image,
efi_handle_t *h)
{
void *exe;
@@ -158,7 +158,7 @@ static int efi_load_image(const char *file, efi_loaded_image_t **loaded_image,
static int efi_execute_image(const char *file)
{
efi_handle_t handle;
- efi_loaded_image_t *loaded_image;
+ struct efi_loaded_image *loaded_image;
efi_status_t efiret;
struct linux_kernel_header *image_header;
const char *options;
@@ -204,7 +204,7 @@ static int efi_execute_image(const char *file)
}
#ifdef __x86_64__
-typedef void(*handover_fn)(void *image, efi_system_table_t *table,
+typedef void(*handover_fn)(void *image, struct efi_system_table *table,
struct linux_kernel_header *header);
static inline void linux_efi_handover(efi_handle_t handle,
@@ -239,7 +239,7 @@ static int do_bootm_efi(struct image_data *data)
efi_handle_t handle;
int ret;
const char *options;
- efi_loaded_image_t *loaded_image;
+ struct efi_loaded_image *loaded_image;
struct linux_kernel_header *image_header, *boot_header;
ret = efi_load_image(data->os_file, &loaded_image, &handle);
diff --git a/efi/payload/init.c b/efi/payload/init.c
index 6d65f6d53464..4b612e61afb3 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -40,12 +40,12 @@
#include <bbu.h>
#include <generated/utsrelease.h>
-efi_runtime_services_t *RT;
-efi_boot_services_t *BS;
-efi_system_table_t *efi_sys_table;
+struct efi_runtime_services *RT;
+struct efi_boot_services *BS;
+struct efi_system_table *efi_sys_table;
efi_handle_t efi_parent_image;
struct efi_device_path *efi_device_path;
-efi_loaded_image_t *efi_loaded_image;
+struct efi_loaded_image *efi_loaded_image;
void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size)
{
@@ -269,7 +269,7 @@ device_initcall(efi_init);
/**
* efi-main - Entry point for EFI images
*/
-void efi_main(efi_handle_t image, efi_system_table_t *sys_table)
+void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
{
efi_physical_addr_t mem;
size_t memsize;
diff --git a/fs/efi.c b/fs/efi.c
index 0789f6ecee6b..0cfd5a3aebf6 100644
--- a/fs/efi.c
+++ b/fs/efi.c
@@ -84,9 +84,9 @@ struct efi_file_info {
uint64_t Size;
uint64_t FileSize;
uint64_t PhysicalSize;
- efi_time_t CreateTime;
- efi_time_t LastAccessTime;
- efi_time_t ModificationTime;
+ struct efi_time CreateTime;
+ struct efi_time LastAccessTime;
+ struct efi_time ModificationTime;
uint64_t Attribute;
s16 FileName[1];
};
diff --git a/include/efi.h b/include/efi.h
index f1567f7791b8..10e22f1e9f99 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -92,13 +92,13 @@ typedef guid_t efi_guid_t __aligned(__alignof__(u32));
/*
* Generic EFI table header
*/
-typedef struct {
+struct efi_table_hdr {
u64 signature;
u32 revision;
u32 headersize;
u32 crc32;
u32 reserved;
-} efi_table_hdr_t;
+};
/*
* Memory map descriptor:
@@ -165,7 +165,7 @@ typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
#define EFI_TIME_IN_DAYLIGHT 0x2
#define EFI_UNSPECIFIED_TIMEZONE 0x07ff
-typedef struct {
+struct efi_time {
u16 year;
u8 month;
u8 day;
@@ -177,13 +177,13 @@ typedef struct {
s16 timezone;
u8 daylight;
u8 pad2;
-} efi_time_t;
+};
-typedef struct {
+struct efi_time_cap {
u32 resolution;
u32 accuracy;
u8 sets_to_zero;
-} efi_time_cap_t;
+};
enum efi_locate_search_type {
ALL_HANDLES,
@@ -198,17 +198,17 @@ struct efi_open_protocol_information_entry {
u32 open_count;
};
-typedef enum {
+enum efi_timer_delay {
EFI_TIMER_CANCEL = 0,
EFI_TIMER_PERIODIC = 1,
EFI_TIMER_RELATIVE = 2
-} efi_timer_delay_t;
+};
/*
* EFI Boot Services table
*/
-typedef struct {
- efi_table_hdr_t hdr;
+struct efi_boot_services {
+ struct efi_table_hdr hdr;
void *raise_tpl;
void *restore_tpl;
efi_status_t (EFIAPI *allocate_pages)(int, int, unsigned long,
@@ -232,7 +232,7 @@ typedef struct {
efi_status_t(EFIAPI *create_event)(u32 type , unsigned long tpl,
void (*fn) (void *event, void *ctx),
void *ctx, void **event);
- efi_status_t(EFIAPI *set_timer)(void *event, efi_timer_delay_t type, uint64_t time);
+ efi_status_t(EFIAPI *set_timer)(void *event, enum efi_timer_delay type, uint64_t time);
efi_status_t(EFIAPI *wait_for_event)(unsigned long number_of_events, void *event,
unsigned long *index);
void *signal_event;
@@ -298,18 +298,18 @@ typedef struct {
void *copy_mem;
void *set_mem;
void *create_event_ex;
-} efi_boot_services_t;
+};
-extern efi_boot_services_t *BS;
+extern struct efi_boot_services *BS;
/*
* Types and defines for EFI ResetSystem
*/
-typedef enum {
+enum efi_reset_type {
EFI_RESET_COLD = 0,
EFI_RESET_WARM = 1,
EFI_RESET_SHUTDOWN = 2
-} efi_reset_type_t;
+};
/*
* EFI Runtime Services table
@@ -317,8 +317,8 @@ typedef enum {
#define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
#define EFI_RUNTIME_SERVICES_REVISION 0x00010000
-typedef struct {
- efi_table_hdr_t hdr;
+struct efi_runtime_services {
+ struct efi_table_hdr hdr;
void *get_time;
void *set_time;
void *get_wakeup_time;
@@ -332,14 +332,14 @@ typedef struct {
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 (EFIAPI *reset_system)(efi_reset_type_t reset_type, efi_status_t reset_status,
+ void (EFIAPI *reset_system)(enum efi_reset_type 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;
-} efi_runtime_services_t;
+};
-extern efi_runtime_services_t *RT;
+extern struct efi_runtime_services *RT;
/*
* EFI Configuration Table and GUID definitions
@@ -554,10 +554,10 @@ extern efi_guid_t efi_barebox_vendor_guid;
extern efi_guid_t efi_systemd_vendor_guid;
extern efi_guid_t efi_fdt_guid;
-typedef struct {
+struct efi_config_table {
efi_guid_t guid;
- unsigned long table;
-} efi_config_table_t;
+ void * table;
+};
#define for_each_efi_config_table(t) \
for (t = efi_sys_table->tables; \
@@ -573,8 +573,8 @@ typedef struct {
#define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10))
#define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | (02))
-typedef struct {
- efi_table_hdr_t hdr;
+struct efi_system_table {
+ struct efi_table_hdr hdr;
unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */
u32 fw_revision;
unsigned long con_in_handle;
@@ -583,16 +583,16 @@ typedef struct {
struct efi_simple_text_output_protocol *con_out;
unsigned long stderr_handle;
unsigned long std_err;
- efi_runtime_services_t *runtime;
- efi_boot_services_t *boottime;
+ struct efi_runtime_services *runtime;
+ struct efi_boot_services *boottime;
unsigned long nr_tables;
- efi_config_table_t *tables;
-} efi_system_table_t;
+ struct efi_config_table *tables;
+};
-typedef struct {
+struct efi_loaded_image {
u32 revision;
void *parent_handle;
- efi_system_table_t *system_table;
+ struct efi_system_table *system_table;
void *device_handle;
void *file_path;
void *reserved;
@@ -603,7 +603,7 @@ typedef struct {
unsigned int image_code_type;
unsigned int image_data_type;
unsigned long unload;
-} efi_loaded_image_t;
+};
static inline int
efi_guidcmp (efi_guid_t left, efi_guid_t right)
@@ -611,7 +611,7 @@ efi_guidcmp (efi_guid_t left, efi_guid_t right)
return memcmp(&left, &right, sizeof (efi_guid_t));
}
-__attribute__((noreturn)) void efi_main(efi_handle_t, efi_system_table_t *);
+__attribute__((noreturn)) void efi_main(efi_handle_t, struct efi_system_table *);
/*
* Variable Attributes
@@ -683,23 +683,23 @@ struct efi_simple_input_interface {
void *wait_for_key;
};
-typedef struct {
+struct efi_mac_address {
uint8_t Addr[32];
-} efi_mac_address;
+};
-typedef struct {
+struct efi_ipv4_address {
uint8_t Addr[4];
-} efi_ipv4_address;
+};
-typedef struct {
+struct efi_ipv6_address {
uint8_t Addr[16];
-} efi_ipv6_address;
+};
-typedef union {
+union efi_ip_address {
uint32_t Addr[4];
- efi_ipv4_address v4;
- efi_ipv6_address v6;
-} efi_ip_address;
+ struct efi_ipv4_address v4;
+ struct efi_ipv6_address v6;
+};
struct efi_device_path *device_path_from_handle(efi_handle_t Handle);
char *device_path_to_str(struct efi_device_path *dev_path);
diff --git a/include/efi/device-path.h b/include/efi/device-path.h
index f3af71465bf8..2882b87d6831 100644
--- a/include/efi/device-path.h
+++ b/include/efi/device-path.h
@@ -194,36 +194,36 @@ struct i2_o_device_path {
#define MSG_MAC_ADDR_DP 0x0b
struct mac_addr_device_path {
struct efi_device_path header;
- efi_mac_address mac_address;
+ struct efi_mac_address mac_address;
u8 if_type;
};
#define MSG_IPv4_DP 0x0c
struct ipv4_device_path {
struct efi_device_path header;
- efi_ipv4_address local_ip_address;
- efi_ipv4_address remote_ip_address;
+ struct efi_ipv4_address local_ip_address;
+ struct efi_ipv4_address remote_ip_address;
u16 local_port;
u16 remote_port;
u16 Protocol;
bool static_ip_address;
/* new from UEFI version 2, code must check length field in header */
- efi_ipv4_address gateway_ip_address;
- efi_ipv4_address subnet_mask;
+ struct efi_ipv4_address gateway_ip_address;
+ struct efi_ipv4_address subnet_mask;
};
#define MSG_IPv6_DP 0x0d
struct ipv6_device_path {
struct efi_device_path header;
- efi_ipv6_address local_ip_address;
- efi_ipv6_address remote_ip_address;
+ struct efi_ipv6_address local_ip_address;
+ struct efi_ipv6_address remote_ip_address;
u16 local_port;
u16 remote_port;
u16 Protocol;
bool IPAddress_origin;
/* new from UEFI version 2, code must check length field in header */
u8 prefix_length;
- efi_ipv6_address gateway_ip_address;
+ struct efi_ipv6_address gateway_ip_address;
};
/**
diff --git a/include/efi/efi-payload.h b/include/efi/efi-payload.h
index a2daff08bb3f..cddd8c8ddd47 100644
--- a/include/efi/efi-payload.h
+++ b/include/efi/efi-payload.h
@@ -5,10 +5,10 @@
#include <efi.h>
#include <efi/efi-util.h>
-extern efi_system_table_t *efi_sys_table;
+extern struct efi_system_table *efi_sys_table;
extern efi_handle_t efi_parent_image;
extern struct efi_device_path *efi_device_path;
-extern efi_loaded_image_t *efi_loaded_image;
+extern struct efi_loaded_image *efi_loaded_image;
void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 052/112] efi: make headers self-contained
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (50 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 051/112] efi: don't hide structs, enums or unions behind _t Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 053/112] efi: unify whitespace for GUIDs Ahmad Fatoum
` (59 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
With the loader support, efi.h will grow quite a bit. To avoid having to
include it always, lets move the base definitions into a new
<efi/types.h> and make the different <efi/*.h> headers self contained.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/hw_random/efi-rng.c | 2 +-
efi/devicepath.c | 1 +
efi/errno.c | 1 +
efi/guid.c | 1 +
efi/payload/fdt.c | 1 +
include/efi.h | 72 ++-----------------------------------
include/efi/device-path.h | 2 ++
include/efi/efi-device.h | 4 +++
include/efi/efi-payload.h | 6 +++-
include/efi/efi-stdio.h | 7 +++-
include/efi/efi-util.h | 8 ++++-
include/efi/types.h | 66 ++++++++++++++++++++++++++++++++++
12 files changed, 97 insertions(+), 74 deletions(-)
create mode 100644 include/efi/types.h
diff --git a/drivers/hw_random/efi-rng.c b/drivers/hw_random/efi-rng.c
index b74075e3a4ac..61cb01caf647 100644
--- a/drivers/hw_random/efi-rng.c
+++ b/drivers/hw_random/efi-rng.c
@@ -3,7 +3,7 @@
#include <driver.h>
#include <init.h>
#include <linux/hw_random.h>
-#include <efi/efi-util.h>
+#include <efi.h>
#include <efi/efi-device.h>
struct efi_rng_priv {
diff --git a/efi/devicepath.c b/efi/devicepath.c
index fad36c78a260..63b0ea61f0f9 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -2,6 +2,7 @@
#include <common.h>
#include <efi.h>
+#include <efi/efi-util.h>
#include <malloc.h>
#include <string.h>
#include <wchar.h>
diff --git a/efi/errno.c b/efi/errno.c
index 3bb68e7781e6..ed14b1a8a6b0 100644
--- a/efi/errno.c
+++ b/efi/errno.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <efi/efi-util.h>
+#include <efi.h>
#include <errno.h>
const char *efi_strerror(efi_status_t err)
diff --git a/efi/guid.c b/efi/guid.c
index ca16f4520ff2..8103b3d63114 100644
--- a/efi/guid.c
+++ b/efi/guid.c
@@ -2,6 +2,7 @@
#include <common.h>
#include <efi.h>
+#include <efi/efi-util.h>
efi_guid_t efi_file_info_id = EFI_FILE_INFO_GUID;
efi_guid_t efi_simple_file_system_protocol_guid = EFI_SIMPLE_FILE_SYSTEM_GUID;
diff --git a/efi/payload/fdt.c b/efi/payload/fdt.c
index faa7a5ad8d41..8dacaa8b524a 100644
--- a/efi/payload/fdt.c
+++ b/efi/payload/fdt.c
@@ -5,6 +5,7 @@
#include <common.h>
#include <init.h>
#include <libfile.h>
+#include <efi.h>
#include <efi/efi-payload.h>
#include <efi/efi-device.h>
diff --git a/include/efi.h b/include/efi.h
index 10e22f1e9f99..2b248a17013d 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -14,15 +14,7 @@
*/
#include <linux/string.h>
#include <linux/types.h>
-#include <linux/uuid.h>
-
-#ifdef CONFIG_EFI_PAYLOAD
-#define EFIAPI __attribute__((ms_abi))
-#else
-#define EFIAPI
-#endif
-
-struct efi_device_path;
+#include <efi/types.h>
/* Bit mask for EFI status code with error */
#define EFI_ERROR_MASK (1UL << (BITS_PER_LONG-1))
@@ -62,33 +54,6 @@ struct efi_device_path;
#define EFI_ERROR(a) (((signed long) a) < 0)
-typedef unsigned long efi_status_t;
-typedef u16 efi_char16_t; /* UNICODE character */
-typedef u64 efi_physical_addr_t;
-typedef void *efi_handle_t;
-
-/*
- * The UEFI spec and EDK2 reference implementation both define EFI_GUID as
- * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment
- * is 32 bits not 8 bits like our guid_t. In some cases (i.e., on 32-bit ARM),
- * this means that firmware services invoked by the kernel may assume that
- * efi_guid_t* arguments are 32-bit aligned, and use memory accessors that
- * do not tolerate misalignment. So let's set the minimum alignment to 32 bits.
- *
- * Note that the UEFI spec as well as some comments in the EDK2 code base
- * suggest that EFI_GUID should be 64-bit aligned, but this appears to be
- * a mistake, given that no code seems to exist that actually enforces that
- * or relies on it.
- */
-typedef guid_t efi_guid_t __aligned(__alignof__(u32));
-
-#define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
-((efi_guid_t) \
-{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
- (b) & 0xff, ((b) >> 8) & 0xff, \
- (c) & 0xff, ((c) >> 8) & 0xff, \
- (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
-
/*
* Generic EFI table header
*/
@@ -605,12 +570,6 @@ struct efi_loaded_image {
unsigned long unload;
};
-static inline int
-efi_guidcmp (efi_guid_t left, efi_guid_t right)
-{
- return memcmp(&left, &right, sizeof (efi_guid_t));
-}
-
__attribute__((noreturn)) void efi_main(efi_handle_t, struct efi_system_table *);
/*
@@ -637,12 +596,6 @@ __attribute__((noreturn)) void efi_main(efi_handle_t, struct efi_system_table *)
*/
#define EFI_VARIABLE_GUID_LEN 36
-struct efi_device_path {
- u8 type;
- u8 sub_type;
- u16 length;
-} __attribute ((packed));
-
struct simple_text_output_mode {
s32 max_mode;
s32 mode;
@@ -670,10 +623,7 @@ struct efi_simple_text_output_protocol {
struct simple_text_output_mode *mode;
};
-struct efi_input_key {
- u16 scan_code;
- s16 unicode_char;
-};
+struct efi_input_key;
struct efi_simple_input_interface {
efi_status_t(EFIAPI *reset)(struct efi_simple_input_interface *this,
@@ -683,24 +633,6 @@ struct efi_simple_input_interface {
void *wait_for_key;
};
-struct efi_mac_address {
- uint8_t Addr[32];
-};
-
-struct efi_ipv4_address {
- uint8_t Addr[4];
-};
-
-struct efi_ipv6_address {
- uint8_t Addr[16];
-};
-
-union efi_ip_address {
- uint32_t Addr[4];
- struct efi_ipv4_address v4;
- struct efi_ipv6_address v6;
-};
-
struct efi_device_path *device_path_from_handle(efi_handle_t Handle);
char *device_path_to_str(struct efi_device_path *dev_path);
u8 device_path_to_type(struct efi_device_path *dev_path);
diff --git a/include/efi/device-path.h b/include/efi/device-path.h
index 2882b87d6831..4b97cadde4f1 100644
--- a/include/efi/device-path.h
+++ b/include/efi/device-path.h
@@ -1,6 +1,8 @@
#ifndef __EFI_DEVICE_PATH_H
#define __EFI_DEVICE_PATH_H
+#include <efi/types.h>
+
/*
* Hardware Device Path (UEFI 2.4 specification, version 2.4 § 9.3.2.)
*/
diff --git a/include/efi/efi-device.h b/include/efi/efi-device.h
index cb665edf657e..eaf89beb8ed1 100644
--- a/include/efi/efi-device.h
+++ b/include/efi/efi-device.h
@@ -2,6 +2,10 @@
#ifndef __EFI_EFI_DEVICE_H
#define __EFI_EFI_DEVICE_H
+#include <efi/types.h>
+#include <efi/efi-util.h>
+#include <driver.h>
+
struct efi_device {
struct device dev;
efi_guid_t *guids;
diff --git a/include/efi/efi-payload.h b/include/efi/efi-payload.h
index cddd8c8ddd47..3713ef359228 100644
--- a/include/efi/efi-payload.h
+++ b/include/efi/efi-payload.h
@@ -2,9 +2,12 @@
#ifndef __EFI_PAYLOAD_H
#define __EFI_PAYLOAD_H
-#include <efi.h>
+#include <efi/types.h>
#include <efi/efi-util.h>
+struct efi_system_table;
+struct efi_loaded_image;
+
extern struct efi_system_table *efi_sys_table;
extern efi_handle_t efi_parent_image;
extern struct efi_device_path *efi_device_path;
@@ -14,6 +17,7 @@ void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size);
static inline void *efi_get_global_var(char *name, int *var_size)
{
+ extern efi_guid_t efi_global_variable_guid;
return efi_get_variable(name, &efi_global_variable_guid, var_size);
}
diff --git a/include/efi/efi-stdio.h b/include/efi/efi-stdio.h
index e8af244bfcf6..623b42c10f19 100644
--- a/include/efi/efi-stdio.h
+++ b/include/efi/efi-stdio.h
@@ -2,7 +2,7 @@
#ifndef EFI_STDIO_H_
#define EFI_STDIO_H_
-#include <efi.h>
+#include <efi/types.h>
struct efi_simple_text_input_ex_protocol;
@@ -16,6 +16,11 @@ struct efi_key_state {
u8 toggle_state;
};
+struct efi_input_key {
+ u16 scan_code;
+ s16 unicode_char;
+};
+
struct efi_key_data {
struct efi_input_key key;
struct efi_key_state state;
diff --git a/include/efi/efi-util.h b/include/efi/efi-util.h
index 78e352456ad1..c61f3a5b05d2 100644
--- a/include/efi/efi-util.h
+++ b/include/efi/efi-util.h
@@ -2,7 +2,7 @@
#ifndef __EFI_UTIL_H
#define __EFI_UTIL_H
-#include <efi.h>
+#include <efi/types.h>
const char *efi_strerror(efi_status_t err);
int efi_errno(efi_status_t err);
@@ -11,4 +11,10 @@ int __efivarfs_parse_filename(const char *filename, efi_guid_t *vendor,
s16 *name, size_t *namelen);
int efivarfs_parse_filename(const char *filename, efi_guid_t *vendor, s16 **name);
+static inline int
+efi_guidcmp (efi_guid_t left, efi_guid_t right)
+{
+ return memcmp(&left, &right, sizeof (efi_guid_t));
+}
+
#endif
diff --git a/include/efi/types.h b/include/efi/types.h
new file mode 100644
index 000000000000..3d42948d2b62
--- /dev/null
+++ b/include/efi/types.h
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _EFI_TYPES_H_
+#define _EFI_TYPES_H_
+
+#include <linux/types.h>
+#include <linux/compiler.h>
+#include <linux/uuid.h>
+
+typedef unsigned long efi_status_t;
+typedef u16 efi_char16_t; /* UNICODE character */
+typedef u64 efi_physical_addr_t;
+typedef void *efi_handle_t;
+
+/*
+ * The UEFI spec and EDK2 reference implementation both define EFI_GUID as
+ * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment
+ * is 32 bits not 8 bits like our guid_t. In some cases (i.e., on 32-bit ARM),
+ * this means that firmware services invoked by the kernel may assume that
+ * efi_guid_t* arguments are 32-bit aligned, and use memory accessors that
+ * do not tolerate misalignment. So let's set the minimum alignment to 32 bits.
+ *
+ * Note that the UEFI spec as well as some comments in the EDK2 code base
+ * suggest that EFI_GUID should be 64-bit aligned, but this appears to be
+ * a mistake, given that no code seems to exist that actually enforces that
+ * or relies on it.
+ */
+typedef guid_t efi_guid_t __aligned(__alignof__(u32));
+
+#define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
+((efi_guid_t) \
+{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
+ (b) & 0xff, ((b) >> 8) & 0xff, \
+ (c) & 0xff, ((c) >> 8) & 0xff, \
+ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
+
+#ifdef CONFIG_EFI_PAYLOAD
+#define EFIAPI __attribute__((ms_abi))
+#else
+#define EFIAPI
+#endif
+
+struct efi_device_path {
+ u8 type;
+ u8 sub_type;
+ u16 length;
+} __packed;
+
+struct efi_mac_address {
+ uint8_t Addr[32];
+};
+
+struct efi_ipv4_address {
+ uint8_t Addr[4];
+};
+
+struct efi_ipv6_address {
+ uint8_t Addr[16];
+};
+
+union efi_ip_address {
+ uint32_t Addr[4];
+ struct efi_ipv4_address v4;
+ struct efi_ipv6_address v6;
+};
+
+#endif
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 053/112] efi: unify whitespace for GUIDs
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (51 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 052/112] efi: make headers self-contained Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 054/112] efi: efi-guid: add more GUIDs Ahmad Fatoum
` (58 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Half the GUID definitions indent with a tab and the other with 4 spaces.
Stick to 4 spaces throughout and remove the discrepancy.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/efi.h | 86 +++++++++++++++++++++++++--------------------------
1 file changed, 43 insertions(+), 43 deletions(-)
diff --git a/include/efi.h b/include/efi.h
index 2b248a17013d..8635ab58f981 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -373,138 +373,138 @@ extern struct efi_runtime_services *RT;
EFI_GUID( 0xA19832B9, 0xAC25, 0x11D3, 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D )
#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
- EFI_GUID(0x0964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+ EFI_GUID(0x0964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
#define EFI_UNKNOWN_DEVICE_GUID \
- EFI_GUID(0xcf31fac5, 0xc24e, 0x11d2, 0x85, 0xf3, 0x0, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b)
+ EFI_GUID(0xcf31fac5, 0xc24e, 0x11d2, 0x85, 0xf3, 0x0, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b)
#define EFI_BLOCK_IO_PROTOCOL_GUID \
- EFI_GUID(0x964e5b21, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+ EFI_GUID(0x964e5b21, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
/* additional GUID from EDK2 */
#define EFI_FIRMWARE_VOLUME2_PROTOCOL_GUID \
- EFI_GUID(0x220e73b6, 0x6bdb, 0x4413, 0x84, 0x5, 0xb9, 0x74, 0xb1, 0x8, 0x61, 0x9a)
+ EFI_GUID(0x220e73b6, 0x6bdb, 0x4413, 0x84, 0x5, 0xb9, 0x74, 0xb1, 0x8, 0x61, 0x9a)
#define EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID \
- EFI_GUID(0x8f644fa9, 0xe850, 0x4db1, 0x9c, 0xe2, 0xb, 0x44, 0x69, 0x8e, 0x8d, 0xa4)
+ EFI_GUID(0x8f644fa9, 0xe850, 0x4db1, 0x9c, 0xe2, 0xb, 0x44, 0x69, 0x8e, 0x8d, 0xa4)
#define EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID \
- EFI_GUID(0x2f707ebb, 0x4a1a, 0x11d4, 0x9a, 0x38, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+ EFI_GUID(0x2f707ebb, 0x4a1a, 0x11d4, 0x9a, 0x38, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
#define EFI_ISA_ACPI_PROTOCOL_GUID \
- EFI_GUID(0x64a892dc, 0x5561, 0x4536, 0x92, 0xc7, 0x79, 0x9b, 0xfc, 0x18, 0x33, 0x55)
+ EFI_GUID(0x64a892dc, 0x5561, 0x4536, 0x92, 0xc7, 0x79, 0x9b, 0xfc, 0x18, 0x33, 0x55)
#define EFI_ISA_IO_PROTOCOL_GUID \
- EFI_GUID(0x7ee2bd44, 0x3da0, 0x11d4, 0x9a, 0x38, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+ EFI_GUID(0x7ee2bd44, 0x3da0, 0x11d4, 0x9a, 0x38, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
#define EFI_STANDARD_ERROR_DEVICE_GUID \
- EFI_GUID(0xd3b36f2d, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+ EFI_GUID(0xd3b36f2d, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
#define EFI_CONSOLE_OUT_DEVICE_GUID \
- EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+ EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
#define EFI_CONSOLE_IN_DEVICE_GUID \
- EFI_GUID(0xd3b36f2b, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+ EFI_GUID(0xd3b36f2b, 0xd551, 0x11d4, 0x9a, 0x46, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
#define EFI_SIMPLE_TEXT_OUT_PROTOCOL_GUID \
- EFI_GUID(0x387477c2, 0x69c7, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+ EFI_GUID(0x387477c2, 0x69c7, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
#define EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID \
- EFI_GUID(0xdd9e7534, 0x7762, 0x4698, 0x8c, 0x14, 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa)
+ EFI_GUID(0xdd9e7534, 0x7762, 0x4698, 0x8c, 0x14, 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa)
#define EFI_SIMPLE_TEXT_IN_PROTOCOL_GUID \
- EFI_GUID(0x387477c1, 0x69c7, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+ EFI_GUID(0x387477c1, 0x69c7, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
#define EFI_DISK_IO_PROTOCOL_GUID \
- EFI_GUID(0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+ EFI_GUID(0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
#define EFI_IDE_CONTROLLER_INIT_PROTOCOL_GUID \
- EFI_GUID(0xa1e37052, 0x80d9, 0x4e65, 0xa3, 0x17, 0x3e, 0x9a, 0x55, 0xc4, 0x3e, 0xc9)
+ EFI_GUID(0xa1e37052, 0x80d9, 0x4e65, 0xa3, 0x17, 0x3e, 0x9a, 0x55, 0xc4, 0x3e, 0xc9)
#define EFI_DISK_INFO_PROTOCOL_GUID \
- EFI_GUID(0xd432a67f, 0x14dc, 0x484b, 0xb3, 0xbb, 0x3f, 0x2, 0x91, 0x84, 0x93, 0x27)
+ EFI_GUID(0xd432a67f, 0x14dc, 0x484b, 0xb3, 0xbb, 0x3f, 0x2, 0x91, 0x84, 0x93, 0x27)
#define EFI_SERIAL_IO_PROTOCOL_GUID \
- EFI_GUID(0xbb25cf6f, 0xf1d4, 0x11d2, 0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0xfd)
+ EFI_GUID(0xbb25cf6f, 0xf1d4, 0x11d2, 0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0xfd)
#define EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL_GUID \
- EFI_GUID(0x3bc1b285, 0x8a15, 0x4a82, 0xaa, 0xbf, 0x4d, 0x7d, 0x13, 0xfb, 0x32, 0x65)
+ EFI_GUID(0x3bc1b285, 0x8a15, 0x4a82, 0xaa, 0xbf, 0x4d, 0x7d, 0x13, 0xfb, 0x32, 0x65)
#define EFI_LOAD_FILE2_PROTOCOL_GUID \
- EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d)
+ EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d)
#define EFI_MTFTP4_SERVICE_BINDING_PROTOCOL_GUID \
- EFI_GUID(0x2fe800be, 0x8f01, 0x4aa6, 0x94, 0x6b, 0xd7, 0x13, 0x88, 0xe1, 0x83, 0x3f)
+ EFI_GUID(0x2fe800be, 0x8f01, 0x4aa6, 0x94, 0x6b, 0xd7, 0x13, 0x88, 0xe1, 0x83, 0x3f)
#define EFI_DHCP4_PROTOCOL_GUID \
- EFI_GUID(0x9d9a39d8, 0xbd42, 0x4a73, 0xa4, 0xd5, 0x8e, 0xe9, 0x4b, 0xe1, 0x13, 0x80)
+ EFI_GUID(0x9d9a39d8, 0xbd42, 0x4a73, 0xa4, 0xd5, 0x8e, 0xe9, 0x4b, 0xe1, 0x13, 0x80)
#define EFI_UDP4_SERVICE_BINDING_PROTOCOL_GUID \
- EFI_GUID(0x83f01464, 0x99bd, 0x45e5, 0xb3, 0x83, 0xaf, 0x63, 0x05, 0xd8, 0xe9, 0xe6)
+ EFI_GUID(0x83f01464, 0x99bd, 0x45e5, 0xb3, 0x83, 0xaf, 0x63, 0x05, 0xd8, 0xe9, 0xe6)
#define EFI_TCP4_SERVICE_BINDING_PROTOCOL_GUID \
- EFI_GUID(0x00720665, 0x67EB, 0x4a99, 0xBA, 0xF7, 0xD3, 0xC3, 0x3A, 0x1C, 0x7C, 0xC9)
+ EFI_GUID(0x00720665, 0x67EB, 0x4a99, 0xBA, 0xF7, 0xD3, 0xC3, 0x3A, 0x1C, 0x7C, 0xC9)
#define EFI_IP4_SERVICE_BINDING_PROTOCOL_GUID \
- EFI_GUID(0xc51711e7, 0xb4bf, 0x404a, 0xbf, 0xb8, 0x0a, 0x04, 0x8e, 0xf1, 0xff, 0xe4)
+ EFI_GUID(0xc51711e7, 0xb4bf, 0x404a, 0xbf, 0xb8, 0x0a, 0x04, 0x8e, 0xf1, 0xff, 0xe4)
#define EFI_IP4_CONFIG_PROTOCOL_GUID \
- EFI_GUID(0x3b95aa31, 0x3793, 0x434b, 0x86, 0x67, 0xc8, 0x07, 0x08, 0x92, 0xe0, 0x5e)
+ EFI_GUID(0x3b95aa31, 0x3793, 0x434b, 0x86, 0x67, 0xc8, 0x07, 0x08, 0x92, 0xe0, 0x5e)
#define EFI_ARP_SERVICE_BINDING_PROTOCOL_GUID\
- EFI_GUID(0xf44c00ee, 0x1f2c, 0x4a00, 0xaa, 0x9, 0x1c, 0x9f, 0x3e, 0x8, 0x0, 0xa3)
+ EFI_GUID(0xf44c00ee, 0x1f2c, 0x4a00, 0xaa, 0x9, 0x1c, 0x9f, 0x3e, 0x8, 0x0, 0xa3)
#define EFI_MANAGED_NETWORK_SERVICE_BINDING_PROTOCOL_GUID \
- EFI_GUID(0xf36ff770, 0xa7e1, 0x42cf, 0x9e, 0xd2, 0x56, 0xf0, 0xf2, 0x71, 0xf4, 0x4c)
+ EFI_GUID(0xf36ff770, 0xa7e1, 0x42cf, 0x9e, 0xd2, 0x56, 0xf0, 0xf2, 0x71, 0xf4, 0x4c)
#define EFI_VLAN_CONFIG_PROTOCOL_GUID \
- EFI_GUID(0x9e23d768, 0xd2f3, 0x4366, 0x9f, 0xc3, 0x3a, 0x7a, 0xba, 0x86, 0x43, 0x74)
+ EFI_GUID(0x9e23d768, 0xd2f3, 0x4366, 0x9f, 0xc3, 0x3a, 0x7a, 0xba, 0x86, 0x43, 0x74)
#define EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID \
- EFI_GUID(0x330d4706, 0xf2a0, 0x4e4f, 0xa3, 0x69, 0xb6, 0x6f, 0xa8, 0xd5, 0x43, 0x85)
+ EFI_GUID(0x330d4706, 0xf2a0, 0x4e4f, 0xa3, 0x69, 0xb6, 0x6f, 0xa8, 0xd5, 0x43, 0x85)
#define EFI_LOAD_FILE_PROTOCOL_GUID \
- EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+ EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
#define EFI_COMPONENT_NAME2_PROTOCOL_GUID \
- EFI_GUID(0x6a7a5cff, 0xe8d9, 0x4f70, 0xba, 0xda, 0x75, 0xab, 0x30, 0x25, 0xce, 0x14)
+ EFI_GUID(0x6a7a5cff, 0xe8d9, 0x4f70, 0xba, 0xda, 0x75, 0xab, 0x30, 0x25, 0xce, 0x14)
#define EFI_IDEBUSDXE_INF_GUID \
- EFI_GUID(0x69fd8e47, 0xa161, 0x4550, 0xb0, 0x1a, 0x55, 0x94, 0xce, 0xb2, 0xb2, 0xb2)
+ EFI_GUID(0x69fd8e47, 0xa161, 0x4550, 0xb0, 0x1a, 0x55, 0x94, 0xce, 0xb2, 0xb2, 0xb2)
#define EFI_TERMINALDXE_INF_GUID \
- EFI_GUID(0x9e863906, 0xa40f, 0x4875, 0x97, 0x7f, 0x5b, 0x93, 0xff, 0x23, 0x7f, 0xc6)
+ EFI_GUID(0x9e863906, 0xa40f, 0x4875, 0x97, 0x7f, 0x5b, 0x93, 0xff, 0x23, 0x7f, 0xc6)
#define EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID_31 \
- EFI_GUID(0x1aced566, 0x76ed, 0x4218, 0xbc, 0x81, 0x76, 0x7f, 0x1f, 0x97, 0x7a, 0x89)
+ EFI_GUID(0x1aced566, 0x76ed, 0x4218, 0xbc, 0x81, 0x76, 0x7f, 0x1f, 0x97, 0x7a, 0x89)
#define EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID \
- EFI_GUID(0xe18541cd, 0xf755, 0x4f73, 0x92, 0x8d, 0x64, 0x3c, 0x8a, 0x79, 0xb2, 0x29)
+ EFI_GUID(0xe18541cd, 0xf755, 0x4f73, 0x92, 0x8d, 0x64, 0x3c, 0x8a, 0x79, 0xb2, 0x29)
#define EFI_ISCSIDXE_INF_GUID \
- EFI_GUID(0x4579b72d, 0x7ec4, 0x4dd4, 0x84, 0x86, 0x08, 0x3c, 0x86, 0xb1, 0x82, 0xa7)
+ EFI_GUID(0x4579b72d, 0x7ec4, 0x4dd4, 0x84, 0x86, 0x08, 0x3c, 0x86, 0xb1, 0x82, 0xa7)
#define EFI_VLANCONFIGDXE_INF_GUID \
- EFI_GUID(0xe4f61863, 0xfe2c, 0x4b56, 0xa8, 0xf4, 0x08, 0x51, 0x9b, 0xc4, 0x39, 0xdf)
+ EFI_GUID(0xe4f61863, 0xfe2c, 0x4b56, 0xa8, 0xf4, 0x08, 0x51, 0x9b, 0xc4, 0x39, 0xdf)
#define EFI_TIMESTAMP_PROTOCOL_GUID \
- EFI_GUID(0xafbfde41, 0x2e6e, 0x4262, 0xba, 0x65, 0x62, 0xb9, 0x23, 0x6e, 0x54, 0x95)
+ EFI_GUID(0xafbfde41, 0x2e6e, 0x4262, 0xba, 0x65, 0x62, 0xb9, 0x23, 0x6e, 0x54, 0x95)
/* barebox specific GUIDs */
#define EFI_BAREBOX_VENDOR_GUID \
- EFI_GUID(0x5b91f69c, 0x8b88, 0x4a2b, 0x92, 0x69, 0x5f, 0x1d, 0x80, 0x2b, 0x51, 0x75)
+ EFI_GUID(0x5b91f69c, 0x8b88, 0x4a2b, 0x92, 0x69, 0x5f, 0x1d, 0x80, 0x2b, 0x51, 0x75)
/* for systemd */
#define EFI_SYSTEMD_VENDOR_GUID \
- EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
+ EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
/* for TPM 1.2 */
#define EFI_TCG_PROTOCOL_GUID \
- EFI_GUID(0xf541796d, 0xa62e, 0x4954, 0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd)
+ EFI_GUID(0xf541796d, 0xa62e, 0x4954, 0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd)
/* for TPM 2.0 */
#define EFI_TCG2_PROTOCOL_GUID \
- EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
+ EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
extern efi_guid_t efi_file_info_id;
extern efi_guid_t efi_simple_file_system_protocol_guid;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 054/112] efi: efi-guid: add more GUIDs
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (52 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 053/112] efi: unify whitespace for GUIDs Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 055/112] ARM64: cpu: setupc: rewrite to be fully PIC Ahmad Fatoum
` (57 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
These GUIDs will be useful for the incoming EFI loader support, so add
them all at once.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/guid.c | 35 +++++++++++++++++++++++++++++-
include/efi.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 93 insertions(+), 1 deletion(-)
diff --git a/efi/guid.c b/efi/guid.c
index 8103b3d63114..f6bd4a24e2bf 100644
--- a/efi/guid.c
+++ b/efi/guid.c
@@ -6,6 +6,8 @@
efi_guid_t efi_file_info_id = EFI_FILE_INFO_GUID;
efi_guid_t efi_simple_file_system_protocol_guid = EFI_SIMPLE_FILE_SYSTEM_GUID;
+efi_guid_t efi_file_system_info_guid = EFI_FILE_SYSTEM_INFO_GUID;
+efi_guid_t efi_system_volume_label_id = EFI_FILE_SYSTEM_VOLUME_LABEL_ID;
efi_guid_t efi_device_path_protocol_guid = EFI_DEVICE_PATH_PROTOCOL_GUID;
efi_guid_t efi_loaded_image_protocol_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
efi_guid_t efi_unknown_device_guid = EFI_UNKNOWN_DEVICE_GUID;
@@ -16,6 +18,32 @@ efi_guid_t efi_rng_protocol_guid = EFI_RNG_PROTOCOL_GUID;
efi_guid_t efi_barebox_vendor_guid = EFI_BAREBOX_VENDOR_GUID;
efi_guid_t efi_systemd_vendor_guid = EFI_SYSTEMD_VENDOR_GUID;
efi_guid_t efi_fdt_guid = EFI_DEVICE_TREE_GUID;
+efi_guid_t efi_loaded_image_device_path_guid =
+ EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID;
+const efi_guid_t efi_device_path_to_text_protocol_guid =
+ EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID;
+const efi_guid_t efi_dt_fixup_protocol_guid = EFI_DT_FIXUP_PROTOCOL_GUID;
+/* GUID of the EFI_DRIVER_BINDING_PROTOCOL */
+const efi_guid_t efi_driver_binding_protocol_guid = EFI_DRIVER_BINDING_PROTOCOL_GUID;
+
+/* event group ExitBootServices() invoked */
+const efi_guid_t efi_guid_event_group_exit_boot_services =
+ EFI_EVENT_GROUP_EXIT_BOOT_SERVICES;
+/* event group SetVirtualAddressMap() invoked */
+const efi_guid_t efi_guid_event_group_virtual_address_change =
+ EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE;
+/* event group memory map changed */
+const efi_guid_t efi_guid_event_group_memory_map_change =
+ EFI_EVENT_GROUP_MEMORY_MAP_CHANGE;
+/* event group boot manager about to boot */
+const efi_guid_t efi_guid_event_group_ready_to_boot = EFI_EVENT_GROUP_READY_TO_BOOT;
+/* event group ResetSystem() invoked (before ExitBootServices) */
+const efi_guid_t efi_guid_event_group_reset_system = EFI_EVENT_GROUP_RESET_SYSTEM;
+/* GUIDs of the Load File and Load File2 protocols */
+const efi_guid_t efi_load_file_protocol_guid = EFI_LOAD_FILE_PROTOCOL_GUID;
+const efi_guid_t efi_load_file2_protocol_guid = EFI_LOAD_FILE2_PROTOCOL_GUID;
+const efi_guid_t efi_device_path_utilities_protocol_guid =
+ EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID;
#define EFI_GUID_STRING(guid, short, long) do { \
if (!efi_guidcmp(guid, *g)) \
@@ -42,14 +70,19 @@ const char *efi_guid_string(efi_guid_t *g)
EFI_GUID_STRING(EFI_PCI_IO_PROTOCOL_GUID, "PCI IO Protocol", "EFI 1.1 PCI IO Protocol");
EFI_GUID_STRING(EFI_USB_IO_PROTOCOL_GUID, "USB IO Protocol", "EFI 1.0 USB IO Protocol");
EFI_GUID_STRING(EFI_FILE_INFO_GUID, "File Info", "EFI File Info");
+ EFI_GUID_STRING(EFI_FILE_SYSTEM_INFO_GUID, "Filesystem Info", "EFI FileSystem Info");
+ EFI_GUID_STRING(EFI_FILE_SYSTEM_VOLUME_LABEL_ID, "Filesystem Volume Label ID", "EFI FileSystem Volume Label ID");
EFI_GUID_STRING(EFI_SIMPLE_FILE_SYSTEM_GUID, "Filesystem", "EFI 1.0 Simple FileSystem");
EFI_GUID_STRING(EFI_DEVICE_TREE_GUID, "Device Tree", "EFI Device Tree GUID");
EFI_GUID_STRING(EFI_DEVICE_PATH_PROTOCOL_GUID, "Device Path Protocol", "EFI 1.0 Device Path protocol");
+ EFI_GUID_STRING(EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID, "Device Path To Text Protocol", "EFI Device Path To Text Protocol");
+ EFI_GUID_STRING(EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID, "Device Path Utilities Protocol", "EFI Device Path Utilities Protocol");
EFI_GUID_STRING(EFI_SIMPLE_NETWORK_PROTOCOL_GUID, "Simple Network Protocol", "EFI 1.0 Simple Network Protocol");
EFI_GUID_STRING(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, "Filesystem Protocol", "EFI 1.0 Simple FileSystem Protocol");
EFI_GUID_STRING(EFI_UNKNOWN_DEVICE_GUID, "Efi Unknown Device", "Efi Unknown Device GUID");
EFI_GUID_STRING(EFI_BLOCK_IO_PROTOCOL_GUID, "BlockIo Protocol", "EFI 1.0 Block IO protocol");
-
+ EFI_GUID_STRING(EFI_RNG_PROTOCOL_GUID, "RNG Protocol", "EFI RNG protocol");
+ EFI_GUID_STRING(EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID, "Loaded Image Device Path Protocol", "EFI LoadedImageDevicePath Protocol");
EFI_GUID_STRING(EFI_FIRMWARE_VOLUME2_PROTOCOL_GUID, "FirmwareVolume2Protocol", "Efi FirmwareVolume2Protocol");
EFI_GUID_STRING(EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID, "FirmwareVolumeBlock Protocol", "Firmware Volume Block protocol");
EFI_GUID_STRING(EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID, "PciRootBridgeIo Protocol", "EFI 1.1 Pci Root Bridge IO Protocol");
diff --git a/include/efi.h b/include/efi.h
index 8635ab58f981..ec4c2a522df4 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -306,6 +306,27 @@ struct efi_runtime_services {
extern struct efi_runtime_services *RT;
+/* EFI event group GUID definitions */
+#define EFI_EVENT_GROUP_EXIT_BOOT_SERVICES \
+ EFI_GUID(0x27abf055, 0xb1b8, 0x4c26, 0x80, 0x48, \
+ 0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf)
+
+#define EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE \
+ EFI_GUID(0x13fa7698, 0xc831, 0x49c7, 0x87, 0xea, \
+ 0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96)
+
+#define EFI_EVENT_GROUP_MEMORY_MAP_CHANGE \
+ EFI_GUID(0x78bee926, 0x692f, 0x48fd, 0x9e, 0xdb, \
+ 0x01, 0x42, 0x2e, 0xf0, 0xd7, 0xab)
+
+#define EFI_EVENT_GROUP_READY_TO_BOOT \
+ EFI_GUID(0x7ce88fb3, 0x4bd7, 0x4679, 0x87, 0xa8, \
+ 0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b)
+
+#define EFI_EVENT_GROUP_RESET_SYSTEM \
+ EFI_GUID(0x62da6a56, 0x13fb, 0x485a, 0xa8, 0xda, \
+ 0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b)
+
/*
* EFI Configuration Table and GUID definitions
*/
@@ -345,6 +366,9 @@ extern struct efi_runtime_services *RT;
#define EFI_LOADED_IMAGE_PROTOCOL_GUID \
EFI_GUID( 0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
+#define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \
+ EFI_GUID(0xbc62157e, 0x3e33, 0x4fec, 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf)
+
#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
EFI_GUID( 0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a )
@@ -363,12 +387,24 @@ extern struct efi_runtime_services *RT;
#define EFI_SIMPLE_FILE_SYSTEM_GUID \
EFI_GUID( 0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
+#define EFI_FILE_SYSTEM_INFO_GUID \
+ EFI_GUID(0x09576e93, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+
+#define EFI_FILE_SYSTEM_VOLUME_LABEL_ID \
+ EFI_GUID(0xdb47d7d3, 0xfe81, 0x11d3, 0x9a, 0x35, 0x00, 0x90, 0x27, 0x3f, 0xC1, 0x4d)
+
#define EFI_DEVICE_TREE_GUID \
EFI_GUID( 0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 )
#define EFI_DEVICE_PATH_PROTOCOL_GUID \
EFI_GUID( 0x9576e91, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
+#define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
+ EFI_GUID( 0x8b843e20, 0x8132, 0x4852, 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c)
+
+#define EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID \
+ EFI_GUID(0x0379be4e, 0xd706, 0x437d, 0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4)
+
#define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \
EFI_GUID( 0xA19832B9, 0xAC25, 0x11D3, 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D )
@@ -415,6 +451,9 @@ extern struct efi_runtime_services *RT;
#define EFI_SIMPLE_TEXT_IN_PROTOCOL_GUID \
EFI_GUID(0x387477c1, 0x69c7, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+#define EFI_CONSOLE_CONTROL_GUID \
+ EFI_GUID(0xf42f7782, 0x12e, 0x4c12, 0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21)
+
#define EFI_DISK_IO_PROTOCOL_GUID \
EFI_GUID(0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
@@ -506,8 +545,16 @@ extern struct efi_runtime_services *RT;
#define EFI_TCG2_PROTOCOL_GUID \
EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
+#define EFI_DT_FIXUP_PROTOCOL_GUID \
+ EFI_GUID(0xe617d64c, 0xfe08, 0x46da, 0xf4, 0xdc, 0xbb, 0xd5, 0x87, 0x0c, 0x73, 0x00)
+
+#define EFI_DRIVER_BINDING_PROTOCOL_GUID \
+ EFI_GUID(0x18a031ab, 0xb443, 0x4d1a, 0xa5, 0xc0, 0x0c, 0x09, 0x26, 0x1e, 0x9f, 0x71)
+
extern efi_guid_t efi_file_info_id;
extern efi_guid_t efi_simple_file_system_protocol_guid;
+extern efi_guid_t efi_file_system_info_guid;
+extern efi_guid_t efi_system_volume_label_id;
extern efi_guid_t efi_device_path_protocol_guid;
extern efi_guid_t efi_loaded_image_protocol_guid;
extern efi_guid_t efi_unknown_device_guid;
@@ -518,6 +565,18 @@ extern efi_guid_t efi_rng_protocol_guid;
extern efi_guid_t efi_barebox_vendor_guid;
extern efi_guid_t efi_systemd_vendor_guid;
extern efi_guid_t efi_fdt_guid;
+extern efi_guid_t efi_loaded_image_device_path_guid;
+extern const efi_guid_t efi_device_path_to_text_protocol_guid;
+extern const efi_guid_t efi_dt_fixup_protocol_guid;
+extern const efi_guid_t efi_driver_binding_protocol_guid;
+extern const efi_guid_t efi_guid_event_group_exit_boot_services;
+extern const efi_guid_t efi_guid_event_group_virtual_address_change;
+extern const efi_guid_t efi_guid_event_group_memory_map_change;
+extern const efi_guid_t efi_guid_event_group_ready_to_boot;
+extern const efi_guid_t efi_guid_event_group_reset_system;
+extern const efi_guid_t efi_load_file_protocol_guid;
+extern const efi_guid_t efi_load_file2_protocol_guid;
+extern const efi_guid_t efi_device_path_utilities_protocol_guid;
struct efi_config_table {
efi_guid_t guid;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 055/112] ARM64: cpu: setupc: rewrite to be fully PIC
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (53 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 054/112] efi: efi-guid: add more GUIDs Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 056/112] ARM64: runtime-offset: make get_runtime_offset " Ahmad Fatoum
` (56 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The code resulting from building the barebox ARM64 assembly contains
relocations, which could've been position-independent just as well.
Let's make them truly position independent by turning:
ldr x0, =label
into
adr_l x0, label
adr_l is position independent by virtue of being implemented using adrp,
so it's usuable as-is before relocation and requires no manual addition
of get_runtime_offset().
With these changes, only relocation necessary for the ARM64 generic DT
2nd stage is the one needed for get_runtime_offset() to find out
whether barebox has been relocated.
This is one step towards supporting mapping barebox PBL text section
W^X, which precludes relocation entries emitted for code.
With this change applied, there is still a data relocation entry
in assembly code for get_runtime_offset(), but that doesn't bother us
because it's in the data section.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/cpu/setupc_64.S | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/arch/arm/cpu/setupc_64.S b/arch/arm/cpu/setupc_64.S
index f38f893be90b..2138c2a600fa 100644
--- a/arch/arm/cpu/setupc_64.S
+++ b/arch/arm/cpu/setupc_64.S
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <linux/linkage.h>
+#include <asm/assembler.h>
#include <asm/sections.h>
.section .text.setupc
@@ -10,9 +11,9 @@
*/
ENTRY(setup_c)
mov x15, x30
- ldr x0, =__bss_start
+ adr_l x0, __bss_start
mov x1, #0
- ldr x2, =__bss_stop
+ adr_l x2, __bss_stop
sub x2, x2, x0
bl __memset /* clear bss */
mov x30, x15
@@ -29,12 +30,12 @@ ENDPROC(setup_c)
/* x0: target address */
#ifdef __PBL__
ENTRY(relocate_to_adr_full)
- ldr x2, =__image_end
+ adr_l x2, __image_end
b 1f
#endif
ENTRY(relocate_to_adr)
- ldr x2, =__bss_start
+ adr_l x2, __bss_start
b 1f
1:
@@ -45,18 +46,13 @@ ENTRY(relocate_to_adr)
mov x21, x0
- bl get_runtime_offset
- mov x5, x0
-
- ldr x0, =_text
- mov x20, x0
-
- add x1, x0, x5 /* x1: from address */
+ adr_l x1, _text
+ mov x20, x1
cmp x1, x21 /* already at correct address? */
beq 1f /* yes, skip copy to new address */
- sub x2, x2, x0 /* x2: size */
+ sub x2, x2, x1 /* x2: size */
mov x0, x21 /* x0: target */
/* adjust return address */
@@ -70,7 +66,7 @@ ENTRY(relocate_to_adr)
mov x0,#0
ic ivau, x0 /* flush icache */
- ldr x0,=1f
+ adr_l x0, 1f
sub x0, x0, x20
add x0, x0, x21
br x0 /* jump to relocated address */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 056/112] ARM64: runtime-offset: make get_runtime_offset fully PIC
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (54 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 055/112] ARM64: cpu: setupc: rewrite to be fully PIC Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 057/112] pbl: introduce CONFIG_PBL_FULLY_PIC Ahmad Fatoum
` (55 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
get_runtime_offset returns the offset that needs to be added onto
code addresses to arrive at the runtime address. This is 0 after code
relocation and the function calculates it by keeping a reference to _text
and substituting it from the actual _text address, which is found out in
a position-independent manner.
For enabling barebox PBL text section to be mappable W^X, we need to
avoid relocation entries within code, so let's move the runtime offset
into the data section, which is always mapped writable.
As ldr has only a 4K range for label references, we switch to ldr_l,
which has a 4G range.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/lib64/runtime-offset.S | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/arm/lib64/runtime-offset.S b/arch/arm/lib64/runtime-offset.S
index 822e323c142e..b10c104b4dd0 100644
--- a/arch/arm/lib64/runtime-offset.S
+++ b/arch/arm/lib64/runtime-offset.S
@@ -11,10 +11,12 @@
*/
ENTRY(get_runtime_offset)
adr x0, _text
- ldr x1, linkadr
+ ldr_l x1, linkadr
subs x0, x0, x1
ret
+ENDPROC(get_runtime_offset)
+.section ".data.runtime_offset","a"
.align 3
linkadr:
/*
@@ -24,4 +26,3 @@ linkadr:
* use _text here since that is 0x0 and is correct without relocation.
*/
.quad _text
-ENDPROC(get_runtime_offset)
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 057/112] pbl: introduce CONFIG_PBL_FULLY_PIC
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (55 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 056/112] ARM64: runtime-offset: make get_runtime_offset " Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-08 7:47 ` Sascha Hauer
2024-01-03 18:12 ` [PATCH 058/112] efi: payload: fix ARM build Ahmad Fatoum
` (54 subsequent siblings)
111 siblings, 1 reply; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
In the quest for making barebox PBL code W^X mappable, we have now taken
care to make the ARM64 assembly routines not emit code relocations,
so let's do the same for the C code as well.
We do this by setting pragma GCC visibility push(hidden) globally. This
option is stronger than -fvisibility=hidden and ensures we are
completely position-independent. See kernel commit e544ea57ac07
("x86/boot/compressed: Force hidden visibility for all symbol references")
for more information.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/export.h | 2 +-
include/linux/hidden.h | 19 +++++++++++++++++++
pbl/Kconfig | 7 +++++++
scripts/Makefile.lib | 5 +++++
scripts/Makefile.pic | 22 ++++++++++++++++++++++
5 files changed, 54 insertions(+), 1 deletion(-)
create mode 100644 include/linux/hidden.h
create mode 100644 scripts/Makefile.pic
diff --git a/include/linux/export.h b/include/linux/export.h
index 8f47742bea99..a136d727d128 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -6,7 +6,7 @@
#define THIS_MODULE 0
-#ifdef CONFIG_MODULES
+#if defined(CONFIG_MODULES) && !defined(__DISABLE_EXPORTS)
struct kernel_symbol
{
diff --git a/include/linux/hidden.h b/include/linux/hidden.h
new file mode 100644
index 000000000000..49a17b6b5962
--- /dev/null
+++ b/include/linux/hidden.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * When building position independent code with GCC using the -fPIC option,
+ * (or even the -fPIE one on older versions), it will assume that we are
+ * building a dynamic object (either a shared library or an executable) that
+ * may have symbol references that can only be resolved at load time. For a
+ * variety of reasons (ELF symbol preemption, the CoW footprint of the section
+ * that is modified by the loader), this results in all references to symbols
+ * with external linkage to go via entries in the Global Offset Table (GOT),
+ * which carries absolute addresses which need to be fixed up when the
+ * executable image is loaded at an offset which is different from its link
+ * time offset.
+ *
+ * Fortunately, there is a way to inform the compiler that such symbol
+ * references will be satisfied at link time rather than at load time, by
+ * giving them 'hidden' visibility.
+ */
+
+#pragma GCC visibility push(hidden)
diff --git a/pbl/Kconfig b/pbl/Kconfig
index 91970c19bc1e..23fcbd20dacd 100644
--- a/pbl/Kconfig
+++ b/pbl/Kconfig
@@ -46,6 +46,13 @@ config PBL_RELOCATABLE
This option only influences the PBL image. See RELOCATABLE to also make
the real image relocatable.
+config PBL_FULLY_PIC
+ bool "fully position-independent pbl image"
+ depends on PBL_RELOCATABLE && ARM
+ help
+ Compared to CONFIG_PBL_RELOCATABLE, this image has no relocations in
+ the code sections.
+
config PBL_VERIFY_PIGGY
depends on ARM
bool
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 0b236babb275..ec9cb4bf4028 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -170,6 +170,11 @@ _stackp_flags_pbl-$(CONFIG_PBL_STACKPROTECTOR_ALL) := -fstack-protector-all
_c_flags += $(if $(part-of-pbl),$(_stackp_flags_pbl-y),$(_stackp_flags-y))
+ifeq ($(CONFIG_PBL_FULLY_PIC),y)
+include scripts/Makefile.pic
+PBL_CPPFLAGS += $(picflags-y)
+endif
+
# If building barebox in a separate objtree expand all occurrences
# of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
diff --git a/scripts/Makefile.pic b/scripts/Makefile.pic
new file mode 100644
index 000000000000..c30894ba98d9
--- /dev/null
+++ b/scripts/Makefile.pic
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# The stub may be linked into the kernel proper or into a separate boot binary,
+# but in either case, it executes before the kernel does (with MMU disabled) so
+# things like ftrace and stack-protector are likely to cause trouble if left
+# enabled, even if doing so doesn't break the build.
+#
+picflags-$(CONFIG_X86_64) := -mcmodel=small
+picflags-$(CONFIG_X86) += -fPIC -fno-asynchronous-unwind-tables
+
+ifeq ($(CONFIG_ARM),y)
+picflags-$(CONFIG_CPU_32) := -fpic -mno-single-pic-base
+picflags-$(CONFIG_CPU_64) := -fpie
+endif
+
+picflags-y += -include $(srctree)/include/linux/hidden.h \
+ -D__fully_pic__ \
+ -D__NO_FORTIFY \
+ -ffreestanding \
+ -fno-stack-protector \
+ $(call cc-option,-fno-addrsig) \
+ -D__DISABLE_EXPORTS
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 057/112] pbl: introduce CONFIG_PBL_FULLY_PIC
2024-01-03 18:12 ` [PATCH 057/112] pbl: introduce CONFIG_PBL_FULLY_PIC Ahmad Fatoum
@ 2024-01-08 7:47 ` Sascha Hauer
2024-01-22 19:15 ` Ahmad Fatoum
0 siblings, 1 reply; 134+ messages in thread
From: Sascha Hauer @ 2024-01-08 7:47 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Jan 03, 2024 at 07:12:17PM +0100, Ahmad Fatoum wrote:
> In the quest for making barebox PBL code W^X mappable, we have now taken
> care to make the ARM64 assembly routines not emit code relocations,
> so let's do the same for the C code as well.
>
> We do this by setting pragma GCC visibility push(hidden) globally. This
> option is stronger than -fvisibility=hidden and ensures we are
> completely position-independent. See kernel commit e544ea57ac07
> ("x86/boot/compressed: Force hidden visibility for all symbol references")
> for more information.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> include/linux/export.h | 2 +-
> include/linux/hidden.h | 19 +++++++++++++++++++
> pbl/Kconfig | 7 +++++++
> scripts/Makefile.lib | 5 +++++
> scripts/Makefile.pic | 22 ++++++++++++++++++++++
> 5 files changed, 54 insertions(+), 1 deletion(-)
> create mode 100644 include/linux/hidden.h
> create mode 100644 scripts/Makefile.pic
>
> diff --git a/include/linux/export.h b/include/linux/export.h
> index 8f47742bea99..a136d727d128 100644
> --- a/include/linux/export.h
> +++ b/include/linux/export.h
> @@ -6,7 +6,7 @@
>
> #define THIS_MODULE 0
>
> -#ifdef CONFIG_MODULES
> +#if defined(CONFIG_MODULES) && !defined(__DISABLE_EXPORTS)
>
> struct kernel_symbol
> {
> diff --git a/include/linux/hidden.h b/include/linux/hidden.h
> new file mode 100644
> index 000000000000..49a17b6b5962
> --- /dev/null
> +++ b/include/linux/hidden.h
> @@ -0,0 +1,19 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * When building position independent code with GCC using the -fPIC option,
> + * (or even the -fPIE one on older versions), it will assume that we are
> + * building a dynamic object (either a shared library or an executable) that
> + * may have symbol references that can only be resolved at load time. For a
> + * variety of reasons (ELF symbol preemption, the CoW footprint of the section
> + * that is modified by the loader), this results in all references to symbols
> + * with external linkage to go via entries in the Global Offset Table (GOT),
> + * which carries absolute addresses which need to be fixed up when the
> + * executable image is loaded at an offset which is different from its link
> + * time offset.
> + *
> + * Fortunately, there is a way to inform the compiler that such symbol
> + * references will be satisfied at link time rather than at load time, by
> + * giving them 'hidden' visibility.
> + */
> +
> +#pragma GCC visibility push(hidden)
> diff --git a/pbl/Kconfig b/pbl/Kconfig
> index 91970c19bc1e..23fcbd20dacd 100644
> --- a/pbl/Kconfig
> +++ b/pbl/Kconfig
> @@ -46,6 +46,13 @@ config PBL_RELOCATABLE
> This option only influences the PBL image. See RELOCATABLE to also make
> the real image relocatable.
>
> +config PBL_FULLY_PIC
> + bool "fully position-independent pbl image"
> + depends on PBL_RELOCATABLE && ARM
> + help
> + Compared to CONFIG_PBL_RELOCATABLE, this image has no relocations in
> + the code sections.
Shouldn't we make PBL_FULLY_PIC the default when available?
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 057/112] pbl: introduce CONFIG_PBL_FULLY_PIC
2024-01-08 7:47 ` Sascha Hauer
@ 2024-01-22 19:15 ` Ahmad Fatoum
0 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-22 19:15 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 08.01.24 08:47, Sascha Hauer wrote:
> On Wed, Jan 03, 2024 at 07:12:17PM +0100, Ahmad Fatoum wrote:
>> In the quest for making barebox PBL code W^X mappable, we have now taken
>> care to make the ARM64 assembly routines not emit code relocations,
>> so let's do the same for the C code as well.
>>
>> We do this by setting pragma GCC visibility push(hidden) globally. This
>> option is stronger than -fvisibility=hidden and ensures we are
>> completely position-independent. See kernel commit e544ea57ac07
>> ("x86/boot/compressed: Force hidden visibility for all symbol references")
>> for more information.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> include/linux/export.h | 2 +-
>> include/linux/hidden.h | 19 +++++++++++++++++++
>> pbl/Kconfig | 7 +++++++
>> scripts/Makefile.lib | 5 +++++
>> scripts/Makefile.pic | 22 ++++++++++++++++++++++
>> 5 files changed, 54 insertions(+), 1 deletion(-)
>> create mode 100644 include/linux/hidden.h
>> create mode 100644 scripts/Makefile.pic
>>
>> diff --git a/include/linux/export.h b/include/linux/export.h
>> index 8f47742bea99..a136d727d128 100644
>> --- a/include/linux/export.h
>> +++ b/include/linux/export.h
>> @@ -6,7 +6,7 @@
>>
>> #define THIS_MODULE 0
>>
>> -#ifdef CONFIG_MODULES
>> +#if defined(CONFIG_MODULES) && !defined(__DISABLE_EXPORTS)
>>
>> struct kernel_symbol
>> {
>> diff --git a/include/linux/hidden.h b/include/linux/hidden.h
>> new file mode 100644
>> index 000000000000..49a17b6b5962
>> --- /dev/null
>> +++ b/include/linux/hidden.h
>> @@ -0,0 +1,19 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/*
>> + * When building position independent code with GCC using the -fPIC option,
>> + * (or even the -fPIE one on older versions), it will assume that we are
>> + * building a dynamic object (either a shared library or an executable) that
>> + * may have symbol references that can only be resolved at load time. For a
>> + * variety of reasons (ELF symbol preemption, the CoW footprint of the section
>> + * that is modified by the loader), this results in all references to symbols
>> + * with external linkage to go via entries in the Global Offset Table (GOT),
>> + * which carries absolute addresses which need to be fixed up when the
>> + * executable image is loaded at an offset which is different from its link
>> + * time offset.
>> + *
>> + * Fortunately, there is a way to inform the compiler that such symbol
>> + * references will be satisfied at link time rather than at load time, by
>> + * giving them 'hidden' visibility.
>> + */
>> +
>> +#pragma GCC visibility push(hidden)
>> diff --git a/pbl/Kconfig b/pbl/Kconfig
>> index 91970c19bc1e..23fcbd20dacd 100644
>> --- a/pbl/Kconfig
>> +++ b/pbl/Kconfig
>> @@ -46,6 +46,13 @@ config PBL_RELOCATABLE
>> This option only influences the PBL image. See RELOCATABLE to also make
>> the real image relocatable.
>>
>> +config PBL_FULLY_PIC
>> + bool "fully position-independent pbl image"
>> + depends on PBL_RELOCATABLE && ARM
>> + help
>> + Compared to CONFIG_PBL_RELOCATABLE, this image has no relocations in
>> + the code sections.
>
> Shouldn't we make PBL_FULLY_PIC the default when available?
Eventually, yes. But I want this to get some more testing before making it so.
>
> Sascha
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 058/112] efi: payload: fix ARM build
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (56 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 057/112] pbl: introduce CONFIG_PBL_FULLY_PIC Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86 Ahmad Fatoum
` (53 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
So far we only ever built EFI for x86. Prepare building it for ARM by
removing the x86-specific attributes.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/image.c | 4 ++--
include/efi/types.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/efi/payload/image.c b/efi/payload/image.c
index f9706c028ed9..8e5ad87de22f 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -217,8 +217,8 @@ static inline void linux_efi_handover(efi_handle_t handle,
handover(handle, efi_sys_table, header);
}
#else
-typedef void(*handover_fn)(VOID *image, EFI_SYSTEM_TABLE *table,
- struct SetupHeader *setup) __attribute__((regparm(0)));
+typedef void(*handover_fn)(void *image, struct efi_system_table *table,
+ struct linux_kernel_header *setup);
static inline void linux_efi_handover(efi_handle_t handle,
struct linux_kernel_header *header)
diff --git a/include/efi/types.h b/include/efi/types.h
index 3d42948d2b62..6e134387692f 100644
--- a/include/efi/types.h
+++ b/include/efi/types.h
@@ -33,7 +33,7 @@ typedef guid_t efi_guid_t __aligned(__alignof__(u32));
(c) & 0xff, ((c) >> 8) & 0xff, \
(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
-#ifdef CONFIG_EFI_PAYLOAD
+#ifdef __x86_64__
#define EFIAPI __attribute__((ms_abi))
#else
#define EFIAPI
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (57 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 058/112] efi: payload: fix ARM build Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:58 ` Michael Olbrich
2024-01-03 18:12 ` [PATCH 060/112] ARM: pbl: add 64K segment alignment for PE/COFF Ahmad Fatoum
` (52 subsequent siblings)
111 siblings, 1 reply; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Michael Olbrich, Ahmad Fatoum
When run as EFI payload, barebox will not have full access to DRAM and will
have to ask the EFI firmware for memory. It does so once at the beginning
and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
the buffer was always placed beneath the 1G boundary.
Aforementioned commit didn't elaborate why a maximum of 1G in particular
was chosen. Anyways, non-PC architectures have different memory maps, so
a 1G limit doesn't make sense there. Therefore restrict the limit to
ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.
This can break PCI drivers on systems that so far assumed barebox memory
is located in the first 4G, but that's ok. That code will need to be
fixed eventually anyway.
Cc: Michael Olbrich <m.olbrich@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/init.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/efi/payload/init.c b/efi/payload/init.c
index 4b612e61afb3..0c2f38e9c86a 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -292,7 +292,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
BS->handle_protocol(efi_loaded_image->device_handle,
&efi_device_path_protocol_guid, (void **)&efi_device_path);
- mem = 0x3fffffff;
+ mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
EFI_LOADER_DATA,
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86
2024-01-03 18:12 ` [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86 Ahmad Fatoum
@ 2024-01-03 18:58 ` Michael Olbrich
2024-01-04 11:17 ` Ahmad Fatoum
0 siblings, 1 reply; 134+ messages in thread
From: Michael Olbrich @ 2024-01-03 18:58 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Jan 03, 2024 at 07:12:19PM +0100, Ahmad Fatoum wrote:
> When run as EFI payload, barebox will not have full access to DRAM and will
> have to ask the EFI firmware for memory. It does so once at the beginning
> and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
> the buffer was always placed beneath the 1G boundary.
>
> Aforementioned commit didn't elaborate why a maximum of 1G in particular
> was chosen. Anyways, non-PC architectures have different memory maps, so
> a 1G limit doesn't make sense there. Therefore restrict the limit to
> ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.
The 1G is somewhat arbitrary but if you don't restrict the memory to 32bit,
then loading the kernel may fail: The addresses in "struct
linux_kernel_header" are only 32bit. So if you impose no restrictions at
all, then this memory cannot be used for the kernel and initrd.
Regards,
Michael
> This can break PCI drivers on systems that so far assumed barebox memory
> is located in the first 4G, but that's ok. That code will need to be
> fixed eventually anyway.
>
> Cc: Michael Olbrich <m.olbrich@pengutronix.de>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> efi/payload/init.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/efi/payload/init.c b/efi/payload/init.c
> index 4b612e61afb3..0c2f38e9c86a 100644
> --- a/efi/payload/init.c
> +++ b/efi/payload/init.c
> @@ -292,7 +292,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
> BS->handle_protocol(efi_loaded_image->device_handle,
> &efi_device_path_protocol_guid, (void **)&efi_device_path);
>
> - mem = 0x3fffffff;
> + mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
> for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
> efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
> EFI_LOADER_DATA,
> --
> 2.39.2
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86
2024-01-03 18:58 ` Michael Olbrich
@ 2024-01-04 11:17 ` Ahmad Fatoum
2024-01-04 18:10 ` Michael Olbrich
0 siblings, 1 reply; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-04 11:17 UTC (permalink / raw)
To: barebox, Michael Olbrich
On 03.01.24 19:58, Michael Olbrich wrote:
> On Wed, Jan 03, 2024 at 07:12:19PM +0100, Ahmad Fatoum wrote:
>> When run as EFI payload, barebox will not have full access to DRAM and will
>> have to ask the EFI firmware for memory. It does so once at the beginning
>> and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
>> the buffer was always placed beneath the 1G boundary.
>>
>> Aforementioned commit didn't elaborate why a maximum of 1G in particular
>> was chosen. Anyways, non-PC architectures have different memory maps, so
>> a 1G limit doesn't make sense there. Therefore restrict the limit to
>> ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.
>
> The 1G is somewhat arbitrary but if you don't restrict the memory to 32bit,
> then loading the kernel may fail: The addresses in "struct
> linux_kernel_header" are only 32bit. So if you impose no restrictions at
> all, then this memory cannot be used for the kernel and initrd.
The limit for x86 remains at 1G. It's only for other architectures, that we
remove the limit. I suspect that other architectures won't have this kind
of problems though , because they would boot the kernel image via EFI load
and start image boot services, where the EFI firmware takes care to layout
the boot artifacts.
Once we have that in place, we could even use it on x86 instead of
using struct linux_kernel_header, but I haven't investigated this yet.
Thanks,
Ahmad
>
> Regards,
> Michael
>
>> This can break PCI drivers on systems that so far assumed barebox memory
>> is located in the first 4G, but that's ok. That code will need to be
>> fixed eventually anyway.
>>
>> Cc: Michael Olbrich <m.olbrich@pengutronix.de>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> efi/payload/init.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/efi/payload/init.c b/efi/payload/init.c
>> index 4b612e61afb3..0c2f38e9c86a 100644
>> --- a/efi/payload/init.c
>> +++ b/efi/payload/init.c
>> @@ -292,7 +292,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
>> BS->handle_protocol(efi_loaded_image->device_handle,
>> &efi_device_path_protocol_guid, (void **)&efi_device_path);
>>
>> - mem = 0x3fffffff;
>> + mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
>> for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
>> efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
>> EFI_LOADER_DATA,
>> --
>> 2.39.2
>>
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86
2024-01-04 11:17 ` Ahmad Fatoum
@ 2024-01-04 18:10 ` Michael Olbrich
2024-01-05 9:14 ` Ahmad Fatoum
0 siblings, 1 reply; 134+ messages in thread
From: Michael Olbrich @ 2024-01-04 18:10 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Thu, Jan 04, 2024 at 12:17:12PM +0100, Ahmad Fatoum wrote:
> On 03.01.24 19:58, Michael Olbrich wrote:
> > On Wed, Jan 03, 2024 at 07:12:19PM +0100, Ahmad Fatoum wrote:
> >> When run as EFI payload, barebox will not have full access to DRAM and will
> >> have to ask the EFI firmware for memory. It does so once at the beginning
> >> and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
> >> the buffer was always placed beneath the 1G boundary.
> >>
> >> Aforementioned commit didn't elaborate why a maximum of 1G in particular
> >> was chosen. Anyways, non-PC architectures have different memory maps, so
> >> a 1G limit doesn't make sense there. Therefore restrict the limit to
> >> ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.
> >
> > The 1G is somewhat arbitrary but if you don't restrict the memory to 32bit,
> > then loading the kernel may fail: The addresses in "struct
> > linux_kernel_header" are only 32bit. So if you impose no restrictions at
> > all, then this memory cannot be used for the kernel and initrd.
>
> The limit for x86 remains at 1G. It's only for other architectures, that we
> remove the limit. I suspect that other architectures won't have this kind
> of problems though , because they would boot the kernel image via EFI load
> and start image boot services, where the EFI firmware takes care to layout
> the boot artifacts.
>
> Once we have that in place, we could even use it on x86 instead of
> using struct linux_kernel_header, but I haven't investigated this yet.
How do you load the initrd via EFI? As far as I know, that only works as a
filename in the EFI boot partition. That was the reason for implementing
the "legacy" boot mode. And what about the device-tree?
Michael
> >> This can break PCI drivers on systems that so far assumed barebox memory
> >> is located in the first 4G, but that's ok. That code will need to be
> >> fixed eventually anyway.
> >>
> >> Cc: Michael Olbrich <m.olbrich@pengutronix.de>
> >> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> >> ---
> >> efi/payload/init.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/efi/payload/init.c b/efi/payload/init.c
> >> index 4b612e61afb3..0c2f38e9c86a 100644
> >> --- a/efi/payload/init.c
> >> +++ b/efi/payload/init.c
> >> @@ -292,7 +292,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
> >> BS->handle_protocol(efi_loaded_image->device_handle,
> >> &efi_device_path_protocol_guid, (void **)&efi_device_path);
> >>
> >> - mem = 0x3fffffff;
> >> + mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
> >> for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
> >> efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
> >> EFI_LOADER_DATA,
> >> --
> >> 2.39.2
> >>
> >>
> >
>
> --
> Pengutronix e.K. | |
> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86
2024-01-04 18:10 ` Michael Olbrich
@ 2024-01-05 9:14 ` Ahmad Fatoum
2024-01-05 9:31 ` Michael Olbrich
0 siblings, 1 reply; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-05 9:14 UTC (permalink / raw)
To: barebox, Michael Olbrich
Hello Michael,
On 04.01.24 19:10, Michael Olbrich wrote:
> On Thu, Jan 04, 2024 at 12:17:12PM +0100, Ahmad Fatoum wrote:
>> On 03.01.24 19:58, Michael Olbrich wrote:
>>> On Wed, Jan 03, 2024 at 07:12:19PM +0100, Ahmad Fatoum wrote:
>>>> When run as EFI payload, barebox will not have full access to DRAM and will
>>>> have to ask the EFI firmware for memory. It does so once at the beginning
>>>> and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
>>>> the buffer was always placed beneath the 1G boundary.
>>>>
>>>> Aforementioned commit didn't elaborate why a maximum of 1G in particular
>>>> was chosen. Anyways, non-PC architectures have different memory maps, so
>>>> a 1G limit doesn't make sense there. Therefore restrict the limit to
>>>> ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.
>>>
>>> The 1G is somewhat arbitrary but if you don't restrict the memory to 32bit,
>>> then loading the kernel may fail: The addresses in "struct
>>> linux_kernel_header" are only 32bit. So if you impose no restrictions at
>>> all, then this memory cannot be used for the kernel and initrd.
>>
>> The limit for x86 remains at 1G. It's only for other architectures, that we
>> remove the limit. I suspect that other architectures won't have this kind
>> of problems though , because they would boot the kernel image via EFI load
>> and start image boot services, where the EFI firmware takes care to layout
>> the boot artifacts.
>>
>> Once we have that in place, we could even use it on x86 instead of
>> using struct linux_kernel_header, but I haven't investigated this yet.
>
> How do you load the initrd via EFI? As far as I know, that only works as a
> filename in the EFI boot partition.
This seems to be relaxed in newer kernels, see
https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/
> That was the reason for implementing
> the "legacy" boot mode. And what about the device-tree?
There is an EFI config table for FDT (DEVICE_TREE_GUID in Linux code). barebox
as EFI loader can use it to provide its own DT. I have to check what's the cleanest
way for barebox as EFI payload to provide a different DT, but I hope there is a way
without barebox as EFI payload having to manipulate the device tree itself.
Cheers,
Ahmad
>
> Michael
>
>>>> This can break PCI drivers on systems that so far assumed barebox memory
>>>> is located in the first 4G, but that's ok. That code will need to be
>>>> fixed eventually anyway.
>>>>
>>>> Cc: Michael Olbrich <m.olbrich@pengutronix.de>
>>>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>>>> ---
>>>> efi/payload/init.c | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/efi/payload/init.c b/efi/payload/init.c
>>>> index 4b612e61afb3..0c2f38e9c86a 100644
>>>> --- a/efi/payload/init.c
>>>> +++ b/efi/payload/init.c
>>>> @@ -292,7 +292,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
>>>> BS->handle_protocol(efi_loaded_image->device_handle,
>>>> &efi_device_path_protocol_guid, (void **)&efi_device_path);
>>>>
>>>> - mem = 0x3fffffff;
>>>> + mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
>>>> for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
>>>> efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
>>>> EFI_LOADER_DATA,
>>>> --
>>>> 2.39.2
>>>>
>>>>
>>>
>>
>> --
>> Pengutronix e.K. | |
>> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
>> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
>> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>>
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86
2024-01-05 9:14 ` Ahmad Fatoum
@ 2024-01-05 9:31 ` Michael Olbrich
2024-01-05 10:41 ` Ahmad Fatoum
0 siblings, 1 reply; 134+ messages in thread
From: Michael Olbrich @ 2024-01-05 9:31 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
Hi,
On Fri, Jan 05, 2024 at 10:14:33AM +0100, Ahmad Fatoum wrote:
> On 04.01.24 19:10, Michael Olbrich wrote:
> > On Thu, Jan 04, 2024 at 12:17:12PM +0100, Ahmad Fatoum wrote:
> >> On 03.01.24 19:58, Michael Olbrich wrote:
> >>> On Wed, Jan 03, 2024 at 07:12:19PM +0100, Ahmad Fatoum wrote:
> >>>> When run as EFI payload, barebox will not have full access to DRAM and will
> >>>> have to ask the EFI firmware for memory. It does so once at the beginning
> >>>> and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
> >>>> the buffer was always placed beneath the 1G boundary.
> >>>>
> >>>> Aforementioned commit didn't elaborate why a maximum of 1G in particular
> >>>> was chosen. Anyways, non-PC architectures have different memory maps, so
> >>>> a 1G limit doesn't make sense there. Therefore restrict the limit to
> >>>> ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.
> >>>
> >>> The 1G is somewhat arbitrary but if you don't restrict the memory to 32bit,
> >>> then loading the kernel may fail: The addresses in "struct
> >>> linux_kernel_header" are only 32bit. So if you impose no restrictions at
> >>> all, then this memory cannot be used for the kernel and initrd.
> >>
> >> The limit for x86 remains at 1G. It's only for other architectures, that we
> >> remove the limit. I suspect that other architectures won't have this kind
> >> of problems though , because they would boot the kernel image via EFI load
> >> and start image boot services, where the EFI firmware takes care to layout
> >> the boot artifacts.
> >>
> >> Once we have that in place, we could even use it on x86 instead of
> >> using struct linux_kernel_header, but I haven't investigated this yet.
> >
> > How do you load the initrd via EFI? As far as I know, that only works as a
> > filename in the EFI boot partition.
>
> This seems to be relaxed in newer kernels, see
> https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/
It's not quite clear to me how that works, but from what I can tell,
requires support from the firmware and barebox needs to use it. So that
does not help here.
You need to either disable the legacy handler to avoid arbitrary failures
or explicitly allocate the initrd memory from efi with the restriction to
<4G.
Michael
> > That was the reason for implementing
> > the "legacy" boot mode. And what about the device-tree?
>
> There is an EFI config table for FDT (DEVICE_TREE_GUID in Linux code). barebox
> as EFI loader can use it to provide its own DT. I have to check what's the cleanest
> way for barebox as EFI payload to provide a different DT, but I hope there is a way
> without barebox as EFI payload having to manipulate the device tree itself.
>
> Cheers,
> Ahmad
>
> >
> > Michael
> >
> >>>> This can break PCI drivers on systems that so far assumed barebox memory
> >>>> is located in the first 4G, but that's ok. That code will need to be
> >>>> fixed eventually anyway.
> >>>>
> >>>> Cc: Michael Olbrich <m.olbrich@pengutronix.de>
> >>>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> >>>> ---
> >>>> efi/payload/init.c | 2 +-
> >>>> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>>>
> >>>> diff --git a/efi/payload/init.c b/efi/payload/init.c
> >>>> index 4b612e61afb3..0c2f38e9c86a 100644
> >>>> --- a/efi/payload/init.c
> >>>> +++ b/efi/payload/init.c
> >>>> @@ -292,7 +292,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
> >>>> BS->handle_protocol(efi_loaded_image->device_handle,
> >>>> &efi_device_path_protocol_guid, (void **)&efi_device_path);
> >>>>
> >>>> - mem = 0x3fffffff;
> >>>> + mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
> >>>> for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
> >>>> efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
> >>>> EFI_LOADER_DATA,
> >>>> --
> >>>> 2.39.2
> >>>>
> >>>>
> >>>
> >>
> >> --
> >> Pengutronix e.K. | |
> >> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> >> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> >> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
> >>
> >>
> >
>
> --
> Pengutronix e.K. | |
> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86
2024-01-05 9:31 ` Michael Olbrich
@ 2024-01-05 10:41 ` Ahmad Fatoum
2024-01-05 14:58 ` Michael Olbrich
0 siblings, 1 reply; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-05 10:41 UTC (permalink / raw)
To: barebox
On 05.01.24 10:31, Michael Olbrich wrote:
> Hi,
>
> On Fri, Jan 05, 2024 at 10:14:33AM +0100, Ahmad Fatoum wrote:
>> On 04.01.24 19:10, Michael Olbrich wrote:
>>> On Thu, Jan 04, 2024 at 12:17:12PM +0100, Ahmad Fatoum wrote:
>>>> On 03.01.24 19:58, Michael Olbrich wrote:
>>>>> On Wed, Jan 03, 2024 at 07:12:19PM +0100, Ahmad Fatoum wrote:
>>>>>> When run as EFI payload, barebox will not have full access to DRAM and will
>>>>>> have to ask the EFI firmware for memory. It does so once at the beginning
>>>>>> and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
>>>>>> the buffer was always placed beneath the 1G boundary.
>>>>>>
>>>>>> Aforementioned commit didn't elaborate why a maximum of 1G in particular
>>>>>> was chosen. Anyways, non-PC architectures have different memory maps, so
>>>>>> a 1G limit doesn't make sense there. Therefore restrict the limit to
>>>>>> ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.
>>>>>
>>>>> The 1G is somewhat arbitrary but if you don't restrict the memory to 32bit,
>>>>> then loading the kernel may fail: The addresses in "struct
>>>>> linux_kernel_header" are only 32bit. So if you impose no restrictions at
>>>>> all, then this memory cannot be used for the kernel and initrd.
>>>>
>>>> The limit for x86 remains at 1G. It's only for other architectures, that we
>>>> remove the limit. I suspect that other architectures won't have this kind
>>>> of problems though , because they would boot the kernel image via EFI load
>>>> and start image boot services, where the EFI firmware takes care to layout
>>>> the boot artifacts.
>>>>
>>>> Once we have that in place, we could even use it on x86 instead of
>>>> using struct linux_kernel_header, but I haven't investigated this yet.
>>>
>>> How do you load the initrd via EFI? As far as I know, that only works as a
>>> filename in the EFI boot partition.
>>
>> This seems to be relaxed in newer kernels, see
>> https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/
>
> It's not quite clear to me how that works, but from what I can tell,
> requires support from the firmware and barebox needs to use it. So that
> does not help here.
> You need to either disable the legacy handler to avoid arbitrary failures
> or explicitly allocate the initrd memory from efi with the restriction to
> <4G.
The legacy handler wouldn't apply to other architectures:
- The Kernel images for ARM64 and RISC-V have different more-specific filetypes
than filetype_exe
- The Linux kernel header check will probabaly fail for every format that's not
x86
Cheers,
Ahmad
>
> Michael
>
>>> That was the reason for implementing
>>> the "legacy" boot mode. And what about the device-tree?
>>
>> There is an EFI config table for FDT (DEVICE_TREE_GUID in Linux code). barebox
>> as EFI loader can use it to provide its own DT. I have to check what's the cleanest
>> way for barebox as EFI payload to provide a different DT, but I hope there is a way
>> without barebox as EFI payload having to manipulate the device tree itself.
>>
>> Cheers,
>> Ahmad
>>
>>>
>>> Michael
>>>
>>>>>> This can break PCI drivers on systems that so far assumed barebox memory
>>>>>> is located in the first 4G, but that's ok. That code will need to be
>>>>>> fixed eventually anyway.
>>>>>>
>>>>>> Cc: Michael Olbrich <m.olbrich@pengutronix.de>
>>>>>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>>>>>> ---
>>>>>> efi/payload/init.c | 2 +-
>>>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>>
>>>>>> diff --git a/efi/payload/init.c b/efi/payload/init.c
>>>>>> index 4b612e61afb3..0c2f38e9c86a 100644
>>>>>> --- a/efi/payload/init.c
>>>>>> +++ b/efi/payload/init.c
>>>>>> @@ -292,7 +292,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
>>>>>> BS->handle_protocol(efi_loaded_image->device_handle,
>>>>>> &efi_device_path_protocol_guid, (void **)&efi_device_path);
>>>>>>
>>>>>> - mem = 0x3fffffff;
>>>>>> + mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
>>>>>> for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
>>>>>> efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
>>>>>> EFI_LOADER_DATA,
>>>>>> --
>>>>>> 2.39.2
>>>>>>
>>>>>>
>>>>>
>>>>
>>>> --
>>>> Pengutronix e.K. | |
>>>> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
>>>> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
>>>> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>>>>
>>>>
>>>
>>
>> --
>> Pengutronix e.K. | |
>> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
>> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
>> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>>
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86
2024-01-05 10:41 ` Ahmad Fatoum
@ 2024-01-05 14:58 ` Michael Olbrich
2024-01-08 7:22 ` Ahmad Fatoum
0 siblings, 1 reply; 134+ messages in thread
From: Michael Olbrich @ 2024-01-05 14:58 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Fri, Jan 05, 2024 at 11:41:09AM +0100, Ahmad Fatoum wrote:
> On 05.01.24 10:31, Michael Olbrich wrote:
> > On Fri, Jan 05, 2024 at 10:14:33AM +0100, Ahmad Fatoum wrote:
> >> On 04.01.24 19:10, Michael Olbrich wrote:
> >>> On Thu, Jan 04, 2024 at 12:17:12PM +0100, Ahmad Fatoum wrote:
> >>>> On 03.01.24 19:58, Michael Olbrich wrote:
> >>>>> On Wed, Jan 03, 2024 at 07:12:19PM +0100, Ahmad Fatoum wrote:
> >>>>>> When run as EFI payload, barebox will not have full access to DRAM and will
> >>>>>> have to ask the EFI firmware for memory. It does so once at the beginning
> >>>>>> and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
> >>>>>> the buffer was always placed beneath the 1G boundary.
> >>>>>>
> >>>>>> Aforementioned commit didn't elaborate why a maximum of 1G in particular
> >>>>>> was chosen. Anyways, non-PC architectures have different memory maps, so
> >>>>>> a 1G limit doesn't make sense there. Therefore restrict the limit to
> >>>>>> ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.
> >>>>>
> >>>>> The 1G is somewhat arbitrary but if you don't restrict the memory to 32bit,
> >>>>> then loading the kernel may fail: The addresses in "struct
> >>>>> linux_kernel_header" are only 32bit. So if you impose no restrictions at
> >>>>> all, then this memory cannot be used for the kernel and initrd.
> >>>>
> >>>> The limit for x86 remains at 1G. It's only for other architectures, that we
> >>>> remove the limit. I suspect that other architectures won't have this kind
> >>>> of problems though , because they would boot the kernel image via EFI load
> >>>> and start image boot services, where the EFI firmware takes care to layout
> >>>> the boot artifacts.
> >>>>
> >>>> Once we have that in place, we could even use it on x86 instead of
> >>>> using struct linux_kernel_header, but I haven't investigated this yet.
> >>>
> >>> How do you load the initrd via EFI? As far as I know, that only works as a
> >>> filename in the EFI boot partition.
> >>
> >> This seems to be relaxed in newer kernels, see
> >> https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/
> >
> > It's not quite clear to me how that works, but from what I can tell,
> > requires support from the firmware and barebox needs to use it. So that
> > does not help here.
> > You need to either disable the legacy handler to avoid arbitrary failures
> > or explicitly allocate the initrd memory from efi with the restriction to
> > <4G.
>
> The legacy handler wouldn't apply to other architectures:
>
> - The Kernel images for ARM64 and RISC-V have different more-specific filetypes
> than filetype_exe
Ah, now I get it. I forgot that that code is x86 specific. So how do you
boot Linux from EFI anyways on other architectures?
I don't see any filetypes for EFI binaries for other architectures. I'm not
sure how that works but would expect to find some code that hands over
efi_sys_table? Or what am I missing?
And if you boot a non-EFI binary shouldn't you call RS->exit_boot_services()
before actually starting the kernel?
And we should move setting LoaderTimeExecUSec into some kind of barebox
shutdown handler to ensure that it is set even if other bootm handlers are
used. But that's all unrelated to this patch.
Regards,
Michael
> - The Linux kernel header check will probabaly fail for every format that's not
> x86
>
> Cheers,
> Ahmad
>
> >
> > Michael
> >
> >>> That was the reason for implementing
> >>> the "legacy" boot mode. And what about the device-tree?
> >>
> >> There is an EFI config table for FDT (DEVICE_TREE_GUID in Linux code). barebox
> >> as EFI loader can use it to provide its own DT. I have to check what's the cleanest
> >> way for barebox as EFI payload to provide a different DT, but I hope there is a way
> >> without barebox as EFI payload having to manipulate the device tree itself.
> >>
> >> Cheers,
> >> Ahmad
> >>
> >>>
> >>> Michael
> >>>
> >>>>>> This can break PCI drivers on systems that so far assumed barebox memory
> >>>>>> is located in the first 4G, but that's ok. That code will need to be
> >>>>>> fixed eventually anyway.
> >>>>>>
> >>>>>> Cc: Michael Olbrich <m.olbrich@pengutronix.de>
> >>>>>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> >>>>>> ---
> >>>>>> efi/payload/init.c | 2 +-
> >>>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>>>>>
> >>>>>> diff --git a/efi/payload/init.c b/efi/payload/init.c
> >>>>>> index 4b612e61afb3..0c2f38e9c86a 100644
> >>>>>> --- a/efi/payload/init.c
> >>>>>> +++ b/efi/payload/init.c
> >>>>>> @@ -292,7 +292,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
> >>>>>> BS->handle_protocol(efi_loaded_image->device_handle,
> >>>>>> &efi_device_path_protocol_guid, (void **)&efi_device_path);
> >>>>>>
> >>>>>> - mem = 0x3fffffff;
> >>>>>> + mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
> >>>>>> for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
> >>>>>> efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
> >>>>>> EFI_LOADER_DATA,
> >>>>>> --
> >>>>>> 2.39.2
> >>>>>>
> >>>>>>
> >>>>>
> >>>>
> >>>> --
> >>>> Pengutronix e.K. | |
> >>>> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> >>>> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> >>>> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
> >>>>
> >>>>
> >>>
> >>
> >> --
> >> Pengutronix e.K. | |
> >> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> >> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> >> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
> >>
> >>
> >
>
> --
> Pengutronix e.K. | |
> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86
2024-01-05 14:58 ` Michael Olbrich
@ 2024-01-08 7:22 ` Ahmad Fatoum
0 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-08 7:22 UTC (permalink / raw)
To: barebox
On 05.01.24 15:58, Michael Olbrich wrote:
> On Fri, Jan 05, 2024 at 11:41:09AM +0100, Ahmad Fatoum wrote:
>> On 05.01.24 10:31, Michael Olbrich wrote:
>>> On Fri, Jan 05, 2024 at 10:14:33AM +0100, Ahmad Fatoum wrote:
>>>> On 04.01.24 19:10, Michael Olbrich wrote:
>>>>> On Thu, Jan 04, 2024 at 12:17:12PM +0100, Ahmad Fatoum wrote:
>>>>>> On 03.01.24 19:58, Michael Olbrich wrote:
>>>>>>> On Wed, Jan 03, 2024 at 07:12:19PM +0100, Ahmad Fatoum wrote:
>>>>>>>> When run as EFI payload, barebox will not have full access to DRAM and will
>>>>>>>> have to ask the EFI firmware for memory. It does so once at the beginning
>>>>>>>> and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
>>>>>>>> the buffer was always placed beneath the 1G boundary.
>>>>>>>>
>>>>>>>> Aforementioned commit didn't elaborate why a maximum of 1G in particular
>>>>>>>> was chosen. Anyways, non-PC architectures have different memory maps, so
>>>>>>>> a 1G limit doesn't make sense there. Therefore restrict the limit to
>>>>>>>> ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.
>>>>>>>
>>>>>>> The 1G is somewhat arbitrary but if you don't restrict the memory to 32bit,
>>>>>>> then loading the kernel may fail: The addresses in "struct
>>>>>>> linux_kernel_header" are only 32bit. So if you impose no restrictions at
>>>>>>> all, then this memory cannot be used for the kernel and initrd.
>>>>>>
>>>>>> The limit for x86 remains at 1G. It's only for other architectures, that we
>>>>>> remove the limit. I suspect that other architectures won't have this kind
>>>>>> of problems though , because they would boot the kernel image via EFI load
>>>>>> and start image boot services, where the EFI firmware takes care to layout
>>>>>> the boot artifacts.
>>>>>>
>>>>>> Once we have that in place, we could even use it on x86 instead of
>>>>>> using struct linux_kernel_header, but I haven't investigated this yet.
>>>>>
>>>>> How do you load the initrd via EFI? As far as I know, that only works as a
>>>>> filename in the EFI boot partition.
>>>>
>>>> This seems to be relaxed in newer kernels, see
>>>> https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/
>>>
>>> It's not quite clear to me how that works, but from what I can tell,
>>> requires support from the firmware and barebox needs to use it. So that
>>> does not help here.
>>> You need to either disable the legacy handler to avoid arbitrary failures
>>> or explicitly allocate the initrd memory from efi with the restriction to
>>> <4G.
>>
>> The legacy handler wouldn't apply to other architectures:
>>
>> - The Kernel images for ARM64 and RISC-V have different more-specific filetypes
>> than filetype_exe
>
> Ah, now I get it. I forgot that that code is x86 specific. So how do you
> boot Linux from EFI anyways on other architectures?
We don't yet.
> I don't see any filetypes for EFI binaries for other architectures. I'm not
> sure how that works but would expect to find some code that hands over
> efi_sys_table? Or what am I missing?
Only binfmt handler is registered for normal EFI start. initrd/DT will have
to follow later.
> And if you boot a non-EFI binary shouldn't you call RS->exit_boot_services()
> before actually starting the kernel?
Possibly. I remember that booting a kernel without EFI stub failed, but haven't
investigated why this was the case.
> And we should move setting LoaderTimeExecUSec into some kind of barebox
> shutdown handler to ensure that it is set even if other bootm handlers are
> used. But that's all unrelated to this patch.
Yes. I'll keep that in mind for when the bootm handler is added.
Thanks,
Ahmad
>
> Regards,
> Michael
>
>> - The Linux kernel header check will probabaly fail for every format that's not
>> x86
>>
>> Cheers,
>> Ahmad
>>
>>>
>>> Michael
>>>
>>>>> That was the reason for implementing
>>>>> the "legacy" boot mode. And what about the device-tree?
>>>>
>>>> There is an EFI config table for FDT (DEVICE_TREE_GUID in Linux code). barebox
>>>> as EFI loader can use it to provide its own DT. I have to check what's the cleanest
>>>> way for barebox as EFI payload to provide a different DT, but I hope there is a way
>>>> without barebox as EFI payload having to manipulate the device tree itself.
>>>>
>>>> Cheers,
>>>> Ahmad
>>>>
>>>>>
>>>>> Michael
>>>>>
>>>>>>>> This can break PCI drivers on systems that so far assumed barebox memory
>>>>>>>> is located in the first 4G, but that's ok. That code will need to be
>>>>>>>> fixed eventually anyway.
>>>>>>>>
>>>>>>>> Cc: Michael Olbrich <m.olbrich@pengutronix.de>
>>>>>>>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>>>>>>>> ---
>>>>>>>> efi/payload/init.c | 2 +-
>>>>>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>>>>
>>>>>>>> diff --git a/efi/payload/init.c b/efi/payload/init.c
>>>>>>>> index 4b612e61afb3..0c2f38e9c86a 100644
>>>>>>>> --- a/efi/payload/init.c
>>>>>>>> +++ b/efi/payload/init.c
>>>>>>>> @@ -292,7 +292,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
>>>>>>>> BS->handle_protocol(efi_loaded_image->device_handle,
>>>>>>>> &efi_device_path_protocol_guid, (void **)&efi_device_path);
>>>>>>>>
>>>>>>>> - mem = 0x3fffffff;
>>>>>>>> + mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
>>>>>>>> for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
>>>>>>>> efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
>>>>>>>> EFI_LOADER_DATA,
>>>>>>>> --
>>>>>>>> 2.39.2
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>> --
>>>>>> Pengutronix e.K. | |
>>>>>> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
>>>>>> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
>>>>>> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>>>>>>
>>>>>>
>>>>>
>>>>
>>>> --
>>>> Pengutronix e.K. | |
>>>> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
>>>> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
>>>> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>>>>
>>>>
>>>
>>
>> --
>> Pengutronix e.K. | |
>> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
>> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
>> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>>
>>
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 060/112] ARM: pbl: add 64K segment alignment for PE/COFF
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (58 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86 Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-08 8:05 ` Sascha Hauer
2024-01-03 18:12 ` [PATCH 061/112] efi: add efi_is_loader/efi_is_payload helpers Ahmad Fatoum
` (51 subsequent siblings)
111 siblings, 1 reply; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
An EFI stubbed ARM64 kernel can be booted either via EFI or via the
normal boot protocol. We'll want barebox to be able to behave the same,
so extend section alignment to enable this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/include/asm/memory.h | 20 ++++++++++++++++++++
arch/arm/lib/pbl.lds.S | 18 ++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 23fbbd8438a1..765b089beb59 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -3,6 +3,9 @@
#ifndef __ASM_ARM_MEMORY_H
#define __ASM_ARM_MEMORY_H
+#include <linux/sizes.h>
+
+#ifndef __ASSEMBLY__
#include <memory.h>
#include <linux/const.h>
@@ -13,4 +16,21 @@ static inline int arm_add_mem_device(const char* name, resource_size_t start,
return barebox_add_memory_bank(name, start, size);
}
+#endif
+
+
+/*
+ * Alignment of barebox PBL segments (e.g. .text, .data).
+ *
+ * 4 B granule: Same flat rwx mapping for everything
+ * 4 KB granule: 16 level 3 entries, with contiguous bit
+ * 16 KB granule: 4 level 3 entries, without contiguous bit
+ * 64 KB granule: 1 level 3 entry
+ */
+#ifdef CONFIG_EFI_PAYLOAD
+#define PBL_SEGMENT_ALIGN SZ_64K
+#else
+#define PBL_SEGMENT_ALIGN 4
+#endif
+
#endif /* __ASM_ARM_MEMORY_H */
diff --git a/arch/arm/lib/pbl.lds.S b/arch/arm/lib/pbl.lds.S
index cafb27b2d55e..95929d7558bc 100644
--- a/arch/arm/lib/pbl.lds.S
+++ b/arch/arm/lib/pbl.lds.S
@@ -5,6 +5,24 @@
#include <asm/barebox.lds.h>
#include <asm-generic/memory_layout.h>
#include <asm-generic/pointer.h>
+#include <asm/memory.h>
+
+/*
+ * The size of the PE/COFF section that covers the barebox image, which
+ * runs from _stext to _edata, must be a round multiple of the PE/COFF
+ * FileAlignment, which we set to its minimum value of 0x200. '_stext'
+ * itself must be 4 KB aligned, because that's what the adrp instructions
+ * expects, so padding out _edata to a 0x200 aligned boundary should be
+ * sufficient.
+ */
+PECOFF_FILE_ALIGNMENT = 0x200;
+
+#ifdef CONFIG_EFI_STUB
+#define PECOFF_EDATA_PADDING \
+ .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
+#else
+#define PECOFF_EDATA_PADDING
+#endif
#ifdef CONFIG_PBL_RELOCATABLE
#define BASE 0x0
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 060/112] ARM: pbl: add 64K segment alignment for PE/COFF
2024-01-03 18:12 ` [PATCH 060/112] ARM: pbl: add 64K segment alignment for PE/COFF Ahmad Fatoum
@ 2024-01-08 8:05 ` Sascha Hauer
2024-01-22 19:18 ` Ahmad Fatoum
0 siblings, 1 reply; 134+ messages in thread
From: Sascha Hauer @ 2024-01-08 8:05 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Jan 03, 2024 at 07:12:20PM +0100, Ahmad Fatoum wrote:
> An EFI stubbed ARM64 kernel can be booted either via EFI or via the
> normal boot protocol. We'll want barebox to be able to behave the same,
> so extend section alignment to enable this.
This description reads as if it would change something, but at this
point this patch only introduces unused defines. They are first used in
086/112.
Does it hurt to move the usage of PBL_SEGMENT_ALIGN and PECOFF_EDATA_PADDING
to this patch? If not, I'd suggest doing so to make the intention of
this patch clearer.
Sascha
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> arch/arm/include/asm/memory.h | 20 ++++++++++++++++++++
> arch/arm/lib/pbl.lds.S | 18 ++++++++++++++++++
> 2 files changed, 38 insertions(+)
>
> diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
> index 23fbbd8438a1..765b089beb59 100644
> --- a/arch/arm/include/asm/memory.h
> +++ b/arch/arm/include/asm/memory.h
> @@ -3,6 +3,9 @@
> #ifndef __ASM_ARM_MEMORY_H
> #define __ASM_ARM_MEMORY_H
>
> +#include <linux/sizes.h>
> +
> +#ifndef __ASSEMBLY__
> #include <memory.h>
>
> #include <linux/const.h>
> @@ -13,4 +16,21 @@ static inline int arm_add_mem_device(const char* name, resource_size_t start,
> return barebox_add_memory_bank(name, start, size);
> }
>
> +#endif
> +
> +
> +/*
> + * Alignment of barebox PBL segments (e.g. .text, .data).
> + *
> + * 4 B granule: Same flat rwx mapping for everything
> + * 4 KB granule: 16 level 3 entries, with contiguous bit
> + * 16 KB granule: 4 level 3 entries, without contiguous bit
> + * 64 KB granule: 1 level 3 entry
> + */
> +#ifdef CONFIG_EFI_PAYLOAD
> +#define PBL_SEGMENT_ALIGN SZ_64K
> +#else
> +#define PBL_SEGMENT_ALIGN 4
> +#endif
> +
> #endif /* __ASM_ARM_MEMORY_H */
> diff --git a/arch/arm/lib/pbl.lds.S b/arch/arm/lib/pbl.lds.S
> index cafb27b2d55e..95929d7558bc 100644
> --- a/arch/arm/lib/pbl.lds.S
> +++ b/arch/arm/lib/pbl.lds.S
> @@ -5,6 +5,24 @@
> #include <asm/barebox.lds.h>
> #include <asm-generic/memory_layout.h>
> #include <asm-generic/pointer.h>
> +#include <asm/memory.h>
> +
> +/*
> + * The size of the PE/COFF section that covers the barebox image, which
> + * runs from _stext to _edata, must be a round multiple of the PE/COFF
> + * FileAlignment, which we set to its minimum value of 0x200. '_stext'
> + * itself must be 4 KB aligned, because that's what the adrp instructions
> + * expects, so padding out _edata to a 0x200 aligned boundary should be
> + * sufficient.
> + */
> +PECOFF_FILE_ALIGNMENT = 0x200;
> +
> +#ifdef CONFIG_EFI_STUB
> +#define PECOFF_EDATA_PADDING \
> + .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
> +#else
> +#define PECOFF_EDATA_PADDING
> +#endif
>
> #ifdef CONFIG_PBL_RELOCATABLE
> #define BASE 0x0
> --
> 2.39.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 060/112] ARM: pbl: add 64K segment alignment for PE/COFF
2024-01-08 8:05 ` Sascha Hauer
@ 2024-01-22 19:18 ` Ahmad Fatoum
0 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-22 19:18 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 08.01.24 09:05, Sascha Hauer wrote:
> On Wed, Jan 03, 2024 at 07:12:20PM +0100, Ahmad Fatoum wrote:
>> An EFI stubbed ARM64 kernel can be booted either via EFI or via the
>> normal boot protocol. We'll want barebox to be able to behave the same,
>> so extend section alignment to enable this.
>
> This description reads as if it would change something, but at this
> point this patch only introduces unused defines. They are first used in
> 086/112.
>
> Does it hurt to move the usage of PBL_SEGMENT_ALIGN and PECOFF_EDATA_PADDING
> to this patch? If not, I'd suggest doing so to make the intention of
> this patch clearer.
Ok, done.
>
> Sascha
>
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> arch/arm/include/asm/memory.h | 20 ++++++++++++++++++++
>> arch/arm/lib/pbl.lds.S | 18 ++++++++++++++++++
>> 2 files changed, 38 insertions(+)
>>
>> diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
>> index 23fbbd8438a1..765b089beb59 100644
>> --- a/arch/arm/include/asm/memory.h
>> +++ b/arch/arm/include/asm/memory.h
>> @@ -3,6 +3,9 @@
>> #ifndef __ASM_ARM_MEMORY_H
>> #define __ASM_ARM_MEMORY_H
>>
>> +#include <linux/sizes.h>
>> +
>> +#ifndef __ASSEMBLY__
>> #include <memory.h>
>>
>> #include <linux/const.h>
>> @@ -13,4 +16,21 @@ static inline int arm_add_mem_device(const char* name, resource_size_t start,
>> return barebox_add_memory_bank(name, start, size);
>> }
>>
>> +#endif
>> +
>> +
>> +/*
>> + * Alignment of barebox PBL segments (e.g. .text, .data).
>> + *
>> + * 4 B granule: Same flat rwx mapping for everything
>> + * 4 KB granule: 16 level 3 entries, with contiguous bit
>> + * 16 KB granule: 4 level 3 entries, without contiguous bit
>> + * 64 KB granule: 1 level 3 entry
>> + */
>> +#ifdef CONFIG_EFI_PAYLOAD
>> +#define PBL_SEGMENT_ALIGN SZ_64K
>> +#else
>> +#define PBL_SEGMENT_ALIGN 4
>> +#endif
>> +
>> #endif /* __ASM_ARM_MEMORY_H */
>> diff --git a/arch/arm/lib/pbl.lds.S b/arch/arm/lib/pbl.lds.S
>> index cafb27b2d55e..95929d7558bc 100644
>> --- a/arch/arm/lib/pbl.lds.S
>> +++ b/arch/arm/lib/pbl.lds.S
>> @@ -5,6 +5,24 @@
>> #include <asm/barebox.lds.h>
>> #include <asm-generic/memory_layout.h>
>> #include <asm-generic/pointer.h>
>> +#include <asm/memory.h>
>> +
>> +/*
>> + * The size of the PE/COFF section that covers the barebox image, which
>> + * runs from _stext to _edata, must be a round multiple of the PE/COFF
>> + * FileAlignment, which we set to its minimum value of 0x200. '_stext'
>> + * itself must be 4 KB aligned, because that's what the adrp instructions
>> + * expects, so padding out _edata to a 0x200 aligned boundary should be
>> + * sufficient.
>> + */
>> +PECOFF_FILE_ALIGNMENT = 0x200;
>> +
>> +#ifdef CONFIG_EFI_STUB
>> +#define PECOFF_EDATA_PADDING \
>> + .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
>> +#else
>> +#define PECOFF_EDATA_PADDING
>> +#endif
>>
>> #ifdef CONFIG_PBL_RELOCATABLE
>> #define BASE 0x0
>> --
>> 2.39.2
>>
>>
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 061/112] efi: add efi_is_loader/efi_is_payload helpers
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (59 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 060/112] ARM: pbl: add 64K segment alignment for PE/COFF Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 062/112] efi: payload: suppress EFI payload initcalls when not EFI-loaded Ahmad Fatoum
` (50 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
So far, whether we are running under EFI was a compile-time decision.
This will change with ARM support, where the same barebox binary can
either probe from DT or from EFI. Prepare for this by adding helpers
to determine whether barebox is acting as EFI loader or as payload.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/efi/efi-mode.h | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
create mode 100644 include/efi/efi-mode.h
diff --git a/include/efi/efi-mode.h b/include/efi/efi-mode.h
new file mode 100644
index 000000000000..a917c038a1b0
--- /dev/null
+++ b/include/efi/efi-mode.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __EFI_MODE_H
+#define __EFI_MODE_H
+
+#include <linux/stddef.h>
+#include <linux/types.h>
+
+struct efi_boot_services;
+extern struct efi_boot_services *BS;
+
+static inline bool efi_is_payload(void)
+{
+ return IS_ENABLED(CONFIG_EFI_PAYLOAD) && BS;
+}
+
+static inline bool efi_is_loader(void)
+{
+ return false;
+}
+
+static inline struct efi_boot_services *efi_get_boot_services(void)
+{
+ if (efi_is_payload())
+ return BS;
+
+ return NULL;
+}
+
+#endif
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 062/112] efi: payload: suppress EFI payload initcalls when not EFI-loaded
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (60 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 061/112] efi: add efi_is_loader/efi_is_payload helpers Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 063/112] ARM: make board data definitions accessible to other architectures Ahmad Fatoum
` (49 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
For development, it has proven very useful to be able to load the same
barebox binary both as EFI loader and EFI payload and debug the
interaction. For this to work, we need to mark all current EFI payload
initcalls as such to avoid running them when barebox is not running
as EFI payload.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/x86/mach-efi/clocksource.c | 4 +--
common/startup.c | 3 +-
drivers/bus/acpi.c | 2 +-
drivers/efi/efi-device.c | 2 +-
efi/payload/fdt.c | 2 +-
efi/payload/image.c | 2 +-
efi/payload/init.c | 17 ++++++-----
efi/payload/iomem.c | 3 +-
fs/efivarfs.c | 2 +-
include/acpi.h | 3 +-
include/efi/efi-device.h | 6 +---
include/efi/efi-init.h | 51 +++++++++++++++++++++++++++++++++
12 files changed, 75 insertions(+), 22 deletions(-)
create mode 100644 include/efi/efi-init.h
diff --git a/arch/x86/mach-efi/clocksource.c b/arch/x86/mach-efi/clocksource.c
index c7e557d7a228..daf3b3965851 100644
--- a/arch/x86/mach-efi/clocksource.c
+++ b/arch/x86/mach-efi/clocksource.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <common.h>
-#include <init.h>
+#include <efi/efi-init.h>
#include <driver.h>
static int efi_x86_pure_init(void)
@@ -10,4 +10,4 @@ static int efi_x86_pure_init(void)
return platform_device_register(dev);
}
-core_initcall(efi_x86_pure_init);
+core_efi_initcall(efi_x86_pure_init);
diff --git a/common/startup.c b/common/startup.c
index bbba72f89255..522e2de75527 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -38,6 +38,7 @@
#include <watchdog.h>
#include <glob.h>
#include <net.h>
+#include <efi/efi-mode.h>
#include <bselftest.h>
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
@@ -54,7 +55,7 @@ static int mount_root(void)
mkdir("/tmp", 0);
mount("none", "devfs", "/dev", NULL);
- if (IS_ENABLED(CONFIG_FS_EFIVARFS)) {
+ if (IS_ENABLED(CONFIG_FS_EFIVARFS) && efi_is_payload()) {
mkdir("/efivars", 0);
mount("none", "efivarfs", "/efivars", NULL);
}
diff --git a/drivers/bus/acpi.c b/drivers/bus/acpi.c
index 953ccd755f98..c5a818c34bd4 100644
--- a/drivers/bus/acpi.c
+++ b/drivers/bus/acpi.c
@@ -246,4 +246,4 @@ static int efi_acpi_probe(void)
acpi_bus.dev->priv = table;
return acpi_register_devices(&acpi_bus);
}
-postcore_initcall(efi_acpi_probe);
+postcore_efi_initcall(efi_acpi_probe);
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index f93bbc6a4e50..a533bc43eb37 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -462,7 +462,7 @@ static int efi_init_devices(void)
return 0;
}
-core_initcall(efi_init_devices);
+core_efi_initcall(efi_init_devices);
void efi_pause_devices(void)
{
diff --git a/efi/payload/fdt.c b/efi/payload/fdt.c
index 8dacaa8b524a..b50c09691976 100644
--- a/efi/payload/fdt.c
+++ b/efi/payload/fdt.c
@@ -41,4 +41,4 @@ static int efi_fdt_probe(void)
return 0;
}
-late_initcall(efi_fdt_probe);
+late_efi_initcall(efi_fdt_probe);
diff --git a/efi/payload/image.c b/efi/payload/image.c
index 8e5ad87de22f..b9cdb0e0562a 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -332,4 +332,4 @@ static int efi_register_image_handler(void)
return 0;
}
-late_initcall(efi_register_image_handler);
+late_efi_initcall(efi_register_image_handler);
diff --git a/efi/payload/init.c b/efi/payload/init.c
index 0c2f38e9c86a..906ede38336e 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -205,7 +205,7 @@ static int misc_init(void)
return 0;
}
-late_initcall(misc_init);
+late_efi_initcall(misc_init);
static struct NS16550_plat ns16550_plat = {
.clock = 115200 * 16,
@@ -223,7 +223,7 @@ static int efi_console_init(void)
return 0;
}
-console_initcall(efi_console_init);
+console_efi_initcall(efi_console_init);
static void __noreturn efi_restart_system(struct restart_handler *rst)
{
@@ -247,7 +247,7 @@ static int restart_register_feature(void)
return 0;
}
-coredevice_initcall(restart_register_feature);
+coredevice_efi_initcall(restart_register_feature);
extern char image_base[];
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
@@ -264,7 +264,7 @@ static int efi_init(void)
return 0;
}
-device_initcall(efi_init);
+device_efi_initcall(efi_init);
/**
* efi-main - Entry point for EFI images
@@ -324,7 +324,7 @@ static int efi_core_init(void)
dev = device_alloc("efi-wdt", DEVICE_ID_SINGLE);
return platform_device_register(dev);
}
-core_initcall(efi_core_init);
+core_efi_initcall(efi_core_init);
/* Features of the loader, i.e. systemd-boot, barebox (imported from systemd) */
#define EFI_LOADER_FEATURE_CONFIG_TIMEOUT (1LL << 0)
@@ -384,7 +384,7 @@ static int efi_postcore_init(void)
return 0;
}
-postcore_initcall(efi_postcore_init);
+postcore_efi_initcall(efi_postcore_init);
static int efi_late_init(void)
{
@@ -433,10 +433,13 @@ static int efi_late_init(void)
return 0;
}
-late_initcall(efi_late_init);
+late_efi_initcall(efi_late_init);
static int do_efiexit(int argc, char *argv[])
{
+ if (!BS)
+ return -ENOSYS;
+
console_flush();
if (!streq_ptr(argv[1], "-f"))
diff --git a/efi/payload/iomem.c b/efi/payload/iomem.c
index 316dacd6b3c2..d4390c856769 100644
--- a/efi/payload/iomem.c
+++ b/efi/payload/iomem.c
@@ -7,6 +7,7 @@
#include <init.h>
#include <efi.h>
#include <efi/efi-payload.h>
+#include <efi/efi-init.h>
#include <memory.h>
#include <linux/sizes.h>
@@ -175,4 +176,4 @@ static int efi_barebox_populate_mmap(void)
free(mmap_buf);
return ret;
}
-mem_initcall(efi_barebox_populate_mmap);
+mem_efi_initcall(efi_barebox_populate_mmap);
diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index 5d805aefbf10..b19931806140 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -371,4 +371,4 @@ static int efivarfs_init(void)
return register_fs_driver(&efivarfs_driver);
}
-coredevice_initcall(efivarfs_init);
+coredevice_efi_initcall(efivarfs_init);
diff --git a/include/acpi.h b/include/acpi.h
index 2761fe60502c..0756f94501cc 100644
--- a/include/acpi.h
+++ b/include/acpi.h
@@ -9,6 +9,7 @@
#include <linux/string.h>
#include <linux/types.h>
#include <driver.h>
+#include <efi/efi-init.h>
/* Names within the namespace are 4 bytes long */
@@ -130,7 +131,7 @@ static inline struct acpi_driver *to_acpi_driver(struct driver *drv)
}
#define device_acpi_driver(drv) \
- register_driver_macro(device, acpi, drv)
+ register_efi_driver_macro(device, acpi, drv)
static inline int acpi_driver_register(struct acpi_driver *acpidrv)
{
diff --git a/include/efi/efi-device.h b/include/efi/efi-device.h
index eaf89beb8ed1..5f7490028b9e 100644
--- a/include/efi/efi-device.h
+++ b/include/efi/efi-device.h
@@ -5,6 +5,7 @@
#include <efi/types.h>
#include <efi/efi-util.h>
#include <driver.h>
+#include <efi/efi-init.h>
struct efi_device {
struct device dev;
@@ -37,11 +38,6 @@ static inline struct efi_driver *to_efi_driver(struct driver *drv)
return container_of(drv, struct efi_driver, driver);
}
-#define device_efi_driver(drv) \
- register_driver_macro(device, efi, drv)
-
-#define fs_efi_driver(drv) \
- register_driver_macro(fs, efi, drv)
static inline int efi_driver_register(struct efi_driver *efidrv)
{
efidrv->driver.bus = &efi_bus;
diff --git a/include/efi/efi-init.h b/include/efi/efi-init.h
new file mode 100644
index 000000000000..f524f3973e0e
--- /dev/null
+++ b/include/efi/efi-init.h
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef EFI_INIT_H_
+#define EFI_INIT_H_
+
+#include <init.h>
+#include <linux/compiler.h>
+
+struct efi_boot_services;
+extern struct efi_boot_services *BS;
+
+#ifdef CONFIG_EFI_PAYLOAD
+#define efi_payload_initcall(level, fn) level##_initcall(fn)
+#else
+#define efi_payload_initcall(level, fn)
+#endif
+
+/* For use by EFI payload */
+#define __define_efi_initcall(level, fn) \
+ static int __maybe_unused __efi_initcall_##fn(void) \
+ { \
+ return BS ? fn() : 0; \
+ } \
+ efi_payload_initcall(level, __efi_initcall_##fn);
+
+#define core_efi_initcall(fn) __define_efi_initcall(core, fn)
+#define postcore_efi_initcall(fn) __define_efi_initcall(postcore, fn)
+#define console_efi_initcall(fn) __define_efi_initcall(console, fn)
+#define coredevice_efi_initcall(fn) __define_efi_initcall(coredevice, fn)
+#define mem_efi_initcall(fn) __define_efi_initcall(mem, fn)
+#define device_efi_initcall(fn) __define_efi_initcall(device, fn)
+#define fs_efi_initcall(fn) __define_efi_initcall(fs, fn)
+#define late_efi_initcall(fn) __define_efi_initcall(late, fn)
+
+#define register_efi_driver_macro(level,bus,drv) \
+ static int __init drv##_register(void) \
+ { \
+ return bus##_driver_register(&drv); \
+ } \
+ level##_efi_initcall(drv##_register)
+
+#define core_efi_driver(drv) \
+ register_efi_driver_macro(core, efi, drv)
+
+#define device_efi_driver(drv) \
+ register_efi_driver_macro(device, efi, drv)
+
+#define fs_efi_driver(drv) \
+ register_efi_driver_macro(fs, efi, drv)
+
+#endif
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 063/112] ARM: make board data definitions accessible to other architectures
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (61 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 062/112] efi: payload: suppress EFI payload initcalls when not EFI-loaded Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 064/112] boarddata: add barebox_boarddata_is_machine helper Ahmad Fatoum
` (48 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
struct barebox_arm_boarddata is a way for PBL to handover a machine
number instead of a FDT. We will reuse this mechanism to hand over EFI
image handle and system table in a later commit, so prepare for that by
moving it to a central location and adjust the naming.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/include/asm/barebox-arm.h | 30 +++++-----------------
include/boarddata.h | 41 ++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 23 deletions(-)
create mode 100644 include/boarddata.h
diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index 382fa8505a66..c72fe0726f74 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -23,34 +23,14 @@
#include <asm/sections.h>
#include <asm/reloc.h>
#include <linux/stringify.h>
+#include <boarddata.h>
#define ARM_EARLY_PAGETABLE_SIZE SZ_64K
void __noreturn barebox_arm_entry(unsigned long membase, unsigned long memsize, void *boarddata);
-struct barebox_arm_boarddata {
-#define BAREBOX_ARM_BOARDDATA_MAGIC 0xabe742c3
- u32 magic;
- u32 machine; /* machine number to pass to barebox. This may or may
- * not be a ARM machine number registered on arm.linux.org.uk.
- * It must only be unique across barebox. Please use a number
- * that do not potientially clashes with registered machines,
- * i.e. use a number > 0x10000.
- */
-};
-
-/*
- * Create a boarddata struct at given address. Suitable to be passed
- * as boarddata to barebox_arm_entry(). The machine can be retrieved
- * later with barebox_arm_machine().
- */
-static inline void boarddata_create(void *adr, u32 machine)
-{
- struct barebox_arm_boarddata *bd = adr;
-
- bd->magic = BAREBOX_ARM_BOARDDATA_MAGIC;
- bd->machine = machine;
-}
+#define barebox_arm_boarddata barebox_boarddata
+#define BAREBOX_ARM_BOARDDATA_MAGIC BAREBOX_BOARDDATA_MAGIC
u32 barebox_arm_machine(void);
@@ -58,6 +38,10 @@ unsigned long arm_mem_ramoops_get(void);
unsigned long arm_mem_membase_get(void);
unsigned long arm_mem_endmem_get(void);
+struct barebox_arm_boarddata *barebox_arm_get_boarddata(void);
+
+#define barebox_arm_get_boarddata barebox_get_boarddata
+
#if defined(CONFIG_RELOCATABLE) && defined(CONFIG_ARM_EXCEPTIONS)
void arm_fixup_vectors(void);
#else
diff --git a/include/boarddata.h b/include/boarddata.h
new file mode 100644
index 000000000000..68ad0d146495
--- /dev/null
+++ b/include/boarddata.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _BAREBOX_BOARDDATA_H_
+#define _BAREBOX_BOARDDATA_H_
+
+#include <linux/types.h>
+
+struct barebox_boarddata {
+#define BAREBOX_BOARDDATA_MAGIC 0xabe742c3
+ u32 magic;
+#define BAREBOX_MACH_TYPE_EFI 0xef1bbef1
+ u32 machine; /* machine number to pass to barebox. This may or may
+ * not be a ARM machine number registered on arm.linux.org.uk.
+ * It must only be unique across barebox. Please use a number
+ * that do not potientially clashes with registered machines,
+ * i.e. use a number > 0x10000.
+ */
+#ifdef CONFIG_EFI_STUB
+ void *image;
+ void *sys_table;
+#endif
+};
+
+/*
+ * Create a boarddata struct at given address. Suitable to be passed
+ * as boarddata to barebox_$ARCH_entry(). The boarddata can be retrieved
+ * later with barebox_get_boarddata().
+ */
+static inline struct barebox_boarddata *boarddata_create(void *adr, u32 machine)
+{
+ struct barebox_boarddata *bd = adr;
+
+ bd->magic = BAREBOX_BOARDDATA_MAGIC;
+ bd->machine = machine;
+
+ return bd;
+}
+
+const struct barebox_boarddata *barebox_get_boarddata(void);
+
+#endif /* _BAREBOX_BOARDDATA_H_ */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 064/112] boarddata: add barebox_boarddata_is_machine helper
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (62 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 063/112] ARM: make board data definitions accessible to other architectures Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 065/112] common: add PE/COFF loader Ahmad Fatoum
` (47 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
In a later commit, the same barebox binary may be used either as EFI payload
or as EFI loader being initialized from the device tree. The
difference will be the barebox_boarddata, so add a helper for checking
it.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/boarddata.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/boarddata.h b/include/boarddata.h
index 68ad0d146495..8c048fd957b4 100644
--- a/include/boarddata.h
+++ b/include/boarddata.h
@@ -38,4 +38,12 @@ static inline struct barebox_boarddata *boarddata_create(void *adr, u32 machine)
const struct barebox_boarddata *barebox_get_boarddata(void);
+static inline bool barebox_boarddata_is_machine(const struct barebox_boarddata *bd,
+ u32 machine)
+{
+ if (!bd || bd->magic != BAREBOX_BOARDDATA_MAGIC)
+ return false;
+ return bd->machine == machine;
+}
+
#endif /* _BAREBOX_BOARDDATA_H_ */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 065/112] common: add PE/COFF loader
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (63 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 064/112] boarddata: add barebox_boarddata_is_machine helper Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-08 8:37 ` Sascha Hauer
2024-01-03 18:12 ` [PATCH 066/112] efi: use efi_handle_t where appropriate Ahmad Fatoum
` (46 subsequent siblings)
111 siblings, 1 reply; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
EFI loader will need to parse and load PE executables. Add functions to
facilitate that. The API is inspired by the already existing ELF API.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/Kconfig | 3 +
common/Makefile | 1 +
common/pe.c | 377 +++++++++++++++++++++++++++++++
include/asm-generic/pe.h | 56 +++++
include/linux/pagemap.h | 1 +
include/linux/pe.h | 468 +++++++++++++++++++++++++++++++++++++++
include/pe.h | 316 ++++++++++++++++++++++++++
7 files changed, 1222 insertions(+)
create mode 100644 common/pe.c
create mode 100644 include/asm-generic/pe.h
create mode 100644 include/linux/pe.h
create mode 100644 include/pe.h
diff --git a/common/Kconfig b/common/Kconfig
index 0e8188d2b2fb..311b6a7d9b65 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -624,6 +624,9 @@ config BOOTM_AIMAGE
help
Support using Android Images.
+config PE
+ bool "PE/COFF Support" if COMPILE_TEST
+
config ELF
bool "ELF Support" if COMPILE_TEST
diff --git a/common/Makefile b/common/Makefile
index 936997d9bcdd..54df0d78edc3 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -13,6 +13,7 @@ obj-pbl-y += memsize.o
obj-y += resource.o
obj-pbl-y += bootsource.o
obj-$(CONFIG_ELF) += elf.o
+obj-$(CONFIG_PE) += pe.o
obj-y += restart.o
obj-y += poweroff.o
obj-y += slice.o
diff --git a/common/pe.c b/common/pe.c
new file mode 100644
index 000000000000..b14a0f8891c1
--- /dev/null
+++ b/common/pe.c
@@ -0,0 +1,377 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * PE image loader
+ *
+ * based partly on wine code
+ *
+ * Copyright (c) 2016 Alexander Graf
+ */
+
+#define pr_fmt(fmt) "pe: " fmt
+
+#include <common.h>
+#include <pe.h>
+#include <linux/sizes.h>
+#include <libfile.h>
+#include <memory.h>
+#include <linux/err.h>
+
+static int machines[] = {
+#if defined(__aarch64__)
+ IMAGE_FILE_MACHINE_ARM64,
+#elif defined(__arm__)
+ IMAGE_FILE_MACHINE_ARM,
+ IMAGE_FILE_MACHINE_THUMB,
+ IMAGE_FILE_MACHINE_ARMNT,
+#endif
+
+#if defined(__x86_64__)
+ IMAGE_FILE_MACHINE_AMD64,
+#elif defined(__i386__)
+ IMAGE_FILE_MACHINE_I386,
+#endif
+
+#if defined(__riscv) && (__riscv_xlen == 32)
+ IMAGE_FILE_MACHINE_RISCV32,
+#endif
+
+#if defined(__riscv) && (__riscv_xlen == 64)
+ IMAGE_FILE_MACHINE_RISCV64,
+#endif
+ 0 };
+
+/**
+ * pe_loader_relocate() - relocate PE binary
+ *
+ * @rel: pointer to the relocation table
+ * @rel_size: size of the relocation table in bytes
+ * @pe_reloc: actual load address of the image
+ * @pref_address: preferred load address of the image
+ * Return: status code
+ */
+static int pe_loader_relocate(const IMAGE_BASE_RELOCATION *rel,
+ unsigned long rel_size, void *pe_reloc,
+ unsigned long pref_address)
+{
+ unsigned long delta = (unsigned long)pe_reloc - pref_address;
+ const IMAGE_BASE_RELOCATION *end;
+ int i;
+
+ if (delta == 0)
+ return 0;
+
+ end = (const IMAGE_BASE_RELOCATION *)((const char *)rel + rel_size);
+ while (rel < end && rel->SizeOfBlock) {
+ const uint16_t *relocs = (const uint16_t *)(rel + 1);
+ i = (rel->SizeOfBlock - sizeof(*rel)) / sizeof(uint16_t);
+ while (i--) {
+ uint32_t offset = (uint32_t)(*relocs & 0xfff) +
+ rel->VirtualAddress;
+ int type = *relocs >> PAGE_SHIFT;
+ uint64_t *x64 = pe_reloc + offset;
+ uint32_t *x32 = pe_reloc + offset;
+ uint16_t *x16 = pe_reloc + offset;
+
+ switch (type) {
+ case IMAGE_REL_BASED_ABSOLUTE:
+ break;
+ case IMAGE_REL_BASED_HIGH:
+ *x16 += ((uint32_t)delta) >> 16;
+ break;
+ case IMAGE_REL_BASED_LOW:
+ *x16 += (uint16_t)delta;
+ break;
+ case IMAGE_REL_BASED_HIGHLOW:
+ *x32 += (uint32_t)delta;
+ break;
+ case IMAGE_REL_BASED_DIR64:
+ *x64 += (uint64_t)delta;
+ break;
+#ifdef __riscv
+ case IMAGE_REL_BASED_RISCV_HI20:
+ *x32 = ((*x32 & 0xfffff000) + (uint32_t)delta) |
+ (*x32 & 0x00000fff);
+ break;
+ case IMAGE_REL_BASED_RISCV_LOW12I:
+ case IMAGE_REL_BASED_RISCV_LOW12S:
+ /* We know that we're 4k aligned */
+ if (delta & 0xfff) {
+ pr_err("Unsupported reloc offset\n");
+ return -ENOEXEC;
+ }
+ break;
+#endif
+ default:
+ pr_err("Unknown Relocation off %x type %x\n",
+ offset, type);
+ return -ENOEXEC;
+ }
+ relocs++;
+ }
+ rel = (const IMAGE_BASE_RELOCATION *)relocs;
+ }
+ return 0;
+}
+
+/**
+ * pe_check_header() - check if a memory buffer contains a PE-COFF image
+ *
+ * @buffer: buffer to check
+ * @size: size of buffer
+ * @nt_header: on return pointer to NT header of PE-COFF image
+ * Return: 0 if the buffer contains a PE-COFF image
+ */
+static int pe_check_header(void *buffer, size_t size, void **nt_header)
+{
+ IMAGE_DOS_HEADER *dos = buffer;
+ IMAGE_NT_HEADERS32 *nt;
+
+ if (size < sizeof(*dos))
+ return -EINVAL;
+
+ /* Check for DOS magix */
+ if (dos->e_magic != IMAGE_DOS_SIGNATURE)
+ return -EINVAL;
+
+ /*
+ * Check if the image section header fits into the file. Knowing that at
+ * least one section header follows we only need to check for the length
+ * of the 64bit header which is longer than the 32bit header.
+ */
+ if (size < dos->e_lfanew + sizeof(IMAGE_NT_HEADERS32))
+ return -EINVAL;
+ nt = (IMAGE_NT_HEADERS32 *)((u8 *)buffer + dos->e_lfanew);
+
+ /* Check for PE-COFF magic */
+ if (nt->Signature != IMAGE_NT_SIGNATURE)
+ return -EINVAL;
+
+ if (nt_header)
+ *nt_header = nt;
+
+ return 0;
+}
+
+/**
+ * section_size() - determine size of section
+ *
+ * The size of a section in memory if normally given by VirtualSize.
+ * If VirtualSize is not provided, use SizeOfRawData.
+ *
+ * @sec: section header
+ * Return: size of section in memory
+ */
+static u32 section_size(IMAGE_SECTION_HEADER *sec)
+{
+ if (sec->Misc.VirtualSize)
+ return sec->Misc.VirtualSize;
+ else
+ return sec->SizeOfRawData;
+}
+
+struct pe_image *pe_open_buf(void *bin, size_t pe_size)
+{
+ struct pe_image *pe;
+ int i;
+ int supported = 0;
+ int ret;
+
+ pe = calloc(1, sizeof(*pe));
+ if (!pe)
+ return ERR_PTR(-ENOMEM);
+
+ ret = pe_check_header(bin, pe_size, (void **)&pe->nt);
+ if (ret) {
+ pr_err("Not a PE-COFF file\n");
+ ret = -ENOEXEC;
+ goto err;
+ }
+
+ for (i = 0; machines[i]; i++)
+ if (machines[i] == pe->nt->FileHeader.Machine) {
+ supported = 1;
+ break;
+ }
+
+ if (!supported) {
+ pr_err("Machine type 0x%04x is not supported\n",
+ pe->nt->FileHeader.Machine);
+ ret = -ENOEXEC;
+ goto err;
+ }
+
+ pe->num_sections = pe->nt->FileHeader.NumberOfSections;
+ pe->sections = (void *)&pe->nt->OptionalHeader +
+ pe->nt->FileHeader.SizeOfOptionalHeader;
+
+ if (pe_size < ((void *)pe->sections + sizeof(pe->sections[0]) * pe->num_sections - bin)) {
+ pr_err("Invalid number of sections: %d\n", pe->num_sections);
+ ret = -ENOEXEC;
+ goto err;
+ }
+
+ pe->bin = bin;
+
+ return pe;
+err:
+ return ERR_PTR(ret);
+}
+
+struct pe_image *pe_open(const char *filename)
+{
+ struct pe_image *pe;
+ size_t size;
+ void *bin;
+
+ bin = read_file(filename, &size);
+ if (!bin)
+ return NULL;
+
+ pe = pe_open_buf(bin, size);
+
+ //free(bin); // FIXME
+ return pe;
+}
+
+static struct resource *pe_alloc(size_t virt_size)
+{
+ resource_size_t start, end;
+ int ret;
+
+ ret = memory_bank_first_find_space(&start, &end);
+ if (ret)
+ return NULL;
+
+ start = ALIGN(start, SZ_64K);
+
+ if (start + virt_size > end)
+ return NULL;
+
+ return request_sdram_region("pe-code", start, virt_size);
+}
+
+unsigned long pe_get_mem_size(struct pe_image *pe)
+{
+ unsigned long virt_size = 0;
+ int i;
+
+ /* Calculate upper virtual address boundary */
+ for (i = pe->num_sections - 1; i >= 0; i--) {
+ IMAGE_SECTION_HEADER *sec = &pe->sections[i];
+
+ virt_size = max_t(unsigned long, virt_size,
+ sec->VirtualAddress + section_size(sec));
+ }
+
+ /* Read 32/64bit specific header bits */
+ if (pe->nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
+ IMAGE_NT_HEADERS64 *nt64 = (void *)pe->nt;
+ IMAGE_OPTIONAL_HEADER64 *opt = &nt64->OptionalHeader;
+
+ virt_size = ALIGN(virt_size, opt->SectionAlignment);
+ } else if (pe->nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+ IMAGE_OPTIONAL_HEADER32 *opt = &pe->nt->OptionalHeader;
+
+ virt_size = ALIGN(virt_size, opt->SectionAlignment);
+ } else {
+ pr_err("Invalid optional header magic %x\n",
+ pe->nt->OptionalHeader.Magic);
+ return 0;
+ }
+
+ return virt_size;
+}
+
+int pe_load(struct pe_image *pe)
+{
+ int rel_idx = IMAGE_DIRECTORY_ENTRY_BASERELOC;
+ uint64_t image_base;
+ unsigned long virt_size;
+ unsigned long rel_size;
+ const IMAGE_BASE_RELOCATION *rel;
+ IMAGE_DOS_HEADER *dos;
+ struct resource *code;
+ void *pe_reloc;
+ int i;
+
+ virt_size = pe_get_mem_size(pe);
+ if (!virt_size)
+ return -ENOEXEC;
+
+ /* Read 32/64bit specific header bits */
+ if (pe->nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
+ IMAGE_NT_HEADERS64 *nt64 = (void *)pe->nt;
+ IMAGE_OPTIONAL_HEADER64 *opt = &nt64->OptionalHeader;
+ image_base = opt->ImageBase;
+ pe->image_type = opt->Subsystem;
+
+ code = pe_alloc(virt_size);
+ if (!code)
+ return -ENOMEM;
+
+ pe_reloc = (void *)code->start;
+
+ pe->entry = code->start + opt->AddressOfEntryPoint;
+ rel_size = opt->DataDirectory[rel_idx].Size;
+ rel = pe_reloc + opt->DataDirectory[rel_idx].VirtualAddress;
+ } else if (pe->nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+ IMAGE_OPTIONAL_HEADER32 *opt = &pe->nt->OptionalHeader;
+ image_base = opt->ImageBase;
+ pe->image_type = opt->Subsystem;
+ virt_size = ALIGN(virt_size, opt->SectionAlignment);
+
+ code = pe_alloc(virt_size);
+ if (!code)
+ return -ENOMEM;
+
+ pe_reloc = (void *)code->start;
+
+ pe->entry = code->start + opt->AddressOfEntryPoint;
+ rel_size = opt->DataDirectory[rel_idx].Size;
+ rel = pe_reloc + opt->DataDirectory[rel_idx].VirtualAddress;
+ } else {
+ pr_err("Invalid optional header magic %x\n",
+ pe->nt->OptionalHeader.Magic);
+ return -ENOEXEC;
+ }
+
+ /* Copy PE headers */
+ memcpy(pe_reloc, pe->bin,
+ sizeof(*dos)
+ + sizeof(*pe->nt)
+ + pe->nt->FileHeader.SizeOfOptionalHeader
+ + pe->num_sections * sizeof(IMAGE_SECTION_HEADER));
+
+ /* Load sections into RAM */
+ for (i = pe->num_sections - 1; i >= 0; i--) {
+ IMAGE_SECTION_HEADER *sec = &pe->sections[i];
+ u32 copy_size = section_size(sec);
+
+ if (copy_size > sec->SizeOfRawData) {
+ copy_size = sec->SizeOfRawData;
+ memset(pe_reloc + sec->VirtualAddress, 0,
+ sec->Misc.VirtualSize);
+ }
+
+ memcpy(pe_reloc + sec->VirtualAddress,
+ pe->bin + sec->PointerToRawData,
+ copy_size);
+ }
+
+ /* Run through relocations */
+ if (pe_loader_relocate(rel, rel_size, pe_reloc,
+ (unsigned long)image_base) != 0) {
+ release_sdram_region(code);
+ return -EINVAL;
+ }
+
+ pe->code = code;
+
+ return 0;
+}
+
+void pe_close(struct pe_image *pe)
+{
+ release_sdram_region(pe->code);
+ free(pe);
+}
diff --git a/include/asm-generic/pe.h b/include/asm-generic/pe.h
new file mode 100644
index 000000000000..a1df7471348e
--- /dev/null
+++ b/include/asm-generic/pe.h
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Portable Executable and Common Object Constants
+ *
+ * Copyright (c) 2018 Heinrich Schuchardt
+ *
+ * based on the "Microsoft Portable Executable and Common Object File Format
+ * Specification", revision 11, 2017-01-23
+ */
+
+#ifndef _ASM_PE_H
+#define _ASM_PE_H
+
+/* Characteristics */
+#define IMAGE_FILE_RELOCS_STRIPPED 0x0001
+#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
+#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
+#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
+#define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010
+#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
+/* Reserved 0x0040 */
+#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
+#define IMAGE_FILE_32BIT_MACHINE 0x0100
+#define IMAGE_FILE_DEBUG_STRIPPED 0x0200
+#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
+#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
+#define IMAGE_FILE_SYSTEM 0x1000
+#define IMAGE_FILE_DLL 0x2000
+#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
+#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
+
+/* Machine types */
+#define IMAGE_FILE_MACHINE_I386 0x014c
+#define IMAGE_FILE_MACHINE_ARM 0x01c0
+#define IMAGE_FILE_MACHINE_THUMB 0x01c2
+#define IMAGE_FILE_MACHINE_ARMNT 0x01c4
+#define IMAGE_FILE_MACHINE_AMD64 0x8664
+#define IMAGE_FILE_MACHINE_ARM64 0xaa64
+#define IMAGE_FILE_MACHINE_RISCV32 0x5032
+#define IMAGE_FILE_MACHINE_RISCV64 0x5064
+
+/* Header magic constants */
+#define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x010b
+#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x020b
+#define IMAGE_DOS_SIGNATURE 0x5a4d /* MZ */
+#define IMAGE_NT_SIGNATURE 0x00004550 /* PE00 */
+
+/* Subsystem type */
+#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
+#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
+#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
+#define IMAGE_SUBSYSTEM_EFI_ROM 13
+
+#define LINUX_ARM64_MAGIC 0x644d5241
+
+#endif /* _ASM_PE_H */
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 01cbfc17c57b..0db192e4d3ab 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -12,6 +12,7 @@
#define PAGE_SIZE 4096
#define PAGE_SHIFT 12
+#define PAGE_MASK (PAGE_SIZE - 1)
#define PAGE_ALIGN(s) ALIGN(s, PAGE_SIZE)
#define PAGE_ALIGN_DOWN(x) ALIGN_DOWN(x, PAGE_SIZE)
diff --git a/include/linux/pe.h b/include/linux/pe.h
new file mode 100644
index 000000000000..daf09ffffe38
--- /dev/null
+++ b/include/linux/pe.h
@@ -0,0 +1,468 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright 2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * Author(s): Peter Jones <pjones@redhat.com>
+ */
+#ifndef __LINUX_PE_H
+#define __LINUX_PE_H
+
+#include <linux/types.h>
+
+/*
+ * Linux EFI stub v1.0 adds the following functionality:
+ * - Loading initrd from the LINUX_EFI_INITRD_MEDIA_GUID device path,
+ * - Loading/starting the kernel from firmware that targets a different
+ * machine type, via the entrypoint exposed in the .compat PE/COFF section.
+ *
+ * The recommended way of loading and starting v1.0 or later kernels is to use
+ * the LoadImage() and StartImage() EFI boot services, and expose the initrd
+ * via the LINUX_EFI_INITRD_MEDIA_GUID device path.
+ *
+ * Versions older than v1.0 support initrd loading via the image load options
+ * (using initrd=, limited to the volume from which the kernel itself was
+ * loaded), or via arch specific means (bootparams, DT, etc).
+ *
+ * On x86, LoadImage() and StartImage() can be omitted if the EFI handover
+ * protocol is implemented, which can be inferred from the version,
+ * handover_offset and xloadflags fields in the bootparams structure.
+ */
+#define LINUX_EFISTUB_MAJOR_VERSION 0x1
+#define LINUX_EFISTUB_MINOR_VERSION 0x0
+
+#define MZ_MAGIC 0x5a4d /* "MZ" */
+
+#define PE_MAGIC 0x00004550 /* "PE\0\0" */
+#define PE_OPT_MAGIC_PE32 0x010b
+#define PE_OPT_MAGIC_PE32_ROM 0x0107
+#define PE_OPT_MAGIC_PE32PLUS 0x020b
+
+/* machine type */
+#define IMAGE_FILE_MACHINE_UNKNOWN 0x0000
+#define IMAGE_FILE_MACHINE_AM33 0x01d3
+#define IMAGE_FILE_MACHINE_AMD64 0x8664
+#define IMAGE_FILE_MACHINE_ARM 0x01c0
+#define IMAGE_FILE_MACHINE_ARMV7 0x01c4
+#define IMAGE_FILE_MACHINE_ARM64 0xaa64
+#define IMAGE_FILE_MACHINE_EBC 0x0ebc
+#define IMAGE_FILE_MACHINE_I386 0x014c
+#define IMAGE_FILE_MACHINE_IA64 0x0200
+#define IMAGE_FILE_MACHINE_M32R 0x9041
+#define IMAGE_FILE_MACHINE_MIPS16 0x0266
+#define IMAGE_FILE_MACHINE_MIPSFPU 0x0366
+#define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466
+#define IMAGE_FILE_MACHINE_POWERPC 0x01f0
+#define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
+#define IMAGE_FILE_MACHINE_R4000 0x0166
+#define IMAGE_FILE_MACHINE_RISCV32 0x5032
+#define IMAGE_FILE_MACHINE_RISCV64 0x5064
+#define IMAGE_FILE_MACHINE_RISCV128 0x5128
+#define IMAGE_FILE_MACHINE_SH3 0x01a2
+#define IMAGE_FILE_MACHINE_SH3DSP 0x01a3
+#define IMAGE_FILE_MACHINE_SH3E 0x01a4
+#define IMAGE_FILE_MACHINE_SH4 0x01a6
+#define IMAGE_FILE_MACHINE_SH5 0x01a8
+#define IMAGE_FILE_MACHINE_THUMB 0x01c2
+#define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169
+
+/* flags */
+#define IMAGE_FILE_RELOCS_STRIPPED 0x0001
+#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
+#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
+#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
+#define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010
+#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
+#define IMAGE_FILE_16BIT_MACHINE 0x0040
+#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
+#define IMAGE_FILE_32BIT_MACHINE 0x0100
+#define IMAGE_FILE_DEBUG_STRIPPED 0x0200
+#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
+#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
+#define IMAGE_FILE_SYSTEM 0x1000
+#define IMAGE_FILE_DLL 0x2000
+#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
+#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
+
+#define IMAGE_FILE_OPT_ROM_MAGIC 0x107
+#define IMAGE_FILE_OPT_PE32_MAGIC 0x10b
+#define IMAGE_FILE_OPT_PE32_PLUS_MAGIC 0x20b
+
+#define IMAGE_SUBSYSTEM_UNKNOWN 0
+#define IMAGE_SUBSYSTEM_NATIVE 1
+#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
+#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
+#define IMAGE_SUBSYSTEM_POSIX_CUI 7
+#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
+#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
+#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
+#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
+#define IMAGE_SUBSYSTEM_EFI_ROM_IMAGE 13
+#define IMAGE_SUBSYSTEM_XBOX 14
+
+#define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE 0x0040
+#define IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY 0x0080
+#define IMAGE_DLL_CHARACTERISTICS_NX_COMPAT 0x0100
+#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200
+#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
+#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800
+#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000
+#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
+
+/* they actually defined 0x00000000 as well, but I think we'll skip that one. */
+#define IMAGE_SCN_RESERVED_0 0x00000001
+#define IMAGE_SCN_RESERVED_1 0x00000002
+#define IMAGE_SCN_RESERVED_2 0x00000004
+#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* don't pad - obsolete */
+#define IMAGE_SCN_RESERVED_3 0x00000010
+#define IMAGE_SCN_CNT_CODE 0x00000020 /* .text */
+#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* .data */
+#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* .bss */
+#define IMAGE_SCN_LNK_OTHER 0x00000100 /* reserved */
+#define IMAGE_SCN_LNK_INFO 0x00000200 /* .drectve comments */
+#define IMAGE_SCN_RESERVED_4 0x00000400
+#define IMAGE_SCN_LNK_REMOVE 0x00000800 /* .o only - scn to be rm'd*/
+#define IMAGE_SCN_LNK_COMDAT 0x00001000 /* .o only - COMDAT data */
+#define IMAGE_SCN_RESERVED_5 0x00002000 /* spec omits this */
+#define IMAGE_SCN_RESERVED_6 0x00004000 /* spec omits this */
+#define IMAGE_SCN_GPREL 0x00008000 /* global pointer referenced data */
+/* spec lists 0x20000 twice, I suspect they meant 0x10000 for one of them */
+#define IMAGE_SCN_MEM_PURGEABLE 0x00010000 /* reserved for "future" use */
+#define IMAGE_SCN_16BIT 0x00020000 /* reserved for "future" use */
+#define IMAGE_SCN_LOCKED 0x00040000 /* reserved for "future" use */
+#define IMAGE_SCN_PRELOAD 0x00080000 /* reserved for "future" use */
+/* and here they just stuck a 1-byte integer in the middle of a bitfield */
+#define IMAGE_SCN_ALIGN_1BYTES 0x00100000 /* it does what it says on the box */
+#define IMAGE_SCN_ALIGN_2BYTES 0x00200000
+#define IMAGE_SCN_ALIGN_4BYTES 0x00300000
+#define IMAGE_SCN_ALIGN_8BYTES 0x00400000
+#define IMAGE_SCN_ALIGN_16BYTES 0x00500000
+#define IMAGE_SCN_ALIGN_32BYTES 0x00600000
+#define IMAGE_SCN_ALIGN_64BYTES 0x00700000
+#define IMAGE_SCN_ALIGN_128BYTES 0x00800000
+#define IMAGE_SCN_ALIGN_256BYTES 0x00900000
+#define IMAGE_SCN_ALIGN_512BYTES 0x00a00000
+#define IMAGE_SCN_ALIGN_1024BYTES 0x00b00000
+#define IMAGE_SCN_ALIGN_2048BYTES 0x00c00000
+#define IMAGE_SCN_ALIGN_4096BYTES 0x00d00000
+#define IMAGE_SCN_ALIGN_8192BYTES 0x00e00000
+#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* extended relocations */
+#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 /* scn can be discarded */
+#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* cannot be cached */
+#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* not pageable */
+#define IMAGE_SCN_MEM_SHARED 0x10000000 /* can be shared */
+#define IMAGE_SCN_MEM_EXECUTE 0x20000000 /* can be executed as code */
+#define IMAGE_SCN_MEM_READ 0x40000000 /* readable */
+#define IMAGE_SCN_MEM_WRITE 0x80000000 /* writeable */
+
+#define IMAGE_DEBUG_TYPE_CODEVIEW 2
+
+#ifndef __ASSEMBLY__
+
+struct mz_hdr {
+ uint16_t magic; /* MZ_MAGIC */
+ uint16_t lbsize; /* size of last used block */
+ uint16_t blocks; /* pages in file, 0x3 */
+ uint16_t relocs; /* relocations */
+ uint16_t hdrsize; /* header size in "paragraphs" */
+ uint16_t min_extra_pps; /* .bss */
+ uint16_t max_extra_pps; /* runtime limit for the arena size */
+ uint16_t ss; /* relative stack segment */
+ uint16_t sp; /* initial %sp register */
+ uint16_t checksum; /* word checksum */
+ uint16_t ip; /* initial %ip register */
+ uint16_t cs; /* initial %cs relative to load segment */
+ uint16_t reloc_table_offset; /* offset of the first relocation */
+ uint16_t overlay_num; /* overlay number. set to 0. */
+ uint16_t reserved0[4]; /* reserved */
+ uint16_t oem_id; /* oem identifier */
+ uint16_t oem_info; /* oem specific */
+ uint16_t reserved1[10]; /* reserved */
+ uint32_t peaddr; /* address of pe header */
+ char message[]; /* message to print */
+};
+
+struct mz_reloc {
+ uint16_t offset;
+ uint16_t segment;
+};
+
+struct pe_hdr {
+ uint32_t magic; /* PE magic */
+ uint16_t machine; /* machine type */
+ uint16_t sections; /* number of sections */
+ uint32_t timestamp; /* time_t */
+ uint32_t symbol_table; /* symbol table offset */
+ uint32_t symbols; /* number of symbols */
+ uint16_t opt_hdr_size; /* size of optional header */
+ uint16_t flags; /* flags */
+};
+
+/* the fact that pe32 isn't padded where pe32+ is 64-bit means union won't
+ * work right. vomit. */
+struct pe32_opt_hdr {
+ /* "standard" header */
+ uint16_t magic; /* file type */
+ uint8_t ld_major; /* linker major version */
+ uint8_t ld_minor; /* linker minor version */
+ uint32_t text_size; /* size of text section(s) */
+ uint32_t data_size; /* size of data section(s) */
+ uint32_t bss_size; /* size of bss section(s) */
+ uint32_t entry_point; /* file offset of entry point */
+ uint32_t code_base; /* relative code addr in ram */
+ uint32_t data_base; /* relative data addr in ram */
+ /* "windows" header */
+ uint32_t image_base; /* preferred load address */
+ uint32_t section_align; /* alignment in bytes */
+ uint32_t file_align; /* file alignment in bytes */
+ uint16_t os_major; /* major OS version */
+ uint16_t os_minor; /* minor OS version */
+ uint16_t image_major; /* major image version */
+ uint16_t image_minor; /* minor image version */
+ uint16_t subsys_major; /* major subsystem version */
+ uint16_t subsys_minor; /* minor subsystem version */
+ uint32_t win32_version; /* reserved, must be 0 */
+ uint32_t image_size; /* image size */
+ uint32_t header_size; /* header size rounded up to
+ file_align */
+ uint32_t csum; /* checksum */
+ uint16_t subsys; /* subsystem */
+ uint16_t dll_flags; /* more flags! */
+ uint32_t stack_size_req;/* amt of stack requested */
+ uint32_t stack_size; /* amt of stack required */
+ uint32_t heap_size_req; /* amt of heap requested */
+ uint32_t heap_size; /* amt of heap required */
+ uint32_t loader_flags; /* reserved, must be 0 */
+ uint32_t data_dirs; /* number of data dir entries */
+};
+
+struct pe32plus_opt_hdr {
+ uint16_t magic; /* file type */
+ uint8_t ld_major; /* linker major version */
+ uint8_t ld_minor; /* linker minor version */
+ uint32_t text_size; /* size of text section(s) */
+ uint32_t data_size; /* size of data section(s) */
+ uint32_t bss_size; /* size of bss section(s) */
+ uint32_t entry_point; /* file offset of entry point */
+ uint32_t code_base; /* relative code addr in ram */
+ /* "windows" header */
+ uint64_t image_base; /* preferred load address */
+ uint32_t section_align; /* alignment in bytes */
+ uint32_t file_align; /* file alignment in bytes */
+ uint16_t os_major; /* major OS version */
+ uint16_t os_minor; /* minor OS version */
+ uint16_t image_major; /* major image version */
+ uint16_t image_minor; /* minor image version */
+ uint16_t subsys_major; /* major subsystem version */
+ uint16_t subsys_minor; /* minor subsystem version */
+ uint32_t win32_version; /* reserved, must be 0 */
+ uint32_t image_size; /* image size */
+ uint32_t header_size; /* header size rounded up to
+ file_align */
+ uint32_t csum; /* checksum */
+ uint16_t subsys; /* subsystem */
+ uint16_t dll_flags; /* more flags! */
+ uint64_t stack_size_req;/* amt of stack requested */
+ uint64_t stack_size; /* amt of stack required */
+ uint64_t heap_size_req; /* amt of heap requested */
+ uint64_t heap_size; /* amt of heap required */
+ uint32_t loader_flags; /* reserved, must be 0 */
+ uint32_t data_dirs; /* number of data dir entries */
+};
+
+struct data_dirent {
+ uint32_t virtual_address; /* relative to load address */
+ uint32_t size;
+};
+
+struct data_directory {
+ struct data_dirent exports; /* .edata */
+ struct data_dirent imports; /* .idata */
+ struct data_dirent resources; /* .rsrc */
+ struct data_dirent exceptions; /* .pdata */
+ struct data_dirent certs; /* certs */
+ struct data_dirent base_relocations; /* .reloc */
+ struct data_dirent debug; /* .debug */
+ struct data_dirent arch; /* reservered */
+ struct data_dirent global_ptr; /* global pointer reg. Size=0 */
+ struct data_dirent tls; /* .tls */
+ struct data_dirent load_config; /* load configuration structure */
+ struct data_dirent bound_imports; /* no idea */
+ struct data_dirent import_addrs; /* import address table */
+ struct data_dirent delay_imports; /* delay-load import table */
+ struct data_dirent clr_runtime_hdr; /* .cor (object only) */
+ struct data_dirent reserved;
+};
+
+struct section_header {
+ char name[8]; /* name or "/12\0" string tbl offset */
+ uint32_t virtual_size; /* size of loaded section in ram */
+ uint32_t virtual_address; /* relative virtual address */
+ uint32_t raw_data_size; /* size of the section */
+ uint32_t data_addr; /* file pointer to first page of sec */
+ uint32_t relocs; /* file pointer to relocation entries */
+ uint32_t line_numbers; /* line numbers! */
+ uint16_t num_relocs; /* number of relocations */
+ uint16_t num_lin_numbers; /* srsly. */
+ uint32_t flags;
+};
+
+enum x64_coff_reloc_type {
+ IMAGE_REL_AMD64_ABSOLUTE = 0,
+ IMAGE_REL_AMD64_ADDR64,
+ IMAGE_REL_AMD64_ADDR32,
+ IMAGE_REL_AMD64_ADDR32N,
+ IMAGE_REL_AMD64_REL32,
+ IMAGE_REL_AMD64_REL32_1,
+ IMAGE_REL_AMD64_REL32_2,
+ IMAGE_REL_AMD64_REL32_3,
+ IMAGE_REL_AMD64_REL32_4,
+ IMAGE_REL_AMD64_REL32_5,
+ IMAGE_REL_AMD64_SECTION,
+ IMAGE_REL_AMD64_SECREL,
+ IMAGE_REL_AMD64_SECREL7,
+ IMAGE_REL_AMD64_TOKEN,
+ IMAGE_REL_AMD64_SREL32,
+ IMAGE_REL_AMD64_PAIR,
+ IMAGE_REL_AMD64_SSPAN32,
+};
+
+enum arm_coff_reloc_type {
+ IMAGE_REL_ARM_ABSOLUTE,
+ IMAGE_REL_ARM_ADDR32,
+ IMAGE_REL_ARM_ADDR32N,
+ IMAGE_REL_ARM_BRANCH2,
+ IMAGE_REL_ARM_BRANCH1,
+ IMAGE_REL_ARM_SECTION,
+ IMAGE_REL_ARM_SECREL,
+};
+
+enum sh_coff_reloc_type {
+ IMAGE_REL_SH3_ABSOLUTE,
+ IMAGE_REL_SH3_DIRECT16,
+ IMAGE_REL_SH3_DIRECT32,
+ IMAGE_REL_SH3_DIRECT8,
+ IMAGE_REL_SH3_DIRECT8_WORD,
+ IMAGE_REL_SH3_DIRECT8_LONG,
+ IMAGE_REL_SH3_DIRECT4,
+ IMAGE_REL_SH3_DIRECT4_WORD,
+ IMAGE_REL_SH3_DIRECT4_LONG,
+ IMAGE_REL_SH3_PCREL8_WORD,
+ IMAGE_REL_SH3_PCREL8_LONG,
+ IMAGE_REL_SH3_PCREL12_WORD,
+ IMAGE_REL_SH3_STARTOF_SECTION,
+ IMAGE_REL_SH3_SIZEOF_SECTION,
+ IMAGE_REL_SH3_SECTION,
+ IMAGE_REL_SH3_SECREL,
+ IMAGE_REL_SH3_DIRECT32_NB,
+ IMAGE_REL_SH3_GPREL4_LONG,
+ IMAGE_REL_SH3_TOKEN,
+ IMAGE_REL_SHM_PCRELPT,
+ IMAGE_REL_SHM_REFLO,
+ IMAGE_REL_SHM_REFHALF,
+ IMAGE_REL_SHM_RELLO,
+ IMAGE_REL_SHM_RELHALF,
+ IMAGE_REL_SHM_PAIR,
+ IMAGE_REL_SHM_NOMODE,
+};
+
+enum ppc_coff_reloc_type {
+ IMAGE_REL_PPC_ABSOLUTE,
+ IMAGE_REL_PPC_ADDR64,
+ IMAGE_REL_PPC_ADDR32,
+ IMAGE_REL_PPC_ADDR24,
+ IMAGE_REL_PPC_ADDR16,
+ IMAGE_REL_PPC_ADDR14,
+ IMAGE_REL_PPC_REL24,
+ IMAGE_REL_PPC_REL14,
+ IMAGE_REL_PPC_ADDR32N,
+ IMAGE_REL_PPC_SECREL,
+ IMAGE_REL_PPC_SECTION,
+ IMAGE_REL_PPC_SECREL16,
+ IMAGE_REL_PPC_REFHI,
+ IMAGE_REL_PPC_REFLO,
+ IMAGE_REL_PPC_PAIR,
+ IMAGE_REL_PPC_SECRELLO,
+ IMAGE_REL_PPC_GPREL,
+ IMAGE_REL_PPC_TOKEN,
+};
+
+enum x86_coff_reloc_type {
+ IMAGE_REL_I386_ABSOLUTE,
+ IMAGE_REL_I386_DIR16,
+ IMAGE_REL_I386_REL16,
+ IMAGE_REL_I386_DIR32,
+ IMAGE_REL_I386_DIR32NB,
+ IMAGE_REL_I386_SEG12,
+ IMAGE_REL_I386_SECTION,
+ IMAGE_REL_I386_SECREL,
+ IMAGE_REL_I386_TOKEN,
+ IMAGE_REL_I386_SECREL7,
+ IMAGE_REL_I386_REL32,
+};
+
+enum ia64_coff_reloc_type {
+ IMAGE_REL_IA64_ABSOLUTE,
+ IMAGE_REL_IA64_IMM14,
+ IMAGE_REL_IA64_IMM22,
+ IMAGE_REL_IA64_IMM64,
+ IMAGE_REL_IA64_DIR32,
+ IMAGE_REL_IA64_DIR64,
+ IMAGE_REL_IA64_PCREL21B,
+ IMAGE_REL_IA64_PCREL21M,
+ IMAGE_REL_IA64_PCREL21F,
+ IMAGE_REL_IA64_GPREL22,
+ IMAGE_REL_IA64_LTOFF22,
+ IMAGE_REL_IA64_SECTION,
+ IMAGE_REL_IA64_SECREL22,
+ IMAGE_REL_IA64_SECREL64I,
+ IMAGE_REL_IA64_SECREL32,
+ IMAGE_REL_IA64_DIR32NB,
+ IMAGE_REL_IA64_SREL14,
+ IMAGE_REL_IA64_SREL22,
+ IMAGE_REL_IA64_SREL32,
+ IMAGE_REL_IA64_UREL32,
+ IMAGE_REL_IA64_PCREL60X,
+ IMAGE_REL_IA64_PCREL60B,
+ IMAGE_REL_IA64_PCREL60F,
+ IMAGE_REL_IA64_PCREL60I,
+ IMAGE_REL_IA64_PCREL60M,
+ IMAGE_REL_IA64_IMMGPREL6,
+ IMAGE_REL_IA64_TOKEN,
+ IMAGE_REL_IA64_GPREL32,
+ IMAGE_REL_IA64_ADDEND,
+};
+
+struct coff_reloc {
+ uint32_t virtual_address;
+ uint32_t symbol_table_index;
+ union {
+ enum x64_coff_reloc_type x64_type;
+ enum arm_coff_reloc_type arm_type;
+ enum sh_coff_reloc_type sh_type;
+ enum ppc_coff_reloc_type ppc_type;
+ enum x86_coff_reloc_type x86_type;
+ enum ia64_coff_reloc_type ia64_type;
+ uint16_t data;
+ };
+};
+
+/*
+ * Definitions for the contents of the certs data block
+ */
+#define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002
+#define WIN_CERT_TYPE_EFI_OKCS115 0x0EF0
+#define WIN_CERT_TYPE_EFI_GUID 0x0EF1
+
+#define WIN_CERT_REVISION_1_0 0x0100
+#define WIN_CERT_REVISION_2_0 0x0200
+
+struct win_certificate {
+ uint32_t length;
+ uint16_t revision;
+ uint16_t cert_type;
+};
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* __LINUX_PE_H */
diff --git a/include/pe.h b/include/pe.h
new file mode 100644
index 000000000000..9170e7b44f77
--- /dev/null
+++ b/include/pe.h
@@ -0,0 +1,316 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Portable Executable binary format structures
+ *
+ * Copyright (c) 2016 Alexander Graf
+ *
+ * Based on wine code
+ */
+
+#ifndef _PE_H
+#define _PE_H
+
+#include <asm-generic/pe.h>
+
+typedef struct _IMAGE_DOS_HEADER {
+ uint16_t e_magic; /* 00: MZ Header signature */
+ uint16_t e_cblp; /* 02: Bytes on last page of file */
+ uint16_t e_cp; /* 04: Pages in file */
+ uint16_t e_crlc; /* 06: Relocations */
+ uint16_t e_cparhdr; /* 08: Size of header in paragraphs */
+ uint16_t e_minalloc; /* 0a: Minimum extra paragraphs needed */
+ uint16_t e_maxalloc; /* 0c: Maximum extra paragraphs needed */
+ uint16_t e_ss; /* 0e: Initial (relative) SS value */
+ uint16_t e_sp; /* 10: Initial SP value */
+ uint16_t e_csum; /* 12: Checksum */
+ uint16_t e_ip; /* 14: Initial IP value */
+ uint16_t e_cs; /* 16: Initial (relative) CS value */
+ uint16_t e_lfarlc; /* 18: File address of relocation table */
+ uint16_t e_ovno; /* 1a: Overlay number */
+ uint16_t e_res[4]; /* 1c: Reserved words */
+ uint16_t e_oemid; /* 24: OEM identifier (for e_oeminfo) */
+ uint16_t e_oeminfo; /* 26: OEM information; e_oemid specific */
+ uint16_t e_res2[10]; /* 28: Reserved words */
+ uint32_t e_lfanew; /* 3c: Offset to extended header */
+} IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
+
+typedef struct _IMAGE_FILE_HEADER {
+ uint16_t Machine;
+ uint16_t NumberOfSections;
+ uint32_t TimeDateStamp;
+ uint32_t PointerToSymbolTable;
+ uint32_t NumberOfSymbols;
+ uint16_t SizeOfOptionalHeader;
+ uint16_t Characteristics;
+} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
+
+typedef struct _IMAGE_DATA_DIRECTORY {
+ uint32_t VirtualAddress;
+ uint32_t Size;
+} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
+
+#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
+
+typedef struct _IMAGE_OPTIONAL_HEADER64 {
+ uint16_t Magic; /* 0x20b */
+ uint8_t MajorLinkerVersion;
+ uint8_t MinorLinkerVersion;
+ uint32_t SizeOfCode;
+ uint32_t SizeOfInitializedData;
+ uint32_t SizeOfUninitializedData;
+ uint32_t AddressOfEntryPoint;
+ uint32_t BaseOfCode;
+ uint64_t ImageBase;
+ uint32_t SectionAlignment;
+ uint32_t FileAlignment;
+ uint16_t MajorOperatingSystemVersion;
+ uint16_t MinorOperatingSystemVersion;
+ uint16_t MajorImageVersion;
+ uint16_t MinorImageVersion;
+ uint16_t MajorSubsystemVersion;
+ uint16_t MinorSubsystemVersion;
+ uint32_t Win32VersionValue;
+ uint32_t SizeOfImage;
+ uint32_t SizeOfHeaders;
+ uint32_t CheckSum;
+ uint16_t Subsystem;
+ uint16_t DllCharacteristics;
+ uint64_t SizeOfStackReserve;
+ uint64_t SizeOfStackCommit;
+ uint64_t SizeOfHeapReserve;
+ uint64_t SizeOfHeapCommit;
+ uint32_t LoaderFlags;
+ uint32_t NumberOfRvaAndSizes;
+ IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
+} IMAGE_OPTIONAL_HEADER64, *PIMAGE_OPTIONAL_HEADER64;
+
+typedef struct _IMAGE_NT_HEADERS64 {
+ uint32_t Signature;
+ IMAGE_FILE_HEADER FileHeader;
+ IMAGE_OPTIONAL_HEADER64 OptionalHeader;
+} IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64;
+
+typedef struct _IMAGE_OPTIONAL_HEADER {
+
+ /* Standard fields */
+
+ uint16_t Magic; /* 0x10b or 0x107 */ /* 0x00 */
+ uint8_t MajorLinkerVersion;
+ uint8_t MinorLinkerVersion;
+ uint32_t SizeOfCode;
+ uint32_t SizeOfInitializedData;
+ uint32_t SizeOfUninitializedData;
+ uint32_t AddressOfEntryPoint; /* 0x10 */
+ uint32_t BaseOfCode;
+ uint32_t BaseOfData;
+
+ /* NT additional fields */
+
+ uint32_t ImageBase;
+ uint32_t SectionAlignment; /* 0x20 */
+ uint32_t FileAlignment;
+ uint16_t MajorOperatingSystemVersion;
+ uint16_t MinorOperatingSystemVersion;
+ uint16_t MajorImageVersion;
+ uint16_t MinorImageVersion;
+ uint16_t MajorSubsystemVersion; /* 0x30 */
+ uint16_t MinorSubsystemVersion;
+ uint32_t Win32VersionValue;
+ uint32_t SizeOfImage;
+ uint32_t SizeOfHeaders;
+ uint32_t CheckSum; /* 0x40 */
+ uint16_t Subsystem;
+ uint16_t DllCharacteristics;
+ uint32_t SizeOfStackReserve;
+ uint32_t SizeOfStackCommit;
+ uint32_t SizeOfHeapReserve; /* 0x50 */
+ uint32_t SizeOfHeapCommit;
+ uint32_t LoaderFlags;
+ uint32_t NumberOfRvaAndSizes;
+ IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; /* 0x60 */
+ /* 0xE0 */
+} IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32;
+
+typedef struct _IMAGE_NT_HEADERS {
+ uint32_t Signature; /* "PE"\0\0 */ /* 0x00 */
+ IMAGE_FILE_HEADER FileHeader; /* 0x04 */
+ IMAGE_OPTIONAL_HEADER32 OptionalHeader; /* 0x18 */
+} IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32;
+
+#define IMAGE_SIZEOF_SHORT_NAME 8
+
+typedef struct _IMAGE_SECTION_HEADER {
+ uint8_t Name[IMAGE_SIZEOF_SHORT_NAME];
+ union {
+ uint32_t PhysicalAddress;
+ uint32_t VirtualSize;
+ } Misc;
+ uint32_t VirtualAddress;
+ uint32_t SizeOfRawData;
+ uint32_t PointerToRawData;
+ uint32_t PointerToRelocations;
+ uint32_t PointerToLinenumbers;
+ uint16_t NumberOfRelocations;
+ uint16_t NumberOfLinenumbers;
+ uint32_t Characteristics;
+} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
+
+/* Indices for Optional Header Data Directories */
+#define IMAGE_DIRECTORY_ENTRY_SECURITY 4
+#define IMAGE_DIRECTORY_ENTRY_BASERELOC 5
+
+typedef struct _IMAGE_BASE_RELOCATION
+{
+ uint32_t VirtualAddress;
+ uint32_t SizeOfBlock;
+ /* WORD TypeOffset[1]; */
+} IMAGE_BASE_RELOCATION,*PIMAGE_BASE_RELOCATION;
+
+typedef struct _IMAGE_RELOCATION
+{
+ union {
+ uint32_t VirtualAddress;
+ uint32_t RelocCount;
+ } DUMMYUNIONNAME;
+ uint32_t SymbolTableIndex;
+ uint16_t Type;
+} IMAGE_RELOCATION, *PIMAGE_RELOCATION;
+
+#define IMAGE_SIZEOF_RELOCATION 10
+
+/* generic relocation types */
+#define IMAGE_REL_BASED_ABSOLUTE 0
+#define IMAGE_REL_BASED_HIGH 1
+#define IMAGE_REL_BASED_LOW 2
+#define IMAGE_REL_BASED_HIGHLOW 3
+#define IMAGE_REL_BASED_HIGHADJ 4
+#define IMAGE_REL_BASED_MIPS_JMPADDR 5
+#define IMAGE_REL_BASED_ARM_MOV32A 5 /* yes, 5 too */
+#define IMAGE_REL_BASED_ARM_MOV32 5 /* yes, 5 too */
+#define IMAGE_REL_BASED_RISCV_HI20 5 /* yes, 5 too */
+#define IMAGE_REL_BASED_SECTION 6
+#define IMAGE_REL_BASED_REL 7
+#define IMAGE_REL_BASED_ARM_MOV32T 7 /* yes, 7 too */
+#define IMAGE_REL_BASED_THUMB_MOV32 7 /* yes, 7 too */
+#define IMAGE_REL_BASED_RISCV_LOW12I 7 /* yes, 7 too */
+#define IMAGE_REL_BASED_RISCV_LOW12S 8
+#define IMAGE_REL_BASED_MIPS_JMPADDR16 9
+#define IMAGE_REL_BASED_IA64_IMM64 9 /* yes, 9 too */
+#define IMAGE_REL_BASED_DIR64 10
+#define IMAGE_REL_BASED_HIGH3ADJ 11
+
+/* ARM relocation types */
+#define IMAGE_REL_ARM_ABSOLUTE 0x0000
+#define IMAGE_REL_ARM_ADDR 0x0001
+#define IMAGE_REL_ARM_ADDR32NB 0x0002
+#define IMAGE_REL_ARM_BRANCH24 0x0003
+#define IMAGE_REL_ARM_BRANCH11 0x0004
+#define IMAGE_REL_ARM_TOKEN 0x0005
+#define IMAGE_REL_ARM_GPREL12 0x0006
+#define IMAGE_REL_ARM_GPREL7 0x0007
+#define IMAGE_REL_ARM_BLX24 0x0008
+#define IMAGE_REL_ARM_BLX11 0x0009
+#define IMAGE_REL_ARM_SECTION 0x000E
+#define IMAGE_REL_ARM_SECREL 0x000F
+#define IMAGE_REL_ARM_MOV32A 0x0010
+#define IMAGE_REL_ARM_MOV32T 0x0011
+#define IMAGE_REL_ARM_BRANCH20T 0x0012
+#define IMAGE_REL_ARM_BRANCH24T 0x0014
+#define IMAGE_REL_ARM_BLX23T 0x0015
+
+/* ARM64 relocation types */
+#define IMAGE_REL_ARM64_ABSOLUTE 0x0000
+#define IMAGE_REL_ARM64_ADDR32 0x0001
+#define IMAGE_REL_ARM64_ADDR32NB 0x0002
+#define IMAGE_REL_ARM64_BRANCH26 0x0003
+#define IMAGE_REL_ARM64_PAGEBASE_REL21 0x0004
+#define IMAGE_REL_ARM64_REL21 0x0005
+#define IMAGE_REL_ARM64_PAGEOFFSET_12A 0x0006
+#define IMAGE_REL_ARM64_PAGEOFFSET_12L 0x0007
+#define IMAGE_REL_ARM64_SECREL 0x0008
+#define IMAGE_REL_ARM64_SECREL_LOW12A 0x0009
+#define IMAGE_REL_ARM64_SECREL_HIGH12A 0x000A
+#define IMAGE_REL_ARM64_SECREL_LOW12L 0x000B
+#define IMAGE_REL_ARM64_TOKEN 0x000C
+#define IMAGE_REL_ARM64_SECTION 0x000D
+#define IMAGE_REL_ARM64_ADDR64 0x000E
+
+/* AMD64 relocation types */
+#define IMAGE_REL_AMD64_ABSOLUTE 0x0000
+#define IMAGE_REL_AMD64_ADDR64 0x0001
+#define IMAGE_REL_AMD64_ADDR32 0x0002
+#define IMAGE_REL_AMD64_ADDR32NB 0x0003
+#define IMAGE_REL_AMD64_REL32 0x0004
+#define IMAGE_REL_AMD64_REL32_1 0x0005
+#define IMAGE_REL_AMD64_REL32_2 0x0006
+#define IMAGE_REL_AMD64_REL32_3 0x0007
+#define IMAGE_REL_AMD64_REL32_4 0x0008
+#define IMAGE_REL_AMD64_REL32_5 0x0009
+#define IMAGE_REL_AMD64_SECTION 0x000A
+#define IMAGE_REL_AMD64_SECREL 0x000B
+#define IMAGE_REL_AMD64_SECREL7 0x000C
+#define IMAGE_REL_AMD64_TOKEN 0x000D
+#define IMAGE_REL_AMD64_SREL32 0x000E
+#define IMAGE_REL_AMD64_PAIR 0x000F
+#define IMAGE_REL_AMD64_SSPAN32 0x0010
+
+/* certificate appended to PE image */
+typedef struct _WIN_CERTIFICATE {
+ uint32_t dwLength;
+ uint16_t wRevision;
+ uint16_t wCertificateType;
+ uint8_t bCertificate[];
+} WIN_CERTIFICATE, *LPWIN_CERTIFICATE;
+
+/* Definitions for the contents of the certs data block */
+#define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002
+#define WIN_CERT_TYPE_EFI_OKCS115 0x0EF0
+#define WIN_CERT_TYPE_EFI_GUID 0x0EF1
+
+#define WIN_CERT_REVISION_1_0 0x0100
+#define WIN_CERT_REVISION_2_0 0x0200
+
+struct pe_image {
+ u64 entry;
+ struct resource *code;
+ void *bin;
+
+ u16 image_type;
+ IMAGE_SECTION_HEADER *sections;
+ IMAGE_NT_HEADERS32 *nt;
+ int num_sections;
+};
+
+#ifdef CONFIG_PE
+struct pe_image *pe_open(const char *filename);
+unsigned long pe_get_mem_size(struct pe_image *pe);
+struct pe_image *pe_open_buf(void *bin, size_t pe_size);
+int pe_load(struct pe_image *pe);
+void pe_close(struct pe_image *pe);
+#else
+static inline struct pe_image *pe_open(const char *filename)
+{
+ return ERR_PTR(-ENOSYS);
+}
+
+static inline unsigned long pe_get_mem_size(struct pe_image *pe)
+{
+ return 0;
+}
+
+static inline struct pe_image *pe_open_buf(void *bin, size_t pe_size)
+{
+ return ERR_PTR(-ENOSYS);
+}
+
+static inline int pe_load(struct pe_image *pe)
+{
+ return -ENOSYS;
+}
+
+static inline void pe_close(struct pe_image *pe)
+{
+}
+#endif
+
+#endif /* _PE_H */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 065/112] common: add PE/COFF loader
2024-01-03 18:12 ` [PATCH 065/112] common: add PE/COFF loader Ahmad Fatoum
@ 2024-01-08 8:37 ` Sascha Hauer
2024-03-04 17:09 ` Ahmad Fatoum
0 siblings, 1 reply; 134+ messages in thread
From: Sascha Hauer @ 2024-01-08 8:37 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Jan 03, 2024 at 07:12:25PM +0100, Ahmad Fatoum wrote:
> EFI loader will need to parse and load PE executables. Add functions to
> facilitate that. The API is inspired by the already existing ELF API.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> common/Kconfig | 3 +
> common/Makefile | 1 +
> common/pe.c | 377 +++++++++++++++++++++++++++++++
> include/asm-generic/pe.h | 56 +++++
> include/linux/pagemap.h | 1 +
> include/linux/pe.h | 468 +++++++++++++++++++++++++++++++++++++++
> include/pe.h | 316 ++++++++++++++++++++++++++
> 7 files changed, 1222 insertions(+)
> create mode 100644 common/pe.c
> create mode 100644 include/asm-generic/pe.h
> create mode 100644 include/linux/pe.h
> create mode 100644 include/pe.h
>
> +struct pe_image *pe_open(const char *filename)
> +{
> + struct pe_image *pe;
> + size_t size;
> + void *bin;
> +
> + bin = read_file(filename, &size);
> + if (!bin)
> + return NULL;
The static inline wrapper of this function indicates you should return
an error pointer here.
> +
> + pe = pe_open_buf(bin, size);
> +
> + //free(bin); // FIXME
Isn't this only a matter of adding free(pe->bin) to pe_close() and
freeing it here in case pe_open_buf() fails?
> diff --git a/include/asm-generic/pe.h b/include/asm-generic/pe.h
> new file mode 100644
> index 000000000000..a1df7471348e
> --- /dev/null
> +++ b/include/asm-generic/pe.h
> @@ -0,0 +1,56 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Portable Executable and Common Object Constants
> + *
> + * Copyright (c) 2018 Heinrich Schuchardt
> + *
> + * based on the "Microsoft Portable Executable and Common Object File Format
> + * Specification", revision 11, 2017-01-23
> + */
> +
> +#ifndef _ASM_PE_H
> +#define _ASM_PE_H
> +
> +/* Characteristics */
> +#define IMAGE_FILE_RELOCS_STRIPPED 0x0001
> +#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
> +#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
> +#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
> +#define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010
> +#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
> +/* Reserved 0x0040 */
> +#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
> +#define IMAGE_FILE_32BIT_MACHINE 0x0100
> +#define IMAGE_FILE_DEBUG_STRIPPED 0x0200
> +#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
> +#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
> +#define IMAGE_FILE_SYSTEM 0x1000
> +#define IMAGE_FILE_DLL 0x2000
> +#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
> +#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
These defines are duplicated in include/linux/pe.h
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 065/112] common: add PE/COFF loader
2024-01-08 8:37 ` Sascha Hauer
@ 2024-03-04 17:09 ` Ahmad Fatoum
0 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 17:09 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 08.01.24 09:37, Sascha Hauer wrote:
> On Wed, Jan 03, 2024 at 07:12:25PM +0100, Ahmad Fatoum wrote:
>> EFI loader will need to parse and load PE executables. Add functions to
>> facilitate that. The API is inspired by the already existing ELF API.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> common/Kconfig | 3 +
>> common/Makefile | 1 +
>> common/pe.c | 377 +++++++++++++++++++++++++++++++
>> include/asm-generic/pe.h | 56 +++++
>> include/linux/pagemap.h | 1 +
>> include/linux/pe.h | 468 +++++++++++++++++++++++++++++++++++++++
>> include/pe.h | 316 ++++++++++++++++++++++++++
>> 7 files changed, 1222 insertions(+)
>> create mode 100644 common/pe.c
>> create mode 100644 include/asm-generic/pe.h
>> create mode 100644 include/linux/pe.h
>> create mode 100644 include/pe.h
>>
>> +struct pe_image *pe_open(const char *filename)
>> +{
>> + struct pe_image *pe;
>> + size_t size;
>> + void *bin;
>> +
>> + bin = read_file(filename, &size);
>> + if (!bin)
>> + return NULL;
>
> The static inline wrapper of this function indicates you should return
> an error pointer here.
>
>> +
>> + pe = pe_open_buf(bin, size);
>> +
>> + //free(bin); // FIXME
>
> Isn't this only a matter of adding free(pe->bin) to pe_close() and
> freeing it here in case pe_open_buf() fails?
>
>
>> diff --git a/include/asm-generic/pe.h b/include/asm-generic/pe.h
>> new file mode 100644
>> index 000000000000..a1df7471348e
>> --- /dev/null
>> +++ b/include/asm-generic/pe.h
>> @@ -0,0 +1,56 @@
>> +/* SPDX-License-Identifier: GPL-2.0+ */
>> +/*
>> + * Portable Executable and Common Object Constants
>> + *
>> + * Copyright (c) 2018 Heinrich Schuchardt
>> + *
>> + * based on the "Microsoft Portable Executable and Common Object File Format
>> + * Specification", revision 11, 2017-01-23
>> + */
>> +
>> +#ifndef _ASM_PE_H
>> +#define _ASM_PE_H
>> +
>> +/* Characteristics */
>> +#define IMAGE_FILE_RELOCS_STRIPPED 0x0001
>> +#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
>> +#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
>> +#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
>> +#define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010
>> +#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
>> +/* Reserved 0x0040 */
>> +#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
>> +#define IMAGE_FILE_32BIT_MACHINE 0x0100
>> +#define IMAGE_FILE_DEBUG_STRIPPED 0x0200
>> +#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
>> +#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
>> +#define IMAGE_FILE_SYSTEM 0x1000
>> +#define IMAGE_FILE_DLL 0x2000
>> +#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
>> +#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
>
> These defines are duplicated in include/linux/pe.h
Indeed. Some struct definitions are also duplicated between the U-Boot
header originating from Wine and <linux/pe.h>. I have removed the
duplication for v3.
Thanks,
Ahmad
>
> Sascha
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 066/112] efi: use efi_handle_t where appropriate
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (64 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 065/112] common: add PE/COFF loader Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 067/112] efi: block: move definitions into header file Ahmad Fatoum
` (45 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
efi_handle_t is a typedef for a void pointer. We use either void *
directly or unsigned long at places, where a handle would be the more
descriptive type. Fix this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/serial/efi-stdio.c | 2 +-
include/efi.h | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c
index b3b696d8fb3c..a0994168f0db 100644
--- a/drivers/serial/efi-stdio.c
+++ b/drivers/serial/efi-stdio.c
@@ -430,7 +430,7 @@ static int efi_console_probe(struct device *dev)
if (!priv->inputbuffer)
return -ENOMEM;
- efiret = BS->open_protocol((void *)efi_sys_table->con_in_handle,
+ efiret = BS->open_protocol(efi_sys_table->con_in_handle,
&inex_guid,
(void **)&inex,
efi_parent_image,
diff --git a/include/efi.h b/include/efi.h
index ec4c2a522df4..18583bf62594 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -601,11 +601,11 @@ struct efi_system_table {
struct efi_table_hdr hdr;
unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */
u32 fw_revision;
- unsigned long con_in_handle;
+ efi_handle_t con_in_handle;
struct efi_simple_input_interface *con_in;
- unsigned long con_out_handle;
+ efi_handle_t con_out_handle;
struct efi_simple_text_output_protocol *con_out;
- unsigned long stderr_handle;
+ efi_handle_t stderr_handle;
unsigned long std_err;
struct efi_runtime_services *runtime;
struct efi_boot_services *boottime;
@@ -615,9 +615,9 @@ struct efi_system_table {
struct efi_loaded_image {
u32 revision;
- void *parent_handle;
+ efi_handle_t parent_handle;
struct efi_system_table *system_table;
- void *device_handle;
+ efi_handle_t device_handle;
void *file_path;
void *reserved;
u32 load_options_size;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 067/112] efi: block: move definitions into header file
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (65 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 066/112] efi: use efi_handle_t where appropriate Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 068/112] efi: define efi_handle_t as opaque pointer Ahmad Fatoum
` (44 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We will need these definitions for the EFI loader as well, so move them
into a header.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/block/efi-block-io.c | 27 ---------------------------
include/efi.h | 27 +++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/drivers/block/efi-block-io.c b/drivers/block/efi-block-io.c
index 810b6da32d55..876b46c2d7a7 100644
--- a/drivers/block/efi-block-io.c
+++ b/drivers/block/efi-block-io.c
@@ -19,33 +19,6 @@
#define EFI_BLOCK_IO_PROTOCOL_REVISION2 0x00020001
#define EFI_BLOCK_IO_PROTOCOL_REVISION3 ((2<<16) | (31))
-struct efi_block_io_media{
- u32 media_id;
- bool removable_media;
- bool media_present;
- bool logical_partition;
- bool read_only;
- bool write_caching;
- u32 block_size;
- u32 io_align;
- sector_t last_block;
- u64 lowest_aligned_lba; /* added in Revision 2 */
- u32 logical_blocks_per_physical_block; /* added in Revision 2 */
- u32 optimal_transfer_length_granularity; /* added in Revision 3 */
-};
-
-struct efi_block_io_protocol {
- u64 revision;
- struct efi_block_io_media *media;
- efi_status_t(EFIAPI *reset)(struct efi_block_io_protocol *this,
- bool ExtendedVerification);
- efi_status_t(EFIAPI *read)(struct efi_block_io_protocol *this, u32 media_id,
- u64 lba, unsigned long buffer_size, void *buf);
- efi_status_t(EFIAPI *write)(struct efi_block_io_protocol *this, u32 media_id,
- u64 lba, unsigned long buffer_size, void *buf);
- efi_status_t(EFIAPI *flush)(struct efi_block_io_protocol *this);
-};
-
struct efi_bio_priv {
struct efi_block_io_protocol *protocol;
struct device *dev;
diff --git a/include/efi.h b/include/efi.h
index 18583bf62594..2e34c6be068a 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -655,6 +655,33 @@ __attribute__((noreturn)) void efi_main(efi_handle_t, struct efi_system_table *)
*/
#define EFI_VARIABLE_GUID_LEN 36
+struct efi_block_io_media{
+ u32 media_id;
+ bool removable_media;
+ bool media_present;
+ bool logical_partition;
+ bool read_only;
+ bool write_caching;
+ u32 block_size;
+ u32 io_align;
+ sector_t last_block;
+ u64 lowest_aligned_lba; /* added in Revision 2 */
+ u32 logical_blocks_per_physical_block; /* added in Revision 2 */
+ u32 optimal_transfer_length_granularity; /* added in Revision 3 */
+};
+
+struct efi_block_io_protocol {
+ u64 revision;
+ struct efi_block_io_media *media;
+ efi_status_t(EFIAPI *reset)(struct efi_block_io_protocol *this,
+ bool ExtendedVerification);
+ efi_status_t(EFIAPI *read)(struct efi_block_io_protocol *this, u32 media_id,
+ u64 lba, unsigned long buffer_size, void *buf);
+ efi_status_t(EFIAPI *write)(struct efi_block_io_protocol *this, u32 media_id,
+ u64 lba, unsigned long buffer_size, void *buf);
+ efi_status_t(EFIAPI *flush)(struct efi_block_io_protocol *this);
+};
+
struct simple_text_output_mode {
s32 max_mode;
s32 mode;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 068/112] efi: define efi_handle_t as opaque pointer
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (66 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 067/112] efi: block: move definitions into header file Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 069/112] efi: constify guid_t in API Ahmad Fatoum
` (43 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Typedef'ing efi_handle_t as void * means that we don't catch instance
where we pass a double indirect pointer when a normal pointer is
expected.
With loader support, we will start to dereference it anyway, so have it
point at an opaque type instead.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/efi/efi-device.c | 12 ++++++------
include/efi/types.h | 4 +++-
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index a533bc43eb37..3a16deab5f6b 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -53,7 +53,7 @@ static int efi_locate_handle(enum efi_locate_search_type search_type,
return 0;
}
-static struct efi_device *efi_find_device(efi_handle_t *handle)
+static struct efi_device *efi_find_device(efi_handle_t handle)
{
struct device *dev;
struct efi_device *efidev;
@@ -80,10 +80,10 @@ static void efi_devinfo(struct device *dev)
efi_guid_string(&efidev->guids[i]));
}
-static efi_handle_t *efi_find_parent(efi_handle_t *handle)
+static efi_handle_t efi_find_parent(efi_handle_t handle)
{
unsigned long handle_count = 0;
- efi_handle_t *handles = NULL, *parent;
+ efi_handle_t *handles = NULL, parent;
unsigned long num_guids;
efi_guid_t **guids;
int ret, i, j, k;
@@ -134,7 +134,7 @@ static efi_handle_t *efi_find_parent(efi_handle_t *handle)
return parent;
}
-static struct efi_device *efi_add_device(efi_handle_t *handle, efi_guid_t **guids,
+static struct efi_device *efi_add_device(efi_handle_t handle, efi_guid_t **guids,
int num_guids)
{
struct efi_device *efidev;
@@ -238,7 +238,7 @@ static int efi_register_device(struct efi_device *efidev)
void efi_register_devices(void)
{
unsigned long handle_count = 0;
- efi_handle_t *handles = NULL;
+ efi_handle_t *handles = NULL;
unsigned long num_guids;
efi_guid_t **guids;
int ret, i;
@@ -402,7 +402,7 @@ static void efi_set_bootsource(void)
enum bootsource src = BOOTSOURCE_UNKNOWN;
int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
- efi_handle_t *efi_parent;
+ efi_handle_t efi_parent;
if (!efi_loaded_image->parent_handle)
goto out;
diff --git a/include/efi/types.h b/include/efi/types.h
index 6e134387692f..3309820416be 100644
--- a/include/efi/types.h
+++ b/include/efi/types.h
@@ -9,7 +9,9 @@
typedef unsigned long efi_status_t;
typedef u16 efi_char16_t; /* UNICODE character */
typedef u64 efi_physical_addr_t;
-typedef void *efi_handle_t;
+
+struct efi_object;
+typedef struct efi_object *efi_handle_t;
/*
* The UEFI spec and EDK2 reference implementation both define EFI_GUID as
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 069/112] efi: constify guid_t in API
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (67 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 068/112] efi: define efi_handle_t as opaque pointer Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 070/112] efi: rename efi_simple_input_interface to efi_simple_text_input_protocol Ahmad Fatoum
` (42 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Improve const safety by marking parameters that are pointers to const as
such.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/efi.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/efi.h b/include/efi.h
index 2e34c6be068a..f0c968ec5e8a 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -241,12 +241,12 @@ struct efi_boot_services {
#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
#define EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010
#define EFI_OPEN_PROTOCOL_EXCLUSIVE 0x00000020
- efi_status_t (EFIAPI *open_protocol)(efi_handle_t handle, efi_guid_t *protocol,
+ efi_status_t (EFIAPI *open_protocol)(efi_handle_t handle, const efi_guid_t *protocol,
void ** interface, efi_handle_t agent_handle,
efi_handle_t controller_handle, u32 attributes);
- efi_status_t (EFIAPI *close_protocol)(efi_handle_t handle, efi_guid_t *protocol,
+ efi_status_t (EFIAPI *close_protocol)(efi_handle_t handle, const efi_guid_t *protocol,
efi_handle_t agent, efi_handle_t controller);
- efi_status_t(EFIAPI *open_protocol_information)(efi_handle_t handle, efi_guid_t *Protocol,
+ efi_status_t(EFIAPI *open_protocol_information)(efi_handle_t handle, const efi_guid_t *Protocol,
struct efi_open_protocol_information_entry **entry_buffer,
unsigned long *entry_count);
efi_status_t (EFIAPI *protocols_per_handle)(efi_handle_t handle,
@@ -254,7 +254,7 @@ struct efi_boot_services {
unsigned long *protocols_buffer_count);
efi_status_t (EFIAPI *locate_handle_buffer) (
enum efi_locate_search_type search_type,
- efi_guid_t *protocol, void *search_key,
+ const efi_guid_t *protocol, void *search_key,
unsigned long *no_handles, efi_handle_t **buffer);
void *locate_protocol;
void *install_multiple_protocol_interfaces;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 070/112] efi: rename efi_simple_input_interface to efi_simple_text_input_protocol
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (68 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 069/112] efi: constify guid_t in API Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 071/112] efi: add EFI_WARN constants Ahmad Fatoum
` (41 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
This aligns the name with what's in the specification.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/serial/efi-stdio.c | 2 +-
include/efi.h | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c
index a0994168f0db..c8c84270093e 100644
--- a/drivers/serial/efi-stdio.c
+++ b/drivers/serial/efi-stdio.c
@@ -20,7 +20,7 @@
struct efi_console_priv {
struct efi_simple_text_output_protocol *out;
- struct efi_simple_input_interface *in;
+ struct efi_simple_text_input_protocol *in;
struct efi_simple_text_input_ex_protocol *inex;
struct console_device cdev;
u16 efi_console_buffer[CONFIG_CBSIZE + 1];
diff --git a/include/efi.h b/include/efi.h
index f0c968ec5e8a..1749001adb48 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -602,7 +602,7 @@ struct efi_system_table {
unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */
u32 fw_revision;
efi_handle_t con_in_handle;
- struct efi_simple_input_interface *con_in;
+ struct efi_simple_text_input_protocol *con_in;
efi_handle_t con_out_handle;
struct efi_simple_text_output_protocol *con_out;
efi_handle_t stderr_handle;
@@ -711,12 +711,12 @@ struct efi_simple_text_output_protocol {
struct efi_input_key;
-struct efi_simple_input_interface {
- efi_status_t(EFIAPI *reset)(struct efi_simple_input_interface *this,
+struct efi_simple_text_input_protocol {
+ efi_status_t(EFIAPI *reset)(struct efi_simple_text_input_protocol *this,
bool ExtendedVerification);
- efi_status_t(EFIAPI *read_key_stroke)(struct efi_simple_input_interface *this,
+ efi_status_t(EFIAPI *read_key_stroke)(struct efi_simple_text_input_protocol *this,
struct efi_input_key *key);
- void *wait_for_key;
+ struct efi_event *wait_for_key;
};
struct efi_device_path *device_path_from_handle(efi_handle_t Handle);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 071/112] efi: add EFI_WARN constants
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (69 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 070/112] efi: rename efi_simple_input_interface to efi_simple_text_input_protocol Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 072/112] efi-stdio: fix wait_for_event argument Ahmad Fatoum
` (40 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
These constants can be returned by some of the EFI loader protocols
implemented later on.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/efi.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/efi.h b/include/efi.h
index 1749001adb48..7e8b7f0a49b8 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -52,6 +52,14 @@
#define EFI_INVALID_LANGUAGE (32 | EFI_ERROR_MASK)
#define EFI_COMPROMISED_DATA (33 | EFI_ERROR_MASK)
+#define EFI_WARN_UNKNOWN_GLYPH 1
+#define EFI_WARN_DELETE_FAILURE 2
+#define EFI_WARN_WRITE_FAILURE 3
+#define EFI_WARN_BUFFER_TOO_SMALL 4
+#define EFI_WARN_STALE_DATA 5
+#define EFI_WARN_FILE_SYSTEM 6
+#define EFI_WARN_RESET_REQUIRED 7
+
#define EFI_ERROR(a) (((signed long) a) < 0)
/*
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 072/112] efi-stdio: fix wait_for_event argument
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (70 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 071/112] efi: add EFI_WARN constants Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 073/112] efi-stdio: wait for extended input key event when using extended input Ahmad Fatoum
` (39 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
EFI v2.10 documents the following about EFI events:
| // EFI_EVENT: Handle to an event structure. Type VOID *
|
| typedef
| EFI_STATUS
| (EFIAPI *EFI_WAIT_FOR_EVENT) (
| IN UINTN NumberOfEvents,
| IN EFI_EVENT *Event,
| OUT UINTN *Index
| );
|
| typedef struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL {
| EFI_INPUT_RESET Reset;
| EFI_INPUT_READ_KEY ReadKeyStroke;
| EFI_EVENT WaitForKey;
| } EFI_SIMPLE_TEXT_INPUT_PROTOCOL;
To sum up, wait_for_event takes the number of events to wait for and a
pointer to an EFI_EVENT array of that size. Because we define efi_event
as void *, it went unnoticed that we passed a plain pointer instead of
a pointer to a pointer like the API expects.
With the using of an opaque type in the follow-up commit, this will
trigger a warning, so we fix this here in anticipation.
I am not sure how this went unnoticed so far, but the efi-stdio
console driver behaves as one would expect in Qemu.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/serial/efi-stdio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c
index c8c84270093e..d31de5f53796 100644
--- a/drivers/serial/efi-stdio.c
+++ b/drivers/serial/efi-stdio.c
@@ -87,7 +87,7 @@ static int efi_read_key(struct efi_console_priv *priv, bool wait)
/* wait until key is pressed */
if (wait)
- BS->wait_for_event(1, priv->in->wait_for_key, &index);
+ BS->wait_for_event(1, &priv->in->wait_for_key, &index);
if (priv->inex) {
efiret = priv->inex->read_key_stroke_ex(priv->inex, &kd);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 073/112] efi-stdio: wait for extended input key event when using extended input
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (71 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 072/112] efi-stdio: fix wait_for_event argument Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 074/112] efi: flesh out EFI definitions in header Ahmad Fatoum
` (38 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Extended input protocol support was added to deal with EFI firmwares that
don't report control characters rendering utilities like barebox edit
unusable.
The extended input support comes with its own event for use with the
wait_for_event boot service, which we should use instead of the
non-extended variant in case we are going to read the key with the
extended protocol.
Fixes: 438f80e98658 ("serial: efi-stdio: Add simple_text_input_ex_protocol backend")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/serial/efi-stdio.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c
index d31de5f53796..235d67a303ed 100644
--- a/drivers/serial/efi-stdio.c
+++ b/drivers/serial/efi-stdio.c
@@ -79,17 +79,23 @@ static int xlate_keypress(struct efi_input_key *k)
return k->unicode_char & 0xff;
}
-static int efi_read_key(struct efi_console_priv *priv, bool wait)
+static void efi_wait_single_event(void *event)
{
unsigned long index;
+
+ /* wait until key is pressed */
+ BS->wait_for_event(1, &event, &index);
+}
+
+static int efi_read_key(struct efi_console_priv *priv, bool wait)
+{
efi_status_t efiret;
struct efi_key_data kd;
- /* wait until key is pressed */
- if (wait)
- BS->wait_for_event(1, &priv->in->wait_for_key, &index);
-
if (priv->inex) {
+ if (wait)
+ efi_wait_single_event(priv->inex->wait_for_key_ex);
+
efiret = priv->inex->read_key_stroke_ex(priv->inex, &kd);
if (efiret == EFI_NOT_READY)
@@ -118,6 +124,9 @@ static int efi_read_key(struct efi_console_priv *priv, bool wait)
}
}
+ if (wait)
+ efi_wait_single_event(priv->in->wait_for_key);
+
efiret = priv->in->read_key_stroke(priv->in, &kd.key);
if (EFI_ERROR(efiret))
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 074/112] efi: flesh out EFI definitions in header
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (72 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 073/112] efi-stdio: wait for extended input key event when using extended input Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 075/112] efi: add efi_driver_binding_protocol Ahmad Fatoum
` (37 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We have a lot of function pointer members in the protocols, that were
defined as void pointers instead of properly prototyped function pointers.
Similarly, a lot of data types are defined to equivalent types that
aren't as descriptive, e.g. size_t vs ulong and s16 vs efi_char16_t.
Let's switch them over all at once. No functional change as the types
are either equivalent or were unused in the case of function pointers.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/clocksource/efi.c | 4 +-
drivers/serial/efi-stdio.c | 4 +-
include/efi.h | 115 ++++++++++++++++++++++---------------
include/efi/efi-stdio.h | 4 +-
4 files changed, 74 insertions(+), 53 deletions(-)
diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
index 11dbb6189786..1ac587a715f2 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi.c
@@ -12,14 +12,14 @@
#include <linux/err.h>
static uint64_t ticks = 1;
-static void *efi_cs_evt;
+static struct efi_event *efi_cs_evt;
static uint64_t efi_cs_read(void)
{
return ticks;
}
-static void efi_cs_inc(void *event, void *ctx)
+static void efi_cs_inc(struct efi_event *event, void *ctx)
{
ticks++;
}
diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c
index 235d67a303ed..92133f837838 100644
--- a/drivers/serial/efi-stdio.c
+++ b/drivers/serial/efi-stdio.c
@@ -79,9 +79,9 @@ static int xlate_keypress(struct efi_input_key *k)
return k->unicode_char & 0xff;
}
-static void efi_wait_single_event(void *event)
+static void efi_wait_single_event(struct efi_event *event)
{
- unsigned long index;
+ size_t index;
/* wait until key is pressed */
BS->wait_for_event(1, &event, &index);
diff --git a/include/efi.h b/include/efi.h
index 7e8b7f0a49b8..08cb07c8b946 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -177,18 +177,20 @@ enum efi_timer_delay {
EFI_TIMER_RELATIVE = 2
};
+struct efi_event;
+
/*
* EFI Boot Services table
*/
struct efi_boot_services {
struct efi_table_hdr hdr;
- void *raise_tpl;
- void *restore_tpl;
+ efi_status_t (EFIAPI *raise_tpl)(unsigned long new_tpl);
+ void (EFIAPI *restore_tpl)(unsigned long old_tpl);
efi_status_t (EFIAPI *allocate_pages)(int, int, unsigned long,
efi_physical_addr_t *);
efi_status_t (EFIAPI *free_pages)(efi_physical_addr_t, unsigned long);
- efi_status_t (EFIAPI *get_memory_map)(unsigned long *, void *, unsigned long *,
- unsigned long *, u32 *);
+ efi_status_t (EFIAPI *get_memory_map)(size_t *, struct efi_memory_desc *,
+ size_t *, size_t *, u32 *);
efi_status_t (EFIAPI *allocate_pool)(int, unsigned long, void **);
efi_status_t (EFIAPI *free_pool)(void *);
#define EFI_EVT_TIMER 0x80000000
@@ -203,33 +205,39 @@ struct efi_boot_services {
#define EFI_TPL_NOTIFY 16
#define EFI_TPL_HIGH_LEVEL 31
efi_status_t(EFIAPI *create_event)(u32 type , unsigned long tpl,
- void (*fn) (void *event, void *ctx),
- void *ctx, void **event);
- efi_status_t(EFIAPI *set_timer)(void *event, enum efi_timer_delay type, uint64_t time);
- efi_status_t(EFIAPI *wait_for_event)(unsigned long number_of_events, void *event,
- unsigned long *index);
- void *signal_event;
- efi_status_t(EFIAPI *close_event)(void *event);
- void *check_event;
- void *install_protocol_interface;
- void *reinstall_protocol_interface;
- void *uninstall_protocol_interface;
- efi_status_t (EFIAPI *handle_protocol)(efi_handle_t, efi_guid_t *, void **);
+ void (*fn) (struct efi_event *event, void *ctx),
+ void *ctx, struct efi_event **event);
+ efi_status_t(EFIAPI *set_timer)(struct efi_event *event, enum efi_timer_delay type, uint64_t time);
+ efi_status_t(EFIAPI *wait_for_event)(size_t number_of_events, struct efi_event **event,
+ size_t *index);
+ efi_status_t (EFIAPI *signal_event)(struct efi_event *event);
+ efi_status_t(EFIAPI *close_event)(struct efi_event *event);
+#define EFI_NATIVE_INTERFACE 0x00000000
+ efi_status_t (EFIAPI *check_event)(struct efi_event *event);
+ efi_status_t (EFIAPI *install_protocol_interface)(efi_handle_t *handle, const efi_guid_t *protocol,
+ int protocol_interface_type, void *protocol_interface);
+ efi_status_t (EFIAPI *reinstall_protocol_interface)(efi_handle_t handle, const efi_guid_t *protocol,
+ void *old_interface, void *new_interface);
+ efi_status_t (EFIAPI *uninstall_protocol_interface)(efi_handle_t handle,
+ const efi_guid_t *protocol, void *protocol_interface);
+
+ efi_status_t (EFIAPI *handle_protocol)(efi_handle_t, const efi_guid_t *, void **);
void *__reserved;
- void *register_protocol_notify;
+ efi_status_t (EFIAPI *register_protocol_notify)(const efi_guid_t *protocol, struct efi_event *event,
+ void **registration);
efi_status_t (EFIAPI *locate_handle) (enum efi_locate_search_type search_type,
- efi_guid_t *protocol, void *search_key,
- unsigned long *buffer_size, efi_handle_t *buffer);
- efi_status_t (EFIAPI *locate_device_path)(efi_guid_t *protocol,
+ const efi_guid_t *protocol, void *search_key,
+ size_t *buffer_size, efi_handle_t *buffer);
+ efi_status_t (EFIAPI *locate_device_path)(const efi_guid_t *protocol,
struct efi_device_path **device_path, efi_handle_t *device);
- void *install_configuration_table;
+ efi_status_t (EFIAPI *install_configuration_table)(const efi_guid_t *guid, void *table);
efi_status_t (EFIAPI *load_image)(bool boot_policiy, efi_handle_t parent_image,
struct efi_device_path *file_path, void *source_buffer,
unsigned long source_size, efi_handle_t *image);
efi_status_t (EFIAPI *start_image)(efi_handle_t handle,
- unsigned long *exitdata_size, s16 **exitdata);
+ size_t *exitdata_size, u16 **exitdata);
efi_status_t(EFIAPI *exit)(efi_handle_t handle, efi_status_t exit_status,
- unsigned long exitdata_size, s16 *exitdata);
+ unsigned long exitdata_size, u16 *exitdata);
efi_status_t (EFIAPI *unload_image)(efi_handle_t handle);
efi_status_t (EFIAPI *exit_boot_services)(efi_handle_t, unsigned long);
void *get_next_monotonic_count;
@@ -237,12 +245,13 @@ struct efi_boot_services {
efi_status_t (EFIAPI *set_watchdog_timer)(unsigned long timeout,
uint64_t watchdog_code,
unsigned long data_size,
- s16 *watchdog_data);
+ u16 *watchdog_data);
efi_status_t(EFIAPI *connect_controller)(efi_handle_t controller_handle,
efi_handle_t *driver_image_handle,
struct efi_device_path *remaining_device_path,
bool Recursive);
- void *disconnect_controller;
+ efi_status_t (EFIAPI *disconnect_controller)(efi_handle_t controller_handle,
+ efi_handle_t driver_image_handle, efi_handle_t child_handle);
#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002
#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL 0x00000004
@@ -264,12 +273,14 @@ struct efi_boot_services {
enum efi_locate_search_type search_type,
const efi_guid_t *protocol, void *search_key,
unsigned long *no_handles, efi_handle_t **buffer);
- void *locate_protocol;
- void *install_multiple_protocol_interfaces;
- void *uninstall_multiple_protocol_interfaces;
- void *calculate_crc32;
- void *copy_mem;
- void *set_mem;
+ efi_status_t (EFIAPI *locate_protocol)(const efi_guid_t *protocol,
+ void *registration, void **protocol_interface);
+ efi_status_t (EFIAPI *install_multiple_protocol_interfaces)(efi_handle_t *handle, ...);
+ efi_status_t (EFIAPI *uninstall_multiple_protocol_interfaces)(efi_handle_t handle, ...);
+ efi_status_t (EFIAPI *calculate_crc32)(const void *data,
+ unsigned long data_size, uint32_t *crc32);
+ void (EFIAPI *copy_mem)(void *destination, const void *source, unsigned long length);
+ void (EFIAPI *set_mem)(void *buffer, unsigned long size, uint8_t value);
void *create_event_ex;
};
@@ -281,7 +292,8 @@ extern struct efi_boot_services *BS;
enum efi_reset_type {
EFI_RESET_COLD = 0,
EFI_RESET_WARM = 1,
- EFI_RESET_SHUTDOWN = 2
+ EFI_RESET_SHUTDOWN = 2,
+ EFI_RESET_PLATFORM_SPECIFIC = 3,
};
/*
@@ -292,19 +304,24 @@ enum efi_reset_type {
struct efi_runtime_services {
struct efi_table_hdr hdr;
- void *get_time;
- void *set_time;
- void *get_wakeup_time;
- void *set_wakeup_time;
- void *set_virtual_address_map;
- void *convert_pointer;
- efi_status_t (EFIAPI *get_variable)(s16 *variable_name, efi_guid_t *vendor,
+ efi_status_t (EFIAPI *get_time)(struct efi_time *time,
+ struct efi_time_cap *capabilities);
+ efi_status_t (EFIAPI *set_time)(struct efi_time *time);
+ efi_status_t (EFIAPI *get_wakeup_time)(char *enabled, char *pending,
+ struct efi_time *time);
+ efi_status_t (EFIAPI *set_wakeup_time)(char enabled, struct efi_time *time);
+ efi_status_t (EFIAPI *set_virtual_address_map)(size_t memory_map_size,
+ size_t descriptor_size,
+ uint32_t descriptor_version,
+ struct efi_memory_desc *virtmap);
+ efi_status_t (*convert_pointer)(unsigned long dbg, void **address);
+ efi_status_t (EFIAPI *get_variable)(efi_char16_t *variable_name, const efi_guid_t *vendor,
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);
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;
+ efi_status_t (EFIAPI *get_next_high_mono_count)(uint32_t *high_count);
void (EFIAPI *reset_system)(enum efi_reset_type reset_type, efi_status_t reset_status,
unsigned long data_size, void *reset_data);
void *update_capsule;
@@ -607,14 +624,14 @@ struct efi_config_table {
struct efi_system_table {
struct efi_table_hdr hdr;
- unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */
+ efi_char16_t *fw_vendor; /* physical addr of CHAR16 vendor string */
u32 fw_revision;
efi_handle_t con_in_handle;
struct efi_simple_text_input_protocol *con_in;
efi_handle_t con_out_handle;
struct efi_simple_text_output_protocol *con_out;
efi_handle_t stderr_handle;
- unsigned long std_err;
+ struct efi_simple_text_output_protocol *std_err;
struct efi_runtime_services *runtime;
struct efi_boot_services *boottime;
unsigned long nr_tables;
@@ -634,7 +651,7 @@ struct efi_loaded_image {
__aligned_u64 image_size;
unsigned int image_code_type;
unsigned int image_data_type;
- unsigned long unload;
+ efi_status_t (EFIAPI *unload)(efi_handle_t image_handle);
};
__attribute__((noreturn)) void efi_main(efi_handle_t, struct efi_system_table *);
@@ -700,9 +717,12 @@ struct simple_text_output_mode {
};
struct efi_simple_text_output_protocol {
- void *reset;
- efi_status_t (EFIAPI *output_string)(void *, void *);
- void *test_string;
+ efi_status_t (EFIAPI *reset)(
+ struct efi_simple_text_output_protocol *this,
+ char extended_verification);
+ efi_status_t (EFIAPI *output_string)(struct efi_simple_text_output_protocol *this, const efi_char16_t *str);
+ efi_status_t (EFIAPI *test_string)(struct efi_simple_text_output_protocol *this,
+ const efi_char16_t *str);
efi_status_t(EFIAPI *query_mode)(struct efi_simple_text_output_protocol *this,
unsigned long mode_number, unsigned long *columns, unsigned long *rows);
@@ -713,7 +733,8 @@ struct efi_simple_text_output_protocol {
efi_status_t(EFIAPI *clear_screen) (struct efi_simple_text_output_protocol *this);
efi_status_t(EFIAPI *set_cursor_position) (struct efi_simple_text_output_protocol *this,
unsigned long column, unsigned long row);
- efi_status_t(EFIAPI *enable_cursor)(void *, bool enable);
+ efi_status_t(EFIAPI *enable_cursor)(struct efi_simple_text_output_protocol *this,
+ bool enable);
struct simple_text_output_mode *mode;
};
diff --git a/include/efi/efi-stdio.h b/include/efi/efi-stdio.h
index 623b42c10f19..0b3a184a78a8 100644
--- a/include/efi/efi-stdio.h
+++ b/include/efi/efi-stdio.h
@@ -18,7 +18,7 @@ struct efi_key_state {
struct efi_input_key {
u16 scan_code;
- s16 unicode_char;
+ efi_char16_t unicode_char;
};
struct efi_key_data {
@@ -55,7 +55,7 @@ typedef efi_status_t (EFIAPI *efi_unregister_keystroke_notify)(
struct efi_simple_text_input_ex_protocol {
efi_input_reset_ex reset;
efi_input_read_key_ex read_key_stroke_ex;
- void *wait_for_key_ex;
+ struct efi_event *wait_for_key_ex;
efi_set_state set_state;
efi_register_keystroke_notify register_key_notify;
efi_unregister_keystroke_notify unregister_key_notify;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 075/112] efi: add efi_driver_binding_protocol
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (73 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 074/112] efi: flesh out EFI definitions in header Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 076/112] efi: improve usability of EFI_PAGE_* macros Ahmad Fatoum
` (36 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We didn't need this for the EFI payload use case, but will need this for
the EFI loader use case.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/efi.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/include/efi.h b/include/efi.h
index 08cb07c8b946..a6dbc14ff3d9 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -576,6 +576,25 @@ extern struct efi_runtime_services *RT;
#define EFI_DRIVER_BINDING_PROTOCOL_GUID \
EFI_GUID(0x18a031ab, 0xb443, 0x4d1a, 0xa5, 0xc0, 0x0c, 0x09, 0x26, 0x1e, 0x9f, 0x71)
+struct efi_driver_binding_protocol {
+ efi_status_t (EFIAPI * supported)(
+ struct efi_driver_binding_protocol *this,
+ efi_handle_t controller_handle,
+ struct efi_device_path *remaining_device_path);
+ efi_status_t (EFIAPI * start)(
+ struct efi_driver_binding_protocol *this,
+ efi_handle_t controller_handle,
+ struct efi_device_path *remaining_device_path);
+ efi_status_t (EFIAPI * stop)(
+ struct efi_driver_binding_protocol *this,
+ efi_handle_t controller_handle,
+ size_t number_of_children,
+ efi_handle_t *child_handle_buffer);
+ u32 version;
+ efi_handle_t image_handle;
+ efi_handle_t driver_binding_handle;
+};
+
extern efi_guid_t efi_file_info_id;
extern efi_guid_t efi_simple_file_system_protocol_guid;
extern efi_guid_t efi_file_system_info_guid;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 076/112] efi: improve usability of EFI_PAGE_* macros
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (74 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 075/112] efi: add efi_driver_binding_protocol Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 077/112] fs: efi: move definitions into header Ahmad Fatoum
` (35 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
EFI code may want to mask addresses to check if they are page aligned.
Add a macro that masks the lower bits and while at it turn the type of
EFI_PAGE_SIZE to be 64 bits, so we avoid issues of truncation during
multiplication with a 32 bit value.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/efi.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/efi.h b/include/efi.h
index a6dbc14ff3d9..a73c96ef3a82 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -117,7 +117,8 @@ enum efi_memory_type {
#define EFI_MEMORY_DESCRIPTOR_VERSION 1
#define EFI_PAGE_SHIFT 12
-#define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
+#define EFI_PAGE_SIZE (1ULL << EFI_PAGE_SHIFT)
+#define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
/*
* Allocation types for calls to boottime->allocate_pages.
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 077/112] fs: efi: move definitions into header
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (75 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 076/112] efi: improve usability of EFI_PAGE_* macros Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 078/112] efi: fs: flesh out file system definitions Ahmad Fatoum
` (34 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
EFI loader support will require access to these same definitions, so
move them into a header.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/efi.c | 59 ---------------------------------------------------
include/efi.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 59 deletions(-)
diff --git a/fs/efi.c b/fs/efi.c
index 0cfd5a3aebf6..11073e9961c4 100644
--- a/fs/efi.c
+++ b/fs/efi.c
@@ -32,65 +32,6 @@
#include <efi/efi-device.h>
#include <linux/stddef.h>
-/* Open modes */
-#define EFI_FILE_MODE_READ 0x0000000000000001
-#define EFI_FILE_MODE_WRITE 0x0000000000000002
-#define EFI_FILE_MODE_CREATE 0x8000000000000000
-
-/* File attributes */
-#define EFI_FILE_READ_ONLY 0x0000000000000001
-#define EFI_FILE_HIDDEN 0x0000000000000002
-#define EFI_FILE_SYSTEM 0x0000000000000004
-#define EFI_FILE_RESERVIED 0x0000000000000008
-#define EFI_FILE_DIRECTORY 0x0000000000000010
-#define EFI_FILE_ARCHIVE 0x0000000000000020
-#define EFI_FILE_VALID_ATTR 0x0000000000000037
-
-#define EFI_FILE_HANDLE_REVISION 0x00010000
-struct efi_file_handle {
- uint64_t Revision;
- efi_status_t(EFIAPI *open)(struct efi_file_handle *File,
- struct efi_file_handle **NewHandle, s16 *FileName,
- uint64_t OpenMode, uint64_t Attributes);
- efi_status_t(EFIAPI *close)(struct efi_file_handle *File);
- efi_status_t(EFIAPI *delete)(struct efi_file_handle *File);
- efi_status_t(EFIAPI *read)(struct efi_file_handle *File, unsigned long *BufferSize,
- void *Buffer);
- efi_status_t(EFIAPI *write)(struct efi_file_handle *File,
- unsigned long *BufferSize, void *Buffer);
- efi_status_t(EFIAPI *get_position)(struct efi_file_handle *File,
- uint64_t *Position);
- efi_status_t(EFIAPI *set_position)(struct efi_file_handle *File,
- uint64_t Position);
- efi_status_t(EFIAPI *get_info)(struct efi_file_handle *File,
- efi_guid_t *InformationType, unsigned long *BufferSize,
- void *Buffer);
- efi_status_t(EFIAPI *set_info)(struct efi_file_handle *File,
- efi_guid_t *InformationType, unsigned long BufferSize,
- void *Buffer);
- efi_status_t(EFIAPI *flush)(struct efi_file_handle *File);
-};
-
-#define EFI_FILE_IO_INTERFACE_REVISION 0x00010000
-
-struct efi_file_io_interface {
- uint64_t Revision;
- efi_status_t(EFIAPI *open_volume)(
- struct efi_file_io_interface *This,
- struct efi_file_handle **Root);
-};
-
-struct efi_file_info {
- uint64_t Size;
- uint64_t FileSize;
- uint64_t PhysicalSize;
- struct efi_time CreateTime;
- struct efi_time LastAccessTime;
- struct efi_time ModificationTime;
- uint64_t Attribute;
- s16 FileName[1];
-};
-
struct efifs_priv {
struct efi_file_handle *root_dir;
struct efi_file_io_interface *protocol;
diff --git a/include/efi.h b/include/efi.h
index a73c96ef3a82..e0080552cf53 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -674,6 +674,65 @@ struct efi_loaded_image {
efi_status_t (EFIAPI *unload)(efi_handle_t image_handle);
};
+/* Open modes */
+#define EFI_FILE_MODE_READ 0x0000000000000001
+#define EFI_FILE_MODE_WRITE 0x0000000000000002
+#define EFI_FILE_MODE_CREATE 0x8000000000000000
+
+/* File attributes */
+#define EFI_FILE_READ_ONLY 0x0000000000000001
+#define EFI_FILE_HIDDEN 0x0000000000000002
+#define EFI_FILE_SYSTEM 0x0000000000000004
+#define EFI_FILE_RESERVIED 0x0000000000000008
+#define EFI_FILE_DIRECTORY 0x0000000000000010
+#define EFI_FILE_ARCHIVE 0x0000000000000020
+#define EFI_FILE_VALID_ATTR 0x0000000000000037
+
+#define EFI_FILE_HANDLE_REVISION 0x00010000
+struct efi_file_handle {
+ uint64_t Revision;
+ efi_status_t(EFIAPI *open)(struct efi_file_handle *File,
+ struct efi_file_handle **NewHandle, s16 *FileName,
+ uint64_t OpenMode, uint64_t Attributes);
+ efi_status_t(EFIAPI *close)(struct efi_file_handle *File);
+ efi_status_t(EFIAPI *delete)(struct efi_file_handle *File);
+ efi_status_t(EFIAPI *read)(struct efi_file_handle *File, unsigned long *BufferSize,
+ void *Buffer);
+ efi_status_t(EFIAPI *write)(struct efi_file_handle *File,
+ unsigned long *BufferSize, void *Buffer);
+ efi_status_t(EFIAPI *get_position)(struct efi_file_handle *File,
+ uint64_t *Position);
+ efi_status_t(EFIAPI *set_position)(struct efi_file_handle *File,
+ uint64_t Position);
+ efi_status_t(EFIAPI *get_info)(struct efi_file_handle *File,
+ efi_guid_t *InformationType, unsigned long *BufferSize,
+ void *Buffer);
+ efi_status_t(EFIAPI *set_info)(struct efi_file_handle *File,
+ efi_guid_t *InformationType, unsigned long BufferSize,
+ void *Buffer);
+ efi_status_t(EFIAPI *flush)(struct efi_file_handle *File);
+};
+
+#define EFI_FILE_IO_INTERFACE_REVISION 0x00010000
+
+struct efi_file_io_interface {
+ uint64_t Revision;
+ efi_status_t(EFIAPI *open_volume)(
+ struct efi_file_io_interface *This,
+ struct efi_file_handle **Root);
+};
+
+struct efi_file_info {
+ uint64_t Size;
+ uint64_t FileSize;
+ uint64_t PhysicalSize;
+ struct efi_time CreateTime;
+ struct efi_time LastAccessTime;
+ struct efi_time ModificationTime;
+ uint64_t Attribute;
+ s16 FileName[1];
+};
+
__attribute__((noreturn)) void efi_main(efi_handle_t, struct efi_system_table *);
/*
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 078/112] efi: fs: flesh out file system definitions
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (76 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 077/112] fs: efi: move definitions into header Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 079/112] efi: stdio: fix efi_register_keystroke_notify prototype Ahmad Fatoum
` (33 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
A number of members aren't prototyped or are using compatible, but less
descriptive. In preparation for adding EFI loader as another user of
these definitions, flesh them out.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/efi.h | 79 ++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 65 insertions(+), 14 deletions(-)
diff --git a/include/efi.h b/include/efi.h
index e0080552cf53..80d2f784847b 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -303,6 +303,8 @@ enum efi_reset_type {
#define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
#define EFI_RUNTIME_SERVICES_REVISION 0x00010000
+struct efi_capsule_header;
+
struct efi_runtime_services {
struct efi_table_hdr hdr;
efi_status_t (EFIAPI *get_time)(struct efi_time *time,
@@ -317,16 +319,21 @@ struct efi_runtime_services {
struct efi_memory_desc *virtmap);
efi_status_t (*convert_pointer)(unsigned long dbg, void **address);
efi_status_t (EFIAPI *get_variable)(efi_char16_t *variable_name, const efi_guid_t *vendor,
- 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);
- efi_status_t (EFIAPI *set_variable)(s16 *variable_name, efi_guid_t *vendor,
- u32 Attributes, unsigned long data_size, void *data);
+ u32 *Attributes, size_t *data_size, void *data);
+ efi_status_t (EFIAPI *get_next_variable)(size_t *variable_name_size,
+ efi_char16_t *variable_name, efi_guid_t *vendor);
+ efi_status_t (EFIAPI *set_variable)(efi_char16_t *variable_name, const efi_guid_t *vendor,
+ u32 Attributes, size_t data_size, const void *data);
efi_status_t (EFIAPI *get_next_high_mono_count)(uint32_t *high_count);
void (EFIAPI *reset_system)(enum efi_reset_type reset_type, efi_status_t reset_status,
- unsigned long data_size, void *reset_data);
- void *update_capsule;
- void *query_capsule_caps;
+ size_t data_size, void *reset_data);
+ efi_status_t (EFIAPI *update_capsule)(struct efi_capsule_header **capsule_header_array,
+ size_t capsule_count,
+ u64 scatter_gather_list);
+ efi_status_t (EFIAPI *query_capsule_caps)(struct efi_capsule_header **capsule_header_array,
+ size_t capsule_count,
+ u64 *maximum_capsule_size,
+ u32 *reset_type);
void *query_variable_info;
};
@@ -688,29 +695,58 @@ struct efi_loaded_image {
#define EFI_FILE_ARCHIVE 0x0000000000000020
#define EFI_FILE_VALID_ATTR 0x0000000000000037
+struct efi_file_io_token {
+ struct efi_event *event;
+ efi_status_t status;
+ size_t buffer_size;
+ void *buffer;
+};
+
#define EFI_FILE_HANDLE_REVISION 0x00010000
+#define EFI_FILE_HANDLE_REVISION2 0x00020000
+#define EFI_FILE_HANDLE_LATEST_REVISION EFI_FILE_PROTOCOL_REVISION2
struct efi_file_handle {
uint64_t Revision;
efi_status_t(EFIAPI *open)(struct efi_file_handle *File,
- struct efi_file_handle **NewHandle, s16 *FileName,
+ struct efi_file_handle **NewHandle, efi_char16_t *FileName,
uint64_t OpenMode, uint64_t Attributes);
efi_status_t(EFIAPI *close)(struct efi_file_handle *File);
efi_status_t(EFIAPI *delete)(struct efi_file_handle *File);
- efi_status_t(EFIAPI *read)(struct efi_file_handle *File, unsigned long *BufferSize,
+ efi_status_t(EFIAPI *read)(struct efi_file_handle *File, size_t *BufferSize,
void *Buffer);
efi_status_t(EFIAPI *write)(struct efi_file_handle *File,
- unsigned long *BufferSize, void *Buffer);
+ size_t *BufferSize, void *Buffer);
efi_status_t(EFIAPI *get_position)(struct efi_file_handle *File,
uint64_t *Position);
efi_status_t(EFIAPI *set_position)(struct efi_file_handle *File,
uint64_t Position);
efi_status_t(EFIAPI *get_info)(struct efi_file_handle *File,
- efi_guid_t *InformationType, unsigned long *BufferSize,
+ const efi_guid_t *InformationType, size_t *BufferSize,
void *Buffer);
efi_status_t(EFIAPI *set_info)(struct efi_file_handle *File,
- efi_guid_t *InformationType, unsigned long BufferSize,
+ const efi_guid_t *InformationType, size_t BufferSize,
void *Buffer);
efi_status_t(EFIAPI *flush)(struct efi_file_handle *File);
+ efi_status_t (EFIAPI *open_ex)(struct efi_file_handle *this,
+ struct efi_file_handle **new_handle,
+ u16 *file_name, u64 open_mode, u64 attributes,
+ struct efi_file_io_token *token);
+ efi_status_t (EFIAPI *read_ex)(struct efi_file_handle *this,
+ struct efi_file_io_token *token);
+ efi_status_t (EFIAPI *write_ex)(struct efi_file_handle *this,
+ struct efi_file_io_token *token);
+ efi_status_t (EFIAPI *flush_ex)(struct efi_file_handle *this,
+ struct efi_file_io_token *token);
+};
+
+#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION 0x00010000
+
+struct efi_load_file_protocol {
+ efi_status_t (EFIAPI *load_file)(struct efi_load_file_protocol *this,
+ struct efi_device_path *file_path,
+ bool boot_policy,
+ size_t *buffer_size,
+ void *buffer);
};
#define EFI_FILE_IO_INTERFACE_REVISION 0x00010000
@@ -722,6 +758,12 @@ struct efi_file_io_interface {
struct efi_file_handle **Root);
};
+struct efi_simple_file_system_protocol {
+ u64 Revision;
+ efi_status_t (EFIAPI *open_volume)(struct efi_simple_file_system_protocol *this,
+ struct efi_file_handle **root);
+};
+
struct efi_file_info {
uint64_t Size;
uint64_t FileSize;
@@ -730,7 +772,16 @@ struct efi_file_info {
struct efi_time LastAccessTime;
struct efi_time ModificationTime;
uint64_t Attribute;
- s16 FileName[1];
+ efi_char16_t FileName[];
+};
+
+struct efi_file_system_info {
+ u64 size;
+ u8 read_only;
+ u64 volume_size;
+ u64 free_space;
+ u32 block_size;
+ efi_char16_t volume_label[];
};
__attribute__((noreturn)) void efi_main(efi_handle_t, struct efi_system_table *);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 079/112] efi: stdio: fix efi_register_keystroke_notify prototype
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (77 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 078/112] efi: fs: flesh out file system definitions Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 080/112] video: mark EFI_GOP driver x86-only for now Ahmad Fatoum
` (32 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The keydata passed to efi_register_keystroke_notify is passed by
reference, not by value, according to spec.
This introduced no functional change as we don't yet use the prototype.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/efi/efi-stdio.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/efi/efi-stdio.h b/include/efi/efi-stdio.h
index 0b3a184a78a8..55ceb47d1b79 100644
--- a/include/efi/efi-stdio.h
+++ b/include/efi/efi-stdio.h
@@ -42,7 +42,7 @@ typedef efi_status_t (EFIAPI *efi_key_notify_function)(
typedef efi_status_t (EFIAPI *efi_register_keystroke_notify)(
struct efi_simple_text_input_ex_protocol *this,
- struct efi_key_data keydata,
+ struct efi_key_data *keydata,
efi_key_notify_function key_notification_function,
void **notify_handle
);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 080/112] video: mark EFI_GOP driver x86-only for now
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (78 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 079/112] efi: stdio: fix efi_register_keystroke_notify prototype Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 081/112] filetype: add new file types for EFI-enabled Linux images Ahmad Fatoum
` (31 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The driver currently crashes when running barebox on ARM64 Virt under
Tianocore. Until that's resolved, mark it x86-only.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/video/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 571ce49ef616..9e176d3198de 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -32,6 +32,7 @@ config DRIVER_VIDEO_ATMEL_HLCD
config DRIVER_VIDEO_EFI_GOP
bool "EFI Graphics Output Protocol (GOP)"
depends on EFI_PAYLOAD
+ depends on X86
config DRIVER_VIDEO_IMX
bool "i.MX framebuffer driver"
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 081/112] filetype: add new file types for EFI-enabled Linux images
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (79 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 080/112] video: mark EFI_GOP driver x86-only for now Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 082/112] efi: payload: register handler for EFI-stubbed ARM64 kernel Ahmad Fatoum
` (30 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We currently detect EFI-stubbed Linux images for ARM64 and RISC-V as
normal kernel images and would boot them that way. As these images
additionally start with MZ like normal PE executables, lets have new
filetypes for them. No functional change yet, but we can use a different
bootm handler for them in the future when boot is configured to be
EFI-enabled.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/lib64/armlinux.c | 7 +++++++
arch/riscv/lib/bootm.c | 7 +++++++
common/filetype.c | 13 ++++++++++---
include/filetype.h | 2 ++
4 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/arch/arm/lib64/armlinux.c b/arch/arm/lib64/armlinux.c
index 8382ffdf1b04..40fea37f53a7 100644
--- a/arch/arm/lib64/armlinux.c
+++ b/arch/arm/lib64/armlinux.c
@@ -37,6 +37,12 @@ static struct image_handler aarch64_linux_handler = {
.filetype = filetype_arm64_linux_image,
};
+static struct image_handler aarch64_linux_efi_handler = {
+ .name = "ARM aarch64 Linux/EFI image",
+ .bootm = do_bootm_linux,
+ .filetype = filetype_arm64_efi_linux_image,
+};
+
static struct image_handler aarch64_fit_handler = {
.name = "FIT image",
.bootm = do_bootm_linux,
@@ -83,6 +89,7 @@ static struct image_handler aarch64_barebox_handler = {
static int aarch64_register_image_handler(void)
{
+ register_image_handler(&aarch64_linux_efi_handler);
register_image_handler(&aarch64_linux_handler);
register_image_handler(&aarch64_barebox_handler);
diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
index 6984f282be4d..6bbf7bd156d8 100644
--- a/arch/riscv/lib/bootm.c
+++ b/arch/riscv/lib/bootm.c
@@ -36,6 +36,12 @@ static struct image_handler riscv_linux_handler = {
.filetype = filetype_riscv_linux_image,
};
+static struct image_handler riscv_linux_efi_handler = {
+ .name = "RISC-V Linux/EFI image",
+ .bootm = do_bootm_linux,
+ .filetype = filetype_riscv_linux_efi_image,
+};
+
static struct image_handler riscv_fit_handler = {
.name = "FIT image",
.bootm = do_bootm_linux,
@@ -51,6 +57,7 @@ static struct image_handler riscv_barebox_handler = {
static int riscv_register_image_handler(void)
{
register_image_handler(&riscv_linux_handler);
+ register_image_handler(&riscv_linux_efi_handler);
register_image_handler(&riscv_barebox_handler);
if (IS_ENABLED(CONFIG_FITIMAGE))
diff --git a/common/filetype.c b/common/filetype.c
index f726a933d245..5bf531b107ff 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -62,7 +62,9 @@ static const struct filetype_str filetype_str[] = {
[filetype_kwbimage_v1] = { "MVEBU kwbimage (v1)", "kwb1" },
[filetype_android_sparse] = { "Android sparse image", "sparse" },
[filetype_arm64_linux_image] = { "ARM aarch64 Linux image", "aarch64-linux" },
+ [filetype_arm64_efi_linux_image] = { "ARM aarch64 Linux/EFI image", "aarch64-efi-linux" },
[filetype_riscv_linux_image] = { "RISC-V Linux image", "riscv-linux" },
+ [filetype_riscv_efi_linux_image] = { "RISC-V Linux/EFI image", "riscv-efi-linux" },
[filetype_riscv_barebox_image] = { "RISC-V barebox image", "riscv-barebox" },
[filetype_elf] = { "ELF", "elf" },
[filetype_imx_image_v1] = { "i.MX image (v1)", "imx-image-v1" },
@@ -249,6 +251,11 @@ enum filetype file_detect_partition_table(const void *_buf, size_t bufsize)
return filetype_unknown;
}
+static bool is_dos_exe(const u8 *buf8)
+{
+ return buf8[0] == 'M' && buf8[1] == 'Z';
+}
+
#define CH_TOC_section_name 0x14
enum filetype file_detect_type(const void *_buf, size_t bufsize)
@@ -311,9 +318,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
if (buf[0] == be32_to_cpu(0x534F4659))
return filetype_bpk;
if (le32_to_cpu(buf[14]) == 0x644d5241)
- return filetype_arm64_linux_image;
+ return is_dos_exe(buf8) ? filetype_arm64_efi_linux_image : filetype_arm64_linux_image;
if (le32_to_cpu(buf[14]) == 0x05435352)
- return filetype_riscv_linux_image;
+ return is_dos_exe(buf8) ? filetype_riscv_efi_linux_image : filetype_riscv_linux_image;
if (le32_to_cpu(buf[14]) == 0x56435352 && !memcmp(&buf[12], "barebox", 8))
return filetype_riscv_barebox_image;
if (strncmp(buf8, "RKNS", 4) == 0)
@@ -367,7 +374,7 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
if (buf[9] == 0x016f2818 || buf[9] == 0x18286f01)
return filetype_arm_zimage;
- if (buf8[0] == 'M' && buf8[1] == 'Z')
+ if (is_dos_exe(buf8))
return filetype_exe;
if (bufsize < 256)
diff --git a/include/filetype.h b/include/filetype.h
index 4e646aec9d6f..125e81fee7f4 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -44,7 +44,9 @@ enum filetype {
filetype_kwbimage_v1,
filetype_android_sparse,
filetype_arm64_linux_image,
+ filetype_arm64_efi_linux_image,
filetype_riscv_linux_image,
+ filetype_riscv_efi_linux_image,
filetype_riscv_barebox_image,
filetype_elf,
filetype_imx_image_v1,
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 082/112] efi: payload: register handler for EFI-stubbed ARM64 kernel
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (80 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 081/112] filetype: add new file types for EFI-enabled Linux images Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 083/112] efi: payload: factor C efi_main into dedicated file Ahmad Fatoum
` (29 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The normal DT-only ARM64 boot handlers are not registered when barebox
is running as EFI payload. Instead, barebox started via EFI should start
images via EFI as well. Add a suitable binfmt handlers that does just that.
We intentionally don't register a bootm handler just yet, because we
need to take care of initrd and boot arguments still.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/image.c | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/efi/payload/image.c b/efi/payload/image.c
index b9cdb0e0562a..0795010cd9d2 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -155,12 +155,26 @@ static int efi_load_image(const char *file, struct efi_loaded_image **loaded_ima
return -efi_errno(efiret);
}
-static int efi_execute_image(const char *file)
+static bool is_linux_image(enum filetype filetype, const void *base)
+{
+ const struct linux_kernel_header *hdr = base;
+
+ if (IS_ENABLED(CONFIG_X86) &&
+ hdr->boot_flag == 0xAA55 && hdr->header == 0x53726448)
+ return true;
+
+ if (IS_ENABLED(CONFIG_CPU_V8) &&
+ filetype == filetype_arm64_efi_linux_image)
+ return true;
+
+ return false;
+}
+
+static int efi_execute_image(enum filetype filetype, const char *file)
{
efi_handle_t handle;
struct efi_loaded_image *loaded_image;
efi_status_t efiret;
- struct linux_kernel_header *image_header;
const char *options;
bool is_driver;
int ret;
@@ -172,9 +186,7 @@ static int efi_execute_image(const char *file)
is_driver = (loaded_image->image_code_type == EFI_BOOT_SERVICES_CODE) ||
(loaded_image->image_code_type == EFI_RUNTIME_SERVICES_CODE);
- image_header = (struct linux_kernel_header *)loaded_image->image_base;
- if (image_header->boot_flag == 0xAA55 &&
- image_header->header == 0x53726448) {
+ if (is_linux_image(filetype, loaded_image->image_base)) {
pr_debug("Linux kernel detected. Adding bootargs.");
options = linux_bootargs_get();
pr_info("add linux options '%s'\n", options);
@@ -317,7 +329,7 @@ static struct image_handler efi_handle_tr = {
static int efi_execute(struct binfmt_hook *b, char *file, int argc, char **argv)
{
- return efi_execute_image(file);
+ return efi_execute_image(b->type, file);
}
static struct binfmt_hook binfmt_efi_hook = {
@@ -325,11 +337,19 @@ static struct binfmt_hook binfmt_efi_hook = {
.hook = efi_execute,
};
+static struct binfmt_hook binfmt_arm64_efi_hook = {
+ .type = filetype_arm64_efi_linux_image,
+ .hook = efi_execute,
+};
+
static int efi_register_image_handler(void)
{
register_image_handler(&efi_handle_tr);
binfmt_register(&binfmt_efi_hook);
+ if (IS_ENABLED(CONFIG_CPU_V8))
+ binfmt_register(&binfmt_arm64_efi_hook);
+
return 0;
}
late_efi_initcall(efi_register_image_handler);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 083/112] efi: payload: factor C efi_main into dedicated file
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (81 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 082/112] efi: payload: register handler for EFI-stubbed ARM64 kernel Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 084/112] efi: payload: early-mem: simplify error message reporting Ahmad Fatoum
` (28 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
For barebox as EFI payload on ARM, we will not call start_barebox()
ourselves as we will be using PBL, which we don't on x86 yet.
Therefore move that code out of the common init.c into a new
entry-single.c and early-mem.c that can be used as needed.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/Makefile | 2 ++
efi/payload/early-mem.c | 32 +++++++++++++++++++++++++++
efi/payload/entry-single.c | 45 ++++++++++++++++++++++++++++++++++++++
efi/payload/init.c | 45 --------------------------------------
include/efi/efi-payload.h | 3 +++
5 files changed, 82 insertions(+), 45 deletions(-)
create mode 100644 efi/payload/early-mem.c
create mode 100644 efi/payload/entry-single.c
diff --git a/efi/payload/Makefile b/efi/payload/Makefile
index eeed046b0045..71305bee7006 100644
--- a/efi/payload/Makefile
+++ b/efi/payload/Makefile
@@ -5,3 +5,5 @@ obj-y += image.o
obj-$(CONFIG_OFTREE) += fdt.o
bbenv-y += env-efi
obj-$(CONFIG_CMD_IOMEM) += iomem.o
+obj-pbl-$(CONFIG_EFI_PAYLOAD) += early-mem.o
+obj-$(CONFIG_EFI_PAYLOAD) += entry-single.o
diff --git a/efi/payload/early-mem.c b/efi/payload/early-mem.c
new file mode 100644
index 000000000000..24bc1d34cc51
--- /dev/null
+++ b/efi/payload/early-mem.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/kernel.h>
+#include <linux/sizes.h>
+#include <efi.h>
+#include <efi/efi-payload.h>
+#include <linux/pagemap.h>
+
+efi_physical_addr_t efi_earlymem_alloc(const struct efi_system_table *sys_table,
+ size_t *memsize)
+{
+ struct efi_boot_services *bs = sys_table->boottime;
+ efi_physical_addr_t mem;
+ efi_status_t efiret;
+
+ mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
+ for (*memsize = SZ_256M; *memsize >= SZ_8M; *memsize /= 2) {
+ efiret = bs->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
+ EFI_LOADER_DATA,
+ *memsize/PAGE_SIZE, &mem);
+ if (!EFI_ERROR(efiret))
+ break;
+ if (efiret != EFI_OUT_OF_RESOURCES)
+ panic("failed to allocate malloc pool: %s\n",
+ efi_strerror(efiret));
+ }
+ if (EFI_ERROR(efiret))
+ panic("failed to allocate malloc pool: %s\n",
+ efi_strerror(efiret));
+
+ return mem;
+}
diff --git a/efi/payload/entry-single.c b/efi/payload/entry-single.c
new file mode 100644
index 000000000000..cb7981e03060
--- /dev/null
+++ b/efi/payload/entry-single.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#ifdef CONFIG_DEBUG_LL
+#define DEBUG
+#endif
+
+#include <linux/kernel.h>
+#include <linux/sizes.h>
+#include <efi.h>
+#include <efi/efi-payload.h>
+#include <memory.h>
+#include <common.h>
+
+/**
+ * efi-main - Entry point for EFI images
+ */
+void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
+{
+ efi_status_t efiret;
+ size_t memsize;
+ efi_physical_addr_t mem;
+
+#ifdef DEBUG
+ sys_table->con_out->output_string(sys_table->con_out, L"barebox\n");
+#endif
+
+ BS = sys_table->boottime;
+
+ efi_parent_image = image;
+ efi_sys_table = sys_table;
+ RT = sys_table->runtime;
+
+ efiret = BS->open_protocol(efi_parent_image, &efi_loaded_image_protocol_guid,
+ (void **)&efi_loaded_image,
+ efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (!EFI_ERROR(efiret))
+ BS->handle_protocol(efi_loaded_image->device_handle,
+ &efi_device_path_protocol_guid, (void **)&efi_device_path);
+
+ mem = efi_earlymem_alloc(sys_table, &memsize);
+
+ mem_malloc_init((void *)mem, (void *)mem + memsize - 1);
+
+ start_barebox();
+}
diff --git a/efi/payload/init.c b/efi/payload/init.c
index 906ede38336e..6c790c680602 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -266,51 +266,6 @@ static int efi_init(void)
}
device_efi_initcall(efi_init);
-/**
- * efi-main - Entry point for EFI images
- */
-void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
-{
- efi_physical_addr_t mem;
- size_t memsize;
- efi_status_t efiret;
-
-#ifdef DEBUG
- sys_table->con_out->output_string(sys_table->con_out, L"barebox\n");
-#endif
-
- BS = sys_table->boottime;
-
- efi_parent_image = image;
- efi_sys_table = sys_table;
- RT = sys_table->runtime;
-
- efiret = BS->open_protocol(efi_parent_image, &efi_loaded_image_protocol_guid,
- (void **)&efi_loaded_image,
- efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- if (!EFI_ERROR(efiret))
- BS->handle_protocol(efi_loaded_image->device_handle,
- &efi_device_path_protocol_guid, (void **)&efi_device_path);
-
- mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
- for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
- efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
- EFI_LOADER_DATA,
- memsize/PAGE_SIZE, &mem);
- if (!EFI_ERROR(efiret))
- break;
- if (efiret != EFI_OUT_OF_RESOURCES)
- panic("failed to allocate malloc pool: %s\n",
- efi_strerror(efiret));
- }
- if (EFI_ERROR(efiret))
- panic("failed to allocate malloc pool: %s\n",
- efi_strerror(efiret));
- mem_malloc_init((void *)mem, (void *)mem + memsize - 1);
-
- start_barebox();
-}
-
static int efi_core_init(void)
{
struct device *dev;
diff --git a/include/efi/efi-payload.h b/include/efi/efi-payload.h
index 3713ef359228..774c069229ab 100644
--- a/include/efi/efi-payload.h
+++ b/include/efi/efi-payload.h
@@ -25,4 +25,7 @@ int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
void *buf, unsigned long size);
int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec);
+efi_physical_addr_t efi_earlymem_alloc(const struct efi_system_table *sys_table,
+ size_t *memsize);
+
#endif
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 084/112] efi: payload: early-mem: simplify error message reporting
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (82 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 083/112] efi: payload: factor C efi_main into dedicated file Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 085/112] efi: payload: early-mem: use EFI_PAGE_SIZE instead of PAGE_SIZE Ahmad Fatoum
` (27 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Adding a size to the error message means that we can just use a single
error message for either error case with no loss of information.
While at it, we turn the error string into a code: This file can be
built for PBL later on and we won't have efi_strerror there.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/early-mem.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/efi/payload/early-mem.c b/efi/payload/early-mem.c
index 24bc1d34cc51..f9bf562c98ad 100644
--- a/efi/payload/early-mem.c
+++ b/efi/payload/early-mem.c
@@ -18,15 +18,12 @@ efi_physical_addr_t efi_earlymem_alloc(const struct efi_system_table *sys_table,
efiret = bs->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
EFI_LOADER_DATA,
*memsize/PAGE_SIZE, &mem);
- if (!EFI_ERROR(efiret))
+ if (!EFI_ERROR(efiret) || efiret != EFI_OUT_OF_RESOURCES)
break;
- if (efiret != EFI_OUT_OF_RESOURCES)
- panic("failed to allocate malloc pool: %s\n",
- efi_strerror(efiret));
}
if (EFI_ERROR(efiret))
- panic("failed to allocate malloc pool: %s\n",
- efi_strerror(efiret));
+ panic("failed to allocate %zu byte memory pool: 0x%lx\n",
+ *memsize, efiret);
return mem;
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 085/112] efi: payload: early-mem: use EFI_PAGE_SIZE instead of PAGE_SIZE
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (83 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 084/112] efi: payload: early-mem: simplify error message reporting Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 086/112] ARM64: add optional EFI stub Ahmad Fatoum
` (26 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Maybe one day we'll support 16K or 64K pages, but EFI_PAGE_SIZE as used
by EFI_ALLOCATE_PAGES is always in units of 4K pages, so let's use the
correct defines.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/early-mem.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/efi/payload/early-mem.c b/efi/payload/early-mem.c
index f9bf562c98ad..b4e8790a39c4 100644
--- a/efi/payload/early-mem.c
+++ b/efi/payload/early-mem.c
@@ -4,7 +4,6 @@
#include <linux/sizes.h>
#include <efi.h>
#include <efi/efi-payload.h>
-#include <linux/pagemap.h>
efi_physical_addr_t efi_earlymem_alloc(const struct efi_system_table *sys_table,
size_t *memsize)
@@ -17,7 +16,7 @@ efi_physical_addr_t efi_earlymem_alloc(const struct efi_system_table *sys_table,
for (*memsize = SZ_256M; *memsize >= SZ_8M; *memsize /= 2) {
efiret = bs->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
EFI_LOADER_DATA,
- *memsize/PAGE_SIZE, &mem);
+ *memsize / EFI_PAGE_SIZE, &mem);
if (!EFI_ERROR(efiret) || efiret != EFI_OUT_OF_RESOURCES)
break;
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 086/112] ARM64: add optional EFI stub
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (84 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 085/112] efi: payload: early-mem: use EFI_PAGE_SIZE instead of PAGE_SIZE Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 087/112] efi: devicepath: improve const safety Ahmad Fatoum
` (25 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
While very recent binutils releases have dedicated efi-*-aarch targets,
we may want to support older toolchains. For this reason, we import
the kernel's EFI stub PE fakery, so the same barebox-dt-2nd.img may be
loaded as if it were a "normal" or an EFI-stubbed kernel.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Makefile | 6 +-
arch/arm/Kconfig | 1 +
arch/arm/cpu/Kconfig | 1 +
arch/arm/cpu/board-dt-2nd-aarch64.S | 8 +-
arch/arm/cpu/cpu.c | 6 ++
| 122 ++++++++++++++++++++++++++++
arch/arm/cpu/entry.c | 3 +
arch/arm/cpu/interrupts_64.c | 6 +-
arch/arm/cpu/mmu-common.c | 4 +
arch/arm/cpu/start.c | 16 ++--
arch/arm/include/asm/pci.h | 4 +-
arch/arm/lib/pbl.lds.S | 13 +++
arch/arm/lib64/armlinux.c | 4 +
arch/x86/Kconfig | 1 +
efi/Kconfig | 13 ++-
efi/payload/Makefile | 2 +
efi/payload/boarddata.c | 45 ++++++++++
efi/payload/entry-multi.c | 45 ++++++++++
include/pbl.h | 4 +
test/self/mmu.c | 7 ++
20 files changed, 299 insertions(+), 12 deletions(-)
create mode 100644 arch/arm/cpu/efi-header-aarch64.S
create mode 100644 efi/payload/boarddata.c
create mode 100644 efi/payload/entry-multi.c
diff --git a/Makefile b/Makefile
index c5c627bb6a8c..a49b3c62d2bf 100644
--- a/Makefile
+++ b/Makefile
@@ -734,7 +734,11 @@ images: barebox.bin FORCE
images/%.s: barebox.bin FORCE
$(Q)$(MAKE) $(build)=images $@
-ifdef CONFIG_PBL_IMAGE
+ifdef CONFIG_EFI_STUB
+all: barebox.bin images barebox.efi
+barebox.efi: FORCE
+ $(Q)ln -fsn images/barebox-dt-2nd.img $@
+else ifdef CONFIG_PBL_IMAGE
all: barebox.bin images
else
all: barebox-flash-image barebox-flash-images
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index ee3914620ecd..186e045d3512 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -9,6 +9,7 @@ config ARM
select HAVE_ARCH_KASAN
select ARCH_HAS_SJLJ
select ARM_OPTIMZED_STRING_FUNCTIONS if KASAN
+ select HAVE_EFI_STUB
default y
config ARM_LINUX
diff --git a/arch/arm/cpu/Kconfig b/arch/arm/cpu/Kconfig
index 40dd35833a63..e69acaacdf2f 100644
--- a/arch/arm/cpu/Kconfig
+++ b/arch/arm/cpu/Kconfig
@@ -21,6 +21,7 @@ config CPU_64
select HAS_DMA
select ARCH_WANT_FRAME_POINTERS
select ARCH_HAS_ZERO_PAGE
+ select HAVE_EFI_PAYLOAD
# Select CPU types depending on the architecture selected. This selects
# which CPUs we support in the kernel image, and the compiler instruction
diff --git a/arch/arm/cpu/board-dt-2nd-aarch64.S b/arch/arm/cpu/board-dt-2nd-aarch64.S
index d2c9f132cef6..030366c1cbf5 100644
--- a/arch/arm/cpu/board-dt-2nd-aarch64.S
+++ b/arch/arm/cpu/board-dt-2nd-aarch64.S
@@ -2,6 +2,7 @@
#include <linux/linkage.h>
#include <asm/barebox-arm64.h>
#include <asm/image.h>
+#include "efi-header-aarch64.S"
#define IMAGE_FLAGS \
(ARM64_IMAGE_FLAG_PAGE_SIZE_4K << ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT) | \
@@ -9,7 +10,7 @@
.section .text_head_entry_start_dt_2nd
ENTRY("start_dt_2nd")
- adr x1, 0 /* code0 */
+ efi_signature_nop /* code0 */
b 2f /* code1 */
.xword 0x80000 /* Image load offset */
.xword _barebox_image_size /* Effective Image size */
@@ -18,12 +19,15 @@ ENTRY("start_dt_2nd")
.xword 0 /* reserved */
.xword 0 /* reserved */
.ascii ARM64_IMAGE_MAGIC /* magic number */
- .int 0 /* reserved (PE-COFF offset) */
+ .int .Lpe_header_offset /* reserved (PE-COFF offset) */
.asciz "barebox" /* unused for now */
2:
+ adr x1, 0
mov sp, x1
/* Stack now grows into the 0x80000 image load offset specified
* above. This is more than enough until FDT /memory is decoded.
*/
b dt_2nd_aarch64
+
+ __EFI_PE_HEADER
ENTRY_PROC_END(start_dt_2nd)
diff --git a/arch/arm/cpu/cpu.c b/arch/arm/cpu/cpu.c
index cacd442b28da..5f1ffe9a3c76 100644
--- a/arch/arm/cpu/cpu.c
+++ b/arch/arm/cpu/cpu.c
@@ -17,6 +17,7 @@
#include <asm/cputype.h>
#include <asm/cache.h>
#include <asm/ptrace.h>
+#include <efi/efi-mode.h>
/**
* Enable processor's instruction cache
@@ -82,6 +83,8 @@ static void disable_interrupts(void)
*/
static void arch_shutdown(void)
{
+ if (efi_is_payload())
+ return;
#ifdef CONFIG_MMU
mmu_disable();
@@ -96,6 +99,9 @@ extern unsigned long arm_stack_top;
static int arm_request_stack(void)
{
+ if (efi_is_payload())
+ return 0;
+
if (!request_sdram_region("stack", arm_stack_top - STACK_SIZE, STACK_SIZE))
pr_err("Error: Cannot request SDRAM region for stack\n");
--git a/arch/arm/cpu/efi-header-aarch64.S b/arch/arm/cpu/efi-header-aarch64.S
new file mode 100644
index 000000000000..941d0d8fdcaa
--- /dev/null
+++ b/arch/arm/cpu/efi-header-aarch64.S
@@ -0,0 +1,122 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2013 - 2017 Linaro, Ltd.
+ * Copyright (C) 2013, 2014 Red Hat, Inc.
+ */
+
+#include <linux/pe.h>
+#include <linux/sizes.h>
+#include <asm/memory.h>
+
+ .macro efi_signature_nop
+#ifdef CONFIG_EFI_STUB
+.L_head:
+ /*
+ * This ccmp instruction has no meaningful effect except that
+ * its opcode forms the magic "MZ" signature required by UEFI.
+ */
+ ccmp x18, #0, #0xd, pl
+#else
+ /*
+ * Bootloaders may inspect the opcode at the start of the kernel
+ * image to decide if the kernel is capable of booting via UEFI.
+ * So put an ordinary NOP here, not the "MZ.." pseudo-nop above.
+ */
+ nop
+#endif
+ .endm
+
+ .macro __EFI_PE_HEADER
+#ifdef CONFIG_EFI_STUB
+ .set .Lpe_header_offset, . - .L_head
+ .long PE_MAGIC
+ .short IMAGE_FILE_MACHINE_ARM64 // Machine
+ .short .Lsection_count // NumberOfSections
+ .long 0 // TimeDateStamp
+ .long 0 // PointerToSymbolTable
+ .long 0 // NumberOfSymbols
+ .short .Lsection_table - .Loptional_header // SizeOfOptionalHeader
+ .short IMAGE_FILE_DEBUG_STRIPPED | \
+ IMAGE_FILE_EXECUTABLE_IMAGE | \
+ IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics
+
+.Loptional_header:
+ .short PE_OPT_MAGIC_PE32PLUS // PE32+ format
+ .byte 0x02 // MajorLinkerVersion
+ .byte 0x14 // MinorLinkerVersion
+ .long _sdata - .Lefi_header_end // SizeOfCode
+ .long __pecoff_data_size // SizeOfInitializedData
+ .long 0 // SizeOfUninitializedData
+ .long __efistub_efi_pe_entry - .L_head // AddressOfEntryPoint
+ .long .Lefi_header_end - .L_head // BaseOfCode
+
+ .quad 0 // ImageBase
+ .long PBL_SEGMENT_ALIGN // SectionAlignment
+ .long PECOFF_FILE_ALIGNMENT // FileAlignment
+ .short 0 // MajorOperatingSystemVersion
+ .short 0 // MinorOperatingSystemVersion
+ .short LINUX_EFISTUB_MAJOR_VERSION // MajorImageVersion
+ .short LINUX_EFISTUB_MINOR_VERSION // MinorImageVersion
+ .short 0 // MajorSubsystemVersion
+ .short 0 // MinorSubsystemVersion
+ .long 0 // Win32VersionValue
+
+ .long __image_end - .L_head // SizeOfImage
+
+ // Everything before the kernel image is considered part of the header
+ .long .Lefi_header_end - .L_head // SizeOfHeaders
+ .long 0 // CheckSum
+ .short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem
+ .short 0 // DllCharacteristics
+ .quad 0 // SizeOfStackReserve
+ .quad 0 // SizeOfStackCommit
+ .quad 0 // SizeOfHeapReserve
+ .quad 0 // SizeOfHeapCommit
+ .long 0 // LoaderFlags
+ .long (.Lsection_table - .) / 8 // NumberOfRvaAndSizes
+
+ .quad 0 // ExportTable
+ .quad 0 // ImportTable
+ .quad 0 // ResourceTable
+ .quad 0 // ExceptionTable
+ .quad 0 // CertificationTable
+ .quad 0 // BaseRelocationTable
+
+ // Section table
+.Lsection_table:
+ .ascii ".text\0\0\0"
+ .long _sdata - .Lefi_header_end // VirtualSize
+ .long .Lefi_header_end - .L_head // VirtualAddress
+ .long _sdata - .Lefi_header_end // SizeOfRawData
+ .long .Lefi_header_end - .L_head // PointerToRawData
+
+ .long 0 // PointerToRelocations
+ .long 0 // PointerToLineNumbers
+ .short 0 // NumberOfRelocations
+ .short 0 // NumberOfLineNumbers
+ .long IMAGE_SCN_CNT_CODE | \
+ IMAGE_SCN_MEM_READ | \
+ IMAGE_SCN_MEM_EXECUTE // Characteristics
+
+ .ascii ".data\0\0\0"
+ .long __pecoff_data_size // VirtualSize
+ .long _sdata - .L_head // VirtualAddress
+ .long __pecoff_data_rawsize // SizeOfRawData
+ .long _sdata - .L_head // PointerToRawData
+
+ .long 0 // PointerToRelocations
+ .long 0 // PointerToLineNumbers
+ .short 0 // NumberOfRelocations
+ .short 0 // NumberOfLineNumbers
+ .long IMAGE_SCN_CNT_INITIALIZED_DATA | \
+ IMAGE_SCN_MEM_READ | \
+ IMAGE_SCN_MEM_WRITE // Characteristics
+
+ .set .Lsection_count, (. - .Lsection_table) / 40
+
+ .balign PBL_SEGMENT_ALIGN
+.Lefi_header_end:
+#else
+ .set .Lpe_header_offset, 0x0
+#endif
+ .endm
diff --git a/arch/arm/cpu/entry.c b/arch/arm/cpu/entry.c
index dc264c877117..cc08d0ff7e42 100644
--- a/arch/arm/cpu/entry.c
+++ b/arch/arm/cpu/entry.c
@@ -42,3 +42,6 @@ void NAKED __noreturn barebox_arm_entry(unsigned long membase,
__barebox_arm_entry(membase, memsize, boarddata,
arm_mem_stack_top(membase + memsize));
}
+
+void __noreturn barebox_pbl_entry(ulong, ulong, void *)
+ __alias(barebox_arm_entry);
diff --git a/arch/arm/cpu/interrupts_64.c b/arch/arm/cpu/interrupts_64.c
index b3e7da179756..6262ba8872db 100644
--- a/arch/arm/cpu/interrupts_64.c
+++ b/arch/arm/cpu/interrupts_64.c
@@ -11,6 +11,7 @@
#include <init.h>
#include <asm/system.h>
#include <asm/esr.h>
+#include <efi/efi-mode.h>
/* Avoid missing prototype warning, called from assembly */
void do_bad_sync (struct pt_regs *pt_regs);
@@ -204,6 +205,9 @@ static int aarch64_init_vectors(void)
{
unsigned int el;
+ if (efi_is_payload())
+ return 0;
+
el = current_el();
switch (el) {
case 3:
@@ -221,4 +225,4 @@ static int aarch64_init_vectors(void)
return 0;
}
-pure_initcall(aarch64_init_vectors);
+core_initcall(aarch64_init_vectors);
diff --git a/arch/arm/cpu/mmu-common.c b/arch/arm/cpu/mmu-common.c
index acd4a9d35413..aeaf6c269df6 100644
--- a/arch/arm/cpu/mmu-common.c
+++ b/arch/arm/cpu/mmu-common.c
@@ -13,6 +13,7 @@
#include <memory.h>
#include <zero_page.h>
#include "mmu-common.h"
+#include <efi/efi-mode.h>
void arch_sync_dma_for_cpu(void *vaddr, size_t size,
enum dma_data_direction dir)
@@ -67,6 +68,9 @@ void zero_page_faulting(void)
static int mmu_init(void)
{
+ if (efi_is_payload())
+ return 0;
+
if (list_empty(&memory_banks)) {
resource_size_t start;
int ret;
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 9f4cdfe67fbf..0351dcb9278d 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -43,14 +43,18 @@ static bool blob_is_arm_boarddata(const void *blob)
return bd->magic == BAREBOX_ARM_BOARDDATA_MAGIC;
}
+const struct barebox_boarddata *barebox_get_boarddata(void)
+{
+ if (!barebox_boarddata || !blob_is_arm_boarddata(barebox_boarddata))
+ return NULL;
+
+ return barebox_boarddata;
+}
+
u32 barebox_arm_machine(void)
{
- if (barebox_boarddata && blob_is_arm_boarddata(barebox_boarddata)) {
- const struct barebox_arm_boarddata *bd = barebox_boarddata;
- return bd->machine;
- } else {
- return 0;
- }
+ const struct barebox_boarddata *bd = barebox_get_boarddata();
+ return bd ? bd->machine : 0;
}
void *barebox_arm_boot_dtb(void)
diff --git a/arch/arm/include/asm/pci.h b/arch/arm/include/asm/pci.h
index d7419cabe7ef..7c834f110111 100644
--- a/arch/arm/include/asm/pci.h
+++ b/arch/arm/include/asm/pci.h
@@ -2,6 +2,8 @@
#ifndef __ASM_PCI_H
#define __ASM_PCI_H
-#define pcibios_assign_all_busses() 1
+#include <efi/efi-mode.h>
+
+#define pcibios_assign_all_busses() (!efi_is_payload())
#endif
diff --git a/arch/arm/lib/pbl.lds.S b/arch/arm/lib/pbl.lds.S
index 95929d7558bc..ec7296f0fb34 100644
--- a/arch/arm/lib/pbl.lds.S
+++ b/arch/arm/lib/pbl.lds.S
@@ -3,6 +3,7 @@
#include <linux/sizes.h>
#include <asm/barebox.lds.h>
+#include <asm/memory.h>
#include <asm-generic/memory_layout.h>
#include <asm-generic/pointer.h>
#include <asm/memory.h>
@@ -80,7 +81,9 @@ SECTIONS
.barebox_imd : { BAREBOX_IMD }
+ . = ALIGN(PBL_SEGMENT_ALIGN);
_etext = .; /* End of text and rodata section */
+ _sdata = .;
. = ALIGN(4);
.data : { *(.data*) }
@@ -127,6 +130,16 @@ SECTIONS
}
__pblext_end = .;
+ PECOFF_EDATA_PADDING
+
+ __pecoff_data_rawsize = ABSOLUTE(. - _etext);
+
+ /* .bss is dwarfed by piggydata size, so we just handle .bss
+ * as normal PE data
+ */
+
+ __pecoff_data_size = ABSOLUTE(. - _etext);
+
.image_end : { KEEP(*(.__image_end)) }
pbl_image_size = . - BASE;
diff --git a/arch/arm/lib64/armlinux.c b/arch/arm/lib64/armlinux.c
index 40fea37f53a7..4628c8ab5693 100644
--- a/arch/arm/lib64/armlinux.c
+++ b/arch/arm/lib64/armlinux.c
@@ -5,6 +5,7 @@
#include <memory.h>
#include <init.h>
#include <bootm.h>
+#include <efi/efi-mode.h>
static int do_bootm_linux(struct image_data *data)
{
@@ -89,6 +90,9 @@ static struct image_handler aarch64_barebox_handler = {
static int aarch64_register_image_handler(void)
{
+ if (efi_is_payload())
+ return 0;
+
register_image_handler(&aarch64_linux_efi_handler);
register_image_handler(&aarch64_linux_handler);
register_image_handler(&aarch64_barebox_handler);
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 8b00a674a688..5b4982455385 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -5,6 +5,7 @@ config X86
select HAS_KALLSYMS
select HAS_DMA
select GENERIC_FIND_NEXT_BIT
+ select HAVE_EFI_PAYLOAD
default y
config ARCH_TEXT_BASE
diff --git a/efi/Kconfig b/efi/Kconfig
index 971d58a7a9c0..35a57a3a42de 100644
--- a/efi/Kconfig
+++ b/efi/Kconfig
@@ -2,8 +2,12 @@
menu "EFI (Extensible Firmware Interface) Support"
-config EFI_PAYLOAD
+config HAVE_EFI_PAYLOAD
bool
+
+config EFI_PAYLOAD
+ bool "Build as EFI payload" if COMPILE_TEST
+ depends on HAVE_EFI_PAYLOAD
select EFI
select EFI_GUID
select EFI_DEVICEPATH
@@ -16,6 +20,13 @@ config EFI_PAYLOAD
config EFI
bool
+config HAVE_EFI_STUB
+ bool
+
+config EFI_STUB
+ def_bool EFI_PAYLOAD
+ depends on HAVE_EFI_STUB
+
config EFI_GUID
bool
help
diff --git a/efi/payload/Makefile b/efi/payload/Makefile
index 71305bee7006..a4a0332a8288 100644
--- a/efi/payload/Makefile
+++ b/efi/payload/Makefile
@@ -7,3 +7,5 @@ bbenv-y += env-efi
obj-$(CONFIG_CMD_IOMEM) += iomem.o
obj-pbl-$(CONFIG_EFI_PAYLOAD) += early-mem.o
obj-$(CONFIG_EFI_PAYLOAD) += entry-single.o
+pbl-$(CONFIG_EFI_STUB) += entry-multi.o
+obj-$(CONFIG_EFI_STUB) += boarddata.o
diff --git a/efi/payload/boarddata.c b/efi/payload/boarddata.c
new file mode 100644
index 000000000000..3260e31c7bf7
--- /dev/null
+++ b/efi/payload/boarddata.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define pr_fmt(fmt) "efi-boarddata: " fmt
+
+#ifdef CONFIG_DEBUG_INITCALLS
+#define DEBUG
+#endif
+
+#include <efi/efi-payload.h>
+#include <efi.h>
+#include <boarddata.h>
+#include <memory.h>
+#include <linux/kernel.h>
+#include <linux/printk.h>
+#include <debug_ll.h>
+#include <init.h>
+
+static int handle_efi_boarddata(void)
+{
+ const struct barebox_boarddata *bd = barebox_get_boarddata();
+ efi_status_t efiret;
+
+ if (!barebox_boarddata_is_machine(bd, BAREBOX_MACH_TYPE_EFI))
+ return 0;
+
+ barebox_add_memory_bank("ram0", mem_malloc_start(), mem_malloc_size());
+
+ efi_parent_image = bd->image;
+ efi_sys_table = bd->sys_table;
+ BS = efi_sys_table->boottime;
+ RT = efi_sys_table->runtime;
+
+ pr_debug("parent_image = %p, sys_table = %p\n",
+ efi_parent_image, efi_sys_table);
+
+ efiret = BS->open_protocol(efi_parent_image, &efi_loaded_image_protocol_guid,
+ (void **)&efi_loaded_image,
+ efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (!EFI_ERROR(efiret))
+ BS->handle_protocol(efi_loaded_image->device_handle,
+ &efi_device_path_protocol_guid, (void **)&efi_device_path);
+
+ return 0;
+}
+pure_initcall(handle_efi_boarddata);
diff --git a/efi/payload/entry-multi.c b/efi/payload/entry-multi.c
new file mode 100644
index 000000000000..f929ab01ec7b
--- /dev/null
+++ b/efi/payload/entry-multi.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/kernel.h>
+#include <linux/linkage.h>
+#include <linux/sizes.h>
+#include <boarddata.h>
+#include <stdio.h>
+#include <efi.h>
+#include <asm/common.h>
+#include <efi/efi-util.h>
+#include <efi/efi-payload.h>
+#include <pbl.h>
+
+static struct barebox_boarddata boarddata = {
+ .magic = BAREBOX_BOARDDATA_MAGIC,
+ .machine = BAREBOX_MACH_TYPE_EFI,
+};
+
+asmlinkage void __efistub_efi_pe_entry(void *image, struct efi_system_table *sys_table);
+
+static void efi_putc(void *ctx, int ch)
+{
+ struct efi_system_table *sys_table = ctx;
+ wchar_t ws[2] = { ch, L'\0' };
+
+ sys_table->con_out->output_string(sys_table->con_out, ws);
+}
+
+void __efistub_efi_pe_entry(void *image, struct efi_system_table *sys_table)
+{
+ size_t memsize;
+ efi_physical_addr_t mem;
+
+#ifdef DEBUG
+ sys_table->con_out->output_string(sys_table->con_out, L"\nbarebox\n");
+#endif
+ pbl_set_putc(efi_putc, sys_table);
+
+ boarddata.image = image;
+ boarddata.sys_table = sys_table;
+
+ mem = efi_earlymem_alloc(sys_table, &memsize);
+
+ barebox_pbl_entry(mem, memsize, &boarddata);
+}
diff --git a/include/pbl.h b/include/pbl.h
index 44957f59784e..0633e340bef3 100644
--- a/include/pbl.h
+++ b/include/pbl.h
@@ -15,6 +15,7 @@
#ifndef __ASSEMBLY__
#include <linux/types.h>
+#include <linux/compiler.h>
extern unsigned long free_mem_ptr;
extern unsigned long free_mem_end_ptr;
@@ -36,4 +37,7 @@ int pbl_barebox_verify(const void *compressed_start, unsigned int len,
const void *hash, unsigned int hash_len);
#endif
+void __noreturn barebox_pbl_entry(ulong, ulong, void *);
+
+
#endif /* __PBL_H__ */
diff --git a/test/self/mmu.c b/test/self/mmu.c
index dbe5004550a8..60bc9b38e84a 100644
--- a/test/self/mmu.c
+++ b/test/self/mmu.c
@@ -9,6 +9,7 @@
#include <abort.h>
#include <zero_page.h>
#include <linux/sizes.h>
+#include <efi/efi-mode.h>
#include <memory.h>
#define TEST_BUFFER_SIZE SZ_1M
@@ -258,6 +259,12 @@ static void test_zero_page(void)
static void test_mmu(void)
{
+ if (efi_is_payload()) {
+ pr_info("MMU was not initialized by us\n");
+ skipped_tests += 23;
+ return;
+ }
+
test_zero_page();
test_remap();
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 087/112] efi: devicepath: improve const safety
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (85 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 086/112] ARM64: add optional EFI stub Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 088/112] efi: refactor device_path_to_partuuid for code reuse Ahmad Fatoum
` (24 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The device path traversal functions don't modify the device path itself,
so reflect that in the function prototypes.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/devicepath.c | 140 ++++++++++++++++++++++++-----------------------
include/efi.h | 10 ++--
2 files changed, 76 insertions(+), 74 deletions(-)
diff --git a/efi/devicepath.c b/efi/devicepath.c
index 63b0ea61f0f9..6ec0c3780f37 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -49,7 +49,7 @@ char *cprintf(struct string *str, const char *fmt, ...)
#define DP_IS_END_SUBTYPE(a) ( ((a)->sub_type == END_ENTIRE_DEVICE_PATH_SUBTYPE )
#define device_path_type(a) ( ((a)->type) & EFI_DP_TYPE_MASK )
-#define next_device_path_node(a) ( (struct efi_device_path *) ( ((u8 *) (a)) + (a)->length))
+#define next_device_path_node(a) ( (const struct efi_device_path *) ( ((u8 *) (a)) + (a)->length))
#define is_device_path_end_type(a) ( device_path_type(a) == END_DEVICE_PATH_TYPE )
#define is_device_path_end_sub_type(a) ( (a)->sub_type == END_ENTIRE_DEVICE_PATH_SUBTYPE )
#define is_device_path_end(a) ( is_device_path_end_type(a) && is_device_path_end_sub_type(a) )
@@ -61,23 +61,23 @@ char *cprintf(struct string *str, const char *fmt, ...)
(a)->length = sizeof(struct efi_device_path); \
}
-struct efi_device_path end_device_path = {
+const struct efi_device_path end_device_path = {
.type = END_DEVICE_PATH_TYPE,
.sub_type = END_ENTIRE_DEVICE_PATH_SUBTYPE,
.length = END_DEVICE_PATH_LENGTH,
};
-struct efi_device_path end_instance_device_path = {
+const struct efi_device_path end_instance_device_path = {
.type = END_DEVICE_PATH_TYPE,
.sub_type = END_INSTANCE_DEVICE_PATH_SUBTYPE,
.length = END_DEVICE_PATH_LENGTH,
};
-struct efi_device_path *
+const struct efi_device_path *
device_path_from_handle(efi_handle_t Handle)
{
efi_status_t Status;
- struct efi_device_path *device_path;
+ const struct efi_device_path *device_path;
Status = BS->handle_protocol(Handle, &efi_device_path_protocol_guid,
(void *) &device_path);
@@ -132,27 +132,27 @@ unpack_device_path(const struct efi_device_path *dev_path)
}
static void
-dev_path_pci(struct string *str, void *dev_path)
+dev_path_pci(struct string *str, const void *dev_path)
{
- struct pci_device_path *Pci;
+ const struct pci_device_path *Pci;
Pci = dev_path;
cprintf(str, "Pci(0x%x,0x%x)", Pci->Device, Pci->Function);
}
static void
-dev_path_pccard(struct string *str, void *dev_path)
+dev_path_pccard(struct string *str, const void *dev_path)
{
- struct pccard_device_path *Pccard;
+ const struct pccard_device_path *Pccard;
Pccard = dev_path;
cprintf(str, "Pccard(0x%x)", Pccard->function_number);
}
static void
-dev_path_mem_map(struct string *str, void *dev_path)
+dev_path_mem_map(struct string *str, const void *dev_path)
{
- struct memmap_device_path *mem_map;
+ const struct memmap_device_path *mem_map;
mem_map = dev_path;
cprintf(str, "mem_map(%d,0x%llx,0x%llx)",
@@ -161,18 +161,18 @@ dev_path_mem_map(struct string *str, void *dev_path)
}
static void
-dev_path_controller(struct string *str, void *dev_path)
+dev_path_controller(struct string *str, const void *dev_path)
{
- struct controller_device_path *Controller;
+ const struct controller_device_path *Controller;
Controller = dev_path;
cprintf(str, "Ctrl(%d)", Controller->Controller);
}
static void
-dev_path_vendor(struct string *str, void *dev_path)
+dev_path_vendor(struct string *str, const void *dev_path)
{
- struct vendor_device_path *Vendor;
+ const struct vendor_device_path *Vendor;
char *type;
struct unknown_device_vendor_device_path *unknown_dev_path;
@@ -207,9 +207,9 @@ dev_path_vendor(struct string *str, void *dev_path)
type: 2 (ACPI Device Path) sub_type: 1 (ACPI Device Path)
*/
static void
-dev_path_acpi(struct string *str, void *dev_path)
+dev_path_acpi(struct string *str, const void *dev_path)
{
- struct acpi_hid_device_path *Acpi;
+ const struct acpi_hid_device_path *Acpi;
Acpi = dev_path;
if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
@@ -250,9 +250,9 @@ dev_path_acpi(struct string *str, void *dev_path)
}
static void
-dev_path_atapi(struct string *str, void *dev_path)
+dev_path_atapi(struct string *str, const void *dev_path)
{
- struct atapi_device_path *Atapi;
+ const struct atapi_device_path *Atapi;
Atapi = dev_path;
cprintf(str, "Ata(%s,%s)",
@@ -261,18 +261,18 @@ dev_path_atapi(struct string *str, void *dev_path)
}
static void
-dev_path_scsi(struct string *str, void *dev_path)
+dev_path_scsi(struct string *str, const void *dev_path)
{
- struct scsi_device_path *Scsi;
+ const struct scsi_device_path *Scsi;
Scsi = dev_path;
cprintf(str, "Scsi(%d,%d)", Scsi->Pun, Scsi->Lun);
}
static void
-dev_path_fibre(struct string *str, void *dev_path)
+dev_path_fibre(struct string *str, const void *dev_path)
{
- struct fibrechannel_device_path *Fibre;
+ const struct fibrechannel_device_path *Fibre;
Fibre = dev_path;
cprintf(str, "Fibre%s(0x%016llx,0x%016llx)",
@@ -281,36 +281,36 @@ dev_path_fibre(struct string *str, void *dev_path)
}
static void
-dev_path1394(struct string *str, void *dev_path)
+dev_path1394(struct string *str, const void *dev_path)
{
- struct f1394_device_path *F1394;
+ const struct f1394_device_path *F1394;
F1394 = dev_path;
cprintf(str, "1394(%pU)", &F1394->Guid);
}
static void
-dev_path_usb(struct string *str, void *dev_path)
+dev_path_usb(struct string *str, const void *dev_path)
{
- struct usb_device_path *Usb;
+ const struct usb_device_path *Usb;
Usb = dev_path;
cprintf(str, "Usb(0x%x,0x%x)", Usb->Port, Usb->Endpoint);
}
static void
-dev_path_i2_o(struct string *str, void *dev_path)
+dev_path_i2_o(struct string *str, const void *dev_path)
{
- struct i2_o_device_path *i2_o;
+ const struct i2_o_device_path *i2_o;
i2_o = dev_path;
cprintf(str, "i2_o(0x%X)", i2_o->Tid);
}
static void
-dev_path_mac_addr(struct string *str, void *dev_path)
+dev_path_mac_addr(struct string *str, const void *dev_path)
{
- struct mac_addr_device_path *MAC;
+ const struct mac_addr_device_path *MAC;
unsigned long hw_address_size;
unsigned long Index;
@@ -335,14 +335,14 @@ dev_path_mac_addr(struct string *str, void *dev_path)
}
static void
-cat_print_iPv4(struct string *str, struct efi_ipv4_address * address)
+cat_print_iPv4(struct string *str, const struct efi_ipv4_address * address)
{
cprintf(str, "%d.%d.%d.%d", address->Addr[0], address->Addr[1],
address->Addr[2], address->Addr[3]);
}
static bool
-is_not_null_iPv4(struct efi_ipv4_address * address)
+is_not_null_iPv4(const struct efi_ipv4_address * address)
{
u8 val;
@@ -364,9 +364,9 @@ cat_print_network_protocol(struct string *str, u16 Proto)
}
static void
-dev_path_iPv4(struct string *str, void *dev_path)
+dev_path_iPv4(struct string *str, const void *dev_path)
{
- struct ipv4_device_path *ip;
+ const struct ipv4_device_path *ip;
bool show;
ip = dev_path;
@@ -406,7 +406,7 @@ dev_path_iPv4(struct string *str, void *dev_path)
#define cat_print_iPv6_ADD( x , y ) ( ( (u16) ( x ) ) << 8 | ( y ) )
static void
-cat_print_ipv6(struct string *str, struct efi_ipv6_address * address)
+cat_print_ipv6(struct string *str, const struct efi_ipv6_address * address)
{
cprintf(str, "%x:%x:%x:%x:%x:%x:%x:%x",
cat_print_iPv6_ADD(address->Addr[0], address->Addr[1]),
@@ -420,9 +420,9 @@ cat_print_ipv6(struct string *str, struct efi_ipv6_address * address)
}
static void
-dev_path_iPv6(struct string *str, void *dev_path)
+dev_path_iPv6(struct string *str, const void *dev_path)
{
- struct ipv6_device_path *ip;
+ const struct ipv6_device_path *ip;
ip = dev_path;
cprintf(str, "IPv6(");
@@ -444,9 +444,9 @@ dev_path_iPv6(struct string *str, void *dev_path)
}
static void
-dev_path_infini_band(struct string *str, void *dev_path)
+dev_path_infini_band(struct string *str, const void *dev_path)
{
- struct infiniband_device_path *infini_band;
+ const struct infiniband_device_path *infini_band;
infini_band = dev_path;
cprintf(str, "Infiniband(0x%x,%pU,0x%llx,0x%llx,0x%llx)",
@@ -456,9 +456,9 @@ dev_path_infini_band(struct string *str, void *dev_path)
}
static void
-dev_path_uart(struct string *str, void *dev_path)
+dev_path_uart(struct string *str, const void *dev_path)
{
- struct uart_device_path *Uart;
+ const struct uart_device_path *Uart;
s8 Parity;
Uart = dev_path;
@@ -516,9 +516,9 @@ dev_path_uart(struct string *str, void *dev_path)
}
static void
-dev_path_sata(struct string *str, void *dev_path)
+dev_path_sata(struct string *str, const void *dev_path)
{
- struct sata_device_path *sata;
+ const struct sata_device_path *sata;
sata = dev_path;
cprintf(str, "Sata(0x%x,0x%x,0x%x)", sata->HBAPort_number,
@@ -526,9 +526,9 @@ dev_path_sata(struct string *str, void *dev_path)
}
static void
-dev_path_hard_drive(struct string *str, void *dev_path)
+dev_path_hard_drive(struct string *str, const void *dev_path)
{
- struct harddrive_device_path *hd;
+ const struct harddrive_device_path *hd;
hd = dev_path;
switch (hd->signature_type) {
@@ -551,18 +551,18 @@ dev_path_hard_drive(struct string *str, void *dev_path)
}
static void
-dev_path_cdrom(struct string *str, void *dev_path)
+dev_path_cdrom(struct string *str, const void *dev_path)
{
- struct cdrom_device_path *cd;
+ const struct cdrom_device_path *cd;
cd = dev_path;
cprintf(str, "CDROM(0x%x)", cd->boot_entry);
}
static void
-dev_path_file_path(struct string *str, void *dev_path)
+dev_path_file_path(struct string *str, const void *dev_path)
{
- struct filepath_device_path *Fp;
+ const struct filepath_device_path *Fp;
char *dst;
Fp = dev_path;
@@ -575,18 +575,18 @@ dev_path_file_path(struct string *str, void *dev_path)
}
static void
-dev_path_media_protocol(struct string *str, void *dev_path)
+dev_path_media_protocol(struct string *str, const void *dev_path)
{
- struct media_protocol_device_path *media_prot;
+ const struct media_protocol_device_path *media_prot;
media_prot = dev_path;
cprintf(str, "%pU", &media_prot->Protocol);
}
static void
-dev_path_bss_bss(struct string *str, void *dev_path)
+dev_path_bss_bss(struct string *str, const void *dev_path)
{
- struct bbs_bbs_device_path *Bss;
+ const struct bbs_bbs_device_path *Bss;
char *type;
Bss = dev_path;
@@ -618,7 +618,7 @@ dev_path_bss_bss(struct string *str, void *dev_path)
}
static void
-dev_path_end_instance(struct string *str, void *dev_path)
+dev_path_end_instance(struct string *str, const void *dev_path)
{
cprintf(str, ",");
}
@@ -629,10 +629,10 @@ dev_path_end_instance(struct string *str, void *dev_path)
*/
static void
-dev_path_node_unknown(struct string *str, void *dev_path)
+dev_path_node_unknown(struct string *str, const void *dev_path)
{
- struct efi_device_path *Path;
- u8 *value;
+ const struct efi_device_path *Path;
+ const u8 *value;
int length, index;
Path = dev_path;
value = dev_path;
@@ -684,7 +684,7 @@ dev_path_node_unknown(struct string *str, void *dev_path)
struct {
u8 type;
u8 sub_type;
- void (*Function) (struct string *, void *);
+ void (*Function) (struct string *, const void *);
} dev_path_table[] = {
{
HARDWARE_DEVICE_PATH, HW_PCI_DP, dev_path_pci}, {
@@ -717,10 +717,11 @@ struct {
0, 0, NULL}
};
-static int __device_path_to_str(struct string *str, struct efi_device_path *dev_path)
+static int __device_path_to_str(struct string *str,
+ const struct efi_device_path *dev_path)
{
- struct efi_device_path *dev_path_node;
- void (*dump_node) (struct string *, void *);
+ const struct efi_device_path *dev_path_node;
+ void (*dump_node) (struct string *, const void *);
int i;
dev_path = unpack_device_path(dev_path);
@@ -753,7 +754,7 @@ static int __device_path_to_str(struct string *str, struct efi_device_path *dev_
return 0;
}
-char *device_path_to_str(struct efi_device_path *dev_path)
+char *device_path_to_str(const struct efi_device_path *dev_path)
{
struct string str = {};
@@ -770,9 +771,9 @@ 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)
+u8 device_path_to_type(const struct efi_device_path *dev_path)
{
- struct efi_device_path *dev_path_next;
+ const struct efi_device_path *dev_path_next;
dev_path = unpack_device_path(dev_path);
dev_path_next = next_device_path_node(dev_path);
@@ -785,9 +786,9 @@ u8 device_path_to_type(struct efi_device_path *dev_path)
return device_path_type(dev_path);
}
-u8 device_path_to_subtype(struct efi_device_path *dev_path)
+u8 device_path_to_subtype(const struct efi_device_path *dev_path)
{
- struct efi_device_path *dev_path_next;
+ const struct efi_device_path *dev_path_next;
dev_path = unpack_device_path(dev_path);
dev_path_next = next_device_path_node(dev_path);
@@ -800,9 +801,10 @@ u8 device_path_to_subtype(struct efi_device_path *dev_path)
return dev_path->sub_type;
}
-char *device_path_to_partuuid(struct efi_device_path *dev_path)
+
+char *device_path_to_partuuid(const struct efi_device_path *dev_path)
{
- struct efi_device_path *dev_path_node;
+ const struct efi_device_path *dev_path_node;
struct harddrive_device_path *hd;
char *str = NULL;;
diff --git a/include/efi.h b/include/efi.h
index 80d2f784847b..6795dc414c3c 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -878,11 +878,11 @@ struct efi_simple_text_input_protocol {
struct efi_event *wait_for_key;
};
-struct efi_device_path *device_path_from_handle(efi_handle_t Handle);
-char *device_path_to_str(struct efi_device_path *dev_path);
-u8 device_path_to_type(struct efi_device_path *dev_path);
-u8 device_path_to_subtype(struct efi_device_path *dev_path);
-char *device_path_to_partuuid(struct efi_device_path *dev_path);
+const struct efi_device_path *device_path_from_handle(efi_handle_t handle);
+char *device_path_to_str(const struct efi_device_path *dev_path);
+u8 device_path_to_type(const struct efi_device_path *dev_path);
+u8 device_path_to_subtype(const struct efi_device_path *dev_path);
+char *device_path_to_partuuid(const struct efi_device_path *dev_path);
const char *efi_guid_string(efi_guid_t *g);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 088/112] efi: refactor device_path_to_partuuid for code reuse
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (86 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 087/112] efi: devicepath: improve const safety Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 089/112] efi: devicepath: implement device_path_to_str_buf variant Ahmad Fatoum
` (23 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Continuing walk of a device path until the next compatible node will
come in handy later as well, so factor that out into a new
device_path_next_compatible_node().
No functional change intended.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/devicepath.c | 41 ++++++++++++++++++++++++-----------------
1 file changed, 24 insertions(+), 17 deletions(-)
diff --git a/efi/devicepath.c b/efi/devicepath.c
index 6ec0c3780f37..d562bf482955 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -801,33 +801,40 @@ u8 device_path_to_subtype(const struct efi_device_path *dev_path)
return dev_path->sub_type;
}
+static const struct efi_device_path *
+device_path_next_compatible_node(const struct efi_device_path *dev_path,
+ u8 type, u8 subtype)
+{
+ for (; !is_device_path_end(dev_path);
+ dev_path = next_device_path_node(dev_path)) {
+
+ if (device_path_type(dev_path) != type)
+ continue;
+
+ if (dev_path->sub_type != subtype)
+ continue;
+
+ return dev_path;
+ }
+
+ return NULL;
+}
char *device_path_to_partuuid(const struct efi_device_path *dev_path)
{
- const struct efi_device_path *dev_path_node;
- struct harddrive_device_path *hd;
- char *str = NULL;;
-
dev_path = unpack_device_path(dev_path);
- for (dev_path_node = dev_path; !is_device_path_end(dev_path_node);
- dev_path_node = next_device_path_node(dev_path_node)) {
-
- if (device_path_type(dev_path_node) != MEDIA_DEVICE_PATH)
- continue;
-
- if (dev_path_node->sub_type != MEDIA_HARDDRIVE_DP)
- continue;
-
- hd = (struct harddrive_device_path *)dev_path_node;
+ while ((dev_path = device_path_next_compatible_node(dev_path,
+ MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP))) {
+ struct harddrive_device_path *hd =
+ (struct harddrive_device_path *)dev_path;
if (hd->signature_type != SIGNATURE_TYPE_GUID)
continue;
- str = xasprintf("%pUl", (efi_guid_t *)&(hd->signature[0]));
- break;
+ return xasprintf("%pUl", (efi_guid_t *)&(hd->signature[0]));
}
- return str;
+ return NULL;
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 089/112] efi: devicepath: implement device_path_to_str_buf variant
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (87 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 088/112] efi: refactor device_path_to_partuuid for code reuse Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 090/112] vsprintf: add %pD for printing EFI device path Ahmad Fatoum
` (22 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Existing device_path_to_str() formats a buffer once to determines the amount
of space necessary and then allocates it and formats it again.
To make this functionality available as printf format specifier, we need
a variant that doesn't allocate memory and that's preferably single
pass, which we add here.
No functional change for users of device_path_to_str().
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/devicepath.c | 71 +++++++++++++++++++++++++++++++++++-------------
include/efi.h | 1 +
2 files changed, 53 insertions(+), 19 deletions(-)
diff --git a/efi/devicepath.c b/efi/devicepath.c
index d562bf482955..0c2fc4d86927 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -6,11 +6,13 @@
#include <malloc.h>
#include <string.h>
#include <wchar.h>
+#include <linux/overflow.h>
#include <efi/device-path.h>
struct string {
char *str;
- int len;
+ unsigned allocated;
+ unsigned used;
};
char *cprintf(struct string *str, const char *fmt, ...)
@@ -18,17 +20,22 @@ char *cprintf(struct string *str, const char *fmt, ...)
char *cprintf(struct string *str, const char *fmt, ...)
{
+ void *buf = str->str;
+ unsigned bufsize = 0;
va_list args;
int len;
+ if (str->str) {
+ buf += str->used;
+ if (check_sub_overflow(str->allocated, str->used, &bufsize))
+ bufsize = 0;
+ }
+
va_start(args, fmt);
- if (str->str)
- len = vsprintf(str->str + str->len, fmt, args);
- else
- len = vsnprintf(NULL, 0, fmt, args);
+ len = vsnprintf(buf, bufsize, fmt, args);
va_end(args);
- str->len += len;
+ str->used += len;
return NULL;
}
@@ -717,8 +724,8 @@ struct {
0, 0, NULL}
};
-static int __device_path_to_str(struct string *str,
- const struct efi_device_path *dev_path)
+static void __device_path_to_str(struct string *str,
+ const struct efi_device_path *dev_path)
{
const struct efi_device_path *dev_path_node;
void (*dump_node) (struct string *, const void *);
@@ -743,32 +750,58 @@ static int __device_path_to_str(struct string *str,
if (!dump_node)
dump_node = dev_path_node_unknown;
- if (str->len && dump_node != dev_path_end_instance)
+ if (str->used && dump_node != dev_path_end_instance)
cprintf(str, "/");
dump_node(str, dev_path_node);
dev_path_node = next_device_path_node(dev_path_node);
}
-
- return 0;
}
+/**
+ * device_path_to_str_buf() - formats a device path into a preallocated buffer
+ *
+ * @dev_path: The EFI device path to format
+ * @buf: The buffer to format into or optionally NULL if @len is zero
+ * @len: The number of bytes that may be written into @buf
+ * Return: total number of bytes that are required to store the formatted
+ * result, excluding the terminating NUL byte, which is always
+ * written.
+ */
+size_t device_path_to_str_buf(const struct efi_device_path *dev_path,
+ char *buf, size_t len)
+{
+ struct string str = {
+ .str = buf,
+ .allocated = len,
+ };
+
+ __device_path_to_str(&str, dev_path);
+
+ return str.used;
+}
+
+/**
+ * device_path_to_str() - formats a device path into a newly allocated buffer
+ *
+ * @dev_path: The EFI device path to format
+ * Return: A pointer to the nul-terminated formatted device path.
+ */
char *device_path_to_str(const struct efi_device_path *dev_path)
{
- struct string str = {};
+ void *buf;
+ size_t size;
- __device_path_to_str(&str, dev_path);
+ size = device_path_to_str_buf(dev_path, NULL, 0);
- str.str = malloc(str.len + 1);
- if (!str.str)
+ buf = malloc(size + 1);
+ if (!buf)
return NULL;
- str.len = 0;
+ device_path_to_str_buf(dev_path, buf, size + 1);
- __device_path_to_str(&str, dev_path);
-
- return str.str;
+ return buf;
}
u8 device_path_to_type(const struct efi_device_path *dev_path)
diff --git a/include/efi.h b/include/efi.h
index 6795dc414c3c..45e4080fac08 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -880,6 +880,7 @@ struct efi_simple_text_input_protocol {
const struct efi_device_path *device_path_from_handle(efi_handle_t handle);
char *device_path_to_str(const struct efi_device_path *dev_path);
+size_t device_path_to_str_buf(const struct efi_device_path *dev_path, char buf[], size_t size);
u8 device_path_to_type(const struct efi_device_path *dev_path);
u8 device_path_to_subtype(const struct efi_device_path *dev_path);
char *device_path_to_partuuid(const struct efi_device_path *dev_path);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 090/112] vsprintf: add %pD for printing EFI device path
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (88 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 089/112] efi: devicepath: implement device_path_to_str_buf variant Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-08 9:01 ` Sascha Hauer
2024-01-03 18:12 ` [PATCH 091/112] lib: string: import Linux strreplace helper Ahmad Fatoum
` (21 subsequent siblings)
111 siblings, 1 reply; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We already have a few users that will want to print EFI device paths and
will gain quite a few more with incoming loader support, so let's allow
printing them directly with printf with the %pD format specifier.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
lib/vsprintf.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index ea092c06d3d6..e41a1abee652 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -20,6 +20,7 @@
#include <kallsyms.h>
#include <wchar.h>
#include <of.h>
+#include <efi.h>
#include <common.h>
#include <pbl.h>
@@ -348,6 +349,15 @@ char *uuid_string(char *buf, const char *end, const u8 *addr, int field_width,
return string(buf, end, uuid, field_width, precision, flags);
}
+static char *device_path_string(char *buf, const char *end, const struct efi_device_path *dp,
+ int field_width, int precision, int flags)
+{
+ if (!dp)
+ return string(buf, end, NULL, field_width, precision, flags);
+
+ return buf + device_path_to_str_buf(dp, buf, end - buf);
+}
+
static noinline_for_stack
char *hex_string(char *buf, const char *end, const u8 *addr, int field_width,
int precision, int flags, const char *fmt)
@@ -519,6 +529,10 @@ static char *pointer(const char *fmt, char *buf, const char *end, const void *pt
case 'J':
if (fmt[1] == 'P' && IS_ENABLED(CONFIG_JSMN))
return jsonpath_string(buf, end, ptr, field_width, precision, flags, fmt);
+ case 'D':
+ if (IS_ENABLED(CONFIG_EFI_DEVICEPATH))
+ return device_path_string(buf, end, ptr, field_width, precision, flags);
+ break;
}
return raw_pointer(buf, end, ptr, field_width, precision, flags);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 090/112] vsprintf: add %pD for printing EFI device path
2024-01-03 18:12 ` [PATCH 090/112] vsprintf: add %pD for printing EFI device path Ahmad Fatoum
@ 2024-01-08 9:01 ` Sascha Hauer
2024-03-04 17:26 ` Ahmad Fatoum
0 siblings, 1 reply; 134+ messages in thread
From: Sascha Hauer @ 2024-01-08 9:01 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Jan 03, 2024 at 07:12:50PM +0100, Ahmad Fatoum wrote:
> We already have a few users that will want to print EFI device paths and
> will gain quite a few more with incoming loader support, so let's allow
> printing them directly with printf with the %pD format specifier.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> lib/vsprintf.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index ea092c06d3d6..e41a1abee652 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -20,6 +20,7 @@
> #include <kallsyms.h>
> #include <wchar.h>
> #include <of.h>
> +#include <efi.h>
>
> #include <common.h>
> #include <pbl.h>
> @@ -348,6 +349,15 @@ char *uuid_string(char *buf, const char *end, const u8 *addr, int field_width,
> return string(buf, end, uuid, field_width, precision, flags);
> }
>
> +static char *device_path_string(char *buf, const char *end, const struct efi_device_path *dp,
> + int field_width, int precision, int flags)
> +{
> + if (!dp)
> + return string(buf, end, NULL, field_width, precision, flags);
> +
> + return buf + device_path_to_str_buf(dp, buf, end - buf);
> +}
> +
> static noinline_for_stack
> char *hex_string(char *buf, const char *end, const u8 *addr, int field_width,
> int precision, int flags, const char *fmt)
> @@ -519,6 +529,10 @@ static char *pointer(const char *fmt, char *buf, const char *end, const void *pt
> case 'J':
> if (fmt[1] == 'P' && IS_ENABLED(CONFIG_JSMN))
> return jsonpath_string(buf, end, ptr, field_width, precision, flags, fmt);
> + case 'D':
> + if (IS_ENABLED(CONFIG_EFI_DEVICEPATH))
> + return device_path_string(buf, end, ptr, field_width, precision, flags);
> + break;
Linux uses 'D' to print a filename from a struct file. This might become
useful for barebox as well, so we might better choose a different letter
here.
Otherwise I think it's ok to introduce barebox specific pointer types in
our printf implementation, even when they conflict with ones from the
kernel, but we should update the comment above this function accordingly
and clearly state when a letter is barebox specific.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* Re: [PATCH 090/112] vsprintf: add %pD for printing EFI device path
2024-01-08 9:01 ` Sascha Hauer
@ 2024-03-04 17:26 ` Ahmad Fatoum
0 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 17:26 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
Hello Sascha,
On 08.01.24 10:01, Sascha Hauer wrote:
> On Wed, Jan 03, 2024 at 07:12:50PM +0100, Ahmad Fatoum wrote:
>> We already have a few users that will want to print EFI device paths and
>> will gain quite a few more with incoming loader support, so let's allow
>> printing them directly with printf with the %pD format specifier.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> lib/vsprintf.c | 14 ++++++++++++++
>> 1 file changed, 14 insertions(+)
>>
>> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
>> index ea092c06d3d6..e41a1abee652 100644
>> --- a/lib/vsprintf.c
>> +++ b/lib/vsprintf.c
>> @@ -20,6 +20,7 @@
>> #include <kallsyms.h>
>> #include <wchar.h>
>> #include <of.h>
>> +#include <efi.h>
>>
>> #include <common.h>
>> #include <pbl.h>
>> @@ -348,6 +349,15 @@ char *uuid_string(char *buf, const char *end, const u8 *addr, int field_width,
>> return string(buf, end, uuid, field_width, precision, flags);
>> }
>>
>> +static char *device_path_string(char *buf, const char *end, const struct efi_device_path *dp,
>> + int field_width, int precision, int flags)
>> +{
>> + if (!dp)
>> + return string(buf, end, NULL, field_width, precision, flags);
>> +
>> + return buf + device_path_to_str_buf(dp, buf, end - buf);
>> +}
>> +
>> static noinline_for_stack
>> char *hex_string(char *buf, const char *end, const u8 *addr, int field_width,
>> int precision, int flags, const char *fmt)
>> @@ -519,6 +529,10 @@ static char *pointer(const char *fmt, char *buf, const char *end, const void *pt
>> case 'J':
>> if (fmt[1] == 'P' && IS_ENABLED(CONFIG_JSMN))
>> return jsonpath_string(buf, end, ptr, field_width, precision, flags, fmt);
>> + case 'D':
>> + if (IS_ENABLED(CONFIG_EFI_DEVICEPATH))
>> + return device_path_string(buf, end, ptr, field_width, precision, flags);
>> + break;
>
> Linux uses 'D' to print a filename from a struct file. This might become
> useful for barebox as well, so we might better choose a different letter
> here.
We can use 'd' along with f->f_path.dentry for that when we need to.
Another letter may conflict in future with something else that we want.
I would prefer to use 'D' as that's what U-Boot does and it avoids needless
churn for the UEFI code.
> Otherwise I think it's ok to introduce barebox specific pointer types in
> our printf implementation, even when they conflict with ones from the
> kernel, but we should update the comment above this function accordingly
> and clearly state when a letter is barebox specific.
I can do that.
Thanks,
Ahmad
>
> Sascha
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 091/112] lib: string: import Linux strreplace helper
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (89 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 090/112] vsprintf: add %pD for printing EFI device path Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 092/112] efi: payload: dynamically determine bootloader file name Ahmad Fatoum
` (20 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
This helper replaces all occurrences of a given character in a string.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/string.h | 1 +
lib/string.c | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/include/linux/string.h b/include/linux/string.h
index 32ce56939699..0d046f783280 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -115,6 +115,7 @@ extern char * skip_spaces(const char *);
extern char *strim(char *);
void *memchr_inv(const void *start, int c, size_t bytes);
+char *strreplace(char *str, char old, char new);
/**
* memzero_explicit - Fill a region of memory (e.g. sensitive
diff --git a/lib/string.c b/lib/string.c
index 695e50bc8fc1..374f326143a7 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -1028,3 +1028,24 @@ char *strjoin(const char *separator, char **arr, size_t arrlen)
return buf;
}
EXPORT_SYMBOL(strjoin);
+
+/**
+ * strreplace - Replace all occurrences of character in string.
+ * @str: The string to operate on.
+ * @old: The character being replaced.
+ * @new: The character @old is replaced with.
+ *
+ * Replaces the each @old character with a @new one in the given string @str.
+ *
+ * Return: pointer to the string @str itself.
+ */
+char *strreplace(char *str, char old, char new)
+{
+ char *s = str;
+
+ for (; *s; ++s)
+ if (*s == old)
+ *s = new;
+ return str;
+}
+EXPORT_SYMBOL(strreplace);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 092/112] efi: payload: dynamically determine bootloader file name
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (90 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 091/112] lib: string: import Linux strreplace helper Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 093/112] efi: payload: iomem: register later Ahmad Fatoum
` (19 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
\EFI\BOOT\BOOTx64.EFI is only the default file path for x86_64. It's
different for other architectures and even for x86_64, the EFI loader
may be configured to execute a differently named file.
Fix this by querying the EFI loader for the file name instead of
hardcoding it and while at it, we add debug prints for the loaded image
and its parent to make it easier to debug in future.
On the off chance, that the EFI firmware doesn't inform us of a file
name this way, we revert back to a hardcoded value, that is
architecture-dependent.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/Kconfig | 10 ++++++++++
efi/devicepath.c | 39 +++++++++++++++++++++++++++++++++------
efi/payload/init.c | 23 ++++++++++++++++++-----
include/efi.h | 1 +
4 files changed, 62 insertions(+), 11 deletions(-)
diff --git a/efi/Kconfig b/efi/Kconfig
index 35a57a3a42de..3bda02600c94 100644
--- a/efi/Kconfig
+++ b/efi/Kconfig
@@ -35,4 +35,14 @@ config EFI_GUID
config EFI_DEVICEPATH
bool
+config EFI_PAYLOAD_DEFAULT_PATH
+ string
+ default "EFI/BOOT/BOOTARM.EFI" if CPU_32
+ default "EFI/BOOT/BOOTAA64.EFI" if CPU_64
+ default "EFI/BOOT/BOOTIA32.EFI" if X86_32
+ default "EFI/BOOT/BOOTx64.EFI" if X86_64
+ default "EFI/BOOT/BOOTRISCV32.EFI" if ARCH_RV32I
+ default "EFI/BOOT/BOOTRISCV64.EFI" if ARCH_RV64I
+ default "EFI/BOOT/BAREBOX.EFI"
+
endmenu
diff --git a/efi/devicepath.c b/efi/devicepath.c
index 0c2fc4d86927..98aba6289e18 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -83,15 +83,23 @@ const struct efi_device_path end_instance_device_path = {
const struct efi_device_path *
device_path_from_handle(efi_handle_t Handle)
{
+ const efi_guid_t *const protocols[] = {
+ &efi_loaded_image_device_path_guid,
+ &efi_device_path_protocol_guid,
+ NULL
+ };
+ const efi_guid_t * const*proto;
efi_status_t Status;
- const struct efi_device_path *device_path;
- Status = BS->handle_protocol(Handle, &efi_device_path_protocol_guid,
- (void *) &device_path);
- if (EFI_ERROR(Status))
- device_path = NULL;
+ for (proto = protocols; *proto; proto++) {
+ const struct efi_device_path *device_path;
- return device_path;
+ Status = BS->handle_protocol(Handle, *proto, (void *) &device_path);
+ if (!EFI_ERROR(Status) && device_path)
+ return device_path;
+ }
+
+ return NULL;
}
static struct efi_device_path *
@@ -871,3 +879,22 @@ char *device_path_to_partuuid(const struct efi_device_path *dev_path)
return NULL;
}
+char *device_path_to_filepath(const struct efi_device_path *dev_path)
+{
+ struct filepath_device_path *fp = NULL;
+ char *path;
+
+ dev_path = unpack_device_path(dev_path);
+
+ while ((dev_path = device_path_next_compatible_node(dev_path,
+ MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP))) {
+ fp = container_of(dev_path, struct filepath_device_path, header);
+ dev_path = next_device_path_node(&fp->header);
+ }
+
+ path = strdup_wchar_to_char(fp->path_name);
+ if (!path)
+ return NULL;
+
+ return strreplace(path, '\\', '/');
+}
diff --git a/efi/payload/init.c b/efi/payload/init.c
index 6c790c680602..354120b11a86 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -299,7 +299,10 @@ core_efi_initcall(efi_core_init);
static int efi_postcore_init(void)
{
- char *uuid;
+ const struct efi_device_path *parent_image_dp, *loaded_image_dp;
+ char *bbu_path = "/boot/" CONFIG_EFI_PAYLOAD_DEFAULT_PATH;
+
+ char *filepath, *uuid;
static const uint64_t loader_features =
EFI_LOADER_FEATURE_DEVICETREE;
@@ -321,8 +324,10 @@ static int efi_postcore_init(void)
efi_set_variable_uint64_le("LoaderFeatures", &efi_systemd_vendor_guid,
loader_features);
- uuid = device_path_to_partuuid(device_path_from_handle(
- efi_loaded_image->device_handle));
+ loaded_image_dp = device_path_from_handle(efi_loaded_image->device_handle);
+ pr_debug("loaded-image: %pD\n", loaded_image_dp);
+
+ uuid = device_path_to_partuuid(loaded_image_dp);
if (uuid) {
wchar_t *uuid16 = xstrdup_char_to_wchar(uuid);
efi_set_variable("LoaderDevicePartUUID",
@@ -334,8 +339,16 @@ static int efi_postcore_init(void)
free(uuid16);
}
- bbu_register_std_file_update("fat", 0, "/boot/EFI/BOOT/BOOTx64.EFI",
- filetype_exe);
+ parent_image_dp = device_path_from_handle(efi_parent_image);
+ pr_debug("parent-image: %pD\n", parent_image_dp);
+
+ filepath = device_path_to_filepath(parent_image_dp);
+ if (filepath) {
+ bbu_path = basprintf("/boot/%s", filepath);
+ free(filepath);
+ }
+
+ bbu_register_std_file_update("fat", 0, bbu_path, filetype_exe);
return 0;
}
diff --git a/include/efi.h b/include/efi.h
index 45e4080fac08..6bb5f8cb0a30 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -884,6 +884,7 @@ size_t device_path_to_str_buf(const struct efi_device_path *dev_path, char buf[]
u8 device_path_to_type(const struct efi_device_path *dev_path);
u8 device_path_to_subtype(const struct efi_device_path *dev_path);
char *device_path_to_partuuid(const struct efi_device_path *dev_path);
+char *device_path_to_filepath(const struct efi_device_path *dev_path);
const char *efi_guid_string(efi_guid_t *g);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 093/112] efi: payload: iomem: register later
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (91 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 092/112] efi: payload: dynamically determine bootloader file name Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 094/112] efi: payload: protect against buggy EFI implementations Ahmad Fatoum
` (18 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
efi_barebox_populate_mmap() will silently skip reserving areas that are
already reserved. Yet, because it's called so early, it will prevent
finer grained reservation for barebox internal areas. Move the initcall
later to fix this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/iomem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/efi/payload/iomem.c b/efi/payload/iomem.c
index d4390c856769..832f6db72b76 100644
--- a/efi/payload/iomem.c
+++ b/efi/payload/iomem.c
@@ -176,4 +176,4 @@ static int efi_barebox_populate_mmap(void)
free(mmap_buf);
return ret;
}
-mem_efi_initcall(efi_barebox_populate_mmap);
+device_efi_initcall(efi_barebox_populate_mmap);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 094/112] efi: payload: protect against buggy EFI implementations
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (92 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 093/112] efi: payload: iomem: register later Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 095/112] efi: payload: don't require efi_loaded_image->parent_handle for bootsource detection Ahmad Fatoum
` (17 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
barebox' EFI loaded image handle should have a device path, but on the
off-case that it doesn't, we should just return an error code instead of
dereferencing a null pointer.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/init.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/efi/payload/init.c b/efi/payload/init.c
index 354120b11a86..b312866cb1f6 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -327,6 +327,9 @@ static int efi_postcore_init(void)
loaded_image_dp = device_path_from_handle(efi_loaded_image->device_handle);
pr_debug("loaded-image: %pD\n", loaded_image_dp);
+ if (!loaded_image_dp)
+ return -EINVAL;
+
uuid = device_path_to_partuuid(loaded_image_dp);
if (uuid) {
wchar_t *uuid16 = xstrdup_char_to_wchar(uuid);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 095/112] efi: payload: don't require efi_loaded_image->parent_handle for bootsource detection
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (93 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 094/112] efi: payload: protect against buggy EFI implementations Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 096/112] commands: add cpuinfo -s option for stacktrace Ahmad Fatoum
` (16 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Enrico Jorns, Ahmad Fatoum
This fixes bootsource detection running barebox as EFI payload under
EDK2 2020.11.
Fixes: 443eb41376d9 ("efi: add bootsource detection")
Cc: Enrico Jorns <ejo@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/efi/efi-device.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 3a16deab5f6b..857f1b8c097e 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -404,9 +404,6 @@ static void efi_set_bootsource(void)
efi_handle_t efi_parent;
- if (!efi_loaded_image->parent_handle)
- goto out;
-
efi_parent = efi_find_parent(efi_loaded_image->device_handle);
if (!efi_parent)
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 096/112] commands: add cpuinfo -s option for stacktrace
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (94 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 095/112] efi: payload: don't require efi_loaded_image->parent_handle for bootsource detection Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 097/112] efi: devicepath: align MemoryMapped name with spec Ahmad Fatoum
` (15 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
While a call to dump_stack() is easily hacked into the code, it can be
useful during development to just print the stacktrace from the shell,
e.g. to verify that kallsyms sharing for EFI works as intended.
Add an option to cpuinfo to provide this functionality.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/cpu/cpuinfo.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/cpuinfo.c b/arch/arm/cpu/cpuinfo.c
index aea50e80d194..2d3fe2ac8d0c 100644
--- a/arch/arm/cpu/cpuinfo.c
+++ b/arch/arm/cpu/cpuinfo.c
@@ -4,6 +4,7 @@
/* cpuinfo.c - Show information about cp15 registers */
#include <common.h>
+#include <getopt.h>
#include <command.h>
#include <complete.h>
#include <asm/system.h>
@@ -49,9 +50,23 @@ static int do_cpuinfo(int argc, char *argv[])
{
unsigned long mainid, cache, cr;
char *architecture, *implementer;
- int i;
+ int opt, i;
int cpu_arch;
+ while ((opt = getopt(argc, argv, "s")) > 0) {
+ switch (opt) {
+ case 's':
+ if (!IS_ENABLED(CONFIG_ARCH_HAS_STACK_DUMP))
+ return -ENOSYS;
+
+ printf("SP: 0x%08lx\n", get_sp());
+ dump_stack();
+ return 0;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
#ifdef CONFIG_CPU_64v8
__asm__ __volatile__(
"mrs %0, midr_el1\n"
@@ -255,10 +270,16 @@ static int do_cpuinfo(int argc, char *argv[])
return 0;
}
+BAREBOX_CMD_HELP_START(cpuinfo)
+BAREBOX_CMD_HELP_TEXT("Shows misc info about CPU")
+BAREBOX_CMD_HELP_OPT ("-s", "print call stack info (if supported)")
+BAREBOX_CMD_HELP_END
+
BAREBOX_CMD_START(cpuinfo)
.cmd = do_cpuinfo,
BAREBOX_CMD_DESC("show info about CPU")
+ BAREBOX_CMD_OPTS("[-s]")
BAREBOX_CMD_GROUP(CMD_GRP_INFO)
BAREBOX_CMD_COMPLETE(empty_complete)
+ BAREBOX_CMD_HELP(cmd_cpuinfo_help)
BAREBOX_CMD_END
-
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 097/112] efi: devicepath: align MemoryMapped name with spec
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (95 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 096/112] commands: add cpuinfo -s option for stacktrace Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 098/112] efi: devicepath: pretty print BBS BEV DeviceType Ahmad Fatoum
` (14 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The strings are currently only for barebox-internal consumption, but we
may in future expose them over the EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, so
we should start using the naming that's in the specification.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/devicepath.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/efi/devicepath.c b/efi/devicepath.c
index 98aba6289e18..dfedeb6239ac 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -170,7 +170,7 @@ dev_path_mem_map(struct string *str, const void *dev_path)
const struct memmap_device_path *mem_map;
mem_map = dev_path;
- cprintf(str, "mem_map(%d,0x%llx,0x%llx)",
+ cprintf(str, "MemoryMapped(0x%x,0x%llx,0x%llx)",
mem_map->memory_type,
mem_map->starting_address, mem_map->ending_address);
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 098/112] efi: devicepath: pretty print BBS BEV DeviceType
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (96 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 097/112] efi: devicepath: align MemoryMapped name with spec Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:12 ` [PATCH 099/112] efi: devicepath: format GUIDs as little endian Ahmad Fatoum
` (13 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
BBS paths can have multiple types, one of them is the device type, which
we will start abusing in a later commit, so make sure it's
translated to a readable string.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/devicepath.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/efi/devicepath.c b/efi/devicepath.c
index dfedeb6239ac..53387d8bd127 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -624,6 +624,9 @@ dev_path_bss_bss(struct string *str, const void *dev_path)
case BBS_TYPE_EMBEDDED_NETWORK:
type = "Net";
break;
+ case BBS_TYPE_DEV:
+ type = "Dev";
+ break;
default:
type = "?";
break;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 099/112] efi: devicepath: format GUIDs as little endian
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (97 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 098/112] efi: devicepath: pretty print BBS BEV DeviceType Ahmad Fatoum
@ 2024-01-03 18:12 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 100/112] efi: devicepath: move END device node definitions into header Ahmad Fatoum
` (12 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The default for %pU is to format as big endian, which isn't the correct
representation for EFI GUIDs, which are little endian.
Fix the format specifier to avoid the confusion.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/devicepath.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/efi/devicepath.c b/efi/devicepath.c
index 53387d8bd127..d3a0204bd380 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -207,7 +207,7 @@ dev_path_vendor(struct string *str, const void *dev_path)
break;
}
- cprintf(str, "Ven%s(%pU", type, &Vendor->Guid);
+ cprintf(str, "Ven%s(%pUl", type, &Vendor->Guid);
if (efi_guidcmp(Vendor->Guid, efi_unknown_device_guid) == 0) {
/* GUID used by EFI to enumerate an EDD 1.1 device */
unknown_dev_path =
@@ -301,7 +301,7 @@ dev_path1394(struct string *str, const void *dev_path)
const struct f1394_device_path *F1394;
F1394 = dev_path;
- cprintf(str, "1394(%pU)", &F1394->Guid);
+ cprintf(str, "1394(%pUl)", &F1394->Guid);
}
static void
@@ -464,7 +464,7 @@ dev_path_infini_band(struct string *str, const void *dev_path)
const struct infiniband_device_path *infini_band;
infini_band = dev_path;
- cprintf(str, "Infiniband(0x%x,%pU,0x%llx,0x%llx,0x%llx)",
+ cprintf(str, "Infiniband(0x%x,%pUl,0x%llx,0x%llx,0x%llx)",
infini_band->resource_flags, &infini_band->port_gid,
infini_band->service_id, infini_band->target_port_id,
infini_band->device_id);
@@ -553,10 +553,7 @@ dev_path_hard_drive(struct string *str, const void *dev_path)
);
break;
case SIGNATURE_TYPE_GUID:
- cprintf(str, "HD(Part%d,Sig%pU)",
- hd->partition_number,
- (efi_guid_t *) & (hd->signature[0])
- );
+ cprintf(str, "HD(Part%d,Sig%pUl)", hd->partition_number, (guid_t *)hd->signature);
break;
default:
cprintf(str, "HD(Part%d,mbr_type=%02x,sig_type=%02x)",
@@ -595,7 +592,7 @@ dev_path_media_protocol(struct string *str, const void *dev_path)
const struct media_protocol_device_path *media_prot;
media_prot = dev_path;
- cprintf(str, "%pU", &media_prot->Protocol);
+ cprintf(str, "%pUl", &media_prot->Protocol);
}
static void
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 100/112] efi: devicepath: move END device node definitions into header
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (98 preceding siblings ...)
2024-01-03 18:12 ` [PATCH 099/112] efi: devicepath: format GUIDs as little endian Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 101/112] efi: devicepath: drop underscores in hex constants Ahmad Fatoum
` (11 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
While at it, drop DP_IS_END_TYPE and DP_IS_END_SUBTYPE, which are
unused.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/devicepath.c | 12 ------------
include/efi/device-path.h | 10 ++++++++++
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/efi/devicepath.c b/efi/devicepath.c
index d3a0204bd380..12a94fdb6ef8 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -43,18 +43,6 @@ char *cprintf(struct string *str, const char *fmt, ...)
#define MIN_ALIGNMENT_SIZE 8 /* FIXME: X86_64 specific */
#define ALIGN_SIZE(a) ((a % MIN_ALIGNMENT_SIZE) ? MIN_ALIGNMENT_SIZE - (a % MIN_ALIGNMENT_SIZE) : 0)
-#define EFI_DP_TYPE_MASK 0x7f
-#define EFI_DP_TYPE_UNPACKED 0x80
-
-#define END_DEVICE_PATH_TYPE 0x7f
-
-#define END_ENTIRE_DEVICE_PATH_SUBTYPE 0xff
-#define END_INSTANCE_DEVICE_PATH_SUBTYPE 0x01
-#define END_DEVICE_PATH_LENGTH (sizeof(struct efi_device_path))
-
-#define DP_IS_END_TYPE(a)
-#define DP_IS_END_SUBTYPE(a) ( ((a)->sub_type == END_ENTIRE_DEVICE_PATH_SUBTYPE )
-
#define device_path_type(a) ( ((a)->type) & EFI_DP_TYPE_MASK )
#define next_device_path_node(a) ( (const struct efi_device_path *) ( ((u8 *) (a)) + (a)->length))
#define is_device_path_end_type(a) ( device_path_type(a) == END_DEVICE_PATH_TYPE )
diff --git a/include/efi/device-path.h b/include/efi/device-path.h
index 4b97cadde4f1..b7dc518859ac 100644
--- a/include/efi/device-path.h
+++ b/include/efi/device-path.h
@@ -387,4 +387,14 @@ struct bbs_bbs_device_path {
#define BBS_TYPE_DEV 0x80
#define BBS_TYPE_UNKNOWN 0x_fF
+
+#define EFI_DP_TYPE_MASK 0x7f
+#define EFI_DP_TYPE_UNPACKED 0x80
+
+#define END_DEVICE_PATH_TYPE 0x7f
+
+#define END_ENTIRE_DEVICE_PATH_SUBTYPE 0xff
+#define END_INSTANCE_DEVICE_PATH_SUBTYPE 0x01
+#define END_DEVICE_PATH_LENGTH (sizeof(struct efi_device_path))
+
#endif /* __EFI_DEVICE_PATH_H */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 101/112] efi: devicepath: drop underscores in hex constants
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (99 preceding siblings ...)
2024-01-03 18:13 ` [PATCH 100/112] efi: devicepath: move END device node definitions into header Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 102/112] efi: devicepath: namespace definitions Ahmad Fatoum
` (10 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The macros couldn't be used before as they would fail to parse, but we
will start using BBS_TYPE_UNKNOWN.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/efi/device-path.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/efi/device-path.h b/include/efi/device-path.h
index b7dc518859ac..91c8ce57c69c 100644
--- a/include/efi/device-path.h
+++ b/include/efi/device-path.h
@@ -177,7 +177,7 @@ struct device_logical_unit_device_path {
u8 Lun; /* Logical Unit Number */
};
-#define MSG_USB_CLASS_DP 0x0_f
+#define MSG_USB_CLASS_DP 0x0f
struct usb_class_device_path {
struct efi_device_path header;
u16 vendor_id;
@@ -385,7 +385,7 @@ struct bbs_bbs_device_path {
#define BBS_TYPE_USB 0x05
#define BBS_TYPE_EMBEDDED_NETWORK 0x06
#define BBS_TYPE_DEV 0x80
-#define BBS_TYPE_UNKNOWN 0x_fF
+#define BBS_TYPE_UNKNOWN 0xff
#define EFI_DP_TYPE_MASK 0x7f
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 102/112] efi: devicepath: namespace definitions
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (100 preceding siblings ...)
2024-01-03 18:13 ` [PATCH 101/112] efi: devicepath: drop underscores in hex constants Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 103/112] efi: devicepath: use flexible array members for trailing strings Ahmad Fatoum
` (9 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Using a DEVICE_PATH_ prefix everywhere will make it clear what the
definitions is about and in part align us with the naming in U-Boot.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/efi/efi-device.c | 5 +-
efi/devicepath.c | 164 +++++++++++++++++++-------------------
include/efi/device-path.h | 162 ++++++++++++++++++-------------------
3 files changed, 166 insertions(+), 165 deletions(-)
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 857f1b8c097e..bbc76e9ef769 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -192,10 +192,11 @@ static int efi_register_device(struct efi_device *efidev)
* of the main MAC messaging device. Don't register these in barebox as
* they would show up as duplicate ethernet devices.
*/
- if (device_path_to_type(efidev->devpath) == MESSAGING_DEVICE_PATH) {
+ if (device_path_to_type(efidev->devpath) == DEVICE_PATH_TYPE_MESSAGING_DEVICE) {
u8 subtype = device_path_to_subtype(efidev->devpath);
- if (subtype == MSG_IPv4_DP || subtype == MSG_IPv6_DP)
+ if (subtype == DEVICE_PATH_SUB_TYPE_MSG_IPv4 ||
+ subtype == DEVICE_PATH_SUB_TYPE_MSG_IPv6)
return -EINVAL;
}
diff --git a/efi/devicepath.c b/efi/devicepath.c
index 12a94fdb6ef8..229810d49bbc 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -43,29 +43,29 @@ char *cprintf(struct string *str, const char *fmt, ...)
#define MIN_ALIGNMENT_SIZE 8 /* FIXME: X86_64 specific */
#define ALIGN_SIZE(a) ((a % MIN_ALIGNMENT_SIZE) ? MIN_ALIGNMENT_SIZE - (a % MIN_ALIGNMENT_SIZE) : 0)
-#define device_path_type(a) ( ((a)->type) & EFI_DP_TYPE_MASK )
+#define device_path_type(a) ( ((a)->type) & DEVICE_PATH_TYPE_MASK )
#define next_device_path_node(a) ( (const struct efi_device_path *) ( ((u8 *) (a)) + (a)->length))
-#define is_device_path_end_type(a) ( device_path_type(a) == END_DEVICE_PATH_TYPE )
-#define is_device_path_end_sub_type(a) ( (a)->sub_type == END_ENTIRE_DEVICE_PATH_SUBTYPE )
+#define is_device_path_end_type(a) ( device_path_type(a) == DEVICE_PATH_TYPE_END )
+#define is_device_path_end_sub_type(a) ( (a)->sub_type == DEVICE_PATH_SUB_TYPE_END )
#define is_device_path_end(a) ( is_device_path_end_type(a) && is_device_path_end_sub_type(a) )
-#define is_device_path_unpacked(a) ( (a)->type & EFI_DP_TYPE_UNPACKED )
+#define is_device_path_unpacked(a) ( (a)->type & DEVICE_PATH_TYPE_UNPACKED )
#define set_device_path_end_node(a) { \
- (a)->type = END_DEVICE_PATH_TYPE; \
- (a)->sub_type = END_ENTIRE_DEVICE_PATH_SUBTYPE; \
+ (a)->type = DEVICE_PATH_TYPE_END; \
+ (a)->sub_type = DEVICE_PATH_SUB_TYPE_END; \
(a)->length = sizeof(struct efi_device_path); \
}
const struct efi_device_path end_device_path = {
- .type = END_DEVICE_PATH_TYPE,
- .sub_type = END_ENTIRE_DEVICE_PATH_SUBTYPE,
- .length = END_DEVICE_PATH_LENGTH,
+ .type = DEVICE_PATH_TYPE_END,
+ .sub_type = DEVICE_PATH_SUB_TYPE_END,
+ .length = DEVICE_PATH_END_LENGTH,
};
const struct efi_device_path end_instance_device_path = {
- .type = END_DEVICE_PATH_TYPE,
- .sub_type = END_INSTANCE_DEVICE_PATH_SUBTYPE,
- .length = END_DEVICE_PATH_LENGTH,
+ .type = DEVICE_PATH_TYPE_END,
+ .sub_type = DEVICE_PATH_SUB_TYPE_INSTANCE_END,
+ .length = DEVICE_PATH_END_LENGTH,
};
const struct efi_device_path *
@@ -121,7 +121,7 @@ unpack_device_path(const struct efi_device_path *dev_path)
memcpy(Dest, Src, Size);
Size += ALIGN_SIZE(Size);
Dest->length = Size;
- Dest->type |= EFI_DP_TYPE_UNPACKED;
+ Dest->type |= DEVICE_PATH_TYPE_UNPACKED;
Dest =
(struct efi_device_path *) (((u8 *) Dest) + Size);
@@ -137,7 +137,7 @@ unpack_device_path(const struct efi_device_path *dev_path)
static void
dev_path_pci(struct string *str, const void *dev_path)
{
- const struct pci_device_path *Pci;
+ const struct efi_device_path_pci *Pci;
Pci = dev_path;
cprintf(str, "Pci(0x%x,0x%x)", Pci->Device, Pci->Function);
@@ -146,7 +146,7 @@ dev_path_pci(struct string *str, const void *dev_path)
static void
dev_path_pccard(struct string *str, const void *dev_path)
{
- const struct pccard_device_path *Pccard;
+ const struct efi_device_path_pccard *Pccard;
Pccard = dev_path;
cprintf(str, "Pccard(0x%x)", Pccard->function_number);
@@ -155,7 +155,7 @@ dev_path_pccard(struct string *str, const void *dev_path)
static void
dev_path_mem_map(struct string *str, const void *dev_path)
{
- const struct memmap_device_path *mem_map;
+ const struct efi_device_path_memory *mem_map;
mem_map = dev_path;
cprintf(str, "MemoryMapped(0x%x,0x%llx,0x%llx)",
@@ -166,7 +166,7 @@ dev_path_mem_map(struct string *str, const void *dev_path)
static void
dev_path_controller(struct string *str, const void *dev_path)
{
- const struct controller_device_path *Controller;
+ const struct efi_device_path_controller *Controller;
Controller = dev_path;
cprintf(str, "Ctrl(%d)", Controller->Controller);
@@ -175,19 +175,19 @@ dev_path_controller(struct string *str, const void *dev_path)
static void
dev_path_vendor(struct string *str, const void *dev_path)
{
- const struct vendor_device_path *Vendor;
+ const struct efi_device_path_vendor *Vendor;
char *type;
- struct unknown_device_vendor_device_path *unknown_dev_path;
+ struct efi_device_path_unknown_device_vendor *unknown_dev_path;
Vendor = dev_path;
switch (device_path_type(&Vendor->header)) {
- case HARDWARE_DEVICE_PATH:
+ case DEVICE_PATH_TYPE_HARDWARE_DEVICE:
type = "Hw";
break;
- case MESSAGING_DEVICE_PATH:
+ case DEVICE_PATH_TYPE_MESSAGING_DEVICE:
type = "Msg";
break;
- case MEDIA_DEVICE_PATH:
+ case DEVICE_PATH_TYPE_MEDIA_DEVICE:
type = "Media";
break;
default:
@@ -199,7 +199,7 @@ dev_path_vendor(struct string *str, const void *dev_path)
if (efi_guidcmp(Vendor->Guid, efi_unknown_device_guid) == 0) {
/* GUID used by EFI to enumerate an EDD 1.1 device */
unknown_dev_path =
- (struct unknown_device_vendor_device_path *) Vendor;
+ (struct efi_device_path_unknown_device_vendor *) Vendor;
cprintf(str, ":%02x)", unknown_dev_path->legacy_drive_letter);
} else {
cprintf(str, ")");
@@ -212,7 +212,7 @@ dev_path_vendor(struct string *str, const void *dev_path)
static void
dev_path_acpi(struct string *str, const void *dev_path)
{
- const struct acpi_hid_device_path *Acpi;
+ const struct efi_device_path_acpi_hid *Acpi;
Acpi = dev_path;
if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
@@ -255,7 +255,7 @@ dev_path_acpi(struct string *str, const void *dev_path)
static void
dev_path_atapi(struct string *str, const void *dev_path)
{
- const struct atapi_device_path *Atapi;
+ const struct efi_device_path_atapi *Atapi;
Atapi = dev_path;
cprintf(str, "Ata(%s,%s)",
@@ -266,7 +266,7 @@ dev_path_atapi(struct string *str, const void *dev_path)
static void
dev_path_scsi(struct string *str, const void *dev_path)
{
- const struct scsi_device_path *Scsi;
+ const struct efi_device_path_scsi *Scsi;
Scsi = dev_path;
cprintf(str, "Scsi(%d,%d)", Scsi->Pun, Scsi->Lun);
@@ -275,18 +275,18 @@ dev_path_scsi(struct string *str, const void *dev_path)
static void
dev_path_fibre(struct string *str, const void *dev_path)
{
- const struct fibrechannel_device_path *Fibre;
+ const struct efi_device_path_fibrechannel *Fibre;
Fibre = dev_path;
cprintf(str, "Fibre%s(0x%016llx,0x%016llx)",
device_path_type(&Fibre->header) ==
- MSG_FIBRECHANNEL_DP ? "" : "Ex", Fibre->WWN, Fibre->Lun);
+ DEVICE_PATH_SUB_TYPE_MSG_FIBRECHANNEL ? "" : "Ex", Fibre->WWN, Fibre->Lun);
}
static void
dev_path1394(struct string *str, const void *dev_path)
{
- const struct f1394_device_path *F1394;
+ const struct efi_device_path_f1394 *F1394;
F1394 = dev_path;
cprintf(str, "1394(%pUl)", &F1394->Guid);
@@ -295,7 +295,7 @@ dev_path1394(struct string *str, const void *dev_path)
static void
dev_path_usb(struct string *str, const void *dev_path)
{
- const struct usb_device_path *Usb;
+ const struct efi_device_path_usb *Usb;
Usb = dev_path;
cprintf(str, "Usb(0x%x,0x%x)", Usb->Port, Usb->Endpoint);
@@ -304,7 +304,7 @@ dev_path_usb(struct string *str, const void *dev_path)
static void
dev_path_i2_o(struct string *str, const void *dev_path)
{
- const struct i2_o_device_path *i2_o;
+ const struct efi_device_path_i2_o *i2_o;
i2_o = dev_path;
cprintf(str, "i2_o(0x%X)", i2_o->Tid);
@@ -313,7 +313,7 @@ dev_path_i2_o(struct string *str, const void *dev_path)
static void
dev_path_mac_addr(struct string *str, const void *dev_path)
{
- const struct mac_addr_device_path *MAC;
+ const struct efi_device_path_mac_addr *MAC;
unsigned long hw_address_size;
unsigned long Index;
@@ -369,7 +369,7 @@ cat_print_network_protocol(struct string *str, u16 Proto)
static void
dev_path_iPv4(struct string *str, const void *dev_path)
{
- const struct ipv4_device_path *ip;
+ const struct efi_device_path_ipv4 *ip;
bool show;
ip = dev_path;
@@ -381,7 +381,7 @@ dev_path_iPv4(struct string *str, const void *dev_path)
show = is_not_null_iPv4(&ip->local_ip_address);
if (!show
&& ip->header.length ==
- sizeof (struct ipv4_device_path)) {
+ sizeof (struct efi_device_path_ipv4)) {
/* only version 2 includes gateway and netmask */
show |= is_not_null_iPv4(&ip->gateway_ip_address);
show |= is_not_null_iPv4(&ip->subnet_mask);
@@ -390,7 +390,7 @@ dev_path_iPv4(struct string *str, const void *dev_path)
cprintf(str, ",");
cat_print_iPv4(str, &ip->local_ip_address);
if (ip->header.length ==
- sizeof (struct ipv4_device_path)) {
+ sizeof (struct efi_device_path_ipv4)) {
/* only version 2 includes gateway and netmask */
show = is_not_null_iPv4(&ip->gateway_ip_address);
show |= is_not_null_iPv4(&ip->subnet_mask);
@@ -425,7 +425,7 @@ cat_print_ipv6(struct string *str, const struct efi_ipv6_address * address)
static void
dev_path_iPv6(struct string *str, const void *dev_path)
{
- const struct ipv6_device_path *ip;
+ const struct efi_device_path_ipv6 *ip;
ip = dev_path;
cprintf(str, "IPv6(");
@@ -437,7 +437,7 @@ dev_path_iPv6(struct string *str, const void *dev_path)
"stateful_auto_configure") : "Static");
cat_print_ipv6(str, &ip->local_ip_address);
if (ip->header.length ==
- sizeof (struct ipv6_device_path)) {
+ sizeof (struct efi_device_path_ipv6)) {
cprintf(str, ",");
cat_print_ipv6(str, &ip->gateway_ip_address);
cprintf(str, ",");
@@ -449,7 +449,7 @@ dev_path_iPv6(struct string *str, const void *dev_path)
static void
dev_path_infini_band(struct string *str, const void *dev_path)
{
- const struct infiniband_device_path *infini_band;
+ const struct efi_device_path_infiniband *infini_band;
infini_band = dev_path;
cprintf(str, "Infiniband(0x%x,%pUl,0x%llx,0x%llx,0x%llx)",
@@ -461,7 +461,7 @@ dev_path_infini_band(struct string *str, const void *dev_path)
static void
dev_path_uart(struct string *str, const void *dev_path)
{
- const struct uart_device_path *Uart;
+ const struct efi_device_path_uart *Uart;
s8 Parity;
Uart = dev_path;
@@ -521,7 +521,7 @@ dev_path_uart(struct string *str, const void *dev_path)
static void
dev_path_sata(struct string *str, const void *dev_path)
{
- const struct sata_device_path *sata;
+ const struct efi_device_path_sata *sata;
sata = dev_path;
cprintf(str, "Sata(0x%x,0x%x,0x%x)", sata->HBAPort_number,
@@ -531,7 +531,7 @@ dev_path_sata(struct string *str, const void *dev_path)
static void
dev_path_hard_drive(struct string *str, const void *dev_path)
{
- const struct harddrive_device_path *hd;
+ const struct efi_device_path_hard_drive_path *hd;
hd = dev_path;
switch (hd->signature_type) {
@@ -553,7 +553,7 @@ dev_path_hard_drive(struct string *str, const void *dev_path)
static void
dev_path_cdrom(struct string *str, const void *dev_path)
{
- const struct cdrom_device_path *cd;
+ const struct efi_device_path_cdrom_path *cd;
cd = dev_path;
cprintf(str, "CDROM(0x%x)", cd->boot_entry);
@@ -562,7 +562,7 @@ dev_path_cdrom(struct string *str, const void *dev_path)
static void
dev_path_file_path(struct string *str, const void *dev_path)
{
- const struct filepath_device_path *Fp;
+ const struct efi_device_path_file_path *Fp;
char *dst;
Fp = dev_path;
@@ -577,7 +577,7 @@ dev_path_file_path(struct string *str, const void *dev_path)
static void
dev_path_media_protocol(struct string *str, const void *dev_path)
{
- const struct media_protocol_device_path *media_prot;
+ const struct efi_device_path_media_protocol *media_prot;
media_prot = dev_path;
cprintf(str, "%pUl", &media_prot->Protocol);
@@ -586,7 +586,7 @@ dev_path_media_protocol(struct string *str, const void *dev_path)
static void
dev_path_bss_bss(struct string *str, const void *dev_path)
{
- const struct bbs_bbs_device_path *Bss;
+ const struct efi_device_path_bbs_bbs *Bss;
char *type;
Bss = dev_path;
@@ -641,26 +641,26 @@ dev_path_node_unknown(struct string *str, const void *dev_path)
value = dev_path;
value += 4;
switch (Path->type) {
- case HARDWARE_DEVICE_PATH:{
+ case DEVICE_PATH_TYPE_HARDWARE_DEVICE:{
/* Unknown Hardware Device Path */
cprintf(str, "hardware_path(%d", Path->sub_type);
break;
}
- case ACPI_DEVICE_PATH:{/* Unknown ACPI Device Path */
+ case DEVICE_PATH_TYPE_ACPI_DEVICE:{/* Unknown ACPI Device Path */
cprintf(str, "acpi_path(%d", Path->sub_type);
break;
}
- case MESSAGING_DEVICE_PATH:{
+ case DEVICE_PATH_TYPE_MESSAGING_DEVICE:{
/* Unknown Messaging Device Path */
cprintf(str, "Msg(%d", Path->sub_type);
break;
}
- case MEDIA_DEVICE_PATH:{
+ case DEVICE_PATH_TYPE_MEDIA_DEVICE:{
/* Unknown Media Device Path */
cprintf(str, "media_path(%d", Path->sub_type);
break;
}
- case BBS_DEVICE_PATH:{ /* Unknown BIOS Boot Specification Device Path */
+ case DEVICE_PATH_TYPE_BBS_DEVICE:{ /* Unknown BIOS Boot Specification Device Path */
cprintf(str, "bbs_path(%d", Path->sub_type);
break;
}
@@ -690,32 +690,32 @@ struct {
void (*Function) (struct string *, const void *);
} dev_path_table[] = {
{
- HARDWARE_DEVICE_PATH, HW_PCI_DP, dev_path_pci}, {
- HARDWARE_DEVICE_PATH, HW_PCCARD_DP, dev_path_pccard}, {
- HARDWARE_DEVICE_PATH, HW_MEMMAP_DP, dev_path_mem_map}, {
- HARDWARE_DEVICE_PATH, HW_VENDOR_DP, dev_path_vendor}, {
- HARDWARE_DEVICE_PATH, HW_CONTROLLER_DP, dev_path_controller}, {
- ACPI_DEVICE_PATH, ACPI_DP, dev_path_acpi}, {
- MESSAGING_DEVICE_PATH, MSG_ATAPI_DP, dev_path_atapi}, {
- MESSAGING_DEVICE_PATH, MSG_SCSI_DP, dev_path_scsi}, {
- MESSAGING_DEVICE_PATH, MSG_FIBRECHANNEL_DP, dev_path_fibre}, {
- MESSAGING_DEVICE_PATH, MSG_1394_DP, dev_path1394}, {
- MESSAGING_DEVICE_PATH, MSG_USB_DP, dev_path_usb}, {
- MESSAGING_DEVICE_PATH, MSG_I2_o_DP, dev_path_i2_o}, {
- MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, dev_path_mac_addr}, {
- MESSAGING_DEVICE_PATH, MSG_IPv4_DP, dev_path_iPv4}, {
- MESSAGING_DEVICE_PATH, MSG_IPv6_DP, dev_path_iPv6}, {
- MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP, dev_path_infini_band}, {
- MESSAGING_DEVICE_PATH, MSG_UART_DP, dev_path_uart}, {
- MESSAGING_DEVICE_PATH, MSG_SATA_DP, dev_path_sata}, {
- MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, dev_path_vendor}, {
- MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, dev_path_hard_drive}, {
- MEDIA_DEVICE_PATH, MEDIA_CDROM_DP, dev_path_cdrom}, {
- MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, dev_path_vendor}, {
- MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, dev_path_file_path}, {
- MEDIA_DEVICE_PATH, MEDIA_PROTOCOL_DP, dev_path_media_protocol}, {
- BBS_DEVICE_PATH, BBS_BBS_DP, dev_path_bss_bss}, {
- END_DEVICE_PATH_TYPE, END_INSTANCE_DEVICE_PATH_SUBTYPE,
+ DEVICE_PATH_TYPE_HARDWARE_DEVICE, DEVICE_PATH_SUB_TYPE_PCI, dev_path_pci}, {
+ DEVICE_PATH_TYPE_HARDWARE_DEVICE, DEVICE_PATH_SUB_TYPE_PCCARD, dev_path_pccard}, {
+ DEVICE_PATH_TYPE_HARDWARE_DEVICE, DEVICE_PATH_SUB_TYPE_MEMORY, dev_path_mem_map}, {
+ DEVICE_PATH_TYPE_HARDWARE_DEVICE, DEVICE_PATH_SUB_TYPE_VENDOR, dev_path_vendor}, {
+ DEVICE_PATH_TYPE_HARDWARE_DEVICE, DEVICE_PATH_SUB_TYPE_CONTROLLER, dev_path_controller}, {
+ DEVICE_PATH_TYPE_ACPI_DEVICE, DEVICE_PATH_SUB_TYPE_ACPI_DEVICE, dev_path_acpi}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_ATAPI, dev_path_atapi}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_SCSI, dev_path_scsi}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_FIBRECHANNEL, dev_path_fibre}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_1394, dev_path1394}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_USB, dev_path_usb}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_I2_o, dev_path_i2_o}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR, dev_path_mac_addr}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_IPv4, dev_path_iPv4}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_IPv6, dev_path_iPv6}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_INFINIBAND, dev_path_infini_band}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_UART, dev_path_uart}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_SATA, dev_path_sata}, {
+ DEVICE_PATH_TYPE_MESSAGING_DEVICE, DEVICE_PATH_SUB_TYPE_MSG_VENDOR, dev_path_vendor}, {
+ DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH, dev_path_hard_drive}, {
+ DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_CDROM_PATH, dev_path_cdrom}, {
+ DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_VENDOR_PATH, dev_path_vendor}, {
+ DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_FILE_PATH, dev_path_file_path}, {
+ DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_MEDIA_PROTOCOL, dev_path_media_protocol}, {
+ DEVICE_PATH_TYPE_BBS_DEVICE, DEVICE_PATH_SUB_TYPE_BBS_BBS, dev_path_bss_bss}, {
+ DEVICE_PATH_TYPE_END, DEVICE_PATH_SUB_TYPE_INSTANCE_END,
dev_path_end_instance}, {
0, 0, NULL}
};
@@ -854,9 +854,9 @@ char *device_path_to_partuuid(const struct efi_device_path *dev_path)
dev_path = unpack_device_path(dev_path);
while ((dev_path = device_path_next_compatible_node(dev_path,
- MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP))) {
- struct harddrive_device_path *hd =
- (struct harddrive_device_path *)dev_path;
+ DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH))) {
+ struct efi_device_path_hard_drive_path *hd =
+ (struct efi_device_path_hard_drive_path *)dev_path;
if (hd->signature_type != SIGNATURE_TYPE_GUID)
continue;
@@ -869,14 +869,14 @@ char *device_path_to_partuuid(const struct efi_device_path *dev_path)
char *device_path_to_filepath(const struct efi_device_path *dev_path)
{
- struct filepath_device_path *fp = NULL;
+ struct efi_device_path_file_path *fp = NULL;
char *path;
dev_path = unpack_device_path(dev_path);
while ((dev_path = device_path_next_compatible_node(dev_path,
- MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP))) {
- fp = container_of(dev_path, struct filepath_device_path, header);
+ DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_FILE_PATH))) {
+ fp = container_of(dev_path, struct efi_device_path_file_path, header);
dev_path = next_device_path_node(&fp->header);
}
diff --git a/include/efi/device-path.h b/include/efi/device-path.h
index 91c8ce57c69c..8d64ac4900ac 100644
--- a/include/efi/device-path.h
+++ b/include/efi/device-path.h
@@ -7,42 +7,42 @@
* Hardware Device Path (UEFI 2.4 specification, version 2.4 § 9.3.2.)
*/
-#define HARDWARE_DEVICE_PATH 0x01
+#define DEVICE_PATH_TYPE_HARDWARE_DEVICE 0x01
-#define HW_PCI_DP 0x01
-struct pci_device_path {
+#define DEVICE_PATH_SUB_TYPE_PCI 0x01
+struct efi_device_path_pci {
struct efi_device_path header;
u8 Function;
u8 Device;
};
-#define HW_PCCARD_DP 0x02
-struct pccard_device_path {
+#define DEVICE_PATH_SUB_TYPE_PCCARD 0x02
+struct efi_device_path_pccard {
struct efi_device_path header;
u8 function_number;
};
-#define HW_MEMMAP_DP 0x03
-struct memmap_device_path {
+#define DEVICE_PATH_SUB_TYPE_MEMORY 0x03
+struct efi_device_path_memory {
struct efi_device_path header;
u32 memory_type;
efi_physical_addr_t starting_address;
efi_physical_addr_t ending_address;
};
-#define HW_VENDOR_DP 0x04
-struct vendor_device_path {
+#define DEVICE_PATH_SUB_TYPE_VENDOR 0x04
+struct efi_device_path_vendor {
struct efi_device_path header;
efi_guid_t Guid;
};
-struct unknown_device_vendor_device_path {
- struct vendor_device_path device_path;
+struct efi_device_path_unknown_device_vendor {
+ struct efi_device_path_vendor device_path;
u8 legacy_drive_letter;
};
-#define HW_CONTROLLER_DP 0x05
-struct controller_device_path {
+#define DEVICE_PATH_SUB_TYPE_CONTROLLER 0x05
+struct efi_device_path_controller {
struct efi_device_path header;
u32 Controller;
};
@@ -50,17 +50,17 @@ struct controller_device_path {
/*
* ACPI Device Path (UEFI 2.4 specification, version 2.4 § 9.3.3 and 9.3.4.)
*/
-#define ACPI_DEVICE_PATH 0x02
+#define DEVICE_PATH_TYPE_ACPI_DEVICE 0x02
-#define ACPI_DP 0x01
-struct acpi_hid_device_path {
+#define DEVICE_PATH_SUB_TYPE_ACPI_DEVICE 0x01
+struct efi_device_path_acpi_hid {
struct efi_device_path header;
u32 HID;
u32 UID;
};
-#define EXPANDED_ACPI_DP 0x02
-struct expanded_acpi_hid_device_path {
+#define DEVICE_PATH_SUB_TYPE_EXPANDED_ACPI_DEVICE 0x02
+struct efi_device_path_expanded_acpi {
struct efi_device_path header;
u32 HID;
u32 UID;
@@ -68,8 +68,8 @@ struct expanded_acpi_hid_device_path {
u8 hid_str[1];
};
-#define ACPI_ADR_DP 3
-struct acpi_adr_device_path {
+#define DEVICE_PATH_SUB_TYPE_ACPI_ADR_DEVICE 3
+struct efi_device_path_acpi_adr {
struct efi_device_path header;
u32 ADR;
};
@@ -91,25 +91,25 @@ struct acpi_adr_device_path {
/*
* Messaging Device Path (UEFI 2.4 specification, version 2.4 § 9.3.5.)
*/
-#define MESSAGING_DEVICE_PATH 0x03
+#define DEVICE_PATH_TYPE_MESSAGING_DEVICE 0x03
-#define MSG_ATAPI_DP 0x01
-struct atapi_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_ATAPI 0x01
+struct efi_device_path_atapi {
struct efi_device_path header;
u8 primary_secondary;
u8 slave_master;
u16 Lun;
};
-#define MSG_SCSI_DP 0x02
-struct scsi_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_SCSI 0x02
+struct efi_device_path_scsi {
struct efi_device_path header;
u16 Pun;
u16 Lun;
};
-#define MSG_FIBRECHANNEL_DP 0x03
-struct fibrechannel_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_FIBRECHANNEL 0x03
+struct efi_device_path_fibrechannel {
struct efi_device_path header;
u32 Reserved;
u64 WWN;
@@ -120,23 +120,23 @@ struct fibrechannel_device_path {
* Fibre Channel Ex sub_type.
* UEFI 2.0 specification version 2.4 § 9.3.5.6.
*/
-#define MSG_FIBRECHANNELEX_DP 21
-struct fibrechannelex_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_FIBRECHANNEL_EX 21
+struct efi_device_path_fibrechannelex {
struct efi_device_path header;
u32 Reserved;
u8 WWN[8]; /* World Wide Name */
u8 Lun[8]; /* Logical unit, T-10 SCSI Architecture Model 4 specification */
};
-#define MSG_1394_DP 0x04
-struct f1394_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_1394 0x04
+struct efi_device_path_f1394 {
struct efi_device_path header;
u32 Reserved;
u64 Guid;
};
-#define MSG_USB_DP 0x05
-struct usb_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_USB 0x05
+struct efi_device_path_usb {
struct efi_device_path header;
u8 Port;
u8 Endpoint;
@@ -146,8 +146,8 @@ struct usb_device_path {
* SATA Device Path sub_type.
* UEFI 2.0 specification version 2.4 § 9.3.5.6.
*/
-#define MSG_SATA_DP 18
-struct sata_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_SATA 18
+struct efi_device_path_sata {
struct efi_device_path header;
u16 HBAPort_number;
u16 port_multiplier_port_number;
@@ -158,8 +158,8 @@ struct sata_device_path {
* USB WWID Device Path sub_type.
* UEFI 2.0 specification version 2.4 § 9.3.5.7.
*/
-#define MSG_USB_WWID_DP 16
-struct usb_wwid_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_USB_WWID 16
+struct efi_device_path_usb_wwid {
struct efi_device_path header;
u16 interface_number;
u16 vendor_id;
@@ -171,14 +171,14 @@ struct usb_wwid_device_path {
* Device Logical Unit sub_type.
* UEFI 2.0 specification version 2.4 § 9.3.5.8.
*/
-#define MSG_DEVICE_LOGICAL_UNIT_DP 17
-struct device_logical_unit_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_DEVICE_LOGICAL_UNIT 17
+struct efi_device_path_logical_unit {
struct efi_device_path header;
u8 Lun; /* Logical Unit Number */
};
-#define MSG_USB_CLASS_DP 0x0f
-struct usb_class_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS 0x0f
+struct efi_device_path_usb_class {
struct efi_device_path header;
u16 vendor_id;
u16 product_id;
@@ -187,21 +187,21 @@ struct usb_class_device_path {
u8 device_protocol;
};
-#define MSG_I2_o_DP 0x06
-struct i2_o_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_I2_o 0x06
+struct efi_device_path_i2_o {
struct efi_device_path header;
u32 Tid;
};
-#define MSG_MAC_ADDR_DP 0x0b
-struct mac_addr_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR 0x0b
+struct efi_device_path_mac_addr {
struct efi_device_path header;
struct efi_mac_address mac_address;
u8 if_type;
};
-#define MSG_IPv4_DP 0x0c
-struct ipv4_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_IPv4 0x0c
+struct efi_device_path_ipv4 {
struct efi_device_path header;
struct efi_ipv4_address local_ip_address;
struct efi_ipv4_address remote_ip_address;
@@ -214,8 +214,8 @@ struct ipv4_device_path {
struct efi_ipv4_address subnet_mask;
};
-#define MSG_IPv6_DP 0x0d
-struct ipv6_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_IPv6 0x0d
+struct efi_device_path_ipv6 {
struct efi_device_path header;
struct efi_ipv6_address local_ip_address;
struct efi_ipv6_address remote_ip_address;
@@ -232,14 +232,14 @@ struct ipv6_device_path {
* Device Logical Unit sub_type.
* UEFI 2.0 specification version 2.4 § 9.3.5.8.
*/
-#define MSG_VLAN_DP 20
-struct vlan_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_VLAN 20
+struct efi_device_path_vlan {
struct efi_device_path header;
u16 vlan_id;
};
-#define MSG_INFINIBAND_DP 0x09
-struct infiniband_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_INFINIBAND 0x09
+struct efi_device_path_infiniband {
struct efi_device_path header;
u32 resource_flags;
efi_guid_t port_gid;
@@ -248,8 +248,8 @@ struct infiniband_device_path {
u64 device_id;
};
-#define MSG_UART_DP 0x0e
-struct uart_device_path {
+#define DEVICE_PATH_SUB_TYPE_MSG_UART 0x0e
+struct efi_device_path_uart {
struct efi_device_path header;
u32 Reserved;
u64 baud_rate;
@@ -258,7 +258,7 @@ struct uart_device_path {
u8 stop_bits;
};
-#define MSG_VENDOR_DP 0x0a
+#define DEVICE_PATH_SUB_TYPE_MSG_VENDOR 0x0a
/* Use VENDOR_DEVICE_PATH struct */
#define DEVICE_PATH_MESSAGING_PC_ANSI \
@@ -288,10 +288,10 @@ struct uart_device_path {
/*
* Media Device Path (UEFI 2.4 specification, version 2.4 § 9.3.6.)
*/
-#define MEDIA_DEVICE_PATH 0x04
+#define DEVICE_PATH_TYPE_MEDIA_DEVICE 0x04
-#define MEDIA_HARDDRIVE_DP 0x01
-struct harddrive_device_path {
+#define DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH 0x01
+struct efi_device_path_hard_drive_path {
struct efi_device_path header;
u32 partition_number;
u64 partition_start;
@@ -307,27 +307,27 @@ struct harddrive_device_path {
#define SIGNATURE_TYPE_MBR 0x01
#define SIGNATURE_TYPE_GUID 0x02
-#define MEDIA_CDROM_DP 0x02
-struct cdrom_device_path {
+#define DEVICE_PATH_SUB_TYPE_CDROM_PATH 0x02
+struct efi_device_path_cdrom_path {
struct efi_device_path header;
u32 boot_entry;
u64 partition_start;
u64 partition_size;
};
-#define MEDIA_VENDOR_DP 0x03
+#define DEVICE_PATH_SUB_TYPE_VENDOR_PATH 0x03
/* Use VENDOR_DEVICE_PATH struct */
-#define MEDIA_FILEPATH_DP 0x04
-struct filepath_device_path {
+#define DEVICE_PATH_SUB_TYPE_FILE_PATH 0x04
+struct efi_device_path_file_path {
struct efi_device_path header;
s16 path_name[1];
};
#define SIZE_OF_FILEPATH_DEVICE_PATH offsetof(FILEPATH_DEVICE_PATH,path_name)
-#define MEDIA_PROTOCOL_DP 0x05
-struct media_protocol_device_path {
+#define DEVICE_PATH_SUB_TYPE_MEDIA_PROTOCOL 0x05
+struct efi_device_path_media_protocol {
struct efi_device_path header;
efi_guid_t Protocol;
};
@@ -336,8 +336,8 @@ struct media_protocol_device_path {
* PIWG Firmware File sub_type.
* UEFI 2.0 specification version 2.4 § 9.3.6.6.
*/
-#define MEDIA_PIWG_FW_FILE_DP 6
-struct media_fw_vol_filepath_device_path {
+#define DEVICE_PATH_SUB_TYPE_PIWG_FW_FILE 6
+struct efi_device_path_media_fw_vol_file_path {
struct efi_device_path header;
efi_guid_t fv_file_name;
};
@@ -346,8 +346,8 @@ struct media_fw_vol_filepath_device_path {
* PIWG Firmware Volume Device Path sub_type.
* UEFI 2.0 specification version 2.4 § 9.3.6.7.
*/
-#define MEDIA_PIWG_FW_VOL_DP 7
-struct media_fw_vol_device_path {
+#define DEVICE_PATH_SUB_TYPE_PIWG_FW_VOL 7
+struct efi_device_media_piwg_fw_vol {
struct efi_device_path header;
efi_guid_t fv_name;
};
@@ -356,8 +356,8 @@ struct media_fw_vol_device_path {
* Media relative offset range device path.
* UEFI 2.0 specification version 2.4 § 9.3.6.8.
*/
-#define MEDIA_RELATIVE_OFFSET_RANGE_DP 8
-struct media_relative_offset_range_device_path {
+#define DEVICE_PATH_SUB_TYPE_MEDIA_RELATIVE_OFFSET_RANGE 8
+struct efi_device_media_relative_offset_range {
struct efi_device_path header;
u32 Reserved;
u64 starting_offset;
@@ -367,10 +367,10 @@ struct media_relative_offset_range_device_path {
/*
* BIOS Boot Specification Device Path (UEFI 2.4 specification, version 2.4 § 9.3.7.)
*/
-#define BBS_DEVICE_PATH 0x05
+#define DEVICE_PATH_TYPE_BBS_DEVICE 0x05
-#define BBS_BBS_DP 0x01
-struct bbs_bbs_device_path {
+#define DEVICE_PATH_SUB_TYPE_BBS_BBS 0x01
+struct efi_device_path_bbs_bbs {
struct efi_device_path header;
u16 device_type;
u16 status_flag;
@@ -388,13 +388,13 @@ struct bbs_bbs_device_path {
#define BBS_TYPE_UNKNOWN 0xff
-#define EFI_DP_TYPE_MASK 0x7f
-#define EFI_DP_TYPE_UNPACKED 0x80
+#define DEVICE_PATH_TYPE_MASK 0x7f
+#define DEVICE_PATH_TYPE_UNPACKED 0x80
-#define END_DEVICE_PATH_TYPE 0x7f
+#define DEVICE_PATH_TYPE_END 0x7f
-#define END_ENTIRE_DEVICE_PATH_SUBTYPE 0xff
-#define END_INSTANCE_DEVICE_PATH_SUBTYPE 0x01
-#define END_DEVICE_PATH_LENGTH (sizeof(struct efi_device_path))
+#define DEVICE_PATH_SUB_TYPE_END 0xff
+#define DEVICE_PATH_SUB_TYPE_INSTANCE_END 0x01
+#define DEVICE_PATH_END_LENGTH (sizeof(struct efi_device_path))
#endif /* __EFI_DEVICE_PATH_H */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 103/112] efi: devicepath: use flexible array members for trailing strings
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (101 preceding siblings ...)
2024-01-03 18:13 ` [PATCH 102/112] efi: devicepath: namespace definitions Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 104/112] efi: devicepath: drop unused macro Ahmad Fatoum
` (8 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
When we start using fortified string operations in the future, we will
need to replace zero and one sized trailing arrays with flexible arrays
where required everywhere, but for now let's just avoid having any in
the EFI code.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/efi/device-path.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/efi/device-path.h b/include/efi/device-path.h
index 8d64ac4900ac..433233f38c0d 100644
--- a/include/efi/device-path.h
+++ b/include/efi/device-path.h
@@ -65,7 +65,7 @@ struct efi_device_path_expanded_acpi {
u32 HID;
u32 UID;
u32 CID;
- u8 hid_str[1];
+ u8 hid_str[];
};
#define DEVICE_PATH_SUB_TYPE_ACPI_ADR_DEVICE 3
@@ -164,7 +164,7 @@ struct efi_device_path_usb_wwid {
u16 interface_number;
u16 vendor_id;
u16 product_id;
- s16 serial_number[1]; /* UTF-16 characters of the USB serial number */
+ s16 serial_number[]; /* UTF-16 characters of the USB serial number */
};
/**
@@ -321,7 +321,7 @@ struct efi_device_path_cdrom_path {
#define DEVICE_PATH_SUB_TYPE_FILE_PATH 0x04
struct efi_device_path_file_path {
struct efi_device_path header;
- s16 path_name[1];
+ s16 path_name[];
};
#define SIZE_OF_FILEPATH_DEVICE_PATH offsetof(FILEPATH_DEVICE_PATH,path_name)
@@ -374,7 +374,7 @@ struct efi_device_path_bbs_bbs {
struct efi_device_path header;
u16 device_type;
u16 status_flag;
- s8 String[1];
+ s8 String[];
};
/* device_type definitions - from BBS specification */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 104/112] efi: devicepath: drop unused macro
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (102 preceding siblings ...)
2024-01-03 18:13 ` [PATCH 103/112] efi: devicepath: use flexible array members for trailing strings Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 105/112] efi: devicepath: let compiler worry about unaligned unpacking Ahmad Fatoum
` (7 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
This is used no where, so it can just be dropped.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/efi/device-path.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/include/efi/device-path.h b/include/efi/device-path.h
index 433233f38c0d..39221ca369de 100644
--- a/include/efi/device-path.h
+++ b/include/efi/device-path.h
@@ -324,8 +324,6 @@ struct efi_device_path_file_path {
s16 path_name[];
};
-#define SIZE_OF_FILEPATH_DEVICE_PATH offsetof(FILEPATH_DEVICE_PATH,path_name)
-
#define DEVICE_PATH_SUB_TYPE_MEDIA_PROTOCOL 0x05
struct efi_device_path_media_protocol {
struct efi_device_path header;
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 105/112] efi: devicepath: let compiler worry about unaligned unpacking
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (103 preceding siblings ...)
2024-01-03 18:13 ` [PATCH 104/112] efi: devicepath: drop unused macro Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 106/112] efi: devicepath: correct formatting of BBS Ahmad Fatoum
` (6 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Device path nodes are tightly packed and subsequent device nodes may
start at any boundary. To parse these, existing code allocated a new
buffer and unpacked device paths into it, so they are at a natural
boundary (chosen as 8 bytes with x86_64 in mind).
We can simplify this by using __packed and letting the compiler worry
about not generating unaligned accesses. This has the benefit of
simplifying the incoming EFI loader implementation and we now no longer
leak the unpacked EFI device path.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/devicepath.c | 56 -------------------------------
include/efi/device-path.h | 70 +++++++++++++++++++--------------------
2 files changed, 35 insertions(+), 91 deletions(-)
diff --git a/efi/devicepath.c b/efi/devicepath.c
index 229810d49bbc..0df43f222018 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -40,15 +40,11 @@ char *cprintf(struct string *str, const char *fmt, ...)
return NULL;
}
-#define MIN_ALIGNMENT_SIZE 8 /* FIXME: X86_64 specific */
-#define ALIGN_SIZE(a) ((a % MIN_ALIGNMENT_SIZE) ? MIN_ALIGNMENT_SIZE - (a % MIN_ALIGNMENT_SIZE) : 0)
-
#define device_path_type(a) ( ((a)->type) & DEVICE_PATH_TYPE_MASK )
#define next_device_path_node(a) ( (const struct efi_device_path *) ( ((u8 *) (a)) + (a)->length))
#define is_device_path_end_type(a) ( device_path_type(a) == DEVICE_PATH_TYPE_END )
#define is_device_path_end_sub_type(a) ( (a)->sub_type == DEVICE_PATH_SUB_TYPE_END )
#define is_device_path_end(a) ( is_device_path_end_type(a) && is_device_path_end_sub_type(a) )
-#define is_device_path_unpacked(a) ( (a)->type & DEVICE_PATH_TYPE_UNPACKED )
#define set_device_path_end_node(a) { \
(a)->type = DEVICE_PATH_TYPE_END; \
@@ -90,50 +86,6 @@ device_path_from_handle(efi_handle_t Handle)
return NULL;
}
-static struct efi_device_path *
-unpack_device_path(const struct efi_device_path *dev_path)
-{
- const struct efi_device_path *Src;
- struct efi_device_path *Dest, *new_path;
- unsigned long Size;
-
- /* Walk device path and round sizes to valid boundaries */
-
- Src = dev_path;
- Size = 0;
- for (;;) {
- Size += Src->length;
- Size += ALIGN_SIZE(Size);
-
- if (is_device_path_end(Src)) {
- break;
- }
-
- Src = next_device_path_node(Src);
- }
-
- new_path = xzalloc(Size);
-
- Src = dev_path;
- Dest = new_path;
- for (;;) {
- Size = Src->length;
- memcpy(Dest, Src, Size);
- Size += ALIGN_SIZE(Size);
- Dest->length = Size;
- Dest->type |= DEVICE_PATH_TYPE_UNPACKED;
- Dest =
- (struct efi_device_path *) (((u8 *) Dest) + Size);
-
- if (is_device_path_end(Src))
- break;
-
- Src = next_device_path_node(Src);
- }
-
- return new_path;
-}
-
static void
dev_path_pci(struct string *str, const void *dev_path)
{
@@ -727,8 +679,6 @@ static void __device_path_to_str(struct string *str,
void (*dump_node) (struct string *, const void *);
int i;
- dev_path = unpack_device_path(dev_path);
-
dev_path_node = dev_path;
while (!is_device_path_end(dev_path_node)) {
dump_node = NULL;
@@ -804,7 +754,6 @@ u8 device_path_to_type(const struct efi_device_path *dev_path)
{
const 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)) {
@@ -819,7 +768,6 @@ u8 device_path_to_subtype(const struct efi_device_path *dev_path)
{
const 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)) {
@@ -851,8 +799,6 @@ device_path_next_compatible_node(const struct efi_device_path *dev_path,
char *device_path_to_partuuid(const struct efi_device_path *dev_path)
{
- dev_path = unpack_device_path(dev_path);
-
while ((dev_path = device_path_next_compatible_node(dev_path,
DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH))) {
struct efi_device_path_hard_drive_path *hd =
@@ -872,8 +818,6 @@ char *device_path_to_filepath(const struct efi_device_path *dev_path)
struct efi_device_path_file_path *fp = NULL;
char *path;
- dev_path = unpack_device_path(dev_path);
-
while ((dev_path = device_path_next_compatible_node(dev_path,
DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_FILE_PATH))) {
fp = container_of(dev_path, struct efi_device_path_file_path, header);
diff --git a/include/efi/device-path.h b/include/efi/device-path.h
index 39221ca369de..f6f11672f5d6 100644
--- a/include/efi/device-path.h
+++ b/include/efi/device-path.h
@@ -2,6 +2,7 @@
#define __EFI_DEVICE_PATH_H
#include <efi/types.h>
+#include <linux/compiler.h>
/*
* Hardware Device Path (UEFI 2.4 specification, version 2.4 § 9.3.2.)
@@ -14,13 +15,13 @@ struct efi_device_path_pci {
struct efi_device_path header;
u8 Function;
u8 Device;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_PCCARD 0x02
struct efi_device_path_pccard {
struct efi_device_path header;
u8 function_number;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MEMORY 0x03
struct efi_device_path_memory {
@@ -28,24 +29,24 @@ struct efi_device_path_memory {
u32 memory_type;
efi_physical_addr_t starting_address;
efi_physical_addr_t ending_address;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_VENDOR 0x04
struct efi_device_path_vendor {
struct efi_device_path header;
efi_guid_t Guid;
-};
+} __packed;
struct efi_device_path_unknown_device_vendor {
struct efi_device_path_vendor device_path;
u8 legacy_drive_letter;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_CONTROLLER 0x05
struct efi_device_path_controller {
struct efi_device_path header;
u32 Controller;
-};
+} __packed;
/*
* ACPI Device Path (UEFI 2.4 specification, version 2.4 § 9.3.3 and 9.3.4.)
@@ -57,7 +58,7 @@ struct efi_device_path_acpi_hid {
struct efi_device_path header;
u32 HID;
u32 UID;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_EXPANDED_ACPI_DEVICE 0x02
struct efi_device_path_expanded_acpi {
@@ -66,13 +67,13 @@ struct efi_device_path_expanded_acpi {
u32 UID;
u32 CID;
u8 hid_str[];
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_ACPI_ADR_DEVICE 3
struct efi_device_path_acpi_adr {
struct efi_device_path header;
u32 ADR;
-};
+} __packed;
/*
* EISA ID Macro
@@ -99,14 +100,14 @@ struct efi_device_path_atapi {
u8 primary_secondary;
u8 slave_master;
u16 Lun;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MSG_SCSI 0x02
struct efi_device_path_scsi {
struct efi_device_path header;
u16 Pun;
u16 Lun;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MSG_FIBRECHANNEL 0x03
struct efi_device_path_fibrechannel {
@@ -114,7 +115,7 @@ struct efi_device_path_fibrechannel {
u32 Reserved;
u64 WWN;
u64 Lun;
-};
+} __packed;
/**
* Fibre Channel Ex sub_type.
@@ -126,21 +127,21 @@ struct efi_device_path_fibrechannelex {
u32 Reserved;
u8 WWN[8]; /* World Wide Name */
u8 Lun[8]; /* Logical unit, T-10 SCSI Architecture Model 4 specification */
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MSG_1394 0x04
struct efi_device_path_f1394 {
struct efi_device_path header;
u32 Reserved;
u64 Guid;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MSG_USB 0x05
struct efi_device_path_usb {
struct efi_device_path header;
u8 Port;
u8 Endpoint;
-};
+} __packed;
/**
* SATA Device Path sub_type.
@@ -152,7 +153,7 @@ struct efi_device_path_sata {
u16 HBAPort_number;
u16 port_multiplier_port_number;
u16 Lun; /* Logical Unit Number */
-};
+} __packed;
/**
* USB WWID Device Path sub_type.
@@ -165,7 +166,7 @@ struct efi_device_path_usb_wwid {
u16 vendor_id;
u16 product_id;
s16 serial_number[]; /* UTF-16 characters of the USB serial number */
-};
+} __packed;
/**
* Device Logical Unit sub_type.
@@ -175,7 +176,7 @@ struct efi_device_path_usb_wwid {
struct efi_device_path_logical_unit {
struct efi_device_path header;
u8 Lun; /* Logical Unit Number */
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS 0x0f
struct efi_device_path_usb_class {
@@ -185,20 +186,20 @@ struct efi_device_path_usb_class {
u8 device_class;
u8 device_subclass;
u8 device_protocol;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MSG_I2_o 0x06
struct efi_device_path_i2_o {
struct efi_device_path header;
u32 Tid;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR 0x0b
struct efi_device_path_mac_addr {
struct efi_device_path header;
struct efi_mac_address mac_address;
u8 if_type;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MSG_IPv4 0x0c
struct efi_device_path_ipv4 {
@@ -212,7 +213,7 @@ struct efi_device_path_ipv4 {
/* new from UEFI version 2, code must check length field in header */
struct efi_ipv4_address gateway_ip_address;
struct efi_ipv4_address subnet_mask;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MSG_IPv6 0x0d
struct efi_device_path_ipv6 {
@@ -226,7 +227,7 @@ struct efi_device_path_ipv6 {
/* new from UEFI version 2, code must check length field in header */
u8 prefix_length;
struct efi_ipv6_address gateway_ip_address;
-};
+} __packed;
/**
* Device Logical Unit sub_type.
@@ -236,7 +237,7 @@ struct efi_device_path_ipv6 {
struct efi_device_path_vlan {
struct efi_device_path header;
u16 vlan_id;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MSG_INFINIBAND 0x09
struct efi_device_path_infiniband {
@@ -246,7 +247,7 @@ struct efi_device_path_infiniband {
u64 service_id;
u64 target_port_id;
u64 device_id;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MSG_UART 0x0e
struct efi_device_path_uart {
@@ -256,7 +257,7 @@ struct efi_device_path_uart {
u8 data_bits;
u8 Parity;
u8 stop_bits;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MSG_VENDOR 0x0a
/* Use VENDOR_DEVICE_PATH struct */
@@ -299,7 +300,7 @@ struct efi_device_path_hard_drive_path {
u8 signature[16];
u8 mbr_type;
u8 signature_type;
-};
+} __packed;
#define MBR_TYPE_PCAT 0x01
#define MBR_TYPE_EFI_PARTITION_TABLE_HEADER 0x02
@@ -313,7 +314,7 @@ struct efi_device_path_cdrom_path {
u32 boot_entry;
u64 partition_start;
u64 partition_size;
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_VENDOR_PATH 0x03
/* Use VENDOR_DEVICE_PATH struct */
@@ -322,13 +323,13 @@ struct efi_device_path_cdrom_path {
struct efi_device_path_file_path {
struct efi_device_path header;
s16 path_name[];
-};
+} __packed;
#define DEVICE_PATH_SUB_TYPE_MEDIA_PROTOCOL 0x05
struct efi_device_path_media_protocol {
struct efi_device_path header;
efi_guid_t Protocol;
-};
+} __packed;
/**
* PIWG Firmware File sub_type.
@@ -338,7 +339,7 @@ struct efi_device_path_media_protocol {
struct efi_device_path_media_fw_vol_file_path {
struct efi_device_path header;
efi_guid_t fv_file_name;
-};
+} __packed;
/**
* PIWG Firmware Volume Device Path sub_type.
@@ -348,7 +349,7 @@ struct efi_device_path_media_fw_vol_file_path {
struct efi_device_media_piwg_fw_vol {
struct efi_device_path header;
efi_guid_t fv_name;
-};
+} __packed;
/**
* Media relative offset range device path.
@@ -360,7 +361,7 @@ struct efi_device_media_relative_offset_range {
u32 Reserved;
u64 starting_offset;
u64 ending_offset;
-};
+} __packed;
/*
* BIOS Boot Specification Device Path (UEFI 2.4 specification, version 2.4 § 9.3.7.)
@@ -373,7 +374,7 @@ struct efi_device_path_bbs_bbs {
u16 device_type;
u16 status_flag;
s8 String[];
-};
+} __packed;
/* device_type definitions - from BBS specification */
#define BBS_TYPE_FLOPPY 0x01
@@ -387,7 +388,6 @@ struct efi_device_path_bbs_bbs {
#define DEVICE_PATH_TYPE_MASK 0x7f
-#define DEVICE_PATH_TYPE_UNPACKED 0x80
#define DEVICE_PATH_TYPE_END 0x7f
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 106/112] efi: devicepath: correct formatting of BBS
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (104 preceding siblings ...)
2024-01-03 18:13 ` [PATCH 105/112] efi: devicepath: let compiler worry about unaligned unpacking Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 107/112] commands: provide efi_handle_dump in both payload and loader Ahmad Fatoum
` (5 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
It's the BIOS boot specification (BBS) and not BSS. Fix the typo in
preparation for abusing it.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/devicepath.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/efi/devicepath.c b/efi/devicepath.c
index 0df43f222018..23963aa0cbb7 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -536,13 +536,13 @@ dev_path_media_protocol(struct string *str, const void *dev_path)
}
static void
-dev_path_bss_bss(struct string *str, const void *dev_path)
+dev_path_bbs_bbs(struct string *str, const void *dev_path)
{
- const struct efi_device_path_bbs_bbs *Bss;
+ const struct efi_device_path_bbs_bbs *bbs;
char *type;
- Bss = dev_path;
- switch (Bss->device_type) {
+ bbs = dev_path;
+ switch (bbs->device_type) {
case BBS_TYPE_FLOPPY:
type = "Floppy";
break;
@@ -569,7 +569,7 @@ dev_path_bss_bss(struct string *str, const void *dev_path)
break;
}
- cprintf(str, "Bss-%s(%s)", type, Bss->String);
+ cprintf(str, "BBS(%s,%s)", type, bbs->String);
}
static void
@@ -666,7 +666,7 @@ struct {
DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_VENDOR_PATH, dev_path_vendor}, {
DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_FILE_PATH, dev_path_file_path}, {
DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_MEDIA_PROTOCOL, dev_path_media_protocol}, {
- DEVICE_PATH_TYPE_BBS_DEVICE, DEVICE_PATH_SUB_TYPE_BBS_BBS, dev_path_bss_bss}, {
+ DEVICE_PATH_TYPE_BBS_DEVICE, DEVICE_PATH_SUB_TYPE_BBS_BBS, dev_path_bbs_bbs}, {
DEVICE_PATH_TYPE_END, DEVICE_PATH_SUB_TYPE_INSTANCE_END,
dev_path_end_instance}, {
0, 0, NULL}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 107/112] commands: provide efi_handle_dump in both payload and loader
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (105 preceding siblings ...)
2024-01-03 18:13 ` [PATCH 106/112] efi: devicepath: correct formatting of BBS Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 108/112] lib: uuid: implement uuid/guid_parse Ahmad Fatoum
` (4 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The efi_handle_dump command is currently used when barebox is built as
payload, but it's also useful when running as a loader to list handles
and their protocols. Move the code into a common area to make it
accessible in both configurations.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/Kconfig | 8 ++
commands/Makefile | 1 +
commands/efi_handle_dump.c | 181 ++++++++++++++++++++++++++++++++++
drivers/efi/Makefile | 3 +-
drivers/efi/efi-device.c | 196 +------------------------------------
drivers/efi/efi-handle.c | 43 ++++++++
include/efi/efi-device.h | 9 ++
7 files changed, 246 insertions(+), 195 deletions(-)
create mode 100644 commands/efi_handle_dump.c
create mode 100644 drivers/efi/efi-handle.c
diff --git a/commands/Kconfig b/commands/Kconfig
index eddfbee208a1..b1e7e9ff2012 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -123,6 +123,14 @@ config CMD_DRVINFO
help
List compiled-in device drivers and the devices they support.
+config CMD_EFI_HANDLE_DUMP
+ tristate
+ default y
+ depends on EFI
+ prompt "efi_handle_dump"
+ help
+ Dump information on EFI handles
+
config CMD_HELP
tristate
default y
diff --git a/commands/Makefile b/commands/Makefile
index 81bf5651ddc2..8ae72b10a17b 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -148,5 +148,6 @@ obj-$(CONFIG_CMD_UBSAN) += ubsan.o
obj-$(CONFIG_CMD_SELFTEST) += selftest.o
obj-$(CONFIG_CMD_TUTORIAL) += tutorial.o
obj-$(CONFIG_CMD_STACKSMASH) += stacksmash.o
+obj-$(CONFIG_CMD_EFI_HANDLE_DUMP) += efi_handle_dump.o
UBSAN_SANITIZE_ubsan.o := y
diff --git a/commands/efi_handle_dump.c b/commands/efi_handle_dump.c
new file mode 100644
index 000000000000..43cdb8ac503e
--- /dev/null
+++ b/commands/efi_handle_dump.c
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * efi-device.c - barebox EFI payload support
+ *
+ * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ */
+
+#include <common.h>
+#include <command.h>
+#include <efi.h>
+#include <efi/efi-device.h>
+#include <efi/efi-mode.h>
+
+static void efi_devpath(efi_handle_t handle)
+{
+ efi_status_t efiret;
+ void *devpath;
+ char *dev_path_str;
+
+ efiret = BS->open_protocol(handle, &efi_device_path_protocol_guid,
+ &devpath, NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (EFI_ERROR(efiret))
+ return;
+
+ dev_path_str = device_path_to_str(devpath);
+ if (dev_path_str) {
+ printf(" Devpath: \n %s\n", dev_path_str);
+ free(dev_path_str);
+ }
+}
+
+static void efi_dump(efi_handle_t *handles, unsigned long handle_count)
+{
+ int i, j;
+ unsigned long num_guids;
+ efi_guid_t **guids;
+
+ if (!handles || !handle_count)
+ return;
+
+ for (i = 0; i < handle_count; i++) {
+ printf("handle-%p\n", handles[i]);
+
+ BS->protocols_per_handle(handles[i], &guids, &num_guids);
+ printf(" Protocols:\n");
+ for (j = 0; j < num_guids; j++)
+ printf(" %d: %pUl: %s\n", j, guids[j],
+ efi_guid_string(guids[j]));
+ efi_devpath(handles[i]);
+ }
+ printf("\n");
+}
+
+static unsigned char to_digit(unsigned char c)
+{
+ if (c >= '0' && c <= '9')
+ c -= '0';
+ else if (c >= 'A' && c <= 'F')
+ c -= 'A' - 10;
+ else
+ c -= 'a' - 10;
+
+ return c;
+}
+
+#define read_xbit(src, dest, bit) \
+ do { \
+ int __i; \
+ for (__i = (bit - 4); __i >= 0; __i -= 4, src++) \
+ dest |= to_digit(*src) << __i; \
+ } while (0)
+
+static int do_efi_protocol_dump(int argc, char **argv)
+{
+ unsigned long handle_count = 0;
+ efi_handle_t *handles = NULL;
+ int ret;
+ efi_guid_t guid;
+ u32 a = 0;
+ u16 b = 0;
+ u16 c = 0;
+ u8 d0 = 0;
+ u8 d1 = 0;
+ u8 d2 = 0;
+ u8 d3 = 0;
+ u8 d4 = 0;
+ u8 d5 = 0;
+ u8 d6 = 0;
+ u8 d7 = 0;
+
+ /* Format 220e73b6-6bdb-4413-8405-b974b108619a */
+ if (argc == 1) {
+ char *s = argv[0];
+ int len = strlen(s);
+
+ if (len != 36)
+ return -EINVAL;
+
+ read_xbit(s, a, 32);
+ if (*s != '-')
+ return -EINVAL;
+ s++;
+ read_xbit(s, b, 16);
+ if (*s != '-')
+ return -EINVAL;
+ s++;
+ read_xbit(s, c, 16);
+ if (*s != '-')
+ return -EINVAL;
+ s++;
+ read_xbit(s, d0, 8);
+ read_xbit(s, d1, 8);
+ if (*s != '-')
+ return -EINVAL;
+ s++;
+ read_xbit(s, d2, 8);
+ read_xbit(s, d3, 8);
+ read_xbit(s, d4, 8);
+ read_xbit(s, d5, 8);
+ read_xbit(s, d6, 8);
+ read_xbit(s, d7, 8);
+ } else if (argc == 11) {
+ /* Format :
+ * 220e73b6 6bdb 4413 84 05 b9 74 b1 08 61 9a
+ * or
+ * 0x220e73b6 0x6bdb 0x14413 0x84 0x05 0xb9 0x74 0xb1 0x08 0x61 0x9a
+ */
+ a = simple_strtoul(argv[0], NULL, 16);
+ b = simple_strtoul(argv[1], NULL, 16);
+ c = simple_strtoul(argv[2], NULL, 16);
+ d0 = simple_strtoul(argv[3], NULL, 16);
+ d1 = simple_strtoul(argv[4], NULL, 16);
+ d2 = simple_strtoul(argv[5], NULL, 16);
+ d3 = simple_strtoul(argv[6], NULL, 16);
+ d4 = simple_strtoul(argv[7], NULL, 16);
+ d5 = simple_strtoul(argv[8], NULL, 16);
+ d6 = simple_strtoul(argv[9], NULL, 16);
+ d7 = simple_strtoul(argv[10], NULL, 16);
+ } else {
+ return -EINVAL;
+ }
+
+ guid = EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7);
+
+ printf("Searching for:\n");
+ printf(" %pUl: %s\n", &guid, efi_guid_string(&guid));
+
+ ret = __efi_locate_handle(BS, BY_PROTOCOL, &guid, NULL, &handle_count, &handles);
+ if (!ret)
+ efi_dump(handles, handle_count);
+
+ return 0;
+}
+
+static int do_efi_handle_dump(int argc, char *argv[])
+{
+ unsigned long handle_count = 0;
+ efi_handle_t *handles = NULL;
+ int ret;
+
+ if (argc > 1)
+ return do_efi_protocol_dump(--argc, ++argv);
+
+ ret = __efi_locate_handle(BS, ALL_HANDLES, NULL, NULL, &handle_count, &handles);
+ if (!ret)
+ efi_dump(handles, handle_count);
+
+ return 0;
+}
+
+BAREBOX_CMD_HELP_START(efi_handle_dump)
+BAREBOX_CMD_HELP_TEXT("Dump all the efi handle with protocol and devpath\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(efi_handle_dump)
+ .cmd = do_efi_handle_dump,
+ BAREBOX_CMD_DESC("Usage: efi_handle_dump")
+ BAREBOX_CMD_OPTS("[a-b-c-d0d1-d3d4d5d6d7] or [a b c d0 d1 d2 d3 d4 d5 d6 d7]")
+ BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+ BAREBOX_CMD_HELP(cmd_efi_handle_dump_help)
+BAREBOX_CMD_END
diff --git a/drivers/efi/Makefile b/drivers/efi/Makefile
index bd8fadac4222..4e3c39e14486 100644
--- a/drivers/efi/Makefile
+++ b/drivers/efi/Makefile
@@ -1,2 +1,3 @@
# SPDX-License-Identifier: GPL-2.0-only
-obj-y += efi-device.o
+obj-y += efi-handle.o
+obj-$(CONFIG_EFI_PAYLOAD) += efi-device.o
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index bbc76e9ef769..33c82c81dd1d 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -6,7 +6,6 @@
*/
#include <bootsource.h>
-#include <command.h>
#include <common.h>
#include <driver.h>
#include <malloc.h>
@@ -27,30 +26,8 @@ static int efi_locate_handle(enum efi_locate_search_type search_type,
unsigned long *no_handles,
efi_handle_t **buffer)
{
- efi_status_t efiret;
- unsigned long buffer_size = 0;
- efi_handle_t *buf;
-
- efiret = BS->locate_handle(search_type, protocol, search_key, &buffer_size,
- NULL);
- if (EFI_ERROR(efiret) && efiret != EFI_BUFFER_TOO_SMALL)
- return -efi_errno(efiret);
-
- buf = malloc(buffer_size);
- if (!buf)
- return -ENOMEM;
-
- efiret = BS->locate_handle(search_type, protocol, search_key, &buffer_size,
- buf);
- if (EFI_ERROR(efiret)) {
- free(buf);
- return -efi_errno(efiret);
- }
-
- *no_handles = buffer_size / sizeof(efi_handle_t);
- *buffer = buf;
-
- return 0;
+ return __efi_locate_handle(BS, search_type, protocol, search_key, no_handles,
+ buffer);
}
static struct efi_device *efi_find_device(efi_handle_t handle)
@@ -499,172 +476,3 @@ void efi_continue_devices(void)
efidrv->dev_continue(efidev);
}
}
-
-static void efi_devpath(efi_handle_t handle)
-{
- efi_status_t efiret;
- void *devpath;
- char *dev_path_str;
-
- efiret = BS->open_protocol(handle, &efi_device_path_protocol_guid,
- &devpath, NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- if (EFI_ERROR(efiret))
- return;
-
- dev_path_str = device_path_to_str(devpath);
- if (dev_path_str) {
- printf(" Devpath: \n %s\n", dev_path_str);
- free(dev_path_str);
- }
-}
-
-static void efi_dump(efi_handle_t *handles, unsigned long handle_count)
-{
- int i, j;
- unsigned long num_guids;
- efi_guid_t **guids;
-
- if (!handles || !handle_count)
- return;
-
- for (i = 0; i < handle_count; i++) {
- printf("handle-%p\n", handles[i]);
-
- BS->protocols_per_handle(handles[i], &guids, &num_guids);
- printf(" Protocols:\n");
- for (j = 0; j < num_guids; j++)
- printf(" %d: %pUl: %s\n", j, guids[j],
- efi_guid_string(guids[j]));
- efi_devpath(handles[i]);
- }
- printf("\n");
-}
-
-static unsigned char to_digit(unsigned char c)
-{
- if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'F')
- c -= 'A' - 10;
- else
- c -= 'a' - 10;
-
- return c;
-}
-
-#define read_xbit(src, dest, bit) \
- do { \
- int __i; \
- for (__i = (bit - 4); __i >= 0; __i -= 4, src++) \
- dest |= to_digit(*src) << __i; \
- } while (0)
-
-static int do_efi_protocol_dump(int argc, char **argv)
-{
- unsigned long handle_count = 0;
- efi_handle_t *handles = NULL;
- int ret;
- efi_guid_t guid;
- u32 a = 0;
- u16 b = 0;
- u16 c = 0;
- u8 d0 = 0;
- u8 d1 = 0;
- u8 d2 = 0;
- u8 d3 = 0;
- u8 d4 = 0;
- u8 d5 = 0;
- u8 d6 = 0;
- u8 d7 = 0;
-
- /* Format 220e73b6-6bdb-4413-8405-b974b108619a */
- if (argc == 1) {
- char *s = argv[0];
- int len = strlen(s);
-
- if (len != 36)
- return -EINVAL;
-
- read_xbit(s, a, 32);
- if (*s != '-')
- return -EINVAL;
- s++;
- read_xbit(s, b, 16);
- if (*s != '-')
- return -EINVAL;
- s++;
- read_xbit(s, c, 16);
- if (*s != '-')
- return -EINVAL;
- s++;
- read_xbit(s, d0, 8);
- read_xbit(s, d1, 8);
- if (*s != '-')
- return -EINVAL;
- s++;
- read_xbit(s, d2, 8);
- read_xbit(s, d3, 8);
- read_xbit(s, d4, 8);
- read_xbit(s, d5, 8);
- read_xbit(s, d6, 8);
- read_xbit(s, d7, 8);
- } else if (argc == 11) {
- /* Format :
- * 220e73b6 6bdb 4413 84 05 b9 74 b1 08 61 9a
- * or
- * 0x220e73b6 0x6bdb 0x14413 0x84 0x05 0xb9 0x74 0xb1 0x08 0x61 0x9a
- */
- a = simple_strtoul(argv[0], NULL, 16);
- b = simple_strtoul(argv[1], NULL, 16);
- c = simple_strtoul(argv[2], NULL, 16);
- d0 = simple_strtoul(argv[3], NULL, 16);
- d1 = simple_strtoul(argv[4], NULL, 16);
- d2 = simple_strtoul(argv[5], NULL, 16);
- d3 = simple_strtoul(argv[6], NULL, 16);
- d4 = simple_strtoul(argv[7], NULL, 16);
- d5 = simple_strtoul(argv[8], NULL, 16);
- d6 = simple_strtoul(argv[9], NULL, 16);
- d7 = simple_strtoul(argv[10], NULL, 16);
- } else {
- return -EINVAL;
- }
-
- guid = EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7);
-
- printf("Searching for:\n");
- printf(" %pUl: %s\n", &guid, efi_guid_string(&guid));
-
- ret = efi_locate_handle(BY_PROTOCOL, &guid, NULL, &handle_count, &handles);
- if (!ret)
- efi_dump(handles, handle_count);
-
- return 0;
-}
-
-static int do_efi_handle_dump(int argc, char *argv[])
-{
- unsigned long handle_count = 0;
- efi_handle_t *handles = NULL;
- int ret;
-
- if (argc > 1)
- return do_efi_protocol_dump(--argc, ++argv);
-
- ret = efi_locate_handle(ALL_HANDLES, NULL, NULL, &handle_count, &handles);
- if (!ret)
- efi_dump(handles, handle_count);
-
- return 0;
-}
-
-BAREBOX_CMD_HELP_START(efi_handle_dump)
-BAREBOX_CMD_HELP_TEXT("Dump all the efi handle with protocol and devpath\n")
-BAREBOX_CMD_HELP_END
-
-BAREBOX_CMD_START(efi_handle_dump)
- .cmd = do_efi_handle_dump,
- BAREBOX_CMD_DESC("Usage: efi_handle_dump")
- BAREBOX_CMD_OPTS("[a-b-c-d0d1-d3d4d5d6d7] or [a b c d0 d1 d2 d3 d4 d5 d6 d7]")
- BAREBOX_CMD_GROUP(CMD_GRP_MISC)
- BAREBOX_CMD_HELP(cmd_efi_handle_dump_help)
-BAREBOX_CMD_END
diff --git a/drivers/efi/efi-handle.c b/drivers/efi/efi-handle.c
new file mode 100644
index 000000000000..be9013cb648f
--- /dev/null
+++ b/drivers/efi/efi-handle.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ */
+
+#include <common.h>
+#include <efi.h>
+#include <efi/efi-util.h>
+#include <efi/efi-device.h>
+#include <efi/efi-mode.h>
+
+int __efi_locate_handle(struct efi_boot_services *bs,
+ enum efi_locate_search_type search_type,
+ efi_guid_t *protocol,
+ void *search_key,
+ unsigned long *no_handles,
+ efi_handle_t **buffer)
+{
+ efi_status_t efiret;
+ unsigned long buffer_size = 0;
+ efi_handle_t *buf;
+
+ efiret = bs->locate_handle(search_type, protocol, search_key, &buffer_size,
+ NULL);
+ if (EFI_ERROR(efiret) && efiret != EFI_BUFFER_TOO_SMALL)
+ return -efi_errno(efiret);
+
+ buf = malloc(buffer_size);
+ if (!buf)
+ return -ENOMEM;
+
+ efiret = bs->locate_handle(search_type, protocol, search_key, &buffer_size,
+ buf);
+ if (EFI_ERROR(efiret)) {
+ free(buf);
+ return -efi_errno(efiret);
+ }
+
+ *no_handles = buffer_size / sizeof(efi_handle_t);
+ *buffer = buf;
+
+ return 0;
+}
diff --git a/include/efi/efi-device.h b/include/efi/efi-device.h
index 5f7490028b9e..5d2110356fd4 100644
--- a/include/efi/efi-device.h
+++ b/include/efi/efi-device.h
@@ -63,4 +63,13 @@ static inline bool efi_device_has_guid(struct efi_device *efidev, efi_guid_t gui
return false;
}
+enum efi_locate_search_type;
+
+int __efi_locate_handle(struct efi_boot_services *bs,
+ enum efi_locate_search_type search_type,
+ efi_guid_t *protocol,
+ void *search_key,
+ unsigned long *no_handles,
+ efi_handle_t **buffer);
+
#endif /* __EFI_EFI_DEVICE_H */
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 108/112] lib: uuid: implement uuid/guid_parse
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (106 preceding siblings ...)
2024-01-03 18:13 ` [PATCH 107/112] commands: provide efi_handle_dump in both payload and loader Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 109/112] commands: efi_handle_dump: prepare for supporting EFI loader Ahmad Fatoum
` (3 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We opencode this at least once in EFI code, so import the Linux
definition and start using that instead.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
lib/uuid.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/lib/uuid.c b/lib/uuid.c
index db75be1725bf..c83227c0d1e7 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -8,9 +8,72 @@
#include <linux/uuid.h>
#include <module.h>
+#include <linux/ctype.h>
#include <linux/export.h>
const guid_t guid_null;
EXPORT_SYMBOL(guid_null);
const uuid_t uuid_null;
EXPORT_SYMBOL(uuid_null);
+
+const u8 guid_index[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15};
+const u8 uuid_index[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
+
+/**
+ * uuid_is_valid - checks if a UUID string is valid
+ * @uuid: UUID string to check
+ *
+ * Description:
+ * It checks if the UUID string is following the format:
+ * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+ *
+ * where x is a hex digit.
+ *
+ * Return: true if input is valid UUID string.
+ */
+bool uuid_is_valid(const char *uuid)
+{
+ unsigned int i;
+
+ for (i = 0; i < UUID_STRING_LEN; i++) {
+ if (i == 8 || i == 13 || i == 18 || i == 23) {
+ if (uuid[i] != '-')
+ return false;
+ } else if (!isxdigit(uuid[i])) {
+ return false;
+ }
+ }
+
+ return true;
+}
+EXPORT_SYMBOL(uuid_is_valid);
+
+static int __uuid_parse(const char *uuid, __u8 b[16], const u8 ei[16])
+{
+ static const u8 si[16] = {0,2,4,6,9,11,14,16,19,21,24,26,28,30,32,34};
+ unsigned int i;
+
+ if (!uuid_is_valid(uuid))
+ return -EINVAL;
+
+ for (i = 0; i < 16; i++) {
+ int hi = hex_to_bin(uuid[si[i] + 0]);
+ int lo = hex_to_bin(uuid[si[i] + 1]);
+
+ b[ei[i]] = (hi << 4) | lo;
+ }
+
+ return 0;
+}
+
+int guid_parse(const char *uuid, guid_t *u)
+{
+ return __uuid_parse(uuid, u->b, guid_index);
+}
+EXPORT_SYMBOL(guid_parse);
+
+int uuid_parse(const char *uuid, uuid_t *u)
+{
+ return __uuid_parse(uuid, u->b, uuid_index);
+}
+EXPORT_SYMBOL(uuid_parse);
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 109/112] commands: efi_handle_dump: prepare for supporting EFI loader
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (107 preceding siblings ...)
2024-01-03 18:13 ` [PATCH 108/112] lib: uuid: implement uuid/guid_parse Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 110/112] commands: efi_handle_dump: print loaded image devpath Ahmad Fatoum
` (2 subsequent siblings)
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
For debugging, it can be useful to dump handles from within the loader
without having to boot barebox as EFI payload first.
Prepare for this by removing implicit dependency on being an EFI
payload.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/efi_handle_dump.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/commands/efi_handle_dump.c b/commands/efi_handle_dump.c
index 43cdb8ac503e..1f7b1caa13f9 100644
--- a/commands/efi_handle_dump.c
+++ b/commands/efi_handle_dump.c
@@ -8,16 +8,16 @@
#include <common.h>
#include <command.h>
#include <efi.h>
-#include <efi/efi-device.h>
#include <efi/efi-mode.h>
+#include <efi/efi-device.h>
-static void efi_devpath(efi_handle_t handle)
+static void efi_devpath(struct efi_boot_services *bs, efi_handle_t handle)
{
efi_status_t efiret;
void *devpath;
char *dev_path_str;
- efiret = BS->open_protocol(handle, &efi_device_path_protocol_guid,
+ efiret = bs->open_protocol(handle, &efi_device_path_protocol_guid,
&devpath, NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (EFI_ERROR(efiret))
return;
@@ -29,7 +29,7 @@ static void efi_devpath(efi_handle_t handle)
}
}
-static void efi_dump(efi_handle_t *handles, unsigned long handle_count)
+static void efi_dump(struct efi_boot_services *bs, efi_handle_t *handles, unsigned long handle_count)
{
int i, j;
unsigned long num_guids;
@@ -41,12 +41,12 @@ static void efi_dump(efi_handle_t *handles, unsigned long handle_count)
for (i = 0; i < handle_count; i++) {
printf("handle-%p\n", handles[i]);
- BS->protocols_per_handle(handles[i], &guids, &num_guids);
+ bs->protocols_per_handle(handles[i], &guids, &num_guids);
printf(" Protocols:\n");
for (j = 0; j < num_guids; j++)
printf(" %d: %pUl: %s\n", j, guids[j],
efi_guid_string(guids[j]));
- efi_devpath(handles[i]);
+ efi_devpath(bs, handles[i]);
}
printf("\n");
}
@@ -70,7 +70,7 @@ static unsigned char to_digit(unsigned char c)
dest |= to_digit(*src) << __i; \
} while (0)
-static int do_efi_protocol_dump(int argc, char **argv)
+static int do_efi_protocol_dump(struct efi_boot_services *bs, int argc, char **argv)
{
unsigned long handle_count = 0;
efi_handle_t *handles = NULL;
@@ -145,9 +145,9 @@ static int do_efi_protocol_dump(int argc, char **argv)
printf("Searching for:\n");
printf(" %pUl: %s\n", &guid, efi_guid_string(&guid));
- ret = __efi_locate_handle(BS, BY_PROTOCOL, &guid, NULL, &handle_count, &handles);
+ ret = __efi_locate_handle(bs, BY_PROTOCOL, &guid, NULL, &handle_count, &handles);
if (!ret)
- efi_dump(handles, handle_count);
+ efi_dump(bs, handles, handle_count);
return 0;
}
@@ -156,14 +156,21 @@ static int do_efi_handle_dump(int argc, char *argv[])
{
unsigned long handle_count = 0;
efi_handle_t *handles = NULL;
+ struct efi_boot_services *bs;
int ret;
- if (argc > 1)
- return do_efi_protocol_dump(--argc, ++argv);
+ bs = efi_get_boot_services();
+ if (!bs) {
+ printf("EFI not yet initialized\n");
+ return COMMAND_ERROR;
+ }
- ret = __efi_locate_handle(BS, ALL_HANDLES, NULL, NULL, &handle_count, &handles);
+ if (argc > 1)
+ return do_efi_protocol_dump(bs, --argc, ++argv);
+
+ ret = __efi_locate_handle(bs, ALL_HANDLES, NULL, NULL, &handle_count, &handles);
if (!ret)
- efi_dump(handles, handle_count);
+ efi_dump(bs, handles, handle_count);
return 0;
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 110/112] commands: efi_handle_dump: print loaded image devpath
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (108 preceding siblings ...)
2024-01-03 18:13 ` [PATCH 109/112] commands: efi_handle_dump: prepare for supporting EFI loader Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 111/112] commands: efi_handle_dump: use guid_parse instead of open-coding Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 112/112] commands: efi_handle_dump: don't ignore failure to parse GUID Ahmad Fatoum
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Device Path and Loaded Image Device Path are different things.
Print both for maximum utility.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/efi_handle_dump.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/commands/efi_handle_dump.c b/commands/efi_handle_dump.c
index 1f7b1caa13f9..74d53c9a17c5 100644
--- a/commands/efi_handle_dump.c
+++ b/commands/efi_handle_dump.c
@@ -11,20 +11,23 @@
#include <efi/efi-mode.h>
#include <efi/efi-device.h>
-static void efi_devpath(struct efi_boot_services *bs, efi_handle_t handle)
+static void efi_devpath(struct efi_boot_services *bs,
+ efi_handle_t handle,
+ const efi_guid_t *guid,
+ const char *desc)
{
efi_status_t efiret;
void *devpath;
char *dev_path_str;
- efiret = bs->open_protocol(handle, &efi_device_path_protocol_guid,
- &devpath, NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ efiret = bs->open_protocol(handle, guid, &devpath, NULL, NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (EFI_ERROR(efiret))
return;
dev_path_str = device_path_to_str(devpath);
if (dev_path_str) {
- printf(" Devpath: \n %s\n", dev_path_str);
+ printf(" %s: \n %s\n", desc, dev_path_str);
free(dev_path_str);
}
}
@@ -46,7 +49,11 @@ static void efi_dump(struct efi_boot_services *bs, efi_handle_t *handles, unsign
for (j = 0; j < num_guids; j++)
printf(" %d: %pUl: %s\n", j, guids[j],
efi_guid_string(guids[j]));
- efi_devpath(bs, handles[i]);
+
+ efi_devpath(bs, handles[i], &efi_device_path_protocol_guid,
+ "Devpath");
+ efi_devpath(bs, handles[i], &efi_loaded_image_device_path_guid,
+ "Image Devpath");
}
printf("\n");
}
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 111/112] commands: efi_handle_dump: use guid_parse instead of open-coding
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (109 preceding siblings ...)
2024-01-03 18:13 ` [PATCH 110/112] commands: efi_handle_dump: print loaded image devpath Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
2024-01-03 18:13 ` [PATCH 112/112] commands: efi_handle_dump: don't ignore failure to parse GUID Ahmad Fatoum
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Now that we have GUID parsing functions, let's start using them.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/efi_handle_dump.c | 69 +++++---------------------------------
1 file changed, 8 insertions(+), 61 deletions(-)
diff --git a/commands/efi_handle_dump.c b/commands/efi_handle_dump.c
index 74d53c9a17c5..461d330c2fa4 100644
--- a/commands/efi_handle_dump.c
+++ b/commands/efi_handle_dump.c
@@ -8,6 +8,7 @@
#include <common.h>
#include <command.h>
#include <efi.h>
+#include <linux/uuid.h>
#include <efi/efi-mode.h>
#include <efi/efi-device.h>
@@ -58,75 +59,22 @@ static void efi_dump(struct efi_boot_services *bs, efi_handle_t *handles, unsign
printf("\n");
}
-static unsigned char to_digit(unsigned char c)
-{
- if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'F')
- c -= 'A' - 10;
- else
- c -= 'a' - 10;
-
- return c;
-}
-
-#define read_xbit(src, dest, bit) \
- do { \
- int __i; \
- for (__i = (bit - 4); __i >= 0; __i -= 4, src++) \
- dest |= to_digit(*src) << __i; \
- } while (0)
-
static int do_efi_protocol_dump(struct efi_boot_services *bs, int argc, char **argv)
{
unsigned long handle_count = 0;
efi_handle_t *handles = NULL;
int ret;
efi_guid_t guid;
- u32 a = 0;
- u16 b = 0;
- u16 c = 0;
- u8 d0 = 0;
- u8 d1 = 0;
- u8 d2 = 0;
- u8 d3 = 0;
- u8 d4 = 0;
- u8 d5 = 0;
- u8 d6 = 0;
- u8 d7 = 0;
/* Format 220e73b6-6bdb-4413-8405-b974b108619a */
if (argc == 1) {
- char *s = argv[0];
- int len = strlen(s);
-
- if (len != 36)
- return -EINVAL;
-
- read_xbit(s, a, 32);
- if (*s != '-')
- return -EINVAL;
- s++;
- read_xbit(s, b, 16);
- if (*s != '-')
- return -EINVAL;
- s++;
- read_xbit(s, c, 16);
- if (*s != '-')
- return -EINVAL;
- s++;
- read_xbit(s, d0, 8);
- read_xbit(s, d1, 8);
- if (*s != '-')
- return -EINVAL;
- s++;
- read_xbit(s, d2, 8);
- read_xbit(s, d3, 8);
- read_xbit(s, d4, 8);
- read_xbit(s, d5, 8);
- read_xbit(s, d6, 8);
- read_xbit(s, d7, 8);
+ ret = guid_parse(argv[0], &guid);
+ if (ret)
+ return ret;
} else if (argc == 11) {
+ u32 a;
+ u16 b, c;
+ u8 d0, d1, d2, d3, d4, d5, d6, d7;
/* Format :
* 220e73b6 6bdb 4413 84 05 b9 74 b1 08 61 9a
* or
@@ -143,12 +91,11 @@ static int do_efi_protocol_dump(struct efi_boot_services *bs, int argc, char **a
d5 = simple_strtoul(argv[8], NULL, 16);
d6 = simple_strtoul(argv[9], NULL, 16);
d7 = simple_strtoul(argv[10], NULL, 16);
+ guid = EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7);
} else {
return -EINVAL;
}
- guid = EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7);
-
printf("Searching for:\n");
printf(" %pUl: %s\n", &guid, efi_guid_string(&guid));
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread
* [PATCH 112/112] commands: efi_handle_dump: don't ignore failure to parse GUID
2024-01-03 18:11 [PATCH 000/112] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (110 preceding siblings ...)
2024-01-03 18:13 ` [PATCH 111/112] commands: efi_handle_dump: use guid_parse instead of open-coding Ahmad Fatoum
@ 2024-01-03 18:13 ` Ahmad Fatoum
111 siblings, 0 replies; 134+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 18:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
simple_strtoul should probably be removed altogether. Let's start by
removing it from efi_handle_dump.c, so invalid input is not ignored.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/efi_handle_dump.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/commands/efi_handle_dump.c b/commands/efi_handle_dump.c
index 461d330c2fa4..a9db5eb75b69 100644
--- a/commands/efi_handle_dump.c
+++ b/commands/efi_handle_dump.c
@@ -69,8 +69,6 @@ static int do_efi_protocol_dump(struct efi_boot_services *bs, int argc, char **a
/* Format 220e73b6-6bdb-4413-8405-b974b108619a */
if (argc == 1) {
ret = guid_parse(argv[0], &guid);
- if (ret)
- return ret;
} else if (argc == 11) {
u32 a;
u16 b, c;
@@ -80,22 +78,26 @@ static int do_efi_protocol_dump(struct efi_boot_services *bs, int argc, char **a
* or
* 0x220e73b6 0x6bdb 0x14413 0x84 0x05 0xb9 0x74 0xb1 0x08 0x61 0x9a
*/
- a = simple_strtoul(argv[0], NULL, 16);
- b = simple_strtoul(argv[1], NULL, 16);
- c = simple_strtoul(argv[2], NULL, 16);
- d0 = simple_strtoul(argv[3], NULL, 16);
- d1 = simple_strtoul(argv[4], NULL, 16);
- d2 = simple_strtoul(argv[5], NULL, 16);
- d3 = simple_strtoul(argv[6], NULL, 16);
- d4 = simple_strtoul(argv[7], NULL, 16);
- d5 = simple_strtoul(argv[8], NULL, 16);
- d6 = simple_strtoul(argv[9], NULL, 16);
- d7 = simple_strtoul(argv[10], NULL, 16);
- guid = EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7);
+ ret = kstrtou32(argv[0], 16, &a);
+ ret = ret ?: kstrtou16(argv[1], 16, &b);
+ ret = ret ?: kstrtou16(argv[2], 16, &c);
+ ret = ret ?: kstrtou8(argv[3], 16, &d0);
+ ret = ret ?: kstrtou8(argv[4], 16, &d1);
+ ret = ret ?: kstrtou8(argv[5], 16, &d2);
+ ret = ret ?: kstrtou8(argv[6], 16, &d3);
+ ret = ret ?: kstrtou8(argv[7], 16, &d4);
+ ret = ret ?: kstrtou8(argv[8], 16, &d5);
+ ret = ret ?: kstrtou8(argv[9], 16, &d6);
+ ret = ret ?: kstrtou8(argv[10], 16, &d7);
+ if (!ret)
+ guid = EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7);
} else {
- return -EINVAL;
+ ret = -EINVAL;
}
+ if (ret)
+ return ret;
+
printf("Searching for:\n");
printf(" %pUl: %s\n", &guid, efi_guid_string(&guid));
--
2.39.2
^ permalink raw reply [flat|nested] 134+ messages in thread