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