U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Cc: Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,
	Shantur Rathore <i@shantur.com>, Bin Meng <bmeng@tinylab.org>,
	AKASHI Takahiro <akashi.tkhro@gmail.com>,
	Masahisa Kojima <kojima.masahisa@socionext.com>,
	Raymond Mao <raymond.mao@linaro.org>,
	Mark Kettenis <kettenis@openbsd.org>,
	Joao Marcos Costa <jmcosta944@gmail.com>,
	u-boot@lists.denx.de
Subject: Re: [RFC 05/14] cmd: efidebug: add support for setting fdt
Date: Wed, 22 May 2024 09:16:46 +0300	[thread overview]
Message-ID: <Zk2NzrpdiOL6IhMr@hera> (raw)
In-Reply-To: <20240426141321.232236-6-heinrich.schuchardt@canonical.com>

Hi Heinrich

On Fri, Apr 26, 2024 at 04:13:12PM +0200, Heinrich Schuchardt wrote:
> We already support creating a load option where the device-path
> field contains the concatenation of the binary device-path and
> optionally the device path of the initrd which we expose via the
> EFI_LOAD_FILE2_PROTOCOL.
>
> Allow to append another device-path pointing to the device-tree
> identified by the device-tree GUID.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  cmd/efidebug.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 63 insertions(+), 5 deletions(-)
>
> diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> index 93ba16efc7d..32c64711b6c 100644
> --- a/cmd/efidebug.c
> +++ b/cmd/efidebug.c
> @@ -660,16 +660,33 @@ static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag,
>   * @part:	disk partition
>   * @file:	filename
>   * @shortform:	create short form device path
> + * @fdt:	create path for device-tree
>   * Return:	pointer to the device path or ERR_PTR
>   */
>  static
>  struct efi_device_path *create_initrd_dp(const char *dev, const char *part,
> -					 const char *file, int shortform)
> +					 const char *file, bool shortform,
> +					 bool fdt)

Overall the patch looks correct. Can we pick a better name instead of
create_initrd_dp() & efi_initrd_dp? Do you have in mind any extra uses
cases apart from the initrd and dtb? If yes, then we could convert the i
'bool fdt' to an enum.

Since all these are encoded in the load option perhaps we can rename it to
create_lo_dp and efi_lo_dp?

>
>  {
>  	struct efi_device_path *tmp_dp = NULL, *tmp_fp = NULL, *short_fp = NULL;
>  	struct efi_device_path *initrd_dp = NULL;
>  	efi_status_t ret;
> +	const struct efi_initrd_dp fdt_dp = {
> +		.vendor = {
> +			{
> +			DEVICE_PATH_TYPE_MEDIA_DEVICE,
> +			DEVICE_PATH_SUB_TYPE_VENDOR_PATH,
> +			sizeof(fdt_dp.vendor),
> +			},
> +			EFI_FDT_GUID,
> +		},
> +		.end = {
> +			DEVICE_PATH_TYPE_END,
> +			DEVICE_PATH_SUB_TYPE_END,
> +			sizeof(fdt_dp.end),
> +		}
> +	};
>  	const struct efi_initrd_dp id_dp = {
>  		.vendor = {
>  			{
> @@ -696,7 +713,8 @@ struct efi_device_path *create_initrd_dp(const char *dev, const char *part,
>  	if (!short_fp)
>  		short_fp = tmp_fp;
>
> -	initrd_dp = efi_dp_concat((const struct efi_device_path *)&id_dp,
> +	initrd_dp = efi_dp_concat((const struct efi_device_path *)
> +				  (fdt ? &fdt_dp : &id_dp),
>  				  short_fp);
>
>  out:
> @@ -796,6 +814,7 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
>  	struct efi_device_path *fp_free = NULL;
>  	struct efi_device_path *final_fp = NULL;
>  	struct efi_device_path *initrd_dp = NULL;
> +	struct efi_device_path *fdt_dp = NULL;
>  	struct efi_load_option lo;
>  	void *data = NULL;
>  	efi_uintn_t size;
> @@ -860,6 +879,27 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
>  			argc -= 5;
>  			argv += 5;
>  			break;
> +		case 'd':
> +			shortform = 1;
> +			fallthrough;
> +		case 'D':
> +			if (argc < 3 || fdt_dp) {
> +				r = CMD_RET_USAGE;
> +				goto out;
> +			}
> +
> +			fdt_dp = create_initrd_dp(argv[1], argv[2], argv[3],
> +						  shortform, true);
> +			if (!fdt_dp) {
> +				printf("Cannot add a device-tree\n");
> +				r = CMD_RET_FAILURE;
> +				goto out;
> +			}
> +			argc -= 3;
> +			argv += 3;
> +			fp_size += efi_dp_size(fdt_dp) +
> +				sizeof(struct efi_device_path);
> +			break;
>  		case 'i':
>  			shortform = 1;
>  			/* fallthrough */
> @@ -870,7 +910,7 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
>  			}
>
>  			initrd_dp = create_initrd_dp(argv[1], argv[2], argv[3],
> -						     shortform);
> +						     shortform, false);
>  			if (!initrd_dp) {
>  				printf("Cannot add an initrd\n");
>  				r = CMD_RET_FAILURE;
> @@ -929,6 +969,15 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
>  		}
>  	}
>
> +	if (fdt_dp) {
> +		final_fp = efi_dp_merge(final_fp, &fp_size, fdt_dp);
> +		if (!final_fp) {
> +			printf("Cannot create final device path\n");
> +			r = CMD_RET_FAILURE;
> +			goto out;
> +		}
> +	}
> +
>  	lo.file_path = final_fp;
>  	lo.file_path_length = fp_size;
>
> @@ -952,6 +1001,7 @@ out:
>  	free(data);
>  	efi_free_pool(final_fp);
>  	efi_free_pool(initrd_dp);
> +	efi_free_pool(fdt_dp);
>  	efi_free_pool(fp_free);
>  	free(lo.label);
>
> @@ -1014,7 +1064,8 @@ static int do_efi_boot_rm(struct cmd_tbl *cmdtp, int flag,
>   */
>  static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
>  {
> -	struct efi_device_path *initrd_path = NULL;
> +	struct efi_device_path *fdt_path;
> +	struct efi_device_path *initrd_path;
>  	struct efi_load_option lo;
>  	efi_status_t ret;
>
> @@ -1043,6 +1094,12 @@ static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
>  		efi_free_pool(initrd_path);
>  	}
>
> +	fdt_path = efi_dp_from_lo(&lo, &efi_guid_fdt);
> +	if (fdt_path) {
> +		printf("  device-tree path: %pD\n", fdt_path);
> +		efi_free_pool(fdt_path);
> +	}
> +
>  	printf("  data:\n");
>  	print_hex_dump("    ", DUMP_PREFIX_OFFSET, 16, 1,
>  		       lo.optional_data, *size, true);
> @@ -1570,8 +1627,9 @@ U_BOOT_LONGHELP(efidebug,
>  	"\n"
>  	"efidebug boot add - set UEFI BootXXXX variable\n"
>  	"  -b|-B <bootid> <label> <interface> <devnum>[:<part>] <file path>\n"
> +	"  -d|-D <interface> <devnum>[:<part>] <device-tree file path>\n"
>  	"  -i|-I <interface> <devnum>[:<part>] <initrd file path>\n"
> -	"  (-b, -i for short form device path)\n"
> +	"  (-b, -d, -i for short form device path)\n"
>  #if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT))
>  	"  -u <bootid> <label> <uri>\n"
>  #endif
> --
> 2.43.0
>

Regards
/Ilias

  reply	other threads:[~2024-05-22  6:16 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-26 14:13 [RFC 00/14] efi_loader: improve device-tree loading Heinrich Schuchardt
2024-04-26 14:13 ` [RFC 01/14] efi_loader: pass GUID by address to efi_dp_from_lo Heinrich Schuchardt
2024-04-26 23:50   ` Ilias Apalodimas
2024-04-26 14:13 ` [RFC 02/14] efi_loader: library function efi_dp_merge Heinrich Schuchardt
2024-04-26 14:30   ` Ilias Apalodimas
2024-04-26 14:52     ` Heinrich Schuchardt
2024-04-26 15:47       ` Ilias Apalodimas
2024-05-14 12:49         ` Heinrich Schuchardt
2024-05-14 12:58           ` Mark Kettenis
2024-05-14 13:08             ` Heinrich Schuchardt
2024-05-22  5:57           ` Ilias Apalodimas
2024-04-26 14:13 ` [RFC 03/14] efi_loader: simplify efi_dp_concat() Heinrich Schuchardt
2024-04-28 13:29   ` Ilias Apalodimas
2024-04-26 14:13 ` [RFC 04/14] cmd: eficonfig: add support for setting fdt Heinrich Schuchardt
2024-04-27 17:21   ` E Shattow
2024-04-27 21:25     ` Heinrich Schuchardt
2024-04-28  4:13       ` E Shattow
2024-04-26 14:13 ` [RFC 05/14] cmd: efidebug: " Heinrich Schuchardt
2024-05-22  6:16   ` Ilias Apalodimas [this message]
2024-04-26 14:13 ` [RFC 06/14] efi_loader: superfluous efi_restore_gd after EFI_CALL Heinrich Schuchardt
2024-04-26 14:13 ` [RFC 07/14] cmd: terminate efidebug test bootmgr early on error Heinrich Schuchardt
2024-04-26 14:13 ` [RFC 08/14] efi_loader: improve error handling in try_load_entry() Heinrich Schuchardt
2024-04-26 14:13 ` [RFC 09/14] efi_loader: do not install dtb if bootmgr fails Heinrich Schuchardt
2024-05-22  6:17   ` Ilias Apalodimas
2024-05-22  6:27     ` Ilias Apalodimas
2024-04-26 14:13 ` [RFC 10/14] efi_loader: load device-tree specified in boot option Heinrich Schuchardt
2024-05-22  6:28   ` Ilias Apalodimas
2024-04-26 14:13 ` [RFC 11/14] efi_loader: move distro_efi_get_fdt_name() Heinrich Schuchardt
2024-04-26 14:52   ` Caleb Connolly
2024-04-26 15:18     ` Heinrich Schuchardt
2024-04-26 14:13 ` [RFC 12/14] efi_loader: return binary from efi_dp_from_lo() Heinrich Schuchardt
2024-04-28 13:28   ` Ilias Apalodimas
2024-05-14 12:57     ` Heinrich Schuchardt
2024-04-26 14:13 ` [RFC 13/14] efi_loader: export efi_load_image_from_path Heinrich Schuchardt
2024-04-28 13:32   ` Ilias Apalodimas
2024-04-26 14:13 ` [RFC 14/14] efi_loader: load distro dtb in bootmgr Heinrich Schuchardt

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=Zk2NzrpdiOL6IhMr@hera \
    --to=ilias.apalodimas@linaro.org \
    --cc=akashi.tkhro@gmail.com \
    --cc=bmeng@tinylab.org \
    --cc=heinrich.schuchardt@canonical.com \
    --cc=i@shantur.com \
    --cc=jmcosta944@gmail.com \
    --cc=kettenis@openbsd.org \
    --cc=kojima.masahisa@socionext.com \
    --cc=raymond.mao@linaro.org \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --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