blob: 9b28328a1d76c72574045a1b3bbefa457995beff [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mike Frysingera2274902011-04-02 21:40:19 -04002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Mike Frysingera2274902011-04-02 21:40:19 -04005 */
6
7#include <common.h>
8#include <command.h>
Simon Glass313112a2019-08-01 09:46:46 -06009#include <env.h>
Simon Glass1a974af2019-08-01 09:46:36 -060010#include <gzip.h>
Simon Glass655306c2020-05-10 11:39:58 -060011#include <part.h>
Mike Frysingera2274902011-04-02 21:40:19 -040012
Simon Glassed38aef2020-05-10 11:40:03 -060013static int do_unzip(struct cmd_tbl *cmdtp, int flag, int argc,
14 char *const argv[])
Mike Frysingera2274902011-04-02 21:40:19 -040015{
16 unsigned long src, dst;
17 unsigned long src_len = ~0UL, dst_len = ~0UL;
Mike Frysingera2274902011-04-02 21:40:19 -040018
19 switch (argc) {
20 case 4:
21 dst_len = simple_strtoul(argv[3], NULL, 16);
22 /* fall through */
23 case 3:
24 src = simple_strtoul(argv[1], NULL, 16);
25 dst = simple_strtoul(argv[2], NULL, 16);
26 break;
27 default:
Simon Glassa06dfc72011-12-10 08:44:01 +000028 return CMD_RET_USAGE;
Mike Frysingera2274902011-04-02 21:40:19 -040029 }
30
31 if (gunzip((void *) dst, dst_len, (void *) src, &src_len) != 0)
32 return 1;
33
Heinrich Schuchardt16f29352019-01-06 12:34:16 +010034 printf("Uncompressed size: %lu = 0x%lX\n", src_len, src_len);
Simon Glass4d949a22017-08-03 12:22:10 -060035 env_set_hex("filesize", src_len);
Mike Frysingera2274902011-04-02 21:40:19 -040036
37 return 0;
38}
39
40U_BOOT_CMD(
41 unzip, 4, 1, do_unzip,
42 "unzip a memory region",
43 "srcaddr dstaddr [dstsize]"
44);
Eric Nelson20072f82015-02-15 16:16:07 -070045
Simon Glassed38aef2020-05-10 11:40:03 -060046static int do_gzwrite(struct cmd_tbl *cmdtp, int flag,
47 int argc, char *const argv[])
Eric Nelson20072f82015-02-15 16:16:07 -070048{
Simon Glasse3394752016-02-29 15:25:34 -070049 struct blk_desc *bdev;
Eric Nelson20072f82015-02-15 16:16:07 -070050 int ret;
51 unsigned char *addr;
52 unsigned long length;
53 unsigned long writebuf = 1<<20;
54 u64 startoffs = 0;
55 u64 szexpected = 0;
56
57 if (argc < 5)
58 return CMD_RET_USAGE;
Simon Glasse6649a62016-02-29 15:25:43 -070059 ret = blk_get_device_by_str(argv[1], argv[2], &bdev);
Eric Nelson20072f82015-02-15 16:16:07 -070060 if (ret < 0)
61 return CMD_RET_FAILURE;
62
63 addr = (unsigned char *)simple_strtoul(argv[3], NULL, 16);
64 length = simple_strtoul(argv[4], NULL, 16);
65
66 if (5 < argc) {
67 writebuf = simple_strtoul(argv[5], NULL, 16);
68 if (6 < argc) {
69 startoffs = simple_strtoull(argv[6], NULL, 16);
70 if (7 < argc)
71 szexpected = simple_strtoull(argv[7],
72 NULL, 16);
73 }
74 }
75
76 ret = gzwrite(addr, length, bdev, writebuf, startoffs, szexpected);
77
78 return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
79}
80
81U_BOOT_CMD(
82 gzwrite, 8, 0, do_gzwrite,
83 "unzip and write memory to block device",
84 "<interface> <dev> <addr> length [wbuf=1M [offs=0 [outsize=0]]]\n"
85 "\twbuf is the size in bytes (hex) of write buffer\n"
86 "\t\tand should be padded to erase size for SSDs\n"
87 "\toffs is the output start offset in bytes (hex)\n"
88 "\toutsize is the size of the expected output (hex bytes)\n"
89 "\t\tand is required for files with uncompressed lengths\n"
90 "\t\t4 GiB or larger\n"
91);