mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Lucas Stach <l.stach@pengutronix.de>, barebox@lists.infradead.org
Subject: Re: [PATCH v2 2/2] bootm: add support for booting compressed images
Date: Fri, 28 May 2021 09:06:15 +0200	[thread overview]
Message-ID: <82f7ab09-4164-3ab2-4f94-455d084952d5@pengutronix.de> (raw)
In-Reply-To: <20210526090216.4003977-2-l.stach@pengutronix.de>

On 26.05.21 11:02, Lucas Stach wrote:
> ARM64 does not have a self extracting image format, but relies on the image
> being externally compressed with one of the standard compression algorithms.
> 
> Add support for decompressing the bootm OS image. It is added in common
> code as it may also be useful for other images/architectures.
> 
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>

FWIW: Tested-by: Ahmad Fatoum <a.fatoum@pengutronix.de> # RISC-V 64-bit

> ---
> v2: Add proper error handling if nested bootm fails.
> ---
>  common/bootm.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 93 insertions(+)
> 
> diff --git a/common/bootm.c b/common/bootm.c
> index 092116beb94a..f5c0e5184b0a 100644
> --- a/common/bootm.c
> +++ b/common/bootm.c
> @@ -12,6 +12,7 @@
>  #include <environment.h>
>  #include <linux/stat.h>
>  #include <magicvar.h>
> +#include <uncompress.h>
>  
>  static LIST_HEAD(handler_list);
>  
> @@ -808,6 +809,86 @@ err_out:
>  	return ret;
>  }
>  
> +static int do_bootm_compressed(struct image_data *img_data)
> +{
> +	struct bootm_data bootm_data = {
> +		.oftree_file = img_data->oftree_file,
> +		.initrd_file = img_data->initrd_file,
> +		.tee_file = img_data->tee_file,
> +		.verbose = img_data->verbose,
> +		.verify = img_data->verify,
> +		.force = img_data->force,
> +		.dryrun = img_data->dryrun,
> +		.initrd_address = img_data->initrd_address,
> +		.os_address = img_data->os_address,
> +		.os_entry = img_data->os_entry,
> +	};
> +	int from, to, ret;
> +	char *dstpath;
> +
> +	from = open(img_data->os_file, O_RDONLY);
> +	if (from < 0)
> +		return -ENODEV;
> +
> +	dstpath = make_temp("bootm-compressed");
> +	if (!dstpath) {
> +		ret = -ENOMEM;
> +		goto fail_from;
> +	}
> +
> +	to = open(dstpath, O_CREAT | O_WRONLY);
> +	if (to < 0) {
> +		ret = -ENODEV;
> +		goto fail_make_temp;
> +	}
> +
> +	ret = uncompress_fd_to_fd(from, to, uncompress_err_stdout);
> +	if (ret)
> +		goto fail_to;
> +
> +	bootm_data.os_file = dstpath;
> +	ret = bootm_boot(&bootm_data);
> +
> +fail_to:
> +	close(to);
> +	unlink(dstpath);
> +fail_make_temp:
> +	free(dstpath);
> +fail_from:
> +	close(from);
> +	return ret;
> +}
> +
> +static struct image_handler bzip2_bootm_handler = {
> +	.name = "BZIP2 compressed file",
> +	.bootm = do_bootm_compressed,
> +	.filetype = filetype_bzip2,
> +};
> +
> +static struct image_handler gzip_bootm_handler = {
> +	.name = "GZIP compressed file",
> +	.bootm = do_bootm_compressed,
> +	.filetype = filetype_gzip,
> +};
> +
> +static struct image_handler lzo_bootm_handler = {
> +	.name = "LZO compressed file",
> +	.bootm = do_bootm_compressed,
> +	.filetype = filetype_lzo_compressed,
> +};
> +
> +static struct image_handler lz4_bootm_handler = {
> +	.name = "LZ4 compressed file",
> +	.bootm = do_bootm_compressed,
> +	.filetype = filetype_lz4_compressed,
> +};
> +
> +static struct image_handler xz_bootm_handler = {
> +	.name = "XZ compressed file",
> +	.bootm = do_bootm_compressed,
> +	.filetype = filetype_xz_compressed,
> +};
> +
>  static int bootm_init(void)
>  {
>  	globalvar_add_simple("bootm.image", NULL);
> @@ -830,6 +911,18 @@ static int bootm_init(void)
>  	globalvar_add_simple_enum("bootm.verify", (unsigned int *)&bootm_verify_mode,
>  				  bootm_verify_names, ARRAY_SIZE(bootm_verify_names));
>  
> +
> +	if (IS_ENABLED(CONFIG_BZLIB))
> +		register_image_handler(&bzip2_bootm_handler);
> +	if (IS_ENABLED(CONFIG_ZLIB))
> +		register_image_handler(&gzip_bootm_handler);
> +	if (IS_ENABLED(CONFIG_LZO_DECOMPRESS))
> +		register_image_handler(&lzo_bootm_handler);
> +	if (IS_ENABLED(CONFIG_LZ4_DECOMPRESS))
> +		register_image_handler(&lz4_bootm_handler);
> +	if (IS_ENABLED(CONFIG_XZ_DECOMPRESS))
> +		register_image_handler(&xz_bootm_handler);
> +
>  	return 0;
>  }
>  late_initcall(bootm_init);
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2021-05-28  7:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-26  9:02 [PATCH v2 1/2] uncompress: use read_full to fill decompression buffer Lucas Stach
2021-05-26  9:02 ` [PATCH v2 2/2] bootm: add support for booting compressed images Lucas Stach
2021-05-28  7:06   ` Ahmad Fatoum [this message]
2021-05-27  6:50 ` [PATCH v2 1/2] uncompress: use read_full to fill decompression buffer Sascha Hauer

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=82f7ab09-4164-3ab2-4f94-455d084952d5@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=l.stach@pengutronix.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