]> git.ipfire.org Git - thirdparty/u-boot.git/blame - cmd/unzip.c
Merge tag 'video-for-2019.07-rc1' of git://git.denx.de/u-boot-video
[thirdparty/u-boot.git] / cmd / unzip.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
c3d2a17c
MF
2/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
c3d2a17c
MF
5 */
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;
c3d2a17c
MF
14
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:
4c12eeb8 24 return CMD_RET_USAGE;
c3d2a17c
MF
25 }
26
27 if (gunzip((void *) dst, dst_len, (void *) src, &src_len) != 0)
28 return 1;
29
9ae2ddc8 30 printf("Uncompressed size: %lu = 0x%lX\n", src_len, src_len);
018f5303 31 env_set_hex("filesize", src_len);
c3d2a17c
MF
32
33 return 0;
34}
35
36U_BOOT_CMD(
37 unzip, 4, 1, do_unzip,
38 "unzip a memory region",
39 "srcaddr dstaddr [dstsize]"
40);
5d27223e
EN
41
42static int do_gzwrite(cmd_tbl_t *cmdtp, int flag,
43 int argc, char * const argv[])
44{
4101f687 45 struct blk_desc *bdev;
5d27223e
EN
46 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;
ebac37cf 55 ret = blk_get_device_by_str(argv[1], argv[2], &bdev);
5d27223e
EN
56 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);