All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 6/9] efi_loader: Add runtime services
Date: Fri, 15 Jan 2016 01:26:42 +0100	[thread overview]
Message-ID: <56983CC2.3000306@suse.de> (raw)
In-Reply-To: <20151226183304.GZ25034@bivouac.eciton.net>



On 26.12.15 19:33, Leif Lindholm wrote:
> On Tue, Dec 22, 2015 at 02:57:53PM +0100, Alexander Graf wrote:
>> After booting has finished, EFI allows firmware to still interact with the OS
>> using the "runtime services". These callbacks live in a separate address space,
>> since they are available long after U-Boot has been overwritten by the OS.
>>
>> However, since U-Boot has no notion of RTS, we just create an extremely minimal
>> RTS stub that just declares all functions as unsupported. We could in the future
>> map U-boot environment variables to EFI variables here.
>>
>> Signed-off-by: Alexander Graf <agraf@suse.de>
>> ---
>>  arch/arm/cpu/armv8/u-boot.lds |  8 ++++++
>>  arch/arm/cpu/u-boot.lds       | 13 ++++++++++
>>  arch/arm/lib/sections.c       |  2 ++
>>  include/efi_loader.h          |  3 +++
>>  lib/efi_loader/efi_runtime.c  | 59 +++++++++++++++++++++++++++++++++++++++++++
>>  5 files changed, 85 insertions(+)
>>  create mode 100644 lib/efi_loader/efi_runtime.c
>>
>> diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds
>> index 4c12222..7c5b032 100644
>> --- a/arch/arm/cpu/armv8/u-boot.lds
>> +++ b/arch/arm/cpu/armv8/u-boot.lds
>> @@ -42,6 +42,14 @@ SECTIONS
>>  
>>  	. = ALIGN(8);
>>  
>> +	.efi_runtime : {
>> +                __efi_runtime_start = .;
>> +		*(efi_runtime)
>> +                __efi_runtime_stop = .;
>> +	}
>> +
>> +	. = ALIGN(8);
>> +
>>  	.image_copy_end :
>>  	{
>>  		*(.__image_copy_end)
>> diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
>> index d48a905..b5198d0 100644
>> --- a/arch/arm/cpu/u-boot.lds
>> +++ b/arch/arm/cpu/u-boot.lds
>> @@ -89,6 +89,19 @@ SECTIONS
>>  
>>  	. = ALIGN(4);
>>  
>> +	.__efi_runtime_start : {
>> +		*(.__efi_runtime_start)
>> +	}
>> +
>> +	.efi_runtime : {
>> +		*(efi_runtime)
>> +	}
>> +
>> +	.__efi_runtime_stop : {
>> +		*(.__efi_runtime_stop)
>> +	}
>> +	. = ALIGN(4);
>> +
>>  	.image_copy_end :
>>  	{
>>  		*(.__image_copy_end)
>> diff --git a/arch/arm/lib/sections.c b/arch/arm/lib/sections.c
>> index a1205c3..21b3066 100644
>> --- a/arch/arm/lib/sections.c
>> +++ b/arch/arm/lib/sections.c
>> @@ -27,4 +27,6 @@ char __rel_dyn_start[0] __attribute__((section(".__rel_dyn_start")));
>>  char __rel_dyn_end[0] __attribute__((section(".__rel_dyn_end")));
>>  char __secure_start[0] __attribute__((section(".__secure_start")));
>>  char __secure_end[0] __attribute__((section(".__secure_end")));
>> +char __efi_runtime_start[0] __attribute__((section(".__efi_runtime_start")));
>> +char __efi_runtime_stop[0] __attribute__((section(".__efi_runtime_stop")));
>>  char _end[0] __attribute__((section(".__end")));
>> diff --git a/include/efi_loader.h b/include/efi_loader.h
>> index 7fb2106..af1c88f 100644
>> --- a/include/efi_loader.h
>> +++ b/include/efi_loader.h
>> @@ -39,6 +39,7 @@
>>  
>>  #define EFI_EXIT(ret) efi_exit_func(ret);
>>  
>> +extern const struct efi_runtime_services efi_runtime_services;
>>  extern struct efi_system_table systab;
>>  
>>  extern const struct efi_simple_text_output_protocol efi_con_out;
>> @@ -49,6 +50,8 @@ extern const efi_guid_t efi_guid_console_control;
>>  extern const efi_guid_t efi_guid_device_path;
>>  extern const efi_guid_t efi_guid_loaded_image;
>>  
>> +extern unsigned int __efi_runtime_start, __efi_runtime_stop;
>> +
>>  struct efi_class_map {
>>  	const efi_guid_t *guid;
>>  	const void *interface;
>> diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
>> new file mode 100644
>> index 0000000..214e1f5
>> --- /dev/null
>> +++ b/lib/efi_loader/efi_runtime.c
>> @@ -0,0 +1,59 @@
>> +/*
>> + *  EFI application runtime services
>> + *
>> + *  Copyright (c) 2015 Alexander Graf
>> + *
>> + *  This library is free software; you can redistribute it and/or
>> + *  modify it under the terms of the GNU Lesser General Public
>> + *  License as published by the Free Software Foundation; either
>> + *  version 2.1 of the License, or (at your option) any later version.
>> + *
>> + *  This library is distributed in the hope that it will be useful,
>> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + *  Lesser General Public License for more details.
>> + *
>> + *  You should have received a copy of the GNU Lesser General Public
>> + *  License along with this library; if not, write to the Free Software
>> + *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
>> + *
>> + *  SPDX-License-Identifier:     LGPL-2.1+
>> + */
>> +
>> +#include <common.h>
>> +#include <efi_loader.h>
>> +
>> +/*
>> + * EFI Runtime code is still alive when U-Boot is long overwritten. To isolate
>> + * this code from the rest, we put it into a special section.
>> + *
>> + *        !!WARNING!!
>> + *
>> + * This means that we can not rely on any code outside of this file at runtime.
>> + * Please keep it fully self-contained.
>> + */
>> +asm(".section efi_runtime,\"a\"");
>> +
>> +static efi_status_t efi_unimplemented(void)
>> +{
>> +	return EFI_UNSUPPORTED;
> 
> Again, EFI_UNSUPPORTED is not necessarily a valid return value for all
> runtime services.
> 
>> +}
>> +
>> +const struct efi_runtime_services efi_runtime_services = {
>> +	.hdr = {
>> +		.signature = EFI_RUNTIME_SERVICES_SIGNATURE,
>> +		.revision = EFI_RUNTIME_SERVICES_REVISION,
>> +		.headersize = sizeof(struct efi_table_hdr),
>> +	},
>> +	.get_time = (void *)&efi_unimplemented,
> 
> EFI_DEVICE_ERROR
> 
>> +	.set_time = (void *)&efi_unimplemented,
> 
> EFI_DEVICE_ERROR
> 
>> +	.get_wakeup_time = (void *)&efi_unimplemented,
>> +	.set_wakeup_time = (void *)&efi_unimplemented,
> 
> Both of these are fine, and correct, to return EFI_UNSUPPORTED.
> 
>> +	.set_virtual_address_map = (void *)&efi_unimplemented,
>> +	.convert_pointer = (void *)&efi_unimplemented,
> 
> There really isn't a way to gracefully decline these two functions.
> All valid error codes refer to invalid inputs.

Ok, changing to EFI_INVALID_PARAMETER then :).

> 
>> +	.get_variable = (void *)&efi_unimplemented,
> 
> EFI_DEVICE_ERROR would probably be the closest thing to a correct
> return code in this instance.
> 
>> +	.get_next_variable = (void *)&efi_unimplemented,
> 
> (get_next_variable_name?)

git blame says it's Simon's fault :).

867a6ac8 (Simon Glass    2015-07-31 09:31:36 -0600 170)
efi_status_t (EFIAPI *get_next_variable)(
867a6ac8 (Simon Glass    2015-07-31 09:31:36 -0600 171)
        unsigned long *variable_name_size,
867a6ac8 (Simon Glass    2015-07-31 09:31:36 -0600 172)
        s16 *variable_name, efi_guid_t *vendor);

> Again, EFI_DEVICE_ERROR, is probably the least wrong return value.
> 
>> +	.set_variable = (void *)&efi_unimplemented,
> 
> EFI_DEVICE_ERROR
> 
>> +	.get_next_high_mono_count = (void *)&efi_unimplemented,
> 
> EFI_DEVICE_ERROR
> 

Ok, fixed all of the above.

>> +	.reset_system = (void *)&efi_unimplemented,
> 
> "The ResetSystem() function does not return."

Hrm, I think returning EFI_UNSUPPORTED is still better than while(1) {
}. With the return an OS at least has the chance to fix things up itself.


Alex

  reply	other threads:[~2016-01-15  0:26 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-22 13:57 [U-Boot] [PATCH 0/9] EFI payload / application support Alexander Graf
2015-12-22 13:57 ` [U-Boot] [PATCH 1/9] disk/part.c: Expose a list of available block drivers Alexander Graf
2016-01-14 19:18   ` Tom Rini
2016-01-14 23:11   ` Simon Glass
2016-01-14 23:33     ` Alexander Graf
2016-01-15  0:46       ` Simon Glass
2016-01-15  1:04         ` Alexander Graf
2015-12-22 13:57 ` [U-Boot] [PATCH 2/9] include/efi_api.h: Add more detailed API definitions Alexander Graf
2015-12-22 13:57 ` [U-Boot] [PATCH 3/9] efi_loader: Add PE image loader Alexander Graf
2015-12-26 16:26   ` Leif Lindholm
2016-01-14 23:45     ` Alexander Graf
2016-01-15 12:29       ` Leif Lindholm
2015-12-22 13:57 ` [U-Boot] [PATCH 4/9] efi_loader: Add boot time services Alexander Graf
2015-12-22 14:15   ` Andreas Färber
2015-12-22 14:31     ` Alexander Graf
2015-12-26 18:09   ` Leif Lindholm
2016-01-15  0:13     ` Alexander Graf
2016-01-15 13:02       ` Leif Lindholm
2016-01-15 14:14         ` Alexander Graf
2016-01-15 14:21           ` Leif Lindholm
2016-01-15 17:04             ` Alexander Graf
2016-01-15  3:40     ` Alexander Graf
2015-12-22 13:57 ` [U-Boot] [PATCH 5/9] efi_loader: Add console interface Alexander Graf
2015-12-22 13:57 ` [U-Boot] [PATCH 6/9] efi_loader: Add runtime services Alexander Graf
2015-12-26 18:33   ` Leif Lindholm
2016-01-15  0:26     ` Alexander Graf [this message]
2016-01-15 13:52       ` Leif Lindholm
2016-01-15 14:15         ` Alexander Graf
2016-01-15 14:22           ` Leif Lindholm
2015-12-22 13:57 ` [U-Boot] [PATCH 7/9] efi_loader: Add disk interfaces Alexander Graf
2016-01-15  1:37   ` Simon Glass
2016-01-15  2:40     ` Alexander Graf
2015-12-22 13:57 ` [U-Boot] [PATCH 8/9] efi_loader: Add "bootefi" command Alexander Graf
2015-12-24 11:15   ` Matwey V. Kornilov
2015-12-25  9:02     ` Alexander Graf
2015-12-25  9:25       ` Andreas Färber
2015-12-25  9:40         ` Matwey V. Kornilov
2015-12-25 17:04           ` Tom Rini
2015-12-26 18:55         ` Leif Lindholm
2015-12-27 15:33           ` Alexander Graf
2015-12-26 18:45       ` Leif Lindholm
2015-12-25 16:58     ` Tom Rini
2015-12-22 13:57 ` [U-Boot] [PATCH 9/9] efi_loader: hook up in build environment Alexander Graf
2015-12-22 18:28 ` [U-Boot] [PATCH 0/9] EFI payload / application support Matwey V. Kornilov
2015-12-22 20:32   ` Alexander Graf
2015-12-25  3:29 ` Tom Rini
2015-12-25  8:53   ` Alexander Graf
2015-12-25 16:50     ` Tom Rini
2015-12-25 16:53       ` Matwey V. Kornilov
2015-12-25 17:00         ` Tom Rini
2016-01-15  3:00       ` Alexander Graf
2016-01-15  3:06         ` Tom Rini
2015-12-25 19:34 ` Blibbet
2015-12-26 15:31 ` Leif Lindholm
2015-12-26 16:27   ` Alexander Graf
2015-12-26 19:34     ` Leif Lindholm
2016-01-04 16:25       ` Alexander Graf
2016-01-04 16:56         ` Tom Rini
2016-01-04 18:03           ` Andreas Färber
2016-01-04 18:41             ` Andreas Färber
2016-01-04 19:54               ` Tom Rini
2016-01-04 22:37                 ` Dennis Gilmore
2016-01-04 22:48                   ` Alexander Graf
2016-01-15  3:40             ` Peter Robinson
2016-01-04 20:11           ` Matwey V. Kornilov
2016-01-15  3:32           ` Peter Robinson
2015-12-27 18:10   ` Tom Rini
2015-12-27 18:39     ` Leif Lindholm
2015-12-27 19:48       ` Tom Rini
2016-01-05 20:18       ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56983CC2.3000306@suse.de \
    --to=agraf@suse.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.