public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: Rasmus Villemoes <rasmus.villemoes@prevas.dk>, u-boot@lists.denx.de
Cc: Simon Glass <sjg@chromium.org>,
	Alper Nebi Yasak <alpernebiyasak@gmail.com>,
	Kever Yang <kever.yang@rock-chips.com>
Subject: Re: [PATCH 1/4] mkimage: also honour -B even without external data
Date: Wed, 27 Sep 2023 15:02:15 -0400	[thread overview]
Message-ID: <6ac71b7e-d84e-10d5-e500-0d54e5d6c191@gmail.com> (raw)
In-Reply-To: <20230919113705.109639-2-rasmus.villemoes@prevas.dk>

On 9/19/23 07:37, Rasmus Villemoes wrote:
> In some cases, using the "external data" feature is impossible or
> undesirable, but one may still want (or need) the FIT image to have a
> certain alignment. Also, given the current 'mkimage -h' output,
> 
>    -B => align size in hex for FIT structure and header
> 
> it is quite unexpected for -B to be effectively ignored without -E.

FWIW, this behavior is documented in doc/mkimage.1 (which should also be
updated if this behavior is implemented):

| The alignment, in hexadecimal, that external data will be aligned to.
| This option only has an effect when -E is specified.

And, for additional context, the documentation for -E is

| After processing, move the image data outside the FIT and store a data
| offset in the FIT. Images will be placed one after the other
| immediately after the FIT, with each one aligned to a 4-byte boundary.
| The existing ‘data’ property in each image will be replaced with
| ‘data-offset’ and ‘data-size’ properties. A ‘data-offset’ of 0
| indicates that it starts in the first (4-byte-aligned) byte after the
| FIT.

Based on this documentation and my understanding of the code as-is, -B
controls the alignment of the images themselves, not the size multiple
of the FIT. However, from what I can tell, this patch does not actually
affect the alignment of the images, but rather adjusts the size of the
overall FIT to a certain alignment. I find this rather unexpected.

--Sean

> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
>   tools/fit_image.c | 40 ++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 40 insertions(+)
> 
> diff --git a/tools/fit_image.c b/tools/fit_image.c
> index 9fe69ea0d9..2f5b25098a 100644
> --- a/tools/fit_image.c
> +++ b/tools/fit_image.c
> @@ -712,6 +712,42 @@ err:
>   	return ret;
>   }
>   
> +/**
> + * fit_align() - Ensure FIT image has certain alignment
> + *
> + * This takes a normal FIT file (with embedded data) and increases its
> + * size so that it is a multiple of params->bl_len.
> + */
> +static int fit_align(struct image_tool_params *params, const char *fname)
> +{
> +	int fit_size, new_size;
> +	int fd;
> +	struct stat sbuf;
> +	void *fdt;
> +	int ret = 0;
> +	int align_size;
> +
> +	align_size = params->bl_len;
> +	fd = mmap_fdt(params->cmdname, fname, 0, &fdt, &sbuf, false, false);
> +	if (fd < 0)
> +		return -EIO;
> +
> +	fit_size = fdt_totalsize(fdt);
> +	new_size = ALIGN(fit_size, align_size);
> +	fdt_set_totalsize(fdt, new_size);
> +	debug("Size extended from from %x to %x\n", fit_size, new_size);
> +	munmap(fdt, sbuf.st_size);
> +
> +	if (ftruncate(fd, new_size)) {
> +		debug("%s: Failed to truncate file: %s\n", __func__,
> +		      strerror(errno));
> +		ret = -EIO;
> +	}
> +
> +	close(fd);
> +	return ret;
> +}
> +
>   /**
>    * fit_handle_file - main FIT file processing function
>    *
> @@ -817,6 +853,10 @@ static int fit_handle_file(struct image_tool_params *params)
>   		ret = fit_extract_data(params, tmpfile);
>   		if (ret)
>   			goto err_system;
> +	} else if (params->bl_len) {
> +		ret = fit_align(params, tmpfile);
> +		if (ret)
> +			goto err_system;
>   	}
>   
>   	if (rename (tmpfile, params->imagefile) == -1) {


  parent reply	other threads:[~2023-09-27 19:02 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-19 11:37 [PATCH 0/4] mkimage: also honour -B even without external data Rasmus Villemoes
2023-09-19 11:37 ` [PATCH 1/4] " Rasmus Villemoes
2023-09-21  1:02   ` Simon Glass
2023-09-21  7:57     ` Rasmus Villemoes
2023-09-22 15:26       ` Simon Glass
2023-09-25  8:47         ` Rasmus Villemoes
2023-09-25 13:10           ` Simon Glass
2023-09-25 13:25             ` Rasmus Villemoes
2023-09-27 19:02   ` Sean Anderson [this message]
2023-09-28  7:10     ` Rasmus Villemoes
2023-09-29 13:16       ` Sean Anderson
2023-11-04 19:43         ` Simon Glass
2023-11-06  8:15           ` Rasmus Villemoes
2023-09-19 11:37 ` [PATCH 2/4] binman: test: rename 275_fit_align.dts -> 275_fit_align_external.dts Rasmus Villemoes
2023-09-21  1:02   ` Simon Glass
2023-09-19 11:37 ` [PATCH 3/4] tools: binman: add test case for fit, align without fit, external-offset Rasmus Villemoes
2023-09-21  1:03   ` Simon Glass
2023-09-19 11:37 ` [PATCH 4/4] binman: update documentation for fit,align property Rasmus Villemoes
2023-09-21  1:03   ` Simon Glass
2023-09-25 15:14   ` Jonas Karlman
2023-09-26  6:25     ` Rasmus Villemoes
2023-09-27 14:19       ` Simon Glass
2023-09-28  8:02 ` [PATCH 5/4] mkimage: update man page and -h output Rasmus Villemoes
2023-10-02  1:17   ` Simon Glass
2023-10-11 18:37   ` Tom Rini
2023-10-11 19:07     ` Rasmus Villemoes
2023-10-11 19:33       ` Tom Rini
2023-10-12  2:40         ` Simon Glass
2023-10-12  2:17       ` Sean Anderson
2023-10-12 12:02         ` Tom Rini
2023-10-13 18:30         ` Rasmus Villemoes
2023-11-07  0:46           ` Sean Anderson
2023-11-07  7:30             ` Rasmus Villemoes
2023-11-07  7:33               ` Rasmus Villemoes

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=6ac71b7e-d84e-10d5-e500-0d54e5d6c191@gmail.com \
    --to=seanga2@gmail.com \
    --cc=alpernebiyasak@gmail.com \
    --cc=kever.yang@rock-chips.com \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=sjg@chromium.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