env: Allow U-Boot scripts to be placed in a .env file
[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>
c7694dd4 9#include <env.h>
0c670fc1 10#include <gzip.h>
e6f6f9e6 11#include <part.h>
c3d2a17c 12
09140113
SG
13static int do_unzip(struct cmd_tbl *cmdtp, int flag, int argc,
14 char *const argv[])
c3d2a17c
MF
15{
16 unsigned long src, dst;
17 unsigned long src_len = ~0UL, dst_len = ~0UL;
c3d2a17c
MF
18
19 switch (argc) {
20 case 4:
7e5f460e 21 dst_len = hextoul(argv[3], NULL);
c3d2a17c
MF
22 /* fall through */
23 case 3:
7e5f460e
SG
24 src = hextoul(argv[1], NULL);
25 dst = hextoul(argv[2], NULL);
c3d2a17c
MF
26 break;
27 default:
4c12eeb8 28 return CMD_RET_USAGE;
c3d2a17c
MF
29 }
30
31 if (gunzip((void *) dst, dst_len, (void *) src, &src_len) != 0)
32 return 1;
33
9ae2ddc8 34 printf("Uncompressed size: %lu = 0x%lX\n", src_len, src_len);
018f5303 35 env_set_hex("filesize", src_len);
c3d2a17c
MF
36
37 return 0;
38}
39
40U_BOOT_CMD(
41 unzip, 4, 1, do_unzip,
42 "unzip a memory region",
43 "srcaddr dstaddr [dstsize]"
44);
5d27223e 45
09140113
SG
46static int do_gzwrite(struct cmd_tbl *cmdtp, int flag,
47 int argc, char *const argv[])
5d27223e 48{
4101f687 49 struct blk_desc *bdev;
5d27223e
EN
50 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;
ebac37cf 59 ret = blk_get_device_by_str(argv[1], argv[2], &bdev);
5d27223e
EN
60 if (ret < 0)
61 return CMD_RET_FAILURE;
62
7e5f460e
SG
63 addr = (unsigned char *)hextoul(argv[3], NULL);
64 length = hextoul(argv[4], NULL);
5d27223e
EN
65
66 if (5 < argc) {
7e5f460e 67 writebuf = hextoul(argv[5], NULL);
5d27223e
EN
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);
This page took 0.293 seconds and 4 git commands to generate.