diff mbox series

[U-Boot,v3,15/18] efi_loader: output load options in helloworld

Message ID 20171126130523.4993-16-xypron.glpk@gmx.de
State Accepted
Delegated to: Alexander Graf
Headers show
Series efi_loader: manage protocols in a linked list (v3) | expand

Commit Message

Heinrich Schuchardt Nov. 26, 2017, 1:05 p.m. UTC
We need to test if we pass a valid image handle when loading
and EFI application. This cannot be done in efi_selftest as
it is not loaded as an image.

So let's enhance helloworld a bit.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v3
	no change
v2
	new patch
---
 lib/efi_loader/helloworld.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

Comments

Florian Fainelli Dec. 9, 2017, 11:09 p.m. UTC | #1
On 11/26/2017 05:05 AM, Heinrich Schuchardt wrote:
> We need to test if we pass a valid image handle when loading
> and EFI application. This cannot be done in efi_selftest as
> it is not loaded as an image.
> 
> So let's enhance helloworld a bit.
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

This particular patch/commit bbf75dd9345d0b1a7ec7a50016547eb7c759b7af
("efi_loader: output load options in helloworld") was bisected and
causes the Lamobo_R1_defconfig build using the toolchain at [1] to fail
with:

/home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
error: required section '.got' not found in the linker script
/home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
final link failed: Invalid operation
scripts/Makefile.lib:409: recipe for target
'lib/efi_loader/helloworld_efi.so' failed
make[2]: *** [lib/efi_loader/helloworld_efi.so] Error 1
rm lib/efi_loader/helloworld.o
scripts/Makefile.build:425: recipe for target 'lib/efi_loader' failed
make[1]: *** [lib/efi_loader] Error 2

[1]: https://github.com/Broadcom/stbgcc-6.3/releases/tag/stbgcc-6.3-1.1

> ---
> v3
> 	no change
> v2
> 	new patch
> ---
>  lib/efi_loader/helloworld.c | 37 +++++++++++++++++++++++++++++++++++--
>  1 file changed, 35 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/efi_loader/helloworld.c b/lib/efi_loader/helloworld.c
> index 77130a36dd..e59c24c788 100644
> --- a/lib/efi_loader/helloworld.c
> +++ b/lib/efi_loader/helloworld.c
> @@ -5,19 +5,52 @@
>   * Written by Simon Glass <sjg@chromium.org>
>   *
>   * SPDX-License-Identifier:     GPL-2.0+
> + *
> + * This program demonstrates calling a boottime service.
> + * It writes a greeting and the load options to the console.
>   */
>  
>  #include <common.h>
>  #include <efi_api.h>
>  
> +/*
> + * Entry point of the EFI application.
> + *
> + * @handle	handle of the loaded image
> + * @systable	system table
> + * @return	status code
> + */
>  efi_status_t EFIAPI efi_main(efi_handle_t handle,
>  			     struct efi_system_table *systable)
>  {
>  	struct efi_simple_text_output_protocol *con_out = systable->con_out;
>  	struct efi_boot_services *boottime = systable->boottime;
> +	struct efi_loaded_image *loaded_image;
> +	const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
> +	efi_status_t ret;
>  
>  	con_out->output_string(con_out, L"Hello, world!\n");
> -	boottime->exit(handle, 0, 0, NULL);
>  
> -	return EFI_SUCCESS;
> +	/* Get the loaded image protocol */
> +	ret = boottime->handle_protocol(handle, &loaded_image_guid,
> +					(void **)&loaded_image);
> +	if (ret != EFI_SUCCESS) {
> +		con_out->output_string(con_out,
> +				       L"Cannot open loaded image protocol\n");
> +		goto out;
> +	}
> +	/* Output the load options */
> +	con_out->output_string(con_out, L"Load options: ");
> +	if (loaded_image->load_options_size && loaded_image->load_options)
> +		con_out->output_string(con_out,
> +				       (u16 *)loaded_image->load_options);
> +	else
> +		con_out->output_string(con_out, L"<none>");
> +	con_out->output_string(con_out, L"\n");
> +
> +out:
> +	boottime->exit(handle, ret, 0, NULL);
> +
> +	/* We should never arrive here */
> +	return ret;
>  }
>
Heinrich Schuchardt Dec. 10, 2017, 6:40 a.m. UTC | #2
On 12/10/2017 12:09 AM, Florian Fainelli wrote:
> 
> 
> On 11/26/2017 05:05 AM, Heinrich Schuchardt wrote:
>> We need to test if we pass a valid image handle when loading
>> and EFI application. This cannot be done in efi_selftest as
>> it is not loaded as an image.
>>
>> So let's enhance helloworld a bit.
>>
>> Reviewed-by: Simon Glass <sjg@chromium.org>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> 
> This particular patch/commit bbf75dd9345d0b1a7ec7a50016547eb7c759b7af
> ("efi_loader: output load options in helloworld") was bisected and
> causes the Lamobo_R1_defconfig build using the toolchain at [1] to fail
> with:
> 
> /home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
> error: required section '.got' not found in the linker script
> /home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
> final link failed: Invalid operation
> scripts/Makefile.lib:409: recipe for target
> 'lib/efi_loader/helloworld_efi.so' failed
> make[2]: *** [lib/efi_loader/helloworld_efi.so] Error 1
> rm lib/efi_loader/helloworld.o
> scripts/Makefile.build:425: recipe for target 'lib/efi_loader' failed
> make[1]: *** [lib/efi_loader] Error 2
> 
> [1]: https://github.com/Broadcom/stbgcc-6.3/releases/tag/stbgcc-6.3-1.1
> 

Isn't this fixed by
http://git.denx.de/?p=u-boot.git;a=commit;h=3bb74f9800cdc4cf10a87f2725242c2565256654
"efi_loader helloworld.efi: Fix building with -Os" ?

Best Regards

Heinrich

>> ---
>> v3
>> 	no change
>> v2
>> 	new patch
>> ---
>>   lib/efi_loader/helloworld.c | 37 +++++++++++++++++++++++++++++++++++--
>>   1 file changed, 35 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/efi_loader/helloworld.c b/lib/efi_loader/helloworld.c
>> index 77130a36dd..e59c24c788 100644
>> --- a/lib/efi_loader/helloworld.c
>> +++ b/lib/efi_loader/helloworld.c
>> @@ -5,19 +5,52 @@
>>    * Written by Simon Glass <sjg@chromium.org>
>>    *
>>    * SPDX-License-Identifier:     GPL-2.0+
>> + *
>> + * This program demonstrates calling a boottime service.
>> + * It writes a greeting and the load options to the console.
>>    */
>>   
>>   #include <common.h>
>>   #include <efi_api.h>
>>   
>> +/*
>> + * Entry point of the EFI application.
>> + *
>> + * @handle	handle of the loaded image
>> + * @systable	system table
>> + * @return	status code
>> + */
>>   efi_status_t EFIAPI efi_main(efi_handle_t handle,
>>   			     struct efi_system_table *systable)
>>   {
>>   	struct efi_simple_text_output_protocol *con_out = systable->con_out;
>>   	struct efi_boot_services *boottime = systable->boottime;
>> +	struct efi_loaded_image *loaded_image;
>> +	const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
>> +	efi_status_t ret;
>>   
>>   	con_out->output_string(con_out, L"Hello, world!\n");
>> -	boottime->exit(handle, 0, 0, NULL);
>>   
>> -	return EFI_SUCCESS;
>> +	/* Get the loaded image protocol */
>> +	ret = boottime->handle_protocol(handle, &loaded_image_guid,
>> +					(void **)&loaded_image);
>> +	if (ret != EFI_SUCCESS) {
>> +		con_out->output_string(con_out,
>> +				       L"Cannot open loaded image protocol\n");
>> +		goto out;
>> +	}
>> +	/* Output the load options */
>> +	con_out->output_string(con_out, L"Load options: ");
>> +	if (loaded_image->load_options_size && loaded_image->load_options)
>> +		con_out->output_string(con_out,
>> +				       (u16 *)loaded_image->load_options);
>> +	else
>> +		con_out->output_string(con_out, L"<none>");
>> +	con_out->output_string(con_out, L"\n");
>> +
>> +out:
>> +	boottime->exit(handle, ret, 0, NULL);
>> +
>> +	/* We should never arrive here */
>> +	return ret;
>>   }
>>
>
Florian Fainelli Dec. 10, 2017, 10:20 p.m. UTC | #3
On 12/09/2017 10:40 PM, Heinrich Schuchardt wrote:
> On 12/10/2017 12:09 AM, Florian Fainelli wrote:
>>
>>
>> On 11/26/2017 05:05 AM, Heinrich Schuchardt wrote:
>>> We need to test if we pass a valid image handle when loading
>>> and EFI application. This cannot be done in efi_selftest as
>>> it is not loaded as an image.
>>>
>>> So let's enhance helloworld a bit.
>>>
>>> Reviewed-by: Simon Glass <sjg@chromium.org>
>>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>>
>> This particular patch/commit bbf75dd9345d0b1a7ec7a50016547eb7c759b7af
>> ("efi_loader: output load options in helloworld") was bisected and
>> causes the Lamobo_R1_defconfig build using the toolchain at [1] to fail
>> with:
>>
>> /home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
>> error: required section '.got' not found in the linker script
>> /home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
>> final link failed: Invalid operation
>> scripts/Makefile.lib:409: recipe for target
>> 'lib/efi_loader/helloworld_efi.so' failed
>> make[2]: *** [lib/efi_loader/helloworld_efi.so] Error 1
>> rm lib/efi_loader/helloworld.o
>> scripts/Makefile.build:425: recipe for target 'lib/efi_loader' failed
>> make[1]: *** [lib/efi_loader] Error 2
>>
>> [1]: https://github.com/Broadcom/stbgcc-6.3/releases/tag/stbgcc-6.3-1.1
>>
> 
> Isn't this fixed by
> http://git.denx.de/?p=u-boot.git;a=commit;h=3bb74f9800cdc4cf10a87f2725242c2565256654
> 
> "efi_loader helloworld.efi: Fix building with -Os" ?

Nope, my tree is at v2018.01-rc1-115-g335f7b1290ce which contains that
commit already.
Alexander Graf Dec. 11, 2017, 8:15 a.m. UTC | #4
On 10.12.17 23:20, Florian Fainelli wrote:
> 
> 
> On 12/09/2017 10:40 PM, Heinrich Schuchardt wrote:
>> On 12/10/2017 12:09 AM, Florian Fainelli wrote:
>>>
>>>
>>> On 11/26/2017 05:05 AM, Heinrich Schuchardt wrote:
>>>> We need to test if we pass a valid image handle when loading
>>>> and EFI application. This cannot be done in efi_selftest as
>>>> it is not loaded as an image.
>>>>
>>>> So let's enhance helloworld a bit.
>>>>
>>>> Reviewed-by: Simon Glass <sjg@chromium.org>
>>>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>>>
>>> This particular patch/commit bbf75dd9345d0b1a7ec7a50016547eb7c759b7af
>>> ("efi_loader: output load options in helloworld") was bisected and
>>> causes the Lamobo_R1_defconfig build using the toolchain at [1] to fail
>>> with:
>>>
>>> /home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
>>> error: required section '.got' not found in the linker script
>>> /home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
>>> final link failed: Invalid operation
>>> scripts/Makefile.lib:409: recipe for target
>>> 'lib/efi_loader/helloworld_efi.so' failed
>>> make[2]: *** [lib/efi_loader/helloworld_efi.so] Error 1
>>> rm lib/efi_loader/helloworld.o
>>> scripts/Makefile.build:425: recipe for target 'lib/efi_loader' failed
>>> make[1]: *** [lib/efi_loader] Error 2
>>>
>>> [1]: https://github.com/Broadcom/stbgcc-6.3/releases/tag/stbgcc-6.3-1.1
>>>
>>
>> Isn't this fixed by
>> http://git.denx.de/?p=u-boot.git;a=commit;h=3bb74f9800cdc4cf10a87f2725242c2565256654
>>
>> "efi_loader helloworld.efi: Fix building with -Os" ?
> 
> Nope, my tree is at v2018.01-rc1-115-g335f7b1290ce which contains that
> commit already.

Yeah, but the issue is the same :(

$ nm lib/efi_loader/helloworld.o
00000000 T efi_main
         U memcpy

Gcc simply optimizes the loaded_image_guid assignment into a memcpy()
and I can't find any way to prohibit it from doing that.

I guess the easiest way out of that mess is to just not do a dynamic
struct assignment but instead put loaded_image_guid explicitly into the
.rodata section.

I'll send a patch.


Alex
diff mbox series

Patch

diff --git a/lib/efi_loader/helloworld.c b/lib/efi_loader/helloworld.c
index 77130a36dd..e59c24c788 100644
--- a/lib/efi_loader/helloworld.c
+++ b/lib/efi_loader/helloworld.c
@@ -5,19 +5,52 @@ 
  * Written by Simon Glass <sjg@chromium.org>
  *
  * SPDX-License-Identifier:     GPL-2.0+
+ *
+ * This program demonstrates calling a boottime service.
+ * It writes a greeting and the load options to the console.
  */
 
 #include <common.h>
 #include <efi_api.h>
 
+/*
+ * Entry point of the EFI application.
+ *
+ * @handle	handle of the loaded image
+ * @systable	system table
+ * @return	status code
+ */
 efi_status_t EFIAPI efi_main(efi_handle_t handle,
 			     struct efi_system_table *systable)
 {
 	struct efi_simple_text_output_protocol *con_out = systable->con_out;
 	struct efi_boot_services *boottime = systable->boottime;
+	struct efi_loaded_image *loaded_image;
+	const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
+	efi_status_t ret;
 
 	con_out->output_string(con_out, L"Hello, world!\n");
-	boottime->exit(handle, 0, 0, NULL);
 
-	return EFI_SUCCESS;
+	/* Get the loaded image protocol */
+	ret = boottime->handle_protocol(handle, &loaded_image_guid,
+					(void **)&loaded_image);
+	if (ret != EFI_SUCCESS) {
+		con_out->output_string(con_out,
+				       L"Cannot open loaded image protocol\n");
+		goto out;
+	}
+	/* Output the load options */
+	con_out->output_string(con_out, L"Load options: ");
+	if (loaded_image->load_options_size && loaded_image->load_options)
+		con_out->output_string(con_out,
+				       (u16 *)loaded_image->load_options);
+	else
+		con_out->output_string(con_out, L"<none>");
+	con_out->output_string(con_out, L"\n");
+
+out:
+	boottime->exit(handle, ret, 0, NULL);
+
+	/* We should never arrive here */
+	return ret;
 }