blob: f7aabf72d1e73ae64c5255adf8299bac3aeb45da [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mike Frysingerc3d2a172011-04-02 21:40:19 -04002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Mike Frysingerc3d2a172011-04-02 21:40:19 -04005 */
6
7#include <common.h>
8#include <command.h>
9
10static int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
11{
12 unsigned long src, dst;
13 unsigned long src_len = ~0UL, dst_len = ~0UL;
Mike Frysingerc3d2a172011-04-02 21:40:19 -040014
15 switch (argc) {
16 case 4:
17 dst_len = simple_strtoul(argv[3], NULL, 16);
18 /* fall through */
19 case 3:
20 src = simple_strtoul(argv[1], NULL, 16);
21 dst = simple_strtoul(argv[2], NULL, 16);
22 break;
23 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +000024 return CMD_RET_USAGE;
Mike Frysingerc3d2a172011-04-02 21:40:19 -040025 }
26
27 if (gunzip((void *) dst, dst_len, (void *) src, &src_len) != 0)
28 return 1;
29
30 printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
Simon Glass018f5302017-08-03 12:22:10 -060031 env_set_hex("filesize", src_len);
Mike Frysingerc3d2a172011-04-02 21:40:19 -040032
33 return 0;
34}
35
36U_BOOT_CMD(
37 unzip, 4, 1, do_unzip,
38 "unzip a memory region",
39 "srcaddr dstaddr [dstsize]"
40);
Eric Nelson5d272232015-02-15 16:16:07 -070041
42static int do_gzwrite(cmd_tbl_t *cmdtp, int flag,
43 int argc, char * const argv[])
44{
Simon Glass4101f682016-02-29 15:25:34 -070045 struct blk_desc *bdev;
Eric Nelson5d272232015-02-15 16:16:07 -070046 int ret;
47 unsigned char *addr;
48 unsigned long length;
49 unsigned long writebuf = 1<<20;
50 u64 startoffs = 0;
51 u64 szexpected = 0;
52
53 if (argc < 5)
54 return CMD_RET_USAGE;
Simon Glassebac37c2016-02-29 15:25:43 -070055 ret = blk_get_device_by_str(argv[1], argv[2], &bdev);
Eric Nelson5d272232015-02-15 16:16:07 -070056 if (ret < 0)
57 return CMD_RET_FAILURE;
58
59 addr = (unsigned char *)simple_strtoul(argv[3], NULL, 16);
60 length = simple_strtoul(argv[4], NULL, 16);
61
62 if (5 < argc) {
63 writebuf = simple_strtoul(argv[5], NULL, 16);
64 if (6 < argc) {
65 startoffs = simple_strtoull(argv[6], NULL, 16);
66 if (7 < argc)
67 szexpected = simple_strtoull(argv[7],
68 NULL, 16);
69 }
70 }
71
72 ret = gzwrite(addr, length, bdev, writebuf, startoffs, szexpected);
73
74 return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
75}
76
77U_BOOT_CMD(
78 gzwrite, 8, 0, do_gzwrite,
79 "unzip and write memory to block device",
80 "<interface> <dev> <addr> length [wbuf=1M [offs=0 [outsize=0]]]\n"
81 "\twbuf is the size in bytes (hex) of write buffer\n"
82 "\t\tand should be padded to erase size for SSDs\n"
83 "\toffs is the output start offset in bytes (hex)\n"
84 "\toutsize is the size of the expected output (hex bytes)\n"
85 "\t\tand is required for files with uncompressed lengths\n"
86 "\t\t4 GiB or larger\n"
87);