History log of /openbsd-current/sys/arch/arm64/stand/efiboot/efiboot.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.50 23-Feb-2024 kettenis

There is a 21BY x13s model. Handle it like 21BX.

ok beck@, deraadt@


# 1.49 04-Feb-2024 kettenis

Add a DMA constraint for the x13s. Some brilliant person at Qualcomm
decided that tying a wifi interface that can only do 32-bit DMA to their
compute platform that typically comes with at least 8G of memory was a
sensible thing to do.

Maybe we should be able to use an IOMMU to work around that. But they
fucked that up as well.

ok patrick@, phessler@


Revision tags: OPENBSD_7_4_BASE
# 1.48 12-May-2023 kettenis

Fall back on loading the kernel from the EFI system partition if we're
booting from a disk without a BSD disklabel.

ok kn@, caspar@


Revision tags: OPENBSD_7_3_BASE
# 1.47 15-Feb-2023 kettenis

The GMAC on the Rockchip RK356x and RK3588 SoCs can only do 32-bit DMA
so set the appropriate DMA constraint.

ok patrick@


# 1.46 08-Dec-2022 patrick

Forcibly set console output to the framebuffer on the Lenovo x13s.
We should actually do something like checking that both stdout-path
and serial0 don't exist to realize we have to switch, but this hack
gets us going for now.

ok kettenis@


# 1.45 07-Dec-2022 patrick

The ACPI tables on the Lenovo x13s are incomplete and unusable. For
that reason, identify that we're running on that machine by looking at
the SMBIOS tables and load alternate device tree binaries from disk.

ok kettenis@


# 1.44 05-Nov-2022 patrick

Not every device tree we're getting passed has an /aliases or /chosen node,
but our code assumes so. It's useful to have them, so create them if they
do not exist.

ok kettenis@


# 1.43 05-Nov-2022 patrick

Activate the device tree we just loaded from disk. While this doesn't fix
any current bug, it might catch issues in the future.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.42 28-Jun-2022 kettenis

On the x13s, using the EfiLoaderData memory type for the memory block
that we load the kernel into doesn't work. But changing it to EfiLoaderCode
makes it work. Presumably the firmware creates a mapping with executable
permissions in that case, which is obviously needed for executing kernel
code.

ok patrick@, mlarkin@


# 1.41 06-Apr-2022 kettenis

Support switching from glass console to serial console on systems that
default to glass console.

ok miod@, patrick@


Revision tags: OPENBSD_7_1_BASE
# 1.40 17-Mar-2022 kettenis

Fix previous commit; the FDT header is big-endian so we need to do the
appropriate byte swapping.


# 1.39 16-Mar-2022 kettenis

When we allocate space a buffer with some extra space for the FDT, adjust
the size of the FDT to reflect the size of that buffer. This prevents
an FDT overflow if the original FDT doesn't have enough space for the
additional properties that we add to it in our bootloader.

Fixes boot on the mcbin.
tested by bluhm@, ok patrick@


# 1.38 15-Dec-2021 deraadt

typo in previous


# 1.37 14-Dec-2021 kettenis

Use "rng-seed" and "kaslr-seed" properties from the device tree to mix in
some extra entropy.

ok deraadt@


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.49 04-Feb-2024 kettenis

Add a DMA constraint for the x13s. Some brilliant person at Qualcomm
decided that tying a wifi interface that can only do 32-bit DMA to their
compute platform that typically comes with at least 8G of memory was a
sensible thing to do.

Maybe we should be able to use an IOMMU to work around that. But they
fucked that up as well.

ok patrick@, phessler@


Revision tags: OPENBSD_7_4_BASE
# 1.48 12-May-2023 kettenis

Fall back on loading the kernel from the EFI system partition if we're
booting from a disk without a BSD disklabel.

ok kn@, caspar@


Revision tags: OPENBSD_7_3_BASE
# 1.47 15-Feb-2023 kettenis

The GMAC on the Rockchip RK356x and RK3588 SoCs can only do 32-bit DMA
so set the appropriate DMA constraint.

ok patrick@


# 1.46 08-Dec-2022 patrick

Forcibly set console output to the framebuffer on the Lenovo x13s.
We should actually do something like checking that both stdout-path
and serial0 don't exist to realize we have to switch, but this hack
gets us going for now.

ok kettenis@


# 1.45 07-Dec-2022 patrick

The ACPI tables on the Lenovo x13s are incomplete and unusable. For
that reason, identify that we're running on that machine by looking at
the SMBIOS tables and load alternate device tree binaries from disk.

ok kettenis@


# 1.44 05-Nov-2022 patrick

Not every device tree we're getting passed has an /aliases or /chosen node,
but our code assumes so. It's useful to have them, so create them if they
do not exist.

ok kettenis@


# 1.43 05-Nov-2022 patrick

Activate the device tree we just loaded from disk. While this doesn't fix
any current bug, it might catch issues in the future.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.42 28-Jun-2022 kettenis

On the x13s, using the EfiLoaderData memory type for the memory block
that we load the kernel into doesn't work. But changing it to EfiLoaderCode
makes it work. Presumably the firmware creates a mapping with executable
permissions in that case, which is obviously needed for executing kernel
code.

ok patrick@, mlarkin@


# 1.41 06-Apr-2022 kettenis

Support switching from glass console to serial console on systems that
default to glass console.

ok miod@, patrick@


Revision tags: OPENBSD_7_1_BASE
# 1.40 17-Mar-2022 kettenis

Fix previous commit; the FDT header is big-endian so we need to do the
appropriate byte swapping.


# 1.39 16-Mar-2022 kettenis

When we allocate space a buffer with some extra space for the FDT, adjust
the size of the FDT to reflect the size of that buffer. This prevents
an FDT overflow if the original FDT doesn't have enough space for the
additional properties that we add to it in our bootloader.

Fixes boot on the mcbin.
tested by bluhm@, ok patrick@


# 1.38 15-Dec-2021 deraadt

typo in previous


# 1.37 14-Dec-2021 kettenis

Use "rng-seed" and "kaslr-seed" properties from the device tree to mix in
some extra entropy.

ok deraadt@


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.48 12-May-2023 kettenis

Fall back on loading the kernel from the EFI system partition if we're
booting from a disk without a BSD disklabel.

ok kn@, caspar@


Revision tags: OPENBSD_7_3_BASE
# 1.47 15-Feb-2023 kettenis

The GMAC on the Rockchip RK356x and RK3588 SoCs can only do 32-bit DMA
so set the appropriate DMA constraint.

ok patrick@


# 1.46 08-Dec-2022 patrick

Forcibly set console output to the framebuffer on the Lenovo x13s.
We should actually do something like checking that both stdout-path
and serial0 don't exist to realize we have to switch, but this hack
gets us going for now.

ok kettenis@


# 1.45 07-Dec-2022 patrick

The ACPI tables on the Lenovo x13s are incomplete and unusable. For
that reason, identify that we're running on that machine by looking at
the SMBIOS tables and load alternate device tree binaries from disk.

ok kettenis@


# 1.44 05-Nov-2022 patrick

Not every device tree we're getting passed has an /aliases or /chosen node,
but our code assumes so. It's useful to have them, so create them if they
do not exist.

ok kettenis@


# 1.43 05-Nov-2022 patrick

Activate the device tree we just loaded from disk. While this doesn't fix
any current bug, it might catch issues in the future.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.42 28-Jun-2022 kettenis

On the x13s, using the EfiLoaderData memory type for the memory block
that we load the kernel into doesn't work. But changing it to EfiLoaderCode
makes it work. Presumably the firmware creates a mapping with executable
permissions in that case, which is obviously needed for executing kernel
code.

ok patrick@, mlarkin@


# 1.41 06-Apr-2022 kettenis

Support switching from glass console to serial console on systems that
default to glass console.

ok miod@, patrick@


Revision tags: OPENBSD_7_1_BASE
# 1.40 17-Mar-2022 kettenis

Fix previous commit; the FDT header is big-endian so we need to do the
appropriate byte swapping.


# 1.39 16-Mar-2022 kettenis

When we allocate space a buffer with some extra space for the FDT, adjust
the size of the FDT to reflect the size of that buffer. This prevents
an FDT overflow if the original FDT doesn't have enough space for the
additional properties that we add to it in our bootloader.

Fixes boot on the mcbin.
tested by bluhm@, ok patrick@


# 1.38 15-Dec-2021 deraadt

typo in previous


# 1.37 14-Dec-2021 kettenis

Use "rng-seed" and "kaslr-seed" properties from the device tree to mix in
some extra entropy.

ok deraadt@


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.47 15-Feb-2023 kettenis

The GMAC on the Rockchip RK356x and RK3588 SoCs can only do 32-bit DMA
so set the appropriate DMA constraint.

ok patrick@


# 1.46 08-Dec-2022 patrick

Forcibly set console output to the framebuffer on the Lenovo x13s.
We should actually do something like checking that both stdout-path
and serial0 don't exist to realize we have to switch, but this hack
gets us going for now.

ok kettenis@


# 1.45 07-Dec-2022 patrick

The ACPI tables on the Lenovo x13s are incomplete and unusable. For
that reason, identify that we're running on that machine by looking at
the SMBIOS tables and load alternate device tree binaries from disk.

ok kettenis@


# 1.44 05-Nov-2022 patrick

Not every device tree we're getting passed has an /aliases or /chosen node,
but our code assumes so. It's useful to have them, so create them if they
do not exist.

ok kettenis@


# 1.43 05-Nov-2022 patrick

Activate the device tree we just loaded from disk. While this doesn't fix
any current bug, it might catch issues in the future.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.42 28-Jun-2022 kettenis

On the x13s, using the EfiLoaderData memory type for the memory block
that we load the kernel into doesn't work. But changing it to EfiLoaderCode
makes it work. Presumably the firmware creates a mapping with executable
permissions in that case, which is obviously needed for executing kernel
code.

ok patrick@, mlarkin@


# 1.41 06-Apr-2022 kettenis

Support switching from glass console to serial console on systems that
default to glass console.

ok miod@, patrick@


Revision tags: OPENBSD_7_1_BASE
# 1.40 17-Mar-2022 kettenis

Fix previous commit; the FDT header is big-endian so we need to do the
appropriate byte swapping.


# 1.39 16-Mar-2022 kettenis

When we allocate space a buffer with some extra space for the FDT, adjust
the size of the FDT to reflect the size of that buffer. This prevents
an FDT overflow if the original FDT doesn't have enough space for the
additional properties that we add to it in our bootloader.

Fixes boot on the mcbin.
tested by bluhm@, ok patrick@


# 1.38 15-Dec-2021 deraadt

typo in previous


# 1.37 14-Dec-2021 kettenis

Use "rng-seed" and "kaslr-seed" properties from the device tree to mix in
some extra entropy.

ok deraadt@


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.46 08-Dec-2022 patrick

Forcibly set console output to the framebuffer on the Lenovo x13s.
We should actually do something like checking that both stdout-path
and serial0 don't exist to realize we have to switch, but this hack
gets us going for now.

ok kettenis@


# 1.45 07-Dec-2022 patrick

The ACPI tables on the Lenovo x13s are incomplete and unusable. For
that reason, identify that we're running on that machine by looking at
the SMBIOS tables and load alternate device tree binaries from disk.

ok kettenis@


# 1.44 05-Nov-2022 patrick

Not every device tree we're getting passed has an /aliases or /chosen node,
but our code assumes so. It's useful to have them, so create them if they
do not exist.

ok kettenis@


# 1.43 05-Nov-2022 patrick

Activate the device tree we just loaded from disk. While this doesn't fix
any current bug, it might catch issues in the future.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.42 28-Jun-2022 kettenis

On the x13s, using the EfiLoaderData memory type for the memory block
that we load the kernel into doesn't work. But changing it to EfiLoaderCode
makes it work. Presumably the firmware creates a mapping with executable
permissions in that case, which is obviously needed for executing kernel
code.

ok patrick@, mlarkin@


# 1.41 06-Apr-2022 kettenis

Support switching from glass console to serial console on systems that
default to glass console.

ok miod@, patrick@


Revision tags: OPENBSD_7_1_BASE
# 1.40 17-Mar-2022 kettenis

Fix previous commit; the FDT header is big-endian so we need to do the
appropriate byte swapping.


# 1.39 16-Mar-2022 kettenis

When we allocate space a buffer with some extra space for the FDT, adjust
the size of the FDT to reflect the size of that buffer. This prevents
an FDT overflow if the original FDT doesn't have enough space for the
additional properties that we add to it in our bootloader.

Fixes boot on the mcbin.
tested by bluhm@, ok patrick@


# 1.38 15-Dec-2021 deraadt

typo in previous


# 1.37 14-Dec-2021 kettenis

Use "rng-seed" and "kaslr-seed" properties from the device tree to mix in
some extra entropy.

ok deraadt@


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.44 05-Nov-2022 patrick

Not every device tree we're getting passed has an /aliases or /chosen node,
but our code assumes so. It's useful to have them, so create them if they
do not exist.

ok kettenis@


# 1.43 05-Nov-2022 patrick

Activate the device tree we just loaded from disk. While this doesn't fix
any current bug, it might catch issues in the future.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.42 28-Jun-2022 kettenis

On the x13s, using the EfiLoaderData memory type for the memory block
that we load the kernel into doesn't work. But changing it to EfiLoaderCode
makes it work. Presumably the firmware creates a mapping with executable
permissions in that case, which is obviously needed for executing kernel
code.

ok patrick@, mlarkin@


# 1.41 06-Apr-2022 kettenis

Support switching from glass console to serial console on systems that
default to glass console.

ok miod@, patrick@


Revision tags: OPENBSD_7_1_BASE
# 1.40 17-Mar-2022 kettenis

Fix previous commit; the FDT header is big-endian so we need to do the
appropriate byte swapping.


# 1.39 16-Mar-2022 kettenis

When we allocate space a buffer with some extra space for the FDT, adjust
the size of the FDT to reflect the size of that buffer. This prevents
an FDT overflow if the original FDT doesn't have enough space for the
additional properties that we add to it in our bootloader.

Fixes boot on the mcbin.
tested by bluhm@, ok patrick@


# 1.38 15-Dec-2021 deraadt

typo in previous


# 1.37 14-Dec-2021 kettenis

Use "rng-seed" and "kaslr-seed" properties from the device tree to mix in
some extra entropy.

ok deraadt@


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.42 28-Jun-2022 kettenis

On the x13s, using the EfiLoaderData memory type for the memory block
that we load the kernel into doesn't work. But changing it to EfiLoaderCode
makes it work. Presumably the firmware creates a mapping with executable
permissions in that case, which is obviously needed for executing kernel
code.

ok patrick@, mlarkin@


# 1.41 06-Apr-2022 kettenis

Support switching from glass console to serial console on systems that
default to glass console.

ok miod@, patrick@


Revision tags: OPENBSD_7_1_BASE
# 1.40 17-Mar-2022 kettenis

Fix previous commit; the FDT header is big-endian so we need to do the
appropriate byte swapping.


# 1.39 16-Mar-2022 kettenis

When we allocate space a buffer with some extra space for the FDT, adjust
the size of the FDT to reflect the size of that buffer. This prevents
an FDT overflow if the original FDT doesn't have enough space for the
additional properties that we add to it in our bootloader.

Fixes boot on the mcbin.
tested by bluhm@, ok patrick@


# 1.38 15-Dec-2021 deraadt

typo in previous


# 1.37 14-Dec-2021 kettenis

Use "rng-seed" and "kaslr-seed" properties from the device tree to mix in
some extra entropy.

ok deraadt@


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.41 06-Apr-2022 kettenis

Support switching from glass console to serial console on systems that
default to glass console.

ok miod@, patrick@


Revision tags: OPENBSD_7_1_BASE
# 1.40 17-Mar-2022 kettenis

Fix previous commit; the FDT header is big-endian so we need to do the
appropriate byte swapping.


# 1.39 16-Mar-2022 kettenis

When we allocate space a buffer with some extra space for the FDT, adjust
the size of the FDT to reflect the size of that buffer. This prevents
an FDT overflow if the original FDT doesn't have enough space for the
additional properties that we add to it in our bootloader.

Fixes boot on the mcbin.
tested by bluhm@, ok patrick@


# 1.38 15-Dec-2021 deraadt

typo in previous


# 1.37 14-Dec-2021 kettenis

Use "rng-seed" and "kaslr-seed" properties from the device tree to mix in
some extra entropy.

ok deraadt@


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.40 17-Mar-2022 kettenis

Fix previous commit; the FDT header is big-endian so we need to do the
appropriate byte swapping.


# 1.39 16-Mar-2022 kettenis

When we allocate space a buffer with some extra space for the FDT, adjust
the size of the FDT to reflect the size of that buffer. This prevents
an FDT overflow if the original FDT doesn't have enough space for the
additional properties that we add to it in our bootloader.

Fixes boot on the mcbin.
tested by bluhm@, ok patrick@


# 1.38 15-Dec-2021 deraadt

typo in previous


# 1.37 14-Dec-2021 kettenis

Use "rng-seed" and "kaslr-seed" properties from the device tree to mix in
some extra entropy.

ok deraadt@


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.38 15-Dec-2021 deraadt

typo in previous


# 1.37 14-Dec-2021 kettenis

Use "rng-seed" and "kaslr-seed" properties from the device tree to mix in
some extra entropy.

ok deraadt@


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.37 14-Dec-2021 kettenis

Use "rng-seed" and "kaslr-seed" properties from the device tree to mix in
some extra entropy.

ok deraadt@


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.36 26-Oct-2021 patrick

Allocate fresh memory to put our device tree into, to make sure we have least
one page of free space for us to extend into. Fixes booting on VMware Fusion.

ok kettenis@


# 1.35 26-Oct-2021 patrick

Remove more occurences of O_RDONLY in our bootloaders.

"just do it" deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.34 09-Jul-2021 patrick

Parse /soc/dma-ranges to populate the openbsd,dma-constraint property.
On the MNT Reform, which uses a i.MX8MQ with 4 GB of memory, this makes
sure that we don't allocate DMA buffers above the 32-bit boundary. As
it turns out the i.MX8MQ's I/O devices are limited to 32-bit addresses.
The i.MX8MP seems to be better in that regard, though at least the USB
controller is still limited. That's a bit harder to fix in a dynamic
fashion, but we'll take care of that as soon as someone shows up with
an i.MX8MP with that much memory.

ok kettenis@


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.33 06-Jun-2021 krw

Replace all uses of 'EFI_CALL(func, params)' with
the expansion 'func(params)'.

Allows upcoming removal of eficall.h.

Tested & ok naddy@


Revision tags: OPENBSD_6_9_BASE
# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.32 26-Mar-2021 kn

Fix "mach dtb" return code to avoid bogus boot

Bootloader command functions must return zero in case of failure,
returning 1 tells the bootloader to boot the currently set kernel iamge.

"machine dtb" is is the wrong way around so using it triggers a boot.

Fix this and print a brief usage (like other commands such as "hexdump" do)
while here.

Feedback OK patrick


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.31 09-Mar-2021 kettenis

Node without a "status" property should be considered enabled as well.

ok patrick@


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.30 09-Feb-2021 kettenis

Make sure that switching the console from serial to framebuffer works
for framebuffer nodes under / and /chosen.

ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.29 10-May-2020 kettenis

Pass boothowto from the bootloader to the kernel by adding a
openbsd,boothowto property under /chosen.

ok patrick@


Revision tags: OPENBSD_6_7_BASE
# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.28 21-Apr-2020 kettenis

Add an openbsd,dma-constraint property to the /chosen node and set it
to an appropriate value for the Raspberry Pi 4.

ok patrick@


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.27 22-Mar-2020 kettenis

Make efi_device_path_depth() return the full device path depth if we don't
find a media device path node. Fixes booting OpenBSD on some older U-Boot
versions that are in wide circulation such as 2017.09 and 2017.11.

ok patrick@


Revision tags: OPENBSD_6_6_BASE
# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.26 12-Aug-2019 kettenis

Remove spurious newline. Spotted by patrick@


# 1.25 12-Aug-2019 kettenis

Make it possible to switch to framebuffer "glass" console in case it
isn't the default already.

ok patrick@


# 1.24 10-Aug-2019 kettenis

Fix pixel formats. Turns out the order in the device tree description is
exactly the opposite of the order in the enum used by UEFI.

Makes console output come out white-on-blue instead of white-on-red.

ok patrick@


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.23 25-Apr-2019 naddy

Add a check to tftp_open() that we are actually opening a TFTP device.

When reading a file from a non-TFTP device, clear the bootmac variable
to prevent the kernel from going into netboot mode.

This allows loading a kernel from a disk device after having booted
efiboot from PXE.

style tweak and ok kettenis@


Revision tags: OPENBSD_6_5_BASE
# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.22 31-Jan-2019 patrick

Implement booting from softraid on arm64. This consists of creating a
list of available block devices, so we can also boot from another block
device than the one that efiboot was loaded from. Softraid will then
create a list of volumes by checking the partition table for RAID and
matching softraid metadata. If efiboot was loaded from the same
physical drive as a softraid volume, it will use the soft- raid volume
as boot device and it will ask you to unlock it. The UUID and key of
that boot volume will be passed as FDT properties to the kernel. Those
FDT properties will be zeroed explicitly by the kernel after they have
been passed to the softraid stack.

ok kettenis@


Revision tags: OPENBSD_6_4_BASE
# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.21 25-Aug-2018 yasuoka

Don't treat UnicodeChar == 0 as a keyboard input. The same fix was
done on amd64 already. Original diff from Frank Groeneveld

ok tb patrick


# 1.20 23-Aug-2018 patrick

Set the pointer to the EFI Runtime Services, otherwise we call into
nowhere.

ok kettenis@


# 1.19 19-Aug-2018 patrick

Implement "mach dtb <filename.dtb>" in efiboot(8). This way we can
provide our own FDT if the BIOS doesn't supply one, or even override
the supplied one.

Idea from and ok kettenis@


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.18 10-Jul-2018 kettenis

Add a "machine acpi" command to force booting with ACPI enabled.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.17 25-Jun-2018 kettenis

Add code that builds a basic device tree from ACPI tables if the firmware
didn't provide its own device tree.

ok patrick@


Revision tags: OPENBSD_6_3_BASE
# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.16 02-Mar-2018 jsg

The UEFI specification states that a watchdog timer should be armed for
five minutes. Disable the timer to make it possible to use efiboot for
more than five minutes.

ok patrick@ kettenis@


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.15 06-Feb-2018 naddy

Allow the kernel to recognize that it has been netbooted and to add the
boot interface to the "netboot" group. efiboot grabs the MAC address
from the PXE environment, passes it to the kernel, where it is matched
against the list of ethernet interfaces and the boot device is set.
Concept and most of the code cribbed from amd64.
ok kettenis@


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.14 21-Jan-2018 patrick

Implement network boot support in efiboot(8). This changes efiboot(8)
to recognize if it has been booted via PXE. The new TFTP file system
layer will then use the matching PXE base code protocol handle to load
the files. Since this uses the PXE base code protocol for abstraction
instead of the raw Simple Network protocol this will at this point not
work on u-boot based machines.

ok kettenis@


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


Revision tags: OPENBSD_6_2_BASE
# 1.13 23-Aug-2017 kettenis

If the firmware provides a framebuffer through the Graphics Output Protocol,
create a "simple-framebuffer" node such that the kernel can attach the
simplefb(4) driver. Only do this if such a "simple-framebuffer" node
doesn't exist already.

ok patrick@, jsg@


# 1.12 22-Aug-2017 kettenis

Some small cleanups to reduce the diffs to the armv7 efiboot.

ok tom@, jsg@


# 1.11 07-Aug-2017 kettenis

Add "machine exit" and "machine poweroff" commands to the arm64 and armv7
bootloaders. Replace while (1) { } with for (;;) continue; per request
from tom@.

ok tom@, jsg@


# 1.10 31-Jul-2017 kettenis

Back out previous commit but handle the case where the device path consists
of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's
somewhat broken device path handling. Add comments to prevent confusion
in the future. Bump the version number once again.

ok brynet@


# 1.9 29-Jul-2017 kettenis

Fix off-by-one in return value of efi_device_path_depth().

ok patrick@


# 1.8 24-Jul-2017 patrick

Port amd64's updates to the device path comparison to arm64 as well.


# 1.7 07-May-2017 kettenis

Pass the address of the EFI system table and the EFI memory map through
properties in the /chosen node of the FDT. The properties match the ones
used by Linux (see Documentation/arm/uefi.txt in the Linux kernel source
tree) but with the "linux," prefix replaced by "openbsd,".

ok jmatthew@, tom@


Revision tags: OPENBSD_6_1_BASE
# 1.6 11-Mar-2017 jsg

Set EVT_NOTIFY_SIGNAL when calling boot services CreateEvent().
The UEFI specification states this is required to have the notification
function called. U-Boot's EFI loader calls the notification function
without the flag set but the EDK2 implementation of UEFI requires the
flag.

With this change the timer ticks and autoboot works on the OverDrive
3000.

ok kettenis@


# 1.5 08-Feb-2017 patrick

Retry BS->ExitBootServices() if it fails, like on amd64. Also we need
to make sure to pass the current mapkey to prove EFI that we know the
current memory map and its constraints. Otherwise EFI can choose to
only partially exit until we pass the correct key. As we already use
the memory map to allocate memory for the kernel, split the previous
function into one simply retrieving the table and another one who uses
the map to allocate memory. At some point it would be nice to actually
pass the table to the kernel since its data is more reliable than the
FDT only. While there, sync a bit of style with the amd64 version.


# 1.4 04-Feb-2017 patrick

In reality our kernel does not need to be aligned at a 256M boundary,
but simply at 2M boundary. This might have been a requirement from
armv7, but it's not true for arm64. This also helps reduce memory
holes below the kernel.


# 1.3 03-Feb-2017 patrick

Explicitly ask EFI to allocate the page we picked out to lay our
kernel in, and not just use some memory address that we found in
the table.


# 1.2 22-Jan-2017 kettenis

Increment the right loop variable.

ok patrick@


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.