]> Git Repo - u-boot.git/blame - cmd/unzip.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[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, [email protected].
c3d2a17c
MF
5 */
6
d678a59d 7#include <common.h>
c3d2a17c 8#include <command.h>
c7694dd4 9#include <env.h>
0c670fc1 10#include <gzip.h>
6cdc8be7 11#include <mapmem.h>
e6f6f9e6 12#include <part.h>
c3d2a17c 13
09140113
SG
14static int do_unzip(struct cmd_tbl *cmdtp, int flag, int argc,
15 char *const argv[])
c3d2a17c
MF
16{
17 unsigned long src, dst;
18 unsigned long src_len = ~0UL, dst_len = ~0UL;
c3d2a17c
MF
19
20 switch (argc) {
21 case 4:
7e5f460e 22 dst_len = hextoul(argv[3], NULL);
c3d2a17c
MF
23 /* fall through */
24 case 3:
7e5f460e
SG
25 src = hextoul(argv[1], NULL);
26 dst = hextoul(argv[2], NULL);
c3d2a17c
MF
27 break;
28 default:
4c12eeb8 29 return CMD_RET_USAGE;
c3d2a17c
MF
30 }
31
6cdc8be7
SG
32 if (gunzip(map_sysmem(dst, dst_len), dst_len, map_sysmem(src, 0),
33 &src_len) != 0)
c3d2a17c
MF
34 return 1;
35
9ae2ddc8 36 printf("Uncompressed size: %lu = 0x%lX\n", src_len, src_len);
018f5303 37 env_set_hex("filesize", src_len);
c3d2a17c
MF
38
39 return 0;
40}
41
42U_BOOT_CMD(
43 unzip, 4, 1, do_unzip,
44 "unzip a memory region",
45 "srcaddr dstaddr [dstsize]"
46);
5d27223e 47
09140113
SG
48static int do_gzwrite(struct cmd_tbl *cmdtp, int flag,
49 int argc, char *const argv[])
5d27223e 50{
4101f687 51 struct blk_desc *bdev;
5d27223e
EN
52 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;
ebac37cf 61 ret = blk_get_device_by_str(argv[1], argv[2], &bdev);
5d27223e
EN
62 if (ret < 0)
63 return CMD_RET_FAILURE;
64
7e5f460e
SG
65 addr = (unsigned char *)hextoul(argv[3], NULL);
66 length = hextoul(argv[4], NULL);
5d27223e
EN
67
68 if (5 < argc) {
7e5f460e 69 writebuf = hextoul(argv[5], NULL);
5d27223e
EN
70 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);
This page took 0.308803 seconds and 4 git commands to generate.