Commit Graph

664 Commits

Author SHA1 Message Date
Kelvin Zhang
a1be045514 [lib][uefi] Migrate to boot memory protocol
Image loading protocol is deprecated, migrate
2025-09-18 22:13:33 -07:00
Kelvin Zhang
848fbfefe7 [lib][uefi] Mark bio functions as WEAK
OEMs may want to override certain bio functions, hence mark
`open_block_device` and `open_async_block_device`  as WEAK. This allows
OEMs to customize any of the bio functions
2025-09-18 22:13:33 -07:00
Kelvin Zhang
72c92b5d81 [lib][uefi] Update protocol headers from upstream
Copied from https://cs.android.com/android/kernel/superproject/+/common-android-mainline:bootable/libbootloader/gbl/libefi_types/defs/protocols/
2025-09-17 10:27:49 -07:00
Yi-Yo Chiang
fb9c37cbd6 [lib][uefi] Implement EFI_ERASE_BLOCK protocol 2025-09-05 13:49:28 -07:00
Yi-Yo Chiang
91a76a9a03 [lib][uefi] Fix -Wc++20-compat compiler warning 2025-09-04 23:27:02 -07:00
Yi-Yo Chiang
b1e26e90cd [lib][uefi] Update UEFI protocol definitions
GBL HEAD: 878653395d
2025-09-04 09:59:22 -07:00
Travis Geiselbrecht
2377c3d440 [make] fix three misuses of TOBOOL
Forgot to expand the variable in the call to the TOBOOL function which
would cause the result to always be true. In this case always resulted
in the test code for these three modules to be included.
2025-09-03 15:14:18 -07:00
Travis Geiselbrecht
fff0f2a740 [arch][arm64] add support for 16k pages 2025-08-31 21:47:32 -07:00
Yi-Yo Chiang
e38bf65034 [lib][uefi] Default implementation of BootService.SetWatchdogTimer()
The platform_watchdog_ methods are optional features that the target
platform can choose to implement.
If they are implemented, then BootService.SetWatchdogTimer() would call
them to setup the hardware watchdog.
If they are not implemented (for example presubmit targets), then
BootService.SetWatchdogTimer() would test the WEAK symbol against a NULL
pointer and error out.

To use BootService.SetWatchdogTimer(), platforms can choose to either
implement platform_watchdog_init and platform_watchdog_set_enabled, or
override the entire BootService.SetWatchdogTimer() method.
2025-08-22 09:21:56 -07:00
Yi-Yo Chiang
7b26b7cf3a [lib][uefi] Stub implementation of BootService.RaiseTpl .RestoreTpl 2025-08-22 09:21:56 -07:00
Kelvin Zhang
2be24ed6e6 [lib][uefi] Fix os loading protocol setup
get_buffer was actually unused, fix
2025-08-15 01:02:55 -04:00
Ying-Chun Liu (PaulLiu)
17dc5cd0aa lib: uefi: runtime_service_provider.cpp: implement Get/SetVariable
GBL debug target will use GetVariable to get a variable called
gbl_debug. If the variable exists, it waits for the gdb to be started.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
2025-08-14 12:25:36 -04:00
Ying-Chun Liu (PaulLiu)
45d7da5640 lib: uefi: add volatile UEFI variable support
GBL needs to read an UEFI variable called "gbl_debug".
We add 2 commands. "uefi_set_var" to set an UEFI variable. And
"uefi_list_var" to list the UEFI variables.

For GBL, we can use "uefi_set_var gbl_debug 1" to enable its
debug mode.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
2025-08-14 12:25:36 -04:00
Ying-Chun Liu (PaulLiu)
de3e831eae lib: uefi: add charset converting helper functions.
The UEFI variable names are in UTF-16. We add several helper
functions to convert US-ASCII to UTF-16.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
2025-08-14 12:25:36 -04:00
Kelvin Zhang
af1f19a2cc [lib][uefi] Add interrupt based async IO support
Add a new API to bio layer(read_async) where function will
return immediately, and a callback function will be called from
interrupt context, when block driver completes the IO request.
2025-08-13 16:13:38 -04:00
Ying-Chun Liu (PaulLiu)
cfeef533d1 lib: uefi: debug_support.cpp: fix code-style of teardown_debug_support()
This commit refactors teardown_debug_support() to make the code
looks simpler.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
2025-08-11 14:19:55 -04:00
Kelvin Zhang
22b808b6ec [lib][uefi] Fix LTRACEF logging
LTRACEF already outputs function name, no need to do it again
2025-08-08 16:13:30 -04:00
Kelvin Zhang
0f15dc23bc [lib][uefi] Move several memory APIs to uefi_platform.cpp
This allows OEMs to customize exactly how their memories are allocated.
For examples, OEMs might want to allocate certain parts of the UEFI
from high address kernel space, for ease of access in LK world.
Since UEFI spec requires everything to be identity mapped, the default
implementation of memory allocation is identity mapped.
2025-08-08 03:06:05 -04:00
Ying-Chun Liu (PaulLiu)
c5612330cc lib: uefi: add EfiDebugImageInfo for debug
This commit adds the functionality of generate EfiDebugImageInfo
while loading the image.

This feature is described in UEFI Spec 2.10. Section 18.4.3.
The implementation ensures support for hardware-assisted debugging and
provides a standardized mechanism for debuggers to discover the load
address of an EFI application.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
2025-08-06 03:19:47 -04:00
Ying-Chun Liu (PaulLiu)
1ffb54dace lib: uefi: add EfiDebugImageInfoTable for debug
EfiDebugImageInfoTable is used to store EfiLoadedImage for
debug purpose. This commit adds the table to the EfiConfigurationTable.

This feature is described in UEFI Spec version 2.10. Section 18.4.
The implementation ensures support for hardware-assisted debugging and
provides a standardized mechanism for debuggers to discover and interact
with system-level debug resources.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
2025-08-06 03:19:47 -04:00
Ying-Chun Liu (PaulLiu)
ea327d7242 lib: uefi: add EfiSystemTablePointer for debug
Add EfiSystemTablePointer structure for remote debugger to locate
the address of EfiSystemTable.

This feature is described in UEFI SPEC version 2.10. Section 18.4.2.
The implementation ensures support for hardware-assisted debugging and
provides a standardized mechanism for debuggers to discover the EFI
system table.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
2025-08-06 03:19:47 -04:00
Ying-Chun Liu (PaulLiu)
777297f156 lib: uefi: uefi.cpp: set vendor string of SystemTable
Setting the vendor string makes us easier for testing the
SystemTablePointer. When we discover SystemTable we can check
if the vendor string is set with proper value.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
2025-08-06 03:19:47 -04:00
Ying-Chun Liu (PaulLiu)
7c23aac677 lib: uefi: boot_service_provider.cpp: implement Stall call
We implement a Stall call for easier testing with Rust UEFI application.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
Link: https://rust-osdev.github.io/uefi-rs/tutorial/app.html
2025-08-06 03:19:47 -04:00
Kelvin Zhang
07f5cdf370 [lib][uefi] Make UEFI API signal_event usable in interrupt context
This is to prepare events API for interrupt based async block I/O,
in which case UEFI events will be signaled from block driver callback(in
in interrupt context).
2025-08-05 14:21:57 -04:00
Kelvin Zhang
9bbfeabb9d [lib][uefi] Free memory used by UEFI app after app returns 2025-08-05 14:21:57 -04:00
Yi-Yo Chiang
6ae7086222 [lib][uefi] Add GBL protocol definitions
GBL HEAD: aosp/I28a1926447e54401d9678c40a98957d558125ced
2025-08-05 03:51:19 -04:00
Yi-Yo Chiang
3460cd6c2d [lib][uefi] Implement EFI_TIMESTAMP_PROTOCOL
Reads the ARM64-specific counter registers.
This only works on ARM64 platform obviously, which is the only platform
we support for UEFI at the moment.
2025-07-30 00:11:49 -04:00
Kelvin Zhang
f356261b67 [lib][uefi] Allow identity mapped pages to be free'ed
Since UEFI requires app to be run in physical address space,
we allocate memory that are identity mapped. Previous identity
mapping works as follows:

1. call vmm_alloc_contigious to obtain a VA1(virtual address) mapping to
   PA1(physical address)
2. Use arch_mmu_query to obtain PA1 from VA1
3. arch_mmu_unmap VA1 <-> PA1
4. arch_mmu_map PA1 <-> PA1

Now we can return PA1 as a valid virtual address pointer, which is
mapped to physical memory. However, this has problems. LK allocates a
vmm_region_t struct for each call to vmm_alloc_* . This struct can
never be free'ed, as the associated virtual address VA1 is forever
lost. We can't even free PA1, as PA1 is not a valid argument to
vmm_free(PA1 does not have associated vmm_region_t struct).

The new approach uses pmm_alloc and vmm_reserve_space, allowing
vmm_free_region to be called.
2025-07-23 10:46:42 -07:00
Kelvin Zhang
f7d8f58cdc [lib][uefi] Support async blockio 2025-07-23 10:46:42 -07:00
Kelvin Zhang
76ce54625a [lib][uefi] Support 5 arguments for switch stack call
Some functions have >4 arguments, bump support to 5 arguments
2025-07-16 14:00:00 -07:00
Kelvin Zhang
e8cea74e9b [lib][uefi] Implement events API in UEFI
LK already has events APIs. To support events protocols in UEFI spec,
I created a wrapper object for LK events. This wrapper object keeps
additional data that are necessary to support UEFI events spec:

* Notification function, or callbacks
* Argument for the notification function
* Type of this UEFI event (which specifies when the callback should be
  called)

The events API is essential for supporting async I/O in UEFI. Intended
use case looks like:

* UEFI app creates an event object, attatch callback to this event
* UEFI app calls LK for asynchronous read/write on a block device, with
  the newly created events object
* LK executes IO operation in background, after IO finishes, signal the
  specified event object
* UEFI's callback gets executed
2025-07-16 14:00:00 -07:00
Kelvin Zhang
2ff6ab3920 [lib][uefi] Implement os loading buffer protocol 2025-07-16 14:00:00 -07:00
Kelvin Zhang
953b519d69 [lib][uefi] Update os configuration protocol
Two breaking changes:

* fixup_kernel_commandline was removed by upstream
* GblEfiDeviceTreeMetadata's reserve field is removed, instead a `type`
  variable is inserted earlier in the struct.

Both changes come from upstream GBL, update LK accordingly
2025-07-16 13:59:59 -07:00
Kelvin Zhang
62409f55f6 [lib][uefi] Add error checking to certain functions 2025-07-16 13:59:59 -07:00
Matt Schulte
e51cf68c3c [lib][libc] Make errno thread safe using TLS APIs
Before this change, errno was "completely un-threadsafe" as the comment
states.

This changes errno to be threadsafe by making errno a thread local
variable.
2025-07-10 15:37:43 -07:00
Chieh-Min Wang
816be268be [console] support background command execution
Launch a thread to execute commands when the last argument is ampersand

Signed-off-by: Chieh-Min Wang <cmwang@google.com>
2025-07-09 23:12:51 -07:00
Travis Geiselbrecht
73d29b0860 [lib][libc] don't compile the floating point tests if there's no FPU 2025-06-10 23:57:05 -07:00
Travis Geiselbrecht
2865ab6813 [lib][libc][tests] switch floating point test vector to a constructor
This should avoid a problem with older compilers that do not support non
trivial designated initializers.
2025-06-10 23:37:51 -07:00
Travis Geiselbrecht
03bc415b2b [lib][libc] a few little style tweaks in the printf code
No functional change.
2025-06-10 23:10:45 -07:00
Travis Geiselbrecht
c8f011a159 [lib][libc][tests] move the floating point printf test to libc unittests
Complete moving the rest of the previously manual printf tests out of
app/tests and into lib/libc/test as a proper unit test.
2025-06-10 23:10:45 -07:00
Travis Geiselbrecht
433b02ce10 [lib][libc] move all the printf routines into printf.c
Some of the wrapper routines (printf, fprintf, etc) were defined in
stdio.c which is not necessarily compiled with the same compiler flags
concerning floating point support.

On some architectures (arm64, x86-64) this caused the wrapper routines
to clobber the floating point registers prior to getting into the
printf_engine.
2025-06-10 23:10:45 -07:00
Kelvin Zhang
32429c6c11 [lib][uefi] Allow complete platform customization for UEFI
Added platform_setup_system_table, where platform/vendor can
make arbitrary changes to UEFI's system table, overriding
any of the UEFI protocols with custom one.
2025-06-03 22:17:22 -07:00
Kelvin Zhang
b8a584b69a [lib][uefi] Move certain UEFI headers to public include dir
This allows other components to reference basic UEFI types. Now
different platforms can provide their own override for certain UEFI
protocols.

To keep good include structure, all public headers are put under
include/uefi.
2025-06-03 22:17:22 -07:00
Kelvin Zhang
b10701feaa [lib][uefi] Make load_pe_file extern linkage
This function was previously put in anon namespace, making it
unavailable for other source files to consume. Since we made this
function an API for consumption, move outside anon namespace so
that linkers can find it.
2025-05-28 16:04:10 -07:00
Michael Bishop
d66ad44db3 bio: use shifts to divide 2025-05-06 23:40:25 -07:00
Kelvin Zhang
55e2d6f2aa [lib][uefi] Move platform dependent functions to a separate file 2025-04-29 14:17:10 -07:00
Kelvin Zhang
9b5a187952 Put functions in anon namespace if possible 2025-04-28 17:53:55 -07:00
Kelvin Zhang
5ee4e35921 [lib][uefi] Allow load_pe_file to be called from other apps/libs 2025-04-28 17:48:52 -07:00
Kelvin Zhang
fbc354e7e3 [lib][uefi] Implement ResetSystem protocol 2025-04-28 17:48:52 -07:00
Kelvin Zhang
27696ee6c2 [lib][uefi] Make exit_boot_service weak link
This allows different platforms to provide their own implementation
of exit_boot_service
2025-04-28 17:48:52 -07:00