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

When loading a device tree using the "mach dtb" command, give firmware
a chance to make modifications (such as applying memory reservations)
by using the EFI devicetree fixup protocol.

ok patrick@, jca@


Revision tags: OPENBSD_7_5_BASE
# 1.47 26-Oct-2023 jsg

add cd9660


Revision tags: OPENBSD_7_4_BASE
# 1.46 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@


# 1.45 18-Apr-2023 dlg

add support for loading files from the EFI System Partition.

this means you can put a bsd.rd next to BOOTAA64.EFI and go "boot
esp0a:bsd.rd" (assuming bsd.rd is in the root of the boot partition).

cool! krw@
ok kettenis@ patrick@


Revision tags: OPENBSD_7_3_BASE
# 1.44 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.43 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.42 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.41 05-Nov-2022 patrick

Bump version number so that it's easier to see if the running version has
the bugfixes in.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.40 15-Aug-2022 kn

Add softraid(4) RAID 1C boot support

This is the arm64 adaptation of stsp's (commitid: p55cmsVoEH0fRg77)
"add support for booting from RAID 1C softraid(4) volumes on amd64".

Tell the boot loader to decrypt 1C like C volumes and check the number of
disks in 1C like in 1C volumes -- no new code rquired.

Tested on SolidRun CEX7
OK stsp

NB: While kernel and boot loader support root on softraid on arm64,
installboot(8) does not, i.e. default installations still require manual
disk preparation for now.


# 1.39 30-Jul-2022 patrick

Now that we have proper .text and .data sections we need to move dt_blob to
.data. dt_blob is a basic device tree that is populated from ACPI tables
when booting with ACPI instead of DT. Since we're modifying its content we
need to put it somewhere writeable.

Found and proposed by mlarkin@
ok kettenis@ mlarkin@


# 1.38 29-Jul-2022 kettenis

Give to PE/COFF file proper .text and .data sections, and fill in the
characteristics field in the COFF header. Makes our bootloader work in the
x13s. With help from mlarkin@.

ok mlarkin@


# 1.37 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.36 14-Mar-2022 kettenis

The current FDT code we use in the bootloader is buggy and will write into
memory beyond the actual FDT data structure when adding information to the
device tree. This is especially problematic on ACPI systems where we add
lots of information to the device tree based on ACPI tables. Fix the FDT
code to never write beyond the end of the data structure and panic if we
run out of free space. Raise the amount of free space frm 4K to 16K for
the proto-FDT we use on ACPI systems. Bump the version number of the
arm64 bootloader.

ok visa@, patrick@


# 1.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 26-Oct-2023 jsg

add cd9660


Revision tags: OPENBSD_7_4_BASE
# 1.46 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@


# 1.45 18-Apr-2023 dlg

add support for loading files from the EFI System Partition.

this means you can put a bsd.rd next to BOOTAA64.EFI and go "boot
esp0a:bsd.rd" (assuming bsd.rd is in the root of the boot partition).

cool! krw@
ok kettenis@ patrick@


Revision tags: OPENBSD_7_3_BASE
# 1.44 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.43 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.42 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.41 05-Nov-2022 patrick

Bump version number so that it's easier to see if the running version has
the bugfixes in.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.40 15-Aug-2022 kn

Add softraid(4) RAID 1C boot support

This is the arm64 adaptation of stsp's (commitid: p55cmsVoEH0fRg77)
"add support for booting from RAID 1C softraid(4) volumes on amd64".

Tell the boot loader to decrypt 1C like C volumes and check the number of
disks in 1C like in 1C volumes -- no new code rquired.

Tested on SolidRun CEX7
OK stsp

NB: While kernel and boot loader support root on softraid on arm64,
installboot(8) does not, i.e. default installations still require manual
disk preparation for now.


# 1.39 30-Jul-2022 patrick

Now that we have proper .text and .data sections we need to move dt_blob to
.data. dt_blob is a basic device tree that is populated from ACPI tables
when booting with ACPI instead of DT. Since we're modifying its content we
need to put it somewhere writeable.

Found and proposed by mlarkin@
ok kettenis@ mlarkin@


# 1.38 29-Jul-2022 kettenis

Give to PE/COFF file proper .text and .data sections, and fill in the
characteristics field in the COFF header. Makes our bootloader work in the
x13s. With help from mlarkin@.

ok mlarkin@


# 1.37 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.36 14-Mar-2022 kettenis

The current FDT code we use in the bootloader is buggy and will write into
memory beyond the actual FDT data structure when adding information to the
device tree. This is especially problematic on ACPI systems where we add
lots of information to the device tree based on ACPI tables. Fix the FDT
code to never write beyond the end of the data structure and panic if we
run out of free space. Raise the amount of free space frm 4K to 16K for
the proto-FDT we use on ACPI systems. Bump the version number of the
arm64 bootloader.

ok visa@, patrick@


# 1.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 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@


# 1.45 18-Apr-2023 dlg

add support for loading files from the EFI System Partition.

this means you can put a bsd.rd next to BOOTAA64.EFI and go "boot
esp0a:bsd.rd" (assuming bsd.rd is in the root of the boot partition).

cool! krw@
ok kettenis@ patrick@


Revision tags: OPENBSD_7_3_BASE
# 1.44 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.43 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.42 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.41 05-Nov-2022 patrick

Bump version number so that it's easier to see if the running version has
the bugfixes in.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.40 15-Aug-2022 kn

Add softraid(4) RAID 1C boot support

This is the arm64 adaptation of stsp's (commitid: p55cmsVoEH0fRg77)
"add support for booting from RAID 1C softraid(4) volumes on amd64".

Tell the boot loader to decrypt 1C like C volumes and check the number of
disks in 1C like in 1C volumes -- no new code rquired.

Tested on SolidRun CEX7
OK stsp

NB: While kernel and boot loader support root on softraid on arm64,
installboot(8) does not, i.e. default installations still require manual
disk preparation for now.


# 1.39 30-Jul-2022 patrick

Now that we have proper .text and .data sections we need to move dt_blob to
.data. dt_blob is a basic device tree that is populated from ACPI tables
when booting with ACPI instead of DT. Since we're modifying its content we
need to put it somewhere writeable.

Found and proposed by mlarkin@
ok kettenis@ mlarkin@


# 1.38 29-Jul-2022 kettenis

Give to PE/COFF file proper .text and .data sections, and fill in the
characteristics field in the COFF header. Makes our bootloader work in the
x13s. With help from mlarkin@.

ok mlarkin@


# 1.37 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.36 14-Mar-2022 kettenis

The current FDT code we use in the bootloader is buggy and will write into
memory beyond the actual FDT data structure when adding information to the
device tree. This is especially problematic on ACPI systems where we add
lots of information to the device tree based on ACPI tables. Fix the FDT
code to never write beyond the end of the data structure and panic if we
run out of free space. Raise the amount of free space frm 4K to 16K for
the proto-FDT we use on ACPI systems. Bump the version number of the
arm64 bootloader.

ok visa@, patrick@


# 1.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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.45 18-Apr-2023 dlg

add support for loading files from the EFI System Partition.

this means you can put a bsd.rd next to BOOTAA64.EFI and go "boot
esp0a:bsd.rd" (assuming bsd.rd is in the root of the boot partition).

cool! krw@
ok kettenis@ patrick@


Revision tags: OPENBSD_7_3_BASE
# 1.44 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.43 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.42 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.41 05-Nov-2022 patrick

Bump version number so that it's easier to see if the running version has
the bugfixes in.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.40 15-Aug-2022 kn

Add softraid(4) RAID 1C boot support

This is the arm64 adaptation of stsp's (commitid: p55cmsVoEH0fRg77)
"add support for booting from RAID 1C softraid(4) volumes on amd64".

Tell the boot loader to decrypt 1C like C volumes and check the number of
disks in 1C like in 1C volumes -- no new code rquired.

Tested on SolidRun CEX7
OK stsp

NB: While kernel and boot loader support root on softraid on arm64,
installboot(8) does not, i.e. default installations still require manual
disk preparation for now.


# 1.39 30-Jul-2022 patrick

Now that we have proper .text and .data sections we need to move dt_blob to
.data. dt_blob is a basic device tree that is populated from ACPI tables
when booting with ACPI instead of DT. Since we're modifying its content we
need to put it somewhere writeable.

Found and proposed by mlarkin@
ok kettenis@ mlarkin@


# 1.38 29-Jul-2022 kettenis

Give to PE/COFF file proper .text and .data sections, and fill in the
characteristics field in the COFF header. Makes our bootloader work in the
x13s. With help from mlarkin@.

ok mlarkin@


# 1.37 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.36 14-Mar-2022 kettenis

The current FDT code we use in the bootloader is buggy and will write into
memory beyond the actual FDT data structure when adding information to the
device tree. This is especially problematic on ACPI systems where we add
lots of information to the device tree based on ACPI tables. Fix the FDT
code to never write beyond the end of the data structure and panic if we
run out of free space. Raise the amount of free space frm 4K to 16K for
the proto-FDT we use on ACPI systems. Bump the version number of the
arm64 bootloader.

ok visa@, patrick@


# 1.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 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.43 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.42 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.41 05-Nov-2022 patrick

Bump version number so that it's easier to see if the running version has
the bugfixes in.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.40 15-Aug-2022 kn

Add softraid(4) RAID 1C boot support

This is the arm64 adaptation of stsp's (commitid: p55cmsVoEH0fRg77)
"add support for booting from RAID 1C softraid(4) volumes on amd64".

Tell the boot loader to decrypt 1C like C volumes and check the number of
disks in 1C like in 1C volumes -- no new code rquired.

Tested on SolidRun CEX7
OK stsp

NB: While kernel and boot loader support root on softraid on arm64,
installboot(8) does not, i.e. default installations still require manual
disk preparation for now.


# 1.39 30-Jul-2022 patrick

Now that we have proper .text and .data sections we need to move dt_blob to
.data. dt_blob is a basic device tree that is populated from ACPI tables
when booting with ACPI instead of DT. Since we're modifying its content we
need to put it somewhere writeable.

Found and proposed by mlarkin@
ok kettenis@ mlarkin@


# 1.38 29-Jul-2022 kettenis

Give to PE/COFF file proper .text and .data sections, and fill in the
characteristics field in the COFF header. Makes our bootloader work in the
x13s. With help from mlarkin@.

ok mlarkin@


# 1.37 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.36 14-Mar-2022 kettenis

The current FDT code we use in the bootloader is buggy and will write into
memory beyond the actual FDT data structure when adding information to the
device tree. This is especially problematic on ACPI systems where we add
lots of information to the device tree based on ACPI tables. Fix the FDT
code to never write beyond the end of the data structure and panic if we
run out of free space. Raise the amount of free space frm 4K to 16K for
the proto-FDT we use on ACPI systems. Bump the version number of the
arm64 bootloader.

ok visa@, patrick@


# 1.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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.43 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.42 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.41 05-Nov-2022 patrick

Bump version number so that it's easier to see if the running version has
the bugfixes in.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.40 15-Aug-2022 kn

Add softraid(4) RAID 1C boot support

This is the arm64 adaptation of stsp's (commitid: p55cmsVoEH0fRg77)
"add support for booting from RAID 1C softraid(4) volumes on amd64".

Tell the boot loader to decrypt 1C like C volumes and check the number of
disks in 1C like in 1C volumes -- no new code rquired.

Tested on SolidRun CEX7
OK stsp

NB: While kernel and boot loader support root on softraid on arm64,
installboot(8) does not, i.e. default installations still require manual
disk preparation for now.


# 1.39 30-Jul-2022 patrick

Now that we have proper .text and .data sections we need to move dt_blob to
.data. dt_blob is a basic device tree that is populated from ACPI tables
when booting with ACPI instead of DT. Since we're modifying its content we
need to put it somewhere writeable.

Found and proposed by mlarkin@
ok kettenis@ mlarkin@


# 1.38 29-Jul-2022 kettenis

Give to PE/COFF file proper .text and .data sections, and fill in the
characteristics field in the COFF header. Makes our bootloader work in the
x13s. With help from mlarkin@.

ok mlarkin@


# 1.37 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.36 14-Mar-2022 kettenis

The current FDT code we use in the bootloader is buggy and will write into
memory beyond the actual FDT data structure when adding information to the
device tree. This is especially problematic on ACPI systems where we add
lots of information to the device tree based on ACPI tables. Fix the FDT
code to never write beyond the end of the data structure and panic if we
run out of free space. Raise the amount of free space frm 4K to 16K for
the proto-FDT we use on ACPI systems. Bump the version number of the
arm64 bootloader.

ok visa@, patrick@


# 1.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 05-Nov-2022 patrick

Bump version number so that it's easier to see if the running version has
the bugfixes in.

ok kettenis@


Revision tags: OPENBSD_7_2_BASE
# 1.40 15-Aug-2022 kn

Add softraid(4) RAID 1C boot support

This is the arm64 adaptation of stsp's (commitid: p55cmsVoEH0fRg77)
"add support for booting from RAID 1C softraid(4) volumes on amd64".

Tell the boot loader to decrypt 1C like C volumes and check the number of
disks in 1C like in 1C volumes -- no new code rquired.

Tested on SolidRun CEX7
OK stsp

NB: While kernel and boot loader support root on softraid on arm64,
installboot(8) does not, i.e. default installations still require manual
disk preparation for now.


# 1.39 30-Jul-2022 patrick

Now that we have proper .text and .data sections we need to move dt_blob to
.data. dt_blob is a basic device tree that is populated from ACPI tables
when booting with ACPI instead of DT. Since we're modifying its content we
need to put it somewhere writeable.

Found and proposed by mlarkin@
ok kettenis@ mlarkin@


# 1.38 29-Jul-2022 kettenis

Give to PE/COFF file proper .text and .data sections, and fill in the
characteristics field in the COFF header. Makes our bootloader work in the
x13s. With help from mlarkin@.

ok mlarkin@


# 1.37 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.36 14-Mar-2022 kettenis

The current FDT code we use in the bootloader is buggy and will write into
memory beyond the actual FDT data structure when adding information to the
device tree. This is especially problematic on ACPI systems where we add
lots of information to the device tree based on ACPI tables. Fix the FDT
code to never write beyond the end of the data structure and panic if we
run out of free space. Raise the amount of free space frm 4K to 16K for
the proto-FDT we use on ACPI systems. Bump the version number of the
arm64 bootloader.

ok visa@, patrick@


# 1.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 15-Aug-2022 kn

Add softraid(4) RAID 1C boot support

This is the arm64 adaptation of stsp's (commitid: p55cmsVoEH0fRg77)
"add support for booting from RAID 1C softraid(4) volumes on amd64".

Tell the boot loader to decrypt 1C like C volumes and check the number of
disks in 1C like in 1C volumes -- no new code rquired.

Tested on SolidRun CEX7
OK stsp

NB: While kernel and boot loader support root on softraid on arm64,
installboot(8) does not, i.e. default installations still require manual
disk preparation for now.


# 1.39 30-Jul-2022 patrick

Now that we have proper .text and .data sections we need to move dt_blob to
.data. dt_blob is a basic device tree that is populated from ACPI tables
when booting with ACPI instead of DT. Since we're modifying its content we
need to put it somewhere writeable.

Found and proposed by mlarkin@
ok kettenis@ mlarkin@


# 1.38 29-Jul-2022 kettenis

Give to PE/COFF file proper .text and .data sections, and fill in the
characteristics field in the COFF header. Makes our bootloader work in the
x13s. With help from mlarkin@.

ok mlarkin@


# 1.37 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.36 14-Mar-2022 kettenis

The current FDT code we use in the bootloader is buggy and will write into
memory beyond the actual FDT data structure when adding information to the
device tree. This is especially problematic on ACPI systems where we add
lots of information to the device tree based on ACPI tables. Fix the FDT
code to never write beyond the end of the data structure and panic if we
run out of free space. Raise the amount of free space frm 4K to 16K for
the proto-FDT we use on ACPI systems. Bump the version number of the
arm64 bootloader.

ok visa@, patrick@


# 1.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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.39 30-Jul-2022 patrick

Now that we have proper .text and .data sections we need to move dt_blob to
.data. dt_blob is a basic device tree that is populated from ACPI tables
when booting with ACPI instead of DT. Since we're modifying its content we
need to put it somewhere writeable.

Found and proposed by mlarkin@
ok kettenis@ mlarkin@


# 1.38 29-Jul-2022 kettenis

Give to PE/COFF file proper .text and .data sections, and fill in the
characteristics field in the COFF header. Makes our bootloader work in the
x13s. With help from mlarkin@.

ok mlarkin@


# 1.37 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.36 14-Mar-2022 kettenis

The current FDT code we use in the bootloader is buggy and will write into
memory beyond the actual FDT data structure when adding information to the
device tree. This is especially problematic on ACPI systems where we add
lots of information to the device tree based on ACPI tables. Fix the FDT
code to never write beyond the end of the data structure and panic if we
run out of free space. Raise the amount of free space frm 4K to 16K for
the proto-FDT we use on ACPI systems. Bump the version number of the
arm64 bootloader.

ok visa@, patrick@


# 1.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 29-Jul-2022 kettenis

Give to PE/COFF file proper .text and .data sections, and fill in the
characteristics field in the COFF header. Makes our bootloader work in the
x13s. With help from mlarkin@.

ok mlarkin@


# 1.37 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.36 14-Mar-2022 kettenis

The current FDT code we use in the bootloader is buggy and will write into
memory beyond the actual FDT data structure when adding information to the
device tree. This is especially problematic on ACPI systems where we add
lots of information to the device tree based on ACPI tables. Fix the FDT
code to never write beyond the end of the data structure and panic if we
run out of free space. Raise the amount of free space frm 4K to 16K for
the proto-FDT we use on ACPI systems. Bump the version number of the
arm64 bootloader.

ok visa@, patrick@


# 1.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 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.36 14-Mar-2022 kettenis

The current FDT code we use in the bootloader is buggy and will write into
memory beyond the actual FDT data structure when adding information to the
device tree. This is especially problematic on ACPI systems where we add
lots of information to the device tree based on ACPI tables. Fix the FDT
code to never write beyond the end of the data structure and panic if we
run out of free space. Raise the amount of free space frm 4K to 16K for
the proto-FDT we use on ACPI systems. Bump the version number of the
arm64 bootloader.

ok visa@, patrick@


# 1.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 14-Mar-2022 kettenis

The current FDT code we use in the bootloader is buggy and will write into
memory beyond the actual FDT data structure when adding information to the
device tree. This is especially problematic on ACPI systems where we add
lots of information to the device tree based on ACPI tables. Fix the FDT
code to never write beyond the end of the data structure and panic if we
run out of free space. Raise the amount of free space frm 4K to 16K for
the proto-FDT we use on ACPI systems. Bump the version number of the
arm64 bootloader.

ok visa@, patrick@


# 1.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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.35 14-Dec-2021 kettenis

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

ok 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 02-Jun-2021 kettenis

Add support for booting from disks with 4k sectors. Inspired by the
code we already have for amd64, but changed to use EFI memory allocation
interfaces as some implementations seem to insist on page-aligned memory.

ok krw@


Revision tags: OPENBSD_6_9_BASE
# 1.32 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 09-Feb-2021 kettenis

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

ok patrick@


# 1.31 09-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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-Dec-2020 krw

Use daddr_t and not daddr32_t in boot media.

At a minimum, amd64/i386 should now boot from 4TB GPT formatted disks.

More daddr32_t terminations with extreme prejudice to follow.

Tested by various, in snaps for a few days.

ok deraadt@


Revision tags: OPENBSD_6_8_BASE
# 1.30 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 26-May-2020 deraadt

increment version numbers, due to recent RB_GOODSEED and fchmod +T changes


# 1.29 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 18-May-2020 patrick

Our check to see if the EFI services support Mtftp() doesn't work
on U-Boot anymore, since we checked if the method is provided, but
now U-Boot provides a simple stub that only returns EFI_UNSUPPORTED.
A proper UEFI would throw EFI_INVALID_PARAMETER if we pass NULL
as first parameter, but U-Boot doesn't. This way we can see if
the method is actually provided and not just a stub.

ok kettenis@


# 1.28 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 11-May-2020 kettenis

Should have bumped this to 1.0 a long time ago.


Revision tags: OPENBSD_6_7_BASE
# 1.27 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 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.26 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 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@


# 1.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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.25 29-Feb-2020 otto

Allow arm64 efiboot(8) to read from an ffs2 filesystem. ok kettenis@


# 1.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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.24 29-Oct-2019 deraadt

Use arc4 to bit-spread the 512-byte random buffer over the .openbsd.randomdata
section, which has grown a fair bit with the introduction of retguard.
Mortimer discovered the repeated 512-byte sequence as retguard keys, and
this resolves the issue. (Chacha does not fit on the media, so 1.5K early
drop RC4 is hopefully sufficient in our KARL link universe)
Version crank the bootblocks. sysupgrade -s will install new bootblocks.
ok djm mortimer


Revision tags: OPENBSD_6_6_BASE
# 1.23 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 13-Aug-2019 patrick

Allow PXE booting using u-boot by relaxing our requirements
of the EFI PXE protocol. This also brings us in line with
the GRUB2 implementation.

Tested by naddy@ to behave the same
Tested by sven falempin on his Pine64


# 1.22 12-Aug-2019 kettenis

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

ok patrick@


# 1.21 04-Aug-2019 deraadt

crank version, following fchmod change


# 1.20 03-Aug-2019 deraadt

In the bootblocks, after discovering and opening /bsd.upgrade, fchmod -x
so the file cannot be re-executed upon the next boot. This provides a
stronger one-shot-upgrade model than the upgrade script's rm /bsd.upgrade.
Now various forms of upgrade failure will reboot into /bsd, which is probably
more recoverable. Performing fchmod -x depends on (1) use of MI boot.c
(not alpha/macppc/sparc64/sgi/octeon) and (2) "can write blocks" functionality
in the IO layer. Most architectures have this support now.

Two diagnostics "fchmod a-x %s: failed" and "/bsd.upgrade is not u+x" will
remain in the tree while refinements happen for some of the laggard
architectures.

based upon a discussion florian
tested in snapshots for more than a week without any complaints


Revision tags: OPENBSD_6_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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_5_BASE
# 1.19 10-Apr-2019 deraadt

crank versions


# 1.18 08-Apr-2019 florian

crank version; looks good deraadt


# 1.17 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 31-Jan-2019 kettenis

Bump version number to be able to distinguish bootloaders with softraid
support.


# 1.16 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.15 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 08-Apr-2018 kettenis

Add support for the EFI Random Number Generator Protocol and use it to XOR
random data into the buffer that we feed the kernel.

ok deraadt@


# 1.14 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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 31-Mar-2018 patrick

Bump version number so that we can see if efiboot(8) supports EFI's Simple
Network protocol or not.


# 1.13 31-Mar-2018 patrick

In addition to using EFI's PXE protocol implement a network driver that
makes use of EFI's Simple Network protocol. This allows us to speak
raw network on U-Boot based machines so we can do TFTP boot on those as
well.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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.12 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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.11 30-Jan-2018 naddy

Fix TFTP reading of zero-size files:

The AllocatePages EFI call returns an error when the allocation
size is 0. Skip allocating memory and actually transferring the
file when it is empty.

Properly return the number of unread bytes so that a read() of n
bytes does not return n if no bytes were read.

While here, disallow lseek() beyond the TFTP file buffer for SEEK_CUR
as we already do for SEEK_SET.

ok patrick@


# 1.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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.10 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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.9 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


# 1.8 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.7 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.6 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.5 29-Jul-2017 kettenis

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

ok patrick@


# 1.4 24-Jul-2017 patrick

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


# 1.3 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.2 08-Feb-2017 patrick

Pass the physical address to the end of symbols to the kernel. From
armv7 we inherited the mechanism to manually modify the kernel symbol
table to change the value of esym. We don't use this, but instead use
the virtual address that is passed to the kernel. This change makes us
only work on and hand out physical addresses. Bump the efiboot version
to make this ABI change more visible.


# 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.