blob: bc6cee060432fc6040ba51d51f55ca3879360de7 [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>
Simon Glassc7694dd2019-08-01 09:46:46 -06009#include <env.h>
Simon Glass0c670fc2019-08-01 09:46:36 -060010#include <gzip.h>
Simon Glass6cdc8be2021-11-19 13:23:52 -070011#include <mapmem.h>
Simon Glasse6f6f9e2020-05-10 11:39:58 -060012#include <part.h>
Mike Frysingerc3d2a172011-04-02 21:40:19 -040013
Simon Glass09140112020-05-10 11:40:03 -060014static int do_unzip(struct cmd_tbl *cmdtp, int flag, int argc,
15 char *const argv[])
Mike Frysingerc3d2a172011-04-02 21:40:19 -040016{
17 unsigned long src, dst;
18 unsigned long src_len = ~0UL, dst_len = ~0UL;
Mike Frysingerc3d2a172011-04-02 21:40:19 -040019
20 switch (argc) {
21 case 4:
Simon Glass7e5f4602021-07-24 09:03:29 -060022 dst_len = hextoul(argv[3], NULL);
Mike Frysingerc3d2a172011-04-02 21:40:19 -040023 /* fall through */
24 case 3:
Simon Glass7e5f4602021-07-24 09:03:29 -060025 src = hextoul(argv[1], NULL);
26 dst = hextoul(argv[2], NULL);
Mike Frysingerc3d2a172011-04-02 21:40:19 -040027 break;
28 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +000029 return CMD_RET_USAGE;
Mike Frysingerc3d2a172011-04-02 21:40:19 -040030 }
31
Simon Glass6cdc8be2021-11-19 13:23:52 -070032 if (gunzip(map_sysmem(dst, dst_len), dst_len, map_sysmem(src, 0),
33 &src_len) != 0)
Mike Frysingerc3d2a172011-04-02 21:40:19 -040034 return 1;
35
Heinrich Schuchardt9ae2ddc2019-01-06 12:34:16 +010036 printf("Uncompressed size: %lu = 0x%lX\n", src_len, src_len);
Simon Glass018f5302017-08-03 12:22:10 -060037 env_set_hex("filesize", src_len);
Mike Frysingerc3d2a172011-04-02 21:40:19 -040038
39 return 0;
40}
41
42U_BOOT_CMD(
43 unzip, 4, 1, do_unzip,
44 "unzip a memory region",
45 "srcaddr dstaddr [dstsize]"
46);
Eric Nelson5d272232015-02-15 16:16:07 -070047
Simon Glass09140112020-05-10 11:40:03 -060048static int do_gzwrite(struct cmd_tbl *cmdtp, int flag,
49 int argc, char *const argv[])
Eric Nelson5d272232015-02-15 16:16:07 -070050{
Simon Glass4101f682016-02-29 15:25:34 -070051 struct blk_desc *bdev;
Eric Nelson5d272232015-02-15 16:16:07 -070052 int ret;
53 unsigned char *addr;
54 unsigned long length;
55 unsigned long writebuf = 1<<20;
56 u64 startoffs = 0;
57 u64 szexpected = 0;
58
59 if (argc < 5)
60 return CMD_RET_USAGE;
Simon Glassebac37c2016-02-29 15:25:43 -070061 ret = blk_get_device_by_str(argv[1], argv[2], &bdev);
Eric Nelson5d272232015-02-15 16:16:07 -070062 if (ret < 0)
63 return CMD_RET_FAILURE;
64
Simon Glass7e5f4602021-07-24 09:03:29 -060065 addr = (unsigned char *)hextoul(argv[3], NULL);
66 length = hextoul(argv[4], NULL);
Eric Nelson5d272232015-02-15 16:16:07 -070067
68 if (5 < argc) {
Simon Glass7e5f4602021-07-24 09:03:29 -060069 writebuf = hextoul(argv[5], NULL);
Eric Nelson5d272232015-02-15 16:16:07 -070070 if (6 < argc) {
71 startoffs = simple_strtoull(argv[6], NULL, 16);
72 if (7 < argc)
73 szexpected = simple_strtoull(argv[7],
74 NULL, 16);
75 }
76 }
77
78 ret = gzwrite(addr, length, bdev, writebuf, startoffs, szexpected);
79
80 return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
81}
82
83U_BOOT_CMD(
84 gzwrite, 8, 0, do_gzwrite,
85 "unzip and write memory to block device",
86 "<interface> <dev> <addr> length [wbuf=1M [offs=0 [outsize=0]]]\n"
87 "\twbuf is the size in bytes (hex) of write buffer\n"
88 "\t\tand should be padded to erase size for SSDs\n"
89 "\toffs is the output start offset in bytes (hex)\n"
90 "\toutsize is the size of the expected output (hex bytes)\n"
91 "\t\tand is required for files with uncompressed lengths\n"
92 "\t\t4 GiB or larger\n"
93);