blob: 2d25542882291d3315b65204a1aa174ddd0a14e9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Lei Wene4e248d2012-09-28 04:26:47 +00002/*
3 * (C) Copyright 2012
4 * Lei Wen <leiwen@marvell.com>, Marvell Inc.
Lei Wene4e248d2012-09-28 04:26:47 +00005 */
6
Lei Wene4e248d2012-09-28 04:26:47 +00007#include <command.h>
Simon Glass313112a2019-08-01 09:46:46 -06008#include <env.h>
Michael Wallec11187a2020-05-22 14:07:37 +02009#include <gzip.h>
Tom Rini5c1444f2024-04-27 08:10:59 -060010#include <vsprintf.h>
Lei Wene4e248d2012-09-28 04:26:47 +000011
Simon Glassed38aef2020-05-10 11:40:03 -060012static int do_zip(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Lei Wene4e248d2012-09-28 04:26:47 +000013{
14 unsigned long src, dst;
15 unsigned long src_len, dst_len = ~0UL;
Lei Wene4e248d2012-09-28 04:26:47 +000016
17 switch (argc) {
18 case 5:
Simon Glass3ff49ec2021-07-24 09:03:29 -060019 dst_len = hextoul(argv[4], NULL);
Lei Wene4e248d2012-09-28 04:26:47 +000020 /* fall through */
21 case 4:
Simon Glass3ff49ec2021-07-24 09:03:29 -060022 src = hextoul(argv[1], NULL);
23 src_len = hextoul(argv[2], NULL);
24 dst = hextoul(argv[3], NULL);
Lei Wene4e248d2012-09-28 04:26:47 +000025 break;
26 default:
27 return cmd_usage(cmdtp);
28 }
29
30 if (gzip((void *) dst, &dst_len, (void *) src, src_len) != 0)
31 return 1;
32
Heinrich Schuchardt191cd602019-01-06 12:38:37 +010033 printf("Compressed size: %lu = 0x%lX\n", dst_len, dst_len);
Simon Glass4d949a22017-08-03 12:22:10 -060034 env_set_hex("filesize", dst_len);
Lei Wene4e248d2012-09-28 04:26:47 +000035
36 return 0;
37}
38
39U_BOOT_CMD(
40 zip, 5, 1, do_zip,
41 "zip a memory region",
42 "srcaddr srcsize dstaddr [dstsize]"
43);