public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v6 4/7] cmd: efidebug: add drivers command
Date: Wed, 20 Feb 2019 11:22:16 +0900	[thread overview]
Message-ID: <20190220022215.GG20286@linaro.org> (raw)
In-Reply-To: <9ba673e0-253a-618c-5c49-9219e1212bb2@gmx.de>

On Tue, Feb 19, 2019 at 08:49:30PM +0100, Heinrich Schuchardt wrote:
> On 1/24/19 12:04 PM, AKASHI Takahiro wrote:
> > "drivers" command prints all the uefi drivers on the system.
> > 
> > => efi drivers
> > Driver           Name                 Image Path
> > ================ ==================== ====================
> > 000000007ef003d0 <NULL>               <built-in>
> > 
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> > ---
> >  cmd/efidebug.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 79 insertions(+), 1 deletion(-)
> > 
> > diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> > index 8a7f775b117a..1b788c76a895 100644
> > --- a/cmd/efidebug.c
> > +++ b/cmd/efidebug.c
> > @@ -111,6 +111,80 @@ static int do_efi_show_devices(cmd_tbl_t *cmdtp, int flag,
> >  	return CMD_RET_SUCCESS;
> >  }
> >  
> > +static int efi_get_driver_handle_info(efi_handle_t handle, u16 **driver_name,
> > +				      u16 **image_path)
> > +{
> > +	struct efi_handler *handler;
> > +	struct efi_loaded_image *image;
> > +	efi_status_t ret;
> > +
> > +	/*
> > +	 * driver name
> > +	 * TODO: support EFI_COMPONENT_NAME2_PROTOCOL
> > +	 */
> > +	*driver_name = NULL;
> > +
> > +	/* image name */
> > +	ret = efi_search_protocol(handle, &efi_guid_loaded_image, &handler);
> > +	if (ret != EFI_SUCCESS) {
> > +		*image_path = NULL;
> > +		return 0;
> > +	}
> > +
> > +	image = handler->protocol_interface;
> > +	*image_path = efi_dp_str(image->file_path);
> > +
> > +	return 0;
> > +}
> > +
> > +static int do_efi_show_drivers(cmd_tbl_t *cmdtp, int flag,
> > +			       int argc, char * const argv[])
> > +{
> > +	efi_handle_t *handles = NULL, *handle;
> > +	efi_uintn_t size = 0;
> > +	u16 *driver_name, *image_path_text;
> > +	efi_status_t ret;
> > +	int i;
> > +
> 
> You are duplicating the logic of LocateHandleBuffer(). Why?

Will fix.

> > +	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("Driver%.*s Name                 Image Path\n",
> > +	       EFI_HANDLE_WIDTH - 6, spc);
> > +	printf("%.*s ==================== ====================\n",
> > +	       EFI_HANDLE_WIDTH, sep);
> > +	handle = handles;
> > +	for (i = 0; i < size / sizeof(*handle); i++) {
> > +		if (!efi_get_driver_handle_info(*handle, &driver_name,
> > +						&image_path_text)) {
> > +			if (image_path_text)
> > +				printf("%p %-20ls %ls\n",
> > +				       *handle, driver_name, image_path_text);
> > +			else
> > +				printf("%p %-20ls <built-in>\n",
> > +				       *handle, driver_name);
> > +			efi_free_pool(driver_name);
> > +			efi_free_pool(image_path_text);
> > +		}
> > +		handle++;
> > +	}
> > +
> 
> You are leaking 'handles' here.

Will fix.

Thanks,
-Takahiro Akashi

> Best regards
> 
> Heinrich
> 
> > +	return CMD_RET_SUCCESS;
> > +}
> > +
> >  static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag,
> >  			   int argc, char * const argv[])
> >  {
> > @@ -504,6 +578,8 @@ static cmd_tbl_t cmd_efidebug_sub[] = {
> >  	U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""),
> >  	U_BOOT_CMD_MKENT(devices, CONFIG_SYS_MAXARGS, 1, do_efi_show_devices,
> >  			 "", ""),
> > +	U_BOOT_CMD_MKENT(drivers, CONFIG_SYS_MAXARGS, 1, do_efi_show_drivers,
> > +			 "", ""),
> >  };
> >  
> >  /* Interpreter command to configure UEFI environment */
> > @@ -551,7 +627,9 @@ static char efidebug_help_text[] =
> >  	"  - set/show UEFI boot order\n"
> >  	"\n"
> >  	"efidebug devices\n"
> > -	"  - show uefi devices\n";
> > +	"  - show uefi devices\n"
> > +	"efidebug drivers\n"
> > +	"  - show uefi drivers\n";
> >  #endif
> >  
> >  U_BOOT_CMD(
> > 
> 

  reply	other threads:[~2019-02-20  2:22 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-24 11:04 [U-Boot] [PATCH v6 0/7] cmd: add efidebug for efi environment AKASHI Takahiro
2019-01-24 11:04 ` [U-Boot] [PATCH v6 1/7] cmd: env: add "-e" option for handling UEFI variables AKASHI Takahiro
2019-01-25 12:42   ` Alexander Graf
2019-01-29  3:22     ` AKASHI Takahiro
2019-01-24 11:04 ` [U-Boot] [PATCH v6 2/7] cmd: add efidebug command AKASHI Takahiro
2019-02-19 19:32   ` Heinrich Schuchardt
2019-02-20  4:58     ` AKASHI Takahiro
2019-02-20  6:40       ` Heinrich Schuchardt
2019-01-24 11:04 ` [U-Boot] [PATCH v6 3/7] cmd: efidebug: add devices command AKASHI Takahiro
2019-02-19 19:46   ` Heinrich Schuchardt
2019-02-19 19:53     ` Heinrich Schuchardt
2019-02-20  2:20     ` AKASHI Takahiro
2019-02-20  6:49       ` Heinrich Schuchardt
2019-02-20  7:42         ` AKASHI Takahiro
2019-01-24 11:04 ` [U-Boot] [PATCH v6 4/7] cmd: efidebug: add drivers command AKASHI Takahiro
2019-02-19 19:49   ` Heinrich Schuchardt
2019-02-20  2:22     ` AKASHI Takahiro [this message]
2019-01-24 11:04 ` [U-Boot] [PATCH v6 5/7] cmd: efidebug: add dh command AKASHI Takahiro
2019-01-24 11:04 ` [U-Boot] [PATCH v6 6/7] cmd: efidebug: add images command AKASHI Takahiro
2019-01-29 15:35   ` Alexander Graf
2019-01-30  0:00     ` AKASHI Takahiro
2019-02-19 19:51   ` Heinrich Schuchardt
2019-01-24 11:04 ` [U-Boot] [PATCH v6 7/7] cmd: efidebug: add memmap command AKASHI Takahiro
2019-02-19 19:11   ` Heinrich Schuchardt
2019-02-20  0:53     ` AKASHI Takahiro
2019-02-20  6:53       ` Heinrich Schuchardt
2019-02-20  7:45         ` AKASHI Takahiro
2019-01-25 11:56 ` [U-Boot] [PATCH v6 0/7] cmd: add efidebug for efi environment Alexander Graf
2019-01-29  3:07   ` AKASHI Takahiro

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20190220022215.GG20286@linaro.org \
    --to=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

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

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