blob: b433f1889f913ee8ac371d7bb6b2357f7fabf08c [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
7#include <common.h>
8#include <command.h>
Simon Glass313112a2019-08-01 09:46:46 -06009#include <env.h>
Lei Wene4e248d2012-09-28 04:26:47 +000010
Simon Glassed38aef2020-05-10 11:40:03 -060011static int do_zip(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Lei Wene4e248d2012-09-28 04:26:47 +000012{
13 unsigned long src, dst;
14 unsigned long src_len, dst_len = ~0UL;
Lei Wene4e248d2012-09-28 04:26:47 +000015
16 switch (argc) {
17 case 5:
18 dst_len = simple_strtoul(argv[4], NULL, 16);
19 /* fall through */
20 case 4:
21 src = simple_strtoul(argv[1], NULL, 16);
22 src_len = simple_strtoul(argv[2], NULL, 16);
23 dst = simple_strtoul(argv[3], NULL, 16);
24 break;
25 default:
26 return cmd_usage(cmdtp);
27 }
28
29 if (gzip((void *) dst, &dst_len, (void *) src, src_len) != 0)
30 return 1;
31
Heinrich Schuchardt191cd602019-01-06 12:38:37 +010032 printf("Compressed size: %lu = 0x%lX\n", dst_len, dst_len);
Simon Glass4d949a22017-08-03 12:22:10 -060033 env_set_hex("filesize", dst_len);
Lei Wene4e248d2012-09-28 04:26:47 +000034
35 return 0;
36}
37
38U_BOOT_CMD(
39 zip, 5, 1, do_zip,
40 "zip a memory region",
41 "srcaddr srcsize dstaddr [dstsize]"
42);