]> git.ipfire.org Git - people/ms/u-boot.git/blame - cmd/unzip.c
omap3_logic: Fix Environmental location
[people/ms/u-boot.git] / cmd / unzip.c
CommitLineData
c3d2a17c
MF
1/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
c3d2a17c
MF
6 */
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;
c3d2a17c
MF
15
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:
4c12eeb8 25 return CMD_RET_USAGE;
c3d2a17c
MF
26 }
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);
018f5303 32 env_set_hex("filesize", src_len);
c3d2a17c
MF
33
34 return 0;
35}
36
37U_BOOT_CMD(
38 unzip, 4, 1, do_unzip,
39 "unzip a memory region",
40 "srcaddr dstaddr [dstsize]"
41);
5d27223e
EN
42
43static int do_gzwrite(cmd_tbl_t *cmdtp, int flag,
44 int argc, char * const argv[])
45{
4101f687 46 struct blk_desc *bdev;
5d27223e
EN
47 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;
ebac37cf 56 ret = blk_get_device_by_str(argv[1], argv[2], &bdev);
5d27223e
EN
57 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);