Message ID | 20190115025522.12060-6-takahiro.akashi@linaro.org |
---|---|
State | New |
Headers | show |
Series | cmd: add efitool for efi environment | expand |
On 1/15/19 3:55 AM, AKASHI Takahiro wrote: > "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 > > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> > --- > cmd/efitool.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 102 insertions(+), 1 deletion(-) > > diff --git a/cmd/efitool.c b/cmd/efitool.c > index 4d46721fbf91..4bd6367b4bd9 100644 > --- a/cmd/efitool.c > +++ b/cmd/efitool.c > @@ -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 *. > + 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, > + }, 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 \ > + { > + NULL, > + {{0,},}, > + } You could use the ARRAY_SIZE() macro instead of the NULL entry. > +}; > + > +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; Please, put this logic into a separate function returning const char *. Return NULL if not found. > + > + 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[]) > { Please, use the standard way of adding sub-commands. See doc/README.commands. Best regards Heinrich > 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( >
On Tue, Jan 15, 2019 at 05:55:26AM +0100, Heinrich Schuchardt wrote: > On 1/15/19 3:55 AM, AKASHI Takahiro wrote: > > "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 > > > > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> > > --- > > cmd/efitool.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++- > > 1 file changed, 102 insertions(+), 1 deletion(-) > > > > diff --git a/cmd/efitool.c b/cmd/efitool.c > > index 4d46721fbf91..4bd6367b4bd9 100644 > > --- a/cmd/efitool.c > > +++ b/cmd/efitool.c > > @@ -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 *. OK > > + 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, > > + }, > > We implement a few more protocols, e.g. > > include/efi_api.h:467:#define BLOCK_IO_GUID \ > include/efi_api.h:977:#define EFI_DRIVER_BINDING_PROTOCOL_GUID \ > include/efi_api.h:999:#define EFI_UNICODE_COLLATION_PROTOCOL2_GUID \ They are already in there. > include/efi_api.h:283:#define LOADED_IMAGE_PROTOCOL_GUID \ > include/efi_api.h:700:#define EFI_GOP_GUID \ Added. > > + { > > + NULL, > > + {{0,},}, > > + } > You could use the ARRAY_SIZE() macro instead of the NULL entry. OK > > +}; > > + > > +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; > > Please, put this logic into a separate function returning const char *. > Return NULL if not found. OK > > + > > + 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[]) > > { > > Please, use the standard way of adding sub-commands. See > doc/README.commands. OK Thanks, -Takahiro Akashi > Best regards > > Heinrich > > > 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( > > >
diff --git a/cmd/efitool.c b/cmd/efitool.c index 4d46721fbf91..4bd6367b4bd9 100644 --- a/cmd/efitool.c +++ b/cmd/efitool.c @@ -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(
"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 Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> --- cmd/efitool.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-)