* [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support
@ 2024-03-04 18:58 Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 001/113] string: implement strcmp_ptr and streq_ptr helpers Ahmad Fatoum
` (113 more replies)
0 siblings, 114 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 UTC (permalink / raw)
To: barebox
I've been working on enabling use of barebox as EFI loader for a while.
It's already functional enough to boot efi-stubbed Linux directly or via
Grub, but some key parts like proper runtime services and the EFI boot
manager are still missing.
Nevertheless, A lot of commits are already in a good enough shape to be
upstreamed, which I collected in this series. A second WIP series with
the EFI loader support will follow afterwards.
This series lays the ground work for using barebox as EFI loader (i.e.
EFI firmware) on - at first - ARM64 systems:
- Generalize existing x86 EFI payload support, so it's usable on other
architectures and for barebox as EFI loader
- Rework virtual file system support, so we can easily map EFI file
system protocol onto barebox VFS
- Add barebox payload on ARM64 support to allow further
experimentation and to have an in-tree payload to test barebox
as EFI loader against
The payload has been tested with Qemu Virt64 against Tianocore, U-Boot and
my upcoming barebox EFI loader patches. It's not fully usable as Grub
replacement yet, because a boot handler isn't registered, but it was
very useful to develop the loader, which is why I am including it here,
even if not yet fully featured.
Most patches are the same between v1 and v2. Patches that changed have
a changelog.
Ahmad Fatoum (113):
string: implement strcmp_ptr and streq_ptr helpers
commands: efiexit: flush console and shutdown barebox
treewide: add errno_set helper for returning positive error code in
errno
vsprintf: guard against NULL in UUID %pU
common: add option to poweroff system on failure
boot: print error code when booting fails
common: efi: move directory to top-level
efi: payload: rename CONFIG_EFI_BOOTUP to CONFIG_EFI_PAYLOAD
efi: payload: image: return actual read_file() error
of: don't report failure to of_read_file twice
efi: payload: make missing state reporting less verbose
libfile: factor out read_file_into_buf helper
efi: payload: image: allocate image via loader if it exceeds malloc
area
efi: payload: image: use assigned barebox loader type on x86
efi: payload: iomem: adjust types to avoid casting
commands: kallsyms: add command-line interface
block: define BLOCKSIZE globally in block.h
cdev: implement setter/getter for cdev device node
block: virtio: assign virtio-mmio device tree node to cdevs
commands: stat: print DT node for cdevs if available
partitions: have parsers record bootable bits
commands: stat: display bootable partition table bit info
block: record block device type
include: add definitions for UAPI discoverable partitions spec
efi: payload: restrict 8250 UART at I/O port 0x3f8 registration to x86
fs: fix unreaddir, so readdir returns unread dirent first
fs: turn creat into static inline helper
fs: drop unused LOOKUP_ flags
fs: opendir: reference mount point until closedir is called
fs: factor out opendir iteration
fs: implement fdopendir and rewinddir
fs: remove unused member from struct nameidata
fs: always check path_init for errors
fs: set current working dir directly when mounting root
fs: implement openat and friends
fs: implement O_PATH
fs: support different root directories
fs: implement O_CHROOT
commands: introduce new findmnt command
fs: initialize struct nameidata::last
fs: support opening /
test: self: add dirfd tests
commands: stat: add option for statat
efi: payload: lower command line options print from error to info
efi: payload: init: warn if /boot FS is unknown
commands: time: switch to using getopt for -n
commands: time: reduce strjoin runtime, drop trailing space
commands: time: refactor into new strjoin
test: self: add strjoin tests
filetype: have cdev_detect_type take a cdev
ARM: mmu-early: gracefully handle already enabled MMU
efi: don't hide structs, enums or unions behind _t
efi: make headers self-contained
efi: unify whitespace for GUIDs
efi: efi-guid: add more GUIDs
ARM64: cpu: setupc: rewrite to be fully PIC
ARM64: runtime-offset: make get_runtime_offset fully PIC
pbl: introduce CONFIG_PBL_FULLY_PIC
efi: payload: fix ARM build
efi: payload: init: restrict barebox mem to first 1G only on x86
efi: add efi_is_loader/efi_is_payload helpers
efi: payload: suppress EFI payload initcalls when not EFI-loaded
ARM: make board data definitions accessible to other architectures
boarddata: add barebox_boarddata_is_machine helper
common: add PE/COFF loader
efi: use efi_handle_t where appropriate
efi: block: move definitions into header file
efi: define efi_handle_t as opaque pointer
efi: constify guid_t in API
efi: rename efi_simple_input_interface to
efi_simple_text_input_protocol
efi: add EFI_WARN constants
efi-stdio: fix wait_for_event argument
efi-stdio: wait for extended input key event when using extended input
efi: flesh out EFI definitions in header
efi: add efi_driver_binding_protocol
efi: improve usability of EFI_PAGE_* macros
fs: efi: move definitions into header
efi: fs: flesh out file system definitions
efi: stdio: fix efi_register_keystroke_notify prototype
video: mark EFI_GOP driver x86-only for now
filetype: add new file types for EFI-enabled Linux images
efi: payload: register handler for EFI-stubbed ARM64 kernel
efi: payload: factor C efi_main into dedicated file
efi: payload: early-mem: simplify error message reporting
efi: payload: early-mem: use EFI_PAGE_SIZE instead of PAGE_SIZE
ARM64: add optional EFI stub
efi: devicepath: improve const safety
efi: refactor device_path_to_partuuid for code reuse
efi: devicepath: implement device_path_to_str_buf variant
lib: vsprintf: align documentation with current feature set
vsprintf: add %pD for printing EFI device path
lib: string: import Linux strreplace helper
efi: payload: dynamically determine bootloader file name
efi: payload: iomem: register later
efi: payload: protect against buggy EFI implementations
efi: payload: don't require efi_loaded_image->parent_handle for
bootsource detection
commands: add cpuinfo -s option for stacktrace
efi: devicepath: align MemoryMapped name with spec
efi: devicepath: pretty print BBS BEV DeviceType
efi: devicepath: format GUIDs as little endian
efi: devicepath: move END device node definitions into header
efi: devicepath: drop underscores in hex constants
efi: devicepath: namespace definitions
efi: devicepath: use flexible array members for trailing strings
efi: devicepath: drop unused macro
efi: devicepath: let compiler worry about unaligned unpacking
efi: devicepath: correct formatting of BBS
commands: provide efi_handle_dump in both payload and loader
lib: uuid: implement uuid/guid_parse
commands: efi_handle_dump: prepare for supporting EFI loader
commands: efi_handle_dump: print loaded image devpath
commands: efi_handle_dump: use guid_parse instead of open-coding
commands: efi_handle_dump: don't ignore failure to parse GUID
Kconfig | 1 +
Makefile | 7 +-
arch/arm/Kconfig | 1 +
arch/arm/cpu/Kconfig | 1 +
arch/arm/cpu/board-dt-2nd-aarch64.S | 8 +-
arch/arm/cpu/cpu.c | 6 +
arch/arm/cpu/cpuinfo.c | 25 +-
arch/arm/cpu/efi-header-aarch64.S | 122 ++++
arch/arm/cpu/entry.c | 3 +
arch/arm/cpu/interrupts_64.c | 6 +-
arch/arm/cpu/mmu-common.c | 4 +
arch/arm/cpu/mmu_32.c | 3 +
arch/arm/cpu/mmu_64.c | 3 +
arch/arm/cpu/setupc_64.S | 22 +-
arch/arm/cpu/start.c | 16 +-
arch/arm/include/asm/barebox-arm.h | 30 +-
arch/arm/include/asm/memory.h | 20 +
arch/arm/include/asm/pci.h | 4 +-
arch/arm/lib/pbl.lds.S | 31 +
arch/arm/lib64/armlinux.c | 11 +
arch/arm/lib64/runtime-offset.S | 5 +-
arch/riscv/lib/bootm.c | 7 +
arch/sandbox/board/hostfile.c | 3 +-
arch/x86/Kconfig | 3 +-
arch/x86/mach-efi/clocksource.c | 4 +-
arch/x86/mach-efi/reloc_ia32.c | 2 +-
commands/Kconfig | 38 +-
commands/Makefile | 4 +
commands/efi_handle_dump.c | 144 ++++
commands/findmnt.c | 108 +++
commands/kallsyms.c | 50 ++
commands/of_diff.c | 5 +-
commands/of_display_timings.c | 4 +-
commands/of_overlay.c | 4 +-
commands/oftree.c | 4 +-
commands/readlink.c | 2 +-
commands/stat.c | 26 +-
commands/time.c | 35 +-
common/Kconfig | 49 +-
common/Makefile | 2 +-
common/block.c | 26 +-
common/boot.c | 2 +-
common/efi/Kconfig | 27 -
common/efi/payload/Makefile | 7 -
common/filetype.c | 25 +-
common/misc.c | 12 +-
common/partitions.c | 4 +-
common/partitions/dos.c | 10 +
common/partitions/efi.c | 18 +
common/pe.c | 379 +++++++++++
common/startup.c | 3 +-
drivers/Makefile | 2 +-
drivers/ata/ahci.c | 1 +
drivers/ata/disk_ata_drive.c | 1 +
drivers/block/Kconfig | 2 +-
drivers/block/efi-block-io.c | 28 +-
drivers/block/virtio_blk.c | 2 +
drivers/bus/Kconfig | 2 +-
drivers/bus/acpi.c | 6 +-
drivers/clocksource/Kconfig | 4 +-
drivers/clocksource/efi.c | 4 +-
drivers/efi/Makefile | 3 +-
drivers/efi/efi-device.c | 220 +------
drivers/efi/efi-handle.c | 43 ++
drivers/hw_random/efi-rng.c | 2 +-
drivers/mci/mci-core.c | 3 +-
drivers/net/Kconfig | 2 +-
drivers/net/efi-snp.c | 20 +-
drivers/nvme/host/core.c | 1 +
drivers/nvmem/core.c | 2 +-
drivers/of/Kconfig | 2 +-
drivers/of/of_path.c | 4 +-
drivers/of/overlay.c | 4 +-
drivers/of/partition.c | 12 +-
drivers/pci/Kconfig | 2 +-
drivers/serial/Kconfig | 4 +-
drivers/serial/efi-stdio.c | 23 +-
drivers/usb/storage/usb.c | 1 +
drivers/video/Kconfig | 3 +-
drivers/virtio/virtio.c | 1 +
drivers/watchdog/Kconfig | 2 +-
efi/Kconfig | 48 ++
{common/efi => efi}/Makefile | 2 +-
{common/efi => efi}/devicepath.c | 458 ++++++-------
{common/efi => efi}/efivar-filename.c | 0
{common/efi => efi}/errno.c | 1 +
{common/efi => efi}/guid.c | 36 +-
efi/payload/Makefile | 11 +
efi/payload/boarddata.c | 45 ++
efi/payload/early-mem.c | 28 +
efi/payload/entry-multi.c | 45 ++
efi/payload/entry-single.c | 45 ++
.../payload/env-efi/network/eth0-discover | 0
{common/efi => efi}/payload/fdt.c | 5 +-
{common/efi => efi}/payload/image.c | 104 ++-
{common/efi => efi}/payload/init.c | 144 ++--
{common/efi => efi}/payload/iomem.c | 8 +-
fs/Kconfig | 4 +-
fs/devfs-core.c | 2 +-
fs/efi.c | 59 --
fs/efivarfs.c | 2 +-
fs/fs.c | 531 ++++++++-------
include/acpi.h | 3 +-
include/ata_drive.h | 5 +-
include/block.h | 18 +-
include/boarddata.h | 49 ++
include/dirent.h | 5 +
include/driver.h | 21 +
include/efi.h | 617 +++++++++++-------
include/efi/device-path.h | 258 ++++----
include/efi/efi-device.h | 19 +-
include/efi/efi-init.h | 51 ++
include/efi/efi-mode.h | 30 +
include/efi/efi-payload.h | 13 +-
include/efi/efi-stdio.h | 11 +-
include/efi/efi-util.h | 8 +-
include/efi/partition.h | 6 +-
include/efi/types.h | 68 ++
include/errno.h | 7 +
include/fcntl.h | 22 +-
include/filetype.h | 6 +-
include/fs.h | 6 +-
include/libfile.h | 4 +
include/linux/export.h | 2 +-
include/linux/hidden.h | 19 +
include/linux/namei.h | 13 -
include/linux/pagemap.h | 1 +
include/linux/pe.h | 482 ++++++++++++++
include/linux/string.h | 1 +
include/partitions.h | 2 +
include/pbl.h | 4 +
include/pe.h | 124 ++++
include/string.h | 13 +
include/sys/stat.h | 8 +-
include/uapi/spec/dps.h | 370 +++++++++++
include/unistd.h | 35 +-
lib/libfile.c | 59 +-
lib/parameter.c | 22 +-
lib/string.c | 49 ++
lib/uuid.c | 63 ++
lib/vsprintf.c | 47 +-
pbl/Kconfig | 7 +
scripts/Makefile.lib | 5 +
scripts/Makefile.pic | 22 +
test/self/Kconfig | 5 +
test/self/Makefile | 1 +
test/self/dirfd.c | 129 ++++
test/self/mmu.c | 7 +
test/self/string.c | 28 +
149 files changed, 4545 insertions(+), 1520 deletions(-)
create mode 100644 arch/arm/cpu/efi-header-aarch64.S
create mode 100644 commands/efi_handle_dump.c
create mode 100644 commands/findmnt.c
create mode 100644 commands/kallsyms.c
delete mode 100644 common/efi/Kconfig
delete mode 100644 common/efi/payload/Makefile
create mode 100644 common/pe.c
create mode 100644 drivers/efi/efi-handle.c
create mode 100644 efi/Kconfig
rename {common/efi => efi}/Makefile (80%)
rename {common/efi => efi}/devicepath.c (50%)
rename {common/efi => efi}/efivar-filename.c (100%)
rename {common/efi => efi}/errno.c (99%)
rename {common/efi => efi}/guid.c (77%)
create mode 100644 efi/payload/Makefile
create mode 100644 efi/payload/boarddata.c
create mode 100644 efi/payload/early-mem.c
create mode 100644 efi/payload/entry-multi.c
create mode 100644 efi/payload/entry-single.c
rename {common/efi => efi}/payload/env-efi/network/eth0-discover (100%)
rename {common/efi => efi}/payload/fdt.c (90%)
rename {common/efi => efi}/payload/image.c (76%)
rename {common/efi => efi}/payload/init.c (77%)
rename {common/efi => efi}/payload/iomem.c (95%)
create mode 100644 include/boarddata.h
create mode 100644 include/efi/efi-init.h
create mode 100644 include/efi/efi-mode.h
create mode 100644 include/efi/types.h
create mode 100644 include/linux/hidden.h
create mode 100644 include/linux/pe.h
create mode 100644 include/pe.h
create mode 100644 include/uapi/spec/dps.h
create mode 100644 scripts/Makefile.pic
create mode 100644 test/self/dirfd.c
--
2.39.2
^ permalink raw reply [flat|nested] 115+ messages in thread
* [PATCH v2 001/113] string: implement strcmp_ptr and streq_ptr helpers
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 002/113] commands: efiexit: flush console and shutdown barebox Ahmad Fatoum
` (112 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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] 115+ messages in thread
* [PATCH v2 002/113] commands: efiexit: flush console and shutdown barebox
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 001/113] string: implement strcmp_ptr and streq_ptr helpers Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 003/113] treewide: add errno_set helper for returning positive error code in errno Ahmad Fatoum
` (111 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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 e2f763853fed..bb4c156d686d 100644
--- a/common/efi/payload/init.c
+++ b/common/efi/payload/init.c
@@ -429,16 +429,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] 115+ messages in thread
* [PATCH v2 003/113] treewide: add errno_set helper for returning positive error code in errno
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 001/113] string: implement strcmp_ptr and streq_ptr helpers Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 002/113] commands: efiexit: flush console and shutdown barebox Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 004/113] vsprintf: guard against NULL in UUID %pU Ahmad Fatoum
` (110 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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 dc80f3f85828..c587d10eabcc 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] 115+ messages in thread
* [PATCH v2 004/113] vsprintf: guard against NULL in UUID %pU
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (2 preceding siblings ...)
2024-03-04 18:58 ` [PATCH v2 003/113] treewide: add errno_set helper for returning positive error code in errno Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 005/113] common: add option to poweroff system on failure Ahmad Fatoum
` (109 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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 3dda15868373..b12d04e37885 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -329,6 +329,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] 115+ messages in thread
* [PATCH v2 005/113] common: add option to poweroff system on failure
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (3 preceding siblings ...)
2024-03-04 18:58 ` [PATCH v2 004/113] vsprintf: guard against NULL in UUID %pU Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 006/113] boot: print error code when booting fails Ahmad Fatoum
` (108 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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 d16c8696dad4..cb0fef46ccbe 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] 115+ messages in thread
* [PATCH v2 006/113] boot: print error code when booting fails
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (4 preceding siblings ...)
2024-03-04 18:58 ` [PATCH v2 005/113] common: add option to poweroff system on failure Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 007/113] common: efi: move directory to top-level Ahmad Fatoum
` (107 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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] 115+ messages in thread
* [PATCH v2 007/113] common: efi: move directory to top-level
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (5 preceding siblings ...)
2024-03-04 18:58 ` [PATCH v2 006/113] boot: print error code when booting fails Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 008/113] efi: payload: rename CONFIG_EFI_BOOTUP to CONFIG_EFI_PAYLOAD Ahmad Fatoum
` (106 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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 6c70767e9070..358cd4140ce8 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 cb0fef46ccbe..a7034a166189 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1800,8 +1800,6 @@ config WERROR
endmenu
-source "common/efi/Kconfig"
-
config HAS_DEBUG_LL
bool
diff --git a/common/Makefile b/common/Makefile
index c31cbab9e48f..42edb40999b1 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] 115+ messages in thread
* [PATCH v2 008/113] efi: payload: rename CONFIG_EFI_BOOTUP to CONFIG_EFI_PAYLOAD
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (6 preceding siblings ...)
2024-03-04 18:58 ` [PATCH v2 007/113] common: efi: move directory to top-level Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 009/113] efi: payload: image: return actual read_file() error Ahmad Fatoum
` (105 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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 b982ea32cb3a..85f7e067d09a 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -46,5 +46,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 fd85ac91b266..7b94a76c5687 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 430cc6a4e7ab..13e9ff6924bb 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -285,7 +285,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 71f6103f0e69..2791100a2d9c 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] 115+ messages in thread
* [PATCH v2 009/113] efi: payload: image: return actual read_file() error
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (7 preceding siblings ...)
2024-03-04 18:58 ` [PATCH v2 008/113] efi: payload: rename CONFIG_EFI_BOOTUP to CONFIG_EFI_PAYLOAD Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 010/113] of: don't report failure to of_read_file twice Ahmad Fatoum
` (104 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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] 115+ messages in thread
* [PATCH v2 010/113] of: don't report failure to of_read_file twice
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (8 preceding siblings ...)
2024-03-04 18:58 ` [PATCH v2 009/113] efi: payload: image: return actual read_file() error Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 011/113] efi: payload: make missing state reporting less verbose Ahmad Fatoum
` (103 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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 bb4c156d686d..6e5ddfd22beb 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -400,10 +400,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] 115+ messages in thread
* [PATCH v2 011/113] efi: payload: make missing state reporting less verbose
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (9 preceding siblings ...)
2024-03-04 18:58 ` [PATCH v2 010/113] of: don't report failure to of_read_file twice Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 012/113] libfile: factor out read_file_into_buf helper Ahmad Fatoum
` (102 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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 6e5ddfd22beb..9afb11fd94a5 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -386,28 +386,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] 115+ messages in thread
* [PATCH v2 012/113] libfile: factor out read_file_into_buf helper
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (10 preceding siblings ...)
2024-03-04 18:58 ` [PATCH v2 011/113] efi: payload: make missing state reporting less verbose Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 013/113] efi: payload: image: allocate image via loader if it exceeds malloc area Ahmad Fatoum
` (101 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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] 115+ messages in thread
* [PATCH v2 013/113] efi: payload: image: allocate image via loader if it exceeds malloc area
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (11 preceding siblings ...)
2024-03-04 18:58 ` [PATCH v2 012/113] libfile: factor out read_file_into_buf helper Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 014/113] efi: payload: image: use assigned barebox loader type on x86 Ahmad Fatoum
` (100 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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] 115+ messages in thread
* [PATCH v2 014/113] efi: payload: image: use assigned barebox loader type on x86
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (12 preceding siblings ...)
2024-03-04 18:58 ` [PATCH v2 013/113] efi: payload: image: allocate image via loader if it exceeds malloc area Ahmad Fatoum
@ 2024-03-04 18:58 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 015/113] efi: payload: iomem: adjust types to avoid casting Ahmad Fatoum
` (99 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:58 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] 115+ messages in thread
* [PATCH v2 015/113] efi: payload: iomem: adjust types to avoid casting
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (13 preceding siblings ...)
2024-03-04 18:58 ` [PATCH v2 014/113] efi: payload: image: use assigned barebox loader type on x86 Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 016/113] commands: kallsyms: add command-line interface Ahmad Fatoum
` (98 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 016/113] commands: kallsyms: add command-line interface
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (14 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 015/113] efi: payload: iomem: adjust types to avoid casting Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 017/113] block: define BLOCKSIZE globally in block.h Ahmad Fatoum
` (97 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 d8bcb573fd43..04bfc85a951d 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2199,6 +2199,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 b3114102765c..8fdff75a72a6 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] 115+ messages in thread
* [PATCH v2 017/113] block: define BLOCKSIZE globally in block.h
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (15 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 016/113] commands: kallsyms: add command-line interface Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 018/113] cdev: implement setter/getter for cdev device node Ahmad Fatoum
` (96 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 98ed67e96674..faf0e7c0cbe5 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 aaaa97400f3a..e27579cdbd49 100644
--- a/include/block.h
+++ b/include/block.h
@@ -37,6 +37,8 @@ struct block_device {
bool need_reparse;
};
+#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] 115+ messages in thread
* [PATCH v2 018/113] cdev: implement setter/getter for cdev device node
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (16 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 017/113] block: define BLOCKSIZE globally in block.h Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 019/113] block: virtio: assign virtio-mmio device tree node to cdevs Ahmad Fatoum
` (95 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 7c9f443ee7bd..729ea238b97d 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 87d4591d99c5..376c62be9eab 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 b7c950620bca..cda1dfac9dac 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -578,6 +578,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] 115+ messages in thread
* [PATCH v2 019/113] block: virtio: assign virtio-mmio device tree node to cdevs
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (17 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 018/113] cdev: implement setter/getter for cdev device node Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 020/113] commands: stat: print DT node for cdevs if available Ahmad Fatoum
` (94 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 020/113] commands: stat: print DT node for cdevs if available
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (18 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 019/113] block: virtio: assign virtio-mmio device tree node to cdevs Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 021/113] partitions: have parsers record bootable bits Ahmad Fatoum
` (93 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 021/113] partitions: have parsers record bootable bits
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (19 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 020/113] commands: stat: print DT node for cdevs if available Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 022/113] commands: stat: display bootable partition table bit info Ahmad Fatoum
` (92 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 ++++++++++++++++++
include/driver.h | 5 +++++
include/efi/partition.h | 6 ++++--
include/partitions.h | 2 ++
6 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/common/partitions.c b/common/partitions.c
index 7bcd0973b8ff..5b861c40fca3 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -50,8 +50,8 @@ static int register_one_partition(struct block_device *blk, struct partition *pa
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 1b0051f9784f..8e4edd885bfa 100644
--- a/common/partitions/dos.c
+++ b/common/partitions/dos.c
@@ -189,6 +189,15 @@ static void dos_extended_partition(struct block_device *blk, struct dos_partitio
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
@@ -237,6 +246,7 @@ static struct partition_desc *dos_partition(void *buf, struct block_device *blk)
pentry->first_sec = first_sec;
pentry->size = get_unaligned_le32(&table[i].partition_size);
pentry->dos_partition_type = table[i].type;
+ extract_flags(&table[i], pentry);
pentry->num = i;
sprintf(pentry->partuuid, "%08x-%02d", signature, i + 1);
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 703d23c71524..9df40e3c15f3 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -444,6 +444,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 part_get_efi_name(gpt_entry *pte, const char *src)
{
int i;
@@ -498,6 +515,7 @@ static struct partition_desc *efi_partition(void *buf, struct block_device *blk)
epart = xzalloc(sizeof(*epart));
epart->pte = &ptes[i];
pentry = &epart->part;
+ 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/include/driver.h b/include/driver.h
index cda1dfac9dac..54b30d9921e0 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -565,6 +565,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;
@@ -637,6 +638,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 184b4fd961dd..8ce62c859b12 100644
--- a/include/efi/partition.h
+++ b/include/efi/partition.h
@@ -101,8 +101,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))
diff --git a/include/partitions.h b/include/partitions.h
index b5379db92a03..785fb77ab167 100644
--- a/include/partitions.h
+++ b/include/partitions.h
@@ -26,6 +26,8 @@ struct partition {
};
struct list_head list;
int num;
+ unsigned int flags;
+ unsigned int typeflags;
};
struct partition_parser;
--
2.39.2
^ permalink raw reply [flat|nested] 115+ messages in thread
* [PATCH v2 022/113] commands: stat: display bootable partition table bit info
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (20 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 021/113] partitions: have parsers record bootable bits Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 023/113] block: record block device type Ahmad Fatoum
` (91 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 023/113] block: record block device type
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (21 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 022/113] commands: stat: display bootable partition table bit info Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 024/113] include: add definitions for UAPI discoverable partitions spec Ahmad Fatoum
` (90 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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>
---
v1 -> v2:
- fix typo breaking compilation of disk_ata_drive.c
---
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 faf0e7c0cbe5..c7ca4fb4034a 100644
--- a/common/block.c
+++ b/common/block.c
@@ -495,3 +495,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..a49acc1641da 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;
+ port->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 e27579cdbd49..a0f226c7649f 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] 115+ messages in thread
* [PATCH v2 024/113] include: add definitions for UAPI discoverable partitions spec
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (22 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 023/113] block: record block device type Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 025/113] efi: payload: restrict 8250 UART at I/O port 0x3f8 registration to x86 Ahmad Fatoum
` (89 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 025/113] efi: payload: restrict 8250 UART at I/O port 0x3f8 registration to x86
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (23 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 024/113] include: add definitions for UAPI discoverable partitions spec Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 026/113] fs: fix unreaddir, so readdir returns unread dirent first Ahmad Fatoum
` (88 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 9afb11fd94a5..5f2cb085da90 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] 115+ messages in thread
* [PATCH v2 026/113] fs: fix unreaddir, so readdir returns unread dirent first
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (24 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 025/113] efi: payload: restrict 8250 UART at I/O port 0x3f8 registration to x86 Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 027/113] fs: turn creat into static inline helper Ahmad Fatoum
` (87 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 027/113] fs: turn creat into static inline helper
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (25 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 026/113] fs: fix unreaddir, so readdir returns unread dirent first Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 028/113] fs: drop unused LOOKUP_ flags Ahmad Fatoum
` (86 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 028/113] fs: drop unused LOOKUP_ flags
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (26 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 027/113] fs: turn creat into static inline helper Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 029/113] fs: opendir: reference mount point until closedir is called Ahmad Fatoum
` (85 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 029/113] fs: opendir: reference mount point until closedir is called
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (27 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 028/113] fs: drop unused LOOKUP_ flags Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 030/113] fs: factor out opendir iteration Ahmad Fatoum
` (84 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 030/113] fs: factor out opendir iteration
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (28 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 029/113] fs: opendir: reference mount point until closedir is called Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 031/113] fs: implement fdopendir and rewinddir Ahmad Fatoum
` (83 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 031/113] fs: implement fdopendir and rewinddir
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (29 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 030/113] fs: factor out opendir iteration Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 032/113] fs: remove unused member from struct nameidata Ahmad Fatoum
` (82 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 032/113] fs: remove unused member from struct nameidata
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (30 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 031/113] fs: implement fdopendir and rewinddir Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 033/113] fs: always check path_init for errors Ahmad Fatoum
` (81 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 033/113] fs: always check path_init for errors
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (31 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 032/113] fs: remove unused member from struct nameidata Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 034/113] fs: set current working dir directly when mounting root Ahmad Fatoum
` (80 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 034/113] fs: set current working dir directly when mounting root
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (32 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 033/113] fs: always check path_init for errors Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 035/113] fs: implement openat and friends Ahmad Fatoum
` (79 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 035/113] fs: implement openat and friends
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (33 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 034/113] fs: set current working dir directly when mounting root Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 036/113] fs: implement O_PATH Ahmad Fatoum
` (78 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 036/113] fs: implement O_PATH
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (34 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 035/113] fs: implement openat and friends Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 037/113] fs: support different root directories Ahmad Fatoum
` (77 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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>
---
v1 -> v2:
- rename allow_pathonly to o_path_ok (Sascha)
---
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..cda1f39519fe 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 o_path_ok)
{
if (fd < 0 || fd >= MAX_FILES || !files[fd].in_use) {
errno = EBADF;
return ERR_PTR(-errno);
}
+ if (!o_path_ok && (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] 115+ messages in thread
* [PATCH v2 037/113] fs: support different root directories
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (35 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 036/113] fs: implement O_PATH Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 038/113] fs: implement O_CHROOT Ahmad Fatoum
` (76 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 cda1f39519fe..7aa8a5d69b25 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] 115+ messages in thread
* [PATCH v2 038/113] fs: implement O_CHROOT
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (36 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 037/113] fs: support different root directories Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 039/113] commands: introduce new findmnt command Ahmad Fatoum
` (75 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 7aa8a5d69b25..9b876fe1f9be 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] 115+ messages in thread
* [PATCH v2 039/113] commands: introduce new findmnt command
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (37 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 038/113] fs: implement O_CHROOT Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 040/113] fs: initialize struct nameidata::last Ahmad Fatoum
` (74 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 04bfc85a951d..9df3c67d930d 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_PARTED
tristate
depends on PARTITION
diff --git a/commands/Makefile b/commands/Makefile
index 8fdff75a72a6..19c006101dc6 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 9b876fe1f9be..0ff7f1b6f947 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 54b30d9921e0..7ff65d63946d 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -590,6 +590,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] 115+ messages in thread
* [PATCH v2 040/113] fs: initialize struct nameidata::last
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (38 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 039/113] commands: introduce new findmnt command Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 041/113] fs: support opening / Ahmad Fatoum
` (73 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 0ff7f1b6f947..acd89dd1c9a4 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] 115+ messages in thread
* [PATCH v2 041/113] fs: support opening /
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (39 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 040/113] fs: initialize struct nameidata::last Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 042/113] test: self: add dirfd tests Ahmad Fatoum
` (72 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 acd89dd1c9a4..fa1d01d892dc 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] 115+ messages in thread
* [PATCH v2 042/113] test: self: add dirfd tests
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (40 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 041/113] fs: support opening / Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 043/113] commands: stat: add option for statat Ahmad Fatoum
` (71 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 043/113] commands: stat: add option for statat
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (41 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 042/113] test: self: add dirfd tests Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 044/113] efi: payload: lower command line options print from error to info Ahmad Fatoum
` (70 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 9df3c67d930d..269d2432b45e 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1011,12 +1011,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 fa1d01d892dc..3bd476713595 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] 115+ messages in thread
* [PATCH v2 044/113] efi: payload: lower command line options print from error to info
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (42 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 043/113] commands: stat: add option for statat Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 045/113] efi: payload: init: warn if /boot FS is unknown Ahmad Fatoum
` (69 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 045/113] efi: payload: init: warn if /boot FS is unknown
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (43 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 044/113] efi: payload: lower command line options print from error to info Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 046/113] commands: time: switch to using getopt for -n Ahmad Fatoum
` (68 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 5f2cb085da90..592cf662d540 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>
@@ -396,6 +398,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] 115+ messages in thread
* [PATCH v2 046/113] commands: time: switch to using getopt for -n
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (44 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 045/113] efi: payload: init: warn if /boot FS is unknown Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 047/113] commands: time: reduce strjoin runtime, drop trailing space Ahmad Fatoum
` (67 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Now that we have support for the stop-at-first-non-option scanning mode
indicated by a leading `+', there is nothing preventing us from using
getopt for the time command. This rids us of interleaving argument
parsing with the command's processing, has the command behave as one
would expect, e.g. if multiple -n arguments are specified and allows for
easier future extension.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
- new patch
---
commands/time.c | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/commands/time.c b/commands/time.c
index 5b8933ea6553..72647a3bb876 100644
--- a/commands/time.c
+++ b/commands/time.c
@@ -5,30 +5,38 @@
#include <clock.h>
#include <linux/math64.h>
#include <malloc.h>
+#include <getopt.h>
static int do_time(int argc, char *argv[])
{
- int i;
+ int i, opt;
unsigned char *buf;
u64 start, end, diff64;
bool nanoseconds = false;
int len = 1; /* '\0' */
- if (argc < 2)
+ while ((opt = getopt(argc, argv, "+n")) > 0) {
+ switch (opt) {
+ case 'n':
+ nanoseconds = true;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ argv += optind;
+ argc -= optind;
+
+ if (argc < 1)
return COMMAND_ERROR_USAGE;
- for (i = 1; i < argc; i++)
+ for (i = 0; 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++) {
+ for (i = 0; i < argc; i++) {
strcat(buf, argv[i]);
strcat(buf, " ");
}
--
2.39.2
^ permalink raw reply [flat|nested] 115+ messages in thread
* [PATCH v2 047/113] commands: time: reduce strjoin runtime, drop trailing space
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (45 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 046/113] commands: time: switch to using getopt for -n Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 048/113] commands: time: refactor into new strjoin Ahmad Fatoum
` (66 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
time concatenates its arguments to pass it to run_command in a
suboptimal manner: The destination string is traversed from the
beginning on every iteration due to strcat and we have a left-over
separator at the end, while it's only needed in-between.
In preparation for factoring the code out as a library strjoin function,
fix these shortcomings.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
- swapped order with follow-up commit (Sascha)
---
commands/time.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/commands/time.c b/commands/time.c
index 72647a3bb876..0a38db61845d 100644
--- a/commands/time.c
+++ b/commands/time.c
@@ -10,7 +10,7 @@
static int do_time(int argc, char *argv[])
{
int i, opt;
- unsigned char *buf;
+ unsigned char *buf, *p;
u64 start, end, diff64;
bool nanoseconds = false;
int len = 1; /* '\0' */
@@ -34,13 +34,15 @@ static int do_time(int argc, char *argv[])
for (i = 0; i < argc; i++)
len += strlen(argv[i]) + 1;
- buf = xzalloc(len);
+ p = buf = xmalloc(len);
- for (i = 0; i < argc; i++) {
- strcat(buf, argv[i]);
- strcat(buf, " ");
+ for (i = 0; i < argc - 1; i++) {
+ p = stpcpy(p, argv[i]);
+ p = mempcpy(p, " ", strlen(" "));
}
+ stpcpy(p, argv[i]);
+
start = get_time_ns();
run_command(buf);
--
2.39.2
^ permalink raw reply [flat|nested] 115+ messages in thread
* [PATCH v2 048/113] commands: time: refactor into new strjoin
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (46 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 047/113] commands: time: reduce strjoin runtime, drop trailing space Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 049/113] test: self: add strjoin tests Ahmad Fatoum
` (65 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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>
---
v1 -> v2:
- swapped order with previous commit (Sascha)
Originally posted at: https://lore.barebox.org/barebox/20221027073334.GS6702@pengutronix.de/
Changes:
- remove if statemnt in loop (Sascha)
---
commands/time.c | 17 +++--------------
include/string.h | 2 ++
lib/string.c | 28 ++++++++++++++++++++++++++++
3 files changed, 33 insertions(+), 14 deletions(-)
diff --git a/commands/time.c b/commands/time.c
index 0a38db61845d..a3f270407122 100644
--- a/commands/time.c
+++ b/commands/time.c
@@ -9,11 +9,10 @@
static int do_time(int argc, char *argv[])
{
- int i, opt;
- unsigned char *buf, *p;
+ int opt;
+ unsigned char *buf;
u64 start, end, diff64;
bool nanoseconds = false;
- int len = 1; /* '\0' */
while ((opt = getopt(argc, argv, "+n")) > 0) {
switch (opt) {
@@ -31,17 +30,7 @@ static int do_time(int argc, char *argv[])
if (argc < 1)
return COMMAND_ERROR_USAGE;
- for (i = 0; i < argc; i++)
- len += strlen(argv[i]) + 1;
-
- p = buf = xmalloc(len);
-
- for (i = 0; i < argc - 1; i++) {
- p = stpcpy(p, argv[i]);
- p = mempcpy(p, " ", strlen(" "));
- }
-
- stpcpy(p, argv[i]);
+ buf = strjoin(" ", argv, argc);
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..695e50bc8fc1 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -1000,3 +1000,31 @@ 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, *p;
+ int i;
+
+ separatorlen = strlen(separator);
+
+ for (i = 0; i < arrlen; i++)
+ len += strlen(arr[i]) + separatorlen;
+
+ if (!arrlen)
+ return xzalloc(1);
+
+ 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] 115+ messages in thread
* [PATCH v2 049/113] test: self: add strjoin tests
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (47 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 048/113] commands: time: refactor into new strjoin Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 050/113] filetype: have cdev_detect_type take a cdev Ahmad Fatoum
` (64 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 050/113] filetype: have cdev_detect_type take a cdev
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (48 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 049/113] test: self: add strjoin tests Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 051/113] ARM: mmu-early: gracefully handle already enabled MMU Ahmad Fatoum
` (63 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 7f1ce20d0094..ba0f61e5d87e 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -456,20 +456,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);
@@ -482,8 +476,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 3bd476713595..341cf62bbca7 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 a1f98f2a983a..f73b2da61f5a 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -66,13 +66,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] 115+ messages in thread
* [PATCH v2 051/113] ARM: mmu-early: gracefully handle already enabled MMU
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (49 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 050/113] filetype: have cdev_detect_type take a cdev Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 052/113] efi: don't hide structs, enums or unions behind _t Ahmad Fatoum
` (62 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 12cd644de0c7..f907421da998 100644
--- a/arch/arm/cpu/mmu_64.c
+++ b/arch/arm/cpu/mmu_64.c
@@ -314,6 +314,9 @@ void mmu_early_enable(unsigned long membase, unsigned long memsize)
u64 optee_membase;
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] 115+ messages in thread
* [PATCH v2 052/113] efi: don't hide structs, enums or unions behind _t
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (50 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 051/113] ARM: mmu-early: gracefully handle already enabled MMU Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 053/113] efi: make headers self-contained Ahmad Fatoum
` (61 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 0d11b604ae5d..b6d618815810 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;
@@ -212,7 +212,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 592cf662d540..557bf033a4a2 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)
{
@@ -270,7 +270,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] 115+ messages in thread
* [PATCH v2 053/113] efi: make headers self-contained
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (51 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 052/113] efi: don't hide structs, enums or unions behind _t Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 054/113] efi: unify whitespace for GUIDs Ahmad Fatoum
` (60 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 054/113] efi: unify whitespace for GUIDs
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (52 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 053/113] efi: make headers self-contained Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 055/113] efi: efi-guid: add more GUIDs Ahmad Fatoum
` (59 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 055/113] efi: efi-guid: add more GUIDs
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (53 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 054/113] efi: unify whitespace for GUIDs Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 056/113] ARM64: cpu: setupc: rewrite to be fully PIC Ahmad Fatoum
` (58 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 056/113] ARM64: cpu: setupc: rewrite to be fully PIC
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (54 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 055/113] efi: efi-guid: add more GUIDs Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 057/113] ARM64: runtime-offset: make get_runtime_offset " Ahmad Fatoum
` (57 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 057/113] ARM64: runtime-offset: make get_runtime_offset fully PIC
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (55 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 056/113] ARM64: cpu: setupc: rewrite to be fully PIC Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 058/113] pbl: introduce CONFIG_PBL_FULLY_PIC Ahmad Fatoum
` (56 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 058/113] pbl: introduce CONFIG_PBL_FULLY_PIC
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (56 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 057/113] ARM64: runtime-offset: make get_runtime_offset " Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 059/113] efi: payload: fix ARM build Ahmad Fatoum
` (55 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 223bf0640e1b..669a49a530a2 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 "Verify barebox proper hash before decompression" if COMPILE_TEST
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index f205e08afc13..6b1f0ccbc003 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] 115+ messages in thread
* [PATCH v2 059/113] efi: payload: fix ARM build
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (57 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 058/113] pbl: introduce CONFIG_PBL_FULLY_PIC Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 060/113] efi: payload: init: restrict barebox mem to first 1G only on x86 Ahmad Fatoum
` (54 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 060/113] efi: payload: init: restrict barebox mem to first 1G only on x86
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (58 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 059/113] efi: payload: fix ARM build Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 061/113] efi: add efi_is_loader/efi_is_payload helpers Ahmad Fatoum
` (53 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 557bf033a4a2..dedecbf92cec 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -293,7 +293,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] 115+ messages in thread
* [PATCH v2 061/113] efi: add efi_is_loader/efi_is_payload helpers
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (59 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 060/113] efi: payload: init: restrict barebox mem to first 1G only on x86 Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 062/113] efi: payload: suppress EFI payload initcalls when not EFI-loaded Ahmad Fatoum
` (52 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 062/113] efi: payload: suppress EFI payload initcalls when not EFI-loaded
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (60 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 061/113] efi: add efi_is_loader/efi_is_payload helpers Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 063/113] ARM: make board data definitions accessible to other architectures Ahmad Fatoum
` (51 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 b6d618815810..593617073345 100644
--- a/drivers/bus/acpi.c
+++ b/drivers/bus/acpi.c
@@ -233,4 +233,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 dedecbf92cec..9bc0741e044b 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[],
@@ -265,7 +265,7 @@ static int efi_init(void)
return 0;
}
-device_initcall(efi_init);
+device_efi_initcall(efi_init);
/**
* efi-main - Entry point for EFI images
@@ -325,7 +325,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)
@@ -385,7 +385,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)
{
@@ -434,10 +434,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] 115+ messages in thread
* [PATCH v2 063/113] ARM: make board data definitions accessible to other architectures
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (61 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 062/113] efi: payload: suppress EFI payload initcalls when not EFI-loaded Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 064/113] boarddata: add barebox_boarddata_is_machine helper Ahmad Fatoum
` (50 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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 361edcf37eef..7a7e5a240317 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] 115+ messages in thread
* [PATCH v2 064/113] boarddata: add barebox_boarddata_is_machine helper
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (62 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 063/113] ARM: make board data definitions accessible to other architectures Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 065/113] common: add PE/COFF loader Ahmad Fatoum
` (49 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 065/113] common: add PE/COFF loader
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (63 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 064/113] boarddata: add barebox_boarddata_is_machine helper Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 066/113] efi: use efi_handle_t where appropriate Ahmad Fatoum
` (48 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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>
---
v1 -> v2:
- replace use of pe.h header originating from Wine with <linux/pe.h>
---
common/Kconfig | 3 +
common/Makefile | 1 +
common/pe.c | 379 +++++++++++++++++++++++++++++++
include/linux/pagemap.h | 1 +
include/linux/pe.h | 482 ++++++++++++++++++++++++++++++++++++++++
include/pe.h | 124 +++++++++++
6 files changed, 990 insertions(+)
create mode 100644 common/pe.c
create mode 100644 include/linux/pe.h
create mode 100644 include/pe.h
diff --git a/common/Kconfig b/common/Kconfig
index a7034a166189..33903aa249b7 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -623,6 +623,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 42edb40999b1..2fc4a703c8c4 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..5c33665dfa74
--- /dev/null
+++ b/common/pe.c
@@ -0,0 +1,379 @@
+// 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)
+{
+ struct mz_hdr *dos = buffer;
+ IMAGE_NT_HEADERS32 *nt;
+
+ if (size < sizeof(*dos))
+ return -EINVAL;
+
+ /* Check for DOS magix */
+ if (dos->magic != MZ_MAGIC)
+ 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->peaddr + sizeof(IMAGE_NT_HEADERS32))
+ return -EINVAL;
+ nt = (IMAGE_NT_HEADERS32 *)((u8 *)buffer + dos->peaddr);
+
+ /* Check for PE-COFF magic */
+ if (nt->FileHeader.magic != PE_MAGIC)
+ 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.sections;
+ pe->sections = (void *)&pe->nt->OptionalHeader +
+ pe->nt->FileHeader.opt_hdr_size;
+
+ 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 ERR_PTR(-errno);
+
+ pe = pe_open_buf(bin, size);
+ if (IS_ERR(pe))
+ free(bin);
+
+ 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 == PE_OPT_MAGIC_PE32PLUS) {
+ IMAGE_NT_HEADERS64 *nt64 = (void *)pe->nt;
+ struct pe32plus_opt_hdr *opt = &nt64->OptionalHeader;
+
+ virt_size = ALIGN(virt_size, opt->section_align);
+ } else if (pe->nt->OptionalHeader.magic == PE_OPT_MAGIC_PE32) {
+ struct pe32_opt_hdr *opt = &pe->nt->OptionalHeader;
+
+ virt_size = ALIGN(virt_size, opt->section_align);
+ } 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;
+ struct mz_hdr *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 == PE_OPT_MAGIC_PE32PLUS) {
+ IMAGE_NT_HEADERS64 *nt64 = (void *)pe->nt;
+ struct pe32plus_opt_hdr *opt = &nt64->OptionalHeader;
+ image_base = opt->image_base;
+ pe->image_type = opt->subsys;
+
+ code = pe_alloc(virt_size);
+ if (!code)
+ return -ENOMEM;
+
+ pe_reloc = (void *)code->start;
+
+ pe->entry = code->start + opt->entry_point;
+ rel_size = nt64->DataDirectory[rel_idx].size;
+ rel = pe_reloc + nt64->DataDirectory[rel_idx].virtual_address;
+ } else if (pe->nt->OptionalHeader.magic == PE_OPT_MAGIC_PE32) {
+ struct pe32_opt_hdr *opt = &pe->nt->OptionalHeader;
+ image_base = opt->image_base;
+ pe->image_type = opt->subsys;
+ virt_size = ALIGN(virt_size, opt->section_align);
+
+ code = pe_alloc(virt_size);
+ if (!code)
+ return -ENOMEM;
+
+ pe_reloc = (void *)code->start;
+
+ pe->entry = code->start + opt->entry_point;
+ rel_size = pe->nt->DataDirectory[rel_idx].size;
+ rel = pe_reloc + pe->nt->DataDirectory[rel_idx].virtual_address;
+ } 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.opt_hdr_size
+ + 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->bin);
+ free(pe);
+}
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..fdf9c95709ba
--- /dev/null
+++ b/include/linux/pe.h
@@ -0,0 +1,482 @@
+/* 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>
+
+/*
+ * Starting from version v3.0, the major version field should be interpreted as
+ * a bit mask of features supported by the kernel's EFI stub:
+ * - 0x1: initrd loading from the LINUX_EFI_INITRD_MEDIA_GUID device path,
+ * - 0x2: initrd loading using the initrd= command line option, where the file
+ * may be specified using device path notation, and is not required to
+ * reside on the same volume as the loaded kernel image.
+ *
+ * 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 may support initrd loading via the image load
+ * options (using initrd=, limited to the volume from which the kernel itself
+ * was loaded), or only via arch specific means (bootparams, DT, etc).
+ *
+ * The minor version field must remain 0x0.
+ * (https://lore.kernel.org/all/efd6f2d4-547c-1378-1faa-53c044dbd297@gmail.com/)
+ */
+#define LINUX_EFISTUB_MAJOR_VERSION 0x3
+#define LINUX_EFISTUB_MINOR_VERSION 0x0
+
+/*
+ * LINUX_PE_MAGIC appears at offset 0x38 into the MS-DOS header of EFI bootable
+ * Linux kernel images that target the architecture as specified by the PE/COFF
+ * header machine type field.
+ */
+#define LINUX_PE_MAGIC 0x818223cd
+
+#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
+#define IMAGE_FILE_MACHINE_LOONGARCH32 0x6232
+#define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264
+
+/* 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
+
+#define IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT 0x0001
+#define IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT 0x0040
+
+/* 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
+#define IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS 20
+
+#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..742dd8235a24
--- /dev/null
+++ b/include/pe.h
@@ -0,0 +1,124 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Portable Executable binary format structures
+ *
+ * Copyright (c) 2016 Alexander Graf
+ *
+ * Based on wine code, adjusted to use <linux/pe.h> defines
+ */
+
+#ifndef _PE_H
+#define _PE_H
+
+#include <linux/pe.h>
+
+#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
+
+typedef struct _IMAGE_NT_HEADERS64 {
+ struct pe_hdr FileHeader;
+ struct pe32plus_opt_hdr OptionalHeader;
+ struct data_dirent DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
+} IMAGE_NT_HEADERS64;
+
+typedef struct _IMAGE_NT_HEADERS {
+ struct pe_hdr FileHeader;
+ struct pe32_opt_hdr OptionalHeader;
+ struct data_dirent DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
+} IMAGE_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;
+
+/* 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;
+
+#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
+
+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] 115+ messages in thread
* [PATCH v2 066/113] efi: use efi_handle_t where appropriate
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (64 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 065/113] common: add PE/COFF loader Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 067/113] efi: block: move definitions into header file Ahmad Fatoum
` (47 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 067/113] efi: block: move definitions into header file
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (65 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 066/113] efi: use efi_handle_t where appropriate Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 068/113] efi: define efi_handle_t as opaque pointer Ahmad Fatoum
` (46 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 068/113] efi: define efi_handle_t as opaque pointer
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (66 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 067/113] efi: block: move definitions into header file Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 069/113] efi: constify guid_t in API Ahmad Fatoum
` (45 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 069/113] efi: constify guid_t in API
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (67 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 068/113] efi: define efi_handle_t as opaque pointer Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 070/113] efi: rename efi_simple_input_interface to efi_simple_text_input_protocol Ahmad Fatoum
` (44 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 070/113] efi: rename efi_simple_input_interface to efi_simple_text_input_protocol
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (68 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 069/113] efi: constify guid_t in API Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 071/113] efi: add EFI_WARN constants Ahmad Fatoum
` (43 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 071/113] efi: add EFI_WARN constants
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (69 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 070/113] efi: rename efi_simple_input_interface to efi_simple_text_input_protocol Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 072/113] efi-stdio: fix wait_for_event argument Ahmad Fatoum
` (42 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 072/113] efi-stdio: fix wait_for_event argument
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (70 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 071/113] efi: add EFI_WARN constants Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 073/113] efi-stdio: wait for extended input key event when using extended input Ahmad Fatoum
` (41 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 073/113] efi-stdio: wait for extended input key event when using extended input
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (71 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 072/113] efi-stdio: fix wait_for_event argument Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 074/113] efi: flesh out EFI definitions in header Ahmad Fatoum
` (40 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 074/113] efi: flesh out EFI definitions in header
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (72 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 073/113] efi-stdio: wait for extended input key event when using extended input Ahmad Fatoum
@ 2024-03-04 18:59 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 075/113] efi: add efi_driver_binding_protocol Ahmad Fatoum
` (39 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 18:59 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] 115+ messages in thread
* [PATCH v2 075/113] efi: add efi_driver_binding_protocol
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (73 preceding siblings ...)
2024-03-04 18:59 ` [PATCH v2 074/113] efi: flesh out EFI definitions in header Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 076/113] efi: improve usability of EFI_PAGE_* macros Ahmad Fatoum
` (38 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 076/113] efi: improve usability of EFI_PAGE_* macros
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (74 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 075/113] efi: add efi_driver_binding_protocol Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 077/113] fs: efi: move definitions into header Ahmad Fatoum
` (37 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 077/113] fs: efi: move definitions into header
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (75 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 076/113] efi: improve usability of EFI_PAGE_* macros Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 078/113] efi: fs: flesh out file system definitions Ahmad Fatoum
` (36 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 078/113] efi: fs: flesh out file system definitions
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (76 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 077/113] fs: efi: move definitions into header Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 079/113] efi: stdio: fix efi_register_keystroke_notify prototype Ahmad Fatoum
` (35 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 079/113] efi: stdio: fix efi_register_keystroke_notify prototype
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (77 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 078/113] efi: fs: flesh out file system definitions Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 080/113] video: mark EFI_GOP driver x86-only for now Ahmad Fatoum
` (34 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 080/113] video: mark EFI_GOP driver x86-only for now
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (78 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 079/113] efi: stdio: fix efi_register_keystroke_notify prototype Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 081/113] filetype: add new file types for EFI-enabled Linux images Ahmad Fatoum
` (33 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 081/113] filetype: add new file types for EFI-enabled Linux images
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (79 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 080/113] video: mark EFI_GOP driver x86-only for now Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 082/113] efi: payload: register handler for EFI-stubbed ARM64 kernel Ahmad Fatoum
` (32 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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>
---
v1 -> v2:
- fix typo in RISC-V bootm code
---
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..a6655b8aafb1 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_efi_linux_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 ba0f61e5d87e..f922494500d5 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -63,7 +63,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" },
@@ -251,6 +253,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)
@@ -313,9 +320,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)
@@ -373,7 +380,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 f73b2da61f5a..6425c9c8c5b9 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] 115+ messages in thread
* [PATCH v2 082/113] efi: payload: register handler for EFI-stubbed ARM64 kernel
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (80 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 081/113] filetype: add new file types for EFI-enabled Linux images Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 083/113] efi: payload: factor C efi_main into dedicated file Ahmad Fatoum
` (31 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 083/113] efi: payload: factor C efi_main into dedicated file
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (81 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 082/113] efi: payload: register handler for EFI-stubbed ARM64 kernel Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 084/113] efi: payload: early-mem: simplify error message reporting Ahmad Fatoum
` (30 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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 9bc0741e044b..d5ec86fafe1a 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -267,51 +267,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] 115+ messages in thread
* [PATCH v2 084/113] efi: payload: early-mem: simplify error message reporting
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (82 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 083/113] efi: payload: factor C efi_main into dedicated file Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 085/113] efi: payload: early-mem: use EFI_PAGE_SIZE instead of PAGE_SIZE Ahmad Fatoum
` (29 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 085/113] efi: payload: early-mem: use EFI_PAGE_SIZE instead of PAGE_SIZE
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (83 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 084/113] efi: payload: early-mem: simplify error message reporting Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 086/113] ARM64: add optional EFI stub Ahmad Fatoum
` (28 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 086/113] ARM64: add optional EFI stub
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (84 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 085/113] efi: payload: early-mem: use EFI_PAGE_SIZE instead of PAGE_SIZE Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 087/113] efi: devicepath: improve const safety Ahmad Fatoum
` (27 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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>
---
v1 -> v2:
- squash with commit introducing PECOFF_EDATA_PADDING
---
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/memory.h | 20 +++++
arch/arm/include/asm/pci.h | 4 +-
arch/arm/lib/pbl.lds.S | 31 +++++++
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 ++
21 files changed, 337 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 358cd4140ce8..5a4300deadb2 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 86fc912ac49f..1377679ac90c 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/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/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 cafb27b2d55e..ec7296f0fb34 100644
--- a/arch/arm/lib/pbl.lds.S
+++ b/arch/arm/lib/pbl.lds.S
@@ -3,8 +3,27 @@
#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>
+
+/*
+ * 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
@@ -62,7 +81,9 @@ SECTIONS
.barebox_imd : { BAREBOX_IMD }
+ . = ALIGN(PBL_SEGMENT_ALIGN);
_etext = .; /* End of text and rodata section */
+ _sdata = .;
. = ALIGN(4);
.data : { *(.data*) }
@@ -109,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 85f7e067d09a..aab0c3c63261 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -6,6 +6,7 @@ config X86
select HAS_DMA
select GENERIC_FIND_NEXT_BIT
select ARCH_DMA_DEFAULT_COHERENT
+ 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] 115+ messages in thread
* [PATCH v2 087/113] efi: devicepath: improve const safety
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (85 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 086/113] ARM64: add optional EFI stub Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 088/113] efi: refactor device_path_to_partuuid for code reuse Ahmad Fatoum
` (26 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 088/113] efi: refactor device_path_to_partuuid for code reuse
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (86 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 087/113] efi: devicepath: improve const safety Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 089/113] efi: devicepath: implement device_path_to_str_buf variant Ahmad Fatoum
` (25 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 089/113] efi: devicepath: implement device_path_to_str_buf variant
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (87 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 088/113] efi: refactor device_path_to_partuuid for code reuse Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 090/113] lib: vsprintf: align documentation with current feature set Ahmad Fatoum
` (24 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 090/113] lib: vsprintf: align documentation with current feature set
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (88 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 089/113] efi: devicepath: implement device_path_to_str_buf variant Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 091/113] vsprintf: add %pD for printing EFI device path Ahmad Fatoum
` (23 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The documentation lists modifiers unsupported by barebox and lacks
modifiers that are actually supported. Align the documentation with the
currently supported feature set and reorder it to the same order used
inside the pointer() main switch statement.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
- new patch
---
lib/vsprintf.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index b12d04e37885..4458616e442b 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -472,8 +472,6 @@ char *device_node_string(char *buf, const char *end, const struct device_node *n
*
* Right now we handle:
*
- * - 'I' [4] for IPv4 addresses printed in the usual way
- * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
* - 'S' For symbolic direct pointers
* - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form
* "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@@ -493,12 +491,18 @@ char *device_node_string(char *buf, const char *end, const struct device_node *n
* correctness of the format string and va_list arguments.
* - 'a[pd]' For address types [p] phys_addr_t, [d] dma_addr_t and derivatives
* (default assumed to be phys_addr_t, passed by reference)
+ * - 'I' [4] for IPv4 addresses printed in the usual way
+ * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
+ * - 'e' For formatting error pointers as string descriptions
+ * - 'OF' For a device tree node
+ * - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with
+ * a certain separator (' ' by default):
+ * C colon
+ * D dash
+ * N no separator
+ * - 'JP' For a JSON path
* - 'M' For a 6-byte MAC address, it prints the address in the
* usual colon-separated hex notation
- *
- * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
- * function pointers are really function descriptors, which contain a
- * pointer to the real address.
*/
static char *pointer(const char *fmt, char *buf, const char *end, const void *ptr,
int field_width, int precision, int flags)
@@ -573,10 +577,11 @@ static char *errno_string(char *buf, const char *end, int field_width, int preci
* @fmt: The format string to use
* @args: Arguments for the format string
*
- * This function follows C99 vsnprintf, but has some extensions:
- * %pS output the name of a text symbol
- * %pF output the name of a function pointer
- * %pR output the address range in a struct resource
+ * This function generally follows C99 vsnprintf, but has some
+ * extensions and a few limitations:
+ *
+ * - ``%n`` is unsupported
+ * - ``%p*`` is handled by pointer()
*
* The return value is the number of characters which would
* be generated for the given input, excluding the trailing
--
2.39.2
^ permalink raw reply [flat|nested] 115+ messages in thread
* [PATCH v2 091/113] vsprintf: add %pD for printing EFI device path
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (89 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 090/113] lib: vsprintf: align documentation with current feature set Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 092/113] lib: string: import Linux strreplace helper Ahmad Fatoum
` (22 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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>
---
v1 -> v2:
- add documentation for new specifier (Sascha)
---
lib/vsprintf.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 4458616e442b..1b7d568e8f0c 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>
@@ -368,6 +369,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)
@@ -470,7 +480,7 @@ char *device_node_string(char *buf, const char *end, const struct device_node *n
* by an extra set of alphanumeric characters that are extended format
* specifiers.
*
- * Right now we handle:
+ * Right now we handle following Linux-compatible format specifiers:
*
* - 'S' For symbolic direct pointers
* - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form
@@ -503,6 +513,10 @@ char *device_node_string(char *buf, const char *end, const struct device_node *n
* - 'JP' For a JSON path
* - 'M' For a 6-byte MAC address, it prints the address in the
* usual colon-separated hex notation
+ *
+ * Additionally, we support following barebox-specific format specifiers:
+ *
+ * - 'D' For EFI device paths
*/
static char *pointer(const char *fmt, char *buf, const char *end, const void *ptr,
int field_width, int precision, int flags)
@@ -548,6 +562,10 @@ static char *pointer(const char *fmt, char *buf, const char *end, const void *pt
case 'M':
/* Colon separated: 00:01:02:03:04:05 */
return mac_address_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] 115+ messages in thread
* [PATCH v2 092/113] lib: string: import Linux strreplace helper
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (90 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 091/113] vsprintf: add %pD for printing EFI device path Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 093/113] efi: payload: dynamically determine bootloader file name Ahmad Fatoum
` (21 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 093/113] efi: payload: dynamically determine bootloader file name
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (91 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 092/113] lib: string: import Linux strreplace helper Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 094/113] efi: payload: iomem: register later Ahmad Fatoum
` (20 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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 d5ec86fafe1a..0f518d4954cb 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -300,7 +300,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;
@@ -322,8 +325,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",
@@ -335,8 +340,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] 115+ messages in thread
* [PATCH v2 094/113] efi: payload: iomem: register later
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (92 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 093/113] efi: payload: dynamically determine bootloader file name Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 095/113] efi: payload: protect against buggy EFI implementations Ahmad Fatoum
` (19 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 095/113] efi: payload: protect against buggy EFI implementations
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (93 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 094/113] efi: payload: iomem: register later Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 096/113] efi: payload: don't require efi_loaded_image->parent_handle for bootsource detection Ahmad Fatoum
` (18 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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 0f518d4954cb..5701d7ad6dcf 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -328,6 +328,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] 115+ messages in thread
* [PATCH v2 096/113] efi: payload: don't require efi_loaded_image->parent_handle for bootsource detection
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (94 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 095/113] efi: payload: protect against buggy EFI implementations Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 097/113] commands: add cpuinfo -s option for stacktrace Ahmad Fatoum
` (17 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 097/113] commands: add cpuinfo -s option for stacktrace
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (95 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 096/113] efi: payload: don't require efi_loaded_image->parent_handle for bootsource detection Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 098/113] efi: devicepath: align MemoryMapped name with spec Ahmad Fatoum
` (16 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 098/113] efi: devicepath: align MemoryMapped name with spec
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (96 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 097/113] commands: add cpuinfo -s option for stacktrace Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 099/113] efi: devicepath: pretty print BBS BEV DeviceType Ahmad Fatoum
` (15 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 099/113] efi: devicepath: pretty print BBS BEV DeviceType
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (97 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 098/113] efi: devicepath: align MemoryMapped name with spec Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 100/113] efi: devicepath: format GUIDs as little endian Ahmad Fatoum
` (14 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 100/113] efi: devicepath: format GUIDs as little endian
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (98 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 099/113] efi: devicepath: pretty print BBS BEV DeviceType Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 101/113] efi: devicepath: move END device node definitions into header Ahmad Fatoum
` (13 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 101/113] efi: devicepath: move END device node definitions into header
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (99 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 100/113] efi: devicepath: format GUIDs as little endian Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 102/113] efi: devicepath: drop underscores in hex constants Ahmad Fatoum
` (12 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 102/113] efi: devicepath: drop underscores in hex constants
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (100 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 101/113] efi: devicepath: move END device node definitions into header Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 103/113] efi: devicepath: namespace definitions Ahmad Fatoum
` (11 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 103/113] efi: devicepath: namespace definitions
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (101 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 102/113] efi: devicepath: drop underscores in hex constants Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 104/113] efi: devicepath: use flexible array members for trailing strings Ahmad Fatoum
` (10 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 104/113] efi: devicepath: use flexible array members for trailing strings
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (102 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 103/113] efi: devicepath: namespace definitions Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 105/113] efi: devicepath: drop unused macro Ahmad Fatoum
` (9 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 105/113] efi: devicepath: drop unused macro
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (103 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 104/113] efi: devicepath: use flexible array members for trailing strings Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 106/113] efi: devicepath: let compiler worry about unaligned unpacking Ahmad Fatoum
` (8 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 106/113] efi: devicepath: let compiler worry about unaligned unpacking
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (104 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 105/113] efi: devicepath: drop unused macro Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 107/113] efi: devicepath: correct formatting of BBS Ahmad Fatoum
` (7 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 107/113] efi: devicepath: correct formatting of BBS
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (105 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 106/113] efi: devicepath: let compiler worry about unaligned unpacking Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 108/113] commands: provide efi_handle_dump in both payload and loader Ahmad Fatoum
` (6 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 108/113] commands: provide efi_handle_dump in both payload and loader
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (106 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 107/113] efi: devicepath: correct formatting of BBS Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 109/113] lib: uuid: implement uuid/guid_parse Ahmad Fatoum
` (5 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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 | 2 +
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, 247 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 269d2432b45e..8d0816c4d0f0 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 19c006101dc6..30e1f8403eef 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -149,4 +149,6 @@ obj-$(CONFIG_CMD_SELFTEST) += selftest.o
obj-$(CONFIG_CMD_TUTORIAL) += tutorial.o
obj-$(CONFIG_CMD_STACKSMASH) += stacksmash.o
obj-$(CONFIG_CMD_PARTED) += parted.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] 115+ messages in thread
* [PATCH v2 109/113] lib: uuid: implement uuid/guid_parse
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (107 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 108/113] commands: provide efi_handle_dump in both payload and loader Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 110/113] commands: efi_handle_dump: prepare for supporting EFI loader Ahmad Fatoum
` (4 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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 60a651e3301a..1c134bfb4b15 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -9,6 +9,7 @@
#include <linux/uuid.h>
#include <module.h>
#include <stdlib.h>
+#include <linux/ctype.h>
#include <linux/export.h>
const guid_t guid_null;
@@ -16,6 +17,9 @@ 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};
+
/**
* generate_random_uuid - generate a random UUID
* @uuid: where to put the generated UUID
@@ -44,3 +48,62 @@ void generate_random_guid(unsigned char guid[16])
guid[8] = (guid[8] & 0x3F) | 0x80;
}
EXPORT_SYMBOL(generate_random_guid);
+
+/**
+ * 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] 115+ messages in thread
* [PATCH v2 110/113] commands: efi_handle_dump: prepare for supporting EFI loader
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (108 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 109/113] lib: uuid: implement uuid/guid_parse Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 111/113] commands: efi_handle_dump: print loaded image devpath Ahmad Fatoum
` (3 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 111/113] commands: efi_handle_dump: print loaded image devpath
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (109 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 110/113] commands: efi_handle_dump: prepare for supporting EFI loader Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 112/113] commands: efi_handle_dump: use guid_parse instead of open-coding Ahmad Fatoum
` (2 subsequent siblings)
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 112/113] commands: efi_handle_dump: use guid_parse instead of open-coding
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (110 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 111/113] commands: efi_handle_dump: print loaded image devpath Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 113/113] commands: efi_handle_dump: don't ignore failure to parse GUID Ahmad Fatoum
2024-03-05 15:28 ` [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Sascha Hauer
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* [PATCH v2 113/113] commands: efi_handle_dump: don't ignore failure to parse GUID
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (111 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 112/113] commands: efi_handle_dump: use guid_parse instead of open-coding Ahmad Fatoum
@ 2024-03-04 19:00 ` Ahmad Fatoum
2024-03-05 15:28 ` [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Sascha Hauer
113 siblings, 0 replies; 115+ messages in thread
From: Ahmad Fatoum @ 2024-03-04 19:00 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] 115+ messages in thread
* Re: [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
` (112 preceding siblings ...)
2024-03-04 19:00 ` [PATCH v2 113/113] commands: efi_handle_dump: don't ignore failure to parse GUID Ahmad Fatoum
@ 2024-03-05 15:28 ` Sascha Hauer
113 siblings, 0 replies; 115+ messages in thread
From: Sascha Hauer @ 2024-03-05 15:28 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Mon, 04 Mar 2024 19:58:45 +0100, Ahmad Fatoum wrote:
> I've been working on enabling use of barebox as EFI loader for a while.
> It's already functional enough to boot efi-stubbed Linux directly or via
> Grub, but some key parts like proper runtime services and the EFI boot
> manager are still missing.
>
> Nevertheless, A lot of commits are already in a good enough shape to be
> upstreamed, which I collected in this series. A second WIP series with
> the EFI loader support will follow afterwards.
>
> [...]
Applied, thanks!
[001/113] string: implement strcmp_ptr and streq_ptr helpers
https://git.pengutronix.de/cgit/barebox/commit/?id=ab6b3b6b43a7 (link may not be stable)
[002/113] commands: efiexit: flush console and shutdown barebox
https://git.pengutronix.de/cgit/barebox/commit/?id=d4a47c5f1477 (link may not be stable)
[003/113] treewide: add errno_set helper for returning positive error code in errno
https://git.pengutronix.de/cgit/barebox/commit/?id=b0b6b9bd2634 (link may not be stable)
[004/113] vsprintf: guard against NULL in UUID %pU
https://git.pengutronix.de/cgit/barebox/commit/?id=85ffcfca19ba (link may not be stable)
[005/113] common: add option to poweroff system on failure
https://git.pengutronix.de/cgit/barebox/commit/?id=225004aad397 (link may not be stable)
[006/113] boot: print error code when booting fails
https://git.pengutronix.de/cgit/barebox/commit/?id=1d06756875f0 (link may not be stable)
[007/113] common: efi: move directory to top-level
https://git.pengutronix.de/cgit/barebox/commit/?id=c30fcd81f548 (link may not be stable)
[008/113] efi: payload: rename CONFIG_EFI_BOOTUP to CONFIG_EFI_PAYLOAD
https://git.pengutronix.de/cgit/barebox/commit/?id=196140266808 (link may not be stable)
[009/113] efi: payload: image: return actual read_file() error
https://git.pengutronix.de/cgit/barebox/commit/?id=b917445432d5 (link may not be stable)
[010/113] of: don't report failure to of_read_file twice
https://git.pengutronix.de/cgit/barebox/commit/?id=fdd7da1169dc (link may not be stable)
[011/113] efi: payload: make missing state reporting less verbose
https://git.pengutronix.de/cgit/barebox/commit/?id=c7fbc51c572e (link may not be stable)
[012/113] libfile: factor out read_file_into_buf helper
https://git.pengutronix.de/cgit/barebox/commit/?id=761f51b69966 (link may not be stable)
[013/113] efi: payload: image: allocate image via loader if it exceeds malloc area
https://git.pengutronix.de/cgit/barebox/commit/?id=63c4468ff1b1 (link may not be stable)
[014/113] efi: payload: image: use assigned barebox loader type on x86
https://git.pengutronix.de/cgit/barebox/commit/?id=45883d351bde (link may not be stable)
[015/113] efi: payload: iomem: adjust types to avoid casting
https://git.pengutronix.de/cgit/barebox/commit/?id=33860c392de7 (link may not be stable)
[016/113] commands: kallsyms: add command-line interface
https://git.pengutronix.de/cgit/barebox/commit/?id=396fe8fb8b71 (link may not be stable)
[017/113] block: define BLOCKSIZE globally in block.h
https://git.pengutronix.de/cgit/barebox/commit/?id=2285dd1e4f19 (link may not be stable)
[018/113] cdev: implement setter/getter for cdev device node
https://git.pengutronix.de/cgit/barebox/commit/?id=29d0e0522828 (link may not be stable)
[019/113] block: virtio: assign virtio-mmio device tree node to cdevs
https://git.pengutronix.de/cgit/barebox/commit/?id=2481ff8ac2df (link may not be stable)
[020/113] commands: stat: print DT node for cdevs if available
https://git.pengutronix.de/cgit/barebox/commit/?id=3401bb216585 (link may not be stable)
[021/113] partitions: have parsers record bootable bits
https://git.pengutronix.de/cgit/barebox/commit/?id=35c1e544eb11 (link may not be stable)
[022/113] commands: stat: display bootable partition table bit info
https://git.pengutronix.de/cgit/barebox/commit/?id=aca95e86e163 (link may not be stable)
[023/113] block: record block device type
https://git.pengutronix.de/cgit/barebox/commit/?id=46ba653ef10e (link may not be stable)
[024/113] include: add definitions for UAPI discoverable partitions spec
https://git.pengutronix.de/cgit/barebox/commit/?id=cba5b8e2c184 (link may not be stable)
[025/113] efi: payload: restrict 8250 UART at I/O port 0x3f8 registration to x86
https://git.pengutronix.de/cgit/barebox/commit/?id=4a3f29461bab (link may not be stable)
[026/113] fs: fix unreaddir, so readdir returns unread dirent first
https://git.pengutronix.de/cgit/barebox/commit/?id=32ee1f61b692 (link may not be stable)
[027/113] fs: turn creat into static inline helper
https://git.pengutronix.de/cgit/barebox/commit/?id=2ac0fe5c32ff (link may not be stable)
[028/113] fs: drop unused LOOKUP_ flags
https://git.pengutronix.de/cgit/barebox/commit/?id=582d3b8bd764 (link may not be stable)
[029/113] fs: opendir: reference mount point until closedir is called
https://git.pengutronix.de/cgit/barebox/commit/?id=4378835b3730 (link may not be stable)
[030/113] fs: factor out opendir iteration
https://git.pengutronix.de/cgit/barebox/commit/?id=8208b020c4d2 (link may not be stable)
[031/113] fs: implement fdopendir and rewinddir
https://git.pengutronix.de/cgit/barebox/commit/?id=8c5a89504ae5 (link may not be stable)
[032/113] fs: remove unused member from struct nameidata
https://git.pengutronix.de/cgit/barebox/commit/?id=8de734a1f939 (link may not be stable)
[033/113] fs: always check path_init for errors
https://git.pengutronix.de/cgit/barebox/commit/?id=a9020bdff31a (link may not be stable)
[034/113] fs: set current working dir directly when mounting root
https://git.pengutronix.de/cgit/barebox/commit/?id=abb3a37a5031 (link may not be stable)
[035/113] fs: implement openat and friends
https://git.pengutronix.de/cgit/barebox/commit/?id=c47228735021 (link may not be stable)
[036/113] fs: implement O_PATH
https://git.pengutronix.de/cgit/barebox/commit/?id=049b0e98ded7 (link may not be stable)
[037/113] fs: support different root directories
https://git.pengutronix.de/cgit/barebox/commit/?id=127f7b809e0c (link may not be stable)
[038/113] fs: implement O_CHROOT
https://git.pengutronix.de/cgit/barebox/commit/?id=b89cf57d484e (link may not be stable)
[039/113] commands: introduce new findmnt command
https://git.pengutronix.de/cgit/barebox/commit/?id=992f8aeec132 (link may not be stable)
[040/113] fs: initialize struct nameidata::last
https://git.pengutronix.de/cgit/barebox/commit/?id=6548e5b9ca68 (link may not be stable)
[041/113] fs: support opening /
https://git.pengutronix.de/cgit/barebox/commit/?id=3a478ff3e1e6 (link may not be stable)
[042/113] test: self: add dirfd tests
https://git.pengutronix.de/cgit/barebox/commit/?id=fe477b0a74de (link may not be stable)
[043/113] commands: stat: add option for statat
https://git.pengutronix.de/cgit/barebox/commit/?id=5b175c52b53b (link may not be stable)
[044/113] efi: payload: lower command line options print from error to info
https://git.pengutronix.de/cgit/barebox/commit/?id=73d824f77554 (link may not be stable)
[045/113] efi: payload: init: warn if /boot FS is unknown
https://git.pengutronix.de/cgit/barebox/commit/?id=3893b00bda38 (link may not be stable)
[046/113] commands: time: switch to using getopt for -n
https://git.pengutronix.de/cgit/barebox/commit/?id=a238ac807882 (link may not be stable)
[047/113] commands: time: reduce strjoin runtime, drop trailing space
https://git.pengutronix.de/cgit/barebox/commit/?id=35a903414ddc (link may not be stable)
[048/113] commands: time: refactor into new strjoin
https://git.pengutronix.de/cgit/barebox/commit/?id=788f616946df (link may not be stable)
[049/113] test: self: add strjoin tests
https://git.pengutronix.de/cgit/barebox/commit/?id=f0102c263aeb (link may not be stable)
[050/113] filetype: have cdev_detect_type take a cdev
https://git.pengutronix.de/cgit/barebox/commit/?id=9294edaa4382 (link may not be stable)
[051/113] ARM: mmu-early: gracefully handle already enabled MMU
https://git.pengutronix.de/cgit/barebox/commit/?id=f53fc0b3212e (link may not be stable)
[052/113] efi: don't hide structs, enums or unions behind _t
https://git.pengutronix.de/cgit/barebox/commit/?id=05d94839c918 (link may not be stable)
[053/113] efi: make headers self-contained
https://git.pengutronix.de/cgit/barebox/commit/?id=a1c7c158eedf (link may not be stable)
[054/113] efi: unify whitespace for GUIDs
https://git.pengutronix.de/cgit/barebox/commit/?id=0e9c0a9cbd0a (link may not be stable)
[055/113] efi: efi-guid: add more GUIDs
https://git.pengutronix.de/cgit/barebox/commit/?id=62a782bb02f5 (link may not be stable)
[056/113] ARM64: cpu: setupc: rewrite to be fully PIC
https://git.pengutronix.de/cgit/barebox/commit/?id=0bfc6ab8bc65 (link may not be stable)
[057/113] ARM64: runtime-offset: make get_runtime_offset fully PIC
https://git.pengutronix.de/cgit/barebox/commit/?id=22ae71e69d20 (link may not be stable)
[058/113] pbl: introduce CONFIG_PBL_FULLY_PIC
https://git.pengutronix.de/cgit/barebox/commit/?id=a7e6cd8e3efa (link may not be stable)
[059/113] efi: payload: fix ARM build
https://git.pengutronix.de/cgit/barebox/commit/?id=f6559edc80d3 (link may not be stable)
[060/113] efi: payload: init: restrict barebox mem to first 1G only on x86
https://git.pengutronix.de/cgit/barebox/commit/?id=b488d9ada034 (link may not be stable)
[061/113] efi: add efi_is_loader/efi_is_payload helpers
https://git.pengutronix.de/cgit/barebox/commit/?id=626d4126b0e9 (link may not be stable)
[062/113] efi: payload: suppress EFI payload initcalls when not EFI-loaded
https://git.pengutronix.de/cgit/barebox/commit/?id=b2059a82e395 (link may not be stable)
[063/113] ARM: make board data definitions accessible to other architectures
https://git.pengutronix.de/cgit/barebox/commit/?id=6debda9a2625 (link may not be stable)
[064/113] boarddata: add barebox_boarddata_is_machine helper
https://git.pengutronix.de/cgit/barebox/commit/?id=3361b466b5a7 (link may not be stable)
[065/113] common: add PE/COFF loader
https://git.pengutronix.de/cgit/barebox/commit/?id=5e418b7cf555 (link may not be stable)
[066/113] efi: use efi_handle_t where appropriate
https://git.pengutronix.de/cgit/barebox/commit/?id=069bf5f7dd0f (link may not be stable)
[067/113] efi: block: move definitions into header file
https://git.pengutronix.de/cgit/barebox/commit/?id=b10356152382 (link may not be stable)
[068/113] efi: define efi_handle_t as opaque pointer
https://git.pengutronix.de/cgit/barebox/commit/?id=36f28caa8701 (link may not be stable)
[069/113] efi: constify guid_t in API
https://git.pengutronix.de/cgit/barebox/commit/?id=5da3afed6bff (link may not be stable)
[070/113] efi: rename efi_simple_input_interface to efi_simple_text_input_protocol
https://git.pengutronix.de/cgit/barebox/commit/?id=4420b7d6bccc (link may not be stable)
[071/113] efi: add EFI_WARN constants
https://git.pengutronix.de/cgit/barebox/commit/?id=d030653880e5 (link may not be stable)
[072/113] efi-stdio: fix wait_for_event argument
https://git.pengutronix.de/cgit/barebox/commit/?id=4c402a058e38 (link may not be stable)
[073/113] efi-stdio: wait for extended input key event when using extended input
https://git.pengutronix.de/cgit/barebox/commit/?id=f1f47dbf94a8 (link may not be stable)
[074/113] efi: flesh out EFI definitions in header
https://git.pengutronix.de/cgit/barebox/commit/?id=51b155eb9e02 (link may not be stable)
[075/113] efi: add efi_driver_binding_protocol
https://git.pengutronix.de/cgit/barebox/commit/?id=b2af074756a0 (link may not be stable)
[076/113] efi: improve usability of EFI_PAGE_* macros
https://git.pengutronix.de/cgit/barebox/commit/?id=9135eff90223 (link may not be stable)
[077/113] fs: efi: move definitions into header
https://git.pengutronix.de/cgit/barebox/commit/?id=bcfdca61e191 (link may not be stable)
[078/113] efi: fs: flesh out file system definitions
https://git.pengutronix.de/cgit/barebox/commit/?id=9ba434fc6e95 (link may not be stable)
[079/113] efi: stdio: fix efi_register_keystroke_notify prototype
https://git.pengutronix.de/cgit/barebox/commit/?id=0fe55b4c7fd4 (link may not be stable)
[080/113] video: mark EFI_GOP driver x86-only for now
https://git.pengutronix.de/cgit/barebox/commit/?id=de32a6e176a7 (link may not be stable)
[081/113] filetype: add new file types for EFI-enabled Linux images
https://git.pengutronix.de/cgit/barebox/commit/?id=1c8a0198f2dd (link may not be stable)
[082/113] efi: payload: register handler for EFI-stubbed ARM64 kernel
https://git.pengutronix.de/cgit/barebox/commit/?id=158ca31e5619 (link may not be stable)
[083/113] efi: payload: factor C efi_main into dedicated file
https://git.pengutronix.de/cgit/barebox/commit/?id=c6d2ed6850ee (link may not be stable)
[084/113] efi: payload: early-mem: simplify error message reporting
https://git.pengutronix.de/cgit/barebox/commit/?id=cc43c6e4c6cd (link may not be stable)
[085/113] efi: payload: early-mem: use EFI_PAGE_SIZE instead of PAGE_SIZE
https://git.pengutronix.de/cgit/barebox/commit/?id=3919cc4b2996 (link may not be stable)
[086/113] ARM64: add optional EFI stub
https://git.pengutronix.de/cgit/barebox/commit/?id=742e78976dd4 (link may not be stable)
[087/113] efi: devicepath: improve const safety
https://git.pengutronix.de/cgit/barebox/commit/?id=b9dea1fef6b1 (link may not be stable)
[088/113] efi: refactor device_path_to_partuuid for code reuse
https://git.pengutronix.de/cgit/barebox/commit/?id=e5bf6b3e56b5 (link may not be stable)
[089/113] efi: devicepath: implement device_path_to_str_buf variant
https://git.pengutronix.de/cgit/barebox/commit/?id=8d242311041c (link may not be stable)
[090/113] lib: vsprintf: align documentation with current feature set
https://git.pengutronix.de/cgit/barebox/commit/?id=26224692c14d (link may not be stable)
[091/113] vsprintf: add %pD for printing EFI device path
https://git.pengutronix.de/cgit/barebox/commit/?id=402dae62ce82 (link may not be stable)
[092/113] lib: string: import Linux strreplace helper
https://git.pengutronix.de/cgit/barebox/commit/?id=b823168b76ff (link may not be stable)
[093/113] efi: payload: dynamically determine bootloader file name
https://git.pengutronix.de/cgit/barebox/commit/?id=f1230c7f92cd (link may not be stable)
[094/113] efi: payload: iomem: register later
https://git.pengutronix.de/cgit/barebox/commit/?id=7584e768f48a (link may not be stable)
[095/113] efi: payload: protect against buggy EFI implementations
https://git.pengutronix.de/cgit/barebox/commit/?id=e0e30f636242 (link may not be stable)
[096/113] efi: payload: don't require efi_loaded_image->parent_handle for bootsource detection
https://git.pengutronix.de/cgit/barebox/commit/?id=1c18863354dc (link may not be stable)
[097/113] commands: add cpuinfo -s option for stacktrace
https://git.pengutronix.de/cgit/barebox/commit/?id=ffa2c5d47d18 (link may not be stable)
[098/113] efi: devicepath: align MemoryMapped name with spec
https://git.pengutronix.de/cgit/barebox/commit/?id=41781cbb27ae (link may not be stable)
[099/113] efi: devicepath: pretty print BBS BEV DeviceType
https://git.pengutronix.de/cgit/barebox/commit/?id=fcbbd5db1c51 (link may not be stable)
[100/113] efi: devicepath: format GUIDs as little endian
https://git.pengutronix.de/cgit/barebox/commit/?id=0a4d84b435c6 (link may not be stable)
[101/113] efi: devicepath: move END device node definitions into header
https://git.pengutronix.de/cgit/barebox/commit/?id=066114dcd743 (link may not be stable)
[102/113] efi: devicepath: drop underscores in hex constants
https://git.pengutronix.de/cgit/barebox/commit/?id=80f5353a74cf (link may not be stable)
[103/113] efi: devicepath: namespace definitions
https://git.pengutronix.de/cgit/barebox/commit/?id=58f24203d77d (link may not be stable)
[104/113] efi: devicepath: use flexible array members for trailing strings
https://git.pengutronix.de/cgit/barebox/commit/?id=b2e6b2ebb0a0 (link may not be stable)
[105/113] efi: devicepath: drop unused macro
https://git.pengutronix.de/cgit/barebox/commit/?id=257b49108c97 (link may not be stable)
[106/113] efi: devicepath: let compiler worry about unaligned unpacking
https://git.pengutronix.de/cgit/barebox/commit/?id=93ab2357f7fd (link may not be stable)
[107/113] efi: devicepath: correct formatting of BBS
https://git.pengutronix.de/cgit/barebox/commit/?id=009208f801ca (link may not be stable)
[108/113] commands: provide efi_handle_dump in both payload and loader
https://git.pengutronix.de/cgit/barebox/commit/?id=387d6f9ed9a1 (link may not be stable)
[109/113] lib: uuid: implement uuid/guid_parse
https://git.pengutronix.de/cgit/barebox/commit/?id=193958495437 (link may not be stable)
[110/113] commands: efi_handle_dump: prepare for supporting EFI loader
https://git.pengutronix.de/cgit/barebox/commit/?id=910bca1d6bc7 (link may not be stable)
[111/113] commands: efi_handle_dump: print loaded image devpath
https://git.pengutronix.de/cgit/barebox/commit/?id=473e9898a13b (link may not be stable)
[112/113] commands: efi_handle_dump: use guid_parse instead of open-coding
https://git.pengutronix.de/cgit/barebox/commit/?id=1151c4325bc7 (link may not be stable)
[113/113] commands: efi_handle_dump: don't ignore failure to parse GUID
https://git.pengutronix.de/cgit/barebox/commit/?id=281c2b56b928 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 115+ messages in thread
end of thread, other threads:[~2024-03-05 15:29 UTC | newest]
Thread overview: 115+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-04 18:58 [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 001/113] string: implement strcmp_ptr and streq_ptr helpers Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 002/113] commands: efiexit: flush console and shutdown barebox Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 003/113] treewide: add errno_set helper for returning positive error code in errno Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 004/113] vsprintf: guard against NULL in UUID %pU Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 005/113] common: add option to poweroff system on failure Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 006/113] boot: print error code when booting fails Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 007/113] common: efi: move directory to top-level Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 008/113] efi: payload: rename CONFIG_EFI_BOOTUP to CONFIG_EFI_PAYLOAD Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 009/113] efi: payload: image: return actual read_file() error Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 010/113] of: don't report failure to of_read_file twice Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 011/113] efi: payload: make missing state reporting less verbose Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 012/113] libfile: factor out read_file_into_buf helper Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 013/113] efi: payload: image: allocate image via loader if it exceeds malloc area Ahmad Fatoum
2024-03-04 18:58 ` [PATCH v2 014/113] efi: payload: image: use assigned barebox loader type on x86 Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 015/113] efi: payload: iomem: adjust types to avoid casting Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 016/113] commands: kallsyms: add command-line interface Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 017/113] block: define BLOCKSIZE globally in block.h Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 018/113] cdev: implement setter/getter for cdev device node Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 019/113] block: virtio: assign virtio-mmio device tree node to cdevs Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 020/113] commands: stat: print DT node for cdevs if available Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 021/113] partitions: have parsers record bootable bits Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 022/113] commands: stat: display bootable partition table bit info Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 023/113] block: record block device type Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 024/113] include: add definitions for UAPI discoverable partitions spec Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 025/113] efi: payload: restrict 8250 UART at I/O port 0x3f8 registration to x86 Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 026/113] fs: fix unreaddir, so readdir returns unread dirent first Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 027/113] fs: turn creat into static inline helper Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 028/113] fs: drop unused LOOKUP_ flags Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 029/113] fs: opendir: reference mount point until closedir is called Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 030/113] fs: factor out opendir iteration Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 031/113] fs: implement fdopendir and rewinddir Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 032/113] fs: remove unused member from struct nameidata Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 033/113] fs: always check path_init for errors Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 034/113] fs: set current working dir directly when mounting root Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 035/113] fs: implement openat and friends Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 036/113] fs: implement O_PATH Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 037/113] fs: support different root directories Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 038/113] fs: implement O_CHROOT Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 039/113] commands: introduce new findmnt command Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 040/113] fs: initialize struct nameidata::last Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 041/113] fs: support opening / Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 042/113] test: self: add dirfd tests Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 043/113] commands: stat: add option for statat Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 044/113] efi: payload: lower command line options print from error to info Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 045/113] efi: payload: init: warn if /boot FS is unknown Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 046/113] commands: time: switch to using getopt for -n Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 047/113] commands: time: reduce strjoin runtime, drop trailing space Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 048/113] commands: time: refactor into new strjoin Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 049/113] test: self: add strjoin tests Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 050/113] filetype: have cdev_detect_type take a cdev Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 051/113] ARM: mmu-early: gracefully handle already enabled MMU Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 052/113] efi: don't hide structs, enums or unions behind _t Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 053/113] efi: make headers self-contained Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 054/113] efi: unify whitespace for GUIDs Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 055/113] efi: efi-guid: add more GUIDs Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 056/113] ARM64: cpu: setupc: rewrite to be fully PIC Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 057/113] ARM64: runtime-offset: make get_runtime_offset " Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 058/113] pbl: introduce CONFIG_PBL_FULLY_PIC Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 059/113] efi: payload: fix ARM build Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 060/113] efi: payload: init: restrict barebox mem to first 1G only on x86 Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 061/113] efi: add efi_is_loader/efi_is_payload helpers Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 062/113] efi: payload: suppress EFI payload initcalls when not EFI-loaded Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 063/113] ARM: make board data definitions accessible to other architectures Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 064/113] boarddata: add barebox_boarddata_is_machine helper Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 065/113] common: add PE/COFF loader Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 066/113] efi: use efi_handle_t where appropriate Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 067/113] efi: block: move definitions into header file Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 068/113] efi: define efi_handle_t as opaque pointer Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 069/113] efi: constify guid_t in API Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 070/113] efi: rename efi_simple_input_interface to efi_simple_text_input_protocol Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 071/113] efi: add EFI_WARN constants Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 072/113] efi-stdio: fix wait_for_event argument Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 073/113] efi-stdio: wait for extended input key event when using extended input Ahmad Fatoum
2024-03-04 18:59 ` [PATCH v2 074/113] efi: flesh out EFI definitions in header Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 075/113] efi: add efi_driver_binding_protocol Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 076/113] efi: improve usability of EFI_PAGE_* macros Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 077/113] fs: efi: move definitions into header Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 078/113] efi: fs: flesh out file system definitions Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 079/113] efi: stdio: fix efi_register_keystroke_notify prototype Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 080/113] video: mark EFI_GOP driver x86-only for now Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 081/113] filetype: add new file types for EFI-enabled Linux images Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 082/113] efi: payload: register handler for EFI-stubbed ARM64 kernel Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 083/113] efi: payload: factor C efi_main into dedicated file Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 084/113] efi: payload: early-mem: simplify error message reporting Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 085/113] efi: payload: early-mem: use EFI_PAGE_SIZE instead of PAGE_SIZE Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 086/113] ARM64: add optional EFI stub Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 087/113] efi: devicepath: improve const safety Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 088/113] efi: refactor device_path_to_partuuid for code reuse Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 089/113] efi: devicepath: implement device_path_to_str_buf variant Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 090/113] lib: vsprintf: align documentation with current feature set Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 091/113] vsprintf: add %pD for printing EFI device path Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 092/113] lib: string: import Linux strreplace helper Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 093/113] efi: payload: dynamically determine bootloader file name Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 094/113] efi: payload: iomem: register later Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 095/113] efi: payload: protect against buggy EFI implementations Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 096/113] efi: payload: don't require efi_loaded_image->parent_handle for bootsource detection Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 097/113] commands: add cpuinfo -s option for stacktrace Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 098/113] efi: devicepath: align MemoryMapped name with spec Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 099/113] efi: devicepath: pretty print BBS BEV DeviceType Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 100/113] efi: devicepath: format GUIDs as little endian Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 101/113] efi: devicepath: move END device node definitions into header Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 102/113] efi: devicepath: drop underscores in hex constants Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 103/113] efi: devicepath: namespace definitions Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 104/113] efi: devicepath: use flexible array members for trailing strings Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 105/113] efi: devicepath: drop unused macro Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 106/113] efi: devicepath: let compiler worry about unaligned unpacking Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 107/113] efi: devicepath: correct formatting of BBS Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 108/113] commands: provide efi_handle_dump in both payload and loader Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 109/113] lib: uuid: implement uuid/guid_parse Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 110/113] commands: efi_handle_dump: prepare for supporting EFI loader Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 111/113] commands: efi_handle_dump: print loaded image devpath Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 112/113] commands: efi_handle_dump: use guid_parse instead of open-coding Ahmad Fatoum
2024-03-04 19:00 ` [PATCH v2 113/113] commands: efi_handle_dump: don't ignore failure to parse GUID Ahmad Fatoum
2024-03-05 15:28 ` [PATCH v2 000/113] efi: prepare for ARM64 EFI loader support Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox