cmd: add efitool for efi environment
v4 cover cmd: add efitool for efi environment
This patch set is a collection of patches to enhance efi user interfaces /commands. It will help improve user experience on efi boot and make it more usable *without* edk2's shell utility.
Let's see how it works:
=> efitool boot add 1 SHELL mmc 0:1 /Shell.efi "" => efitool boot add 2 HELLO mmc 0:1 /hello.efi "" => efitool boot dump
Boot0001:
attributes: A-- (0x00000001) label: SHELL file_path: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)/HD(1,MBR,0x086246ba,0x800,0x40000)/\\Shell.efi data: Boot0002: attributes: A-- (0x00000001) label: HELLO file_path: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)/HD(1,MBR,0x086246ba,0x800,0x40000)/\\hello.efi data:
=> efitool boot order 1 2
=> efitool boot order
1: Boot0001: SHELL
2: Boot0002: HELLO
=> run -e Boot0002 (or bootefi bootmgr - 2) ; '-' means no dtb specified
WARNING: booting without device tree
Booting: HELLO
## Starting EFI application at 000000007db8b040 ... Hello, world!
## Application terminated, r = 0
=> env set -e PlatformLang en ; important!
(or you can do "efitool setvar PlatformLang en")
=> env print -e
Boot0001: {boot,run}(blob)
00000000: 01 00 00 00 68 00 53 00 ....h.S.
00000010: 48 00 45 00 4c 00 4c 00 H.E.L.L.
00000020: 00 00 01 04 14 00 b9 73 .......s
00000030: 1d e6 84 a3 cc 4a ae ab .....J..
00000040: 82 e8 28 f3 62 8b 03 1a ..(.b...
00000050: 05 00 00 03 1a 05 00 00 ........
00000060: 04 01 2a 00 01 00 00 00 ..*.....
00000070: 00 08 00 00 00 00 00 00 ........
00000080: 00 00 04 00 00 00 00 00 ........
00000090: ba 46 62 08 00 00 00 00 .Fb.....
000000a0: 00 00 00 00 00 00 00 00 ........
000000b0: 01 01 04 04 1c 00 5c 00 ......\.
000000c0: 5c 00 53 00 68 00 65 00 \.S.h.e.
000000d0: 6c 00 6c 00 2e 00 65 00 l.l...e.
000000e0: 66 00 69 00 00 00 7f ff f.i....
000000f0: 04 00 00 ...
Boot0002: {boot,run}(blob)
00000000: 01 00 00 00 68 00 48 00 ....h.H.
00000010: 45 00 4c 00 4c 00 4f 00 E.L.L.O.
00000020: 00 00 01 04 14 00 b9 73 .......s
00000030: 1d e6 84 a3 cc 4a ae ab .....J..
00000040: 82 e8 28 f3 62 8b 03 1a ..(.b...
00000050: 05 00 00 03 1a 05 00 00 ........
00000060: 04 01 2a 00 01 00 00 00 ..*.....
00000070: 00 08 00 00 00 00 00 00 ........
00000080: 00 00 04 00 00 00 00 00 ........
00000090: ba 46 62 08 00 00 00 00 .Fb.....
000000a0: 00 00 00 00 00 00 00 00 ........
000000b0: 01 01 04 04 1c 00 5c 00 ......\.
000000c0: 5c 00 68 00 65 00 6c 00 \.h.e.l.
000000d0: 6c 00 6f 00 2e 00 65 00 l.o...e.
000000e0: 66 00 69 00 00 00 7f ff f.i....
000000f0: 04 00 00 ...BootOrder: {boot,run}(blob)
00000000: 01 00 02 00 ....
OsIndicationsSupported: {ro,boot}(blob) 00000000: 00 00 00 00 00 00 00 00 ........
PlatformLang: {boot,run}(blob)
00000000: 65 6e en
=> run -e Boot0001 or bootefi bootmgr
(UEFI shell ...)
"setvar" command now supports efi shell-like syntax:
=> env set -e foo =S\"akashi\" =0x012345 =Habcdef => env print -e foo
foo: {boot,run}(blob)
00000000: 61 6b 61 73 68 69 45 23 akashiE# 00000010: 01 00 ab cd ef .....
Other useful sub commands are:
=> efitool devices ; print uefi devices
=> efitool drivers ; print uefi drivers
=> efitool dh ; print uefi handles
=> efitool images ; print loaded images
=> efitool memmap ; dump uefi memory map
Enjoy!
-Takahiro Akashi
Changes in v4 (Jan 15, 2019)
* rename the command name from efishell to efitool
* use efi_uintn_t for "size" if appropriate
* correct a help text for "boot add" sub-command
* "boot" sub-command always takes a hexadecimal number
* use systab.boottime directly instead of a local variable, bs
* fix a bug in "setvar" sub-command
* fix a bug in "devices" and "dh" sub-command
* fix a bug in "memmap" sub-command
* add "boot next" sub-command to set BootNext variable
* "drivers" sub-command prints more useful info, including a driver's name which originates from a corresponding u-boot efi driver
* "dh" sub-commands prints more useful info, including a list of protocols which are bound to a given handle
Changes in v3 (Dec 18, 2018)
* split v2 into two separate patch series
* add CONFIG_CMD_EFISHELL to enable/disable efishell command
* add missing free() at several places in efishell command
Changes in v2 (Nov 5, 2018)
* modify efi_dp_from_name() for use in efishell
* rename efi_marshal_load_option() to efi_serialize_load_option(), taking a "struct efi_load_option" as an argument
* improve a format in dumping uefi variables
* enhance a setvar syntax as efi's shell does
* change a syntax from "bootefi bootmgr -2" to "bootefi bootmgr - 2"
* add -e option to run command
* add -e option to env command
* add more sub-commands
AKASHI Takahiro (9):
cmd: add efitool command
cmd: efitool: add devices command
efi_driver: add name to driver binding protocol
cmd: efitool: add drivers command
cmd: efitool: add dh command
cmd: efitool: add images command
cmd: efitool: add memmap command
cmd: efitool: export uefi variable helper functions
cmd: env: add "-e" option for handling UEFI variables
cmd/Kconfig | 10 + cmd/Makefile | 1 + cmd/efitool.c | 1103 +++++++++++++++++++++++++++++++++++ cmd/nvedit.c | 61 +- include/command.h | 4 + include/efi_driver.h | 1 + lib/efi_driver/efi_uclass.c | 1 + 7 files changed, 1179 insertions(+), 2 deletions(-) create mode 100644 cmd/efitool.c
Signature · 1 line
2.19.1
PATCH v4 1/9 cmd: add efitool command
Currently, there is no easy way to add or modify UEFI variables. In particular, bootmgr supports BootOrder/BootXXXX variables, it is quite hard to define them as u-boot variables because they are represented in a complicated and encoded format.
The new command, efitool, helps address these issues and give us more friendly interfaces:
* efitool boot add: add BootXXXX variable
* efitool boot rm: remove BootXXXX variable
* efitool boot dump: display all BootXXXX variables
* efitool boot order: set/display a boot order (BootOrder)
* efitool setvar: set an UEFI variable (with limited functionality)
* efitool dumpvar: display all UEFI variables
As the name suggests, this command basically provides a subset fo UEFI shell commands with simplified functionality.
--- cmd/Kconfig | 10 + cmd/Makefile | 1 + cmd/efitool.c | 707 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 718 insertions(+) create mode 100644 cmd/efitool.c
cmd/Kconfig +10 -0
@@ -1397,6 +1397,16 @@ config CMD_DISPLAY displayed on a simple board-specific display. Implement display_putc() to use it. +config CMD_EFITOOL + bool "efitool - display/customize UEFI environment" + depends on EFI_LOADER + default n + help + Enable the 'efitool' command which provides a subset of UEFI + shell utility with simplified functionality. It will be useful + particularly for managing boot parameters as well as examining + various EFI status for debugging. + config CMD_LED bool "led" default y if LED
cmd/Makefile +1 -0
@@ -51,6 +51,7 @@ obj-$(CONFIG_CMD_ECHO) += echo.o obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o obj-$(CONFIG_CMD_EEPROM) += eeprom.o obj-$(CONFIG_EFI_STUB) += efi.o +obj-$(CONFIG_CMD_EFITOOL) += efitool.o obj-$(CONFIG_CMD_ELF) += elf.o obj-$(CONFIG_HUSH_PARSER) += exit.o obj-$(CONFIG_CMD_EXT4) += ext4.o
cmd/efitool.c new file +707 -0
707 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH v4 1/9 cmd: add efitool command
Quoted 14 lines · AKASHI Takahiro
Currently, there is no easy way to add or modify UEFI variables. In particular, bootmgr supports BootOrder/BootXXXX variables, it is quite hard to define them as u-boot variables because they are represented in a complicated and encoded format.
The new command, efitool, helps address these issues and give us more friendly interfaces:
* efitool boot add: add BootXXXX variable
* efitool boot rm: remove BootXXXX variable
* efitool boot dump: display all BootXXXX variables
* efitool boot order: set/display a boot order (BootOrder)
* efitool setvar: set an UEFI variable (with limited functionality)
* efitool dumpvar: display all UEFI variables
Quoted 4 lines
As the name suggests, this command basically provides a subset fo UEFI shell commands with simplified functionality.
Signed-off-by AKASHI Takahiro <[email protected]>
Hello Takahiro,
thanks a lot for your patch series. The additional command is really useful.
Unfortunately the implementation of sub-commands does not follow the coding style of other sub-commands. Could you please have a look at the current doc/README.commands
http://git.denx.de/?p=u-boot.git;a=blob;f=doc/README.commands
I think it should be easy to convert your code to follow the implementation style suggested there and used all over U-Boot.
Sorry that I did not put this into an earlier comment. I only learnt about this recently by a review from Simon and then updated the README.
Please, add the new file in MAINTAINERS to the EFI PAYLOAD section.
Best regards
Heinrich
PATCH v4 1/9 cmd: add efitool command
Quoted 22 lines · Heinrich Schuchardt
Quoted 14 lines · AKASHI Takahiro
Currently, there is no easy way to add or modify UEFI variables. In particular, bootmgr supports BootOrder/BootXXXX variables, it is quite hard to define them as u-boot variables because they are represented in a complicated and encoded format.
The new command, efitool, helps address these issues and give us more friendly interfaces:
* efitool boot add: add BootXXXX variable
* efitool boot rm: remove BootXXXX variable
* efitool boot dump: display all BootXXXX variables
* efitool boot order: set/display a boot order (BootOrder)
* efitool setvar: set an UEFI variable (with limited functionality)
* efitool dumpvar: display all UEFI variablesQuoted 4 lines
As the name suggests, this command basically provides a subset fo UEFI shell commands with simplified functionality.
Signed-off-by AKASHI Takahiro <[email protected]>Hello Takahiro,
Quoted 7 lines
thanks a lot for your patch series. The additional command is really useful.
Unfortunately the implementation of sub-commands does not follow the coding style of other sub-commands. Could you please have a look at the current doc/README.commands
http://git.denx.de/?p=u-boot.git;a=blob;f=doc/README.commands
OK.
Quoted 7 lines
I think it should be easy to convert your code to follow the implementation style suggested there and used all over U-Boot.
Sorry that I did not put this into an earlier comment. I only learnt about this recently by a review from Simon and then updated the README.
Please, add the new file in
MAINTAINERSto the EFI PAYLOAD section.
Sure
Thanks,
-Takahiro Akashi
Quoted 3 lines
Best regards
Heinrich
PATCH v4 2/9 cmd: efitool: add devices command
In reply to AKASHI Takahiro"devices" command prints all the uefi variables on the system.
=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
D
e
v Device Path
================ ====================
7ef3bfa0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
7ef3cca0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
7ef3d070 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
7ef3d1b0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
7ef3d3e0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)--- cmd/efitool.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-)
cmd/efitool.c +97 -1
@@ -18,6 +18,8 @@#include <linux/ctype.h> #include <asm/global_data.h> +#define BS systab.boottime +static void dump_var_data (char *data,unsigned long len) {char *start, *end, *p;
@@ -266,6 +268,96 @@ out:return ret; } +static int efi_get_handles_by_proto (efi_guid_t *guid,efi_handle_t **handlesp, +int *num) +{ +efi_handle_t *handles =NULL ; +efi_uintn_t size =0 ; +efi_status_t ret; + +if (guid) { + ret =BS ->locate_handle (BY_PROTOCOL , guid,NULL , &size, + handles); +if (ret ==EFI_BUFFER_TOO_SMALL ) { + handles =calloc (1 , size); +if (!handles) +return -1 ; + + ret =BS ->locate_handle (BY_PROTOCOL , guid,NULL , &size, + handles); + } +if (ret !=EFI_SUCCESS ) { +free (handles); +return -1 ; + } + }else { + ret =BS ->locate_handle (ALL_HANDLES ,NULL ,NULL , &size,NULL ); +if (ret ==EFI_BUFFER_TOO_SMALL ) { + handles =calloc (1 , size); +if (!handles) +return -1 ; + + ret =BS ->locate_handle (ALL_HANDLES ,NULL ,NULL , &size, + handles); + } +if (ret !=EFI_SUCCESS ) { +free (handles); +return -1 ; + } + } + + *handlesp = handles; + *num = size /sizeof (efi_handle_t); + +return 0 ; +} + +static int efi_get_device_handle_info (efi_handle_t handle,u16 **name) +{ +struct efi_device_path *dp; +efi_status_t ret; + + ret =BS ->open_protocol (handle, &efi_guid_device_path, + (void **)&dp,NULL /* FIXME */ ,NULL , +EFI_OPEN_PROTOCOL_GET_PROTOCOL ); +if (ret ==EFI_SUCCESS ) { + *name =efi_dp_str (dp); +return 0 ; + }else { +return -1 ; + } +} + +static int do_efi_show_devices (int argc,char *const argv[]) +{ +efi_handle_t *handles; +u16 *devname; +int num, i; + + handles =NULL ; + num =0 ; +if (efi_get_handles_by_proto (NULL , &handles, &num)) +return CMD_RET_FAILURE ; + +if (!num) +return CMD_RET_SUCCESS ; + +printf ("D\n" ); +printf ("e\n" ); +printf ("v Device Path\n" ); +printf ("================ ====================\n" ); +for (i =0 ; i < num; i++) { +if (!efi_get_device_handle_info (handles[i], &devname)) { +printf ("%16p %ls\n" , handles[i], devname); +efi_free_pool (devname); + } + } + +free (handles); + +return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {int id;
@@ -673,6 +765,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_dump_var (argc, argv); else if (!strcmp(command, "setvar"))return do_efi_set_var (argc, argv); + else if (!strcmp(command, "devices")) +return do_efi_show_devices (argc, argv); else return CMD_RET_USAGE; }
@@ -697,7 +791,9 @@ static char efitool_help_text[] =" - show UEFI variable's value\n" "efitool setvar <name> [<value>]\n" " - set/delete uefi variable's value\n" -" <value> may be \"=\"...\"\", \"=0x...\", \"=H...\", (set) or \"=\" (delete)\n" ; +" <value> may be \"=\"...\"\", \"=0x...\", \"=H...\", (set) or \"=\" (delete)\n" +"efitool devices\n" +" - show uefi devices\n" ;#endif U_BOOT_CMD(
Signature · 1 line
2.19.1
PATCH v4 2/9 cmd: efitool: add devices command
Quoted 92 lines · AKASHI Takahiro
"devices" command prints all the uefi variables on the system.
=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
D
e
v Device Path
================ ====================7ef3bfa0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b) 7ef3cca0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0) 7ef3d070 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0) 7ef3d1b0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000) 7ef3d3e0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)Signed-off-by AKASHI Takahiro <[email protected]>--- cmd/efitool.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-)cmd/efitool.c +56
-0@@ -18,6 +18,8 @@#include <linux/ctype.h> #include <asm/global_data.h> +#define BS systab.boottime +static void dump_var_data (char *data,unsigned long len) {char *start, *end, *p;@@ -266,6 +268,96 @@ out:return ret; } +static int efi_get_handles_by_proto (efi_guid_t *guid,efi_handle_t **handlesp, +int *num) +{ +efi_handle_t *handles =NULL ; +efi_uintn_t size =0 ; +efi_status_t ret; + +if (guid) { + ret =BS ->locate_handle (BY_PROTOCOL , guid,NULL , &size, + handles); +if (ret ==EFI_BUFFER_TOO_SMALL ) { + handles =calloc (1 , size); +if (!handles) +return -1 ; + + ret =BS ->locate_handle (BY_PROTOCOL , guid,NULL , &size, + handles); + } +if (ret !=EFI_SUCCESS ) { +free (handles); +return -1 ; + } + }else { + ret =BS ->locate_handle (ALL_HANDLES ,NULL ,NULL , &size,NULL ); +if (ret ==EFI_BUFFER_TOO_SMALL ) { + handles =calloc (1 , size); +if (!handles) +return -1 ; + + ret =BS ->locate_handle (ALL_HANDLES ,NULL ,NULL , &size, + handles); + } +if (ret !=EFI_SUCCESS ) { +free (handles); +return -1 ; + } + } + + *handlesp = handles; + *num = size /sizeof (efi_handle_t); + +return 0 ; +} + +static int efi_get_device_handle_info (efi_handle_t handle,u16 **name) +{ +struct efi_device_path *dp; +efi_status_t ret; + + ret =BS ->open_protocol (handle, &efi_guid_device_path, + (void **)&dp,NULL /* FIXME */ ,NULL , +EFI_OPEN_PROTOCOL_GET_PROTOCOL ); +if (ret ==EFI_SUCCESS ) { + *name =efi_dp_str (dp);
cmd/efitool.c out: · line 334
Quoted 10 lines
cmd/efitool.c +10
-0+return 0 ; + }else { +return -1 ; + } +} + +static int do_efi_show_devices (int argc,char *const argv[]) +{ +efi_handle_t *handles; +u16 *devname;
This is the device path. So why not call it dev_path?
Quoted 18 lines
cmd/efitool.c +18
-0+int num, i; + + handles =NULL ; + num =0 ; +if (efi_get_handles_by_proto (NULL , &handles, &num)) +return CMD_RET_FAILURE ; + +if (!num) +return CMD_RET_SUCCESS ; + +printf ("D\n" ); +printf ("e\n" ); +printf ("v Device Path\n" ); +printf ("================ ====================\n" ); +for (i =0 ; i < num; i++) { +if (!efi_get_device_handle_info (handles[i], &devname)) { +printf ("%16p %ls\n" , handles[i], devname); +efi_free_pool (devname);
cmd/efitool.c out: · line 362
Quoted 10 lines
cmd/efitool.c +8
-0+ } + } + +free (handles); + +return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {
Please, use the standard way of adding sub-commands, cf. doc/README.commands.
Thanks a lot for your contribution.
Regards
Heinrich
Quoted 22 lines
cmd/efitool.c +5
-1int id;@@ -673,6 +765,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_dump_var (argc, argv); else if (!strcmp(command, "setvar"))return do_efi_set_var (argc, argv); + else if (!strcmp(command, "devices")) +return do_efi_show_devices (argc, argv); else return CMD_RET_USAGE; }@@ -697,7 +791,9 @@ static char efitool_help_text[] =" - show UEFI variable's value\n" "efitool setvar <name> [<value>]\n" " - set/delete uefi variable's value\n" -" <value> may be \"=\"...\"\", \"=0x...\", \"=H...\", (set) or \"=\" (delete)\n" ; +" <value> may be \"=\"...\"\", \"=0x...\", \"=H...\", (set) or \"=\" (delete)\n" +"efitool devices\n" +" - show uefi devices\n" ;#endif U_BOOT_CMD(
PATCH v4 2/9 cmd: efitool: add devices command
Quoted 97 lines · Heinrich Schuchardt
Quoted 96 lines · AKASHI Takahiro
"devices" command prints all the uefi variables on the system.
=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
D
e
v Device Path
================ ====================7ef3bfa0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b) 7ef3cca0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0) 7ef3d070 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0) 7ef3d1b0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000) 7ef3d3e0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)Signed-off-by AKASHI Takahiro <[email protected]>--- cmd/efitool.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-)cmd/efitool.c +60
-0@@ -18,6 +18,8 @@#include <linux/ctype.h> #include <asm/global_data.h> +#define BS systab.boottime +static void dump_var_data (char *data,unsigned long len) {char *start, *end, *p;@@ -266,6 +268,96 @@ out:return ret; } +static int efi_get_handles_by_proto (efi_guid_t *guid,efi_handle_t **handlesp, +int *num) +{ +efi_handle_t *handles =NULL ; +efi_uintn_t size =0 ; +efi_status_t ret; + +if (guid) { + ret =BS ->locate_handle (BY_PROTOCOL , guid,NULL , &size, + handles); +if (ret ==EFI_BUFFER_TOO_SMALL ) { + handles =calloc (1 , size); +if (!handles) +return -1 ; + + ret =BS ->locate_handle (BY_PROTOCOL , guid,NULL , &size, + handles); + } +if (ret !=EFI_SUCCESS ) { +free (handles); +return -1 ; + } + }else { + ret =BS ->locate_handle (ALL_HANDLES ,NULL ,NULL , &size,NULL ); +if (ret ==EFI_BUFFER_TOO_SMALL ) { + handles =calloc (1 , size); +if (!handles) +return -1 ; + + ret =BS ->locate_handle (ALL_HANDLES ,NULL ,NULL , &size, + handles); + } +if (ret !=EFI_SUCCESS ) { +free (handles); +return -1 ; + } + } + + *handlesp = handles; + *num = size /sizeof (efi_handle_t); + +return 0 ; +} + +static int efi_get_device_handle_info (efi_handle_t handle,u16 **name) +{ +struct efi_device_path *dp; +efi_status_t ret; + + ret =BS ->open_protocol (handle, &efi_guid_device_path, + (void **)&dp,NULL /* FIXME */ ,NULL , +EFI_OPEN_PROTOCOL_GET_PROTOCOL ); +if (ret ==EFI_SUCCESS ) { + *name =efi_dp_str (dp); +return 0 ; + }else { +return -1 ; + }
Quoted 8 lines
cmd/efitool.c out: · line 334
Quoted 6 lines
cmd/efitool.c +6
-0+} + +static int do_efi_show_devices (int argc,char *const argv[]) +{ +efi_handle_t *handles; +u16 *devname;This is the device path. So why not call it
dev_path?
dev_path is normally used for a device path object itself. I prefer dp_text.
Quoted 23 lines
Quoted 23 lines
cmd/efitool.c +23
-0+int num, i; + + handles =NULL ; + num =0 ; +if (efi_get_handles_by_proto (NULL , &handles, &num)) +return CMD_RET_FAILURE ; + +if (!num) +return CMD_RET_SUCCESS ; + +printf ("D\n" ); +printf ("e\n" ); +printf ("v Device Path\n" ); +printf ("================ ====================\n" ); +for (i =0 ; i < num; i++) { +if (!efi_get_device_handle_info (handles[i], &devname)) { +printf ("%16p %ls\n" , handles[i], devname); +efi_free_pool (devname); + } + } + +free (handles); +
Quoted 8 lines
cmd/efitool.c out: · line 362
Quoted 5 lines
cmd/efitool.c +3
-0+return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {Please, use the standard way of adding sub-commands, cf. doc/README.commands.
OK
Thanks,
-Takahiro Akashi
Quoted 29 lines
Thanks a lot for your contribution.
Regards
Heinrich
Quoted 22 lines
cmd/efitool.c +5
-1int id;@@ -673,6 +765,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_dump_var (argc, argv); else if (!strcmp(command, "setvar"))return do_efi_set_var (argc, argv); + else if (!strcmp(command, "devices")) +return do_efi_show_devices (argc, argv); else return CMD_RET_USAGE; }@@ -697,7 +791,9 @@ static char efitool_help_text[] =" - show UEFI variable's value\n" "efitool setvar <name> [<value>]\n" " - set/delete uefi variable's value\n" -" <value> may be \"=\"...\"\", \"=0x...\", \"=H...\", (set) or \"=\" (delete)\n" ; +" <value> may be \"=\"...\"\", \"=0x...\", \"=H...\", (set) or \"=\" (delete)\n" +"efitool devices\n" +" - show uefi devices\n" ;#endif U_BOOT_CMD(
PATCH v4 3/9 efi_driver: add name to driver binding protocol
In reply to AKASHI TakahiroThis new field will be shown as a driver's name in "efitool drivers" command.
--- include/efi_driver.h | 1 + lib/efi_driver/efi_uclass.c | 1 + 2 files changed, 2 insertions(+)
include/efi_driver.h +1 -0
@@ -34,6 +34,7 @@ struct efi_driver_ops {* This structure adds internal fields to the driver binding protocol. */ struct efi_driver_binding_extended_protocol { +const char *name;struct efi_driver_binding_protocol bp;const struct efi_driver_ops *ops; };
lib/efi_driver/efi_uclass.c +1 -0
@@ -271,6 +271,7 @@ static efi_status_t efi_add_driver(struct driver *drv) bp->bp.stop = efi_uc_stop; bp->bp.version =0xffffffff ; bp->ops = drv->ops; + bp->name = drv->name; ret =efi_create_handle (&bp->bp.driver_binding_handle);if (ret !=EFI_SUCCESS ) {
Signature · 1 line
2.19.1
PATCH v4 3/9 efi_driver: add name to driver binding protocol
Quoted 2 lines · AKASHI Takahiro
This new field will be shown as a driver's name in "efitool drivers" command.
We can have drivers supplied by U-Boot and drivers supplied by an EFI binary that we recently installed via the bootefi command.
A driver installed via the bootefi command will not have allocated memory for the extra fields.
So you cannot use the name field in your "efitool drivers" command.
Best regards
Heinrich
Quoted 32 lines
Signed-off-by AKASHI Takahiro <[email protected]>--- include/efi_driver.h | 1 + lib/efi_driver/efi_uclass.c | 1 + 2 files changed, 2 insertions(+)include/efi_driver.h +1
-0@@ -34,6 +34,7 @@ struct efi_driver_ops {* This structure adds internal fields to the driver binding protocol. */ struct efi_driver_binding_extended_protocol { +const char *name;struct efi_driver_binding_protocol bp;const struct efi_driver_ops *ops; };lib/efi_driver/efi_uclass.c +1
-0@@ -271,6 +271,7 @@ static efi_status_t efi_add_driver(struct driver *drv) bp->bp.stop = efi_uc_stop; bp->bp.version =0xffffffff ; bp->ops = drv->ops; + bp->name = drv->name; ret =efi_create_handle (&bp->bp.driver_binding_handle);if (ret !=EFI_SUCCESS ) {
PATCH v4 3/9 efi_driver: add name to driver binding protocol
You raised a couple of questions to me.
Quoted 5 lines · Heinrich Schuchardt
Quoted 2 lines · AKASHI Takahiro
This new field will be shown as a driver's name in "efitool drivers" command.
We can have drivers supplied by U-Boot
I assume that what you mention here is a UCLASS_EFI driver.
What's the problem is;efi_add_driver() adds EFI_DRIVER_BINDING_PROTOCOL with *efi_driver_binding_extended_protocol* interface, which is NOT compatible with EFI_DRIVER_BINDING_PROTOCOL.
On the other hand, for example, in your efi_selftest_controller test a test driver is set up by installing EFI_DRIVER_BINDING_PROTOCOL with EFI_DRIVER_BINDING_PROTOCOL interface.
So we have no way to distinguish the two cases(handles) and cannot deal with them properly.
Quoted 5 lines
and drivers supplied by an EFI
binary that we recently installed via the bootefi command.A driver installed via the bootefi command will not have allocated memory for the extra fields.
There is no good example of driver of such kind.
I don't know how we can retrieve a meaningful "driver name."
Quoted 1 line
So you cannot use the name field in your "efitool drivers" command.
Any suggestion?
Thanks,
-Takahiro Akashi
Quoted 38 lines
Best regards
Heinrich
Quoted 32 lines
Signed-off-by AKASHI Takahiro <[email protected]>--- include/efi_driver.h | 1 + lib/efi_driver/efi_uclass.c | 1 + 2 files changed, 2 insertions(+)include/efi_driver.h +1
-0@@ -34,6 +34,7 @@ struct efi_driver_ops {* This structure adds internal fields to the driver binding protocol. */ struct efi_driver_binding_extended_protocol { +const char *name;struct efi_driver_binding_protocol bp;const struct efi_driver_ops *ops; };lib/efi_driver/efi_uclass.c +1
-0@@ -271,6 +271,7 @@ static efi_status_t efi_add_driver(struct driver *drv) bp->bp.stop = efi_uc_stop; bp->bp.version =0xffffffff ; bp->ops = drv->ops; + bp->name = drv->name; ret =efi_create_handle (&bp->bp.driver_binding_handle);if (ret !=EFI_SUCCESS ) {
PATCH v4 3/9 efi_driver: add name to driver binding protocol
Quoted 19 lines · AKASHI Takahiro
You raised a couple of questions to me.
Quoted 5 lines · Heinrich Schuchardt
Quoted 2 lines · AKASHI Takahiro
This new field will be shown as a driver's name in "efitool drivers" command.
We can have drivers supplied by U-Boot
I assume that what you mention here is a
UCLASS_EFIdriver.What's the problem is;
efi_add_driver()addsEFI_DRIVER_BINDING_PROTOCOLwith *efi_driver_binding_extended_protocol* interface, which is NOT compatible withEFI_DRIVER_BINDING_PROTOCOL.
On the other hand, for example, in yourefi_selftest_controllertest a test driver is set up by installingEFI_DRIVER_BINDING_PROTOCOLwithEFI_DRIVER_BINDING_PROTOCOLinterface.
Quoted 2 lines
So we have no way to distinguish the two cases(handles) and cannot deal with them properly.
Correct. It is allowable to add private fields to a protocol. EDK2 does the same. But we cannot make any assumptions about the private fields here.
Quoted 9 lines
Quoted 6 lines
and drivers supplied by an EFI
binary that we recently installed via the bootefi command.A driver installed via the bootefi command will not have allocated memory for the extra fields.
There is no good example of driver of such kind.
I don't know how we can retrieve a meaningful "driver name."
The UEFI spec does not foresee any name field.
The interesting information is: on which handle did the driver install which protocol.
This information could be gathered by looping over all protocols on all handles and looking for an OpenProtocolInformation where the driver is the controller.
For me it would be fine if we leave that to a later patch.
Best regards
Heinrich
Quoted 47 lines
Quoted 2 lines
So you cannot use the name field in your "efitool drivers" command.
Any suggestion?
Thanks,
-Takahiro AkashiQuoted 38 lines
Best regards
Heinrich
Quoted 32 lines
Signed-off-by AKASHI Takahiro <[email protected]>--- include/efi_driver.h | 1 + lib/efi_driver/efi_uclass.c | 1 + 2 files changed, 2 insertions(+)include/efi_driver.h +1
-0@@ -34,6 +34,7 @@ struct efi_driver_ops {* This structure adds internal fields to the driver binding protocol. */ struct efi_driver_binding_extended_protocol { +const char *name;struct efi_driver_binding_protocol bp;const struct efi_driver_ops *ops; };lib/efi_driver/efi_uclass.c +1
-0@@ -271,6 +271,7 @@ static efi_status_t efi_add_driver(struct driver *drv) bp->bp.stop = efi_uc_stop; bp->bp.version =0xffffffff ; bp->ops = drv->ops; + bp->name = drv->name; ret =efi_create_handle (&bp->bp.driver_binding_handle);if (ret !=EFI_SUCCESS ) {
PATCH v4 3/9 efi_driver: add name to driver binding protocol
Quoted 20 lines · Heinrich Schuchardt
Quoted 19 lines · AKASHI Takahiro
You raised a couple of questions to me.
Quoted 5 lines · Heinrich Schuchardt
Quoted 2 lines · AKASHI Takahiro
This new field will be shown as a driver's name in "efitool drivers" command.
We can have drivers supplied by U-Boot
I assume that what you mention here is a
UCLASS_EFIdriver.What's the problem is;
efi_add_driver()addsEFI_DRIVER_BINDING_PROTOCOLwith *efi_driver_binding_extended_protocol* interface, which is NOT compatible withEFI_DRIVER_BINDING_PROTOCOL.
On the other hand, for example, in yourefi_selftest_controllertest a test driver is set up by installingEFI_DRIVER_BINDING_PROTOCOLwithEFI_DRIVER_BINDING_PROTOCOLinterface.
Quoted 5 lines
Quoted 2 lines
So we have no way to distinguish the two cases(handles) and cannot deal with them properly.
Correct. It is allowable to add private fields to a protocol. EDK2 does the same. But we cannot make any assumptions about the private fields here.
I misunderstood something here, but anyhow,
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
and drivers supplied by an EFI
binary that we recently installed via the bootefi command.A driver installed via the bootefi command will not have allocated memory for the extra fields.
There is no good example of driver of such kind.
I don't know how we can retrieve a meaningful "driver name."The UEFI spec does not foresee any name field.
Edk2's shell does get a driver's name by using COMPONENT_NAME2_PROTOCOL, and we'd better do the same way.
So "<NULL>" will be printed with my patch for now.
-Takahiro Akashi
Quoted 61 lines
The interesting information is: on which handle did the driver install which protocol.
This information could be gathered by looping over all protocols on all handles and looking for an OpenProtocolInformation where the driver is the controller.
For me it would be fine if we leave that to a later patch.
Best regards
Heinrich
Quoted 47 lines
Quoted 2 lines
So you cannot use the name field in your "efitool drivers" command.
Any suggestion?
Thanks,
-Takahiro AkashiQuoted 38 lines
Best regards
Heinrich
Quoted 32 lines
Signed-off-by AKASHI Takahiro <[email protected]>--- include/efi_driver.h | 1 + lib/efi_driver/efi_uclass.c | 1 + 2 files changed, 2 insertions(+)include/efi_driver.h +1
-0@@ -34,6 +34,7 @@ struct efi_driver_ops {* This structure adds internal fields to the driver binding protocol. */ struct efi_driver_binding_extended_protocol { +const char *name;struct efi_driver_binding_protocol bp;const struct efi_driver_ops *ops; };lib/efi_driver/efi_uclass.c +1
-0@@ -271,6 +271,7 @@ static efi_status_t efi_add_driver(struct driver *drv) bp->bp.stop = efi_uc_stop; bp->bp.version =0xffffffff ; bp->ops = drv->ops; + bp->name = drv->name; ret =efi_create_handle (&bp->bp.driver_binding_handle);if (ret !=EFI_SUCCESS ) {
PATCH v4 4/9 cmd: efitool: add drivers command
In reply to AKASHI Takahiro"drivers" command prints all the uefi drivers on the system.
=> efi drivers
D
r
v Driver Name Image Path
================ ==================== ==========
7ef31d30 EFI block driver <built-in>
--- cmd/efitool.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-)
cmd/efitool.c +83 -1
@@ -8,6 +8,7 @@#include <charset.h> #include <common.h> #include <command.h> +#include <efi_driver.h> #include <efi_loader.h> #include <environment.h> #include <errno.h>
@@ -16,6 +17,7 @@#include <malloc.h> #include <search.h> #include <linux/ctype.h> +#include <linux/kernel.h> #include <asm/global_data.h> #define BS systab.boottime
@@ -358,6 +360,82 @@ static int do_efi_show_devices(int argc, char * const argv[])return CMD_RET_SUCCESS ; } +static int efi_get_driver_handle_info (efi_handle_t handle,u16 **name, +u16 **devname,u16 **filename) +{ +struct efi_handler *handler; +struct efi_driver_binding_extended_protocol *bp; +efi_status_t ret; + + ret =efi_search_protocol (handle, &efi_guid_driver_binding_protocol, + &handler); +if (ret !=EFI_SUCCESS ) +return -1 ; + bp = handler->protocol_interface; + + *name =malloc ((strlen (bp->name) +1 ) *sizeof (u16)); +if (*name) +ascii2unicode (*name, bp->name); + +/* +* TODO: +* handle image->device_handle, +* use append_device_path() +*/ + *devname =NULL ; + *filename =NULL ; + +return 0 ; +} + +static int do_efi_show_drivers (int argc,char *const argv[]) +{ +efi_handle_t *handles =NULL , *handle; +efi_uintn_t size =0 ; +u16 *drvname, *devname, *filename; +efi_status_t ret; +int i; + + ret =BS ->locate_handle (BY_PROTOCOL , &efi_guid_driver_binding_protocol, +NULL , &size,NULL ); +if (ret ==EFI_BUFFER_TOO_SMALL ) { + handles =calloc (1 , size); +if (!handles) +return CMD_RET_FAILURE ; + + ret =BS ->locate_handle (BY_PROTOCOL , + &efi_guid_driver_binding_protocol, +NULL , &size, handles); + } +if (ret !=EFI_SUCCESS ) { +free (handles); +return CMD_RET_FAILURE ; + } + +printf ("D\n" ); +printf ("r\n" ); +printf ("v Driver Name Image Path\n" ); +printf ("================ ==================== ==========\n" ); + handle = handles; +for (i =0 ; i < size /sizeof (*handle); i++) { +if (!efi_get_driver_handle_info (*handle, &drvname, &devname, + &filename)) { +if (filename) +printf ("%16p %-20ls %ls/%ls\n" , + *handle, drvname, devname, filename); +else +printf ("%16p %-20ls <built-in>\n" , + *handle, drvname); +free (drvname); +free (devname); +free (filename); + } + handle++; + } + +return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {int id;
@@ -767,6 +845,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_set_var (argc, argv); else if (!strcmp(command, "devices"))return do_efi_show_devices (argc, argv); + else if (!strcmp(command, "drivers")) +return do_efi_show_drivers (argc, argv); else return CMD_RET_USAGE; }
@@ -793,7 +873,9 @@ static char efitool_help_text[] =" - set/delete uefi variable's value\n" " <value> may be \"=\"...\"\", \"=0x...\", \"=H...\", (set) or \"=\" (delete)\n" "efitool devices\n" -" - show uefi devices\n" ; +" - show uefi devices\n" +"efitool drivers\n" +" - show uefi drivers\n" ;#endif U_BOOT_CMD(
Signature · 1 line
2.19.1
PATCH v4 4/9 cmd: efitool: add drivers command
Quoted 35 lines · AKASHI Takahiro
"drivers" command prints all the uefi drivers on the system.
=> efi drivers
D
r
v Driver Name Image Path
================ ==================== ==========
7ef31d30EFI block driver <built-in>Signed-off-by AKASHI Takahiro <[email protected]>--- cmd/efitool.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-)cmd/efitool.c +2
-0@@ -8,6 +8,7 @@#include <charset.h> #include <common.h> #include <command.h> +#include <efi_driver.h> #include <efi_loader.h> #include <environment.h> #include <errno.h> @@ -16,6 +17,7 @@#include <malloc.h> #include <search.h> #include <linux/ctype.h> +#include <linux/kernel.h> #include <asm/global_data.h> #define BS systab.boottime
cmd/efitool.c static int do_efi_show_devices(int argc, char * const argv[]) · line 367
Quoted 8 lines
cmd/efitool.c +5
-0@@ -358,6 +360,82 @@ static int do_efi_show_devices(int argc, char * const argv[])return CMD_RET_SUCCESS ; } +static int efi_get_driver_handle_info (efi_handle_t handle,u16 **name, +u16 **devname,u16 **filename) +{ +struct efi_handler *handler; +struct efi_driver_binding_extended_protocol *bp;
We can have drivers supplied by U-Boot and drivers supplied by an EFI binary that we recently installed via the bootefi command.
A driver installed via the bootefi command will not have allocated memory for the extra fields. So the rest of the code accessing the name field will produce an illegal memory access.
Best regards
Heinrich
Quoted 95 lines
cmd/efitool.c +76
-1+efi_status_t ret; + + ret =efi_search_protocol (handle, &efi_guid_driver_binding_protocol, + &handler); +if (ret !=EFI_SUCCESS ) +return -1 ; + bp = handler->protocol_interface; + + *name =malloc ((strlen (bp->name) +1 ) *sizeof (u16)); +if (*name) +ascii2unicode (*name, bp->name); + +/* +* TODO: +* handle image->device_handle, +* use append_device_path() +*/ + *devname =NULL ; + *filename =NULL ; + +return 0 ; +} + +static int do_efi_show_drivers (int argc,char *const argv[]) +{ +efi_handle_t *handles =NULL , *handle; +efi_uintn_t size =0 ; +u16 *drvname, *devname, *filename; +efi_status_t ret; +int i; + + ret =BS ->locate_handle (BY_PROTOCOL , &efi_guid_driver_binding_protocol, +NULL , &size,NULL ); +if (ret ==EFI_BUFFER_TOO_SMALL ) { + handles =calloc (1 , size); +if (!handles) +return CMD_RET_FAILURE ; + + ret =BS ->locate_handle (BY_PROTOCOL , + &efi_guid_driver_binding_protocol, +NULL , &size, handles); + } +if (ret !=EFI_SUCCESS ) { +free (handles); +return CMD_RET_FAILURE ; + } + +printf ("D\n" ); +printf ("r\n" ); +printf ("v Driver Name Image Path\n" ); +printf ("================ ==================== ==========\n" ); + handle = handles; +for (i =0 ; i < size /sizeof (*handle); i++) { +if (!efi_get_driver_handle_info (*handle, &drvname, &devname, + &filename)) { +if (filename) +printf ("%16p %-20ls %ls/%ls\n" , + *handle, drvname, devname, filename); +else +printf ("%16p %-20ls <built-in>\n" , + *handle, drvname); +free (drvname); +free (devname); +free (filename); + } + handle++; + } + +return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {int id;@@ -767,6 +845,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_set_var (argc, argv); else if (!strcmp(command, "devices"))return do_efi_show_devices (argc, argv); + else if (!strcmp(command, "drivers")) +return do_efi_show_drivers (argc, argv); else return CMD_RET_USAGE; }@@ -793,7 +873,9 @@ static char efitool_help_text[] =" - set/delete uefi variable's value\n" " <value> may be \"=\"...\"\", \"=0x...\", \"=H...\", (set) or \"=\" (delete)\n" "efitool devices\n" -" - show uefi devices\n" ; +" - show uefi devices\n" +"efitool drivers\n" +" - show uefi drivers\n" ;#endif U_BOOT_CMD(
PATCH v4 5/9 cmd: efitool: add dh command
In reply to AKASHI Takahiro"dh" command prints all the uefi handles used in the system.
=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex 7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System 7ef3d3e0: Block IO, Device Path, Simple File System
--- cmd/efitool.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-)
cmd/efitool.c +102 -1
@@ -436,6 +436,103 @@ static int do_efi_show_drivers(int argc, char * const argv[])return CMD_RET_SUCCESS ; } +static struct { +u16 *name; +efi_guid_t guid; +} guid_list[] = { + { +L"Device Path" , +DEVICE_PATH_GUID , + }, + { +L"Device Path To Text" , +EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID , + }, + { +L"Device Path Utilities" , +EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID , + }, + { +L"Unicode Collation 2" , +EFI_UNICODE_COLLATION_PROTOCOL2_GUID , + }, + { +L"Driver Binding" , +EFI_DRIVER_BINDING_PROTOCOL_GUID , + }, + { +L"Simple Text Input" , +EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID , + }, + { +L"Simple Text Input Ex" , +EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID , + }, + { +L"Simple Text Output" , +EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID , + }, + { +L"Block IO" , +BLOCK_IO_GUID , + }, + { +L"Simple File System" , +EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID , + }, + { +NULL , + {{0 ,},}, + }, +}; + +static int do_efi_show_handles (int argc,char *const argv[]) +{ +efi_handle_t *handles; +efi_guid_t **guid; +efi_uintn_t count; +int num, i, j, k; +efi_status_t ret; + + handles =NULL ; + num =0 ; +if (efi_get_handles_by_proto (NULL , &handles, &num)) +return CMD_RET_FAILURE ; + +if (!num) +return CMD_RET_SUCCESS ; + +for (i =0 ; i < num; i++) { +printf ("%16p:" , handles[i]); + ret =BS ->protocols_per_handle (handles[i], &guid, &count); +if (ret || !count) { +putc ('\n' ); +continue ; + } + +for (j =0 ; j < count; j++) { +for (k =0 ; guid_list[k].name; k++) +if (!guidcmp (&guid_list[k].guid, guid[j])) +break ; + +if (j) +printf (", " ); +else +putc (' ' ); + +if (guid[j]) +printf ("%ls" , guid_list[k].name); +else +printf ("%pUl" , guid[j]); + } +putc ('\n' ); + } + +free (handles); + +return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {int id;
@@ -847,6 +944,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_show_devices (argc, argv); else if (!strcmp(command, "drivers"))return do_efi_show_drivers (argc, argv); + else if (!strcmp(command, "dh")) +return do_efi_show_handles (argc, argv); else return CMD_RET_USAGE; }
@@ -875,7 +974,9 @@ static char efitool_help_text[] ="efitool devices\n" " - show uefi devices\n" "efitool drivers\n" -" - show uefi drivers\n" ; +" - show uefi drivers\n" +"efitool dh\n" +" - show uefi handles\n" ;#endif U_BOOT_CMD(
Signature · 1 line
2.19.1
PATCH v4 5/9 cmd: efitool: add dh command
Quoted 23 lines · AKASHI Takahiro
"dh" command prints all the uefi handles used in the system.
=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System7ef3d3e0: Block IO, Device Path, Simple File SystemSigned-off-by AKASHI Takahiro <[email protected]>--- cmd/efitool.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-)cmd/efitool.c +0
-0
cmd/efitool.c static int do_efi_show_drivers(int argc, char * const argv[]) · line 440
Quoted 5 lines
cmd/efitool.c +2
-0@@ -436,6 +436,103 @@ static int do_efi_show_drivers(int argc, char * const argv[])return CMD_RET_SUCCESS ; } +static struct { + u16 *name;
Please, reduce the memory size by using char *.
Quoted 32 lines
cmd/efitool.c +32
-0+efi_guid_t guid; +} guid_list[] = { + { +L"Device Path" , +DEVICE_PATH_GUID , + }, + { +L"Device Path To Text" , +EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID , + }, + { +L"Device Path Utilities" , +EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID , + }, + { +L"Unicode Collation 2" , +EFI_UNICODE_COLLATION_PROTOCOL2_GUID , + }, + { +L"Driver Binding" , +EFI_DRIVER_BINDING_PROTOCOL_GUID , + }, + { +L"Simple Text Input" , +EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID , + }, + { +L"Simple Text Input Ex" , +EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID , + }, + { + L"Simple Text Output",
cmd/efitool.c static int do_efi_show_drivers(int argc, char * const argv[]) · line 482
Quoted 10 lines
cmd/efitool.c +10
-0+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID , + }, + { +L"Block IO" , +BLOCK_IO_GUID , + }, + { +L"Simple File System" , + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, + },
We implement a few more protocols, e.g.
include/efi_api.h:283:#define LOADED_IMAGE_PROTOCOL_GUID \
include/efi_api.h:467:#define BLOCK_IO_GUID \
include/efi_api.h:700:#define EFI_GOP_GUID \
include/efi_api.h:977:#define EFI_DRIVER_BINDING_PROTOCOL_GUID \
include/efi_api.h:999:#define EFI_UNICODE_COLLATION_PROTOCOL2_GUID \
cmd/efitool.c static int do_efi_show_drivers(int argc, char * const argv[]) · line 511
Quoted 4 lines
cmd/efitool.c +4
-0+ { +NULL , + {{0,},}, + }
You could use the ARRAY_SIZE() macro instead of the NULL entry.
Quoted 20 lines
cmd/efitool.c +20
-0+}; + +static int do_efi_show_handles (int argc,char *const argv[]) +{ +efi_handle_t *handles; +efi_guid_t **guid; +efi_uintn_t count; +int num, i, j, k; +efi_status_t ret; + + handles =NULL ; + num =0 ; +if (efi_get_handles_by_proto (NULL , &handles, &num)) +return CMD_RET_FAILURE ; + +if (!num) +return CMD_RET_SUCCESS ; + +for (i =0 ; i < num; i++) { +printf ("%16p:" , handles[i]);
cmd/efitool.c static int do_efi_show_drivers(int argc, char * const argv[]) · line 516
Quoted 10 lines
cmd/efitool.c +10
-0+ ret =BS ->protocols_per_handle (handles[i], &guid, &count); +if (ret || !count) { +putc ('\n' ); +continue ; + } + +for (j =0 ; j < count; j++) { +for (k =0 ; guid_list[k].name; k++) +if (!guidcmp (&guid_list[k].guid, guid[j])) +break ;
Please, put this logic into a separate function returning const char *. Return NULL if not found.
Quoted 11 lines
cmd/efitool.c +11
-0+ +if (j) +printf (", " ); +else +putc (' ' ); + +if (guid[j]) +printf ("%ls" , guid_list[k].name); +else +printf ("%pUl" , guid[j]); + }
cmd/efitool.c static int do_efi_show_drivers(int argc, char * const argv[]) · line 537
Quoted 10 lines
cmd/efitool.c +8
-0+putc ('\n' ); + } + +free (handles); + +return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {
Please, use the standard way of adding sub-commands. See doc/README.commands.
Best regards
Heinrich
Quoted 22 lines
cmd/efitool.c +5
-1int id;@@ -847,6 +944,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_show_devices (argc, argv); else if (!strcmp(command, "drivers"))return do_efi_show_drivers (argc, argv); + else if (!strcmp(command, "dh")) +return do_efi_show_handles (argc, argv); else return CMD_RET_USAGE; }@@ -875,7 +974,9 @@ static char efitool_help_text[] ="efitool devices\n" " - show uefi devices\n" "efitool drivers\n" -" - show uefi drivers\n" ; +" - show uefi drivers\n" +"efitool dh\n" +" - show uefi handles\n" ;#endif U_BOOT_CMD(
PATCH v4 5/9 cmd: efitool: add dh command
Quoted 27 lines · Heinrich Schuchardt
Quoted 26 lines · AKASHI Takahiro
"dh" command prints all the uefi handles used in the system.
=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System7ef3d3e0: Block IO, Device Path, Simple File SystemSigned-off-by AKASHI Takahiro <[email protected]>--- cmd/efitool.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-)cmd/efitool.c +0
-0@@ -436,6 +436,103 @@ static int do_efi_show_drivers(int argc, char * const argv[])return CMD_RET_SUCCESS ; }
Quoted 4 lines
cmd/efitool.c static int do_efi_show_drivers(int argc, char * const argv[]) · line 440
Quoted 2 lines
cmd/efitool.c +2
-0+static struct { + u16 *name;Please, reduce the memory size by using char *.
OK
Quoted 45 lines
Quoted 32 lines
cmd/efitool.c +32
-0+efi_guid_t guid; +} guid_list[] = { + { +L"Device Path" , +DEVICE_PATH_GUID , + }, + { +L"Device Path To Text" , +EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID , + }, + { +L"Device Path Utilities" , +EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID , + }, + { +L"Unicode Collation 2" , +EFI_UNICODE_COLLATION_PROTOCOL2_GUID , + }, + { +L"Driver Binding" , +EFI_DRIVER_BINDING_PROTOCOL_GUID , + }, + { +L"Simple Text Input" , +EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID , + }, + { +L"Simple Text Input Ex" , +EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID , + }, + { + L"Simple Text Output",cmd/efitool.c static int do_efi_show_drivers(int argc, char * const argv[]) · line 482
Quoted 10 lines
cmd/efitool.c +10
-0+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID , + }, + { +L"Block IO" , +BLOCK_IO_GUID , + }, + { +L"Simple File System" , + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, + },We implement a few more protocols, e.g.
Quoted 3 lines
include/efi_api.h:467:#define
BLOCK_IO_GUID\
include/efi_api.h:977:#defineEFI_DRIVER_BINDING_PROTOCOL_GUID\
include/efi_api.h:999:#defineEFI_UNICODE_COLLATION_PROTOCOL2_GUID\
They are already in there.
Quoted 2 lines
include/efi_api.h:283:#define
LOADED_IMAGE_PROTOCOL_GUID\
include/efi_api.h:700:#defineEFI_GOP_GUID\
Added.
Quoted 5 lines
cmd/efitool.c static int do_efi_show_drivers(int argc, char * const argv[]) · line 511
Quoted 4 lines
cmd/efitool.c +4
-0+ { +NULL , + {{0,},}, + }You could use the
ARRAY_SIZE()macro instead of the NULL entry.
OK
Quoted 25 lines
Quoted 25 lines
cmd/efitool.c +25
-0+}; + +static int do_efi_show_handles (int argc,char *const argv[]) +{ +efi_handle_t *handles; +efi_guid_t **guid; +efi_uintn_t count; +int num, i, j, k; +efi_status_t ret; + + handles =NULL ; + num =0 ; +if (efi_get_handles_by_proto (NULL , &handles, &num)) +return CMD_RET_FAILURE ; + +if (!num) +return CMD_RET_SUCCESS ; + +for (i =0 ; i < num; i++) { +printf ("%16p:" , handles[i]); + ret =BS ->protocols_per_handle (handles[i], &guid, &count); +if (ret || !count) { +putc ('\n' ); +continue ; + }
Quoted 8 lines
cmd/efitool.c static int do_efi_show_drivers(int argc, char * const argv[]) · line 516
Quoted 5 lines
cmd/efitool.c +5
-0+ +for (j =0 ; j < count; j++) { +for (k =0 ; guid_list[k].name; k++) +if (!guidcmp (&guid_list[k].guid, guid[j])) +break ;Please, put this logic into a separate function returning const char *. Return NULL if not found.
OK
Quoted 16 lines
Quoted 16 lines
cmd/efitool.c +16
-0+ +if (j) +printf (", " ); +else +putc (' ' ); + +if (guid[j]) +printf ("%ls" , guid_list[k].name); +else +printf ("%pUl" , guid[j]); + } +putc ('\n' ); + } + +free (handles); +
Quoted 8 lines
cmd/efitool.c static int do_efi_show_drivers(int argc, char * const argv[]) · line 537
Quoted 5 lines
cmd/efitool.c +3
-0+return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {Please, use the standard way of adding sub-commands. See doc/README.commands.
OK
Thanks,
-Takahiro Akashi
Quoted 27 lines
Best regards
Heinrich
Quoted 22 lines
cmd/efitool.c +5
-1int id;@@ -847,6 +944,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_show_devices (argc, argv); else if (!strcmp(command, "drivers"))return do_efi_show_drivers (argc, argv); + else if (!strcmp(command, "dh")) +return do_efi_show_handles (argc, argv); else return CMD_RET_USAGE; }@@ -875,7 +974,9 @@ static char efitool_help_text[] ="efitool devices\n" " - show uefi devices\n" "efitool drivers\n" -" - show uefi drivers\n" ; +" - show uefi drivers\n" +"efitool dh\n" +" - show uefi handles\n" ;#endif U_BOOT_CMD(
PATCH v4 6/9 cmd: efitool: add images command
In reply to AKASHI Takahiro"images" command prints loaded images-related information.
--- cmd/efitool.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
cmd/efitool.c +12 -1
@@ -533,6 +533,13 @@ static int do_efi_show_handles(int argc, char * const argv[])return CMD_RET_SUCCESS ; } +static int do_efi_show_images (int argc,char *const argv[]) +{ +efi_print_image_infos (NULL ); + +return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {int id;
@@ -946,6 +953,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_show_drivers (argc, argv); else if (!strcmp(command, "dh"))return do_efi_show_handles (argc, argv); + else if (!strcmp(command, "images")) +return do_efi_show_images (argc, argv); else return CMD_RET_USAGE; }
@@ -976,7 +985,9 @@ static char efitool_help_text[] ="efitool drivers\n" " - show uefi drivers\n" "efitool dh\n" -" - show uefi handles\n" ; +" - show uefi handles\n" +"efitool images\n" +" - show loaded images\n" ;#endif U_BOOT_CMD(
Signature · 1 line
2.19.1
PATCH v4 6/9 cmd: efitool: add images command
Quoted 14 lines · AKASHI Takahiro
"images" command prints loaded images-related information.
Signed-off-by AKASHI Takahiro <[email protected]>--- cmd/efitool.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)cmd/efitool.c +0
-0@@ -533,6 +533,13 @@ static int do_efi_show_handles(int argc, char * const argv[])return CMD_RET_SUCCESS ; }
cmd/efitool.c static int do_efi_show_handles(int argc, char * const argv[]) · line 544
Quoted 10 lines
cmd/efitool.c +7
-0+static int do_efi_show_images (int argc,char *const argv[]) +{ +efi_print_image_infos (NULL ); + +return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {
Please, use the standard way of adding sub-commands. See doc/README.commands.
Best regards
Heinrich
Quoted 22 lines
cmd/efitool.c +5
-1int id;@@ -946,6 +953,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_show_drivers (argc, argv); else if (!strcmp(command, "dh"))return do_efi_show_handles (argc, argv); + else if (!strcmp(command, "images")) +return do_efi_show_images (argc, argv); else return CMD_RET_USAGE; }@@ -976,7 +985,9 @@ static char efitool_help_text[] ="efitool drivers\n" " - show uefi drivers\n" "efitool dh\n" -" - show uefi handles\n" ; +" - show uefi handles\n" +"efitool images\n" +" - show loaded images\n" ;#endif U_BOOT_CMD(
PATCH v4 6/9 cmd: efitool: add images command
Quoted 16 lines · Heinrich Schuchardt
Quoted 15 lines · AKASHI Takahiro
"images" command prints loaded images-related information.
Signed-off-by AKASHI Takahiro <[email protected]>--- cmd/efitool.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)cmd/efitool.c +0
-0@@ -533,6 +533,13 @@ static int do_efi_show_handles(int argc, char * const argv[])return CMD_RET_SUCCESS ; }
Quoted 12 lines
cmd/efitool.c static int do_efi_show_handles(int argc, char * const argv[]) · line 544
Quoted 9 lines
cmd/efitool.c +7
-0+static int do_efi_show_images (int argc,char *const argv[]) +{ +efi_print_image_infos (NULL ); + +return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {Please, use the standard way of adding sub-commands. See doc/README.commands.
OK
-Takahiro Akashi
Quoted 27 lines
Best regards
Heinrich
Quoted 22 lines
cmd/efitool.c +5
-1int id;@@ -946,6 +953,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_show_drivers (argc, argv); else if (!strcmp(command, "dh"))return do_efi_show_handles (argc, argv); + else if (!strcmp(command, "images")) +return do_efi_show_images (argc, argv); else return CMD_RET_USAGE; }@@ -976,7 +985,9 @@ static char efitool_help_text[] ="efitool drivers\n" " - show uefi drivers\n" "efitool dh\n" -" - show uefi handles\n" ; +" - show uefi handles\n" +"efitool images\n" +" - show loaded images\n" ;#endif U_BOOT_CMD(
PATCH v4 7/9 cmd: efitool: add memmap command
In reply to AKASHI Takahiro"memmap" command prints uefi-specific memory map information. => efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB RUNTIME DATA 000000007de27000-000000007de28000 WB|RT RESERVED 000000007de28000-000000007de2a000 WB RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT RESERVED 000000007de2b000-000000007de2c000 WB RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT LOADER DATA 000000007de2d000-000000007ff37000 WB RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT LOADER DATA 000000007ff38000-0000000080000000 WB
--- cmd/efitool.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-)
cmd/efitool.c +77 -1
@@ -540,6 +540,78 @@ static int do_efi_show_images(int argc, char * const argv[])return CMD_RET_SUCCESS ; } +static const char *const efi_mem_type_string[] = { + [EFI_RESERVED_MEMORY_TYPE ] ="RESERVED" , + [EFI_LOADER_CODE ] ="LOADER CODE" , + [EFI_LOADER_DATA ] ="LOADER DATA" , + [EFI_BOOT_SERVICES_CODE ] ="BOOT CODE" , + [EFI_BOOT_SERVICES_DATA ] ="BOOT DATA" , + [EFI_RUNTIME_SERVICES_CODE ] ="RUNTIME CODE" , + [EFI_RUNTIME_SERVICES_DATA ] ="RUNTIME DATA" , + [EFI_CONVENTIONAL_MEMORY ] ="CONVENTIONAL" , + [EFI_UNUSABLE_MEMORY ] ="UNUSABLE MEM" , + [EFI_ACPI_RECLAIM_MEMORY ] ="ACPI RECLAIM MEM" , + [EFI_ACPI_MEMORY_NVS ] ="ACPI NVS" , + [EFI_MMAP_IO ] ="IO" , + [EFI_MMAP_IO_PORT ] ="IO PORT" , + [EFI_PAL_CODE ] ="PAL" , +}; + +#define EFI_MEM_ATTR (attribute, bit, string) \ + if ((attribute) & (bit)) { \ + if (sep) \ + putc('|'); \ + sep = 1; \ + printf(string); \ + } + +static int do_efi_show_memmap (int argc,char *const argv[]) +{ +struct efi_mem_desc *memmap =NULL , *map; +efi_uintn_t map_size =0 ; +int i, sep; +efi_status_t ret; + + ret =efi_get_memory_map (&map_size, memmap,NULL ,NULL ,NULL ); +if (ret ==EFI_BUFFER_TOO_SMALL ) { + memmap =malloc (map_size); +if (!memmap) +return CMD_RET_FAILURE ; + ret =efi_get_memory_map (&map_size, memmap,NULL ,NULL ,NULL ); + } +if (ret !=EFI_SUCCESS ) { +free (memmap); +return CMD_RET_FAILURE ; + } + +printf ("Type Start End Attributes\n" ); +printf ("================ ================ ================ ==========\n" ); +for (i =0 , map = memmap; i < map_size /sizeof (*map); map++, i++) { + sep =0 ; +printf ("%-16s %016llx-%016llx " , + efi_mem_type_string[map->type], + map->physical_start, + map->physical_start + map->num_pages *EFI_PAGE_SIZE ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_UC ,"UC" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_WC ,"WC" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_WT ,"WT" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_WB ,"WB" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_UCE ,"UCE" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_WP ,"WP" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_RP ,"RP" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_XP ,"WP" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_NV ,"NV" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_MORE_RELIABLE ,"REL" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_RO ,"RO" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_RUNTIME ,"RT" ); +putc ('\n' ); + } + +free (memmap); + +return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {int id;
@@ -955,6 +1027,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_show_handles (argc, argv); else if (!strcmp(command, "images"))return do_efi_show_images (argc, argv); + else if (!strcmp(command, "memmap")) +return do_efi_show_memmap (argc, argv); else return CMD_RET_USAGE; }
@@ -987,7 +1061,9 @@ static char efitool_help_text[] ="efitool dh\n" " - show uefi handles\n" "efitool images\n" -" - show loaded images\n" ; +" - show loaded images\n" +"efitool memmap\n" +" - show uefi memory map\n" ;#endif U_BOOT_CMD(
Signature · 1 line
2.19.1
PATCH v4 7/9 cmd: efitool: add memmap command
Quoted 50 lines · AKASHI Takahiro
"memmap" command prints uefi-specific memory map information. => efi memmap
Type Start End Attributes
================ ================ ================ ==========CONVENTIONAL 0000000040000000-000000007de27000 WB RUNTIME DATA 000000007de27000-000000007de28000 WB|RT RESERVED 000000007de28000-000000007de2a000 WB RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT RESERVED 000000007de2b000-000000007de2c000 WB RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT LOADER DATA 000000007de2d000-000000007ff37000 WB RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT LOADER DATA 000000007ff38000-0000000080000000 WBSigned-off-by AKASHI Takahiro <[email protected]>--- cmd/efitool.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-)cmd/efitool.c +23
-0@@ -540,6 +540,78 @@ static int do_efi_show_images(int argc, char * const argv[])return CMD_RET_SUCCESS ; } +static const char *const efi_mem_type_string[] = { + [EFI_RESERVED_MEMORY_TYPE ] ="RESERVED" , + [EFI_LOADER_CODE ] ="LOADER CODE" , + [EFI_LOADER_DATA ] ="LOADER DATA" , + [EFI_BOOT_SERVICES_CODE ] ="BOOT CODE" , + [EFI_BOOT_SERVICES_DATA ] ="BOOT DATA" , + [EFI_RUNTIME_SERVICES_CODE ] ="RUNTIME CODE" , + [EFI_RUNTIME_SERVICES_DATA ] ="RUNTIME DATA" , + [EFI_CONVENTIONAL_MEMORY ] ="CONVENTIONAL" , + [EFI_UNUSABLE_MEMORY ] ="UNUSABLE MEM" , + [EFI_ACPI_RECLAIM_MEMORY ] ="ACPI RECLAIM MEM" , + [EFI_ACPI_MEMORY_NVS ] ="ACPI NVS" , + [EFI_MMAP_IO ] ="IO" , + [EFI_MMAP_IO_PORT ] ="IO PORT" , + [EFI_PAL_CODE ] ="PAL" , +}; + +#define EFI_MEM_ATTR (attribute, bit, string) \ + if ((attribute) & (bit)) { \ + if (sep) \ + putc('|'); \ + sep = 1; \ + printf(string); \
cmd/efitool.c static int do_efi_show_images(int argc, char * const argv[]) · line 575
Quoted 10 lines
cmd/efitool.c +10
-0+ } + +static int do_efi_show_memmap (int argc,char *const argv[]) +{ +struct efi_mem_desc *memmap =NULL , *map; +efi_uintn_t map_size =0 ; +int i, sep; +efi_status_t ret; + + ret =efi_get_memory_map (&map_size, memmap,NULL ,NULL ,NULL );
ret = EFI_SUCCCESS will only occur if the memory has not been setup yet.
So shouldn't we error out if ret != EFI_BUFFER_TOO_SMALL ?
Quoted 21 lines
cmd/efitool.c +21
-0+if (ret ==EFI_BUFFER_TOO_SMALL ) { + memmap =malloc (map_size); +if (!memmap) +return CMD_RET_FAILURE ; + ret =efi_get_memory_map (&map_size, memmap,NULL ,NULL ,NULL ); + } +if (ret !=EFI_SUCCESS ) { +free (memmap); +return CMD_RET_FAILURE ; + } + +printf ("Type Start End Attributes\n" ); +printf ("================ ================ ================ ==========\n" ); +for (i =0 , map = memmap; i < map_size /sizeof (*map); map++, i++) { + sep =0 ; +printf ("%-16s %016llx-%016llx " , + efi_mem_type_string[map->type], + map->physical_start, + map->physical_start + map->num_pages *EFI_PAGE_SIZE ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_UC ,"UC" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_WC ,"WC" );
cmd/efitool.c static int do_efi_show_images(int argc, char * const argv[]) · line 606
Quoted 10 lines
cmd/efitool.c +10
-0+EFI_MEM_ATTR (map->attribute,EFI_MEMORY_WT ,"WT" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_WB ,"WB" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_UCE ,"UCE" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_WP ,"WP" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_RP ,"RP" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_XP ,"WP" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_NV ,"NV" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_MORE_RELIABLE ,"REL" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_RO ,"RO" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_RUNTIME ,"RT" );
Please, put that logic into a separate function which returns a const char *. Then we need only a single printf().
I suggest to use an array for the mapping:
struct memory_attribute_name {
u64 attribute;
const char *short_name;
};struct memory_attribute_name memory_attribute_names[] = {
{EFI_MEMORY_UC, "UC"},
...
};For looping you can use ARRAY_SIZE(memory_attribute_names).
cmd/efitool.c static int do_efi_show_images(int argc, char * const argv[]) · line 616
Quoted 10 lines
cmd/efitool.c +8
-0+putc ('\n' ); + } + +free (memmap); + +return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {
Please, refer to doc/README.commands for the standard way of adding sub-commands.
Best regards
Heinrich
Quoted 22 lines
cmd/efitool.c +5
-1int id;@@ -955,6 +1027,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_show_handles (argc, argv); else if (!strcmp(command, "images"))return do_efi_show_images (argc, argv); + else if (!strcmp(command, "memmap")) +return do_efi_show_memmap (argc, argv); else return CMD_RET_USAGE; }@@ -987,7 +1061,9 @@ static char efitool_help_text[] ="efitool dh\n" " - show uefi handles\n" "efitool images\n" -" - show loaded images\n" ; +" - show loaded images\n" +"efitool memmap\n" +" - show uefi memory map\n" ;#endif U_BOOT_CMD(
PATCH v4 7/9 cmd: efitool: add memmap command
Quoted 55 lines · Heinrich Schuchardt
Quoted 54 lines · AKASHI Takahiro
"memmap" command prints uefi-specific memory map information. => efi memmap
Type Start End Attributes
================ ================ ================ ==========CONVENTIONAL 0000000040000000-000000007de27000 WB RUNTIME DATA 000000007de27000-000000007de28000 WB|RT RESERVED 000000007de28000-000000007de2a000 WB RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT RESERVED 000000007de2b000-000000007de2c000 WB RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT LOADER DATA 000000007de2d000-000000007ff37000 WB RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT LOADER DATA 000000007ff38000-0000000080000000 WBSigned-off-by AKASHI Takahiro <[email protected]>--- cmd/efitool.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-)cmd/efitool.c +27
-0@@ -540,6 +540,78 @@ static int do_efi_show_images(int argc, char * const argv[])return CMD_RET_SUCCESS ; } +static const char *const efi_mem_type_string[] = { + [EFI_RESERVED_MEMORY_TYPE ] ="RESERVED" , + [EFI_LOADER_CODE ] ="LOADER CODE" , + [EFI_LOADER_DATA ] ="LOADER DATA" , + [EFI_BOOT_SERVICES_CODE ] ="BOOT CODE" , + [EFI_BOOT_SERVICES_DATA ] ="BOOT DATA" , + [EFI_RUNTIME_SERVICES_CODE ] ="RUNTIME CODE" , + [EFI_RUNTIME_SERVICES_DATA ] ="RUNTIME DATA" , + [EFI_CONVENTIONAL_MEMORY ] ="CONVENTIONAL" , + [EFI_UNUSABLE_MEMORY ] ="UNUSABLE MEM" , + [EFI_ACPI_RECLAIM_MEMORY ] ="ACPI RECLAIM MEM" , + [EFI_ACPI_MEMORY_NVS ] ="ACPI NVS" , + [EFI_MMAP_IO ] ="IO" , + [EFI_MMAP_IO_PORT ] ="IO PORT" , + [EFI_PAL_CODE ] ="PAL" , +}; + +#define EFI_MEM_ATTR (attribute, bit, string) \ + if ((attribute) & (bit)) { \ + if (sep) \ + putc('|'); \ + sep = 1; \ + printf(string); \ + } + +static int do_efi_show_memmap (int argc,char *const argv[]) +{
Quoted 8 lines
cmd/efitool.c static int do_efi_show_images(int argc, char * const argv[]) · line 575
Quoted 6 lines
cmd/efitool.c +6
-0+struct efi_mem_desc *memmap =NULL , *map; +efi_uintn_t map_size =0 ; +int i, sep; +efi_status_t ret; + + ret =efi_get_memory_map (&map_size, memmap,NULL ,NULL ,NULL );ret =
EFI_SUCCCESSwill only occur if the memory has not been setup yet.
I don't think so.
Quoted 28 lines
So shouldn't we error out if ret !=
EFI_BUFFER_TOO_SMALL?Quoted 26 lines
cmd/efitool.c +26
-0+if (ret ==EFI_BUFFER_TOO_SMALL ) { + memmap =malloc (map_size); +if (!memmap) +return CMD_RET_FAILURE ; + ret =efi_get_memory_map (&map_size, memmap,NULL ,NULL ,NULL ); + } +if (ret !=EFI_SUCCESS ) { +free (memmap); +return CMD_RET_FAILURE ; + } + +printf ("Type Start End Attributes\n" ); +printf ("================ ================ ================ ==========\n" ); +for (i =0 , map = memmap; i < map_size /sizeof (*map); map++, i++) { + sep =0 ; +printf ("%-16s %016llx-%016llx " , + efi_mem_type_string[map->type], + map->physical_start, + map->physical_start + map->num_pages *EFI_PAGE_SIZE ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_UC ,"UC" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_WC ,"WC" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_WT ,"WT" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_WB ,"WB" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_UCE ,"UCE" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_WP ,"WP" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_RP ,"RP" );
Quoted 8 lines
cmd/efitool.c static int do_efi_show_images(int argc, char * const argv[]) · line 606
Quoted 5 lines
cmd/efitool.c +5
-0+EFI_MEM_ATTR (map->attribute,EFI_MEMORY_XP ,"WP" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_NV ,"NV" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_MORE_RELIABLE ,"REL" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_RO ,"RO" ); +EFI_MEM_ATTR (map->attribute,EFI_MEMORY_RUNTIME ,"RT" );Please, put that logic into a separate function which returns a const char *. Then we need only a single
printf().
I don't think it's worth generating a one-time string only for this specific use.
If 'printf' is a matter, I will simply replace it to puts() here.
Quoted 14 lines
I suggest to use an array for the mapping:
struct memory_attribute_name { u64 attribute; const char *short_name; };struct memory_attribute_name memory_attribute_names[] = { {EFI_MEMORY_UC, "UC"}, ... };For looping you can use
ARRAY_SIZE(memory_attribute_names).
Quoted 13 lines
cmd/efitool.c static int do_efi_show_images(int argc, char * const argv[]) · line 616
Quoted 10 lines
cmd/efitool.c +8
-0+putc ('\n' ); + } + +free (memmap); + +return CMD_RET_SUCCESS ; +} +static int do_efi_boot_add (int argc,char *const argv[]) {Please, refer to doc/README.commands for the standard way of adding sub-commands.
OK
Thanks,
-Takahiro Akashi
Quoted 27 lines
Best regards
Heinrich
Quoted 22 lines
cmd/efitool.c +5
-1int id;@@ -955,6 +1027,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,return do_efi_show_handles (argc, argv); else if (!strcmp(command, "images"))return do_efi_show_images (argc, argv); + else if (!strcmp(command, "memmap")) +return do_efi_show_memmap (argc, argv); else return CMD_RET_USAGE; }@@ -987,7 +1061,9 @@ static char efitool_help_text[] ="efitool dh\n" " - show uefi handles\n" "efitool images\n" -" - show loaded images\n" ; +" - show loaded images\n" +"efitool memmap\n" +" - show uefi memory map\n" ;#endif U_BOOT_CMD(
PATCH v4 8/9 cmd: efitool: export uefi variable helper functions
In reply to AKASHI TakahiroThose function will be used for integration with 'env' command so as to handle uefi variables.
--- cmd/efitool.c | 38 ++++++++++++++++++++++++++++++++++---- include/command.h | 4 ++++ 2 files changed, 38 insertions(+), 4 deletions(-)
cmd/efitool.c +34 -4
@@ -67,7 +67,7 @@ static void dump_var_data(char *data, unsigned long len)* * efi_$guid_$varname = {attributes}(type)value */ -static int do_efi_dump_var (int argc,char *const argv[]) +static int _do_efi_dump_var (int argc,char *const argv[]) {char regex[256 ];char *const regexlist[] = {regex};
@@ -130,6 +130,21 @@ static int do_efi_dump_var(int argc, char * const argv[])return CMD_RET_SUCCESS ; } +int do_efi_dump_var (int argc,char *const argv[]) +{ +efi_status_t r; + +/* Initialize EFI drivers */ + r =efi_init_obj_list (); +if (r !=EFI_SUCCESS ) { +printf ("Error: Cannot set up EFI drivers, r = %lu\n" , + r & ~EFI_ERROR_MASK ); +return CMD_RET_FAILURE ; + } + +return _do_efi_dump_var (argc, argv); +} +static int append_value (char **bufp,unsigned long *sizep,char *data) {char *tmp_buf =NULL , *new_buf =NULL , *value;
@@ -227,7 +242,7 @@ out:return 0 ; } -static int do_efi_set_var (int argc,char *const argv[]) +static int _do_efi_set_var (int argc,char *const argv[]) {char *var_name, *value =NULL ;efi_uintn_t size =0 ;
@@ -270,6 +285,21 @@ out:return ret; } +int do_efi_set_var (int argc,char *const argv[]) +{ +efi_status_t r; + +/* Initialize EFI drivers */ + r =efi_init_obj_list (); +if (r !=EFI_SUCCESS ) { +printf ("Error: Cannot set up EFI drivers, r = %lu\n" , + r & ~EFI_ERROR_MASK ); +return CMD_RET_FAILURE ; + } + +return _do_efi_set_var (argc, argv); +} +static int efi_get_handles_by_proto (efi_guid_t *guid,efi_handle_t **handlesp,int *num) {
@@ -1016,9 +1046,9 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,if (!strcmp (command,"boot" ))return do_efi_boot_opt (argc, argv);else if (!strcmp (command,"dumpvar" ) || !strcmp (command,"dmpstore" )) -return do_efi_dump_var (argc, argv); +return _do_efi_dump_var (argc, argv);else if (!strcmp (command,"setvar" )) -return do_efi_set_var (argc, argv); +return _do_efi_set_var (argc, argv);else if (!strcmp (command,"devices" ))return do_efi_show_devices (argc, argv);else if (!strcmp (command,"drivers" ))
include/command.h +4 -0
@@ -51,6 +51,10 @@ extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);#if defined(CONFIG_CMD_BOOTEFI )extern int do_bootefi_run (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]);#endif +#if defined(CONFIG_CMD_EFITOOL ) +int do_efi_dump_var (int argc,char *const argv[]); +int do_efi_set_var (int argc,char *const argv[]); +#endif /* common/command.c */ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
Signature · 1 line
2.19.1
PATCH v4 8/9 cmd: efitool: export uefi variable helper functions
Quoted 14 lines · AKASHI Takahiro
Those function will be used for integration with 'env' command so as to handle uefi variables.
Signed-off-by AKASHI Takahiro <[email protected]>--- cmd/efitool.c | 38 ++++++++++++++++++++++++++++++++++---- include/command.h | 4 ++++ 2 files changed, 38 insertions(+), 4 deletions(-)cmd/efitool.c +0
-0
cmd/efitool.c static void dump_var_data(char *data, unsigned long len) · line 70
Quoted 5 lines
cmd/efitool.c +1
-1@@ -67,7 +67,7 @@ static void dump_var_data(char *data, unsigned long len)* * efi_$guid_$varname = {attributes}(type)value */ -static int do_efi_dump_var (int argc,char *const argv[]) +static int _do_efi_dump_var (int argc,char *const argv[])
Please, do not use two function names only distinguished by and underscore. A a reader I will always wonder which does what.
Please, use names that describe what the difference is.
Quoted 6 lines
cmd/efitool.c +0
-0{char regex[256 ];char *const regexlist[] = {regex};@@ -130,6 +130,21 @@ static int do_efi_dump_var(int argc, char * const argv[])return CMD_RET_SUCCESS ; }
cmd/efitool.c static int do_efi_dump_var(int argc, char * const argv[]) · line 141
Quoted 10 lines
cmd/efitool.c +9
-0+int do_efi_dump_var (int argc,char *const argv[]) +{ +efi_status_t r; + +/* Initialize EFI drivers */ + r =efi_init_obj_list (); +if (r !=EFI_SUCCESS ) { +printf ("Error: Cannot set up EFI drivers, r = %lu\n" , + r & ~EFI_ERROR_MASK );
You duplicate this code below.
So, please, put this into a separate function.
That could also help to avoid having separate do_efi_set_var and _do_efi_set_var.
Quoted 20 lines
cmd/efitool.c +7
-1+return CMD_RET_FAILURE ; + } + +return _do_efi_dump_var (argc, argv); +} +static int append_value (char **bufp,unsigned long *sizep,char *data) {char *tmp_buf =NULL , *new_buf =NULL , *value;@@ -227,7 +242,7 @@ out:return 0 ; } -static int do_efi_set_var (int argc,char *const argv[]) +static int _do_efi_set_var (int argc,char *const argv[]) {char *var_name, *value =NULL ;efi_uintn_t size =0 ;@@ -270,6 +285,21 @@ out:return ret;
cmd/efitool.c out: · line 295
Quoted 10 lines
cmd/efitool.c +8
-0} +int do_efi_set_var (int argc,char *const argv[]) +{ +efi_status_t r; + +/* Initialize EFI drivers */ + r =efi_init_obj_list (); +if (r !=EFI_SUCCESS ) { + printf("Error: Cannot set up EFI drivers, r = %lu\n",
It is more then drivers that we setup. So perhaps
"Cannot initialize UEFI sub-system."
Quoted 27 lines
cmd/efitool.c +9
-2+ r & ~EFI_ERROR_MASK); +return CMD_RET_FAILURE ; + } + +return _do_efi_set_var (argc, argv); +} +static int efi_get_handles_by_proto (efi_guid_t *guid,efi_handle_t **handlesp,int *num) {@@ -1016,9 +1046,9 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,if (!strcmp (command,"boot" ))return do_efi_boot_opt (argc, argv);else if (!strcmp (command,"dumpvar" ) || !strcmp (command,"dmpstore" )) -return do_efi_dump_var (argc, argv); +return _do_efi_dump_var (argc, argv);else if (!strcmp (command,"setvar" )) -return do_efi_set_var (argc, argv); +return _do_efi_set_var (argc, argv);else if (!strcmp (command,"devices" ))return do_efi_show_devices (argc, argv);else if (!strcmp (command,"drivers" ))include/command.h +0
-0
include/command.h extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); · line 54
Quoted 4 lines
include/command.h +1
-0@@ -51,6 +51,10 @@ extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);#if defined(CONFIG_CMD_BOOTEFI )extern int do_bootefi_run (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]);#endif +#if defined(CONFIG_CMD_EFITOOL )
The definition has not dependencies. No need for an #if here.
include/command.h extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
Quoted 3 lines
include/command.h +3
-0+int do_efi_dump_var (int argc,char *const argv[]); +int do_efi_set_var (int argc,char *const argv[]); +#endi
Shouldn't we put this into some include/efi*?
Best regards
Heinrich
Quoted 4 lines
include/command.h +0
-0/* common/command.c */ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
PATCH v4 8/9 cmd: efitool: export uefi variable helper functions
Quoted 10 lines · Heinrich Schuchardt
Quoted 9 lines · AKASHI Takahiro
Those function will be used for integration with 'env' command so as to handle uefi variables.
Signed-off-by AKASHI Takahiro <[email protected]>--- cmd/efitool.c | 38 ++++++++++++++++++++++++++++++++++---- include/command.h | 4 ++++ 2 files changed, 38 insertions(+), 4 deletions(-)
Quoted 13 lines
cmd/efitool.c static void dump_var_data(char *data, unsigned long len) · line 70
Quoted 10 lines
cmd/efitool.c +1
-1@@ -67,7 +67,7 @@ static void dump_var_data(char *data, unsigned long len)* * efi_$guid_$varname = {attributes}(type)value */ -static int do_efi_dump_var (int argc,char *const argv[]) +static int _do_efi_dump_var (int argc,char *const argv[])Please, do not use two function names only distinguished by and underscore. A a reader I will always wonder which does what.
While I believe that "_" and "__" are a very common practice to show an internal version of function,
Quoted 1 line
Please, use names that describe what the difference is.
I will revert _do_efi_dump_var() to do_efi_dump_var() and change do_efi_dump_var() to do_efi_dump_var_ext().
Quoted 7 lines
Quoted 7 lines
cmd/efitool.c +0
-0{char regex[256 ];char *const regexlist[] = {regex};@@ -130,6 +130,21 @@ static int do_efi_dump_var(int argc, char * const argv[])return CMD_RET_SUCCESS ; }
Quoted 11 lines
cmd/efitool.c static int do_efi_dump_var(int argc, char * const argv[]) · line 141
Quoted 9 lines
cmd/efitool.c +9
-0+int do_efi_dump_var (int argc,char *const argv[]) +{ +efi_status_t r; + +/* Initialize EFI drivers */ + r =efi_init_obj_list (); +if (r !=EFI_SUCCESS ) { +printf ("Error: Cannot set up EFI drivers, r = %lu\n" , + r & ~EFI_ERROR_MASK );You duplicate this code below.
Do you want another function for just calling one function? I don't think it's worth doing so.
Quoted 4 lines
So, please, put this into a separate function.
That could also help to avoid having separate
do_efi_set_varand_do_efi_set_var.
I don't get your point.
Do you want to call efi_init_obj_list() at every do_efi_xxx()? It just doesn't make sense.
Quoted 33 lines
Quoted 20 lines
cmd/efitool.c +7
-1+return CMD_RET_FAILURE ; + } + +return _do_efi_dump_var (argc, argv); +} +static int append_value (char **bufp,unsigned long *sizep,char *data) {char *tmp_buf =NULL , *new_buf =NULL , *value;@@ -227,7 +242,7 @@ out:return 0 ; } -static int do_efi_set_var (int argc,char *const argv[]) +static int _do_efi_set_var (int argc,char *const argv[]) {char *var_name, *value =NULL ;efi_uintn_t size =0 ;@@ -270,6 +285,21 @@ out:return ret;cmd/efitool.c out: · line 295
Quoted 10 lines
cmd/efitool.c +8
-0} +int do_efi_set_var (int argc,char *const argv[]) +{ +efi_status_t r; + +/* Initialize EFI drivers */ + r =efi_init_obj_list (); +if (r !=EFI_SUCCESS ) { + printf("Error: Cannot set up EFI drivers, r = %lu\n",It is more then drivers that we setup. So perhaps
Quoted 1 line
"Cannot initialize UEFI sub-system."
I don't mind, but that string directly comes from the original code in bootefi.c.
Quoted 25 lines
Quoted 25 lines
cmd/efitool.c +9
-2+ r & ~EFI_ERROR_MASK); +return CMD_RET_FAILURE ; + } + +return _do_efi_set_var (argc, argv); +} +static int efi_get_handles_by_proto (efi_guid_t *guid,efi_handle_t **handlesp,int *num) {@@ -1016,9 +1046,9 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag,if (!strcmp (command,"boot" ))return do_efi_boot_opt (argc, argv);else if (!strcmp (command,"dumpvar" ) || !strcmp (command,"dmpstore" )) -return do_efi_dump_var (argc, argv); +return _do_efi_dump_var (argc, argv);else if (!strcmp (command,"setvar" )) -return do_efi_set_var (argc, argv); +return _do_efi_set_var (argc, argv);else if (!strcmp (command,"devices" ))return do_efi_show_devices (argc, argv);else if (!strcmp (command,"drivers" ))include/command.h +0
-1--- a/include/command.h
Quoted 8 lines
include/command.h extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); · line 54
Quoted 6 lines
+++
b/include/command.hinclude/command.h +1
-0@@ -51,6 +51,10 @@ extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);#if defined(CONFIG_CMD_BOOTEFI )extern int do_bootefi_run (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]);#endif +#if defined(CONFIG_CMD_EFITOOL )The definition has not dependencies. No need for an #if here.
Currently has, but as you and Alex suggested in a separate thread, we may want to enable it (and do_efi_dump/set_var() as well) whether or not CMD_BOOTEFI and CMD_EFIDEBUG, respectively, are defined.
Thanks,
-Takahiro Akashi
Quoted 15 lines
include/command.h extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
Quoted 3 lines
include/command.h +3
-0+int do_efi_dump_var (int argc,char *const argv[]); +int do_efi_set_var (int argc,char *const argv[]); +#endi Shouldn't we put this into some
include/efi*?Best regards
Heinrich
Quoted 4 lines
include/command.h +0
-0/* common/command.c */ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
PATCH v4 9/9 cmd: env: add "-e" option for handling UEFI variables
In reply to AKASHI Takahiro"env [print|set] -e" allows for handling uefi variables without knowing details about mapping to corresponding u-boot variables.
--- cmd/nvedit.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-)
cmd/nvedit.c +59 -2
@@ -27,6 +27,8 @@#include <cli.h> #include <command.h> #include <console.h> +#include <efi.h> +#include <efi_loader.h> #include <environment.h> #include <search.h> #include <errno.h>
@@ -119,6 +121,25 @@ static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,int rcode =0 ;int env_flag =H_HIDE_DOT ; +#if defined(CONFIG_CMD_EFITOOL ) +if (argc >1 && argv[1 ][0 ] =='-' && argv[1 ][1 ] =='e' ) { +efi_status_t r; + + argc--; + argv++; + +/* Initialize EFI drivers */ + r =efi_init_obj_list (); +if (r !=EFI_SUCCESS ) { +printf ("Error: Cannot set up EFI drivers, r = %lu\n" , + r & ~EFI_ERROR_MASK ); +return CMD_RET_FAILURE ; + } + +return do_efi_dump_var (argc, argv); + } +#endif +if (argc >1 && argv[1 ][0 ] =='-' && argv[1 ][1 ] =='a' ) { argc--; argv++;
@@ -216,6 +237,26 @@ static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)ENTRY e, *ep;debug ("Initial value for argc=%d\n" , argc); + +#if defined(CONFIG_CMD_EFITOOL ) +if (argc >1 && argv[1 ][0 ] =='-' && argv[1 ][1 ] =='e' ) { +efi_status_t r; + + argc--; + argv++; + +/* Initialize EFI drivers */ + r =efi_init_obj_list (); +if (r !=EFI_SUCCESS ) { +printf ("Error: Cannot set up EFI drivers, r = %lu\n" , + r & ~EFI_ERROR_MASK ); +return CMD_RET_FAILURE ; + } + +return do_efi_set_var (argc, argv); + } +#endif +while (argc >1 && **(argv +1 ) =='-' ) {char *arg = *++argv;
@@ -1262,15 +1303,23 @@ static char env_help_text[] =#if defined(CONFIG_CMD_IMPORTENV ) "env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import environment\n"#endif +#if defined(CONFIG_CMD_EFITOOL ) +"env print [-a | -e [name] | name ...] - print environment\n" +#else "env print [-a | name ...] - print environment\n" +#endif #if defined(CONFIG_CMD_RUN ) "env run var [...] - run commands in an environment variable\n"#endif #if defined(CONFIG_CMD_SAVEENV ) && !defined(CONFIG_ENV_IS_NOWHERE ) "env save - save environment\n"#endif +#if defined(CONFIG_CMD_EFITOOL ) +"env set [-e | -f] name [arg ...]\n" ; +#else "env set [-f] name [arg ...]\n" ;#endif +#endif U_BOOT_CMD( env, CONFIG_SYS_MAXARGS, 1, do_env,
@@ -1295,6 +1344,10 @@ U_BOOT_CMD_COMPLETE( printenv, CONFIG_SYS_MAXARGS, 1, do_env_print, "print environment variables", "[-a]\n - print [all] values of all environment variables\n" +#if defined(CONFIG_CMD_EFITOOL ) +"printenv -e [<name>]\n" + " - print UEFI variable 'name' or all the variables\n" +#endif "printenv name ...\n" " - print value of environment variable 'name'" , var_complete
@@ -1322,7 +1375,11 @@ U_BOOT_CMD_COMPLETE(U_BOOT_CMD_COMPLETE ( setenv,CONFIG_SYS_MAXARGS ,0 , do_env_set,"set environment variables" , - "[-f] name value ...\n" +#if defined(CONFIG_CMD_EFITOOL) + "-e <name> [<value>]\n" + " - set UEFI variable 'name' to 'value' ...'\n" +#endif +"setenv [-f] name value ...\n" " - [forcibly] set environment variable 'name' to 'value ...'\n" "setenv [-f] name\n" " - [forcibly] delete environment variable 'name'",
@@ -1345,7 +1402,7 @@ U_BOOT_CMD_COMPLETE("run commands in an environment variable" ,"var [...]\n" " - run the commands in the environment variable(s) 'var'" -#if defined(CONFIG_CMD_BOOTEFI ) +#if defined(CONFIG_CMD_EFITOOL )"\n" "run -e [BootXXXX]\n" " - load and run UEFI app based on 'BootXXXX' UEFI variable",
Signature · 1 line
2.19.1
PATCH v4 9/9 cmd: env: add "-e" option for handling UEFI variables
Quoted 2 lines · AKASHI Takahiro
"env [print|set] -e" allows for handling uefi variables without knowing details about mapping to corresponding u-boot variables.
Why do we need two alternative ways to achieve the same result? We already have 'efitool setvar' and 'efitool dumpvar'.
Best regards
Heinrich
Quoted 3 lines
Signed-off-by AKASHI Takahiro <[email protected]>---
PATCH v4 9/9 cmd: env: add "-e" option for handling UEFI variables
Quoted 5 lines · Heinrich Schuchardt
Quoted 2 lines · AKASHI Takahiro
"env [print|set] -e" allows for handling uefi variables without knowing details about mapping to corresponding u-boot variables.
Why do we need two alternative ways to achieve the same result? We already have 'efitool setvar' and 'efitool dumpvar'.
I asked for it.
If it was me, I would just drop the "efitool" versions. The more we can have in common code / CLI, the better for everyone.
But if Takahiro is passionate about having everything accessible through a single efi helper command for his debugging, I wouldn't oppose to it :).
Alex
PATCH v4 9/9 cmd: env: add "-e" option for handling UEFI variables
In reply to AKASHI TakahiroQuoted 22 lines · AKASHI Takahiro
"env [print|set] -e" allows for handling uefi variables without knowing details about mapping to corresponding u-boot variables.
Signed-off-by AKASHI Takahiro <[email protected]>--- cmd/nvedit.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-)cmd/nvedit.c +2
-0@@ -27,6 +27,8 @@#include <cli.h> #include <command.h> #include <console.h> +#include <efi.h> +#include <efi_loader.h> #include <environment.h> #include <search.h> #include <errno.h>
cmd/nvedit.c static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc, · line 124
Quoted 4 lines
cmd/nvedit.c +1
-0@@ -119,6 +121,25 @@ static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,int rcode =0 ;int env_flag =H_HIDE_DOT ; +#if defined(CONFIG_CMD_EFITOOL )
This needs to be available without your EFITOOL (which really is a DEBUG command). So this needs to be accessible using only CONFIG_EFI_LOADER I think. Maybe we can add a CONFIG_CMD_EFI_SUBCMD or so that these bits are guarded by if you think that someone really wants to live without.
Alex
v4 cover cmd: add efitool for efi environment
In reply to AKASHI TakahiroQuoted 7 lines
Am 15.01.2019 um 03:55 schrieb AKASHI Takahiro <[email protected]>:
This patch set is a collection of patches to enhance efi user interfaces /commands. It will help improve user experience on efi boot and make it more usable *without* edk2's shell utility.
Thanks a lot again. This is invaluable for efi_loader debugging. I found myself so many times adding printfs to enumarate bits this command would have just told me.
Quoted 3 lines
Let's see how it works:
=> efitool boot add 1 SHELL mmc 0:1 /Shell.efi ""
efidebug please :). I thought we agreed that this is an optional command, people can not expect to have around with no command line syntax guarantees? The name must reflect that. Efitool does not.
Alex